Fixed bugs with crafting with shift
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
package refinedstorage.container;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.container.slot.*;
|
||||
import refinedstorage.network.MessageGridCraftingShift;
|
||||
import refinedstorage.tile.grid.IGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
import refinedstorage.tile.grid.WirelessGrid;
|
||||
@@ -102,21 +98,6 @@ public class ContainerGrid extends ContainerBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int id, int clickedButton, ClickType clickType, EntityPlayer player) {
|
||||
Slot slot = id >= 0 ? getSlot(id) : null;
|
||||
|
||||
if (player.worldObj.isRemote && slot instanceof SlotGridCraftingResult && grid.getType() == EnumGridType.CRAFTING && slot.getHasStack()) {
|
||||
if (GuiScreen.isShiftKeyDown()) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingShift((TileGrid) grid));
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return super.slotClick(id, clickedButton, clickType, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMergeSlot(ItemStack stack, Slot slot) {
|
||||
if (slot == craftingResultSlot || slot == patternResultSlot) {
|
||||
@@ -129,12 +110,18 @@ public class ContainerGrid extends ContainerBase {
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
||||
if (!player.worldObj.isRemote) {
|
||||
ItemStack stack = inventorySlots.get(slotIndex).getStack();
|
||||
Slot slot = inventorySlots.get(slotIndex);
|
||||
|
||||
if (stack != null) {
|
||||
inventorySlots.get(slotIndex).putStack(grid.onItemPush(player, stack));
|
||||
if (slot == craftingResultSlot) {
|
||||
((TileGrid) grid).onCraftedShift(this, player);
|
||||
} else if (slot != patternResultSlot && !(slot instanceof SlotSpecimenLegacy)) {
|
||||
ItemStack stack = inventorySlots.get(slotIndex).getStack();
|
||||
|
||||
detectAndSendChanges();
|
||||
if (stack != null) {
|
||||
inventorySlots.get(slotIndex).putStack(grid.onItemPush(player, stack));
|
||||
|
||||
detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ public class SlotGridCraftingResult extends SlotCrafting {
|
||||
|
||||
onCrafting(stack);
|
||||
|
||||
grid.onCrafted(container, true);
|
||||
if (!player.worldObj.isRemote) {
|
||||
grid.onCrafted();
|
||||
|
||||
container.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package refinedstorage.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import refinedstorage.container.ContainerGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class MessageGridCraftingShift extends MessageHandlerPlayerToServer<MessageGridCraftingShift> implements IMessage {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
public MessageGridCraftingShift() {
|
||||
}
|
||||
|
||||
public MessageGridCraftingShift(TileGrid grid) {
|
||||
this.x = grid.getPos().getX();
|
||||
this.y = grid.getPos().getY();
|
||||
this.z = grid.getPos().getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageGridCraftingShift message, EntityPlayerMP player) {
|
||||
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
|
||||
|
||||
if (tile instanceof TileGrid) {
|
||||
TileGrid grid = (TileGrid) tile;
|
||||
|
||||
if (grid.isConnected() && player.openContainer instanceof ContainerGrid) {
|
||||
grid.onCraftedShift((ContainerGrid) player.openContainer, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,6 @@ public class CommonProxy {
|
||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridSettingsUpdate.class, MessageWirelessGridSettingsUpdate.class, id++, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridHeldItemPush.class, MessageWirelessGridHeldItemPush.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(MessageGridCraftingStart.class, MessageGridCraftingStart.class, id++, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridCraftingStart.class, MessageWirelessGridCraftingStart.class, id++, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, id++, Side.SERVER);
|
||||
|
||||
@@ -142,32 +142,26 @@ public class TileGrid extends TileMachine implements IGrid {
|
||||
result.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(matrix, worldObj));
|
||||
}
|
||||
|
||||
public void onCrafted(ContainerGrid container, boolean sendChanges) {
|
||||
if (!worldObj.isRemote) {
|
||||
ItemStack[] remainder = CraftingManager.getInstance().getRemainingItems(matrix, worldObj);
|
||||
public void onCrafted() {
|
||||
ItemStack[] remainder = CraftingManager.getInstance().getRemainingItems(matrix, worldObj);
|
||||
|
||||
for (int i = 0; i < matrix.getSizeInventory(); ++i) {
|
||||
if (remainder[i] != null) {
|
||||
matrix.setInventorySlotContents(i, remainder[i].copy());
|
||||
} else {
|
||||
ItemStack slot = matrix.getStackInSlot(i);
|
||||
for (int i = 0; i < matrix.getSizeInventory(); ++i) {
|
||||
if (remainder[i] != null) {
|
||||
matrix.setInventorySlotContents(i, remainder[i].copy());
|
||||
} else {
|
||||
ItemStack slot = matrix.getStackInSlot(i);
|
||||
|
||||
if (slot != null) {
|
||||
if (slot.stackSize == 1 && isConnected()) {
|
||||
matrix.setInventorySlotContents(i, controller.take(slot, 1));
|
||||
} else {
|
||||
matrix.decrStackSize(i, 1);
|
||||
}
|
||||
if (slot != null) {
|
||||
if (slot.stackSize == 1 && isConnected()) {
|
||||
matrix.setInventorySlotContents(i, controller.take(slot, 1));
|
||||
} else {
|
||||
matrix.decrStackSize(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onCraftingMatrixChanged();
|
||||
|
||||
if (sendChanges) {
|
||||
container.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
|
||||
onCraftingMatrixChanged();
|
||||
}
|
||||
|
||||
public void onCraftedShift(ContainerGrid container, EntityPlayer player) {
|
||||
@@ -176,7 +170,7 @@ public class TileGrid extends TileMachine implements IGrid {
|
||||
ItemStack crafted = result.getStackInSlot(0);
|
||||
|
||||
while (true) {
|
||||
onCrafted(container, false);
|
||||
onCrafted();
|
||||
|
||||
craftedItemsList.add(crafted.copy());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user