Begin on less network usage. This is very broken!
This commit is contained in:
		| @@ -6,10 +6,8 @@ import net.minecraft.inventory.Slot; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import refinedstorage.block.EnumGridType; | ||||
| import refinedstorage.container.slot.SlotGridCraftingResult; | ||||
| import refinedstorage.tile.TileController; | ||||
| import refinedstorage.tile.grid.IGrid; | ||||
| import refinedstorage.tile.grid.TileGrid; | ||||
| import refinedstorage.tile.grid.WirelessGrid; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| @@ -81,8 +79,9 @@ public class ContainerGrid extends ContainerBase { | ||||
|     public void onContainerClosed(EntityPlayer player) { | ||||
|         super.onContainerClosed(player); | ||||
|  | ||||
|         if (grid instanceof WirelessGrid && ((WirelessGrid) grid).getBoundTile() instanceof TileController) { | ||||
|         // @TODO: Fix | ||||
|         /*if (grid instanceof WirelessGrid && ((WirelessGrid) grid).getBoundTile() instanceof TileController) { | ||||
|             grid.getController().onCloseWirelessGrid(player); | ||||
|         } | ||||
|         }*/ | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -17,10 +17,8 @@ import refinedstorage.gui.sidebutton.SideButtonRedstoneMode; | ||||
| import refinedstorage.jei.PluginRefinedStorage; | ||||
| import refinedstorage.network.MessageGridCraftingClear; | ||||
| import refinedstorage.network.MessageGridCraftingPush; | ||||
| import refinedstorage.network.MessageStoragePull; | ||||
| import refinedstorage.network.MessageStoragePush; | ||||
| import refinedstorage.network.MessageGridStoragePull; | ||||
| import refinedstorage.storage.ItemGroup; | ||||
| import refinedstorage.tile.TileController; | ||||
| import refinedstorage.tile.grid.IGrid; | ||||
| import refinedstorage.tile.grid.TileGrid; | ||||
| import refinedstorage.tile.grid.WirelessGrid; | ||||
| @@ -75,7 +73,7 @@ public class GuiGrid extends GuiBase { | ||||
|         items.clear(); | ||||
|  | ||||
|         if (grid.isConnected()) { | ||||
|             items.addAll(grid.getController().getItemGroups()); | ||||
|             items.addAll(grid.getItemGroups()); | ||||
|  | ||||
|             if (!searchField.getText().trim().isEmpty()) { | ||||
|                 Iterator<ItemGroup> t = items.iterator(); | ||||
| @@ -256,33 +254,31 @@ public class GuiGrid extends GuiBase { | ||||
|         boolean clickedClear = clickedButton == 0 && isHoveringOverClear(mouseX - guiLeft, mouseY - guiTop); | ||||
|  | ||||
|         if (grid.isConnected()) { | ||||
|             TileController controller = grid.getController(); | ||||
|  | ||||
|             if (isHoveringOverSlot() && container.getPlayer().inventory.getItemStack() != null && (clickedButton == 0 || clickedButton == 1)) { | ||||
|                 RefinedStorage.NETWORK.sendToServer(new MessageStoragePush(controller.getPos().getX(), controller.getPos().getY(), controller.getPos().getZ(), -1, clickedButton == 1)); | ||||
|                 grid.onItemPush(-1, clickedButton == 1); | ||||
|             } else if (isHoveringOverItemInSlot() && container.getPlayer().inventory.getItemStack() == null) { | ||||
|                 int flags = 0; | ||||
|  | ||||
|                 if (clickedButton == 1) { | ||||
|                     flags |= MessageStoragePull.PULL_HALF; | ||||
|                     flags |= MessageGridStoragePull.PULL_HALF; | ||||
|                 } | ||||
|  | ||||
|                 if (GuiScreen.isShiftKeyDown()) { | ||||
|                     flags |= MessageStoragePull.PULL_SHIFT; | ||||
|                     flags |= MessageGridStoragePull.PULL_SHIFT; | ||||
|                 } | ||||
|  | ||||
|                 if (clickedButton == 2) { | ||||
|                     flags |= MessageStoragePull.PULL_ONE; | ||||
|                     flags |= MessageGridStoragePull.PULL_ONE; | ||||
|                 } | ||||
|  | ||||
|                 RefinedStorage.NETWORK.sendToServer(new MessageStoragePull(controller.getPos().getX(), controller.getPos().getY(), controller.getPos().getZ(), hoveringItemId, flags)); | ||||
|                 grid.onItemPull(hoveringItemId, flags); | ||||
|             } else if (clickedClear) { | ||||
|                 RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingClear((TileGrid) grid)); | ||||
|             } else { | ||||
|                 for (Slot slot : container.getPlayerInventorySlots()) { | ||||
|                     if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop)) { | ||||
|                         if (GuiScreen.isShiftKeyDown()) { | ||||
|                             RefinedStorage.NETWORK.sendToServer(new MessageStoragePush(controller.getPos().getX(), controller.getPos().getY(), controller.getPos().getZ(), slot.slotNumber, clickedButton == 1)); | ||||
|                             grid.onItemPush(slot.slotNumber, clickedButton == 1); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|   | ||||
							
								
								
									
										55
									
								
								src/main/java/refinedstorage/network/MessageContainerUpdate.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										55
									
								
								src/main/java/refinedstorage/network/MessageContainerUpdate.java
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| package refinedstorage.network; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.client.Minecraft; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||||
| import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; | ||||
| import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||||
| import refinedstorage.tile.INetworkTile; | ||||
|  | ||||
| public class MessageContainerUpdate implements IMessage, IMessageHandler<MessageContainerUpdate, IMessage> { | ||||
|     private TileEntity tile; | ||||
|     private int x; | ||||
|     private int y; | ||||
|     private int z; | ||||
|  | ||||
|     public MessageContainerUpdate() { | ||||
|     } | ||||
|  | ||||
|     public MessageContainerUpdate(TileEntity tile) { | ||||
|         this.tile = tile; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         x = buf.readInt(); | ||||
|         y = buf.readInt(); | ||||
|         z = buf.readInt(); | ||||
|  | ||||
|         if (Minecraft.getMinecraft().theWorld != null) { | ||||
|             tile = Minecraft.getMinecraft().theWorld.getTileEntity(new BlockPos(x, y, z)); | ||||
|  | ||||
|             if (tile instanceof INetworkTile) { | ||||
|                 ((INetworkTile) tile).receiveContainerData(buf); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         buf.writeInt(tile.getPos().getX()); | ||||
|         buf.writeInt(tile.getPos().getY()); | ||||
|         buf.writeInt(tile.getPos().getZ()); | ||||
|  | ||||
|         if (tile instanceof INetworkTile) { | ||||
|             ((INetworkTile) tile).sendContainerData(buf); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public IMessage onMessage(MessageContainerUpdate message, MessageContext ctx) { | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
| @@ -9,43 +9,44 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||||
| import refinedstorage.item.ItemWirelessGrid; | ||||
| import refinedstorage.storage.ItemGroup; | ||||
| import refinedstorage.tile.TileController; | ||||
| import refinedstorage.tile.grid.TileGrid; | ||||
| 
 | ||||
| public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStoragePull> implements IMessage { | ||||
| public class MessageGridStoragePull extends MessageHandlerPlayerToServer<MessageGridStoragePull> implements IMessage { | ||||
|     public static final int PULL_HALF = 1; | ||||
|     public static final int PULL_ONE = 2; | ||||
|     public static final int PULL_SHIFT = 4; | ||||
| 
 | ||||
|     private int x; | ||||
|     private int y; | ||||
|     private int z; | ||||
|     private int gridX; | ||||
|     private int gridY; | ||||
|     private int gridZ; | ||||
|     private int id; | ||||
|     private int flags; | ||||
| 
 | ||||
|     public MessageStoragePull() { | ||||
|     public MessageGridStoragePull() { | ||||
|     } | ||||
| 
 | ||||
|     public MessageStoragePull(int x, int y, int z, int id, int flags) { | ||||
|         this.x = x; | ||||
|         this.y = y; | ||||
|         this.z = z; | ||||
|     public MessageGridStoragePull(int gridX, int gridY, int gridZ, int id, int flags) { | ||||
|         this.gridX = gridX; | ||||
|         this.gridY = gridY; | ||||
|         this.gridZ = gridZ; | ||||
|         this.id = id; | ||||
|         this.flags = flags; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         x = buf.readInt(); | ||||
|         y = buf.readInt(); | ||||
|         z = buf.readInt(); | ||||
|         gridX = buf.readInt(); | ||||
|         gridY = buf.readInt(); | ||||
|         gridZ = buf.readInt(); | ||||
|         id = buf.readInt(); | ||||
|         flags = buf.readInt(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         buf.writeInt(x); | ||||
|         buf.writeInt(y); | ||||
|         buf.writeInt(z); | ||||
|         buf.writeInt(gridX); | ||||
|         buf.writeInt(gridY); | ||||
|         buf.writeInt(gridZ); | ||||
|         buf.writeInt(id); | ||||
|         buf.writeInt(flags); | ||||
|     } | ||||
| @@ -63,11 +64,11 @@ public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStor | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void handle(MessageStoragePull message, EntityPlayerMP player) { | ||||
|         TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z)); | ||||
|     public void handle(MessageGridStoragePull message, EntityPlayerMP player) { | ||||
|         TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.gridX, message.gridY, message.gridZ)); | ||||
| 
 | ||||
|         if (tile instanceof TileController && ((TileController) tile).isActive()) { | ||||
|             TileController controller = (TileController) tile; | ||||
|         if (tile instanceof TileGrid && ((TileGrid) tile).isConnected()) { | ||||
|             TileController controller = ((TileGrid) tile).getController(); | ||||
| 
 | ||||
|             if (message.id < controller.getItemGroups().size()) { | ||||
|                 ItemGroup group = controller.getItemGroups().get(message.id); | ||||
| @@ -8,67 +8,68 @@ import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||||
| import refinedstorage.item.ItemWirelessGrid; | ||||
| import refinedstorage.tile.TileController; | ||||
| import refinedstorage.tile.grid.TileGrid; | ||||
| 
 | ||||
| public class MessageStoragePush extends MessageHandlerPlayerToServer<MessageStoragePush> implements IMessage { | ||||
|     private int x; | ||||
|     private int y; | ||||
|     private int z; | ||||
|     private int slot; | ||||
| public class MessageGridStoragePush extends MessageHandlerPlayerToServer<MessageGridStoragePush> implements IMessage { | ||||
|     private int gridX; | ||||
|     private int gridY; | ||||
|     private int gridZ; | ||||
|     private int playerSlot; | ||||
|     private boolean one; | ||||
| 
 | ||||
|     public MessageStoragePush() { | ||||
|     public MessageGridStoragePush() { | ||||
|     } | ||||
| 
 | ||||
|     public MessageStoragePush(int x, int y, int z, int slot, boolean one) { | ||||
|         this.x = x; | ||||
|         this.y = y; | ||||
|         this.z = z; | ||||
|         this.slot = slot; | ||||
|     public MessageGridStoragePush(int gridX, int gridY, int gridZ, int playerSlot, boolean one) { | ||||
|         this.gridX = gridX; | ||||
|         this.gridY = gridY; | ||||
|         this.gridZ = gridZ; | ||||
|         this.playerSlot = playerSlot; | ||||
|         this.one = one; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         x = buf.readInt(); | ||||
|         y = buf.readInt(); | ||||
|         z = buf.readInt(); | ||||
|         slot = buf.readInt(); | ||||
|         gridX = buf.readInt(); | ||||
|         gridY = buf.readInt(); | ||||
|         gridZ = buf.readInt(); | ||||
|         playerSlot = buf.readInt(); | ||||
|         one = buf.readBoolean(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         buf.writeInt(x); | ||||
|         buf.writeInt(y); | ||||
|         buf.writeInt(z); | ||||
|         buf.writeInt(slot); | ||||
|         buf.writeInt(gridX); | ||||
|         buf.writeInt(gridY); | ||||
|         buf.writeInt(gridZ); | ||||
|         buf.writeInt(playerSlot); | ||||
|         buf.writeBoolean(one); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void handle(MessageStoragePush message, EntityPlayerMP player) { | ||||
|         TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z)); | ||||
|     public void handle(MessageGridStoragePush message, EntityPlayerMP player) { | ||||
|         TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.gridX, message.gridY, message.gridZ)); | ||||
| 
 | ||||
|         if (tile instanceof TileController && ((TileController) tile).isActive()) { | ||||
|             TileController controller = (TileController) tile; | ||||
|         if (tile instanceof TileGrid && ((TileGrid) tile).isConnected()) { | ||||
|             TileController controller = ((TileGrid) tile).getController(); | ||||
| 
 | ||||
|             ItemStack stack; | ||||
| 
 | ||||
|             if (message.slot == -1) { | ||||
|             if (message.playerSlot == -1) { | ||||
|                 stack = player.inventory.getItemStack().copy(); | ||||
| 
 | ||||
|                 if (message.one) { | ||||
|                     stack.stackSize = 1; | ||||
|                 } | ||||
|             } else { | ||||
|                 stack = player.inventory.getStackInSlot(message.slot); | ||||
|                 stack = player.inventory.getStackInSlot(message.playerSlot); | ||||
|             } | ||||
| 
 | ||||
|             if (stack != null) { | ||||
|                 boolean success = controller.push(stack); | ||||
| 
 | ||||
|                 if (success) { | ||||
|                     if (message.slot == -1) { | ||||
|                     if (message.playerSlot == -1) { | ||||
|                         if (message.one) { | ||||
|                             player.inventory.getItemStack().stackSize--; | ||||
| 
 | ||||
| @@ -81,7 +82,7 @@ public class MessageStoragePush extends MessageHandlerPlayerToServer<MessageStor | ||||
| 
 | ||||
|                         player.updateHeldItem(); | ||||
|                     } else { | ||||
|                         player.inventory.setInventorySlotContents(message.slot, null); | ||||
|                         player.inventory.setInventorySlotContents(message.playerSlot, null); | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
| @@ -32,7 +32,7 @@ public class MessageTileUpdate implements IMessage, IMessageHandler<MessageTileU | ||||
|             tile = Minecraft.getMinecraft().theWorld.getTileEntity(new BlockPos(x, y, z)); | ||||
|  | ||||
|             if (tile instanceof INetworkTile) { | ||||
|                 ((INetworkTile) tile).fromBytes(buf); | ||||
|                 ((INetworkTile) tile).receiveData(buf); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -44,7 +44,7 @@ public class MessageTileUpdate implements IMessage, IMessageHandler<MessageTileU | ||||
|         buf.writeInt(tile.getPos().getZ()); | ||||
|  | ||||
|         if (tile instanceof INetworkTile) { | ||||
|             ((INetworkTile) tile).toBytes(buf); | ||||
|             ((INetworkTile) tile).sendData(buf); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -35,8 +35,8 @@ public class CommonProxy { | ||||
|     public void preInit(FMLPreInitializationEvent e) { | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageTileUpdate.class, MessageTileUpdate.class, 0, Side.CLIENT); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, 1, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageStoragePush.class, MessageStoragePush.class, 2, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageStoragePull.class, MessageStoragePull.class, 3, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageGridStoragePush.class, MessageGridStoragePush.class, 2, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageGridStoragePull.class, MessageGridStoragePull.class, 3, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageCompareUpdate.class, MessageCompareUpdate.class, 4, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageModeToggle.class, MessageModeToggle.class, 5, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageDetectorModeUpdate.class, MessageDetectorModeUpdate.class, 6, Side.SERVER); | ||||
| @@ -47,6 +47,7 @@ public class CommonProxy { | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageGridCraftingPush.class, MessageGridCraftingPush.class, 12, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageGridCraftingTransfer.class, MessageGridCraftingTransfer.class, 13, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageWirelessGridSettingsUpdate.class, MessageWirelessGridSettingsUpdate.class, 14, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageContainerUpdate.class, MessageContainerUpdate.class, 15, Side.CLIENT); | ||||
|  | ||||
|         NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler()); | ||||
|  | ||||
|   | ||||
| @@ -1,9 +1,16 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.inventory.Container; | ||||
|  | ||||
| public interface INetworkTile { | ||||
|     void fromBytes(ByteBuf buf); | ||||
|     void receiveData(ByteBuf buf); | ||||
|  | ||||
|     void toBytes(ByteBuf buf); | ||||
|     void sendData(ByteBuf buf); | ||||
|  | ||||
|     void receiveContainerData(ByteBuf buf); | ||||
|  | ||||
|     void sendContainerData(ByteBuf buf); | ||||
|  | ||||
|     Class<? extends Container> getContainer(); | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,8 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import net.minecraft.block.state.IBlockState; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.entity.player.EntityPlayerMP; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.network.NetworkManager; | ||||
| @@ -13,12 +15,13 @@ import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
| import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.network.MessageContainerUpdate; | ||||
| import refinedstorage.network.MessageTileUpdate; | ||||
|  | ||||
| public abstract class TileBase extends TileEntity implements ITickable { | ||||
|     public static final String NBT_DIRECTION = "Direction"; | ||||
|  | ||||
|     public static final int UPDATE_RANGE = 256; | ||||
|     public static final int UPDATE_RANGE = 32; | ||||
|  | ||||
|     private EnumFacing direction = EnumFacing.NORTH; | ||||
|  | ||||
| @@ -33,6 +36,12 @@ public abstract class TileBase extends TileEntity implements ITickable { | ||||
|                 TargetPoint target = new TargetPoint(worldObj.provider.getDimensionType().getId(), pos.getX(), pos.getY(), pos.getZ(), UPDATE_RANGE); | ||||
|  | ||||
|                 RefinedStorage.NETWORK.sendToAllAround(new MessageTileUpdate(this), target); | ||||
|  | ||||
|                 for (EntityPlayer player : worldObj.playerEntities) { | ||||
|                     if (((INetworkTile) this).getContainer() == player.openContainer.getClass()) { | ||||
|                         RefinedStorage.NETWORK.sendTo(new MessageContainerUpdate(this), (EntityPlayerMP) player); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -2,11 +2,13 @@ package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.item.ItemBlock; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import refinedstorage.container.ContainerConstructor; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.tile.config.ICompareConfig; | ||||
| import refinedstorage.util.InventoryUtils; | ||||
| @@ -33,7 +35,7 @@ public class TileConstructor extends TileMachine implements ICompareConfig { | ||||
|             Block tryingToPlace = ((ItemBlock) inventory.getStackInSlot(0).getItem()).getBlock(); | ||||
|  | ||||
|             if (tryingToPlace.canPlaceBlockAt(worldObj, front)) { | ||||
|                 ItemStack took = getController().take(inventory.getStackInSlot(0).copy(), compare); | ||||
|                 ItemStack took = controller.take(inventory.getStackInSlot(0).copy(), compare); | ||||
|  | ||||
|                 if (took != null) { | ||||
|                     worldObj.setBlockState(front, tryingToPlace.getStateFromMeta(took.getItemDamage()), 1 | 2); | ||||
| @@ -75,19 +77,24 @@ public class TileConstructor extends TileMachine implements ICompareConfig { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         compare = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(compare); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerConstructor.class; | ||||
|     } | ||||
|  | ||||
|     public IInventory getInventory() { | ||||
|         return inventory; | ||||
|     } | ||||
|   | ||||
| @@ -4,18 +4,22 @@ import cofh.api.energy.EnergyStorage; | ||||
| import cofh.api.energy.IEnergyReceiver; | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.EnumHand; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.RefinedStorageBlocks; | ||||
| import refinedstorage.RefinedStorageGui; | ||||
| import refinedstorage.RefinedStorageItems; | ||||
| import refinedstorage.block.BlockController; | ||||
| import refinedstorage.block.EnumControllerType; | ||||
| import refinedstorage.container.ContainerController; | ||||
| import refinedstorage.item.ItemWirelessGrid; | ||||
| import refinedstorage.storage.IStorage; | ||||
| import refinedstorage.storage.IStorageProvider; | ||||
| @@ -43,10 +47,11 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor | ||||
|     private EnergyStorage energy = new EnergyStorage(32000); | ||||
|     private int energyUsage; | ||||
|  | ||||
|     private boolean activeClientSide; | ||||
|  | ||||
|     private boolean destroyed = false; | ||||
|  | ||||
|     @SideOnly(Side.CLIENT) | ||||
|     private boolean activeClientSide; | ||||
|  | ||||
|     @Override | ||||
|     public void update() { | ||||
|         super.update(); | ||||
| @@ -374,10 +379,6 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor | ||||
|         return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, pos); | ||||
|     } | ||||
|  | ||||
|     public boolean isActiveClientSide() { | ||||
|         return activeClientSide; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public RedstoneMode getRedstoneMode() { | ||||
|         return redstoneMode; | ||||
| @@ -396,32 +397,34 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         activeClientSide = buf.readBoolean(); | ||||
|  | ||||
|     public void receiveData(ByteBuf buf) { | ||||
|         int lastEnergy = energy.getEnergyStored(); | ||||
|  | ||||
|         activeClientSide = buf.readBoolean(); | ||||
|  | ||||
|         energy.setEnergyStored(buf.readInt()); | ||||
|  | ||||
|         if (lastEnergy != energy.getEnergyStored()) { | ||||
|             worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 2 | 4); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void sendData(ByteBuf buf) { | ||||
|         buf.writeBoolean(isActive()); | ||||
|  | ||||
|         buf.writeInt(energy.getEnergyStored()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         energyUsage = buf.readInt(); | ||||
|  | ||||
|         redstoneMode = RedstoneMode.getById(buf.readInt()); | ||||
|  | ||||
|         itemGroups.clear(); | ||||
|  | ||||
|         int size = buf.readInt(); | ||||
|  | ||||
|         for (int i = 0; i < size; ++i) { | ||||
|             itemGroups.add(new ItemGroup(buf)); | ||||
|         } | ||||
|  | ||||
|         machines.clear(); | ||||
|  | ||||
|         size = buf.readInt(); | ||||
|         int size = buf.readInt(); | ||||
|  | ||||
|         for (int i = 0; i < size; ++i) { | ||||
|             TileEntity tile = worldObj.getTileEntity(new BlockPos(buf.readInt(), buf.readInt(), buf.readInt())); | ||||
| @@ -433,20 +436,11 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         buf.writeBoolean(isActive()); | ||||
|  | ||||
|         buf.writeInt(energy.getEnergyStored()); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         buf.writeInt(energyUsage); | ||||
|  | ||||
|         buf.writeInt(redstoneMode.id); | ||||
|  | ||||
|         buf.writeInt(itemGroups.size()); | ||||
|  | ||||
|         for (ItemGroup group : itemGroups) { | ||||
|             group.toBytes(buf, itemGroups.indexOf(group)); | ||||
|         } | ||||
|  | ||||
|         buf.writeInt(machines.size()); | ||||
|  | ||||
|         for (TileMachine machine : machines) { | ||||
| @@ -455,4 +449,13 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor | ||||
|             buf.writeInt(machine.getPos().getZ()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public boolean isActiveClientSide() { | ||||
|         return activeClientSide; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerController.class; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,11 +3,13 @@ package refinedstorage.tile; | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.state.IBlockState; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.item.Item; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import refinedstorage.container.ContainerDestructor; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.tile.config.ICompareConfig; | ||||
| import refinedstorage.tile.config.IModeConfig; | ||||
| @@ -47,7 +49,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode | ||||
|                     worldObj.setBlockToAir(front); | ||||
|  | ||||
|                     for (ItemStack drop : drops) { | ||||
|                         if (!getController().push(drop)) { | ||||
|                         if (!controller.push(drop)) { | ||||
|                             InventoryUtils.dropStack(worldObj, drop, front.getX(), front.getY(), front.getZ()); | ||||
|                         } | ||||
|                     } | ||||
| @@ -118,21 +120,25 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         compare = buf.readInt(); | ||||
|         mode = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(compare); | ||||
|         buf.writeInt(mode); | ||||
|     } | ||||
|  | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerDestructor.class; | ||||
|     } | ||||
|  | ||||
|     public IInventory getInventory() { | ||||
|         return inventory; | ||||
|     } | ||||
|   | ||||
| @@ -1,10 +1,12 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import refinedstorage.RefinedStorageBlocks; | ||||
| import refinedstorage.container.ContainerDetector; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.storage.ItemGroup; | ||||
| import refinedstorage.tile.config.ICompareConfig; | ||||
| @@ -50,7 +52,7 @@ public class TileDetector extends TileMachine implements ICompareConfig { | ||||
|             if (slot != null) { | ||||
|                 boolean foundAny = false; | ||||
|  | ||||
|                 for (ItemGroup group : getController().getItemGroups()) { | ||||
|                 for (ItemGroup group : controller.getItemGroups()) { | ||||
|                     if (group.compare(slot, compare)) { | ||||
|                         foundAny = true; | ||||
|  | ||||
| @@ -156,12 +158,8 @@ public class TileDetector extends TileMachine implements ICompareConfig { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|  | ||||
|         compare = buf.readInt(); | ||||
|         mode = buf.readInt(); | ||||
|         amount = buf.readInt(); | ||||
|     public void receiveData(ByteBuf buf) { | ||||
|         super.receiveData(buf); | ||||
|  | ||||
|         boolean lastPowered = powered; | ||||
|  | ||||
| @@ -173,13 +171,33 @@ public class TileDetector extends TileMachine implements ICompareConfig { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendData(ByteBuf buf) { | ||||
|         super.sendData(buf); | ||||
|  | ||||
|         buf.writeBoolean(powered); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(compare); | ||||
|         buf.writeInt(mode); | ||||
|         buf.writeInt(amount); | ||||
|         buf.writeBoolean(powered); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         compare = buf.readInt(); | ||||
|         mode = buf.readInt(); | ||||
|         amount = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerDetector.class; | ||||
|     } | ||||
|  | ||||
|     public IInventory getInventory() { | ||||
|   | ||||
| @@ -2,12 +2,14 @@ package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.util.text.ITextComponent; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.block.EnumStorageType; | ||||
| import refinedstorage.container.ContainerDiskDrive; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.network.MessagePriorityUpdate; | ||||
| import refinedstorage.storage.*; | ||||
| @@ -89,8 +91,8 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(priority); | ||||
|         buf.writeInt(compare); | ||||
| @@ -98,14 +100,19 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         priority = buf.readInt(); | ||||
|         compare = buf.readInt(); | ||||
|         mode = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerDiskDrive.class; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int getCompare() { | ||||
|         return compare; | ||||
|   | ||||
| @@ -1,11 +1,13 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.tileentity.TileEntityHopper; | ||||
| import refinedstorage.container.ContainerExporter; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.tile.config.ICompareConfig; | ||||
| import refinedstorage.util.InventoryUtils; | ||||
| @@ -39,13 +41,13 @@ public class TileExporter extends TileMachine implements ICompareConfig { | ||||
|                         ItemStack toTake = slot.copy(); | ||||
|                         toTake.stackSize = 1; | ||||
|  | ||||
|                         ItemStack took = getController().take(toTake, compare); | ||||
|                         ItemStack took = controller.take(toTake, compare); | ||||
|  | ||||
|                         if (took != null) { | ||||
|                             ItemStack remaining = TileEntityHopper.putStackInInventoryAllSlots(connectedInventory, took, getDirection().getOpposite()); | ||||
|  | ||||
|                             if (remaining != null) { | ||||
|                                 getController().push(remaining); | ||||
|                                 controller.push(remaining); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
| @@ -87,19 +89,24 @@ public class TileExporter extends TileMachine implements ICompareConfig { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         compare = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(compare); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerExporter.class; | ||||
|     } | ||||
|  | ||||
|     public IInventory getInventory() { | ||||
|         return inventory; | ||||
|     } | ||||
|   | ||||
| @@ -1,12 +1,14 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import powercrystals.minefactoryreloaded.api.IDeepStorageUnit; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.container.ContainerStorage; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.network.MessagePriorityUpdate; | ||||
| import refinedstorage.storage.IStorage; | ||||
| @@ -175,8 +177,8 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(priority); | ||||
|  | ||||
| @@ -197,8 +199,8 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         priority = buf.readInt(); | ||||
|         stored = buf.readInt(); | ||||
| @@ -206,6 +208,11 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | ||||
|         mode = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerStorage.class; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void readFromNBT(NBTTagCompound nbt) { | ||||
|         super.readFromNBT(nbt); | ||||
|   | ||||
| @@ -1,11 +1,13 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.inventory.ISidedInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import refinedstorage.container.ContainerImporter; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.tile.config.ICompareConfig; | ||||
| import refinedstorage.tile.config.IModeConfig; | ||||
| @@ -55,7 +57,7 @@ public class TileImporter extends TileMachine implements ICompareConfig, IModeCo | ||||
|                         toTake.stackSize = 1; | ||||
|  | ||||
|                         if (canImport(toTake) && sided.canExtractItem(availableSlot, toTake, getDirection().getOpposite())) { | ||||
|                             if (getController().push(toTake)) { | ||||
|                             if (controller.push(toTake)) { | ||||
|                                 sided.decrStackSize(availableSlot, 1); | ||||
|                                 sided.markDirty(); | ||||
|                             } | ||||
| @@ -82,7 +84,7 @@ public class TileImporter extends TileMachine implements ICompareConfig, IModeCo | ||||
|  | ||||
|                     // If we can't import and/ or push, move on (otherwise we stay on the same slot forever) | ||||
|                     if (canImport(toTake)) { | ||||
|                         if (getController().push(toTake)) { | ||||
|                         if (controller.push(toTake)) { | ||||
|                             inventory.decrStackSize(currentSlot, 1); | ||||
|                             inventory.markDirty(); | ||||
|                         } else { | ||||
| @@ -188,21 +190,26 @@ public class TileImporter extends TileMachine implements ICompareConfig, IModeCo | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         compare = buf.readInt(); | ||||
|         mode = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(compare); | ||||
|         buf.writeInt(mode); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerImporter.class; | ||||
|     } | ||||
|  | ||||
|     public IInventory getInventory() { | ||||
|         return inventory; | ||||
|     } | ||||
|   | ||||
| @@ -2,12 +2,14 @@ package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.inventory.ISidedInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.text.ITextComponent; | ||||
| import refinedstorage.container.ContainerInterface; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.tile.config.ICompareConfig; | ||||
| import refinedstorage.util.InventoryUtils; | ||||
| @@ -50,7 +52,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided | ||||
|                 ItemStack toPush = slot.copy(); | ||||
|                 toPush.stackSize = 1; | ||||
|  | ||||
|                 if (getController().push(toPush)) { | ||||
|                 if (controller.push(toPush)) { | ||||
|                     decrStackSize(currentSlot, 1); | ||||
|                 } | ||||
|             } | ||||
| @@ -65,7 +67,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided | ||||
|  | ||||
|                 if (got != null) { | ||||
|                     if (!InventoryUtils.compareStack(wanted, got, compare)) { | ||||
|                         if (getController().push(got)) { | ||||
|                         if (controller.push(got)) { | ||||
|                             inventory.setInventorySlotContents(i + 9, null); | ||||
|                         } | ||||
|                     } else { | ||||
| @@ -83,7 +85,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided | ||||
|                     ItemStack goingToTake = wanted.copy(); | ||||
|                     goingToTake.stackSize = needed; | ||||
|  | ||||
|                     ItemStack took = getController().take(goingToTake, compare); | ||||
|                     ItemStack took = controller.take(goingToTake, compare); | ||||
|  | ||||
|                     if (took != null) { | ||||
|                         if (got == null) { | ||||
| @@ -94,7 +96,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided | ||||
|                     } | ||||
|                 } | ||||
|             } else if (got != null) { | ||||
|                 if (getController().push(got)) { | ||||
|                 if (controller.push(got)) { | ||||
|                     inventory.setInventorySlotContents(i + 9, null); | ||||
|                 } | ||||
|             } | ||||
| @@ -122,19 +124,24 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         compare = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(compare); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerInterface.class; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int getSizeInventory() { | ||||
|         return inventory.getSizeInventory(); | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import refinedstorage.block.BlockMachine; | ||||
| @@ -11,47 +10,39 @@ import refinedstorage.tile.config.RedstoneMode; | ||||
| public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeConfig { | ||||
|     protected boolean connected = false; | ||||
|     protected RedstoneMode redstoneMode = RedstoneMode.IGNORE; | ||||
|  | ||||
|     private BlockPos controllerPosition; | ||||
|  | ||||
|     private Block originalBlock; | ||||
|     protected TileController controller; | ||||
|  | ||||
|     public void onConnected(TileController controller) { | ||||
|         if (worldObj != null && worldObj.getBlockState(pos).getBlock() == originalBlock) { | ||||
|         if (worldObj != null && worldObj.getBlockState(pos).getBlock() == blockType) { | ||||
|             markDirty(); | ||||
|  | ||||
|             connected = true; | ||||
|             this.connected = true; | ||||
|             this.controller = controller; | ||||
|  | ||||
|             worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true)); | ||||
|  | ||||
|             controllerPosition = controller.getPos(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void onDisconnected() { | ||||
|         if (worldObj != null && worldObj.getBlockState(pos).getBlock() == originalBlock) { | ||||
|         if (worldObj != null && worldObj.getBlockState(pos).getBlock() == blockType) { | ||||
|             markDirty(); | ||||
|  | ||||
|             connected = false; | ||||
|             this.connected = false; | ||||
|             this.controller = null; | ||||
|  | ||||
|             worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public TileController getController() { | ||||
|         return controller; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void update() { | ||||
|         if (worldObj == null) { | ||||
|             super.update(); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if (ticks == 0) { | ||||
|             originalBlock = worldObj.getBlockState(pos).getBlock(); | ||||
|         } | ||||
|  | ||||
|         super.update(); | ||||
|  | ||||
|         if (!worldObj.isRemote && isConnected()) { | ||||
|         if (worldObj != null && !worldObj.isRemote && isConnected()) { | ||||
|             updateMachine(); | ||||
|         } | ||||
|     } | ||||
| @@ -77,37 +68,30 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed | ||||
|         return pos; | ||||
|     } | ||||
|  | ||||
|     public TileController getController() { | ||||
|         return (TileController) worldObj.getTileEntity(controllerPosition); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|     public void receiveData(ByteBuf buf) { | ||||
|         boolean lastConnected = connected; | ||||
|  | ||||
|         connected = buf.readBoolean(); | ||||
|  | ||||
|         if (connected) { | ||||
|             controllerPosition = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt()); | ||||
|         } | ||||
|  | ||||
|         redstoneMode = RedstoneMode.getById(buf.readInt()); | ||||
|  | ||||
|         if (lastConnected != connected) { | ||||
|             // @TODO: make this work and use correct flags? | ||||
|             worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 2 | 4); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|     public void sendData(ByteBuf buf) { | ||||
|         buf.writeBoolean(connected); | ||||
|  | ||||
|         if (connected) { | ||||
|             buf.writeInt(controllerPosition.getX()); | ||||
|             buf.writeInt(controllerPosition.getY()); | ||||
|             buf.writeInt(controllerPosition.getZ()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         redstoneMode = RedstoneMode.getById(buf.readInt()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         buf.writeInt(redstoneMode.id); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import net.minecraft.inventory.Container; | ||||
| import refinedstorage.container.ContainerRelay; | ||||
| import refinedstorage.tile.config.RedstoneMode; | ||||
|  | ||||
| public class TileRelay extends TileMachine { | ||||
| @@ -15,4 +17,9 @@ public class TileRelay extends TileMachine { | ||||
|     @Override | ||||
|     public void updateMachine() { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerRelay.class; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.inventory.ISidedInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| @@ -10,6 +11,7 @@ import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.text.ITextComponent; | ||||
| import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||||
| import refinedstorage.container.ContainerSolderer; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.tile.solderer.ISoldererRecipe; | ||||
| import refinedstorage.tile.solderer.SoldererRegistry; | ||||
| @@ -112,8 +114,8 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         working = buf.readBoolean(); | ||||
|         progress = buf.readInt(); | ||||
| @@ -121,14 +123,19 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeBoolean(working); | ||||
|         buf.writeInt(progress); | ||||
|         buf.writeInt(recipe != null ? recipe.getDuration() : 0); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerSolderer.class; | ||||
|     } | ||||
|  | ||||
|     public boolean isWorking() { | ||||
|         return working; | ||||
|     } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| @@ -10,6 +11,7 @@ import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.RefinedStorageBlocks; | ||||
| import refinedstorage.block.BlockStorage; | ||||
| import refinedstorage.block.EnumStorageType; | ||||
| import refinedstorage.container.ContainerStorage; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.network.MessagePriorityUpdate; | ||||
| import refinedstorage.storage.*; | ||||
| @@ -95,8 +97,8 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(NBTStorage.getStored(tag)); | ||||
|         buf.writeInt(priority); | ||||
| @@ -105,8 +107,8 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         stored = buf.readInt(); | ||||
|         priority = buf.readInt(); | ||||
| @@ -114,6 +116,11 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora | ||||
|         mode = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerStorage.class; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addItems(List<ItemGroup> items) { | ||||
|         getStorage().addItems(items); | ||||
|   | ||||
| @@ -1,13 +1,19 @@ | ||||
| package refinedstorage.tile.grid; | ||||
|  | ||||
| import refinedstorage.block.EnumGridType; | ||||
| import refinedstorage.tile.TileController; | ||||
| import refinedstorage.storage.ItemGroup; | ||||
| import refinedstorage.tile.config.IRedstoneModeConfig; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| public interface IGrid { | ||||
|     EnumGridType getType(); | ||||
|  | ||||
|     TileController getController(); | ||||
|     List<ItemGroup> getItemGroups(); | ||||
|  | ||||
|     void onItemPush(int playerSlot, boolean one); | ||||
|  | ||||
|     void onItemPull(int id, int flags); | ||||
|  | ||||
|     int getSortingType(); | ||||
|  | ||||
|   | ||||
| @@ -8,6 +8,8 @@ import net.minecraft.inventory.InventoryCrafting; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.item.crafting.CraftingManager; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.RefinedStorageBlocks; | ||||
| import refinedstorage.block.BlockGrid; | ||||
| @@ -15,6 +17,9 @@ import refinedstorage.block.EnumGridType; | ||||
| import refinedstorage.container.ContainerGrid; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.network.MessageGridSettingsUpdate; | ||||
| import refinedstorage.network.MessageGridStoragePull; | ||||
| import refinedstorage.network.MessageGridStoragePush; | ||||
| import refinedstorage.storage.ItemGroup; | ||||
| import refinedstorage.tile.TileMachine; | ||||
| import refinedstorage.tile.config.IRedstoneModeConfig; | ||||
| import refinedstorage.util.InventoryUtils; | ||||
| @@ -54,6 +59,9 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|     private int sortingType = SORTING_TYPE_NAME; | ||||
|     private int searchBoxMode = SEARCH_BOX_MODE_NORMAL; | ||||
|  | ||||
|     @SideOnly(Side.CLIENT) | ||||
|     private List<ItemGroup> itemGroups = new ArrayList<ItemGroup>(); | ||||
|  | ||||
|     @Override | ||||
|     public int getEnergyUsage() { | ||||
|         return 4; | ||||
| @@ -71,6 +79,21 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|         return EnumGridType.NORMAL; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<ItemGroup> getItemGroups() { | ||||
|         return itemGroups; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onItemPush(int playerSlot, boolean one) { | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageGridStoragePush(getPos().getX(), getPos().getY(), getPos().getZ(), playerSlot, one)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onItemPull(int id, int flags) { | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageGridStoragePull(getPos().getX(), getPos().getY(), getPos().getZ(), id, flags)); | ||||
|     } | ||||
|  | ||||
|     public InventoryCrafting getCraftingInventory() { | ||||
|         return craftingInventory; | ||||
|     } | ||||
| @@ -92,7 +115,7 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|  | ||||
|                 if (slot != null) { | ||||
|                     if (slot.stackSize == 1 && isConnected()) { | ||||
|                         craftingInventory.setInventorySlotContents(i, getController().take(slot.copy())); | ||||
|                         craftingInventory.setInventorySlotContents(i, controller.take(slot.copy())); | ||||
|                     } else { | ||||
|                         craftingInventory.decrStackSize(i, 1); | ||||
|                     } | ||||
| @@ -124,7 +147,7 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|  | ||||
|         for (ItemStack craftedItem : craftedItemsList) { | ||||
|             if (!player.inventory.addItemStackToInventory(craftedItem.copy())) { | ||||
|                 if (isConnected() && getController().push(craftedItem.copy())) { | ||||
|                 if (isConnected() && controller.push(craftedItem.copy())) { | ||||
|                     // NO OP | ||||
|                 } else { | ||||
|                     InventoryUtils.dropStack(player.worldObj, craftedItem, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ()); | ||||
| @@ -139,7 +162,7 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|                 ItemStack slot = craftingInventory.getStackInSlot(i); | ||||
|  | ||||
|                 if (slot != null) { | ||||
|                     if (!getController().push(slot)) { | ||||
|                     if (!controller.push(slot)) { | ||||
|                         return; | ||||
|                     } | ||||
|  | ||||
| @@ -152,7 +175,7 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|                     ItemStack[] possibilities = recipe[i]; | ||||
|  | ||||
|                     for (ItemStack possibility : possibilities) { | ||||
|                         ItemStack took = getController().take(possibility); | ||||
|                         ItemStack took = controller.take(possibility); | ||||
|  | ||||
|                         if (took != null) { | ||||
|                             craftingInventory.setInventorySlotContents(i, possibility); | ||||
| @@ -244,21 +267,44 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         super.toBytes(buf); | ||||
|     public void sendContainerData(ByteBuf buf) { | ||||
|         super.sendContainerData(buf); | ||||
|  | ||||
|         buf.writeInt(sortingDirection); | ||||
|         buf.writeInt(sortingType); | ||||
|         buf.writeInt(searchBoxMode); | ||||
|  | ||||
|         if (connected) { | ||||
|             buf.writeInt(controller.getItemGroups().size()); | ||||
|  | ||||
|             for (ItemGroup group : controller.getItemGroups()) { | ||||
|                 group.toBytes(buf, controller.getItemGroups().indexOf(group)); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         super.fromBytes(buf); | ||||
|     public void receiveContainerData(ByteBuf buf) { | ||||
|         super.receiveContainerData(buf); | ||||
|  | ||||
|         sortingDirection = buf.readInt(); | ||||
|         sortingType = buf.readInt(); | ||||
|         searchBoxMode = buf.readInt(); | ||||
|  | ||||
|         itemGroups.clear(); | ||||
|  | ||||
|         if (connected) { | ||||
|             int size = buf.readInt(); | ||||
|  | ||||
|             for (int i = 0; i < size; ++i) { | ||||
|                 itemGroups.add(new ItemGroup(buf)); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Class<? extends Container> getContainer() { | ||||
|         return ContainerGrid.class; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -1,16 +1,17 @@ | ||||
| package refinedstorage.tile.grid; | ||||
|  | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumHand; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.block.EnumGridType; | ||||
| import refinedstorage.item.ItemWirelessGrid; | ||||
| import refinedstorage.network.MessageWirelessGridSettingsUpdate; | ||||
| import refinedstorage.tile.TileController; | ||||
| import refinedstorage.storage.ItemGroup; | ||||
| import refinedstorage.tile.config.IRedstoneModeConfig; | ||||
| import refinedstorage.util.HandUtils; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| public class WirelessGrid implements IGrid { | ||||
|     private ItemStack stack; | ||||
| @@ -34,13 +35,19 @@ public class WirelessGrid implements IGrid { | ||||
|         return EnumGridType.NORMAL; | ||||
|     } | ||||
|  | ||||
|     public TileEntity getBoundTile() { | ||||
|         return world.getTileEntity(new BlockPos(ItemWirelessGrid.getX(stack), ItemWirelessGrid.getY(stack), ItemWirelessGrid.getZ(stack))); | ||||
|     @Override | ||||
|     public List<ItemGroup> getItemGroups() { | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public TileController getController() { | ||||
|         return (TileController) getBoundTile(); | ||||
|     public void onItemPush(int playerSlot, boolean one) { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onItemPull(int id, int flags) { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -60,21 +67,21 @@ public class WirelessGrid implements IGrid { | ||||
|  | ||||
|     @Override | ||||
|     public void onSortingTypeChanged(int type) { | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(hand == EnumHand.OFF_HAND ? 1 : 0, getSortingDirection(), type, getSearchBoxMode())); | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(HandUtils.getIdFromHand(hand), getSortingDirection(), type, getSearchBoxMode())); | ||||
|  | ||||
|         this.sortingType = type; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onSortingDirectionChanged(int direction) { | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(hand == EnumHand.OFF_HAND ? 1 : 0, direction, getSortingType(), getSearchBoxMode())); | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(HandUtils.getIdFromHand(hand), direction, getSortingType(), getSearchBoxMode())); | ||||
|  | ||||
|         this.sortingDirection = direction; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onSearchBoxModeChanged(int searchBoxMode) { | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(hand == EnumHand.OFF_HAND ? 1 : 0, getSortingDirection(), getSortingType(), searchBoxMode)); | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(HandUtils.getIdFromHand(hand), getSortingDirection(), getSortingType(), searchBoxMode)); | ||||
|  | ||||
|         this.searchBoxMode = searchBoxMode; | ||||
|     } | ||||
| @@ -86,6 +93,6 @@ public class WirelessGrid implements IGrid { | ||||
|  | ||||
|     @Override | ||||
|     public boolean isConnected() { | ||||
|         return getBoundTile() instanceof TileController && getController().isActiveClientSide(); | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge