From 521b040f63325d8f1cc29912a8bb8595fe8d813c Mon Sep 17 00:00:00 2001 From: Boblet Date: Tue, 9 Aug 2022 16:46:21 +0200 Subject: [PATCH] amazon warehouse employee machine --- .../java/api/hbm/ntl/StorageManifest.java | 26 ++- .../com/hbm/blocks/network/CraneBoxer.java | 9 + .../com/hbm/blocks/network/CraneUnboxer.java | 13 +- .../java/com/hbm/entity/EntityMappings.java | 1 + .../item/EntityMovingConveyorObject.java | 164 ++++++++++++++ .../com/hbm/entity/item/EntityMovingItem.java | 204 +++--------------- .../hbm/entity/item/EntityMovingPackage.java | 93 ++++++++ src/main/java/com/hbm/main/ClientProxy.java | 1 + .../render/entity/item/RenderMovingItem.java | 1 - .../entity/item/RenderMovingPackage.java | 50 +++++ .../network/TileEntityCraneBoxer.java | 81 +++++++ .../network/TileEntityCraneUnboxer.java | 29 ++- src/main/java/com/hbm/util/ItemStackUtil.java | 3 - .../hbm/util/fauxpointtwelve/BlockPos.java | 4 + .../models/machines/stirling_steel.png | Bin 0 -> 3851 bytes 15 files changed, 492 insertions(+), 187 deletions(-) create mode 100644 src/main/java/com/hbm/entity/item/EntityMovingConveyorObject.java create mode 100644 src/main/java/com/hbm/entity/item/EntityMovingPackage.java create mode 100644 src/main/java/com/hbm/render/entity/item/RenderMovingPackage.java create mode 100644 src/main/resources/assets/hbm/textures/models/machines/stirling_steel.png 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 0000000000000000000000000000000000000000..9f570617606a86944862bbf98d1d0c9918a9387c GIT binary patch literal 3851 zcmV+m5A^VfP)U5gvn8OQ%;M(edDjV6+{-B)L~>t*dWrVcC{+l0b~Kxi=} zxcDLlUn~^z0opIni$K3appXk+gwmS?5|YqRC#5va*03ps?h<2cEJwSQD(z_Ww!2xK zUTDvFG}1`(D$R_}4;Jfaj%LoT|MTdX=RD^*CEoDmZP!Yc$-RYyGp z&WMQ_-{>a_Ns@dWjFT}Oi)YYmHgR}(h-R~i>FH_S9;3GSv!DLtcZY|EnsAQAGpHXO zLv1uss#I}KlC}2Y{47{sKgFvaw|ZW`RH@=@Ou*#iBmm&(=m_VhXAq0UAc`UcLBQPH z9B+?NTNALVs>l_~NG6j=rBYoVs8*|Z^6YzDT)g0$h}jMF!w)|onM`&KxK^v-oFrrV zdV!b491b2wpv3z!pXxPUpKh6|VzYCa*CJKduHgyO9OEXiU&E4R554n5$7Ohk& z+DzP)D_1Z%ISEx&QLR?7y1Lpvmdjy(e;?PbUhz#pY$lEg_UfgTu0Hx}tE!5>{QVo^ z%V37Y&6_s^oelW$#~%m!?;BVPeD%`G*jUvy^Bsz}QYBg+aZ4rGxPY2Bz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