Fixed inconsistant Tesla electric bolt
This commit is contained in:
parent
20e864b1e0
commit
7ec588d529
1 changed files with 28 additions and 11 deletions
|
@ -45,11 +45,13 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
public final static int DEFAULT_COLOR = 12;
|
||||
public final float TRANSFER_CAP = 10;
|
||||
private int dyeID = DEFAULT_COLOR;
|
||||
private boolean doTransfer = true;
|
||||
|
||||
private boolean canReceive = true;
|
||||
private boolean attackEntities = true;
|
||||
|
||||
/** Client side to do sparks */
|
||||
private boolean doTransfer = true;
|
||||
|
||||
/** Prevents transfer loops */
|
||||
private final Set<TileEntityTesla> outputBlacklist = new HashSet<TileEntityTesla>();
|
||||
private final Set<TileEntityTesla> connectedTeslas = new HashSet<TileEntityTesla>();
|
||||
|
@ -93,7 +95,7 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
{
|
||||
this.produce();
|
||||
|
||||
if (this.doTransfer && this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && this.getEnergyStored() > 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))
|
||||
if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && ((this.worldObj.isRemote && this.doTransfer) || (this.getEnergyStored() > 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))))
|
||||
{
|
||||
final TileEntityTesla topTesla = this.getTopTelsa();
|
||||
final Vector3 topTeslaVector = new Vector3(topTesla);
|
||||
|
@ -189,7 +191,7 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
{
|
||||
float transferEnergy = this.getEnergyStored() / transferTeslaCoils.size();
|
||||
int count = 0;
|
||||
|
||||
boolean sentPacket = false;
|
||||
for (ITesla tesla : transferTeslaCoils)
|
||||
{
|
||||
if (this.zapCounter % 5 == 0 && ResonantInduction.SOUND_FXS)
|
||||
|
@ -210,6 +212,11 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
|
||||
this.transfer(tesla, Math.min(transferEnergy, TRANSFER_CAP));
|
||||
|
||||
if (!sentPacket)
|
||||
{
|
||||
this.sendPacket(3);
|
||||
}
|
||||
|
||||
if (this.attackEntities && this.zapCounter % 5 == 0)
|
||||
{
|
||||
MovingObjectPosition mop = topTeslaVector.clone().translate(0.5).rayTraceEntities(this.worldObj, targetVector.clone().translate(0.5));
|
||||
|
@ -234,11 +241,13 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
|
||||
this.zapCounter++;
|
||||
this.outputBlacklist.clear();
|
||||
|
||||
this.doTransfer = false;
|
||||
}
|
||||
|
||||
if (!this.worldObj.isRemote && this.getEnergyStored() > 0 != doPacketUpdate)
|
||||
{
|
||||
this.setPacket(2);
|
||||
this.sendPacket(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +266,6 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
@Override
|
||||
public float receiveElectricity(ElectricityPack receive, boolean doReceive)
|
||||
{
|
||||
this.doTransfer = true;
|
||||
return super.receiveElectricity(receive, doReceive);
|
||||
}
|
||||
|
||||
|
@ -284,7 +292,15 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
return PacketHandler.getTileEntityPacket(this, (byte) 2, this.getEnergyStored());
|
||||
}
|
||||
|
||||
public void setPacket(int id)
|
||||
/**
|
||||
* Do Tesla Beam.
|
||||
*/
|
||||
public Packet getDescriptionPacket3()
|
||||
{
|
||||
return PacketHandler.getTileEntityPacket(this, (byte) 3);
|
||||
}
|
||||
|
||||
public void sendPacket(int id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
|
@ -294,6 +310,9 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
case 2:
|
||||
PacketDispatcher.sendPacketToAllInDimension(this.getDescriptionPacket2(), this.worldObj.provider.dimensionId);
|
||||
break;
|
||||
case 3:
|
||||
PacketDispatcher.sendPacketToAllInDimension(this.getDescriptionPacket3(), this.worldObj.provider.dimensionId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,11 +339,10 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
case 2:
|
||||
this.setEnergyStored(input.readFloat());
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case 3:
|
||||
this.doTransfer = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
|
@ -352,8 +370,7 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
|||
this.receiveElectricity(transferEnergy, true);
|
||||
}
|
||||
|
||||
this.doTransfer = true;
|
||||
this.setPacket(2);
|
||||
this.sendPacket(2);
|
||||
return transferEnergy;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue