From 02dd0f15d37bd5183994bb97361c728e1171652e Mon Sep 17 00:00:00 2001 From: Bass Date: Fri, 16 Aug 2019 14:44:51 +0100 Subject: Tesla Effects --- .../java/com/github/technus/tectech/TecTech.java | 3 +- src/main/java/com/github/technus/tectech/Util.java | 50 ++++++++ .../technus/tectech/loader/NetworkDispatcher.java | 7 +- .../tectech/mechanics/data/RendererMessage.java | 95 +++++++++++++++ .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 134 +++++++++++++-------- .../single/GT_MetaTileEntity_TeslaCoil.java | 48 +++++++- 6 files changed, 282 insertions(+), 55 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/data/RendererMessage.java (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index f998a9017b..79defc0a1a 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -87,7 +87,7 @@ public class TecTech { FMLCommonHandler.instance().bus().register(playerPersistence); MinecraftForge.EVENT_BUS.register(playerPersistence); - chunkDataHandler=new ChunkDataHandler(); + chunkDataHandler=new ChunkDataHandler(); FMLCommonHandler.instance().bus().register(chunkDataHandler); MinecraftForge.EVENT_BUS.register(chunkDataHandler); @@ -197,7 +197,6 @@ public class TecTech { MainLoader.postLoad(); chunkDataHandler.registerChunkMetaDataHandler(anomalyHandler=new AnomalyHandler()); - } @Mod.EventHandler diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java index 3b1fdf0961..774e8a45c8 100644 --- a/src/main/java/com/github/technus/tectech/Util.java +++ b/src/main/java/com/github/technus/tectech/Util.java @@ -37,6 +37,7 @@ import org.apache.commons.lang3.StringUtils; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.Serializable; import java.lang.reflect.Field; import java.util.*; import java.util.regex.Matcher; @@ -146,6 +147,55 @@ public final class Util { return result.toString(); } + public static class thaumSpark implements Serializable { + private static final long serialVersionUID = 3235649915488422364L; + public int x, z, wID; + public byte y, xR, yR, zR; + + public thaumSpark(){ + this.x = 0; + this.z = 0; + this.y = 0; + + this.xR = 0; + this.yR = 0; + this.zR = 0; + + this.wID = 0; + } + + public thaumSpark(int x, byte y, int z, byte xR, byte yR, byte zR, int wID) { + this.x = x; + this.z = z; + this.y = y; + + this.xR = xR; + this.yR = yR; + this.zR = zR; + + this.wID = wID; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + thaumSpark that = (thaumSpark) o; + return x == that.x && + y == that.y && + z == that.z && + wID == that.wID && + xR == that.xR && + yR == that.yR && + zR == that.zR; + } + + @Override + public int hashCode() { + return Objects.hash(x, z, y, wID, xR, yR, zR); + } + } + //region junk /* //Check Machine Structure based on string[][] (effectively char[][][]), ond offset of the controller 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 0f20d31f4d..72d1a23b05 100644 --- a/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java +++ b/src/main/java/com/github/technus/tectech/loader/NetworkDispatcher.java @@ -1,9 +1,10 @@ package com.github.technus.tectech.loader; -import com.github.technus.tectech.thing.metaTileEntity.pipe.PipeActivityMessage; -import com.github.technus.tectech.thing.metaTileEntity.RotationMessage; import com.github.technus.tectech.mechanics.data.ChunkDataMessage; import com.github.technus.tectech.mechanics.data.PlayerDataMessage; +import com.github.technus.tectech.mechanics.data.RendererMessage; +import com.github.technus.tectech.thing.metaTileEntity.RotationMessage; +import com.github.technus.tectech.thing.metaTileEntity.pipe.PipeActivityMessage; import static com.github.technus.tectech.Reference.MODID; @@ -26,5 +27,7 @@ public class NetworkDispatcher extends eu.usrv.yamcore.network.PacketDispatcher registerMessage(ChunkDataMessage.ClientHandler.class, ChunkDataMessage.ChunkDataData.class); registerMessage(PlayerDataMessage.ServerHandler.class, PlayerDataMessage.PlayerDataQuery.class); registerMessage(PlayerDataMessage.ClientHandler.class, PlayerDataMessage.PlayerDataData.class); + registerMessage(RendererMessage.ServerHandler.class, RendererMessage.RendererQuery.class); + registerMessage(RendererMessage.ClientHandler.class, RendererMessage.RendererData.class); } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/data/RendererMessage.java b/src/main/java/com/github/technus/tectech/mechanics/data/RendererMessage.java new file mode 100644 index 0000000000..4bb6d9028d --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/data/RendererMessage.java @@ -0,0 +1,95 @@ +package com.github.technus.tectech.mechanics.data; + +import com.github.technus.tectech.Util; +import cpw.mods.fml.common.Loader; +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.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; +import thaumcraft.client.fx.bolt.FXLightningBolt; + +import java.io.*; +import java.util.HashSet; + +public class RendererMessage implements IMessage { + HashSet sparkList = new HashSet(); + + public RendererMessage(){} + + @Override + public void fromBytes(ByteBuf pBuffer) { + try { + InputStream is = new ByteArrayInputStream(pBuffer.array()); + ObjectInputStream ois = new ObjectInputStream(is); + Object data = ois.readObject(); + sparkList = (HashSet)data; + } catch (IOException | ClassNotFoundException ex) { + } + } + + @Override + public void toBytes(ByteBuf pBuffer) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(sparkList); + oos.flush(); + InputStream is = new ByteArrayInputStream(baos.toByteArray()); + pBuffer.writeBytes(is, baos.toByteArray().length); + } catch (IOException ex) { + } + } + + + public static class RendererQuery extends RendererMessage { + public RendererQuery() { + } + } + + public static class RendererData extends RendererMessage { + public RendererData() { + } + + public RendererData(RendererQuery query){ + sparkList=query.sparkList; + } + + public RendererData(HashSet eSparkList) { + sparkList=eSparkList; + } + } + + + public static class ClientHandler extends AbstractClientMessageHandler{ + @Override + public IMessage handleClientMessage(EntityPlayer pPlayer, RendererData pMessage, MessageContext pCtx) { + for(Util.thaumSpark sp : pMessage.sparkList){ + thaumLightning(sp.x, sp.y, sp.z, sp.xR, sp.yR, sp.zR, sp.wID); + } + pMessage.sparkList.clear(); + return null; + } + } + + public static class ServerHandler extends AbstractServerMessageHandler{ + @Override + public IMessage handleServerMessage(EntityPlayer pPlayer, RendererQuery pMessage, MessageContext pCtx) { + return new RendererData(pMessage); + } + } + + private static void thaumLightning(int tX, byte tY, int tZ, int tXN, byte tYN, int tZN, int wID){ + if(Loader.isModLoaded("Thaumcraft")){ + World world = DimensionManager.getWorld(wID); + FXLightningBolt bolt = new FXLightningBolt(world,tX+0.5F,tY+0.5F,tZ+0.5F,tX+tXN+0.5F,tY+tYN+0.5F,tZ+tZN+0.5F,world.rand.nextLong(), 6, 0.5F, 8); + bolt.defaultFractal(); + bolt.setType(2); + bolt.setWidth(0.125F); + bolt.finalizeBolt(); + } + } +} 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 78dd2f860c..f82a444fc6 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 @@ -1,6 +1,9 @@ package com.github.technus.tectech.thing.metaTileEntity.multi; import com.github.technus.tectech.CommonValues; +import com.github.technus.tectech.Util; +import com.github.technus.tectech.loader.NetworkDispatcher; +import com.github.technus.tectech.mechanics.data.RendererMessage; 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.metaTileEntity.IConstructable; @@ -20,14 +23,14 @@ import gregtech.api.metatileentity.implementations.*; import gregtech.api.objects.GT_RenderedTexture; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; -import thaumcraft.client.fx.bolt.FXLightningBolt; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import static com.github.technus.tectech.CommonValues.V; import static com.github.technus.tectech.Util.StructureBuilder; @@ -38,6 +41,8 @@ import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStat import static gregtech.api.enums.GT_Values.E; public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_MultiblockBase_EM implements IConstructable { + private final static HashSet sparkList = new HashSet(); + private static Textures.BlockIcons.CustomIcon ScreenOFF; private static Textures.BlockIcons.CustomIcon ScreenON; @@ -47,7 +52,6 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private Map eTeslaMap = new HashMap<>(); //Used to store targets for power transmission private final ArrayList eCapacitorHatches = new ArrayList<>(); //Used to determine count and tier of capacitors present - private float[][] eLightningTargets; private int scanTime = 0; //Scan timer used for tesla search intervals @@ -62,16 +66,16 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock private float overdriveEfficiency = 0.95F; //Overdrive efficiency added losses //Scan range fields - private double xPosScanMin; - private double xPosScanMax; - private double yPosScan0; - private double yPosScan1; - private double yPosScan2; - private double yPosScan3; - private double yPosScan4; - private double yPosScan5; - private double zPosScanMin; - private double zPosScanMax; + private int xPosScanMin; + private int xPosScanMax; + private int yPosScan0; + private int yPosScan1; + private int yPosScan2; + private int yPosScan3; + private int yPosScan4; + private int yPosScan5; + private int zPosScanMin; + private int zPosScanMax; //region structure private static final String[][] shape0 = new String[][]{//3 16 0 @@ -603,19 +607,29 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock } + private static void thaumLightning(IGregTechTileEntity mte, IGregTechTileEntity node) { + int x = mte.getXCoord(); + byte y = (byte) mte.getYCoord(); + int z = mte.getZCoord(); + + byte xR = (byte) (node.getXCoord() - x); + byte yR = (byte) (node.getYCoord() - y); + byte zR = (byte) (node.getZCoord() - z); + + int wID = mte.getWorld().provider.dimensionId; + + sparkList.add(new Util.thaumSpark(x,y,z,xR,yR,zR,wID)); + } + @Override public boolean onRunningTick(ItemStack aStack) { IGregTechTileEntity mte = getBaseMetaTileEntity(); - float tXN = mte.getXCoord(); - float tYN = mte.getYCoord(); - float tZN = mte.getZCoord(); - //Hysteresis based ePowerPass setting long energyMax = maxEUStore() / 2; long energyStored = getEUVar(); - float energyFrac = (float)energyStored/energyMax; + float energyFrac = (float) energyStored / energyMax; energyCapacityDisplay.set(energyMax); energyStoredDisplay.set(energyStored); @@ -631,23 +645,23 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock switch (scanTime) { case 0: scanTimeDisplay.updateStatus(); - scanForTransmissionTargets((int) xPosScanMin, (int) yPosScan0, (int) zPosScanMin, (int) xPosScanMax - 1, (int) yPosScan1 - 1, (int) zPosScanMax - 1); + scanForTransmissionTargets(xPosScanMin, yPosScan0, zPosScanMin, xPosScanMax - 1, yPosScan1 - 1, zPosScanMax - 1); break; case 20: scanTimeDisplay.updateStatus(); - scanForTransmissionTargets((int) xPosScanMin, (int) yPosScan1, (int) zPosScanMin, (int) xPosScanMax - 1, (int) yPosScan1 - 1, (int) zPosScanMax - 1); + scanForTransmissionTargets(xPosScanMin, yPosScan1, zPosScanMin, xPosScanMax - 1, yPosScan1 - 1, zPosScanMax - 1); break; case 40: scanTimeDisplay.updateStatus(); - scanForTransmissionTargets((int) xPosScanMin, (int) yPosScan2, (int) zPosScanMin, (int) xPosScanMax - 1, (int) yPosScan1 - 1, (int) zPosScanMax - 1); + scanForTransmissionTargets(xPosScanMin, yPosScan2, zPosScanMin, xPosScanMax - 1, yPosScan1 - 1, zPosScanMax - 1); break; case 60: scanTimeDisplay.updateStatus(); - scanForTransmissionTargets((int) xPosScanMin, (int) yPosScan3, (int) zPosScanMin, (int) xPosScanMax - 1, (int) yPosScan4 - 1, (int) zPosScanMax - 1); + scanForTransmissionTargets(xPosScanMin, yPosScan3, zPosScanMin, xPosScanMax - 1, yPosScan4 - 1, zPosScanMax - 1); break; case 80: scanTimeDisplay.updateStatus(); - scanForTransmissionTargets((int) xPosScanMin, (int) yPosScan4, (int) zPosScanMin, (int) xPosScanMax, (int) yPosScan5, (int) zPosScanMax); + scanForTransmissionTargets(xPosScanMin, yPosScan4, zPosScanMin, xPosScanMax, yPosScan5, zPosScanMax); break; default: if (scanTime == (int) scanTimeMinSetting.get() - 1) { @@ -661,33 +675,30 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock if (nodeInside instanceof GT_MetaTileEntity_TeslaCoil) { GT_MetaTileEntity_TeslaCoil teslaCoil = (GT_MetaTileEntity_TeslaCoil) nodeInside; - float tX = node.getXCoord(); - float tY = node.getYCoord(); - float tZ = node.getZCoord(); + int tX = node.getXCoord(); + int tY = node.getYCoord(); + int tZ = node.getZCoord(); - FXLightningBolt bolt = new FXLightningBolt(mte.getWorld(),tXN,tYN,tZN,tX,tY,tZ,mte.getWorld().rand.nextLong(), 6, 0.5F, 8); - bolt.defaultFractal(); - bolt.setType(2); - bolt.setWidth(0.125F); - bolt.finalizeBolt(); + int tXN = mte.getXCoord(); + int tYN = mte.getYCoord(); + int tZN = mte.getZCoord(); - new FXLightningBolt(getBaseMetaTileEntity().getWorld(),tX,tY,tZ,tXN,tYN,tZN,10000,1,1); - 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); + 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 RRx : eTeslaMap.entrySet()) { IGregTechTileEntity nodeN = RRx.getKey(); - if (nodeN == node){ + 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){ + 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); + teslaCoil.eTeslaMap.put(nodeN, tOffset); } } } catch (Exception e) { @@ -705,16 +716,16 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock //Power Limit Settings long outputVoltage; - if (outputVoltageSetting.get() > 0){ - outputVoltage = Math.min(outputVoltageMax,(long)outputVoltageSetting.get()); + if (outputVoltageSetting.get() > 0) { + outputVoltage = Math.min(outputVoltageMax, (long) outputVoltageSetting.get()); } else { outputVoltage = outputVoltageMax; } outputVoltageDisplay.set(outputVoltage); long outputCurrent; - if (outputCurrentSetting.get() > 0){ - outputCurrent = Math.min(outputCurrentMax,(long)outputCurrentSetting.get()); + if (outputCurrentSetting.get() > 0) { + outputCurrent = Math.min(outputCurrentMax, (long) outputCurrentSetting.get()); } else { outputCurrent = outputCurrentMax; } @@ -723,12 +734,12 @@ 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); + float rangeFrac = (float) ((-0.5 * Math.pow(energyFrac, 2)) + (1.5 * energyFrac)); + int transferRadiusTower = (int) (transferRadiusTowerSetting.get() * getRangeMulti(mTier, vTier) * rangeFrac); transferRadiusTowerDisplay.set(transferRadiusTower); - int transferRadiusTransceiver = (int)(transferRadiusTransceiverSetting.get()*getRangeMulti(mTier,vTier)*rangeFrac); + int transferRadiusTransceiver = (int) (transferRadiusTransceiverSetting.get() * getRangeMulti(mTier, vTier) * rangeFrac); transferRadiusTransceiverDisplay.set(transferRadiusTransceiver); - int transferRadiusCoverUltimate=(int)(transferRadiusCoverUltimateSetting.get()*getRangeMulti(mTier,vTier)*rangeFrac); + int transferRadiusCoverUltimate = (int) (transferRadiusCoverUltimateSetting.get() * getRangeMulti(mTier, vTier) * rangeFrac); transferRadiusCoverUltimateDisplay.set(transferRadiusCoverUltimate); //Clean the eTeslaMap @@ -761,13 +772,13 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock while (sparks > 0) { boolean idle = true; for (Map.Entry Rx : entriesSortedByValues(eTeslaMap)) { - if(energyStored >= (overDriveSetting.get() > 0 ? outputVoltage*2 : outputVoltage)) { + if (energyStored >= (overDriveSetting.get() > 0 ? outputVoltage * 2 : outputVoltage)) { IGregTechTileEntity node = Rx.getKey(); IMetaTileEntity nodeInside = node.getMetaTileEntity(); long outputVoltageInjectable; long outputVoltageConsumption; - if (overDriveSetting.get() > 0){ + if (overDriveSetting.get() > 0) { outputVoltageInjectable = outputVoltage; outputVoltageConsumption = getEnergyEfficiency(outputVoltage, mTier, true) + (lossPerBlock * Rx.getValue()); } else { @@ -781,6 +792,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock if (nodeTesla.getEUVar() + outputVoltageInjectable <= (nodeTesla.maxEUStore() / 2)) { setEUVar(getEUVar() - outputVoltageConsumption); node.increaseStoredEnergyUnits(outputVoltageConsumption, true); + thaumLightning(mte, node); sparks--; idle = false; } @@ -790,6 +802,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock if (!nodeTesla.powerPassToggle) { if (node.injectEnergyUnits((byte) 6, outputVoltageInjectable, 1L) > 0L) { setEUVar(getEUVar() - outputVoltageConsumption); + thaumLightning(mte, node); sparks--; idle = false; } @@ -797,6 +810,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock } else if ((node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil_Ultimate) && Rx.getValue() <= transferRadiusCoverUltimate) { if (node.injectEnergyUnits((byte) 1, outputVoltageInjectable, 1L) > 0L) { setEUVar(getEUVar() - outputVoltageConsumption); + thaumLightning(mte, node); sparks--; idle = false; } @@ -814,6 +828,26 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock } } outputCurrentDisplay.set(outputCurrent - sparks); + if (scanTime % 60 == 0 && !sparkList.isEmpty()) { + World aWorld = mte.getWorld(); + Iterator iterator = aWorld.playerEntities.iterator(); + while (iterator.hasNext()) { + Object tObject = iterator.next(); + + if (!(tObject instanceof EntityPlayerMP)) { + break; + } + + EntityPlayerMP tPlayer = (EntityPlayerMP) tObject; + Chunk tChunk = aWorld.getChunkFromBlockCoords(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getZCoord()); + if (tPlayer.getServerForPlayer().getPlayerManager().isPlayerWatchingChunk(tPlayer, tChunk.xPosition, tChunk.zPosition)) { + NetworkDispatcher.INSTANCE.sendTo(new RendererMessage.RendererData(sparkList), tPlayer); + } + } + sparkList.clear(); + } + } else { + outputCurrentDisplay.set(0); } 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 81418f0c4f..57089bea7a 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,8 @@ package com.github.technus.tectech.thing.metaTileEntity.single; import com.github.technus.tectech.Util; +import com.github.technus.tectech.loader.NetworkDispatcher; +import com.github.technus.tectech.mechanics.data.RendererMessage; 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.metaTileEntity.multi.GT_MetaTileEntity_TM_teslaCoil; @@ -12,8 +14,13 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicBatteryBuffer; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import static com.github.technus.tectech.CommonValues.V; @@ -23,6 +30,9 @@ import static java.lang.Math.round; public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer { + private final static HashSet sparkList = new HashSet(); + private byte sparkCount = 0; + private int maxTier = 4; //Max tier of transceiver private int minTier = 0; //Min tier of transceiver @@ -170,10 +180,24 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB return new GT_MetaTileEntity_TeslaCoil(mName, mTier, mDescription, mTextures, mInventory.length); } + private static void thaumLightning(IGregTechTileEntity mte, IGregTechTileEntity node) { + int x = mte.getXCoord(); + byte y = (byte) mte.getYCoord(); + int z = mte.getZCoord(); + + byte xR = (byte) (node.getXCoord() - x); + byte yR = (byte) (node.getYCoord() - y); + byte zR = (byte) (node.getZCoord() - z); + + int wID = mte.getWorld().provider.dimensionId; + + sparkList.add(new Util.thaumSpark(x,y,z,xR,yR,zR,wID)); + } + @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPostTick(aBaseMetaTileEntity, aTick); - if (aBaseMetaTileEntity.isClientSide() || eTeslaMap.isEmpty()) { + if (aBaseMetaTileEntity.isClientSide()) { return; } @@ -239,6 +263,7 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB if (nodeTesla.getEUVar() + outputVoltageInjectable <= (nodeTesla.maxEUStore() / 2)) { setEUVar(getEUVar() - outputVoltageConsumption); node.increaseStoredEnergyUnits(outputVoltageInjectable, true); + thaumLightning(aBaseMetaTileEntity,node); outputCurrent--; idle = false; } @@ -246,6 +271,7 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB } else if ((node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil) && !(node.getCoverBehaviorAtSide((byte) 1) instanceof GT_Cover_TM_TeslaCoil_Ultimate) && Rx.getValue() <= transferRadiusCover) { if (node.injectEnergyUnits((byte) 1, outputVoltageInjectable, 1L) > 0L) { setEUVar(getEUVar() - outputVoltageConsumption); + thaumLightning(aBaseMetaTileEntity,node); outputCurrent--; idle = false; } @@ -263,5 +289,25 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB } } } + sparkCount++; + if (sparkCount == 60){ + sparkCount = 0; + World aWorld = aBaseMetaTileEntity.getWorld(); + Iterator iterator = aWorld.playerEntities.iterator(); + while (iterator.hasNext()) { + Object tObject = iterator.next(); + + if (!(tObject instanceof EntityPlayerMP)) { + break; + } + + EntityPlayerMP tPlayer = (EntityPlayerMP) tObject; + Chunk tChunk = aWorld.getChunkFromBlockCoords(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getZCoord()); + if (tPlayer.getServerForPlayer().getPlayerManager().isPlayerWatchingChunk(tPlayer, tChunk.xPosition, tChunk.zPosition)) { + NetworkDispatcher.INSTANCE.sendTo(new RendererMessage.RendererData(sparkList), tPlayer); + } + } + sparkList.clear(); + } } } \ No newline at end of file -- cgit