From 1951169f7bfc508b85d4d0cbceb6d7094782dc09 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 30 Oct 2022 13:12:25 +0100 Subject: [PATCH 01/11] Bump to v1.11.2. --- CHANGELOG.md | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d40c8ec424..66ab73106b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [v1.11.1] - 2022-10-30 + ### Fixed - Fixed not using Forge silicon tag for recipes. diff --git a/build.gradle b/build.gradle index d1b060627d..9909073a04 100755 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ apply plugin: 'maven-publish' group = 'com.refinedmods' archivesBaseName = 'refinedstorage' -version = '1.11.1' +version = '1.11.2' if (System.getenv('GITHUB_SHA') != null) { version += '+' + System.getenv('GITHUB_SHA').substring(0, 7) From b8fa8d3d103117245bbf3b644f352fd24bd82af9 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 15:10:37 +0100 Subject: [PATCH 02/11] Remove RS silicon tag. Cleanup for d0e66a34a6518d27497b4f1ba5859359d134b9c3 --- .../resources/data/refinedstorage/tags/items/silicon.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/main/resources/data/refinedstorage/tags/items/silicon.json diff --git a/src/main/resources/data/refinedstorage/tags/items/silicon.json b/src/main/resources/data/refinedstorage/tags/items/silicon.json deleted file mode 100644 index 2daf5b841f..0000000000 --- a/src/main/resources/data/refinedstorage/tags/items/silicon.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "replace": false, - "values": [ - "refinedstorage:silicon" - ] -} \ No newline at end of file From 25ca9eda14fd3e252732755f4551f74a164a86a4 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 15:44:02 +0100 Subject: [PATCH 03/11] Start using ForgeCapabilities. --- .../network/grid/handler/FluidGridHandler.java | 3 ++- .../network/grid/handler/ItemGridHandler.java | 3 ++- .../grid/handler/PortableFluidGridHandler.java | 4 ++-- .../grid/handler/PortableItemGridHandler.java | 3 ++- .../item/WirelessCraftingMonitorNetworkItem.java | 5 +++-- .../item/WirelessFluidGridNetworkItem.java | 5 +++-- .../network/item/WirelessGridNetworkItem.java | 6 +++--- .../network/node/StorageMonitorNetworkNode.java | 6 +++--- .../refinedstorage/block/ControllerBlock.java | 6 +++--- .../blockentity/ControllerBlockEntity.java | 4 ++-- .../blockentity/CrafterBlockEntity.java | 4 ++-- .../blockentity/DiskDriveBlockEntity.java | 4 ++-- .../blockentity/DiskManipulatorBlockEntity.java | 4 ++-- .../blockentity/FluidInterfaceBlockEntity.java | 7 +++---- .../blockentity/InterfaceBlockEntity.java | 3 ++- .../NetworkTransmitterBlockEntity.java | 3 ++- .../blockentity/grid/GridBlockEntity.java | 3 ++- .../blockentity/grid/portable/PortableGrid.java | 15 +++++++-------- .../grid/portable/PortableGridBlockEntity.java | 8 ++++---- .../refinedstorage/item/EnergyItem.java | 9 ++++----- .../item/blockitem/EnergyBlockItem.java | 9 ++++----- .../EnergyCapabilityProvider.java | 4 ++-- .../property/ControllerItemPropertyGetter.java | 4 ++-- .../loottable/ControllerLootFunction.java | 4 ++-- .../refinedstorage/util/LevelUtils.java | 7 +++---- .../refinedstorage/util/StackUtils.java | 4 ++-- 26 files changed, 70 insertions(+), 67 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/FluidGridHandler.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/FluidGridHandler.java index 01a08b6b86..b079e85e71 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/FluidGridHandler.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/FluidGridHandler.java @@ -15,6 +15,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Containers; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; @@ -40,7 +41,7 @@ public void onExtract(ServerPlayer player, UUID id, boolean shift) { return; } - NetworkUtils.extractBucketFromPlayerInventoryOrNetwork(player, network, bucket -> bucket.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).ifPresent(fluidHandler -> { + NetworkUtils.extractBucketFromPlayerInventoryOrNetwork(player, network, bucket -> bucket.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM, null).ifPresent(fluidHandler -> { network.getFluidStorageTracker().changed(player, stack.copy()); FluidStack extracted = network.extractFluid(stack, FluidType.BUCKET_VOLUME, Action.PERFORM); diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/ItemGridHandler.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/ItemGridHandler.java index e4d986d559..9a7fbacc68 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/ItemGridHandler.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/ItemGridHandler.java @@ -19,6 +19,7 @@ import net.minecraft.core.Direction; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; @@ -174,7 +175,7 @@ public void onExtract(ServerPlayer player, UUID id, int preferredSlot, int flags if (!took.isEmpty()) { if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) { - Optional playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).resolve(); + Optional playerInventory = player.getCapability(ForgeCapabilities.ITEM_HANDLER, Direction.UP).resolve(); if (playerInventory.isPresent()) { if (preferredSlot != -1) { ItemStack remainder = playerInventory.get().insertItem(preferredSlot, took, true); diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/PortableFluidGridHandler.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/PortableFluidGridHandler.java index fec61b53c0..4bf9483170 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/PortableFluidGridHandler.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/PortableFluidGridHandler.java @@ -10,9 +10,9 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Containers; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; import org.apache.commons.lang3.tuple.Pair; @@ -53,7 +53,7 @@ public void onExtract(ServerPlayer player, UUID id, boolean shift) { } if (!bucket.isEmpty()) { - bucket.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).ifPresent(fluidHandler -> { + bucket.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM, null).ifPresent(fluidHandler -> { portableGrid.getFluidStorageTracker().changed(player, stack.copy()); fluidHandler.fill(portableGrid.getFluidStorage().extract(stack, FluidType.BUCKET_VOLUME, IComparer.COMPARE_NBT, Action.PERFORM), IFluidHandler.FluidAction.EXECUTE); diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/PortableItemGridHandler.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/PortableItemGridHandler.java index a6c6d5f1eb..9050346b11 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/PortableItemGridHandler.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/grid/handler/PortableItemGridHandler.java @@ -10,6 +10,7 @@ import net.minecraft.core.Direction; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; @@ -93,7 +94,7 @@ public void onExtract(ServerPlayer player, UUID id, int preferredSlot, int flags if (!took.isEmpty()) { if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) { - IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null); + IItemHandler playerInventory = player.getCapability(ForgeCapabilities.ITEM_HANDLER, Direction.UP).orElse(null); if (playerInventory != null) { if (preferredSlot != -1) { ItemStack remainder = playerInventory.insertItem(preferredSlot, took, true); diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessCraftingMonitorNetworkItem.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessCraftingMonitorNetworkItem.java index e895d36bf0..619bd08b61 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessCraftingMonitorNetworkItem.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessCraftingMonitorNetworkItem.java @@ -15,6 +15,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.network.NetworkHooks; @@ -39,7 +40,7 @@ public Player getPlayer() { @Override public boolean onOpen(INetwork network) { - IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); + IEnergyStorage energy = stack.getCapability(ForgeCapabilities.ENERGY, null).orElse(null); if (RS.SERVER_CONFIG.getWirelessCraftingMonitor().getUseEnergy() && ((WirelessCraftingMonitorItem) stack.getItem()).getType() != WirelessCraftingMonitorItem.Type.CREATIVE && @@ -73,7 +74,7 @@ public boolean onOpen(INetwork network) { @Override public void drainEnergy(int energy) { if (RS.SERVER_CONFIG.getWirelessCraftingMonitor().getUseEnergy() && ((WirelessCraftingMonitorItem) stack.getItem()).getType() != WirelessCraftingMonitorItem.Type.CREATIVE) { - stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(energyStorage -> { + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(energyStorage -> { energyStorage.extractEnergy(energy, false); if (energyStorage.getEnergyStored() <= 0) { diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessFluidGridNetworkItem.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessFluidGridNetworkItem.java index d9b9bcc8b6..4589b56749 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessFluidGridNetworkItem.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessFluidGridNetworkItem.java @@ -14,6 +14,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; @@ -37,7 +38,7 @@ public Player getPlayer() { @Override public boolean onOpen(INetwork network) { - IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); + IEnergyStorage energy = stack.getCapability(ForgeCapabilities.ENERGY, null).orElse(null); if (RS.SERVER_CONFIG.getWirelessFluidGrid().getUseEnergy() && ((WirelessFluidGridItem) stack.getItem()).getType() != WirelessFluidGridItem.Type.CREATIVE && @@ -64,7 +65,7 @@ public boolean onOpen(INetwork network) { @Override public void drainEnergy(int energy) { if (RS.SERVER_CONFIG.getWirelessFluidGrid().getUseEnergy() && ((WirelessFluidGridItem) stack.getItem()).getType() != WirelessFluidGridItem.Type.CREATIVE) { - stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(energyStorage -> { + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(energyStorage -> { energyStorage.extractEnergy(energy, false); if (energyStorage.getEnergyStored() <= 0) { diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessGridNetworkItem.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessGridNetworkItem.java index 7a2af45cc2..0bd63f85bd 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessGridNetworkItem.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/item/WirelessGridNetworkItem.java @@ -14,7 +14,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.energy.IEnergyStorage; public class WirelessGridNetworkItem implements INetworkItem { @@ -37,7 +37,7 @@ public Player getPlayer() { @Override public boolean onOpen(INetwork network) { - IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); + IEnergyStorage energy = stack.getCapability(ForgeCapabilities.ENERGY, null).orElse(null); if (RS.SERVER_CONFIG.getWirelessGrid().getUseEnergy() && ((WirelessGridItem) stack.getItem()).getType() != WirelessGridItem.Type.CREATIVE && @@ -64,7 +64,7 @@ public boolean onOpen(INetwork network) { @Override public void drainEnergy(int energy) { if (RS.SERVER_CONFIG.getWirelessGrid().getUseEnergy() && ((WirelessGridItem) stack.getItem()).getType() != WirelessGridItem.Type.CREATIVE) { - stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(energyStorage -> { + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(energyStorage -> { energyStorage.extractEnergy(energy, false); if (energyStorage.getEnergyStored() <= 0) { diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/StorageMonitorNetworkNode.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/StorageMonitorNetworkNode.java index bf8a87843e..57d9a7c2f9 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/StorageMonitorNetworkNode.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/StorageMonitorNetworkNode.java @@ -24,9 +24,9 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.capability.IFluidHandler; import org.apache.commons.lang3.tuple.Pair; @@ -218,7 +218,7 @@ private void extractFluids(Player player) { boolean shift = player.isCrouching(); if (shift) { - NetworkUtils.extractBucketFromPlayerInventoryOrNetwork(player, network, bucket -> bucket.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).ifPresent(fluidHandler -> { + NetworkUtils.extractBucketFromPlayerInventoryOrNetwork(player, network, bucket -> bucket.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM, null).ifPresent(fluidHandler -> { network.getFluidStorageTracker().changed(player, stack.copy()); fluidHandler.fill(network.extractFluid(stack, FluidType.BUCKET_VOLUME, Action.PERFORM), IFluidHandler.FluidAction.EXECUTE); diff --git a/src/main/java/com/refinedmods/refinedstorage/block/ControllerBlock.java b/src/main/java/com/refinedmods/refinedstorage/block/ControllerBlock.java index ea45c615b1..9d2bbf6062 100644 --- a/src/main/java/com/refinedmods/refinedstorage/block/ControllerBlock.java +++ b/src/main/java/com/refinedmods/refinedstorage/block/ControllerBlock.java @@ -32,7 +32,7 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.network.NetworkHooks; import javax.annotation.Nullable; @@ -64,11 +64,11 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L super.setPlacedBy(level, pos, state, entity, stack); if (!level.isClientSide) { - stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(energyFromStack -> { + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(energyFromStack -> { BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity != null) { - blockEntity.getCapability(CapabilityEnergy.ENERGY).ifPresent(energyFromBlockEntity -> energyFromBlockEntity.receiveEnergy(energyFromStack.getEnergyStored(), false)); + blockEntity.getCapability(ForgeCapabilities.ENERGY).ifPresent(energyFromBlockEntity -> energyFromBlockEntity.receiveEnergy(energyFromStack.getEnergyStored(), false)); } }); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/ControllerBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/ControllerBlockEntity.java index fa8ca31b1c..f6c4f7ca2b 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/ControllerBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/ControllerBlockEntity.java @@ -22,8 +22,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import javax.annotation.Nonnull; @@ -158,7 +158,7 @@ public void setRedstoneMode(RedstoneMode mode) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityEnergy.ENERGY) { + if (cap == ForgeCapabilities.ENERGY) { return energyProxyCap.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/CrafterBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/CrafterBlockEntity.java index 0835aaa2e8..325110b34e 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/CrafterBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/CrafterBlockEntity.java @@ -11,8 +11,8 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; @@ -43,7 +43,7 @@ public CrafterNetworkNode createNode(Level level, BlockPos pos) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && direction != null && !direction.equals(this.getNode().getDirection())) { + if (cap == ForgeCapabilities.ITEM_HANDLER && direction != null && !direction.equals(this.getNode().getDirection())) { return patternsCapability.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/DiskDriveBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/DiskDriveBlockEntity.java index 7b5fbe9cf2..8fcddcd026 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/DiskDriveBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/DiskDriveBlockEntity.java @@ -21,8 +21,8 @@ import net.minecraftforge.client.model.data.ModelData; import net.minecraftforge.client.model.data.ModelProperty; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; @@ -140,7 +140,7 @@ public ModelData getModelData() { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (cap == ForgeCapabilities.ITEM_HANDLER) { return diskCapability.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/DiskManipulatorBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/DiskManipulatorBlockEntity.java index 67da6f9bef..61562493fa 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/DiskManipulatorBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/DiskManipulatorBlockEntity.java @@ -21,8 +21,8 @@ import net.minecraftforge.client.model.data.ModelData; import net.minecraftforge.client.model.data.ModelProperty; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; @@ -98,7 +98,7 @@ public ModelData getModelData() { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (cap == ForgeCapabilities.ITEM_HANDLER) { return diskCapability.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/FluidInterfaceBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/FluidInterfaceBlockEntity.java index 60ccd1d5db..f662ce5f8e 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/FluidInterfaceBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/FluidInterfaceBlockEntity.java @@ -10,11 +10,10 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; @@ -40,9 +39,9 @@ public FluidInterfaceBlockEntity(BlockPos pos, BlockState state) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (cap == ForgeCapabilities.ITEM_HANDLER) { return inCapability.cast(); - } else if (cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { + } else if (cap == ForgeCapabilities.FLUID_HANDLER) { return tankCapability.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/InterfaceBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/InterfaceBlockEntity.java index cab60b7373..8eb1d0f24e 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/InterfaceBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/InterfaceBlockEntity.java @@ -10,6 +10,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; @@ -34,7 +35,7 @@ public InterfaceBlockEntity(BlockPos pos, BlockState state) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (cap == ForgeCapabilities.ITEM_HANDLER) { return itemsCapability.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/NetworkTransmitterBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/NetworkTransmitterBlockEntity.java index 112c2bdb3d..df635bab07 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/NetworkTransmitterBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/NetworkTransmitterBlockEntity.java @@ -12,6 +12,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; @@ -51,7 +52,7 @@ public NetworkTransmitterNetworkNode createNode(Level level, BlockPos pos) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (cap == ForgeCapabilities.ITEM_HANDLER) { return networkCardCapability.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/GridBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/GridBlockEntity.java index c5978ca609..78c5a01b2a 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/GridBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/GridBlockEntity.java @@ -19,6 +19,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; @@ -131,7 +132,7 @@ public GridNetworkNode createNode(Level level, BlockPos pos) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && type == GridType.PATTERN) { + if (cap == ForgeCapabilities.ITEM_HANDLER && type == GridType.PATTERN) { return diskCapability.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/portable/PortableGrid.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/portable/PortableGrid.java index ac15d5c964..88be0c2686 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/portable/PortableGrid.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/portable/PortableGrid.java @@ -42,14 +42,13 @@ import com.refinedmods.refinedstorage.util.StackUtils; 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.entity.player.Player; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.inventory.ResultContainer; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.items.IItemHandlerModifiable; @@ -132,7 +131,9 @@ public PortableGrid(@Nullable Player player, ItemStack stack, PlayerSlot slot) { public void onOpen() { drainEnergy(RS.SERVER_CONFIG.getPortableGrid().getOpenUsage()); - } private final BaseItemHandler disk = new BaseItemHandler(1) + } + + private final BaseItemHandler disk = new BaseItemHandler(1) .addValidator(new StorageDiskItemValidator()) .addListener(((handler, slot, reading) -> { if (player != null && !player.level.isClientSide) { @@ -189,7 +190,7 @@ public IStorageDisk getStorage() { @Override public void drainEnergy(int energy) { if (RS.SERVER_CONFIG.getPortableGrid().getUseEnergy() && ((PortableGridBlockItem) stack.getItem()).getType() != PortableGridBlockItem.Type.CREATIVE) { - stack.getCapability(CapabilityEnergy.ENERGY, null) + stack.getCapability(ForgeCapabilities.ENERGY, null) .ifPresent(energyStorage -> energyStorage.extractEnergy(energy, false)); } } @@ -197,7 +198,7 @@ public void drainEnergy(int energy) { @Override public int getEnergy() { if (RS.SERVER_CONFIG.getPortableGrid().getUseEnergy() && ((PortableGridBlockItem) stack.getItem()).getType() != PortableGridBlockItem.Type.CREATIVE) { - return stack.getCapability(CapabilityEnergy.ENERGY, null) + return stack.getCapability(ForgeCapabilities.ENERGY, null) .map(IEnergyStorage::getEnergyStored) .orElse(RS.SERVER_CONFIG.getPortableGrid().getCapacity()); } @@ -449,7 +450,7 @@ private boolean hasDisk() { public boolean isGridActive() { if (RS.SERVER_CONFIG.getPortableGrid().getUseEnergy() && ((PortableGridBlockItem) stack.getItem()).getType() != PortableGridBlockItem.Type.CREATIVE && - stack.getCapability(CapabilityEnergy.ENERGY).orElse(null).getEnergyStored() <= RS.SERVER_CONFIG.getPortableGrid().getOpenUsage()) { + stack.getCapability(ForgeCapabilities.ENERGY).orElse(null).getEnergyStored() <= RS.SERVER_CONFIG.getPortableGrid().getOpenUsage()) { return false; } @@ -510,6 +511,4 @@ public AccessType getAccessType() { } - - } diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/portable/PortableGridBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/portable/PortableGridBlockEntity.java index 028bedfdcb..2fb1e54e6e 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/portable/PortableGridBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/grid/portable/PortableGridBlockEntity.java @@ -65,8 +65,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.EnergyStorage; import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fluids.FluidStack; @@ -244,7 +244,7 @@ public void applyDataFromItemToBlockEntity(ItemStack stack) { this.tabPage = WirelessGridItem.getTabPage(stack); this.size = WirelessGridItem.getSize(stack); - this.energyStorage = createEnergyStorage(stack.getCapability(CapabilityEnergy.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0)); + this.energyStorage = createEnergyStorage(stack.getCapability(ForgeCapabilities.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0)); if (stack.hasTag()) { for (int i = 0; i < 4; ++i) { @@ -291,7 +291,7 @@ public void applyDataFromBlockEntityToItem(ItemStack stack) { stack.getTag().put(NBT_ENCHANTMENTS, enchants); } - stack.getCapability(CapabilityEnergy.ENERGY, null).ifPresent(itemEnergy -> itemEnergy.receiveEnergy(energyStorage.getEnergyStored(), false)); + stack.getCapability(ForgeCapabilities.ENERGY, null).ifPresent(itemEnergy -> itemEnergy.receiveEnergy(energyStorage.getEnergyStored(), false)); for (int i = 0; i < 4; ++i) { StackUtils.writeItems(filter, i, stack.getTag()); @@ -748,7 +748,7 @@ public void readUpdate(CompoundTag tag) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction direction) { - if (cap == CapabilityEnergy.ENERGY) { + if (cap == ForgeCapabilities.ENERGY) { return energyStorageCap.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/item/EnergyItem.java b/src/main/java/com/refinedmods/refinedstorage/item/EnergyItem.java index c8e2676b7f..152e3d7c7c 100644 --- a/src/main/java/com/refinedmods/refinedstorage/item/EnergyItem.java +++ b/src/main/java/com/refinedmods/refinedstorage/item/EnergyItem.java @@ -4,14 +4,13 @@ import com.refinedmods.refinedstorage.render.Styles; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; - import net.minecraft.util.Mth; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import javax.annotation.Nullable; @@ -41,7 +40,7 @@ public boolean isBarVisible(ItemStack stack) { @Override public int getBarWidth(ItemStack stack) { - IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY).orElse(null); + IEnergyStorage energy = stack.getCapability(ForgeCapabilities.ENERGY).orElse(null); if (energy == null) { return 0; } @@ -51,7 +50,7 @@ public int getBarWidth(ItemStack stack) { @Override public int getBarColor(ItemStack stack) { - IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); + IEnergyStorage energy = stack.getCapability(ForgeCapabilities.ENERGY, null).orElse(null); if (energy == null) { return super.getBarColor(stack); } @@ -63,7 +62,7 @@ public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip.add(Component.translatable("misc.refinedstorage.energy_stored", energy.getEnergyStored(), energy.getMaxEnergyStored()).setStyle(Styles.GRAY))); } } diff --git a/src/main/java/com/refinedmods/refinedstorage/item/blockitem/EnergyBlockItem.java b/src/main/java/com/refinedmods/refinedstorage/item/blockitem/EnergyBlockItem.java index 9153e8f12b..e6219fd75f 100644 --- a/src/main/java/com/refinedmods/refinedstorage/item/blockitem/EnergyBlockItem.java +++ b/src/main/java/com/refinedmods/refinedstorage/item/blockitem/EnergyBlockItem.java @@ -5,14 +5,13 @@ import com.refinedmods.refinedstorage.render.Styles; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; - import net.minecraft.util.Mth; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import javax.annotation.Nullable; @@ -42,7 +41,7 @@ public boolean isBarVisible(ItemStack stack) { @Override public int getBarWidth(ItemStack stack) { - IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY).orElse(null); + IEnergyStorage energy = stack.getCapability(ForgeCapabilities.ENERGY).orElse(null); if (energy == null) { return 0; } @@ -52,7 +51,7 @@ public int getBarWidth(ItemStack stack) { @Override public int getBarColor(ItemStack stack) { - IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); + IEnergyStorage energy = stack.getCapability(ForgeCapabilities.ENERGY, null).orElse(null); if (energy == null) { return super.getBarColor(stack); } @@ -64,7 +63,7 @@ public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip.add(Component.translatable("misc.refinedstorage.energy_stored", energy.getEnergyStored(), energy.getMaxEnergyStored()).setStyle(Styles.GRAY))); + stack.getCapability(ForgeCapabilities.ENERGY, null).ifPresent(energy -> tooltip.add(Component.translatable("misc.refinedstorage.energy_stored", energy.getEnergyStored(), energy.getMaxEnergyStored()).setStyle(Styles.GRAY))); } } } diff --git a/src/main/java/com/refinedmods/refinedstorage/item/capabilityprovider/EnergyCapabilityProvider.java b/src/main/java/com/refinedmods/refinedstorage/item/capabilityprovider/EnergyCapabilityProvider.java index ed42531249..04bf87041b 100644 --- a/src/main/java/com/refinedmods/refinedstorage/item/capabilityprovider/EnergyCapabilityProvider.java +++ b/src/main/java/com/refinedmods/refinedstorage/item/capabilityprovider/EnergyCapabilityProvider.java @@ -4,9 +4,9 @@ import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import javax.annotation.Nonnull; @@ -22,7 +22,7 @@ public EnergyCapabilityProvider(ItemStack stack, int energyCapacity) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction dire) { - if (cap == CapabilityEnergy.ENERGY) { + if (cap == ForgeCapabilities.ENERGY) { return capability.cast(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/item/property/ControllerItemPropertyGetter.java b/src/main/java/com/refinedmods/refinedstorage/item/property/ControllerItemPropertyGetter.java index 46fce94f38..205ec1c433 100644 --- a/src/main/java/com/refinedmods/refinedstorage/item/property/ControllerItemPropertyGetter.java +++ b/src/main/java/com/refinedmods/refinedstorage/item/property/ControllerItemPropertyGetter.java @@ -6,7 +6,7 @@ import net.minecraft.client.renderer.item.ItemPropertyFunction; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.energy.IEnergyStorage; import javax.annotation.Nullable; @@ -14,7 +14,7 @@ public class ControllerItemPropertyGetter implements ItemPropertyFunction { @Override public float call(ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, int p) { - IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY).orElse(null); + IEnergyStorage storage = stack.getCapability(ForgeCapabilities.ENERGY).orElse(null); if (storage != null) { return Network.getEnergyType(storage.getEnergyStored(), storage.getMaxEnergyStored()).ordinal(); } diff --git a/src/main/java/com/refinedmods/refinedstorage/loottable/ControllerLootFunction.java b/src/main/java/com/refinedmods/refinedstorage/loottable/ControllerLootFunction.java index c4b62c13ab..e1a2b14874 100644 --- a/src/main/java/com/refinedmods/refinedstorage/loottable/ControllerLootFunction.java +++ b/src/main/java/com/refinedmods/refinedstorage/loottable/ControllerLootFunction.java @@ -12,7 +12,7 @@ import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; -import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.common.capabilities.ForgeCapabilities; public class ControllerLootFunction extends LootItemConditionalFunction { protected ControllerLootFunction(LootItemCondition[] conditions) { @@ -30,7 +30,7 @@ protected ItemStack run(ItemStack itemStack, LootContext lootContext) { if (blockEntity instanceof ControllerBlockEntity) { INetwork network = ((ControllerBlockEntity) blockEntity).getRemovedNetwork() == null ? ((ControllerBlockEntity) blockEntity).getNetwork() : ((ControllerBlockEntity) blockEntity).getRemovedNetwork(); - itemStack.getCapability(CapabilityEnergy.ENERGY).ifPresent(energy -> energy.receiveEnergy(network.getEnergyStorage().getEnergyStored(), false)); + itemStack.getCapability(ForgeCapabilities.ENERGY).ifPresent(energy -> energy.receiveEnergy(network.getEnergyStorage().getEnergyStored(), false)); } return itemStack; diff --git a/src/main/java/com/refinedmods/refinedstorage/util/LevelUtils.java b/src/main/java/com/refinedmods/refinedstorage/util/LevelUtils.java index 950bc27123..f6ee3adb3f 100644 --- a/src/main/java/com/refinedmods/refinedstorage/util/LevelUtils.java +++ b/src/main/java/com/refinedmods/refinedstorage/util/LevelUtils.java @@ -17,11 +17,10 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.ForgeMod; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayerFactory; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.wrapper.InvWrapper; import net.minecraftforge.items.wrapper.SidedInvWrapper; @@ -47,7 +46,7 @@ public static IItemHandler getItemHandler(@Nullable BlockEntity blockEntity, Dir return null; } - IItemHandler handler = blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side).orElse(null); + IItemHandler handler = blockEntity.getCapability(ForgeCapabilities.ITEM_HANDLER, side).orElse(null); if (handler == null) { if (side != null && blockEntity instanceof WorldlyContainer) { handler = new SidedInvWrapper((WorldlyContainer) blockEntity, side); @@ -61,7 +60,7 @@ public static IItemHandler getItemHandler(@Nullable BlockEntity blockEntity, Dir public static IFluidHandler getFluidHandler(@Nullable BlockEntity blockEntity, Direction side) { if (blockEntity != null) { - return blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side).orElse(null); + return blockEntity.getCapability(ForgeCapabilities.FLUID_HANDLER, side).orElse(null); } return null; diff --git a/src/main/java/com/refinedmods/refinedstorage/util/StackUtils.java b/src/main/java/com/refinedmods/refinedstorage/util/StackUtils.java index 0551c5c751..a9be05da7b 100644 --- a/src/main/java/com/refinedmods/refinedstorage/util/StackUtils.java +++ b/src/main/java/com/refinedmods/refinedstorage/util/StackUtils.java @@ -18,9 +18,9 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandlerItem; import net.minecraftforge.items.IItemHandler; @@ -296,7 +296,7 @@ public static Pair getFluid(ItemStack stack, boolean simu stack = ItemHandlerHelper.copyStackWithSize(stack, 1); } - IFluidHandlerItem handler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).orElse(null); + IFluidHandlerItem handler = stack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM, null).orElse(null); if (handler != null) { FluidStack result = handler.drain(FluidType.BUCKET_VOLUME, simulate ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE); From 93ac94c251d0d512920defb8ba06b640db3e62ae Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 16:01:03 +0100 Subject: [PATCH 04/11] Catch crash for network node desync. #3424 --- .../blockentity/NetworkNodeBlockEntity.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/NetworkNodeBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/NetworkNodeBlockEntity.java index d7629fb533..ec6f3ab353 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/NetworkNodeBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/NetworkNodeBlockEntity.java @@ -62,16 +62,26 @@ public N getNode() { INetworkNodeManager manager = API.instance().getNetworkNodeManager((ServerLevel) level); - INetworkNode node = manager.getNode(worldPosition); + try { + INetworkNode node = manager.getNode(worldPosition); - if (node == null) { - LOGGER.warn("Expected a node @ {} but couldn't find it, creating a new one...", worldPosition); - node = createNode(level, worldPosition); - manager.setNode(worldPosition, node); - manager.markForSaving(); + if (node == null) { + LOGGER.warn("Expected a node @ {} but couldn't find it, creating a new one...", worldPosition); + node = createAndSetNode(manager); + } + + return (N) node; + } catch (ClassCastException e) { + LOGGER.warn("Node @ {} got desynced with it's block entity container, recreating", worldPosition, e); + return (N) createAndSetNode(manager); } + } - return (N) node; + private INetworkNode createAndSetNode(INetworkNodeManager manager) { + INetworkNode node = createNode(level, worldPosition); + manager.setNode(worldPosition, node); + manager.markForSaving(); + return node; } @Override From 761b43999763436b1243a40f889a6c73e228a778 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 16:04:49 +0100 Subject: [PATCH 05/11] Catch crash for block state desync. #3424 Could be in some other places as well but let's see what this does. --- .../apiimpl/network/node/NetworkNode.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/NetworkNode.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/NetworkNode.java index 5de1057ffc..53f1e43af8 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/NetworkNode.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/NetworkNode.java @@ -18,13 +18,18 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraftforge.items.IItemHandler; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.UUID; public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor { + private static final Logger LOGGER = LogManager.getLogger(); + private static final String NBT_OWNER = "Owner"; private static final String NBT_VERSION = "Version"; private static final int CURRENT_VERSION = 1; @@ -256,8 +261,15 @@ public Direction getDirection() { if (direction == null) { BlockState state = level.getBlockState(pos); - if (state.getBlock() instanceof BaseBlock) { - direction = state.getValue(((BaseBlock) state.getBlock()).getDirection().getProperty()); + if (state.getBlock() instanceof BaseBlock baseBlock) { + DirectionProperty property = baseBlock.getDirection().getProperty(); + + if (state.hasProperty(property)) { + direction = state.getValue(property); + } else { + LOGGER.warn("Node @ {} has no direction! Consider recreating the block", pos); + return Direction.NORTH; + } } } From a0a64234329dedec70da77accbaef44d45c073a6 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 16:11:07 +0100 Subject: [PATCH 06/11] Catch crash for network desync. #3424 --- .../blockentity/ControllerBlockEntity.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/blockentity/ControllerBlockEntity.java b/src/main/java/com/refinedmods/refinedstorage/blockentity/ControllerBlockEntity.java index f6c4f7ca2b..f9c971286b 100644 --- a/src/main/java/com/refinedmods/refinedstorage/blockentity/ControllerBlockEntity.java +++ b/src/main/java/com/refinedmods/refinedstorage/blockentity/ControllerBlockEntity.java @@ -25,6 +25,8 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.energy.IEnergyStorage; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -32,6 +34,8 @@ import java.util.List; public class ControllerBlockEntity extends BaseBlockEntity implements INetworkNodeProxy, IRedstoneConfigurable { + private static final Logger LOGGER = LogManager.getLogger(); + public static final BlockEntitySynchronizationParameter REDSTONE_MODE = RedstoneMode.createParameter(); public static final BlockEntitySynchronizationParameter ENERGY_USAGE = new BlockEntitySynchronizationParameter<>(EntityDataSerializers.INT, 0, t -> t.getNetwork().getEnergyUsage()); public static final BlockEntitySynchronizationParameter ENERGY_STORED = new BlockEntitySynchronizationParameter<>(EntityDataSerializers.INT, 0, t -> t.getNetwork().getEnergyStorage().getEnergyStored()); @@ -94,10 +98,14 @@ public INetwork getNetwork() { return dummyNetwork; } - INetwork network = API.instance().getNetworkManager((ServerLevel) level).getNetwork(worldPosition); + INetworkManager manager = API.instance().getNetworkManager((ServerLevel) level); + INetwork network = manager.getNetwork(worldPosition); if (network == null) { - throw new IllegalStateException("No network present at " + worldPosition); + LOGGER.warn("Expected a network @ {} but couldn't find it, creating a new one...", worldPosition); + network = new Network(level, worldPosition, type); + manager.setNetwork(worldPosition, network); + manager.markForSaving(); } return network; From 5f8b445a780157017c58f1804ee66ffa08cab014 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 20:01:27 +0100 Subject: [PATCH 07/11] Fixed chained crafters not taking over the name of the root crafter. Fixes #3418 --- CHANGELOG.md | 4 ++++ .../autocrafting/ICraftingPatternContainer.java | 12 ++++++++++++ .../apiimpl/network/node/CrafterNetworkNode.java | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ab73106b..83298cd15f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed + +- Fixed chained crafters not taking over the name of the root crafter. + ## [v1.11.1] - 2022-10-30 ### Fixed diff --git a/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/ICraftingPatternContainer.java b/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/ICraftingPatternContainer.java index c1cc8e56ce..12759c578a 100644 --- a/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/ICraftingPatternContainer.java +++ b/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/ICraftingPatternContainer.java @@ -86,11 +86,23 @@ default int getMaximumSuccessfulCraftingUpdates() { /** * The name of this container for categorizing in the Crafting Manager GUI. + * Will return the name of the root container if we're in a chained scenario. * * @return the name of this container */ Component getName(); + /** + * The custom name of this container, as set in an anvil for example. + * Can be null. + * + * @return the name of this container + */ + @Nullable + default Component getCustomName() { + return null; + } + /** * @return the position of this container */ diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/CrafterNetworkNode.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/CrafterNetworkNode.java index d9f252ceba..847438b8d9 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/CrafterNetworkNode.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/CrafterNetworkNode.java @@ -297,10 +297,20 @@ public IItemHandlerModifiable getPatternInventory() { return patternsInventory; } + @Override + @Nullable + public Component getCustomName() { + return displayName; + } + @Override public Component getName() { - if (displayName != null) { - return displayName; + ICraftingPatternContainer root = getRootContainer(); + if (root != null) { + Component displayNameOfRoot = root.getCustomName(); + if (displayNameOfRoot != null) { + return displayNameOfRoot; + } } BlockEntity facing = getConnectedBlockEntity(); From 75ebe8ae5120f85a413cf89cedc4965e43602e61 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 20:15:06 +0100 Subject: [PATCH 08/11] Move 1.9.17 and 1.9.18 to new changelog format. --- CHANGELOG-old.md | 17 ----------------- CHANGELOG.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/CHANGELOG-old.md b/CHANGELOG-old.md index 90ede8402d..fdf7f2ca1e 100644 --- a/CHANGELOG-old.md +++ b/CHANGELOG-old.md @@ -1,22 +1,5 @@ # Refined Storage Changelog -### 1.9.18 - -- Fixed potential Pattern crash when loading Minecraft. - -### 1.9.17 -- Added more slots to the Pattern Grid (Darkere) -- Combined Fluid and Item View in the Pattern Grid (Darkere) -- Fixed Relay not working (Darkere) -- Fixed Wireless Transmitter only working upright (Darkere) -- Fixed Portable Grid not opening when pointing at a block (Darkere) -- Fixed being able to circumvent locked slots by scrolling (Darkere) -- Processing patterns now use the order of items/fluids specified in the pattern (Darkere, necauqua) -- Fixed multiple bugs related to transferring recipes into the crafting grid (Darkere) -- Fixed autocrafting task getting stuck if two tasks fulfilled each others requirements (Darkere) -- Fixed fluid autocrafting breaking when using 2 stacks of the same fluid in a pattern (Darkere) -- Amount specifying screen is now limited to valid values (Darkere) - ### 1.9.16 - Added Covers for all cable types! (Buuz135) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83298cd15f..2af2d7ff56 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,3 +112,31 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Ported to Minecraft 1.18.1. - Focused side buttons now display their tooltip properly. - Improved performance of retrieving patterns by [@metalshark](https://github.com/metalshark). + +## [v1.9.18] - 2022-05-18 + +### Fixed + +- Fixed potential Pattern crash when loading Minecraft. + +## [v1.9.17] - 2022-01-30 + +### Added + +- More slots for the Pattern Grid. + +### Changed + +- Combined fluid and item view in the Pattern Grid. +- Processing patterns now use the order of items/fluids specified in the pattern. +- Amount specifying screen is now limited to valid values. + +### Fixed + +- Fixed Relay not working. +- Fixed Wireless Transmitter only working upright. +- Fixed Portable Grid not opening when pointing at a block. +- Fixed being able to circumvent locked slots by scrolling. +- Fixed multiple bugs related to transferring recipes into the crafting grid. +- Fixed autocrafting task getting stuck if two tasks fulfilled each others requirements. +- Fixed fluid autocrafting breaking when using 2 stacks of the same fluid in a pattern. From c37dfc13a3e08b05a5fa4efb32eca2c78943cff5 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 20:47:25 +0100 Subject: [PATCH 09/11] Add keep a changelog format for entire 1.9.x series. --- CHANGELOG-old.md | 162 ------------------------------- CHANGELOG.md | 242 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+), 162 deletions(-) diff --git a/CHANGELOG-old.md b/CHANGELOG-old.md index fdf7f2ca1e..437b0afec7 100644 --- a/CHANGELOG-old.md +++ b/CHANGELOG-old.md @@ -1,167 +1,5 @@ # Refined Storage Changelog -### 1.9.16 - -- Added Covers for all cable types! (Buuz135) -- Improved JEI integration to pick the best option when transferring items (Darkere) -- Fixed an issue where too many items in a grid would kick the player (Darkere) -- Fixed an issue where the portable grid does not open from Inventory anymore after some use (Darkere) -- Fixed craftable view in grids not showing items that were already in storage (BlueAgent) -- Fixed Wireless Crafting Monitor not working as Curio (Darkere) -- Fixed wrong slot being locked in some cases when opening Wireless Item (Darkere) -- Slightly sped up External Storage item look up (necauqua) -- Fixed extraction from Storage Monitor not respecting maximum stack size (Darkere) -- Added Polish translation (joker876) -- Added Italian translation (maicol07) -- Addons can now override how Crafters insert items (Darkere) - -### 1.9.15 - -- Fixed Refined Storage Addons compatibility (Darkere) - -### 1.9.14 - -- Implemented Curios support (Darkere) - -### 1.9.13 - -- Fixed count on Storage Monitor having Z fighting (tivec) -- Fixed items on Storage Monitor not being flat (raoulvdberge) -- Removed experimental pipeline nagging message (raoulvdberge) -- Fixed crash when using an External Storage on a fluid inventory (jeremiahwinsley) -- Added some performance improvements for autocrafting (necauqua, Darkere) -- Fixed a memory leak in the pattern cache (necauqua) -- Fixed Detector crashing when dyed (Darkere) -- Fixed autocrafting being stuck after clicking "Start" (necauqua) -- Fixed Crafting Monitor not being able to show hours (Darkere) -- Fixed capacity rendering of infinite storages (Darkere) -- Fixed wrong alignment for the JEI request autocrafting tooltip (Darkere) -- Fixed mobs getting stuck in Refined Storage cables (Darkere) -- Fixed dismantling storage blocks ignoring stack size (Darkere) -- Fixed Ice and Fire banners breaking with Refined Storage (Darkere, necauqua) -- Fixed empty keybinding causing GL errors (Darkere) -- Fixed some parts of the Japanese translation (akihironagai) -- Fixed rendering issue on blocks when using OptiFine (ylou) - -### 1.9.12 - -- Fixed some issues when using the Grid when it's offline (Darkere) -- Fixed crafting events not being fired in some cases in the Grid (Darkere) -- Fixed not being able to set fluid filter slot output quantity (Darkere) -- Fixed mod id search not working for Industrial Foregoing (Darkere) -- Fixed fluid autocrafting duplicating fluids (Darkere) -- Fixed some Grid crashes (ScoreUnder) -- Fixed constructor not using compare mode correctly in some cases (ScoreUnder) -- Fixed duplication bug in the Interface (Darkere) - -### 1.9.11 - -- Fixed disks and network devices not loading when they did not previously exist - -If you are affected by this please go to the world/data/ folder and remove the ".temp" ending from the files before -launching. - -### 1.9.10 - -- Improve performance of the Grid view (ScoreUnder) -- Fixed Disk Manipulator model glitches (Darkere) -- Improve performance of the Disk Manipulator (Darkere) -- Fixed being unable to set quantity in output slots of the Pattern Grid (Darkere) -- Fixed External Storage in fluid mode losing track of fluids sometimes (Darkere) -- Added code to avoid / minimize data corruption issues caused by Minecraft (Darkere) -- Fixed processing autocrafting orders stealing items from each other (Darkere) -- Fixed Constructor in fluid mode voiding fluid source blocks in front of it (Darkere) -- Update Japanese translation (alyxferrari) -- Fixed crash when recoloring blocks that have no rotation component (Darkere) -- Fixed reloading resource packs breaking Refined Storage textures (Darkere) - -### 1.9.9 - -- Fixed Refined Storage sidebuttons displaying over the JEI bookmark pagination buttons (raoulvdberge) -- Fixed issue where Crafters may fail to recognize an inventory/tank for some patterns (Darkere) -- Fixed issue where the Crafter Manager can crash on invalid patterns (raoulvdberge) -- Fixed issue where alternatives in the Pattern Grid weren't being saved properly (raoulvdberge) -- Fixed not being able to change the Exporter filter slot count with regulator mode without closing and re-opening the - container (raoulvdberge) - -### 1.9.8 - -- Fixed server crash when scrolling in Grid (Darkere) -- Fixed various issues with Grid interactions working without power (Darkere) -- Fixed changing rotation not updating blocks (Darkere) -- Added a JEI synchronized (two-way) search box mode to the Grid (ScoreUnder) -- Added a nag message when a player joins the world that asks the player to enable the experimental Forge lighting - pipeline to ensure correct rendering (raoulvdberge) - -### 1.9.7 - -- Added functionality to move items in the Grid with shift/ctrl + scrolling (Darkere) -- Changed JEI transfer error mechanics (raoulvdberge) -- Fixed crash when opening Controller GUI (Darkere) -- Fixed dye being consumed without effect in some cases (Darkere) -- Fixed deadlock caused by Portable Grid (Darkere) -- Fixed custom tooltips not working in the Grid (Darkere) - -### 1.9.6 - -- Port to Minecraft 1.16.3 (raoulvdberge) -- Added colored block variants (Darkere) -- Added functionality to show missing items in the JEI transfer screen (Darkere) -- Added functionality to request missing items from autocrafting in the JEI transfer screen (Darkere) -- Added client config option to remember the Grid search query (raoulvdberge) -- Fixed Portable Grid losing enchantments when placing and breaking (raoulvdberge) - -### 1.9.5 - -- Re-added the `/refinedstorage disk create ` command (raoulvdberge) -- Added the `/refinedstorage disk list` command (raoulvdberge) -- Added the `/refinedstorage disk list ` command (raoulvdberge) -- Added the `/refinedstorage network list ` command (raoulvdberge) -- Added the `/refinedstorage network get ` command (raoulvdberge) -- Added the `/refinedstorage network get autocrafting list` command (raoulvdberge) -- Added the `/refinedstorage network get autocrafting get ` command (raoulvdberge) -- Added the `/refinedstorage network get autocrafting cancel` command (raoulvdberge) -- Added the `/refinedstorage network get autocrafting cancel ` command (raoulvdberge) -- Added JEI ghost ingredient dragging support (raoulvdberge) -- Fixed text field not being focused in amount specifying screens (raoulvdberge) - -### 1.9.4 - -- Fixed JEI recipes/usages keys not working in Grids (raoulvdberge) - -### 1.9.3 - -- Port to Minecraft 1.16.2 (raoulvdberge) -- Fixed duplication bug with the Constructor (Darkere) -- Updated Japanese translation (a2y4) -- Updated Taiwanese translation (ForFunPenguin) -- Refactored autocrafting code (raoulvdberge) - -### 1.9.2b - -Fixed duplication bug with the Constructor (Darkere, raoulvdberge) - -### 1.9.2 - -- Fixed crash with Forge version 67 (Darkere) -- Fixed cases where Refined Storage unwillingly acts like a chunkloader (raoulvdberge) -- Fixed Network Transmitters being able to connect to any network device (raoulvdberge) -- Fixed Crafting Tweaks buttons being in the wrong position after changing the size configuration of the Grid ( - raoulvdberge) -- Networks that are in a chunk that isn't loaded will no longer work, they will turn off. Chunkload the Controller to - maintain a functioning network over long distances (Darkere/raoulvdberge) -- Re-added interdimensional networks with the Network Transmitter and Network Receiver (raoulvdberge) -- Re-added MouseTweaks integration (raoulvdberge) - -### 1.9.1 - -- Fixed server crash (raoulvdberge) - -### 1.9 - -- Port to Minecraft 1.16 (raoulvdberge) -- Fixed wrench requiring shift click to rotate blocks (raoulvdberge) - ### 1.8.8 - Fixed duplication bug and weird behavior in the Crafting Grid matrix (Darkere) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af2d7ff56..2de82eaf03 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,3 +140,245 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Fixed multiple bugs related to transferring recipes into the crafting grid. - Fixed autocrafting task getting stuck if two tasks fulfilled each others requirements. - Fixed fluid autocrafting breaking when using 2 stacks of the same fluid in a pattern. + +## [v1.9.16] - 2021-11-16 + +### Added + +- Added Covers for all cable types. +- Added Polish translation. +- Added Italian translation. +- Addons can now override how crafters insert items. + +### Changed + +- Improved JEI integration to pick the best option when transferring items. + +### Fixed + +- Fixed an issue where too many items in a grid would kick the player. +- Fixed an issue where the portable grid does not open from Inventory anymore after some use. +- Fixed craftable view in grids not showing items that were already in storage. +- Fixed Wireless Crafting Monitor not working as Curio. +- Fixed wrong slot being locked in some cases when opening a wireless item. +- Slightly sped up External Storage item look up. +- Fixed extraction from Storage Monitor not respecting maximum stack size. + +## [v1.9.15] - 2021-07-25 + +### Fixed + +- Fixed Refined Storage Addons compatibility. + +## [v1.9.14] - 2021-07-25 + +### Added + +- Implemented Curios support. + +## [v1.9.13] - 2021-06-14 + +### Added + +- Added some performance improvements for autocrafting. + +### Fixed + +- Fixed count on Storage Monitor having Z fighting. +- Fixed items on Storage Monitor not being flat. +- Fixed crash when using an External Storage on a fluid inventory. +- Fixed a memory leak in the pattern cache. +- Fixed Detector crashing when dyed. +- Fixed autocrafting being stuck after clicking "Start". +- Fixed Crafting Monitor not being able to show hours. +- Fixed capacity rendering of infinite storages. +- Fixed wrong alignment for the JEI request autocrafting tooltip. +- Fixed mobs getting stuck in Refined Storage cables. +- Fixed dismantling storage blocks ignoring stack size. +- Fixed Ice and Fire banners breaking with Refined Storage. necauqua) +- Fixed empty keybinding causing GL errors. +- Fixed some parts of the Japanese translation. +- Fixed rendering issue on blocks when using OptiFine. + +### Removed + +- Removed experimental pipeline nagging message. + +## [v1.9.12] - 2021-02-07 + +### Fixed + +- Fixed some issues when using the Grid when it's offline. +- Fixed crafting events not being fired in some cases in the Grid. +- Fixed not being able to set fluid filter slot output quantity. +- Fixed mod id search not working for Industrial Foregoing. +- Fixed fluid autocrafting duplicating fluids. +- Fixed some Grid crashes. +- Fixed constructor not using compare mode correctly in some cases. +- Fixed duplication bug in the Interface. + +## [v1.9.11] - 2021-01-03 + +### Fixed + +- Fixed disks and network devices not loading when they did not previously exist + - If you are affected by this please go to the world/data/ folder and remove the ".temp" ending from the files + before + launching. + +## [v1.9.10] - 2021-01-02 + +### Changed + +- Update Japanese translation. + +### Fixed + +- Improve performance of the Grid view. +- Fixed Disk Manipulator model glitches. +- Improve performance of the Disk Manipulator. +- Fixed being unable to set quantity in output slots of the Pattern Grid. +- Fixed External Storage in fluid mode losing track of fluids sometimes. +- Added code to avoid / minimize data corruption issues caused by Minecraft. +- Fixed processing autocrafting orders stealing items from each other. +- Fixed Constructor in fluid mode voiding fluid source blocks in front of it. +- Fixed crash when recoloring blocks that have no rotation component. +- Fixed reloading resource packs breaking Refined Storage textures. + +## [v1.9.9] - 2020-11-14 + +### Fixed + +- Fixed Refined Storage sidebuttons displaying over the JEI bookmark pagination buttons. +- Fixed issue where Crafters may fail to recognize an inventory/tank for some patterns. +- Fixed issue where the Crafter Manager can crash on invalid patterns. +- Fixed issue where alternatives in the Pattern Grid weren't being saved properly. +- Fixed not being able to change the Exporter filter slot count with regulator mode without closing and re-opening the + container. + +## [v1.9.8] - 2020-10-24 + +### Added + +- Added a JEI synchronized (two-way) search box mode to the Grid. +- Added a nag message when a player joins the world that asks the player to enable the experimental Forge lighting + pipeline to ensure correct rendering. + +### Fixed + +- Fixed server crash when scrolling in Grid. +- Fixed various issues with Grid interactions working without power. +- Fixed changing rotation not updating blocks. + +## [v1.9.7] - 2020-10-04 + +### Added + +- Added functionality to move items in the Grid with shift/ctrl + scrolling. + +### Changed + +- Changed JEI transfer error mechanics. + +### Fixed + +- Fixed crash when opening Controller GUI. +- Fixed dye being consumed without effect in some cases. +- Fixed deadlock caused by Portable Grid. +- Fixed custom tooltips not working in the Grid. + +## [v1.9.6] - 2020-09-25 + +### Added + +- Port to Minecraft 1.16.3. +- Added colored block variants. +- Added functionality to show missing items in the JEI transfer screen. +- Added functionality to request missing items from autocrafting in the JEI transfer screen. +- Added client config option to remember the Grid search query. + +### Fixed + +- Fixed Portable Grid losing enchantments when placing and breaking. + +## [v1.9.5] - 2020-09-06 + +### Added + +- Re-added the `/refinedstorage disk create ` command. +- Added the `/refinedstorage disk list` command. +- Added the `/refinedstorage disk list ` command. +- Added the `/refinedstorage network list ` command. +- Added the `/refinedstorage network get ` command. +- Added the `/refinedstorage network get autocrafting list` command. +- Added the `/refinedstorage network get autocrafting get ` command. +- Added the `/refinedstorage network get autocrafting cancel` command. +- Added the `/refinedstorage network get autocrafting cancel ` command. +- Added JEI ghost ingredient dragging support. + +### Fixed + +- Fixed text field not being focused in amount specifying screens. + +## [v1.9.4] - 2020-08-30 + +### Fixed + +- Fixed JEI recipes/usages keys not working in Grids. + +## [v1.9.3] - 2020-08-24 + +### Added + +- Port to Minecraft 1.16.2. + +### Changed + +- Updated Japanese translation. +- Updated Taiwanese translation. +- Refactored autocrafting code. + +### Fixed + +- Fixed duplication bug with the Constructor. + +## [v1.9.2b] - 2020-09-11 + +### Fixed + +- Fixed duplication bug with the Constructor. + +## [v1.9.2] - 2020-07-17 + +### Added + +- Re-added interdimensional networks with the Network Transmitter and Network Receiver. +- Re-added MouseTweaks integration. + +### Changed + +- Networks that are in a chunk that isn't loaded will no longer work, they will turn off. Chunkload the Controller to + maintain a functioning network over long distances. + +### Fixed + +- Fixed crash with Forge version 67. +- Fixed cases where Refined Storage unwillingly acts like a chunkloader. +- Fixed Network Transmitters being able to connect to any network device. +- Fixed Crafting Tweaks buttons being in the wrong position after changing the size configuration of the Grid. + +## [v1.9.1] - 2020-07-14 + +### Fixed + +- Fixed server crash. + +## [v1.9.0] - 2020-07-14 + +### Added + +- Port to Minecraft 1.16. + +### Fixed + +- Fixed wrench requiring shift click to rotate blocks. From 254a86215a6d94e6db8487e108c424ec756963d2 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 20:57:46 +0100 Subject: [PATCH 10/11] Add beta versioning for v1.9.0-v1.9.1-v1.9.2(b)-v1.9.3. --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de82eaf03..ce9471ccfe 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -326,7 +326,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Fixed JEI recipes/usages keys not working in Grids. -## [v1.9.3] - 2020-08-24 +## [v1.9.3-beta] - 2020-08-24 ### Added @@ -342,13 +342,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Fixed duplication bug with the Constructor. -## [v1.9.2b] - 2020-09-11 +## [v1.9.2b-beta] - 2020-09-11 ### Fixed - Fixed duplication bug with the Constructor. -## [v1.9.2] - 2020-07-17 +## [v1.9.2-beta] - 2020-07-17 ### Added @@ -367,13 +367,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Fixed Network Transmitters being able to connect to any network device. - Fixed Crafting Tweaks buttons being in the wrong position after changing the size configuration of the Grid. -## [v1.9.1] - 2020-07-14 +## [v1.9.1-beta] - 2020-07-14 ### Fixed - Fixed server crash. -## [v1.9.0] - 2020-07-14 +## [v1.9.0-beta] - 2020-07-14 ### Added From aaf528bce28f0808a170893b7e748ce14162b7ff Mon Sep 17 00:00:00 2001 From: Darkere Date: Mon, 12 Dec 2022 22:46:52 +0100 Subject: [PATCH 11/11] Rework Ingredient tracker to track stored items and compare IngredientList against that --- CHANGELOG.md | 5 + .../container/GridContainerMenu.java | 6 +- .../jei/GridRecipeTransferHandler.java | 103 +++----- .../integration/jei/Ingredient.java | 36 ++- .../integration/jei/IngredientTracker.java | 246 ++++++++++++------ .../jei/RecipeTransferCraftingGridError.java | 20 +- .../jei/RecipeTransferPatternGridError.java | 7 +- .../refinedstorage/screen/BaseScreen.java | 2 +- .../screen/grid/GridScreen.java | 14 +- .../screen/grid/view/GridViewImpl.java | 18 ++ .../screen/grid/view/IGridView.java | 5 + 11 files changed, 296 insertions(+), 166 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce9471ccfe..ec914cb0bb 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Available items indicator in JEI now updates while JEI is open + ### Fixed - Fixed chained crafters not taking over the name of the root crafter. +- Fixed lag when opening JEI in large system ## [v1.11.1] - 2022-10-30 diff --git a/src/main/java/com/refinedmods/refinedstorage/container/GridContainerMenu.java b/src/main/java/com/refinedmods/refinedstorage/container/GridContainerMenu.java index a112d504bf..e414a285d0 100644 --- a/src/main/java/com/refinedmods/refinedstorage/container/GridContainerMenu.java +++ b/src/main/java/com/refinedmods/refinedstorage/container/GridContainerMenu.java @@ -9,6 +9,9 @@ import com.refinedmods.refinedstorage.api.storage.cache.IStorageCache; import com.refinedmods.refinedstorage.api.storage.cache.IStorageCacheListener; import com.refinedmods.refinedstorage.apiimpl.network.node.GridNetworkNode; +import com.refinedmods.refinedstorage.blockentity.BaseBlockEntity; +import com.refinedmods.refinedstorage.blockentity.config.IType; +import com.refinedmods.refinedstorage.blockentity.grid.portable.IPortableGrid; import com.refinedmods.refinedstorage.container.slot.filter.FilterSlot; import com.refinedmods.refinedstorage.container.slot.filter.FluidFilterSlot; import com.refinedmods.refinedstorage.container.slot.grid.CraftingGridSlot; @@ -17,9 +20,6 @@ import com.refinedmods.refinedstorage.container.slot.legacy.LegacyDisabledSlot; import com.refinedmods.refinedstorage.container.slot.legacy.LegacyFilterSlot; import com.refinedmods.refinedstorage.screen.IScreenInfoProvider; -import com.refinedmods.refinedstorage.blockentity.BaseBlockEntity; -import com.refinedmods.refinedstorage.blockentity.config.IType; -import com.refinedmods.refinedstorage.blockentity.grid.portable.IPortableGrid; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; diff --git a/src/main/java/com/refinedmods/refinedstorage/integration/jei/GridRecipeTransferHandler.java b/src/main/java/com/refinedmods/refinedstorage/integration/jei/GridRecipeTransferHandler.java index 793fc3d544..c85ae911a1 100644 --- a/src/main/java/com/refinedmods/refinedstorage/integration/jei/GridRecipeTransferHandler.java +++ b/src/main/java/com/refinedmods/refinedstorage/integration/jei/GridRecipeTransferHandler.java @@ -8,8 +8,6 @@ import com.refinedmods.refinedstorage.network.grid.GridProcessingTransferMessage; import com.refinedmods.refinedstorage.network.grid.GridTransferMessage; import com.refinedmods.refinedstorage.screen.grid.GridScreen; -import com.refinedmods.refinedstorage.screen.grid.stack.IGridStack; -import com.refinedmods.refinedstorage.screen.grid.stack.ItemGridStack; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.forge.ForgeTypes; import mezz.jei.api.gui.ingredient.IRecipeSlotView; @@ -20,14 +18,16 @@ import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; public class GridRecipeTransferHandler implements IRecipeTransferHandler { @@ -58,26 +58,38 @@ public RecipeType getRecipeType() { @Override public @Nullable IRecipeTransferError transferRecipe(GridContainerMenu container, Object recipe, IRecipeSlotsView recipeSlots, Player player, boolean maxTransfer, boolean doTransfer) { - if (!(container.getScreenInfoProvider() instanceof GridScreen)) { + if (!(container.getScreenInfoProvider() instanceof GridScreen gridScreen)) { return null; } + + //When JEI is open the screen no longer ticks and doesn't run Actions. However, we do still want to run the actions that update the grid to keep the stored items up to date + gridScreen.runActions(); + + Ingredient.IngredientList ingredientList = new Ingredient.IngredientList(); + for (IRecipeSlotView slotView : recipeSlots.getSlotViews(RecipeIngredientRole.INPUT)) { + Optional firstStack = slotView.getIngredients(VanillaTypes.ITEM_STACK).findAny(); + ingredientList.add(new Ingredient(slotView, firstStack.map(ItemStack::getCount).orElse(0))); + } + + IngredientTracker tracker = IngredientTracker.getTracker(container); + tracker.updateAvailability(ingredientList, container, player); + GridType type = container.getGrid().getGridType(); if (type == GridType.CRAFTING) { - return transferRecipeForCraftingGrid(container, recipe, recipeSlots, player, doTransfer); + return transferRecipeForCraftingGrid(container, recipe, recipeSlots, player, doTransfer, ingredientList); } else if (type == GridType.PATTERN) { - return transferRecipeForPatternGrid(container, recipe, recipeSlots, player, doTransfer); + return transferRecipeForPatternGrid(container, recipe, recipeSlots, player, doTransfer, ingredientList); } return null; } - private RecipeTransferCraftingGridError transferRecipeForCraftingGrid(GridContainerMenu container, Object recipe, IRecipeSlotsView recipeLayout, Player player, boolean doTransfer) { - IngredientTracker tracker = createTracker(container, recipeLayout, player, doTransfer); + private RecipeTransferCraftingGridError transferRecipeForCraftingGrid(GridContainerMenu container, Object recipe, IRecipeSlotsView recipeLayout, Player player, boolean doTransfer, Ingredient.IngredientList ingredientList) { if (doTransfer) { - if (tracker.hasMissingButAutocraftingAvailable() && Screen.hasControlDown()) { - tracker.createCraftingRequests().forEach((id, count) -> RS.NETWORK_HANDLER.sendToServer( + if (ingredientList.hasMissingButAutocraftingAvailable() && Screen.hasControlDown()) { + ingredientList.createCraftingRequests().forEach((id, count) -> RS.NETWORK_HANDLER.sendToServer( new GridCraftingPreviewRequestMessage( id, count, @@ -86,79 +98,38 @@ private RecipeTransferCraftingGridError transferRecipeForCraftingGrid(GridContai ) )); } else { - moveItems(container, recipe, recipeLayout, tracker); + moveItems(container, recipe, recipeLayout, player); } } else { - if (tracker.hasMissing()) { - return new RecipeTransferCraftingGridError(tracker); + if (ingredientList.hasMissing()) { + return new RecipeTransferCraftingGridError(ingredientList); } } return null; } - private IRecipeTransferError transferRecipeForPatternGrid(GridContainerMenu container, Object recipe, IRecipeSlotsView recipeLayout, Player player, boolean doTransfer) { - IngredientTracker tracker = createTracker(container, recipeLayout, player, doTransfer); - + private IRecipeTransferError transferRecipeForPatternGrid(GridContainerMenu container, Object recipe, IRecipeSlotsView recipeLayout, Player player, boolean doTransfer, Ingredient.IngredientList ingredientList) { if (doTransfer) { - moveItems(container, recipe, recipeLayout, tracker); + moveItems(container, recipe, recipeLayout, player); } else { - if (tracker.isAutocraftingAvailable()) { - return new RecipeTransferPatternGridError(tracker); + if (ingredientList.isAutocraftingAvailable()) { + return new RecipeTransferPatternGridError(ingredientList); } } return null; } - private IngredientTracker createTracker(GridContainerMenu container, IRecipeSlotsView recipeLayout, Player player, boolean doTransfer) { - IngredientTracker tracker = new IngredientTracker(recipeLayout, doTransfer); - - // Using IGridView#getStacks will return a *filtered* list of items in the view, - // which will cause problems - especially if the user uses JEI synchronised searching. - // Instead, we will use IGridView#getAllStacks which provides an unordered view of all GridStacks. - Collection gridStacks = ((GridScreen) container.getScreenInfoProvider()).getView().getAllStacks(); - - // Check grid - if (container.getGrid().isGridActive()) { - for (IGridStack gridStack : gridStacks) { - if (gridStack instanceof ItemGridStack) { - tracker.addAvailableStack(((ItemGridStack) gridStack).getStack(), gridStack); - } - } - } - - // Check inventory - for (int inventorySlot = 0; inventorySlot < player.getInventory().getContainerSize(); inventorySlot++) { - if (!player.getInventory().getItem(inventorySlot).isEmpty()) { - tracker.addAvailableStack(player.getInventory().getItem(inventorySlot), null); - } - } - - // Check grid crafting slots - if (container.getGrid().getGridType().equals(GridType.CRAFTING)) { - CraftingContainer craftingMatrix = container.getGrid().getCraftingMatrix(); - if (craftingMatrix != null) { - for (int matrixSlot = 0; matrixSlot < craftingMatrix.getContainerSize(); matrixSlot++) { - if (!craftingMatrix.getItem(matrixSlot).isEmpty()) { - tracker.addAvailableStack(craftingMatrix.getItem(matrixSlot), null); - } - } - } - } - - return tracker; - } - public boolean hasTransferredRecently() { return System.currentTimeMillis() - lastTransferTimeMs <= TRANSFER_SCROLLBAR_DELAY_MS; } - private void moveItems(GridContainerMenu gridContainer, Object recipe, IRecipeSlotsView recipeLayout, IngredientTracker tracker) { + private void moveItems(GridContainerMenu gridContainer, Object recipe, IRecipeSlotsView recipeLayout, Player player) { this.lastTransferTimeMs = System.currentTimeMillis(); if (gridContainer.getGrid().getGridType() == GridType.PATTERN && !(recipe instanceof CraftingRecipe)) { - moveForProcessing(recipeLayout, tracker); + moveForProcessing(recipeLayout, gridContainer, player); } else { move(recipeLayout); } @@ -185,7 +156,7 @@ private void move(IRecipeSlotsView recipeSlotsView) { RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(inputs)); } - private void moveForProcessing(IRecipeSlotsView recipeLayout, IngredientTracker tracker) { + private void moveForProcessing(IRecipeSlotsView recipeLayout, GridContainerMenu gridContainer, Player player) { List inputs = new LinkedList<>(); List outputs = new LinkedList<>(); @@ -194,13 +165,13 @@ private void moveForProcessing(IRecipeSlotsView recipeLayout, IngredientTracker List inputSlots = recipeLayout.getSlotViews(RecipeIngredientRole.INPUT); for (IRecipeSlotView view : inputSlots) { - handleItemIngredient(inputs, view, tracker); + handleItemIngredient(inputs, view, gridContainer, player); handleFluidIngredient(fluidInputs, view); } List outputSlots = recipeLayout.getSlotViews(RecipeIngredientRole.OUTPUT); for (IRecipeSlotView view : outputSlots) { - handleItemIngredient(outputs, view, tracker); + handleItemIngredient(outputs, view, gridContainer, player); handleFluidIngredient(fluidOutputs, view); } @@ -213,9 +184,9 @@ private void handleFluidIngredient(List list, IRecipeSlotView slotVi } } - private void handleItemIngredient(List list, IRecipeSlotView slotView, IngredientTracker tracker) { + private void handleItemIngredient(List list, IRecipeSlotView slotView, GridContainerMenu gridContainer, Player player) { if (slotView != null && slotView.getIngredients(VanillaTypes.ITEM_STACK).findAny().isPresent()) { - ItemStack stack = tracker.findBestMatch(slotView.getIngredients(VanillaTypes.ITEM_STACK).toList()); + ItemStack stack = IngredientTracker.getTracker(gridContainer).findBestMatch(gridContainer, player, slotView.getIngredients(VanillaTypes.ITEM_STACK).toList()); if (stack.isEmpty() && slotView.getDisplayedIngredient(VanillaTypes.ITEM_STACK).isPresent()) { stack = slotView.getDisplayedIngredient(VanillaTypes.ITEM_STACK).get(); diff --git a/src/main/java/com/refinedmods/refinedstorage/integration/jei/Ingredient.java b/src/main/java/com/refinedmods/refinedstorage/integration/jei/Ingredient.java index c2aa43de11..9764745b63 100644 --- a/src/main/java/com/refinedmods/refinedstorage/integration/jei/Ingredient.java +++ b/src/main/java/com/refinedmods/refinedstorage/integration/jei/Ingredient.java @@ -2,7 +2,7 @@ import mezz.jei.api.gui.ingredient.IRecipeSlotView; -import java.util.UUID; +import java.util.*; class Ingredient { private final IRecipeSlotView slotView; @@ -16,7 +16,7 @@ public Ingredient(IRecipeSlotView view, int count) { } public boolean isAvailable() { - return getMissingAmount() == 0; + return getMissingAmount() <= 0; } public int getMissingAmount() { @@ -42,4 +42,36 @@ public void setCraftStackId(UUID craftStackId) { public void fulfill(int amount) { fulfilled += amount; } + + static class IngredientList { + List ingredients = new ArrayList<>(); + + void add(Ingredient ingredient) { + ingredients.add(ingredient); + } + + public boolean hasMissing() { + return ingredients.stream().anyMatch(ingredient -> !ingredient.isAvailable()); + } + + public boolean hasMissingButAutocraftingAvailable() { + return ingredients.stream().anyMatch(ingredient -> !ingredient.isAvailable() && ingredient.isCraftable()); + } + + public boolean isAutocraftingAvailable() { + return ingredients.stream().anyMatch(Ingredient::isCraftable); + } + + public Map createCraftingRequests() { + Map toRequest = new HashMap<>(); + + for (Ingredient ingredient : ingredients) { + if (!ingredient.isAvailable() && ingredient.isCraftable()) { + toRequest.merge(ingredient.getCraftStackId(), ingredient.getMissingAmount(), Integer::sum); + } + } + + return toRequest; + } + } } diff --git a/src/main/java/com/refinedmods/refinedstorage/integration/jei/IngredientTracker.java b/src/main/java/com/refinedmods/refinedstorage/integration/jei/IngredientTracker.java index dd59c33108..a99e0deab6 100644 --- a/src/main/java/com/refinedmods/refinedstorage/integration/jei/IngredientTracker.java +++ b/src/main/java/com/refinedmods/refinedstorage/integration/jei/IngredientTracker.java @@ -2,124 +2,214 @@ import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern; import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPatternProvider; +import com.refinedmods.refinedstorage.api.network.grid.GridType; import com.refinedmods.refinedstorage.api.util.IComparer; import com.refinedmods.refinedstorage.apiimpl.API; +import com.refinedmods.refinedstorage.container.GridContainerMenu; import com.refinedmods.refinedstorage.item.PatternItem; +import com.refinedmods.refinedstorage.screen.grid.GridScreen; import com.refinedmods.refinedstorage.screen.grid.stack.IGridStack; +import com.refinedmods.refinedstorage.screen.grid.stack.ItemGridStack; +import com.refinedmods.refinedstorage.screen.grid.view.IGridView; +import com.refinedmods.refinedstorage.util.ItemStackKey; import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.ingredient.IRecipeSlotView; -import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -import mezz.jei.api.recipe.RecipeIngredientRole; import net.minecraft.client.Minecraft; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Item; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.registries.ForgeRegistries; -import javax.annotation.Nullable; import java.util.*; public class IngredientTracker { - private final List ingredients = new ArrayList<>(); - private final Map storedItems = new HashMap<>(); - private boolean doTransfer; - public IngredientTracker(IRecipeSlotsView recipeLayout, boolean doTransfer) { - for (IRecipeSlotView slotView : recipeLayout.getSlotViews(RecipeIngredientRole.INPUT)) { - Optional optionalItemStack = slotView.getIngredients(VanillaTypes.ITEM_STACK).findAny(); + private static IngredientTracker INSTANCE; - optionalItemStack.ifPresent(stack -> ingredients.add(new Ingredient(slotView, stack.getCount()))); - } + private final Map storedItems = new HashMap<>(); + private final Map patternItems = new HashMap<>(); + private final Map craftableItems = new HashMap<>(); - this.doTransfer = doTransfer; + public static IngredientTracker getTracker(GridContainerMenu gridContainer) { + if (INSTANCE == null) { + INSTANCE = new IngredientTracker(gridContainer); + } + return INSTANCE; } - public Collection getIngredients() { - return ingredients; + public static void invalidate() { + INSTANCE = null; } - public void addAvailableStack(ItemStack stack, @Nullable IGridStack gridStack) { - int available = stack.getCount(); - if (doTransfer) { - if (stack.getItem() instanceof ICraftingPatternProvider) { - ICraftingPattern pattern = PatternItem.fromCache(Minecraft.getInstance().level, stack); - if (pattern.isValid()) { - for (ItemStack outputStack : pattern.getOutputs()) { - storedItems.merge(registryName(outputStack.getItem()), outputStack.getCount(), Integer::sum); - } + public IngredientTracker(GridContainerMenu gridContainer) { + + // Using IGridView#getStacks will return a *filtered* list of items in the view, + // which will cause problems - especially if the user uses JEI synchronised searching. + // Instead, we will use IGridView#getAllStacks which provides an unordered view of all GridStacks. + IGridView view = ((GridScreen) gridContainer.getScreenInfoProvider()).getView(); + + //Existing stacks are synced by the fact that they are both referencing the same object. However, new stacks need to be added. + view.addDeltaListener((iGridStack -> { + if (iGridStack instanceof ItemGridStack stack) { + if (stack.isCraftable()) { + craftableItems.put(new ItemStackKey(stack.getStack()), stack.getId()); + } else { + addStack(stack.getStack()); } - } else { - storedItems.merge(registryName(stack.getItem()), available, Integer::sum); } - } - - for (Ingredient ingredient : ingredients) { - if (available == 0) { - return; + })); + Collection gridStacks = view.getAllStacks(); + + // Check grid + if (gridContainer.getGrid().isGridActive()) { + for (IGridStack gridStack : gridStacks) { + if (gridStack instanceof ItemGridStack stackInGrid) { + + // for craftables we should easily be able to take the hit from hashing the nbt + if (stackInGrid.isCraftable()) { + craftableItems.put(new ItemStackKey(stackInGrid.getStack()), gridStack.getId()); + } else { // for non-craftables we don't hash nbt to avoid the performance hit + addStack(stackInGrid.getStack()); + } + } } + } + } - Optional match = ingredient - .getSlotView() - .getIngredients(VanillaTypes.ITEM_STACK) - .filter(s -> API.instance().getComparer().isEqual(stack, s, IComparer.COMPARE_NBT)) - .findFirst(); - - if (match.isPresent()) { - // Craftables and non-craftables are 2 different gridstacks - // As such we need to ignore craftable stacks as they are not actual items - if (gridStack != null && gridStack.isCraftable()) { - ingredient.setCraftStackId(gridStack.getId()); - } else if (!ingredient.isAvailable()) { - int needed = ingredient.getMissingAmount(); - int used = Math.min(available, needed); - ingredient.fulfill(used); - available -= used; + public void addStack(ItemStack stack) { + if (stack.isEmpty()) { + return; + } + if (stack.getItem() instanceof ICraftingPatternProvider) { + ICraftingPattern pattern = PatternItem.fromCache(Minecraft.getInstance().level, stack); + if (pattern.isValid()) { + for (ItemStack outputStack : pattern.getOutputs()) { + patternItems.merge(new ItemStackKey(outputStack), 1, Integer::sum); } } + + } else { + storedItems.merge(new ItemStackKey(stack), stack.getCount(), Integer::sum); } - } - public boolean hasMissing() { - return ingredients.stream().anyMatch(ingredient -> !ingredient.isAvailable()); } - public boolean hasMissingButAutocraftingAvailable() { - return ingredients.stream().anyMatch(ingredient -> !ingredient.isAvailable() && ingredient.isCraftable()); - } - public boolean isAutocraftingAvailable() { - return ingredients.stream().anyMatch(Ingredient::isCraftable); - } + public ItemStack findBestMatch(GridContainerMenu gridContainer, Player player, List list) { + ItemStack resultStack = ItemStack.EMPTY; + int count = 0; - public Map createCraftingRequests() { - Map toRequest = new HashMap<>(); - for (Ingredient ingredient : ingredients) { - if (!ingredient.isAvailable() && ingredient.isCraftable()) { - toRequest.merge(ingredient.getCraftStackId(), ingredient.getMissingAmount(), Integer::sum); + for (ItemStack listStack : list) { + + //check crafting matrix + if (gridContainer.getGrid().getGridType().equals(GridType.CRAFTING)) { + CraftingContainer craftingMatrix = gridContainer.getGrid().getCraftingMatrix(); + if (craftingMatrix != null) { + for (int matrixSlot = 0; matrixSlot < craftingMatrix.getContainerSize(); matrixSlot++) { + ItemStack stackInSlot = craftingMatrix.getItem(matrixSlot); + if (API.instance().getComparer().isEqual(listStack, stackInSlot, IComparer.COMPARE_NBT)) { + if (stackInSlot.getCount() > count) { + count = stackInSlot.getCount(); + resultStack = stackInSlot; + } + } + } + } } - } - return toRequest; - } + //check inventory + for (int inventorySlot = 0; inventorySlot < player.getInventory().getContainerSize(); inventorySlot++) { + ItemStack stackInSlot = player.getInventory().getItem(inventorySlot); + if (API.instance().getComparer().isEqual(listStack, stackInSlot, IComparer.COMPARE_NBT)) { + if (stackInSlot.getCount() > count) { + count = stackInSlot.getCount(); + resultStack = stackInSlot; + } + } + } - public ItemStack findBestMatch(List list) { - ItemStack stack = ItemStack.EMPTY; - int count = 0; + //check storage + var stored = storedItems.get(new ItemStackKey(listStack)); + if (stored != null) { + if (stored > count) { + resultStack = listStack; + count = stored; + } + } + } - for (ItemStack itemStack : list) { - Integer stored = storedItems.get(registryName(itemStack.getItem())); - if (stored != null && stored > count) { - stack = itemStack; - count = stored; + //If the item is not in storage check patterns autocrafting + if (count == 0) { + for (ItemStack itemStack : list) { + ItemStackKey key = new ItemStackKey(itemStack); + if (craftableItems.get(key) != null) { + resultStack = itemStack; + break; + } else if (patternItems.get(key) != null) { + resultStack = itemStack; + break; + } } } - return stack; + return resultStack; } - private ResourceLocation registryName(final Item item) { - return ForgeRegistries.ITEMS.getKey(item); + public void updateAvailability(Ingredient.IngredientList ingredientList, GridContainerMenu gridContainer, Player player) { + Map usedMatrixStacks = new HashMap<>(); + Map usedInventoryStacks = new HashMap<>(); + Map usedStoredStacks = new HashMap<>(); + + //Gather available Stacks + for (Ingredient ingredient : ingredientList.ingredients) { + ingredient.getSlotView().getIngredients(VanillaTypes.ITEM_STACK).takeWhile(stack -> !ingredient.isAvailable()).forEach(stack -> { + + ingredient.setCraftStackId(craftableItems.get(new ItemStackKey(stack))); + // Check grid crafting slots + if (gridContainer.getGrid().getGridType().equals(GridType.CRAFTING)) { + CraftingContainer craftingMatrix = gridContainer.getGrid().getCraftingMatrix(); + if (craftingMatrix != null) { + for (int matrixSlot = 0; matrixSlot < craftingMatrix.getContainerSize(); matrixSlot++) { + if (checkStack(usedMatrixStacks, ingredient, stack, matrixSlot, craftingMatrix.getItem(matrixSlot))) { + return; + } + } + } + } + + //read inventory + for (int inventorySlot = 0; inventorySlot < player.getInventory().getContainerSize(); inventorySlot++) { + if (checkStack(usedInventoryStacks, ingredient, stack, inventorySlot, player.getInventory().getItem(inventorySlot))) { + return; + } + } + + //Check Stored Stacks + ItemStackKey key = new ItemStackKey(stack); + Integer stored = storedItems.get(key); + if (stored != null) { + Integer used = usedStoredStacks.get(key); + int amount = Math.min(ingredient.getMissingAmount(), used == null ? stored : stored - used); + if (amount > 0) { + ingredient.fulfill(amount); + usedStoredStacks.put(key, used == null ? amount : used + amount); + } + } + }); + } } + + private boolean checkStack(Map usedMatrixStacks, Ingredient ingredient, ItemStack stack, int slot, ItemStack stackInSlot) { + if (API.instance().getComparer().isEqual(stack, stackInSlot, IComparer.COMPARE_NBT)) { + Integer used = usedMatrixStacks.get(slot); + int amount = Math.min(ingredient.getMissingAmount(), used == null ? stackInSlot.getCount() : stackInSlot.getCount() - used); + if (amount > 0) { + ingredient.fulfill(amount); + usedMatrixStacks.put(slot, amount); + } + return ingredient.isAvailable(); + } + return false; + } + } diff --git a/src/main/java/com/refinedmods/refinedstorage/integration/jei/RecipeTransferCraftingGridError.java b/src/main/java/com/refinedmods/refinedstorage/integration/jei/RecipeTransferCraftingGridError.java index c04a9dfda4..b0e58f7c45 100644 --- a/src/main/java/com/refinedmods/refinedstorage/integration/jei/RecipeTransferCraftingGridError.java +++ b/src/main/java/com/refinedmods/refinedstorage/integration/jei/RecipeTransferCraftingGridError.java @@ -8,7 +8,6 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; - import java.awt.*; import java.util.ArrayList; import java.util.List; @@ -17,10 +16,11 @@ public class RecipeTransferCraftingGridError implements IRecipeTransferError { protected static final Color AUTOCRAFTING_HIGHLIGHT_COLOR = new Color(0.0f, 0.0f, 1.0f, 0.4f); private static final Color MISSING_HIGHLIGHT_COLOR = new Color(1.0f, 0.0f, 0.0f, 0.4f); private static final boolean HOST_OS_IS_MACOS = System.getProperty("os.name").equals("Mac OS X"); - protected final IngredientTracker tracker; + protected final Ingredient.IngredientList ingredientList; + - public RecipeTransferCraftingGridError(IngredientTracker tracker) { - this.tracker = tracker; + public RecipeTransferCraftingGridError(Ingredient.IngredientList ingredientList) { + this.ingredientList = ingredientList; } @Override @@ -28,6 +28,16 @@ public Type getType() { return Type.COSMETIC; } + @Override + public int getButtonHighlightColor() { + if (ingredientList.hasMissingButAutocraftingAvailable()) { + return AUTOCRAFTING_HIGHLIGHT_COLOR.getRGB(); + } else if (ingredientList.hasMissing()) { + return MISSING_HIGHLIGHT_COLOR.getRGB(); + } + return IRecipeTransferError.super.getButtonHighlightColor(); + } + @Override public void showError(PoseStack poseStack, int mouseX, int mouseY, IRecipeSlotsView recipeSlotsView, int recipeX, int recipeY) { poseStack.translate(recipeX, recipeY, 0); @@ -44,7 +54,7 @@ protected List drawIngredientHighlights(PoseStack stack, int recipeX, boolean craftMessage = false; boolean missingMessage = false; - for (Ingredient ingredient : tracker.getIngredients()) { + for (Ingredient ingredient : ingredientList.ingredients) { if (!ingredient.isAvailable()) { if (ingredient.isCraftable()) { ingredient.getSlotView().drawHighlight(stack, AUTOCRAFTING_HIGHLIGHT_COLOR.getRGB()); diff --git a/src/main/java/com/refinedmods/refinedstorage/integration/jei/RecipeTransferPatternGridError.java b/src/main/java/com/refinedmods/refinedstorage/integration/jei/RecipeTransferPatternGridError.java index dbc608b34f..9aac904ea4 100644 --- a/src/main/java/com/refinedmods/refinedstorage/integration/jei/RecipeTransferPatternGridError.java +++ b/src/main/java/com/refinedmods/refinedstorage/integration/jei/RecipeTransferPatternGridError.java @@ -4,13 +4,12 @@ import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; - import java.util.ArrayList; import java.util.List; public class RecipeTransferPatternGridError extends RecipeTransferCraftingGridError { - public RecipeTransferPatternGridError(IngredientTracker tracker) { - super(tracker); + public RecipeTransferPatternGridError(Ingredient.IngredientList ingredients) { + super(ingredients); } @Override @@ -20,7 +19,7 @@ protected List drawIngredientHighlights(PoseStack stack, int recipeX, boolean craftMessage = false; - for (Ingredient ingredient : tracker.getIngredients()) { + for (Ingredient ingredient : ingredientList.ingredients) { if (ingredient.isCraftable()) { ingredient.getSlotView().drawHighlight(stack, AUTOCRAFTING_HIGHLIGHT_COLOR.getRGB()); craftMessage = true; diff --git a/src/main/java/com/refinedmods/refinedstorage/screen/BaseScreen.java b/src/main/java/com/refinedmods/refinedstorage/screen/BaseScreen.java index 276e690ae6..2b24dcfa87 100644 --- a/src/main/java/com/refinedmods/refinedstorage/screen/BaseScreen.java +++ b/src/main/java/com/refinedmods/refinedstorage/screen/BaseScreen.java @@ -73,7 +73,7 @@ public static void executeLater(Consumer callback) { executeLater(AbstractContainerScreen.class, callback); } - private void runActions() { + public void runActions() { runActions(getClass()); runActions(AbstractContainerScreen.class); } diff --git a/src/main/java/com/refinedmods/refinedstorage/screen/grid/GridScreen.java b/src/main/java/com/refinedmods/refinedstorage/screen/grid/GridScreen.java index 13a9995a05..381738dba1 100644 --- a/src/main/java/com/refinedmods/refinedstorage/screen/grid/GridScreen.java +++ b/src/main/java/com/refinedmods/refinedstorage/screen/grid/GridScreen.java @@ -10,6 +10,12 @@ import com.refinedmods.refinedstorage.api.network.grid.handler.IItemGridHandler; import com.refinedmods.refinedstorage.apiimpl.network.node.GridNetworkNode; import com.refinedmods.refinedstorage.apiimpl.render.ElementDrawers; +import com.refinedmods.refinedstorage.blockentity.NetworkNodeBlockEntity; +import com.refinedmods.refinedstorage.blockentity.config.IType; +import com.refinedmods.refinedstorage.blockentity.data.BlockEntitySynchronizationManager; +import com.refinedmods.refinedstorage.blockentity.grid.GridBlockEntity; +import com.refinedmods.refinedstorage.blockentity.grid.portable.IPortableGrid; +import com.refinedmods.refinedstorage.blockentity.grid.portable.PortableGridBlockEntity; import com.refinedmods.refinedstorage.container.GridContainerMenu; import com.refinedmods.refinedstorage.network.grid.*; import com.refinedmods.refinedstorage.screen.BaseScreen; @@ -24,12 +30,6 @@ import com.refinedmods.refinedstorage.screen.widget.SearchWidget; import com.refinedmods.refinedstorage.screen.widget.TabListWidget; import com.refinedmods.refinedstorage.screen.widget.sidebutton.*; -import com.refinedmods.refinedstorage.blockentity.NetworkNodeBlockEntity; -import com.refinedmods.refinedstorage.blockentity.config.IType; -import com.refinedmods.refinedstorage.blockentity.data.BlockEntitySynchronizationManager; -import com.refinedmods.refinedstorage.blockentity.grid.GridBlockEntity; -import com.refinedmods.refinedstorage.blockentity.grid.portable.IPortableGrid; -import com.refinedmods.refinedstorage.blockentity.grid.portable.PortableGridBlockEntity; import com.refinedmods.refinedstorage.util.RenderUtils; import com.refinedmods.refinedstorage.util.TimeUtils; import net.minecraft.ChatFormatting; @@ -37,7 +37,6 @@ import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; - import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; @@ -658,6 +657,7 @@ public void removed() { if (!RS.CLIENT_CONFIG.getGrid().getRememberSearchQuery()) { searchQuery = ""; } + getView().removed(); } public SearchWidget getSearchField() { diff --git a/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/GridViewImpl.java b/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/GridViewImpl.java index 96f6a470a8..1600b836ad 100644 --- a/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/GridViewImpl.java +++ b/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/GridViewImpl.java @@ -1,6 +1,7 @@ package com.refinedmods.refinedstorage.screen.grid.view; import com.refinedmods.refinedstorage.api.network.grid.IGrid; +import com.refinedmods.refinedstorage.integration.jei.IngredientTracker; import com.refinedmods.refinedstorage.screen.grid.GridScreen; import com.refinedmods.refinedstorage.screen.grid.filtering.GridFilterParser; import com.refinedmods.refinedstorage.screen.grid.sorting.IGridSorter; @@ -9,6 +10,7 @@ import javax.annotation.Nullable; import java.util.*; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -22,6 +24,8 @@ public class GridViewImpl implements IGridView { private boolean active = false; private List stacks = new ArrayList<>(); + private List> deltaListeners = new ArrayList<>(); + public GridViewImpl(GridScreen screen, IGridSorter defaultSorter, List sorters) { this.screen = screen; this.defaultSorter = defaultSorter; @@ -73,6 +77,17 @@ public void sort() { this.screen.updateScrollbar(); } + @Override + public void addDeltaListener(Consumer listener) { + deltaListeners.add(listener); + } + + @Override + public void removed() { + deltaListeners.clear(); + IngredientTracker.invalidate(); + } + private Comparator getActiveSort() { IGrid grid = screen.getGrid(); SortingDirection sortingDirection = grid.getSortingDirection() == IGrid.SORTING_DIRECTION_DESCENDING ? SortingDirection.DESCENDING : SortingDirection.ASCENDING; @@ -153,6 +168,9 @@ public void postChange(IGridStack stack, int delta) { if (craftingStack != null && shouldSort && activeFilters.test(existing)) { stacks.remove(craftingStack); } + + deltaListeners.forEach(consumer -> consumer.accept(stack)); + } else { if (shouldSort) { stacks.remove(existing); diff --git a/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/IGridView.java b/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/IGridView.java index 866040abd1..bd4aa145c9 100644 --- a/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/IGridView.java +++ b/src/main/java/com/refinedmods/refinedstorage/screen/grid/view/IGridView.java @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.List; import java.util.UUID; +import java.util.function.Consumer; public interface IGridView { List getStacks(); @@ -24,4 +25,8 @@ public interface IGridView { boolean canCraft(); void sort(); + + void addDeltaListener(Consumer listener); + + void removed(); }