effect amulets

This commit is contained in:
Jenny 2025-04-02 20:12:25 +02:00
parent b549ef8df2
commit 5352ce4840
Signed by: Jenny
GPG Key ID: 2072A14E40940632
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package com.jenny.magic.items;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
public class AmuletEffect extends BaseItem {
private MobEffect effect;
private int delay, duration, amplifier;
public AmuletEffect(Properties pProperties, MobEffect effect, int delay, int duration, int amplifier) {
super(pProperties.stacksTo(1));
this.effect = effect;
this.delay = delay;
this.duration = duration;
this.amplifier = amplifier;
}
@Override
public void inventoryTick(@NotNull ItemStack pStack, @NotNull Level pLevel, @NotNull Entity pEntity, int pSlotId, boolean pIsSelected) {
if (!pLevel.isClientSide && ((ServerLevel) pLevel).getServer().getTickCount() % this.delay == 0) {
if (pEntity instanceof LivingEntity p) {
p.addEffect(new MobEffectInstance(effect, this.duration, this.amplifier, true, true, true, null, Optional.empty()));
System.out.println("test1878567");
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.jenny.magic.items; package com.jenny.magic.items;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Biomes;
import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.IEventBus;
@ -22,6 +23,9 @@ public class items {
public static final RegistryObject<Item> SCROLL_REPEL = ITEMS.register("scroll_repel", () -> new RepelScroll(new Item.Properties().stacksTo(16))); public static final RegistryObject<Item> SCROLL_REPEL = ITEMS.register("scroll_repel", () -> new RepelScroll(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> SCROLL_BONEMEAL = ITEMS.register("scroll_bonemeal", () -> new BonemealScroll(new Item.Properties().stacksTo(16))); public static final RegistryObject<Item> SCROLL_BONEMEAL = ITEMS.register("scroll_bonemeal", () -> new BonemealScroll(new Item.Properties().stacksTo(16)));
public static final RegistryObject<Item> AMULET_REPAIR = ITEMS.register("amulet_repair", () -> new AmuletRepair(new Item.Properties())); public static final RegistryObject<Item> AMULET_REPAIR = ITEMS.register("amulet_repair", () -> new AmuletRepair(new Item.Properties()));
public static final RegistryObject<Item> AMULET_BREATHING = ITEMS.register("amulet_breathing", () -> new AmuletEffect(new Item.Properties(), MobEffects.WATER_BREATHING, 100, 200, 1));
public static final RegistryObject<Item> AMULET_NIGHTVISION = ITEMS.register("amulet_nightvision", () -> new AmuletEffect(new Item.Properties(), MobEffects.NIGHT_VISION, 200, 500, 1));
public static final RegistryObject<Item> DRAGON_HEART = ITEMS.register("dragon_heart", () -> new QualityItem(new Item.Properties())); public static final RegistryObject<Item> DRAGON_HEART = ITEMS.register("dragon_heart", () -> new QualityItem(new Item.Properties()));
public static void register(IEventBus bus) { public static void register(IEventBus bus) {