martigpg3

Untitled

Jan 19th, 2026
83
0
Never
8
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. package net.martigpg3.tutorialmod.item.custom;
  2.  
  3. import net.minecraft.block.BlockState;
  4. import net.minecraft.entity.Entity;
  5. import net.minecraft.entity.EquipmentSlot;
  6. import net.minecraft.entity.ItemEntity;
  7. import net.minecraft.entity.LivingEntity;
  8. import net.minecraft.entity.effect.StatusEffectInstance;
  9. import net.minecraft.entity.effect.StatusEffects;
  10. import net.minecraft.entity.player.PlayerEntity;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.server.network.ServerPlayerEntity;
  14. import net.minecraft.server.world.ServerWorld;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.world.World;
  17.  
  18. import java.util.Random;
  19.  
  20. public class LuckyStickItem extends Item {
  21.     public LuckyStickItem(Settings settings) {
  22.         super(settings);
  23.     }
  24.  
  25.     @Override
  26.     public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) {
  27.  
  28.         if(!world.isClient())
  29.         {
  30.             stack.damage(1, ((ServerWorld) world), ((ServerPlayerEntity) miner),
  31.                     item -> miner.sendEquipmentBreakStatus(item, EquipmentSlot.MAINHAND));
  32.         }
  33.  
  34.         return super.postMine(stack, world, state, pos, miner);
  35.     }
  36.  
  37.     @Override
  38.     public void onItemEntityDestroyed(ItemEntity entity) {
  39.         World world = entity.getWorld();
  40.         Entity owner = entity.getOwner();
  41.  
  42.         if(!world.isClient() && owner instanceof PlayerEntity player)
  43.         {
  44.  
  45.             int random = new Random().nextInt(3) + 1;
  46.  
  47.             if(random == 1)
  48.             {
  49.                 player.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS,400, 2, false, true));
  50.             }
  51.             if(random == 2)
  52.             {
  53.                 player.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED,400, 2, false, true));
  54.             }
  55.             if(random == 3)
  56.             {
  57.                 player.addStatusEffect(new StatusEffectInstance(StatusEffects.LEVITATION,400, 2, false, true));
  58.             }
  59.         }
  60.  
  61.         super.onItemEntityDestroyed(entity);
  62.     }
  63. }
  64.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment