diff --git a/src/main/java/api/hbm/ntl/StorageManifest.java b/src/main/java/api/hbm/ntl/StorageManifest.java index 3106dcb98..a1be6d9cc 100644 --- a/src/main/java/api/hbm/ntl/StorageManifest.java +++ b/src/main/java/api/hbm/ntl/StorageManifest.java @@ -1,6 +1,9 @@ package api.hbm.ntl; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -27,11 +30,30 @@ public class StorageManifest { meta.metaNBT.put(stack.getItemDamage(), nbt); } - long amount = nbt.nbtAmount.containsKey(stack.stackTagCompound) ? nbt.nbtAmount.get(stack.stackTagCompound) : 0; + NBTTagCompound compound = stack.hasTagCompound() ? (NBTTagCompound) stack.stackTagCompound.copy() : null; + long amount = nbt.nbtAmount.containsKey(compound) ? nbt.nbtAmount.get(compound) : 0; amount += stack.stackSize; - nbt.nbtAmount.put(stack.stackTagCompound, amount); + nbt.nbtAmount.put(compound, amount); + } + + public List getStacks() { + List stacks = new ArrayList(); + + for(Entry itemNode : itemMeta.entrySet()) { + for(Entry metaNode : itemNode.getValue().metaNBT.entrySet()) { + for(Entry nbtNode : metaNode.getValue().nbtAmount.entrySet()) { + + ItemStack itemStack = new ItemStack(Item.getItemById(itemNode.getKey()), 1, metaNode.getKey()); + itemStack.stackTagCompound = nbtNode.getKey(); + StorageStack stack = new StorageStack(itemStack, nbtNode.getValue()); + stacks.add(stack); + } + } + } + + return stacks; } public class MetaNode { diff --git a/src/main/java/com/hbm/blocks/network/CraneBoxer.java b/src/main/java/com/hbm/blocks/network/CraneBoxer.java index 811731a83..5c66aee95 100644 --- a/src/main/java/com/hbm/blocks/network/CraneBoxer.java +++ b/src/main/java/com/hbm/blocks/network/CraneBoxer.java @@ -10,6 +10,8 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -59,7 +61,14 @@ public class CraneBoxer extends BlockCraneBase implements IEnterableBlock { @Override public void onItemEnter(World world, int x, int y, int z, ForgeDirection dir, IConveyorItem entity) { + TileEntityCraneBoxer boxer = (TileEntityCraneBoxer) world.getTileEntity(x, y, z); + ItemStack remainder = CraneInserter.addToInventory(boxer, boxer.getAccessibleSlotsFromSide(dir.ordinal()), entity.getItemStack(), dir.ordinal()); + + if(remainder != null && remainder.stackSize > 0) { + EntityItem drop = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, remainder.copy()); + world.spawnEntityInWorld(drop); + } } @Override diff --git a/src/main/java/com/hbm/blocks/network/CraneUnboxer.java b/src/main/java/com/hbm/blocks/network/CraneUnboxer.java index 710e61711..499ee0903 100644 --- a/src/main/java/com/hbm/blocks/network/CraneUnboxer.java +++ b/src/main/java/com/hbm/blocks/network/CraneUnboxer.java @@ -10,6 +10,8 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -61,11 +63,20 @@ public class CraneUnboxer extends BlockCraneBase implements IEnterableBlock { @Override public boolean canPackageEnter(World world, int x, int y, int z, ForgeDirection dir, IConveyorPackage entity) { - return false; + return true; } @Override public void onPackageEnter(World world, int x, int y, int z, ForgeDirection dir, IConveyorPackage entity) { + TileEntityCraneUnboxer unboxer = (TileEntityCraneUnboxer) world.getTileEntity(x, y, z); + for(ItemStack stack : entity.getItemStacks()) { + ItemStack remainder = CraneInserter.addToInventory(unboxer, unboxer.getAccessibleSlotsFromSide(dir.ordinal()), stack, dir.ordinal()); + + if(remainder != null && remainder.stackSize > 0) { + EntityItem drop = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, remainder.copy()); + world.spawnEntityInWorld(drop); + } + } } } diff --git a/src/main/java/com/hbm/entity/EntityMappings.java b/src/main/java/com/hbm/entity/EntityMappings.java index f402e48c9..9f9c0db4b 100644 --- a/src/main/java/com/hbm/entity/EntityMappings.java +++ b/src/main/java/com/hbm/entity/EntityMappings.java @@ -171,6 +171,7 @@ public class EntityMappings { addEntity(EntitySoyuz.class, "entity_soyuz", 1000); addEntity(EntitySoyuzCapsule.class, "entity_soyuz_capsule", 1000); addEntity(EntityMovingItem.class, "entity_c_item", 1000); + addEntity(EntityMovingPackage.class, "entity_c_package", 1000); addEntity(EntityCloudTom.class, "entity_moonstone_blast", 1000); addEntity(EntityBeamVortex.class, "entity_vortex_beam", 1000); addEntity(EntityFireworks.class, "entity_firework_ball", 1000); diff --git a/src/main/java/com/hbm/entity/item/EntityMovingConveyorObject.java b/src/main/java/com/hbm/entity/item/EntityMovingConveyorObject.java new file mode 100644 index 000000000..779696bba --- /dev/null +++ b/src/main/java/com/hbm/entity/item/EntityMovingConveyorObject.java @@ -0,0 +1,164 @@ +package com.hbm.entity.item; + +import com.hbm.lib.Library; +import com.hbm.util.fauxpointtwelve.BlockPos; + +import api.hbm.conveyor.IConveyorBelt; +import api.hbm.conveyor.IEnterableBlock; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public abstract class EntityMovingConveyorObject extends Entity { + + protected int turnProgress; + protected double syncPosX; + protected double syncPosY; + protected double syncPosZ; + @SideOnly(Side.CLIENT) protected double velocityX; + @SideOnly(Side.CLIENT) protected double velocityY; + @SideOnly(Side.CLIENT) protected double velocityZ; + + public EntityMovingConveyorObject(World world) { + super(world); + this.noClip = true; + } + + @Override + public boolean canBeCollidedWith() { + return true; + } + + @Override + public boolean canAttackWithItem() { + return true; + } + + @Override + public boolean hitByEntity(Entity attacker) { + + if(attacker instanceof EntityPlayer) { + this.setDead(); + } + + return false; + } + + @Override + protected boolean canTriggerWalking() { + return true; + } + + @Override + public void onUpdate() { + + if(worldObj.isRemote) { + if(this.turnProgress > 0) { + double interpX = this.posX + (this.syncPosX - this.posX) / (double) this.turnProgress; + double interpY = this.posY + (this.syncPosY - this.posY) / (double) this.turnProgress; + double interpZ = this.posZ + (this.syncPosZ - this.posZ) / (double) this.turnProgress; + --this.turnProgress; + this.setPosition(interpX, interpY, interpZ); + } else { + this.setPosition(this.posX, this.posY, this.posZ); + } + } + + if(!worldObj.isRemote) { + + int blockX = (int) Math.floor(posX); + int blockY = (int) Math.floor(posY); + int blockZ = (int) Math.floor(posZ); + + Block b = worldObj.getBlock(blockX, blockY, blockZ); + + if(!(b instanceof IConveyorBelt)) { + + if(onLeaveConveyor()) { + return; + } + } else { + + Vec3 target = ((IConveyorBelt) b).getTravelLocation(worldObj, blockX, blockY, blockZ, Vec3.createVectorHelper(posX, posY, posZ), getMoveSpeed()); + this.motionX = target.xCoord - posX; + this.motionY = target.yCoord - posY; + this.motionZ = target.zCoord - posZ; + } + + BlockPos lastPos = new BlockPos(posX, posY, posZ); + this.moveEntity(motionX, motionY, motionZ); + BlockPos newPos = new BlockPos(posX, posY, posZ); + + if(!lastPos.equals(newPos)) { + + Block newBlock = worldObj.getBlock(newPos.getX(), newPos.getY(), newPos.getZ()); + + if(newBlock instanceof IEnterableBlock) { + + ForgeDirection dir = ForgeDirection.UNKNOWN; + + if(lastPos.getX() > newPos.getX() && lastPos.getY() == newPos.getY() && lastPos.getZ() == newPos.getZ()) dir = Library.POS_X; + else if(lastPos.getX() < newPos.getX() && lastPos.getY() == newPos.getY() && lastPos.getZ() == newPos.getZ()) dir = Library.NEG_X; + else if(lastPos.getX() == newPos.getX() && lastPos.getY() > newPos.getY() && lastPos.getZ() == newPos.getZ()) dir = Library.POS_Y; + else if(lastPos.getX() == newPos.getX() && lastPos.getY() < newPos.getY() && lastPos.getZ() == newPos.getZ()) dir = Library.NEG_Y; + else if(lastPos.getX() == newPos.getX() && lastPos.getY() == newPos.getY() && lastPos.getZ() > newPos.getZ()) dir = Library.POS_Z; + else if(lastPos.getX() == newPos.getX() && lastPos.getY() == newPos.getY() && lastPos.getZ() < newPos.getZ()) dir = Library.NEG_Z; + + IEnterableBlock enterable = (IEnterableBlock) newBlock; + enterBlock(enterable, newPos, dir); + + } else { + + if(!newBlock.getMaterial().isSolid()) { + + newBlock = worldObj.getBlock(newPos.getX(), newPos.getY() - 1, newPos.getZ()); + + if(newBlock instanceof IEnterableBlock) { + + IEnterableBlock enterable = (IEnterableBlock) newBlock; + enterBlockFalling(enterable, newPos); + } + } + } + } + } + } + + public abstract void enterBlock(IEnterableBlock enterable, BlockPos pos, ForgeDirection dir); + + public void enterBlockFalling(IEnterableBlock enterable, BlockPos pos) { + this.enterBlock(enterable, pos.add(0, -1, 0), ForgeDirection.UP); + } + + /** + * @return true if the update loop should end + */ + public abstract boolean onLeaveConveyor(); + + public double getMoveSpeed() { + return 0.0625D; + } + + @SideOnly(Side.CLIENT) + public void setVelocity(double motionX, double motionY, double motionZ) { + this.velocityX = this.motionX = motionX; + this.velocityY = this.motionY = motionY; + this.velocityZ = this.motionZ = motionZ; + } + + @SideOnly(Side.CLIENT) + public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int theNumberThree) { + this.syncPosX = x; + this.syncPosY = y; + this.syncPosZ = z; + this.turnProgress = theNumberThree + 2; //use 4-ply for extra smoothness + this.motionX = this.velocityX; + this.motionY = this.velocityY; + this.motionZ = this.velocityZ; + } +} diff --git a/src/main/java/com/hbm/entity/item/EntityMovingItem.java b/src/main/java/com/hbm/entity/item/EntityMovingItem.java index 23d3e8200..50d39e160 100644 --- a/src/main/java/com/hbm/entity/item/EntityMovingItem.java +++ b/src/main/java/com/hbm/entity/item/EntityMovingItem.java @@ -1,42 +1,23 @@ package com.hbm.entity.item; -import com.hbm.lib.Library; import com.hbm.util.fauxpointtwelve.BlockPos; -import api.hbm.conveyor.IConveyorBelt; import api.hbm.conveyor.IConveyorItem; import api.hbm.conveyor.IEnterableBlock; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; -import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public class EntityMovingItem extends Entity implements IConveyorItem { - - private int turnProgress; - private double syncPosX; - private double syncPosY; - private double syncPosZ; - @SideOnly(Side.CLIENT) - private double velocityX; - @SideOnly(Side.CLIENT) - private double velocityY; - @SideOnly(Side.CLIENT) - private double velocityZ; +public class EntityMovingItem extends EntityMovingConveyorObject implements IConveyorItem { public EntityMovingItem(World p_i1582_1_) { super(p_i1582_1_); this.setSize(0.375F, 0.375F); - this.noClip = true; } public void setItemStack(ItemStack stack) { @@ -44,16 +25,13 @@ public class EntityMovingItem extends Entity implements IConveyorItem { this.getDataWatcher().setObjectWatched(10); } + @Override public ItemStack getItemStack() { - ItemStack stack = this.getDataWatcher().getWatchableObjectItemStack(10); return stack == null ? new ItemStack(Blocks.stone) : stack; } - public boolean canBeCollidedWith() { - return true; - } - + @Override public boolean interactFirst(EntityPlayer player) { if(!worldObj.isRemote && player.inventory.addItemStackToInventory(this.getItemStack().copy())) { @@ -63,6 +41,7 @@ public class EntityMovingItem extends Entity implements IConveyorItem { return false; } + @Override public boolean attackEntityFrom(DamageSource source, float amount) { if(!worldObj.isRemote) { @@ -72,156 +51,6 @@ public class EntityMovingItem extends Entity implements IConveyorItem { return true; } - public boolean canAttackWithItem() { - return true; - } - - public boolean hitByEntity(Entity attacker) { - - if(attacker instanceof EntityPlayer) { - } - - this.setDead(); - - return false; - } - - protected boolean canTriggerWalking() { - return true; - } - - private int schedule = 0; - - public void onUpdate() { - - if(worldObj.isRemote) { - if(this.turnProgress > 0) { - double interpX = this.posX + (this.syncPosX - this.posX) / (double) this.turnProgress; - double interpY = this.posY + (this.syncPosY - this.posY) / (double) this.turnProgress; - double interpZ = this.posZ + (this.syncPosZ - this.posZ) / (double) this.turnProgress; - --this.turnProgress; - this.setPosition(interpX, interpY, interpZ); - } else { - this.setPosition(this.posX, this.posY, this.posZ); - } - } - - if(!worldObj.isRemote) { - - int blockX = (int) Math.floor(posX); - int blockY = (int) Math.floor(posY); - int blockZ = (int) Math.floor(posZ); - - Block b = worldObj.getBlock(blockX, blockY, blockZ); - - if(!(b instanceof IConveyorBelt)) { - this.setDead(); - EntityItem item = new EntityItem(worldObj, posX + motionX * 2, posY + motionY * 2, posZ + motionZ * 2, this.getItemStack()); - item.motionX = this.motionX * 2; - item.motionY = 0.1; - item.motionZ = this.motionZ * 2; - item.velocityChanged = true; - worldObj.spawnEntityInWorld(item); - return; - } else { - - Vec3 target = ((IConveyorBelt) b).getTravelLocation(worldObj, blockX, blockY, blockZ, Vec3.createVectorHelper(posX, posY, posZ), 0.0625); - //this.worldObj.spawnParticle("reddust", target.xCoord, target.yCoord, target.zCoord, 0, 0, 0); - this.motionX = target.xCoord - posX; - this.motionY = target.yCoord - posY; - this.motionZ = target.zCoord - posZ; - } - - /*if(worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)) == ModBlocks.conveyor) { - - if(schedule <= 0) { - ForgeDirection dir = ForgeDirection.getOrientation(worldObj.getBlockMetadata((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ))); - - if(worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY) + 1, (int) Math.floor(posZ)) == ModBlocks.conveyor && motionY >= 0) { - dir = ForgeDirection.DOWN; - } - - if(worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY) - 1, (int) Math.floor(posZ)) == ModBlocks.conveyor && motionY <= 0) { - dir = ForgeDirection.UP; - } - - double speed = 0.0625; - - schedule = (int) (1 / speed); - motionX = -speed * dir.offsetX; - motionY = -speed * dir.offsetY; - motionZ = -speed * dir.offsetZ; - - this.velocityChanged = true; - } - - schedule--; - }*/ - - BlockPos lastPos = new BlockPos(posX, posY, posZ); - this.moveEntity(motionX, motionY, motionZ); - BlockPos newPos = new BlockPos(posX, posY, posZ); - - if(!lastPos.equals(newPos)) { - - Block newBlock = worldObj.getBlock(newPos.getX(), newPos.getY(), newPos.getZ()); - - if(newBlock instanceof IEnterableBlock) { - - ForgeDirection dir = ForgeDirection.UNKNOWN; - - if(lastPos.getX() > newPos.getX() && lastPos.getY() == newPos.getY() && lastPos.getZ() == newPos.getZ()) dir = Library.POS_X; - else if(lastPos.getX() < newPos.getX() && lastPos.getY() == newPos.getY() && lastPos.getZ() == newPos.getZ()) dir = Library.NEG_X; - else if(lastPos.getX() == newPos.getX() && lastPos.getY() > newPos.getY() && lastPos.getZ() == newPos.getZ()) dir = Library.POS_Y; - else if(lastPos.getX() == newPos.getX() && lastPos.getY() < newPos.getY() && lastPos.getZ() == newPos.getZ()) dir = Library.NEG_Y; - else if(lastPos.getX() == newPos.getX() && lastPos.getY() == newPos.getY() && lastPos.getZ() > newPos.getZ()) dir = Library.POS_Z; - else if(lastPos.getX() == newPos.getX() && lastPos.getY() == newPos.getY() && lastPos.getZ() < newPos.getZ()) dir = Library.NEG_Z; - - IEnterableBlock enterable = (IEnterableBlock) newBlock; - - if(enterable.canItemEnter(worldObj, newPos.getX(), newPos.getY(), newPos.getZ(), dir, this)) { - - enterable.onItemEnter(worldObj, newPos.getX(), newPos.getY(), newPos.getZ(), dir, this); - this.setDead(); - } - } else { - - if(!newBlock.getMaterial().isSolid()) { - - newBlock = worldObj.getBlock(newPos.getX(), newPos.getY() - 1, newPos.getZ()); - - if(newBlock instanceof IEnterableBlock) { - - IEnterableBlock enterable = (IEnterableBlock) newBlock; - if(enterable.canItemEnter(worldObj, newPos.getX(), newPos.getY() - 1, newPos.getZ(), ForgeDirection.UP, this)) { - enterable.onItemEnter(worldObj, newPos.getX(), newPos.getY() - 1, newPos.getZ(), ForgeDirection.UP, this); - this.setDead(); - } - } - } - } - } - } - } - - @SideOnly(Side.CLIENT) - public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_) { - this.velocityX = this.motionX = p_70016_1_; - this.velocityY = this.motionY = p_70016_3_; - this.velocityZ = this.motionZ = p_70016_5_; - } - - @SideOnly(Side.CLIENT) - public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int theNumberThree) { - this.syncPosX = x; - this.syncPosY = y; - this.syncPosZ = z; - this.turnProgress = theNumberThree + 2; //use 4-ply for extra smoothness - this.motionX = this.velocityX; - this.motionY = this.velocityY; - this.motionZ = this.velocityZ; - } - @Override protected void entityInit() { this.getDataWatcher().addObjectByDataType(10, 5); @@ -235,8 +64,6 @@ public class EntityMovingItem extends Entity implements IConveyorItem { ItemStack stack = getDataWatcher().getWatchableObjectItemStack(10); - schedule = nbt.getInteger("schedule"); - if(stack == null || stack.stackSize <= 0) this.setDead(); } @@ -246,7 +73,28 @@ public class EntityMovingItem extends Entity implements IConveyorItem { if(this.getItemStack() != null) nbt.setTag("Item", this.getItemStack().writeToNBT(new NBTTagCompound())); + } - nbt.setInteger("schedule", schedule); + @Override + public void enterBlock(IEnterableBlock enterable, BlockPos pos, ForgeDirection dir) { + + if(enterable.canItemEnter(worldObj, pos.getX(), pos.getY(), pos.getZ(), dir, this)) { + enterable.onItemEnter(worldObj, pos.getX(), pos.getY(), pos.getZ(), dir, this); + this.setDead(); + } + } + + @Override + public boolean onLeaveConveyor() { + + this.setDead(); + EntityItem item = new EntityItem(worldObj, posX + motionX * 2, posY + motionY * 2, posZ + motionZ * 2, this.getItemStack()); + item.motionX = this.motionX * 2; + item.motionY = 0.1; + item.motionZ = this.motionZ * 2; + item.velocityChanged = true; + worldObj.spawnEntityInWorld(item); + + return true; } } diff --git a/src/main/java/com/hbm/entity/item/EntityMovingPackage.java b/src/main/java/com/hbm/entity/item/EntityMovingPackage.java new file mode 100644 index 000000000..210b3ad5f --- /dev/null +++ b/src/main/java/com/hbm/entity/item/EntityMovingPackage.java @@ -0,0 +1,93 @@ +package com.hbm.entity.item; + +import com.hbm.util.ItemStackUtil; +import com.hbm.util.fauxpointtwelve.BlockPos; + +import api.hbm.conveyor.IConveyorPackage; +import api.hbm.conveyor.IEnterableBlock; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class EntityMovingPackage extends EntityMovingConveyorObject implements IConveyorPackage { + + protected ItemStack[] contents = new ItemStack[0]; + + public EntityMovingPackage(World world) { + super(world); + this.setSize(0.5F, 0.5F); + } + + @Override + protected void entityInit() { } + + public void setItemStacks(ItemStack[] stacks) { + this.contents = ItemStackUtil.carefulCopyArray(stacks); + } + + @Override + public ItemStack[] getItemStacks() { + return contents; + } + + @Override + public void enterBlock(IEnterableBlock enterable, BlockPos pos, ForgeDirection dir) { + + if(enterable.canPackageEnter(worldObj, pos.getX(), pos.getY(), pos.getZ(), dir, this)) { + enterable.onPackageEnter(worldObj, pos.getX(), pos.getY(), pos.getZ(), dir, this); + this.setDead(); + } + } + + @Override + public boolean onLeaveConveyor() { + + this.setDead(); + + for(ItemStack stack : contents) { + EntityItem item = new EntityItem(worldObj, posX + motionX * 2, posY + motionY * 2, posZ + motionZ * 2, stack); + item.motionX = this.motionX * 2; + item.motionY = 0.1; + item.motionZ = this.motionZ * 2; + item.velocityChanged = true; + worldObj.spawnEntityInWorld(item); + } + + return true; + } + + @Override + protected void writeEntityToNBT(NBTTagCompound nbt) { + NBTTagList nbttaglist = new NBTTagList(); + + for(int i = 0; i < this.contents.length; ++i) { + if(this.contents[i] != null) { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("slot", (byte) i); + this.contents[i].writeToNBT(nbttagcompound1); + nbttaglist.appendTag(nbttagcompound1); + } + } + + nbt.setTag("contents", nbttaglist); + nbt.setInteger("count", this.contents.length); + } + + @Override + protected void readEntityFromNBT(NBTTagCompound nbt) { + this.contents = new ItemStack[nbt.getInteger("count")]; + NBTTagList nbttaglist = nbt.getTagList("contents", 10); + + for(int i = 0; i < nbttaglist.tagCount(); ++i) { + NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); + int j = nbttagcompound1.getByte("slot") & 255; + + if(j >= 0 && j < this.contents.length) { + this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + } + } + } +} diff --git a/src/main/java/com/hbm/main/ClientProxy.java b/src/main/java/com/hbm/main/ClientProxy.java index f1aa6009b..87d1d7dde 100644 --- a/src/main/java/com/hbm/main/ClientProxy.java +++ b/src/main/java/com/hbm/main/ClientProxy.java @@ -657,6 +657,7 @@ public class ClientProxy extends ServerProxy { RenderingRegistry.registerEntityRenderingHandler(EntityMagnusCartus.class, new RenderMagnusCartus()); //items RenderingRegistry.registerEntityRenderingHandler(EntityMovingItem.class, new RenderMovingItem()); + RenderingRegistry.registerEntityRenderingHandler(EntityMovingPackage.class, new RenderMovingPackage()); RenderingRegistry.registerEntityRenderingHandler(EntityTNTPrimedBase.class, new RenderTNTPrimedBase()); //mobs RenderingRegistry.registerEntityRenderingHandler(EntityNuclearCreeper.class, new RenderNuclearCreeper()); diff --git a/src/main/java/com/hbm/render/entity/item/RenderMovingItem.java b/src/main/java/com/hbm/render/entity/item/RenderMovingItem.java index 92747da0f..49702b541 100644 --- a/src/main/java/com/hbm/render/entity/item/RenderMovingItem.java +++ b/src/main/java/com/hbm/render/entity/item/RenderMovingItem.java @@ -49,5 +49,4 @@ public class RenderMovingItem extends Render { protected ResourceLocation getEntityTexture(Entity p_110775_1_) { return null; } - } diff --git a/src/main/java/com/hbm/render/entity/item/RenderMovingPackage.java b/src/main/java/com/hbm/render/entity/item/RenderMovingPackage.java new file mode 100644 index 000000000..5bab44b60 --- /dev/null +++ b/src/main/java/com/hbm/render/entity/item/RenderMovingPackage.java @@ -0,0 +1,50 @@ +package com.hbm.render.entity.item; + +import java.util.Random; + +import org.lwjgl.opengl.GL11; + +import com.hbm.blocks.ModBlocks; + +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +public class RenderMovingPackage extends Render { + + private ItemStack dummy; + + @Override + public void doRender(Entity entity, double x, double y, double z, float f1, float f2) { + + GL11.glPushMatrix(); + GL11.glTranslated(x, y, z); + + Random rand = new Random(entity.getEntityId()); + GL11.glTranslated(0, rand.nextDouble() * 0.0625, 0); + + if(this.dummy == null) { + this.dummy = new ItemStack(ModBlocks.crate); + } + + EntityItem dummy = new EntityItem(entity.worldObj, 0, 0, 0, this.dummy); + dummy.hoverStart = 0.0F; + + RenderItem.renderInFrame = true; + double scale = 8D / 6D; + GL11.glScaled(scale, scale, scale); + RenderManager.instance.renderEntityWithPosYaw(dummy, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F); + RenderItem.renderInFrame = false; + + GL11.glPopMatrix(); + } + + @Override + protected ResourceLocation getEntityTexture(Entity p_110775_1_) { + return null; + } +} diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityCraneBoxer.java b/src/main/java/com/hbm/tileentity/network/TileEntityCraneBoxer.java index 848b1bb51..861e7a42c 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityCraneBoxer.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityCraneBoxer.java @@ -1,18 +1,33 @@ package com.hbm.tileentity.network; +import com.hbm.entity.item.EntityMovingItem; +import com.hbm.entity.item.EntityMovingPackage; import com.hbm.inventory.container.ContainerCraneBoxer; import com.hbm.inventory.gui.GUICraneBoxer; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityMachineBase; +import api.hbm.conveyor.IConveyorBelt; +import api.hbm.ntl.StorageManifest; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Vec3; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIProvider { + + public byte mode = 0; + public static final byte MODE_4 = 0; + public static final byte MODE_8 = 1; + public static final byte MODE_16 = 2; + public static final byte MODE_REDSTONE = 3; + public TileEntityCraneBoxer() { super(7 * 3); @@ -26,6 +41,72 @@ public class TileEntityCraneBoxer extends TileEntityMachineBase implements IGUIP @Override public void updateEntity() { + if(!worldObj.isRemote && mode != MODE_REDSTONE && worldObj.getTotalWorldTime() % 20 == 0) { + int pack = 1; + + switch(mode) { + case MODE_4: pack = 4; break; + case MODE_8: pack = 8; break; + case MODE_16: pack = 16; break; + } + + int fullStacks = 0; + + // NO! + /*StorageManifest manifest = new StorageManifest(); //i wrote some of this for a feature that i scrapped so why not make proper use of it? + + for(int i = 0; i < slots.length; i++) { + if(slots[i] != null) { + manifest.writeStack(slots[i]); + } + }*/ + + for(int i = 0; i < slots.length; i++) { + + if(slots[i] != null && slots[i].stackSize == slots[i].getMaxStackSize()) { + fullStacks++; + } + } + + ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()); + Block b = worldObj.getBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ); + IConveyorBelt belt = null; + + if(b instanceof IConveyorBelt) { + belt = (IConveyorBelt) b; + } + + if(belt != null && fullStacks >= pack) { + + ItemStack[] box = new ItemStack[pack]; + + for(int i = 0; i < slots.length && pack > 0; i++) { + + if(slots[i] != null && slots[i].stackSize == slots[i].getMaxStackSize()) { + pack--; + box[pack] = slots[i].copy(); + slots[i] = null; + } + } + + EntityMovingPackage moving = new EntityMovingPackage(worldObj); + Vec3 pos = Vec3.createVectorHelper(xCoord + 0.5 + dir.offsetX * 0.55, yCoord + 0.5 + dir.offsetY * 0.55, zCoord + 0.5 + dir.offsetZ * 0.55); + Vec3 snap = belt.getClosestSnappingPosition(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, pos); + moving.setPosition(snap.xCoord, snap.yCoord, snap.zCoord); + moving.setItemStacks(box); + worldObj.spawnEntityInWorld(moving); + } + } + } + + @Override + public int[] getAccessibleSlotsFromSide(int p_94128_1_) { + return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemStack) { + return true; } @Override diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityCraneUnboxer.java b/src/main/java/com/hbm/tileentity/network/TileEntityCraneUnboxer.java index 2c1664889..ec08ba704 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityCraneUnboxer.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityCraneUnboxer.java @@ -1,7 +1,32 @@ package com.hbm.tileentity.network; -import net.minecraft.tileentity.TileEntity; +import com.hbm.tileentity.TileEntityMachineBase; -public class TileEntityCraneUnboxer extends TileEntity { +import net.minecraft.item.ItemStack; +public class TileEntityCraneUnboxer extends TileEntityMachineBase { + + public TileEntityCraneUnboxer() { + super(7 * 3); + } + + @Override + public String getName() { + return "container.craneUnboxer"; + } + + @Override + public void updateEntity() { + + } + + @Override + public int[] getAccessibleSlotsFromSide(int p_94128_1_) { + return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemStack) { + return true; + } } diff --git a/src/main/java/com/hbm/util/ItemStackUtil.java b/src/main/java/com/hbm/util/ItemStackUtil.java index eb8741f82..ea4c1b843 100644 --- a/src/main/java/com/hbm/util/ItemStackUtil.java +++ b/src/main/java/com/hbm/util/ItemStackUtil.java @@ -1,11 +1,8 @@ package com.hbm.util; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import com.hbm.inventory.RecipesCommon.ComparableStack; - import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; diff --git a/src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java b/src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java index 5cfe629a7..e15027227 100644 --- a/src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java +++ b/src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java @@ -26,6 +26,10 @@ public class BlockPos { this((int)MathHelper.floor_double(x), (int)MathHelper.floor_double(y), (int)MathHelper.floor_double(z)); } + public BlockPos add(int x, int y, int z) { + return x == 0 && y == 0 && z == 0 ? this : new BlockPos(this.getX() + x, this.getY() + y, this.getZ() + z); + } + public BlockPos add(double x, double y, double z) { return x == 0.0D && y == 0.0D && z == 0.0D ? this : new BlockPos((double) this.getX() + x, (double) this.getY() + y, (double) this.getZ() + z); } diff --git a/src/main/resources/assets/hbm/textures/models/machines/stirling_steel.png b/src/main/resources/assets/hbm/textures/models/machines/stirling_steel.png new file mode 100644 index 000000000..9f5706176 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/models/machines/stirling_steel.png differ