Skip to content

Commit

Permalink
fix server npe + bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Dec 15, 2023
1 parent c96b684 commit f55321b
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 83 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'idea'

version = "2.4.33-r"
version = "2.5.0-r"
group = "ae2fc"
archivesBaseName = "Fluid Craft for AE2"

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/glodblock/github/FluidCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;

@Mod(modid = FluidCraft.MODID, version = FluidCraft.VERSION, useMetadata = true, dependencies = "required:appliedenergistics2@[v0.54.1,)")
@Mod(modid = FluidCraft.MODID, version = FluidCraft.VERSION, useMetadata = true, dependencies = "required:appliedenergistics2@[v0.55.27,)")
public class FluidCraft {

public static final String MODID = "ae2fc";
public static final String VERSION = "2.4.33-r";
public static final String VERSION = "2.5.0-r";

@Mod.Instance(MODID)
public static FluidCraft INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,25 @@
package com.glodblock.github.client.container;

import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ITerminalHost;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.helpers.PlayerSource;
import com.glodblock.github.common.part.PartExtendedFluidPatternTerminal;
import com.glodblock.github.common.part.PartFluidPatternTerminal;
import com.glodblock.github.inventory.GuiType;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.loader.FCItems;
import com.glodblock.github.util.Ae2Reflect;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;

public class ContainerFCCraftConfirm extends ContainerCraftConfirm {

public ContainerFCCraftConfirm(InventoryPlayer ip, ITerminalHost te) {
super(ip, te);
}

@Override
public void startJob() {
GuiType originalGui = null;
IActionHost ah = this.getActionHost();

if (ah instanceof WirelessTerminalGuiObject) {
ItemStack tool = ((WirelessTerminalGuiObject) ah).getItemStack();
if (tool.getItem() == FCItems.WIRELESS_FLUID_PATTERN_TERMINAL) {
originalGui = GuiType.WIRELESS_FLUID_PATTERN_TERMINAL;
}
}

if (ah instanceof PartFluidPatternTerminal) {
originalGui = GuiType.FLUID_PATTERN_TERMINAL;
}

if (ah instanceof PartExtendedFluidPatternTerminal) {
originalGui = GuiType.FLUID_EXTENDED_PATTERN_TERMINAL;
}

IActionHost h = (IActionHost)this.getTarget();
if (h != null) {
IGridNode node = h.getActionableNode();
IGrid grid = node.getGrid();
if (Ae2Reflect.getCraftJob(this) != null && !this.isSimulation()) {
ICraftingGrid cc = grid.getCache(ICraftingGrid.class);
ICraftingLink g = cc.submitJob(Ae2Reflect.getCraftJob(this), null, this.getSelectedCpu() == -1 ? null : Ae2Reflect.getCraftingCPU(Ae2Reflect.getCPUs(this).get(this.getSelectedCpu())), true, this.getActionSrc());
this.setAutoStart(false);
if (g == null) {
this.setJob(cc.beginCraftingJob(this.getWorld(), grid, this.getActionSrc(), Ae2Reflect.getCraftJob(this).getOutput(), null));
} else if (originalGui != null && this.getOpenContext() != null) {
ContainerOpenContext context = this.getOpenContext();
InventoryHandler.openGui(
this.getInventoryPlayer().player,
this.getInventoryPlayer().player.world,
new BlockPos(Ae2Reflect.getContextX(context), Ae2Reflect.getContextY(context), Ae2Reflect.getContextZ(context)),
this.getOpenContext().getSide().getFacing(),
originalGui
);
}
}
}
public IActionSource getActionSrc() {
return new PlayerSource(this.getPlayerInv().player, (IActionHost)this.getTarget());
}

private IActionSource getActionSrc() {
return new PlayerSource(this.getPlayerInv().player, (IActionHost)this.getTarget());
@Override
public IActionHost getActionHost() {
return super.getActionHost();
}

}
33 changes: 33 additions & 0 deletions src/main/java/com/glodblock/github/client/warn/WarnMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.glodblock.github.client.warn;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class WarnMessage {

public static WarnMessage INSTANCE = new WarnMessage();
private boolean finished = false;
private WarnMessage() {
// NO-OP
}

@SideOnly(Side.CLIENT)
@SubscribeEvent(receiveCanceled = true)
public void onTick(TickEvent.ClientTickEvent event) {
if (!finished && Minecraft.getMinecraft().player != null) {
EntityPlayer player = Minecraft.getMinecraft().player;
finished = true;
player.sendMessage(new TextComponentString("AE2FC 2.5.0-r is on beta test!"));
player.sendMessage(new TextComponentString("If you encounter any bug or something not working"));
player.sendMessage(new TextComponentString("Please report it to https://github.com/GlodBlock/AE2FluidCraft-Rework"));
MinecraftForge.EVENT_BUS.unregister(this);
}
}

}
67 changes: 67 additions & 0 deletions src/main/java/com/glodblock/github/coremod/CoreModHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,52 @@
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.IMachineSet;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerPatternEncoder;
import appeng.container.implementations.CraftingCPURecord;
import appeng.crafting.MECraftingInventory;
import appeng.fluids.parts.PartFluidInterface;
import appeng.fluids.tile.TileFluidInterface;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.MachineSet;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.parts.misc.PartInterface;
import appeng.tile.misc.TileInterface;
import appeng.util.InventoryAdaptor;
import appeng.util.inv.BlockingInventoryAdaptor;
import appeng.util.item.AEItemStack;
import com.glodblock.github.client.container.ContainerFCCraftConfirm;
import com.glodblock.github.common.item.ItemFluidCraftEncodedPattern;
import com.glodblock.github.common.item.ItemFluidEncodedPattern;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.item.ItemLargeEncodedPattern;
import com.glodblock.github.common.item.fake.FakeFluids;
import com.glodblock.github.common.item.fake.FakeItemRegister;
import com.glodblock.github.common.part.PartDualInterface;
import com.glodblock.github.common.part.PartExtendedFluidPatternTerminal;
import com.glodblock.github.common.part.PartFluidPatternTerminal;
import com.glodblock.github.common.tile.TileDualInterface;
import com.glodblock.github.handler.FluidConvertingItemHandler;
import com.glodblock.github.integration.mek.FCGasItems;
import com.glodblock.github.integration.mek.FakeGases;
import com.glodblock.github.inventory.BlockingFluidInventoryAdaptor;
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
import com.glodblock.github.inventory.FluidConvertingInventoryCrafting;
import com.glodblock.github.inventory.GuiType;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.loader.FCItems;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.ModAndClassUtil;
Expand All @@ -53,6 +66,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
Expand All @@ -61,6 +75,7 @@
import net.minecraftforge.items.IItemHandler;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -334,4 +349,56 @@ public static ItemStack transformPattern(ContainerPatternEncoder container, Item
return output;
}

public static boolean startJob(ContainerCraftConfirm ccc, ArrayList<CraftingCPURecord> cpus, ICraftingJob result) {
GuiType originalGui = null;
if (!(ccc instanceof ContainerFCCraftConfirm)) {
return false;
}
ContainerFCCraftConfirm container = (ContainerFCCraftConfirm) ccc;
IActionHost ah = container.getActionHost();

if (ah instanceof WirelessTerminalGuiObject) {
ItemStack tool = ((WirelessTerminalGuiObject) ah).getItemStack();
if (tool.getItem() == FCItems.WIRELESS_FLUID_PATTERN_TERMINAL) {
originalGui = GuiType.WIRELESS_FLUID_PATTERN_TERMINAL;
}
}

if (ah instanceof PartFluidPatternTerminal) {
originalGui = GuiType.FLUID_PATTERN_TERMINAL;
}

if (ah instanceof PartExtendedFluidPatternTerminal) {
originalGui = GuiType.FLUID_EXTENDED_PATTERN_TERMINAL;
}

if (originalGui == null) {
return false;
}

IActionHost h = (IActionHost)container.getTarget();
if (h != null) {
IGridNode node = h.getActionableNode();
IGrid grid = node.getGrid();
if (result != null && !container.isSimulation()) {
ICraftingGrid cc = grid.getCache(ICraftingGrid.class);
ICraftingLink g = cc.submitJob(result, null, container.getSelectedCpu() == -1 ? null : Ae2Reflect.getCraftingCPU(cpus.get(container.getSelectedCpu())), true, container.getActionSrc());
container.setAutoStart(false);
if (g == null) {
container.setJob(cc.beginCraftingJob(container.getWorld(), grid, container.getActionSrc(), result.getOutput(), null));
} else if (container.getOpenContext() != null) {
ContainerOpenContext context = container.getOpenContext();
InventoryHandler.openGui(
container.getInventoryPlayer().player,
container.getInventoryPlayer().player.world,
new BlockPos(Ae2Reflect.getContextX(context), Ae2Reflect.getContextY(context), Ae2Reflect.getContextZ(context)),
container.getOpenContext().getSide().getFacing(),
originalGui
);
}
}
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public byte[] transform(String name, String transformedName, byte[] code) {
case "appeng.container.implementations.ContainerPatternEncoder":
tform = ContainerPatternEncoderTransformer.INSTANCE;
break;
case "appeng.container.implementations.ContainerCraftConfirm":
tform = ContainerCraftConfirmTransformer.INSTANCE;
break;
default:
return code;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.glodblock.github.coremod.transform;

import com.glodblock.github.coremod.FCClassTransformer;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class ContainerCraftConfirmTransformer extends FCClassTransformer.ClassMapper {

public static ContainerCraftConfirmTransformer INSTANCE = new ContainerCraftConfirmTransformer();

private ContainerCraftConfirmTransformer() {
// NO-OP
}

@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new TransformContainerCraftConfirm(Opcodes.ASM5, downstream);
}

@Override
protected int getWriteFlags() {
return ClassWriter.COMPUTE_FRAMES;
}

private static class TransformContainerCraftConfirm extends ClassVisitor {

public TransformContainerCraftConfirm(int api, ClassVisitor cv) {
super(api, cv);
}

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("startJob")) {
return new TransformStartJob(api, super.visitMethod(access, name, desc, signature, exceptions));
} else {
return super.visitMethod(access, name, desc, signature, exceptions);
}
}

}

private static class TransformStartJob extends MethodVisitor {

Label L = new Label();

public TransformStartJob(int api, MethodVisitor mv) {
super(api, mv);
}

@Override
public void visitCode() {
super.visitCode();
super.visitVarInsn(Opcodes.ALOAD, 0);
super.visitInsn(Opcodes.DUP);
super.visitFieldInsn(Opcodes.GETFIELD, "appeng/container/implementations/ContainerCraftConfirm", "cpus", "Ljava/util/ArrayList;");
super.visitVarInsn(Opcodes.ALOAD, 0);
super.visitFieldInsn(Opcodes.GETFIELD, "appeng/container/implementations/ContainerCraftConfirm", "result", "Lappeng/api/networking/crafting/ICraftingJob;");
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/CoreModHooks",
"startJob",
"(Lappeng/container/implementations/ContainerCraftConfirm;Ljava/util/ArrayList;Lappeng/api/networking/crafting/ICraftingJob;)Z",
false);
super.visitJumpInsn(Opcodes.IFEQ, L);
super.visitInsn(Opcodes.RETURN);
super.visitLabel(L);
}

}

}
2 changes: 2 additions & 0 deletions src/main/java/com/glodblock/github/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.glodblock.github.client.render.DropColourHandler;
import com.glodblock.github.client.render.RenderIngredientBuffer;
import com.glodblock.github.client.render.RenderLargeIngredientBuffer;
import com.glodblock.github.client.warn.WarnMessage;
import com.glodblock.github.common.item.fake.FakeItemRegister;
import com.glodblock.github.common.tile.TileIngredientBuffer;
import com.glodblock.github.common.tile.TileLargeIngredientBuffer;
Expand Down Expand Up @@ -36,6 +37,7 @@ public RegistryHandler createRegistryHandler() {
public void preInit(FMLPreInitializationEvent event) {
super.preInit(event);
MinecraftForge.EVENT_BUS.register(dropColourHandler);
MinecraftForge.EVENT_BUS.register(WarnMessage.INSTANCE);
ClientRegistry.bindTileEntitySpecialRenderer(TileIngredientBuffer.class, new RenderIngredientBuffer());
ClientRegistry.bindTileEntitySpecialRenderer(TileLargeIngredientBuffer.class, new RenderLargeIngredientBuffer());
}
Expand Down
Loading

0 comments on commit f55321b

Please sign in to comment.