Change how Pipe Guage works
Changed it so that the block being clicked on now supplies the custom readout message. This way each block can have its own message instead of a general one for the TE type.
This commit is contained in:
parent
680203f2b6
commit
a688f25511
6 changed files with 221 additions and 183 deletions
|
@ -8,8 +8,10 @@ import net.minecraft.src.Item;
|
||||||
import net.minecraft.src.ItemStack;
|
import net.minecraft.src.ItemStack;
|
||||||
import net.minecraft.src.TileEntity;
|
import net.minecraft.src.TileEntity;
|
||||||
import net.minecraft.src.World;
|
import net.minecraft.src.World;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import dark.BasicUtilities.BasicUtilitiesMain;
|
import dark.BasicUtilities.BasicUtilitiesMain;
|
||||||
import dark.BasicUtilities.api.IForce;
|
import dark.BasicUtilities.api.IForce;
|
||||||
|
import dark.BasicUtilities.api.IReadOut;
|
||||||
import dark.BasicUtilities.api.Liquid;
|
import dark.BasicUtilities.api.Liquid;
|
||||||
import dark.BasicUtilities.pipes.TileEntityPipe;
|
import dark.BasicUtilities.pipes.TileEntityPipe;
|
||||||
import dark.BasicUtilities.tanks.TileEntityLTank;
|
import dark.BasicUtilities.tanks.TileEntityLTank;
|
||||||
|
@ -28,88 +30,65 @@ public class ItemGuage extends Item
|
||||||
this.setCreativeTab(CreativeTabs.tabTools);
|
this.setCreativeTab(CreativeTabs.tabTools);
|
||||||
this.setMaxStackSize(1);
|
this.setMaxStackSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||||
{
|
{
|
||||||
par3List.add(new ItemStack(this, 1, 0));
|
par3List.add(new ItemStack(this, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIconFromDamage(int par1)
|
public int getIconFromDamage(int par1)
|
||||||
{
|
{
|
||||||
switch(par1)
|
switch (par1)
|
||||||
{
|
{
|
||||||
case 0: return 24;
|
case 0:
|
||||||
}
|
return 24;
|
||||||
|
}
|
||||||
return this.iconIndex;
|
return this.iconIndex;
|
||||||
}
|
}
|
||||||
public String getTextureFile() {
|
|
||||||
return BasicUtilitiesMain.ITEM_PNG;
|
public String getTextureFile()
|
||||||
}
|
{
|
||||||
|
return BasicUtilitiesMain.ITEM_PNG;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getItemName()
|
public String getItemName()
|
||||||
{
|
{
|
||||||
return "guage";
|
return "guage";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
|
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World par3World, int x, int y, int z, int side, float par8, float par9, float par10)
|
||||||
{
|
{
|
||||||
if(!par3World.isRemote)
|
if (!par3World.isRemote)
|
||||||
{
|
{
|
||||||
if(itemStack.getItemDamage() == 0)
|
if (itemStack.getItemDamage() == 0)
|
||||||
{
|
{
|
||||||
TileEntity blockEntity = par3World.getBlockTileEntity(par4, par5, par6);
|
TileEntity blockEntity = par3World.getBlockTileEntity(x, y, z);
|
||||||
if(blockEntity instanceof TileEntityPipe)
|
if(blockEntity instanceof IReadOut)
|
||||||
{
|
{
|
||||||
TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity;
|
String output = ((IReadOut) blockEntity).getMeterReading(player,ForgeDirection.getOrientation(side));
|
||||||
Liquid type = pipeEntity.getType();
|
if(output.length() > 100) output = output.substring(0, 100);
|
||||||
int steam = pipeEntity.getStoredLiquid(type);
|
output.trim();
|
||||||
int pressure = pipeEntity.presure;
|
player.sendChatToPlayer("ReadOut: "+output);
|
||||||
String typeName = type.lName;
|
}
|
||||||
String print = "Error";
|
}
|
||||||
|
|
||||||
print = typeName +" " + steam +" @ "+pressure+"PSI";
|
}
|
||||||
|
|
||||||
player.sendChatToPlayer(print);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(blockEntity instanceof TileEntityLTank)
|
|
||||||
{
|
|
||||||
TileEntityLTank pipeEntity = (TileEntityLTank) blockEntity;
|
|
||||||
Liquid type = pipeEntity.getType();
|
|
||||||
int steam = pipeEntity.getStoredLiquid(type);
|
|
||||||
String typeName = type.lName;
|
|
||||||
String print = "Error";
|
|
||||||
|
|
||||||
print = typeName +" " + steam;
|
|
||||||
|
|
||||||
player.sendChatToPlayer(print);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(blockEntity instanceof IForce)
|
|
||||||
{
|
|
||||||
IForce rod = (IForce) blockEntity;
|
|
||||||
int steam = rod.getForce();
|
|
||||||
int pressure = rod.getAnimationPos();
|
|
||||||
String print = "Error";
|
|
||||||
|
|
||||||
print = " " + steam +"N "+pressure*45+"degrees";
|
|
||||||
|
|
||||||
player.sendChatToPlayer(print);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public String getItemNameIS(ItemStack par1ItemStack)
|
|
||||||
|
public String getItemNameIS(ItemStack par1ItemStack)
|
||||||
{
|
{
|
||||||
int var3 = par1ItemStack.getItemDamage();
|
int var3 = par1ItemStack.getItemDamage();
|
||||||
switch(var3)
|
switch (var3)
|
||||||
{
|
{
|
||||||
case 0: return "PipeGuage";
|
case 0:
|
||||||
}
|
return "PipeGuage";
|
||||||
|
}
|
||||||
return this.getItemName();
|
return this.getItemName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
common/dark/BasicUtilities/api/IReadOut.java
Normal file
17
common/dark/BasicUtilities/api/IReadOut.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package dark.BasicUtilities.api;
|
||||||
|
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
|
public interface IReadOut
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Grabs the message displayed to the user
|
||||||
|
* on right click of the machine with the
|
||||||
|
* pipe gauge
|
||||||
|
* @param user
|
||||||
|
* @param side - may not work correctly yet but should give you a side
|
||||||
|
* @return - a string to be displayed to the player for a reading. automatically adds ReadOut: to the beginning
|
||||||
|
*/
|
||||||
|
public String getMeterReading(EntityPlayer user, ForgeDirection side);
|
||||||
|
}
|
|
@ -14,10 +14,11 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
import dark.BasicUtilities.BasicUtilitiesMain;
|
import dark.BasicUtilities.BasicUtilitiesMain;
|
||||||
import dark.BasicUtilities.api.IForce;
|
import dark.BasicUtilities.api.IForce;
|
||||||
import dark.Library.Util.MetaData;
|
import dark.BasicUtilities.api.IReadOut;
|
||||||
|
import dark.Library.Util.MetaGroupingHelper;
|
||||||
import dark.Library.prefab.TileEntityMachine;
|
import dark.Library.prefab.TileEntityMachine;
|
||||||
|
|
||||||
public class TileEntityGen extends TileEntityMachine implements IPacketReceiver, IForce, IElectricityProducer
|
public class TileEntityGen extends TileEntityMachine implements IPacketReceiver, IForce, IElectricityProducer,IReadOut
|
||||||
{
|
{
|
||||||
ForgeDirection facing = ForgeDirection.DOWN;
|
ForgeDirection facing = ForgeDirection.DOWN;
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ public class TileEntityGen extends TileEntityMachine implements IPacketReceiver,
|
||||||
this.genAmmount = force / this.getVoltage();
|
this.genAmmount = force / this.getVoltage();
|
||||||
int wireCount = 0;
|
int wireCount = 0;
|
||||||
|
|
||||||
facing = ForgeDirection.getOrientation(MetaData.getMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord))).getOpposite();
|
facing = ForgeDirection.getOrientation(MetaGroupingHelper.getMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord))).getOpposite();
|
||||||
|
|
||||||
if (!this.isDisabled())
|
if (!this.isDisabled())
|
||||||
{
|
{
|
||||||
|
@ -224,4 +225,10 @@ public class TileEntityGen extends TileEntityMachine implements IPacketReceiver,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMeterReading(EntityPlayer user, ForgeDirection side)
|
||||||
|
{
|
||||||
|
return this.force+"N Input "+this.genAmmount+"W output";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,125 +14,147 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
import dark.BasicUtilities.BasicUtilitiesMain;
|
import dark.BasicUtilities.BasicUtilitiesMain;
|
||||||
import dark.BasicUtilities.api.IForce;
|
import dark.BasicUtilities.api.IForce;
|
||||||
|
import dark.BasicUtilities.api.IReadOut;
|
||||||
|
|
||||||
public class TileEntityRod extends TileEntity implements IPacketReceiver,IForce {
|
public class TileEntityRod extends TileEntity implements IPacketReceiver, IForce, IReadOut
|
||||||
|
{
|
||||||
|
|
||||||
public int pos = 0;
|
public int pos = 0;
|
||||||
private int force = 0;
|
private int force = 0;
|
||||||
private int pForce = 0;
|
private int pForce = 0;
|
||||||
public int aForce = 0;
|
public int aForce = 0;
|
||||||
public int forceMax = 1000;
|
public int forceMax = 1000;
|
||||||
private int tickCount = 0;
|
private int tickCount = 0;
|
||||||
private int posCount = 0;
|
private int posCount = 0;
|
||||||
|
|
||||||
private ForgeDirection frontDir;
|
private ForgeDirection frontDir;
|
||||||
private ForgeDirection backDir;
|
private ForgeDirection backDir;
|
||||||
|
|
||||||
private TileEntity bb;
|
private TileEntity bb;
|
||||||
private TileEntity ff;
|
private TileEntity ff;
|
||||||
@Override
|
|
||||||
public void updateEntity()
|
|
||||||
{
|
|
||||||
super.updateEntity();
|
|
||||||
if(tickCount++ >=10)
|
|
||||||
{ tickCount = 0;
|
|
||||||
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
|
||||||
frontDir = ForgeDirection.getOrientation(meta);
|
|
||||||
backDir = ForgeDirection.getOrientation(meta).getOpposite();
|
|
||||||
bb = worldObj.getBlockTileEntity(xCoord+backDir.offsetX, yCoord, zCoord+backDir.offsetZ);
|
|
||||||
ff = worldObj.getBlockTileEntity(xCoord+frontDir.offsetX, yCoord, zCoord+frontDir.offsetZ);
|
|
||||||
if(force > 0)
|
|
||||||
{
|
|
||||||
int posCountA = (forceMax/force) & 10;
|
|
||||||
if(posCount++ >= posCountA)
|
|
||||||
{
|
|
||||||
pos ++;if(pos > 7){pos = 0;};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(bb instanceof TileEntityRod)
|
|
||||||
{
|
|
||||||
this.pos = ((IForce)bb).getAnimationPos();
|
|
||||||
}
|
|
||||||
if(!worldObj.isRemote)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(ff instanceof IForce)
|
@Override
|
||||||
{
|
public void updateEntity()
|
||||||
if(((IForce) ff).canInputSide(backDir))
|
{
|
||||||
{
|
super.updateEntity();
|
||||||
((IForce) ff).applyForce(aForce);
|
if (tickCount++ >= 10)
|
||||||
}
|
{
|
||||||
}
|
tickCount = 0;
|
||||||
if(bb instanceof IForce)
|
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||||
{
|
frontDir = ForgeDirection.getOrientation(meta);
|
||||||
if(((IForce) bb).canOutputSide(frontDir))
|
backDir = ForgeDirection.getOrientation(meta).getOpposite();
|
||||||
{
|
bb = worldObj.getBlockTileEntity(xCoord + backDir.offsetX, yCoord, zCoord + backDir.offsetZ);
|
||||||
this.force = ((IForce) bb).getForce();
|
ff = worldObj.getBlockTileEntity(xCoord + frontDir.offsetX, yCoord, zCoord + frontDir.offsetZ);
|
||||||
}
|
if (force > 0)
|
||||||
}else
|
{
|
||||||
{
|
int posCountA = (forceMax / force) & 10;
|
||||||
this.force -=Math.max(force/10, 0);
|
if (posCount++ >= posCountA)
|
||||||
}
|
{
|
||||||
aForce = Math.max(force - 10,0);
|
pos++;
|
||||||
if(this.force != this.pForce)
|
if (pos > 7)
|
||||||
{
|
{
|
||||||
Packet packet = PacketManager.getPacket(BasicUtilitiesMain.CHANNEL,this, new Object[]{force});
|
pos = 0;
|
||||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
|
}
|
||||||
}
|
;
|
||||||
this.pForce = this.force;
|
}
|
||||||
}
|
}
|
||||||
}
|
if (bb instanceof TileEntityRod)
|
||||||
}
|
{
|
||||||
@Override
|
this.pos = ((IForce) bb).getAnimationPos();
|
||||||
public int getForceSide(ForgeDirection side) {
|
}
|
||||||
return aForce;
|
if (!worldObj.isRemote)
|
||||||
}
|
{
|
||||||
|
|
||||||
@Override
|
if (ff instanceof IForce)
|
||||||
public boolean canOutputSide(ForgeDirection side) {
|
{
|
||||||
if(side == frontDir)
|
if (((IForce) ff).canInputSide(backDir))
|
||||||
{
|
{
|
||||||
return true;
|
((IForce) ff).applyForce(aForce);
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}
|
if (bb instanceof IForce)
|
||||||
|
{
|
||||||
|
if (((IForce) bb).canOutputSide(frontDir))
|
||||||
|
{
|
||||||
|
this.force = ((IForce) bb).getForce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.force -= Math.max(force / 10, 0);
|
||||||
|
}
|
||||||
|
aForce = Math.max(force - 10, 0);
|
||||||
|
if (this.force != this.pForce)
|
||||||
|
{
|
||||||
|
Packet packet = PacketManager.getPacket(BasicUtilitiesMain.CHANNEL, this, new Object[]
|
||||||
|
{ force });
|
||||||
|
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
|
||||||
|
}
|
||||||
|
this.pForce = this.force;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInputSide(ForgeDirection side) {
|
public int getForceSide(ForgeDirection side)
|
||||||
if(side == backDir)
|
{
|
||||||
{
|
return aForce;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int applyForce(int force) {
|
public boolean canOutputSide(ForgeDirection side)
|
||||||
this.force = force;
|
{
|
||||||
return force;
|
if (side == frontDir) { return true; }
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlePacketData(INetworkManager network, int packetType,
|
public boolean canInputSide(ForgeDirection side)
|
||||||
Packet250CustomPayload packet, EntityPlayer player,
|
{
|
||||||
ByteArrayDataInput data) {
|
if (side == backDir) { return true; }
|
||||||
try
|
return false;
|
||||||
{
|
}
|
||||||
this.force = data.readInt();
|
|
||||||
}catch(Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
System.out.print("MechRodDataFailure \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
@Override
|
||||||
@Override
|
public int applyForce(int force)
|
||||||
public int getAnimationPos() {
|
{
|
||||||
return this.pos;
|
this.force = force;
|
||||||
}
|
return force;
|
||||||
@Override
|
}
|
||||||
public int getForce() {
|
|
||||||
// TODO Auto-generated method stub
|
@Override
|
||||||
return this.force;
|
public void handlePacketData(INetworkManager network, int packetType,
|
||||||
}
|
Packet250CustomPayload packet, EntityPlayer player,
|
||||||
|
ByteArrayDataInput data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.force = data.readInt();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.print("MechRodDataFailure \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAnimationPos()
|
||||||
|
{
|
||||||
|
return this.pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getForce()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return this.force;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMeterReading(EntityPlayer user, ForgeDirection side)
|
||||||
|
{
|
||||||
|
return this.aForce + "N Out " + this.force + "N In";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,11 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
import dark.BasicUtilities.BasicUtilitiesMain;
|
import dark.BasicUtilities.BasicUtilitiesMain;
|
||||||
import dark.BasicUtilities.api.IConsumer;
|
import dark.BasicUtilities.api.IConsumer;
|
||||||
import dark.BasicUtilities.api.IProducer;
|
import dark.BasicUtilities.api.IProducer;
|
||||||
|
import dark.BasicUtilities.api.IReadOut;
|
||||||
import dark.BasicUtilities.api.Liquid;
|
import dark.BasicUtilities.api.Liquid;
|
||||||
import dark.BasicUtilities.api.MHelper;
|
import dark.BasicUtilities.api.MHelper;
|
||||||
|
|
||||||
public class TileEntityPipe extends TileEntity implements IConsumer, IPacketReceiver
|
public class TileEntityPipe extends TileEntity implements IConsumer, IPacketReceiver,IReadOut
|
||||||
{
|
{
|
||||||
protected Liquid type = Liquid.DEFUALT;
|
protected Liquid type = Liquid.DEFUALT;
|
||||||
|
|
||||||
|
@ -225,4 +226,10 @@ public class TileEntityPipe extends TileEntity implements IConsumer, IPacketRece
|
||||||
par1NBTTagCompound.setInteger("liquid", this.liquidStored);
|
par1NBTTagCompound.setInteger("liquid", this.liquidStored);
|
||||||
par1NBTTagCompound.setInteger("type", this.type.ordinal());
|
par1NBTTagCompound.setInteger("type", this.type.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMeterReading(EntityPlayer user, ForgeDirection side)
|
||||||
|
{
|
||||||
|
return this.liquidStored+" "+this.type.name()+" @ "+this.presure+"PSI";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,12 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
import dark.BasicUtilities.BasicUtilitiesMain;
|
import dark.BasicUtilities.BasicUtilitiesMain;
|
||||||
import dark.BasicUtilities.api.IProducer;
|
import dark.BasicUtilities.api.IProducer;
|
||||||
|
import dark.BasicUtilities.api.IReadOut;
|
||||||
import dark.BasicUtilities.api.IStorageTank;
|
import dark.BasicUtilities.api.IStorageTank;
|
||||||
import dark.BasicUtilities.api.Liquid;
|
import dark.BasicUtilities.api.Liquid;
|
||||||
import dark.BasicUtilities.api.MHelper;
|
import dark.BasicUtilities.api.MHelper;
|
||||||
|
|
||||||
public class TileEntityLTank extends TileEntity implements IStorageTank, IProducer, IPacketReceiver
|
public class TileEntityLTank extends TileEntity implements IStorageTank, IProducer, IPacketReceiver,IReadOut
|
||||||
{
|
{
|
||||||
public TileEntity[] cc =
|
public TileEntity[] cc =
|
||||||
{ null, null, null, null, null, null };
|
{ null, null, null, null, null, null };
|
||||||
|
@ -196,4 +197,9 @@ public class TileEntityLTank extends TileEntity implements IStorageTank, IProduc
|
||||||
this.type = dm;
|
this.type = dm;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String getMeterReading(EntityPlayer user, ForgeDirection side)
|
||||||
|
{
|
||||||
|
return this.LStored+" "+"/"+this.LMax+" "+this.type.name()+" Stored";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue