Remove usage of that packet

This commit is contained in:
Raoul Van den Berge
2016-03-28 23:17:27 +02:00
parent d28aa15d1c
commit 1991c64da3
6 changed files with 30 additions and 84 deletions

View File

@@ -1,7 +1,9 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import refinedstorage.block.EnumGridType;
import refinedstorage.container.slot.SlotGridCraftingResult;
import refinedstorage.tile.TileGrid;
@@ -36,11 +38,31 @@ public class ContainerGrid extends ContainerBase {
}
}
addSlotToContainer(new SlotGridCraftingResult(player, grid.getCraftingInventory(), grid.getCraftingResultInventory(), grid, 0, 133 + 4, 120 + 4));
addSlotToContainer(new SlotGridCraftingResult(this, player, grid.getCraftingInventory(), grid.getCraftingResultInventory(), grid, 0, 133 + 4, 120 + 4));
}
}
public List<Slot> getCraftingSlots() {
return craftingSlots;
}
// I'm overriding detectAndSendChanges() here because the default check
// checks if the item stacks are equal, and if so, then it will only send the new slot contents.
// The thing is though, when the grid replaces the slots with new items from the storage
// system, the item stack replaced WILL be the same!
// That's why we override this here to get rid of the check and ALWAYS send slot changes.
@Override
public void detectAndSendChanges() {
for (int i = 0; i < this.inventorySlots.size(); ++i) {
ItemStack itemstack = ((Slot) this.inventorySlots.get(i)).getStack();
ItemStack itemstack1 = (ItemStack) this.inventoryItemStacks.get(i);
itemstack1 = itemstack == null ? null : itemstack.copy();
this.inventoryItemStacks.set(i, itemstack1);
for (int j = 0; j < this.crafters.size(); ++j) {
((ICrafting) this.crafters.get(j)).sendSlotContents(this, i, itemstack1);
}
}
}
}

View File

@@ -5,15 +5,18 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import refinedstorage.container.ContainerGrid;
import refinedstorage.tile.TileGrid;
public class SlotGridCraftingResult extends SlotCrafting {
private ContainerGrid container;
private IInventory craftingMatrix;
private TileGrid grid;
public SlotGridCraftingResult(EntityPlayer player, InventoryCrafting craftingMatrix, IInventory craftingResult, TileGrid grid, int id, int x, int y) {
public SlotGridCraftingResult(ContainerGrid container, EntityPlayer player, InventoryCrafting craftingMatrix, IInventory craftingResult, TileGrid grid, int id, int x, int y) {
super(player, craftingMatrix, craftingResult, id, x, y);
this.container = container;
this.craftingMatrix = craftingMatrix;
this.grid = grid;
}
@@ -30,6 +33,6 @@ public class SlotGridCraftingResult extends SlotCrafting {
super.onPickupFromSlot(player, stack);
grid.onCrafted(matrixSlots);
grid.onCrafted(container, matrixSlots);
}
}

View File

@@ -1,72 +0,0 @@
package refinedstorage.network;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.ByteBufUtils;
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.TileGrid;
public class MessageGridCraftingUpdate implements IMessage, IMessageHandler<MessageGridCraftingUpdate, IMessage> {
private int x;
private int y;
private int z;
private ItemStack[] craftingMatrix = new ItemStack[9];
public MessageGridCraftingUpdate() {
}
public MessageGridCraftingUpdate(TileGrid grid) {
this.x = grid.getPos().getX();
this.y = grid.getPos().getY();
this.z = grid.getPos().getZ();
for (int i = 0; i < 9; ++i) {
craftingMatrix[i] = grid.getCraftingInventory().getStackInSlot(i);
}
}
@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
for (int i = 0; i < 9; ++i) {
craftingMatrix[i] = ByteBufUtils.readItemStack(buf);
}
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
for (ItemStack stack : craftingMatrix) {
ByteBufUtils.writeItemStack(buf, stack);
}
}
@Override
public IMessage onMessage(final MessageGridCraftingUpdate message, MessageContext context) {
Minecraft.getMinecraft().addScheduledTask(new Runnable() {
@Override
public void run() {
TileEntity tile = Minecraft.getMinecraft().theWorld.getTileEntity(new BlockPos(message.x, message.y, message.z));
if (tile instanceof TileGrid) {
for (int i = 0; i < 9; ++i) {
((TileGrid) tile).getCraftingInventory().setInventorySlotContents(i, message.craftingMatrix[i]);
}
}
}
});
return null;
}
}

View File

@@ -34,7 +34,6 @@ public class CommonProxy {
RefinedStorage.NETWORK.registerMessage(MessageModeToggle.class, MessageModeToggle.class, 5, Side.SERVER);
RefinedStorage.NETWORK.registerMessage(MessageDetectorModeUpdate.class, MessageDetectorModeUpdate.class, 6, Side.SERVER);
RefinedStorage.NETWORK.registerMessage(MessageDetectorAmountUpdate.class, MessageDetectorAmountUpdate.class, 7, Side.SERVER);
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingUpdate.class, MessageGridCraftingUpdate.class, 8, Side.CLIENT);
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingClear.class, MessageGridCraftingClear.class, 9, Side.SERVER);
RefinedStorage.NETWORK.registerMessage(MessagePriorityUpdate.class, MessagePriorityUpdate.class, 10, Side.SERVER);
RefinedStorage.NETWORK.registerMessage(MessageGridSortingUpdate.class, MessageGridSortingUpdate.class, 11, Side.SERVER);

View File

@@ -359,7 +359,6 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
machines.add((TileMachine) tile);
}
}
}
@Override

View File

@@ -8,13 +8,10 @@ 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.common.network.NetworkRegistry.TargetPoint;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.block.BlockGrid;
import refinedstorage.block.EnumGridType;
import refinedstorage.inventory.InventorySimple;
import refinedstorage.network.MessageGridCraftingUpdate;
import refinedstorage.storage.StorageItem;
import refinedstorage.util.InventoryUtils;
@@ -76,7 +73,7 @@ public class TileGrid extends TileMachine {
craftingResultInventory.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftingInventory, worldObj));
}
public void onCrafted(ItemStack[] matrixSlots) {
public void onCrafted(Container container, ItemStack[] matrixSlots) {
if (isConnected() && !worldObj.isRemote) {
for (int i = 0; i < craftingInventory.getSizeInventory(); ++i) {
ItemStack slot = craftingInventory.getStackInSlot(i);
@@ -94,9 +91,7 @@ public class TileGrid extends TileMachine {
onCraftingMatrixChanged();
TargetPoint target = new TargetPoint(worldObj.provider.getDimensionType().getId(), pos.getX(), pos.getY(), pos.getZ(), UPDATE_RANGE);
RefinedStorage.NETWORK.sendToAllAround(new MessageGridCraftingUpdate(this), target);
container.detectAndSendChanges();
}
}