mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 10:34:40 +00:00
Universal GUI (#340)
Co-authored-by: Kogepan229 <[email protected]> Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
213 files changed
+1859
-19432
No files matched your search
@@ -1,145 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
|
||||
import appeng.api.config.CraftingMode;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingJob;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
import appeng.core.AELog;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
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;
|
||||
|
||||
public class CPacketCraftRequest implements IMessage {
|
||||
|
||||
private long amount;
|
||||
private boolean heldShift;
|
||||
|
||||
private CraftingMode craftingMode;
|
||||
|
||||
public CPacketCraftRequest() {}
|
||||
|
||||
public CPacketCraftRequest(final int craftAmt, final boolean shift) {
|
||||
this(craftAmt, shift, CraftingMode.STANDARD);
|
||||
}
|
||||
|
||||
public CPacketCraftRequest(final int craftAmt, final boolean shift, final CraftingMode craftingMode) {
|
||||
amount = craftAmt;
|
||||
heldShift = shift;
|
||||
this.craftingMode = craftingMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeLong(amount);
|
||||
buf.writeBoolean(heldShift);
|
||||
buf.writeBoolean(this.craftingMode == CraftingMode.STANDARD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
amount = buf.readLong();
|
||||
heldShift = buf.readBoolean();
|
||||
craftingMode = buf.readBoolean() ? CraftingMode.STANDARD : CraftingMode.IGNORE_MISSING;
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketCraftRequest, IMessage> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(CPacketCraftRequest message, MessageContext ctx) {
|
||||
if (ctx.getServerHandler().playerEntity.openContainer instanceof final ContainerCraftAmount cca) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
final Object target = cca.getTarget();
|
||||
if (target instanceof final IGridHost gh) {
|
||||
final IGridNode gn = gh.getGridNode(ForgeDirection.UNKNOWN);
|
||||
|
||||
if (gn == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final IGrid g = gn.getGrid();
|
||||
if (g == null || cca.getItemToCraft() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
cca.getItemToCraft().setStackSize(message.amount);
|
||||
|
||||
Future<ICraftingJob> futureJob = null;
|
||||
try {
|
||||
final ICraftingGrid cg = g.getCache(ICraftingGrid.class);
|
||||
if(cg instanceof CraftingGridCache cgc) {
|
||||
futureJob = cgc.beginCraftingJob(
|
||||
cca.getWorld(),
|
||||
cca.getGrid(),
|
||||
cca.getActionSrc(),
|
||||
cca.getItemToCraft(),
|
||||
message.craftingMode,
|
||||
null);
|
||||
}else {
|
||||
futureJob = cg.beginCraftingJob(
|
||||
cca.getWorld(),
|
||||
cca.getGrid(),
|
||||
cca.getActionSrc(),
|
||||
cca.getItemToCraft(),
|
||||
null);
|
||||
}
|
||||
|
||||
final ContainerOpenContext context = cca.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
GuiType.FLUID_CRAFTING_CONFIRM);
|
||||
} else if (target instanceof IWirelessTerminal) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(((IWirelessTerminal) target).getInventorySlot(), 0, 0),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
GuiType.FLUID_CRAFTING_CONFIRM_ITEM);
|
||||
}
|
||||
|
||||
if (player.openContainer instanceof final ContainerCraftConfirm ccc) {
|
||||
ccc.setItemToCraft(cca.getItemToCraft());
|
||||
ccc.setAutoStart(message.heldShift);
|
||||
ccc.setJob(futureJob);
|
||||
cca.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
if (futureJob != null) {
|
||||
futureJob.cancel(true);
|
||||
}
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.FluidInterfaceButtons;
|
||||
import com.glodblock.github.common.tile.TileFluidInterface;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SidelessMode;
|
||||
import appeng.container.AEBaseContainer;
|
||||
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;
|
||||
|
||||
public class CPacketCustomButtonUpdate implements IMessage {
|
||||
|
||||
public CPacketCustomButtonUpdate() {}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketCustomButtonUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketCustomButtonUpdate message, MessageContext ctx) {
|
||||
final Container c = ctx.getServerHandler().playerEntity.openContainer;
|
||||
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
|
||||
if (c instanceof AEBaseContainer abc && abc.getTarget() instanceof TileFluidInterface tfi) {
|
||||
if (tfi.getDataObject() instanceof FluidInterfaceButtons fib) {
|
||||
fib.setSidelessMode((SidelessMode) tfi.getConfigManager().getSetting(Settings.SIDELESS_MODE));
|
||||
FluidCraft.proxy.netHandler.sendTo(new SPacketCustomButtonUpdate(fib), player);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternEncoder;
|
||||
|
||||
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;
|
||||
|
||||
public class CPacketEncodePattern implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketEncodePattern, IMessage> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(CPacketEncodePattern message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
if (player.openContainer instanceof ContainerFluidPatternEncoder) {
|
||||
((ContainerFluidPatternEncoder) player.openContainer).encodePattern();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,23 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidStorageBus;
|
||||
import com.glodblock.github.client.gui.container.base.FCBaseContainer;
|
||||
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.UltraTerminalButtons;
|
||||
import com.glodblock.github.client.gui.container.ContainerMagnetFilter;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IItemTerminal;
|
||||
import com.glodblock.github.inventory.item.IWirelessExtendCard;
|
||||
import com.glodblock.github.inventory.item.IWirelessMagnetFilter;
|
||||
import com.glodblock.github.inventory.item.WirelessMagnet;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.PrimaryGui;
|
||||
import appeng.container.interfaces.IContainerSubGui;
|
||||
import appeng.container.interfaces.IInventorySlotAware;
|
||||
import appeng.helpers.ICustomButtonProvider;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -23,21 +25,34 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class CPacketFluidPatternTermBtns implements IMessage {
|
||||
|
||||
private String Name = "";
|
||||
private String Value = "";
|
||||
private Command command;
|
||||
private String value = "";
|
||||
|
||||
public CPacketFluidPatternTermBtns(final String name, final String value) {
|
||||
Name = name;
|
||||
Value = value;
|
||||
public enum Command {
|
||||
RESTOCK,
|
||||
MAGNET_MODE,
|
||||
MAGNET_OPEN_FILTER,
|
||||
MAGNET_FILTER_NBT,
|
||||
MAGNET_FILTER_META,
|
||||
MAGNET_FILTER_ORE,
|
||||
MAGNET_FILTER_OREDICT_STATE,
|
||||
MAGNET_FILTER_OREDICT_FILTER,
|
||||
MAGNET_FILTER_MODE,
|
||||
MAGNET_FILTER_CLEAR
|
||||
}
|
||||
|
||||
public CPacketFluidPatternTermBtns(final String name, final Integer value) {
|
||||
Name = name;
|
||||
Value = value.toString();
|
||||
public CPacketFluidPatternTermBtns(final Command command, final String value) {
|
||||
this.command = command;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public CPacketFluidPatternTermBtns(final String name, final boolean value) {
|
||||
this(name, value ? 1 : 0);
|
||||
public CPacketFluidPatternTermBtns(final Command command, final Integer value) {
|
||||
this.command = command;
|
||||
this.value = value.toString();
|
||||
}
|
||||
|
||||
public CPacketFluidPatternTermBtns(final Command command, final boolean value) {
|
||||
this(command, value ? 1 : 0);
|
||||
}
|
||||
|
||||
public CPacketFluidPatternTermBtns() {
|
||||
@@ -46,29 +61,23 @@ public class CPacketFluidPatternTermBtns implements IMessage {
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int leName = buf.readInt();
|
||||
this.command = Command.values()[buf.readInt()];
|
||||
|
||||
int leVal = buf.readInt();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < leName; i++) {
|
||||
sb.append(buf.readChar());
|
||||
}
|
||||
Name = sb.toString();
|
||||
sb = new StringBuilder();
|
||||
for (int i = 0; i < leVal; i++) {
|
||||
sb.append(buf.readChar());
|
||||
}
|
||||
Value = sb.toString();
|
||||
this.value = sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(Name.length());
|
||||
buf.writeInt(Value.length());
|
||||
for (int i = 0; i < Name.length(); i++) {
|
||||
buf.writeChar(Name.charAt(i));
|
||||
}
|
||||
for (int i = 0; i < Value.length(); i++) {
|
||||
buf.writeChar(Value.charAt(i));
|
||||
buf.writeInt(this.command.ordinal());
|
||||
|
||||
buf.writeInt(this.value.length());
|
||||
for (int i = 0; i < this.value.length(); i++) {
|
||||
buf.writeChar(this.value.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,93 +85,62 @@ public class CPacketFluidPatternTermBtns implements IMessage {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ctx) {
|
||||
String Name = message.Name;
|
||||
String Value = message.Value;
|
||||
final Command command = message.command;
|
||||
final String value = message.value;
|
||||
final Container c = ctx.getServerHandler().playerEntity.openContainer;
|
||||
final EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
if (Name.startsWith("WirelessTerminal.") && (c instanceof FCBaseContainer)) {
|
||||
final FCBaseContainer cpt = (FCBaseContainer) c;
|
||||
final IItemTerminal itemTerminal = (IItemTerminal) cpt.getHost();
|
||||
final IWirelessExtendCard iwt = (IWirelessExtendCard) itemTerminal;
|
||||
switch (Name) {
|
||||
case "WirelessTerminal.Stock":
|
||||
iwt.setRestock(!iwt.isRestock());
|
||||
break;
|
||||
case "WirelessTerminal.MagnetMode":
|
||||
iwt.setMagnetCardNextMode();
|
||||
break;
|
||||
case "WirelessTerminal.OpenMagnet":
|
||||
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
|
||||
if (c instanceof ContainerMagnetFilter cmf && cmf.getTarget() instanceof IWirelessMagnetFilter iwmf) {
|
||||
switch (command) {
|
||||
case MAGNET_FILTER_NBT -> iwmf.setNBTMode(value.equals("1"));
|
||||
case MAGNET_FILTER_META -> iwmf.setMetaMode(value.equals("1"));
|
||||
case MAGNET_FILTER_ORE -> iwmf.setOreMode(value.equals("1"));
|
||||
case MAGNET_FILTER_OREDICT_STATE -> iwmf.setOreDictMode(value.equals("1"));
|
||||
case MAGNET_FILTER_OREDICT_FILTER -> iwmf.setOreDictFilter(value);
|
||||
case MAGNET_FILTER_MODE -> iwmf.setListMode(value.equals("1"));
|
||||
case MAGNET_FILTER_CLEAR -> iwmf.clearConfig();
|
||||
}
|
||||
iwmf.saveSettings();
|
||||
} else if (c instanceof AEBaseContainer abc && abc.getTarget() instanceof ICustomButtonProvider icbp) {
|
||||
|
||||
switch (command) {
|
||||
case RESTOCK -> {
|
||||
if (icbp.getDataObject() instanceof UltraTerminalButtons utb) {
|
||||
utb.toggleRestock();
|
||||
}
|
||||
}
|
||||
case MAGNET_MODE -> {
|
||||
if (icbp.getDataObject() instanceof UltraTerminalButtons utb) {
|
||||
utb.toggleMagnetMode();
|
||||
}
|
||||
}
|
||||
case MAGNET_OPEN_FILTER -> {
|
||||
final PrimaryGui pGui = abc.getPrimaryGui();
|
||||
final int nextGui = abc.getSwitchAbleGuiNext();
|
||||
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(
|
||||
cpt.getPortableCell().getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
-1),
|
||||
ForgeDirection.UNKNOWN,
|
||||
GuiType.WIRELESS_MAGNET_FILTER);
|
||||
break;
|
||||
case "WirelessTerminal.magnet.NBT":
|
||||
((IWirelessMagnetFilter) itemTerminal).setNBTMode(Value.equals("1"));
|
||||
break;
|
||||
case "WirelessTerminal.magnet.Meta":
|
||||
((IWirelessMagnetFilter) itemTerminal).setMetaMode(Value.equals("1"));
|
||||
break;
|
||||
case "WirelessTerminal.magnet.Ore":
|
||||
((IWirelessMagnetFilter) itemTerminal).setOreMode(Value.equals("1"));
|
||||
break;
|
||||
case "WirelessTerminal.magnet.OreDictState":
|
||||
((IWirelessMagnetFilter) itemTerminal).setOreDictMode(Value.equals("1"));
|
||||
break;
|
||||
case "WirelessTerminal.magnet.OreDictFilter":
|
||||
((IWirelessMagnetFilter) itemTerminal).setOreDictFilter(Value);
|
||||
break;
|
||||
case "WirelessTerminal.magnet.FilterMode":
|
||||
((IWirelessMagnetFilter) itemTerminal).setListMode(
|
||||
Value.equals("1") ? WirelessMagnet.ListMode.WhiteList
|
||||
: WirelessMagnet.ListMode.BlackList);
|
||||
break;
|
||||
case "WirelessTerminal.magnet.clear":
|
||||
((IWirelessMagnetFilter) itemTerminal).clearConfig();
|
||||
break;
|
||||
}
|
||||
itemTerminal.saveSettings();
|
||||
} else if (Name.startsWith("PatternTerminal.") && (c instanceof final FCContainerEncodeTerminal cpt)) {
|
||||
switch (Name) {
|
||||
case "PatternTerminal.CraftMode" -> cpt.getPatternTerminal().setCraftingRecipe(Value.equals("1"));
|
||||
case "PatternTerminal.Encode" -> {
|
||||
switch (Value) {
|
||||
case "0" -> cpt.encode();
|
||||
case "1" -> cpt.encodeAndMoveToInventory();
|
||||
case "3" -> cpt.encodeAllItemAndMoveToInventory();
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(
|
||||
((IInventorySlotAware) abc.getTarget()).getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
-1),
|
||||
ForgeDirection.UNKNOWN,
|
||||
GuiType.WIRELESS_MAGNET_FILTER);
|
||||
|
||||
if (player.openContainer instanceof IContainerSubGui sg) {
|
||||
sg.setPrimaryGui(pGui);
|
||||
}
|
||||
|
||||
if (player.openContainer instanceof AEBaseContainer ab) {
|
||||
ab.setSwitchAbleGuiNext(nextGui);
|
||||
}
|
||||
}
|
||||
case "PatternTerminal.Clear" -> cpt.clear();
|
||||
case "PatternTerminal.Substitute" -> cpt.getPatternTerminal().setSubstitution(Value.equals("1"));
|
||||
case "PatternTerminal.Invert" -> cpt.getPatternTerminal().setInverted(Value.equals("1"));
|
||||
case "PatternTerminal.Double" -> cpt.doubleStacks(Integer.parseInt(message.Value));
|
||||
case "PatternTerminal.Combine" -> cpt.getPatternTerminal().setCombineMode(Value.equals("1"));
|
||||
case "PatternTerminal.beSubstitute" -> cpt.getPatternTerminal().setBeSubstitute(Value.equals("1"));
|
||||
case "PatternTerminal.ActivePage" ->
|
||||
cpt.getPatternTerminal().setActivePage(Integer.parseInt(Value));
|
||||
case "PatternTerminal.Prioritize" -> {
|
||||
switch (Value) {
|
||||
case "0", "1" -> cpt.getPatternTerminal().setPrioritization(Value.equals("1"));
|
||||
case "2" -> cpt.getPatternTerminal().sortCraftingItems();
|
||||
}
|
||||
}
|
||||
case "PatternTerminal.AutoFillerPattern" ->
|
||||
cpt.getPatternTerminal().setAutoFillPattern(Value.equals("1"));
|
||||
}
|
||||
cpt.getPatternTerminal().saveSettings();
|
||||
} else if (Name.startsWith("StorageBus.") && c instanceof ContainerFluidStorageBus ccw) {
|
||||
if (Name.equals("StorageBus.Action")) {
|
||||
if (Value.equals("Partition")) {
|
||||
ccw.partition();
|
||||
} else if (Value.equals("Clear")) {
|
||||
ccw.clear();
|
||||
}
|
||||
}
|
||||
|
||||
icbp.writeCustomButtonData();
|
||||
|
||||
FluidCraft.proxy.netHandler.sendTo(new SPacketCustomButtonUpdate(icbp.getDataObject()), player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidMonitor;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
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;
|
||||
|
||||
public class CPacketFluidUpdate implements IMessage {
|
||||
|
||||
private IAEFluidStack fluid;
|
||||
private boolean shift;
|
||||
private int slotIndex;
|
||||
|
||||
public CPacketFluidUpdate() {}
|
||||
|
||||
/**
|
||||
* Used by transferStackInSlot. No clicked fluid, always shift.
|
||||
*/
|
||||
public CPacketFluidUpdate(int slotIndex) {
|
||||
this(null, slotIndex, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by handleMouseClick. Always uses mouse stack.
|
||||
*/
|
||||
public CPacketFluidUpdate(IAEFluidStack fluid, boolean shift) {
|
||||
this(fluid, -1, shift);
|
||||
}
|
||||
|
||||
private CPacketFluidUpdate(IAEFluidStack fluid, int slotIndex, boolean shift) {
|
||||
this.fluid = fluid;
|
||||
this.slotIndex = slotIndex;
|
||||
this.shift = shift;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
try {
|
||||
if (buf.readBoolean()) {
|
||||
this.fluid = AEFluidStack.loadFluidStackFromPacket(buf);
|
||||
} else {
|
||||
this.fluid = null;
|
||||
}
|
||||
this.slotIndex = buf.readInt();
|
||||
this.shift = buf.readBoolean();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
try {
|
||||
if (fluid == null) {
|
||||
buf.writeBoolean(false);
|
||||
} else {
|
||||
buf.writeBoolean(true);
|
||||
fluid.writeToPacket(buf);
|
||||
}
|
||||
buf.writeInt(this.slotIndex);
|
||||
buf.writeBoolean(this.shift);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketFluidUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketFluidUpdate message, MessageContext ctx) {
|
||||
Container container = ctx.getServerHandler().playerEntity.openContainer;
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
if (container instanceof ContainerFluidMonitor) {
|
||||
((ContainerFluidMonitor) container).postChange(message.fluid, player, message.slotIndex, message.shift);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,240 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.container.ContainerPatternMulti;
|
||||
import com.glodblock.github.client.gui.container.ContainerPatternValueAmount;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.container.implementations.ContainerPatternItemRenamer;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.tile.networking.TileCableBus;
|
||||
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;
|
||||
|
||||
public class CPacketInventoryAction implements IMessage {
|
||||
|
||||
private InventoryAction action;
|
||||
private int slot;
|
||||
private long id;
|
||||
private IAEItemStack stack;
|
||||
private boolean isEmpty;
|
||||
|
||||
public CPacketInventoryAction() {}
|
||||
|
||||
public CPacketInventoryAction(final InventoryAction action, final int slot, final long id) {
|
||||
this.action = action;
|
||||
this.slot = slot;
|
||||
this.id = id;
|
||||
this.stack = null;
|
||||
this.isEmpty = true;
|
||||
}
|
||||
|
||||
public CPacketInventoryAction(final InventoryAction action, final int slot, final long id, IAEItemStack stack) {
|
||||
this.action = action;
|
||||
this.slot = slot;
|
||||
this.id = id;
|
||||
this.stack = stack;
|
||||
this.isEmpty = stack == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(action.ordinal());
|
||||
buf.writeInt(slot);
|
||||
buf.writeLong(id);
|
||||
buf.writeBoolean(isEmpty);
|
||||
if (!isEmpty) {
|
||||
try {
|
||||
stack.writeToPacket(buf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
action = InventoryAction.values()[buf.readInt()];
|
||||
slot = buf.readInt();
|
||||
id = buf.readLong();
|
||||
isEmpty = buf.readBoolean();
|
||||
if (!isEmpty) {
|
||||
try {
|
||||
stack = AEItemStack.loadItemStackFromPacket(buf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketInventoryAction, IMessage> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(CPacketInventoryAction message, MessageContext ctx) {
|
||||
final EntityPlayerMP sender = ctx.getServerHandler().playerEntity;
|
||||
if (sender.openContainer instanceof final AEBaseContainer baseContainer) {
|
||||
Object target = baseContainer.getTarget();
|
||||
if (message.action == InventoryAction.AUTO_CRAFT) {
|
||||
final ContainerOpenContext context = baseContainer.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
te.getWorldObj(),
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(baseContainer.getOpenContext().getSide()),
|
||||
GuiType.FLUID_CRAFTING_AMOUNT);
|
||||
} else if (target instanceof IWirelessTerminal wt) {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
sender.worldObj,
|
||||
new BlockPos(
|
||||
wt.getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
0),
|
||||
ForgeDirection.UNKNOWN,
|
||||
GuiType.FLUID_CRAFTING_AMOUNT);
|
||||
}
|
||||
if (sender.openContainer instanceof final ContainerCraftAmount cca) {
|
||||
if (baseContainer.getTargetStack() != null) {
|
||||
cca.getCraftingItem().putStack(baseContainer.getTargetStack().getItemStack());
|
||||
cca.setItemToCraft(baseContainer.getTargetStack());
|
||||
if (message.id > 0) {
|
||||
cca.setInitialCraftAmount(message.id);
|
||||
}
|
||||
}
|
||||
cca.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
} else if (message.action == InventoryAction.SET_PATTERN_VALUE) {
|
||||
final ContainerOpenContext context = baseContainer.getOpenContext();
|
||||
if (context != null && message.stack != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
if (te instanceof TileCableBus) {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
te.getWorldObj(),
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(baseContainer.getOpenContext().getSide()),
|
||||
GuiType.PATTERN_VALUE_SET);
|
||||
} else {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
te.getWorldObj(),
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(baseContainer.getOpenContext().getSide()),
|
||||
GuiType.PATTERN_VALUE_SET_TILE);
|
||||
}
|
||||
} else if (target instanceof IWirelessTerminal wt) {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
sender.worldObj,
|
||||
new BlockPos(
|
||||
wt.getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
0),
|
||||
ForgeDirection.UNKNOWN,
|
||||
GuiType.PATTERN_VALUE_SET);
|
||||
}
|
||||
int amt = (int) message.stack.getStackSize();
|
||||
if (message.stack.getItem() instanceof ItemFluidPacket) {
|
||||
FluidStack fluid = ItemFluidPacket.getFluidStack(message.stack);
|
||||
amt = fluid == null ? 1 : fluid.amount;
|
||||
}
|
||||
FluidCraft.proxy.netHandler.sendTo(new SPacketSetItemAmount(amt), sender);
|
||||
if (sender.openContainer instanceof final ContainerPatternValueAmount cpv) {
|
||||
if (baseContainer.getTargetStack() != null) {
|
||||
cpv.setValueIndex(message.slot);
|
||||
cpv.getPatternValue().putStack(baseContainer.getTargetStack().getItemStack());
|
||||
}
|
||||
cpv.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
} else if (message.action == InventoryAction.SET_PATTERN_MULTI) {
|
||||
final ContainerOpenContext context = baseContainer.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
te.getWorldObj(),
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(baseContainer.getOpenContext().getSide()),
|
||||
GuiType.GUI_PATTERN_MULTI);
|
||||
} else if (target instanceof IWirelessTerminal wt) {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
sender.worldObj,
|
||||
new BlockPos(
|
||||
wt.getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
0),
|
||||
ForgeDirection.UNKNOWN,
|
||||
GuiType.GUI_PATTERN_MULTI);
|
||||
}
|
||||
if (sender.openContainer instanceof ContainerPatternMulti cpm) {
|
||||
cpm.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
} else if (message.action == InventoryAction.RENAME_PATTERN_ITEM) {
|
||||
final ContainerOpenContext context = baseContainer.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
te.getWorldObj(),
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(baseContainer.getOpenContext().getSide()),
|
||||
GuiType.GUI_PATTERN_ITEM_RENAMER);
|
||||
} else if (target instanceof IWirelessTerminal wt) {
|
||||
InventoryHandler.openGui(
|
||||
sender,
|
||||
sender.worldObj,
|
||||
new BlockPos(
|
||||
wt.getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
0),
|
||||
ForgeDirection.UNKNOWN,
|
||||
GuiType.GUI_PATTERN_ITEM_RENAMER);
|
||||
}
|
||||
if (sender.openContainer instanceof ContainerPatternItemRenamer cpir) {
|
||||
if (baseContainer.getTargetStack() != null) {
|
||||
cpir.getPatternValue().putStack(baseContainer.getTargetStack().getItemStack());
|
||||
}
|
||||
cpir.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
}else {
|
||||
baseContainer.doAction(sender, message.action, message.slot, message.id);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,24 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.common.parts.PartFluidLevelEmitter;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
|
||||
import appeng.api.parts.ILevelEmitter;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.parts.automation.PartLevelEmitter;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.PrimaryGui;
|
||||
import appeng.container.interfaces.IContainerSubGui;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -35,6 +41,7 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
DISABLE,
|
||||
ENABLE_ALL,
|
||||
DISABLE_ALL,
|
||||
RENAME
|
||||
}
|
||||
|
||||
public CPacketLevelTerminalCommands() {}
|
||||
@@ -57,7 +64,7 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
action = Action.values()[buf.readInt()];
|
||||
switch (action) {
|
||||
case EDIT -> {
|
||||
case EDIT, RENAME -> {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
@@ -83,7 +90,7 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(action.ordinal());
|
||||
switch (action) {
|
||||
case EDIT -> {
|
||||
case EDIT, RENAME -> {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
@@ -110,30 +117,25 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
@Override
|
||||
public IMessage onMessage(CPacketLevelTerminalCommands message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
switch (message.action) {
|
||||
case EDIT -> {
|
||||
|
||||
if (Objects.requireNonNull(message.action) == Action.EDIT) {
|
||||
if (player.openContainer instanceof AEBaseContainer abc) {
|
||||
final PrimaryGui pGui = abc.getPrimaryGui();
|
||||
|
||||
TileEntity tile = DimensionManager.getWorld(message.dim)
|
||||
.getTileEntity(message.x, message.y, message.z);
|
||||
|
||||
if (tile instanceof IPartHost host) {
|
||||
IPart part = host.getPart(message.side);
|
||||
if (part instanceof PartLevelEmitter) {
|
||||
if (part instanceof ILevelEmitter) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
tile.getWorldObj(),
|
||||
new BlockPos(tile),
|
||||
message.side,
|
||||
GuiType.LEVEL_EMITTER_PROXY);
|
||||
} else if (part instanceof PartFluidLevelEmitter) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
tile.getWorldObj(),
|
||||
new BlockPos(tile),
|
||||
message.side,
|
||||
GuiType.FLUID_LEVEL_EMITTER);
|
||||
}
|
||||
} else {
|
||||
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
tile.getWorldObj(),
|
||||
@@ -141,21 +143,24 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
message.side,
|
||||
GuiType.LEVEL_MAINTAINER);
|
||||
}
|
||||
}
|
||||
case BACK -> {
|
||||
GuiType originalGui = GuiType.getByOrdinal(message.originalGui);
|
||||
if (originalGui == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(message.x, message.y, message.z, DimensionManager.getWorld(message.dim)),
|
||||
message.side,
|
||||
originalGui);
|
||||
if (player.openContainer instanceof IContainerSubGui sg) {
|
||||
sg.setPrimaryGui(pGui);
|
||||
}
|
||||
}
|
||||
} else if (Objects.requireNonNull(message.action) == Action.RENAME) {
|
||||
if (player.openContainer instanceof AEBaseContainer abc) {
|
||||
final PrimaryGui pGui = abc.getPrimaryGui();
|
||||
|
||||
TileEntity tile = DimensionManager.getWorld(message.dim)
|
||||
.getTileEntity(message.x, message.y, message.z);
|
||||
|
||||
Platform.openGUI(player, tile, message.side, GuiBridge.GUI_RENAMER);
|
||||
|
||||
if (player.openContainer instanceof IContainerSubGui sg) {
|
||||
sg.setPrimaryGui(pGui);
|
||||
}
|
||||
}
|
||||
default -> {}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerPatternMulti;
|
||||
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
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;
|
||||
|
||||
public class CPacketPatternMultiSet implements IMessage {
|
||||
|
||||
private static GuiType guiType;
|
||||
private static int multi;
|
||||
|
||||
public CPacketPatternMultiSet(GuiType guiType, int multi) {
|
||||
CPacketPatternMultiSet.guiType = guiType;
|
||||
CPacketPatternMultiSet.multi = multi;
|
||||
}
|
||||
|
||||
public CPacketPatternMultiSet() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf byteBuf) {
|
||||
guiType = GuiType.getByOrdinal(byteBuf.readByte());
|
||||
multi = byteBuf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf byteBuf) {
|
||||
byteBuf.writeByte(guiType != null ? guiType.ordinal() : 0);
|
||||
byteBuf.writeInt(multi);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketPatternMultiSet, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketPatternMultiSet message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
if (player.openContainer instanceof ContainerPatternMulti cpv) {
|
||||
final Object target = cpv.getTarget();
|
||||
if (target instanceof IGridHost) {
|
||||
final ContainerOpenContext context = cpv.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
te.getWorldObj(),
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(cpv.getOpenContext().getSide()),
|
||||
guiType);
|
||||
} else if (target instanceof IWirelessTerminal wt) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(
|
||||
wt.getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
0),
|
||||
ForgeDirection.UNKNOWN,
|
||||
guiType);
|
||||
}
|
||||
if (player.openContainer instanceof FCContainerEncodeTerminal cpt) {
|
||||
cpt.multiplyOrDivideStacks(multi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerPatternValueAmount;
|
||||
import com.glodblock.github.client.gui.container.ContainerSuperStockReplenisher;
|
||||
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.gui.PartOrItemGuiFactory;
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.slot.SlotFake;
|
||||
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;
|
||||
|
||||
public class CPacketPatternValueSet implements IMessage {
|
||||
|
||||
private GuiType originGui;
|
||||
private int amount;
|
||||
private int valueIndex;
|
||||
|
||||
public CPacketPatternValueSet() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public CPacketPatternValueSet(int originalGui, int amount, int valueIndex) {
|
||||
this.originGui = GuiType.getByOrdinal(originalGui);
|
||||
this.amount = amount;
|
||||
this.valueIndex = valueIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(originGui.ordinal());
|
||||
buf.writeInt(amount);
|
||||
buf.writeInt(valueIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.originGui = GuiType.getByOrdinal(buf.readInt());
|
||||
this.amount = buf.readInt();
|
||||
this.valueIndex = buf.readInt();
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketPatternValueSet, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketPatternValueSet message, MessageContext ctx) {
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
if (player.openContainer instanceof ContainerPatternValueAmount cpv) {
|
||||
final Object target = cpv.getTarget();
|
||||
if (target instanceof IGridHost) {
|
||||
final ContainerOpenContext context = cpv.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.originGui);
|
||||
} else if (message.originGui.guiFactory instanceof PartOrItemGuiFactory) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(
|
||||
player.inventory.currentItem,
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
0),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.originGui);
|
||||
} else if (target instanceof IWirelessTerminal) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(((IWirelessTerminal) target).getInventorySlot(), 0, 0),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.originGui);
|
||||
}
|
||||
if (player.openContainer instanceof FCContainerEncodeTerminal
|
||||
|| player.openContainer instanceof ContainerSuperStockReplenisher) {
|
||||
Slot slot = player.openContainer.getSlot(message.valueIndex);
|
||||
if (slot instanceof SlotFake) {
|
||||
ItemStack stack = slot.getStack().copy();
|
||||
if (Util.isFluidPacket(stack)) {
|
||||
FluidStack fluidStack = ItemFluidPacket.getFluidStack(stack);
|
||||
if (fluidStack != null) {
|
||||
fluidStack = ItemFluidPacket.getFluidStack(stack).copy();
|
||||
fluidStack.amount = message.amount;
|
||||
}
|
||||
slot.putStack(ItemFluidPacket.newStack(fluidStack));
|
||||
} else {
|
||||
stack.stackSize = message.amount;
|
||||
slot.putStack(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IClickableInTerminal;
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.helpers.ICustomNameObject;
|
||||
import appeng.tile.networking.TileCableBus;
|
||||
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;
|
||||
|
||||
public class CPacketRenamer implements IMessage {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int dim;
|
||||
private ForgeDirection side;
|
||||
private Action action;
|
||||
private String text;
|
||||
|
||||
public enum Action {
|
||||
OPEN,
|
||||
GET_TEXT,
|
||||
SET_TEXT,
|
||||
}
|
||||
|
||||
public CPacketRenamer() {}
|
||||
|
||||
public CPacketRenamer(String text) {
|
||||
this.action = Action.SET_TEXT;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public CPacketRenamer(Action a) {
|
||||
this.action = a;
|
||||
}
|
||||
|
||||
public CPacketRenamer(int x, int y, int z, int dim, ForgeDirection side) {
|
||||
this.action = Action.OPEN;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.dim = dim;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.action = Action.values()[buf.readInt()];
|
||||
if (this.action == Action.OPEN) {
|
||||
this.x = buf.readInt();
|
||||
this.y = buf.readInt();
|
||||
this.z = buf.readInt();
|
||||
this.dim = buf.readInt();
|
||||
this.side = ForgeDirection.getOrientation(buf.readInt());
|
||||
} else if (this.action == Action.SET_TEXT) {
|
||||
int leName = buf.readInt();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < leName; i++) {
|
||||
sb.append(buf.readChar());
|
||||
}
|
||||
this.text = sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(this.action.ordinal());
|
||||
if (this.action == Action.OPEN) {
|
||||
buf.writeInt(this.x);
|
||||
buf.writeInt(this.y);
|
||||
buf.writeInt(this.z);
|
||||
buf.writeInt(this.dim);
|
||||
buf.writeInt(side.ordinal());
|
||||
} else if (this.action == Action.SET_TEXT) {
|
||||
buf.writeInt(this.text.length());
|
||||
for (int i = 0; i < this.text.length(); i++) {
|
||||
buf.writeChar(this.text.charAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketRenamer, IMessage> {
|
||||
|
||||
private String getName(ICustomNameObject obj) {
|
||||
return obj.hasCustomName() ? obj.getCustomName() : "";
|
||||
}
|
||||
|
||||
private String getName(TileEntity tile, ForgeDirection side) {
|
||||
if (tile instanceof TileCableBus) {
|
||||
return getName((ICustomNameObject) ((TileCableBus) tile).getPart(side));
|
||||
} else {
|
||||
return getName((ICustomNameObject) tile);
|
||||
}
|
||||
}
|
||||
|
||||
private void setName(TileEntity tile, ForgeDirection side, String text) {
|
||||
if (tile instanceof TileCableBus) {
|
||||
((ICustomNameObject) ((TileCableBus) tile).getPart(side)).setCustomName(text);
|
||||
} else {
|
||||
((ICustomNameObject) tile).setCustomName(text);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(CPacketRenamer message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
AEBaseContainer con = (AEBaseContainer) player.openContainer;
|
||||
switch (message.action) {
|
||||
case OPEN -> {
|
||||
if (con.getTarget() instanceof IClickableInTerminal clickableInterface) {
|
||||
TileEntity tile = DimensionManager.getWorld(message.dim)
|
||||
.getTileEntity(message.x, message.y, message.z);
|
||||
if (!(tile instanceof ICustomNameObject)) {
|
||||
break;
|
||||
}
|
||||
|
||||
String name = getName(tile, message.side);
|
||||
clickableInterface.setClickedInterface(
|
||||
new Util.DimensionalCoordSide(
|
||||
message.x,
|
||||
message.y,
|
||||
message.z,
|
||||
message.dim,
|
||||
message.side,
|
||||
name));
|
||||
|
||||
if (con.getTarget() instanceof IWirelessTerminal terminal) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(
|
||||
terminal.getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
1),
|
||||
message.side,
|
||||
GuiType.RENAMER);
|
||||
} else if (con.getTarget() instanceof IUpgradeableHost host) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(host.getTile()),
|
||||
con.getOpenContext().getSide(),
|
||||
GuiType.RENAMER);
|
||||
}
|
||||
}
|
||||
}
|
||||
case GET_TEXT -> {
|
||||
if (con.getTarget() instanceof IClickableInTerminal clickableInterface) {
|
||||
Util.DimensionalCoordSide intMsg = clickableInterface.getClickedInterface();
|
||||
TileEntity tile = DimensionManager.getWorld(intMsg.getDimension())
|
||||
.getTileEntity(intMsg.x, intMsg.y, intMsg.z);
|
||||
FluidCraft.proxy.netHandler
|
||||
.sendTo(new SPacketStringUpdate(this.getName(tile, intMsg.getSide())), player);
|
||||
}
|
||||
}
|
||||
case SET_TEXT -> {
|
||||
if (con.getTarget() instanceof IClickableInTerminal clickableInterface) {
|
||||
Util.DimensionalCoordSide intMsg = clickableInterface.getClickedInterface();
|
||||
TileEntity tile = DimensionManager.getWorld(intMsg.getDimension())
|
||||
.getTileEntity(intMsg.x, intMsg.y, intMsg.z);
|
||||
this.setName(tile, intMsg.getSide(), message.text);
|
||||
|
||||
FluidCraft.proxy.netHandler.sendTo(new SPacketSwitchBack(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,17 +6,28 @@ import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
|
||||
import com.glodblock.github.common.parts.PartFluidInterface;
|
||||
import com.glodblock.github.common.parts.PartFluidP2PInterface;
|
||||
import com.glodblock.github.common.tile.TileFluidInterface;
|
||||
import com.glodblock.github.common.tile.TileSuperStockReplenisher;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.UltraTerminalModes;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.PrimaryGui;
|
||||
import appeng.container.interfaces.IContainerSubGui;
|
||||
import appeng.helpers.ICustomButtonProvider;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -24,15 +35,15 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class CPacketSwitchGuis implements IMessage {
|
||||
|
||||
private GuiType guiType;
|
||||
private UltraTerminalModes mode;
|
||||
private boolean switchTerminal;
|
||||
|
||||
public CPacketSwitchGuis(GuiType guiType) {
|
||||
this(guiType, false);
|
||||
public CPacketSwitchGuis(UltraTerminalModes mode) {
|
||||
this(mode, false);
|
||||
}
|
||||
|
||||
public CPacketSwitchGuis(GuiType guiType, boolean switchTerminal) {
|
||||
this.guiType = guiType;
|
||||
public CPacketSwitchGuis(UltraTerminalModes mode, boolean switchTerminal) {
|
||||
this.mode = mode;
|
||||
this.switchTerminal = switchTerminal;
|
||||
}
|
||||
|
||||
@@ -42,13 +53,14 @@ public class CPacketSwitchGuis implements IMessage {
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf byteBuf) {
|
||||
guiType = GuiType.getByOrdinal(byteBuf.readByte());
|
||||
final int ord = byteBuf.readInt();
|
||||
mode = ord != -1 ? UltraTerminalModes.values()[ord] : null;
|
||||
switchTerminal = byteBuf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf byteBuf) {
|
||||
byteBuf.writeByte(guiType != null ? guiType.ordinal() : 0);
|
||||
byteBuf.writeInt(mode != null ? mode.ordinal() : -1);
|
||||
byteBuf.writeBoolean(this.switchTerminal);
|
||||
}
|
||||
|
||||
@@ -57,43 +69,51 @@ public class CPacketSwitchGuis implements IMessage {
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(CPacketSwitchGuis message, MessageContext ctx) {
|
||||
if (message.guiType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
Container cont = player.openContainer;
|
||||
|
||||
// switch terminal
|
||||
if (message.switchTerminal) {
|
||||
ItemWirelessUltraTerminal.switchTerminal(player, message.guiType);
|
||||
return null;
|
||||
}
|
||||
|
||||
// open new terminal
|
||||
if (cont instanceof AEBaseContainer) {
|
||||
ContainerOpenContext context = ((AEBaseContainer) cont).getOpenContext();
|
||||
if (context == null) {
|
||||
return null;
|
||||
if (message.switchTerminal) {
|
||||
ImmutablePair<Integer, ItemStack> temp = Util.getUltraWirelessTerm(player);
|
||||
if (temp != null && temp.getRight().getItem() instanceof ItemWirelessUltraTerminal iwut) {
|
||||
if (message.mode != null && cont instanceof AEBaseContainer abc) {
|
||||
abc.setSwitchAbleGuiNext(message.mode.ordinal());
|
||||
|
||||
}
|
||||
iwut.switchTerminal(player, temp, message.mode);
|
||||
if (player.openContainer instanceof AEBaseContainer abc) {
|
||||
if (abc.getTarget() instanceof ICustomButtonProvider icbp) {
|
||||
FluidCraft.proxy.netHandler
|
||||
.sendTo(new SPacketCustomButtonUpdate(icbp.getDataObject()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
} else {
|
||||
if (cont instanceof AEBaseContainer aeBaseContainer) {
|
||||
final PrimaryGui pGui = aeBaseContainer.getPrimaryGui();
|
||||
ContainerOpenContext context = aeBaseContainer.getOpenContext();
|
||||
if (context == null) return null;
|
||||
TileEntity te = context.getTile();
|
||||
Object target = aeBaseContainer.getTarget();
|
||||
GuiType guiType;
|
||||
|
||||
if (te instanceof TileSuperStockReplenisher) guiType = GuiType.GUI_SUPER_STOCK_REPLENISHER;
|
||||
else if (te instanceof TileFluidInterface || target instanceof PartFluidInterface
|
||||
|| target instanceof PartFluidP2PInterface)
|
||||
guiType = GuiType.DUAL_INTERFACE_FLUID;
|
||||
else return null;
|
||||
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.guiType);
|
||||
} else if (((AEBaseContainer) cont).getTarget() instanceof IWirelessTerminal) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(
|
||||
((IWirelessTerminal) ((AEBaseContainer) cont).getTarget()).getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
0),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.guiType);
|
||||
guiType);
|
||||
|
||||
if (player.openContainer instanceof IContainerSubGui sg) {
|
||||
sg.setPrimaryGui(pGui);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerItemMonitor;
|
||||
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;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
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;
|
||||
|
||||
public class CPacketTransferRecipe implements IMessage {
|
||||
|
||||
private List<OrderStack<?>> inputs;
|
||||
private List<OrderStack<?>> outputs;
|
||||
private boolean isCraft;
|
||||
private static final int MAX_INDEX = 81;
|
||||
private static final int MAX_SLOTS_INDEX = 32;
|
||||
private boolean shift;
|
||||
|
||||
public CPacketTransferRecipe() {}
|
||||
|
||||
public CPacketTransferRecipe(List<OrderStack<?>> IN, List<OrderStack<?>> OUT, boolean craft) {
|
||||
this(IN, OUT, craft, false);
|
||||
}
|
||||
|
||||
public CPacketTransferRecipe(List<OrderStack<?>> IN, List<OrderStack<?>> OUT, boolean craft, boolean shift) {
|
||||
this.inputs = IN;
|
||||
this.outputs = OUT;
|
||||
this.isCraft = craft;
|
||||
this.shift = shift;
|
||||
}
|
||||
|
||||
// TODO: this should use GZIP to compress the message
|
||||
// NBT to ByteBuf has a compress stream
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeBoolean(isCraft);
|
||||
buf.writeBoolean(shift);
|
||||
NBTTagCompound nbt_m = new NBTTagCompound();
|
||||
NBTTagCompound nbt_i = new NBTTagCompound();
|
||||
NBTTagCompound nbt_o = new NBTTagCompound();
|
||||
for (OrderStack<?> stack : inputs) {
|
||||
stack.writeToNBT(nbt_i);
|
||||
}
|
||||
for (OrderStack<?> stack : outputs) {
|
||||
stack.writeToNBT(nbt_o);
|
||||
}
|
||||
nbt_m.setTag("i", nbt_i);
|
||||
nbt_m.setTag("o", nbt_o);
|
||||
ByteBufUtils.writeTag(buf, nbt_m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
isCraft = buf.readBoolean();
|
||||
shift = buf.readBoolean();
|
||||
inputs = new LinkedList<>();
|
||||
outputs = new LinkedList<>();
|
||||
NBTTagCompound nbt_m = ByteBufUtils.readTag(buf);
|
||||
NBTTagCompound nbt_i = nbt_m.getCompoundTag("i");
|
||||
NBTTagCompound nbt_o = nbt_m.getCompoundTag("o");
|
||||
for (int i = 0; i < MAX_INDEX; i++) {
|
||||
OrderStack<?> tmp = OrderStack.readFromNBT(nbt_i, null, i);
|
||||
if (tmp != null && inputs.size() < MAX_SLOTS_INDEX) inputs.add(tmp);
|
||||
}
|
||||
for (int i = 0; i < MAX_INDEX; i++) {
|
||||
OrderStack<?> tmp = OrderStack.readFromNBT(nbt_o, null, i);
|
||||
if (tmp != null && inputs.size() < MAX_SLOTS_INDEX) outputs.add(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketTransferRecipe, IMessage> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) {
|
||||
Container c = ctx.getServerHandler().playerEntity.openContainer;
|
||||
if (c instanceof ContainerItemMonitor) {
|
||||
IMEMonitor<IAEItemStack> monitor = ((ContainerItemMonitor) c).getMonitor();
|
||||
IItemList<IAEItemStack> storageList = AEApi.instance().storage().createItemList();
|
||||
if (monitor != null) {
|
||||
storageList = monitor.getStorageList();
|
||||
}
|
||||
if (c instanceof FCContainerEncodeTerminal cf) {
|
||||
// pattern terminal only
|
||||
|
||||
boolean combine = cf.combine;
|
||||
cf.getPatternTerminal().setCraftingRecipe(message.isCraft);
|
||||
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 (!message.isCraft) {
|
||||
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);
|
||||
}
|
||||
// using exists item to fill slot
|
||||
if (message.shift && !storageList.isEmpty()) {
|
||||
for (@SuppressWarnings("rawtypes")
|
||||
OrderStack stack : message.inputs) {
|
||||
if (stack.getStack() instanceof FluidStack || stack.getItems() == null) continue;
|
||||
IAEItemStack iaeItemStack = AEApi.instance().storage()
|
||||
.createItemStack((ItemStack) stack.getStack());
|
||||
if (storageList.findPrecise(iaeItemStack) == null) {
|
||||
// try to replace item
|
||||
for (ItemStack replaceItemStack : stack.getItems()) {
|
||||
if (storageList.findPrecise(
|
||||
AEApi.instance().storage().createItemStack(replaceItemStack)) != null) {
|
||||
stack.putStack(replaceItemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import static com.glodblock.github.util.Util.toggleRestock;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ContainerPlayer;
|
||||
@@ -9,15 +11,16 @@ import net.minecraft.util.StatCollector;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidLevelEmitter;
|
||||
import com.glodblock.github.common.item.ItemBaseWirelessTerminal;
|
||||
import com.glodblock.github.inventory.item.WirelessCraftingTerminalInventory;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
@@ -55,15 +58,12 @@ public class CPacketValueConfig implements IMessage {
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
Container container = player.openContainer;
|
||||
if (container != null) {
|
||||
if (container instanceof ContainerFluidLevelEmitter) {
|
||||
((ContainerFluidLevelEmitter) container).setLevel(message.amount, player);
|
||||
} else if (container instanceof ContainerPlayer) {
|
||||
if (container instanceof ContainerPlayer) {
|
||||
ImmutablePair<Integer, ItemStack> result = Util.getUltraWirelessTerm(player);
|
||||
if (result != null) {
|
||||
final ItemStack wirelessTerm = result.getRight();
|
||||
if (message.valueIndex == 1) {
|
||||
ItemBaseWirelessTerminal
|
||||
.toggleRestockItemsMode(wirelessTerm, !Util.isRestock(wirelessTerm));
|
||||
toggleRestock(wirelessTerm);
|
||||
player.addChatMessage(
|
||||
new ChatComponentText(
|
||||
StatCollector.translateToLocal(
|
||||
@@ -85,25 +85,31 @@ public class CPacketValueConfig implements IMessage {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void restockItems(ItemStack terminal, IGridNode gridNode, int slot, EntityPlayer player) {
|
||||
WirelessCraftingTerminalInventory inv = new WirelessCraftingTerminalInventory(
|
||||
terminal,
|
||||
slot,
|
||||
gridNode,
|
||||
player);
|
||||
IGrid targetGrid = gridNode.getGrid();
|
||||
IMEMonitor<IAEItemStack> itemStorage = null;
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack is = player.inventory.mainInventory[i];
|
||||
if (is != null) {
|
||||
int maxSize = is.getMaxStackSize();
|
||||
if (is.stackSize < maxSize) {
|
||||
int fillSize = maxSize - is.stackSize;
|
||||
IAEItemStack ias = AEApi.instance().storage().createItemStack(is);
|
||||
ias.setStackSize(fillSize);
|
||||
if (targetGrid != null) {
|
||||
IStorageGrid sg = targetGrid.getCache(IStorageGrid.class);
|
||||
if (sg != null) {
|
||||
itemStorage = sg.getItemInventory();
|
||||
}
|
||||
}
|
||||
|
||||
IAEItemStack extractedItem = (IAEItemStack) inv
|
||||
.extractItems(ias, Actionable.MODULATE, inv.getActionSource());
|
||||
if (extractedItem != null) {
|
||||
player.inventory.addItemStackToInventory(extractedItem.getItemStack());
|
||||
if (itemStorage != null) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack is = player.inventory.mainInventory[i];
|
||||
if (is != null) {
|
||||
int maxSize = is.getMaxStackSize();
|
||||
if (is.stackSize < maxSize) {
|
||||
int fillSize = maxSize - is.stackSize;
|
||||
IAEItemStack ias = AEApi.instance().storage().createItemStack(is);
|
||||
ias.setStackSize(fillSize);
|
||||
|
||||
IAEItemStack extractedItem = itemStorage
|
||||
.extractItems(ias, Actionable.MODULATE, new PlayerSource(player, null));
|
||||
if (extractedItem != null) {
|
||||
player.inventory.addItemStackToInventory(extractedItem.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.helpers.ICustomButtonDataObject;
|
||||
import appeng.helpers.ICustomButtonProvider;
|
||||
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;
|
||||
|
||||
public class SPacketCustomButtonUpdate implements IMessage {
|
||||
|
||||
private ICustomButtonDataObject dataObject;
|
||||
|
||||
private ByteBuf buf;
|
||||
|
||||
public SPacketCustomButtonUpdate() {}
|
||||
|
||||
public SPacketCustomButtonUpdate(ICustomButtonDataObject dataObject) {
|
||||
this.dataObject = dataObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.buf = buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
this.dataObject.writeByte(buf);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketCustomButtonUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SPacketCustomButtonUpdate message, MessageContext ctx) {
|
||||
if (Minecraft.getMinecraft().thePlayer.openContainer instanceof AEBaseContainer abc
|
||||
&& abc.getTarget() instanceof ICustomButtonProvider icbp) {
|
||||
icbp.getDataObject().readByte(message.buf);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiEssentiaTerminal;
|
||||
import com.glodblock.github.client.gui.GuiFluidIO;
|
||||
import com.glodblock.github.client.gui.GuiFluidInterface;
|
||||
import com.glodblock.github.client.gui.GuiFluidLevelEmitter;
|
||||
import com.glodblock.github.client.gui.GuiFluidStorageBus;
|
||||
import com.glodblock.github.client.gui.GuiFluidTerminal;
|
||||
import com.glodblock.github.client.gui.GuiIngredientBuffer;
|
||||
import com.glodblock.github.client.gui.GuiLargeIngredientBuffer;
|
||||
import com.glodblock.github.util.Util;
|
||||
@@ -90,33 +85,10 @@ public class SPacketFluidUpdate implements IMessage {
|
||||
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet()) {
|
||||
((GuiLargeIngredientBuffer) gs).update(e.getKey(), e.getValue());
|
||||
}
|
||||
} else if (gs instanceof GuiFluidIO) {
|
||||
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet()) {
|
||||
((GuiFluidIO) gs).update(e.getKey(), e.getValue());
|
||||
}
|
||||
} else if (gs instanceof GuiFluidInterface) {
|
||||
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet()) {
|
||||
((GuiFluidInterface) gs).update(e.getKey(), e.getValue());
|
||||
}
|
||||
} else if (gs instanceof GuiFluidTerminal) {
|
||||
if (message.itemStack != null) {
|
||||
((GuiFluidTerminal) gs).update(message.itemStack.getItemStack());
|
||||
} else {
|
||||
((GuiFluidTerminal) gs).update(null);
|
||||
}
|
||||
} else if (gs instanceof GuiEssentiaTerminal) {
|
||||
if (message.itemStack != null) {
|
||||
((GuiEssentiaTerminal) gs).update(message.itemStack.getItemStack());
|
||||
} else {
|
||||
((GuiEssentiaTerminal) gs).update(null);
|
||||
}
|
||||
} else if (gs instanceof GuiFluidStorageBus) {
|
||||
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet())
|
||||
((GuiFluidStorageBus) gs).update(e.getKey(), e.getValue());
|
||||
} else if (gs instanceof GuiFluidLevelEmitter) {
|
||||
for (Map.Entry<Integer, IAEFluidStack> e : message.list.entrySet()) {
|
||||
((GuiFluidLevelEmitter) gs).update(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import static com.glodblock.github.common.tile.TileLevelMaintainer.RequestInfo;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.api.registries.LevelState;
|
||||
import com.glodblock.github.client.gui.GuiLevelMaintainer;
|
||||
|
||||
import appeng.api.features.LevelState;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import static appeng.util.Platform.readStackByte;
|
||||
import static appeng.util.Platform.writeStackByte;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.glodblock.github.api.registries.LevelItemInfo;
|
||||
import com.glodblock.github.api.registries.LevelState;
|
||||
import com.glodblock.github.client.gui.GuiLevelTerminal;
|
||||
|
||||
import appeng.api.features.LevelItemInfo;
|
||||
import appeng.api.features.LevelState;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.features.AEFeature;
|
||||
@@ -176,7 +179,7 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
infolist = new LevelItemInfo[infoSize];
|
||||
for (int i = 0; i < infoSize; i++) {
|
||||
if (!buf.readBoolean()) continue;
|
||||
ItemStack stack = ByteBufUtils.readItemStack(buf);
|
||||
IAEStack<?> stack = readStackByte(buf);
|
||||
long quantity = buf.readLong();
|
||||
long batchSize = buf.readLong();
|
||||
LevelState state = LevelState.values()[buf.readInt()];
|
||||
@@ -206,7 +209,7 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
buf.writeBoolean(info != null);
|
||||
if (info == null) continue;
|
||||
// System.out.println("Writing info: " + info.stack != null);
|
||||
ByteBufUtils.writeItemStack(buf, info.stack);
|
||||
writeStackByte(info.stack, buf);
|
||||
buf.writeLong(info.quantity);
|
||||
buf.writeLong(info.batchSize);
|
||||
buf.writeInt(info.state.ordinal());
|
||||
@@ -293,7 +296,7 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
this.index = buf.readInt();
|
||||
if (buf.readBoolean()) {
|
||||
this.info = new LevelItemInfo(
|
||||
ByteBufUtils.readItemStack(buf),
|
||||
readStackByte(buf),
|
||||
buf.readLong(),
|
||||
buf.readLong(),
|
||||
LevelState.values()[buf.readInt()]);
|
||||
@@ -312,7 +315,7 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
super.write(buf);
|
||||
buf.writeInt(index);
|
||||
buf.writeBoolean(info != null);
|
||||
ByteBufUtils.writeItemStack(buf, info.stack);
|
||||
writeStackByte(info.stack, buf);
|
||||
buf.writeLong(info.quantity);
|
||||
buf.writeLong(info.batchSize);
|
||||
buf.writeInt(info.state.ordinal());
|
||||
@@ -334,7 +337,7 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
this.infoList = new LevelItemInfo[infoSize];
|
||||
for (int i = 0; i < infoSize; i++) {
|
||||
if (!buf.readBoolean()) continue;
|
||||
ItemStack stack = ByteBufUtils.readItemStack(buf);
|
||||
IAEStack<?> stack = readStackByte(buf);
|
||||
long quantity = buf.readLong();
|
||||
long batchSize = buf.readLong();
|
||||
LevelState state = LevelState.values()[buf.readInt()];
|
||||
@@ -356,7 +359,7 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
buf.writeBoolean(info != null);
|
||||
if (info == null) continue;
|
||||
buf.writeInt(i);
|
||||
ByteBufUtils.writeItemStack(buf, info.stack);
|
||||
writeStackByte(info.stack, buf);
|
||||
buf.writeLong(info.quantity);
|
||||
buf.writeLong(info.batchSize);
|
||||
buf.writeInt(info.state.ordinal());
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
|
||||
import com.glodblock.github.client.gui.GuiFluidMonitor;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Dedicated packet for fluid updates.
|
||||
*/
|
||||
public class SPacketMEFluidInvUpdate implements IMessage {
|
||||
|
||||
private List<IAEFluidStack> list = new ArrayList<>();
|
||||
private byte ref = (byte) 0;
|
||||
private boolean resort = true;
|
||||
|
||||
public SPacketMEFluidInvUpdate() {}
|
||||
|
||||
/**
|
||||
* Used for the GUI to confirm crafting. 0 = available 1 = pending 2 = missing
|
||||
*/
|
||||
public SPacketMEFluidInvUpdate(byte b) {
|
||||
ref = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* If resort, call "updateView()". Used when multiple packets are sent to open an inventory; only the last packet
|
||||
* should resort
|
||||
*
|
||||
* @param resort whether this packet should resort the term or not
|
||||
*/
|
||||
public SPacketMEFluidInvUpdate(boolean resort) {
|
||||
this.resort = resort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ref = buf.readByte();
|
||||
resort = buf.readBoolean();
|
||||
int amount = buf.readInt();
|
||||
list = new ArrayList<>(amount);
|
||||
try {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
list.add(AEFluidStack.loadFluidStackFromPacket(buf));
|
||||
}
|
||||
} catch (Exception io) {
|
||||
System.out.println("Error handling payload w/ " + amount + " items.");
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(ref);
|
||||
buf.writeBoolean(resort);
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (IAEFluidStack is : list) {
|
||||
is.writeToPacket(buf);
|
||||
}
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setResort(boolean resort) {
|
||||
this.resort = resort;
|
||||
}
|
||||
|
||||
public void appendFluid(final IAEFluidStack is) {
|
||||
list.add(is);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketMEFluidInvUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public IMessage onMessage(SPacketMEFluidInvUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiFluidMonitor) {
|
||||
((GuiFluidMonitor) gs).postUpdate(message.list, message.resort);
|
||||
} else if (gs instanceof GuiFluidCraftConfirm) {
|
||||
((GuiFluidCraftConfirm) gs).postUpdate((List) message.list, message.ref);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
|
||||
import com.glodblock.github.client.gui.GuiItemMonitor;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Packet dedicated to item inventory update.
|
||||
*/
|
||||
public class SPacketMEItemInvUpdate implements IMessage {
|
||||
|
||||
private List<IAEItemStack> list = new ArrayList<>();
|
||||
private byte ref = (byte) 0;
|
||||
private boolean resort = true;
|
||||
|
||||
public SPacketMEItemInvUpdate() {}
|
||||
|
||||
/**
|
||||
* Used for the GUI to confirm crafting. 0 = available 1 = pending 2 = missing
|
||||
*/
|
||||
public SPacketMEItemInvUpdate(byte b) {
|
||||
ref = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* If resort, call "updateView()". Used when multiple packets are sent to open an inventory; only the last packet
|
||||
* should resort.
|
||||
*
|
||||
* @param resort whether this packet should resort the term or not
|
||||
*/
|
||||
public SPacketMEItemInvUpdate(boolean resort) {
|
||||
this.resort = resort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ref = buf.readByte();
|
||||
resort = buf.readBoolean();
|
||||
int amount = buf.readInt();
|
||||
list = new ArrayList<>(amount);
|
||||
try {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
list.add(AEItemStack.loadItemStackFromPacket(buf));
|
||||
}
|
||||
} catch (Exception io) {
|
||||
System.out.println("Error handling payload w/ " + amount + " items.");
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(ref);
|
||||
buf.writeBoolean(resort);
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (IAEItemStack is : list) {
|
||||
is.writeToPacket(buf);
|
||||
}
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setResort(boolean resort) {
|
||||
this.resort = resort;
|
||||
}
|
||||
|
||||
public void appendItem(final IAEItemStack is) {
|
||||
list.add(is);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketMEItemInvUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SPacketMEItemInvUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiItemMonitor) {
|
||||
((GuiItemMonitor) gs).postUpdate(message.list, message.resort);
|
||||
} else if (gs instanceof GuiFluidCraftConfirm) {
|
||||
((GuiFluidCraftConfirm) gs).postUpdate(message.list, message.ref);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.Config;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
/**
|
||||
* Only should exist on the server side! Schedules packets to be sent every `packetRate` ms.
|
||||
*/
|
||||
public class SPacketMEUpdateBuffer {
|
||||
|
||||
private static ScheduledExecutorService executor;
|
||||
private static ScheduledFuture<?> task;
|
||||
|
||||
private static final Map<EntityPlayerMP, LinkedHashSet<IAEItemStack>> itemBuffer = new HashMap<>();
|
||||
private static final Map<EntityPlayerMP, LinkedHashSet<IAEFluidStack>> fluidBuffer = new HashMap<>();
|
||||
|
||||
public static void start() {
|
||||
executor = Executors.newSingleThreadScheduledExecutor(r -> {
|
||||
Thread thread = new Thread(r);
|
||||
thread.setName("AE2FC Network worker");
|
||||
thread.setDaemon(true);
|
||||
thread.setPriority(6);
|
||||
return thread;
|
||||
});
|
||||
task = executor
|
||||
.scheduleAtFixedRate(SPacketMEUpdateBuffer::sendBuffer, 0, Config.packetRate, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
if (task != null) {
|
||||
task.cancel(false);
|
||||
}
|
||||
if (executor != null) {
|
||||
executor.shutdown();
|
||||
}
|
||||
executor = null;
|
||||
task = null;
|
||||
synchronized (itemBuffer) {
|
||||
itemBuffer.clear();
|
||||
}
|
||||
synchronized (fluidBuffer) {
|
||||
fluidBuffer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleItemUpdate(EntityPlayerMP player, List<IAEItemStack> stacks) {
|
||||
synchronized (itemBuffer) {
|
||||
if (!itemBuffer.containsKey(player)) {
|
||||
itemBuffer.put(player, new LinkedHashSet<>(1024));
|
||||
}
|
||||
LinkedHashSet<IAEItemStack> buffer = itemBuffer.get(player);
|
||||
stacks.forEach(s -> buffer.add(s.copy()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleFluidUpdate(EntityPlayerMP player, List<IAEFluidStack> stacks) {
|
||||
synchronized (fluidBuffer) {
|
||||
if (!fluidBuffer.containsKey(player)) {
|
||||
fluidBuffer.put(player, new LinkedHashSet<>(1024));
|
||||
}
|
||||
LinkedHashSet<IAEFluidStack> buffer = fluidBuffer.get(player);
|
||||
stacks.forEach(s -> buffer.add(s.copy()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendBuffer() {
|
||||
synchronized (itemBuffer) {
|
||||
itemBuffer.forEach((player, updates) -> {
|
||||
if (updates.isEmpty()) return;
|
||||
int i = 0;
|
||||
SPacketMEItemInvUpdate packet = new SPacketMEItemInvUpdate(false);
|
||||
Iterator<IAEItemStack> it = updates.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (i < Config.packetSize) {
|
||||
packet.appendItem(it.next());
|
||||
it.remove();
|
||||
i++;
|
||||
} else {
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
packet = new SPacketMEItemInvUpdate(false);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
packet.setResort(true);
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
});
|
||||
}
|
||||
synchronized (fluidBuffer) {
|
||||
fluidBuffer.forEach((player, updates) -> {
|
||||
if (updates.isEmpty()) return;
|
||||
int i = 0;
|
||||
SPacketMEFluidInvUpdate packet = new SPacketMEFluidInvUpdate(false);
|
||||
Iterator<IAEFluidStack> it = updates.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (i < Config.packetSize) {
|
||||
packet.appendFluid(it.next());
|
||||
it.remove();
|
||||
i++;
|
||||
} else {
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
packet = new SPacketMEFluidInvUpdate(false);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
packet.setResort(true);
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear(EntityPlayerMP player) {
|
||||
synchronized (itemBuffer) {
|
||||
if (itemBuffer.containsKey(player)) {
|
||||
itemBuffer.get(player).clear();
|
||||
}
|
||||
}
|
||||
synchronized (fluidBuffer) {
|
||||
if (fluidBuffer.containsKey(player)) {
|
||||
fluidBuffer.get(player).clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
if (event.player instanceof EntityPlayerMP) {
|
||||
clear((EntityPlayerMP) event.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.implementations.ContainerPatternItemRenamer;
|
||||
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;
|
||||
|
||||
public class SPacketPatternItemRenamer implements IMessage {
|
||||
|
||||
private GuiType guiType;
|
||||
private String name = "";
|
||||
private int valueIndex;
|
||||
|
||||
public SPacketPatternItemRenamer() {}
|
||||
|
||||
public SPacketPatternItemRenamer(GuiType guiType, String text, int valIndex) {
|
||||
this.guiType = guiType;
|
||||
name = text;
|
||||
valueIndex = valIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(guiType != null ? guiType.ordinal() : 0);
|
||||
buf.writeInt(valueIndex);
|
||||
|
||||
buf.writeInt(name.length());
|
||||
for (int i = 0; i < name.length(); i++) {
|
||||
buf.writeChar(name.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
guiType = GuiType.getByOrdinal(buf.readByte());
|
||||
valueIndex = buf.readInt();
|
||||
|
||||
int leName = buf.readInt();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < leName; i++) {
|
||||
sb.append(buf.readChar());
|
||||
}
|
||||
name = sb.toString();
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketPatternItemRenamer, IMessage> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(SPacketPatternItemRenamer message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
if (player.openContainer instanceof ContainerPatternItemRenamer cpv) {
|
||||
ContainerOpenContext context = cpv.getOpenContext();
|
||||
if (context == null) {
|
||||
return null;
|
||||
}
|
||||
TileEntity te = context.getTile();
|
||||
if (te != null) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(te),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.guiType);
|
||||
} else if (cpv.getTarget() instanceof IWirelessTerminal iwt) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(
|
||||
iwt.getInventorySlot(),
|
||||
Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM),
|
||||
0),
|
||||
Objects.requireNonNull(context.getSide()),
|
||||
message.guiType);
|
||||
}
|
||||
if (player.openContainer instanceof FCContainerEncodeTerminal) {
|
||||
Slot slot = player.openContainer.getSlot(message.valueIndex);
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack nextStack = slot.getStack().copy();
|
||||
nextStack.setStackDisplayName(message.name);
|
||||
slot.putStack(nextStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiPatternValueAmount;
|
||||
|
||||
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;
|
||||
|
||||
public class SPacketSetItemAmount implements IMessage {
|
||||
|
||||
private int amount;
|
||||
|
||||
public SPacketSetItemAmount() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public SPacketSetItemAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
amount = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(amount);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketSetItemAmount, IMessage> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(SPacketSetItemAmount message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiPatternValueAmount) {
|
||||
((GuiPatternValueAmount) gs).setAmount(message.amount);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiRenamer;
|
||||
|
||||
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;
|
||||
|
||||
public class SPacketStringUpdate implements IMessage {
|
||||
|
||||
private String text;
|
||||
private int slot;
|
||||
|
||||
public SPacketStringUpdate() {}
|
||||
|
||||
public SPacketStringUpdate(String text, int slot) {
|
||||
this.text = text;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public SPacketStringUpdate(String text) {
|
||||
this.text = text;
|
||||
this.slot = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.slot = buf.readInt();
|
||||
int leName = buf.readInt();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < leName; i++) {
|
||||
sb.append(buf.readChar());
|
||||
}
|
||||
this.text = sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(this.slot);
|
||||
buf.writeInt(this.text.length());
|
||||
for (int i = 0; i < this.text.length(); i++) {
|
||||
buf.writeChar(this.text.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketStringUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SPacketStringUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiRenamer) {
|
||||
((GuiRenamer) gs).postUpdate(message.text);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiRenamer;
|
||||
|
||||
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;
|
||||
|
||||
public class SPacketSwitchBack implements IMessage {
|
||||
|
||||
public SPacketSwitchBack() {}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketSwitchBack, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SPacketSwitchBack message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiRenamer) {
|
||||
((GuiRenamer) gs).switchGui();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user