begin work

This commit is contained in:
GlodBlock committed 2022-05-10 17:57:38 +08:00
commit db2ad29b52
124 files changed
+11799

No files matched your search

@@ -0,0 +1,118 @@
package com.glodblock.github.network;
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.core.AELog;
import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.Util;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.concurrent.Future;
public class CPacketCraftRequest implements IMessage {
private long amount;
private boolean heldShift;
public CPacketCraftRequest() {
}
public CPacketCraftRequest( final int craftAmt, final boolean shift ) {
amount = craftAmt;
heldShift = shift;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeLong(amount);
buf.writeBoolean(heldShift);
}
@Override
public void fromBytes(ByteBuf buf) {
amount = buf.readLong();
heldShift = buf.readBoolean();
}
public static class Handler implements IMessageHandler<CPacketCraftRequest, IMessage> {
@Nullable
@Override
public IMessage onMessage(CPacketCraftRequest message, MessageContext ctx) {
if( ctx.getServerHandler().playerEntity.openContainer instanceof ContainerCraftAmount)
{
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
final ContainerCraftAmount cca = (ContainerCraftAmount) ctx.getServerHandler().playerEntity.openContainer;
final Object target = cca.getTarget();
if( target instanceof IGridHost)
{
final IGridHost gh = (IGridHost) target;
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 );
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();
InventoryHandler.openGui(player, player.worldObj, new BlockPos(te), Objects.requireNonNull(Util.from(context.getSide())), GuiType.FLUID_CRAFTING_CONFIRM);
if( player.openContainer instanceof ContainerFluidCraftConfirm)
{
final ContainerFluidCraftConfirm ccc = (ContainerFluidCraftConfirm) player.openContainer;
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,38 @@
package com.glodblock.github.network;
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;
import net.minecraft.entity.player.EntityPlayerMP;
import javax.annotation.Nullable;
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;
}
}
}
@@ -0,0 +1,95 @@
package com.glodblock.github.network;
import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm;
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.Container;
public class CPacketFluidPatternTermBtns implements IMessage {
private String Name = "";
private String Value = "";
public CPacketFluidPatternTermBtns( final String name, final String value ) {
Name = name;
Value = value;
}
public CPacketFluidPatternTermBtns() {
// NO-OP
}
@Override
public void fromBytes(ByteBuf buf) {
int leName = 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();
}
@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));
}
}
public static class Handler implements IMessageHandler<CPacketFluidPatternTermBtns, IMessage> {
@Override
public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ctx) {
String Name = message.Name;
String Value = message.Value;
final Container c = ctx.getServerHandler().playerEntity.openContainer;
if( Name.startsWith( "PatternTerminal." ) && c instanceof ContainerFluidPatternTerminal)
{
final ContainerFluidPatternTerminal cpt = (ContainerFluidPatternTerminal) c;
switch (Name) {
case "PatternTerminal.CraftMode":
cpt.getPatternTerminal().setCraftingRecipe(Value.equals("1"));
break;
case "PatternTerminal.Encode":
if (Value.equals("2"))
cpt.encodeAndMoveToInventory();
else
cpt.encode();
break;
case "PatternTerminal.Clear":
cpt.clear();
break;
case "PatternTerminal.Substitute":
cpt.getPatternTerminal().setSubstitution(Value.equals("1"));
break;
case "PatternTerminal.Double":
cpt.doubleStacks(Value.equals("1"));
break;
}
} else if(Name.equals( "Terminal.Cpu" ) && c instanceof ContainerFluidCraftConfirm) {
final ContainerFluidCraftConfirm qk = (ContainerFluidCraftConfirm) c;
qk.cycleCpu( Value.equals( "Next" ) );
}
else if( Name.equals( "Terminal.Start" ) && c instanceof ContainerFluidCraftConfirm ) {
final ContainerFluidCraftConfirm qk = (ContainerFluidCraftConfirm) c;
qk.startJob();
}
return null;
}
}
}
@@ -0,0 +1,124 @@
package com.glodblock.github.network;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.core.sync.GuiBridge;
import appeng.helpers.InventoryAction;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.Util;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Objects;
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 int 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 int 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 AEBaseContainer )
{
final AEBaseContainer baseContainer = (AEBaseContainer) sender.openContainer;
if( message.action == InventoryAction.AUTO_CRAFT )
{
final ContainerOpenContext context = baseContainer.getOpenContext();
if( context != null )
{
final TileEntity te = context.getTile();
InventoryHandler.openGui( sender, te.getWorldObj(), new BlockPos(te), Objects.requireNonNull(Util.from(baseContainer.getOpenContext().getSide())), GuiType.FLUID_CRAFTING_AMOUNT );
if( sender.openContainer instanceof ContainerCraftAmount )
{
final ContainerCraftAmount cca = (ContainerCraftAmount) sender.openContainer;
if( baseContainer.getTargetStack() != null )
{
cca.getCraftingItem().putStack( baseContainer.getTargetStack().getItemStack() );
cca.setItemToCraft( baseContainer.getTargetStack() );
}
cca.detectAndSendChanges();
}
}
}
else
{
baseContainer.doAction( sender, message.action, message.slot, message.id );
}
}
return null;
}
}
}
@@ -0,0 +1,56 @@
package com.glodblock.github.network;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.Container;
import java.io.IOException;
public class CPacketSetTargetItem implements IMessage {
private IAEItemStack stack;
public CPacketSetTargetItem() {
}
public CPacketSetTargetItem(IAEItemStack stack) {
this.stack = stack;
}
@Override
public void toBytes(ByteBuf buf) {
try {
stack.writeToPacket(buf);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void fromBytes(ByteBuf buf) {
try {
stack = AEItemStack.loadItemStackFromPacket(buf);
} catch (IOException e) {
e.printStackTrace();
}
}
public static class Handler implements IMessageHandler<CPacketSetTargetItem, IMessage> {
@Override
public IMessage onMessage(CPacketSetTargetItem message, MessageContext ctx) {
Container c = ctx.getServerHandler().playerEntity.openContainer;
if (c instanceof AEBaseContainer) {
((AEBaseContainer) c).setTargetStack(message.stack);
}
return null;
}
}
}
@@ -0,0 +1,68 @@
package com.glodblock.github.network;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.Util;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import javax.annotation.Nullable;
import java.util.Objects;
public class CPacketSwitchGuis implements IMessage {
private GuiType guiType;
public CPacketSwitchGuis(GuiType guiType) {
this.guiType = guiType;
}
public CPacketSwitchGuis() {
// NO-OP
}
@Override
public void fromBytes(ByteBuf byteBuf) {
guiType = GuiType.getByOrdinal(byteBuf.readByte());
}
@Override
public void toBytes(ByteBuf byteBuf) {
byteBuf.writeByte(guiType != null ? guiType.ordinal() : 0);
}
public static class Handler implements IMessageHandler<CPacketSwitchGuis, 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;
if (!(cont instanceof AEBaseContainer)) {
return null;
}
ContainerOpenContext context = ((AEBaseContainer)cont).getOpenContext();
if (context == null) {
return null;
}
TileEntity te = context.getTile();
if (te == null) {
return null;
}
InventoryHandler.openGui(player, player.worldObj, new BlockPos(te), Objects.requireNonNull(Util.from(context.getSide())), message.guiType);
return null;
}
}
}
@@ -0,0 +1,128 @@
package com.glodblock.github.network;
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.nei.object.OrderStack;
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;
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 javax.annotation.Nullable;
import java.util.LinkedList;
import java.util.List;
public class CPacketTransferRecipe implements IMessage {
private List<OrderStack<?>> inputs;
private List<OrderStack<?>> outputs;
private boolean isCraft;
private final static int MAX_INDEX = 16;
public CPacketTransferRecipe(){
}
public CPacketTransferRecipe(List<OrderStack<?>> IN, List<OrderStack<?>> OUT, boolean craft) {
this.inputs = IN;
this.outputs = OUT;
this.isCraft = craft;
}
//I should use GZIP to compress the message, but i'm too lazy.
//NBT to ByteBuf has a compress stream
@Override
public void toBytes(ByteBuf buf) {
buf.writeBoolean(isCraft);
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();
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.add(tmp);
}
for (int i = 0; i < MAX_INDEX; i ++) {
OrderStack<?> tmp = OrderStack.readFromNBT(nbt_o, null, i);
if (tmp != null) outputs.add(tmp);
}
}
public static class Handler implements IMessageHandler<CPacketTransferRecipe, IMessage> {
@Nullable
@Override
public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) {
Container c = ctx.getServerHandler().playerEntity.openContainer;
if (c instanceof ContainerFluidPatternTerminal) {
ContainerFluidPatternTerminal cf = (ContainerFluidPatternTerminal) c;
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);
}
for (OrderStack<?> stack : message.inputs) {
if (stack != null) {
int index = stack.getIndex();
ItemStack stack1;
if (stack.getStack() instanceof ItemStack) {
stack1 = ((ItemStack) stack.getStack()).copy();
}
else if (stack.getStack() instanceof FluidStack) {
stack1 = ItemFluidPacket.newStack((FluidStack) stack.getStack());
}
else throw new UnsupportedOperationException("Trying to get an unsupported item!");
if (index < inputSlot.getSizeInventory())
inputSlot.setInventorySlotContents(index, stack1);
}
}
for (OrderStack<?> stack : message.outputs) {
if (stack != null) {
int index = stack.getIndex();
ItemStack stack1;
if (stack.getStack() instanceof ItemStack) {
stack1 = ((ItemStack) stack.getStack()).copy();
}
else if (stack.getStack() instanceof FluidStack) {
stack1 = ItemFluidPacket.newStack((FluidStack) stack.getStack());
}
else throw new UnsupportedOperationException("Trying to get an unsupported item!");
if (index < outputSlot.getSizeInventory())
outputSlot.setInventorySlotContents(index, stack1);
}
}
c.onCraftMatrixChanged(inputSlot);
c.onCraftMatrixChanged(outputSlot);
}
return null;
}
}
}
@@ -0,0 +1,68 @@
package com.glodblock.github.network;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.item.AEFluidStack;
import com.glodblock.github.client.gui.IFluidSyncContainer;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.Container;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class SPacketFluidSlot implements IMessage {
private Map<Integer, IAEFluidStack> list;
public SPacketFluidSlot() {
}
public SPacketFluidSlot(Map<Integer, IAEFluidStack> data) {
this.list = data;
}
@Override
public void fromBytes(ByteBuf buf) {
int size = buf.readInt();
this.list = new HashMap<>();
try {
for (int i = 0; i < size; i ++) {
int id = buf.readInt();
IAEFluidStack fluid = AEFluidStack.loadFluidStackFromPacket(buf);
list.put(id, fluid);
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(list.size());
try {
for (Map.Entry<Integer, IAEFluidStack> fs : list.entrySet()) {
buf.writeInt(fs.getKey());
fs.getValue().writeToPacket(buf);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static class Handler implements IMessageHandler<SPacketFluidSlot, IMessage> {
@Override
public IMessage onMessage(SPacketFluidSlot message, MessageContext ctx) {
final Container c = ctx.getServerHandler().playerEntity.openContainer;
if( c instanceof IFluidSyncContainer)
{
( (IFluidSyncContainer) c ).receiveFluidSlots( message.list );
}
return null;
}
}
}
@@ -0,0 +1,84 @@
package com.glodblock.github.network;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEItemStack;
import com.glodblock.github.client.gui.GuiFCBaseMonitor;
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.util.LinkedList;
import java.util.List;
public class SPacketMEInventoryUpdate implements IMessage {
private List<IAEItemStack> list;
private byte ref;
public SPacketMEInventoryUpdate() {
ref = 0;
list = new LinkedList<>();
}
public SPacketMEInventoryUpdate(byte b) {
this.ref = b;
list = new LinkedList<>();
}
@Override
public void fromBytes(ByteBuf buf) {
long amount = buf.readLong();
ref = buf.readByte();
list = new LinkedList<>();
try {
for (int i = 0; i < amount; i ++) {
list.add(AEItemStack.loadItemStackFromPacket(buf));
}
} catch (IOException io) {
io.printStackTrace();
}
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeLong(list.size());
buf.writeByte(ref);
try {
for (IAEItemStack itemStack : list) {
itemStack.writeToPacket(buf);
}
} catch (IOException io) {
io.printStackTrace();
}
}
public void appendItem( final IAEItemStack is ) throws BufferOverflowException {
list.add(is);
}
public boolean isEmpty() {
return this.list.isEmpty();
}
public static class Handler implements IMessageHandler<SPacketMEInventoryUpdate, IMessage> {
@Override
public IMessage onMessage(SPacketMEInventoryUpdate message, MessageContext ctx) {
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if( gs instanceof GuiFCBaseMonitor)
{
( (GuiFCBaseMonitor) gs ).postUpdate(message.list);
}
else if ( gs instanceof GuiFluidCraftConfirm) {
( (GuiFluidCraftConfirm) gs ).postUpdate( message.list, message.ref );
}
return null;
}
}
}