diff options
author | basdxz <tudurap.com@gmail.com> | 2020-07-19 08:26:15 +0100 |
---|---|---|
committer | basdxz <tudurap.com@gmail.com> | 2020-07-19 08:26:45 +0100 |
commit | 05b7f7d4111926d1eef68c7643c09f0cac5e09c5 (patch) | |
tree | 3a0f5af080b4b5425d569f89fd7ac27f84d7ab40 | |
parent | f2cbb5c88aff3b3f0f3908601328c53ee652f9dd (diff) | |
download | GT5-Unofficial-05b7f7d4111926d1eef68c7643c09f0cac5e09c5.tar.gz GT5-Unofficial-05b7f7d4111926d1eef68c7643c09f0cac5e09c5.tar.bz2 GT5-Unofficial-05b7f7d4111926d1eef68c7643c09f0cac5e09c5.zip |
Implement Tesla Global List
And then when I do it with lists the way Bart suggested it, I have Tec tell me to rewrite everything using interfaces
4 files changed, 145 insertions, 225 deletions
diff --git a/src/main/java/com/github/technus/tectech/loader/TecTechConfig.java b/src/main/java/com/github/technus/tectech/loader/TecTechConfig.java index 030be65f3b..ae9da94b02 100644 --- a/src/main/java/com/github/technus/tectech/loader/TecTechConfig.java +++ b/src/main/java/com/github/technus/tectech/loader/TecTechConfig.java @@ -28,7 +28,6 @@ public class TecTechConfig extends ConfigManager { public int TESLA_MULTI_LOSS_PER_BLOCK_T1; public int TESLA_MULTI_LOSS_PER_BLOCK_T2; public float TESLA_MULTI_OVERDRIVE_LOSS_FACTOR; - public int TESLA_MULTI_SCAN_RANGE;//TODO delete public boolean TESLA_MULTI_GAS_OUTPUT; public int TESLA_SINGLE_LOSS_PER_BLOCK; public float TESLA_SINGLE_OVERDRIVE_LOSS_FACTOR; @@ -54,7 +53,6 @@ public class TecTechConfig extends ConfigManager { TESLA_MULTI_LOSS_PER_BLOCK_T1 = 1; TESLA_MULTI_LOSS_PER_BLOCK_T2 = 1; TESLA_MULTI_OVERDRIVE_LOSS_FACTOR = 0.25F; - TESLA_MULTI_SCAN_RANGE = 40; TESLA_MULTI_GAS_OUTPUT = false; TESLA_SINGLE_LOSS_PER_BLOCK = 1; TESLA_SINGLE_OVERDRIVE_LOSS_FACTOR = 0.25F; @@ -93,7 +91,6 @@ public class TecTechConfig extends ConfigManager { TESLA_MULTI_LOSS_PER_BLOCK_T1 = _mainConfig.getInt("TeslaMultiLossPerBlockT1", "Balance Tweaks", TESLA_MULTI_LOSS_PER_BLOCK_T1, 0, Integer.MAX_VALUE, "Tesla Tower power transmission loss per block per amp using helium or nitrogen plasma"); TESLA_MULTI_LOSS_PER_BLOCK_T2 = _mainConfig.getInt("TeslaMultiLossPerBlockT1", "Balance Tweaks", TESLA_MULTI_LOSS_PER_BLOCK_T2, 0, Integer.MAX_VALUE, "Tesla Tower power transmission loss per block per amp using radon plasma"); TESLA_MULTI_OVERDRIVE_LOSS_FACTOR = _mainConfig.getFloat("TeslaMultiOverdriveLossFactor", "Balance Tweaks", TESLA_MULTI_OVERDRIVE_LOSS_FACTOR, 0, 1, "Additional Tesla Tower power loss per amp as a factor of the tier voltage"); - TESLA_MULTI_SCAN_RANGE = _mainConfig.getInt("TeslaMultiScanRange", "Balance Tweaks", TESLA_MULTI_SCAN_RANGE, 4, 256, "The horizontal radius scanned by the Tesla Tower"); TESLA_MULTI_GAS_OUTPUT = _mainConfig.getBoolean("TeslaMultiMoltenOutput", "Balance Tweaks", TESLA_MULTI_GAS_OUTPUT, "Set to true to enable outputting plasmas as gasses from the tesla tower with a 1:1 ratio"); TESLA_SINGLE_LOSS_PER_BLOCK = _mainConfig.getInt("TeslaSingleLossPerBlock", "Balance Tweaks", TESLA_SINGLE_LOSS_PER_BLOCK, 0, Integer.MAX_VALUE, "Tesla Transceiver power transmission loss per block per amp"); TESLA_SINGLE_OVERDRIVE_LOSS_FACTOR = _mainConfig.getFloat("TeslaSingleOverdriveLossFactor", "Balance Tweaks", TESLA_SINGLE_OVERDRIVE_LOSS_FACTOR, 0, 1, "Additional Tesla Transceiver power loss per amp as a factor of the tier voltage"); 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 8be875ff4f..6442ba51b6 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,7 +1,6 @@ package com.github.technus.tectech.thing.cover; 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; 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 7d12302477..eca70ca63f 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 @@ -48,8 +48,7 @@ import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStat import static com.github.technus.tectech.util.CommonValues.V; import static com.github.technus.tectech.util.Util.entriesSortedByValues; import static gregtech.api.enums.GT_Values.E; -import static java.lang.Math.max; -import static java.lang.Math.min; +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 { @@ -61,7 +60,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private static final int[] plasmaTierLoss = new int[]{TecTech.configTecTech.TESLA_MULTI_LOSS_PER_BLOCK_T0, TecTech.configTecTech.TESLA_MULTI_LOSS_PER_BLOCK_T1, TecTech.configTecTech.TESLA_MULTI_LOSS_PER_BLOCK_T2}; private static final float overDriveLoss = TecTech.configTecTech.TESLA_MULTI_OVERDRIVE_LOSS_FACTOR;//Default is 0.25F; - private static final int scanRangeXZ = TecTech.configTecTech.TESLA_MULTI_SCAN_RANGE;//Default is 40 private static final boolean doFluidOutput = TecTech.configTecTech.TESLA_MULTI_GAS_OUTPUT; //Default is false //Face icons @@ -73,12 +71,12 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private FluidStack[] mOutputFluidsQueue; //Used to buffer the fluid outputs, so the tesla takes a second to 'cool' any plasma it would output as a gas - public static final HashSet<IGregTechTileEntity> teslaNodeSet = new HashSet<>(); //Targets for power transmission //TODO Make this fill more efficently and globally + public static final HashSet<IGregTechTileEntity> teslaNodeSet = new HashSet<>(); //Targets for power transmission private final HashSet<ThaumSpark> sparkList = new HashSet<>(); //Thaumcraft lighting coordinate pairs, so we can send them in bursts and save on lag - private final Map<IGregTechTileEntity, Integer> eTeslaMap = new HashMap<>(); //Targets for power transmission + private Map<IGregTechTileEntity, Integer> teslaNodeMap = new HashMap<>(); //Targets for power transmission private final ArrayList<GT_MetaTileEntity_Hatch_Capacitor> eCapacitorHatches = new ArrayList<>(); //Capacitor hatches which determine the max voltage tier and count of amps - private int scanTime = 0; //Scan timer used for tesla search intervals //TODO Replace with something that fetches from a global map + 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 @@ -88,11 +86,8 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock //Prevents unnecessary offset calculation, saving on lag private byte oldRotation = -1; private byte oldOrientation = -1; - - //Coordinate Arrays - private final Vec3Impl[] scanPosOffsets = new Vec3Impl[10]; - private Vec3Impl posZap = Vec3Impl.NULL_VECTOR;//Location of the bottom middle of the tower, used as the power transfer origin - public Vec3Impl posTop = Vec3Impl.NULL_VECTOR;//Location of the center of the sphere on top of the tower, used as theThaumcraft lightning origin + //Location of the center of the sphere on top of the tower, used as the Thaumcraft lightning and origin + public Vec3Impl posTop = Vec3Impl.NULL_VECTOR; //endregion //region structure @@ -128,8 +123,8 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock //endregion //region parameters - protected Parameters.Group.ParameterIn popogaSetting, histLowSetting, histHighSetting, transferRadiusTowerSetting, transferRadiusTransceiverSetting, transferRadiusCoverUltimateSetting, outputVoltageSetting, outputCurrentSetting, scanTimeMinSetting, overDriveSetting; - protected Parameters.Group.ParameterOut popogaDisplay, transferRadiusTowerDisplay, transferRadiusTransceiverDisplay, transferRadiusCoverUltimateDisplay, outputVoltageDisplay, outputCurrentDisplay, energyCapacityDisplay, energyStoredDisplay, energyFractionDisplay, scanTimeDisplay; + protected Parameters.Group.ParameterIn popogaSetting, histLowSetting, histHighSetting, transferRadiusTowerSetting, transferRadiusTransceiverSetting, transferRadiusCoverUltimateSetting, outputVoltageSetting, outputCurrentSetting, sortTimeMinSetting, overDriveSetting; + protected Parameters.Group.ParameterOut popogaDisplay, transferRadiusTowerDisplay, transferRadiusTransceiverDisplay, transferRadiusCoverUltimateDisplay, outputVoltageDisplay, outputCurrentDisplay, energyCapacityDisplay, energyStoredDisplay, energyFractionDisplay, sortTimeDisplay; private static final INameFunction<GT_MetaTileEntity_TM_teslaCoil> HYSTERESIS_LOW_SETTING_NAME = (base, p) -> translateToLocal("gt.blockmachines.multimachine.tm.teslaCoil.cfgi.0");//Hysteresis low setting private static final INameFunction<GT_MetaTileEntity_TM_teslaCoil> HYSTERESIS_HIGH_SETTING_NAME = (base, p) -> translateToLocal("gt.blockmachines.multimachine.tm.teslaCoil.cfgi.1");//Hysteresis high setting @@ -294,37 +289,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock return 1F * plasmaBoost; } - private void scanForTransmissionTargets(Vec3Impl coordsMin, Vec3Impl coordsMax) { - //This makes sure the minimums are actually smaller than the maximums - int xMin = min(coordsMin.get0(), coordsMax.get0()); - int yMin = min(coordsMin.get1(), coordsMax.get1()); - int zMin = min(coordsMin.get2(), coordsMax.get2()); - //And vice versa - int xMax = max(coordsMin.get0(), coordsMax.get0()); - int yMax = max(coordsMin.get1(), coordsMax.get1()); - int zMax = max(coordsMin.get2(), coordsMax.get2()); - - for (int xPos = xMin; xPos <= xMax; xPos++) { - for (int yPos = yMin; yPos <= yMax; yPos++) { - for (int zPos = zMin; zPos <= zMax; zPos++) { - if (xPos == 0 && yPos == 0 && zPos == 0) { - continue; - } - IGregTechTileEntity node = getBaseMetaTileEntity().getIGregTechTileEntityOffset(xPos, yPos, zPos); - if (node != null) { - IMetaTileEntity nodeInside = node.getMetaTileEntity(); - if (nodeInside instanceof GT_MetaTileEntity_TeslaCoil || - nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil && node.isActive() || - (node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil)) { - eTeslaMap.put(node, (int) Math.ceil(Math.sqrt(Math.pow(xPos, 2) + Math.pow(yPos, 2) + Math.pow(zPos, 2)))); - } - } - } - } - } - - } - private void thaumLightning(IGregTechTileEntity mte, IGregTechTileEntity node) { byte xR = (byte) (node.getXCoord() - posTop.get0()); byte yR = (byte) (node.getYCoord() - posTop.get1()); @@ -405,26 +369,10 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock oldOrientation = iGregTechTileEntity.getFrontFacing(); //Calculate coordinates of the middle bottom - posZap = getExtendedFacing().getWorldOffset(new Vec3Impl(0, 0, 2)).add(getBaseMetaTileEntity()); + posTop = getExtendedFacing().getWorldOffset(new Vec3Impl(0, 0, 2)).add(getBaseMetaTileEntity()); //Calculate coordinates of the top sphere posTop = getExtendedFacing().getWorldOffset(new Vec3Impl(0, -14, 2)).add(getBaseMetaTileEntity()); - - //Calculate offsets for scanning - scanPosOffsets[0] = getExtendedFacing().getWorldOffset(new Vec3Impl(scanRangeXZ, 0, scanRangeXZ + 3)); - scanPosOffsets[1] = getExtendedFacing().getWorldOffset(new Vec3Impl(-1 * scanRangeXZ, -4, -1 * scanRangeXZ + 3)); - - scanPosOffsets[2] = getExtendedFacing().getWorldOffset(new Vec3Impl(scanRangeXZ, -5, scanRangeXZ + 3)); - scanPosOffsets[3] = getExtendedFacing().getWorldOffset(new Vec3Impl(-1 * scanRangeXZ, -8, -1 * scanRangeXZ + 3)); - - scanPosOffsets[4] = getExtendedFacing().getWorldOffset(new Vec3Impl(scanRangeXZ, -9, scanRangeXZ + 3)); - scanPosOffsets[5] = getExtendedFacing().getWorldOffset(new Vec3Impl(-1 * scanRangeXZ, -12, -1 * scanRangeXZ + 3)); - - scanPosOffsets[6] = getExtendedFacing().getWorldOffset(new Vec3Impl(scanRangeXZ, -13, scanRangeXZ + 3)); - scanPosOffsets[7] = getExtendedFacing().getWorldOffset(new Vec3Impl(-1 * scanRangeXZ, -16, -1 * scanRangeXZ + 3)); - - scanPosOffsets[8] = getExtendedFacing().getWorldOffset(new Vec3Impl(scanRangeXZ, -17, scanRangeXZ + 3)); - scanPosOffsets[9] = getExtendedFacing().getWorldOffset(new Vec3Impl(-1 * scanRangeXZ, -20, -1 * scanRangeXZ + 3)); } return true; } @@ -442,7 +390,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock !transferRadiusCoverUltimateSetting.getStatus(false).isOk || !outputVoltageSetting.getStatus(false).isOk || !outputCurrentSetting.getStatus(false).isOk || - !scanTimeMinSetting.getStatus(false).isOk || + !sortTimeMinSetting.getStatus(false).isOk || !overDriveSetting.getStatus(false).isOk ) return false; @@ -558,7 +506,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock popogaSetting = hatch_5.makeInParameter(1, 0, POPOGA_NAME, POPOGA_STATUS); popogaSetting = hatch_6.makeInParameter(0, 0, POPOGA_NAME, POPOGA_STATUS); popogaSetting = hatch_6.makeInParameter(1, 0, POPOGA_NAME, POPOGA_STATUS); - scanTimeMinSetting = hatch_7.makeInParameter(0, 100, SCAN_TIME_MIN_SETTING_NAME, SCAN_TIME_MIN_STATUS); + sortTimeMinSetting = hatch_7.makeInParameter(0, 100, SCAN_TIME_MIN_SETTING_NAME, SCAN_TIME_MIN_STATUS); popogaSetting = hatch_7.makeInParameter(1, 0, POPOGA_NAME, POPOGA_STATUS); overDriveSetting = hatch_8.makeInParameter(0, 0, OVERDRIVE_SETTING_NAME, OVERDRIVE_STATUS); popogaSetting = hatch_8.makeInParameter(1, 0, POPOGA_NAME, POPOGA_STATUS); @@ -579,7 +527,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock energyCapacityDisplay = hatch_5.makeOutParameter(1, 0, ENERGY_CAPACITY_DISPLAY_NAME, ENERGY_STATUS); energyStoredDisplay = hatch_6.makeOutParameter(0, 0, ENERGY_STORED_DISPLAY_NAME, ENERGY_STATUS); energyFractionDisplay = hatch_6.makeOutParameter(1, 0, ENERGY_FRACTION_DISPLAY_NAME, ENERGY_STATUS); - scanTimeDisplay = hatch_7.makeOutParameter(0, 0, SCAN_TIME_DISPLAY_NAME, SCAN_TIME_STATUS); + sortTimeDisplay = hatch_7.makeOutParameter(0, 0, SCAN_TIME_DISPLAY_NAME, SCAN_TIME_STATUS); popogaDisplay = hatch_7.makeOutParameter(1, 0, POPOGA_NAME, POPOGA_STATUS); popogaDisplay = hatch_8.makeOutParameter(0, 0, POPOGA_NAME, POPOGA_STATUS); popogaDisplay = hatch_8.makeOutParameter(1, 0, POPOGA_NAME, POPOGA_STATUS); @@ -621,120 +569,135 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock } } - @Override - public boolean onRunningTick(ItemStack aStack) { - IGregTechTileEntity mte = getBaseMetaTileEntity(); - //Hysteresis based ePowerPass setting - long energyStored = getEUVar(); - float energyFrac = (float) energyStored / energyCapacity; + public static Map<IGregTechTileEntity, Integer> generateTeslaNodeMap(IGregTechTileEntity orgin){ + Map<IGregTechTileEntity, Integer> generatedNodeMap = new HashMap<>(); + IMetaTileEntity orginInside = orgin.getMetaTileEntity(); + int orginX; + int orginY; + int orginZ; + if (orginInside instanceof GT_MetaTileEntity_TM_teslaCoil) { + GT_MetaTileEntity_TM_teslaCoil teslaTower = (GT_MetaTileEntity_TM_teslaCoil) orginInside; + orginX = teslaTower.posTop.get0(); + orginY = teslaTower.posTop.get1(); + orginZ = teslaTower.posTop.get2(); + } else { + orginX = orgin.getXCoord(); + orginY = orgin.getYCoord(); + orginZ = orgin.getZCoord(); + } - energyCapacityDisplay.set(energyCapacity); - energyStoredDisplay.set(energyStored); - energyFractionDisplay.set(energyFrac); + for (IGregTechTileEntity node : teslaNodeSet) { + if (node == null) { + //Technically, the Tesla Covers do not remove themselves from the list and this is the code that does + teslaNodeSet.remove(null); + continue; + } else if (node == orgin || orgin.getWorld().provider.dimensionId != node.getWorld().provider.dimensionId) { + //Skip if looking at myself and skip if not in the same dimention + //TODO, INTERDIM? + continue; + } - if (!ePowerPass && energyFrac > histHighSetting.get()) { - ePowerPass = true; - } else if (ePowerPass && energyFrac < histLowSetting.get()) { - ePowerPass = false; + //Makes the target coordinates the center of the sphere of the tower if it has one + IMetaTileEntity nodeInside = node.getMetaTileEntity(); + int targetX; + int targetY; + int targetZ; + if (nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil) { + GT_MetaTileEntity_TM_teslaCoil teslaTower = (GT_MetaTileEntity_TM_teslaCoil) nodeInside; + targetX = teslaTower.posTop.get0(); + targetY = teslaTower.posTop.get1(); + targetZ = teslaTower.posTop.get2(); + } else { + targetX = node.getXCoord(); + targetY = node.getYCoord(); + targetZ = node.getZCoord(); + } + + //Find the xyz offsets and calculate the distance between us and the target + int xPosOffset = targetX - orginX; + int yPosOffset = targetY - orginY; + int zPosOffset = targetZ - orginZ; + int distance = (int) ceil(sqrt(pow(xPosOffset, 2) + pow(yPosOffset, 2) + pow(zPosOffset, 2))); + //Thought we need abs here, we don't. An Integer to the power of two is going to be either 0 or positive. + //We also can just put stuff here without further checks, as we always check the next section + generatedNodeMap.put(node, distance); } + return generatedNodeMap; + } + + public static Map<IGregTechTileEntity, Integer> cleanTeslaNodeMap(Map<IGregTechTileEntity, Integer> nodeMap, IGregTechTileEntity orgin) { + IMetaTileEntity orginInside = orgin.getMetaTileEntity(); + //Assumes that if the orgin is not a Tesla Tower, it mus be a single block. + boolean isMulti = orginInside instanceof GT_MetaTileEntity_TM_teslaCoil; - //Clean the eTeslaMap - for (Map.Entry<IGregTechTileEntity, Integer> Rx : eTeslaMap.entrySet()) { + for (Map.Entry<IGregTechTileEntity, Integer> Rx : nodeMap.entrySet()) { + //All the checks need to pass or the target gets removed from the transmission list IGregTechTileEntity node = Rx.getKey(); + //Null check if (node != null) { IMetaTileEntity nodeInside = node.getMetaTileEntity(); + //We need this in a try catch, just as a precaution that a chunk had unloaded or a machine was removed try { + //Is it an Active Tesla Tower with at least some energy capacity? + //Singles and Multis can send power here, so we don't check if (nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil && node.isActive()) { GT_MetaTileEntity_TM_teslaCoil teslaTower = (GT_MetaTileEntity_TM_teslaCoil) nodeInside; if (teslaTower.maxEUStore() > 0) { continue; } - } else if (nodeInside instanceof GT_MetaTileEntity_TeslaCoil) { + //Is it a Tesla Transceiver with at least one battery? + //Only multis can send power to singles + } else if (isMulti && nodeInside instanceof GT_MetaTileEntity_TeslaCoil) { GT_MetaTileEntity_TeslaCoil teslaTransceiver = (GT_MetaTileEntity_TeslaCoil) nodeInside; if (teslaTransceiver.mBatteryCount > 0) { continue; } - } else if ((node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil) && node.getEUCapacity() > 0) { + //Is it a tile entity with a Tesla Coil Cover? + //Only single can send power to non-Rich edition covers + //Since Rich edition inherits from regular, we need the final check + } else if (!isMulti && node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil && + node.getEUCapacity() > 0 && !(node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil_Ultimate)) { + continue; + //Is it a tile entity with a Tesla Coil Cover Rich edition? + //Only multis can send power to Rich edition covers + } else if (isMulti && node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil_Ultimate && node.getEUCapacity() > 0) { continue; } - } catch (Exception e) { + } catch (Exception ignored) { } } - eTeslaMap.remove(Rx.getKey()); + nodeMap.remove(Rx.getKey()); } + return nodeMap; + } - //Scan for transmission targets - switch (scanTime) { - case 0: - scanTimeDisplay.updateStatus(); - scanForTransmissionTargets(scanPosOffsets[0], scanPosOffsets[1]); - break; - case 20: - scanTimeDisplay.updateStatus(); - scanForTransmissionTargets(scanPosOffsets[2], scanPosOffsets[3]); - break; - case 40: - scanTimeDisplay.updateStatus(); - scanForTransmissionTargets(scanPosOffsets[4], scanPosOffsets[5]); - break; - case 60: - scanTimeDisplay.updateStatus(); - scanForTransmissionTargets(scanPosOffsets[6], scanPosOffsets[7]); - break; - case 80: - scanTimeDisplay.updateStatus(); - scanForTransmissionTargets(scanPosOffsets[8], scanPosOffsets[9]); - break; - default: - if (scanTime == (int) scanTimeMinSetting.get() - 1) { - scanTime = -1; - for (Map.Entry<IGregTechTileEntity, Integer> Rx : eTeslaMap.entrySet()) { - IGregTechTileEntity node = Rx.getKey(); - if (node != null) { - IMetaTileEntity nodeInside = node.getMetaTileEntity(); - try { - if (nodeInside instanceof GT_MetaTileEntity_TeslaCoil) { - GT_MetaTileEntity_TeslaCoil teslaCoil = (GT_MetaTileEntity_TeslaCoil) nodeInside; - - int tX = node.getXCoord(); - int tY = node.getYCoord(); - int tZ = node.getZCoord(); - - int tXN = posZap.get0(); - int tYN = posZap.get1(); - int tZN = posZap.get2(); - - int tOffset = (int) Math.ceil(Math.sqrt(Math.pow(tX - tXN, 2) + Math.pow(tY - tYN, 2) + Math.pow(tZ - tZN, 2))); - teslaCoil.eTeslaMap.put(mte, tOffset); - - for (Map.Entry<IGregTechTileEntity, Integer> RRx : eTeslaMap.entrySet()) { - IGregTechTileEntity nodeN = RRx.getKey(); - if (nodeN == node) { - continue; - } - tXN = nodeN.getXCoord(); - tYN = nodeN.getYCoord(); - tZN = nodeN.getZCoord(); - tOffset = (int) Math.ceil(Math.sqrt(Math.pow(tX - tXN, 2) + Math.pow(tY - tYN, 2) + Math.pow(tZ - tZN, 2))); - if (tOffset > 20) { - continue; - } - teslaCoil.eTeslaMap.put(nodeN, tOffset); - } - } - } catch (Exception e) { - eTeslaMap.remove(Rx.getKey()); - } - } - } - } - break; + @Override + public boolean onRunningTick(ItemStack aStack) { + IGregTechTileEntity mte = getBaseMetaTileEntity(); + + //Hysteresis based ePowerPass setting + float energyFrac = (float) getEUVar() / energyCapacity; + + energyCapacityDisplay.set(energyCapacity); + energyStoredDisplay.set(getEUVar()); + energyFractionDisplay.set(energyFrac); + + if (!ePowerPass && energyFrac > histHighSetting.get()) { + ePowerPass = true; + } else if (ePowerPass && energyFrac < histLowSetting.get()) { + ePowerPass = false; } - scanTime++; - scanTimeDisplay.set(scanTime); + //Create the teslaNodeMap + if (sortTime == sortTimeMinSetting.get()) { + sortTime = 0; + sortTimeDisplay.updateStatus(); + teslaNodeMap = generateTeslaNodeMap(mte); + } + sortTime++; + sortTimeDisplay.set(sortTime); //Power Limit Settings long outputVoltage; @@ -756,46 +719,23 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock //Stuff to do if ePowerPass if (ePowerPass) { //Range calculation and display - float rangeFrac = (float) ((-0.5 * Math.pow(energyFrac, 2)) + (1.5 * energyFrac)); - int transferRadiusTower = (int) (transferRadiusTowerSetting.get() * getRangeMulti(mTier, vTier) * rangeFrac); + int transferRadiusTower = (int) (transferRadiusTowerSetting.get() * getRangeMulti(mTier, vTier)); transferRadiusTowerDisplay.set(transferRadiusTower); - int transferRadiusTransceiver = (int) (transferRadiusTransceiverSetting.get() * getRangeMulti(mTier, vTier) * rangeFrac); + int transferRadiusTransceiver = (int) (transferRadiusTransceiverSetting.get() * getRangeMulti(mTier, vTier)); transferRadiusTransceiverDisplay.set(transferRadiusTransceiver); - int transferRadiusCoverUltimate = (int) (transferRadiusCoverUltimateSetting.get() * getRangeMulti(mTier, vTier) * rangeFrac); + int transferRadiusCoverUltimate = (int) (transferRadiusCoverUltimateSetting.get() * getRangeMulti(mTier, vTier)); transferRadiusCoverUltimateDisplay.set(transferRadiusCoverUltimate); - //Clean the eTeslaMap - for (Map.Entry<IGregTechTileEntity, Integer> Rx : eTeslaMap.entrySet()) { - IGregTechTileEntity node = Rx.getKey(); - if (node != null) { - IMetaTileEntity nodeInside = node.getMetaTileEntity(); - try { - if (nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil && node.isActive()) { - GT_MetaTileEntity_TM_teslaCoil teslaTower = (GT_MetaTileEntity_TM_teslaCoil) nodeInside; - if (teslaTower.maxEUStore() > 0) { - continue; - } - } else if (nodeInside instanceof GT_MetaTileEntity_TeslaCoil) { - GT_MetaTileEntity_TeslaCoil teslaCoil = (GT_MetaTileEntity_TeslaCoil) nodeInside; - if (teslaCoil.getStoredEnergy()[1] > 0) { - continue; - } - } else if ((node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil) && node.getEUCapacity() > 0) { - continue; - } - } catch (Exception e) { - } - } - eTeslaMap.remove(Rx.getKey()); - } + //Clean the teslaNodeMap + teslaNodeMap = cleanTeslaNodeMap(teslaNodeMap, mte); //Power transfer long sparks = outputCurrent; while (sparks > 0) { boolean overdriveToggle = overDriveSetting.get() > 0; boolean idle = true; - for (Map.Entry<IGregTechTileEntity, Integer> Rx : entriesSortedByValues(eTeslaMap)) { - if (energyStored >= (overdriveToggle ? outputVoltage * 2 : outputVoltage)) { + for (Map.Entry<IGregTechTileEntity, Integer> Rx : entriesSortedByValues(teslaNodeMap)) { + if (getEUVar() >= (overdriveToggle ? outputVoltage * 2 : outputVoltage)) { IGregTechTileEntity node = Rx.getKey(); IMetaTileEntity nodeInside = node.getMetaTileEntity(); @@ -845,12 +785,12 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock } } outputCurrentDisplay.set(outputCurrent - sparks); - if (scanTime % 60 == 0 && !sparkList.isEmpty()) { + if (sortTime % 60 == 0 && !sparkList.isEmpty()) { NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), mte.getWorld().provider.dimensionId, - mte.getXCoord(), - mte.getYCoord(), - mte.getZCoord(), + posTop.get0(), + posTop.get1(), + posTop.get2(), 256); } sparkList.clear(); 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 47625b999f..657bf6b01a 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 @@ -27,32 +27,25 @@ import java.util.HashMap; import java.util.HashSet;
import java.util.Map;
-import static com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_TM_teslaCoil.teslaNodeSet;
+import static com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_TM_teslaCoil.*;
import static com.github.technus.tectech.util.CommonValues.V;
import static com.github.technus.tectech.util.Util.entriesSortedByValues;
-import static com.github.technus.tectech.util.Util.map;
import static com.github.technus.tectech.thing.metaTileEntity.Textures.*;
import static java.lang.Math.round;
import static net.minecraft.util.StatCollector.translateToLocal;
import static net.minecraft.util.StatCollector.translateToLocalFormatted;
-
public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer {
private final static int perBlockLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_PER_BLOCK;//Default is 1
private final static float overDriveLoss = TecTech.configTecTech.TESLA_SINGLE_OVERDRIVE_LOSS_FACTOR;//Default is 0.25F
- public Map<IGregTechTileEntity, Integer> eTeslaMap = new HashMap<>();//Tesla Map to map them tesla bois!
+ private Map<IGregTechTileEntity, Integer> teslaNodeMap = new HashMap<>();//Tesla Map to map them tesla bois!
private final static HashSet<ThaumSpark> sparkList = new HashSet<>();
private byte sparkCount = 0;
- private final static int maxTier = 4; //Max tier of transceiver
- private final static int minTier = 0; //Min tier of transceiver
-
- private final static int transferRadiusMax = 20;
- private final static int transferRadiusMin = 4;
- private final int transferRadiusLimitTop = (int) map(mTier + 1, minTier + 1, maxTier + 1, transferRadiusMin, transferRadiusMax);
- private final static int transferRadiusLimitBottom = 1; //Minimum user configurable
- private int transferRadius = transferRadiusLimitTop; //Default transferRadius setting
+ private final static int transferRadiusMax = 20; //Maximum user configurable
+ private final static int transferRadiusMin = 4; //Minimum user configurable
+ private int transferRadius = 16; //Default transferRadius setting
public boolean powerPassToggle = false; //Power Pass for public viewing
private final static int histSteps = 20; //Hysteresis Resolution
@@ -68,6 +61,9 @@ 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);
@@ -125,11 +121,11 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB @Override
public boolean onWireCutterRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
if (aPlayer.isSneaking()) {
- if (transferRadius > transferRadiusLimitBottom) {
+ if (transferRadius > transferRadiusMin) {
transferRadius--;
}
} else {
- if (transferRadius < 0) {
+ if (transferRadius < transferRadiusMax) {
transferRadius++;
}
}
@@ -171,13 +167,11 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB @Override
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
ITexture[][][] rTextures = new ITexture[3][17][];
-
for (byte i = -1; i < 16; ++i) {
rTextures[0][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1]};
rTextures[1][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1], TESLA_TRANSCEIVER_TOP_BA};
rTextures[2][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1], this.mInventory.length == 16 ? OVERLAYS_ENERGY_OUT_POWER_TT[this.mTier] : (this.mInventory.length > 4 ? OVERLAYS_ENERGY_OUT_MULTI_TT[this.mTier] : OVERLAYS_ENERGY_OUT_TT[this.mTier])};
}
-
return rTextures;
}
@@ -273,6 +267,13 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB powerPassToggle = false;
}
+ //Create the teslaNodeMap
+ if (sortTime == sortTimeMax) {
+ sortTime = 0;
+ teslaNodeMap = generateTeslaNodeMap(aBaseMetaTileEntity);
+ }
+ sortTime++;
+
//Stuff to do if ePowerPass
if (powerPassToggle) {
float rangeFrac = (float) ((-0.5 * Math.pow(energyFrac, 2)) + (1.5 * energyFrac));
@@ -282,30 +283,13 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB //Radius for transceiver to cover transfers
int transferRadiusCover = (int) (transferRadiusTower / 1.25);
- //Clean the eTeslaMap
- for (Map.Entry<IGregTechTileEntity, Integer> Rx : eTeslaMap.entrySet()) {
- IGregTechTileEntity node = Rx.getKey();
- if (node != null) {
- IMetaTileEntity nodeInside = node.getMetaTileEntity();
- try {
- if (nodeInside instanceof GT_MetaTileEntity_TM_teslaCoil && node.isActive()) {
- GT_MetaTileEntity_TM_teslaCoil teslaTower = (GT_MetaTileEntity_TM_teslaCoil) nodeInside;
- if (teslaTower.maxEUStore() > 0) {
- continue;
- }
- } else if ((node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil) && node.getEUCapacity() > 0) {
- continue;
- }
- } catch (Exception e) {
- }
- }
- eTeslaMap.remove(Rx.getKey());
- }
+ //Clean the teslaNodeMap
+ teslaNodeMap = cleanTeslaNodeMap(teslaNodeMap, aBaseMetaTileEntity);
//Power transfer
while (outputCurrent > 0) {
boolean idle = true;
- for (Map.Entry<IGregTechTileEntity, Integer> Rx : entriesSortedByValues(eTeslaMap)) {
+ for (Map.Entry<IGregTechTileEntity, Integer> Rx : entriesSortedByValues(teslaNodeMap)) {
if (getEUVar() >= (overdriveToggle ? outputVoltage * 2 : outputVoltage)) {
IGregTechTileEntity node = Rx.getKey();
IMetaTileEntity nodeInside = node.getMetaTileEntity();
|