From fbbc86d6094e3e2d4d0a9459957d0338e37a639c Mon Sep 17 00:00:00 2001 From: lothrazar Date: Wed, 4 Dec 2024 17:46:48 -0800 Subject: [PATCH] add expanded remote to curios keybind with some refactoring --- ...ageCraftingRemote.java => ItemRemote.java} | 65 +------------ .../remote/ScreenNetworkCraftingRemote.java | 16 +-- .../remote/ScreenNetworkExpandedRemote.java | 16 +-- .../item/remote/ScreenNetworkRemote.java | 16 +-- .../network/KeybindCurioMessage.java | 19 +--- .../network/SettingsSyncMessage.java | 22 ++--- .../storagenetwork/registry/SsnRegistry.java | 8 +- .../storagenetwork/util/UtilRemote.java | 97 +++++++++++++++++++ .../data/curios/tags/items/charm.json | 1 + update.json | 2 +- 10 files changed, 144 insertions(+), 118 deletions(-) rename src/main/java/com/lothrazar/storagenetwork/item/remote/{ItemStorageCraftingRemote.java => ItemRemote.java} (65%) create mode 100644 src/main/java/com/lothrazar/storagenetwork/util/UtilRemote.java diff --git a/src/main/java/com/lothrazar/storagenetwork/item/remote/ItemStorageCraftingRemote.java b/src/main/java/com/lothrazar/storagenetwork/item/remote/ItemRemote.java similarity index 65% rename from src/main/java/com/lothrazar/storagenetwork/item/remote/ItemStorageCraftingRemote.java rename to src/main/java/com/lothrazar/storagenetwork/item/remote/ItemRemote.java index e7984015..e6baacc8 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ItemStorageCraftingRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ItemRemote.java @@ -2,20 +2,17 @@ import java.util.List; import com.lothrazar.library.item.ItemFlib; -import com.lothrazar.storagenetwork.StorageNetworkMod; import com.lothrazar.storagenetwork.api.DimPos; import com.lothrazar.storagenetwork.api.EnumSortType; import com.lothrazar.storagenetwork.block.main.TileMain; import com.lothrazar.storagenetwork.block.request.TileRequest; -import com.lothrazar.storagenetwork.registry.ConfigRegistry; import com.lothrazar.storagenetwork.registry.SsnRegistry; +import com.lothrazar.storagenetwork.util.UtilRemote; import com.lothrazar.storagenetwork.util.UtilTileEntity; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; @@ -27,19 +24,17 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.network.NetworkHooks; -public class ItemStorageCraftingRemote extends ItemFlib implements MenuProvider { +public class ItemRemote extends ItemFlib implements MenuProvider { public static final String NBT_JEI = TileRequest.NBT_JEI; public static final String NBT_BOUND = "bound"; public static final String NBT_SORT = "sort"; public static final String NBT_DOWN = "down"; - public ItemStorageCraftingRemote(Properties properties) { + public ItemRemote(Properties properties) { super(properties.stacksTo(1)); } @@ -107,62 +102,10 @@ public void appendHoverText(ItemStack stack, Level worldIn, List tool } } - @SuppressWarnings("deprecation") - public static boolean openRemote(Level world, Player player, ItemStack itemStackIn, ItemStorageCraftingRemote thiss) { - DimPos dp = DimPos.getPosStored(itemStackIn); - if (dp == null) { - //unbound or invalid data - UtilTileEntity.statusMessage(player, "item.remote.notconnected"); - return false; - } - //assume we are in the same world - BlockPos posTarget = dp.getBlockPos(); - if (ConfigRegistry.ITEMRANGE.get() != -1) { - double distance = player.distanceToSqr(posTarget.getX() + 0.5D, posTarget.getY() + 0.5D, posTarget.getZ() + 0.5D); - if (distance >= ConfigRegistry.ITEMRANGE.get()) { - UtilTileEntity.statusMessage(player, "item.remote.outofrange"); - return false; - } - } - //else it is -1 so dont even check distance - //k now server only - if (world.isClientSide) { - return false; - } - //now check the dimension world - ServerLevel serverTargetWorld = null; - try { - serverTargetWorld = DimPos.stringDimensionLookup(dp.getDimension(), world.getServer()); - if (serverTargetWorld == null) { - StorageNetworkMod.LOGGER.error("Missing dimension key " + dp.getDimension()); - } - } - catch (Exception e) { - // - StorageNetworkMod.LOGGER.error("unknown exception on dim " + dp.getDimension(), e); - return false; - } - //now check is the area chunk loaded - if (!serverTargetWorld.isAreaLoaded(posTarget, 1)) { - UtilTileEntity.chatMessage(player, "item.remote.notloaded"); - StorageNetworkMod.LOGGER.info(UtilTileEntity.lang("item.remote.notloaded") + posTarget); - return false; - } - BlockEntity tile = serverTargetWorld.getBlockEntity(posTarget); - if (tile instanceof TileMain) { - NetworkHooks.openScreen((ServerPlayer) player, thiss); - return true; - } - else { - player.displayClientMessage(Component.translatable("item.remote.notfound"), true); - return false; - } - } - @Override public InteractionResultHolder use(Level world, Player player, InteractionHand hand) { ItemStack itemStackIn = player.getItemInHand(hand); - if (openRemote(world, player, itemStackIn, this)) { + if (UtilRemote.openRemote(world, player, itemStackIn, this)) { // ok great return InteractionResultHolder.success(itemStackIn); } diff --git a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java index c66461e4..d1a069e2 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java @@ -58,42 +58,42 @@ protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mous @Override public boolean getDownwards() { - return ItemStorageCraftingRemote.getDownwards(remote); + return ItemRemote.getDownwards(remote); } @Override public void setDownwards(boolean val) { - ItemStorageCraftingRemote.setDownwards(remote, val); + ItemRemote.setDownwards(remote, val); } @Override public EnumSortType getSort() { - return ItemStorageCraftingRemote.getSort(remote); + return ItemRemote.getSort(remote); } @Override public void setSort(EnumSortType val) { - ItemStorageCraftingRemote.setSort(remote, val); + ItemRemote.setSort(remote, val); } @Override public boolean isJeiSearchSynced() { - return ItemStorageCraftingRemote.isJeiSearchSynced(remote); + return ItemRemote.isJeiSearchSynced(remote); } @Override public void setJeiSearchSynced(boolean val) { - ItemStorageCraftingRemote.setJeiSearchSynced(remote, val); + ItemRemote.setJeiSearchSynced(remote, val); } @Override public boolean getAutoFocus() { - return ItemStorageCraftingRemote.getAutoFocus(remote); + return ItemRemote.getAutoFocus(remote); } @Override public void setAutoFocus(boolean b) { - ItemStorageCraftingRemote.setAutoFocus(remote, b); + ItemRemote.setAutoFocus(remote, b); } @Override diff --git a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkExpandedRemote.java b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkExpandedRemote.java index 44576004..a263bf58 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkExpandedRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkExpandedRemote.java @@ -56,42 +56,42 @@ protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mous @Override public boolean getDownwards() { - return ItemStorageCraftingRemote.getDownwards(remote); + return ItemRemote.getDownwards(remote); } @Override public void setDownwards(boolean val) { - ItemStorageCraftingRemote.setDownwards(remote, val); + ItemRemote.setDownwards(remote, val); } @Override public EnumSortType getSort() { - return ItemStorageCraftingRemote.getSort(remote); + return ItemRemote.getSort(remote); } @Override public void setSort(EnumSortType val) { - ItemStorageCraftingRemote.setSort(remote, val); + ItemRemote.setSort(remote, val); } @Override public boolean isJeiSearchSynced() { - return ItemStorageCraftingRemote.isJeiSearchSynced(remote); + return ItemRemote.isJeiSearchSynced(remote); } @Override public void setJeiSearchSynced(boolean val) { - ItemStorageCraftingRemote.setJeiSearchSynced(remote, val); + ItemRemote.setJeiSearchSynced(remote, val); } @Override public boolean getAutoFocus() { - return ItemStorageCraftingRemote.getAutoFocus(remote); + return ItemRemote.getAutoFocus(remote); } @Override public void setAutoFocus(boolean b) { - ItemStorageCraftingRemote.setAutoFocus(remote, b); + ItemRemote.setAutoFocus(remote, b); } @Override diff --git a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java index 2bbe88d6..0267fa15 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java @@ -56,42 +56,42 @@ protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mous @Override public boolean getDownwards() { - return ItemStorageCraftingRemote.getDownwards(remote); + return ItemRemote.getDownwards(remote); } @Override public void setDownwards(boolean val) { - ItemStorageCraftingRemote.setDownwards(remote, val); + ItemRemote.setDownwards(remote, val); } @Override public EnumSortType getSort() { - return ItemStorageCraftingRemote.getSort(remote); + return ItemRemote.getSort(remote); } @Override public void setSort(EnumSortType val) { - ItemStorageCraftingRemote.setSort(remote, val); + ItemRemote.setSort(remote, val); } @Override public boolean isJeiSearchSynced() { - return ItemStorageCraftingRemote.isJeiSearchSynced(remote); + return ItemRemote.isJeiSearchSynced(remote); } @Override public void setJeiSearchSynced(boolean val) { - ItemStorageCraftingRemote.setJeiSearchSynced(remote, val); + ItemRemote.setJeiSearchSynced(remote, val); } @Override public boolean getAutoFocus() { - return ItemStorageCraftingRemote.getAutoFocus(remote); + return ItemRemote.getAutoFocus(remote); } @Override public void setAutoFocus(boolean b) { - ItemStorageCraftingRemote.setAutoFocus(remote, b); + ItemRemote.setAutoFocus(remote, b); } @Override diff --git a/src/main/java/com/lothrazar/storagenetwork/network/KeybindCurioMessage.java b/src/main/java/com/lothrazar/storagenetwork/network/KeybindCurioMessage.java index fbbe8c7b..2661ace8 100644 --- a/src/main/java/com/lothrazar/storagenetwork/network/KeybindCurioMessage.java +++ b/src/main/java/com/lothrazar/storagenetwork/network/KeybindCurioMessage.java @@ -1,14 +1,10 @@ package com.lothrazar.storagenetwork.network; import java.util.function.Supplier; -import org.apache.commons.lang3.tuple.Triple; -import com.lothrazar.storagenetwork.item.remote.ItemStorageCraftingRemote; -import com.lothrazar.storagenetwork.registry.SsnRegistry; -import com.lothrazar.storagenetwork.util.UtilInventory; +import com.lothrazar.storagenetwork.util.UtilRemote; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.item.ItemStack; import net.minecraftforge.network.NetworkEvent; public class KeybindCurioMessage { @@ -19,18 +15,7 @@ public static void handle(KeybindCurioMessage message, Supplier { ServerPlayer player = ctx.get().getSender(); ServerLevel serverWorld = (ServerLevel) player.level(); - Triple searchCrafting = UtilInventory.getCurioRemote(player, SsnRegistry.Items.CRAFTING_REMOTE.get()); - ItemStack craftingRemote = searchCrafting.getRight(); - if (!craftingRemote.isEmpty()) { - ItemStorageCraftingRemote.openRemote(serverWorld, player, craftingRemote, SsnRegistry.Items.CRAFTING_REMOTE.get()); - } - else { //crafting is the upgrade, so otherwise do regular - Triple searchResult = UtilInventory.getCurioRemote(player, SsnRegistry.Items.INVENTORY_REMOTE.get()); - ItemStack curioRemote = searchResult.getRight(); - if (!curioRemote.isEmpty()) { - ItemStorageCraftingRemote.openRemote(serverWorld, player, curioRemote, SsnRegistry.Items.INVENTORY_REMOTE.get()); - } - } + UtilRemote.searchAndOpen(player, serverWorld); }); ctx.get().setPacketHandled(true); } diff --git a/src/main/java/com/lothrazar/storagenetwork/network/SettingsSyncMessage.java b/src/main/java/com/lothrazar/storagenetwork/network/SettingsSyncMessage.java index d921381b..96e6018d 100644 --- a/src/main/java/com/lothrazar/storagenetwork/network/SettingsSyncMessage.java +++ b/src/main/java/com/lothrazar/storagenetwork/network/SettingsSyncMessage.java @@ -5,7 +5,7 @@ import com.lothrazar.storagenetwork.api.ITileNetworkSync; import com.lothrazar.storagenetwork.item.remote.ContainerNetworkCraftingRemote; import com.lothrazar.storagenetwork.item.remote.ContainerNetworkRemote; -import com.lothrazar.storagenetwork.item.remote.ItemStorageCraftingRemote; +import com.lothrazar.storagenetwork.item.remote.ItemRemote; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; @@ -49,20 +49,20 @@ public static void handle(SettingsSyncMessage message, Supplier STOCK_UPGRADE = ITEMS.register("stock_upgrade", () -> new ItemUpgrade(new Item.Properties())); public static final RegistryObject OP_U = ITEMS.register("operation_upgrade", () -> new ItemUpgrade(new Item.Properties())); public static final RegistryObject SINGLE_UPGRADE = ITEMS.register("single_upgrade", () -> new ItemUpgrade(new Item.Properties())); - public static final RegistryObject INVENTORY_REMOTE = ITEMS.register("inventory_remote", () -> new ItemStorageCraftingRemote(new Item.Properties())); - public static final RegistryObject CRAFTING_REMOTE = ITEMS.register("crafting_remote", () -> new ItemStorageCraftingRemote(new Item.Properties())); + public static final RegistryObject INVENTORY_REMOTE = ITEMS.register("inventory_remote", () -> new ItemRemote(new Item.Properties())); + public static final RegistryObject CRAFTING_REMOTE = ITEMS.register("crafting_remote", () -> new ItemRemote(new Item.Properties())); public static final RegistryObject PICKER_REMOTE = ITEMS.register("picker_remote", () -> new ItemPicker(new Item.Properties())); public static final RegistryObject COLLECTOR_REMOTE = ITEMS.register("collector_remote", () -> new ItemCollector(new Item.Properties())); public static final RegistryObject BUILDER_REMOTE = ITEMS.register("builder_remote", () -> new ItemBuilder(new Item.Properties())); - public static final RegistryObject EXPANDED_REMOTE = ITEMS.register("expanded_remote", () -> new ItemStorageCraftingRemote(new Item.Properties())); + public static final RegistryObject EXPANDED_REMOTE = ITEMS.register("expanded_remote", () -> new ItemRemote(new Item.Properties())); } @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) diff --git a/src/main/java/com/lothrazar/storagenetwork/util/UtilRemote.java b/src/main/java/com/lothrazar/storagenetwork/util/UtilRemote.java new file mode 100644 index 00000000..7716e723 --- /dev/null +++ b/src/main/java/com/lothrazar/storagenetwork/util/UtilRemote.java @@ -0,0 +1,97 @@ +package com.lothrazar.storagenetwork.util; + +import org.apache.commons.lang3.tuple.Triple; +import com.lothrazar.storagenetwork.StorageNetworkMod; +import com.lothrazar.storagenetwork.api.DimPos; +import com.lothrazar.storagenetwork.block.main.TileMain; +import com.lothrazar.storagenetwork.registry.ConfigRegistry; +import com.lothrazar.storagenetwork.registry.SsnRegistry; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.network.NetworkHooks; + +public class UtilRemote { + + public static void searchAndOpen(ServerPlayer player, ServerLevel serverWorld) { + //TODO: search for data tag? or for a list? + Triple searchResult = UtilInventory.getCurioRemote(player, SsnRegistry.Items.CRAFTING_REMOTE.get()); + ItemStack curioRemote = searchResult.getRight(); + if (!curioRemote.isEmpty()) { + UtilRemote.openRemote(serverWorld, player, curioRemote, SsnRegistry.Items.CRAFTING_REMOTE.get()); + } + else { //crafting is the upgrade, so otherwise do regular + searchResult = UtilInventory.getCurioRemote(player, SsnRegistry.Items.INVENTORY_REMOTE.get()); + curioRemote = searchResult.getRight(); + if (!curioRemote.isEmpty()) { + UtilRemote.openRemote(serverWorld, player, curioRemote, SsnRegistry.Items.INVENTORY_REMOTE.get()); + } + else { + //TODO: refactor this to be much smarter this nested stuff is terrible + searchResult = UtilInventory.getCurioRemote(player, SsnRegistry.Items.EXPANDED_REMOTE.get()); + curioRemote = searchResult.getRight(); + if (!curioRemote.isEmpty()) { + UtilRemote.openRemote(serverWorld, player, curioRemote, SsnRegistry.Items.EXPANDED_REMOTE.get()); + } + } + } + } + + @SuppressWarnings("deprecation") + public static boolean openRemote(Level world, Player player, ItemStack itemStackIn, MenuProvider theRemoteItem) { + DimPos dp = DimPos.getPosStored(itemStackIn); + if (dp == null) { + //unbound or invalid data + UtilTileEntity.statusMessage(player, "item.remote.notconnected"); + return false; + } + //assume we are in the same world + BlockPos posTarget = dp.getBlockPos(); + if (ConfigRegistry.ITEMRANGE.get() != -1) { + double distance = player.distanceToSqr(posTarget.getX() + 0.5D, posTarget.getY() + 0.5D, posTarget.getZ() + 0.5D); + if (distance >= ConfigRegistry.ITEMRANGE.get()) { + UtilTileEntity.statusMessage(player, "item.remote.outofrange"); + return false; + } + } + //else it is -1 so dont even check distance + //k now server only + if (world.isClientSide) { + return false; + } + //now check the dimension world + ServerLevel serverTargetWorld = null; + try { + serverTargetWorld = DimPos.stringDimensionLookup(dp.getDimension(), world.getServer()); + if (serverTargetWorld == null) { + StorageNetworkMod.LOGGER.error("Missing dimension key " + dp.getDimension()); + } + } + catch (Exception e) { + // + StorageNetworkMod.LOGGER.error("unknown exception on dim " + dp.getDimension(), e); + return false; + } + //now check is the area chunk loaded + if (!serverTargetWorld.isAreaLoaded(posTarget, 1)) { + UtilTileEntity.chatMessage(player, "item.remote.notloaded"); + StorageNetworkMod.LOGGER.info(UtilTileEntity.lang("item.remote.notloaded") + posTarget); + return false; + } + BlockEntity tile = serverTargetWorld.getBlockEntity(posTarget); + if (tile instanceof TileMain) { + NetworkHooks.openScreen((ServerPlayer) player, theRemoteItem); + return true; + } + else { + player.displayClientMessage(Component.translatable("item.remote.notfound"), true); + return false; + } + } +} diff --git a/src/main/resources/data/curios/tags/items/charm.json b/src/main/resources/data/curios/tags/items/charm.json index 4b748946..a49dbe37 100644 --- a/src/main/resources/data/curios/tags/items/charm.json +++ b/src/main/resources/data/curios/tags/items/charm.json @@ -1,6 +1,7 @@ { "replace": "false", "values": [ + "storagenetwork:expanded_remote", "storagenetwork:inventory_remote", "storagenetwork:crafting_remote", "storagenetwork:collector_remote" diff --git a/update.json b/update.json index 25bcd2ab..a181ddfc 100644 --- a/update.json +++ b/update.json @@ -12,6 +12,6 @@ ,"1.11.2":"Ported the Cable Facades feature (from Minecraft 1.12.2), so that you can shift-left-click with a block on a cable to hide it with a facade. Disable this feature or ignore certain blocks with the config file" ,"1.11.3":"Fixed item tooltips not rendering in Storage Remote. Fixed visual rendering and text errors inside of import/export cables using the 'operation upgrade'" - ,"1.12.0":"Added new blocks to support large monitors and large GUI Scale resolutions, the Expanded Request Table and the Expanded Remote. Import and Export cable changes: main transactions are now executed inside the cable capabilities, meaning the main root node is doing less central work so overall the network has less wasted cycles." + ,"1.12.0":"Added a new Expanded Request Table and the Expanded Remote to support GUI Scale 2 or larger for players on large monitors/resolutions. Internal refactoring for Import and Export cable capabilities: item transactions are now executed inside the cable tile-entities instead of the main node tile-entity (meaning the main root node is doing less processing work, and also the network overall should have fewer wasted cycles). " } }