diff --git a/build.gradle b/build.gradle index c283c7ac..ddf75a06 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-0.3.5" +version = "1.7.10-0.3.5a" group= "com.zuxelus.energycontrol" archivesBaseName = "EnergyControl" @@ -44,10 +44,10 @@ dependencies { 'libs_/Draconic-Evolution-1.7.10-1.0.2h.jar', 'libs_/EnderCore-1.7.10-0.2.0.40_beta.jar', 'libs_/EnderIO-1.7.10-2.3.0.430_beta.jar', - 'libs_/gregtech_1.7.10-6.15.01.jar', + 'libs_/gregtech_1.7.10-6.17.01.jar', 'libs_/GalacticraftCore-1.7-3.0.12.504.jar', 'libs_/Galacticraft-Planets-1.7-3.0.12.504.jar', - 'libs_/HBM-NTM-.1.0.27_X4724.jar', + 'libs_/HBM-NTM-[1.0.27_X4859].jar', 'libs_/industrialcraft-2-2.2.827-experimental-dev.jar', 'libs_/Mekanism-1.7.10-9.1.1.1031.jar', 'libs_/NotEnoughItems-1.7.10-1.0.5.120-universal.jar', diff --git a/src/main/java/com/zuxelus/energycontrol/config/ConfigHandler.java b/src/main/java/com/zuxelus/energycontrol/config/ConfigHandler.java index 833be7bf..e8c5bad0 100644 --- a/src/main/java/com/zuxelus/energycontrol/config/ConfigHandler.java +++ b/src/main/java/com/zuxelus/energycontrol/config/ConfigHandler.java @@ -20,6 +20,7 @@ public class ConfigHandler { public boolean useCustomSounds; public int alarmPause; public boolean disableRangeCheck; + public boolean disableCircuitRecipe; public void init(File configFile) { if (config == null) @@ -38,6 +39,7 @@ private void loadConfig() { useCustomSounds = config.getBoolean("useCustomSounds", Configuration.CATEGORY_GENERAL, false, "Update file config\\alarms\\assets\\energycontrol\\sounds.json to see your sounds in game", "ec.config.useCustomSounds"); alarmPause = config.getInt("alarmPause", Configuration.CATEGORY_GENERAL, 60, 0, 2000, "", "ec.config.alarmPause"); disableRangeCheck = config.getBoolean("disableRangeCheck", Configuration.CATEGORY_GENERAL, false, "", "ec.config.disableRangeCheck"); + disableCircuitRecipe = config.getBoolean("disableCircuitRecipe", Configuration.CATEGORY_GENERAL, false, "", "ec.config.disableCircuitRecipe"); } catch (Exception e) { EnergyControl.logger.error("Mod has a problem loading it's configuration", e); } finally { diff --git a/src/main/java/com/zuxelus/energycontrol/crossmod/CrossGregTech6.java b/src/main/java/com/zuxelus/energycontrol/crossmod/CrossGregTech6.java index 563bbf55..65982a1a 100644 --- a/src/main/java/com/zuxelus/energycontrol/crossmod/CrossGregTech6.java +++ b/src/main/java/com/zuxelus/energycontrol/crossmod/CrossGregTech6.java @@ -1,8 +1,14 @@ package com.zuxelus.energycontrol.crossmod; +import static gregapi.data.CS.F; + +import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import com.zuxelus.energycontrol.api.PanelString; +import com.zuxelus.energycontrol.hooks.GregTechHooks; import com.zuxelus.energycontrol.init.ModItems; import com.zuxelus.energycontrol.items.ItemComponent; import com.zuxelus.energycontrol.items.cards.ItemCardGregTech; @@ -14,11 +20,38 @@ import com.zuxelus.energycontrol.utils.DataHelper; import com.zuxelus.energycontrol.utils.FluidInfo; +import gregapi.data.TD.Energy; +import gregapi.item.IItemEnergy; +import gregapi.oredict.OreDictMaterialStack; +import gregapi.tileentity.base.TileEntityBase05Inventories; +import gregapi.tileentity.connectors.MultiTileEntityAxle; +import gregapi.tileentity.connectors.MultiTileEntityPipeFluid; +import gregapi.tileentity.connectors.MultiTileEntityWireElectric; +import gregapi.tileentity.machines.MultiTileEntityBasicMachineElectric; +import gregapi.util.ST; +import gregapi.util.UT; +import gregtech.tileentity.energy.converters.MultiTileEntityBoilerTank; +import gregtech.tileentity.energy.converters.MultiTileEntityDynamoElectric; +import gregtech.tileentity.energy.converters.MultiTileEntityMotorElectric; +import gregtech.tileentity.energy.converters.MultiTileEntityTurbineSteam; +import gregtech.tileentity.energy.generators.MultiTileEntityGeneratorGas; +import gregtech.tileentity.energy.generators.MultiTileEntityGeneratorMetal; +import gregtech.tileentity.energy.generators.MultiTileEntityGeneratorSolid; +import gregtech.tileentity.energy.generators.MultiTileEntityMotorLiquid; +import gregtech.tileentity.energy.generators.MultiTileEntitySolarPanelElectric; +import gregtech.tileentity.energy.reactors.MultiTileEntityReactorCore2x2; +import gregtech.tileentity.energy.reactors.MultiTileEntityReactorRodNuclear; import gregtech.tileentity.energy.storage.MultiTileEntityBatteryBox; +import gregtech.tileentity.energy.transformers.MultiTileEntityTransformerElectric; +import gregtech.tileentity.tanks.MultiTileEntityBarrelMetal; +import gregtech.tileentity.tools.MultiTileEntityMold; +import gregtech.tileentity.tools.MultiTileEntitySmeltery; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidTank; public class CrossGregTech6 extends CrossModBase { @@ -36,8 +69,209 @@ public List getAllTanks(TileEntity te) { public NBTTagCompound getCardData(TileEntity te) { NBTTagCompound tag = new NBTTagCompound(); if (te instanceof MultiTileEntityBatteryBox) { - tag.setDouble(DataHelper.ENERGY, ((MultiTileEntityBatteryBox) te).mEnergy); - tag.setDouble(DataHelper.CAPACITY, ((MultiTileEntityBatteryBox) te).mInput * 80 * ((MultiTileEntityBatteryBox) te).invsize()); + MultiTileEntityBatteryBox box = (MultiTileEntityBatteryBox) te; + long energy = 0; + tag.setDouble(DataHelper.ENERGY, box.mEnergy); + for (ItemStack tStack : box.getInventory()) + if (ST.valid(tStack)) + if (tStack.getItem() instanceof IItemEnergy) { + energy = energy + ((IItemEnergy) tStack.getItem()).getEnergyStored(box.mEnergyType, tStack); + } + tag.setDouble("battery", energy); + tag.setDouble("limit0", ((MultiTileEntityBatteryBox) te).mInput * 2 * 40 * ((MultiTileEntityBatteryBox) te).invsize()); + tag.setDouble("limit1", ((MultiTileEntityBatteryBox) te).mInput * 6 * 40 * ((MultiTileEntityBatteryBox) te).invsize()); + tag.setDouble(DataHelper.CAPACITY, ((MultiTileEntityBatteryBox) te).mInput * 8 * 40 * ((MultiTileEntityBatteryBox) te).invsize()); + addHookData(te, tag, DataHelper.CONSUMPTION, DataHelper.OUTPUT, true); + return tag; + } + if (te instanceof MultiTileEntityGeneratorMetal) { + boolean active = DataHelper.getBoolean(MultiTileEntityGeneratorSolid.class, "mBurning", te); + tag.setBoolean(DataHelper.ACTIVE, active); + tag.setDouble(DataHelper.ENERGYHU, DataHelper.getLong(MultiTileEntityGeneratorSolid.class, "mEnergy", te)); + tag.setDouble(DataHelper.OUTPUTHU, active ? DataHelper.getLong(MultiTileEntityGeneratorSolid.class, "mRate", te) : 0); + ItemStack[] list = ((MultiTileEntityGeneratorMetal) te).getInventory(); + if (list[0] != null) + tag.setTag("slot0", list[0].writeToNBT(new NBTTagCompound())); + if (list[1] != null) + tag.setTag("slot1", list[1].writeToNBT(new NBTTagCompound())); + return tag; + } + if (te instanceof MultiTileEntityGeneratorGas) { + FluidTankInfo[] info = ((MultiTileEntityGeneratorGas) te).getTankInfo(null); + if (info.length > 0) { + FluidInfo.addTank(DataHelper.TANK, tag, info[0].fluid, "L"); + tag.setDouble(DataHelper.CAPACITYL, info[0].capacity); + } + return tag; + } + if (te instanceof MultiTileEntitySmeltery) { + try { + Field field = MultiTileEntitySmeltery.class.getDeclaredField("mContent"); + field.setAccessible(true); + List list = (List) field.get(te); + StringBuilder builder = new StringBuilder(); + for (OreDictMaterialStack item : list) { + if (builder.length() > 0) + builder.append(","); + builder.append(String.format("%s: %s", item.mMaterial.mNameLocal, PanelString.getFormatter().format(item.mAmount / 648648000d))); + } + tag.setString("content", builder.toString()); + } catch (Throwable t) { } + tag.setDouble(DataHelper.HEAT, ((MultiTileEntitySmeltery) te).getTemperatureValue((byte) 0)); + return tag; + } + if (te instanceof MultiTileEntityBarrelMetal) { + FluidInfo.addTank(DataHelper.TANK, tag, ((MultiTileEntityBarrelMetal) te).mTank.get(), "L"); + tag.setDouble(DataHelper.CAPACITYL, ((MultiTileEntityBarrelMetal) te).mTank.capacity()); + return tag; + } + if (te instanceof MultiTileEntityMold) { + tag.setDouble(DataHelper.HEAT, ((MultiTileEntityMold) te).getTemperatureValue((byte) 0)); + return tag; + } + if (te instanceof MultiTileEntityPipeFluid) { + FluidInfo.addTank(DataHelper.TANK, tag, ((MultiTileEntityPipeFluid) te).mTanks[0].get(), "L"); + tag.setDouble(DataHelper.CAPACITYL, ((MultiTileEntityPipeFluid) te).mTanks[0].capacity()); + ArrayList values = getHookValues(te); + if (values != null) { + tag.setDouble(DataHelper.OUTPUTL, getAverage(values, 0, GregTechHooks.len)); + } + return tag; + } + if (te instanceof MultiTileEntityAxle) { + ArrayList values = getHookValues(te); + if (values != null) { + long energy = 0; + for (int i = 0; i < 20; i++) + energy = energy + values.get(i); + tag.setDouble(DataHelper.CONSUMPTIONRU, energy / 20.0d); + } + tag.setDouble(DataHelper.OUTPUTRU, ((MultiTileEntityAxle) te).mTransferredLast); + return tag; + } + if (te instanceof MultiTileEntityBoilerTank) { + FluidTankInfo[] info = ((MultiTileEntityBoilerTank) te).getTankInfo(null); + if (info.length > 0) { + FluidInfo.addTank(DataHelper.TANK, tag, info[0].fluid, "L"); + FluidInfo.addTank(DataHelper.TANK2, tag, info[1].fluid, "L"); + } + ArrayList values = getHookValues(te); + if (values != null) { + long water = 0; + long steam = 0; + long energy = 0; + for (int i = 0; i < 60; i++) { + if (i < 20) + water = water + values.get(i); + if (i > 19 && i < 40) + steam = steam + values.get(i); + if (i > 39) + energy = energy + values.get(i); + } + tag.setDouble(DataHelper.CONSUMPTIONL, water / 20.0d); + tag.setDouble(DataHelper.OUTPUTST, steam / 20.0d); + tag.setDouble(DataHelper.CONSUMPTIONHU, energy / 20.0d); + } + return tag; + } + if (te instanceof MultiTileEntityTurbineSteam) { + FluidTankInfo[] info = ((MultiTileEntityTurbineSteam) te).getTankInfo(null); + FluidInfo.addTank(DataHelper.TANK, tag, info[0].fluid, "L"); + ArrayList values = getHookValues(te); + /*if (values != null) { + double energy = 0; + double water = 0; + for (int i = 0; i < GregTechHooks.len * 2; i++) { + if (i < GregTechHooks.len) + energy = energy + values.get(i); + if (i > GregTechHooks.len - 1) + water = water + values.get(i); + } + tag.setDouble(DataHelper.CONSUMPTIONST, energy / GregTechHooks.len * 4); + tag.setDouble(DataHelper.OUTPUTRU, energy / GregTechHooks.len * 2 / 3); + tag.setDouble(DataHelper.OUTPUTL, water / GregTechHooks.len); + }*/ + tag.setDouble(DataHelper.CONSUMPTIONST, getAverage(values, 0, GregTechHooks.len)); + tag.setDouble(DataHelper.OUTPUTRU, getAverage(values, GregTechHooks.len, GregTechHooks.len)); + tag.setDouble(DataHelper.OUTPUTL, getAverage(values, GregTechHooks.len * 2, 50)); + return tag; + } + if (te instanceof MultiTileEntityTransformerElectric) { + tag.setDouble(DataHelper.ENERGY, ((MultiTileEntityTransformerElectric) te).mStorage.mEnergy); + addHookData(te, tag, DataHelper.CONSUMPTION, DataHelper.OUTPUT, true); + return tag; + } + if (te instanceof MultiTileEntityDynamoElectric) { + tag.setDouble(DataHelper.ENERGY, ((MultiTileEntityDynamoElectric) te).mStorage.mEnergy); + addHookData(te, tag, DataHelper.CONSUMPTIONRU, DataHelper.OUTPUT, true); + return tag; + } + if (te instanceof MultiTileEntityMotorElectric) { + tag.setDouble(DataHelper.ENERGYRU, ((MultiTileEntityMotorElectric) te).mStorage.mEnergy); + addHookData(te, tag, DataHelper.CONSUMPTION, DataHelper.OUTPUTRU, true); + return tag; + } + if (te instanceof MultiTileEntityWireElectric) { + ArrayList values = getHookValues(te); + if (values != null) { + tag.setDouble(DataHelper.OUTPUT, getAverage(values, 0, GregTechHooks.len)); + tag.setDouble(DataHelper.ENERGY, values.get(0)); + tag.setDouble("amperage", values.get(GregTechHooks.len)); + } + return tag; + } + if (te instanceof MultiTileEntitySolarPanelElectric) { + addHookData(te, tag, null, DataHelper.OUTPUT, false); + return tag; + } + if (te instanceof MultiTileEntityMotorLiquid) { + FluidTankInfo[] info = ((MultiTileEntityMotorLiquid) te).getTankInfo(null); + if (info.length > 0) { + FluidInfo.addTank(DataHelper.TANK, tag, info[0].fluid, "L"); + FluidInfo.addTank(DataHelper.TANK2, tag, info[1].fluid, "L"); + } + addHookData(te, tag, DataHelper.OUTPUTRU, DataHelper.CONSUMPTIONL, false); + return tag; + } + if (te instanceof MultiTileEntityBasicMachineElectric) { + IFluidTank[] list = ((MultiTileEntityBasicMachineElectric) te).mTanksInput; + int j = 2; + for (int i = 0; i < list.length; i++) + if (list[i] != null) { + FluidInfo.addTank(String.format("%s%s", DataHelper.TANK, j), tag, list[i].getFluid(), "L"); + j++; + } + list = ((MultiTileEntityBasicMachineElectric) te).mTanksOutput; + for (int i = 0; i < list.length; i++) + if (list[i] != null) { + FluidInfo.addTank(String.format("%s%s", DataHelper.TANK, j), tag, list[i].getFluid(), "L"); + j++; + } + addHookData(te, tag, DataHelper.CONSUMPTION, null, true); + return tag; + } + if (te instanceof MultiTileEntityReactorCore2x2) { + IFluidTank[] tanks = ((MultiTileEntityReactorCore2x2) te).mTanks; + FluidInfo.addTank(DataHelper.TANK, tag, tanks[0].getFluid(), "L"); + FluidInfo.addTank(DataHelper.TANK2, tag, tanks[1].getFluid(), "L"); + ArrayList values = getHookValues(te); + if (values != null) { + tag.setDouble(DataHelper.OUTPUTL, getAverage(values, 0, GregTechHooks.len)); + tag.setDouble(DataHelper.CONSUMPTIONL, getAverage(values, GregTechHooks.len, GregTechHooks.len)); + } + long dur = Long.MAX_VALUE; + for (ItemStack stack: DataHelper.getItemStackList(TileEntityBase05Inventories.class, "mInventory", te)) { + if (stack != null && stack.hasTagCompound()) { + NBTTagCompound nbt = stack.getTagCompound(); + long value = nbt.getLong("gt.durability"); + if (value > 0 && value < dur) + dur = value; + } + } + if (dur == Long.MAX_VALUE) + dur = 0; + tag.setDouble("remaining", dur / 120000.0d); + tag.setString("neutrons", Arrays.toString(((MultiTileEntityReactorCore2x2) te).mNeutronCounts)); return tag; } return null; @@ -45,7 +279,37 @@ public NBTTagCompound getCardData(TileEntity te) { @Override public ArrayList getHookValues(TileEntity te) { - return null; + ArrayList values = GregTechHooks.map.get(te); + if (values == null) + GregTechHooks.map.put(te, null); + return values; + } + + public static double getAverage(ArrayList values, int start, int size) { + if (values == null) + return 0; + double sum = 0; + for (int i = start; i < start + size; i++) + sum = sum + values.get(i); + return size > 0 ? sum / size : 0; + } + + public void addHookData(TileEntity te, NBTTagCompound tag, String consumption, String output, boolean showPackage) { + ArrayList values = getHookValues(te); + if (consumption != null) { + double avg = getAverage(values, 0, GregTechHooks.len); + if (showPackage) { + if (GregTechHooks.buffer.containsKey(te)) { + long[] list = GregTechHooks.buffer.get(te); + if (avg == 0) + list[2] = 0; + tag.setDouble("packet", list[2]); + } + } + tag.setDouble(consumption, avg); + } + if (output != null) + tag.setDouble(output, getAverage(values, GregTechHooks.len, GregTechHooks.len)); } @Override diff --git a/src/main/java/com/zuxelus/energycontrol/crossmod/CrossHBM.java b/src/main/java/com/zuxelus/energycontrol/crossmod/CrossHBM.java index 40d9fee3..20eb36d6 100644 --- a/src/main/java/com/zuxelus/energycontrol/crossmod/CrossHBM.java +++ b/src/main/java/com/zuxelus/energycontrol/crossmod/CrossHBM.java @@ -76,11 +76,11 @@ public NBTTagCompound getEnergyData(TileEntity te) { tag.setDouble(DataHelper.CAPACITY, ((TileEntityMachineBattery) te).getMaxPower()); return tag; } - if (te instanceof TileEntityMachineCoal) { + /*if (te instanceof TileEntityMachineCoal) { tag.setDouble(DataHelper.ENERGY, ((TileEntityMachineCoal) te).getPower()); tag.setDouble(DataHelper.CAPACITY, ((TileEntityMachineCoal) te).getMaxPower()); return tag; - } + }*/ if (te instanceof TileEntityMachineDiesel) { tag.setDouble(DataHelper.ENERGY, ((TileEntityMachineDiesel) te).getPower()); tag.setDouble(DataHelper.CAPACITY, ((TileEntityMachineDiesel) te).getMaxPower()); @@ -161,12 +161,12 @@ public NBTTagCompound getEnergyData(TileEntity te) { tag.setLong(DataHelper.CAPACITY, ((TileEntityMachineSchrabidiumTransmutator) te).getMaxPower()); return tag; } - if (te instanceof TileEntityMachineCMBFactory) { + /*if (te instanceof TileEntityMachineCMBFactory) { tag.setLong(DataHelper.ENERGY, ((TileEntityMachineCMBFactory) te).getPower()); tag.setLong(DataHelper.CAPACITY, ((TileEntityMachineCMBFactory) te).getMaxPower()); addTank("tank", tag, ((TileEntityMachineCMBFactory) te).tank); return tag; - } + }*/ if (te instanceof TileEntityMachineTeleporter) { tag.setLong(DataHelper.ENERGY, ((TileEntityMachineTeleporter) te).getPower()); tag.setLong(DataHelper.CAPACITY, ((TileEntityMachineTeleporter) te).getMaxPower()); @@ -277,11 +277,11 @@ public NBTTagCompound getEnergyData(TileEntity te) { tag.setDouble(DataHelper.CAPACITY, ((TileEntityMachineRefinery) te).getMaxPower()); return tag; } - if (te instanceof TileEntityMachineMiningDrill) { + /*if (te instanceof TileEntityMachineMiningDrill) { tag.setLong(DataHelper.ENERGY, ((TileEntityMachineMiningDrill) te).getPower()); tag.setLong(DataHelper.CAPACITY, ((TileEntityMachineMiningDrill) te).getMaxPower()); return tag; - } + }*/ //} if (te instanceof TileEntityProxyEnergy) { TileEntity base = ((TileEntityProxyEnergy) te).getTE(); @@ -299,11 +299,11 @@ public NBTTagCompound getEnergyData(TileEntity te) { return tag; } } - if (te instanceof TileEntityWatzCore) { + /*if (te instanceof TileEntityWatzCore) { tag.setDouble(DataHelper.ENERGY, ((TileEntityWatzCore) te).getPower()); tag.setDouble(DataHelper.CAPACITY, ((TileEntityWatzCore) te).getMaxPower()); return tag; - } + }*/ if (te instanceof TileEntityFWatzCore) { tag.setDouble(DataHelper.ENERGY, ((TileEntityFWatzCore) te).getPower()); tag.setDouble(DataHelper.CAPACITY, ((TileEntityFWatzCore) te).getMaxPower()); @@ -360,8 +360,8 @@ private int getHeat(TileEntity te) { return (int) ((TileEntityRBMKBase) te).heat; /*if (te instanceof TileEntityMachineReactorSmall) return (int) Math.round(((TileEntityMachineReactorSmall) te).hullHeat * 1.0E-5D * 980.0D + 20.0D);*/ - if (te instanceof TileEntityMachineReactorLarge) - return (int) Math.round(((TileEntityMachineReactorLarge) te).hullHeat * 1.0E-5D * 980.0D + 20.0D); + /*if (te instanceof TileEntityMachineReactorLarge) + return (int) Math.round(((TileEntityMachineReactorLarge) te).hullHeat * 1.0E-5D * 980.0D + 20.0D);*/ return -1; } @@ -374,10 +374,10 @@ public List getAllTanks(TileEntity te) { te = te.getWorldObj().getTileEntity(((TileEntityDummy) te).targetX, ((TileEntityDummy) te).targetY, ((TileEntityDummy) te).targetZ); } List result = new ArrayList<>(); - if (te instanceof TileEntityMachineCoal) { + /*if (te instanceof TileEntityMachineCoal) { result.add(toFluidInfo(((TileEntityMachineCoal) te).tank)); return result; - } + }*/ if (te instanceof TileEntityMachineDiesel) { result.add(toFluidInfo(((TileEntityMachineDiesel) te).tank)); return result; @@ -596,7 +596,7 @@ public List getAllTanks(TileEntity te) { result.add(toFluidInfo(((TileEntityMachineReactorSmall) te).tanks[2])); return result; }*/ - if (te instanceof TileEntityMachineReactorLarge) { + /*if (te instanceof TileEntityMachineReactorLarge) { result.add(toFluidInfo(((TileEntityMachineReactorLarge) te).tanks[0])); result.add(toFluidInfo(((TileEntityMachineReactorLarge) te).tanks[1])); result.add(toFluidInfo(((TileEntityMachineReactorLarge) te).tanks[2])); @@ -605,7 +605,7 @@ public List getAllTanks(TileEntity te) { if (te instanceof TileEntityWatzCore) { result.add(toFluidInfo(((TileEntityWatzCore) te).tank)); return result; - } + }*/ if (te instanceof TileEntityFWatzCore) { result.add(toFluidInfo(((TileEntityFWatzCore) te).tanks[0])); result.add(toFluidInfo(((TileEntityFWatzCore) te).tanks[1])); @@ -697,7 +697,7 @@ public NBTTagCompound getCardData(TileEntity te) { tag.setLong(DataHelper.DIFF, ((Long) values.get(0) - (Long) values.get(20)) / 20); return tag; } - if (te instanceof TileEntityMachineCoal) { + /*if (te instanceof TileEntityMachineCoal) { NBTTagCompound tag = new NBTTagCompound(); tag.setBoolean("active", ((TileEntityMachineCoal) te).burnTime > 0); tag.setLong(DataHelper.ENERGY, ((TileEntityMachineCoal) te).getPower()); @@ -711,7 +711,7 @@ public NBTTagCompound getCardData(TileEntity te) { } addTank("tank", tag, ((TileEntityMachineCoal) te).tank); return tag; - } + }*/ if (te instanceof TileEntityMachineDiesel) { NBTTagCompound tag = new NBTTagCompound(); TileEntityMachineDiesel diesel = ((TileEntityMachineDiesel) te); @@ -929,13 +929,13 @@ public NBTTagCompound getCardData(TileEntity te) { tag.setLong(DataHelper.CAPACITY, ((TileEntityMachineSchrabidiumTransmutator) te).getMaxPower()); return tag; } - if (te instanceof TileEntityMachineCMBFactory) { + /*if (te instanceof TileEntityMachineCMBFactory) { NBTTagCompound tag = new NBTTagCompound(); tag.setLong(DataHelper.ENERGY, ((TileEntityMachineCMBFactory) te).getPower()); tag.setLong(DataHelper.CAPACITY, ((TileEntityMachineCMBFactory) te).getMaxPower()); addTank("tank", tag, ((TileEntityMachineCMBFactory) te).tank); return tag; - } + }*/ if (te instanceof TileEntityMachineTeleporter) { NBTTagCompound tag = new NBTTagCompound(); tag.setLong(DataHelper.ENERGY, ((TileEntityMachineTeleporter) te).getPower()); @@ -1325,12 +1325,12 @@ public NBTTagCompound getCardData(TileEntity te) { addTank("tank5", tag, ((TileEntityMachineRefinery) te).tanks[4]); return tag; } - if (te instanceof TileEntityMachineMiningDrill) { + /*if (te instanceof TileEntityMachineMiningDrill) { NBTTagCompound tag = new NBTTagCompound(); tag.setLong(DataHelper.ENERGY, ((TileEntityMachineMiningDrill) te).getPower()); tag.setLong(DataHelper.CAPACITY, ((TileEntityMachineMiningDrill) te).getMaxPower()); return tag; - } + }*/ //} if (te instanceof TileEntityProxyEnergy) { TileEntity base = ((TileEntityProxyEnergy) te).getTE(); @@ -1372,7 +1372,7 @@ else if (reactor.tankTypes[2] == ModForgeFluids.hotsteam) addTank("tank3", tag, reactor.tanks[2]); return tag; }*/ - if (te instanceof TileEntityMachineReactorLarge) { + /*if (te instanceof TileEntityMachineReactorLarge) { NBTTagCompound tag = new NBTTagCompound(); TileEntityMachineReactorLarge reactor = (TileEntityMachineReactorLarge) te; tag.setBoolean("active", reactor.rods > 0 && reactor.fuel > 0); @@ -1426,7 +1426,7 @@ else if (reactor.tankTypes[2] == ModForgeFluids.hotsteam) tag.setLong("heatL", reactor.heatList); addTank("tank", tag, reactor.tank); return tag; - } + }*/ if (te instanceof TileEntityFWatzCore) { NBTTagCompound tag = new NBTTagCompound(); TileEntityFWatzCore core = (TileEntityFWatzCore) te; diff --git a/src/main/java/com/zuxelus/energycontrol/hooks/BaseHooks.java b/src/main/java/com/zuxelus/energycontrol/hooks/BaseHooks.java new file mode 100644 index 00000000..53dda9df --- /dev/null +++ b/src/main/java/com/zuxelus/energycontrol/hooks/BaseHooks.java @@ -0,0 +1,42 @@ +package com.zuxelus.energycontrol.hooks; + +import org.apache.logging.log4j.Level; + +import com.zuxelus.energycontrol.tileentities.TileEntityInfoPanel; +import com.zuxelus.hooklib.asm.At; +import com.zuxelus.hooklib.asm.Hook; +import com.zuxelus.hooklib.asm.InjectionPoint; +import com.zuxelus.hooklib.asm.ReturnCondition; + +import cpw.mods.fml.common.FMLLog; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ReportedException; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeModContainer; + +public class BaseHooks { + + @Hook(at = @At(point = InjectionPoint.RETURN), returnCondition = ReturnCondition.ALWAYS) + public static void updateEntities(World world) { + for (Object obj : world.loadedTileEntityList) + if (obj instanceof TileEntityInfoPanel) { + TileEntityInfoPanel te = (TileEntityInfoPanel) obj; + try { + ((TileEntityInfoPanel) te).updateEntityEnd(); + } catch (Throwable throwable) { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Ticking block entity"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Block entity being ticked"); + te.func_145828_a(crashreportcategory); + if (ForgeModContainer.removeErroringTileEntities) { + FMLLog.getLogger().log(Level.ERROR, crashreport.getCompleteReport()); + te.invalidate(); + world.setBlockToAir(te.xCoord, te.yCoord, te.zCoord); + } else { + throw new ReportedException(crashreport); + } + } + } + } +} diff --git a/src/main/java/com/zuxelus/energycontrol/hooks/ECHookLoader.java b/src/main/java/com/zuxelus/energycontrol/hooks/ECHookLoader.java index 0d991065..f9e16e58 100644 --- a/src/main/java/com/zuxelus/energycontrol/hooks/ECHookLoader.java +++ b/src/main/java/com/zuxelus/energycontrol/hooks/ECHookLoader.java @@ -3,6 +3,8 @@ import com.zuxelus.hooklib.minecraft.HookLoader; import com.zuxelus.hooklib.minecraft.PrimaryClassTransformer; +import net.minecraft.tileentity.TileEntity; + public class ECHookLoader extends HookLoader { @Override @@ -12,10 +14,18 @@ public String[] getASMTransformerClass() { @Override public void registerHooks() { + registerHookContainer("com.zuxelus.energycontrol.hooks.BaseHooks"); registerHookContainer("com.zuxelus.energycontrol.hooks.DraconicEvolutionHooks"); registerHookContainer("com.zuxelus.energycontrol.hooks.EnderIOHooks"); + registerHookContainer("com.zuxelus.energycontrol.hooks.GregTechHooks"); registerHookContainer("com.zuxelus.energycontrol.hooks.HBMHooks"); registerHookContainer("com.zuxelus.energycontrol.hooks.IC2Hooks"); registerHookContainer("com.zuxelus.energycontrol.hooks.NuclearCraftHooks"); } + + public static void removeTileEntity(TileEntity te) { + if (te == null) + return; + GregTechHooks.map.remove(te); + } } diff --git a/src/main/java/com/zuxelus/energycontrol/hooks/GregTechHooks.java b/src/main/java/com/zuxelus/energycontrol/hooks/GregTechHooks.java index fcee4c39..06039a75 100644 --- a/src/main/java/com/zuxelus/energycontrol/hooks/GregTechHooks.java +++ b/src/main/java/com/zuxelus/energycontrol/hooks/GregTechHooks.java @@ -4,28 +4,288 @@ import java.util.HashMap; import java.util.Map; +import com.zuxelus.energycontrol.utils.DataHelper; +import com.zuxelus.hooklib.asm.At; import com.zuxelus.hooklib.asm.Hook; +import com.zuxelus.hooklib.asm.Hook.ReturnValue; +import com.zuxelus.hooklib.asm.InjectionPoint; +import com.zuxelus.hooklib.asm.ReturnCondition; +import gregapi.code.TagData; +import gregapi.data.CS; +import gregapi.tileentity.base.TileEntityBase01Root; +import gregapi.tileentity.connectors.MultiTileEntityPipeFluid; +import gregapi.tileentity.connectors.MultiTileEntityWireElectric; +import gregapi.tileentity.connectors.TileEntityBase10ConnectorRendered; +import gregapi.tileentity.energy.ITileEntityEnergy.Util; +import gregapi.tileentity.energy.TileEntityBase10EnergyBatBox; +import gregapi.tileentity.energy.TileEntityBase10EnergyConverter; +import gregapi.tileentity.machines.MultiTileEntityBasicMachine; +import gregapi.util.UT.Code; +import gregtech.tileentity.energy.converters.MultiTileEntityBoilerTank; +import gregtech.tileentity.energy.converters.MultiTileEntityTurbineSteam; +import gregtech.tileentity.energy.generators.MultiTileEntityMotorLiquid; +import gregtech.tileentity.energy.generators.MultiTileEntitySolarPanelElectric; +import gregtech.tileentity.energy.reactors.MultiTileEntityReactorCore2x2; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; public class GregTechHooks { public static Map map = new HashMap(); + public static Map buffer = new HashMap(); + public static final int len = 360 * 2; + public static final int buf_len = 5; - /*@Hook - public static void doUpdate(TileCapBank te) { + public static ArrayList initArray(int size) { + ArrayList list = new ArrayList<>(size); + for (int i = 0; i < size; i++) + list.add(0L); + return list; + } + + public static void addValue(ArrayList values, int start, int size, long value) { + for (int i = start + size - 1; i > start; i--) + values.set(i, values.get(i - 1)); + values.set(start, value); + } + + @Hook + public static void onTick2(MultiTileEntityBoilerTank te, long aTimer, boolean aIsServerSide) { if (!map.containsKey(te) || te.getWorldObj().isRemote) return; - + long mEnergy = DataHelper.getLong(MultiTileEntityBoilerTank.class, "mEnergy", te); + long mOutput = DataHelper.getLong(MultiTileEntityBoilerTank.class, "mOutput", te); + short mEfficiency = DataHelper.getShort(MultiTileEntityBoilerTank.class, "mEfficiency", te); + short mCoolDownResetTimer = DataHelper.getShort(MultiTileEntityBoilerTank.class, "mCoolDownResetTimer", te); + FluidTankInfo[] info = ((MultiTileEntityBoilerTank) te).getTankInfo(null); + long tConversions = Math.min(info[1].capacity / 2560L, Math.min(mEnergy / 80L, info[0].fluid != null ? info[0].fluid.amount : 0)); ArrayList values = map.get(te); if (values != null && values.size() > 0) { - for (int i = 20; i > 0; i--) + for (int i = 19; i > 0; i--) + values.set(i, values.get(i - 1)); + values.set(0, tConversions); // water + for (int i = 39; i > 20; i--) values.set(i, values.get(i - 1)); - values.set(0, (long) te.getEnergyStored()); + values.set(20, Code.units(tConversions, 10000L, mEfficiency * 160, false)); + for (int i = 59; i > 40; i--) + values.set(i, values.get(i - 1)); + values.set(40, tConversions * 80L); + if (mCoolDownResetTimer == 1) { + values.set(20, -mOutput * 64L); + values.set(40, mOutput * 64L / CS.STEAM_PER_EU); + } } else { values = new ArrayList<>(); - for (int i = 0; i < 21; i++) - values.add((long) te.getEnergyStored()); + for (int i = 0; i < 60; i++) + values.add(0L); map.put(te, values); } - }*/ + } + + @Hook(at = @At(point = InjectionPoint.HEAD)) + public static void doConversion(MultiTileEntityTurbineSteam te, long aTimer) { + if (!map.containsKey(te) || te.getWorldObj().isRemote) + return; + if (!buffer.containsKey(te)) + buffer.put(te, new long[buf_len]); + long[] list = buffer.get(te); + long water = 0; + if (te.mEnergyProducedNextTick == 0) { + if (te.mTank.has(te.getEnergySizeInputMin(te.mConverter.mEnergyIN.mType, (byte)6) * 2L)) { + long steam = te.mSteamCounter + te.mTank.amount(); + if (steam >= 200) { + water = steam / 200; + } + } + } + list[4] = water; + } + + @Hook + public static void onTick2(TileEntityBase10EnergyConverter te, long aTimer, boolean aIsServerSide) { + if (!map.containsKey(te) || !buffer.containsKey(te) || !aIsServerSide) + return; + ArrayList values = map.get(te); + long[] list = buffer.get(te); + if (values != null && values.size() > 0) { + if (te instanceof MultiTileEntityTurbineSteam) { + addValue(values, 0, len, list[3]); + addValue(values, len, len, list[1]); + addValue(values, len * 2, len, list[4]); + list[3] = 0; // consumption + list[1] = 0; // output + list[4] = 0; // water + } else { + addValue(values, 0, len, list[0]); + addValue(values, len, len, list[1]); + list[0] = 0; // consumption + list[1] = 0; // output + } + } else + map.put(te, initArray(len * (te instanceof MultiTileEntityTurbineSteam ? 3 : 2))); + } + + @Hook + public static void onTick2(TileEntityBase10ConnectorRendered te, long aTimer, boolean aIsServerSide) { + if (!map.containsKey(te) || !buffer.containsKey(te) || !aIsServerSide || te instanceof MultiTileEntityWireElectric) + return; + ArrayList values = map.get(te); + long[] list = buffer.get(te); + if (values != null && values.size() > 0) { + addValue(values, 0, len, list[0]); + addValue(values, len, len, list[1]); + //values.set(128, list[2]); + list[0] = 0; + list[1] = 0; + } else + map.put(te, initArray(len * 2)); + } + + @Hook + public static void onTick2(TileEntityBase10EnergyBatBox te, long aTimer, boolean aIsServerSide) { + if (!map.containsKey(te) || !buffer.containsKey(te) || !aIsServerSide) + return; + ArrayList values = map.get(te); + long[] list = buffer.get(te); + if (values != null && values.size() > 0) { + addValue(values, 0, len, list[0]); + addValue(values, len, len, list[1]); + //values.set(128, list[2]); + list[0] = 0; + list[1] = 0; + } else + map.put(te, initArray(len * 2)); + } + + @Hook(at = @At(point = InjectionPoint.RETURN), returnCondition = ReturnCondition.ALWAYS) + public static final long insertEnergyInto(Util te, TagData aEnergyType, byte aSideInto, long aSize, long aAmount, Object aEmitter, TileEntity aReceiver, @ReturnValue long rUsedAmount) { + if (map.containsKey(aReceiver)) { + if (!buffer.containsKey(aReceiver)) + buffer.put(aReceiver, new long[buf_len]); + long[] list = buffer.get(aReceiver); + list[0] = list[0] + rUsedAmount * aSize; + if (list[2] < aSize) + list[2] = aSize; + } + if (aEmitter instanceof TileEntity && map.containsKey(aEmitter)) { + if (!buffer.containsKey(aEmitter)) + buffer.put((TileEntity) aEmitter, new long[buf_len]); + long[] list = buffer.get(aEmitter); + list[1] = list[1] + rUsedAmount * aSize; + } + return rUsedAmount; + } + + @Hook(at = @At(point = InjectionPoint.RETURN), returnCondition = ReturnCondition.ALWAYS) + public static int fill(TileEntityBase01Root te, ForgeDirection aDirection, FluidStack aFluid, boolean aDoFill, @ReturnValue int rFilledAmount) { + if (!map.containsKey(te) || !aDoFill) + return rFilledAmount; + if (!buffer.containsKey(te)) + buffer.put(te, new long[buf_len]); + long[] list = buffer.get(te); + list[3] = list[3] + rFilledAmount; + return rFilledAmount; + } + + @Hook + public static void onTick2(MultiTileEntityWireElectric te, long aTimer, boolean aIsServerSide) { + if (!map.containsKey(te) || !aIsServerSide) + return; + ArrayList values = map.get(te); + //long[] list = buffer.get(te); + if (values != null && values.size() > 0) { + addValue(values, 0, len, te.mTransferredWattage); + values.set(len, te.mTransferredAmperes); + } else + map.put(te, initArray(len * 2)); + } + + @Hook + public static void onTick2(MultiTileEntitySolarPanelElectric te, long aTimer, boolean aIsServerSide) { + if (!map.containsKey(te) || !aIsServerSide) + return; + ArrayList values = map.get(te); + long[] list = buffer.get(te); + if (values != null && values.size() > 0) { + addValue(values, 0, len, list[0]); + addValue(values, len, len, list[1]); + list[0] = 0; + list[1] = 0; + } else + map.put(te, initArray(len * 2)); + } + + @Hook + public static void onTick2(MultiTileEntityBasicMachine te, long aTimer, boolean aIsServerSide) { + if (!map.containsKey(te) || !aIsServerSide) + return; + ArrayList values = map.get(te); + if (!buffer.containsKey(te)) + buffer.put(te, new long[buf_len]); + long[] list = buffer.get(te); + if (values != null && values.size() > 0) { + addValue(values, 0, len, list[0]); + addValue(values, len, len, list[3]); + list[0] = 0; + list[3] = 0; + } else + map.put(te, initArray(len * 2)); + } + + @Hook + public static void onTick2(MultiTileEntityMotorLiquid te, long aTimer, boolean aIsServerSide) { + if (!map.containsKey(te) || !aIsServerSide) + return; + ArrayList values = map.get(te); + if (!buffer.containsKey(te)) + buffer.put(te, new long[buf_len]); + long[] list = buffer.get(te); + if (values != null && values.size() > 0) { + addValue(values, 0, len, list[1]); + addValue(values, len, len, list[3]); + list[1] = 0; + list[3] = 0; + } else + map.put(te, initArray(len * 2)); + } + + @Hook(at = @At(point = InjectionPoint.RETURN)) + public static void onServerTickPre(MultiTileEntityPipeFluid te, boolean aFirst) { + if (!map.containsKey(te)) + return; + ArrayList values = map.get(te); + if (values != null && values.size() > 0) { + addValue(values, 0, len, te.mTransferredAmount); + } else + map.put(te, initArray(len)); + } + + @Hook + public static void onServerTickPost(MultiTileEntityReactorCore2x2 te, boolean aFirst) { + if (aFirst || !map.containsKey(te)) + return; + if (!buffer.containsKey(te)) + buffer.put(te, new long[buf_len]); + long[] list = buffer.get(te); + list[0] = te.mTanks[0].amount(); + list[1] = te.mTanks[1].amount(); + } + + @Hook(at = @At(point = InjectionPoint.RETURN), targetMethod = "onServerTickPost", returnCondition = ReturnCondition.ALWAYS) + public static void onServerTickPostEnd(MultiTileEntityReactorCore2x2 te, boolean aFirst) { + if (aFirst || !map.containsKey(te)) + return; + if (!buffer.containsKey(te)) + buffer.put(te, new long[buf_len]); + long[] list = buffer.get(te); + ArrayList values = map.get(te); + if (values != null && values.size() > 0) { + addValue(values, 0, len, te.mTanks[1].amount() - list[1]); + addValue(values, len, len, list[0] - te.mTanks[0].amount()); + } else + map.put(te, initArray(len * 2)); + } + } diff --git a/src/main/java/com/zuxelus/energycontrol/hooks/HBMHooks.java b/src/main/java/com/zuxelus/energycontrol/hooks/HBMHooks.java index 5a4f8f62..ef6ea9fe 100644 --- a/src/main/java/com/zuxelus/energycontrol/hooks/HBMHooks.java +++ b/src/main/java/com/zuxelus/energycontrol/hooks/HBMHooks.java @@ -70,7 +70,7 @@ public static void updateEntity(TileEntityCondenser te) { map.put(te, values); } - @Hook + /*@Hook public static void updateEntity(TileEntityRBMKBoiler te) { if (!map.containsKey(te) || te.getWorldObj().isRemote) return; @@ -89,7 +89,7 @@ public static void updateEntity(TileEntityRBMKBoiler te) { values.add(consumption); values.add(output); map.put(te, values); - } + }*/ @Hook public static void updateEntity(TileEntityMachineTurbine te) { @@ -191,7 +191,7 @@ public static void updateEntity(TileEntityMachineFENSU te) { } } - @Hook + /*@Hook public static void updateEntity(TileEntityMachineIGenerator te) { if (!map.containsKey(te) || te.getWorldObj().isRemote) return; @@ -222,7 +222,7 @@ public static void updateEntity(TileEntityMachineIGenerator te) { ArrayList values = new ArrayList<>(); values.add(powerGen); map.put(te, values); - } + }*/ @Hook public static void burn(TileEntityCore te, long joules) { diff --git a/src/main/java/com/zuxelus/energycontrol/items/cards/ItemCardGregTech.java b/src/main/java/com/zuxelus/energycontrol/items/cards/ItemCardGregTech.java index 09e97e5f..0fb89de4 100644 --- a/src/main/java/com/zuxelus/energycontrol/items/cards/ItemCardGregTech.java +++ b/src/main/java/com/zuxelus/energycontrol/items/cards/ItemCardGregTech.java @@ -9,9 +9,11 @@ import com.zuxelus.energycontrol.crossmod.CrossModLoader; import com.zuxelus.energycontrol.crossmod.ModIDs; import com.zuxelus.energycontrol.utils.DataHelper; +import com.zuxelus.energycontrol.utils.StringUtils; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gregtech.tileentity.energy.reactors.MultiTileEntityReactorCore2x2; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -51,10 +53,78 @@ private String getItemName(ItemStack stack) { @Override public List getStringData(int settings, ICardReader reader, boolean isServer, boolean showLabels) { List result = reader.getTitleList(); + if (reader.hasField(DataHelper.HEAT)) + result.add(new PanelString("msg.ec.InfoPanelTemp", reader.getDouble("heat"), "K", showLabels)); + if (reader.hasField(DataHelper.AMOUNTL) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelAmount", reader.getDouble(DataHelper.AMOUNTL), "L", showLabels)); if (reader.hasField(DataHelper.ENERGY) && (settings & 2) > 0) - result.add(new PanelString("msg.ec.InfoPanelEnergy", reader.getLong(DataHelper.ENERGY), "EU", showLabels)); + result.add(new PanelString("msg.ec.InfoPanelEnergy", reader.getDouble(DataHelper.ENERGY), "EU", showLabels)); + if (reader.hasField("battery") && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelBattery", reader.getDouble("battery"), "EU", showLabels)); + if (reader.hasField(DataHelper.ENERGYHU) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelEnergy", reader.getDouble(DataHelper.ENERGYHU), "HU", showLabels)); + if (reader.hasField(DataHelper.ENERGYRU) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelEnergy", reader.getDouble(DataHelper.ENERGYRU), "RU", showLabels)); + if (reader.hasField(DataHelper.OUTPUT) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelOutput", reader.getDouble(DataHelper.OUTPUT), "EU/t", showLabels)); + if (reader.hasField(DataHelper.OUTPUTHU) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelOutput", reader.getDouble(DataHelper.OUTPUTHU), "HU/t", showLabels)); + if (reader.hasField(DataHelper.OUTPUTL) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelOutput", reader.getDouble(DataHelper.OUTPUTL), "L/t", showLabels)); + if (reader.hasField(DataHelper.OUTPUTRU) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelOutput", reader.getDouble(DataHelper.OUTPUTRU), "RU/t", showLabels)); + if (reader.hasField(DataHelper.OUTPUTST) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelOutput", reader.getDouble(DataHelper.OUTPUTST), "Steam/t", showLabels)); + if (reader.hasField(DataHelper.CONSUMPTION) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelConsumption", reader.getDouble(DataHelper.CONSUMPTION), "EU/t", showLabels)); + if (reader.hasField(DataHelper.CONSUMPTIONHU) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelConsumption", reader.getDouble(DataHelper.CONSUMPTIONHU), "HU/t", showLabels)); + if (reader.hasField(DataHelper.CONSUMPTIONL) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelConsumption", reader.getDouble(DataHelper.CONSUMPTIONL), "L/t", showLabels)); + if (reader.hasField(DataHelper.CONSUMPTIONRU) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelConsumption", reader.getDouble(DataHelper.CONSUMPTIONRU), "RU/t", showLabels)); + if (reader.hasField(DataHelper.CONSUMPTIONST) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelConsumption", reader.getDouble(DataHelper.CONSUMPTIONST), "Steam/t", showLabels)); + if (reader.hasField(DataHelper.TANK)) + result.add(new PanelString("msg.ec.InfoPanelTank", reader.getString(DataHelper.TANK), showLabels)); + if (reader.hasField(DataHelper.TANK2)) + result.add(new PanelString("msg.ec.InfoPanelTank", reader.getString(DataHelper.TANK2), showLabels)); + if (reader.hasField(DataHelper.TANK3)) + result.add(new PanelString("msg.ec.InfoPanelTank", reader.getString(DataHelper.TANK3), showLabels)); + if (reader.hasField(DataHelper.TANK4)) + result.add(new PanelString("msg.ec.InfoPanelTank", reader.getString(DataHelper.TANK4), showLabels)); if (reader.hasField(DataHelper.CAPACITY) && (settings & 2) > 0) - result.add(new PanelString("msg.ec.InfoPanelCapacity", reader.getLong(DataHelper.CAPACITY), "EU", showLabels)); + result.add(new PanelString("msg.ec.InfoPanelCapacity", reader.getDouble(DataHelper.CAPACITY), "EU", showLabels)); + if (reader.hasField(DataHelper.CAPACITYL) && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelCapacity", reader.getDouble(DataHelper.CAPACITYL), "L", showLabels)); + if (reader.hasField("limit0") && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelLimitDischarge", reader.getDouble("limit0"), "EU", showLabels)); + if (reader.hasField("limit1") && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelLimitCharge", reader.getDouble("limit1"), "EU", showLabels)); + if (reader.hasField("packet") && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelMaxPacket", reader.getDouble("packet"), "", showLabels)); + if (reader.hasField("amperage") && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelAmperage", reader.getDouble("amperage"), "", showLabels)); + if (reader.hasField("remaining") && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelRemaining", reader.getDouble("remaining"), "Minutes", showLabels)); + if (reader.hasField("neutrons") && (settings & 2) > 0) + result.add(new PanelString("msg.ec.InfoPanelNeutrons", reader.getString("neutrons"), showLabels)); + if (reader.hasField("slot0")) { + ItemStack stack = ItemStack.loadItemStackFromNBT(reader.getTag("slot0")); + result.add(new PanelString(String.format("msg.ec.InfoPanelSlot%d", 1), String.format("%s x %s", stack.stackSize, StringUtils.getItemName(stack)), showLabels)); + } + if (reader.hasField("slot1")) { + ItemStack stack = ItemStack.loadItemStackFromNBT(reader.getTag("slot1")); + result.add(new PanelString(String.format("msg.ec.InfoPanelSlot%d", 2), String.format("%s x %s", stack.stackSize, StringUtils.getItemName(stack)), showLabels)); + } + if (reader.hasField("content") && (settings & 2) > 0) { + String[] list = reader.getString("content").split(","); + for (String item : list) { + result.add(new PanelString(item)); + } + } + if (reader.hasField(DataHelper.ACTIVE)) + addOnOff(result, isServer, reader.getBoolean(DataHelper.ACTIVE)); return result; } diff --git a/src/main/java/com/zuxelus/energycontrol/items/cards/ItemCardHBM.java b/src/main/java/com/zuxelus/energycontrol/items/cards/ItemCardHBM.java index ffc44c08..2c0802a0 100644 --- a/src/main/java/com/zuxelus/energycontrol/items/cards/ItemCardHBM.java +++ b/src/main/java/com/zuxelus/energycontrol/items/cards/ItemCardHBM.java @@ -130,8 +130,8 @@ public List getStringData(int settings, ICardReader reader, boolean " " + reader.getString("chunkRad"))); else result.add(new PanelString(reader.getString("chunkRad"))); - if (reader.hasField("active")) - addOnOff(result, isServer, reader.getBoolean("active")); + if (reader.hasField(DataHelper.ACTIVE)) + addOnOff(result, isServer, reader.getBoolean(DataHelper.ACTIVE)); return result; } diff --git a/src/main/java/com/zuxelus/energycontrol/recipes/StorageArrayRecipe.java b/src/main/java/com/zuxelus/energycontrol/recipes/StorageArrayRecipe.java index 60ead473..b14fe55a 100644 --- a/src/main/java/com/zuxelus/energycontrol/recipes/StorageArrayRecipe.java +++ b/src/main/java/com/zuxelus/energycontrol/recipes/StorageArrayRecipe.java @@ -1,7 +1,5 @@ package com.zuxelus.energycontrol.recipes; -import ic2.api.item.IC2Items; - import java.util.Vector; import com.zuxelus.energycontrol.init.ModItems; diff --git a/src/main/java/com/zuxelus/energycontrol/tileentities/TileEntityAdvancedInfoPanel.java b/src/main/java/com/zuxelus/energycontrol/tileentities/TileEntityAdvancedInfoPanel.java index 76e418c1..9fef3efa 100644 --- a/src/main/java/com/zuxelus/energycontrol/tileentities/TileEntityAdvancedInfoPanel.java +++ b/src/main/java/com/zuxelus/energycontrol/tileentities/TileEntityAdvancedInfoPanel.java @@ -209,7 +209,7 @@ public void updateBlockState() { break; } - powered = flag; + setPowered(flag); if (flag == (meta > 5)) return; diff --git a/src/main/java/com/zuxelus/energycontrol/tileentities/TileEntityInfoPanel.java b/src/main/java/com/zuxelus/energycontrol/tileentities/TileEntityInfoPanel.java index 001e8329..4857b49f 100644 --- a/src/main/java/com/zuxelus/energycontrol/tileentities/TileEntityInfoPanel.java +++ b/src/main/java/com/zuxelus/energycontrol/tileentities/TileEntityInfoPanel.java @@ -15,6 +15,7 @@ import com.zuxelus.energycontrol.blocks.BlockDamages; import com.zuxelus.energycontrol.blocks.HoloPanelExtender; import com.zuxelus.energycontrol.blocks.InfoPanelExtender; +import com.zuxelus.energycontrol.hooks.ECHookLoader; import com.zuxelus.energycontrol.init.ModItems; import com.zuxelus.energycontrol.items.ItemUpgrade; import com.zuxelus.energycontrol.items.cards.ItemCardMain; @@ -36,7 +37,9 @@ import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.ForgeDirection; @@ -162,6 +165,8 @@ public boolean getPowered() { public void setPowered(boolean value) { powered = value; + if (!powered) + removeTileEntityFromList(); } public void setScreenData(NBTTagCompound nbtTagCompound) { @@ -334,6 +339,9 @@ public void invalidate() { public void updateEntity() { if (!init) initData(); + } + + public void updateEntityEnd() { if (!powered) return; dataTicker--; @@ -580,7 +588,7 @@ public void updateData() { public void updateBlockState() { int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); boolean flag = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); - powered = flag; + setPowered(flag); if (flag == (meta > 5)) return; @@ -592,6 +600,16 @@ public void updateBlockState() { } } + public void removeTileEntityFromList() { + for (ItemStack card : getCards()) + if (card != null) { + ItemCardReader reader = new ItemCardReader(card); + ChunkCoordinates target = reader.getTarget(); + TileEntity te = getWorldObj().getTileEntity(target.posX, target.posY, target.posZ); + ECHookLoader.removeTileEntity(te); + } + } + public void updateExtenders(Boolean active) { if (screen == null) return; diff --git a/src/main/java/com/zuxelus/energycontrol/utils/DataHelper.java b/src/main/java/com/zuxelus/energycontrol/utils/DataHelper.java index ec0ec2b0..e19822f6 100644 --- a/src/main/java/com/zuxelus/energycontrol/utils/DataHelper.java +++ b/src/main/java/com/zuxelus/energycontrol/utils/DataHelper.java @@ -2,23 +2,30 @@ import java.lang.reflect.Field; -import ic2.core.block.generator.tileentity.TileEntityRTGenerator; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; public class DataHelper { public static final String ACTIVE = "active"; - public static final String AMOUNT = "amount"; + public static final String AMOUNT = "amount"; + public static final String AMOUNTL = "amountL"; public static final String CAPACITY = "capacity"; + public static final String CAPACITYL = "capacityL"; public static final String CAPACITYHU = "capacityHU"; public static final String CAPACITYKU = "capacityKU"; public static final String CAPACITYTU = "capacityTU"; public static final String CONSUMPTION = "consumption"; public static final String CONSUMPTIONHE = "consumptionHE"; + public static final String CONSUMPTIONHU = "consumptionHU"; + public static final String CONSUMPTIONL = "consumptionL"; + public static final String CONSUMPTIONRU = "consumptionRU"; + public static final String CONSUMPTIONST = "consumptionST"; public static final String CONSUMPTIONTU = "consumptionTU"; public static final String DIFF = "diff"; public static final String ENERGY = "energy"; public static final String ENERGYHU = "energyHU"; public static final String ENERGYKU = "energyKU"; + public static final String ENERGYRU = "energyRU"; public static final String ENERGYTU = "energyTU"; public static final String EUTYPE = "euType"; public static final String FUEL = "fuel"; @@ -28,8 +35,11 @@ public class DataHelper { public static final String OUTPUT = "output"; public static final String OUTPUTHU = "outputHU"; public static final String OUTPUTKU = "outputKU"; + public static final String OUTPUTL = "outputL"; + public static final String OUTPUTRU = "outputRU"; public static final String OUTPUTTU = "outputTU"; public static final String OUTPUTMB = "outputmb"; + public static final String OUTPUTST = "outputST"; public static final String PRESSURE = "pressure"; public static final String TANK = "tank"; public static final String TANK2 = "tank2"; @@ -64,6 +74,15 @@ public static int getInt(Class obj, String name, TileEntity te) { return 0; } + public static long getLong(Class obj, String name, TileEntity te) { + try { + Field field = obj.getDeclaredField(name); + field.setAccessible(true); + return (long) field.get(te); + } catch (Throwable t) { } + return 0; + } + public static short getShort(Class obj, String name, TileEntity te) { try { Field field = obj.getDeclaredField(name); @@ -72,5 +91,23 @@ public static short getShort(Class obj, String name, TileEntity te) { } catch (Throwable t) { } return 0; } + + public static boolean getBoolean(Class obj, String name, TileEntity te) { + try { + Field field = obj.getDeclaredField(name); + field.setAccessible(true); + return (boolean) field.get(te); + } catch (Throwable t) { } + return false; + } + + public static ItemStack[] getItemStackList(Class obj, String name, TileEntity te) { + try { + Field field = obj.getDeclaredField(name); + field.setAccessible(true); + return (ItemStack[]) field.get(te); + } catch (Throwable t) { } + return null; + } } diff --git a/src/main/java/com/zuxelus/energycontrol/utils/FluidInfo.java b/src/main/java/com/zuxelus/energycontrol/utils/FluidInfo.java index 1a13813f..621385bc 100644 --- a/src/main/java/com/zuxelus/energycontrol/utils/FluidInfo.java +++ b/src/main/java/com/zuxelus/energycontrol/utils/FluidInfo.java @@ -94,6 +94,13 @@ public static void addTank(String name, NBTTagCompound tag, FluidStack stack) { tag.setString(name, String.format("%s: %s mB", stack.getLocalizedName(), stack.amount)); } + public static void addTank(String name, NBTTagCompound tag, FluidStack stack, String unit) { + if (stack == null) + tag.setString(name, "N/A"); + else + tag.setString(name, String.format("%s: %s %s", stack.getLocalizedName(), stack.amount, unit)); + } + public static List toFluidInfoList(FluidTankInfo[] tanks) { // 1.7.10 if (tanks == null || tanks.length == 0) return null; diff --git a/src/main/resources/assets/energycontrol/lang/en_US.lang b/src/main/resources/assets/energycontrol/lang/en_US.lang index 028ea625..cab7ab3e 100644 --- a/src/main/resources/assets/energycontrol/lang/en_US.lang +++ b/src/main/resources/assets/energycontrol/lang/en_US.lang @@ -119,9 +119,11 @@ msg.ec.InfoPanelNoTarget=Target Not Found msg.ec.InfoPanelAmount=Amount: %s msg.ec.InfoPanelAmountmB=Amount: %s mB +msg.ec.InfoPanelAmperage=Amperage: %s msg.ec.InfoPanelAtmosphericValve=Atmospheric Valve: %s msg.ec.InfoPanelAugmentation=Augmentation: %s msg.ec.InfoPanelBarometer=Barometer: %s +msg.ec.InfoPanelBattery=Battery: %s msg.ec.InfoPanelBlades=Blades: %s msg.ec.InfoPanelBoilRate=Boil Rate: %s mB/t msg.ec.InfoPanelBlockPowered=Block Powered: %s @@ -174,10 +176,13 @@ msg.ec.InfoPanelInjectionRate=Injection Rate: %s msg.ec.InfoPanelInput=Input: %s msg.ec.InfoPanelLensDurability=Lens Durability: %s msg.ec.InfoPanelLeakage=Leakage: %s +msg.ec.InfoPanelLimitCharge=Charge Limit: %s +msg.ec.InfoPanelLimitDischarge=Discharge Limit: %s msg.ec.InfoPanelMaxFlowRate=Max Flow Rate: %s mB/t msg.ec.InfoPanelMaxHeat=Max Heat: %s msg.ec.InfoPanelMaxInput=Max Input: %s msg.ec.InfoPanelMaxOutput=Max Output: %s +msg.ec.InfoPanelMaxPacket=Max Packet: %s msg.ec.InfoPanelMaxSpeed=Max Speed: %s RPM msg.ec.InfoPanelMaxStorage=Max Storage: %s msg.ec.InfoPanelMelting=Melting: %s @@ -185,6 +190,7 @@ msg.ec.InfoPanelMethane=Methane: %s msg.ec.InfoPanelMotors=Motors: %s msg.ec.InfoPanelMultiplier=Multiplier: %s msg.ec.InfoPanelName=Name: %s +msg.ec.InfoPanelNeutrons=Neutrons: %s msg.ec.InfoPanelOff=Off msg.ec.InfoPanelOilTank=Oil Tank: %s msg.ec.InfoPanelOn=On @@ -210,6 +216,7 @@ msg.ec.InfoPanelRadiation=Radiation: %s msg.ec.InfoPanelRateLimit=Rate Limit: %s mB/t msg.ec.InfoPanelRedstonePower=Redstone Power: %s msg.ec.InfoPanelRedstoneMode=Redstone Mode: %s +msg.ec.InfoPanelRemaining=Remaining: %s msg.ec.InfoPanelRotorEfficiency=Rotor Efficiency: %s msg.ec.InfoPanelRotorMass=Rotor Mass: %s msg.ec.InfoPanelRotorSpeed=Rotor Speed: %s RPM