Fixed grid performance by not sending grid data so often
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
# Refined Storage Changelog
|
# Refined Storage Changelog
|
||||||
|
|
||||||
### 0.7.3
|
### 0.7.3
|
||||||
|
**Bugfixes**
|
||||||
|
- Fixed grid performance by not sending grid data so often
|
||||||
|
|
||||||
**Features**
|
**Features**
|
||||||
- Crafting tasks are now sorted from new to old in the Crafting Monitor
|
- Crafting tasks are now sorted from new to old in the Crafting Monitor
|
||||||
|
|
||||||
|
@@ -61,6 +61,8 @@ public class BlockGrid extends BlockMachine {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
|
((TileGrid) world.getTileEntity(pos)).onGridOpened(player);
|
||||||
|
|
||||||
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.GRID, world, pos.getX(), pos.getY(), pos.getZ());
|
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.GRID, world, pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -74,8 +74,8 @@ public class ContainerGrid extends ContainerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileGrid getGrid() {
|
public IGrid getGrid() {
|
||||||
return (TileGrid) grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SlotGridCrafting> getCraftingSlots() {
|
public List<SlotGridCrafting> getCraftingSlots() {
|
||||||
|
@@ -42,7 +42,7 @@ public class MessageGridCraftingShift extends MessageHandlerPlayerToServer<Messa
|
|||||||
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
|
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
|
||||||
|
|
||||||
if (tile instanceof TileGrid && ((TileGrid) tile).getType() == EnumGridType.CRAFTING && player.openContainer instanceof ContainerGrid) {
|
if (tile instanceof TileGrid && ((TileGrid) tile).getType() == EnumGridType.CRAFTING && player.openContainer instanceof ContainerGrid) {
|
||||||
((ContainerGrid) player.openContainer).getGrid().onCraftedShift((ContainerGrid) player.openContainer, player);
|
((TileGrid) ((ContainerGrid) player.openContainer).getGrid()).onCraftedShift((ContainerGrid) player.openContainer, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,7 @@ public class MessageGridCraftingTransfer extends MessageHandlerPlayerToServer<Me
|
|||||||
@Override
|
@Override
|
||||||
public void handle(MessageGridCraftingTransfer message, EntityPlayerMP player) {
|
public void handle(MessageGridCraftingTransfer message, EntityPlayerMP player) {
|
||||||
if (player.openContainer instanceof ContainerGrid) {
|
if (player.openContainer instanceof ContainerGrid) {
|
||||||
TileGrid grid = ((ContainerGrid) player.openContainer).getGrid();
|
TileGrid grid = (TileGrid) ((ContainerGrid) player.openContainer).getGrid();
|
||||||
|
|
||||||
if (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) {
|
if (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) {
|
||||||
ItemStack[][] actualRecipe = new ItemStack[9][];
|
ItemStack[][] actualRecipe = new ItemStack[9][];
|
||||||
|
55
src/main/java/refinedstorage/network/MessageGridItems.java
Executable file
55
src/main/java/refinedstorage/network/MessageGridItems.java
Executable file
@@ -0,0 +1,55 @@
|
|||||||
|
package refinedstorage.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
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.container.ContainerGrid;
|
||||||
|
import refinedstorage.storage.ItemGroup;
|
||||||
|
import refinedstorage.tile.controller.TileController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MessageGridItems implements IMessage, IMessageHandler<MessageGridItems, IMessage> {
|
||||||
|
private TileController controller;
|
||||||
|
private List<ItemGroup> groups = new ArrayList<ItemGroup>();
|
||||||
|
|
||||||
|
public MessageGridItems() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageGridItems(TileController controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
int size = buf.readInt();
|
||||||
|
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
groups.add(new ItemGroup(buf));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeInt(controller.getItemGroups().size());
|
||||||
|
|
||||||
|
for (int i = 0; i < controller.getItemGroups().size(); ++i) {
|
||||||
|
controller.getItemGroups().get(i).toBytes(buf, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMessage onMessage(MessageGridItems message, MessageContext ctx) {
|
||||||
|
Container container = Minecraft.getMinecraft().thePlayer.openContainer;
|
||||||
|
|
||||||
|
if (container instanceof ContainerGrid) {
|
||||||
|
((ContainerGrid) container).getGrid().setItemGroups(message.groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,47 +0,0 @@
|
|||||||
package refinedstorage.network;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
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.storage.ItemGroup;
|
|
||||||
import refinedstorage.tile.controller.TileController;
|
|
||||||
import refinedstorage.tile.grid.WirelessGrid;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MessageWirelessGridItems implements IMessage, IMessageHandler<MessageWirelessGridItems, IMessage> {
|
|
||||||
private TileController controller;
|
|
||||||
|
|
||||||
public MessageWirelessGridItems() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageWirelessGridItems(TileController controller) {
|
|
||||||
this.controller = controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
int size = buf.readInt();
|
|
||||||
|
|
||||||
List<ItemGroup> groups = new ArrayList<ItemGroup>();
|
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
groups.add(new ItemGroup(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
WirelessGrid.ITEM_GROUPS = groups;
|
|
||||||
WirelessGrid.LAST_ITEM_GROUP_UPDATE = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toBytes(ByteBuf buf) {
|
|
||||||
controller.writeItemGroups(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMessage onMessage(MessageWirelessGridItems message, MessageContext ctx) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -50,7 +50,6 @@ public class CommonProxy {
|
|||||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingPush.class, MessageGridCraftingPush.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingPush.class, MessageGridCraftingPush.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingTransfer.class, MessageGridCraftingTransfer.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingTransfer.class, MessageGridCraftingTransfer.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridSettingsUpdate.class, MessageWirelessGridSettingsUpdate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridSettingsUpdate.class, MessageWirelessGridSettingsUpdate.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridItems.class, MessageWirelessGridItems.class, id++, Side.CLIENT);
|
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridStoragePush.class, MessageWirelessGridStoragePush.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridStoragePush.class, MessageWirelessGridStoragePush.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridStoragePull.class, MessageWirelessGridStoragePull.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridStoragePull.class, MessageWirelessGridStoragePull.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingShift.class, MessageGridCraftingShift.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingShift.class, MessageGridCraftingShift.class, id++, Side.SERVER);
|
||||||
@@ -58,6 +57,7 @@ public class CommonProxy {
|
|||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridCraftingStart.class, MessageWirelessGridCraftingStart.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridCraftingStart.class, MessageWirelessGridCraftingStart.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageCraftingMonitorCancel.class, MessageCraftingMonitorCancel.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageCraftingMonitorCancel.class, MessageCraftingMonitorCancel.class, id++, Side.SERVER);
|
||||||
|
RefinedStorage.NETWORK.registerMessage(MessageGridItems.class, MessageGridItems.class, id++, Side.CLIENT);
|
||||||
|
|
||||||
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
||||||
|
|
||||||
|
@@ -4,6 +4,8 @@ import cofh.api.energy.EnergyStorage;
|
|||||||
import cofh.api.energy.IEnergyReceiver;
|
import cofh.api.energy.IEnergyReceiver;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -12,12 +14,15 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.RefinedStorageBlocks;
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.block.BlockController;
|
import refinedstorage.block.BlockController;
|
||||||
import refinedstorage.block.EnumControllerType;
|
import refinedstorage.block.EnumControllerType;
|
||||||
import refinedstorage.container.ContainerController;
|
import refinedstorage.container.ContainerController;
|
||||||
|
import refinedstorage.container.ContainerGrid;
|
||||||
import refinedstorage.item.ItemPattern;
|
import refinedstorage.item.ItemPattern;
|
||||||
|
import refinedstorage.network.MessageGridItems;
|
||||||
import refinedstorage.storage.IStorage;
|
import refinedstorage.storage.IStorage;
|
||||||
import refinedstorage.storage.IStorageProvider;
|
import refinedstorage.storage.IStorageProvider;
|
||||||
import refinedstorage.storage.ItemGroup;
|
import refinedstorage.storage.ItemGroup;
|
||||||
@@ -73,6 +78,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
private int wirelessGridRange;
|
private int wirelessGridRange;
|
||||||
|
|
||||||
private boolean couldRun;
|
private boolean couldRun;
|
||||||
|
private boolean syncing;
|
||||||
|
|
||||||
private long lastEnergyUpdate;
|
private long lastEnergyUpdate;
|
||||||
|
|
||||||
@@ -163,55 +169,6 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void syncMachines() {
|
|
||||||
this.wirelessGridRange = 0;
|
|
||||||
this.energyUsage = 0;
|
|
||||||
this.storages.clear();
|
|
||||||
this.patterns.clear();
|
|
||||||
|
|
||||||
for (TileMachine machine : machines) {
|
|
||||||
if (!machine.mayUpdate()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (machine instanceof TileWirelessTransmitter) {
|
|
||||||
this.wirelessGridRange += ((TileWirelessTransmitter) machine).getRange();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (machine instanceof IStorageProvider) {
|
|
||||||
((IStorageProvider) machine).provide(storages);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (machine instanceof TileCrafter) {
|
|
||||||
TileCrafter crafter = (TileCrafter) machine;
|
|
||||||
|
|
||||||
for (int i = 0; i < TileCrafter.PATTERN_SLOTS; ++i) {
|
|
||||||
ItemStack pattern = crafter.getPatterns().getStackInSlot(i);
|
|
||||||
|
|
||||||
if (pattern != null && ItemPattern.isValid(pattern)) {
|
|
||||||
patterns.add(new CraftingPattern(crafter.getPos().getX(), crafter.getPos().getY(), crafter.getPos().getZ(), ItemPattern.isProcessing(pattern), ItemPattern.getInputs(pattern), ItemPattern.getOutputs(pattern)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.energyUsage += machine.getEnergyUsage();
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(storages, new Comparator<IStorage>() {
|
|
||||||
@Override
|
|
||||||
public int compare(IStorage left, IStorage right) {
|
|
||||||
if (left.getPriority() == right.getPriority()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (left.getPriority() > right.getPriority()) ? -1 : 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
syncItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void addMachine(TileMachine machine) {
|
public void addMachine(TileMachine machine) {
|
||||||
machinesToAdd.add(machine);
|
machinesToAdd.add(machine);
|
||||||
}
|
}
|
||||||
@@ -252,14 +209,6 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
return itemGroups;
|
return itemGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeItemGroups(ByteBuf buf) {
|
|
||||||
buf.writeInt(itemGroups.size());
|
|
||||||
|
|
||||||
for (ItemGroup group : itemGroups) {
|
|
||||||
group.toBytes(buf, itemGroups.indexOf(group));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ICraftingTask> getCraftingTasks() {
|
public List<ICraftingTask> getCraftingTasks() {
|
||||||
return craftingTasks;
|
return craftingTasks;
|
||||||
}
|
}
|
||||||
@@ -310,7 +259,58 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void syncMachines() {
|
||||||
|
this.wirelessGridRange = 0;
|
||||||
|
this.energyUsage = 0;
|
||||||
|
this.storages.clear();
|
||||||
|
this.patterns.clear();
|
||||||
|
|
||||||
|
for (TileMachine machine : machines) {
|
||||||
|
if (!machine.mayUpdate()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (machine instanceof TileWirelessTransmitter) {
|
||||||
|
this.wirelessGridRange += ((TileWirelessTransmitter) machine).getRange();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (machine instanceof IStorageProvider) {
|
||||||
|
((IStorageProvider) machine).provide(storages);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (machine instanceof TileCrafter) {
|
||||||
|
TileCrafter crafter = (TileCrafter) machine;
|
||||||
|
|
||||||
|
for (int i = 0; i < TileCrafter.PATTERN_SLOTS; ++i) {
|
||||||
|
ItemStack pattern = crafter.getPatterns().getStackInSlot(i);
|
||||||
|
|
||||||
|
if (pattern != null && ItemPattern.isValid(pattern)) {
|
||||||
|
patterns.add(new CraftingPattern(crafter.getPos().getX(), crafter.getPos().getY(), crafter.getPos().getZ(), ItemPattern.isProcessing(pattern), ItemPattern.getInputs(pattern), ItemPattern.getOutputs(pattern)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.energyUsage += machine.getEnergyUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(storages, new Comparator<IStorage>() {
|
||||||
|
@Override
|
||||||
|
public int compare(IStorage left, IStorage right) {
|
||||||
|
if (left.getPriority() == right.getPriority()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (left.getPriority() > right.getPriority()) ? -1 : 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
syncItems();
|
||||||
|
syncItemsWithClients();
|
||||||
|
}
|
||||||
|
|
||||||
private void syncItems() {
|
private void syncItems() {
|
||||||
|
this.syncing = true;
|
||||||
|
|
||||||
itemGroups.clear();
|
itemGroups.clear();
|
||||||
|
|
||||||
for (IStorage storage : storages) {
|
for (IStorage storage : storages) {
|
||||||
@@ -360,6 +360,22 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
}
|
}
|
||||||
|
|
||||||
itemGroups.removeAll(combinedGroups);
|
itemGroups.removeAll(combinedGroups);
|
||||||
|
|
||||||
|
this.syncing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void syncItemsWithClients() {
|
||||||
|
if (!syncing) {
|
||||||
|
for (EntityPlayer player : worldObj.playerEntities) {
|
||||||
|
if (player.openContainer.getClass() == ContainerGrid.class) {
|
||||||
|
syncItemsWithClient((EntityPlayerMP) player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void syncItemsWithClient(EntityPlayerMP player) {
|
||||||
|
RefinedStorage.NETWORK.sendTo(new MessageGridItems(this), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean push(ItemStack stack) {
|
public boolean push(ItemStack stack) {
|
||||||
@@ -368,6 +384,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
storage.push(stack);
|
storage.push(stack);
|
||||||
|
|
||||||
syncItems();
|
syncItems();
|
||||||
|
syncItemsWithClients();
|
||||||
|
|
||||||
for (int i = 0; i < stack.stackSize; ++i) {
|
for (int i = 0; i < stack.stackSize; ++i) {
|
||||||
if (!craftingTasks.empty()) {
|
if (!craftingTasks.empty()) {
|
||||||
@@ -416,6 +433,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
|
|
||||||
if (newStack != null) {
|
if (newStack != null) {
|
||||||
syncItems();
|
syncItems();
|
||||||
|
syncItemsWithClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
return newStack;
|
return newStack;
|
||||||
|
@@ -9,7 +9,6 @@ import refinedstorage.RefinedStorageGui;
|
|||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.item.ItemWirelessGrid;
|
import refinedstorage.item.ItemWirelessGrid;
|
||||||
import refinedstorage.network.MessageWirelessGridItems;
|
|
||||||
import refinedstorage.tile.grid.WirelessGridConsumer;
|
import refinedstorage.tile.grid.WirelessGridConsumer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -37,10 +36,6 @@ public class WirelessGridHandler {
|
|||||||
|
|
||||||
if (!RefinedStorageUtils.compareStack(consumer.getWirelessGrid(), consumer.getPlayer().getHeldItem(consumer.getHand()))) {
|
if (!RefinedStorageUtils.compareStack(consumer.getWirelessGrid(), consumer.getPlayer().getHeldItem(consumer.getHand()))) {
|
||||||
consumer.getPlayer().closeScreen(); // This will call onContainerClosed on the Container and remove it from the list
|
consumer.getPlayer().closeScreen(); // This will call onContainerClosed on the Container and remove it from the list
|
||||||
} else {
|
|
||||||
if (controller.mayRun()) {
|
|
||||||
RefinedStorage.NETWORK.sendTo(new MessageWirelessGridItems(controller), (EntityPlayerMP) consumer.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +49,8 @@ public class WirelessGridHandler {
|
|||||||
|
|
||||||
consumers.add(new WirelessGridConsumer(player, hand, player.getHeldItem(hand)));
|
consumers.add(new WirelessGridConsumer(player, hand, player.getHeldItem(hand)));
|
||||||
|
|
||||||
|
controller.syncItemsWithClient((EntityPlayerMP) player);
|
||||||
|
|
||||||
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.WIRELESS_GRID, controller.getWorld(), RefinedStorageUtils.getIdFromHand(hand), 0, 0);
|
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.WIRELESS_GRID, controller.getWorld(), RefinedStorageUtils.getIdFromHand(hand), 0, 0);
|
||||||
|
|
||||||
drainEnergy(player, ItemWirelessGrid.USAGE_OPEN);
|
drainEnergy(player, ItemWirelessGrid.USAGE_OPEN);
|
||||||
@@ -100,4 +97,8 @@ public class WirelessGridHandler {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<WirelessGridConsumer> getConsumers() {
|
||||||
|
return consumers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,8 @@ public interface IGrid {
|
|||||||
|
|
||||||
List<ItemGroup> getItemGroups();
|
List<ItemGroup> getItemGroups();
|
||||||
|
|
||||||
|
void setItemGroups(List<ItemGroup> groups);
|
||||||
|
|
||||||
void onItemPush(int playerSlot, boolean one);
|
void onItemPush(int playerSlot, boolean one);
|
||||||
|
|
||||||
void onItemPull(int id, int flags);
|
void onItemPull(int id, int flags);
|
||||||
|
@@ -2,6 +2,7 @@ package refinedstorage.tile.grid;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.inventory.*;
|
import net.minecraft.inventory.*;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.CraftingManager;
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
@@ -91,6 +92,17 @@ public class TileGrid extends TileMachine implements IGrid {
|
|||||||
return itemGroups;
|
return itemGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItemGroups(List<ItemGroup> itemGroups) {
|
||||||
|
this.itemGroups = itemGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onGridOpened(EntityPlayer player) {
|
||||||
|
if (isConnected()) {
|
||||||
|
controller.syncItemsWithClient((EntityPlayerMP) player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemPush(int playerSlot, boolean one) {
|
public void onItemPush(int playerSlot, boolean one) {
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageGridStoragePush(getPos().getX(), getPos().getY(), getPos().getZ(), playerSlot, one));
|
RefinedStorage.NETWORK.sendToServer(new MessageGridStoragePush(getPos().getX(), getPos().getY(), getPos().getZ(), playerSlot, one));
|
||||||
@@ -335,12 +347,6 @@ public class TileGrid extends TileMachine implements IGrid {
|
|||||||
buf.writeInt(sortingDirection);
|
buf.writeInt(sortingDirection);
|
||||||
buf.writeInt(sortingType);
|
buf.writeInt(sortingType);
|
||||||
buf.writeInt(searchBoxMode);
|
buf.writeInt(searchBoxMode);
|
||||||
|
|
||||||
if (connected) {
|
|
||||||
controller.writeItemGroups(buf);
|
|
||||||
} else {
|
|
||||||
buf.writeInt(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -350,16 +356,6 @@ public class TileGrid extends TileMachine implements IGrid {
|
|||||||
sortingDirection = buf.readInt();
|
sortingDirection = buf.readInt();
|
||||||
sortingType = buf.readInt();
|
sortingType = buf.readInt();
|
||||||
searchBoxMode = buf.readInt();
|
searchBoxMode = buf.readInt();
|
||||||
|
|
||||||
List<ItemGroup> groups = new ArrayList<ItemGroup>();
|
|
||||||
|
|
||||||
int size = buf.readInt();
|
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
groups.add(new ItemGroup(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
itemGroups = groups;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -21,14 +21,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WirelessGrid implements IGrid {
|
public class WirelessGrid implements IGrid {
|
||||||
public static long LAST_ITEM_GROUP_UPDATE = 0;
|
|
||||||
public static List<ItemGroup> ITEM_GROUPS = new ArrayList<ItemGroup>();
|
|
||||||
|
|
||||||
private ItemStack stack;
|
private ItemStack stack;
|
||||||
private EnumHand hand;
|
private EnumHand hand;
|
||||||
private int sortingType;
|
private int sortingType;
|
||||||
private int sortingDirection;
|
private int sortingDirection;
|
||||||
private int searchBoxMode;
|
private int searchBoxMode;
|
||||||
|
private List<ItemGroup> itemGroups = new ArrayList<ItemGroup>();
|
||||||
|
private long lastUpdate;
|
||||||
|
|
||||||
public WirelessGrid(ItemStack stack, EnumHand hand) {
|
public WirelessGrid(ItemStack stack, EnumHand hand) {
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
@@ -45,7 +44,13 @@ public class WirelessGrid implements IGrid {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemGroup> getItemGroups() {
|
public List<ItemGroup> getItemGroups() {
|
||||||
return ITEM_GROUPS;
|
return itemGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItemGroups(List<ItemGroup> groups) {
|
||||||
|
this.itemGroups = groups;
|
||||||
|
this.lastUpdate = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,6 +119,6 @@ public class WirelessGrid implements IGrid {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
return System.currentTimeMillis() - LAST_ITEM_GROUP_UPDATE < 1000;
|
return System.currentTimeMillis() - lastUpdate < 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user