Advertisement
Unstew

onEntityCollision

Feb 18th, 2022
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. @Override //method inside my custom fireblock class
  2.     public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
  3.         if (entity instanceof ItemEntity && ((ItemEntity) entity).getStack().getItem().isFood()) {
  4.             ItemStack foodItem = ((ItemEntity) entity).getStack();
  5.             if (canCook(foodItem)) { //I apologize for all this casting mess
  6.  
  7.                 IFriendlyFireCookable cookableItem = (IFriendlyFireCookable)entity;//applied interface
  8.                 if (cookableItem.incrementCookPercentAndCheckIfCooked()) {//check for cook% and spawn new item
  9.  
  10.                     cookableItem.spawnCookedItemEntity(foodItem, (ItemEntity) entity);
  11.  
  12.                     entity.remove(Entity.RemovalReason.DISCARDED); //remove old item (since it was "cooked"
  13.                 }
  14.  
  15.             }
  16.         }
  17.         super.onEntityCollision(state, world, pos, entity);
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement