forked from GeyserMC/Geyser
Fix display of some more entities (#726)
* Fix display of Evoker and Evoker Fangs * Fix spawner minecart display * Centeralise custom blocks for spawner and furnace minecarts * Add comment explaining class
This commit is contained in:
parent
a91eaa7821
commit
5eef265f80
6 changed files with 152 additions and 35 deletions
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* @author GeyserMC
|
||||||
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geysermc.connector.entity;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used as a base for minecarts with a default block to display like furnaces and spawners
|
||||||
|
*/
|
||||||
|
public class DefaultBlockMinecartEntity extends MinecartEntity {
|
||||||
|
|
||||||
|
public int customBlock = 0;
|
||||||
|
public int customBlockOffset = 0;
|
||||||
|
public boolean showCustomBlock = false;
|
||||||
|
|
||||||
|
public DefaultBlockMinecartEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
|
|
||||||
|
updateDefaultBlockMetadata();
|
||||||
|
metadata.put(EntityData.HAS_DISPLAY, (byte) 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
|
|
||||||
|
// Custom block
|
||||||
|
if (entityMetadata.getId() == 10) {
|
||||||
|
customBlock = (int) entityMetadata.getValue();
|
||||||
|
|
||||||
|
if (showCustomBlock) {
|
||||||
|
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId(customBlock));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom block offset
|
||||||
|
if (entityMetadata.getId() == 11) {
|
||||||
|
customBlockOffset = (int) entityMetadata.getValue();
|
||||||
|
|
||||||
|
if (showCustomBlock) {
|
||||||
|
metadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the custom block should be enabled
|
||||||
|
if (entityMetadata.getId() == 12) {
|
||||||
|
if ((boolean) entityMetadata.getValue()) {
|
||||||
|
showCustomBlock = true;
|
||||||
|
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId(customBlock));
|
||||||
|
metadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset);
|
||||||
|
} else {
|
||||||
|
showCustomBlock = false;
|
||||||
|
updateDefaultBlockMetadata();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDefaultBlockMetadata() { }
|
||||||
|
}
|
|
@ -32,54 +32,26 @@ import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||||
|
|
||||||
public class FurnaceMinecartEntity extends MinecartEntity {
|
public class FurnaceMinecartEntity extends DefaultBlockMinecartEntity {
|
||||||
|
|
||||||
private int customBlock = 0;
|
|
||||||
private int customBlockOffset = 0;
|
|
||||||
private boolean showCustomBlock = false;
|
|
||||||
private boolean hasFuel = false;
|
private boolean hasFuel = false;
|
||||||
|
|
||||||
public FurnaceMinecartEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public FurnaceMinecartEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
super(entityId, geyserId, entityType, position, motion, rotation);
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
|
|
||||||
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId(BlockTranslator.JAVA_RUNTIME_FURNACE_ID));
|
|
||||||
metadata.put(EntityData.HAS_DISPLAY, (byte) 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
|
|
||||||
// Custom block
|
|
||||||
if (entityMetadata.getId() == 10) {
|
|
||||||
customBlock = (int) entityMetadata.getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom block offset
|
|
||||||
if (entityMetadata.getId() == 11) {
|
|
||||||
customBlockOffset = (int) entityMetadata.getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the custom block should be enabled
|
|
||||||
if (entityMetadata.getId() == 12) {
|
|
||||||
if ((boolean) entityMetadata.getValue()) {
|
|
||||||
showCustomBlock = true;
|
|
||||||
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId(customBlock));
|
|
||||||
metadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset);
|
|
||||||
} else {
|
|
||||||
showCustomBlock = false;
|
|
||||||
updateFurnaceMetadata();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entityMetadata.getId() == 13 && !showCustomBlock) {
|
if (entityMetadata.getId() == 13 && !showCustomBlock) {
|
||||||
hasFuel = (boolean) entityMetadata.getValue();
|
hasFuel = (boolean) entityMetadata.getValue();
|
||||||
updateFurnaceMetadata();
|
updateDefaultBlockMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFurnaceMetadata() {
|
@Override
|
||||||
|
public void updateDefaultBlockMetadata() {
|
||||||
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId(hasFuel ? BlockTranslator.JAVA_RUNTIME_FURNACE_LIT_ID : BlockTranslator.JAVA_RUNTIME_FURNACE_ID));
|
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId(hasFuel ? BlockTranslator.JAVA_RUNTIME_FURNACE_LIT_ID : BlockTranslator.JAVA_RUNTIME_FURNACE_ID));
|
||||||
metadata.put(EntityData.DISPLAY_OFFSET, 6);
|
metadata.put(EntityData.DISPLAY_OFFSET, 6);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class MinecartEntity extends Entity {
|
||||||
metadata.put(EntityData.HURT_TIME, Math.min((int) (float) entityMetadata.getValue(), 15));
|
metadata.put(EntityData.HURT_TIME, Math.min((int) (float) entityMetadata.getValue(), 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(this instanceof FurnaceMinecartEntity)) { // Handled in FurnaceMinecartEntity.java
|
if (!(this instanceof DefaultBlockMinecartEntity)) { // Handled in the DefaultBlockMinecartEntity class
|
||||||
// Custom block
|
// Custom block
|
||||||
if (entityMetadata.getId() == 10) {
|
if (entityMetadata.getId() == 10) {
|
||||||
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId((int) entityMetadata.getValue()));
|
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId((int) entityMetadata.getValue()));
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* @author GeyserMC
|
||||||
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geysermc.connector.entity;
|
||||||
|
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||||
|
|
||||||
|
public class SpawnerMinecartEntity extends DefaultBlockMinecartEntity {
|
||||||
|
|
||||||
|
public SpawnerMinecartEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDefaultBlockMetadata() {
|
||||||
|
metadata.put(EntityData.DISPLAY_ITEM, BlockTranslator.getBedrockBlockId(BlockTranslator.JAVA_RUNTIME_SPAWNER_ID));
|
||||||
|
metadata.put(EntityData.DISPLAY_OFFSET, 6);
|
||||||
|
}
|
||||||
|
}
|
|
@ -134,11 +134,12 @@ public enum EntityType {
|
||||||
MINECART_TNT(MinecartEntity.class, 97, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:tnt_minecart"),
|
MINECART_TNT(MinecartEntity.class, 97, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:tnt_minecart"),
|
||||||
MINECART_CHEST(MinecartEntity.class, 98, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:chest_minecart"),
|
MINECART_CHEST(MinecartEntity.class, 98, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:chest_minecart"),
|
||||||
MINECART_FURNACE(FurnaceMinecartEntity.class, 98, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:minecart"),
|
MINECART_FURNACE(FurnaceMinecartEntity.class, 98, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:minecart"),
|
||||||
|
MINECART_SPAWNER(SpawnerMinecartEntity.class, 98, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:minecart"),
|
||||||
MINECART_COMMAND_BLOCK(MinecartEntity.class, 100, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:command_block_minecart"),
|
MINECART_COMMAND_BLOCK(MinecartEntity.class, 100, 0.7f, 0.98f, 0.98f, 0.35f, "minecraft:command_block_minecart"),
|
||||||
LINGERING_POTION(ThrowableEntity.class, 101, 0f),
|
LINGERING_POTION(ThrowableEntity.class, 101, 0f),
|
||||||
LLAMA_SPIT(Entity.class, 102, 0.25f),
|
LLAMA_SPIT(Entity.class, 102, 0.25f),
|
||||||
EVOKER_FANGS(Entity.class, 103, 0.8f, 0.5f),
|
EVOKER_FANGS(Entity.class, 103, 0.8f, 0.5f, 0.5f, 0f, "minecraft:evocation_fang"),
|
||||||
EVOKER(SpellcasterIllagerEntity.class, 104, 1.95f, 0.5f),
|
EVOKER(SpellcasterIllagerEntity.class, 104, 1.95f, 0.6f, 0.6f, 0f, "minecraft:evocation_illager"),
|
||||||
VEX(MonsterEntity.class, 105, 0.8f, 0.4f),
|
VEX(MonsterEntity.class, 105, 0.8f, 0.4f),
|
||||||
ICE_BOMB(Entity.class, 106, 0f),
|
ICE_BOMB(Entity.class, 106, 0f),
|
||||||
BALLOON(Entity.class, 107, 0f), //TODO
|
BALLOON(Entity.class, 107, 0f), //TODO
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class BlockTranslator {
|
||||||
public static final int JAVA_RUNTIME_FURNACE_ID;
|
public static final int JAVA_RUNTIME_FURNACE_ID;
|
||||||
public static final int JAVA_RUNTIME_FURNACE_LIT_ID;
|
public static final int JAVA_RUNTIME_FURNACE_LIT_ID;
|
||||||
|
|
||||||
|
public static final int JAVA_RUNTIME_SPAWNER_ID;
|
||||||
|
|
||||||
private static final int BLOCK_STATE_VERSION = 17760256;
|
private static final int BLOCK_STATE_VERSION = 17760256;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -113,6 +115,7 @@ public class BlockTranslator {
|
||||||
int cobwebRuntimeId = -1;
|
int cobwebRuntimeId = -1;
|
||||||
int furnaceRuntimeId = -1;
|
int furnaceRuntimeId = -1;
|
||||||
int furnaceLitRuntimeId = -1;
|
int furnaceLitRuntimeId = -1;
|
||||||
|
int spawnerRuntimeId = -1;
|
||||||
Iterator<Map.Entry<String, JsonNode>> blocksIterator = blocks.fields();
|
Iterator<Map.Entry<String, JsonNode>> blocksIterator = blocks.fields();
|
||||||
while (blocksIterator.hasNext()) {
|
while (blocksIterator.hasNext()) {
|
||||||
javaRuntimeId++;
|
javaRuntimeId++;
|
||||||
|
@ -199,6 +202,10 @@ public class BlockTranslator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (javaId.startsWith("minecraft:spawner")) {
|
||||||
|
spawnerRuntimeId = javaRuntimeId;
|
||||||
|
}
|
||||||
|
|
||||||
bedrockRuntimeId++;
|
bedrockRuntimeId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +224,11 @@ public class BlockTranslator {
|
||||||
}
|
}
|
||||||
JAVA_RUNTIME_FURNACE_LIT_ID = furnaceLitRuntimeId;
|
JAVA_RUNTIME_FURNACE_LIT_ID = furnaceLitRuntimeId;
|
||||||
|
|
||||||
|
if (spawnerRuntimeId == -1) {
|
||||||
|
throw new AssertionError("Unable to find spawner in palette");
|
||||||
|
}
|
||||||
|
JAVA_RUNTIME_SPAWNER_ID = spawnerRuntimeId;
|
||||||
|
|
||||||
if (waterRuntimeId == -1) {
|
if (waterRuntimeId == -1) {
|
||||||
throw new AssertionError("Unable to find water in palette");
|
throw new AssertionError("Unable to find water in palette");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue