Jump to content

Egietje

Forge Modder
  • Posts

    388
  • Joined

  • Last visited

Everything posted by Egietje

  1. Oh wait, would it work like this: public void addItemToChest(BlockPos pos, World worldIn, Entity entityIn) { if (!worldIn.isRemote) { IBlockState state = worldIn.getBlockState(pos); Block block = state.getBlock(); EntityItem entityItem = (EntityItem) entityIn; ItemStack stack = entityItem.getEntityItem(); Item item = stack.getItem(); if(block.equals(Blocks.CHEST)) { BlockChest chest = (BlockChest) block; TileEntityChest tile = (TileEntityChest) worldIn.getTileEntity(pos); IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, (EnumFacing) state.getValue(FACING)); for (int i = 0;i < handler.getSlots();i++) { if (handler.getStackInSlot(i) != null) { if (handler.getStackInSlot(i).getItem().equals(item)) { if (handler.getStackInSlot(i).stackSize < stack.getMaxStackSize()) { handler.getStackInSlot(i).stackSize++; entityItem.setDead(); } } } else { handler.insertItem(i, stack, false); entityItem.setDead(); break; } } } } }
  2. I don't know how to use them and never used them
  3. You can't change vanilla code, you need mcp for that
  4. So I've made an inserter but it acts weird, it adds 1 new stack and adds 1 item to an already existing one, the code responsible for this: public void addItemToChest(BlockPos pos, World worldIn, Entity entityIn) { if (!worldIn.isRemote) { IBlockState state = worldIn.getBlockState(pos); Block block = state.getBlock(); EntityItem entityItem = (EntityItem) entityIn; if(block.equals(Blocks.CHEST)) { BlockChest chest = (BlockChest) block; ILockableContainer container = chest.getContainer(worldIn, pos, false); for (int i = 0;i < container.getSizeInventory();i++) { if (container.getStackInSlot(i) != null) { if (container.getStackInSlot(i).getItem().equals(entityItem.getEntityItem().getItem())) { if (container.getStackInSlot(i).stackSize < 64) { container.getStackInSlot(i).stackSize++; entityItem.setDead(); } } } else { container.setInventorySlotContents(i, entityItem.getEntityItem()); entityItem.setDead(); break; } } } } } So when I drop 1 item on top of the inserter it adds it to all the stacks of that item and makes a new stack of the item it worked before so...
  5. Thanks, it works
  6. Still does the same
  7. ah, I needed to add a break; to the else Still doesn't work, I now have this: public void addItemToChest(BlockPos pos, World worldIn, Entity entityIn) { IBlockState state = worldIn.getBlockState(pos); Block block = state.getBlock(); EntityItem entityItem = (EntityItem) entityIn; if(block.equals(Blocks.CHEST)) { BlockChest chest = (BlockChest) block; ILockableContainer container = chest.getContainer(worldIn, pos, false); for (int i = 0;i < container.getSizeInventory();i++) { if (container.getStackInSlot(i) != null) { if (container.getStackInSlot(i).getItem().equals(entityItem.getEntityItem().getItem())) { if (container.getStackInSlot(i).stackSize < 64) { container.getStackInSlot(i).stackSize++; entityItem.attackEntityFrom(DamageSource.fall, 500); } } } else { container.setInventorySlotContents(i, entityItem.getEntityItem()); break; } } } } But when I put an item on it it put 2 stacks in there with 3 items..?
  8. But how would I check if there isn't an item?
  9. I know, but how can I make it so if there is nothing in a slot it will put the item from the belt there?
  10. Hello, I have a belt block (well 2 but) and I want to make it so if the belt runs directly into a chest it will put the item in the chest, it works but only if there allready is at least one of that item as a seperate stack (and not a full stack) but how can I make it so if there is not an available place in the chest it will just put it an empty slot? My code so far (just the onEntityCollidedWithBlock method): @Override public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { EnumFacing enumfacing = (EnumFacing)state.getValue(FACING); switch (enumfacing) { case WEST: if(entityIn instanceof EntityLivingBase || entityIn instanceof EntityItem) { entityIn.motionX = -1.25; entityIn.motionZ *= 0.2; } if(entityIn instanceof EntityItem) { IBlockState westState = worldIn.getBlockState(pos.west()); Block westBlock = westState.getBlock(); EntityItem entityItem = (EntityItem) entityIn; if(westBlock.equals(Blocks.CHEST)) { BlockChest chestWest = (BlockChest) westBlock; ILockableContainer container = chestWest.getContainer(worldIn, pos.west(), false); for (int i = 0;i < container.getSizeInventory();i++) { if (container.getStackInSlot(i) != null) { if (container.getStackInSlot(i).getItem().equals(entityItem.getEntityItem().getItem())) { if (container.getStackInSlot(i).stackSize < 64) { container.getStackInSlot(i).stackSize++; entityItem.attackEntityFrom(DamageSource.fall, 500); } } } else { } } } } break; case EAST: if(entityIn instanceof EntityLivingBase || entityIn instanceof EntityItem) { entityIn.motionX = 1.25; entityIn.motionZ *= 0.2; } break; case NORTH: if(entityIn instanceof EntityLivingBase || entityIn instanceof EntityItem) { entityIn.motionZ = -1.25; entityIn.motionX *= 0.2; } break; case SOUTH: if(entityIn instanceof EntityLivingBase || entityIn instanceof EntityItem) { entityIn.motionZ = 1.25; entityIn.motionX *= 0.2; } break; case DOWN: break; case UP: break; default: break; } }
  11. And I think you know this but to add more do another ATTACK_ENTITIES.add(Entity.class);
  12. Put this in there, and remove the private static final Set<Class> ATTACK_ENTITIES = Sets.newHashSet(new Class[] {}); List<Class> ATTACK_ENTITIES = null; ATTACK_ENTITIES.add(EntityZombie.class); for (int i = 0; i < ATTACK_ENTITIES.size(); i++) { Class ATTACK_ENTITY = ATTACK_ENTITIES.get(i); this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, ATTACK_ENTITY, true)); }
  13. Should work
  14. Hmm, the parameters are really different, use this instead of EntityAITarget: this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, ATTACK_ENTITIES, true)); and put this at the top private static final Set<Class> ATTACK_ENTITIES = Sets.newHashSet(new Class[] {}); and in the curly brackets after Class[] you put the entities it should attack, like EntityZombie.class, EntityCreeper.class, EntitySkeleton.class, EntitySpider.class
  15. Put the target AI above the HurtByTarget AI
  16. Can you post the code of your entity's class?
  17. Thanks, it works!
  18. Oh wait, you should have EntityAITarget, not EntityAITargetNonTamed
  19. You should have this one: import com.google.common.base.Predicate;
  20. Probably, yes
  21. Add this to the AI things: this.targetTasks.addTask(1, new EntityAITargetNonTamed(this, EntityMob.class, false, new Predicate<Entity>() { public boolean apply(@Nullable Entity p_apply_1_) { return p_apply_1_ instanceof EntityMob; } })); That will make it attack all of the hostile entities
  22. I've made a half-slab with multiple textures but it only renders 1 flat side, but how can I make it so it renders it the same way as normal slabs? Block model: { "textures": { "0": "km:blocks/fast_belt_front", "1": "km:blocks/fast_belt_side", "2": "km:blocks/fast_belt_top" }, "elements": [ { "name": "Cube", "from": [ 0.0, 0.0, 0.0 ], "to": [ 16.0, 8.0, 16.0 ], "faces": { "north": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 8.0 ] }, "east": { "texture": "#1", "uv": [ 0.0, 8.0, 16.0, 16.0 ] }, "south": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 8.0 ] }, "west": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 8.0 ] }, "up": { "texture": "#2", "uv": [ 0.0, 0.0, 16.0, 16.0 ], "rotation": 270 }, "down": { "texture": "#2", "uv": [ 0.0, 0.0, 16.0, 16.0 ], "rotation": 270 } } } ] } The item model is the same
  23. What entity's should it attack?
  24. Oh wait, just figured it out...
  25. Hello, as the title says, the blockstate of my block doesn't work and I don't know why The item texture and if you hold it the model does work so I don't know why it doesn't work EDIT : Ask for anything I need to put here
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.