Nothing much
just uploading to upload, also change multiBlock enum for the machine too include a Gui ID, the way you had it Calc was ok but wasteful.
This commit is contained in:
parent
c97a065429
commit
ea693be636
5 changed files with 258 additions and 126 deletions
|
@ -29,16 +29,18 @@ public class BlockMulti extends BlockMachine
|
||||||
{
|
{
|
||||||
public static enum MachineType
|
public static enum MachineType
|
||||||
{
|
{
|
||||||
SORTER("Sorter", 0, TileEntitySorter.class), MANIPULATOR("Manipulator", 4, TileEntityManipulator.class), INVALID_1("Invalid", 8, null), INVALID_2("Invalid", 12, null);
|
SORTER("Sorter", 0,0, TileEntitySorter.class), MANIPULATOR("Manipulator", 4,-1, TileEntityManipulator.class), INVALID_1("Invalid", 8,-1, null), INVALID_2("Invalid", 12,-1, null);
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
public int metadata;
|
public int metadata;
|
||||||
|
public int guiID;
|
||||||
public Class<? extends TileEntity> tileEntity;
|
public Class<? extends TileEntity> tileEntity;
|
||||||
|
|
||||||
MachineType(String name, int metadata, Class<? extends TileEntity> tileEntity)
|
MachineType(String name, int metadata,int guiID, Class<? extends TileEntity> tileEntity)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
|
this.guiID = guiID;
|
||||||
this.tileEntity = tileEntity;
|
this.tileEntity = tileEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +118,9 @@ public class BlockMulti extends BlockMachine
|
||||||
if (!par1World.isRemote)
|
if (!par1World.isRemote)
|
||||||
{
|
{
|
||||||
int metadata = par1World.getBlockMetadata(x, y, z);
|
int metadata = par1World.getBlockMetadata(x, y, z);
|
||||||
par5EntityPlayer.openGui(AssemblyLine.instance, MachineType.get(metadata).metadata, par1World, x, y, z);
|
int guiID = MachineType.get(metadata).metadata;
|
||||||
|
if(guiID == -1) return false;
|
||||||
|
par5EntityPlayer.openGui(AssemblyLine.instance,guiID , par1World, x, y, z);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -254,4 +258,5 @@ public class BlockMulti extends BlockMachine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,12 @@ import cpw.mods.fml.common.network.PacketDispatcher;
|
||||||
public class TileEntitySorter extends TileEntityBase implements
|
public class TileEntitySorter extends TileEntityBase implements
|
||||||
IElectricityReceiver, IPacketReceiver {
|
IElectricityReceiver, IPacketReceiver {
|
||||||
/**
|
/**
|
||||||
* Used to id the packet types
|
* Used to id the packet types
|
||||||
*/
|
*/
|
||||||
private enum tPacketID{ANIMATION,GUI,SETTINGON}
|
private enum tPacketID {
|
||||||
|
ANIMATION, GUI, SETTINGON
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Joules required per tick.
|
* Joules required per tick.
|
||||||
*/
|
*/
|
||||||
|
@ -46,73 +49,80 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
/**
|
/**
|
||||||
* on/off value for the GUI buttons
|
* on/off value for the GUI buttons
|
||||||
*/
|
*/
|
||||||
public boolean[] onOff = new boolean[]{true,true,true,true,true};
|
public boolean[] onOff = new boolean[] { true, true, true, true, true };
|
||||||
/**
|
/**
|
||||||
* the belt found in the search area
|
* the belt found in the search area
|
||||||
*/
|
*/
|
||||||
public TileEntityConveyorBelt beltSide = null;
|
public TileEntityConveyorBelt beltSide = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
//has to update a bit faster than a conveyer belt
|
// has to update a bit faster than a conveyer belt
|
||||||
if (this.ticks % 5 == 0) {
|
if (this.ticks % 5 == 0) {
|
||||||
|
|
||||||
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||||
this.firePiston = false;
|
this.firePiston = false;
|
||||||
|
|
||||||
//area to search for items
|
|
||||||
ForgeDirection searchPosition = Vector3.getOrientationFromSide(ForgeDirection.getOrientation(getDirection(meta)), ForgeDirection.SOUTH);
|
|
||||||
TileEntity tileEntity = worldObj.getBlockTileEntity(xCoord+ searchPosition.offsetX, yCoord + searchPosition.offsetY, zCoord + searchPosition.offsetZ);
|
|
||||||
|
|
||||||
//find the belt in that search area
|
// area to search for items
|
||||||
|
ForgeDirection searchPosition = Vector3.getOrientationFromSide(
|
||||||
|
ForgeDirection.getOrientation(getDirection(meta)),
|
||||||
|
ForgeDirection.SOUTH);
|
||||||
|
TileEntity tileEntity = worldObj.getBlockTileEntity(xCoord
|
||||||
|
+ searchPosition.offsetX, yCoord + searchPosition.offsetY,
|
||||||
|
zCoord + searchPosition.offsetZ);
|
||||||
|
|
||||||
|
// find the belt in that search area
|
||||||
if (tileEntity instanceof TileEntityConveyorBelt) {
|
if (tileEntity instanceof TileEntityConveyorBelt) {
|
||||||
this.beltSide = (TileEntityConveyorBelt) tileEntity;
|
this.beltSide = (TileEntityConveyorBelt) tileEntity;
|
||||||
} else {
|
} else {
|
||||||
this.beltSide = null;
|
this.beltSide = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//search area bound box
|
// search area bound box
|
||||||
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(
|
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(xCoord
|
||||||
xCoord + searchPosition.offsetX,
|
+ searchPosition.offsetX, yCoord
|
||||||
yCoord + searchPosition.offsetY,
|
+ searchPosition.offsetY, zCoord
|
||||||
zCoord + searchPosition.offsetZ,
|
+ searchPosition.offsetZ, xCoord
|
||||||
xCoord + searchPosition.offsetX + 1,
|
+ searchPosition.offsetX + 1, yCoord
|
||||||
yCoord + searchPosition.offsetY + 1,
|
+ searchPosition.offsetY + 1, zCoord
|
||||||
zCoord + searchPosition.offsetZ + 1);
|
+ searchPosition.offsetZ + 1);
|
||||||
//EntityItem list
|
// EntityItem list
|
||||||
List<EntityItem> itemsBehind = worldObj.getEntitiesWithinAABB(EntityItem.class, bounds);
|
List<EntityItem> itemsBehind = worldObj.getEntitiesWithinAABB(
|
||||||
|
EntityItem.class, bounds);
|
||||||
|
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
|
|
||||||
if (itemsBehind.size() > 0 && this.wattsReceived > this.WATTS_REQUIRED) {
|
if (itemsBehind.size() > 0
|
||||||
//for every item found check if can be thrown then throw item off belt if it can
|
&& this.wattsReceived > this.WATTS_REQUIRED) {
|
||||||
|
// for every item found check if can be thrown then throw
|
||||||
|
// item off belt if it can
|
||||||
for (EntityItem entity : itemsBehind) {
|
for (EntityItem entity : itemsBehind) {
|
||||||
if (this.canItemBeThrow(entity))
|
if (this.canItemBeThrow(entity)) {
|
||||||
{
|
|
||||||
this.throwItem(searchPosition, entity);
|
this.throwItem(searchPosition, entity);
|
||||||
flag = true;
|
flag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//send packet with animation data if an item was rejected from the area
|
// send packet with animation data if an item was rejected from
|
||||||
if(!worldObj.isRemote && flag)
|
// the area
|
||||||
{
|
if (!worldObj.isRemote && flag) {
|
||||||
Packet packet = PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.data(tPacketID.ANIMATION));
|
Packet packet = PacketManager.getPacket(
|
||||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 30);
|
AssemblyLine.CHANNEL, this,
|
||||||
|
this.data(tPacketID.ANIMATION));
|
||||||
|
PacketManager.sendPacketToClients(packet, worldObj,
|
||||||
|
Vector3.get(this), 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if(!worldObj.isRemote && this.playerUsing > 0)
|
if (!worldObj.isRemote && this.playerUsing > 0) {
|
||||||
{
|
Packet packet = PacketManager.getPacket(AssemblyLine.CHANNEL,
|
||||||
Packet packet = PacketManager.getPacket(AssemblyLine.CHANNEL,this, this.data(tPacketID.GUI));
|
this, this.data(tPacketID.GUI));
|
||||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 10);
|
PacketManager.sendPacketToClients(packet, worldObj,
|
||||||
|
Vector3.get(this), 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,21 +145,23 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
entity.motionX = (double) side.offsetX * 0.1;
|
entity.motionX = (double) side.offsetX * 0.1;
|
||||||
entity.motionY += 0.10000000298023224D;
|
entity.motionY += 0.10000000298023224D;
|
||||||
entity.motionZ = (double) side.offsetZ * 0.1;
|
entity.motionZ = (double) side.offsetZ * 0.1;
|
||||||
this.wattsReceived -= this.WATTS_REQUIRED;
|
this.wattsReceived -= this.WATTS_REQUIRED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canItemBeThrow(Entity entity) {
|
public boolean canItemBeThrow(Entity entity) {
|
||||||
//TODO add other things than items
|
// TODO add other things than items
|
||||||
if (entity instanceof EntityItem) {
|
if (entity instanceof EntityItem) {
|
||||||
EntityItem itemE = (EntityItem) entity;
|
EntityItem itemE = (EntityItem) entity;
|
||||||
ItemStack item = itemE.item;
|
ItemStack item = itemE.item;
|
||||||
|
|
||||||
if (this.onOff[4]) {
|
if (this.onOff[4]) {
|
||||||
|
|
||||||
//reject matching items
|
// reject matching items
|
||||||
for (int i = 0; i < this.containingItems.length; i++) {
|
for (int i = 0; i < this.containingItems.length; i++) {
|
||||||
if (containingItems[i] != null && onOff[i]) {
|
if (containingItems[i] != null && onOff[i]) {
|
||||||
if (containingItems[i].itemID == item.itemID && containingItems[i].getItemDamage() == item.getItemDamage()) {
|
if (containingItems[i].itemID == item.itemID
|
||||||
|
&& containingItems[i].getItemDamage() == item
|
||||||
|
.getItemDamage()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,10 +169,12 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} else if (!this.onOff[4]) {
|
} else if (!this.onOff[4]) {
|
||||||
//reject all but matching items
|
// reject all but matching items
|
||||||
for (int i = 0; i < this.containingItems.length; i++) {
|
for (int i = 0; i < this.containingItems.length; i++) {
|
||||||
if (containingItems[i] != null&& onOff[i]) {
|
if (containingItems[i] != null && onOff[i]) {
|
||||||
if (containingItems[i].itemID == item.itemID && containingItems[i].getItemDamage() == item.getItemDamage()) {
|
if (containingItems[i].itemID == item.itemID
|
||||||
|
&& containingItems[i].getItemDamage() == item
|
||||||
|
.getItemDamage()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +205,6 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
return side == ForgeDirection.DOWN;
|
return side == ForgeDirection.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to change any one of the boolean value of on/off array After
|
* Used to change any one of the boolean value of on/off array After
|
||||||
* changing the value if it was changed client side it will send a packet
|
* changing the value if it was changed client side it will send a packet
|
||||||
|
@ -210,22 +223,22 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
}
|
}
|
||||||
if (worldObj.isRemote) {
|
if (worldObj.isRemote) {
|
||||||
Packet packet = PacketManager.getPacket("asmLine", this,
|
Packet packet = PacketManager.getPacket("asmLine", this,
|
||||||
tPacketID.SETTINGON.ordinal(), i );
|
tPacketID.SETTINGON.ordinal(), i);
|
||||||
PacketDispatcher.sendPacketToServer(packet);
|
PacketDispatcher.sendPacketToServer(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data methods
|
* Data methods
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
for (int i = 0; i < this.onOff.length; i++) {
|
for (int i = 0; i < this.onOff.length; i++) {
|
||||||
this.onOff[i] = nbt.getBoolean("onOff" + i);
|
this.onOff[i] = nbt.getBoolean("onOff" + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt) {
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
@ -233,57 +246,46 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
nbt.setBoolean("onOff" + i, this.onOff[i]);
|
nbt.setBoolean("onOff" + i, this.onOff[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] data(tPacketID id)
|
public Object[] data(tPacketID id) {
|
||||||
{
|
if (id == tPacketID.ANIMATION) {
|
||||||
if(id == tPacketID.ANIMATION)
|
return new Object[] { id.ordinal(), this.firePiston };
|
||||||
{
|
|
||||||
return new Object[]{id.ordinal(),this.firePiston};
|
|
||||||
}
|
}
|
||||||
if(id == tPacketID.GUI)
|
if (id == tPacketID.GUI) {
|
||||||
{
|
|
||||||
Object[] da = new Object[this.onOff.length];
|
Object[] da = new Object[this.onOff.length];
|
||||||
da[0]= id.ordinal();
|
da[0] = id.ordinal();
|
||||||
for(int i =0; i < this.onOff.length; i++)
|
for (int i = 0; i < this.onOff.length; i++) {
|
||||||
{
|
da[i + 1] = onOff[i];
|
||||||
da[i+1] = onOff[i];
|
|
||||||
}
|
}
|
||||||
return da;
|
return da;
|
||||||
}
|
}
|
||||||
return new Object[]{id.ordinal()};
|
return new Object[] { id.ordinal() };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlePacketData(INetworkManager network, int packetType,
|
public void handlePacketData(INetworkManager network, int packetType,
|
||||||
Packet250CustomPayload packet, EntityPlayer player,
|
Packet250CustomPayload packet, EntityPlayer player,
|
||||||
ByteArrayDataInput dataStream) {
|
ByteArrayDataInput dataStream) {
|
||||||
try{
|
try {
|
||||||
int id = dataStream.readInt();
|
int id = dataStream.readInt();
|
||||||
tPacketID pID = tPacketID.values()[id];
|
tPacketID pID = tPacketID.values()[id];
|
||||||
System.out.print("\n id:"+id+" ");
|
System.out.print("\n id:" + id + " ");
|
||||||
if(pID == tPacketID.ANIMATION)
|
if (pID == tPacketID.ANIMATION) {
|
||||||
{
|
this.firePiston = dataStream.readBoolean();
|
||||||
this.firePiston = dataStream.readBoolean();
|
} else if (pID == tPacketID.GUI) {
|
||||||
}else
|
for (int i = 0; i < this.onOff.length; i++) {
|
||||||
if(pID == tPacketID.GUI)
|
this.onOff[i] = dataStream.readBoolean();
|
||||||
{
|
|
||||||
for(int i =0; i < this.onOff.length; i++)
|
|
||||||
{
|
|
||||||
this.onOff[i] = dataStream.readBoolean();
|
|
||||||
}
|
|
||||||
}else
|
|
||||||
if(pID == tPacketID.SETTINGON)
|
|
||||||
{
|
|
||||||
int num = dataStream.readInt();
|
|
||||||
this.changeOnOff(num);
|
|
||||||
}
|
}
|
||||||
|
} else if (pID == tPacketID.SETTINGON) {
|
||||||
}catch(Exception e)
|
int num = dataStream.readInt();
|
||||||
{
|
this.changeOnOff(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inventory methods
|
* inventory methods
|
||||||
*/
|
*/
|
||||||
|
@ -296,12 +298,12 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
public int getInventoryStackLimit() {
|
public int getInventoryStackLimit() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory() {
|
public int getSizeInventory() {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* disabling methods
|
* disabling methods
|
||||||
*/
|
*/
|
||||||
|
@ -319,7 +321,7 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
public boolean canConnect(ForgeDirection side) {
|
public boolean canConnect(ForgeDirection side) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UE methods
|
* UE methods
|
||||||
*/
|
*/
|
||||||
|
@ -327,19 +329,17 @@ public class TileEntitySorter extends TileEntityBase implements
|
||||||
public double getVoltage() {
|
public double getVoltage() {
|
||||||
return 120;
|
return 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double wattRequest() {
|
public double wattRequest() {
|
||||||
return WATTS_REQUIRED;
|
return WATTS_REQUIRED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(TileEntity sender, double amps, double voltage,
|
public void onReceive(TileEntity sender, double amps, double voltage,
|
||||||
ForgeDirection side) {
|
ForgeDirection side) {
|
||||||
this.wattsReceived += (amps * voltage);
|
this.wattsReceived += (amps * voltage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
51
src/common/assemblyline/machines/crafter/ArmHelper.java
Normal file
51
src/common/assemblyline/machines/crafter/ArmHelper.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package assemblyline.machines.crafter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import universalelectricity.core.Vector3;
|
||||||
|
import net.minecraft.src.AxisAlignedBB;
|
||||||
|
import net.minecraft.src.EntityItem;
|
||||||
|
import net.minecraft.src.ItemStack;
|
||||||
|
import net.minecraft.src.World;
|
||||||
|
|
||||||
|
public class ArmHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to locate items in an area
|
||||||
|
* @param start - start xyz
|
||||||
|
* @param End - end xyz
|
||||||
|
* @return list of items
|
||||||
|
*/
|
||||||
|
public List<EntityItem> findItems(World world, Vector3 start, Vector3 end)
|
||||||
|
{
|
||||||
|
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(start.x,start.y,start.z,end.x,end.x,end.x);
|
||||||
|
// EntityItem list
|
||||||
|
List<EntityItem> itemsList = world.getEntitiesWithinAABB(
|
||||||
|
EntityItem.class, bounds);
|
||||||
|
return itemsList;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Used to locate an item type in an area
|
||||||
|
* @param world
|
||||||
|
* @param start
|
||||||
|
* @param end
|
||||||
|
* @param item
|
||||||
|
* @return list of matching items
|
||||||
|
*/
|
||||||
|
public List<EntityItem> findItems(World world, Vector3 start, Vector3 end, ItemStack stack)
|
||||||
|
{
|
||||||
|
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(start.x,start.y,start.z,end.x,end.x,end.x);
|
||||||
|
// EntityItem list
|
||||||
|
List<EntityItem> itemsList = world.getEntitiesWithinAABB(
|
||||||
|
EntityItem.class, bounds);
|
||||||
|
for(EntityItem item : itemsList)
|
||||||
|
{
|
||||||
|
ItemStack stackItem = item.item;
|
||||||
|
if(stackItem.itemID != stack.itemID || stackItem.getItemDamage() != stack.getItemDamage())
|
||||||
|
{
|
||||||
|
itemsList.remove(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return itemsList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,45 +1,117 @@
|
||||||
package assemblyline.machines.crafter;
|
package assemblyline.machines.crafter;
|
||||||
|
|
||||||
|
import universalelectricity.prefab.BlockMachine;
|
||||||
import net.minecraft.src.BlockContainer;
|
import net.minecraft.src.BlockContainer;
|
||||||
import net.minecraft.src.CreativeTabs;
|
import net.minecraft.src.CreativeTabs;
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
import net.minecraft.src.Material;
|
import net.minecraft.src.Material;
|
||||||
import net.minecraft.src.TileEntity;
|
import net.minecraft.src.TileEntity;
|
||||||
import net.minecraft.src.World;
|
import net.minecraft.src.World;
|
||||||
|
import assemblyline.AssemblyLine;
|
||||||
|
|
||||||
public class BlockCrafter extends BlockContainer
|
public class BlockCrafter extends BlockMachine {
|
||||||
{
|
protected BlockCrafter(int par1) {
|
||||||
protected BlockCrafter(int par1)
|
super("AutoCrafters", par1, Material.iron);
|
||||||
{
|
|
||||||
super(par1, Material.iron);
|
|
||||||
this.setResistance(5.0f);
|
this.setResistance(5.0f);
|
||||||
this.setHardness(5.0f);
|
this.setHardness(5.0f);
|
||||||
this.setCreativeTab(CreativeTabs.tabTools);
|
this.setCreativeTab(CreativeTabs.tabTools);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static enum CrafterType {
|
||||||
|
CRAFTER("Crafter", 0,-1, TileEntityAutoCrafter.class);
|
||||||
|
|
||||||
|
public String name;
|
||||||
|
public int metadata;
|
||||||
|
public int guiID;
|
||||||
|
public Class<? extends TileEntity> tileEntity;
|
||||||
|
|
||||||
|
CrafterType(String name, int metadata,int guiID,
|
||||||
|
Class<? extends TileEntity> tileEntity) {
|
||||||
|
this.name = name;
|
||||||
|
this.metadata = metadata;
|
||||||
|
this.guiID = guiID;
|
||||||
|
this.tileEntity = tileEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CrafterType get(int metadata) {
|
||||||
|
for (CrafterType value : CrafterType.values()) {
|
||||||
|
if (metadata >= value.metadata && metadata < value.metadata + 4) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the direction based on the metadata
|
||||||
|
*
|
||||||
|
* @return A direction value from 0 to 4.
|
||||||
|
*/
|
||||||
|
public static int getDirection(int metadata) {
|
||||||
|
return metadata - CrafterType.get(metadata).metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param currentDirection
|
||||||
|
* - An integer from 0 to 4.
|
||||||
|
* @return The metadata this block should change into.
|
||||||
|
*/
|
||||||
|
public int getNextDirectionMeta(int currentDirection) {
|
||||||
|
currentDirection++;
|
||||||
|
|
||||||
|
if (currentDirection >= 4) {
|
||||||
|
currentDirection = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentDirection + this.metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new TIleEntity.
|
||||||
|
*/
|
||||||
|
public TileEntity instantiateTileEntity() {
|
||||||
|
try {
|
||||||
|
return this.tileEntity.newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World var1) {
|
public TileEntity createNewTileEntity(World var1) {
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public TileEntity createNewTileEntity(World var1, int meta) {
|
|
||||||
if(meta >= 0 && meta < 4)
|
|
||||||
{
|
|
||||||
return new TileEntityAutoCrafter();
|
|
||||||
}
|
|
||||||
if(meta >= 4 && meta < 8)
|
|
||||||
{
|
|
||||||
return new TileEntityCraftingArm();
|
|
||||||
}
|
|
||||||
if(meta >= 8 && meta < 12)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
if(meta >= 12 && meta < 16)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity createNewTileEntity(World var1, int metadata) {
|
||||||
|
return CrafterType.get(metadata).instantiateTileEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMachineActivated(World par1World, int x, int y, int z,
|
||||||
|
EntityPlayer par5EntityPlayer) {
|
||||||
|
if (!par1World.isRemote) {
|
||||||
|
int metadata = par1World.getBlockMetadata(x, y, z);
|
||||||
|
int guiID = CrafterType.get(metadata).metadata;
|
||||||
|
if (guiID == -1)
|
||||||
|
return false;
|
||||||
|
par5EntityPlayer.openGui(AssemblyLine.instance, guiID, par1World,
|
||||||
|
x, y, z);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onSneakUseWrench(World par1World, int x, int y, int z,
|
||||||
|
EntityPlayer par5EntityPlayer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRenderType() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,12 @@ package assemblyline.machines.crafter;
|
||||||
import net.minecraft.src.EntityPlayer;
|
import net.minecraft.src.EntityPlayer;
|
||||||
import net.minecraft.src.INetworkManager;
|
import net.minecraft.src.INetworkManager;
|
||||||
import net.minecraft.src.Packet250CustomPayload;
|
import net.minecraft.src.Packet250CustomPayload;
|
||||||
|
import net.minecraft.src.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.common.ISidedInventory;
|
import net.minecraftforge.common.ISidedInventory;
|
||||||
|
import assemblyline.AssemblyLine;
|
||||||
import assemblyline.TileEntityBase;
|
import assemblyline.TileEntityBase;
|
||||||
|
import assemblyline.machines.BlockMulti.MachineType;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
@ -28,4 +31,5 @@ public class TileEntityAutoCrafter extends TileEntityBase
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue