Guest User

ModTagItem

a guest
Oct 23rd, 2020
11
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ModTagItem extends Item {
  2. public ModTagItem() {
  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 tag before: " + target.getCapability(ModTagProvider.MOD_TAG).orElseThrow(
  11. () -> new IllegalArgumentException("LazyOptional must not be empty!")).get());
  12.  
  13. target.getCapability(ModTagProvider.MOD_TAG).ifPresent(iModTag -> iModTag.set(1));
  14.  
  15. System.out.println("Mod tag after: " + target.getCapability(ModTagProvider.MOD_TAG).orElseThrow(
  16. () -> new IllegalArgumentException("LazyOptional cannot be empty!")).get());
  17.  
  18. stack.shrink(1);
  19. }
  20.  
  21. return ActionResultType.func_233537_a_(playerIn.world.isRemote);
  22. } else {
  23. return ActionResultType.PASS;
  24. }
  25. }
  26.  
  27. }
RAW Paste Data