This commit is contained in:
DarkGuardsman 2013-09-03 01:10:35 -04:00
parent 88def701dd
commit 17e709638e
3 changed files with 31 additions and 14 deletions

View file

@ -127,6 +127,7 @@ public class ItemTools extends ItemBasic
//TODO add shift click support to bring up a easier to read GUI or link to the block and add an on screen gui so the player can toy with a design and be updated //TODO add shift click support to bring up a easier to read GUI or link to the block and add an on screen gui so the player can toy with a design and be updated
if (tool == EnumTools.MULTI_METER) if (tool == EnumTools.MULTI_METER)
{ {
//TODO filter all units threw UE unit helper to created nicer looking output text
player.sendChatToPlayer(ChatMessageComponent.func_111066_d("Side>" + ForgeDirection.getOrientation(side).toString())); player.sendChatToPlayer(ChatMessageComponent.func_111066_d("Side>" + ForgeDirection.getOrientation(side).toString()));
boolean out = false; boolean out = false;
if (tileEntity instanceof IElectrical) if (tileEntity instanceof IElectrical)
@ -136,29 +137,29 @@ public class ItemTools extends ItemBasic
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(" Voltage>" + ((IElectrical) tileEntity).getVoltage())); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(" Voltage>" + ((IElectrical) tileEntity).getVoltage()));
if (demand > 0) if (demand > 0)
{ {
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" RequiredWatts> %1$.2fW", demand))); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" RequiredWatts> %1$.2fKW", demand)));
} }
if (provide > 0) if (provide > 0)
{ {
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" AvailableWatts> %1$.2fW", provide))); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" AvailableWatts> %1$.2fKW", provide)));
} }
out = true; out = true;
} }
if (tileEntity instanceof IElectricalStorage) if (tileEntity instanceof IElectricalStorage)
{ {
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" EnergyStored> %1$.2fW of %2$.2fW max", ((IElectricalStorage) tileEntity).getEnergyStored(), ((IElectricalStorage) tileEntity).getMaxEnergyStored()))); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" EnergyStored> %1$.2fKW of %2$.2fW max", ((IElectricalStorage) tileEntity).getEnergyStored(), ((IElectricalStorage) tileEntity).getMaxEnergyStored())));
out = true; out = true;
} }
if (tileEntity instanceof IConductor) if (tileEntity instanceof IConductor)
{ {
out = true; out = true;
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" Resistance> %1$.2fW | AmpMax> %2$.2fW", ((IConductor) tileEntity).getResistance(), ((IConductor) tileEntity).getCurrentCapacity()))); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" Resistance> %1$.2fKW | AmpMax> %2$.2fW", ((IConductor) tileEntity).getResistance(), ((IConductor) tileEntity).getCurrentCapacity())));
if (((IConductor) tileEntity).getNetwork() != null) if (((IConductor) tileEntity).getNetwork() != null)
{ {
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(" Network>" + ((IConductor) tileEntity).getNetwork().toString())); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(" Network>" + ((IConductor) tileEntity).getNetwork().toString()));
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" Network>WattRequired> %1$.2fW | TotalResistance> %2$.2fW", (((IConductor) tileEntity).getNetwork().getRequest() != null ? ((IConductor) tileEntity).getNetwork().getRequest().getWatts() : 0), ((IConductor) tileEntity).getNetwork().getTotalResistance()))); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(" Network>WattRequired> %1$.2fKW | TotalResistance> %2$.2fW", (((IConductor) tileEntity).getNetwork().getRequest() != null ? ((IConductor) tileEntity).getNetwork().getRequest().getWatts() : 0), ((IConductor) tileEntity).getNetwork().getTotalResistance())));
} }
} }
if (!out) if (!out)

View file

@ -5,6 +5,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
/** External inventory management container for an object. Allows for most if not all inventory code
* to be removed from the tile. That is some methods will still need to remain in order to work with
* automation. As well this is not designed to replace the need for IInventory support of a tile but
* to make it easier to manage. Suggested use it to create a prefab manager for several tiles. Then
* have those tiles use the prefab as an extermal inventory manager to reduce code size per class.
*
* @author DarkGuardsman */
public interface IInvBox extends ISidedInventory public interface IInvBox extends ISidedInventory
{ {
/** Gets the inventory array. ForgeDirection.UNKOWN must return all sides */ /** Gets the inventory array. ForgeDirection.UNKOWN must return all sides */

View file

@ -30,19 +30,24 @@ import dark.interfaces.IPowerLess;
import dark.interfaces.PowerSystems; import dark.interfaces.PowerSystems;
import dark.prefab.invgui.InvChest; import dark.prefab.invgui.InvChest;
/** Prefab for most machines in the CoreMachine set. Provides basic power updates, packet updates,
* inventory handling, and other handy methods.
*
* @author DarkGuardsman */
public abstract class TileEntityMachine extends TileEntityUniversalElectrical implements ISidedInventory, IExternalInv, IDisableable, IPacketReceiver, IPowerLess public abstract class TileEntityMachine extends TileEntityUniversalElectrical implements ISidedInventory, IExternalInv, IDisableable, IPacketReceiver, IPowerLess
{ {
//TODO add support for attaching multi-meter to side of machine
/** Forge Ore Directory name of the item to toggle power */ /** Forge Ore Directory name of the item to toggle infinite power mode */
public static String powerToggleItemID = "battery"; public static String powerToggleItemID = "battery";
/** ticks to act dead or disabled */ /** ticks to act dead, disabled, or not function at all */
protected int ticksDisabled = 0; protected int ticksDisabled = 0;
protected float WATTS_PER_TICK, MAX_WATTS; protected float WATTS_PER_TICK, MAX_WATTS;
protected boolean unpowered, running, prevRunning; protected boolean unpowered = false, running = false, prevRunning = false;
/** Inventory used by this machine */ /** Inventory manager used by this machine */
protected IInvBox inventory; protected IInvBox inventory;
/** Default generic packet types used by all machines */ /** Default generic packet types used by all machines */
@ -92,7 +97,8 @@ public abstract class TileEntityMachine extends TileEntityUniversalElectrical im
this.running = this.canRun() && this.consumePower(this.WATTS_PER_TICK, true); this.running = this.canRun() && this.consumePower(this.WATTS_PER_TICK, true);
if (prevRun != this.running) if (prevRun != this.running)
{ {
PacketManager.sendPacketToClients(this.getDescriptionPacket(), worldObj, new Vector3(this), 64); System.out.println("\n\nPower update packet sent to client\n\n\n");
this.sendPowerUpdate();
} }
} }
@ -120,7 +126,7 @@ public abstract class TileEntityMachine extends TileEntityUniversalElectrical im
/** Does this tile have power to run and do work */ /** Does this tile have power to run and do work */
public boolean canRun() public boolean canRun()
{ {
return !this.isDisabled() && (this.runPowerLess() || this.getEnergyStored() >= this.WATTS_PER_TICK); return !this.isDisabled() && (this.runPowerLess() || this.consumePower(this.WATTS_PER_TICK, false));
} }
@Override @Override
@ -230,7 +236,7 @@ public abstract class TileEntityMachine extends TileEntityUniversalElectrical im
@Override @Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{ {
boolean packetSize = false; boolean packetSize = true;
try try
{ {
ByteArrayInputStream bis = new ByteArrayInputStream(packet.data); ByteArrayInputStream bis = new ByteArrayInputStream(packet.data);
@ -273,11 +279,13 @@ public abstract class TileEntityMachine extends TileEntityUniversalElectrical im
if (id.equalsIgnoreCase(TilePacketTypes.POWER.name)) if (id.equalsIgnoreCase(TilePacketTypes.POWER.name))
{ {
this.running = dis.readBoolean(); this.running = dis.readBoolean();
System.out.println("Received isRunning packet");
return true; return true;
} }
if (id.equalsIgnoreCase(TilePacketTypes.NBT.name)) if (id.equalsIgnoreCase(TilePacketTypes.NBT.name))
{ {
this.readFromNBT(Packet.readNBTTagCompound(dis)); this.readFromNBT(Packet.readNBTTagCompound(dis));
return true;
} }
} }
} }
@ -296,8 +304,7 @@ public abstract class TileEntityMachine extends TileEntityUniversalElectrical im
{ {
if (!this.worldObj.isRemote) if (!this.worldObj.isRemote)
{ {
Packet packet = PacketManager.getPacket(this.getChannel(), this, TilePacketTypes.POWER.ordinal(), this.running); PacketManager.sendPacketToClients(PacketManager.getPacket(this.getChannel(), this, TilePacketTypes.POWER.name, this.running), worldObj, new Vector3(this), 64);
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 64);
} }
} }
@ -326,6 +333,7 @@ public abstract class TileEntityMachine extends TileEntityUniversalElectrical im
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.ticksDisabled = nbt.getInteger("disabledTicks"); this.ticksDisabled = nbt.getInteger("disabledTicks");
this.unpowered = nbt.getBoolean("shouldPower"); this.unpowered = nbt.getBoolean("shouldPower");
this.running = nbt.getBoolean("isRunning");
if (nbt.hasKey("wattsReceived")) if (nbt.hasKey("wattsReceived"))
{ {
this.energyStored = (float) nbt.getDouble("wattsReceived"); this.energyStored = (float) nbt.getDouble("wattsReceived");
@ -338,6 +346,7 @@ public abstract class TileEntityMachine extends TileEntityUniversalElectrical im
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setInteger("disabledTicks", this.ticksDisabled); nbt.setInteger("disabledTicks", this.ticksDisabled);
nbt.setBoolean("shouldPower", this.unpowered); nbt.setBoolean("shouldPower", this.unpowered);
nbt.setBoolean("isRunning",this.running);
} }
/*-------------------------------------------------------------- /*--------------------------------------------------------------