Skip to content

Commit

Permalink
Merge pull request #131 from Gu-ZT/CuredItem
Browse files Browse the repository at this point in the history
诅咒金相关物品给玩家带来的debuff进行创造模式判断
  • Loading branch information
Gu-ZT authored Apr 1, 2024
2 parents 8a4f5bd + 12e2976 commit 17a4149
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
27 changes: 27 additions & 0 deletions src/main/java/dev/dubhe/anvilcraft/item/Cured.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
16 changes: 2 additions & 14 deletions src/main/java/dev/dubhe/anvilcraft/item/CuredBlockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
16 changes: 2 additions & 14 deletions src/main/java/dev/dubhe/anvilcraft/item/CuredItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,14 @@
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);
}

@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);
}
}

0 comments on commit 17a4149

Please sign in to comment.