diff --git a/CHANGELOG.md b/CHANGELOG.md index c600138a..e4f9ac79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### Release 1.3.3 + +* Fixed [#159] : Mod crashed with java version 12 or higher due to "javalangnosuchfieldexception modifiers" +* Fixed [#159] : Blocks would glitch in 1.14 - 1.16 after the GUI was opened on the signal or the signalbox. This resulted in the block not reacting to changed states and staying rendered even after the destruction of the block. + ### Release 1.3.2 * Fixed [#151] : Rail switch always points left from either perspective diff --git a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxComplexSignal.java b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxComplexSignal.java index 719a9fe9..373c8c80 100644 --- a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxComplexSignal.java +++ b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxComplexSignal.java @@ -23,6 +23,7 @@ public class GuiSignalBoxComplexSignal implements IScreen { private static TileSignalBox tsb; + private static String signalId; private final ItemStack itemStackRight; private final ItemStack itemStackLeft; @@ -41,10 +42,8 @@ public class GuiSignalBoxComplexSignal implements IScreen { private String originalLeftState; public GuiSignalBoxComplexSignal() { - final TileComplexSignal tsp = tsb.getTileComplexSignal(); - String itemId = tsp.getId(); - modes = LOSBlocks.BLOCK_COMPLEX_SIGNAL.getAllGroupStates(tsp.getId()); + modes = LOSBlocks.BLOCK_COMPLEX_SIGNAL.getAllGroupStates(signalId); modeGroups = modes.keySet(); originalSignalGroup = tsb.getGroupId(getFirstValue(modeGroups)); signalGroup = originalSignalGroup; @@ -56,19 +55,20 @@ public GuiSignalBoxComplexSignal() { itemStackLeft = new ItemStack(LOSItems.ITEM_COMPLEX_SIGNAL, 1); final TagCompound tag = itemStackLeft.getTagCompound(); - tag.setString("itemId", itemId); + tag.setString("itemId", signalId); itemStackLeft.setTagCompound(tag); itemStackRight = new ItemStack(LOSItems.ITEM_COMPLEX_SIGNAL, 1); final TagCompound tag2 = itemStackRight.getTagCompound(); - tag2.setString("itemId", itemId); + tag2.setString("itemId", signalId); itemStackRight.setTagCompound(tag2); } - public static void open(final TileSignalBox tileSignalBox) { + public static void open(final TileSignalBox tileSignalBox, String signalId) { tsb = tileSignalBox; + GuiSignalBoxComplexSignal.signalId = signalId; LOSGuis.SIGNAL_BOX_COMPLEX_SIGNAL.open(MinecraftClient.getPlayer()); } diff --git a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxSignalPart.java b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxSignalPart.java index c7f6666d..839035f4 100644 --- a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxSignalPart.java +++ b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxSignalPart.java @@ -21,6 +21,7 @@ public class GuiSignalBoxSignalPart implements IScreen { private static TileSignalBox tsb; + private static String signalId; private final ItemStack itemStackRight; private final ItemStack itemStackLeft; @@ -34,10 +35,7 @@ public class GuiSignalBoxSignalPart implements IScreen { public GuiSignalBoxSignalPart() { - final TileSignalPart tsp = tsb.getTileSignalPart(); - String itemId = tsp.getId(); - - states = LOSBlocks.BLOCK_SIGNAL_PART.getAllStates(tsp.getId()); + states = LOSBlocks.BLOCK_SIGNAL_PART.getAllStates(signalId); originalRightState = tsb.getActiveGroupState(""); rightState = originalRightState; @@ -47,19 +45,20 @@ public GuiSignalBoxSignalPart() { itemStackLeft = new ItemStack(LOSItems.ITEM_SIGNAL_PART, 1); final TagCompound tag = itemStackLeft.getTagCompound(); - tag.setString("itemId", itemId); + tag.setString("itemId", signalId); itemStackLeft.setTagCompound(tag); itemStackRight = new ItemStack(LOSItems.ITEM_SIGNAL_PART, 1); final TagCompound tag2 = itemStackRight.getTagCompound(); - tag2.setString("itemId", itemId); + tag2.setString("itemId", signalId); itemStackRight.setTagCompound(tag2); } - public static void open(final TileSignalBox tileSignalBox) { + public static void open(final TileSignalBox tileSignalBox, String signalId) { tsb = tileSignalBox; + GuiSignalBoxSignalPart.signalId = signalId; LOSGuis.SIGNAL_BOX_SIGNAL_PART.open(MinecraftClient.getPlayer()); } @@ -76,7 +75,7 @@ public void init(final IScreenBuilder screen) { groupButton = new Button(screen, -100, 0, GuiText.LABEL_SIGNALGROUP.toString("default")) { @Override public void onClick(Player.Hand hand) { - + // Signal parts have only one group - so no logic needed here } }; new Button(screen, -100, 50, "<-- " + GuiText.LABEL_NOREDSTONE) { diff --git a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalPrioritization.java b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalPrioritization.java index 406efbe8..ccc07170 100644 --- a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalPrioritization.java +++ b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalPrioritization.java @@ -17,8 +17,6 @@ import net.landofrails.landofsignals.LOSItems; import net.landofrails.landofsignals.packet.GuiSignalPrioritizationToServerPacket; import net.landofrails.landofsignals.serialization.EmptyStringMapper; -import net.landofrails.landofsignals.tile.TileComplexSignal; -import net.landofrails.landofsignals.tile.TileSignalPart; import util.Matrix4; import java.text.MessageFormat; @@ -26,11 +24,15 @@ import java.util.function.Consumer; import java.util.function.Supplier; +import static net.landofrails.landofsignals.packet.GuiSignalPrioritizationToClientPacket.SIGNAL_PART_ID; + public class GuiSignalPrioritization implements IScreen { - private static TileSignalPart tileSignalPart; - private static TileComplexSignal tileComplexSignal; + private static Integer signalType; private static Vec3i signalPos; + private static String signalId; + private static String[] orderedStates; + private static Map orderedGroupStates; private static final Supplier GUI = () -> LOSGuis.SIGNAL_PRIORITIZATION; @@ -133,8 +135,7 @@ public void onClick(Player.Hand hand) { }; actions[i] = indexOffset -> { - int index = entriesIndex + indexOffset; - itemIndex = index; + itemIndex = entriesIndex + indexOffset; updateButtons(); }; } @@ -176,7 +177,7 @@ public void onEnterKey(IScreenBuilder builder) { @Override public void onClose() { - if (tileSignalPart != null) { + if (signalType == SIGNAL_PART_ID) { if (Arrays.deepEquals(originalStates, states)) { return; } @@ -242,29 +243,20 @@ else if (useNext) } private static T getFirstValue(T[] values) { - for (T object : values) - return object; + if(values != null && values.length >= 1) + return values[0]; return null; } private static Map cleanCopy(Map map) { Map val = new HashMap<>(); - map.forEach((groupId, states) -> { - val.put(groupId, Arrays.copyOf(states, states.length)); - }); + map.forEach((groupId, states) -> val.put(groupId, Arrays.copyOf(states, states.length))); return val; } - // Getters for signal-dependent stuff - private String getId() { - if (tileSignalPart != null) - return tileSignalPart.getId(); - return tileComplexSignal.getId(); - } - private boolean initStates(IScreenBuilder screen) { - if (tileSignalPart != null) { - states = tileSignalPart.getOrderedStates(); + if (signalType == SIGNAL_PART_ID) { + states = orderedStates != null ? Arrays.copyOf(orderedStates, orderedStates.length) : null; if (states == null || states.length == 0) { screen.close(); return false; @@ -275,7 +267,7 @@ private boolean initStates(IScreenBuilder screen) { groups = new String[0]; } else { - groupStates = tileComplexSignal.getOrderedGroupStates(); + groupStates = orderedGroupStates != null? cleanCopy(orderedGroupStates) : null; if (groupStates == null || groupStates.isEmpty()) { screen.close(); return false; @@ -283,7 +275,7 @@ private boolean initStates(IScreenBuilder screen) { originalGroupStates = cleanCopy(groupStates); - Map signalGroups = LOSBlocks.BLOCK_COMPLEX_SIGNAL.getAllGroupStates(tileComplexSignal.getId()); + Map signalGroups = LOSBlocks.BLOCK_COMPLEX_SIGNAL.getAllGroupStates(signalId); groups = signalGroups.keySet().toArray(new String[0]); groupNames = new HashMap<>(); signalGroups.forEach((groupId, group) -> @@ -296,22 +288,21 @@ private boolean initStates(IScreenBuilder screen) { } private void createItem() { - String blockId = getId(); - if (tileSignalPart != null) { + if (signalType == SIGNAL_PART_ID) { item = new ItemStack(LOSItems.ITEM_SIGNAL_PART, 1); TagCompound tag = item.getTagCompound(); - tag.setString("itemId", blockId); + tag.setString("itemId", signalId); item.setTagCompound(tag); } else { item = new ItemStack(LOSItems.ITEM_COMPLEX_SIGNAL, 1); TagCompound tag = item.getTagCompound(); - tag.setString("itemId", blockId); + tag.setString("itemId", signalId); item.setTagCompound(tag); } } private void refreshItem() { - if (tileSignalPart != null) { + if (signalType == SIGNAL_PART_ID) { final TagCompound rightTag = item.getTagCompound(); rightTag.setString("itemState", states[itemIndex]); item.setTagCompound(rightTag); @@ -336,17 +327,13 @@ private void updateGroup(String newGroup) { // Open-Functions - public static void open(Vec3i signalPos, TileSignalPart tileSignalPart) { + public static void open(Vec3i signalPos, int signalType, String signalId, String[] orderedStates, Map orderedGroupStates) { GuiSignalPrioritization.signalPos = signalPos; - GuiSignalPrioritization.tileSignalPart = tileSignalPart; - GuiSignalPrioritization.tileComplexSignal = null; - GUI.get().open(MinecraftClient.getPlayer()); - } + GuiSignalPrioritization.signalType = signalType; + GuiSignalPrioritization.signalId = signalId; + GuiSignalPrioritization.orderedStates = orderedStates; + GuiSignalPrioritization.orderedGroupStates = orderedGroupStates; - public static void open(Vec3i signalPos, TileComplexSignal tileComplexSignal) { - GuiSignalPrioritization.signalPos = signalPos; - GuiSignalPrioritization.tileSignalPart = null; - GuiSignalPrioritization.tileComplexSignal = tileComplexSignal; GUI.get().open(MinecraftClient.getPlayer()); } diff --git a/src/main/java/net/landofrails/landofsignals/packet/GuiSignalPrioritizationToClientPacket.java b/src/main/java/net/landofrails/landofsignals/packet/GuiSignalPrioritizationToClientPacket.java index d4c1849d..80fcc64a 100644 --- a/src/main/java/net/landofrails/landofsignals/packet/GuiSignalPrioritizationToClientPacket.java +++ b/src/main/java/net/landofrails/landofsignals/packet/GuiSignalPrioritizationToClientPacket.java @@ -5,49 +5,60 @@ import cam72cam.mod.net.Packet; import cam72cam.mod.serialization.TagField; import net.landofrails.landofsignals.gui.GuiSignalPrioritization; +import net.landofrails.landofsignals.serialization.MapStringStringArrayMapper; +import net.landofrails.landofsignals.serialization.StringArrayMapper; import net.landofrails.landofsignals.tile.TileComplexSignal; import net.landofrails.landofsignals.tile.TileSignalPart; +import java.util.Map; + public class GuiSignalPrioritizationToClientPacket extends Packet { + public static final int SIGNAL_PART_ID = 1; + public static final int COMPLEX_SIGNAL_ID = 2; + @TagField("signalPos") Vec3i signalPos; - @TagField("tileSignalPart") - TileSignalPart tileSignalPart; - @TagField("tileComplexSignal") - TileComplexSignal tileComplexSignal; + @TagField("signalType") + int signalType; + @TagField("signalId") + String signalId; + @TagField(value = "orderedStates", mapper = StringArrayMapper.class) + String[] orderedStates = null; + @TagField(value = "orderedGroupStates", mapper = MapStringStringArrayMapper.class) + Map orderedGroupStates = null; public GuiSignalPrioritizationToClientPacket() { } - public GuiSignalPrioritizationToClientPacket(Vec3i signalPos, TileSignalPart tileSignalPart) { - this.signalPos = signalPos; - this.tileSignalPart = tileSignalPart; + public GuiSignalPrioritizationToClientPacket(TileSignalPart tileSignalPart) { + this.signalPos = tileSignalPart.getPos(); + this.signalType = SIGNAL_PART_ID; + this.signalId = tileSignalPart.getId(); + this.orderedStates = tileSignalPart.getOrderedStates(); } - public GuiSignalPrioritizationToClientPacket(Vec3i signalPos, TileComplexSignal tileComplexSignal) { - this.signalPos = signalPos; - this.tileComplexSignal = tileComplexSignal; + public GuiSignalPrioritizationToClientPacket(TileComplexSignal tileComplexSignal) { + this.signalPos = tileComplexSignal.getPos(); + this.signalType = COMPLEX_SIGNAL_ID; + this.signalId = tileComplexSignal.getId(); + this.orderedGroupStates = tileComplexSignal.getOrderedGroupStates(); } @Override protected void handle() { - if (tileSignalPart != null) { - getWorld().setBlockEntity(signalPos, tileSignalPart); - GuiSignalPrioritization.open(signalPos, tileSignalPart); - } else if (tileComplexSignal != null) { - getWorld().setBlockEntity(signalPos, tileComplexSignal); - GuiSignalPrioritization.open(signalPos, tileComplexSignal); - } + GuiSignalPrioritization.open(signalPos, signalType, signalId, orderedStates, orderedGroupStates); } public static void sendToPlayer(Player player, TileSignalPart tileSignalPart) { - new GuiSignalPrioritizationToClientPacket(tileSignalPart.getPos(), tileSignalPart).sendToPlayer(player); + tileSignalPart.markDirty(); + new GuiSignalPrioritizationToClientPacket(tileSignalPart).sendToPlayer(player); } public static void sendToPlayer(Player player, TileComplexSignal tileComplexSignal) { - new GuiSignalPrioritizationToClientPacket(tileComplexSignal.getPos(), tileComplexSignal).sendToPlayer(player); + tileComplexSignal.markDirty(); + new GuiSignalPrioritizationToClientPacket(tileComplexSignal).sendToPlayer(player); } } diff --git a/src/main/java/net/landofrails/landofsignals/packet/SignalBoxTileSignalPartPacket.java b/src/main/java/net/landofrails/landofsignals/packet/SignalBoxTileSignalPartPacket.java index bef1b106..8dbe2475 100644 --- a/src/main/java/net/landofrails/landofsignals/packet/SignalBoxTileSignalPartPacket.java +++ b/src/main/java/net/landofrails/landofsignals/packet/SignalBoxTileSignalPartPacket.java @@ -12,45 +12,34 @@ public class SignalBoxTileSignalPartPacket extends Packet { - @TagField("tileSignalPart") - TileSignalPart tileSignalPart; - @TagField("tileComplexSignal") - TileComplexSignal tileComplexSignal; - - @TagField("tileSignalBox") - TileSignalBox tileSignalBox; @TagField("posSignalBox") Vec3i posSignalBox; @TagField("signalType") Byte signalType; + @TagField("signalId") + String signalId; public SignalBoxTileSignalPartPacket() { } public SignalBoxTileSignalPartPacket(final TileSignalPart tileSignalPart, final TileSignalBox tileSignalBox) { - this.tileSignalPart = tileSignalPart; - this.tileSignalBox = tileSignalBox; + this.signalId = tileSignalPart.getId(); this.posSignalBox = tileSignalBox.getPos(); this.signalType = tileSignalBox.getSignalType(); } public SignalBoxTileSignalPartPacket(final TileComplexSignal tileComplexSignal, final TileSignalBox tileSignalBox) { - this.tileComplexSignal = tileComplexSignal; - this.tileSignalBox = tileSignalBox; + this.signalId = tileComplexSignal.getId(); this.posSignalBox = tileSignalBox.getPos(); this.signalType = tileSignalBox.getSignalType(); } @Override protected void handle() { - if (tileSignalPart != null) { - getWorld().setBlockEntity(posSignalBox, tileSignalBox); - getWorld().getBlockEntity(posSignalBox, TileSignalBox.class).setTileSignalPart(tileSignalPart); - GuiSignalBoxSignalPart.open(tileSignalBox); - } else if (tileComplexSignal != null) { - getWorld().setBlockEntity(posSignalBox, tileSignalBox); - getWorld().getBlockEntity(posSignalBox, TileSignalBox.class).setTileComplexSignal(tileComplexSignal); - GuiSignalBoxComplexSignal.open(tileSignalBox); + if (signalType == 0) { + GuiSignalBoxSignalPart.open(getWorld().getBlockEntity(posSignalBox, TileSignalBox.class), signalId); + } else if (signalType == 1) { + GuiSignalBoxComplexSignal.open(getWorld().getBlockEntity(posSignalBox, TileSignalBox.class), signalId); } else { LandOfSignals.error("Can't open Signalbox, no tile entity given."); } diff --git a/src/main/java/net/landofrails/landofsignals/tile/TileComplexSignal.java b/src/main/java/net/landofrails/landofsignals/tile/TileComplexSignal.java index bf59153f..76995f73 100644 --- a/src/main/java/net/landofrails/landofsignals/tile/TileComplexSignal.java +++ b/src/main/java/net/landofrails/landofsignals/tile/TileComplexSignal.java @@ -30,7 +30,7 @@ public class TileComplexSignal extends BlockEntity implements IManipulate { @TagField("blockRotation") private int blockRotate; @TagField("id") - private final String id; + private String id; @TagField(value = "signalGroupStates", mapper = MapStringStringMapper.class) private Map signalGroupStates = new HashMap<>(); // for server only diff --git a/src/main/java/net/landofrails/landofsignals/tile/TileSignPart.java b/src/main/java/net/landofrails/landofsignals/tile/TileSignPart.java index 35a6b361..3fe44917 100644 --- a/src/main/java/net/landofrails/landofsignals/tile/TileSignPart.java +++ b/src/main/java/net/landofrails/landofsignals/tile/TileSignPart.java @@ -25,7 +25,7 @@ public class TileSignPart extends BlockEntity implements IManipulate { @TagField("blockRotation") private int blockRotate; @TagField("id") - private final String id; + private String id; @TagField private String signText; @TagField("offset") diff --git a/src/main/java/net/landofrails/landofsignals/tile/TileSignalBox.java b/src/main/java/net/landofrails/landofsignals/tile/TileSignalBox.java index 986e80fc..52bacad1 100644 --- a/src/main/java/net/landofrails/landofsignals/tile/TileSignalBox.java +++ b/src/main/java/net/landofrails/landofsignals/tile/TileSignalBox.java @@ -63,9 +63,6 @@ public class TileSignalBox extends BlockEntity implements IManipulate { @Nullable private Integer lastRedstone; - private TileSignalPart tileSignalPart; - private TileComplexSignal tileComplexSignal; - // client-only private boolean highlighting = false; @@ -111,6 +108,7 @@ public boolean onClick(Player player, Player.Hand hand, Facing facing, Vec3d hit clearPreviousData(); } + this.markDirty(); new SignalBoxTileSignalPartPacket(tempSignalPart, this).sendToPlayer(player); return true; } @@ -121,6 +119,7 @@ public boolean onClick(Player player, Player.Hand hand, Facing facing, Vec3d hit clearPreviousData(); } + this.markDirty(); new SignalBoxTileSignalPartPacket(tempComplexSignal, this).sendToPlayer(player); return true; } @@ -212,26 +211,6 @@ public void setTileSignalPartPos(final Vec3i pos, final byte signalType) { markDirty(); } - public void setTileSignalPart(final TileSignalPart tileSignalPart) { - this.tileComplexSignal = null; - this.tileSignalPart = tileSignalPart; - this.signalType = 0; - } - - public TileSignalPart getTileSignalPart() { - return tileSignalPart; - } - - public void setTileComplexSignal(TileComplexSignal tileComplexSignal) { - this.tileSignalPart = null; - this.tileComplexSignal = tileComplexSignal; - this.signalType = 1; - } - - public TileComplexSignal getTileComplexSignal() { - return tileComplexSignal; - } - @Nullable public Byte getSignalType() { return this.signalType; diff --git a/src/main/java/net/landofrails/landofsignals/tile/TileSignalPart.java b/src/main/java/net/landofrails/landofsignals/tile/TileSignalPart.java index c61f8f31..41ed3a1f 100644 --- a/src/main/java/net/landofrails/landofsignals/tile/TileSignalPart.java +++ b/src/main/java/net/landofrails/landofsignals/tile/TileSignalPart.java @@ -34,7 +34,7 @@ public class TileSignalPart extends BlockEntity implements IManipulate { @TagField("blockRotation") private int blockRotate; @TagField("id") - private final String id; + private String id; @TagField("texturePath") private String texturePath = ""; @TagField(value = "orderedStates", mapper = StringArrayMapper.class) diff --git a/src/main/java/net/landofrails/landofsignals/tile/TileSignalPartAnimated.java b/src/main/java/net/landofrails/landofsignals/tile/TileSignalPartAnimated.java index a435c4ef..7e37fa36 100644 --- a/src/main/java/net/landofrails/landofsignals/tile/TileSignalPartAnimated.java +++ b/src/main/java/net/landofrails/landofsignals/tile/TileSignalPartAnimated.java @@ -16,7 +16,7 @@ public class TileSignalPartAnimated extends BlockEntityTickable implements IMani @TagField("blockRotation") private int blockRotate; @TagField("id") - private final String id; + private String id; @TagField("texturePath") private String animationOrTextureName;