Made basic machine class have an inf power mode

This mode should only be triggered by players in creative mode. This way
a creative mode player can force the machine to run without power.
This commit is contained in:
Robert Seifert 2013-06-09 05:35:26 -04:00
parent 022a1a0d75
commit 1ef0ea0be2

View file

@ -1,23 +1,27 @@
package dark.library.machine;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
import calclavia.lib.TileEntityUniversalRunnable;
import dark.library.PowerSystems;
public class TileEntityRunnableMachine extends TileEntityUniversalRunnable
{
/** The amount of players using the console. */
public int playersUsing = 0;
public static String powerToggleItemID = "battery";
protected boolean runPowerless = false;
@Override
public void updateEntity()
{
super.updateEntity();
if (this.wattsReceived < this.getWattBuffer() && PowerSystems.runPowerLess(PowerSystems.INDUSTRIALCRAFT, PowerSystems.BUILDCRAFT, PowerSystems.MEKANISM))
/* CREATES FREE POWER IF NO POWER PROVIDER IS FOUND OR BLOCK WAS SET TO RUN WITHOUT POWER */
if (this.wattsReceived < this.getWattBuffer() && (this.runPowerless || PowerSystems.runPowerLess(PowerSystems.INDUSTRIALCRAFT, PowerSystems.BUILDCRAFT, PowerSystems.MEKANISM)))
{
this.wattsReceived += Math.max(this.getWattBuffer() - this.wattsReceived, 0);
}
super.updateEntity();
}
@Override
@ -25,6 +29,7 @@ public class TileEntityRunnableMachine extends TileEntityUniversalRunnable
{
super.readFromNBT(nbt);
this.wattsReceived = nbt.getDouble("wattsReceived");
this.runPowerless = nbt.getBoolean("shouldPower");
}
@Override
@ -32,5 +37,21 @@ public class TileEntityRunnableMachine extends TileEntityUniversalRunnable
{
super.writeToNBT(nbt);
nbt.setDouble("wattsReceived", this.wattsReceived);
nbt.setBoolean("shouldPower", this.runPowerless);
}
/**
* Sets this machine to run without power only if the given stack match an ore directory name
*/
public void toggleInfPower(ItemStack item)
{
for (ItemStack stack : OreDictionary.getOres(this.powerToggleItemID))
{
if (stack.isItemEqual(item))
{
this.runPowerless = !this.runPowerless;
break;
}
}
}
}