Clean up and bug fixes
Fixed a packet being sent per tick bug tried to fix pipes not trading liquid 50% of the time fixed hardness & resistance off all blocks
This commit is contained in:
parent
8390bb786c
commit
5d2450a061
9 changed files with 110 additions and 126 deletions
|
@ -2,12 +2,16 @@ package basicpipes.conductors;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import basicpipes.BasicPipesMain;
|
||||
import basicpipes.pipes.api.ILiquidConsumer;
|
||||
import basicpipes.pipes.api.ILiquidProducer;
|
||||
import basicpipes.pipes.api.Liquid;
|
||||
|
||||
import net.minecraft.src.BlockContainer;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.Material;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -20,71 +24,25 @@ public class BlockPipe extends BlockContainer
|
|||
super(id, Material.iron);
|
||||
this.setBlockName("Pipe");
|
||||
this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
|
||||
this.setHardness(1f);
|
||||
this.setResistance(3f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
|
||||
* adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
|
||||
*/
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
|
||||
*/
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of render function that is called for this block
|
||||
*/
|
||||
public int getRenderType()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the items to drop on destruction.
|
||||
*/
|
||||
public int idDropped(int par1, Random par2Random, int par3)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
//Per tick
|
||||
public int conductorCapacity()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called whenever the block is added into the world. Args: world, x, y, z
|
||||
*/
|
||||
public boolean isOpaqueCube(){return false;}
|
||||
public boolean renderAsNormalBlock(){return false;}
|
||||
public int getRenderType(){return -1;}
|
||||
public int idDropped(int par1, Random par2Random, int par3){return 0;}
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
{
|
||||
super.onBlockAdded(world, x, y, z);
|
||||
|
||||
this.updateConductorTileEntity(world, x, y, z);
|
||||
}
|
||||
public static TileEntity getUEUnit(World world, int x, int y, int z, int side,Liquid type)
|
||||
public static TileEntity getLiquidUnit(World world, int x, int y, int z, int side,Liquid type)
|
||||
{
|
||||
switch(side)
|
||||
{
|
||||
case 0: y -= 1; break;
|
||||
case 1: y += 1; break;
|
||||
case 2: z += 1; break;
|
||||
case 3: z -= 1; break;
|
||||
case 4: x += 1; break;
|
||||
case 5: x -= 1; break;
|
||||
}
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(side);
|
||||
|
||||
//Check if the designated block is a UE Unit - producer, consumer or a conductor
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ);
|
||||
TileEntity returnValue = null;
|
||||
|
||||
if(tileEntity instanceof ILiquidConsumer)
|
||||
|
@ -137,7 +95,7 @@ public class BlockPipe extends BlockContainer
|
|||
{
|
||||
TileEntityPipe conductorTileEntity = (TileEntityPipe) tileEntity;
|
||||
Liquid type = conductorTileEntity.getType();
|
||||
conductorTileEntity.addConnection(getUEUnit(world, x, y, z, i, type), ForgeDirection.getOrientation(i));
|
||||
conductorTileEntity.addConnection(getLiquidUnit(world, x, y, z, i, type), ForgeDirection.getOrientation(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +105,28 @@ public class BlockPipe extends BlockContainer
|
|||
// TODO Auto-generated method stub
|
||||
return new TileEntityPipe();
|
||||
}
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z,int par5, int par6)
|
||||
{
|
||||
TileEntity ent = world.getBlockTileEntity(x, y, z);
|
||||
Random furnaceRand = new Random();
|
||||
if(ent instanceof TileEntityPipe)
|
||||
{
|
||||
TileEntityPipe pipe = (TileEntityPipe) ent;
|
||||
int meta = pipe.type.ordinal();
|
||||
float var8 = furnaceRand.nextFloat() * 0.8F + 0.1F;
|
||||
float var9 = furnaceRand.nextFloat() * 0.8F + 0.1F;
|
||||
float var10 = furnaceRand.nextFloat() * 0.8F + 0.1F;
|
||||
EntityItem var12 = new EntityItem(world, (double)((float)x + var8), (double)((float)y + var9),
|
||||
(double)((float)z + var10), new ItemStack(BasicPipesMain.itemPipes, 1, meta));
|
||||
float var13 = 0.05F;
|
||||
var12.motionX = (double)((float)furnaceRand.nextGaussian() * var13);
|
||||
var12.motionY = (double)((float)furnaceRand.nextGaussian() * var13 + 0.2F);
|
||||
var12.motionZ = (double)((float)furnaceRand.nextGaussian() * var13);
|
||||
world.spawnEntityInWorld(var12);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@ package basicpipes.conductors;
|
|||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.NetworkManager;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.Packet250CustomPayload;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.network.IPacketReceiver;
|
||||
import universalelectricity.network.PacketManager;
|
||||
import universalelectricity.prefab.Vector3;
|
||||
import basicpipes.pipes.api.ILiquidConsumer;
|
||||
import basicpipes.pipes.api.ILiquidProducer;
|
||||
import basicpipes.pipes.api.Liquid;
|
||||
|
@ -70,59 +72,58 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke
|
|||
}
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
//cause the block to update itself every tick needs to be change to .5 seconds to reduce load
|
||||
BlockPipe.updateConductorTileEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
count++;
|
||||
if(count >= 10 && !this.worldObj.isRemote)
|
||||
{
|
||||
PacketManager.sendTileEntityPacket(this, "Pipes", new Object[]{this.type.ordinal()});
|
||||
count = 0;
|
||||
{
|
||||
if(++count >= 5 && !this.worldObj.isRemote)
|
||||
{count = 0;
|
||||
//update connections
|
||||
BlockPipe.updateConductorTileEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
//send packet with liquid type data
|
||||
Packet packet = PacketManager.getPacket("Pipes",this, new Object[]{this.type.ordinal()});
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
|
||||
|
||||
|
||||
|
||||
int connectedUnits = 0;
|
||||
int pipes = 1;
|
||||
int producers = 0;
|
||||
int averageVolume = this.liquidStored;
|
||||
int averagePresure2 = 0;
|
||||
int aProducerPressure = 0;
|
||||
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
if(connectedBlocks[i] instanceof ILiquidConsumer || connectedBlocks[i] instanceof ILiquidProducer)
|
||||
if(connectedBlocks[i] instanceof ILiquidConsumer || connectedBlocks[i] instanceof ILiquidProducer)
|
||||
{
|
||||
connectedUnits ++;
|
||||
if(connectedBlocks[i] instanceof ILiquidProducer)
|
||||
{
|
||||
connectedUnits ++;
|
||||
if(connectedBlocks[i] instanceof ILiquidProducer)
|
||||
if(((ILiquidProducer)connectedBlocks[i]).canProducePresure(this.type, ForgeDirection.getOrientation(i)))
|
||||
{
|
||||
if(((ILiquidProducer)connectedBlocks[i]).canProducePresure(this.type, ForgeDirection.getOrientation(i)))
|
||||
{
|
||||
averagePresure2 += ((ILiquidProducer)connectedBlocks[i]).presureOutput(this.type,ForgeDirection.getOrientation(i));
|
||||
aProducerPressure += ((ILiquidProducer)connectedBlocks[i]).presureOutput(this.type,ForgeDirection.getOrientation(i));
|
||||
producers++;
|
||||
}
|
||||
}
|
||||
|
||||
if(connectedBlocks[i] instanceof TileEntityPipe)
|
||||
{
|
||||
pipes ++;
|
||||
//add pipes volume to average collection value
|
||||
averageVolume += ((TileEntityPipe)connectedBlocks[i]).liquidStored;
|
||||
//get the current pipes pressure
|
||||
int pPressure = ((TileEntityPipe)connectedBlocks[i]).presure ;
|
||||
if(pPressure > hPressure)
|
||||
{
|
||||
this.hPressure = pPressure;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(connectedBlocks[i] instanceof TileEntityPipe)
|
||||
{
|
||||
pipes ++;
|
||||
//add pipes volume to average collection value
|
||||
averageVolume += ((TileEntityPipe)connectedBlocks[i]).liquidStored;
|
||||
//get the current pipes pressure
|
||||
int pPressure = ((TileEntityPipe)connectedBlocks[i]).presure ;
|
||||
if(pPressure > hPressure)
|
||||
{
|
||||
this.hPressure = pPressure;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//turn average collection into actual average pipe volume
|
||||
averageVolume = Math.max(averageVolume/pipes,0);
|
||||
|
||||
|
||||
//sets the pressure of the pipe to the producer pressure or to the highest pipe pressure -1
|
||||
if(producers > 0)
|
||||
{
|
||||
averagePresure2 = Math.max(averagePresure2/producers,0);
|
||||
this.presure = averagePresure2;
|
||||
aProducerPressure = Math.max(aProducerPressure/producers,0);
|
||||
this.presure = aProducerPressure;
|
||||
}
|
||||
else
|
||||
if(connectedUnits > 0)
|
||||
|
@ -146,16 +147,12 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke
|
|||
{
|
||||
int transferVolumeAmount = 0; //amount to be moved
|
||||
ILiquidConsumer connectedConsumer = ((ILiquidConsumer)connectedBlocks[i]);
|
||||
if(connectedBlocks[i] instanceof TileEntityPipe)
|
||||
if(connectedConsumer instanceof TileEntityPipe)
|
||||
{
|
||||
if(((TileEntityPipe)connectedBlocks[i]).presure < this.presure)
|
||||
{
|
||||
transferVolumeAmount = this.liquidStored;
|
||||
}
|
||||
else
|
||||
{
|
||||
transferVolumeAmount = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -165,7 +162,7 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke
|
|||
int rejectedVolume = connectedConsumer.onReceiveLiquid(this.type,transferVolumeAmount, ForgeDirection.getOrientation(i));
|
||||
this.liquidStored = Math.max(Math.min(this.liquidStored - transferVolumeAmount + rejectedVolume, this.capacity), 0);
|
||||
}
|
||||
}else
|
||||
}
|
||||
if(connectedBlocks[i] instanceof ILiquidProducer && this.liquidStored < this.getLiquidCapacity(type))
|
||||
{
|
||||
if(((ILiquidProducer)connectedBlocks[i]).canProduceLiquid(this.type,ForgeDirection.getOrientation(i)))
|
||||
|
|
|
@ -52,8 +52,7 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan
|
|||
this.pos = ((IMechanical)bb).getAnimationPos();
|
||||
}
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
aForce = Math.max(force - 10,0);
|
||||
{
|
||||
if(ff instanceof IMechanical)
|
||||
{
|
||||
if(((IMechanical) ff).canInputSide(backDir))
|
||||
|
@ -61,7 +60,21 @@ public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechan
|
|||
((IMechanical) ff).applyForce(aForce);
|
||||
}
|
||||
}
|
||||
|
||||
if(bb instanceof IMechanical)
|
||||
{
|
||||
if(((IMechanical) bb).getForce() <= 0)
|
||||
{
|
||||
this.force = 0;
|
||||
}
|
||||
if(((IMechanical) bb).canOutputSide(frontDir))
|
||||
{
|
||||
this.force = ((IMechanical) bb).getForce();
|
||||
}
|
||||
}else
|
||||
{
|
||||
this.force = 0;
|
||||
}
|
||||
aForce = Math.max(force - 10,0);
|
||||
Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, new Object[]{force,aForce});
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,9 @@ public class BlockMachine extends BlockContainer
|
|||
this.setCreativeTab(CreativeTabs.tabBlock);
|
||||
this.setRequiresSelfNotify();
|
||||
this.blockIndexInTexture = 26;
|
||||
this.setHardness(1f);
|
||||
this.setResistance(3f);
|
||||
}
|
||||
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
|
@ -39,14 +40,6 @@ public class BlockMachine extends BlockContainer
|
|||
{
|
||||
return ItemRenderHelper.renderID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the items to drop on destruction.
|
||||
*/
|
||||
public int idDropped(int par1, Random par2Random, int par3)
|
||||
{
|
||||
return this.blockID;
|
||||
}
|
||||
protected int damageDropped(int meta)
|
||||
{
|
||||
if(meta < 4)
|
||||
|
|
|
@ -18,7 +18,7 @@ import steampower.burner.TileEntityFireBox;
|
|||
public class BlockMachine extends universalelectricity.prefab.BlockMachine
|
||||
{
|
||||
|
||||
private Random furnaceRand = new Random();
|
||||
private Random mRandom = new Random();
|
||||
private static boolean keepFurnaceInventory = true;
|
||||
|
||||
public BlockMachine(int par1)
|
||||
|
@ -26,7 +26,8 @@ public class BlockMachine extends universalelectricity.prefab.BlockMachine
|
|||
super("machine", par1, Material.iron);
|
||||
this.setRequiresSelfNotify();
|
||||
this.setCreativeTab(CreativeTabs.tabBlock);
|
||||
|
||||
this.setHardness(1f);
|
||||
this.setResistance(3f);
|
||||
}
|
||||
@Override
|
||||
protected int damageDropped(int metadata)
|
||||
|
@ -179,13 +180,13 @@ public class BlockMachine extends universalelectricity.prefab.BlockMachine
|
|||
|
||||
if (var7 != null)
|
||||
{
|
||||
float var8 = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
|
||||
float var9 = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
|
||||
float var10 = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
|
||||
float var8 = this.mRandom.nextFloat() * 0.8F + 0.1F;
|
||||
float var9 = this.mRandom.nextFloat() * 0.8F + 0.1F;
|
||||
float var10 = this.mRandom.nextFloat() * 0.8F + 0.1F;
|
||||
|
||||
while (var7.stackSize > 0)
|
||||
{
|
||||
int var11 = this.furnaceRand.nextInt(21) + 10;
|
||||
int var11 = this.mRandom.nextInt(21) + 10;
|
||||
|
||||
if (var11 > var7.stackSize)
|
||||
{
|
||||
|
@ -201,9 +202,9 @@ public class BlockMachine extends universalelectricity.prefab.BlockMachine
|
|||
}
|
||||
|
||||
float var13 = 0.05F;
|
||||
var12.motionX = (double)((float)this.furnaceRand.nextGaussian() * var13);
|
||||
var12.motionY = (double)((float)this.furnaceRand.nextGaussian() * var13 + 0.2F);
|
||||
var12.motionZ = (double)((float)this.furnaceRand.nextGaussian() * var13);
|
||||
var12.motionX = (double)((float)this.mRandom.nextGaussian() * var13);
|
||||
var12.motionY = (double)((float)this.mRandom.nextGaussian() * var13 + 0.2F);
|
||||
var12.motionZ = (double)((float)this.mRandom.nextGaussian() * var13);
|
||||
par1World.spawnEntityInWorld(var12);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public class TileEntityMachine extends TileEntity implements IInventory, ISided
|
|||
super.updateEntity();
|
||||
|
||||
if(count ++ >= 10 && !worldObj.isRemote)
|
||||
{
|
||||
{count = 0;
|
||||
Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, getSendData());
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ public class ContainerBoiler extends Container
|
|||
this.boiler = par2TileEntityboiler;
|
||||
this.addSlotToContainer(new Slot(par2TileEntityboiler, 0, 56, 17));
|
||||
int line;
|
||||
|
||||
for (line = 0; line < 3; ++line)
|
||||
{
|
||||
for (int slot = 0; slot < 9; ++slot)
|
||||
|
|
|
@ -119,7 +119,8 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv
|
|||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if(count++ >=20){
|
||||
if(count++ >=20)
|
||||
{
|
||||
count = 0;
|
||||
//update/resets connection list
|
||||
TileEntity[] entityList = TradeHelper.getSourounding(this);
|
||||
|
@ -168,7 +169,7 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv
|
|||
{
|
||||
heatStored = Math.max(heatStored - heatNeeded, 0);
|
||||
--waterStored;
|
||||
steamStored = Math.min(steamStored + SteamPowerMain.steamOutBoiler,this.steamMax);
|
||||
steamStored = Math.min(steamStored + 20,this.steamMax);
|
||||
}
|
||||
|
||||
TileEntity blockE = worldObj.getBlockTileEntity(xCoord, yCoord -1, zCoord);
|
||||
|
@ -176,11 +177,11 @@ public class TileEntityBoiler extends TileEntityMachine implements IPacketReceiv
|
|||
if(blockE instanceof IHeatProducer)
|
||||
{
|
||||
this.isBeingHeated = true;
|
||||
heatStored = (int) Math.min((heatStored + ((IHeatProducer)blockE).onProduceHeat(SteamPowerMain.fireOutput, 1)), heatMax);
|
||||
heatStored = (int) Math.min((heatStored + ((IHeatProducer)blockE).onProduceHeat(250, 1)), heatMax);
|
||||
}
|
||||
else if(worldObj.getBlockId(xCoord, yCoord-1, zCoord) == Block.lavaStill.blockID)
|
||||
{
|
||||
heatStored += (int) Math.min((int)(random.nextDouble()*10), heatMax);
|
||||
heatStored += (int) Math.min((int)(random.nextDouble()*100), heatMax);
|
||||
}
|
||||
}
|
||||
super.updateEntity();
|
||||
|
|
|
@ -49,7 +49,7 @@ public class TileEntityFireBox extends TileEntityMachine implements IPacketRecei
|
|||
addConnection();
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
sharCoal();
|
||||
sharCoal();
|
||||
}
|
||||
TileEntity blockEntity = worldObj.getBlockTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
|
||||
if(blockEntity instanceof TileEntityBoiler)
|
||||
|
@ -63,7 +63,7 @@ public class TileEntityFireBox extends TileEntityMachine implements IPacketRecei
|
|||
if (!this.worldObj.isRemote){
|
||||
|
||||
|
||||
maxGenerateRate = SteamPowerMain.fireOutput + (connectedUnits*5);
|
||||
maxGenerateRate = SteamPowerMain.fireOutput + (connectedUnits*10);
|
||||
|
||||
//The top slot is for recharging items. Check if the item is a electric item. If so, recharge it.
|
||||
if (this.storedItems[0] != null && isConnected)
|
||||
|
@ -127,7 +127,7 @@ public class TileEntityFireBox extends TileEntityMachine implements IPacketRecei
|
|||
}
|
||||
else
|
||||
{
|
||||
connectedConsumer.storedItems[0] = new ItemStack(this.storedItems[0].getItem());
|
||||
connectedConsumer.storedItems[0] = new ItemStack(this.storedItems[0].getItem(),1,this.storedItems[0].getItemDamage());
|
||||
this.storedItems[0].stackSize -= 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue