Cleaned out the old AL prefabs for machines
This commit is contained in:
parent
1fb19b287a
commit
f0538c0ace
6 changed files with 721 additions and 1503 deletions
|
@ -1,193 +0,0 @@
|
||||||
package resonantinduction.core.prefab.tile;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
import resonantinduction.core.tilenetwork.INetworkEnergyPart;
|
|
||||||
import resonantinduction.core.tilenetwork.ITileNetwork;
|
|
||||||
import resonantinduction.core.tilenetwork.prefab.NetworkAssembly;
|
|
||||||
import resonantinduction.core.tilenetwork.prefab.NetworkSharedPower;
|
|
||||||
import universalelectricity.api.vector.Vector3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class to be inherited by all machines on the assembly line. This class acts as a single peace
|
|
||||||
* in a network of similar tiles allowing all to share power from one or more sources
|
|
||||||
*
|
|
||||||
* @author DarkGuardsman
|
|
||||||
*/
|
|
||||||
public abstract class TileAssembly extends TileEnergyMachine implements INetworkEnergyPart
|
|
||||||
{
|
|
||||||
/** lowest value the network can update at */
|
|
||||||
public static int refresh_min_rate = 20;
|
|
||||||
/** range by which the network can update at */
|
|
||||||
public static int refresh_diff = 9;
|
|
||||||
/** Network used to link assembly machines together */
|
|
||||||
private NetworkAssembly assemblyNetwork;
|
|
||||||
/** Tiles that are connected to this */
|
|
||||||
public List<TileEntity> connectedTiles = new ArrayList<TileEntity>();
|
|
||||||
/** Random instance */
|
|
||||||
public Random random = new Random();
|
|
||||||
/** Random rate by which this tile updates its network connections */
|
|
||||||
private int updateTick = 1;
|
|
||||||
|
|
||||||
public TileAssembly(long wattsPerTick)
|
|
||||||
{
|
|
||||||
super(wattsPerTick);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileAssembly(long wattsPerTick, long maxEnergy)
|
|
||||||
{
|
|
||||||
super(wattsPerTick, maxEnergy);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidate()
|
|
||||||
{
|
|
||||||
this.getTileNetwork().splitNetwork(this);
|
|
||||||
super.invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity()
|
|
||||||
{
|
|
||||||
super.updateEntity();
|
|
||||||
if (!this.worldObj.isRemote)
|
|
||||||
{
|
|
||||||
if (ticks % updateTick == 0)
|
|
||||||
{
|
|
||||||
this.updateTick = (random.nextInt(1 + refresh_diff) + refresh_min_rate);
|
|
||||||
this.refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canTileConnect(Connection type, ForgeDirection dir)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refresh()
|
|
||||||
{
|
|
||||||
if (this.worldObj != null && !this.worldObj.isRemote)
|
|
||||||
{
|
|
||||||
this.connectedTiles.clear();
|
|
||||||
|
|
||||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
|
||||||
{
|
|
||||||
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
|
||||||
if (tileEntity instanceof TileAssembly && ((TileAssembly) tileEntity).canTileConnect(Connection.NETWORK, dir.getOpposite()))
|
|
||||||
{
|
|
||||||
this.getTileNetwork().mergeNetwork(((TileAssembly) tileEntity).getTileNetwork(), this);
|
|
||||||
connectedTiles.add(tileEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TileEntity> getNetworkConnections()
|
|
||||||
{
|
|
||||||
return this.connectedTiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NetworkAssembly getTileNetwork()
|
|
||||||
{
|
|
||||||
if (!(this.assemblyNetwork instanceof NetworkAssembly))
|
|
||||||
{
|
|
||||||
this.assemblyNetwork = new NetworkAssembly(this);
|
|
||||||
}
|
|
||||||
return this.assemblyNetwork;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setTileNetwork(ITileNetwork network)
|
|
||||||
{
|
|
||||||
if (network instanceof NetworkAssembly)
|
|
||||||
{
|
|
||||||
this.assemblyNetwork = (NetworkAssembly) network;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean consumePower(long request, boolean doExtract)
|
|
||||||
{
|
|
||||||
return ((NetworkSharedPower) this.getTileNetwork()).removePower(this, request, doExtract) >= request;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
|
||||||
{
|
|
||||||
if (this.canConnect(from))
|
|
||||||
{
|
|
||||||
return this.getTileNetwork().addPower(this, receive, doReceive);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Amount of energy this tile runs on per tick */
|
|
||||||
public int getWattLoad()
|
|
||||||
{
|
|
||||||
return 1;// 1J/t or 20J/t
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Conditional load that may not be consumed per tick */
|
|
||||||
public int getExtraLoad()
|
|
||||||
{
|
|
||||||
return 1;// 1J/t or 20J/t
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getEnergyStored()
|
|
||||||
{
|
|
||||||
return ((NetworkSharedPower) this.getTileNetwork()).getEnergy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getMaxEnergyStored()
|
|
||||||
{
|
|
||||||
return ((NetworkSharedPower) this.getTileNetwork()).getEnergyCapacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getEnergy(ForgeDirection from)
|
|
||||||
{
|
|
||||||
return this.getEnergyStored();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getEnergyCapacity(ForgeDirection from)
|
|
||||||
{
|
|
||||||
return this.getMaxEnergyStored();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getPartEnergy()
|
|
||||||
{
|
|
||||||
return this.energyStored;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getPartMaxEnergy()
|
|
||||||
{
|
|
||||||
return this.MAX_JOULES_STORED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPartEnergy(long energy)
|
|
||||||
{
|
|
||||||
this.energyStored = energy;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AxisAlignedBB getRenderBoundingBox()
|
|
||||||
{
|
|
||||||
return INFINITE_EXTENT_AABB;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,408 +0,0 @@
|
||||||
package resonantinduction.core.prefab.tile;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTBase;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagFloat;
|
|
||||||
import net.minecraft.nbt.NBTTagLong;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
import universalelectricity.api.CompatibilityModule;
|
|
||||||
import universalelectricity.api.electricity.IVoltageInput;
|
|
||||||
import universalelectricity.api.electricity.IVoltageOutput;
|
|
||||||
import universalelectricity.api.energy.IEnergyContainer;
|
|
||||||
import universalelectricity.api.energy.IEnergyInterface;
|
|
||||||
import universalelectricity.api.vector.Vector3;
|
|
||||||
import universalelectricity.api.vector.VectorHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Basic energy tile that can consume power
|
|
||||||
*
|
|
||||||
* Based off both UE universal electrical tile, and electrical tile prefabs
|
|
||||||
*
|
|
||||||
* @author DarkGuardsman
|
|
||||||
*/
|
|
||||||
public abstract class TileEnergyMachine extends TileMachine implements IEnergyInterface, IEnergyContainer, IVoltageInput, IVoltageOutput
|
|
||||||
{
|
|
||||||
/** Forge Ore Directory name of the item to toggle infinite power mode */
|
|
||||||
public static String powerToggleItemID = "battery";
|
|
||||||
/** Demand per tick in watts */
|
|
||||||
protected long JOULES_PER_TICK;
|
|
||||||
/** Max limit of the internal battery/buffer of the machine */
|
|
||||||
protected long MAX_JOULES_STORED;
|
|
||||||
/** Current energy stored in the machine's battery/buffer */
|
|
||||||
protected long energyStored = 0;
|
|
||||||
/** Should we run without power */
|
|
||||||
private boolean runWithoutPower = true;
|
|
||||||
/** Point by which this machines suffers low voltage damage */
|
|
||||||
protected long brownOutVoltage = -1;
|
|
||||||
/** Point by which this machines suffers over voltage damage */
|
|
||||||
protected long shortOutVoltage = -1;
|
|
||||||
/** Voltage by which the machine was designed and rated for */
|
|
||||||
protected long ratedVoltage = 240;
|
|
||||||
|
|
||||||
public TileEnergyMachine()
|
|
||||||
{
|
|
||||||
this.brownOutVoltage = this.getVoltage() / 2;
|
|
||||||
this.shortOutVoltage = (long) ((Math.sqrt(2) * this.getVoltage()) + 0.05 * this.getVoltage());
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEnergyMachine(long wattsPerTick)
|
|
||||||
{
|
|
||||||
this();
|
|
||||||
this.JOULES_PER_TICK = wattsPerTick;
|
|
||||||
this.MAX_JOULES_STORED = wattsPerTick * 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEnergyMachine(long wattsPerTick, long maxEnergy)
|
|
||||||
{
|
|
||||||
this(wattsPerTick);
|
|
||||||
this.MAX_JOULES_STORED = maxEnergy;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity()
|
|
||||||
{
|
|
||||||
super.updateEntity();
|
|
||||||
if (!this.worldObj.isRemote && this.isFunctioning())
|
|
||||||
{
|
|
||||||
this.consumePower(this.JOULES_PER_TICK, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Does this tile have power to run and do work */
|
|
||||||
@Override
|
|
||||||
public boolean canFunction()
|
|
||||||
{
|
|
||||||
return super.canFunction() && (this.consumePower(this.JOULES_PER_TICK, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Called when a player activates the tile's block */
|
|
||||||
public boolean onPlayerActivated(EntityPlayer player)
|
|
||||||
{
|
|
||||||
if (player != null && player.capabilities.isCreativeMode)
|
|
||||||
{
|
|
||||||
ItemStack itemStack = player.getHeldItem();
|
|
||||||
if (itemStack != null)
|
|
||||||
{
|
|
||||||
for (ItemStack stack : OreDictionary.getOres(powerToggleItemID))
|
|
||||||
{
|
|
||||||
if (stack.isItemEqual(itemStack))
|
|
||||||
{
|
|
||||||
this.togglePowerMode();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateContainingBlockInfo()
|
|
||||||
{
|
|
||||||
super.updateContainingBlockInfo();
|
|
||||||
// TODO use this to reset any values that are based on the block as this gets called when
|
|
||||||
// the block changes
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ********************************************
|
|
||||||
* Electricity logic
|
|
||||||
* *********************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
|
||||||
{
|
|
||||||
if (this.getInputDirections().contains(from) && receive > 0)
|
|
||||||
{
|
|
||||||
long prevEnergyStored = Math.max(this.getEnergy(from), 0);
|
|
||||||
long newStoredEnergy = Math.min(this.getEnergy(from) + receive, this.getEnergyCapacity(from));
|
|
||||||
if (doReceive)
|
|
||||||
{
|
|
||||||
this.setEnergy(from, newStoredEnergy);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Math.max(newStoredEnergy - prevEnergyStored, 0);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Called to consume power from the internal storage */
|
|
||||||
protected boolean consumePower(long watts, boolean doDrain)
|
|
||||||
{
|
|
||||||
if (watts <= 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getEnergy(ForgeDirection.UNKNOWN) >= watts)
|
|
||||||
{
|
|
||||||
if (doDrain)
|
|
||||||
{
|
|
||||||
this.setEnergy(ForgeDirection.UNKNOWN, this.getEnergyStored() - watts);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract)
|
|
||||||
{
|
|
||||||
if (this.getOutputDirections().contains(from) && request > 0)
|
|
||||||
{
|
|
||||||
long requestedEnergy = Math.min(request, this.energyStored);
|
|
||||||
if (doExtract)
|
|
||||||
{
|
|
||||||
this.setEnergy(from, this.energyStored - requestedEnergy);
|
|
||||||
}
|
|
||||||
return requestedEnergy;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Called to produce power using the output enumset for directions to output in */
|
|
||||||
protected void produce()
|
|
||||||
{
|
|
||||||
for (ForgeDirection direction : this.getOutputDirections())
|
|
||||||
{
|
|
||||||
if (direction != ForgeDirection.UNKNOWN)
|
|
||||||
{
|
|
||||||
TileEntity entity = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), direction);
|
|
||||||
if (CompatibilityModule.canConnect(entity, direction.getOpposite()))
|
|
||||||
{
|
|
||||||
long output = this.onExtractEnergy(direction, this.JOULES_PER_TICK, false);
|
|
||||||
long input = CompatibilityModule.receiveEnergy(entity, direction.getOpposite(), output, true);
|
|
||||||
if (input > 0 && this.onExtractEnergy(direction, input, true) > 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getVoltageInput(ForgeDirection direction)
|
|
||||||
{
|
|
||||||
if (this.getInputDirections().contains(direction))
|
|
||||||
{
|
|
||||||
return this.ratedVoltage;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onWrongVoltage(ForgeDirection direction, long voltage)
|
|
||||||
{
|
|
||||||
if (voltage > this.ratedVoltage)
|
|
||||||
{
|
|
||||||
if (voltage > this.shortOutVoltage)
|
|
||||||
{
|
|
||||||
// TODO damage machine
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (voltage < this.brownOutVoltage)
|
|
||||||
{
|
|
||||||
// TODO cause machine to run slow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getVoltageOutput(ForgeDirection direction)
|
|
||||||
{
|
|
||||||
if (this.getOutputDirections().contains(direction))
|
|
||||||
{
|
|
||||||
return this.ratedVoltage;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ********************************************
|
|
||||||
* Electricity connection logic
|
|
||||||
* *********************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canConnect(ForgeDirection direction)
|
|
||||||
{
|
|
||||||
if (direction == null || direction.equals(ForgeDirection.UNKNOWN))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.getInputDirections().contains(direction) || this.getOutputDirections().contains(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The electrical input direction.
|
|
||||||
*
|
|
||||||
* @return The direction that electricity is entered into the tile. Return null for no input. By
|
|
||||||
* default you can accept power from all sides.
|
|
||||||
*/
|
|
||||||
public EnumSet<ForgeDirection> getInputDirections()
|
|
||||||
{
|
|
||||||
return EnumSet.allOf(ForgeDirection.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The electrical output direction.
|
|
||||||
*
|
|
||||||
* @return The direction that electricity is output from the tile. Return null for no output. By
|
|
||||||
* default it will return an empty EnumSet.
|
|
||||||
*/
|
|
||||||
public EnumSet<ForgeDirection> getOutputDirections()
|
|
||||||
{
|
|
||||||
return EnumSet.noneOf(ForgeDirection.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ********************************************
|
|
||||||
* Machine energy parms
|
|
||||||
* *********************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
public long getVoltage()
|
|
||||||
{
|
|
||||||
return this.ratedVoltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEnergyMachine setVoltage(long volts)
|
|
||||||
{
|
|
||||||
this.ratedVoltage = volts;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMaxEnergyStored()
|
|
||||||
{
|
|
||||||
return this.MAX_JOULES_STORED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getEnergyCapacity(ForgeDirection from)
|
|
||||||
{
|
|
||||||
if (this.canConnect(from) || from == ForgeDirection.UNKNOWN)
|
|
||||||
{
|
|
||||||
return this.getMaxEnergyStored();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxEnergyStored(long energy)
|
|
||||||
{
|
|
||||||
this.MAX_JOULES_STORED = energy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getEnergyStored()
|
|
||||||
{
|
|
||||||
return this.energyStored;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEnergy(ForgeDirection from, long energy)
|
|
||||||
{
|
|
||||||
if (this.canConnect(from) || from == ForgeDirection.UNKNOWN)
|
|
||||||
{
|
|
||||||
this.energyStored = Math.max(Math.min(energy, this.getMaxEnergyStored()), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getEnergy(ForgeDirection from)
|
|
||||||
{
|
|
||||||
if (this.canConnect(from) || from == ForgeDirection.UNKNOWN)
|
|
||||||
{
|
|
||||||
return this.energyStored;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void togglePowerMode()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getJoulesPerTick()
|
|
||||||
{
|
|
||||||
return this.JOULES_PER_TICK;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getJoulesPerSec()
|
|
||||||
{
|
|
||||||
return getJoulesPerTick() * 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getJoulesPerMin()
|
|
||||||
{
|
|
||||||
return getJoulesPerSec() * 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getJoulesPerHour()
|
|
||||||
{
|
|
||||||
return getJoulesPerMin() * 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEnergyMachine setJoulesPerTick(long energy)
|
|
||||||
{
|
|
||||||
this.JOULES_PER_TICK = energy;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEnergyMachine setJoulesPerSecound(long energy)
|
|
||||||
{
|
|
||||||
this.JOULES_PER_TICK = energy / 20;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEnergyMachine setJoulesPerMin(long energy)
|
|
||||||
{
|
|
||||||
this.JOULES_PER_TICK = energy / 1200;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEnergyMachine setJoulesPerHour(long energy)
|
|
||||||
{
|
|
||||||
this.JOULES_PER_TICK = energy / 72000;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ********************************************
|
|
||||||
* DATA/SAVE/LOAD
|
|
||||||
* *********************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound nbt)
|
|
||||||
{
|
|
||||||
super.readFromNBT(nbt);
|
|
||||||
|
|
||||||
NBTBase tag = nbt.getTag("energyStored");
|
|
||||||
if (tag instanceof NBTTagFloat)
|
|
||||||
{
|
|
||||||
this.energyStored = (long) nbt.getFloat("energyStored") * 1000;
|
|
||||||
}
|
|
||||||
else if (tag instanceof NBTTagLong)
|
|
||||||
{
|
|
||||||
this.energyStored = nbt.getLong("energyStored");
|
|
||||||
}
|
|
||||||
|
|
||||||
runWithoutPower = !nbt.getBoolean("shouldPower");
|
|
||||||
this.functioning = nbt.getBoolean("isRunning");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT(NBTTagCompound nbt)
|
|
||||||
{
|
|
||||||
super.writeToNBT(nbt);
|
|
||||||
nbt.setBoolean("shouldPower", !runWithoutPower);
|
|
||||||
nbt.setLong("energyStored", this.getEnergyStored());
|
|
||||||
nbt.setBoolean("isRunning", this.functioning);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,67 +3,31 @@ package resonantinduction.core.prefab.tile;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.ISidedInventory;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.network.packet.Packet;
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
|
||||||
import net.minecraftforge.common.Configuration;
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
import resonantinduction.core.ResonantInduction;
|
import resonantinduction.core.ResonantInduction;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import calclavia.lib.content.IExtraInfo.IExtraTileEntityInfo;
|
import calclavia.lib.network.IPacketReceiverWithID;
|
||||||
import calclavia.lib.network.PacketHandler;
|
import calclavia.lib.network.PacketHandler;
|
||||||
import calclavia.lib.prefab.tile.TileExternalInventory;
|
import calclavia.lib.prefab.tile.TileElectrical;
|
||||||
import calclavia.lib.utility.inventory.IExternalInventory;
|
|
||||||
import calclavia.lib.utility.inventory.IExternalInventoryBox;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
/** Prefab for general machines
|
||||||
import cpw.mods.fml.common.network.Player;
|
*
|
||||||
|
* @author Darkguardsman */
|
||||||
public abstract class TileMachine extends TileExternalInventory implements ISidedInventory, IExternalInventory, IExtraTileEntityInfo
|
public class TileMachine extends TileElectrical implements IPacketReceiverWithID
|
||||||
{
|
{
|
||||||
/** Number of players with the machine's gui container open */
|
|
||||||
protected int playersUsingMachine = 0;
|
|
||||||
/** Is the machine functioning normally */
|
/** Is the machine functioning normally */
|
||||||
protected boolean functioning = false;
|
protected boolean functioning = false;
|
||||||
/** Prev state of function of last update */
|
/** Prev state of function of last update */
|
||||||
protected boolean prevFunctioning = false;
|
protected boolean prevFunctioning = false;
|
||||||
/** Does the machine have a gui */
|
|
||||||
protected boolean hasGUI = false;
|
|
||||||
/** Does teh machine rotate in meta groups of four */
|
|
||||||
protected boolean rotateByMetaGroup = false;
|
|
||||||
/** Can the machine be temp disabled */
|
|
||||||
protected boolean canBeDisabled = false;
|
|
||||||
/** Is the machine enabled by the player */
|
|
||||||
protected boolean enabled = true;
|
|
||||||
/** Is the machine locked by the player */
|
|
||||||
protected boolean locked = false;
|
|
||||||
|
|
||||||
/** Inventory manager used by this machine */
|
protected long joulesPerTick = 0;
|
||||||
protected IExternalInventoryBox inventory;
|
|
||||||
|
|
||||||
/** Default generic packet types used by all machines */
|
public static final int IS_RUN_PACKET_ID = 0;
|
||||||
public static enum SimplePacketTypes
|
public static final int NBT_PACKET_ID = 1;
|
||||||
{
|
public static final int ENERGY_PACKET_ID = 2;
|
||||||
/** Normal packet data of any kind */
|
|
||||||
GENERIC("generic"),
|
|
||||||
/** Power updates */
|
|
||||||
RUNNING("isRunning"),
|
|
||||||
/** GUI display data update */
|
|
||||||
GUI("guiGeneral"),
|
|
||||||
/** Full tile read/write data from tile NBT */
|
|
||||||
NBT("nbtAll"), GUI_EVENT("clientGui"), GUI_COMMAND("clientCommand"),
|
|
||||||
TERMINAL_OUTPUT("serverTerminal");
|
|
||||||
|
|
||||||
public String name;
|
|
||||||
|
|
||||||
private SimplePacketTypes(String name)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
|
@ -76,18 +40,32 @@ public abstract class TileMachine extends TileExternalInventory implements ISide
|
||||||
|
|
||||||
if (prevFunctioning != this.functioning)
|
if (prevFunctioning != this.functioning)
|
||||||
{
|
{
|
||||||
this.sendPowerUpdate();
|
this.sendRunningPacket();
|
||||||
}
|
}
|
||||||
this.sendGUIPacket();
|
if(this.isFunctioning())
|
||||||
|
{
|
||||||
|
this.consumePower(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean consumePower(boolean doConsume)
|
||||||
|
{
|
||||||
|
return this.consumePower(this.joulesPerTick, doConsume);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean consumePower(long joules, boolean doConsume)
|
||||||
|
{
|
||||||
|
return this.energy.extractEnergy(joules, doConsume) >= joules;
|
||||||
|
}
|
||||||
|
|
||||||
/** Can this tile function, or run threw normal processes */
|
/** Can this tile function, or run threw normal processes */
|
||||||
public boolean canFunction()
|
public boolean canFunction()
|
||||||
{
|
{
|
||||||
return this.enabled;
|
return this.consumePower(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called too see if the machine is functioning, server side it redirects to canFunction */
|
||||||
public boolean isFunctioning()
|
public boolean isFunctioning()
|
||||||
{
|
{
|
||||||
if (this.worldObj.isRemote)
|
if (this.worldObj.isRemote)
|
||||||
|
@ -100,70 +78,26 @@ public abstract class TileMachine extends TileExternalInventory implements ISide
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doRunningDebug()
|
@Override
|
||||||
{
|
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||||
System.out.println("\n CanRun: " + this.canFunction());
|
|
||||||
System.out.println(" RedPower: " + this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord));
|
|
||||||
System.out.println(" IsRunning: " + this.functioning);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Called every tick while this tile entity is disabled. */
|
|
||||||
protected void whileDisable()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ForgeDirection getDirection()
|
|
||||||
{
|
|
||||||
if (this.rotateByMetaGroup)
|
|
||||||
{
|
|
||||||
switch (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) % 4)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
return ForgeDirection.NORTH;
|
|
||||||
case 1:
|
|
||||||
return ForgeDirection.SOUTH;
|
|
||||||
case 2:
|
|
||||||
return ForgeDirection.SOUTH;
|
|
||||||
default:
|
|
||||||
return ForgeDirection.WEST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ForgeDirection.UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDirection(ForgeDirection direction)
|
|
||||||
{
|
|
||||||
if (this.rotateByMetaGroup)
|
|
||||||
{
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
case NORTH:
|
|
||||||
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) / 4, 3);
|
|
||||||
case WEST:
|
|
||||||
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) / 4) + 1, 3);
|
|
||||||
case SOUTH:
|
|
||||||
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) / 4) + 2, 3);
|
|
||||||
default:
|
|
||||||
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) / 4) + 3, 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (this.worldObj.isRemote)
|
if (this.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
if (id.equalsIgnoreCase(SimplePacketTypes.RUNNING.name))
|
if (id == IS_RUN_PACKET_ID)
|
||||||
{
|
{
|
||||||
this.functioning = dis.readBoolean();
|
this.functioning = data.readBoolean();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (id.equalsIgnoreCase(SimplePacketTypes.NBT.name))
|
if (id == NBT_PACKET_ID)
|
||||||
{
|
{
|
||||||
this.readFromNBT(PacketHandler.readNBTTagCompound(dis));
|
this.readFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (id == ENERGY_PACKET_ID)
|
||||||
|
{
|
||||||
|
this.energy.readFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,42 +116,24 @@ public abstract class TileMachine extends TileExternalInventory implements ISide
|
||||||
{
|
{
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
this.writeToNBT(tag);
|
this.writeToNBT(tag);
|
||||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, SimplePacketTypes.NBT.name, this, tag), worldObj, new Vector3(this), 64);
|
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, NBT_PACKET_ID, this, tag), worldObj, new Vector3(this), 64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sends a simple true/false am running power update */
|
/** Sends a simple true/false am running power update */
|
||||||
public void sendPowerUpdate()
|
public void sendRunningPacket()
|
||||||
{
|
{
|
||||||
if (!this.worldObj.isRemote)
|
if (!this.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, SimplePacketTypes.RUNNING.name, this, this.functioning), worldObj, new Vector3(this), 64);
|
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, IS_RUN_PACKET_ID, this, this.functioning), worldObj, new Vector3(this), 64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sends a gui packet only to the given player */
|
public void sendPowerPacket()
|
||||||
public Packet getGUIPacket()
|
|
||||||
{
|
{
|
||||||
return null;
|
if (!this.worldObj.isRemote)
|
||||||
}
|
|
||||||
|
|
||||||
public void sendGUIPacket()
|
|
||||||
{
|
{
|
||||||
Packet packet = this.getGUIPacket();
|
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, ENERGY_PACKET_ID, this, this.energy.writeToNBT(new NBTTagCompound())), worldObj, new Vector3(this), 64);
|
||||||
if (this.hasGUI && this.getContainer() != null && packet != null)
|
|
||||||
{
|
|
||||||
this.playersUsingMachine = 0;
|
|
||||||
for (Object entity : this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(10, 10, 10)))
|
|
||||||
{
|
|
||||||
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).openContainer != null)
|
|
||||||
{
|
|
||||||
if (((EntityPlayer) entity).openContainer.getClass().isAssignableFrom(this.getContainer()))
|
|
||||||
{
|
|
||||||
this.playersUsingMachine += 1;
|
|
||||||
PacketDispatcher.sendPacketToPlayer(packet, (Player) entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,19 +142,4 @@ public abstract class TileMachine extends TileExternalInventory implements ISide
|
||||||
{
|
{
|
||||||
return ResonantInduction.PACKET_TILE.getPacket(this, this.functioning);
|
return ResonantInduction.PACKET_TILE.getPacket(this, this.functioning);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasExtraConfigs()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadExtraConfigs(Configuration config)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
package resonantinduction.core.tilenetwork.prefab;
|
|
||||||
|
|
||||||
import resonantinduction.core.prefab.tile.TileAssembly;
|
|
||||||
import resonantinduction.core.tilenetwork.INetworkPart;
|
|
||||||
|
|
||||||
public class NetworkAssembly extends NetworkSharedPower
|
|
||||||
{
|
|
||||||
private long networkPartEnergyRequest = 0;
|
|
||||||
private long lastUpdateTime = 0;
|
|
||||||
static
|
|
||||||
{
|
|
||||||
NetworkUpdateHandler.registerNetworkClass("AssemblyNet", NetworkAssembly.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NetworkAssembly()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public NetworkAssembly(INetworkPart... parts)
|
|
||||||
{
|
|
||||||
super(parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Gets the demand of all parts of the network including network parts */
|
|
||||||
public float getNetworkDemand()
|
|
||||||
{
|
|
||||||
if (System.currentTimeMillis() - this.lastUpdateTime > 100)
|
|
||||||
{
|
|
||||||
this.networkPartEnergyRequest = 0;
|
|
||||||
this.lastUpdateTime = System.currentTimeMillis();
|
|
||||||
for (INetworkPart part : this.getMembers())
|
|
||||||
{
|
|
||||||
if (part instanceof TileAssembly)
|
|
||||||
{
|
|
||||||
networkPartEnergyRequest += ((TileAssembly) part).getWattLoad();
|
|
||||||
networkPartEnergyRequest += ((TileAssembly) part).getExtraLoad();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return networkPartEnergyRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValidMember(INetworkPart part)
|
|
||||||
{
|
|
||||||
return super.isValidMember(part) && part instanceof TileAssembly;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,7 +11,7 @@ import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.api.IArmbot;
|
import resonantinduction.api.IArmbot;
|
||||||
import resonantinduction.core.ResonantInduction;
|
import resonantinduction.core.ResonantInduction;
|
||||||
import resonantinduction.core.prefab.tile.TileAssembly;
|
import resonantinduction.core.prefab.tile.TileMachine;
|
||||||
import resonantinduction.electrical.Electrical;
|
import resonantinduction.electrical.Electrical;
|
||||||
import resonantinduction.electrical.armbot.task.TaskDrop;
|
import resonantinduction.electrical.armbot.task.TaskDrop;
|
||||||
import resonantinduction.electrical.armbot.task.TaskGOTO;
|
import resonantinduction.electrical.armbot.task.TaskGOTO;
|
||||||
|
@ -37,7 +37,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.network.Player;
|
import cpw.mods.fml.common.network.Player;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
|
||||||
public class TileArmbot extends TileAssembly implements IMultiBlock, IArmbot, IBlockActivate
|
public class TileArmbot extends TileMachine implements IMultiBlock, IArmbot
|
||||||
{
|
{
|
||||||
protected int ROTATION_SPEED = 6;
|
protected int ROTATION_SPEED = 6;
|
||||||
|
|
||||||
|
@ -58,9 +58,12 @@ public class TileArmbot extends TileAssembly implements IMultiBlock, IArmbot, IB
|
||||||
/** Var used by the armbot renderer */
|
/** Var used by the armbot renderer */
|
||||||
public EntityItem renderEntityItem;
|
public EntityItem renderEntityItem;
|
||||||
|
|
||||||
|
public static final int ARMBOT_PACKET_ID = 3;
|
||||||
|
public static final int ROTATION_PACKET_ID = 4;
|
||||||
|
|
||||||
public TileArmbot()
|
public TileArmbot()
|
||||||
{
|
{
|
||||||
super(20);
|
this.joulesPerTick = 20;
|
||||||
programHelper = new ProgramHelper(this).setMemoryLimit(20);
|
programHelper = new ProgramHelper(this).setMemoryLimit(20);
|
||||||
Program program = new Program();
|
Program program = new Program();
|
||||||
program.setTaskAt(0, 0, new TaskDrop());
|
program.setTaskAt(0, 0, new TaskDrop());
|
||||||
|
@ -193,50 +196,11 @@ public class TileArmbot extends TileAssembly implements IMultiBlock, IArmbot, IB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getInvName()
|
|
||||||
{
|
|
||||||
return LanguageUtility.getLocal("tile.armbot.name");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommandDisplayText()
|
public String getCommandDisplayText()
|
||||||
{
|
{
|
||||||
return this.displayText;
|
return this.displayText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onActivated(EntityPlayer player)
|
|
||||||
{
|
|
||||||
ItemStack containingStack = this.getStackInSlot(0);
|
|
||||||
|
|
||||||
if (containingStack != null)
|
|
||||||
{
|
|
||||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
|
||||||
{
|
|
||||||
EntityItem dropStack = new EntityItem(this.worldObj, player.posX, player.posY, player.posZ, containingStack);
|
|
||||||
dropStack.delayBeforeCanPickup = 0;
|
|
||||||
this.worldObj.spawnEntityInWorld(dropStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setInventorySlotContents(0, null);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (player.getCurrentEquippedItem() != null)
|
|
||||||
{
|
|
||||||
if (player.getCurrentEquippedItem().getItem() instanceof ItemDisk)
|
|
||||||
{
|
|
||||||
this.setInventorySlotContents(0, player.getCurrentEquippedItem());
|
|
||||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/************************************ Save and load code *************************************/
|
/************************************ Save and load code *************************************/
|
||||||
|
|
||||||
/** NBT Data */
|
/** NBT Data */
|
||||||
|
@ -316,26 +280,26 @@ public class TileArmbot extends TileAssembly implements IMultiBlock, IArmbot, IB
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
|
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (this.worldObj.isRemote && !super.simplePacket(id, dis, player))
|
if (this.worldObj.isRemote && !super.onReceivePacket(id, data, player, extra))
|
||||||
{
|
{
|
||||||
if (id.equalsIgnoreCase("armbot"))
|
if (id == ARMBOT_PACKET_ID)
|
||||||
{
|
{
|
||||||
this.functioning = dis.readBoolean();
|
this.functioning = data.readBoolean();
|
||||||
this.targetYaw = dis.readInt();
|
this.targetYaw = data.readInt();
|
||||||
this.targetPitch = dis.readInt();
|
this.targetPitch = data.readInt();
|
||||||
this.actualYaw = dis.readInt();
|
this.actualYaw = data.readInt();
|
||||||
this.actualPitch = dis.readInt();
|
this.actualPitch = data.readInt();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (id.equalsIgnoreCase("armbotItem"))
|
else if (id == ROTATION_PACKET_ID)
|
||||||
{
|
{
|
||||||
if (dis.readBoolean())
|
if (data.readBoolean())
|
||||||
{
|
{
|
||||||
this.grabbedObject = ItemStack.loadItemStackFromNBT(PacketHandler.readNBTTagCompound(dis));
|
this.grabbedObject = ItemStack.loadItemStackFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -410,12 +374,6 @@ public class TileArmbot extends TileAssembly implements IMultiBlock, IArmbot, IB
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
|
||||||
{
|
|
||||||
return itemstack != null && itemstack.itemID == Electrical.itemDisk.itemID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector3 getHandPos()
|
public Vector3 getHandPos()
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,14 +12,16 @@ import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
import resonantinduction.api.IReadOut;
|
import resonantinduction.api.IReadOut;
|
||||||
import resonantinduction.api.fluid.IDrain;
|
import resonantinduction.api.fluid.IDrain;
|
||||||
import resonantinduction.core.prefab.tile.TileEnergyMachine;
|
import resonantinduction.core.prefab.tile.TileMachine;
|
||||||
import resonantinduction.core.tilenetwork.ITileConnector;
|
import resonantinduction.core.tilenetwork.ITileConnector;
|
||||||
|
import universalelectricity.api.energy.EnergyStorageHandler;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
|
import calclavia.lib.prefab.tile.IRotatable;
|
||||||
import calclavia.lib.utility.FluidUtility;
|
import calclavia.lib.utility.FluidUtility;
|
||||||
|
|
||||||
import com.builtbroken.common.Pair;
|
import com.builtbroken.common.Pair;
|
||||||
|
|
||||||
public class TilePump extends TileEnergyMachine implements IReadOut, ITileConnector
|
public class TilePump extends TileMachine implements IReadOut, ITileConnector, IRotatable
|
||||||
{
|
{
|
||||||
private int currentWorldEdits, MAX_WORLD_EDITS_PER_PROCESS;
|
private int currentWorldEdits, MAX_WORLD_EDITS_PER_PROCESS;
|
||||||
|
|
||||||
|
@ -35,16 +37,12 @@ public class TilePump extends TileEnergyMachine implements IReadOut, ITileConnec
|
||||||
this(10, 50, 5);
|
this(10, 50, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @param wattTick - cost in watts per tick to run the tile
|
||||||
* @param wattTick - cost in watts per tick to run the tile
|
|
||||||
* @param wattDrain - cost in watts to drain or fill one block
|
* @param wattDrain - cost in watts to drain or fill one block
|
||||||
* @param maxEdits - max world edits per update (1/2 second)
|
* @param maxEdits - max world edits per update (1/2 second) */
|
||||||
*/
|
|
||||||
public TilePump(long wattTick, long wattDrain, int maxEdits)
|
public TilePump(long wattTick, long wattDrain, int maxEdits)
|
||||||
{
|
{
|
||||||
// Power calculation for max power (worldEdits * watts per edit) + (watts per tick * one
|
this.energy = new EnergyStorageHandler((maxEdits * wattDrain) + (wattTick * 20));
|
||||||
// second)
|
|
||||||
super(wattTick, (maxEdits * wattDrain) + (wattTick * 20));
|
|
||||||
this.MAX_WORLD_EDITS_PER_PROCESS = maxEdits;
|
this.MAX_WORLD_EDITS_PER_PROCESS = maxEdits;
|
||||||
this.ENERGY_PER_DRAIN = wattDrain;
|
this.ENERGY_PER_DRAIN = wattDrain;
|
||||||
}
|
}
|
||||||
|
@ -93,13 +91,11 @@ public class TilePump extends TileEnergyMachine implements IReadOut, ITileConnec
|
||||||
return new Pair<World, Vector3>(this.worldObj, new Vector3(this).modifyPositionFromSide(ForgeDirection.DOWN));
|
return new Pair<World, Vector3>(this.worldObj, new Vector3(this).modifyPositionFromSide(ForgeDirection.DOWN));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Drains an area starting at the given location
|
||||||
* Drains an area starting at the given location
|
|
||||||
*
|
*
|
||||||
* @param world - world to drain in, most cases will be the TileEntities world
|
* @param world - world to drain in, most cases will be the TileEntities world
|
||||||
* @param loc - origin to start the path finder with. If this is an instance of IDrain this
|
* @param loc - origin to start the path finder with. If this is an instance of IDrain this
|
||||||
* method will act different
|
* method will act different */
|
||||||
*/
|
|
||||||
public void drainAroundArea(World world, Vector3 vec, int update)
|
public void drainAroundArea(World world, Vector3 vec, int update)
|
||||||
{
|
{
|
||||||
Vector3 origin = vec.clone();
|
Vector3 origin = vec.clone();
|
||||||
|
@ -230,4 +226,18 @@ public class TilePump extends TileEnergyMachine implements IReadOut, ITileConnec
|
||||||
return direction != ForgeDirection.DOWN;
|
return direction != ForgeDirection.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ForgeDirection getDirection()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDirection(ForgeDirection direection)
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue