use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.
the class HeatExchangerLogic method update.
@Override
public void update() {
if (getThermalCapacity() < 0.1D) {
temperature = 295;
return;
}
if (newBehaviours != null) {
List<HeatBehaviour> oldBehaviours = behaviours;
behaviours = newBehaviours;
newBehaviours = null;
for (HeatBehaviour oldBehaviour : oldBehaviours) {
// Transfer over equal heat behaviour's info.
int equalBehaviourIndex = behaviours.indexOf(oldBehaviour);
if (equalBehaviourIndex >= 0) {
NBTTagCompound tag = new NBTTagCompound();
oldBehaviour.writeToNBT(tag);
behaviours.get(equalBehaviourIndex).readFromNBT(tag);
}
}
}
Iterator<HeatBehaviour> iterator = behaviours.iterator();
while (iterator.hasNext()) {
HeatBehaviour behaviour = iterator.next();
if (behaviour.getWorld() != null) {
// upon loading from NBT the world is null. gets initialized once 'initializeAsHull' is invoked.
if (behaviour.isApplicable()) {
behaviour.update();
} else {
iterator.remove();
}
}
}
for (IHeatExchangerLogic logic : connectedExchangers) {
// As the connected logics also will tick, we should prevent dispersing more when more are connected.
exchange(logic, this, getTickingHeatExchangers());
}
}
use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.
the class WailaHeatHandler method getNBTData.
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z) {
if (te instanceof IHeatExchanger) {
Set<IHeatExchangerLogic> heatExchangers = new HashSet<IHeatExchangerLogic>();
IHeatExchangerLogic logic = null;
boolean isMultisided = true;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
logic = ((IHeatExchanger) te).getHeatExchangerLogic(d);
if (logic != null) {
if (heatExchangers.contains(logic)) {
isMultisided = false;
break;
} else {
heatExchangers.add(logic);
}
}
}
if (isMultisided) {
NBTTagList tagList = new NBTTagList();
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
logic = ((IHeatExchanger) te).getHeatExchangerLogic(d);
if (logic != null) {
NBTTagCompound heatTag = new NBTTagCompound();
heatTag.setByte("side", (byte) d.ordinal());
heatTag.setInteger("temp", (int) logic.getTemperature());
tagList.appendTag(heatTag);
}
}
tag.setTag("heat", tagList);
} else if (logic != null) {
tag.setInteger("temp", (int) logic.getTemperature());
}
}
return tag;
}
use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.
the class TileEntityBase method addLuaMethods.
/*
* COMPUTERCRAFT API
*/
protected void addLuaMethods() {
if (this instanceof IHeatExchanger) {
final IHeatExchanger exchanger = (IHeatExchanger) this;
luaMethods.add(new LuaMethod("getTemperature") {
@Override
public Object[] call(Object[] args) throws Exception {
if (args.length == 0) {
return new Object[] { exchanger.getHeatExchangerLogic(ForgeDirection.UNKNOWN).getTemperature() };
} else if (args.length == 1) {
IHeatExchangerLogic logic = exchanger.getHeatExchangerLogic(getDirForString((String) args[0]));
return new Object[] { logic != null ? logic.getTemperature() : 0 };
} else {
throw new IllegalArgumentException("getTemperature method requires 0 or 1 argument (direction: up, down, east, west, north, south!");
}
}
});
}
}
use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.
the class ItemManometer method onItemUseFirst.
/**
* Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
* True if something happen and false if it don't. This is for ITEMS, not BLOCKS
*/
@Override
public boolean onItemUseFirst(ItemStack iStack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) {
if (world.isRemote)
return false;
if (((IPressurizable) iStack.getItem()).getPressure(iStack) > 0F) {
TileEntity te = world.getTileEntity(x, y, z);
IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
List<IChatComponent> curInfo = new ArrayList<IChatComponent>();
List<String> info = new ArrayList<String>();
if (te instanceof IManoMeasurable) {
((IManoMeasurable) te).printManometerMessage(player, info);
} else if (machine != null) {
machine.getAirHandler().printManometerMessage(player, info);
}
for (String s : info) curInfo.add(new ChatComponentTranslation(s));
if (te instanceof IHeatExchanger) {
IHeatExchangerLogic exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(ForgeDirection.getOrientation(side));
if (exchanger != null) {
curInfo.add(new ChatComponentTranslation("waila.temperature", (int) exchanger.getTemperature() - 273));
} else {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(d);
if (exchanger != null) {
curInfo.add(new ChatComponentTranslation("waila.temperature." + d.toString().toLowerCase(), (int) exchanger.getTemperature() - 273));
}
}
}
}
if (curInfo.size() > 0) {
((IPressurizable) iStack.getItem()).addAir(iStack, -30);
for (IChatComponent s : curInfo) {
player.addChatComponentMessage(s);
}
return true;
}
} else {
player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "The Manometer doesn't have any charge!"));
return false;
}
return false;
}
use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.
the class HeatExchangerLogic method initializeAsHull.
@Override
public void initializeAsHull(World world, int x, int y, int z, ForgeDirection... validSides) {
if (world.isRemote)
return;
for (IHeatExchangerLogic logic : hullExchangers) {
removeConnectedExchanger(logic);
}
hullExchangers.clear();
newBehaviours = new ArrayList<HeatBehaviour>();
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (isSideValid(validSides, d)) {
HeatBehaviourManager.getInstance().addHeatBehaviours(world, x + d.offsetX, y + d.offsetY, z + d.offsetZ, this, newBehaviours);
IHeatExchangerLogic logic = HeatExchangerManager.getInstance().getLogic(world, x + d.offsetX, y + d.offsetY, z + d.offsetZ, d.getOpposite());
if (logic != null) {
hullExchangers.add(logic);
addConnectedExchanger(logic);
}
}
}
}
Aggregations