From b02bcbfdfdd412a5f94c4c030db788e93a0a8a18 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 17 Jun 2018 02:59:42 +0200 Subject: [PATCH] Fixed portable grid rendering in item form and fixed bug where storage disks in Portable Grids could be moved into themselves. --- CHANGELOG.md | 1 + .../container/ContainerGrid.java | 4 +- .../refinedstorage/proxy/ProxyClient.java | 57 ++++++++++++++++++- .../tile/grid/portable/IPortableGrid.java | 10 ++++ .../tile/grid/portable/PortableGrid.java | 30 +++++----- .../tile/grid/portable/TilePortableGrid.java | 30 +++++++--- 6 files changed, 102 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf0af4760..8baf8544c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ NOTE: Worlds that used Refined Storage 1.5.x are fully compatible with Refined S - You can now re-insert Processing Patterns in the Pattern Grid and have the inputs and outputs be completed (raoulvdberge) - Fixed bug where pattern was recipe pattern was creatable when there was no recipe output (raoulvdberge) - Fixed a crash when breaking an Ender IO conduit with the Destructor (raoulvdberge) +- Fixed bug where storage disks in Portable Grids could be moved into themselves (raoulvdberge) - Added a missing config option for Crafter Manager energy usage (raoulvdberge) - If an Interface is configured to expose the entire network storage (by configuring no export slots), it will no longer expose the entire RS storage, due to performance issues (raoulvdberge) - The Portable Grid no longer exposes a inventory for crossmod interaction, due to performance issues (raoulvdberge) diff --git a/src/main/java/com/raoulvdberge/refinedstorage/container/ContainerGrid.java b/src/main/java/com/raoulvdberge/refinedstorage/container/ContainerGrid.java index 01d1afcff..5e8d6a9be 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/container/ContainerGrid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/container/ContainerGrid.java @@ -208,7 +208,9 @@ public class ContainerGrid extends ContainerBase { Slot slot = inventorySlots.get(slotIndex); if (slot.getHasStack()) { - if (slot == craftingResultSlot) { + if (grid instanceof IPortableGrid && slot.slotNumber == 4) { // Prevent moving disk slot into portable grid itself + return ItemStack.EMPTY; + } else if (slot == craftingResultSlot) { grid.onCraftedShift(player); sendCraftingSlots(); diff --git a/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyClient.java b/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyClient.java index 0b1623075..fde2d8a3b 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyClient.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyClient.java @@ -5,18 +5,23 @@ import com.raoulvdberge.refinedstorage.RSBlocks; import com.raoulvdberge.refinedstorage.RSItems; import com.raoulvdberge.refinedstorage.RSKeyBindings; import com.raoulvdberge.refinedstorage.api.network.grid.GridType; +import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider; +import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskSyncData; +import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.CraftingPattern; import com.raoulvdberge.refinedstorage.block.*; import com.raoulvdberge.refinedstorage.gui.GuiCraftingPreview; import com.raoulvdberge.refinedstorage.gui.grid.GuiCraftingStart; +import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase; import com.raoulvdberge.refinedstorage.item.*; import com.raoulvdberge.refinedstorage.network.MessageGridCraftingPreviewResponse; import com.raoulvdberge.refinedstorage.render.*; import com.raoulvdberge.refinedstorage.tile.TileController; import com.raoulvdberge.refinedstorage.tile.TileStorageMonitor; -import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGrid; +import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid; import com.raoulvdberge.refinedstorage.tile.grid.portable.TilePortableGrid; import com.raoulvdberge.refinedstorage.util.RenderUtils; +import com.raoulvdberge.refinedstorage.util.StackUtils; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -40,6 +45,7 @@ import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.Loader; @@ -49,6 +55,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.List; +import java.util.UUID; public class ProxyClient extends ProxyCommon { @Override @@ -279,9 +286,53 @@ public class ProxyClient extends ProxyCommon { ModelLoader.setCustomStateMapper(RSBlocks.PORTABLE_GRID, new StateMap.Builder().ignore(BlockPortableGrid.TYPE).build()); ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(RSBlocks.PORTABLE_GRID), stack -> { - PortableGrid portableGrid = new PortableGrid(null, stack); // TODO: pass fullness? + ItemHandlerBase disk = new ItemHandlerBase(1); - return new ModelResourceLocation("refinedstorage:portable_grid", "connected=" + Boolean.toString(portableGrid.getEnergy() != 0 && !portableGrid.getDisk().getStackInSlot(0).isEmpty()) + ",direction=north,disk_state=" + TilePortableGrid.getDiskState(portableGrid)); + if (stack.hasTagCompound()) { + StackUtils.readItems(disk, 4, stack.getTagCompound()); + } + + UUID diskId = disk.getStackInSlot(0).isEmpty() ? null : ((IStorageDiskProvider) disk.getStackInSlot(0).getItem()).getId(disk.getStackInSlot(0)); + + IPortableGrid.IPortableGridRenderInfo renderInfo = new IPortableGrid.IPortableGridRenderInfo() { + @Override + public int getStored() { + if (diskId == null) { + return 0; + } + + API.instance().getStorageDiskSync().sendRequest(diskId); + + IStorageDiskSyncData data = API.instance().getStorageDiskSync().getData(diskId); + + return data == null ? 0 : data.getStored(); + } + + @Override + public int getCapacity() { + if (diskId == null) { + return 0; + } + + API.instance().getStorageDiskSync().sendRequest(diskId); + + IStorageDiskSyncData data = API.instance().getStorageDiskSync().getData(diskId); + + return data == null ? 0 : data.getCapacity(); + } + + @Override + public boolean hasStorage() { + return diskId != null; + } + + @Override + public boolean isActive() { + return (stack.getCapability(CapabilityEnergy.ENERGY, null).getEnergyStored() > 0 || stack.getMetadata() == ItemBlockPortableGrid.TYPE_CREATIVE) && hasStorage(); + } + }; + + return new ModelResourceLocation("refinedstorage:portable_grid", "connected=" + Boolean.toString(renderInfo.isActive()) + ",direction=north,disk_state=" + TilePortableGrid.getDiskState(renderInfo)); }); } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/IPortableGrid.java b/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/IPortableGrid.java index d3ec5419e..035ebb7df 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/IPortableGrid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/IPortableGrid.java @@ -10,6 +10,16 @@ import net.minecraftforge.items.IItemHandlerModifiable; import javax.annotation.Nullable; public interface IPortableGrid { + interface IPortableGridRenderInfo { + int getStored(); + + int getCapacity(); + + boolean hasStorage(); + + boolean isActive(); + } + IStorageCache getCache(); @Nullable diff --git a/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/PortableGrid.java b/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/PortableGrid.java index d63cf99a6..ee3637ca9 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/PortableGrid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/PortableGrid.java @@ -86,7 +86,7 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer protected void onContentsChanged(int slot) { super.onContentsChanged(slot); - if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER || (player == null && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)) { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { ItemStack diskStack = getStackInSlot(slot); if (diskStack.isEmpty()) { @@ -102,16 +102,14 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer } } - if (player != null) { - cache.invalidate(); + cache.invalidate(); - StackUtils.writeItems(this, 4, stack.getTagCompound()); - } + StackUtils.writeItems(this, 4, stack.getTagCompound()); } } }; - public PortableGrid(@Nullable EntityPlayer player, ItemStack stack) { + public PortableGrid(EntityPlayer player, ItemStack stack) { this.player = player; this.stack = stack; @@ -132,21 +130,19 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer storageTracker.readFromNBT(stack.getTagCompound().getTagList(NBT_STORAGE_TRACKER, Constants.NBT.TAG_COMPOUND)); } - if (player != null) { - StackUtils.readItems(disk, 4, stack.getTagCompound()); + StackUtils.readItems(disk, 4, stack.getTagCompound()); - if (!player.getEntityWorld().isRemote) { - API.instance().getOneSixMigrationHelper().migrateDiskInventory(player.getEntityWorld(), disk); - } + if (!player.getEntityWorld().isRemote) { + API.instance().getOneSixMigrationHelper().migrateDiskInventory(player.getEntityWorld(), disk); + } - StackUtils.readItems(filter, 0, stack.getTagCompound()); + StackUtils.readItems(filter, 0, stack.getTagCompound()); - drainEnergy(RS.INSTANCE.config.portableGridOpenUsage); + drainEnergy(RS.INSTANCE.config.portableGridOpenUsage); - // If there is no disk onContentsChanged isn't called and the update isn't sent, thus items from the previous grid view would remain clientside - if (!player.getEntityWorld().isRemote && disk.getStackInSlot(0).isEmpty()) { - cache.invalidate(); - } + // If there is no disk onContentsChanged isn't called and the update isn't sent, thus items from the previous grid view would remain clientside + if (!player.getEntityWorld().isRemote && disk.getStackInSlot(0).isEmpty()) { + cache.invalidate(); } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/TilePortableGrid.java b/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/TilePortableGrid.java index 2f2adfe61..d738629de 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/TilePortableGrid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/tile/grid/portable/TilePortableGrid.java @@ -61,7 +61,7 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid, IRedstoneConfigurable, IStorageDiskContainerContext { +public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid, IRedstoneConfigurable, IStorageDiskContainerContext, IPortableGrid.IPortableGridRenderInfo { public static final TileDataParameter REDSTONE_MODE = RedstoneMode.createParameter(); public static final TileDataParameter ENERGY_STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.energyStorage.getEnergyStored()); public static final TileDataParameter SORTING_DIRECTION = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getSortingDirection, (t, v) -> { @@ -476,6 +476,21 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid, checkIfConnectivityChanged(); } + @Override + public int getStored() { + return storage != null ? storage.getStored() : 0; + } + + @Override + public int getCapacity() { + return storage != null ? storage.getCapacity() : 0; + } + + @Override + public boolean hasStorage() { + return storage != null; + } + @Override public int getEnergy() { if (RS.INSTANCE.config.portableGridUsesEnergy && getPortableType() != PortableGridType.CREATIVE) { @@ -628,21 +643,18 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid, markDirty(); } - public static PortableGridDiskState getDiskState(IPortableGrid portableGrid) { - if (portableGrid.getStorage() == null) { + public static PortableGridDiskState getDiskState(IPortableGridRenderInfo renderInfo) { + if (!renderInfo.hasStorage()) { return PortableGridDiskState.NONE; } - if (portableGrid.getEnergy() == 0) { + if (!renderInfo.isActive()) { return PortableGridDiskState.DISCONNECTED; } - int stored = portableGrid.getStorage().getStored(); - int capacity = portableGrid.getStorage().getCapacity(); - - if (stored == capacity) { + if (renderInfo.getStored() == renderInfo.getCapacity()) { return PortableGridDiskState.FULL; - } else if ((int) ((float) stored / (float) capacity * 100F) >= 85) { + } else if ((int) ((float) renderInfo.getStored() / (float) renderInfo.getCapacity() * 100F) >= 85) { return PortableGridDiskState.NEAR_CAPACITY; } else { return PortableGridDiskState.NORMAL;