Fixed portable grid rendering in item form and fixed bug where storage disks in Portable Grids could be moved into themselves.

This commit is contained in:
raoulvdberge
2018-06-17 02:59:42 +02:00
parent 956c8e00bb
commit b02bcbfdfd
6 changed files with 102 additions and 30 deletions

View File

@@ -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)

View File

@@ -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();

View File

@@ -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));
});
}

View File

@@ -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<ItemStack> getCache();
@Nullable

View File

@@ -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();
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,7 +130,6 @@ 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());
if (!player.getEntityWorld().isRemote) {
@@ -148,7 +145,6 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
cache.invalidate();
}
}
}
public ItemStack getStack() {
return stack;

View File

@@ -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<Integer, TilePortableGrid> REDSTONE_MODE = RedstoneMode.createParameter();
public static final TileDataParameter<Integer, TilePortableGrid> ENERGY_STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.energyStorage.getEnergyStored());
public static final TileDataParameter<Integer, TilePortableGrid> 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;