From 4b40b07bf80c1adbe551950be3f9e0e545ce7286 Mon Sep 17 00:00:00 2001 From: William Johnstone Date: Sat, 21 Mar 2020 21:37:55 +0000 Subject: [PATCH] Refactor code and improve sword breaking --- .../translators/block/BlockTranslator.java | 5 +-- .../network/translators/item/ItemEntry.java | 13 +++--- .../translators/item/ToolItemEntry.java | 15 +++++++ .../player/JavaPlayerActionAckTranslator.java | 43 +++++++++++-------- .../org/geysermc/connector/utils/Toolbox.java | 29 ++++++++++--- 5 files changed, 69 insertions(+), 36 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/item/ToolItemEntry.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index 330987615..5132e90d5 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -53,7 +53,7 @@ public class BlockTranslator { private static final Map JAVA_ID_TO_BLOCK_ENTITY_MAP = new HashMap<>(); public static final Int2DoubleMap JAVA_RUNTIME_ID_TO_HARDNESS = new Int2DoubleOpenHashMap(); - public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_BREAK_WITH_HAND = new Int2BooleanOpenHashMap(); + public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND = new Int2BooleanOpenHashMap(); public static final Int2ObjectMap JAVA_RUNTIME_ID_TO_TOOL_TYPE = new Int2ObjectOpenHashMap<>(); // For block breaking animation math @@ -109,7 +109,7 @@ public class BlockTranslator { JAVA_RUNTIME_ID_TO_HARDNESS.put(javaRuntimeId, hardnessNode.doubleValue()); } - JAVA_RUNTIME_ID_TO_CAN_BREAK_WITH_HAND.put(javaRuntimeId, entry.getValue().get("can_break_with_hand").booleanValue()); + JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND.put(javaRuntimeId, entry.getValue().get("can_break_with_hand").booleanValue()); JsonNode toolTypeNode = entry.getValue().get("tool_type"); if (toolTypeNode != null) { @@ -120,7 +120,6 @@ public class BlockTranslator { JAVA_RUNTIME_WOOL_IDS.add(javaRuntimeId); } - if (javaId.contains("cobweb")) { cobwebRuntimeId = javaRuntimeId; } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemEntry.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemEntry.java index b5a9eb42c..e579c20ee 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemEntry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemEntry.java @@ -32,16 +32,13 @@ import lombok.Getter; @AllArgsConstructor public class ItemEntry { - public static ItemEntry AIR = new ItemEntry("minecraft:air", 0, 0, 0, "none", "none"); + public static ItemEntry AIR = new ItemEntry("minecraft:air", 0, 0, 0); - private String javaIdentifier; - private int javaId; + private final String javaIdentifier; + private final int javaId; - private int bedrockId; - private int bedrockData; - - private String toolType; - private String toolTier; + private final int bedrockId; + private final int bedrockData; @Override public boolean equals(Object obj) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ToolItemEntry.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ToolItemEntry.java new file mode 100644 index 000000000..5d1ddd262 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ToolItemEntry.java @@ -0,0 +1,15 @@ +package org.geysermc.connector.network.translators.item; + +import lombok.Getter; + +@Getter +public class ToolItemEntry extends ItemEntry { + private final String toolType; + private final String toolTier; + + public ToolItemEntry(String javaIdentifier, int javaId, int bedrockId, int bedrockData, String toolType, String toolTier) { + super(javaIdentifier, javaId, bedrockId, bedrockData); + this.toolType = toolType; + this.toolTier = toolTier; + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerActionAckTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerActionAckTranslator.java index 34b1646ad..2e28584e9 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerActionAckTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerActionAckTranslator.java @@ -36,6 +36,7 @@ import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.network.translators.block.BlockTranslator; import org.geysermc.connector.network.translators.item.ItemEntry; +import org.geysermc.connector.network.translators.item.ToolItemEntry; import org.geysermc.connector.utils.ChunkUtils; public class JavaPlayerActionAckTranslator extends PacketTranslator { @@ -59,6 +60,8 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator