From 258afcd33fe92453d0d18f9c19534fbe8ae51a0e Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 4 Aug 2013 22:45:32 -0400 Subject: [PATCH] Added quantum tesla --- src/resonantinduction/fx/FXElectricBolt.java | 5 +++ src/resonantinduction/tesla/BlockTesla.java | 40 ++++++++++++++++++- .../tesla/TileEntityTesla.java | 37 +++++++++++++++-- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/resonantinduction/fx/FXElectricBolt.java b/src/resonantinduction/fx/FXElectricBolt.java index c8c87146a..7bc50685e 100644 --- a/src/resonantinduction/fx/FXElectricBolt.java +++ b/src/resonantinduction/fx/FXElectricBolt.java @@ -68,6 +68,11 @@ public class FXElectricBolt extends EntityFX this.start = new BoltPoint(startVec); this.end = new BoltPoint(targetVec); + if (this.end.y == Double.POSITIVE_INFINITY) + { + this.end.y = Minecraft.getMinecraft().thePlayer.posY + 30; + } + /** By default, we do an electrical color */ this.segmentCount = 1; this.particleMaxAge = (3 + this.rand.nextInt(3) - 1); diff --git a/src/resonantinduction/tesla/BlockTesla.java b/src/resonantinduction/tesla/BlockTesla.java index 17245e365..9a6749653 100644 --- a/src/resonantinduction/tesla/BlockTesla.java +++ b/src/resonantinduction/tesla/BlockTesla.java @@ -4,13 +4,14 @@ package resonantinduction.tesla; import net.minecraft.block.ITileEntityProvider; -import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import resonantinduction.ResonantInduction; import resonantinduction.base.BlockBase; +import resonantinduction.base.Vector3; +import resonantinduction.entangler.ItemCoordLink; import resonantinduction.render.BlockRenderingHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -63,6 +64,43 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider } return true; } + else if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemCoordLink) + { + if (tileEntity.linkCoord == null) + { + ItemCoordLink link = ((ItemCoordLink) entityPlayer.getCurrentEquippedItem().getItem()); + Vector3 linkVec = link.getLink(entityPlayer.getCurrentEquippedItem()); + + if (linkVec != null) + { + if (linkVec.getTileEntity(world) instanceof TileEntityTesla) + { + tileEntity.linkCoord = new Vector3(((TileEntityTesla) linkVec.getTileEntity(world)).getTopTelsa()); + tileEntity.dimID = link.getLinkDim(entityPlayer.getCurrentEquippedItem()); + + if (!world.isRemote) + { + entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]"); + } + + link.clearLink(entityPlayer.getCurrentEquippedItem()); + world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "ambient.weather.thunder", 5, 1); + return true; + } + } + } + else + { + tileEntity.linkCoord = null; + + if (!world.isRemote) + { + entityPlayer.addChatMessage("Unlinked Tesla."); + } + + return true; + } + } } else { diff --git a/src/resonantinduction/tesla/TileEntityTesla.java b/src/resonantinduction/tesla/TileEntityTesla.java index 188d86ee6..fab2ffa7b 100644 --- a/src/resonantinduction/tesla/TileEntityTesla.java +++ b/src/resonantinduction/tesla/TileEntityTesla.java @@ -15,6 +15,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet; +import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.DamageSource; @@ -58,6 +59,12 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe private TileEntityTesla topCache = null; private TileEntityTesla controlCache = null; + /** + * Quantum Tesla + */ + public Vector3 linkCoord; + public int dimID; + /** * Client */ @@ -82,8 +89,27 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe if (this.isController()) { // TODO: Fix client side issue. || this.worldObj.isRemote - if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && ((this.getEnergyStored() > 0 && this.doTransfer) || this.worldObj.isRemote) && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) + if (((this.doTransfer) || this.worldObj.isRemote) && this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && this.getEnergyStored() > 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) { + /** + * Quantum transportation. + */ + if (this.linkCoord != null) + { + if (!this.worldObj.isRemote) + { + TileEntity tileEntity = MinecraftServer.getServer().worldServerForDimension(this.dimID).getBlockTileEntity((int) this.linkCoord.x, (int) this.linkCoord.y, (int) this.linkCoord.z); + + if (tileEntity instanceof TileEntityTesla && !tileEntity.isInvalid()) + { + this.transfer(((TileEntityTesla) tileEntity), this.getEnergyStored()); + } + } + + final TileEntityTesla topTesla = this.getTopTelsa(); + final Vector3 topTeslaVector = new Vector3(topTesla); + } + List transferTeslaCoils = new ArrayList(); for (ITesla tesla : TeslaGrid.instance().get()) @@ -163,8 +189,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe double distance = topTeslaVector.distance(targetVector); ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).translate(new Vector3(0.5)), targetVector.translate(new Vector3(0.5)), (float) dyeColors[this.dyeID].x, (float) dyeColors[this.dyeID].y, (float) dyeColors[this.dyeID].z); - tesla.transfer(transferEnergy * (1 - (this.worldObj.rand.nextFloat() * 0.1f)), true); - this.transfer(-transferEnergy, true); + this.transfer(tesla, transferEnergy); if (this.attackEntities && this.zapCounter % 5 == 0) { @@ -257,6 +282,12 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe this.clearCache(); } + private void transfer(ITesla tesla, float transferEnergy) + { + tesla.transfer(transferEnergy * (1 - (this.worldObj.rand.nextFloat() * 0.1f)), true); + this.transfer(-transferEnergy, true); + } + @Override public boolean canReceive(TileEntity tileEntity) {