v5.5.4 Golden Master #1

*Fixed Sound volume update crash, thanks Cisien.
*Obsidian TNT can now be pushed like ICBM explosives.
*Refactored TileEntities to only operate on the server-side.
*Universal Cables and Mechanical Pipes now have their render state
updated on the server-side, and it is synced to the client whenever
necessary.
*Other various improvements -- liquid & energy transfer is now
server-based only.
This commit is contained in:
Aidan Brady 2013-04-21 23:43:04 -04:00
parent 4bb292d32a
commit 4f5ce2f9e9
18 changed files with 674 additions and 670 deletions

View file

@ -135,7 +135,7 @@ public class Sound
{
synchronized(Mekanism.audioHandler.sounds)
{
if(entityplayer.worldObj == tileEntity.worldObj)
if(entityplayer != null && tileEntity != null && entityplayer.worldObj == tileEntity.worldObj)
{
float volume = 0;

View file

@ -143,60 +143,55 @@ public class EnergyTransferProtocol
{
loopThrough(pointer);
boolean fill = FMLCommonHandler.instance().getEffectiveSide().isServer();
Collections.shuffle(availableAcceptors);
if(fill)
double prevNeeded = neededEnergy();
double prevSending = energyToSend;
if(!availableAcceptors.isEmpty())
{
if(!availableAcceptors.isEmpty())
int divider = availableAcceptors.size();
double remaining = energyToSend % divider;
double currentRemaining = remaining;
double sending = (energyToSend-remaining)/divider;
for(TileEntity acceptor : availableAcceptors)
{
int divider = availableAcceptors.size();
double remaining = energyToSend % divider;
double currentRemaining = remaining;
double sending = (energyToSend-remaining)/divider;
double currentSending = sending;
for(TileEntity acceptor : availableAcceptors)
if(currentRemaining > 0)
{
double currentSending = sending;
if(currentRemaining > 0)
{
currentSending += (currentRemaining/divider);
currentRemaining -= (currentRemaining/divider);
}
if(acceptor instanceof IStrictEnergyAcceptor)
{
energyToSend -= (currentSending - ((IStrictEnergyAcceptor)acceptor).transferEnergyToAcceptor(currentSending));
}
else if(acceptor instanceof IEnergySink)
{
double toSend = Math.min(currentSending, (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
energyToSend -= (toSend - (((IEnergySink)acceptor).injectEnergy(MekanismUtils.toIC2Direction(acceptorDirections.get(acceptor).getOpposite()), (int)(toSend*Mekanism.TO_IC2))*Mekanism.FROM_IC2));
}
else if(acceptor instanceof IPowerReceptor && Mekanism.hooks.BuildCraftLoaded)
{
IPowerReceptor receptor = (IPowerReceptor)acceptor;
double electricityNeeded = Math.min(receptor.powerRequest(acceptorDirections.get(acceptor).getOpposite()), receptor.getPowerProvider().getMaxEnergyStored() - receptor.getPowerProvider().getEnergyStored())*Mekanism.FROM_BC;
float transferEnergy = (float)Math.min(electricityNeeded, currentSending);
receptor.getPowerProvider().receiveEnergy((float)(transferEnergy*Mekanism.TO_BC), acceptorDirections.get(acceptor).getOpposite());
energyToSend -= transferEnergy;
}
currentSending += (currentRemaining/divider);
currentRemaining -= (currentRemaining/divider);
}
if(acceptor instanceof IStrictEnergyAcceptor)
{
energyToSend -= (currentSending - ((IStrictEnergyAcceptor)acceptor).transferEnergyToAcceptor(currentSending));
}
else if(acceptor instanceof IEnergySink)
{
double toSend = Math.min(currentSending, (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
energyToSend -= (toSend - (((IEnergySink)acceptor).injectEnergy(MekanismUtils.toIC2Direction(acceptorDirections.get(acceptor).getOpposite()), (int)(toSend*Mekanism.TO_IC2))*Mekanism.FROM_IC2));
}
else if(acceptor instanceof IPowerReceptor && Mekanism.hooks.BuildCraftLoaded)
{
IPowerReceptor receptor = (IPowerReceptor)acceptor;
double electricityNeeded = Math.min(receptor.powerRequest(acceptorDirections.get(acceptor).getOpposite()), receptor.getPowerProvider().getMaxEnergyStored() - receptor.getPowerProvider().getEnergyStored())*Mekanism.FROM_BC;
float transferEnergy = (float)Math.min(electricityNeeded, currentSending);
receptor.getPowerProvider().receiveEnergy((float)(transferEnergy*Mekanism.TO_BC), acceptorDirections.get(acceptor).getOpposite());
energyToSend -= transferEnergy;
}
}
}
else {
double needed = neededEnergy();
if(needed > 0 && energyToSend > 0)
if(prevNeeded > 0 && prevSending > 0)
{
for(TileEntity tileEntity : iteratedCables)
{
for(TileEntity tileEntity : iteratedCables)
if(tileEntity instanceof IUniversalCable)
{
if(tileEntity instanceof IUniversalCable)
{
((IUniversalCable)tileEntity).onTransfer();
}
((IUniversalCable)tileEntity).onTransfer();
}
}
}

View file

@ -50,6 +50,12 @@ public class EntityObsidianTNT extends Entity
return !isDead;
}
@Override
public boolean canBePushed()
{
return true;
}
@Override
public void onUpdate()
{

View file

@ -58,7 +58,7 @@ public class ItemBlockTransmitter extends ItemBlock
else if(itemstack.getItemDamage() == 2)
{
list.add(EnumColor.DARK_GREY + "Capable of transferring:");
list.add("- " + EnumColor.PURPLE + "mB " + EnumColor.GREY + "(LiquidDictionary)");
list.add("- " + EnumColor.PURPLE + "mB " + EnumColor.GREY + "(Liquid Dictionary)");
}
}
}

View file

@ -150,7 +150,6 @@ public class LiquidTransferProtocol
{
loopThrough(pointer);
boolean fill = FMLCommonHandler.instance().getEffectiveSide().isServer();
Collections.shuffle(availableAcceptors);
int liquidSent = 0;
@ -187,7 +186,7 @@ public class LiquidTransferProtocol
tankRemaining--;
}
liquidSent += acceptor.fill(acceptorDirections.get(acceptor), new LiquidStack(liquidToSend.itemID, tankCurrentSending, liquidToSend.itemMeta), fill);
liquidSent += acceptor.fill(acceptorDirections.get(acceptor), new LiquidStack(liquidToSend.itemID, tankCurrentSending, liquidToSend.itemMeta), true);
}
}
else {
@ -195,13 +194,13 @@ public class LiquidTransferProtocol
{
ILiquidTank tank = acceptor.getTank(acceptorDirections.get(acceptor), liquidToSend);
liquidSent += acceptor.fill(acceptorDirections.get(acceptor), new LiquidStack(liquidToSend.itemID, currentSending, liquidToSend.itemMeta), fill);
liquidSent += acceptor.fill(acceptorDirections.get(acceptor), new LiquidStack(liquidToSend.itemID, currentSending, liquidToSend.itemMeta), true);
}
}
}
}
if(!fill && liquidSent > 0)
if(liquidSent > 0)
{
for(TileEntity tileEntity : iteratedPipes)
{
@ -212,8 +211,6 @@ public class LiquidTransferProtocol
((IMechanicalPipe)tileEntity).onTransfer(sendStack);
}
}
return 0;
}
return liquidSent;

View file

@ -74,114 +74,109 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
{
super.onUpdate();
boolean testActive = operatingTicks > 0;
if(inventory[3] != null)
if(!worldObj.isRemote)
{
if(electricityStored < MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY))
if(inventory[3] != null)
{
setJoules(getJoules() + ElectricItemHelper.dechargeItem(inventory[3], getMaxJoules() - getJoules(), getVoltage()));
if(Mekanism.hooks.IC2Loaded && inventory[3].getItem() instanceof IElectricItem)
if(electricityStored < MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY))
{
IElectricItem item = (IElectricItem)inventory[3].getItem();
if(item.canProvideEnergy(inventory[3]))
setJoules(getJoules() + ElectricItemHelper.dechargeItem(inventory[3], getMaxJoules() - getJoules(), getVoltage()));
if(Mekanism.hooks.IC2Loaded && inventory[3].getItem() instanceof IElectricItem)
{
double gain = ElectricItem.discharge(inventory[3], (int)((MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY) - electricityStored)*Mekanism.TO_IC2), 3, false, false)*Mekanism.FROM_IC2;
setJoules(electricityStored + gain);
IElectricItem item = (IElectricItem)inventory[3].getItem();
if(item.canProvideEnergy(inventory[3]))
{
double gain = ElectricItem.discharge(inventory[3], (int)((MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY) - electricityStored)*Mekanism.TO_IC2), 3, false, false)*Mekanism.FROM_IC2;
setJoules(electricityStored + gain);
}
}
}
}
if(inventory[3].itemID == Item.redstone.itemID && electricityStored+1000 <= MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY))
{
setJoules(electricityStored + 1000);
inventory[3].stackSize--;
if(inventory[3].stackSize <= 0)
{
inventory[3] = null;
}
}
}
if(inventory[4] != null)
{
if(inventory[4].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
if(inventory[3].itemID == Item.redstone.itemID && electricityStored+1000 <= MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY))
{
upgradeTicks++;
setJoules(electricityStored + 1000);
inventory[3].stackSize--;
if(inventory[3].stackSize <= 0)
{
inventory[3] = null;
}
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
}
if(inventory[4] != null)
{
if(inventory[4].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[4].stackSize--;
if(inventory[4].stackSize == 0)
{
inventory[4] = null;
}
}
}
else if(inventory[4].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[4].stackSize--;
if(inventory[4].stackSize == 0)
{
inventory[4] = null;
}
}
}
else {
upgradeTicks = 0;
energyMultiplier++;
inventory[4].stackSize--;
if(inventory[4].stackSize == 0)
{
inventory[4] = null;
}
}
}
else if(inventory[4].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[4].stackSize--;
if(inventory[4].stackSize == 0)
{
inventory[4] = null;
}
}
}
else {
upgradeTicks = 0;
}
}
else {
upgradeTicks = 0;
}
handleSecondaryFuel();
if(electricityStored >= ENERGY_PER_TICK && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK)
{
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED) && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK)
handleSecondaryFuel();
if(electricityStored >= ENERGY_PER_TICK && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK)
{
operatingTicks++;
secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK;
electricityStored -= ENERGY_PER_TICK;
}
else if((operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
if(!worldObj.isRemote)
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED) && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK)
{
operatingTicks++;
secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK;
electricityStored -= ENERGY_PER_TICK;
}
else if((operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
operate();
operatingTicks = 0;
secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK;
electricityStored -= ENERGY_PER_TICK;
}
operatingTicks = 0;
secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK;
electricityStored -= ENERGY_PER_TICK;
}
}
if(!canOperate())
{
operatingTicks = 0;
}
if(!worldObj.isRemote)
{
if(!canOperate())
{
operatingTicks = 0;
}
if(canOperate() && electricityStored >= ENERGY_PER_TICK && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK)
{
setActive(true);

View file

@ -36,11 +36,9 @@ public abstract class TileEntityBasicBlock extends TileEntityDisableable impleme
{
if(playersUsing > 0)
{
if(packetTick % 3 == 0)
{
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
packetTick++;
}
}

View file

@ -34,10 +34,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
/** BuildCraft power provider. */
public IPowerProvider powerProvider;
public boolean prevFull;
public boolean prevEmpty;
/**
* The base of all blocks that deal with electricity. It has a facing state, initialized state,
* and a current amount of stored energy.
@ -73,14 +69,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
{
ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, getConsumingSides(), getRequest());
setJoules(getJoules()+electricityPack.getWatts());
if(prevFull != (getMaxEnergy() == getEnergy()) || prevEmpty != (getEnergy() == 0))
{
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
prevFull = getMaxEnergy() == getEnergy();
prevEmpty = getEnergy() == 0;
}
}

View file

@ -43,82 +43,84 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
{
super.onUpdate();
ChargeUtils.discharge(1, this);
if(inventory[3] != null)
if(worldObj.isRemote)
{
if(inventory[3].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
System.out.println(electricityStored);
}
if(!worldObj.isRemote)
{
ChargeUtils.discharge(1, this);
if(inventory[3] != null)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
if(inventory[3].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[3].stackSize--;
if(inventory[3].stackSize == 0)
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
inventory[3] = null;
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[3].stackSize--;
if(inventory[3].stackSize == 0)
{
inventory[3] = null;
}
}
}
}
else if(inventory[3].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
else if(inventory[3].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[3].stackSize--;
if(inventory[3].stackSize == 0)
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
inventory[3] = null;
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[3].stackSize--;
if(inventory[3].stackSize == 0)
{
inventory[3] = null;
}
}
}
else {
upgradeTicks = 0;
}
}
else {
upgradeTicks = 0;
}
}
else {
upgradeTicks = 0;
}
if(electricityStored >= ENERGY_PER_TICK)
{
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
if(electricityStored >= ENERGY_PER_TICK)
{
operatingTicks++;
electricityStored -= ENERGY_PER_TICK;
}
else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
if(!worldObj.isRemote)
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
operatingTicks++;
electricityStored -= ENERGY_PER_TICK;
}
else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
operate();
operatingTicks = 0;
electricityStored -= ENERGY_PER_TICK;
}
operatingTicks = 0;
electricityStored -= ENERGY_PER_TICK;
}
}
if(!canOperate())
{
operatingTicks = 0;
}
if(!worldObj.isRemote)
{
if(!canOperate())
{
operatingTicks = 0;
}
if(canOperate() && electricityStored >= ENERGY_PER_TICK)
{
setActive(true);

View file

@ -67,19 +67,18 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
ChargeUtils.charge(0, this);
ChargeUtils.discharge(1, this);
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
if(electricityStored > 0)
if(!worldObj.isRemote)
{
if(tileEntity instanceof IUniversalCable)
{
setJoules(electricityStored - (Math.min(electricityStored, tier.OUTPUT) - CableUtils.emitEnergyToNetwork(Math.min(electricityStored, tier.OUTPUT), this, ForgeDirection.getOrientation(facing))));
return;
}
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
if(!worldObj.isRemote)
if(electricityStored > 0)
{
if((tileEntity instanceof IEnergyConductor || tileEntity instanceof IEnergyAcceptor) && Mekanism.hooks.IC2Loaded)
if(tileEntity instanceof IUniversalCable)
{
setJoules(electricityStored - (Math.min(electricityStored, tier.OUTPUT) - CableUtils.emitEnergyToNetwork(Math.min(electricityStored, tier.OUTPUT), this, ForgeDirection.getOrientation(facing))));
return;
}
else if((tileEntity instanceof IEnergyConductor || tileEntity instanceof IEnergyAcceptor) && Mekanism.hooks.IC2Loaded)
{
if(electricityStored >= tier.OUTPUT)
{
@ -97,40 +96,40 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
setJoules(electricityStored - transferEnergy);
}
}
}
if(!worldObj.isRemote && tileEntity instanceof IConductor)
{
ForgeDirection outputDirection = ForgeDirection.getOrientation(facing);
ArrayList<IElectricityNetwork> inputNetworks = new ArrayList<IElectricityNetwork>();
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
if(tileEntity instanceof IConductor)
{
if(direction != outputDirection)
ForgeDirection outputDirection = ForgeDirection.getOrientation(facing);
ArrayList<IElectricityNetwork> inputNetworks = new ArrayList<IElectricityNetwork>();
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
IElectricityNetwork network = ElectricityNetworkHelper.getNetworkFromTileEntity(VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), direction), direction);
if(network != null)
if(direction != outputDirection)
{
inputNetworks.add(network);
IElectricityNetwork network = ElectricityNetworkHelper.getNetworkFromTileEntity(VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), direction), direction);
if(network != null)
{
inputNetworks.add(network);
}
}
}
}
TileEntity outputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if(outputNetwork != null && !inputNetworks.contains(outputNetwork))
{
double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getJoules(), 10000));
if(getJoules() > 0 && outputWatts > 0 && getJoules()-outputWatts >= 0)
TileEntity outputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if(outputNetwork != null && !inputNetworks.contains(outputNetwork))
{
outputNetwork.startProducing(this, Math.min(outputWatts, getJoules()) / getVoltage(), getVoltage());
setJoules(electricityStored - outputWatts);
}
else {
outputNetwork.stopProducing(this);
double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getJoules(), 10000));
if(getJoules() > 0 && outputWatts > 0 && getJoules()-outputWatts >= 0)
{
outputNetwork.startProducing(this, Math.min(outputWatts, getJoules()) / getVoltage(), getVoltage());
setJoules(electricityStored - outputWatts);
}
else {
outputNetwork.stopProducing(this);
}
}
}
}

View file

@ -104,112 +104,102 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
Mekanism.proxy.registerSound(this);
}
boolean testActive = false;
for(int i : progress)
if(!worldObj.isRemote)
{
if(i > 0)
ChargeUtils.discharge(1, this);
if(inventory[0] != null)
{
testActive = true;
}
}
ChargeUtils.discharge(1, this);
if(inventory[0] != null)
{
if(inventory[0].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
if(inventory[0].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
inventory[0] = null;
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
}
}
}
else if(inventory[0].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
else if(inventory[0].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
inventory[0] = null;
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
}
}
else {
upgradeTicks = 0;
}
}
else {
upgradeTicks = 0;
}
}
else {
upgradeTicks = 0;
}
for(int process = 0; process < tier.processes; process++)
{
if(electricityStored >= ENERGY_PER_TICK)
for(int process = 0; process < tier.processes; process++)
{
if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
if(electricityStored >= ENERGY_PER_TICK)
{
progress[process]++;
electricityStored -= ENERGY_PER_TICK;
}
else if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
if(!worldObj.isRemote)
if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
progress[process]++;
electricityStored -= ENERGY_PER_TICK;
}
else if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
operate(getInputSlot(process), getOutputSlot(process));
progress[process] = 0;
electricityStored -= ENERGY_PER_TICK;
}
progress[process] = 0;
electricityStored -= ENERGY_PER_TICK;
}
}
if(!canOperate(getInputSlot(process), getOutputSlot(process)))
{
progress[process] = 0;
}
}
if(!worldObj.isRemote)
{
boolean hasOperation = false;
for(int i = 0; i < tier.processes; i++)
{
if(canOperate(getInputSlot(i), getOutputSlot(i)))
if(!canOperate(getInputSlot(process), getOutputSlot(process)))
{
hasOperation = true;
break;
progress[process] = 0;
}
}
if(hasOperation && electricityStored >= ENERGY_PER_TICK)
if(!worldObj.isRemote)
{
setActive(true);
}
else {
setActive(false);
boolean hasOperation = false;
for(int i = 0; i < tier.processes; i++)
{
if(canOperate(getInputSlot(i), getOutputSlot(i)))
{
hasOperation = true;
break;
}
}
if(hasOperation && electricityStored >= ENERGY_PER_TICK)
{
setActive(true);
}
else {
setActive(false);
}
}
}
}

View file

@ -25,13 +25,15 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
{
public LiquidTank dummyTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
public LiquidStack prevLiquid;
public LiquidStack refLiquid = null;
public boolean isActive = false;
public float liquidScale;
public float prevRoundedScale;
public float prevScale;
@Override
public boolean canTransferLiquids(TileEntity fromTile)
@ -56,41 +58,41 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
@Override
public void updateEntity()
{
if(liquidScale > 0)
if(!worldObj.isRemote)
{
liquidScale -= .01;
}
else {
refLiquid = null;
}
if(worldObj.isRemote)
{
float roundedScale = liquidScale*16F;
if(roundedScale != prevRoundedScale)
if(liquidScale != prevScale || refLiquid != prevLiquid)
{
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
prevScale = liquidScale;
prevLiquid = refLiquid;
if(liquidScale > 0)
{
liquidScale -= .01;
}
else {
refLiquid = null;
}
prevRoundedScale = roundedScale;
}
if(isActive)
{
ITankContainer[] connectedAcceptors = PipeUtils.getConnectedAcceptors(this);
for(ITankContainer container : connectedAcceptors)
if(isActive)
{
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(connectedAcceptors).indexOf(container)).getOpposite();
ITankContainer[] connectedAcceptors = PipeUtils.getConnectedAcceptors(this);
if(container != null)
for(ITankContainer container : connectedAcceptors)
{
LiquidStack received = container.drain(side, 100, false);
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(connectedAcceptors).indexOf(container)).getOpposite();
if(received != null && received.amount != 0)
if(container != null)
{
container.drain(side, new LiquidTransferProtocol(this, VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), side.getOpposite()), received).calculate(), true);
LiquidStack received = container.drain(side, 100, false);
if(received != null && received.amount != 0)
{
container.drain(side, new LiquidTransferProtocol(this, VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), side.getOpposite()), received).calculate(), true);
}
}
}
}
@ -118,12 +120,30 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
public void handlePacketData(ByteArrayDataInput dataStream)
{
isActive = dataStream.readBoolean();
liquidScale = dataStream.readFloat();
if(dataStream.readInt() == 1)
{
refLiquid = new LiquidStack(dataStream.readInt(), LiquidContainerRegistry.BUCKET_VOLUME, dataStream.readInt());
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(isActive);
data.add(liquidScale);
if(refLiquid != null)
{
data.add(1);
data.add(refLiquid.itemID);
data.add(refLiquid.itemMeta);
}
else {
data.add(0);
}
return data;
}

View file

@ -106,113 +106,108 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
Mekanism.proxy.registerSound(this);
}
boolean testActive = operatingTicks > 0;
ChargeUtils.discharge(4, this);
if(inventory[0] != null)
if(!worldObj.isRemote)
{
if(inventory[0].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
ChargeUtils.discharge(4, this);
if(inventory[0] != null)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
if(inventory[0].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
inventory[0] = null;
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
}
}
}
else if(inventory[0].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
else if(inventory[0].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
inventory[0] = null;
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
}
}
else {
upgradeTicks = 0;
}
}
else {
upgradeTicks = 0;
}
}
else {
upgradeTicks = 0;
}
if(inventory[1] != null)
{
if(MekanismUtils.getInfuseObject(inventory[1]) != null)
if(inventory[1] != null)
{
InfuseObject infuse = MekanismUtils.getInfuseObject(inventory[1]);
if(type == InfusionType.NONE || type == infuse.type)
if(MekanismUtils.getInfuseObject(inventory[1]) != null)
{
if(infuseStored+infuse.stored <= MAX_INFUSE)
InfuseObject infuse = MekanismUtils.getInfuseObject(inventory[1]);
if(type == InfusionType.NONE || type == infuse.type)
{
infuseStored+=infuse.stored;
type = infuse.type;
inventory[1].stackSize--;
if(inventory[1].stackSize <= 0)
{
inventory[1] = null;
}
if(infuseStored+infuse.stored <= MAX_INFUSE)
{
infuseStored+=infuse.stored;
type = infuse.type;
inventory[1].stackSize--;
if(inventory[1].stackSize <= 0)
{
inventory[1] = null;
}
}
}
}
}
}
if(electricityStored >= ENERGY_PER_TICK)
{
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
if(electricityStored >= ENERGY_PER_TICK)
{
operatingTicks++;
electricityStored -= ENERGY_PER_TICK;
}
else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
if(!worldObj.isRemote)
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
operatingTicks++;
electricityStored -= ENERGY_PER_TICK;
}
else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{
operate();
operatingTicks = 0;
electricityStored -= ENERGY_PER_TICK;
}
operatingTicks = 0;
electricityStored -= ENERGY_PER_TICK;
}
}
if(!canOperate())
{
operatingTicks = 0;
}
if(infuseStored <= 0)
{
infuseStored = 0;
type = InfusionType.NONE;
}
if(!worldObj.isRemote)
{
if(!canOperate())
{
operatingTicks = 0;
}
if(infuseStored <= 0)
{
infuseStored = 0;
type = InfusionType.NONE;
}
if(canOperate() && electricityStored >= ENERGY_PER_TICK)
{
setActive(true);

View file

@ -2,6 +2,8 @@ package mekanism.common;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -14,15 +16,17 @@ import universalelectricity.core.vector.VectorHelper;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import mekanism.api.IUniversalCable;
public class TileEntityUniversalCable extends TileEntity implements IUniversalCable, IPowerReceptor
public class TileEntityUniversalCable extends TileEntity implements IUniversalCable, IPowerReceptor, ITileNetwork
{
public CablePowerProvider powerProvider;
public float liquidScale;
public float prevRoundedScale;
public float prevScale;
public TileEntityUniversalCable()
{
@ -36,24 +40,47 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
@Override
public void updateEntity()
{
if(liquidScale > 0)
if(!worldObj.isRemote)
{
liquidScale -= .01;
if(liquidScale != prevScale)
{
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
prevScale = liquidScale;
if(liquidScale > 0)
{
liquidScale -= .01;
}
}
}
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
float roundedScale = liquidScale*16F;
if(roundedScale != prevRoundedScale)
{
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
}
prevRoundedScale = roundedScale;
PacketHandler.sendDataRequest(this);
}
}
@Override
public void handlePacketData(ByteArrayDataInput dataStream)
{
liquidScale = dataStream.readFloat();
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(liquidScale);
return data;
}
@Override
public boolean canTransferEnergy(TileEntity fromTile)
{

View file

@ -85,136 +85,130 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{
super.onUpdate();
ChargeUtils.discharge(3, this);
if(inventory[0] != null)
{
LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(inventory[0]);
if(liquid != null && liquid.itemID == Block.waterStill.blockID)
{
if(waterTank.getLiquid() == null || waterTank.getLiquid().amount+liquid.amount <= waterTank.getCapacity())
{
waterTank.fill(liquid, true);
if(inventory[0].isItemEqual(new ItemStack(Item.bucketWater)))
{
inventory[0] = new ItemStack(Item.bucketEmpty);
}
else {
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
}
}
}
}
if(!worldObj.isRemote)
{
if(inventory[1] != null && hydrogenStored > 0)
ChargeUtils.discharge(3, this);
if(inventory[0] != null)
{
if(inventory[1].getItem() instanceof IStorageTank)
LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(inventory[0]);
if(liquid != null && liquid.itemID == Block.waterStill.blockID)
{
if(((IStorageTank)inventory[1].getItem()).getGasType(inventory[1]) == EnumGas.HYDROGEN || ((IStorageTank)inventory[1].getItem()).getGasType(inventory[1]) == EnumGas.NONE)
if(waterTank.getLiquid() == null || waterTank.getLiquid().amount+liquid.amount <= waterTank.getCapacity())
{
IStorageTank item = (IStorageTank)inventory[1].getItem();
waterTank.fill(liquid, true);
if(item.canReceiveGas(inventory[1], EnumGas.HYDROGEN))
if(inventory[0].isItemEqual(new ItemStack(Item.bucketWater)))
{
int sendingGas = 0;
inventory[0] = new ItemStack(Item.bucketEmpty);
}
else {
inventory[0].stackSize--;
if(item.getRate() <= hydrogenStored)
if(inventory[0].stackSize == 0)
{
sendingGas = item.getRate();
inventory[0] = null;
}
else if(item.getRate() > hydrogenStored)
{
sendingGas = hydrogenStored;
}
int rejects = item.addGas(inventory[1], EnumGas.HYDROGEN, sendingGas);
setGas(EnumGas.HYDROGEN, hydrogenStored - (sendingGas - rejects));
}
}
}
}
if(inventory[2] != null && oxygenStored > 0)
if(!worldObj.isRemote)
{
if(inventory[2].getItem() instanceof IStorageTank)
if(inventory[1] != null && hydrogenStored > 0)
{
if(((IStorageTank)inventory[2].getItem()).getGasType(inventory[2]) == EnumGas.OXYGEN || ((IStorageTank)inventory[2].getItem()).getGasType(inventory[2]) == EnumGas.NONE)
if(inventory[1].getItem() instanceof IStorageTank)
{
IStorageTank item = (IStorageTank)inventory[2].getItem();
if(item.canReceiveGas(inventory[2], EnumGas.OXYGEN))
if(((IStorageTank)inventory[1].getItem()).getGasType(inventory[1]) == EnumGas.HYDROGEN || ((IStorageTank)inventory[1].getItem()).getGasType(inventory[1]) == EnumGas.NONE)
{
int sendingGas = 0;
IStorageTank item = (IStorageTank)inventory[1].getItem();
if(item.getRate() <= oxygenStored)
if(item.canReceiveGas(inventory[1], EnumGas.HYDROGEN))
{
sendingGas = item.getRate();
}
else if(item.getRate() > oxygenStored)
{
sendingGas = oxygenStored;
int sendingGas = 0;
if(item.getRate() <= hydrogenStored)
{
sendingGas = item.getRate();
}
else if(item.getRate() > hydrogenStored)
{
sendingGas = hydrogenStored;
}
int rejects = item.addGas(inventory[1], EnumGas.HYDROGEN, sendingGas);
setGas(EnumGas.HYDROGEN, hydrogenStored - (sendingGas - rejects));
}
}
}
}
if(inventory[2] != null && oxygenStored > 0)
{
if(inventory[2].getItem() instanceof IStorageTank)
{
if(((IStorageTank)inventory[2].getItem()).getGasType(inventory[2]) == EnumGas.OXYGEN || ((IStorageTank)inventory[2].getItem()).getGasType(inventory[2]) == EnumGas.NONE)
{
IStorageTank item = (IStorageTank)inventory[2].getItem();
int rejects = item.addGas(inventory[2], EnumGas.OXYGEN, sendingGas);
setGas(EnumGas.OXYGEN, oxygenStored - (sendingGas - rejects));
if(item.canReceiveGas(inventory[2], EnumGas.OXYGEN))
{
int sendingGas = 0;
if(item.getRate() <= oxygenStored)
{
sendingGas = item.getRate();
}
else if(item.getRate() > oxygenStored)
{
sendingGas = oxygenStored;
}
int rejects = item.addGas(inventory[2], EnumGas.OXYGEN, sendingGas);
setGas(EnumGas.OXYGEN, oxygenStored - (sendingGas - rejects));
}
}
}
}
}
}
if(oxygenStored < MAX_GAS && hydrogenStored < MAX_GAS && waterTank.getLiquid() != null && waterTank.getLiquid().amount-2 >= 0 && electricityStored-100 > 0)
{
waterTank.drain(2, true);
setJoules(electricityStored - 10);
setGas(EnumGas.OXYGEN, oxygenStored + 1);
setGas(EnumGas.HYDROGEN, hydrogenStored + 2);
}
if(outputType != EnumGas.NONE && getGas(outputType) > 0 && !worldObj.isRemote)
{
setGas(outputType, getGas(outputType) - (Math.min(getGas(outputType), output) - GasTransmission.emitGasToNetwork(outputType, Math.min(getGas(outputType), output), this, ForgeDirection.getOrientation(facing))));
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
if(tileEntity instanceof IGasAcceptor)
if(oxygenStored < MAX_GAS && hydrogenStored < MAX_GAS && waterTank.getLiquid() != null && waterTank.getLiquid().amount-2 >= 0 && electricityStored-100 > 0)
{
if(((IGasAcceptor)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), outputType))
waterTank.drain(2, true);
setEnergy(electricityStored - 10);
setGas(EnumGas.OXYGEN, oxygenStored + 1);
setGas(EnumGas.HYDROGEN, hydrogenStored + 2);
}
if(outputType != EnumGas.NONE && getGas(outputType) > 0)
{
setGas(outputType, getGas(outputType) - (Math.min(getGas(outputType), output) - GasTransmission.emitGasToNetwork(outputType, Math.min(getGas(outputType), output), this, ForgeDirection.getOrientation(facing))));
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
if(tileEntity instanceof IGasAcceptor)
{
int sendingGas = 0;
if(getGas(outputType) >= output)
if(((IGasAcceptor)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), outputType))
{
sendingGas = output;
int sendingGas = 0;
if(getGas(outputType) >= output)
{
sendingGas = output;
}
else if(getGas(outputType) < output)
{
sendingGas = getGas(outputType);
}
int rejects = ((IGasAcceptor)tileEntity).transferGasToAcceptor(sendingGas, outputType);
setGas(outputType, getGas(outputType) - (sendingGas - rejects));
}
else if(getGas(outputType) < output)
{
sendingGas = getGas(outputType);
}
int rejects = ((IGasAcceptor)tileEntity).transferGasToAcceptor(sendingGas, outputType);
setGas(outputType, getGas(outputType) - (sendingGas - rejects));
}
}
}
if(dumpType != EnumGas.NONE && getGas(dumpType) > 0)
{
setGas(dumpType, (getGas(dumpType) - 8));
spawnParticle();
}
if(!worldObj.isRemote)
{
if(prevTankFull != (waterTank.getLiquid() != null && waterTank.getLiquid().amount == waterTank.getCapacity()) || prevTankEmpty != (waterTank.getLiquid() == null || waterTank.getLiquid().amount == 0))
{
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
@ -223,6 +217,16 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
prevTankFull = waterTank.getLiquid() != null && waterTank.getLiquid().amount == waterTank.getCapacity();
prevTankEmpty = waterTank.getLiquid() == null;
}
if(dumpType != EnumGas.NONE && getGas(dumpType) > 0)
{
if(!worldObj.isRemote)
{
setGas(dumpType, (getGas(dumpType) - 8));
}
spawnParticle();
}
}
public void spawnParticle()

View file

@ -84,56 +84,58 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
}
}
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
if(electricityStored > 0)
if(!worldObj.isRemote)
{
if(tileEntity instanceof IUniversalCable)
{
setJoules(electricityStored - (Math.min(electricityStored, output) - CableUtils.emitEnergyToNetwork(Math.min(electricityStored, output), this, ForgeDirection.getOrientation(facing))));
}
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
if(!worldObj.isRemote)
if(electricityStored > 0)
{
if((tileEntity instanceof IEnergyConductor || tileEntity instanceof IEnergyAcceptor) && Mekanism.hooks.IC2Loaded)
if(tileEntity instanceof IUniversalCable)
{
if(electricityStored >= output)
setJoules(electricityStored - (Math.min(electricityStored, output) - CableUtils.emitEnergyToNetwork(Math.min(electricityStored, output), this, ForgeDirection.getOrientation(facing))));
}
if(!worldObj.isRemote)
{
if((tileEntity instanceof IEnergyConductor || tileEntity instanceof IEnergyAcceptor) && Mekanism.hooks.IC2Loaded)
{
EnergyTileSourceEvent event = new EnergyTileSourceEvent(this, output);
MinecraftForge.EVENT_BUS.post(event);
setJoules(electricityStored - (output - event.amount));
if(electricityStored >= output)
{
EnergyTileSourceEvent event = new EnergyTileSourceEvent(this, output);
MinecraftForge.EVENT_BUS.post(event);
setJoules(electricityStored - (output - event.amount));
}
}
else if(isPowerReceptor(tileEntity) && Mekanism.hooks.BuildCraftLoaded)
{
IPowerReceptor receptor = (IPowerReceptor)tileEntity;
double electricityNeeded = Math.min(receptor.powerRequest(ForgeDirection.getOrientation(facing).getOpposite()), receptor.getPowerProvider().getMaxEnergyStored() - receptor.getPowerProvider().getEnergyStored())*Mekanism.FROM_BC;
float transferEnergy = (float)Math.min(electricityStored, Math.min(electricityNeeded, output));
receptor.getPowerProvider().receiveEnergy((float)(transferEnergy*Mekanism.TO_BC), ForgeDirection.getOrientation(facing).getOpposite());
setJoules(electricityStored - transferEnergy);
}
}
else if(isPowerReceptor(tileEntity) && Mekanism.hooks.BuildCraftLoaded)
{
IPowerReceptor receptor = (IPowerReceptor)tileEntity;
double electricityNeeded = Math.min(receptor.powerRequest(ForgeDirection.getOrientation(facing).getOpposite()), receptor.getPowerProvider().getMaxEnergyStored() - receptor.getPowerProvider().getEnergyStored())*Mekanism.FROM_BC;
float transferEnergy = (float)Math.min(electricityStored, Math.min(electricityNeeded, output));
receptor.getPowerProvider().receiveEnergy((float)(transferEnergy*Mekanism.TO_BC), ForgeDirection.getOrientation(facing).getOpposite());
setJoules(electricityStored - transferEnergy);
}
}
}
if(!worldObj.isRemote && tileEntity instanceof IConductor)
{
ForgeDirection outputDirection = ForgeDirection.getOrientation(facing);
TileEntity outputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if(outputNetwork != null)
if(!worldObj.isRemote && tileEntity instanceof IConductor)
{
double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getJoules(), 10000));
if(getJoules() > 0 && outputWatts > 0 && getJoules()-outputWatts >= 0)
ForgeDirection outputDirection = ForgeDirection.getOrientation(facing);
TileEntity outputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if(outputNetwork != null)
{
outputNetwork.startProducing(this, outputWatts / getVoltage(), getVoltage());
setJoules(electricityStored - outputWatts);
}
else {
outputNetwork.stopProducing(this);
double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getJoules(), 10000));
if(getJoules() > 0 && outputWatts > 0 && getJoules()-outputWatts >= 0)
{
outputNetwork.startProducing(this, outputWatts / getVoltage(), getVoltage());
setJoules(electricityStored - outputWatts);
}
else {
outputNetwork.stopProducing(this);
}
}
}
}

View file

@ -54,24 +54,44 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements ITan
{
super.onUpdate();
ChargeUtils.charge(1, this);
if(inventory[0] != null)
if(!worldObj.isRemote)
{
LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(inventory[0]);
ChargeUtils.charge(1, this);
if(liquid != null && liquid.itemID == Block.lavaStill.blockID)
if(inventory[0] != null)
{
if(lavaTank.getLiquid() == null || lavaTank.getLiquid().amount+liquid.amount <= lavaTank.getCapacity())
LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(inventory[0]);
if(liquid != null && liquid.itemID == Block.lavaStill.blockID)
{
lavaTank.fill(liquid, true);
if(inventory[0].isItemEqual(new ItemStack(Item.bucketLava)))
if(lavaTank.getLiquid() == null || lavaTank.getLiquid().amount+liquid.amount <= lavaTank.getCapacity())
{
inventory[0] = new ItemStack(Item.bucketEmpty);
lavaTank.fill(liquid, true);
if(inventory[0].isItemEqual(new ItemStack(Item.bucketLava)))
{
inventory[0] = new ItemStack(Item.bucketEmpty);
}
else {
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
}
}
else {
inventory[0].stackSize--;
}
else {
int fuel = getFuel(inventory[0]);
if(fuel > 0)
{
int fuelNeeded = lavaTank.getCapacity() - (lavaTank.getLiquid() != null ? lavaTank.getLiquid().amount : 0);
if(fuel <= fuelNeeded)
{
lavaTank.fill(new LiquidStack(Block.lavaStill.blockID, fuel), true);
inventory[0].stackSize--;
}
if(inventory[0].stackSize == 0)
{
@ -80,46 +100,20 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements ITan
}
}
}
else {
int fuel = getFuel(inventory[0]);
if(fuel > 0)
{
int fuelNeeded = lavaTank.getCapacity() - (lavaTank.getLiquid() != null ? lavaTank.getLiquid().amount : 0);
if(fuel <= fuelNeeded)
{
lavaTank.fill(new LiquidStack(Block.lavaStill.blockID, fuel), true);
inventory[0].stackSize--;
}
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
}
}
}
setJoules(electricityStored + getEnvironmentBoost());
if(canOperate())
{
if(!worldObj.isRemote)
{
setActive(true);
}
lavaTank.drain(10, true);
setJoules(electricityStored + GENERATION);
}
else {
if(!worldObj.isRemote)
{
setJoules(electricityStored + getEnvironmentBoost());
if(canOperate())
{
setActive(true);
lavaTank.drain(10, true);
setJoules(electricityStored + GENERATION);
}
else {
setActive(false);
}
}
if(!worldObj.isRemote)
{
if(prevTankFull != (lavaTank.getLiquid() != null && lavaTank.getLiquid().amount == lavaTank.getCapacity()) || prevTankEmpty != (lavaTank.getLiquid() == null || lavaTank.getLiquid().amount == 0))
{
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));

View file

@ -43,50 +43,42 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
{
super.onUpdate();
ChargeUtils.charge(1, this);
if(inventory[0] != null && hydrogenStored < MAX_HYDROGEN)
if(!worldObj.isRemote)
{
if(inventory[0].getItem() instanceof IStorageTank)
ChargeUtils.charge(1, this);
if(inventory[0] != null && hydrogenStored < MAX_HYDROGEN)
{
IStorageTank item = (IStorageTank)inventory[0].getItem();
if(item.canProvideGas(inventory[0], EnumGas.HYDROGEN) && item.getGasType(inventory[0]) == EnumGas.HYDROGEN)
if(inventory[0].getItem() instanceof IStorageTank)
{
int received = 0;
int hydrogenNeeded = MAX_HYDROGEN - hydrogenStored;
if(item.getRate() <= hydrogenNeeded)
{
received = item.removeGas(inventory[0], EnumGas.HYDROGEN, item.getRate());
}
else if(item.getRate() > hydrogenNeeded)
{
received = item.removeGas(inventory[0], EnumGas.HYDROGEN, hydrogenNeeded);
}
IStorageTank item = (IStorageTank)inventory[0].getItem();
setGas(EnumGas.HYDROGEN, hydrogenStored + received);
if(item.canProvideGas(inventory[0], EnumGas.HYDROGEN) && item.getGasType(inventory[0]) == EnumGas.HYDROGEN)
{
int received = 0;
int hydrogenNeeded = MAX_HYDROGEN - hydrogenStored;
if(item.getRate() <= hydrogenNeeded)
{
received = item.removeGas(inventory[0], EnumGas.HYDROGEN, item.getRate());
}
else if(item.getRate() > hydrogenNeeded)
{
received = item.removeGas(inventory[0], EnumGas.HYDROGEN, hydrogenNeeded);
}
setGas(EnumGas.HYDROGEN, hydrogenStored + received);
}
}
}
}
if(hydrogenStored > MAX_HYDROGEN)
{
hydrogenStored = MAX_HYDROGEN;
}
if(canOperate())
{
if(!worldObj.isRemote)
if(canOperate())
{
setActive(true);
hydrogenStored-=2;
setJoules(electricityStored + 200);
}
hydrogenStored-=2;
setJoules(electricityStored + 200);
}
else {
if(!worldObj.isRemote)
{
else {
setActive(false);
}
}