Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.martigpg3.tutorialmod.item.custom;
- import net.minecraft.block.BlockState;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EquipmentSlot;
- import net.minecraft.entity.ItemEntity;
- import net.minecraft.entity.LivingEntity;
- import net.minecraft.entity.effect.StatusEffectInstance;
- import net.minecraft.entity.effect.StatusEffects;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.server.network.ServerPlayerEntity;
- import net.minecraft.server.world.ServerWorld;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import java.util.Random;
- public class LuckyStickItem extends Item {
- public LuckyStickItem(Settings settings) {
- super(settings);
- }
- @Override
- public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) {
- if(!world.isClient())
- {
- stack.damage(1, ((ServerWorld) world), ((ServerPlayerEntity) miner),
- item -> miner.sendEquipmentBreakStatus(item, EquipmentSlot.MAINHAND));
- }
- return super.postMine(stack, world, state, pos, miner);
- }
- @Override
- public void onItemEntityDestroyed(ItemEntity entity) {
- World world = entity.getWorld();
- Entity owner = entity.getOwner();
- if(!world.isClient() && owner instanceof PlayerEntity player)
- {
- int random = new Random().nextInt(3) + 1;
- if(random == 1)
- {
- player.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS,400, 2, false, true));
- }
- if(random == 2)
- {
- player.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED,400, 2, false, true));
- }
- if(random == 3)
- {
- player.addStatusEffect(new StatusEffectInstance(StatusEffects.LEVITATION,400, 2, false, true));
- }
- }
- super.onItemEntityDestroyed(entity);
- }
- }
Advertisement