Allowed manipulator to accept energy transport

This commit is contained in:
Henry Mao 2012-12-19 01:12:47 +08:00
parent c474055404
commit 4a318d8a9b
7 changed files with 95 additions and 99 deletions

View file

@ -1 +1 @@
26
27

View file

@ -21,3 +21,4 @@ x AssemblyLine_v0.1.6.23.jar AssemblyLine_v0.1.6.23_api.zip
* AssemblyLine_v0.1.6.24.jar AssemblyLine_v0.1.6.24_api.zip
@ AssemblyLine_v0.1.7.25.jar AssemblyLine_v0.1.7.25_api.zip
* AssemblyLine_v0.1.7.26.jar AssemblyLine_v0.1.7.26_api.zip
* AssemblyLine_v0.1.7.27.jar AssemblyLine_v0.1.7.27_api.zip

View file

@ -30,7 +30,7 @@ public class BlockMulti extends BlockMachine
{
public static enum MachineType
{
REJECTOR("Sorter", 0, 0, TileEntityRejector.class), MANIPULATOR("Manipulator", 4, -1, TileEntityManipulator.class), INVALID_1("Invalid", 8, -1, null), INVALID_2("Invalid", 12, -1, null);
REJECTOR("Rejector", 0, 0, TileEntityRejector.class), MANIPULATOR("Manipulator", 4, -1, TileEntityManipulator.class), INVALID_1("Invalid", 8, -1, null), INVALID_2("Invalid", 12, -1, null);
public String name;
public int metadata;
@ -117,9 +117,11 @@ public class BlockMulti extends BlockMachine
{
int metadata = par1World.getBlockMetadata(x, y, z);
int guiID = MachineType.get(metadata).metadata;
if (guiID == -1)
return false;
if (guiID == -1) { return false; }
par5EntityPlayer.openGui(AssemblyLine.instance, guiID, par1World, x, y, z);
return true;
}
return true;

View file

@ -28,31 +28,35 @@ public abstract class TileEntityAssemblyNetwork extends TileEntityElectricityRec
*/
public int powerTransferRange = 0;
public boolean isBeingPowered()
public boolean isRunning()
{
if (this.wattsReceived > 0) { return true; }
return this.powerTransferRange > 0 || this.wattsReceived > this.getRequest().getWatts();
}
public void updatePowerTransferRange()
{
int maximumTransferRange = 0;
for (int i = 2; i < 6; i++)
for (int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
TileEntity tileEntity = worldObj.getBlockTileEntity(xCoord - direction.offsetX, yCoord, zCoord - direction.offsetZ);
TileEntity tileEntity = worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ);
if (tileEntity instanceof TileEntityConveyorBelt)
if (tileEntity != null)
{
TileEntityConveyorBelt belt = (TileEntityConveyorBelt) tileEntity;
if (belt.powerTransferRange > maximumTransferRange)
if (tileEntity instanceof TileEntityAssemblyNetwork)
{
maximumTransferRange = belt.powerTransferRange;
TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork) tileEntity;
if (assemblyNetwork.powerTransferRange > maximumTransferRange)
{
maximumTransferRange = assemblyNetwork.powerTransferRange;
}
}
}
}
this.powerTransferRange = maximumTransferRange - 1;
return this.powerTransferRange > 0;
this.powerTransferRange = Math.max(maximumTransferRange - 1, 0);
}
@Override
@ -80,14 +84,18 @@ public abstract class TileEntityAssemblyNetwork extends TileEntityElectricityRec
else
{
network.startRequesting(this, this.getRequest());
this.wattsReceived += network.consumeElectricity(this).getWatts();
this.wattsReceived += network.consumeElectricity(this).getWatts() * 2;
}
}
}
}
}
this.onUpdate();
if (this.ticks % 10 == 0)
{
if (this.wattsReceived >= this.getRequest().getWatts())
{
this.wattsReceived = 0;
@ -96,12 +104,29 @@ public abstract class TileEntityAssemblyNetwork extends TileEntityElectricityRec
else
{
this.powerTransferRange = 0;
this.updatePowerTransferRange();
}
}
}
protected abstract ElectricityPack getRequest();
protected void onUpdate()
{
protected abstract int getMaxTransferRange();
}
@Override
public double getVoltage()
{
return 20;
}
protected ElectricityPack getRequest()
{
return new ElectricityPack(15, this.getVoltage());
}
protected int getMaxTransferRange()
{
return 20;
}
}

