Make the slot clear before recipe is transferred to pp encoder

This commit is contained in:
Raoul Van den Berge
2016-10-05 20:12:05 +02:00
parent 507a3ff02e
commit 64f9e23335
5 changed files with 62 additions and 42 deletions

View File

@@ -11,18 +11,18 @@ import refinedstorage.tile.TileProcessingPatternEncoder;
import java.util.Collection;
public class ContainerProcessingPatternEncoder extends ContainerBase {
public ContainerProcessingPatternEncoder(TileProcessingPatternEncoder processingPatternEncoder, EntityPlayer player) {
super(processingPatternEncoder, player);
public ContainerProcessingPatternEncoder(TileProcessingPatternEncoder encoder, EntityPlayer player) {
super(encoder, player);
addSlotToContainer(new SlotItemHandler(processingPatternEncoder.getPatterns(), 0, 152, 18));
addSlotToContainer(new SlotOutput(processingPatternEncoder.getPatterns(), 1, 152, 58));
addSlotToContainer(new SlotItemHandler(encoder.getPatterns(), 0, 152, 18));
addSlotToContainer(new SlotOutput(encoder.getPatterns(), 1, 152, 58));
int ox = 8;
int x = ox;
int y = 20;
for (int i = 0; i < 9 * 2; ++i) {
addSlotToContainer(new SlotSpecimen(processingPatternEncoder.getConfiguration(), i, x, y, SlotSpecimen.SPECIMEN_SIZE));
addSlotToContainer(new SlotSpecimen(encoder.getConfiguration(), i, x, y, SlotSpecimen.SPECIMEN_SIZE));
x += 18;
@@ -68,6 +68,13 @@ public class ContainerProcessingPatternEncoder extends ContainerBase {
return stack;
}
public void clearInputsAndOutputs() {
for (int i = 2; i < 2 + (9 * 2); ++i) {
getSlot(i).putStack(null);
getSlot(i).onSlotChanged();
}
}
public void setInputs(Collection<ItemStack> stacks) {
setSlots(stacks, 2 , 2 + 9);
}
@@ -84,6 +91,7 @@ public class ContainerProcessingPatternEncoder extends ContainerBase {
if (!slot.getHasStack() && slot.isItemValid(stack)) {
slot.putStack(stack);
slot.onSlotChanged();
break;
}
}

View File

@@ -11,12 +11,12 @@ import refinedstorage.tile.TileProcessingPatternEncoder;
import java.io.IOException;
public class GuiProcessingPatternEncoder extends GuiBase {
private TileProcessingPatternEncoder processingPatternEncoder;
private TileProcessingPatternEncoder encoder;
public GuiProcessingPatternEncoder(ContainerProcessingPatternEncoder container, TileProcessingPatternEncoder processingPatternEncoder) {
public GuiProcessingPatternEncoder(ContainerProcessingPatternEncoder container, TileProcessingPatternEncoder encoder) {
super(container, 176, 172);
this.processingPatternEncoder = processingPatternEncoder;
this.encoder = encoder;
}
@Override
@@ -28,7 +28,7 @@ public class GuiProcessingPatternEncoder extends GuiBase {
}
private boolean isOverCreatePattern(int mouseX, int mouseY) {
return inBounds(152, 38, 16, 16, mouseX, mouseY) && processingPatternEncoder.canCreatePattern();
return inBounds(152, 38, 16, 16, mouseX, mouseY) && encoder.canCreatePattern();
}
private boolean isOverClear(int mouseX, int mouseY) {
@@ -47,7 +47,7 @@ public class GuiProcessingPatternEncoder extends GuiBase {
ty = 1;
}
if (!processingPatternEncoder.canCreatePattern()) {
if (!encoder.canCreatePattern()) {
ty = 2;
}
@@ -73,11 +73,11 @@ public class GuiProcessingPatternEncoder extends GuiBase {
super.mouseClicked(mouseX, mouseY, mouseButton);
if (isOverCreatePattern(mouseX - guiLeft, mouseY - guiTop)) {
RefinedStorage.INSTANCE.network.sendToServer(new MessageGridPatternCreate(processingPatternEncoder.getPos().getX(), processingPatternEncoder.getPos().getY(), processingPatternEncoder.getPos().getZ()));
RefinedStorage.INSTANCE.network.sendToServer(new MessageGridPatternCreate(encoder.getPos().getX(), encoder.getPos().getY(), encoder.getPos().getZ()));
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
} else if (isOverClear(mouseX - guiLeft, mouseY - guiTop)) {
RefinedStorage.INSTANCE.network.sendToServer(new MessageProcessingPatternEncoderClear(processingPatternEncoder));
RefinedStorage.INSTANCE.network.sendToServer(new MessageProcessingPatternEncoderClear(encoder));
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
}

View File

@@ -32,28 +32,32 @@ public class RecipeTransferHandlerPattern implements IRecipeTransferHandler<Cont
if (doTransfer) {
Map<Integer, ItemStack> inputs = new HashMap<>();
Map<Integer, ItemStack> outputs = new HashMap<>();
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
ItemStack ingredient = guiIngredient.getDisplayedIngredient();
int hashCode = NetworkUtils.getItemStackHashCode(ingredient);
if (guiIngredient.isInput()) {
if (inputs.containsKey(hashCode)) {
inputs.get(hashCode).stackSize++;
} else {
inputs.put(hashCode, ingredient);
}
} else {
if (outputs.containsKey(hashCode)) {
outputs.get(hashCode).stackSize++;
} else {
outputs.put(hashCode, ingredient);
}
}
}
}
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
ItemStack ingredient = guiIngredient.getDisplayedIngredient();
int hash = NetworkUtils.getItemStackHashCode(ingredient);
if (guiIngredient.isInput()) {
if (inputs.containsKey(hash)) {
inputs.get(hash).stackSize++;
} else {
inputs.put(hash, ingredient);
}
} else {
if (outputs.containsKey(hash)) {
outputs.get(hash).stackSize++;
} else {
outputs.put(hash, ingredient);
}
}
}
}
RefinedStorage.INSTANCE.network.sendToServer(new MessageProcessingPatternEncoderTransfer(inputs.values(), outputs.values()));
}
return null;
}
}

View File

@@ -15,10 +15,10 @@ public class MessageProcessingPatternEncoderClear extends MessageHandlerPlayerTo
public MessageProcessingPatternEncoderClear() {
}
public MessageProcessingPatternEncoderClear(TileProcessingPatternEncoder processingPatternEncoder) {
this.x = processingPatternEncoder.getPos().getX();
this.y = processingPatternEncoder.getPos().getY();
this.z = processingPatternEncoder.getPos().getZ();
public MessageProcessingPatternEncoderClear(TileProcessingPatternEncoder encoder) {
this.x = encoder.getPos().getX();
this.y = encoder.getPos().getY();
this.z = encoder.getPos().getZ();
}
@Override
@@ -40,10 +40,10 @@ public class MessageProcessingPatternEncoderClear extends MessageHandlerPlayerTo
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
if (tile instanceof TileProcessingPatternEncoder) {
TileProcessingPatternEncoder processingPatternEncoder = (TileProcessingPatternEncoder) tile;
TileProcessingPatternEncoder encoder = (TileProcessingPatternEncoder) tile;
for (int i = 0; i < processingPatternEncoder.getConfiguration().getSlots(); ++i) {
processingPatternEncoder.getConfiguration().setStackInSlot(i, null);
for (int i = 0; i < encoder.getConfiguration().getSlots(); ++i) {
encoder.getConfiguration().setStackInSlot(i, null);
}
}
}

View File

@@ -11,11 +11,10 @@ import java.util.ArrayList;
import java.util.Collection;
public class MessageProcessingPatternEncoderTransfer extends MessageHandlerPlayerToServer<MessageProcessingPatternEncoderTransfer> implements IMessage {
private Collection<ItemStack> inputs, outputs;
private Collection<ItemStack> inputs;
private Collection<ItemStack> outputs;
public MessageProcessingPatternEncoderTransfer() {
}
public MessageProcessingPatternEncoderTransfer(Collection<ItemStack> inputs, Collection<ItemStack> outputs) {
@@ -23,16 +22,20 @@ public class MessageProcessingPatternEncoderTransfer extends MessageHandlerPlaye
this.outputs = outputs;
}
@Override
public void fromBytes(ByteBuf buf) {
int size = buf.readInt();
this.inputs = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
this.inputs.add(ByteBufUtils.readItemStack(buf));
}
size = buf.readInt();
this.outputs = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
this.outputs.add(ByteBufUtils.readItemStack(buf));
}
@@ -41,10 +44,13 @@ public class MessageProcessingPatternEncoderTransfer extends MessageHandlerPlaye
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(inputs.size());
for (ItemStack stack : inputs) {
ByteBufUtils.writeItemStack(buf, stack);
}
buf.writeInt(outputs.size());
for (ItemStack stack : outputs) {
ByteBufUtils.writeItemStack(buf, stack);
}
@@ -55,6 +61,8 @@ public class MessageProcessingPatternEncoderTransfer extends MessageHandlerPlaye
if (player.openContainer instanceof ContainerProcessingPatternEncoder) {
ContainerProcessingPatternEncoder encoder = (ContainerProcessingPatternEncoder) player.openContainer;
encoder.clearInputsAndOutputs();
encoder.setInputs(message.inputs);
encoder.setOutputs(message.outputs);
}