From cc518e371ff8557877d3e3f33aac91c0881c6d7b Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 8 Nov 2020 08:51:17 +0000 Subject: Fixes tesla covers Looks like GT5 covers are behaviors and not discrete objects, go figure! This is a horrible fix, but it works. --- .../mechanics/tesla/TeslaCoverConnection.java | 50 ++++++++++++++++++++++ .../tectech/thing/cover/GT_Cover_TM_TeslaCoil.java | 46 ++------------------ .../cover/GT_Cover_TM_TeslaCoil_Ultimate.java | 3 +- 3 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java new file mode 100644 index 0000000000..99e0d75c1c --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java @@ -0,0 +1,50 @@ +package com.github.technus.tectech.mechanics.tesla; + +import com.github.technus.tectech.util.Vec3Impl; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +public class TeslaCoverConnection implements ITeslaConnectableSimple { + private final IGregTechTileEntity IGT; + private final byte teslaReceptionCapability; + + public TeslaCoverConnection(IGregTechTileEntity IGT, byte teslaReceptionCapability) { + this.IGT = IGT; + this.teslaReceptionCapability = teslaReceptionCapability; + } + + @Override + public byte getTeslaReceptionCapability() { + return teslaReceptionCapability; + } + + @Override + public float getTeslaReceptionCoefficient() { + return 1; + } + + @Override + public boolean isTeslaReadyToReceive() { + return true; + } + + @Override + public long getTeslaStoredEnergy() { + return IGT.getStoredEU(); + } + + @Override + public Vec3Impl getTeslaPosition() { + return new Vec3Impl(IGT); + } + + @Override + public Integer getTeslaDimension() { + return IGT.getWorld().provider.dimensionId; + } + + @Override + public boolean teslaInjectEnergy(long teslaVoltageInjected) { + //Same as in the microwave transmitters, this does not account for amp limits + return IGT.injectEnergyUnits((byte) 1, teslaVoltageInjected, 1L) > 0L; + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java index 2efe2f3cbc..d3d9ead6d2 100644 --- a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java @@ -1,9 +1,9 @@ package com.github.technus.tectech.thing.cover; import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple; +import com.github.technus.tectech.mechanics.tesla.TeslaCoverConnection; import com.github.technus.tectech.util.Vec3Impl; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.EntityPlayer; @@ -11,9 +11,7 @@ import net.minecraft.entity.player.EntityPlayer; import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.*; import static ic2.api.info.Info.DMG_ELECTRIC; -public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior implements ITeslaConnectableSimple { - private IGregTechTileEntity IGT; - +public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior { public GT_Cover_TM_TeslaCoil() { } @@ -21,14 +19,10 @@ public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior implements ITeslaCon public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { //Only do stuff if we're on top and have power if (aSide == 1 || aTileEntity.getEUCapacity() > 0) { - //Pull IGT onto the outside, should only execute first tick - if (IGT == null) { - IGT = aTileEntity.getIGregTechTileEntityOffset(0, 0, 0); - } //Makes sure we're on the list - teslaNodeSet.add(this); + teslaNodeSet.add(new TeslaCoverConnection(aTileEntity.getIGregTechTileEntityOffset(0, 0, 0), + getTeslaReceptionCapability())); } - return super.doCoverThings(aSide, aInputRedstone, aCoverID, aCoverVariable, aTileEntity, aTimer); } @@ -57,39 +51,7 @@ public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior implements ITeslaCon return 200; } - @Override public byte getTeslaReceptionCapability() { return 2; } - - @Override - public float getTeslaReceptionCoefficient() { - return 1; - } - - @Override - public boolean isTeslaReadyToReceive() { - return true; - } - - @Override - public long getTeslaStoredEnergy() { - return IGT.getStoredEU(); - } - - @Override - public Vec3Impl getTeslaPosition() { - return new Vec3Impl(IGT); - } - - @Override - public Integer getTeslaDimension() { - return IGT.getWorld().provider.dimensionId; - } - - @Override - public boolean teslaInjectEnergy(long teslaVoltageInjected) { - //Same as in the microwave transmitters, this does not account for amp limits - return IGT.injectEnergyUnits((byte) 1, teslaVoltageInjected, 1L) > 0L; - } } diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil_Ultimate.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil_Ultimate.java index 028ac3a4d6..3417d7ae20 100644 --- a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil_Ultimate.java +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil_Ultimate.java @@ -31,8 +31,7 @@ public class GT_Cover_TM_TeslaCoil_Ultimate extends GT_Cover_TM_TeslaCoil { public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { return true; } - - @Override + public byte getTeslaReceptionCapability() { return 1; } -- cgit From 70b7ebbfc1014ed3f1bd571c31d8b6a550a82abe Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 8 Nov 2020 09:06:04 +0000 Subject: Fixed Tesla hysteresis function --- .../com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java index e397c1dc5f..291acf393d 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java @@ -83,6 +83,10 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { } ITeslaConnectableSimple target = Rx.getKey(); + + //Continue if the target can't receive + if(!target.isTeslaReadyToReceive()) continue; + int distance = Rx.getValue(); //Calculate the voltage output -- cgit From 8dd64d25caf626c538dcb628408a239ee724fc5e Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 15 Nov 2020 15:29:30 +0000 Subject: Tesla Speedup -Switched from sorted HashMap to ArrayListMultiMap -Fixed issue where interface lacked proper methods --- .../tectech/mechanics/tesla/ITeslaConnectable.java | 23 +++--- .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 18 ++++ .../single/GT_MetaTileEntity_TeslaCoil.java | 96 +++++++++++++--------- 3 files changed, 87 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java index 291acf393d..d505ca8e09 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java @@ -1,19 +1,20 @@ package com.github.technus.tectech.mechanics.tesla; import com.github.technus.tectech.mechanics.spark.ThaumSpark; +import com.google.common.collect.Multimap; -import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Objects; -import static com.github.technus.tectech.util.Util.entriesSortedByValues; import static java.lang.Math.sqrt; public interface ITeslaConnectable extends ITeslaConnectableSimple { //Map with all Teslas in the same dimension and the distance to them //TODO Range - HashMap teslaNodeMap = new HashMap<>(); + Multimap getTeslaNodeMap(); + //ThaumCraft lighting coordinate pairs, so we can send them in bursts and save on lag - HashSet sparkList = new HashSet<>(); + HashSet getSparkList(); //-128 to -1 disables capability //0 means any source or target @@ -36,7 +37,7 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { public static final HashSet teslaNodeSet = new HashSet<>();//Targets for power transmission public static void generateTeslaNodeMap(ITeslaConnectable origin) { - origin.teslaNodeMap.clear(); + origin.getTeslaNodeMap().clear(); for (ITeslaConnectableSimple target : teslaNodeSet) { //Sanity checks if (target == null) { @@ -59,13 +60,13 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { //Skip if the range is too vast continue; } - origin.teslaNodeMap.put(target, distance); + origin.getTeslaNodeMap().put(distance, target); } } public static void cleanTeslaNodeMap(ITeslaConnectable origin) { //Wipes all null objects, in practice this is unloaded or improperly removed tesla objects - origin.teslaNodeMap.keySet().removeIf(Objects::isNull); + origin.getTeslaNodeMap().keySet().removeIf(Objects::isNull); } public static long powerTeslaNodeMap(ITeslaConnectable origin) { @@ -76,18 +77,18 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { long remainingAmperes = origin.getTeslaOutputCurrent(); while (remainingAmperes > 0) { long startingAmperes = remainingAmperes; - for (HashMap.Entry Rx : entriesSortedByValues(teslaNodeMap)) { + for (Map.Entry Rx : origin.getTeslaNodeMap().entries()) { if (origin.getTeslaStoredEnergy() < (origin.isOverdriveEnabled() ? origin.getTeslaOutputVoltage() * 2 : origin.getTeslaOutputVoltage())) { //Return and end the tick if we're out of energy to send return origin.getTeslaOutputCurrent() - remainingAmperes; } - ITeslaConnectableSimple target = Rx.getKey(); + ITeslaConnectableSimple target = Rx.getValue(); //Continue if the target can't receive if(!target.isTeslaReadyToReceive()) continue; - int distance = Rx.getValue(); + int distance = Rx.getKey(); //Calculate the voltage output long outputVoltageInjectable; @@ -109,7 +110,7 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { if (target.teslaInjectEnergy(outputVoltageInjectable)) { origin.teslaDrainEnergy(outputVoltageConsumption); - sparkList.add(new ThaumSpark(origin.getTeslaPosition(), target.getTeslaPosition(), origin.getTeslaDimension())); + origin.getSparkList().add(new ThaumSpark(origin.getTeslaPosition(), target.getTeslaPosition(), origin.getTeslaDimension())); remainingAmperes--; } if (remainingAmperes == 0) { diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index 93f6e50c5a..5f6e0fffaa 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -8,6 +8,7 @@ import com.github.technus.tectech.mechanics.spark.ThaumSpark; import com.github.technus.tectech.mechanics.structure.Structure; import com.github.technus.tectech.mechanics.structure.adders.IHatchAdder; import com.github.technus.tectech.mechanics.tesla.ITeslaConnectable; +import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Capacitor; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti; @@ -19,6 +20,8 @@ import com.github.technus.tectech.thing.metaTileEntity.multi.base.Parameters; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedExtendedFacingTexture; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.util.Vec3Impl; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.Materials; @@ -35,6 +38,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; +import java.util.HashSet; import static com.github.technus.tectech.mechanics.structure.Structure.adders; import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.*; @@ -47,6 +51,10 @@ import static java.lang.Math.*; import static net.minecraft.util.StatCollector.translateToLocal; public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_MultiblockBase_EM implements IConstructable, ITeslaConnectable { + //Interface fields + Multimap teslaNodeMap = ArrayListMultimap.create(); + HashSet sparkList = new HashSet<>(); + //region variables private static final int transferRadiusTowerFromConfig = TecTech.configTecTech.TESLA_MULTI_RANGE_TOWER;//Default is 32 private static final int transferRadiusTransceiverFromConfig = TecTech.configTecTech.TESLA_MULTI_RANGE_TRANSCEIVER;//Default is 16 @@ -701,6 +709,16 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock return 0; } + @Override + public Multimap getTeslaNodeMap() { + return teslaNodeMap; + } + + @Override + public HashSet getSparkList() { + return sparkList; + } + @Override public byte getTeslaTransmissionCapability() { return 1; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index 388a253b27..cc42929806 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.thing.metaTileEntity.single; import com.github.technus.tectech.mechanics.tesla.ITeslaConnectable; +import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.TecTech; import com.github.technus.tectech.loader.NetworkDispatcher; @@ -9,6 +10,8 @@ import com.github.technus.tectech.mechanics.spark.ThaumSpark; import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_TM_teslaCoil; import com.github.technus.tectech.util.Util; import com.github.technus.tectech.util.Vec3Impl; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import eu.usrv.yamcore.auxiliary.PlayerChatHelper; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -23,6 +26,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.reflect.FieldUtils; import java.util.Arrays; +import java.util.HashSet; import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.*; import static com.github.technus.tectech.util.CommonValues.V; @@ -32,6 +36,10 @@ import static net.minecraft.util.StatCollector.translateToLocal; import static net.minecraft.util.StatCollector.translateToLocalFormatted; public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer implements ITeslaConnectable { + //Interface fields + Multimap teslaNodeMap = ArrayListMultimap.create(); + HashSet sparkList = new HashSet<>(); + private final static int transferRadiusMax = TecTech.configTecTech.TESLA_SINGLE_RANGE;//Default is 20 private final static int perBlockLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_PER_BLOCK;//Default is 1 private final static float overDriveLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_FACTOR_OVERDRIVE;//Default is 0.25F @@ -179,45 +187,45 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB return new GT_MetaTileEntity_TeslaCoil(mName, mTier, mDescription, mTextures, mInventory.length); } - private void thaumLightning(IGregTechTileEntity mte, IGregTechTileEntity node) { - int x = mte.getXCoord(); - int y = mte.getYCoord(); - int z = mte.getZCoord(); - - byte xR; - byte yR; - byte zR; - - IMetaTileEntity nodeInside = node.getMetaTileEntity(); - if (nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil) { - GT_MetaTileEntity_TM_teslaCoil nodeTesla = (GT_MetaTileEntity_TM_teslaCoil) nodeInside; - xR = (byte) (nodeTesla.posTop.get0() - x); - yR = (byte) (nodeTesla.posTop.get1() - y); - zR = (byte) (nodeTesla.posTop.get2() - z); - } else { - xR = (byte) (node.getXCoord() - x); - yR = (byte) (node.getYCoord() - y); - zR = (byte) (node.getZCoord() - z); - } - - int wID = mte.getWorld().provider.dimensionId; - - sparkList.add(new ThaumSpark(x, y, z, xR, yR, zR, wID)); - } - - private long[] getOutputVoltage(long outputVoltage, int distance, boolean overDriveToggle) { - long outputVoltageInjectable; - long outputVoltageConsumption; - - if (overDriveToggle) { - outputVoltageInjectable = outputVoltage; - outputVoltageConsumption = outputVoltage + (distance * perBlockLoss) + (long) Math.round(overDriveLoss * outputVoltage); - } else { - outputVoltageInjectable = outputVoltage - (distance * perBlockLoss); - outputVoltageConsumption = outputVoltage; - } - return new long[]{outputVoltageInjectable, outputVoltageConsumption}; - } +// private void thaumLightning(IGregTechTileEntity mte, IGregTechTileEntity node) { +// int x = mte.getXCoord(); +// int y = mte.getYCoord(); +// int z = mte.getZCoord(); +// +// byte xR; +// byte yR; +// byte zR; +// +// IMetaTileEntity nodeInside = node.getMetaTileEntity(); +// if (nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil) { +// GT_MetaTileEntity_TM_teslaCoil nodeTesla = (GT_MetaTileEntity_TM_teslaCoil) nodeInside; +// xR = (byte) (nodeTesla.posTop.get0() - x); +// yR = (byte) (nodeTesla.posTop.get1() - y); +// zR = (byte) (nodeTesla.posTop.get2() - z); +// } else { +// xR = (byte) (node.getXCoord() - x); +// yR = (byte) (node.getYCoord() - y); +// zR = (byte) (node.getZCoord() - z); +// } +// +// int wID = mte.getWorld().provider.dimensionId; +// +// sparkList.add(new ThaumSpark(x, y, z, xR, yR, zR, wID)); +// } +// +// private long[] getOutputVoltage(long outputVoltage, int distance, boolean overDriveToggle) { +// long outputVoltageInjectable; +// long outputVoltageConsumption; +// +// if (overDriveToggle) { +// outputVoltageInjectable = outputVoltage; +// outputVoltageConsumption = outputVoltage + (distance * perBlockLoss) + (long) Math.round(overDriveLoss * outputVoltage); +// } else { +// outputVoltageInjectable = outputVoltage - (distance * perBlockLoss); +// outputVoltageConsumption = outputVoltage; +// } +// return new long[]{outputVoltageInjectable, outputVoltageConsumption}; +// } @Override public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { @@ -308,6 +316,16 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB return 1; } + @Override + public Multimap getTeslaNodeMap() { + return teslaNodeMap; + } + + @Override + public HashSet getSparkList() { + return sparkList; + } + @Override public byte getTeslaTransmissionCapability() { return 2; -- cgit From 548e3eb74288448704ec790b4be6bdd16d3f7549 Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 15 Nov 2020 17:07:46 +0000 Subject: Further Optimisation -Tesla Maps are fully written to only one -Subsequent modifications are done to remove or add new Teslas -Lots more encapsulation --- .../tectech/mechanics/tesla/ITeslaConnectable.java | 76 ++++++++++++++-------- .../tectech/thing/cover/GT_Cover_TM_TeslaCoil.java | 4 +- .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 9 +-- .../single/GT_MetaTileEntity_TeslaCoil.java | 8 +-- 4 files changed, 55 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java index d505ca8e09..07059c82b2 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java @@ -34,39 +34,59 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { boolean teslaDrainEnergy(long teslaVoltageDrained); class TeslaUtil { - public static final HashSet teslaNodeSet = new HashSet<>();//Targets for power transmission + private static final HashSet teslaSimpleNodeSet = new HashSet<>();//Targets for power transmission + private static final HashSet teslaNodeSet = new HashSet<>();//Sources of power transmission - public static void generateTeslaNodeMap(ITeslaConnectable origin) { - origin.getTeslaNodeMap().clear(); - for (ITeslaConnectableSimple target : teslaNodeSet) { - //Sanity checks - if (target == null) { - //The Tesla Covers do not remove themselves from the list and this is the code that does - teslaNodeSet.remove(null); - continue; - } else if (origin.equals(target) || !origin.getTeslaDimension().equals(target.getTeslaDimension())) { - //Skip if looking at myself and skip if not in the same dimension - //TODO, INTERDIM? - continue; - } else if (origin.getTeslaTransmissionCapability() != 0 && origin.getTeslaReceptionCapability() != 0 && - origin.getTeslaTransmissionCapability() != origin.getTeslaReceptionCapability()) { - //Skip if incompatible - continue; - } + public static void teslaSimpleNodeSetAdd(ITeslaConnectableSimple target){ + teslaSimpleNodeSet.add(target); + teslaNodeSet.forEach(origin -> addTargetToTeslaOrigin(target, origin)); + } - //Range calc - int distance = (int) sqrt(origin.getTeslaPosition().distanceSq(target.getTeslaPosition())); - if (distance > origin.getTeslaTransmissionRange() * target.getTeslaReceptionCoefficient()) { - //Skip if the range is too vast - continue; - } - origin.getTeslaNodeMap().put(distance, target); + public static void teslaSimpleNodeSetRemove(ITeslaConnectableSimple target){ + teslaSimpleNodeSet.remove(target); + if (target instanceof ITeslaConnectable)teslaNodeSet.remove(target); + teslaNodeSet.forEach(origin -> removeTargetFromTeslaOrigin(target, origin)); + } + + private static void addTargetToTeslaOrigin(ITeslaConnectableSimple target, ITeslaConnectable origin){ + if (origin.equals(target) || !origin.getTeslaDimension().equals(target.getTeslaDimension())) { + //Skip if looking at myself and skip if not in the same dimension + //TODO, INTERDIM? + return; + } else if (origin.getTeslaTransmissionCapability() != 0 && origin.getTeslaReceptionCapability() != 0 && + origin.getTeslaTransmissionCapability() != origin.getTeslaReceptionCapability()) { + //Skip if incompatible + return; + } + //Range calc + int distance = (int) sqrt(origin.getTeslaPosition().distanceSq(target.getTeslaPosition())); + if (distance > origin.getTeslaTransmissionRange() * target.getTeslaReceptionCoefficient()) { + //Skip if the range is too vast + return; } + origin.getTeslaNodeMap().put(distance, target); } - public static void cleanTeslaNodeMap(ITeslaConnectable origin) { - //Wipes all null objects, in practice this is unloaded or improperly removed tesla objects - origin.getTeslaNodeMap().keySet().removeIf(Objects::isNull); + private static void removeTargetFromTeslaOrigin(ITeslaConnectableSimple target, ITeslaConnectable origin){ + //Range calc TODO Remove duplicate? + int distance = (int) sqrt(origin.getTeslaPosition().distanceSq(target.getTeslaPosition())); + origin.getTeslaNodeMap().remove(distance, target); + } + + public static void generateTeslaNodeMap(ITeslaConnectable origin) { + if(!teslaNodeSet.contains(origin)) { + origin.getTeslaNodeMap().clear(); + for (ITeslaConnectableSimple target : teslaSimpleNodeSet) { + //Sanity checks + if (target == null) { + //The Tesla Covers do not remove themselves from the list and this is the code that does + teslaSimpleNodeSet.remove(null); + continue; + } + addTargetToTeslaOrigin(target, origin); + } + } + teslaNodeSet.add(origin); } public static long powerTeslaNodeMap(ITeslaConnectable origin) { diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java index d3d9ead6d2..a573ed740b 100644 --- a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java @@ -1,8 +1,6 @@ package com.github.technus.tectech.thing.cover; -import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple; import com.github.technus.tectech.mechanics.tesla.TeslaCoverConnection; -import com.github.technus.tectech.util.Vec3Impl; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; @@ -20,7 +18,7 @@ public class GT_Cover_TM_TeslaCoil extends GT_CoverBehavior { //Only do stuff if we're on top and have power if (aSide == 1 || aTileEntity.getEUCapacity() > 0) { //Makes sure we're on the list - teslaNodeSet.add(new TeslaCoverConnection(aTileEntity.getIGregTechTileEntityOffset(0, 0, 0), + teslaSimpleNodeSetAdd(new TeslaCoverConnection(aTileEntity.getIGregTechTileEntityOffset(0, 0, 0), getTeslaReceptionCapability())); } return super.doCoverThings(aSide, aInputRedstone, aCoverID, aCoverVariable, aTileEntity, aTimer); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index 5f6e0fffaa..22f1d003e6 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -462,7 +462,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock if (this.getBaseMetaTileEntity().isClientSide()) { return; } - teslaNodeSet.remove(this); + teslaSimpleNodeSetRemove(this); for (GT_MetaTileEntity_Hatch_Capacitor cap : eCapacitorHatches) { if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { cap.getBaseMetaTileEntity().setActive(false); @@ -536,7 +536,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); energyCapacity = aNBT.getLong("eEnergyCapacity"); - teslaNodeSet.add(this); + teslaSimpleNodeSetAdd(this); } @Override @@ -556,7 +556,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock public void onFirstTick_EM(IGregTechTileEntity aBaseMetaTileEntity) { super.onFirstTick_EM(aBaseMetaTileEntity); if (!aBaseMetaTileEntity.isClientSide()) { - teslaNodeSet.add(this); + teslaSimpleNodeSetAdd(this); } } @@ -606,9 +606,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock transferRadiusTransceiverDisplay.set(transferRadiusTower * 2); transferRadiusCoverUltimateDisplay.set(transferRadiusTower); - //Clean the teslaNodeMap - cleanTeslaNodeMap(this); - //Power transfer outputCurrentDisplay.set(powerTeslaNodeMap(this)); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index cc42929806..c7ebb76e09 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -7,14 +7,12 @@ import com.github.technus.tectech.TecTech; import com.github.technus.tectech.loader.NetworkDispatcher; import com.github.technus.tectech.mechanics.spark.RendererMessage; import com.github.technus.tectech.mechanics.spark.ThaumSpark; -import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_TM_teslaCoil; import com.github.technus.tectech.util.Util; import com.github.technus.tectech.util.Vec3Impl; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import eu.usrv.yamcore.auxiliary.PlayerChatHelper; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicBatteryBuffer; @@ -231,7 +229,7 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { super.onFirstTick(aBaseMetaTileEntity); if (!aBaseMetaTileEntity.isClientSide()) { - teslaNodeSet.add(this); + teslaSimpleNodeSetAdd(this); } } @@ -239,14 +237,14 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB public void onRemoval() { super.onRemoval(); if (!this.getBaseMetaTileEntity().isClientSide()) { - teslaNodeSet.remove(this); + teslaSimpleNodeSetRemove(this); } } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - teslaNodeSet.add(this); + teslaSimpleNodeSetAdd(this); } @Override -- cgit From ab706fea9e4192b611788981930a575f6d4205fe Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 15 Nov 2020 17:57:49 +0000 Subject: Thaum Lightning fixes -Less spammy lightning bolts -Still has duplicate code and stuff --- .../tectech/mechanics/tesla/ITeslaConnectable.java | 19 +++-- .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 55 +++++++-------- .../single/GT_MetaTileEntity_TeslaCoil.java | 82 +++++----------------- 3 files changed, 49 insertions(+), 107 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java index 07059c82b2..74aa4b8463 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java @@ -5,7 +5,6 @@ import com.google.common.collect.Multimap; import java.util.HashSet; import java.util.Map; -import java.util.Objects; import static java.lang.Math.sqrt; @@ -74,17 +73,15 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { } public static void generateTeslaNodeMap(ITeslaConnectable origin) { - if(!teslaNodeSet.contains(origin)) { - origin.getTeslaNodeMap().clear(); - for (ITeslaConnectableSimple target : teslaSimpleNodeSet) { - //Sanity checks - if (target == null) { - //The Tesla Covers do not remove themselves from the list and this is the code that does - teslaSimpleNodeSet.remove(null); - continue; - } - addTargetToTeslaOrigin(target, origin); + origin.getTeslaNodeMap().clear(); + for (ITeslaConnectableSimple target : teslaSimpleNodeSet) { + //Sanity checks + if (target == null) { + //The Tesla Covers do not remove themselves from the list and this is the code that does + teslaSimpleNodeSet.remove(null); + continue; } + addTargetToTeslaOrigin(target, origin); } teslaNodeSet.add(origin); } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index 22f1d003e6..d1d645acc2 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -52,8 +52,9 @@ import static net.minecraft.util.StatCollector.translateToLocal; public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_MultiblockBase_EM implements IConstructable, ITeslaConnectable { //Interface fields - Multimap teslaNodeMap = ArrayListMultimap.create(); - HashSet sparkList = new HashSet<>(); + private final Multimap teslaNodeMap = ArrayListMultimap.create(); + private final HashSet sparkList = new HashSet<>(); + private int sparkCount = 10; //region variables private static final int transferRadiusTowerFromConfig = TecTech.configTecTech.TESLA_MULTI_RANGE_TOWER;//Default is 32 @@ -81,8 +82,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private final ArrayList eCapacitorHatches = new ArrayList<>(); //Capacitor hatches which determine the max voltage tier and count of amps - private int sortTime = 0; //Scan timer used for tesla search intervals - private long energyCapacity = 0; //Total energy storage limited by capacitors private long outputVoltageMax = 0; //Tesla voltage output limited by capacitors private int vTier = -1; //Tesla voltage tier limited by capacitors @@ -459,13 +458,12 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock @Override public void onRemoval() { super.onRemoval(); - if (this.getBaseMetaTileEntity().isClientSide()) { - return; - } - teslaSimpleNodeSetRemove(this); - for (GT_MetaTileEntity_Hatch_Capacitor cap : eCapacitorHatches) { - if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { - cap.getBaseMetaTileEntity().setActive(false); + if (!getBaseMetaTileEntity().isClientSide()) { + teslaSimpleNodeSetRemove(this); + for (GT_MetaTileEntity_Hatch_Capacitor cap : eCapacitorHatches) { + if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(cap)) { + cap.getBaseMetaTileEntity().setActive(false); + } } } } @@ -557,13 +555,12 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock super.onFirstTick_EM(aBaseMetaTileEntity); if (!aBaseMetaTileEntity.isClientSide()) { teslaSimpleNodeSetAdd(this); + generateTeslaNodeMap(this); } } @Override public boolean onRunningTick(ItemStack aStack) { - IGregTechTileEntity mte = getBaseMetaTileEntity(); - //Hysteresis based ePowerPass setting float energyFrac = (float) getEUVar() / energyCapacity; @@ -577,15 +574,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock ePowerPass = false; } - //Create the teslaNodeMap - if (sortTime == sortTimeMinSetting.get()) { - sortTime = 0; - sortTimeDisplay.updateStatus(); - generateTeslaNodeMap(this); - } - sortTime++; - sortTimeDisplay.set(sortTime); - //Power Limit Settings if (outputVoltageSetting.get() > 0) { outputVoltage = min(outputVoltageMax, (long) outputVoltageSetting.get()); @@ -609,16 +597,21 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock //Power transfer outputCurrentDisplay.set(powerTeslaNodeMap(this)); - if (!sparkList.isEmpty()) { - NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), - mte.getWorld().provider.dimensionId, - posTop.get0(), - posTop.get1(), - posTop.get2(), - 256); + //Randomly send all the sparks out once every 3 to 5 seconds + sparkCount--; + if (sparkCount == 0){ + IGregTechTileEntity mte = getBaseMetaTileEntity(); + sparkCount = 60 + mte.getWorld().rand.nextInt(41); + if(!sparkList.isEmpty()){ + NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), + mte.getWorld().provider.dimensionId, + mte.getXCoord(), + mte.getYCoord(), + mte.getZCoord(), + 256); + sparkList.clear(); + } } - sparkList.clear(); - return true; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index c7ebb76e09..292d363ad9 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -35,15 +35,13 @@ import static net.minecraft.util.StatCollector.translateToLocalFormatted; public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer implements ITeslaConnectable { //Interface fields - Multimap teslaNodeMap = ArrayListMultimap.create(); - HashSet sparkList = new HashSet<>(); + private final Multimap teslaNodeMap = ArrayListMultimap.create(); + private final HashSet sparkList = new HashSet<>(); + private int sparkCount = 10; private final static int transferRadiusMax = TecTech.configTecTech.TESLA_SINGLE_RANGE;//Default is 20 private final static int perBlockLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_PER_BLOCK;//Default is 1 private final static float overDriveLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_FACTOR_OVERDRIVE;//Default is 0.25F - - private byte sparkCount = 0; - private final static int transferRadiusMin = 4;//Minimum user configurable private int transferRadius = transferRadiusMax;//Default transferRadius setting @@ -61,9 +59,6 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB private String clientLocale = "en_US"; - private int sortTime = 0;//Sorting tick counter - private final static int sortTimeMax = 100;//Sorting tick counter limit, so we only sort once every 5 seconds - public GT_MetaTileEntity_TeslaCoil(int aID, String aName, String aNameRegional, int aTier, int aSlotCount) { super(aID, aName, aNameRegional, aTier, "", aSlotCount); Util.setTier(aTier, this); @@ -185,51 +180,12 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB return new GT_MetaTileEntity_TeslaCoil(mName, mTier, mDescription, mTextures, mInventory.length); } -// private void thaumLightning(IGregTechTileEntity mte, IGregTechTileEntity node) { -// int x = mte.getXCoord(); -// int y = mte.getYCoord(); -// int z = mte.getZCoord(); -// -// byte xR; -// byte yR; -// byte zR; -// -// IMetaTileEntity nodeInside = node.getMetaTileEntity(); -// if (nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil) { -// GT_MetaTileEntity_TM_teslaCoil nodeTesla = (GT_MetaTileEntity_TM_teslaCoil) nodeInside; -// xR = (byte) (nodeTesla.posTop.get0() - x); -// yR = (byte) (nodeTesla.posTop.get1() - y); -// zR = (byte) (nodeTesla.posTop.get2() - z); -// } else { -// xR = (byte) (node.getXCoord() - x); -// yR = (byte) (node.getYCoord() - y); -// zR = (byte) (node.getZCoord() - z); -// } -// -// int wID = mte.getWorld().provider.dimensionId; -// -// sparkList.add(new ThaumSpark(x, y, z, xR, yR, zR, wID)); -// } -// -// private long[] getOutputVoltage(long outputVoltage, int distance, boolean overDriveToggle) { -// long outputVoltageInjectable; -// long outputVoltageConsumption; -// -// if (overDriveToggle) { -// outputVoltageInjectable = outputVoltage; -// outputVoltageConsumption = outputVoltage + (distance * perBlockLoss) + (long) Math.round(overDriveLoss * outputVoltage); -// } else { -// outputVoltageInjectable = outputVoltage - (distance * perBlockLoss); -// outputVoltageConsumption = outputVoltage; -// } -// return new long[]{outputVoltageInjectable, outputVoltageConsumption}; -// } - @Override public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { super.onFirstTick(aBaseMetaTileEntity); if (!aBaseMetaTileEntity.isClientSide()) { teslaSimpleNodeSetAdd(this); + generateTeslaNodeMap(this); } } @@ -266,27 +222,23 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB powerPassToggle = false; } - //Create the teslaNodeMap - if (sortTime == sortTimeMax) { - sortTime = 0; - generateTeslaNodeMap(this); - } - sortTime++; - //Send Power powerTeslaNodeMap(this); - sparkCount++; - if (sparkCount == 60 && !sparkList.isEmpty()) { - sparkCount = 0; - NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), - aBaseMetaTileEntity.getWorld().provider.dimensionId, - aBaseMetaTileEntity.getXCoord(), - aBaseMetaTileEntity.getYCoord(), - aBaseMetaTileEntity.getZCoord(), - 256); + //Randomly send all the sparks out once every 3 to 5 seconds + sparkCount--; + if (sparkCount == 0){ + sparkCount = 60 + aBaseMetaTileEntity.getWorld().rand.nextInt(41); + if(!sparkList.isEmpty()){ + NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), + aBaseMetaTileEntity.getWorld().provider.dimensionId, + aBaseMetaTileEntity.getXCoord(), + aBaseMetaTileEntity.getYCoord(), + aBaseMetaTileEntity.getZCoord(), + 256); + sparkList.clear(); + } } - sparkList.clear(); } @Override -- cgit From 7fc2f07281062f043aa958fe66efed42c48150a7 Mon Sep 17 00:00:00 2001 From: basdxz Date: Mon, 16 Nov 2020 02:05:51 +0000 Subject: Optimised Tesla Energy Injection -Small refactor in RendererMessage -Updated GT5u --- build.properties | 2 +- .../tectech/mechanics/spark/RendererMessage.java | 4 +- .../tectech/mechanics/tesla/ITeslaConnectable.java | 69 +++++++++++----------- 3 files changed, 38 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/build.properties b/build.properties index 02c2b83517..0143910a75 100644 --- a/build.properties +++ b/build.properties @@ -6,7 +6,7 @@ ic2.version=2.2.790-experimental codechickenlib.version=1.1.3.140 codechickencore.version=1.0.7.47 nei.version=1.0.5.120 -gregtech.jenkinsbuild=736 +gregtech.jenkinsbuild=745 gregtech.version=5.09.33.55 #cofhcore.version=[1.7.10]3.1.4-329-dev cofh_core_version=2388751 diff --git a/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java b/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java index 58caed7951..4004a8d826 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java +++ b/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java @@ -31,7 +31,7 @@ public class RendererMessage implements IMessage { ObjectInputStream ois = new ObjectInputStream(is); Object data = ois.readObject(); sparkList = (HashSet) data; - } catch (IOException | ClassNotFoundException ex) { + } catch (IOException | ClassNotFoundException ignored) { } } @@ -44,7 +44,7 @@ public class RendererMessage implements IMessage { oos.flush(); InputStream is = new ByteArrayInputStream(baos.toByteArray()); pBuffer.writeBytes(is, baos.toByteArray().length); - } catch (IOException ex) { + } catch (IOException ignore) { } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java index 74aa4b8463..d5f215053f 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java @@ -87,56 +87,57 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { } public static long powerTeslaNodeMap(ITeslaConnectable origin) { - //Teslas can only send OR receive - if (origin.isTeslaReadyToReceive()) { - return 0L;//TODO Negative values to indicate charging? - } long remainingAmperes = origin.getTeslaOutputCurrent(); - while (remainingAmperes > 0) { - long startingAmperes = remainingAmperes; - for (Map.Entry Rx : origin.getTeslaNodeMap().entries()) { - if (origin.getTeslaStoredEnergy() < (origin.isOverdriveEnabled() ? origin.getTeslaOutputVoltage() * 2 : origin.getTeslaOutputVoltage())) { - //Return and end the tick if we're out of energy to send - return origin.getTeslaOutputCurrent() - remainingAmperes; - } + boolean canSendPower = !origin.isTeslaReadyToReceive() && remainingAmperes > 0; + if (canSendPower) { + for (Map.Entry Rx : origin.getTeslaNodeMap().entries()) { + //Do we still have power left to send kind of check + if (origin.getTeslaStoredEnergy() < (origin.isOverdriveEnabled() ? origin.getTeslaOutputVoltage() * + 2 : origin.getTeslaOutputVoltage())) break; + //Explicit words for the important fields ITeslaConnectableSimple target = Rx.getValue(); - - //Continue if the target can't receive - if(!target.isTeslaReadyToReceive()) continue; - int distance = Rx.getKey(); + //Can our target receive energy? + if(!target.isTeslaReadyToReceive()) continue; //Calculate the voltage output long outputVoltageInjectable; long outputVoltageConsumption; - if (origin.isOverdriveEnabled()) { outputVoltageInjectable = origin.getTeslaOutputVoltage(); - outputVoltageConsumption = origin.getTeslaOutputVoltage() + (distance * origin.getTeslaEnergyLossPerBlock()) + - (long) Math.round(origin.getTeslaOutputVoltage() * origin.getTeslaOverdriveLossCoefficient()); + outputVoltageConsumption = origin.getTeslaOutputVoltage() + + (distance * origin.getTeslaEnergyLossPerBlock()) + + (long) Math.round(origin.getTeslaOutputVoltage() * + origin.getTeslaOverdriveLossCoefficient()); } else { - outputVoltageInjectable = origin.getTeslaOutputVoltage() - (distance * origin.getTeslaEnergyLossPerBlock()); + outputVoltageInjectable = origin.getTeslaOutputVoltage() - (distance * + origin.getTeslaEnergyLossPerBlock()); outputVoltageConsumption = origin.getTeslaOutputVoltage(); } - //Skip the target if the cost is too high - if (origin.getTeslaStoredEnergy() < outputVoltageConsumption) { - continue; + //Break out of the loop if the cost is too high + //Since the next target will have an even higher cost, just quit now. + if (origin.getTeslaStoredEnergy() < outputVoltageConsumption) break; + + //Now shove in as many packets as will fit~ + while(canSendPower){ + if (target.teslaInjectEnergy(outputVoltageInjectable)) { + origin.teslaDrainEnergy(outputVoltageConsumption); + origin.getSparkList().add(new ThaumSpark(origin.getTeslaPosition(), + target.getTeslaPosition(), origin.getTeslaDimension())); + remainingAmperes--; + //Update the can send power flag each time we send power + canSendPower = (origin.getTeslaStoredEnergy() < outputVoltageConsumption || + remainingAmperes == 0); + } else { + //Breaks out when I can't send anymore power + break; + } } - if (target.teslaInjectEnergy(outputVoltageInjectable)) { - origin.teslaDrainEnergy(outputVoltageConsumption); - origin.getSparkList().add(new ThaumSpark(origin.getTeslaPosition(), target.getTeslaPosition(), origin.getTeslaDimension())); - remainingAmperes--; - } - if (remainingAmperes == 0) { - return origin.getTeslaOutputCurrent(); - } - } - //End the tick after one iteration with no transmissions - if (remainingAmperes == startingAmperes) { - return origin.getTeslaOutputCurrent() - remainingAmperes; + //Break out if we can't send power anymore + if (canSendPower)break; } } return origin.getTeslaOutputCurrent() - remainingAmperes; -- cgit From 0304d1464f38ac75cf338ac470f1cc7228cd6d5c Mon Sep 17 00:00:00 2001 From: Tec Date: Wed, 25 Nov 2020 17:25:05 +0100 Subject: Implement anti-laser target hatches! https://www.livescience.com/anti-laser-wireless-charging.html --- .../multi/base/GT_MetaTileEntity_MultiblockBase_EM.java | 4 ++-- src/main/resources/assets/tectech/lang/en_US.lang | 2 +- src/main/resources/assets/tectech/lang/zh_CN.lang | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java index 9af6d40df7..8abb027d3f 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java @@ -1440,7 +1440,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(tHatch)) { euVar = tHatch.maxEUOutput(); if (tHatch.getBaseMetaTileEntity().getStoredEU() <= tHatch.maxEUStore() - euVar && - aBaseMetaTileEntity.decreaseStoredEnergyUnits(euVar + Math.max(euVar >> 7, 1), false)) { + aBaseMetaTileEntity.decreaseStoredEnergyUnits(euVar + Math.max(euVar / 24576, 1), false)) { tHatch.setEUVar(tHatch.getBaseMetaTileEntity().getStoredEU() + euVar); } } @@ -1449,7 +1449,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(tHatch)) { euVar = tHatch.maxEUOutput() * tHatch.Amperes; if (tHatch.getBaseMetaTileEntity().getStoredEU() <= tHatch.maxEUStore() - euVar && - aBaseMetaTileEntity.decreaseStoredEnergyUnits(euVar + Math.max(euVar >> 7, tHatch.Amperes), false)) { + aBaseMetaTileEntity.decreaseStoredEnergyUnits(euVar + Math.max(euVar / 24576, tHatch.Amperes), false)) { tHatch.setEUVar(tHatch.getBaseMetaTileEntity().getStoredEU() + euVar); } } diff --git a/src/main/resources/assets/tectech/lang/en_US.lang b/src/main/resources/assets/tectech/lang/en_US.lang index dc4af9970b..b81b865b22 100644 --- a/src/main/resources/assets/tectech/lang/en_US.lang +++ b/src/main/resources/assets/tectech/lang/en_US.lang @@ -538,7 +538,7 @@ gt.blockmachines.multimachine.em.transformer.name=Active Transformer gt.blockmachines.multimachine.em.transformer.hint=1 - Energy IO Hatches or High Power Casing gt.blockmachines.multimachine.em.transformer.desc.0=Power substation gt.blockmachines.multimachine.em.transformer.desc.1=All the transformation! -gt.blockmachines.multimachine.em.transformer.desc.2=Only 0.78125% power loss, HAYO! +gt.blockmachines.multimachine.em.transformer.desc.2=Only 0.004% power loss, HAYO! gt.blockmachines.multimachine.tm.microwave.name=Microwave Grinder gt.blockmachines.multimachine.tm.microwave.hint.0=1 - Classic Hatches or Clean Stainless Steel Casing diff --git a/src/main/resources/assets/tectech/lang/zh_CN.lang b/src/main/resources/assets/tectech/lang/zh_CN.lang index 6aae89bb1b..cfa23fb88d 100644 --- a/src/main/resources/assets/tectech/lang/zh_CN.lang +++ b/src/main/resources/assets/tectech/lang/zh_CN.lang @@ -535,7 +535,7 @@ gt.blockmachines.multimachine.em.transformer.name=有源变压器 gt.blockmachines.multimachine.em.transformer.hint=1 - 能源仓、动力仓或超能机械方块 gt.blockmachines.multimachine.em.transformer.desc.0=变电站 gt.blockmachines.multimachine.em.transformer.desc.1=任意电压间的相互转换! -gt.blockmachines.multimachine.em.transformer.desc.2=只有0.78125%的能量损失, HAYO! +gt.blockmachines.multimachine.em.transformer.desc.2=只有0.004%的能量损失, HAYO! gt.blockmachines.multimachine.tm.microwave.name=微波发生仪 gt.blockmachines.multimachine.tm.microwave.hint.0=1 - 基础仓室或洁净不锈钢机械方块 -- cgit From 08e3d560737749ed9e8b9848c5f98303e2a9d190 Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 29 Nov 2020 17:27:45 +0000 Subject: Changed lightning Now a constant once every half second --- .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 2 +- .../single/GT_MetaTileEntity_TeslaCoil.java | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index d1d645acc2..a1912bff32 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -601,7 +601,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock sparkCount--; if (sparkCount == 0){ IGregTechTileEntity mte = getBaseMetaTileEntity(); - sparkCount = 60 + mte.getWorld().rand.nextInt(41); + sparkCount = 10; if(!sparkList.isEmpty()){ NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), mte.getWorld().provider.dimensionId, diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index 292d363ad9..28668b7634 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -228,7 +228,7 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB //Randomly send all the sparks out once every 3 to 5 seconds sparkCount--; if (sparkCount == 0){ - sparkCount = 60 + aBaseMetaTileEntity.getWorld().rand.nextInt(41); + sparkCount = 10; if(!sparkList.isEmpty()){ NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), aBaseMetaTileEntity.getWorld().provider.dimensionId, @@ -243,16 +243,15 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - try { - EntityPlayerMP player = (EntityPlayerMP) aPlayer; - clientLocale = (String) FieldUtils.readField(player, "translator", true); - } catch (Exception e) { - clientLocale = "en_US"; + if (aBaseMetaTileEntity.isServerSide()) { + try { + EntityPlayerMP player = (EntityPlayerMP) aPlayer; + clientLocale = (String) FieldUtils.readField(player, "translator", true); + } catch (Exception e) { + clientLocale = "en_US"; + } + aBaseMetaTileEntity.openGUI(aPlayer); } - aBaseMetaTileEntity.openGUI(aPlayer); return true; } -- cgit From bd9322e8352b50f5d816bb65d92bfaeea7bd072c Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 29 Nov 2020 17:28:00 +0000 Subject: More robust Tesla covers --- .../tectech/mechanics/tesla/TeslaCoverConnection.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java index 99e0d75c1c..385ad8d74e 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java @@ -3,12 +3,17 @@ package com.github.technus.tectech.mechanics.tesla; import com.github.technus.tectech.util.Vec3Impl; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.teslaSimpleNodeSetAdd; +import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.teslaSimpleNodeSetRemove; + public class TeslaCoverConnection implements ITeslaConnectableSimple { private final IGregTechTileEntity IGT; + private final Vec3Impl pos; private final byte teslaReceptionCapability; public TeslaCoverConnection(IGregTechTileEntity IGT, byte teslaReceptionCapability) { this.IGT = IGT; + this.pos = new Vec3Impl(IGT); this.teslaReceptionCapability = teslaReceptionCapability; } @@ -34,7 +39,7 @@ public class TeslaCoverConnection implements ITeslaConnectableSimple { @Override public Vec3Impl getTeslaPosition() { - return new Vec3Impl(IGT); + return pos; } @Override @@ -45,6 +50,14 @@ public class TeslaCoverConnection implements ITeslaConnectableSimple { @Override public boolean teslaInjectEnergy(long teslaVoltageInjected) { //Same as in the microwave transmitters, this does not account for amp limits - return IGT.injectEnergyUnits((byte) 1, teslaVoltageInjected, 1L) > 0L; + boolean output = false; + + if (!IGT.isDead()){ + output = IGT.injectEnergyUnits((byte) 1, teslaVoltageInjected, 1L) > 0L; + } else { + teslaSimpleNodeSetRemove(this); + } + + return output; } } -- cgit From 27234f0fae5be18cd66a83d6be0664a2e0e08921 Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 29 Nov 2020 17:50:30 +0000 Subject: Fix power sending logic --- .../com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java index d5f215053f..3cb8d9e9a2 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java @@ -129,7 +129,7 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { remainingAmperes--; //Update the can send power flag each time we send power canSendPower = (origin.getTeslaStoredEnergy() < outputVoltageConsumption || - remainingAmperes == 0); + remainingAmperes > 0); } else { //Breaks out when I can't send anymore power break; @@ -137,7 +137,7 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { } //Break out if we can't send power anymore - if (canSendPower)break; + if (!canSendPower)break; } } return origin.getTeslaOutputCurrent() - remainingAmperes; -- cgit From 36ffce4bc6e283c4d4ffb5913af610206278d2ac Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 29 Nov 2020 18:53:32 +0000 Subject: Fix MultiMap sorting --- .../thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java | 3 ++- .../thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index a1912bff32..580e6195ad 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -22,6 +22,7 @@ import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.util.Vec3Impl; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import com.google.common.collect.MultimapBuilder; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.Materials; @@ -52,7 +53,7 @@ import static net.minecraft.util.StatCollector.translateToLocal; public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_MultiblockBase_EM implements IConstructable, ITeslaConnectable { //Interface fields - private final Multimap teslaNodeMap = ArrayListMultimap.create(); + private final Multimap teslaNodeMap = MultimapBuilder.treeKeys().linkedListValues().build(); private final HashSet sparkList = new HashSet<>(); private int sparkCount = 10; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index 28668b7634..8c3fb9410b 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -11,6 +11,7 @@ import com.github.technus.tectech.util.Util; import com.github.technus.tectech.util.Vec3Impl; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import com.google.common.collect.MultimapBuilder; import eu.usrv.yamcore.auxiliary.PlayerChatHelper; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -35,7 +36,7 @@ import static net.minecraft.util.StatCollector.translateToLocalFormatted; public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer implements ITeslaConnectable { //Interface fields - private final Multimap teslaNodeMap = ArrayListMultimap.create(); + private final Multimap teslaNodeMap = MultimapBuilder.treeKeys().linkedListValues().build(); private final HashSet sparkList = new HashSet<>(); private int sparkCount = 10; -- cgit From b21fbb19c3c1a5093ed3200e7caa637c2699e5e2 Mon Sep 17 00:00:00 2001 From: basdxz Date: Sun, 29 Nov 2020 18:53:59 +0000 Subject: Fix Duplicate Tesla Connections with covers --- .../technus/tectech/mechanics/tesla/ITeslaConnectable.java | 8 +++++--- .../tectech/mechanics/tesla/TeslaCoverConnection.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java index 3cb8d9e9a2..de8d828cf4 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/ITeslaConnectable.java @@ -36,9 +36,11 @@ public interface ITeslaConnectable extends ITeslaConnectableSimple { private static final HashSet teslaSimpleNodeSet = new HashSet<>();//Targets for power transmission private static final HashSet teslaNodeSet = new HashSet<>();//Sources of power transmission - public static void teslaSimpleNodeSetAdd(ITeslaConnectableSimple target){ - teslaSimpleNodeSet.add(target); - teslaNodeSet.forEach(origin -> addTargetToTeslaOrigin(target, origin)); + public static void teslaSimpleNodeSetAdd(ITeslaConnectableSimple target) { + if (!teslaSimpleNodeSet.contains(target)) { + teslaSimpleNodeSet.add(target); + teslaNodeSet.forEach(origin -> addTargetToTeslaOrigin(target, origin)); + } } public static void teslaSimpleNodeSetRemove(ITeslaConnectableSimple target){ diff --git a/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java b/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java index 385ad8d74e..5c6fef6af8 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java +++ b/src/main/java/com/github/technus/tectech/mechanics/tesla/TeslaCoverConnection.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.mechanics.tesla; import com.github.technus.tectech.util.Vec3Impl; +import com.google.common.base.Objects; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.teslaSimpleNodeSetAdd; @@ -60,4 +61,17 @@ public class TeslaCoverConnection implements ITeslaConnectableSimple { return output; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TeslaCoverConnection that = (TeslaCoverConnection) o; + return Objects.equal(IGT, that.IGT); + } + + @Override + public int hashCode() { + return Objects.hashCode(IGT); + } } -- cgit From 6f9466f7251748b7308edea9d845655f3d9b4ac6 Mon Sep 17 00:00:00 2001 From: basdxz Date: Tue, 15 Dec 2020 13:50:35 +0000 Subject: Ender Covers Things missing: -UI -Texture -Recipe -Wiki --- .../technus/tectech/loader/NetworkDispatcher.java | 5 + .../technus/tectech/loader/thing/CoverLoader.java | 4 + .../technus/tectech/loader/thing/ThingsLoader.java | 1 + .../enderStorage/EnderFluidContainer.java | 100 ++++++ .../enderStorage/EnderLinkCoverMessage.java | 122 +++++++ .../mechanics/enderStorage/EnderLinkTag.java | 39 +++ .../mechanics/enderStorage/EnderLinkTank.java | 46 +++ .../enderStorage/EnderWorldSavedData.java | 129 ++++++++ .../technus/tectech/thing/CustomItemList.java | 2 +- .../thing/cover/GT_Cover_TM_EnderFluidLink.java | 356 +++++++++++++++++++++ .../technus/tectech/thing/item/EnderLinkCover.java | 82 +++++ .../blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png | Bin 0 -> 157 bytes .../tectech/textures/items/itemEnderLinkCover.png | Bin 0 -> 169 bytes 13 files changed, 885 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderFluidContainer.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTag.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTank.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderWorldSavedData.java create mode 100644 src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java create mode 100644 src/main/java/com/github/technus/tectech/thing/item/EnderLinkCover.java create mode 100644 src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png create mode 100644 src/main/resources/assets/tectech/textures/items/itemEnderLinkCover.png (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java b/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java index 581c81d15f..1edd924587 100644 --- a/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java +++ b/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java @@ -2,6 +2,7 @@ package com.github.technus.tectech.loader; import com.github.technus.tectech.mechanics.data.ChunkDataMessage; import com.github.technus.tectech.mechanics.data.PlayerDataMessage; +import com.github.technus.tectech.mechanics.enderStorage.EnderLinkCoverMessage; import com.github.technus.tectech.mechanics.spark.RendererMessage; import com.github.technus.tectech.mechanics.alignment.AlignmentMessage; import com.github.technus.tectech.thing.metaTileEntity.hatch.TextParametersMessage; @@ -34,6 +35,10 @@ public class NetworkDispatcher extends eu.usrv.yamcore.network.PacketDispatcher registerMessage(RendererMessage.ClientHandler.class, RendererMessage.RendererData.class); + registerMessage(EnderLinkCoverMessage.ServerHandler.class, EnderLinkCoverMessage.EnderLinkCoverQuery.class); + registerMessage(EnderLinkCoverMessage.ServerUpdateHandler.class, EnderLinkCoverMessage.EnderLinkCoverUpdate.class); + registerMessage(EnderLinkCoverMessage.ClientHandler.class, EnderLinkCoverMessage.EnderLinkCoverData.class); + registerMessage(TextParametersMessage.ServerHandler.class, TextParametersMessage.ParametersTextQuery.class); registerMessage(TextParametersMessage.ServerUpdateHandler.class, TextParametersMessage.ParametersTextUpdate.class); registerMessage(TextParametersMessage.ClientHandler.class, TextParametersMessage.ParametersTextData.class); diff --git a/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java index d7e9a21a67..84dd00f65c 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java @@ -1,8 +1,10 @@ package com.github.technus.tectech.loader.thing; import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.thing.cover.GT_Cover_TM_EnderFluidLink; import com.github.technus.tectech.thing.cover.GT_Cover_TM_TeslaCoil; import com.github.technus.tectech.thing.cover.GT_Cover_TM_TeslaCoil_Ultimate; +import com.github.technus.tectech.thing.item.EnderLinkCover; import com.github.technus.tectech.thing.item.TeslaCoilCover; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; @@ -16,9 +18,11 @@ public class CoverLoader implements Runnable { public void run() { final IIconContainer TESLA_OVERLAY = new Textures.BlockIcons.CustomIcon("iconsets/TESLA_OVERLAY"); final IIconContainer TESLA_OVERLAY_ULTIMATE = new Textures.BlockIcons.CustomIcon("iconsets/TESLA_OVERLAY_ULTIMATE"); + final IIconContainer ENDERFLUIDLINK_OVERLAY = new Textures.BlockIcons.CustomIcon("iconsets/ENDERFLUIDLINK_OVERLAY"); GregTech_API.registerCover(new ItemStack(TeslaCoilCover.INSTANCE, 1, 0), new GT_RenderedTexture(TESLA_OVERLAY), new GT_Cover_TM_TeslaCoil()); GregTech_API.registerCover(new ItemStack(TeslaCoilCover.INSTANCE, 1, 1), new GT_RenderedTexture(TESLA_OVERLAY_ULTIMATE), new GT_Cover_TM_TeslaCoil_Ultimate()); + GregTech_API.registerCover(new ItemStack(EnderLinkCover.INSTANCE, 1, 0), new GT_RenderedTexture(ENDERFLUIDLINK_OVERLAY), new GT_Cover_TM_EnderFluidLink()); TecTech.LOGGER.info("Cover functionality registered"); } } diff --git a/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java index 7b432dbcb4..c5d8a2bb89 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java @@ -60,6 +60,7 @@ public class ThingsLoader implements Runnable { TeslaStaff.run(); TeslaCoilCover.run(); TeslaCoilCapacitor.run(); + EnderLinkCover.run(); TecTech.LOGGER.info("Useful Items registered"); TeslaCoilComponent.run(); diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderFluidContainer.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderFluidContainer.java new file mode 100644 index 0000000000..1a5ad6a69c --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderFluidContainer.java @@ -0,0 +1,100 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import java.io.Serializable; + +public class EnderFluidContainer implements IFluidHandler, Serializable { + private static final int CAPACITY = 64000; + private int fluidID = -1; + private int fluidQuantity = 0; + + public EnderFluidContainer() { + } + + private FluidStack getFluidStack() { + FluidStack fluidStack = null; + if (fluidID >= 0) { + fluidStack = new FluidStack(fluidID, fluidQuantity); + } + return fluidStack; + } + + private void setFluidStack(FluidStack fluidStack) { + if (fluidStack != null && fluidStack.amount != 0) { + fluidID = fluidStack.getFluidID(); + fluidQuantity = fluidStack.amount; + } else { + fluidID = -1; + fluidQuantity = 0; + } + } + + + @Override + public int fill(ForgeDirection side, FluidStack fluidStackIn, boolean doFill) { + int filledFluid = 0; + FluidStack fluidStackStored = getFluidStack(); + if (fluidStackIn != null) { + if (fluidStackStored == null) { + fluidStackStored = fluidStackIn.copy(); + fluidStackStored.amount = 0; + } + if (fluidStackStored.amount < CAPACITY && fluidStackIn.isFluidEqual(fluidStackStored)) { + filledFluid = Math.min(CAPACITY - fluidStackStored.amount, fluidStackIn.amount); + if (doFill) { + fluidStackStored.amount += filledFluid; + setFluidStack(fluidStackStored); + } + } + } + return filledFluid; + } + + @Override + public FluidStack drain(ForgeDirection side, FluidStack fluidStack, boolean doDrain) { + FluidStack fluidStackOutput = null; + if (fluidStack != null && fluidStack.isFluidEqual(getFluidStack())) { + fluidStackOutput = drain(side, fluidStack.amount, doDrain); + } + return fluidStackOutput; + } + + @Override + public FluidStack drain(ForgeDirection side, int amount, boolean doDrain) { + FluidStack fluidStackOutput = null; + FluidStack fluidStackStored = getFluidStack(); + if (fluidStackStored != null && fluidStackStored.amount > 0) { + int drainedFluid = Math.min(fluidStackStored.amount, amount); + fluidStackOutput = fluidStackStored.copy(); + fluidStackOutput.amount = drainedFluid; + if (doDrain) { + fluidStackStored.amount -= drainedFluid; + if (fluidStackStored.amount == 0) { + fluidStackStored = null; + } + setFluidStack(fluidStackStored); + } + } + return fluidStackOutput; + } + + @Override + public boolean canFill(ForgeDirection forgeDirection, Fluid fluid) { + return true; + } + + @Override + public boolean canDrain(ForgeDirection forgeDirection, Fluid fluid) { + return true; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection forgeDirection) { + return new FluidTankInfo[]{new FluidTankInfo(getFluidStack(), CAPACITY)}; + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java new file mode 100644 index 0000000000..de9b10c51d --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java @@ -0,0 +1,122 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import eu.usrv.yamcore.network.client.AbstractClientMessageHandler; +import eu.usrv.yamcore.network.server.AbstractServerMessageHandler; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fluids.IFluidHandler; + +import java.io.*; +import java.util.Arrays; + +import static com.github.technus.tectech.mechanics.enderStorage.EnderWorldSavedData.bindEnderLinkTag; +import static com.github.technus.tectech.mechanics.enderStorage.EnderWorldSavedData.getEnderLinkTag; +import static com.github.technus.tectech.thing.cover.GT_Cover_TM_EnderFluidLink.setEnderLinkTag; + +public class EnderLinkCoverMessage implements IMessage { + EnderLinkTankWithTag messageData; + + public EnderLinkCoverMessage() { + } + + @Override + public void fromBytes(ByteBuf pBuffer) { + try { + //I'd love to know why I need to offset by one byte for this to work + byte[] boop = pBuffer.array(); + boop = Arrays.copyOfRange(boop, 1, boop.length); + InputStream is = new ByteArrayInputStream(boop); + ObjectInputStream ois = new ObjectInputStream(is); + Object data = ois.readObject(); + messageData = (EnderLinkTankWithTag) data; + } catch (Exception ignore) { + } + } + + @Override + public void toBytes(ByteBuf pBuffer) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(messageData); + oos.flush(); + InputStream is = new ByteArrayInputStream(baos.toByteArray()); + pBuffer.writeBytes(is, baos.toByteArray().length); + } catch (Exception ignore) { + } + } + + public static class EnderLinkCoverQuery extends EnderLinkCoverMessage { + public EnderLinkCoverQuery() { + } + + public EnderLinkCoverQuery(EnderLinkTag tag, IFluidHandler fluidHandler) { + messageData = new EnderLinkTankWithTag(tag, fluidHandler); + } + } + + public static class EnderLinkCoverUpdate extends EnderLinkCoverMessage { + public EnderLinkCoverUpdate() { + } + + public EnderLinkCoverUpdate(EnderLinkTag tag, IFluidHandler fluidHandler) { + messageData = new EnderLinkTankWithTag(tag, fluidHandler); + } + } + + public static class EnderLinkCoverData extends EnderLinkCoverMessage { + public EnderLinkCoverData() { + } + + public EnderLinkCoverData(EnderLinkTag tag, IFluidHandler fluidHandler) { + messageData = new EnderLinkTankWithTag(tag, fluidHandler); + } + } + + public static class ServerHandler extends AbstractServerMessageHandler { + @Override + public IMessage handleServerMessage(EntityPlayer pPlayer, EnderLinkCoverQuery pMessage, MessageContext pCtx) { + IMessage reply = null; + if (pMessage.messageData != null) { + reply = new EnderLinkCoverData(getEnderLinkTag(pMessage.messageData.getFluidHandler()), + pMessage.messageData.getFluidHandler()); + } + return reply; + } + } + + public static class ServerUpdateHandler extends AbstractServerMessageHandler { + @Override + public IMessage handleServerMessage(EntityPlayer pPlayer, EnderLinkCoverUpdate pMessage, MessageContext pCtx) { + if (pMessage.messageData != null) { + bindEnderLinkTag(pMessage.messageData.getFluidHandler(), pMessage.messageData.getTag()); + } + return null; + } + } + + public static class ClientHandler extends AbstractClientMessageHandler { + @Override + public IMessage handleClientMessage(EntityPlayer pPlayer, EnderLinkCoverData pMessage, MessageContext pCtx) { + if (pMessage.messageData != null) { + setEnderLinkTag(pMessage.messageData.getTag()); + } + return null; + } + } + + private static class EnderLinkTankWithTag extends EnderLinkTank { + private final EnderLinkTag tag; + + public EnderLinkTankWithTag(EnderLinkTag tag, IFluidHandler fluidHandler) { + super(fluidHandler); + this.tag = tag; + } + + public EnderLinkTag getTag() { + return tag; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTag.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTag.java new file mode 100644 index 0000000000..3d7b7a20b8 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTag.java @@ -0,0 +1,39 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import com.google.common.base.Objects; + +import java.awt.*; +import java.io.Serializable; +import java.util.UUID; + +public class EnderLinkTag implements Serializable { + private final Color color; + private final UUID player; + + public EnderLinkTag(Color color, UUID player) { + this.color = color; + this.player = player; + } + + public int getColorInt() { + return color.getRGB(); + } + + public UUID getUUID() { + return player; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EnderLinkTag that = (EnderLinkTag) o; + return Objects.equal(color, that.color) && + Objects.equal(player, that.player); + } + + @Override + public int hashCode() { + return Objects.hashCode(color, player); + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTank.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTank.java new file mode 100644 index 0000000000..a64a629161 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkTank.java @@ -0,0 +1,46 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import com.google.common.base.Objects; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.fluids.IFluidHandler; + +import java.io.Serializable; + +public class EnderLinkTank implements Serializable { + private final int X; + private final int Y; + private final int Z; + private final int D; + + public EnderLinkTank(IFluidHandler fluidHandler) { + TileEntity tile = (TileEntity)fluidHandler; + X = tile.xCoord; + Y = tile.yCoord; + Z = tile.zCoord; + D = tile.getWorldObj().provider.dimensionId; + } + + public IFluidHandler getFluidHandler() { + IFluidHandler fluidHandler = null; + TileEntity tile = DimensionManager.getWorld(D).getTileEntity(X, Y, Z); + if (tile instanceof IFluidHandler) fluidHandler = (IFluidHandler) tile; + return fluidHandler; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EnderLinkTank that = (EnderLinkTank) o; + return X == that.X && + Y == that.Y && + Z == that.Z && + D == that.D; + } + + @Override + public int hashCode() { + return Objects.hashCode(X, Y, Z, D); + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderWorldSavedData.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderWorldSavedData.java new file mode 100644 index 0000000000..6afa3a494f --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderWorldSavedData.java @@ -0,0 +1,129 @@ +package com.github.technus.tectech.mechanics.enderStorage; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.WorldSavedData; +import net.minecraft.world.storage.MapStorage; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.fluids.IFluidHandler; + +import java.awt.*; +import java.io.*; +import java.util.HashMap; +import java.util.Map; + +import static com.github.technus.tectech.Reference.MODID; + +public class EnderWorldSavedData extends WorldSavedData { + private static EnderWorldSavedData INSTANCE; + + private static final String DATA_NAME = MODID + "_EnderWorldSavedData"; + private static final String ENDER_LIQUID_TAG_LINK = DATA_NAME + "_EnderLiquidTagLink"; + private static final String ENDER_LIQUID_TANK_LINK = DATA_NAME + "_EnderLiquidTankLink"; + private static final EnderLinkTag DEFAULT_LINK_TAG = new EnderLinkTag(Color.WHITE, null); + + private Map EnderLiquidTagLink = new HashMap<>(); + private Map EnderLiquidTankLink = new HashMap<>(); + + public EnderWorldSavedData() { + super(DATA_NAME); + } + + public EnderWorldSavedData(String s) { + super(s); + } + + @Override + public void readFromNBT(NBTTagCompound nbtTagCompound) { + try { + byte[] ba = nbtTagCompound.getByteArray(ENDER_LIQUID_TAG_LINK); + InputStream is = new ByteArrayInputStream(ba); + ObjectInputStream ois = new ObjectInputStream(is); + Object data = ois.readObject(); + EnderLiquidTagLink = (Map) data; + } catch (IOException | ClassNotFoundException ignored) { + System.out.println("ENDER_LIQUID_TAG_LINK LOAD FAILED"); + System.out.println(ignored); + } + + try { + byte[] ba = nbtTagCompound.getByteArray(ENDER_LIQUID_TANK_LINK); + InputStream is = new ByteArrayInputStream(ba); + ObjectInputStream ois = new ObjectInputStream(is); + Object data = ois.readObject(); + EnderLiquidTankLink = (Map) data; + } catch (IOException | ClassNotFoundException ignored) { + System.out.println("ENDER_LIQUID_TANK_LINK LOAD FAILED"); + System.out.println(ignored); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbtTagCompound) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(EnderLiquidTagLink); + oos.flush(); + byte[] data = bos.toByteArray(); + nbtTagCompound.setByteArray(ENDER_LIQUID_TAG_LINK, data); + } catch (IOException ignored) { + System.out.println("ENDER_LIQUID_TAG_LINK SAVE FAILED"); + System.out.println(ignored); + } + + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(EnderLiquidTankLink); + oos.flush(); + byte[] data = bos.toByteArray(); + nbtTagCompound.setByteArray(ENDER_LIQUID_TANK_LINK, data); + } catch (IOException ignored) { + System.out.println("ENDER_LIQUID_TANK_LINK SAVE FAILED"); + System.out.println(ignored); + } + } + + private static void loadInstance() { + if (INSTANCE == null) { + MapStorage storage = DimensionManager.getWorld(0).mapStorage; + INSTANCE = (EnderWorldSavedData) storage.loadData(EnderWorldSavedData.class, DATA_NAME); + if (INSTANCE == null) { + INSTANCE = new EnderWorldSavedData(); + storage.setData(DATA_NAME, INSTANCE); + } + } + INSTANCE.markDirty(); + } + + private static Map getEnderLiquidLink() { + loadInstance(); + return INSTANCE.EnderLiquidTagLink; + } + + private static Map getEnderLiquidTankLink() { + loadInstance(); + return INSTANCE.EnderLiquidTankLink; + } + + public static EnderFluidContainer getEnderFluidContainer(EnderLinkTag tag) { + if (!getEnderLiquidLink().containsKey(tag)) { + getEnderLiquidLink().put(tag, new EnderFluidContainer()); + } + return getEnderLiquidLink().get(tag); + } + + public static EnderLinkTag getEnderLinkTag(IFluidHandler handler) { + EnderLinkTank tank = new EnderLinkTank(handler); + if (!getEnderLiquidTankLink().containsKey(tank)) { + getEnderLiquidTankLink().put(tank, DEFAULT_LINK_TAG); + } + return getEnderLiquidTankLink().get(tank); + } + + public static void bindEnderLinkTag(IFluidHandler handler, EnderLinkTag tag) { + EnderLinkTank tank = new EnderLinkTank(handler); + getEnderLiquidTankLink().remove(tank); + getEnderLiquidTankLink().put(tank, tag); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java index a86695ff4a..44c18fbe09 100644 --- a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java +++ b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java @@ -94,7 +94,7 @@ public enum CustomItemList implements IItemContainer { eM_avr_HV, eM_avr_EV, eM_avr_IV, eM_avr_LuV, eM_avr_ZPM, eM_avr_UV, eM_avr_UHV, eM_avr_UEV, eM_avr_UIV, eM_avr_UMV, - scanContainer, parametrizerMemory, teslaCapacitor, teslaCover, teslaComponent, teslaStaff, + scanContainer, parametrizerMemory, teslaCapacitor, teslaCover, teslaComponent, teslaStaff, enderLinkCover, Machine_TeslaCoil_1by1_LV, Machine_TeslaCoil_1by1_MV, Machine_TeslaCoil_1by1_HV, Machine_TeslaCoil_1by1_EV, Machine_TeslaCoil_1by1_IV, Machine_TeslaCoil_2by2_LV, Machine_TeslaCoil_2by2_MV, Machine_TeslaCoil_2by2_HV, Machine_TeslaCoil_2by2_EV, Machine_TeslaCoil_2by2_IV, diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java new file mode 100644 index 0000000000..9404b3af9f --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java @@ -0,0 +1,356 @@ +package com.github.technus.tectech.thing.cover; + +import com.github.technus.tectech.loader.NetworkDispatcher; +import com.github.technus.tectech.mechanics.enderStorage.EnderLinkCoverMessage; +import com.github.technus.tectech.mechanics.enderStorage.EnderLinkTag; +import eu.usrv.yamcore.auxiliary.PlayerChatHelper; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.GT_GUICover; +import gregtech.api.gui.widgets.GT_GuiIcon; +import gregtech.api.gui.widgets.GT_GuiIconButton; +import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import gregtech.api.interfaces.IGuiScreen; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.net.GT_Packet_TileEntityCover; +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_Utility; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidHandler; + +import java.awt.*; + +import static com.github.technus.tectech.mechanics.enderStorage.EnderWorldSavedData.*; + +public class GT_Cover_TM_EnderFluidLink extends GT_CoverBehavior { + private static final int L_PER_TICK = 8000; + private final static int IMPORT_EXPORT_MASK = 0b0001; + private final static int PUBLIC_PRIVATE_MASK = 0b0010; + private static EnderLinkTag tag = new EnderLinkTag(Color.WHITE, null); + + public GT_Cover_TM_EnderFluidLink() { + } + + public static void setEnderLinkTag(EnderLinkTag inputTag) { + if(inputTag != null) { + tag = inputTag; + //Hacky Way to update the gui + GUI_INSTANCE.resetColorField(); + } + } + + private void transferFluid(IFluidHandler source, byte sSide, IFluidHandler target, byte tSide, int amount) { + FluidStack fluidStack = source.drain(ForgeDirection.getOrientation(sSide), amount, false); + + if (fluidStack != null) { + int fluidTransferred = target.fill(ForgeDirection.getOrientation(tSide), fluidStack, true); + source.drain(ForgeDirection.getOrientation(sSide), fluidTransferred, true); + } + } + + private boolean testBit(int aCoverVariable, int bitMask) { + return (aCoverVariable & bitMask) != 0; + } + + private int toggleBit(int aCoverVariable, int bitMask) { + return (aCoverVariable ^ bitMask); + } + + @Override + public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + if ((aTileEntity instanceof IFluidHandler)) { + IFluidHandler fluidHandlerSelf = (IFluidHandler) aTileEntity; + IFluidHandler fluidHandlerEnder = getEnderFluidContainer(getEnderLinkTag((IFluidHandler) aTileEntity)); + + if (testBit(aCoverVariable, IMPORT_EXPORT_MASK)) { + transferFluid(fluidHandlerEnder, (byte) 6, fluidHandlerSelf, aSide, L_PER_TICK); + } else { + transferFluid(fluidHandlerSelf, aSide, fluidHandlerEnder, (byte) 6, L_PER_TICK); + } + } + return aCoverVariable; + } + + @Override + public String getDescription(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return ""; + } + + @Override + public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return true; + } + + @Override + public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return true; + } + + @Override + public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + int newCoverVariable = toggleBit(aCoverVariable, IMPORT_EXPORT_MASK); + + if (testBit(aCoverVariable, IMPORT_EXPORT_MASK)) { + PlayerChatHelper.SendInfo(aPlayer, "Ender Suction Engaged!");//TODO Translation support + } else { + PlayerChatHelper.SendInfo(aPlayer, "Ender Filling Engaged!"); + } + return newCoverVariable; + } + + @Override + public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + //Runs each tick + return 1; + } + + //region GUI + @Override + public boolean hasCoverGUI() { + return true; + } + + @Override + public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { + //Only open gui if we're placed on a fluid tank + Object gui = null; + if (aTileEntity instanceof IFluidHandler) { + gui = new TM_EnderFluidLinkCover(aSide, aCoverID, coverData, aTileEntity); + } + return gui; + } + + private static TM_EnderFluidLinkCover GUI_INSTANCE; + + private class TM_EnderFluidLinkCover extends GT_GUICover { + private final byte side; + private final int coverID; + private int coverVariable; + private GT_GuiIntegerHexTextBox colorField; + + private final static int START_X = 10; + private final static int START_Y = 25; + private final static int SPACE_X = 18; + private final static int SPACE_Y = 18; + + private final static int SIZE_X = 176; + private final static int SIZE_Y = 107; + + private final static int BOX_SIZE_X = 34; + private final static int BOX_SIZE_Y = 34; + + private final static int TEXT_FIELD_SIZE_X = 72; + private final static int TEXT_FIELD_SIZE_Y = 12; + private final static int TEXT_STRING_LENGTH = 9; + + private final static int FONT_COLOR = 0xFF555555; + private final static int BOX_BORDER_COLOR = 0xFF000000; + + private final static int COLOR_FIELD_ID = 0; + private final static int PUBLIC_BUTTON_ID = 1; + private final static int PRIVATE_BUTTON_ID = 2; + private final static int IMPORT_BUTTON_ID = 3; + private final static int EXPORT_BUTTON_ID = 4; + + private GT_GuiIconButton newButtonWithSpacing(int id, int x, int y, GT_GuiIcon icon) { + return new GT_GuiIconButton(this, id, START_X + SPACE_X * x, START_Y + SPACE_Y * y, icon); + } + + private GT_GuiIntegerHexTextBox newTextField(int id, int x, int y) { + GT_GuiIntegerHexTextBox field = new GT_GuiIntegerHexTextBox(this, id, START_X + SPACE_X * x, + START_Y + SPACE_Y * y, TEXT_FIELD_SIZE_X, TEXT_FIELD_SIZE_Y); + field.setMaxStringLength(TEXT_STRING_LENGTH); + return field; + } + + private int drawNewString(String text, int x, int y) { + int align = 4; + return fontRendererObj.drawString(text, START_X + SPACE_X * x, align + START_Y + SPACE_Y * y, FONT_COLOR); + } + + private void drawColorSquare(int x, int y) { + //Draw the border square + int borderX1 = START_X + SPACE_X * x; + int borderY1 = START_Y + SPACE_Y * y; + int borderX2 = borderX1 + BOX_SIZE_X; + int borderY2 = borderY1 + BOX_SIZE_Y; + drawRect(borderX1, borderY1, borderX2, borderY2, BOX_BORDER_COLOR); + + // + //int white = 0xFFFFFFFF; + //int black = 0xFF000000; + //int checkers_x = 5; + //int checkers_wide = 3; + //int checkers_y = 5; + //int checkers_tall = 3; + //int checkeredX = borderX1 + 1; + //int checkeredY = borderY1 + 1; + //for (int i = 0; i < checkers_x; i++) { + // int checkerX1 = checkeredX + (checkers_wide * i); + // int checkerX2 = checkerX1 + checkers_wide; + // for (int j = 0; j < checkers_y; j++) { + // int checkerY1 = checkeredY + (checkers_tall * j); + // int checkerY2 = checkerY1 + checkers_tall; + // //Sets the color to white-black-white black and snakes around + // int nowColor = (checkers_x * i) + j % 2 == 0 ? white : black; + // drawRect(checkerX1, checkerY1, checkerX2, checkerY2, nowColor); + // } + //} + + int insideX1 = borderX1 + 1; + int insideY1 = borderY1 + 1; + int insideX2 = borderX2 - 1; + int insideY2 = borderY2 - 1; + drawRect(insideX1, insideY1, insideX2, insideY2, tag.getColorInt()); + } + + public TM_EnderFluidLinkCover(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + super(aTileEntity, SIZE_X, SIZE_Y, GT_Utility.intToStack(aCoverID)); + side = aSide; + coverID = aCoverID; + coverVariable = aCoverVariable; + NetworkDispatcher.INSTANCE.sendToServer(new EnderLinkCoverMessage.EnderLinkCoverQuery(tag, (IFluidHandler) tile)); + //Color Value Field + colorField = newTextField(COLOR_FIELD_ID, 2, 1); + GUI_INSTANCE = this; + resetColorField(); + //Public/Private Buttons + newButtonWithSpacing(PUBLIC_BUTTON_ID, 0, 2, GT_GuiIcon.WHITELIST) + .setTooltipText("Public"); + newButtonWithSpacing(PRIVATE_BUTTON_ID, 1, 2, GT_GuiIcon.BLACKLIST) + .setTooltipText("Private"); + //Import/Export Buttons + newButtonWithSpacing(IMPORT_BUTTON_ID, 0, 3, GT_GuiIcon.IMPORT) + .setTooltipText(trans("007", "Import")); + newButtonWithSpacing(EXPORT_BUTTON_ID, 1, 3, GT_GuiIcon.EXPORT) + .setTooltipText(trans("007", "Export")); + } + + @Override + public void drawExtras(int mouseX, int mouseY, float parTicks) { + super.drawExtras(mouseX, mouseY, parTicks); + drawColorSquare(0, 0); + drawNewString("Color Value", 2, 0); + drawNewString("Public/Private", 2, 2); + drawNewString(trans("229", "Import/Export"), 2, 3); + } + + @Override + protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { + updateButtons(); + } + + @Override + public void buttonClicked(GuiButton btn){ + if (getClickable(btn.id)){ + coverVariable = getNewCoverVariable(btn.id); + GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); + } + updateButtons(); + } + + private void updateButtons(){ + GuiButton b; + for (Object o : buttonList) { + b = (GuiButton) o; + b.enabled = getClickable(b.id); + } + } + + private int getNewCoverVariable(int id) { + //TODO make this work between 0 and 1 screwdriver state things + //switch (id) { + // case 0: + // return coverVariable & ~0x1; + // case 1: + // return coverVariable | 0x1; + // case 2: + // if (coverVariable > 5) + // return 0x6 | (coverVariable & ~0xE); + // return (coverVariable & ~0xE); + // case 3: + // if (coverVariable > 5) + // return 0x8 | (coverVariable & ~0xE); + // return 0x2 | (coverVariable & ~0xE); + // case 4: + // if (coverVariable > 5) + // return 0xA | (coverVariable & ~0xE); + // return (0x4 | (coverVariable & ~0xE)); + // case 5: + // if (coverVariable <= 5) + // return coverVariable + 6; + // break; + // case 6: + // if (coverVariable > 5) + // return coverVariable - 6; + //} + return coverVariable; + } + + private boolean getClickable(int id) { + //TODO Make this work for 1 to 2 buttons + //if (coverVariable < 0 | 11 < coverVariable) + // return false; + // + //switch (id) { + // case 0: case 1: + // return (0x1 & coverVariable) != id; + // case 2: + // return (coverVariable % 6) >= 2; + // case 3: + // return (coverVariable % 6) < 2 | 4 <= (coverVariable % 6); + // case 4: + // return (coverVariable % 6) < 4; + // case 5: + // return coverVariable < 6; + // case 6: + // return coverVariable >= 6; + //} + return false; + } + + @Override + public void applyTextBox(GT_GuiIntegerTextBox box) { + try { + String string = box.getText(); + int colorValue = (int) Long.parseLong(string.replaceFirst("#", ""), 16); + tag = new EnderLinkTag(new Color(colorValue, true), tag.getUUID()); + NetworkDispatcher.INSTANCE.sendToServer(new EnderLinkCoverMessage.EnderLinkCoverUpdate(tag, (IFluidHandler) tile)); + } catch (NumberFormatException ignored) { + } + resetColorField(); + } + + @Override + public void resetTextBox(GT_GuiIntegerTextBox box) { + //Solid White becomes: #FFFFFFFF + box.setText("#" + String.format("%08X", tag.getColorInt())); + } + + public void resetColorField() { + resetTextBox(colorField); + } + + private class GT_GuiIntegerHexTextBox extends GT_GuiIntegerTextBox { + public GT_GuiIntegerHexTextBox(IGuiScreen gui, int id, int x, int y, int width, int height) { + super(gui, id, x, y, width, height); + } + + @Override + public boolean validChar(char c, int key) { + boolean isValid; + if (getCursorPosition() == 0) { + isValid = c == '#'; + } else { + isValid = super.validChar(c, key) + || c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E' || c == 'F' + || c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f'; + } + return isValid; + } + } + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/item/EnderLinkCover.java b/src/main/java/com/github/technus/tectech/thing/item/EnderLinkCover.java new file mode 100644 index 0000000000..9e23d2f076 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/item/EnderLinkCover.java @@ -0,0 +1,82 @@ +package com.github.technus.tectech.thing.item; + +import com.github.technus.tectech.util.CommonValues; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; + +import java.util.List; + +import static com.github.technus.tectech.Reference.MODID; +import static com.github.technus.tectech.thing.CustomItemList.enderLinkCover; +import static com.github.technus.tectech.thing.CustomItemList.teslaCover; +import static net.minecraft.util.StatCollector.translateToLocal; + + +public final class EnderLinkCover extends Item { + public static EnderLinkCover INSTANCE; + //private static IIcon ultItemIcon; + + private EnderLinkCover() { + setHasSubtypes(true); + setUnlocalizedName("tm.enderlinkcover"); + setTextureName(MODID + ":itemEnderLinkCover"); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer ep, List aList, boolean boo) { + aList.add(CommonValues.BASS_MARK); + //switch (aStack.getItemDamage()) { + // case 0: + // aList.add(translateToLocal("item.tm.teslaCover.desc.0"));//Tesla-Enables Machines! + // break; + // case 1: + // aList.add(translateToLocal("item.tm.teslaCover.desc.1"));//Tesla-Enables Machines! (BUT LOUDER!!) + // break; + // default: + // aList.add(translateToLocal("item.tm.teslaCover.desc.2"));//Yeet this broken item into some spicy water! + // break; + //} + //aList.add(EnumChatFormatting.BLUE + translateToLocal("item.tm.teslaCover.desc.3"));//Use on top of a machine to enable Tesla capabilities + //aList.add(EnumChatFormatting.BLUE + translateToLocal("item.tm.teslaCover.desc.4"));//Who the hell uses cables anyway? + } + + @Override + public String getUnlocalizedName(ItemStack aStack) { + return getUnlocalizedName() + "." + getDamage(aStack); + } + + public static void run() { + INSTANCE = new EnderLinkCover(); + GameRegistry.registerItem(INSTANCE, INSTANCE.getUnlocalizedName()); + enderLinkCover.set(INSTANCE); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + itemIcon = iconRegister.registerIcon(getIconString()); + //ultItemIcon = iconRegister.registerIcon(MODID + ":itemTeslaCoverUltimate"); + } + + @Override + public IIcon getIconFromDamage(int damage) { + //if (damage == 1) { + // return ultItemIcon; + //} + return itemIcon; + } + + @Override + public void getSubItems(Item aItem, CreativeTabs par2CreativeTabs, List aList) { + aList.add(new ItemStack(aItem, 1, 0)); + //aList.add(new ItemStack(aItem, 1, 1)); + } +} diff --git a/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png new file mode 100644 index 0000000000..49ba0d2db9 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png differ diff --git a/src/main/resources/assets/tectech/textures/items/itemEnderLinkCover.png b/src/main/resources/assets/tectech/textures/items/itemEnderLinkCover.png new file mode 100644 index 0000000000..e57d83adff Binary files /dev/null and b/src/main/resources/assets/tectech/textures/items/itemEnderLinkCover.png differ -- cgit From 9eb861018aedb4b6e70bc664587f1944bcc459bf Mon Sep 17 00:00:00 2001 From: basdxz Date: Wed, 16 Dec 2020 12:40:12 +0000 Subject: Ender Covers UI Completed the On-Click UI --- .../thing/cover/GT_Cover_TM_EnderFluidLink.java | 133 ++++++++++----------- 1 file changed, 66 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java index 9404b3af9f..03c612c190 100644 --- a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_EnderFluidLink.java @@ -11,6 +11,8 @@ import gregtech.api.gui.widgets.GT_GuiIconButton; import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; import gregtech.api.interfaces.IGuiScreen; import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.metatileentity.BaseMetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; @@ -22,6 +24,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; import java.awt.*; +import java.util.UUID; import static com.github.technus.tectech.mechanics.enderStorage.EnderWorldSavedData.*; @@ -29,7 +32,7 @@ public class GT_Cover_TM_EnderFluidLink extends GT_CoverBehavior { private static final int L_PER_TICK = 8000; private final static int IMPORT_EXPORT_MASK = 0b0001; private final static int PUBLIC_PRIVATE_MASK = 0b0010; - private static EnderLinkTag tag = new EnderLinkTag(Color.WHITE, null); + private static EnderLinkTag tag = new EnderLinkTag(Color.WHITE, null);//Client-Sided public GT_Cover_TM_EnderFluidLink() { } @@ -179,27 +182,30 @@ public class GT_Cover_TM_EnderFluidLink extends GT_CoverBehavior { int borderY2 = borderY1 + BOX_SIZE_Y; drawRect(borderX1, borderY1, borderX2, borderY2, BOX_BORDER_COLOR); - // - //int white = 0xFFFFFFFF; - //int black = 0xFF000000; - //int checkers_x = 5; - //int checkers_wide = 3; - //int checkers_y = 5; - //int checkers_tall = 3; - //int checkeredX = borderX1 + 1; - //int checkeredY = borderY1 + 1; - //for (int i = 0; i < checkers_x; i++) { - // int checkerX1 = checkeredX + (checkers_wide * i); - // int checkerX2 = checkerX1 + checkers_wide; - // for (int j = 0; j < checkers_y; j++) { - // int checkerY1 = checkeredY + (checkers_tall * j); - // int checkerY2 = checkerY1 + checkers_tall; - // //Sets the color to white-black-white black and snakes around - // int nowColor = (checkers_x * i) + j % 2 == 0 ? white : black; - // drawRect(checkerX1, checkerY1, checkerX2, checkerY2, nowColor); - // } - //} + //Draw Checkerboard Pattern + int white = 0xFFFFFFFF; + int grey = 0xFFBFBFBF; + boolean whiteOrGrey = true; + int cGridXStart = borderX1 + 1; + int cGridYStart = borderY1 + 1; + int cGridXToDraw = 4; + int cGridYToDraw = 4; + int cSquareWidth = 8; + int cSquareHeight = 8; + for (int i = 0; i < cGridXToDraw; i++) { + for (int j = 0; j < cGridYToDraw; j++) { + int cBoxX1 = cGridXStart + (cSquareWidth * i); + int cBoxY1 = cGridYStart + (cSquareHeight * j); + int cBoxX2 = cBoxX1 + cSquareWidth; + int cBoxY2 = cBoxY1 + cSquareHeight; + int cBoxColor = whiteOrGrey ? white : grey; + drawRect(cBoxX1, cBoxY1, cBoxX2, cBoxY2, cBoxColor); + whiteOrGrey = !whiteOrGrey; + } + whiteOrGrey = !whiteOrGrey; + } + //Draw the actual color int insideX1 = borderX1 + 1; int insideY1 = borderY1 + 1; int insideX2 = borderX2 - 1; @@ -260,56 +266,49 @@ public class GT_Cover_TM_EnderFluidLink extends GT_CoverBehavior { } } + private void switchPrivatePublic(int coverVar) { + UUID ownerUUID = tag.getUUID(); + if (testBit(coverVar, PUBLIC_PRIVATE_MASK)){ + if (tile instanceof BaseMetaTileEntity){ + BaseMetaTileEntity mte = (BaseMetaTileEntity) tile; + ownerUUID = mte.getOwnerUuid(); + } + } else { + ownerUUID = null; + } + EnderLinkTag newTag = new EnderLinkTag(new Color(tag.getColorInt(), true), ownerUUID); + NetworkDispatcher.INSTANCE.sendToServer(new EnderLinkCoverMessage.EnderLinkCoverUpdate(newTag, (IFluidHandler) tile)); + } + private int getNewCoverVariable(int id) { - //TODO make this work between 0 and 1 screwdriver state things - //switch (id) { - // case 0: - // return coverVariable & ~0x1; - // case 1: - // return coverVariable | 0x1; - // case 2: - // if (coverVariable > 5) - // return 0x6 | (coverVariable & ~0xE); - // return (coverVariable & ~0xE); - // case 3: - // if (coverVariable > 5) - // return 0x8 | (coverVariable & ~0xE); - // return 0x2 | (coverVariable & ~0xE); - // case 4: - // if (coverVariable > 5) - // return 0xA | (coverVariable & ~0xE); - // return (0x4 | (coverVariable & ~0xE)); - // case 5: - // if (coverVariable <= 5) - // return coverVariable + 6; - // break; - // case 6: - // if (coverVariable > 5) - // return coverVariable - 6; - //} - return coverVariable; + int tempCoverVariable = coverVariable; + switch (id) { + case PUBLIC_BUTTON_ID: case PRIVATE_BUTTON_ID: + tempCoverVariable = toggleBit(tempCoverVariable, PUBLIC_PRIVATE_MASK); + switchPrivatePublic(tempCoverVariable); + break; + case IMPORT_BUTTON_ID: case EXPORT_BUTTON_ID: + tempCoverVariable = toggleBit(tempCoverVariable, IMPORT_EXPORT_MASK); + } + return tempCoverVariable; } private boolean getClickable(int id) { - //TODO Make this work for 1 to 2 buttons - //if (coverVariable < 0 | 11 < coverVariable) - // return false; - // - //switch (id) { - // case 0: case 1: - // return (0x1 & coverVariable) != id; - // case 2: - // return (coverVariable % 6) >= 2; - // case 3: - // return (coverVariable % 6) < 2 | 4 <= (coverVariable % 6); - // case 4: - // return (coverVariable % 6) < 4; - // case 5: - // return coverVariable < 6; - // case 6: - // return coverVariable >= 6; - //} - return false; + boolean canBeClicked = false; + switch (id) { + case PUBLIC_BUTTON_ID: + canBeClicked = testBit(coverVariable, PUBLIC_PRIVATE_MASK); + break; + case PRIVATE_BUTTON_ID: + canBeClicked = !testBit(coverVariable, PUBLIC_PRIVATE_MASK); + break; + case IMPORT_BUTTON_ID: + canBeClicked = testBit(coverVariable, IMPORT_EXPORT_MASK); + break; + case EXPORT_BUTTON_ID: + canBeClicked = !testBit(coverVariable, IMPORT_EXPORT_MASK); + } + return canBeClicked; } @Override -- cgit From 6fec93b8f4f32abc64a0b6643c41ace97f8eb9d1 Mon Sep 17 00:00:00 2001 From: basdxz Date: Sat, 19 Dec 2020 11:06:57 +0000 Subject: Added Ender Fluid Link Resources -Added Locale -Added Textures --- .../technus/tectech/loader/thing/CoverLoader.java | 4 +- .../technus/tectech/loader/thing/ThingsLoader.java | 2 +- .../enderStorage/EnderLinkCoverMessage.java | 12 ++- .../technus/tectech/thing/CustomItemList.java | 2 +- .../tectech/thing/item/EnderFluidLinkCover.java | 47 ++++++++++++ .../technus/tectech/thing/item/EnderLinkCover.java | 82 --------------------- .../blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png | Bin 157 -> 1986 bytes .../iconsets/ENDERFLUIDLINK_OVERLAY.png.mcmeta | 5 ++ src/main/resources/assets/tectech/lang/en_US.lang | 5 ++ .../textures/items/itemEnderFluidLinkCover.png | Bin 0 -> 574 bytes .../tectech/textures/items/itemEnderLinkCover.png | Bin 169 -> 0 bytes 11 files changed, 72 insertions(+), 87 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/thing/item/EnderFluidLinkCover.java delete mode 100644 src/main/java/com/github/technus/tectech/thing/item/EnderLinkCover.java create mode 100644 src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png.mcmeta create mode 100644 src/main/resources/assets/tectech/textures/items/itemEnderFluidLinkCover.png delete mode 100644 src/main/resources/assets/tectech/textures/items/itemEnderLinkCover.png (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java index 84dd00f65c..1376049f5a 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/CoverLoader.java @@ -4,7 +4,7 @@ import com.github.technus.tectech.TecTech; import com.github.technus.tectech.thing.cover.GT_Cover_TM_EnderFluidLink; import com.github.technus.tectech.thing.cover.GT_Cover_TM_TeslaCoil; import com.github.technus.tectech.thing.cover.GT_Cover_TM_TeslaCoil_Ultimate; -import com.github.technus.tectech.thing.item.EnderLinkCover; +import com.github.technus.tectech.thing.item.EnderFluidLinkCover; import com.github.technus.tectech.thing.item.TeslaCoilCover; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; @@ -22,7 +22,7 @@ public class CoverLoader implements Runnable { GregTech_API.registerCover(new ItemStack(TeslaCoilCover.INSTANCE, 1, 0), new GT_RenderedTexture(TESLA_OVERLAY), new GT_Cover_TM_TeslaCoil()); GregTech_API.registerCover(new ItemStack(TeslaCoilCover.INSTANCE, 1, 1), new GT_RenderedTexture(TESLA_OVERLAY_ULTIMATE), new GT_Cover_TM_TeslaCoil_Ultimate()); - GregTech_API.registerCover(new ItemStack(EnderLinkCover.INSTANCE, 1, 0), new GT_RenderedTexture(ENDERFLUIDLINK_OVERLAY), new GT_Cover_TM_EnderFluidLink()); + GregTech_API.registerCover(new ItemStack(EnderFluidLinkCover.INSTANCE, 1, 0), new GT_RenderedTexture(ENDERFLUIDLINK_OVERLAY), new GT_Cover_TM_EnderFluidLink()); TecTech.LOGGER.info("Cover functionality registered"); } } diff --git a/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java index c5d8a2bb89..6fa0ba2bb3 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/ThingsLoader.java @@ -60,7 +60,7 @@ public class ThingsLoader implements Runnable { TeslaStaff.run(); TeslaCoilCover.run(); TeslaCoilCapacitor.run(); - EnderLinkCover.run(); + EnderFluidLinkCover.run(); TecTech.LOGGER.info("Useful Items registered"); TeslaCoilComponent.run(); diff --git a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java index de9b10c51d..081ce3b309 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java +++ b/src/main/java/com/github/technus/tectech/mechanics/enderStorage/EnderLinkCoverMessage.java @@ -4,6 +4,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import eu.usrv.yamcore.network.client.AbstractClientMessageHandler; import eu.usrv.yamcore.network.server.AbstractServerMessageHandler; +import gregtech.api.metatileentity.BaseMetaTileEntity; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fluids.IFluidHandler; @@ -91,7 +92,16 @@ public class EnderLinkCoverMessage implements IMessage { @Override public IMessage handleServerMessage(EntityPlayer pPlayer, EnderLinkCoverUpdate pMessage, MessageContext pCtx) { if (pMessage.messageData != null) { - bindEnderLinkTag(pMessage.messageData.getFluidHandler(), pMessage.messageData.getTag()); + EnderLinkTag tag = pMessage.messageData.getTag(); + IFluidHandler handler = pMessage.messageData.getFluidHandler(); + if (tag.getUUID() == null){ + bindEnderLinkTag(handler, tag); + } else if (handler instanceof BaseMetaTileEntity) { + BaseMetaTileEntity baseTile = (BaseMetaTileEntity) handler; + if (tag.getUUID() == baseTile.getOwnerUuid()){ + bindEnderLinkTag(handler, tag); + } + } } return null; } diff --git a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java index 44c18fbe09..9bd69c67ed 100644 --- a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java +++ b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java @@ -94,7 +94,7 @@ public enum CustomItemList implements IItemContainer { eM_avr_HV, eM_avr_EV, eM_avr_IV, eM_avr_LuV, eM_avr_ZPM, eM_avr_UV, eM_avr_UHV, eM_avr_UEV, eM_avr_UIV, eM_avr_UMV, - scanContainer, parametrizerMemory, teslaCapacitor, teslaCover, teslaComponent, teslaStaff, enderLinkCover, + scanContainer, parametrizerMemory, teslaCapacitor, teslaCover, teslaComponent, teslaStaff, enderLinkFluidCover, Machine_TeslaCoil_1by1_LV, Machine_TeslaCoil_1by1_MV, Machine_TeslaCoil_1by1_HV, Machine_TeslaCoil_1by1_EV, Machine_TeslaCoil_1by1_IV, Machine_TeslaCoil_2by2_LV, Machine_TeslaCoil_2by2_MV, Machine_TeslaCoil_2by2_HV, Machine_TeslaCoil_2by2_EV, Machine_TeslaCoil_2by2_IV, diff --git a/src/main/java/com/github/technus/tectech/thing/item/EnderFluidLinkCover.java b/src/main/java/com/github/technus/tectech/thing/item/EnderFluidLinkCover.java new file mode 100644 index 0000000000..57a882ec26 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/item/EnderFluidLinkCover.java @@ -0,0 +1,47 @@ +package com.github.technus.tectech.thing.item; + +import com.github.technus.tectech.util.CommonValues; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import java.util.List; + +import static com.github.technus.tectech.Reference.MODID; +import static com.github.technus.tectech.thing.CustomItemList.enderLinkFluidCover; +import static net.minecraft.util.StatCollector.translateToLocal; + +public final class EnderFluidLinkCover extends Item { + public static EnderFluidLinkCover INSTANCE; + + private EnderFluidLinkCover() { + setHasSubtypes(true); + setUnlocalizedName("tm.enderfluidlinkcover"); + setTextureName(MODID + ":itemEnderFluidLinkCover"); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer ep, List aList, boolean boo) { + aList.add(CommonValues.BASS_MARK); + aList.add(translateToLocal("item.tm.enderfluidlinkcover.desc.0"));//Ender-Fluid-Enables Machines! + aList.add(EnumChatFormatting.BLUE + translateToLocal("item.tm.enderfluidlinkcover.desc.1"));//Use on any side of a fluid tank to link it to the Ender + aList.add(EnumChatFormatting.BLUE + translateToLocal("item.tm.enderfluidlinkcover.desc.2"));//Ender Tanks so are laggy -Bot from the Chads of NH + } + + public static void run() { + INSTANCE = new EnderFluidLinkCover(); + GameRegistry.registerItem(INSTANCE, INSTANCE.getUnlocalizedName()); + enderLinkFluidCover.set(INSTANCE); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + itemIcon = iconRegister.registerIcon(getIconString()); + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/item/EnderLinkCover.java b/src/main/java/com/github/technus/tectech/thing/item/EnderLinkCover.java deleted file mode 100644 index 9e23d2f076..0000000000 --- a/src/main/java/com/github/technus/tectech/thing/item/EnderLinkCover.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.github.technus.tectech.thing.item; - -import com.github.technus.tectech.util.CommonValues; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IIcon; - -import java.util.List; - -import static com.github.technus.tectech.Reference.MODID; -import static com.github.technus.tectech.thing.CustomItemList.enderLinkCover; -import static com.github.technus.tectech.thing.CustomItemList.teslaCover; -import static net.minecraft.util.StatCollector.translateToLocal; - - -public final class EnderLinkCover extends Item { - public static EnderLinkCover INSTANCE; - //private static IIcon ultItemIcon; - - private EnderLinkCover() { - setHasSubtypes(true); - setUnlocalizedName("tm.enderlinkcover"); - setTextureName(MODID + ":itemEnderLinkCover"); - } - - @Override - public void addInformation(ItemStack aStack, EntityPlayer ep, List aList, boolean boo) { - aList.add(CommonValues.BASS_MARK); - //switch (aStack.getItemDamage()) { - // case 0: - // aList.add(translateToLocal("item.tm.teslaCover.desc.0"));//Tesla-Enables Machines! - // break; - // case 1: - // aList.add(translateToLocal("item.tm.teslaCover.desc.1"));//Tesla-Enables Machines! (BUT LOUDER!!) - // break; - // default: - // aList.add(translateToLocal("item.tm.teslaCover.desc.2"));//Yeet this broken item into some spicy water! - // break; - //} - //aList.add(EnumChatFormatting.BLUE + translateToLocal("item.tm.teslaCover.desc.3"));//Use on top of a machine to enable Tesla capabilities - //aList.add(EnumChatFormatting.BLUE + translateToLocal("item.tm.teslaCover.desc.4"));//Who the hell uses cables anyway? - } - - @Override - public String getUnlocalizedName(ItemStack aStack) { - return getUnlocalizedName() + "." + getDamage(aStack); - } - - public static void run() { - INSTANCE = new EnderLinkCover(); - GameRegistry.registerItem(INSTANCE, INSTANCE.getUnlocalizedName()); - enderLinkCover.set(INSTANCE); - } - - @Override - @SideOnly(Side.CLIENT) - public void registerIcons(IIconRegister iconRegister) { - itemIcon = iconRegister.registerIcon(getIconString()); - //ultItemIcon = iconRegister.registerIcon(MODID + ":itemTeslaCoverUltimate"); - } - - @Override - public IIcon getIconFromDamage(int damage) { - //if (damage == 1) { - // return ultItemIcon; - //} - return itemIcon; - } - - @Override - public void getSubItems(Item aItem, CreativeTabs par2CreativeTabs, List aList) { - aList.add(new ItemStack(aItem, 1, 0)); - //aList.add(new ItemStack(aItem, 1, 1)); - } -} diff --git a/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png index 49ba0d2db9..010bc0888d 100644 Binary files a/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png and b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png differ diff --git a/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png.mcmeta new file mode 100644 index 0000000000..5e86a7cd5f --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/iconsets/ENDERFLUIDLINK_OVERLAY.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation":{ + "frametime":8 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/tectech/lang/en_US.lang b/src/main/resources/assets/tectech/lang/en_US.lang index b81b865b22..9f49d692b8 100644 --- a/src/main/resources/assets/tectech/lang/en_US.lang +++ b/src/main/resources/assets/tectech/lang/en_US.lang @@ -87,6 +87,11 @@ item.tm.teslaCover.desc.4=Who the hell uses cables anyway? item.tm.teslaStaff.name=Tesla Staff item.tm.teslaStaff.desc=Power of the gods, at the whim of a mortal! +item.tm.enderfluidlinkcover.name=Ender Fluid Link Cover +item.tm.enderfluidlinkcover.desc.0=Ender-Fluid-Enables Machines! +item.tm.enderfluidlinkcover.desc.1=Use on any side of a fluid tank to link it to the Ender +item.tm.enderfluidlinkcover.desc.2=Ender Tanks so are laggy -Bot from the Chads of NH + #Death Messages death.attack.microwaving=%1$s was dehydrated by radiation. death.attack.microwaving.player=%1$s was dehydrated by radiation while fighting %2$s. diff --git a/src/main/resources/assets/tectech/textures/items/itemEnderFluidLinkCover.png b/src/main/resources/assets/tectech/textures/items/itemEnderFluidLinkCover.png new file mode 100644 index 0000000000..201f7e4090 Binary files /dev/null and b/src/main/resources/assets/tectech/textures/items/itemEnderFluidLinkCover.png differ diff --git a/src/main/resources/assets/tectech/textures/items/itemEnderLinkCover.png b/src/main/resources/assets/tectech/textures/items/itemEnderLinkCover.png deleted file mode 100644 index e57d83adff..0000000000 Binary files a/src/main/resources/assets/tectech/textures/items/itemEnderLinkCover.png and /dev/null differ -- cgit From f71194d635e5ebf7d82ab4d402be58e6de60638d Mon Sep 17 00:00:00 2001 From: basdxz Date: Sat, 19 Dec 2020 11:48:49 +0000 Subject: Ender Fluid Covers Recipe -GTNH Recipe --- .../tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java b/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java index 0cfd8242ce..2609a81860 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java +++ b/src/main/java/com/github/technus/tectech/compatibility/dreamcraft/DreamCraftRecipeLoader.java @@ -1686,7 +1686,13 @@ public class DreamCraftRecipeLoader implements Runnable { GT_OreDictUnificator.get(OrePrefixes.plate, Materials.NickelZincFerrite, 2), GT_OreDictUnificator.get(OrePrefixes.foil, Materials.Aluminium, 8), }, Materials.SolderingAlloy.getMolten(72), CustomItemList.teslaCover.getWithDamage(1, 1), 320, 7680); - + //Ender Fluid Link Cover + GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ + GT_OreDictUnificator.get(OrePrefixes.plateDense, Materials.Enderium, 4), + ItemList.Sensor_LuV.get(1), + ItemList.Emitter_LuV.get(1), + ItemList.Electric_Pump_LuV.get(1), + }, Materials.Chrome.getMolten(288), CustomItemList.enderLinkFluidCover.getWithDamage(1, 0), 320, 30720); //endregion //region recycling -- cgit From a5a0df0e6eee81011eb5c359724d9001c7ca1d11 Mon Sep 17 00:00:00 2001 From: basdxz Date: Mon, 21 Dec 2020 00:55:26 +0000 Subject: Fixes Tesla Server-Side -Added Client-Side annotation to the relevant methods -Updated GT5u --- build.properties | 4 ++-- .../com/github/technus/tectech/mechanics/spark/RendererMessage.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/build.properties b/build.properties index 578a6b6e77..b376d96a59 100644 --- a/build.properties +++ b/build.properties @@ -6,8 +6,8 @@ ic2.version=2.2.790-experimental codechickenlib.version=1.1.3.140 codechickencore.version=1.0.7.47 nei.version=1.0.5.120 -gregtech.jenkinsbuild=778 -gregtech.version=5.09.33.57 +gregtech.jenkinsbuild=813 +gregtech.version=5.09.34.01 #cofhcore.version=[1.7.10]3.1.4-329-dev cofh_core_version=2388751 yamcore.version=0.5.79 diff --git a/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java b/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java index 4004a8d826..58356774cc 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java +++ b/src/main/java/com/github/technus/tectech/mechanics/spark/RendererMessage.java @@ -3,6 +3,8 @@ package com.github.technus.tectech.mechanics.spark; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import eu.usrv.yamcore.network.client.AbstractClientMessageHandler; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; @@ -16,7 +18,7 @@ import java.util.Arrays; import java.util.HashSet; public class RendererMessage implements IMessage { - HashSet sparkList = new HashSet(); + HashSet sparkList; public RendererMessage() { } @@ -69,6 +71,7 @@ public class RendererMessage implements IMessage { } } + @SideOnly(Side.CLIENT) private static void thaumLightning(int tX, int tY, int tZ, int tXN, int tYN, int tZN, int wID) { //This is enough to check for thaum, since it only ever matters for client side effects (Tested not to crash) if (Loader.isModLoaded("Thaumcraft")) { -- cgit