Guest User

ModItem Class

a guest
Oct 22nd, 2020
19
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ModItem extends Item {
  2. public ModItem() {
  3. super(new Item.Properties().group(ItemGroup.TOOLS));
  4. }
  5.  
  6. public ActionResultType itemInteractionForEntity(ItemStack stack, PlayerEntity playerIn, LivingEntity target, Hand hand) {
  7. if (!(target instanceof PlayerEntity)) {
  8. if (!playerIn.world.isRemote && target.isAlive()) {
  9.  
  10. System.out.println("Mod cap before: " + target.getCapability(ModCap.MOD_CAP).orElse(new ModCapMethods()).get());
  11. target.getCapability(ModCap.MOD_CAP).ifPresent(IModCap::set);
  12. System.out.println("Mod cap after: " + target.getCapability(ModCap.MOD_CAP).orElse(new ModCapMethods()).get());
  13.  
  14. stack.shrink(1);
  15. }
  16.  
  17. return ActionResultType.func_233537_a_(playerIn.world.isRemote);
  18. } else {
  19. return ActionResultType.PASS;
  20. }
  21. }
  22.  
  23. }
RAW Paste Data