This commit is contained in:
Aidan Brady 2013-08-03 13:41:55 -04:00
commit 236e80bfe1
3 changed files with 62 additions and 42 deletions

View file

@ -62,8 +62,7 @@ public class FXElectricBolt extends EntityFX
/** By default, we do an electrical color */ /** By default, we do an electrical color */
this.segmentCount = 1; this.segmentCount = 1;
this.particleAge = (3 + this.rand.nextInt(3) - 1); this.particleMaxAge = (3 + this.rand.nextInt(3) - 1) * 2;
this.particleMaxAge = (3 + this.rand.nextInt(3) - 1);
this.complexity = 2f; this.complexity = 2f;
this.boltWidth = 0.05f; this.boltWidth = 0.05f;
this.boltLength = this.start.distance(this.end); this.boltLength = this.start.distance(this.end);
@ -78,12 +77,12 @@ public class FXElectricBolt extends EntityFX
this.segments.add(new BoltSegment(this.start, this.end)); this.segments.add(new BoltSegment(this.start, this.end));
this.recalculate(); this.recalculate();
double offsetRatio = this.boltLength * this.complexity; double offsetRatio = this.boltLength * this.complexity;
this.split(2, offsetRatio / 2, 0.7f, 0.1F, 20); this.split(2, offsetRatio / 2, 0.7f, 0.1f, 20);
this.split(2, offsetRatio / 3, 0.5f, 0.1F, 25); this.split(2, offsetRatio / 3, 0.5f, 0.1f, 25);
this.split(2, offsetRatio / 6, 0.5f, 0.1F, 55f / 2); this.split(2, offsetRatio / 6, 0.5f, 0.1f, 28);
this.split(2, offsetRatio / 8, 0.5f, 0.1F, 60f / 2); this.split(2, offsetRatio / 8, 0.5f, 0.1f, 30);
this.split(2, offsetRatio / 12, 0, 0.0F, 0.0F); this.split(2, offsetRatio / 12, 0, 0, 0);
this.split(2, offsetRatio / 16, 0, 0.0F, 0.0F); this.split(2, offsetRatio / 16, 0, 0, 0);
this.recalculate(); this.recalculate();
@ -147,7 +146,7 @@ public class FXElectricBolt extends EntityFX
*/ */
for (int i = 1; i < splitAmount; i++) for (int i = 1; i < splitAmount; i++)
{ {
Vector3 newOffset = segment.difference.getPerpendicular().rotate((float) (this.rand.nextFloat() * 90), segment.difference).scale((this.rand.nextFloat() - 0.5F) * offset); Vector3 newOffset = segment.difference.getPerpendicular().rotate((float) (this.rand.nextFloat() * 180), segment.difference).scale((this.rand.nextFloat() - 0.5F) * offset);
Vector3 basePoint = startPoint.clone().translate(subSegment.clone().scale(i)); Vector3 basePoint = startPoint.clone().translate(subSegment.clone().scale(i));
newPoints[i] = new BoltPoint(basePoint, newOffset); newPoints[i] = new BoltPoint(basePoint, newOffset);
@ -165,7 +164,7 @@ public class FXElectricBolt extends EntityFX
if ((i != 0) && (this.rand.nextFloat() < splitChance)) if ((i != 0) && (this.rand.nextFloat() < splitChance))
{ {
Vector3 splitrot = next.difference.xCrossProduct().rotate(this.rand.nextFloat() * 360.0F, next.difference); Vector3 splitrot = next.difference.xCrossProduct().rotate(this.rand.nextFloat() * 180, next.difference);
Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot).scale(splitLength); Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot).scale(splitLength);
this.maxSplitID += 1; this.maxSplitID += 1;
this.parentIDMap.put(this.maxSplitID, next.splitID); this.parentIDMap.put(this.maxSplitID, next.splitID);
@ -309,29 +308,34 @@ public class FXElectricBolt extends EntityFX
tessellator.addVertexWithUV(rx1 + diffPrev.x, ry1 + diffPrev.y, rz1 + diffPrev.z, 0.5D, 1.0D); tessellator.addVertexWithUV(rx1 + diffPrev.x, ry1 + diffPrev.y, rz1 + diffPrev.z, 0.5D, 1.0D);
tessellator.addVertexWithUV(rx2 + diffNext.x, ry2 + diffNext.y, rz2 + diffNext.z, 0.5D, 1.0D); tessellator.addVertexWithUV(rx2 + diffNext.x, ry2 + diffNext.y, rz2 + diffNext.z, 0.5D, 1.0D);
if (segment.next == null) /**
{ * Render the bolts balls.
Vector3 roundEnd = segment.end.clone().translate(segment.difference.clone().normalize().scale(renderWidth)); */
float rx3 = (float) (roundEnd.x - interpPosX); /*
float ry3 = (float) (roundEnd.y - interpPosY); * if (segment.next == null) { Vector3 roundEnd =
float rz3 = (float) (roundEnd.z - interpPosZ); * segment.end.clone().translate(segment
tessellator.addVertexWithUV(rx3 - diffNext.x, ry3 - diffNext.y, rz3 - diffNext.z, 0.0D, 0.0D); * .difference.clone().normalize().scale(renderWidth)); float rx3 = (float)
tessellator.addVertexWithUV(rx2 - diffNext.x, ry2 - diffNext.y, rz2 - diffNext.z, 0.5D, 0.0D); * (roundEnd.x - interpPosX); float ry3 = (float) (roundEnd.y - interpPosY);
tessellator.addVertexWithUV(rx2 + diffNext.x, ry2 + diffNext.y, rz2 + diffNext.z, 0.5D, 1.0D); * float rz3 = (float) (roundEnd.z - interpPosZ);
tessellator.addVertexWithUV(rx3 + diffNext.x, ry3 + diffNext.y, rz3 + diffNext.z, 0.0D, 1.0D); * tessellator.addVertexWithUV(rx3 - diffNext.x, ry3 - diffNext.y, rz3 -
} * diffNext.z, 0.0D, 0.0D); tessellator.addVertexWithUV(rx2 - diffNext.x, ry2 -
* diffNext.y, rz2 - diffNext.z, 0.5D, 0.0D); tessellator.addVertexWithUV(rx2 +
if (segment.prev == null) * diffNext.x, ry2 + diffNext.y, rz2 + diffNext.z, 0.5D, 1.0D);
{ * tessellator.addVertexWithUV(rx3 + diffNext.x, ry3 + diffNext.y, rz3 +
Vector3 roundEnd = segment.start.clone().difference(segment.difference.clone().normalize().scale(renderWidth)); * diffNext.z, 0.0D, 1.0D); }
float rx3 = (float) (roundEnd.x - interpPosX); *
float ry3 = (float) (roundEnd.y - interpPosY); * if (segment.prev == null) { Vector3 roundEnd =
float rz3 = (float) (roundEnd.z - interpPosZ); * segment.start.clone().difference
tessellator.addVertexWithUV(rx1 - diffPrev.x, ry1 - diffPrev.y, rz1 - diffPrev.z, 0.5D, 0.0D); * (segment.difference.clone().normalize().scale(renderWidth)); float rx3 =
tessellator.addVertexWithUV(rx3 - diffPrev.x, ry3 - diffPrev.y, rz3 - diffPrev.z, 0.0D, 0.0D); * (float) (roundEnd.x - interpPosX); float ry3 = (float) (roundEnd.y -
tessellator.addVertexWithUV(rx3 + diffPrev.x, ry3 + diffPrev.y, rz3 + diffPrev.z, 0.0D, 1.0D); * interpPosY); float rz3 = (float) (roundEnd.z - interpPosZ);
tessellator.addVertexWithUV(rx1 + diffPrev.x, ry1 + diffPrev.y, rz1 + diffPrev.z, 0.5D, 1.0D); * tessellator.addVertexWithUV(rx1 - diffPrev.x, ry1 - diffPrev.y, rz1 -
} * diffPrev.z, 0.5D, 0.0D); tessellator.addVertexWithUV(rx3 - diffPrev.x, ry3 -
* diffPrev.y, rz3 - diffPrev.z, 0.0D, 0.0D); tessellator.addVertexWithUV(rx3 +
* diffPrev.x, ry3 + diffPrev.y, rz3 + diffPrev.z, 0.0D, 1.0D);
* tessellator.addVertexWithUV(rx1 + diffPrev.x, ry1 + diffPrev.y, rz1 +
* diffPrev.z, 0.5D, 1.0D); }
*/
} }
} }
} }
@ -396,13 +400,11 @@ public class FXElectricBolt extends EntityFX
this.alpha = alpha; this.alpha = alpha;
this.id = id; this.id = id;
this.splitID = splitID; this.splitID = splitID;
this.recalculate(); this.difference = this.end.difference(this.start);
} }
public void recalculate() public void recalculate()
{ {
this.difference = this.end.difference(this.start);
if (this.prev != null) if (this.prev != null)
{ {
Vector3 prevDiffNorm = this.prev.difference.clone().normalize(); Vector3 prevDiffNorm = this.prev.difference.clone().normalize();

View file

@ -38,15 +38,18 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
{ {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
tileEntity = ((TileEntityTesla) tileEntity).getControllingTelsa();
if (entityPlayer.getCurrentEquippedItem() != null) if (entityPlayer.getCurrentEquippedItem() != null)
{ {
if (entityPlayer.getCurrentEquippedItem().itemID == Item.dyePowder.itemID) if (entityPlayer.getCurrentEquippedItem().itemID == Item.dyePowder.itemID)
{ {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
((TileEntityTesla) tileEntity).setDye(entityPlayer.getCurrentEquippedItem().getItemDamage()); ((TileEntityTesla) tileEntity).setDye(entityPlayer.getCurrentEquippedItem().getItemDamage());
return true; return true;
} }
} }
return false; return false;
} }

View file

@ -4,14 +4,17 @@
package resonantinduction.tesla; package resonantinduction.tesla;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import net.minecraft.block.BlockFurnace; import net.minecraft.block.BlockFurnace;
import net.minecraft.entity.Entity;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.AxisAlignedBB;
import resonantinduction.ITesla; import resonantinduction.ITesla;
import resonantinduction.PacketHandler; import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
@ -52,7 +55,8 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
/** /**
* Only transfer if it is the bottom controlling Tesla tower. * Only transfer if it is the bottom controlling Tesla tower.
*/ */
if (this.ticks % 2 == 0 && this.isController() && this.getEnergyStored() > 0 && (this.doTransfer || this.worldObj.isRemote) && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) // TODO: Fix client side issue. || this.worldObj.isRemote
if (this.ticks % 2 == 0 && this.isController() && ((this.getEnergyStored() > 0 && this.doTransfer) || this.worldObj.isRemote) && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))
{ {
Set<ITesla> transferTeslaCoils = new HashSet<ITesla>(); Set<ITesla> transferTeslaCoils = new HashSet<ITesla>();
@ -164,7 +168,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
} }
} }
if (this.getEnergyStored() > 0 != doPacketUpdate) if (!this.worldObj.isRemote && this.getEnergyStored() > 0 != doPacketUpdate)
{ {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
} }
@ -173,7 +177,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
return PacketHandler.getTileEntityPacket(this, this.getEnergyStored(), this.dyeID); return PacketHandler.getTileEntityPacket(this, (byte) 1, this.getEnergyStored(), this.dyeID);
} }
@Override @Override
@ -181,8 +185,16 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
{ {
try try
{ {
this.energy = input.readFloat(); switch (input.readByte())
this.dyeID = input.readInt(); {
case 1:
this.energy = input.readFloat();
this.dyeID = input.readInt();
break;
}
this.doTransfer = true;
} }
catch (Exception e) catch (Exception e)
{ {
@ -202,11 +214,14 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
{ {
this.energy = Math.max(this.energy + transferEnergy, 0); this.energy = Math.max(this.energy + transferEnergy, 0);
this.doTransfer = true; this.doTransfer = true;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
} }
else else
{ {
this.getControllingTelsa().transfer(transferEnergy); this.getControllingTelsa().transfer(transferEnergy);
} }
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
} }
public float getEnergyStored() public float getEnergyStored()