Fixed crates and allowed items to go up and down

This commit is contained in:
Henry Mao 2012-12-15 20:56:01 +08:00
parent f7968b4729
commit c8439b6590
7 changed files with 244 additions and 117 deletions

View file

@ -1 +1 @@
18
20

View file

@ -13,3 +13,4 @@ Minecraft 1.4.2
* AssemblyLine_v0.1.3.13.jar AssemblyLine_v0.1.3.13_api.zip
* AssemblyLine_v0.1.4.14.jar AssemblyLine_v0.1.4.14_api.zip
* AssemblyLine_v0.1.5.18.jar AssemblyLine_v0.1.5.18_api.zip
@ AssemblyLine_v0.1.6.19.jar AssemblyLine_v0.1.6.19_api.zip

View file

@ -5,8 +5,11 @@ import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
import assemblyline.client.model.ModelConveyorBelt;
import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.belt.BlockConveyorBelt;
import assemblyline.common.machine.belt.BlockConveyorBelt.SlantType;
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
@ -20,6 +23,7 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer
{
String flip = "";
boolean mid = tileEntity.getIsMiddleBelt();
SlantType slantType = BlockConveyorBelt.getSlant(tileEntity.worldObj, new Vector3(tileEntity));
int face = tileEntity.getDirection().ordinal();
GL11.glPushMatrix();
@ -27,14 +31,53 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer
GL11.glRotatef(180f, 0f, 0f, 1f);
this.bindTextureByName(AssemblyLine.TEXTURE_PATH + "BeltTexture" + flip + ".png");
switch(face)
switch (face)
{
case 2: GL11.glRotatef(0f, 0f, 1f, 0f);break;
case 3: GL11.glRotatef(180f, 0f, 1f, 0f);break;
case 4: GL11.glRotatef(-90f, 0f, 1f, 0f);break;
case 5: GL11.glRotatef(90f, 0f, 1f, 0f);break;
case 2:
GL11.glRotatef(0f, 0f, 1f, 0f);
break;
case 3:
GL11.glRotatef(180f, 0f, 1f, 0f);
break;
case 4:
GL11.glRotatef(-90f, 0f, 1f, 0f);
break;
case 5:
GL11.glRotatef(90f, 0f, 1f, 0f);
break;
}
if (slantType != null)
{
if (slantType == SlantType.UP)
{
if (face == 5 || face == 4)
{
GL11.glTranslatef(0f, 0f, 1f);
GL11.glRotatef(-45f, 1f, 0f, 0f);
}
else if (face == 2 || face == 3)
{
GL11.glTranslatef(0f, 0f, 1f);
GL11.glRotatef(-45f, 1f, 0f, 0f);
}
}
else if (slantType == SlantType.DOWN)
{
if (face == 5 || face == 4)
{
GL11.glTranslatef(0f, 0f, -1f);
GL11.glRotatef(45f, 1f, 0f, 0f);
}
else if (face == 2 || face == 3)
{
GL11.glTranslatef(0f, 0f, -1f);
GL11.glRotatef(45f, 1f, 0f, 0f);
}
}
}
int ent = tileEntity.worldObj.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
model.render(0.0625F, (float) Math.toRadians(tileEntity.wheelRotation), tileEntity.getIsBackCap(), tileEntity.getIsFrontCap(), false);

View file

@ -4,6 +4,7 @@ import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.core.UniversalElectricity;
@ -27,63 +28,56 @@ public class BlockCrate extends BlockMachine
}
/**
* Called upon block activation (right click on the block.)
* Placed the item the player is holding into the crate.
*/
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (world.getBlockTileEntity(x, y, z) != null)
if (!world.isRemote && world.getBlockTileEntity(x, y, z) != null)
{
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
ItemStack containingStack = tileEntity.getStackInSlot(0);
ItemStack itemStack = par5EntityPlayer.getCurrentEquippedItem();
if (itemStack != null)
{
if (tileEntity.containingItems[0] != null)
if (itemStack.isStackable())
{
if (tileEntity.containingItems[0].isItemEqual(itemStack))
if (containingStack != null)
{
tileEntity.containingItems[0].stackSize += itemStack.stackSize;
if (tileEntity.containingItems[0].stackSize > tileEntity.getInventoryStackLimit())
if (containingStack.isStackable() && containingStack.isItemEqual(itemStack))
{
itemStack.stackSize = tileEntity.containingItems[0].stackSize - tileEntity.getInventoryStackLimit();
}
else
{
itemStack.stackSize = 0;
}
int newStackSize = containingStack.stackSize + itemStack.stackSize;
int overFlowAmount = newStackSize - tileEntity.getInventoryStackLimit();
return true;
if (overFlowAmount > 0)
{
itemStack.stackSize = overFlowAmount;
}
else
{
itemStack.stackSize = 0;
}
containingStack.stackSize = newStackSize;
tileEntity.setInventorySlotContents(0, containingStack);
}
}
else
{
tileEntity.setInventorySlotContents(0, itemStack.copy());
itemStack.stackSize = 0;
}
}
else if (itemStack.isStackable())
{
tileEntity.containingItems[0] = itemStack;
itemStack.stackSize = 0;
return true;
}
if (itemStack.stackSize <= 0)
par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, null);
}
else if (tileEntity.containingItems[0] != null)
{
int amountToTake = Math.min(tileEntity.containingItems[0].stackSize, 64);
ItemStack newStack = tileEntity.containingItems[0].copy();
newStack.stackSize = amountToTake;
par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, newStack);
tileEntity.containingItems[0].stackSize -= amountToTake;
if (tileEntity.containingItems[0].stackSize <= 0)
{
tileEntity.containingItems[0] = null;
if (itemStack.stackSize <= 0)
{
par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, null);
}
}
}
}
return false;
return true;
}
/**
@ -92,28 +86,63 @@ public class BlockCrate extends BlockMachine
@Override
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (world.getBlockTileEntity(x, y, z) != null)
if (!world.isRemote && world.getBlockTileEntity(x, y, z) != null)
{
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
ItemStack containingStack = tileEntity.getStackInSlot(0);
if (tileEntity.containingItems[0] != null)
if (containingStack != null)
{
if (tileEntity.containingItems[0].stackSize > 0)
int amountToTake = Math.min(containingStack.stackSize, 64);
ItemStack dropStack = containingStack.copy();
dropStack.stackSize = amountToTake;
EntityItem entityItem = new EntityItem(world, par5EntityPlayer.posX, par5EntityPlayer.posY, par5EntityPlayer.posZ, dropStack);
float var13 = 0.05F;
entityItem.motionX = ((float) world.rand.nextGaussian() * var13);
entityItem.motionY = ((float) world.rand.nextGaussian() * var13 + 0.2F);
entityItem.motionZ = ((float) world.rand.nextGaussian() * var13);
entityItem.delayBeforeCanPickup = 0;
world.spawnEntityInWorld(entityItem);
containingStack.stackSize -= amountToTake;
if (containingStack.stackSize <= 0)
{
if (!world.isRemote)
{
float var6 = 0.7F;
double var7 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
double var9 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
double var11 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
ItemStack dropStack = new ItemStack(this, 1);
ItemBlockCrate.setContainingItemStack(dropStack, tileEntity.containingItems[0]);
EntityItem var13 = new EntityItem(world, (double) x + var7, (double) y + var9, (double) z + var11, dropStack);
var13.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(var13);
tileEntity.containingItems[0] = null;
world.setBlockWithNotify(x, y, z, 0);
}
containingStack = null;
}
tileEntity.setInventorySlotContents(0, containingStack);
}
}
return true;
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote && world.getBlockTileEntity(x, y, z) != null)
{
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
ItemStack containingStack = tileEntity.getStackInSlot(0);
if (containingStack != null)
{
if (containingStack.stackSize > 0)
{
float var6 = 0.7F;
double var7 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
double var9 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
double var11 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
ItemStack dropStack = new ItemStack(this, 1);
ItemBlockCrate.setContainingItemStack(dropStack, containingStack);
EntityItem var13 = new EntityItem(world, (double) x + var7, (double) y + var9, (double) z + var11, dropStack);
var13.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(var13);
tileEntity.setInventorySlotContents(0, null);
world.setBlockWithNotify(x, y, z, 0);
return true;
}
}

View file

@ -2,10 +2,13 @@ package assemblyline.common.block;
import java.util.List;
import assemblyline.common.AssemblyLine;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
public class ItemBlockCrate extends ItemBlock
@ -41,7 +44,15 @@ public class ItemBlockCrate extends ItemBlock
itemStack.setTagCompound(new NBTTagCompound());
}
containingStack.writeToNBT(itemStack.getTagCompound());
if (containingStack != null)
{
NBTTagCompound itemTagCompound = new NBTTagCompound();
containingStack.stackSize = Math.abs(containingStack.stackSize);
containingStack.writeToNBT(itemTagCompound);
itemStack.getTagCompound().setTag("Item", itemTagCompound);
itemStack.getTagCompound().setInteger("Count", containingStack.stackSize);
}
}
public static ItemStack getContainingItemStack(ItemStack itemStack)
@ -49,9 +60,18 @@ public class ItemBlockCrate extends ItemBlock
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
return null;
}
return ItemStack.loadItemStackFromNBT(itemStack.getTagCompound());
NBTTagCompound itemTagCompound = itemStack.getTagCompound().getCompoundTag("Item");
ItemStack containingStack = ItemStack.loadItemStackFromNBT(itemTagCompound);
if (containingStack != null)
{
containingStack.stackSize = itemStack.getTagCompound().getInteger("Count");
}
return containingStack;
}
@Override
@ -66,7 +86,7 @@ public class ItemBlockCrate extends ItemBlock
if (containingItem.stackSize > 0)
{
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
tileEntity.containingItems[0] = containingItem;
tileEntity.setInventorySlotContents(0, containingItem);
}
}
}

View file

@ -19,7 +19,7 @@ import universalelectricity.prefab.tile.TileEntityAdvanced;
public class TileEntityCrate extends TileEntityAdvanced implements ISidedInventory, IPacketReceiver
{
public ItemStack[] containingItems = new ItemStack[1];
private ItemStack[] containingItems = new ItemStack[1];
@Override
public boolean canUpdate()
@ -34,15 +34,22 @@ public class TileEntityCrate extends TileEntityAdvanced implements ISidedInvento
{
try
{
if (this.containingItems[0] == null)
if (dataStream.readBoolean())
{
this.containingItems[0] = new ItemStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
if (this.containingItems[0] == null)
{
this.containingItems[0] = new ItemStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
}
else
{
this.containingItems[0].itemID = dataStream.readInt();
this.containingItems[0].stackSize = dataStream.readInt();
this.containingItems[0].setItemDamage(dataStream.readInt());
}
}
else
{
this.containingItems[0].itemID = dataStream.readInt();
this.containingItems[0].stackSize = dataStream.readInt();
this.containingItems[0].setItemDamage(dataStream.readInt());
this.containingItems[0] = null;
}
}
catch (Exception e)
@ -55,8 +62,8 @@ public class TileEntityCrate extends TileEntityAdvanced implements ISidedInvento
@Override
public Packet getDescriptionPacket()
{
if (this.containingItems[0] != null) { return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.containingItems[0].itemID, this.containingItems[0].stackSize, this.containingItems[0].getItemDamage()); }
return null;
if (this.containingItems[0] != null) { return PacketManager.getPacket(AssemblyLine.CHANNEL, this, true, this.containingItems[0].itemID, this.containingItems[0].stackSize, this.containingItems[0].getItemDamage()); }
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, false);
}
/**
@ -122,11 +129,11 @@ public class TileEntityCrate extends TileEntityAdvanced implements ISidedInvento
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
{
par2ItemStack.stackSize = this.getInventoryStackLimit();
}
if (!this.worldObj.isRemote)
{
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj);
}
if (!this.worldObj.isRemote)
{
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj);
}
}
@ -155,6 +162,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements ISidedInvento
super.readFromNBT(nbt);
NBTTagList var2 = nbt.getTagList("Items");
this.containingItems = new ItemStack[this.getSizeInventory()];
for (int var3 = 0; var3 < var2.tagCount(); ++var3)
@ -167,6 +175,12 @@ public class TileEntityCrate extends TileEntityAdvanced implements ISidedInvento
this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4);
}
}
if (this.containingItems[0] != null)
{
this.containingItems[0].stackSize = nbt.getInteger("Count");
}
}
/**
@ -178,6 +192,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements ISidedInvento
super.writeToNBT(nbt);
NBTTagList var2 = new NBTTagList();
for (int var3 = 0; var3 < this.containingItems.length; ++var3)
{
if (this.containingItems[var3] != null)
@ -188,13 +203,19 @@ public class TileEntityCrate extends TileEntityAdvanced implements ISidedInvento
var2.appendTag(var4);
}
}
nbt.setTag("Items", var2);
if (this.containingItems[0] != null)
{
nbt.setInteger("Count", this.containingItems[0].stackSize);
}
}
@Override
public int getInventoryStackLimit()
{
return 2000;
return 4096;
}
@Override

View file

@ -12,6 +12,7 @@ import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.BlockMachine;
import universalelectricity.prefab.UETab;
import assemblyline.client.render.RenderHelper;
import assemblyline.common.AssemblyLine;
/**
* The block for the actual conveyor belt!
@ -20,6 +21,11 @@ import assemblyline.client.render.RenderHelper;
*/
public class BlockConveyorBelt extends BlockMachine
{
public enum SlantType
{
UP, DOWN
}
public BlockConveyorBelt(int id)
{
super("conveyorBelt", id, UniversalElectricity.machine);
@ -28,12 +34,12 @@ public class BlockConveyorBelt extends BlockMachine
}
/**
* Is this conveyor belt slanted towards a direction?
* Checks the front and the back position to find any conveyor blocks either higher or lower
* than this block to determine if it this conveyor block needs to slant.
*
* @return The ForgeDirection in which this conveyor belt is slanting against. The direction
* given is the high point of the slant. Return Unknown if not slanting.
* @return Returns of this belt is slanting up or down. Returns null if not slanting.
*/
public ForgeDirection getSlant(World world, Vector3 position)
public static SlantType getSlant(World world, Vector3 position)
{
TileEntity t = position.getTileEntity(world);
@ -42,12 +48,20 @@ public class BlockConveyorBelt extends BlockMachine
if (t instanceof TileEntityConveyorBelt)
{
TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt) t;
Vector3 highCheck = position.clone();
highCheck.modifyPositionFromSide(tileEntity.getDirection());
Vector3 frontCheck = position.clone();
frontCheck.modifyPositionFromSide(tileEntity.getDirection());
Vector3 backCheck = position.clone();
backCheck.modifyPositionFromSide(tileEntity.getDirection().getOpposite());
if (Vector3.add(frontCheck, new Vector3(0, 1, 0)).getBlockID(world) == AssemblyLine.blockConveyorBelt.blockID && Vector3.add(backCheck, new Vector3(0, -1, 0)).getBlockID(world) == AssemblyLine.blockConveyorBelt.blockID)
{
return SlantType.UP;
}
else if (Vector3.add(frontCheck, new Vector3(0, -1, 0)).getBlockID(world) == AssemblyLine.blockConveyorBelt.blockID && Vector3.add(backCheck, new Vector3(0, 1, 0)).getBlockID(world) == AssemblyLine.blockConveyorBelt.blockID) { return SlantType.DOWN; }
}
}
return ForgeDirection.UNKNOWN;
return null;
}
@Override
@ -112,43 +126,42 @@ public class BlockConveyorBelt extends BlockMachine
{
TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt) world.getBlockTileEntity(x, y, z);
// if (tileEntity.running)
if (tileEntity.running)
{
SlantType slantType = this.getSlant(world, new Vector3(x, y, z));
ForgeDirection direction = tileEntity.getDirection();
entity.addVelocity(direction.offsetX * tileEntity.speed, direction.offsetY * tileEntity.speed, direction.offsetZ * tileEntity.speed);
entity.onGround = false;
/*
* else if (metadata == 9) { entity.setVelocity(0.0D, 0.0D, 0.1D); entity.onGround =
* false; } else if (metadata == 10) { entity.setVelocity(-0.1D, 0.0D, 0.0D);
* entity.onGround = false; } else if (metadata == 11) { entity.setVelocity(0.0D, 0.0D,
* -0.1D); entity.onGround = false; }
*/
// Move the entity based on the conveyor belt's direction.
entity.addVelocity(direction.offsetX * tileEntity.speed, 0, direction.offsetZ * tileEntity.speed);
/*
* if (metadata == 4) { entity.setVelocity(0.1D, 0.2D, 0.0D); entity.onGround = false; }
* else if (metadata == 5) { entity.setVelocity(0.0D, 0.2D, 0.1D); entity.onGround =
* false; } else if (metadata == 6) { entity.setVelocity(-0.1D, 0.2D, 0.0D);
* entity.onGround = false; } else if (metadata == 7) { entity.setVelocity(0.0D, 0.2D,
* -0.1D); entity.onGround = false; } else if (metadata == 8) { entity.setVelocity(0.1D,
* 0.0D, 0.0D); entity.onGround = false; } else if (metadata == 9) {
* entity.setVelocity(0.0D, 0.0D, 0.1D); entity.onGround = false; } else if (metadata ==
* 10) { entity.setVelocity(-0.1D, 0.0D, 0.0D); entity.onGround = false; } else if
* (metadata == 11) { entity.setVelocity(0.0D, 0.0D, -0.1D); entity.onGround = false; }
* else if (metadata == 0) { if (entity.posZ > (double) z + 0.55D) {
* entity.setVelocity(0.05D, 0.0D, -0.05D); } else if (entity.posZ < (double) z + 0.45D)
* { entity.setVelocity(0.05D, 0.0D, 0.05D); } else { entity.setVelocity(0.1D, 0.0D,
* 0.0D); } } else if (metadata == 1) { if (entity.posX > (double) x + 0.55D) {
* entity.setVelocity(-0.05D, 0.0D, 0.05D); } else if (entity.posX < (double) x + 0.45D)
* { entity.setVelocity(0.05D, 0.0D, 0.05D); } else { entity.setVelocity(0.0D, 0.0D,
* 0.1D); } } else if (metadata == 2) { if (entity.posZ > (double) z + 0.55D) {
* entity.setVelocity(-0.05D, 0.0D, -0.05D); } else if (entity.posZ < (double) z +
* 0.45D) { entity.setVelocity(-0.05D, 0.0D, 0.05D); } else { entity.setVelocity(-0.1D,
* 0.0D, 0.0D); } } else if (metadata == 3) { if (entity.posX > (double) x + 0.55D) {
* entity.setVelocity(-0.05D, 0.0D, -0.05D); } else if (entity.posX < (double) x +
* 0.45D) { entity.setVelocity(0.05D, 0.0D, -0.05D); } else { entity.setVelocity(0.0D,
* 0.0D, -0.1D); } }
*/
// Attempt to move entity to the center of the belt to prevent them from flying off.
if (direction.offsetX != 0)
{
double difference = (z + 0.5) - entity.posZ;
entity.motionZ += difference * 0.005;
}
else if (direction.offsetZ != 0)
{
double difference = (x + 0.5) - entity.posX;
entity.motionX += difference * 0.005;
}
entity.onGround = false;
if (slantType == SlantType.UP)
{
if (entity.motionY < 0.2)
{
entity.addVelocity(0, 0.2, 0);
}
}
else if (slantType == SlantType.DOWN)
{
if (entity.motionY > -0.1)
{
entity.addVelocity(0, -0.1, 0);
}
}
}
}