From 12e297657264f5794b39380c1c8fd720d4cd5f29 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 2 Apr 2024 01:23:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=85=E5=92=92=E9=87=91=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=89=A9=E5=93=81=E7=BB=99=E7=8E=A9=E5=AE=B6=E5=B8=A6=E6=9D=A5?= =?UTF-8?q?=E7=9A=84debuff=E8=BF=9B=E8=A1=8C=E5=88=9B=E9=80=A0=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/dubhe/anvilcraft/item/Cured.java | 27 +++++++++++++++++++ .../dubhe/anvilcraft/item/CuredBlockItem.java | 16 ++--------- .../dev/dubhe/anvilcraft/item/CuredItem.java | 16 ++--------- 3 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 src/main/java/dev/dubhe/anvilcraft/item/Cured.java diff --git a/src/main/java/dev/dubhe/anvilcraft/item/Cured.java b/src/main/java/dev/dubhe/anvilcraft/item/Cured.java new file mode 100644 index 000000000..5ac9f6ba1 --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/item/Cured.java @@ -0,0 +1,27 @@ +package dev.dubhe.anvilcraft.item; + +import dev.dubhe.anvilcraft.init.ModItems; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; + +public interface Cured { + default void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { + if (!(entity instanceof Player player)) return; + if (player.getAbilities().instabuild) return; + MobEffectInstance weakness = new MobEffectInstance(MobEffects.WEAKNESS, 200, 1, false, true); + MobEffectInstance slowness = new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 200, 1, false, true); + MobEffectInstance hungry = new MobEffectInstance(MobEffects.HUNGER, 200, 1, false, true); + player.addEffect((weakness)); + int curedNumber = player.getInventory().countItem(ModItems.CURSED_GOLD_INGOT) + player.getInventory().countItem(ModItems.CURSED_GOLD_NUGGET) + player.getInventory().countItem(ModItems.CURSED_GOLD_BLOCK); + if (curedNumber > 8) { + player.addEffect((slowness)); + } + if (curedNumber > 64) { + player.addEffect((hungry)); + } + } +} diff --git a/src/main/java/dev/dubhe/anvilcraft/item/CuredBlockItem.java b/src/main/java/dev/dubhe/anvilcraft/item/CuredBlockItem.java index 16e737b3a..9a2702f39 100644 --- a/src/main/java/dev/dubhe/anvilcraft/item/CuredBlockItem.java +++ b/src/main/java/dev/dubhe/anvilcraft/item/CuredBlockItem.java @@ -10,7 +10,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -public class CuredBlockItem extends BlockItem { +public class CuredBlockItem extends BlockItem implements Cured { public CuredBlockItem(Block block, Properties properties) { super(block, properties); @@ -19,18 +19,6 @@ public CuredBlockItem(Block block, Properties properties) { @Override public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { super.inventoryTick(stack, level, entity, slotId, isSelected); - if (entity instanceof Player player) { - MobEffectInstance weakness = new MobEffectInstance(MobEffects.WEAKNESS, 200, 1, false, true); - MobEffectInstance slowness = new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 200, 1, false, true); - MobEffectInstance hungry = new MobEffectInstance(MobEffects.HUNGER, 200, 1, false, true); - player.addEffect((weakness)); - int curedNumber = player.getInventory().countItem(ModItems.CURSED_GOLD_INGOT) + player.getInventory().countItem(ModItems.CURSED_GOLD_NUGGET) + player.getInventory().countItem(ModItems.CURSED_GOLD_BLOCK); - if (curedNumber>8){ - player.addEffect((slowness)); - } - if (curedNumber>64){ - player.addEffect((hungry)); - } - } + Cured.super.inventoryTick(stack, level, entity, slotId, isSelected); } } diff --git a/src/main/java/dev/dubhe/anvilcraft/item/CuredItem.java b/src/main/java/dev/dubhe/anvilcraft/item/CuredItem.java index fdb5db869..f9d2f1a3a 100644 --- a/src/main/java/dev/dubhe/anvilcraft/item/CuredItem.java +++ b/src/main/java/dev/dubhe/anvilcraft/item/CuredItem.java @@ -9,7 +9,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -public class CuredItem extends Item { +public class CuredItem extends Item implements Cured { public CuredItem(Properties properties) { super(properties); } @@ -17,18 +17,6 @@ public CuredItem(Properties properties) { @Override public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { super.inventoryTick(stack, level, entity, slotId, isSelected); - if (entity instanceof Player player) { - MobEffectInstance weakness = new MobEffectInstance(MobEffects.WEAKNESS, 200, 1, false, true); - MobEffectInstance slowness = new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 200, 1, false, true); - MobEffectInstance hungry = new MobEffectInstance(MobEffects.HUNGER, 200, 1, false, true); - player.addEffect((weakness)); - int curedNumber = player.getInventory().countItem(ModItems.CURSED_GOLD_INGOT) + player.getInventory().countItem(ModItems.CURSED_GOLD_NUGGET) + player.getInventory().countItem(ModItems.CURSED_GOLD_BLOCK); - if (curedNumber>8){ - player.addEffect((slowness)); - } - if (curedNumber>64){ - player.addEffect((hungry)); - } - } + Cured.super.inventoryTick(stack, level, entity, slotId, isSelected); } }