Skip to content

Commit 97b4e11

Browse files
committed
Add equipment decays faster curse
1 parent 1182e49 commit 97b4e11

2 files changed

Lines changed: 91 additions & 63 deletions

File tree

src/main/java/huix/infinity/common/world/curse/CurseEffectHelper.java

Lines changed: 81 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -39,60 +39,13 @@ public static void learnCurseEffect(PlayerExtension ext) {
3939
}
4040
}
4141

42-
public static boolean isIngestionForbiddenByCurse(Player player, ItemStack itemStack) {
43-
if (!(player instanceof PlayerExtension ext)) return false;
44-
CurseType curse = ext.getCurse();
45-
46-
if (itemStack.ifw_isEdible()) {
47-
if (itemStack.ifw_isAnimalProduct() && curse == CurseType.cannot_eat_meats) {
48-
learnCurseEffect(ext);
49-
return true;
50-
}
51-
if (itemStack.ifw_isPlantProduct() && curse == CurseType.cannot_eat_plants) {
52-
learnCurseEffect(ext);
53-
return true;
54-
}
55-
}
56-
if (itemStack.ifw_isDrink() && curse == CurseType.cannot_drink) {
57-
if (itemStack.getItem() != IFWItems.bottle_of_disenchanting.get()) {
58-
learnCurseEffect(ext);
59-
return true;
60-
}
61-
}
62-
return false;
63-
}
64-
65-
public static boolean canWearArmor(Player player) {
66-
if (!(player instanceof PlayerExtension ext)) return true;
67-
if (ext.getCurse() == CurseType.cannot_wear_armor) {
68-
learnCurseEffect(ext);
69-
return false;
70-
}
71-
return true;
72-
}
73-
public static void handleArmorCurse(Player player) {
74-
if (!canWearArmor(player)) {
75-
EquipmentSlot[] armorSlots = {EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET};
76-
for (EquipmentSlot slot : armorSlots) {
77-
ItemStack armorStack = player.getItemBySlot(slot);
78-
if (!armorStack.isEmpty()) {
79-
boolean added = player.getInventory().add(armorStack);
80-
if (!added) {
81-
player.drop(armorStack, false);
82-
}
83-
player.setItemSlot(slot, ItemStack.EMPTY);
84-
}
85-
}
86-
}
87-
}
8842

