mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 10:34:40 +00:00
refactor 6
This commit is contained in:
1 parent
5b62c4fdc8
commit
8d072f0c89
78 files changed
+525
-882
No files matched your search
@@ -12,7 +12,6 @@ import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -87,7 +86,7 @@ public class CPacketCraftRequest implements IMessage {
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(Util.from(context.getSide())),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
GuiType.FLUID_CRAFTING_CONFIRM);
|
||||
|
||||
if (player.openContainer instanceof ContainerFluidCraftConfirm) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidMonitor;
|
||||
import com.glodblock.github.util.Util;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -42,23 +42,13 @@ public class CPacketFluidUpdate implements IMessage {
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int size = buf.readInt();
|
||||
this.list = new HashMap<>();
|
||||
try {
|
||||
for (int i = 0; i < size; i++) {
|
||||
int id = buf.readInt();
|
||||
boolean isNull = buf.readBoolean();
|
||||
if (!isNull) list.put(id, null);
|
||||
else {
|
||||
IAEFluidStack fluid = AEFluidStack.loadFluidStackFromPacket(buf);
|
||||
list.put(id, fluid);
|
||||
}
|
||||
}
|
||||
Util.readFluidMapFromBuf(this.list, buf);
|
||||
if (buf.readBoolean()) {
|
||||
this.itemStack = AEItemStack.loadItemStackFromPacket(buf).getItemStack();
|
||||
this.slotIndex = buf.readInt();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -66,16 +56,8 @@ public class CPacketFluidUpdate implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (Map.Entry<Integer, IAEFluidStack> fs : list.entrySet()) {
|
||||
buf.writeInt(fs.getKey());
|
||||
if (fs.getValue() == null) buf.writeBoolean(false);
|
||||
else {
|
||||
buf.writeBoolean(true);
|
||||
fs.getValue().writeToPacket(buf);
|
||||
}
|
||||
}
|
||||
Util.writeFluidMapToBuf(this.list, buf);
|
||||
if (this.itemStack != null) {
|
||||
buf.writeBoolean(true);
|
||||
AEItemStack.create(itemStack).writeToPacket(buf);
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -97,7 +96,7 @@ public class CPacketInventoryAction implements IMessage {
|
||||
te.getWorldObj(),
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(
|
||||
Util.from(baseContainer.getOpenContext().getSide())),
|
||||
baseContainer.getOpenContext().getSide()),
|
||||
GuiType.FLUID_CRAFTING_AMOUNT);
|
||||
if (sender.openContainer instanceof ContainerCraftAmount) {
|
||||
final ContainerCraftAmount cca = (ContainerCraftAmount) sender.openContainer;
|
||||
@@ -118,7 +117,7 @@ public class CPacketInventoryAction implements IMessage {
|
||||
te.getWorldObj(),
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(
|
||||
Util.from(baseContainer.getOpenContext().getSide())),
|
||||
baseContainer.getOpenContext().getSide()),
|
||||
GuiType.PATTERN_VALUE_SET);
|
||||
int amt = (int) message.stack.getStackSize();
|
||||
if (message.stack.getItem() instanceof ItemFluidPacket) {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class CPacketPatternValueSet implements IMessage {
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(Util.from(context.getSide())),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.originGui);
|
||||
if (player.openContainer instanceof FCContainerEncodeTerminal) {
|
||||
Slot slot = player.openContainer.getSlot(message.valueIndex);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
public class CPacketSetTargetItem implements IMessage {
|
||||
|
||||
private IAEItemStack stack;
|
||||
|
||||
public CPacketSetTargetItem() {}
|
||||
|
||||
public CPacketSetTargetItem(IAEItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
try {
|
||||
stack.writeToPacket(buf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
try {
|
||||
stack = AEItemStack.loadItemStackFromPacket(buf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketSetTargetItem, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketSetTargetItem message, MessageContext ctx) {
|
||||
Container c = ctx.getServerHandler().playerEntity.openContainer;
|
||||
if (c instanceof AEBaseContainer) {
|
||||
((AEBaseContainer) c).setTargetStack(message.stack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import appeng.container.ContainerOpenContext;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -62,7 +61,7 @@ public class CPacketSwitchGuis implements IMessage {
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(Util.from(context.getSide())),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.guiType);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx;
|
||||
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.nei.NEIUtils;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
@@ -77,8 +76,8 @@ public class CPacketTransferRecipe implements IMessage {
|
||||
@Override
|
||||
public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) {
|
||||
Container c = ctx.getServerHandler().playerEntity.openContainer;
|
||||
if (c instanceof ContainerFluidPatternTerminal) {
|
||||
ContainerFluidPatternTerminal cf = (ContainerFluidPatternTerminal) c;
|
||||
if (c instanceof FCContainerEncodeTerminal) {
|
||||
FCContainerEncodeTerminal cf = (FCContainerEncodeTerminal) c;
|
||||
boolean combine = cf.combine;
|
||||
cf.getPatternTerminal().setCraftingRecipe(message.isCraft);
|
||||
IInventory inputSlot = cf.getInventoryByName("crafting");
|
||||
@@ -98,80 +97,27 @@ public class CPacketTransferRecipe implements IMessage {
|
||||
message.inputs = NEIUtils.clearNull(message.inputs);
|
||||
message.outputs = NEIUtils.clearNull(message.outputs);
|
||||
}
|
||||
|
||||
for (OrderStack<?> stack : message.inputs) {
|
||||
if (stack != null) {
|
||||
int index = stack.getIndex();
|
||||
ItemStack stack1;
|
||||
if (stack.getStack() instanceof ItemStack) {
|
||||
stack1 = ((ItemStack) stack.getStack()).copy();
|
||||
} else if (stack.getStack() instanceof FluidStack) {
|
||||
stack1 = ItemFluidPacket.newStack((FluidStack) stack.getStack());
|
||||
} else throw new UnsupportedOperationException("Trying to get an unsupported item!");
|
||||
if (index < inputSlot.getSizeInventory()) inputSlot.setInventorySlotContents(index, stack1);
|
||||
}
|
||||
}
|
||||
for (OrderStack<?> stack : message.outputs) {
|
||||
if (stack != null) {
|
||||
int index = stack.getIndex();
|
||||
ItemStack stack1;
|
||||
if (stack.getStack() instanceof ItemStack) {
|
||||
stack1 = ((ItemStack) stack.getStack()).copy();
|
||||
} else if (stack.getStack() instanceof FluidStack) {
|
||||
stack1 = ItemFluidPacket.newStack((FluidStack) stack.getStack());
|
||||
} else throw new UnsupportedOperationException("Trying to get an unsupported item!");
|
||||
if (index < outputSlot.getSizeInventory()) outputSlot.setInventorySlotContents(index, stack1);
|
||||
}
|
||||
}
|
||||
c.onCraftMatrixChanged(inputSlot);
|
||||
c.onCraftMatrixChanged(outputSlot);
|
||||
} else if (c instanceof ContainerFluidPatternTerminalEx) {
|
||||
ContainerFluidPatternTerminalEx cf = (ContainerFluidPatternTerminalEx) c;
|
||||
boolean combine = cf.combine;
|
||||
IInventory inputSlot = cf.getInventoryByName("crafting");
|
||||
IInventory outputSlot = cf.getInventoryByName("output");
|
||||
for (int i = 0; i < inputSlot.getSizeInventory(); i++) {
|
||||
inputSlot.setInventorySlotContents(i, null);
|
||||
}
|
||||
for (int i = 0; i < outputSlot.getSizeInventory(); i++) {
|
||||
outputSlot.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
if (combine) {
|
||||
message.inputs = NEIUtils.compress(message.inputs);
|
||||
message.outputs = NEIUtils.compress(message.outputs);
|
||||
}
|
||||
message.inputs = NEIUtils.clearNull(message.inputs);
|
||||
message.outputs = NEIUtils.clearNull(message.outputs);
|
||||
|
||||
for (OrderStack<?> stack : message.inputs) {
|
||||
if (stack != null) {
|
||||
int index = stack.getIndex();
|
||||
ItemStack stack1;
|
||||
if (stack.getStack() instanceof ItemStack) {
|
||||
stack1 = ((ItemStack) stack.getStack()).copy();
|
||||
} else if (stack.getStack() instanceof FluidStack) {
|
||||
stack1 = ItemFluidPacket.newStack((FluidStack) stack.getStack());
|
||||
} else throw new UnsupportedOperationException("Trying to get an unsupported item!");
|
||||
if (index < inputSlot.getSizeInventory()) inputSlot.setInventorySlotContents(index, stack1);
|
||||
}
|
||||
}
|
||||
for (OrderStack<?> stack : message.outputs) {
|
||||
if (stack != null) {
|
||||
int index = stack.getIndex();
|
||||
ItemStack stack1;
|
||||
if (stack.getStack() instanceof ItemStack) {
|
||||
stack1 = ((ItemStack) stack.getStack()).copy();
|
||||
} else if (stack.getStack() instanceof FluidStack) {
|
||||
stack1 = ItemFluidPacket.newStack((FluidStack) stack.getStack());
|
||||
} else throw new UnsupportedOperationException("Trying to get an unsupported item!");
|
||||
if (index < outputSlot.getSizeInventory()) outputSlot.setInventorySlotContents(index, stack1);
|
||||
}
|
||||
}
|
||||
transferPack(message.inputs, inputSlot);
|
||||
transferPack(message.outputs, outputSlot);
|
||||
c.onCraftMatrixChanged(inputSlot);
|
||||
c.onCraftMatrixChanged(outputSlot);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void transferPack(List<OrderStack<?>> packs, IInventory inv) {
|
||||
for (OrderStack<?> stack : packs) {
|
||||
if (stack != null) {
|
||||
int index = stack.getIndex();
|
||||
ItemStack stack1;
|
||||
if (stack.getStack() instanceof ItemStack) {
|
||||
stack1 = ((ItemStack) stack.getStack()).copy();
|
||||
} else if (stack.getStack() instanceof FluidStack) {
|
||||
stack1 = ItemFluidPacket.newStack((FluidStack) stack.getStack());
|
||||
} else throw new UnsupportedOperationException("Trying to get an unsupported item!");
|
||||
if (index < inv.getSizeInventory()) inv.setInventorySlotContents(index, stack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ package com.glodblock.github.network;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.glodblock.github.client.gui.*;
|
||||
import com.glodblock.github.util.Util;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -40,18 +40,9 @@ public class SPacketFluidUpdate implements IMessage {
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int size = buf.readInt();
|
||||
this.list = new HashMap<>();
|
||||
try {
|
||||
for (int i = 0; i < size; i++) {
|
||||
int id = buf.readInt();
|
||||
boolean isNull = buf.readBoolean();
|
||||
if (!isNull) list.put(id, null);
|
||||
else {
|
||||
IAEFluidStack fluid = AEFluidStack.loadFluidStackFromPacket(buf);
|
||||
list.put(id, fluid);
|
||||
}
|
||||
}
|
||||
Util.readFluidMapFromBuf(this.list, buf);
|
||||
if (buf.readBoolean()) {
|
||||
this.itemStack = AEItemStack.loadItemStackFromPacket(buf);
|
||||
}
|
||||
@@ -62,16 +53,8 @@ public class SPacketFluidUpdate implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (Map.Entry<Integer, IAEFluidStack> fs : list.entrySet()) {
|
||||
buf.writeInt(fs.getKey());
|
||||
if (fs.getValue() == null) buf.writeBoolean(false);
|
||||
else {
|
||||
buf.writeBoolean(true);
|
||||
fs.getValue().writeToPacket(buf);
|
||||
}
|
||||
}
|
||||
Util.writeFluidMapToBuf(this.list, buf);
|
||||
if (this.itemStack != null) {
|
||||
buf.writeBoolean(true);
|
||||
this.itemStack.writeToPacket(buf);
|
||||
|
||||
@@ -62,11 +62,7 @@ public class SPacketMEInventoryUpdate implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
if (isFluid) {
|
||||
buf.writeBoolean(true);
|
||||
} else {
|
||||
buf.writeBoolean(false);
|
||||
}
|
||||
buf.writeBoolean(isFluid);
|
||||
buf.writeLong(list.size());
|
||||
buf.writeByte(ref);
|
||||
try {
|
||||
@@ -94,16 +90,17 @@ public class SPacketMEInventoryUpdate implements IMessage {
|
||||
public static class Handler implements IMessageHandler<SPacketMEInventoryUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public IMessage onMessage(SPacketMEInventoryUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiFluidMonitor) {
|
||||
((GuiFluidMonitor) gs).postUpdate((List<IAEFluidStack>) (List<?>) message.list);
|
||||
((GuiFluidMonitor) gs).postUpdate((List) message.list);
|
||||
} else if (gs instanceof GuiItemMonitor) {
|
||||
((GuiItemMonitor) gs).postUpdate((List<IAEItemStack>) (List<?>) message.list);
|
||||
((GuiItemMonitor) gs).postUpdate((List) message.list);
|
||||
} else if (gs instanceof GuiFluidCraftConfirm) {
|
||||
((GuiFluidCraftConfirm) gs).postUpdate((List<IAEItemStack>) (List<?>) message.list, message.ref);
|
||||
((GuiFluidCraftConfirm) gs).postUpdate((List) message.list, message.ref);
|
||||
} else if (gs instanceof GuiLevelMaintainer) {
|
||||
((GuiLevelMaintainer) gs).postUpdate((List<IAEItemStack>) (List<?>) message.list);
|
||||
((GuiLevelMaintainer) gs).postUpdate((List) message.list);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user