Massive reformatting
This commit is contained in:
parent
d3a40a764b
commit
a1caf9acf3
14 changed files with 376 additions and 325 deletions
|
@ -15,26 +15,30 @@ public class ALCommonProxy implements IGuiHandler
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void postInit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
switch(ID)
|
||||
{
|
||||
switch (ID)
|
||||
{
|
||||
case 0: return new GuiSorter(player.inventory, ((TileEntitySorter)tileEntity));
|
||||
case 0:
|
||||
return new GuiSorter(player.inventory, ((TileEntitySorter) tileEntity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -45,12 +49,13 @@ public class ALCommonProxy implements IGuiHandler
|
|||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
switch(ID)
|
||||
{
|
||||
switch (ID)
|
||||
{
|
||||
case 0: return new ContainerSorter(player.inventory, ((TileEntitySorter)tileEntity));
|
||||
case 0:
|
||||
return new ContainerSorter(player.inventory, ((TileEntitySorter) tileEntity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
|||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
@Mod(modid = "AssemblyLine", name = "Assembly Line", version = AssemblyLine.VERSION, dependencies = "after:BasicComponents")
|
||||
@NetworkMod(channels = { AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
|
||||
@NetworkMod(channels =
|
||||
{ AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
|
||||
public class AssemblyLine
|
||||
{
|
||||
@SidedProxy(clientSide = "assemblyline.ALClientProxy", serverSide = "assemblyline.ALCommonProxy")
|
||||
|
@ -52,7 +53,7 @@ public class AssemblyLine
|
|||
|
||||
public static final int BLOCK_ID_PREFIX = 3003;
|
||||
public static final Block blockConveyorBelt = new BlockConveyorBelt(UEConfig.getBlockConfigID(CONFIGURATION, "Conveyor Belt", BLOCK_ID_PREFIX));
|
||||
public static final Block blockInteraction = new BlockMulti(UEConfig.getBlockConfigID(CONFIGURATION, "Machine", BLOCK_ID_PREFIX+1));
|
||||
public static final Block blockInteraction = new BlockMulti(UEConfig.getBlockConfigID(CONFIGURATION, "Machine", BLOCK_ID_PREFIX + 1));
|
||||
|
||||
@PreInit
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
|
|
|
@ -16,7 +16,8 @@ public abstract class TileEntityBase extends TileEntityAdvanced implements IPack
|
|||
protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()];
|
||||
|
||||
/**
|
||||
* The amount of players using this tile entity.
|
||||
* The amount of players using this tile
|
||||
* entity.
|
||||
*/
|
||||
protected int playerUsing = 0;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import assemblyline.render.RenderHelper;
|
|||
|
||||
/**
|
||||
* The block for the actual conveyor belt!
|
||||
*
|
||||
* @author Calclavia, DarkGuardsman
|
||||
*/
|
||||
public class BlockConveyorBelt extends BlockMachine
|
||||
|
@ -29,13 +30,16 @@ public class BlockConveyorBelt extends BlockMachine
|
|||
int angle = MathHelper.floor_double((par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
par1World.setBlockMetadataWithNotify(x, y, z, angle);
|
||||
/*
|
||||
switch (angle)
|
||||
{
|
||||
case 0: par1World.setBlockMetadataWithNotify(x, y, z, 0); break;
|
||||
case 1: par1World.setBlockMetadataWithNotify(x, y, z, 3); break;
|
||||
case 2: par1World.setBlockMetadataWithNotify(x, y, z, 1); break;
|
||||
case 3: par1World.setBlockMetadataWithNotify(x, y, z, 2); break;
|
||||
} */
|
||||
* switch (angle) { case 0:
|
||||
* par1World.setBlockMetadataWithNotify(x,
|
||||
* y, z, 0); break; case 1:
|
||||
* par1World.setBlockMetadataWithNotify(x,
|
||||
* y, z, 3); break; case 2:
|
||||
* par1World.setBlockMetadataWithNotify(x,
|
||||
* y, z, 1); break; case 3:
|
||||
* par1World.setBlockMetadataWithNotify(x,
|
||||
* y, z, 2); break; }
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,11 +69,8 @@ public class BlockConveyorBelt extends BlockMachine
|
|||
*/
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1, int metadata)
|
||||
{
|
||||
if(metadata >=0 && metadata < 4)
|
||||
{
|
||||
return new TileEntityConveyorBelt();
|
||||
}
|
||||
{
|
||||
if (metadata >= 0 && metadata < 4) { return new TileEntityConveyorBelt(); }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
|
|||
|
||||
/**
|
||||
* Steal power from nearby belts.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean searchNeighborBelts()
|
||||
|
@ -188,9 +189,9 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
|
|||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
{
|
||||
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.wattsReceived);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double wattRequest()
|
||||
|
|
|
@ -29,14 +29,14 @@ public class BlockMulti extends BlockMachine
|
|||
{
|
||||
public static enum MachineType
|
||||
{
|
||||
SORTER("Sorter", 0,0, TileEntitySorter.class), MANIPULATOR("Manipulator", 4,-1, TileEntityManipulator.class), INVALID_1("Invalid", 8,-1, null), INVALID_2("Invalid", 12,-1, 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 int metadata;
|
||||
public int guiID;
|
||||
public Class<? extends TileEntity> tileEntity;
|
||||
|
||||
MachineType(String name, int metadata,int guiID, Class<? extends TileEntity> tileEntity)
|
||||
MachineType(String name, int metadata, int guiID, Class<? extends TileEntity> tileEntity)
|
||||
{
|
||||
this.name = name;
|
||||
this.metadata = metadata;
|
||||
|
@ -119,8 +119,9 @@ public class BlockMulti extends BlockMachine
|
|||
{
|
||||
int metadata = par1World.getBlockMetadata(x, y, z);
|
||||
int guiID = MachineType.get(metadata).metadata;
|
||||
if(guiID == -1) return false;
|
||||
par5EntityPlayer.openGui(AssemblyLine.instance,guiID , par1World, x, y, z);
|
||||
if (guiID == -1)
|
||||
return false;
|
||||
par5EntityPlayer.openGui(AssemblyLine.instance, guiID, par1World, x, y, z);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
@ -166,7 +167,7 @@ public class BlockMulti extends BlockMachine
|
|||
|
||||
if (MachineType.get(metadata) == MachineType.MANIPULATOR)
|
||||
{
|
||||
TileEntityManipulator tileEntity = (TileEntityManipulator)par1World.getBlockTileEntity(x, y, z);
|
||||
TileEntityManipulator tileEntity = (TileEntityManipulator) par1World.getBlockTileEntity(x, y, z);
|
||||
tileEntity.isOutput = !tileEntity.isOutput;
|
||||
|
||||
if (!par1World.isRemote)
|
||||
|
|
|
@ -9,87 +9,77 @@ import net.minecraft.src.Slot;
|
|||
|
||||
public class ContainerSorter extends Container
|
||||
{
|
||||
private TileEntitySorter tileEntity;
|
||||
private TileEntitySorter tileEntity;
|
||||
|
||||
public ContainerSorter(InventoryPlayer par1InventoryPlayer, TileEntitySorter tileEntity)
|
||||
{
|
||||
this.tileEntity = tileEntity;
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(tileEntity, 0+i, 33 +i*18, 34));
|
||||
}
|
||||
int var3;
|
||||
public ContainerSorter(InventoryPlayer par1InventoryPlayer, TileEntitySorter tileEntity)
|
||||
{
|
||||
this.tileEntity = tileEntity;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(tileEntity, 0 + i, 33 + i * 18, 34));
|
||||
}
|
||||
int var3;
|
||||
|
||||
for (var3 = 0; var3 < 3; ++var3)
|
||||
{
|
||||
for (int var4 = 0; var4 < 9; ++var4)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
|
||||
}
|
||||
}
|
||||
for (var3 = 0; var3 < 3; ++var3)
|
||||
{
|
||||
for (int var4 = 0; var4 < 9; ++var4)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (var3 = 0; var3 < 9; ++var3)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
|
||||
}
|
||||
}
|
||||
for (var3 = 0; var3 < 9; ++var3)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
|
||||
{
|
||||
return this.tileEntity.isUseableByPlayer(par1EntityPlayer);
|
||||
}
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
|
||||
{
|
||||
return this.tileEntity.isUseableByPlayer(par1EntityPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par1)
|
||||
{
|
||||
ItemStack itemStack3 = null;
|
||||
Slot itemStack = (Slot)this.inventorySlots.get(par1);
|
||||
/**
|
||||
* Called to transfer a stack from one
|
||||
* inventory to the other eg. when shift
|
||||
* clicking.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par1)
|
||||
{
|
||||
ItemStack itemStack3 = null;
|
||||
Slot itemStack = (Slot) this.inventorySlots.get(par1);
|
||||
|
||||
if (itemStack != null && itemStack.getHasStack())
|
||||
{
|
||||
ItemStack itemStack2 = itemStack.getStack();
|
||||
itemStack3 = itemStack2.copy();
|
||||
if (itemStack != null && itemStack.getHasStack())
|
||||
{
|
||||
ItemStack itemStack2 = itemStack.getStack();
|
||||
itemStack3 = itemStack2.copy();
|
||||
|
||||
if (par1 != 0)
|
||||
{
|
||||
if (itemStack2.itemID == Item.coal.shiftedIndex)
|
||||
{
|
||||
if (!this.mergeItemStack(itemStack2, 0, 1, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (par1 >= 30 && par1 < 37 && !this.mergeItemStack(itemStack2, 3, 30, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemStack2, 3, 37, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (par1 != 0)
|
||||
{
|
||||
if (itemStack2.itemID == Item.coal.shiftedIndex)
|
||||
{
|
||||
if (!this.mergeItemStack(itemStack2, 0, 1, false)) { return null; }
|
||||
}
|
||||
else if (par1 >= 30 && par1 < 37 && !this.mergeItemStack(itemStack2, 3, 30, false)) { return null; }
|
||||
}
|
||||
else if (!this.mergeItemStack(itemStack2, 3, 37, false)) { return null; }
|
||||
|
||||
if (itemStack2.stackSize == 0)
|
||||
{
|
||||
itemStack.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStack.onSlotChanged();
|
||||
}
|
||||
if (itemStack2.stackSize == 0)
|
||||
{
|
||||
itemStack.putStack((ItemStack) null);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStack.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemStack2.stackSize == itemStack3.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (itemStack2.stackSize == itemStack3.stackSize) { return null; }
|
||||
|
||||
itemStack.func_82870_a(par1EntityPlayer, itemStack2);
|
||||
}
|
||||
itemStack.func_82870_a(par1EntityPlayer, itemStack2);
|
||||
}
|
||||
|
||||
return itemStack3;
|
||||
}
|
||||
return itemStack3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class ItemBlockMulti extends ItemBlock
|
|||
|
||||
@Override
|
||||
public int getMetadata(int par1)
|
||||
{
|
||||
{
|
||||
return MachineType.get(par1).metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,13 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
|
||||
public class TileEntitySorter extends TileEntityBase implements
|
||||
IElectricityReceiver, IPacketReceiver {
|
||||
public class TileEntitySorter extends TileEntityBase implements IElectricityReceiver, IPacketReceiver
|
||||
{
|
||||
/**
|
||||
* Used to id the packet types
|
||||
*/
|
||||
private enum tPacketID {
|
||||
private enum tPacketID
|
||||
{
|
||||
ANIMATION, GUI, SETTINGON
|
||||
}
|
||||
|
||||
|
@ -49,80 +50,80 @@ public class TileEntitySorter extends TileEntityBase implements
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
public TileEntityConveyorBelt beltSide = null;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
// has to update a bit faster than a conveyer belt
|
||||
if (this.ticks % 5 == 0) {
|
||||
// has to update a bit faster than a
|
||||
// conveyer belt
|
||||
if (this.ticks % 5 == 0)
|
||||
{
|
||||
|
||||
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||
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);
|
||||
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;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this.beltSide = null;
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
// search area bound box
|
||||
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(xCoord
|
||||
+ searchPosition.offsetX, yCoord
|
||||
+ searchPosition.offsetY, zCoord
|
||||
+ searchPosition.offsetZ, xCoord
|
||||
+ searchPosition.offsetX + 1, yCoord
|
||||
+ searchPosition.offsetY + 1, zCoord
|
||||
+ searchPosition.offsetZ + 1);
|
||||
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(xCoord + searchPosition.offsetX, yCoord + searchPosition.offsetY, zCoord + searchPosition.offsetZ, xCoord + searchPosition.offsetX + 1, yCoord + searchPosition.offsetY + 1, zCoord + searchPosition.offsetZ + 1);
|
||||
// EntityItem list
|
||||
List<EntityItem> itemsBehind = worldObj.getEntitiesWithinAABB(
|
||||
EntityItem.class, bounds);
|
||||
List<EntityItem> itemsBehind = worldObj.getEntitiesWithinAABB(EntityItem.class, bounds);
|
||||
|
||||
boolean flag = false;
|
||||
|
||||
if (itemsBehind.size() > 0
|
||||
&& this.wattsReceived > this.WATTS_REQUIRED) {
|
||||
// for every item found check if can be thrown then throw
|
||||
if (itemsBehind.size() > 0 && 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) {
|
||||
if (this.canItemBeThrow(entity)) {
|
||||
for (EntityItem entity : itemsBehind)
|
||||
{
|
||||
if (this.canItemBeThrow(entity))
|
||||
{
|
||||
this.throwItem(searchPosition, entity);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// send packet with animation data if an item was rejected from
|
||||
// send packet with animation data
|
||||
// if an item was rejected from
|
||||
// the area
|
||||
if (!worldObj.isRemote && flag) {
|
||||
Packet packet = PacketManager.getPacket(
|
||||
AssemblyLine.CHANNEL, this,
|
||||
this.data(tPacketID.ANIMATION));
|
||||
PacketManager.sendPacketToClients(packet, worldObj,
|
||||
Vector3.get(this), 30);
|
||||
if (!worldObj.isRemote && flag)
|
||||
{
|
||||
Packet packet = PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.data(tPacketID.ANIMATION));
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 30);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!worldObj.isRemote && this.playerUsing > 0) {
|
||||
Packet packet = PacketManager.getPacket(AssemblyLine.CHANNEL,
|
||||
this, this.data(tPacketID.GUI));
|
||||
PacketManager.sendPacketToClients(packet, worldObj,
|
||||
Vector3.get(this), 10);
|
||||
if (!worldObj.isRemote && this.playerUsing > 0)
|
||||
{
|
||||
Packet packet = PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.data(tPacketID.GUI));
|
||||
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,9 +136,11 @@ public class TileEntitySorter extends TileEntityBase implements
|
|||
* @param entity
|
||||
* - Entity being thrown
|
||||
*/
|
||||
public void throwItem(ForgeDirection side, Entity entity) {
|
||||
public void throwItem(ForgeDirection side, Entity entity)
|
||||
{
|
||||
this.firePiston = true;
|
||||
if (this.beltSide != null) {
|
||||
if (this.beltSide != null)
|
||||
{
|
||||
this.beltSide.ignoreEntity(entity);
|
||||
|
||||
}
|
||||
|
@ -148,35 +151,36 @@ public class TileEntitySorter extends TileEntityBase implements
|
|||
this.wattsReceived -= this.WATTS_REQUIRED;
|
||||
}
|
||||
|
||||
public boolean canItemBeThrow(Entity entity) {
|
||||
public boolean canItemBeThrow(Entity entity)
|
||||
{
|
||||
// TODO add other things than items
|
||||
if (entity instanceof EntityItem) {
|
||||
if (entity instanceof EntityItem)
|
||||
{
|
||||
EntityItem itemE = (EntityItem) entity;
|
||||
ItemStack item = itemE.item;
|
||||
|
||||
if (this.onOff[4]) {
|
||||
if (this.onOff[4])
|
||||
{
|
||||
|
||||
// reject matching items
|
||||
for (int i = 0; i < this.containingItems.length; i++) {
|
||||
if (containingItems[i] != null && onOff[i]) {
|
||||
if (containingItems[i].itemID == item.itemID
|
||||
&& containingItems[i].getItemDamage() == item
|
||||
.getItemDamage()) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < this.containingItems.length; i++)
|
||||
{
|
||||
if (containingItems[i] != null && onOff[i])
|
||||
{
|
||||
if (containingItems[i].itemID == item.itemID && containingItems[i].getItemDamage() == item.getItemDamage()) { return true; }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
} else if (!this.onOff[4]) {
|
||||
}
|
||||
else if (!this.onOff[4])
|
||||
{
|
||||
// reject all but matching items
|
||||
for (int i = 0; i < this.containingItems.length; i++) {
|
||||
if (containingItems[i] != null && onOff[i]) {
|
||||
if (containingItems[i].itemID == item.itemID
|
||||
&& containingItems[i].getItemDamage() == item
|
||||
.getItemDamage()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.containingItems.length; i++)
|
||||
{
|
||||
if (containingItems[i] != null && onOff[i])
|
||||
{
|
||||
if (containingItems[i].itemID == item.itemID && containingItems[i].getItemDamage() == item.getItemDamage()) { return false; }
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -185,45 +189,51 @@ public class TileEntitySorter extends TileEntityBase implements
|
|||
return false;
|
||||
}
|
||||
|
||||
public byte getDirection(int meta) {
|
||||
public byte getDirection(int meta)
|
||||
{
|
||||
|
||||
switch (meta) {
|
||||
case 0:
|
||||
return 2;
|
||||
case 1:
|
||||
return 5;
|
||||
case 2:
|
||||
return 3;
|
||||
case 3:
|
||||
return 4;
|
||||
switch (meta)
|
||||
{
|
||||
case 0:
|
||||
return 2;
|
||||
case 1:
|
||||
return 5;
|
||||
case 2:
|
||||
return 3;
|
||||
case 3:
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveFromSide(ForgeDirection side) {
|
||||
public boolean canReceiveFromSide(ForgeDirection side)
|
||||
{
|
||||
return side == ForgeDirection.DOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* server side with the changes
|
||||
* 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 server side with the changes
|
||||
*
|
||||
* @param i
|
||||
*/
|
||||
public void changeOnOff(int i) {
|
||||
if (i >= this.onOff.length) {
|
||||
return;
|
||||
}
|
||||
if (this.onOff[i]) {
|
||||
public void changeOnOff(int i)
|
||||
{
|
||||
if (i >= this.onOff.length) { return; }
|
||||
if (this.onOff[i])
|
||||
{
|
||||
this.onOff[i] = false;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onOff[i] = true;
|
||||
}
|
||||
if (worldObj.isRemote) {
|
||||
Packet packet = PacketManager.getPacket("asmLine", this,
|
||||
tPacketID.SETTINGON.ordinal(), i);
|
||||
if (worldObj.isRemote)
|
||||
{
|
||||
Packet packet = PacketManager.getPacket("asmLine", this, tPacketID.SETTINGON.ordinal(), i);
|
||||
PacketDispatcher.sendPacketToServer(packet);
|
||||
}
|
||||
}
|
||||
|
@ -232,56 +242,71 @@ public class TileEntitySorter extends TileEntityBase implements
|
|||
* Data methods
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
public void readFromNBT(NBTTagCompound 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
for (int i = 0; i < this.onOff.length; i++) {
|
||||
for (int i = 0; i < this.onOff.length; i++)
|
||||
{
|
||||
nbt.setBoolean("onOff" + i, this.onOff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] data(tPacketID id) {
|
||||
if (id == tPacketID.ANIMATION) {
|
||||
return new Object[] { id.ordinal(), this.firePiston };
|
||||
}
|
||||
if (id == tPacketID.GUI) {
|
||||
public Object[] data(tPacketID id)
|
||||
{
|
||||
if (id == tPacketID.ANIMATION) { return new Object[]
|
||||
{ id.ordinal(), this.firePiston }; }
|
||||
if (id == tPacketID.GUI)
|
||||
{
|
||||
Object[] da = new Object[this.onOff.length];
|
||||
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];
|
||||
}
|
||||
return da;
|
||||
}
|
||||
return new Object[] { id.ordinal() };
|
||||
return new Object[]
|
||||
{ id.ordinal() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(INetworkManager network, int packetType,
|
||||
Packet250CustomPayload packet, EntityPlayer player,
|
||||
ByteArrayDataInput dataStream) {
|
||||
try {
|
||||
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = dataStream.readInt();
|
||||
tPacketID pID = tPacketID.values()[id];
|
||||
System.out.print("\n id:" + id + " ");
|
||||
if (pID == tPacketID.ANIMATION) {
|
||||
if (pID == tPacketID.ANIMATION)
|
||||
{
|
||||
this.firePiston = dataStream.readBoolean();
|
||||
} else if (pID == tPacketID.GUI) {
|
||||
for (int i = 0; i < this.onOff.length; i++) {
|
||||
}
|
||||
else if (pID == tPacketID.GUI)
|
||||
{
|
||||
for (int i = 0; i < this.onOff.length; i++)
|
||||
{
|
||||
this.onOff[i] = dataStream.readBoolean();
|
||||
}
|
||||
} else if (pID == tPacketID.SETTINGON) {
|
||||
}
|
||||
else if (pID == tPacketID.SETTINGON)
|
||||
{
|
||||
int num = dataStream.readInt();
|
||||
this.changeOnOff(num);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -290,17 +315,20 @@ public class TileEntitySorter extends TileEntityBase implements
|
|||
* inventory methods
|
||||
*/
|
||||
@Override
|
||||
public String getInvName() {
|
||||
public String getInvName()
|
||||
{
|
||||
return "Rejector";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
@ -308,17 +336,20 @@ public class TileEntitySorter extends TileEntityBase implements
|
|||
* disabling methods
|
||||
*/
|
||||
@Override
|
||||
public void onDisable(int duration) {
|
||||
public void onDisable(int duration)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisabled() {
|
||||
public boolean isDisabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection side) {
|
||||
public boolean canConnect(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -326,18 +357,20 @@ public class TileEntitySorter extends TileEntityBase implements
|
|||
* UE methods
|
||||
*/
|
||||
@Override
|
||||
public double getVoltage() {
|
||||
public double getVoltage()
|
||||
{
|
||||
return 120;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double wattRequest() {
|
||||
public double wattRequest()
|
||||
{
|
||||
return WATTS_REQUIRED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(TileEntity sender, double amps, double voltage,
|
||||
ForgeDirection side) {
|
||||
public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side)
|
||||
{
|
||||
this.wattsReceived += (amps * voltage);
|
||||
|
||||
}
|
||||
|
|
|
@ -8,24 +8,29 @@ import net.minecraft.src.EntityItem;
|
|||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
public class ArmHelper {
|
||||
public class ArmHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to locate items in an area
|
||||
* @param start - start xyz
|
||||
* @param End - end xyz
|
||||
*
|
||||
* @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);
|
||||
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);
|
||||
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
|
||||
|
@ -34,14 +39,13 @@ public class ArmHelper {
|
|||
*/
|
||||
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);
|
||||
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)
|
||||
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())
|
||||
if (stackItem.itemID != stack.itemID || stackItem.getItemDamage() != stack.getItemDamage())
|
||||
{
|
||||
itemsList.remove(item);
|
||||
}
|
||||
|
|
|
@ -9,58 +9,66 @@ import net.minecraft.src.TileEntity;
|
|||
import net.minecraft.src.World;
|
||||
import assemblyline.AssemblyLine;
|
||||
|
||||
public class BlockCrafter extends BlockMachine {
|
||||
protected BlockCrafter(int par1) {
|
||||
public class BlockCrafter extends BlockMachine
|
||||
{
|
||||
protected BlockCrafter(int par1)
|
||||
{
|
||||
super("AutoCrafters", par1, Material.iron);
|
||||
this.setResistance(5.0f);
|
||||
this.setHardness(5.0f);
|
||||
this.setCreativeTab(CreativeTabs.tabTools);
|
||||
}
|
||||
|
||||
public static enum CrafterType {
|
||||
CRAFTER("Crafter", 0,-1, TileEntityAutoCrafter.class);
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
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
|
||||
* Gets the direction based on the
|
||||
* metadata
|
||||
*
|
||||
* @return A direction value from 0 to 4.
|
||||
*/
|
||||
public static int getDirection(int metadata) {
|
||||
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.
|
||||
* @return The metadata this block should
|
||||
* change into.
|
||||
*/
|
||||
public int getNextDirectionMeta(int currentDirection) {
|
||||
public int getNextDirectionMeta(int currentDirection)
|
||||
{
|
||||
currentDirection++;
|
||||
|
||||
if (currentDirection >= 4) {
|
||||
if (currentDirection >= 4)
|
||||
{
|
||||
currentDirection = 0;
|
||||
}
|
||||
|
||||
|
@ -70,10 +78,14 @@ public class BlockCrafter extends BlockMachine {
|
|||
/**
|
||||
* Creates a new TIleEntity.
|
||||
*/
|
||||
public TileEntity instantiateTileEntity() {
|
||||
try {
|
||||
public TileEntity instantiateTileEntity()
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.tileEntity.newInstance();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
@ -81,37 +93,40 @@ public class BlockCrafter extends BlockMachine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1) {
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1, int metadata) {
|
||||
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) {
|
||||
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);
|
||||
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) {
|
||||
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getRenderType() {
|
||||
public int getRenderType()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,14 +7,16 @@ import net.minecraft.src.ItemStack;
|
|||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
public class EntityCraftingArm extends Entity {
|
||||
public class EntityCraftingArm extends Entity
|
||||
{
|
||||
/**
|
||||
* Used to ID the type of arm
|
||||
*/
|
||||
static enum armType
|
||||
{
|
||||
ARM,SOLDER,DRILL,BREAKER
|
||||
ARM, SOLDER, DRILL, BREAKER
|
||||
}
|
||||
|
||||
/**
|
||||
* type of arm this robotic arm currently is
|
||||
*/
|
||||
|
@ -34,7 +36,8 @@ public class EntityCraftingArm extends Entity {
|
|||
|
||||
public boolean isWorking = false;
|
||||
|
||||
public EntityCraftingArm(World par1World) {
|
||||
public EntityCraftingArm(World par1World)
|
||||
{
|
||||
super(par1World);
|
||||
}
|
||||
|
||||
|
@ -45,22 +48,24 @@ public class EntityCraftingArm extends Entity {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
protected void readEntityFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
this.arm = armType.values()[nbt.getInteger("type")];
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbt) {
|
||||
protected void writeEntityToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setInteger("type", arm.ordinal());
|
||||
|
||||
}
|
||||
|
||||
public boolean grabItem(EntityItem item)
|
||||
{
|
||||
if(this.stack == null)
|
||||
if (this.stack == null)
|
||||
{
|
||||
//TODO set current stack to item as soon as it reaches coords
|
||||
// TODO set current stack to item as
|
||||
// soon as it reaches coords
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ package assemblyline.machines.crafter;
|
|||
|
||||
import net.minecraft.src.Item;
|
||||
|
||||
public class ItemCrafterArm extends Item {
|
||||
public class ItemCrafterArm extends Item
|
||||
{
|
||||
|
||||
protected ItemCrafterArm(int par1) {
|
||||
protected ItemCrafterArm(int par1)
|
||||
{
|
||||
super(par1);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
|
|
@ -3,30 +3,22 @@ package assemblyline.machines.crafter;
|
|||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.INetworkManager;
|
||||
import net.minecraft.src.Packet250CustomPayload;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.ISidedInventory;
|
||||
import assemblyline.AssemblyLine;
|
||||
import assemblyline.TileEntityBase;
|
||||
import assemblyline.machines.BlockMulti.MachineType;
|
||||
import universalelectricity.prefab.TileEntityAdvanced;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
public class TileEntityAutoCrafter extends TileEntityBase
|
||||
public class TileEntityAutoCrafter extends TileEntityAdvanced
|
||||
{
|
||||
@Override
|
||||
public String getInvName()
|
||||
{
|
||||
return "Auto Crafter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in a new issue