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.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import dark.BasicUtilities.BasicUtilitiesMain;
|
||||
import dark.BasicUtilities.api.IForce;
|
||||
import dark.BasicUtilities.api.IReadOut;
|
||||
import dark.BasicUtilities.api.Liquid;
|
||||
import dark.BasicUtilities.pipes.TileEntityPipe;
|
||||
import dark.BasicUtilities.tanks.TileEntityLTank;
|
||||
|
@ -28,74 +30,49 @@ public class ItemGuage extends Item
|
|||
this.setCreativeTab(CreativeTabs.tabTools);
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
par3List.add(new ItemStack(this, 1, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconFromDamage(int par1)
|
||||
{
|
||||
switch (par1)
|
||||
{
|
||||
case 0: return 24;
|
||||
case 0:
|
||||
return 24;
|
||||
}
|
||||
return this.iconIndex;
|
||||
}
|
||||
public String getTextureFile() {
|
||||
|
||||
public String getTextureFile()
|
||||
{
|
||||
return BasicUtilitiesMain.ITEM_PNG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemName()
|
||||
{
|
||||
return "guage";
|
||||
}
|
||||
|
||||
@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 (itemStack.getItemDamage() == 0)
|
||||
{
|
||||
TileEntity blockEntity = par3World.getBlockTileEntity(par4, par5, par6);
|
||||
if(blockEntity instanceof TileEntityPipe)
|
||||
TileEntity blockEntity = par3World.getBlockTileEntity(x, y, z);
|
||||
if(blockEntity instanceof IReadOut)
|
||||
{
|
||||
TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity;
|
||||
Liquid type = pipeEntity.getType();
|
||||
int steam = pipeEntity.getStoredLiquid(type);
|
||||
int pressure = pipeEntity.presure;
|
||||
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;
|
||||
String output = ((IReadOut) blockEntity).getMeterReading(player,ForgeDirection.getOrientation(side));
|
||||
if(output.length() > 100) output = output.substring(0, 100);
|
||||
output.trim();
|
||||
player.sendChatToPlayer("ReadOut: "+output);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,12 +80,14 @@ public class ItemGuage extends Item
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getItemNameIS(ItemStack par1ItemStack)
|
||||
{
|
||||
int var3 = par1ItemStack.getItemDamage();
|
||||
switch (var3)
|
||||
{
|
||||
case 0: return "PipeGuage";
|
||||
case 0:
|
||||
return "PipeGuage";
|
||||
}
|
||||
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.api.IForce;
|
||||
import dark.Library.Util.MetaData;
|
||||
import dark.BasicUtilities.api.IReadOut;
|
||||
import dark.Library.Util.MetaGroupingHelper;
|
||||
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;
|
||||
|
||||
|
@ -42,7 +43,7 @@ public class TileEntityGen extends TileEntityMachine implements IPacketReceiver,
|
|||
this.genAmmount = force / this.getVoltage();
|
||||
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())
|
||||
{
|
||||
|
@ -224,4 +225,10 @@ public class TileEntityGen extends TileEntityMachine implements IPacketReceiver,
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMeterReading(EntityPlayer user, ForgeDirection side)
|
||||
{
|
||||
return this.force+"N Input "+this.genAmmount+"W output";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,8 +14,10 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
|
||||
import dark.BasicUtilities.BasicUtilitiesMain;
|
||||
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;
|
||||
private int force = 0;
|
||||
|
@ -30,12 +32,14 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IForce
|
|||
|
||||
private TileEntity bb;
|
||||
private TileEntity ff;
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
if (tickCount++ >= 10)
|
||||
{ tickCount = 0;
|
||||
{
|
||||
tickCount = 0;
|
||||
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||
frontDir = ForgeDirection.getOrientation(meta);
|
||||
backDir = ForgeDirection.getOrientation(meta).getOpposite();
|
||||
|
@ -46,7 +50,12 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IForce
|
|||
int posCountA = (forceMax / force) & 10;
|
||||
if (posCount++ >= posCountA)
|
||||
{
|
||||
pos ++;if(pos > 7){pos = 0;};
|
||||
pos++;
|
||||
if (pos > 7)
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
if (bb instanceof TileEntityRod)
|
||||
|
@ -69,45 +78,46 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IForce
|
|||
{
|
||||
this.force = ((IForce) bb).getForce();
|
||||
}
|
||||
}else
|
||||
}
|
||||
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});
|
||||
Packet packet = PacketManager.getPacket(BasicUtilitiesMain.CHANNEL, this, new Object[]
|
||||
{ force });
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
|
||||
}
|
||||
this.pForce = this.force;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getForceSide(ForgeDirection side) {
|
||||
public int getForceSide(ForgeDirection side)
|
||||
{
|
||||
return aForce;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOutputSide(ForgeDirection side) {
|
||||
if(side == frontDir)
|
||||
public boolean canOutputSide(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (side == frontDir) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputSide(ForgeDirection side) {
|
||||
if(side == backDir)
|
||||
public boolean canInputSide(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (side == backDir) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int applyForce(int force) {
|
||||
public int applyForce(int force)
|
||||
{
|
||||
this.force = force;
|
||||
return force;
|
||||
}
|
||||
|
@ -115,24 +125,36 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IForce
|
|||
@Override
|
||||
public void handlePacketData(INetworkManager network, int packetType,
|
||||
Packet250CustomPayload packet, EntityPlayer player,
|
||||
ByteArrayDataInput data) {
|
||||
ByteArrayDataInput data)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.force = data.readInt();
|
||||
}catch(Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.print("MechRodDataFailure \n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAnimationPos() {
|
||||
public int getAnimationPos()
|
||||
{
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getForce() {
|
||||
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.api.IConsumer;
|
||||
import dark.BasicUtilities.api.IProducer;
|
||||
import dark.BasicUtilities.api.IReadOut;
|
||||
import dark.BasicUtilities.api.Liquid;
|
||||
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;
|
||||
|
||||
|
@ -225,4 +226,10 @@ public class TileEntityPipe extends TileEntity implements IConsumer, IPacketRece
|
|||
par1NBTTagCompound.setInteger("liquid", this.liquidStored);
|
||||
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.api.IProducer;
|
||||
import dark.BasicUtilities.api.IReadOut;
|
||||
import dark.BasicUtilities.api.IStorageTank;
|
||||
import dark.BasicUtilities.api.Liquid;
|
||||
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 =
|
||||
{ null, null, null, null, null, null };
|
||||
|
@ -196,4 +197,9 @@ public class TileEntityLTank extends TileEntity implements IStorageTank, IProduc
|
|||
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