Skip to content
This repository has been archived by the owner on Sep 17, 2022. It is now read-only.

Digital Interface Cover #362

Merged
merged 15 commits into from
Feb 19, 2021
21 changes: 21 additions & 0 deletions src/main/java/gregicadditions/GAEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
import gregicadditions.input.Key;
import gregicadditions.input.Keybinds;
import gregicadditions.item.GAMetaItems;
import gregicadditions.machines.multi.centralmonitor.MetaTileEntityCentralMonitor;
import gregicadditions.network.KeysPacket;
import gregicadditions.network.NetworkHandler;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IElectricItem;
import gregtech.api.items.armor.ArmorMetaItem;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
Expand Down Expand Up @@ -109,5 +114,21 @@ public void onGUIEvent(GuiOpenEvent event) {
if (resync) NetworkHandler.INSTANCE.sendToServer(new KeysPacket(Keybinds.REGISTERY));
}

@SubscribeEvent
public void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
if (event.getWorld().getTileEntity(event.getPos()) instanceof MetaTileEntityHolder) {
event.setUseBlock(Event.Result.ALLOW);
}
}

@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {
if (event.getEntityPlayer().isCreative()) {
TileEntity holder = event.getWorld().getTileEntity(event.getPos());
if (holder instanceof MetaTileEntityHolder && ((MetaTileEntityHolder) holder).getMetaTileEntity() instanceof MetaTileEntityCentralMonitor) {
((MetaTileEntityCentralMonitor) ((MetaTileEntityHolder) holder).getMetaTileEntity()).invalidateStructure();
}
}
}

}
15 changes: 15 additions & 0 deletions src/main/java/gregicadditions/client/ClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ public class ClientHandler {
public static final TextureArea BRONZE_TANK_ICON = TextureArea.fullImage("textures/gui/steam/bronze_tank_icon.png");
public static SimpleOverlayRenderer STEAM_PUMP_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_steam_pump");
public static OrientedOverlayRenderer BEE_ATTRACTOR = new OrientedOverlayRenderer("machines/attractor", OverlayFace.FRONT, OverlayFace.SIDE);
// cover
public static SimpleOverlayRenderer COVER_INTERFACE_FLUID = new SimpleOverlayRenderer("cover/cover_interface_fluid");
public static SimpleOverlayRenderer COVER_INTERFACE_FLUID_GLASS = new SimpleOverlayRenderer("cover/cover_interface_fluid_glass");
public static SimpleOverlayRenderer COVER_INTERFACE_ITEM = new SimpleOverlayRenderer("cover/cover_interface_item");
public static SimpleOverlayRenderer COVER_INTERFACE_ENERGY = new SimpleOverlayRenderer("cover/cover_interface_energy");
public static SimpleOverlayRenderer COVER_INTERFACE_MACHINE_ON = new SimpleOverlayRenderer("cover/cover_interface_machine_on");
public static SimpleOverlayRenderer COVER_INTERFACE_MACHINE_OFF = new SimpleOverlayRenderer("cover/cover_interface_machine_off");
public static SimpleOverlayRenderer COVER_INTERFACE_PROXY = new SimpleOverlayRenderer("cover/cover_interface_proxy");
public static TextureArea BUTTON_FLUID = TextureArea.fullImage("textures/blocks/cover/cover_interface_fluid_button.png");
public static TextureArea BUTTON_ITEM = TextureArea.fullImage("textures/blocks/cover/cover_interface_item_button.png");
public static TextureArea BUTTON_ENERGY = TextureArea.fullImage("textures/blocks/cover/cover_interface_energy_button.png");
public static TextureArea BUTTON_MACHINE = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_button.png");
public static TextureArea BUTTON_INTERFACE = TextureArea.fullImage("textures/blocks/cover/cover_interface_computer_button.png");
public static TextureArea COVER_INTERFACE_MACHINE_ON_PROXY = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_on_proxy.png");
public static TextureArea COVER_INTERFACE_MACHINE_OFF_PROXY = TextureArea.fullImage("textures/blocks/cover/cover_interface_machine_off_proxy.png");


static {
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/gregicadditions/coremod/GAClassTransformer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package gregicadditions.coremod;

import gregicadditions.coremod.transform.NetworkNodeGridTransformer;
import gregicadditions.coremod.transform.PacketJEIRecipeTransformer;
import gregicadditions.coremod.transform.TileEntityControllerTransformer;
import gregicadditions.coremod.transform.*;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
Expand All @@ -22,6 +20,24 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
case "mcjty.xnet.blocks.controller.TileEntityController":
tform = TileEntityControllerTransformer.INSTANCE;
break;
case "gregtech.api.metatileentity.MetaTileEntityHolder":
tform = MetaTileEntityHolderTransformer.INSTANCE;
break;
case "gregtech.api.render.MetaTileEntityTESR":
tform = MetaTileEntityTESRTransformer.INSTANCE;
break;
case "gregtech.api.capability.impl.EnergyContainerHandler":
tform = EnergyContainerHandlerTransformer.INSTANCE;
break;
case "gregtech.api.capability.impl.EnergyContainerBatteryBuffer":
tform = EnergyContainerBatteryBufferTransformer.INSTANCE;
break;
case "gregtech.common.items.behaviors.CoverPlaceBehavior":
tform = CoverPlaceBehaviorTransformer.INSTANCE;
break;
case "gregtech.api.metatileentity.MetaTileEntity":
tform = MetaTileEntityTransformer.INSTANCE;
break;
default:
return basicClass;
}
Expand Down
121 changes: 121 additions & 0 deletions src/main/java/gregicadditions/coremod/hooks/GregTechCEHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package gregicadditions.coremod.hooks;

import codechicken.lib.render.CCRenderState;
import codechicken.lib.vec.Matrix4;
import gregicadditions.covers.CoverDigitalInterface;
import gregtech.api.capability.impl.EnergyContainerBatteryBuffer;
import gregtech.api.capability.impl.EnergyContainerHandler;
import gregtech.api.cover.CoverBehavior;
import gregtech.api.cover.ICoverable;
import gregtech.api.metatileentity.IFastRenderMetaTileEntity;
import gregtech.api.metatileentity.IRenderMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.common.items.behaviors.CoverPlaceBehavior;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;

public class GregTechCEHooks {

//origin: gregtech/api/metatileentity/MetaTileEntityHolder/hasFastRenderer
public static boolean hasFastRenderer(MetaTileEntityHolder metaTileEntityHolder) {
MetaTileEntity metaTE = metaTileEntityHolder.getMetaTileEntity();
for (EnumFacing side: EnumFacing.VALUES){
CoverBehavior cover = metaTE.getCoverAtSide(side);
if (cover instanceof IFastRenderMetaTileEntity && !(cover instanceof IRenderMetaTileEntity)) {
return true;
}
}
return metaTE instanceof IFastRenderMetaTileEntity && !(metaTE instanceof IRenderMetaTileEntity);
}

//origin: gregtech/api/metatileentity/MetaTileEntityHolder/shouldCoverRenderPass
public static boolean shouldCoverRenderPass(MetaTileEntityHolder holder, int pass) {
MetaTileEntity metaTE = holder.getMetaTileEntity();
if (metaTE == null) return false;
for (EnumFacing side: EnumFacing.VALUES){
CoverBehavior cover = metaTE.getCoverAtSide(side);
if (cover instanceof IFastRenderMetaTileEntity && ((IFastRenderMetaTileEntity) cover).shouldRenderInPass(pass)) {
return true;
}
}
return false;
}

//origin: gregtech/api/metatileentity/MetaTileEntityHolder/renderTileEntityFast
public static void renderTileEntityFast(TileEntity te, double x, double y, double z, float partialTicks, BufferBuilder buffer) {
if(te instanceof MetaTileEntityHolder){
MetaTileEntity metaTE = ((MetaTileEntityHolder) te).getMetaTileEntity();
if (metaTE != null){
Matrix4 translation = (new Matrix4()).translate(x, y, z);
for (EnumFacing side: EnumFacing.VALUES){
CoverBehavior cover = metaTE.getCoverAtSide(side);
if (cover instanceof IFastRenderMetaTileEntity) {
CCRenderState renderState = CCRenderState.instance();
renderState.reset();
renderState.bind(buffer);
renderState.setBrightness(te.getWorld(), te.getPos().offset(side));
((IFastRenderMetaTileEntity)cover).renderMetaTileEntityFast(renderState, translation, partialTicks);
}
}
}
}
}

public static void updateCoverDigitalInterface(MetaTileEntity metaTileEntity, long energyAdded) {
if (metaTileEntity != null ) {
for (EnumFacing side : EnumFacing.VALUES) {
CoverBehavior cover = metaTileEntity.getCoverAtSide(side);
if (cover instanceof CoverDigitalInterface) {
((CoverDigitalInterface) cover).setEnergyChanged(energyAdded);
}
}
}
}

//origin: gregtech.api.capability.impl.EnergyContainerHandler.setEnergyStored()
public static void setEnergyStored(EnergyContainerHandler energyContainerHandler, long energyStored) {
if (energyStored != 0) {
updateCoverDigitalInterface(energyContainerHandler.getMetaTileEntity(), energyStored - energyContainerHandler.getEnergyStored());
}
energyContainerHandler.setEnergyStored(energyStored);
}

//origin: gregtech/api/capability/impl/EnergyContainerBatteryBuffer.changeEnergy() (though gtce not gonna use it. might be called, so hacking it too)
public static void changeEnergy(EnergyContainerBatteryBuffer batteryBuffer, long energyAdded) {
if (energyAdded != 0) {
updateCoverDigitalInterface(batteryBuffer.getMetaTileEntity(), energyAdded);
}
}

//origin: gregtech/api/capability/impl/EnergyContainerBatteryBuffer.acceptEnergyFromNetwork()
public static void acceptEnergyFromNetwork(EnergyContainerBatteryBuffer batteryBuffer, long V, long amperageUsed) {
if (amperageUsed != 0) {
updateCoverDigitalInterface(batteryBuffer.getMetaTileEntity(), V * amperageUsed);
}
}

//origin: gregtech/api/capability/impl/EnergyContainerBatteryBuffer.update()
public static void update(EnergyContainerBatteryBuffer batteryBuffer, long V, long amperageUsed) {
if (amperageUsed != 0) {
updateCoverDigitalInterface(batteryBuffer.getMetaTileEntity(), -V * amperageUsed);
}
}

//origin: gregtech/api/cover/ICoverable.canPlaceCoverOnSide()
public static boolean canPlaceCoverOnSide(ICoverable coverable, EnumFacing side, CoverPlaceBehavior coverPlaceBehavior) {
if (coverPlaceBehavior.coverDefinition.getCoverId().getPath().equals(CoverDigitalInterface.path)) {
return true;
}
return coverable.canPlaceCoverOnSide(side);
}

//origin: gregtech/api/metatileentity/MetaTileEntity.canPlaceCoverOnSide()
public static boolean canPlaceCoverOnSide2(MetaTileEntity coverable, EnumFacing side, CoverBehavior coverBehavior) {
if (coverBehavior instanceof CoverDigitalInterface) {
return true;
}
return coverable.canPlaceCoverOnSide(side);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package gregicadditions.coremod.transform;

import gregicadditions.coremod.GAClassTransformer;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class CoverPlaceBehaviorTransformer extends GAClassTransformer.ClassMapper {

public static final CoverPlaceBehaviorTransformer INSTANCE = new CoverPlaceBehaviorTransformer();

private CoverPlaceBehaviorTransformer() {
// NO-OP
}

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

private static class TransformerCoverPlaceBehavior extends ClassVisitor {

TransformerCoverPlaceBehavior(int api, ClassVisitor cv) {
super(api, cv);
}

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

}

private static class TransformOnItemUseFirst extends MethodVisitor {

TransformOnItemUseFirst(int api, MethodVisitor mv) {
super(api, mv);
}

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (opcode == Opcodes.INVOKEINTERFACE && name.equals("canPlaceCoverOnSide")) {
this.visitVarInsn(Opcodes.ALOAD, 0);
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"gregicadditions/coremod/hooks/GregTechCEHooks",
"canPlaceCoverOnSide",
"(Lgregtech/api/cover/ICoverable;Lnet/minecraft/util/EnumFacing;Lgregtech/common/items/behaviors/CoverPlaceBehavior;)Z",
false);
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package gregicadditions.coremod.transform;

import gregicadditions.coremod.GAClassTransformer;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class EnergyContainerBatteryBufferTransformer extends GAClassTransformer.ClassMapper {

public static final EnergyContainerBatteryBufferTransformer INSTANCE = new EnergyContainerBatteryBufferTransformer();

private EnergyContainerBatteryBufferTransformer() {
// NO-OP
}

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

private static class TransformerEnergyContainerBatteryBuffer extends ClassVisitor {

TransformerEnergyContainerBatteryBuffer(int api, ClassVisitor cv) {
super(api, cv);
}

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
switch (name) {
case "acceptEnergyFromNetwork":
return new TransformAcceptEnergyFromNetwork(api, super.visitMethod(access, name, desc, signature, exceptions));
case "update":
return new TransformUpdate(api, super.visitMethod(access, name, desc, signature, exceptions));
case "changeEnergy":
return new TransformChangeEnergy(api, super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}

}

private static class TransformAcceptEnergyFromNetwork extends MethodVisitor {
static byte now = 0;

TransformAcceptEnergyFromNetwork(int api, MethodVisitor mv) {
super(api, mv);
}

@Override
public void visitInsn(int opcode) {
if (opcode == Opcodes.LRETURN) {
if(++now == 2) {
this.visitVarInsn(Opcodes.ALOAD, 0);
this.visitVarInsn(Opcodes.LLOAD, 2);
this.visitVarInsn(Opcodes.LLOAD, 8);
this.visitMethodInsn(Opcodes.INVOKESTATIC,
"gregicadditions/coremod/hooks/GregTechCEHooks",
"acceptEnergyFromNetwork",
"(Lgregtech/api/capability/impl/EnergyContainerBatteryBuffer;JJ)V",
false);
}
}
super.visitInsn(opcode);
}
}

private static class TransformUpdate extends MethodVisitor {
static byte now = 0;
TransformUpdate(int api, MethodVisitor mv) {
super(api, mv);
}

@Override
public void visitVarInsn(int opcode, int var) {
super.visitVarInsn(opcode, var);
if (opcode == Opcodes.LSTORE && var == 10) {
if (++now == 1) {
this.visitVarInsn(Opcodes.ALOAD, 0);
this.visitVarInsn(Opcodes.LLOAD, 5);
this.visitVarInsn(Opcodes.LLOAD, 10);
this.visitMethodInsn(Opcodes.INVOKESTATIC,
"gregicadditions/coremod/hooks/GregTechCEHooks",
"update",
"(Lgregtech/api/capability/impl/EnergyContainerBatteryBuffer;JJ)V",
false);
}
}
}
}

private static class TransformChangeEnergy extends MethodVisitor {

TransformChangeEnergy(int api, MethodVisitor mv) {
super(api, mv);
}

@Override
public void visitInsn(int opcode) {
if (opcode == Opcodes.LRETURN) {
this.visitVarInsn(Opcodes.ALOAD, 0);
this.visitVarInsn(Opcodes.LLOAD, 7);
this.visitMethodInsn(Opcodes.INVOKESTATIC,
"gregicadditions/coremod/hooks/GregTechCEHooks",
"changeEnergy",
"(Lgregtech/api/capability/impl/EnergyContainerBatteryBuffer;J)V",
false);
}
super.visitInsn(opcode);
}
}
}
Loading