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) synchronized(Mekanism.audioHandler.sounds)
{ {
if(entityplayer.worldObj == tileEntity.worldObj) if(entityplayer != null && tileEntity != null && entityplayer.worldObj == tileEntity.worldObj)
{ {
float volume = 0; float volume = 0;

View file

@ -143,60 +143,55 @@ public class EnergyTransferProtocol
{ {
loopThrough(pointer); loopThrough(pointer);
boolean fill = FMLCommonHandler.instance().getEffectiveSide().isServer();
Collections.shuffle(availableAcceptors); 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 currentSending = sending;
double remaining = energyToSend % divider;
double currentRemaining = remaining;
double sending = (energyToSend-remaining)/divider;
for(TileEntity acceptor : availableAcceptors) if(currentRemaining > 0)
{ {
double currentSending = sending; currentSending += (currentRemaining/divider);
currentRemaining -= (currentRemaining/divider);
if(currentRemaining > 0) }
{
currentSending += (currentRemaining/divider); if(acceptor instanceof IStrictEnergyAcceptor)
currentRemaining -= (currentRemaining/divider); {
} energyToSend -= (currentSending - ((IStrictEnergyAcceptor)acceptor).transferEnergyToAcceptor(currentSending));
}
if(acceptor instanceof IStrictEnergyAcceptor) else if(acceptor instanceof IEnergySink)
{ {
energyToSend -= (currentSending - ((IStrictEnergyAcceptor)acceptor).transferEnergyToAcceptor(currentSending)); 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 IEnergySink) }
{ else if(acceptor instanceof IPowerReceptor && Mekanism.hooks.BuildCraftLoaded)
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)); IPowerReceptor receptor = (IPowerReceptor)acceptor;
} double electricityNeeded = Math.min(receptor.powerRequest(acceptorDirections.get(acceptor).getOpposite()), receptor.getPowerProvider().getMaxEnergyStored() - receptor.getPowerProvider().getEnergyStored())*Mekanism.FROM_BC;
else if(acceptor instanceof IPowerReceptor && Mekanism.hooks.BuildCraftLoaded) float transferEnergy = (float)Math.min(electricityNeeded, currentSending);
{ receptor.getPowerProvider().receiveEnergy((float)(transferEnergy*Mekanism.TO_BC), acceptorDirections.get(acceptor).getOpposite());
IPowerReceptor receptor = (IPowerReceptor)acceptor; energyToSend -= transferEnergy;
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(prevNeeded > 0 && prevSending > 0)
{
if(needed > 0 && energyToSend > 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; return !isDead;
} }
@Override
public boolean canBePushed()
{
return true;
}
@Override @Override
public void onUpdate() public void onUpdate()
{ {

View file

@ -58,7 +58,7 @@ public class ItemBlockTransmitter extends ItemBlock
else if(itemstack.getItemDamage() == 2) else if(itemstack.getItemDamage() == 2)
{ {
list.add(EnumColor.DARK_GREY + "Capable of transferring:"); 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); loopThrough(pointer);
boolean fill = FMLCommonHandler.instance().getEffectiveSide().isServer();
Collections.shuffle(availableAcceptors); Collections.shuffle(availableAcceptors);
int liquidSent = 0; int liquidSent = 0;
@ -187,7 +186,7 @@ public class LiquidTransferProtocol
tankRemaining--; 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 { else {
@ -195,13 +194,13 @@ public class LiquidTransferProtocol
{ {
ILiquidTank tank = acceptor.getTank(acceptorDirections.get(acceptor), liquidToSend); 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) for(TileEntity tileEntity : iteratedPipes)
{ {
@ -212,8 +211,6 @@ public class LiquidTransferProtocol
((IMechanicalPipe)tileEntity).onTransfer(sendStack); ((IMechanicalPipe)tileEntity).onTransfer(sendStack);
} }
} }
return 0;
} }
return liquidSent; return liquidSent;

View file

@ -74,114 +74,109 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
{ {
super.onUpdate(); super.onUpdate();
boolean testActive = operatingTicks > 0; if(!worldObj.isRemote)
if(inventory[3] != null)
{ {
if(electricityStored < MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY)) if(inventory[3] != null)
{ {
setJoules(getJoules() + ElectricItemHelper.dechargeItem(inventory[3], getMaxJoules() - getJoules(), getVoltage())); if(electricityStored < MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY))
if(Mekanism.hooks.IC2Loaded && inventory[3].getItem() instanceof IElectricItem)
{ {
IElectricItem item = (IElectricItem)inventory[3].getItem(); setJoules(getJoules() + ElectricItemHelper.dechargeItem(inventory[3], getMaxJoules() - getJoules(), getVoltage()));
if(item.canProvideEnergy(inventory[3]))
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; IElectricItem item = (IElectricItem)inventory[3].getItem();
setJoules(electricityStored + gain); 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))
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)
{ {
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; 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 { else {
upgradeTicks = 0; upgradeTicks = 0;
} }
}
else { handleSecondaryFuel();
upgradeTicks = 0;
} if(electricityStored >= ENERGY_PER_TICK && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK)
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)
{ {
operatingTicks++; if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED) && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK)
secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK; {
electricityStored -= ENERGY_PER_TICK; operatingTicks++;
} secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK;
else if((operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) electricityStored -= ENERGY_PER_TICK;
{ }
if(!worldObj.isRemote) else if((operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operate(); 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())
if(!canOperate()) {
{ operatingTicks = 0;
operatingTicks = 0; }
}
if(!worldObj.isRemote)
{
if(canOperate() && electricityStored >= ENERGY_PER_TICK && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK) if(canOperate() && electricityStored >= ENERGY_PER_TICK && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK)
{ {
setActive(true); setActive(true);

View file

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

View file

@ -34,10 +34,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
/** BuildCraft power provider. */ /** BuildCraft power provider. */
public IPowerProvider powerProvider; 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, * The base of all blocks that deal with electricity. It has a facing state, initialized state,
* and a current amount of stored energy. * 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()); ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, getConsumingSides(), getRequest());
setJoules(getJoules()+electricityPack.getWatts()); 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(); super.onUpdate();
ChargeUtils.discharge(1, this); if(worldObj.isRemote)
if(inventory[3] != null)
{ {
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++; if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[3].stackSize--;
if(inventory[3].stackSize == 0)
{ {
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)
else if(inventory[3].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{ {
upgradeTicks++; if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[3].stackSize--;
if(inventory[3].stackSize == 0)
{ {
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 { else {
upgradeTicks = 0; upgradeTicks = 0;
} }
}
else { if(electricityStored >= ENERGY_PER_TICK)
upgradeTicks = 0;
}
if(electricityStored >= ENERGY_PER_TICK)
{
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operatingTicks++; if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
electricityStored -= ENERGY_PER_TICK; {
} operatingTicks++;
else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) electricityStored -= ENERGY_PER_TICK;
{ }
if(!worldObj.isRemote) else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operate(); operate();
operatingTicks = 0;
electricityStored -= ENERGY_PER_TICK;
} }
operatingTicks = 0;
electricityStored -= ENERGY_PER_TICK;
} }
}
if(!canOperate())
if(!canOperate()) {
{ operatingTicks = 0;
operatingTicks = 0; }
}
if(!worldObj.isRemote)
{
if(canOperate() && electricityStored >= ENERGY_PER_TICK) if(canOperate() && electricityStored >= ENERGY_PER_TICK)
{ {
setActive(true); setActive(true);

View file

@ -67,19 +67,18 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
ChargeUtils.charge(0, this); ChargeUtils.charge(0, this);
ChargeUtils.discharge(1, this); ChargeUtils.discharge(1, this);
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing)); if(!worldObj.isRemote)
if(electricityStored > 0)
{ {
if(tileEntity instanceof IUniversalCable) TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
{
setJoules(electricityStored - (Math.min(electricityStored, tier.OUTPUT) - CableUtils.emitEnergyToNetwork(Math.min(electricityStored, tier.OUTPUT), this, ForgeDirection.getOrientation(facing))));
return;
}
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) if(electricityStored >= tier.OUTPUT)
{ {
@ -97,40 +96,40 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
setJoules(electricityStored - transferEnergy); 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(direction != outputDirection)
if(network != null)
{ {
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);
TileEntity outputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if(outputNetwork != null && !inputNetworks.contains(outputNetwork))
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)
{ {
outputNetwork.startProducing(this, Math.min(outputWatts, getJoules()) / getVoltage(), getVoltage()); double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getJoules(), 10000));
setJoules(electricityStored - outputWatts);
} if(getJoules() > 0 && outputWatts > 0 && getJoules()-outputWatts >= 0)
else { {
outputNetwork.stopProducing(this); 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); Mekanism.proxy.registerSound(this);
} }
boolean testActive = false; if(!worldObj.isRemote)
for(int i : progress)
{ {
if(i > 0) ChargeUtils.discharge(1, this);
if(inventory[0] != null)
{ {
testActive = true; if(inventory[0].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
}
}
ChargeUtils.discharge(1, this);
if(inventory[0] != null)
{
if(inventory[0].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{ {
upgradeTicks++; if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{ {
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)
else if(inventory[0].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{ {
upgradeTicks++; if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{ {
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 { else {
upgradeTicks = 0; upgradeTicks = 0;
} }
}
else { for(int process = 0; process < tier.processes; process++)
upgradeTicks = 0;
}
for(int process = 0; process < tier.processes; process++)
{
if(electricityStored >= ENERGY_PER_TICK)
{ {
if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) if(electricityStored >= ENERGY_PER_TICK)
{ {
progress[process]++; if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
electricityStored -= ENERGY_PER_TICK; {
} progress[process]++;
else if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) electricityStored -= ENERGY_PER_TICK;
{ }
if(!worldObj.isRemote) else if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operate(getInputSlot(process), getOutputSlot(process)); 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)))
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)))
{ {
hasOperation = true; progress[process] = 0;
break;
} }
} }
if(hasOperation && electricityStored >= ENERGY_PER_TICK) if(!worldObj.isRemote)
{ {
setActive(true); boolean hasOperation = false;
}
else { for(int i = 0; i < tier.processes; i++)
setActive(false); {
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 LiquidTank dummyTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
public LiquidStack prevLiquid;
public LiquidStack refLiquid = null; public LiquidStack refLiquid = null;
public boolean isActive = false; public boolean isActive = false;
public float liquidScale; public float liquidScale;
public float prevRoundedScale; public float prevScale;
@Override @Override
public boolean canTransferLiquids(TileEntity fromTile) public boolean canTransferLiquids(TileEntity fromTile)
@ -56,41 +58,41 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
@Override @Override
public void updateEntity() public void updateEntity()
{ {
if(liquidScale > 0) if(!worldObj.isRemote)
{ {
liquidScale -= .01; if(liquidScale != prevScale || refLiquid != prevLiquid)
}
else {
refLiquid = null;
}
if(worldObj.isRemote)
{
float roundedScale = liquidScale*16F;
if(roundedScale != prevRoundedScale)
{ {
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); 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)
}
if(isActive)
{
ITankContainer[] connectedAcceptors = PipeUtils.getConnectedAcceptors(this);
for(ITankContainer container : connectedAcceptors)
{ {
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) public void handlePacketData(ByteArrayDataInput dataStream)
{ {
isActive = dataStream.readBoolean(); isActive = dataStream.readBoolean();
liquidScale = dataStream.readFloat();
if(dataStream.readInt() == 1)
{
refLiquid = new LiquidStack(dataStream.readInt(), LiquidContainerRegistry.BUCKET_VOLUME, dataStream.readInt());
}
} }
@Override @Override
public ArrayList getNetworkedData(ArrayList data) public ArrayList getNetworkedData(ArrayList data)
{ {
data.add(isActive); 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; return data;
} }

View file

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

View file

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

View file

@ -85,136 +85,130 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
super.onUpdate(); 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(!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(((IStorageTank)inventory[1].getItem()).getGasType(inventory[1]) == EnumGas.HYDROGEN || ((IStorageTank)inventory[1].getItem()).getGasType(inventory[1]) == EnumGas.NONE)
if(item.canReceiveGas(inventory[2], EnumGas.OXYGEN))
{ {
int sendingGas = 0; IStorageTank item = (IStorageTank)inventory[1].getItem();
if(item.getRate() <= oxygenStored) if(item.canReceiveGas(inventory[1], EnumGas.HYDROGEN))
{ {
sendingGas = item.getRate(); int sendingGas = 0;
}
else if(item.getRate() > oxygenStored) if(item.getRate() <= hydrogenStored)
{ {
sendingGas = oxygenStored; 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); if(item.canReceiveGas(inventory[2], EnumGas.OXYGEN))
setGas(EnumGas.OXYGEN, oxygenStored - (sendingGas - rejects)); {
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(oxygenStored < MAX_GAS && hydrogenStored < MAX_GAS && waterTank.getLiquid() != null && waterTank.getLiquid().amount-2 >= 0 && electricityStored-100 > 0)
if(tileEntity instanceof IGasAcceptor)
{ {
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(((IGasAcceptor)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), outputType))
if(getGas(outputType) >= output)
{ {
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)) 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())); 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(); prevTankFull = waterTank.getLiquid() != null && waterTank.getLiquid().amount == waterTank.getCapacity();
prevTankEmpty = waterTank.getLiquid() == null; prevTankEmpty = waterTank.getLiquid() == null;
} }
if(dumpType != EnumGas.NONE && getGas(dumpType) > 0)
{
if(!worldObj.isRemote)
{
setGas(dumpType, (getGas(dumpType) - 8));
}
spawnParticle();
}
} }
public void spawnParticle() public void spawnParticle()

View file

@ -84,56 +84,58 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
} }
} }
if(!worldObj.isRemote)
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
if(electricityStored > 0)
{ {
if(tileEntity instanceof IUniversalCable) TileEntity tileEntity = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), ForgeDirection.getOrientation(facing));
{
setJoules(electricityStored - (Math.min(electricityStored, output) - CableUtils.emitEnergyToNetwork(Math.min(electricityStored, output), 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); if(electricityStored >= output)
MinecraftForge.EVENT_BUS.post(event); {
setJoules(electricityStored - (output - event.amount)); 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)
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)
{ {
double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getJoules(), 10000)); ForgeDirection outputDirection = ForgeDirection.getOrientation(facing);
TileEntity outputTile = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), outputDirection);
if(getJoules() > 0 && outputWatts > 0 && getJoules()-outputWatts >= 0)
IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if(outputNetwork != null)
{ {
outputNetwork.startProducing(this, outputWatts / getVoltage(), getVoltage()); double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getJoules(), 10000));
setJoules(electricityStored - outputWatts);
} if(getJoules() > 0 && outputWatts > 0 && getJoules()-outputWatts >= 0)
else { {
outputNetwork.stopProducing(this); 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(); super.onUpdate();
ChargeUtils.charge(1, this); if(!worldObj.isRemote)
if(inventory[0] != null)
{ {
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(lavaTank.getLiquid() == null || lavaTank.getLiquid().amount+liquid.amount <= lavaTank.getCapacity())
if(inventory[0].isItemEqual(new ItemStack(Item.bucketLava)))
{ {
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) 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 + getEnvironmentBoost());
setJoules(electricityStored + GENERATION);
} if(canOperate())
else { {
if(!worldObj.isRemote) setActive(true);
{
lavaTank.drain(10, true);
setJoules(electricityStored + GENERATION);
}
else {
setActive(false); setActive(false);
} }
}
if(!worldObj.isRemote)
{
if(prevTankFull != (lavaTank.getLiquid() != null && lavaTank.getLiquid().amount == lavaTank.getCapacity()) || prevTankEmpty != (lavaTank.getLiquid() == null || lavaTank.getLiquid().amount == 0)) 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())); PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));

View file

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