View file

@ -15,6 +15,7 @@ import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.implement.IConductor;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.implement.IRedstoneReceptor;
@ -24,63 +25,30 @@ import universalelectricity.prefab.tile.TileEntityElectricityReceiver;
import assemblyline.api.IManipulator;
import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.BlockMulti.MachineType;
import assemblyline.common.machine.belt.TileEntityConveyorBelt.SlantType;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityManipulator extends TileEntityElectricityReceiver implements IRedstoneReceptor, IPacketReceiver, IManipulator
public class TileEntityManipulator extends TileEntityAssemblyNetwork implements IRedstoneReceptor, IPacketReceiver, IManipulator
{
/**
* Joules required to run this thing.
*/
public static final int WATT_REQUEST = 15;
/**
* The amount of watts received.
*/
public double wattsReceived = 0;
/**
* Is the manipulator wrenched to turn into output mode?
*/
public boolean isOutput = false;
private boolean isPowered = false;
private boolean isRedstonePowered = false;
@Override
public void updateEntity()
protected void onUpdate()
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 6; i++)
if (this.ticks % 20 == 0)
{
ForgeDirection inputDirection = ForgeDirection.getOrientation(i);
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, Vector3.get(this), inputDirection);
if (inputTile != null)
{
if (inputTile instanceof IConductor)
{
if (this.wattsReceived >= this.WATT_REQUEST)
{
((IConductor) inputTile).getNetwork().stopRequesting(this);
}
else
{
((IConductor) inputTile).getNetwork().startRequesting(this, this.WATT_REQUEST / this.getVoltage(), this.getVoltage());
this.wattsReceived += ((IConductor) inputTile).getNetwork().consumeElectricity(this).getWatts();
}
}
}
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 20);
}
}
if (!this.worldObj.isRemote)
{
if (!this.isDisabled() && this.wattsReceived >= this.WATT_REQUEST)
if (!this.isDisabled() && this.isRunning())
{
if (!this.isOutput)
{
@ -133,7 +101,7 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
/**
* Finds the connected inventory and outputs the items upon a redstone pulse.
*/
if (this.isPowered)
if (this.isRedstonePowered)
{
this.onPowerOff();
@ -170,8 +138,29 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
}
}
}
}
}
}
this.wattsReceived = 0;
@Override
public Packet getDescriptionPacket()
{
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.isOutput, this.wattsReceived);
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
if (worldObj.isRemote)
{
try
{
this.isOutput = dataStream.readBoolean();
this.wattsReceived = dataStream.readDouble();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
@ -394,12 +383,6 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
return ForgeDirection.getOrientation(MachineType.getDirection(this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)) + 2);
}
@Override
public Packet getDescriptionPacket()
{
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.isOutput);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
@ -420,25 +403,12 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
@Override
public void onPowerOn()
{
this.isPowered = true;
this.isRedstonePowered = true;
}
@Override
public void onPowerOff()
{
this.isPowered = false;
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try
{
this.isOutput = dataStream.readBoolean();
}
catch (Exception e)
{
e.printStackTrace();
}
this.isRedstonePowered = false;
}
}

View file

@ -106,8 +106,9 @@ public class BlockConveyorBelt extends BlockMachine
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity)
{
TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt) world.getBlockTileEntity(x, y, z);
tileEntity.updatePowerTransferRange();
if (tileEntity.isBeingPowered())
if (tileEntity.isRunning())
{
SlantType slantType = tileEntity.getSlant();
ForgeDirection direction = tileEntity.getDirection();

View file

@ -4,6 +4,8 @@ import java.util.EnumSet;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
@ -49,19 +51,21 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements
}
@Override
public void updateEntity()
public void onUpdate()
{
super.updateEntity();
if (!worldObj.isRemote && this.ticks % 10 == 0)
if (!worldObj.isRemote && this.ticks % 20 == 0)
{
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 15);
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 20);
}
if (this.isBeingPowered())
if (this.isRunning())
{
this.wheelRotation -= this.maxSpeed;
this.wheelRotation += 2;
if (this.wheelRotation > 360)
this.wheelRotation = 0;
}
}
@Override
@ -167,7 +171,6 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements
e.printStackTrace();
}
}
}
@Override
@ -209,10 +212,4 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements
nbt.setByte("slant", (byte) this.slantType.ordinal());
}
@Override
protected ElectricityPack getRequest()
{
return new ElectricityPack(10, this.getVoltage());
}
}