From d659e64613d371b9273945793d6e307a6fe552bd Mon Sep 17 00:00:00 2001 From: Danielxs01 Date: Tue, 16 Nov 2021 17:36:13 +0100 Subject: [PATCH] [#25] Current process Completed connection logic. ItemSelection still needs to be fixed. --- .../net/landofrails/stellwand/Stellwand.java | 3 + .../function/BlockSenderFunctionEntity.java | 31 ++- .../storage/BlockSenderStorageEntity.java | 13 ++ .../stellwand/content/guis/SelectItem.java | 18 +- .../content/items/ItemMagnifyingGlass.java | 1 + .../items/connector/AItemConnector.java | 163 ++++++++++++-- .../items/connector/ItemConnector.java | 202 +++--------------- .../items/connector/ItemConnectorSender.java | 86 +++++++- .../items/connector/ItemConnectorSignal.java | 58 ++++- .../stellwand/content/messages/EMessage.java | 1 + .../contentpacks/loader/StaticLoader.java | 8 +- .../assets/landofsignals/lang/de_DE.lang | 3 +- .../assets/landofsignals/lang/en_US.lang | 3 +- 13 files changed, 369 insertions(+), 221 deletions(-) diff --git a/src/main/java/net/landofrails/stellwand/Stellwand.java b/src/main/java/net/landofrails/stellwand/Stellwand.java index 6e4d88d7..cc20f810 100644 --- a/src/main/java/net/landofrails/stellwand/Stellwand.java +++ b/src/main/java/net/landofrails/stellwand/Stellwand.java @@ -8,6 +8,7 @@ import net.landofrails.stellwand.content.entities.storage.*; import net.landofrails.stellwand.content.guis.CustomGuis; import net.landofrails.stellwand.content.items.CustomItems; +import net.landofrails.stellwand.content.items.connector.AItemConnector; import net.landofrails.stellwand.content.network.CustomPackets; import net.landofrails.stellwand.content.recipes.CustomRecipes; import net.landofrails.stellwand.content.tabs.CustomTabs; @@ -37,6 +38,8 @@ public static void commonEvent(ModEvent event) { if (!StellwandConfig.disableStellwand) { Loader.init(); + AItemConnector.registerConnectors(); + CustomGuis.register(); CustomTabs.register(); CustomItems.register(); diff --git a/src/main/java/net/landofrails/stellwand/content/entities/function/BlockSenderFunctionEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/function/BlockSenderFunctionEntity.java index fd78c9c9..df78a484 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/function/BlockSenderFunctionEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/function/BlockSenderFunctionEntity.java @@ -51,16 +51,24 @@ public ItemStack onPick() { @Override public boolean onClick(Player player, Hand hand, Facing facing, Vec3d hit) { - ItemStack item = player.getHeldItem(hand); - ItemStack heldItem = player.getHeldItem(hand); - if (heldItem != null && heldItem.is(CustomItems.ITEMMAGNIFYINGGLASS)) + + // @formatter:off + if (heldItem != null && + ( + heldItem.is(CustomItems.ITEMMAGNIFYINGGLASS) || + heldItem.is(CustomItems.ITEMCONNECTOR1) || + heldItem.is(CustomItems.ITEMCONNECTOR2) || + heldItem.is(CustomItems.ITEMCONNECTOR3) + ) + ) return false; + // @formatter:on - if (isAir(item) && getWorld().isServer) { - if (!entity.signals.isEmpty()) { + if (isAir(heldItem) && hand.equals(Hand.PRIMARY) && getWorld().isServer) { + Vec3i signalPos = entity.getFirstSignal(); + if (signalPos != null) { - Vec3i signalPos = entity.signals.get(0); getWorld().keepLoaded(signalPos); if (getWorld().hasBlockEntity(signalPos, BlockSignalStorageEntity.class)) { BlockSignalStorageEntity signalEntity = getWorld().getBlockEntity(signalPos, BlockSignalStorageEntity.class); @@ -72,13 +80,11 @@ public boolean onClick(Player player, Hand hand, Facing facing, Vec3d hit) { packet.sendToPlayer(player); } else { entity.signals.remove(signalPos); - if (!getWorld().isClient) - ServerMessagePacket.send(player, EMessage.MESSAGE_NO_SIGNAL_FOUND, EMessage.MESSAGE_ERROR1.getRaw()); + ServerMessagePacket.send(player, EMessage.MESSAGE_NO_SIGNAL_FOUND, EMessage.MESSAGE_ERROR1.getRaw()); } } else { - if (!getWorld().isClient) - ServerMessagePacket.send(player, EMessage.MESSAGE_NO_SIGNALS_CONNECTED); + ServerMessagePacket.send(player, EMessage.MESSAGE_NO_SIGNALS_CONNECTED); } return true; @@ -101,6 +107,7 @@ public void onNeighborChange(Vec3i neighbor) { } public void updateSignals() { + entity.refreshSignals(); for (Vec3i signalPos : entity.signals) { getWorld().keepLoaded(signalPos); @@ -152,7 +159,9 @@ public void onBreak() { } private boolean isAir(ItemStack item) { - return item.is(ItemStack.EMPTY) || item.equals(ItemStack.EMPTY); + if (item == null) + return true; + return (item.is(ItemStack.EMPTY) || item.equals(ItemStack.EMPTY)) && item.getTagCompound().isEmpty(); } } diff --git a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSenderStorageEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSenderStorageEntity.java index f63802d2..056220bb 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSenderStorageEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSenderStorageEntity.java @@ -143,6 +143,19 @@ public void setSignal(SignalContainer signalEntity) { this.signalEntity = signalEntity; } + public Vec3i getFirstSignal() { + refreshSignals(); + for (Vec3i pos : this.signals) + if (SignalContainer.isSignal(getWorld(), pos)) + return pos; + return null; + } + + public void refreshSignals() { + this.signals.forEach(signal -> getWorld().keepLoaded(signal)); + this.signals.removeIf(vec3i -> !SignalContainer.isSignal(getWorld(), vec3i) && getWorld().isBlockLoaded(vec3i)); + } + public SignalContainer getSignal() { return this.signalEntity; } diff --git a/src/main/java/net/landofrails/stellwand/content/guis/SelectItem.java b/src/main/java/net/landofrails/stellwand/content/guis/SelectItem.java index 3e6a940d..8b7a123d 100644 --- a/src/main/java/net/landofrails/stellwand/content/guis/SelectItem.java +++ b/src/main/java/net/landofrails/stellwand/content/guis/SelectItem.java @@ -12,10 +12,12 @@ import net.landofrails.stellwand.content.items.CustomItems; import net.landofrails.stellwand.contentpacks.Content; import net.landofrails.stellwand.contentpacks.entries.ContentPack; -import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntry; import net.landofrails.stellwand.contentpacks.types.EntryType; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; import java.util.function.Consumer; public class SelectItem implements IScreen { @@ -26,7 +28,7 @@ public class SelectItem implements IScreen { // Initialized every call private List