89-
public static boolean shouldBlockSprint(Player player) {
90-
if (!(player instanceof PlayerExtension ext)) return false;
91-
if (ext.getCurse() == CurseType.cannot_run) {
43+
public static int handleCorrosionCurseDamage(int damage, LivingEntity entity) {
44+
if (entity instanceof PlayerExtension ext && ext.hasCurse(CurseType.equipment_decays_faster)) {
9245
learnCurseEffect(ext);
93-
return true;
46+
return damage * 2;
9447
}
95-
return false;
48+
return damage;
9649
}
9750

9851
public static int getCursedMaxAirSupply(Player player, int vanillaMaxAir) {
@@ -118,18 +71,40 @@ public static int getCursedBubbleMax(Player player, int vanillaBubbleMax, int ma
11871
return vanillaBubbleMax;
11972
}
12073

121-
public static boolean handleChestCurse(Player player, Block block) {
74+
75+
public static boolean shouldBlockSprint(Player player) {
12276
if (!(player instanceof PlayerExtension ext)) return false;
123-
if (ext.getCurse() == CurseType.cannot_open_chests) { // MITE does not prohibit these
124-
if (block instanceof ChestBlock || block instanceof BarrelBlock /* || block instanceof ShulkerBoxBlock || block instanceof EnderChestBlock */) {
77+
if (ext.getCurse() == CurseType.cannot_run) {
78+
learnCurseEffect(ext);
79+
return true;
80+
}
81+
return false;
82+
}
83+
84+
public static boolean isIngestionForbiddenByCurse(Player player, ItemStack itemStack) {
85+
if (!(player instanceof PlayerExtension ext)) return false;
86+
CurseType curse = ext.getCurse();
87+
88+
if (itemStack.ifw_isEdible()) {
89+
if (itemStack.ifw_isAnimalProduct() && curse == CurseType.cannot_eat_meats) {
90+
learnCurseEffect(ext);
91+
return true;
92+
}
93+
if (itemStack.ifw_isPlantProduct() && curse == CurseType.cannot_eat_plants) {
94+
learnCurseEffect(ext);
95+
return true;
96+
}
97+
}
98+
if (itemStack.ifw_isDrink() && curse == CurseType.cannot_drink) {
99+
if (itemStack.getItem() != IFWItems.bottle_of_disenchanting.get()) {
125100
learnCurseEffect(ext);
126-
player.level().playSound(null, player.getX(), player.getY(), player.getZ(), IFWSoundEvents.CHEST_LOCKED.get(), SoundSource.BLOCKS, 0.2F, 1.0F);
127101
return true;
128102
}
129103
}
130104
return false;
131105
}
132106

107+
133108
public static void handleEndermanAggro(EnderMan enderman) {
134109
Player nearestPlayer = null;
135110
PlayerExtension nearestExt = null;
@@ -159,14 +134,9 @@ public static void handleEndermanAggro(EnderMan enderman) {
159134
}
160135
}
161136

162-
public static boolean shouldBlockSleep(Player player) {
163-
if (!(player instanceof PlayerExtension ext)) return false;
164-
if (ext.getCurse() == CurseType.cannot_sleep) {
165-
learnCurseEffect(ext);
166-
return true;
167-
}
168-
return false;
169-
}
137+
138+
// Clumsiness
139+
170140

171141
public static float getEntangleCurseSlowdown(Player player) {
172142
if (!(player instanceof PlayerExtension ext) || ext.getCurse() != CurseType.entanglement) return 1.0F;
@@ -198,6 +168,54 @@ public static float getEntangleCurseSlowdown(Player player) {
198168
return 1.0F;
199169
}
200170

171+
public static boolean canWearArmor(Player player) {
172+
if (!(player instanceof PlayerExtension ext)) return true;
173+
if (ext.getCurse() == CurseType.cannot_wear_armor) {
174+
learnCurseEffect(ext);
175+
return false;
176+
}
177+
return true;
178+
}
179+
public static void handleArmorCurse(Player player) {
180+
if (!canWearArmor(player)) {
181+
EquipmentSlot[] armorSlots = {EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET};
182+
for (EquipmentSlot slot : armorSlots) {
183+
ItemStack armorStack = player.getItemBySlot(slot);
184+
if (!armorStack.isEmpty()) {
185+
boolean added = player.getInventory().add(armorStack);
186+
if (!added) {
187+
player.drop(armorStack, false);
188+
}
189+
player.setItemSlot(slot, ItemStack.EMPTY);
190+
}
191+
}
192+
}
193+
}
194+
195+
196+
public static boolean handleChestCurse(Player player, Block block) {
197+
if (!(player instanceof PlayerExtension ext)) return false;
198+
if (ext.getCurse() == CurseType.cannot_open_chests) { // MITE does not prohibit these
199+
if (block instanceof ChestBlock || block instanceof BarrelBlock /* || block instanceof ShulkerBoxBlock || block instanceof EnderChestBlock */) {
200+
learnCurseEffect(ext);
201+
player.level().playSound(null, player.getX(), player.getY(), player.getZ(), IFWSoundEvents.CHEST_LOCKED.get(), SoundSource.BLOCKS, 0.2F, 1.0F);
202+
return true;
203+
}
204+
}
205+
return false;
206+
}
207+
208+
209+
public static boolean shouldBlockSleep(Player player) {
210+
if (!(player instanceof PlayerExtension ext)) return false;
211+
if (ext.getCurse() == CurseType.cannot_sleep) {
212+
learnCurseEffect(ext);
213+
return true;
214+
}
215+
return false;
216+
}
217+
218+
201219
public static boolean shouldPreventCurseAttack(LivingEntity target, DamageSource source) {
202220
Entity attacker = source.getEntity();
203221
if (!(attacker instanceof PlayerExtension ext)) return false;

src/main/java/huix/infinity/mixin/world/item/ItemStackMixin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22

33
import huix.infinity.common.core.component.IFWDataComponents;
44
import huix.infinity.common.core.tag.IFWItemTags;
5+
import huix.infinity.common.world.curse.CurseEffectHelper;
56
import huix.infinity.common.world.item.crafting.EnchantingRecipe;
67
import huix.infinity.extension.func.ItemStackExtension;
78
import net.minecraft.resources.ResourceLocation;
9+
import net.minecraft.server.level.ServerLevel;
810
import net.minecraft.tags.ItemTags;
911
import net.minecraft.tags.TagKey;
12+
import net.minecraft.world.entity.LivingEntity;
1013
import net.minecraft.world.item.Item;
1114
import net.minecraft.world.item.ItemStack;
1215
import net.minecraft.world.item.UseAnim;
1316
import org.spongepowered.asm.mixin.Mixin;
1417
import org.spongepowered.asm.mixin.Shadow;
1518
import org.spongepowered.asm.mixin.Unique;
19+
import org.spongepowered.asm.mixin.injection.At;
20+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
1621

1722
@Mixin(ItemStack.class)
1823
public class ItemStackMixin implements ItemStackExtension {
@@ -64,6 +69,11 @@ public boolean is(TagKey<Item> tag) {
6469
throw new AssertionError("Shadow stub called!");
6570
}
6671

72+
@ModifyVariable(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LivingEntity;Ljava/util/function/Consumer;)V", at = @At("HEAD"), ordinal = 0, argsOnly = true)
73+
private int ifw$corrosionCurseDamage(int damage, int original, ServerLevel level, LivingEntity entity, java.util.function.Consumer<?> onBreak) {
74+
return CurseEffectHelper.handleCorrosionCurseDamage(damage, entity);
75+
}
76+
6777
@Override
6878
public boolean ifw_isAnimalProduct() {
6979
return this.is(IFWItemTags.ANIMAL_PRODUCTS)

0 commit comments

Comments
 (0)