Hopefully fixed crash
This commit is contained in:
parent
df70da8bd0
commit
dc925798b0
3 changed files with 248 additions and 250 deletions
|
@ -31,7 +31,7 @@ public class IC2ItemManager implements IElectricItemManager
|
||||||
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) + energyToStore);
|
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) + energyToStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)(energyToStore*Mekanism.TO_IC2);
|
return (int)Math.round(energyToStore*Mekanism.TO_IC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -50,7 +50,7 @@ public class IC2ItemManager implements IElectricItemManager
|
||||||
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) - energyToGive);
|
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) - energyToGive);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)(energyToGive*Mekanism.TO_IC2);
|
return (int)Math.round(energyToGive*Mekanism.TO_IC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -65,7 +65,7 @@ public class IC2ItemManager implements IElectricItemManager
|
||||||
@Override
|
@Override
|
||||||
public int getCharge(ItemStack itemStack)
|
public int getCharge(ItemStack itemStack)
|
||||||
{
|
{
|
||||||
return 0;
|
return (int)Math.round(energizedItem.getEnergy(itemStack)*Mekanism.TO_IC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -92,7 +92,7 @@ public final class TransporterUtils
|
||||||
//Immature BuildCraft inv check
|
//Immature BuildCraft inv check
|
||||||
if(MekanismUtils.useBuildcraft() && inventory instanceof IPowerReceptor)
|
if(MekanismUtils.useBuildcraft() && inventory instanceof IPowerReceptor)
|
||||||
{
|
{
|
||||||
if(((IPowerReceptor)inventory).getPowerReceiver(forgeSide).getType() == Type.MACHINE)
|
if(((IPowerReceptor)inventory).getPowerReceiver(forgeSide) != null && ((IPowerReceptor)inventory).getPowerReceiver(forgeSide).getType() == Type.MACHINE)
|
||||||
{
|
{
|
||||||
connectable[side] = true;
|
connectable[side] = true;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -31,8 +31,6 @@ import universalelectricity.core.vector.Vector3;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Tesla TileEntity.
|
* The Tesla TileEntity.
|
||||||
*
|
*
|
||||||
|
@ -46,278 +44,278 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
||||||
public final static int DEFAULT_COLOR = 12;
|
public final static int DEFAULT_COLOR = 12;
|
||||||
public final float TRANSFER_CAP = 10;
|
public final float TRANSFER_CAP = 10;
|
||||||
private int dyeID = DEFAULT_COLOR;
|
private int dyeID = DEFAULT_COLOR;
|
||||||
|
|
||||||
private boolean canReceive = true;
|
private boolean canReceive = true;
|
||||||
private boolean attackEntities = true;
|
private boolean attackEntities = true;
|
||||||
|
|
||||||
/** Client side to do sparks */
|
/** Client side to do sparks */
|
||||||
private boolean doTransfer = true;
|
private boolean doTransfer = true;
|
||||||
|
|
||||||
/** Prevents transfer loops */
|
/** Prevents transfer loops */
|
||||||
private final Set<TileEntityTesla> outputBlacklist = new HashSet<TileEntityTesla>();
|
private final Set<TileEntityTesla> outputBlacklist = new HashSet<TileEntityTesla>();
|
||||||
private final Set<TileEntityTesla> connectedTeslas = new HashSet<TileEntityTesla>();
|
private final Set<TileEntityTesla> connectedTeslas = new HashSet<TileEntityTesla>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caching
|
* Caching
|
||||||
*/
|
*/
|
||||||
private TileEntityTesla topCache = null;
|
private TileEntityTesla topCache = null;
|
||||||
private TileEntityTesla controlCache = null;
|
private TileEntityTesla controlCache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quantum Tesla
|
* Quantum Tesla
|
||||||
*/
|
*/
|
||||||
public Vector3 linked;
|
public Vector3 linked;
|
||||||
public int linkDim;
|
public int linkDim;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client
|
* Client
|
||||||
*/
|
*/
|
||||||
private int zapCounter = 0;
|
private int zapCounter = 0;
|
||||||
private boolean isLinkedClient;
|
private boolean isLinkedClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initiate()
|
public void initiate()
|
||||||
{
|
{
|
||||||
super.initiate();
|
super.initiate();
|
||||||
TeslaGrid.instance().register(this);
|
TeslaGrid.instance().register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
boolean doPacketUpdate = this.getEnergyStored() > 0;
|
boolean doPacketUpdate = getEnergyStored() > 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only transfer if it is the bottom controlling Tesla tower.
|
* Only transfer if it is the bottom controlling Tesla tower.
|
||||||
*/
|
*/
|
||||||
if (this.isController())
|
if(isController())
|
||||||
{
|
{
|
||||||
this.produce();
|
produce();
|
||||||
|
|
||||||
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))))
|
if(ticks % (5 + worldObj.rand.nextInt(2)) == 0 && ((worldObj.isRemote && doTransfer) || (getEnergyStored() > 0 && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))))
|
||||||
{
|
{
|
||||||
final TileEntityTesla topTesla = this.getTopTelsa();
|
final TileEntityTesla topTesla = getTopTelsa();
|
||||||
final Vector3 topTeslaVector = new Vector3(topTesla);
|
final Vector3 topTeslaVector = new Vector3(topTesla);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quantum transportation.
|
* Quantum transportation.
|
||||||
*/
|
*/
|
||||||
if (this.linked != null || this.isLinkedClient)
|
if(linked != null || isLinkedClient)
|
||||||
{
|
{
|
||||||
if (!this.worldObj.isRemote)
|
if(!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
World dimWorld = MinecraftServer.getServer().worldServerForDimension(this.linkDim);
|
World dimWorld = MinecraftServer.getServer().worldServerForDimension(linkDim);
|
||||||
|
|
||||||
if (dimWorld != null)
|
if(dimWorld != null)
|
||||||
{
|
{
|
||||||
TileEntity transferTile = this.linked.getTileEntity(dimWorld);
|
TileEntity transferTile = linked.getTileEntity(dimWorld);
|
||||||
|
|
||||||
if (transferTile instanceof TileEntityTesla && !transferTile.isInvalid())
|
if(transferTile instanceof TileEntityTesla && !transferTile.isInvalid())
|
||||||
{
|
{
|
||||||
this.transfer(((TileEntityTesla) transferTile), Math.min(this.getProvide(ForgeDirection.UNKNOWN), TRANSFER_CAP));
|
transfer(((TileEntityTesla)transferTile), Math.min(getProvide(ForgeDirection.UNKNOWN), TRANSFER_CAP));
|
||||||
|
|
||||||
if (this.zapCounter % 5 == 0 && MekanismInduction.SOUND_FXS)
|
if(zapCounter % 5 == 0 && MekanismInduction.SOUND_FXS)
|
||||||
{
|
{
|
||||||
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, MekanismInduction.PREFIX + "electricshock", this.getEnergyStored() / 25, 1.3f - 0.5f * (this.dyeID / 16f));
|
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, MekanismInduction.PREFIX + "electricshock", getEnergyStored() / 25, 1.3f - 0.5f * (dyeID / 16f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MekanismInduction.proxy.renderElectricShock(this.worldObj, topTeslaVector.clone().translate(0.5), topTeslaVector.clone().translate(new Vector3(0.5, Double.POSITIVE_INFINITY, 0.5)), false);
|
MekanismInduction.proxy.renderElectricShock(worldObj, topTeslaVector.clone().translate(0.5), topTeslaVector.clone().translate(new Vector3(0.5, Double.POSITIVE_INFINITY, 0.5)), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
List<ITesla> transferTeslaCoils = new ArrayList<ITesla>();
|
List<ITesla> transferTeslaCoils = new ArrayList<ITesla>();
|
||||||
|
|
||||||
for (ITesla tesla : TeslaGrid.instance().get())
|
for(ITesla tesla : TeslaGrid.instance().get())
|
||||||
{
|
{
|
||||||
if (new Vector3((TileEntity) tesla).distance(new Vector3(this)) < this.getRange())
|
if(new Vector3((TileEntity)tesla).distance(new Vector3(this)) < getRange())
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Make sure Tesla is not part of this tower.
|
* Make sure Tesla is not part of this tower.
|
||||||
*/
|
*/
|
||||||
if (!this.connectedTeslas.contains(tesla) && tesla.canReceive(this))
|
if(!connectedTeslas.contains(tesla) && tesla.canReceive(this))
|
||||||
{
|
{
|
||||||
if (tesla instanceof TileEntityTesla)
|
if(tesla instanceof TileEntityTesla)
|
||||||
{
|
{
|
||||||
if (((TileEntityTesla) tesla).getHeight() <= 1)
|
if(((TileEntityTesla)tesla).getHeight() <= 1)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tesla = ((TileEntityTesla) tesla).getControllingTelsa();
|
tesla = ((TileEntityTesla)tesla).getControllingTelsa();
|
||||||
}
|
}
|
||||||
|
|
||||||
transferTeslaCoils.add(tesla);
|
transferTeslaCoils.add(tesla);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort by distance.
|
* Sort by distance.
|
||||||
*/
|
*/
|
||||||
Collections.sort(transferTeslaCoils, new Comparator() {
|
Collections.sort(transferTeslaCoils, new Comparator() {
|
||||||
public int compare(ITesla o1, ITesla o2)
|
public int compare(ITesla o1, ITesla o2)
|
||||||
{
|
{
|
||||||
double distance1 = new Vector3(topTesla).distance(new Vector3((TileEntity) o1));
|
double distance1 = new Vector3(topTesla).distance(new Vector3((TileEntity)o1));
|
||||||
double distance2 = new Vector3(topTesla).distance(new Vector3((TileEntity) o2));
|
double distance2 = new Vector3(topTesla).distance(new Vector3((TileEntity)o2));
|
||||||
|
|
||||||
if (distance1 < distance2)
|
if(distance1 < distance2)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (distance1 > distance2)
|
else if(distance1 > distance2)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object obj, Object obj1)
|
public int compare(Object obj, Object obj1)
|
||||||
{
|
{
|
||||||
return compare((ITesla) obj, (ITesla) obj1);
|
return compare((ITesla)obj, (ITesla)obj1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (transferTeslaCoils.size() > 0)
|
if(transferTeslaCoils.size() > 0)
|
||||||
{
|
{
|
||||||
float transferEnergy = this.getEnergyStored() / transferTeslaCoils.size();
|
float transferEnergy = getEnergyStored() / transferTeslaCoils.size();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
boolean sentPacket = false;
|
boolean sentPacket = false;
|
||||||
for (ITesla tesla : transferTeslaCoils)
|
for(ITesla tesla : transferTeslaCoils)
|
||||||
{
|
{
|
||||||
if (this.zapCounter % 5 == 0 && MekanismInduction.SOUND_FXS)
|
if(zapCounter % 5 == 0 && MekanismInduction.SOUND_FXS)
|
||||||
{
|
{
|
||||||
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, MekanismInduction.PREFIX + "electricshock", this.getEnergyStored() / 25, 1.3f - 0.5f * (this.dyeID / 16f));
|
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, MekanismInduction.PREFIX + "electricshock", getEnergyStored() / 25, 1.3f - 0.5f * (dyeID / 16f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 targetVector = new Vector3((TileEntity) tesla);
|
Vector3 targetVector = new Vector3((TileEntity)tesla);
|
||||||
|
|
||||||
if (tesla instanceof TileEntityTesla)
|
if(tesla instanceof TileEntityTesla)
|
||||||
{
|
{
|
||||||
((TileEntityTesla) tesla).getControllingTelsa().outputBlacklist.add(this);
|
((TileEntityTesla)tesla).getControllingTelsa().outputBlacklist.add(this);
|
||||||
targetVector = new Vector3(((TileEntityTesla) tesla).getTopTelsa());
|
targetVector = new Vector3(((TileEntityTesla)tesla).getTopTelsa());
|
||||||
}
|
}
|
||||||
|
|
||||||
double distance = topTeslaVector.distance(targetVector);
|
double distance = topTeslaVector.distance(targetVector);
|
||||||
MekanismInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).translate(new Vector3(0.5)), targetVector.translate(new Vector3(0.5)), (float) MekanismInduction.DYE_COLORS[this.dyeID].x, (float) MekanismInduction.DYE_COLORS[this.dyeID].y,
|
MekanismInduction.proxy.renderElectricShock(worldObj, new Vector3(topTesla).translate(new Vector3(0.5)), targetVector.translate(new Vector3(0.5)), (float)MekanismInduction.DYE_COLORS[dyeID].x, (float)MekanismInduction.DYE_COLORS[dyeID].y,
|
||||||
(float) MekanismInduction.DYE_COLORS[this.dyeID].z);
|
(float)MekanismInduction.DYE_COLORS[dyeID].z);
|
||||||
|
|
||||||
this.transfer(tesla, Math.min(transferEnergy, TRANSFER_CAP));
|
transfer(tesla, Math.min(transferEnergy, TRANSFER_CAP));
|
||||||
|
|
||||||
if (!sentPacket && transferEnergy > 0)
|
if(!sentPacket && transferEnergy > 0)
|
||||||
{
|
{
|
||||||
this.sendPacket(3);
|
sendPacket(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.attackEntities && this.zapCounter % 5 == 0)
|
if(attackEntities && zapCounter % 5 == 0)
|
||||||
{
|
{
|
||||||
MovingObjectPosition mop = topTeslaVector.clone().translate(0.5).rayTraceEntities(this.worldObj, targetVector.clone().translate(0.5));
|
MovingObjectPosition mop = topTeslaVector.clone().translate(0.5).rayTraceEntities(worldObj, targetVector.clone().translate(0.5));
|
||||||
|
|
||||||
if (mop != null && mop.entityHit != null)
|
if(mop != null && mop.entityHit != null)
|
||||||
{
|
{
|
||||||
if (mop.entityHit instanceof EntityLivingBase)
|
if(mop.entityHit instanceof EntityLivingBase)
|
||||||
{
|
{
|
||||||
mop.entityHit.attackEntityFrom(DamageSource.magic, 4);
|
mop.entityHit.attackEntityFrom(DamageSource.magic, 4);
|
||||||
MekanismInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).clone().translate(0.5), new Vector3(mop.entityHit));
|
MekanismInduction.proxy.renderElectricShock(worldObj, new Vector3(topTesla).clone().translate(0.5), new Vector3(mop.entityHit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count++ > 1)
|
if(count++ > 1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.zapCounter++;
|
zapCounter++;
|
||||||
this.outputBlacklist.clear();
|
outputBlacklist.clear();
|
||||||
|
|
||||||
this.doTransfer = false;
|
doTransfer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.worldObj.isRemote && this.getEnergyStored() > 0 != doPacketUpdate)
|
if(!worldObj.isRemote && getEnergyStored() > 0 != doPacketUpdate)
|
||||||
{
|
{
|
||||||
this.sendPacket(2);
|
sendPacket(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearCache();
|
clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transfer(ITesla tesla, float transferEnergy)
|
private void transfer(ITesla tesla, float transferEnergy)
|
||||||
{
|
{
|
||||||
if (transferEnergy > 0)
|
if(transferEnergy > 0)
|
||||||
{
|
{
|
||||||
tesla.transfer(transferEnergy * (1 - (this.worldObj.rand.nextFloat() * 0.1f)), true);
|
tesla.transfer(transferEnergy * (1 - (worldObj.rand.nextFloat() * 0.1f)), true);
|
||||||
this.transfer(-transferEnergy, true);
|
transfer(-transferEnergy, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float receiveElectricity(ElectricityPack receive, boolean doReceive)
|
public float receiveElectricity(ElectricityPack receive, boolean doReceive)
|
||||||
{
|
{
|
||||||
return super.receiveElectricity(receive, doReceive);
|
return super.receiveElectricity(receive, doReceive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canReceive(TileEntity tileEntity)
|
public boolean canReceive(TileEntity tileEntity)
|
||||||
{
|
{
|
||||||
return this.canReceive && !this.outputBlacklist.contains(tileEntity) && this.getRequest(ForgeDirection.UNKNOWN) > 0;
|
return canReceive && !outputBlacklist.contains(tileEntity) && getRequest(ForgeDirection.UNKNOWN) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canConnect(ForgeDirection direction)
|
public boolean canConnect(ForgeDirection direction)
|
||||||
{
|
{
|
||||||
return this.isController();
|
return isController();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList getNetworkedData(ArrayList data)
|
public ArrayList getNetworkedData(ArrayList data)
|
||||||
{
|
{
|
||||||
data.add((byte) 1);
|
data.add((byte)1);
|
||||||
data.add(getEnergyStored());
|
data.add(getEnergyStored());
|
||||||
data.add(dyeID);
|
data.add(dyeID);
|
||||||
data.add(canReceive);
|
data.add(canReceive);
|
||||||
data.add(attackEntities);
|
data.add(attackEntities);
|
||||||
data.add(linked != null);
|
data.add(linked != null);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList getEnergyPacket()
|
public ArrayList getEnergyPacket()
|
||||||
{
|
{
|
||||||
ArrayList data = new ArrayList();
|
ArrayList data = new ArrayList();
|
||||||
data.add((byte) 2);
|
data.add((byte)2);
|
||||||
data.add(getEnergyStored());
|
data.add(getEnergyStored());
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do Tesla Beam.
|
* Do Tesla Beam.
|
||||||
*/
|
*/
|
||||||
public ArrayList getTeslaPacket()
|
public ArrayList getTeslaPacket()
|
||||||
{
|
{
|
||||||
ArrayList data = new ArrayList();
|
ArrayList data = new ArrayList();
|
||||||
data.add((byte) 3);
|
data.add((byte)3);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPacket(int id)
|
public void sendPacket(int id)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch(id)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())));
|
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())));
|
||||||
|
@ -330,87 +328,87 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlePacketData(ByteArrayDataInput input)
|
public void handlePacketData(ByteArrayDataInput input)
|
||||||
{
|
{
|
||||||
switch (input.readByte())
|
switch(input.readByte())
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
this.setEnergyStored(input.readFloat());
|
setEnergyStored(input.readFloat());
|
||||||
this.dyeID = input.readInt();
|
dyeID = input.readInt();
|
||||||
this.canReceive = input.readBoolean();
|
canReceive = input.readBoolean();
|
||||||
this.attackEntities = input.readBoolean();
|
attackEntities = input.readBoolean();
|
||||||
this.isLinkedClient = input.readBoolean();
|
isLinkedClient = input.readBoolean();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
this.setEnergyStored(input.readFloat());
|
setEnergyStored(input.readFloat());
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
this.doTransfer = true;
|
doTransfer = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isController()
|
private boolean isController()
|
||||||
{
|
{
|
||||||
return this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord) == 0;
|
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCache()
|
private void clearCache()
|
||||||
{
|
{
|
||||||
this.topCache = null;
|
topCache = null;
|
||||||
this.controlCache = null;
|
controlCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float transfer(float transferEnergy, boolean doTransfer)
|
public float transfer(float transferEnergy, boolean doTransfer)
|
||||||
{
|
{
|
||||||
if (isController() || this.getControllingTelsa() == this)
|
if(isController() || getControllingTelsa() == this)
|
||||||
{
|
{
|
||||||
if (doTransfer)
|
if(doTransfer)
|
||||||
{
|
{
|
||||||
this.receiveElectricity(transferEnergy, true);
|
receiveElectricity(transferEnergy, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendPacket(2);
|
sendPacket(2);
|
||||||
return transferEnergy;
|
return transferEnergy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (this.getEnergyStored() > 0)
|
if(getEnergyStored() > 0)
|
||||||
{
|
{
|
||||||
transferEnergy += this.getEnergyStored();
|
transferEnergy += getEnergyStored();
|
||||||
this.setEnergyStored(0);
|
setEnergyStored(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.getControllingTelsa().transfer(transferEnergy, doTransfer);
|
return getControllingTelsa().transfer(transferEnergy, doTransfer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRange()
|
public int getRange()
|
||||||
{
|
{
|
||||||
return Math.min(4 * (this.getHeight() - 1), 50);
|
return Math.min(4 * (getHeight() - 1), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePositionStatus()
|
public void updatePositionStatus()
|
||||||
{
|
{
|
||||||
boolean isTop = new Vector3(this).translate(new Vector3(0, 1, 0)).getTileEntity(this.worldObj) instanceof TileEntityTesla;
|
boolean isTop = new Vector3(this).translate(new Vector3(0, 1, 0)).getTileEntity(worldObj) instanceof TileEntityTesla;
|
||||||
boolean isBottom = new Vector3(this).translate(new Vector3(0, -1, 0)).getTileEntity(this.worldObj) instanceof TileEntityTesla;
|
boolean isBottom = new Vector3(this).translate(new Vector3(0, -1, 0)).getTileEntity(worldObj) instanceof TileEntityTesla;
|
||||||
|
|
||||||
if (isTop && isBottom)
|
if(isTop && isBottom)
|
||||||
{
|
{
|
||||||
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, 1, 3);
|
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 3);
|
||||||
}
|
}
|
||||||
else if (isBottom)
|
else if(isBottom)
|
||||||
{
|
{
|
||||||
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, 2, 3);
|
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 2, 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, 0, 3);
|
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called only on bottom.
|
* Called only on bottom.
|
||||||
*
|
*
|
||||||
|
@ -418,36 +416,36 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
||||||
*/
|
*/
|
||||||
public TileEntityTesla getTopTelsa()
|
public TileEntityTesla getTopTelsa()
|
||||||
{
|
{
|
||||||
if (this.topCache != null)
|
if(topCache != null)
|
||||||
{
|
{
|
||||||
return this.topCache;
|
return topCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.connectedTeslas.clear();
|
connectedTeslas.clear();
|
||||||
Vector3 checkPosition = new Vector3(this);
|
Vector3 checkPosition = new Vector3(this);
|
||||||
TileEntityTesla returnTile = this;
|
TileEntityTesla returnTile = this;
|
||||||
|
|
||||||
while (true)
|
while(true)
|
||||||
{
|
{
|
||||||
TileEntity t = checkPosition.getTileEntity(this.worldObj);
|
TileEntity t = checkPosition.getTileEntity(worldObj);
|
||||||
|
|
||||||
if (t instanceof TileEntityTesla)
|
if(t instanceof TileEntityTesla)
|
||||||
{
|
{
|
||||||
this.connectedTeslas.add((TileEntityTesla) t);
|
connectedTeslas.add((TileEntityTesla)t);
|
||||||
returnTile = (TileEntityTesla) t;
|
returnTile = (TileEntityTesla)t;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPosition.y++;
|
checkPosition.y++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.topCache = returnTile;
|
topCache = returnTile;
|
||||||
return returnTile;
|
return returnTile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For non-controlling Tesla to use.
|
* For non-controlling Tesla to use.
|
||||||
*
|
*
|
||||||
|
@ -455,34 +453,34 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
||||||
*/
|
*/
|
||||||
public TileEntityTesla getControllingTelsa()
|
public TileEntityTesla getControllingTelsa()
|
||||||
{
|
{
|
||||||
if (this.controlCache != null)
|
if(controlCache != null)
|
||||||
{
|
{
|
||||||
return this.controlCache;
|
return controlCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 checkPosition = new Vector3(this);
|
Vector3 checkPosition = new Vector3(this);
|
||||||
TileEntityTesla returnTile = this;
|
TileEntityTesla returnTile = this;
|
||||||
|
|
||||||
while (true)
|
while(true)
|
||||||
{
|
{
|
||||||
TileEntity t = checkPosition.getTileEntity(this.worldObj);
|
TileEntity t = checkPosition.getTileEntity(worldObj);
|
||||||
|
|
||||||
if (t instanceof TileEntityTesla)
|
if(t instanceof TileEntityTesla)
|
||||||
{
|
{
|
||||||
returnTile = (TileEntityTesla) t;
|
returnTile = (TileEntityTesla)t;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPosition.y--;
|
checkPosition.y--;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.controlCache = returnTile;
|
controlCache = returnTile;
|
||||||
return returnTile;
|
return returnTile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called only on bottom.
|
* Called only on bottom.
|
||||||
*
|
*
|
||||||
|
@ -490,64 +488,64 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
||||||
*/
|
*/
|
||||||
public int getHeight()
|
public int getHeight()
|
||||||
{
|
{
|
||||||
this.connectedTeslas.clear();
|
connectedTeslas.clear();
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
while (true)
|
while(true)
|
||||||
{
|
{
|
||||||
TileEntity t = new Vector3(this).translate(new Vector3(0, y, 0)).getTileEntity(this.worldObj);
|
TileEntity t = new Vector3(this).translate(new Vector3(0, y, 0)).getTileEntity(worldObj);
|
||||||
|
|
||||||
if (t instanceof TileEntityTesla)
|
if(t instanceof TileEntityTesla)
|
||||||
{
|
{
|
||||||
this.connectedTeslas.add((TileEntityTesla) t);
|
connectedTeslas.add((TileEntityTesla)t);
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate()
|
public void invalidate()
|
||||||
{
|
{
|
||||||
TeslaGrid.instance().unregister(this);
|
TeslaGrid.instance().unregister(this);
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate()
|
public void validate()
|
||||||
{
|
{
|
||||||
super.validate();
|
super.validate();
|
||||||
|
|
||||||
if (worldObj.isRemote)
|
if(worldObj.isRemote)
|
||||||
{
|
{
|
||||||
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDye(int id)
|
public void setDye(int id)
|
||||||
{
|
{
|
||||||
this.dyeID = id;
|
dyeID = id;
|
||||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean toggleReceive()
|
public boolean toggleReceive()
|
||||||
{
|
{
|
||||||
return this.canReceive = !this.canReceive;
|
return canReceive = !canReceive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean toggleEntityAttack()
|
public boolean toggleEntityAttack()
|
||||||
{
|
{
|
||||||
boolean returnBool = this.attackEntities = !this.attackEntities;
|
boolean returnBool = attackEntities = !attackEntities;
|
||||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||||
return returnBool;
|
return returnBool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a tile entity from NBT.
|
* Reads a tile entity from NBT.
|
||||||
*/
|
*/
|
||||||
|
@ -555,17 +553,17 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
||||||
public void readFromNBT(NBTTagCompound nbt)
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
this.dyeID = nbt.getInteger("dyeID");
|
dyeID = nbt.getInteger("dyeID");
|
||||||
this.canReceive = nbt.getBoolean("canReceive");
|
canReceive = nbt.getBoolean("canReceive");
|
||||||
this.attackEntities = nbt.getBoolean("attackEntities");
|
attackEntities = nbt.getBoolean("attackEntities");
|
||||||
|
|
||||||
if (nbt.hasKey("link_x") && nbt.hasKey("link_y") && nbt.hasKey("link_z"))
|
if(nbt.hasKey("link_x") && nbt.hasKey("link_y") && nbt.hasKey("link_z"))
|
||||||
{
|
{
|
||||||
this.linked = new Vector3(nbt.getInteger("link_x"), nbt.getInteger("link_y"), nbt.getInteger("link_z"));
|
linked = new Vector3(nbt.getInteger("link_x"), nbt.getInteger("link_y"), nbt.getInteger("link_z"));
|
||||||
this.linkDim = nbt.getInteger("linkDim");
|
linkDim = nbt.getInteger("linkDim");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a tile entity to NBT.
|
* Writes a tile entity to NBT.
|
||||||
*/
|
*/
|
||||||
|
@ -573,81 +571,81 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
||||||
public void writeToNBT(NBTTagCompound nbt)
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
nbt.setInteger("dyeID", this.dyeID);
|
nbt.setInteger("dyeID", dyeID);
|
||||||
nbt.setBoolean("canReceive", this.canReceive);
|
nbt.setBoolean("canReceive", canReceive);
|
||||||
nbt.setBoolean("attackEntities", this.attackEntities);
|
nbt.setBoolean("attackEntities", attackEntities);
|
||||||
|
|
||||||
if (this.linked != null)
|
if(linked != null)
|
||||||
{
|
{
|
||||||
nbt.setInteger("link_x", (int) this.linked.x);
|
nbt.setInteger("link_x", (int)linked.x);
|
||||||
nbt.setInteger("link_y", (int) this.linked.y);
|
nbt.setInteger("link_y", (int)linked.y);
|
||||||
nbt.setInteger("link_z", (int) this.linked.z);
|
nbt.setInteger("link_z", (int)linked.z);
|
||||||
nbt.setInteger("linkDim", this.linkDim);
|
nbt.setInteger("linkDim", linkDim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLink(Vector3 vector3, int dimID, boolean setOpponent)
|
public void setLink(Vector3 vector3, int dimID, boolean setOpponent)
|
||||||
{
|
{
|
||||||
if (!this.worldObj.isRemote)
|
if(!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
World otherWorld = MinecraftServer.getServer().worldServerForDimension(this.linkDim);
|
World otherWorld = MinecraftServer.getServer().worldServerForDimension(linkDim);
|
||||||
|
|
||||||
if (setOpponent && this.linked != null && otherWorld != null)
|
if(setOpponent && linked != null && otherWorld != null)
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = this.linked.getTileEntity(otherWorld);
|
TileEntity tileEntity = linked.getTileEntity(otherWorld);
|
||||||
|
|
||||||
if (tileEntity instanceof TileEntityTesla)
|
if(tileEntity instanceof TileEntityTesla)
|
||||||
{
|
{
|
||||||
((TileEntityTesla) tileEntity).setLink(null, this.linkDim, false);
|
((TileEntityTesla)tileEntity).setLink(null, linkDim, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.linked = vector3;
|
linked = vector3;
|
||||||
this.linkDim = dimID;
|
linkDim = dimID;
|
||||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||||
|
|
||||||
World newOtherWorld = MinecraftServer.getServer().worldServerForDimension(this.linkDim);
|
World newOtherWorld = MinecraftServer.getServer().worldServerForDimension(linkDim);
|
||||||
|
|
||||||
if (setOpponent && newOtherWorld != null && this.linked != null)
|
if(setOpponent && newOtherWorld != null && linked != null)
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = this.linked.getTileEntity(newOtherWorld);
|
TileEntity tileEntity = linked.getTileEntity(newOtherWorld);
|
||||||
|
|
||||||
if (tileEntity instanceof TileEntityTesla)
|
if(tileEntity instanceof TileEntityTesla)
|
||||||
{
|
{
|
||||||
((TileEntityTesla) tileEntity).setLink(new Vector3(this), this.worldObj.provider.dimensionId, false);
|
((TileEntityTesla)tileEntity).setLink(new Vector3(this), worldObj.provider.dimensionId, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getRequest(ForgeDirection direction)
|
public float getRequest(ForgeDirection direction)
|
||||||
{
|
{
|
||||||
if (direction != ForgeDirection.DOWN)
|
if(direction != ForgeDirection.DOWN)
|
||||||
{
|
{
|
||||||
return this.getMaxEnergyStored() - this.getEnergyStored();
|
return getMaxEnergyStored() - getEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getProvide(ForgeDirection direction)
|
public float getProvide(ForgeDirection direction)
|
||||||
{
|
{
|
||||||
if (this.isController() && direction == ForgeDirection.DOWN)
|
if(isController() && direction == ForgeDirection.DOWN)
|
||||||
{
|
{
|
||||||
return this.getEnergyStored();
|
return getEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxEnergyStored()
|
public float getMaxEnergyStored()
|
||||||
{
|
{
|
||||||
return TRANSFER_CAP;
|
return TRANSFER_CAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<ForgeDirection> getInputDirections()
|
public EnumSet<ForgeDirection> getInputDirections()
|
||||||
{
|
{
|
||||||
|
@ -655,7 +653,7 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
|
||||||
input.remove(ForgeDirection.DOWN);
|
input.remove(ForgeDirection.DOWN);
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<ForgeDirection> getOutputDirections()
|
public EnumSet<ForgeDirection> getOutputDirections()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue