Skip to content

Commit b7f3457

Browse files
committed
Curse attachment cannot save
1 parent dbafa22 commit b7f3457

12 files changed

Lines changed: 90 additions & 64 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ parchment_mappings_version=2024.11.17
1212
## Neoforge
1313
minecraft_version=1.21.1
1414
minecraft_version_range=[1.21,1.22)
15-
neo_version=21.1.143
15+
neo_version=21.1.140
1616
neo_version_range=[21.1.110,)
1717
loader_version_range=[4,)
1818
neomoddev_version=1.0.20

src/main/java/huix/infinity/attachment/IFWAttachments.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class IFWAttachments {
1616
public static final DeferredRegister<AttachmentType<?>> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.ATTACHMENT_TYPES, InfinityWay.MOD_ID);
1717

1818
public static final Supplier<AttachmentType<Integer>> respawn_xp = ATTACHMENT_TYPES.register(
19-
"respawn_xp", () -> AttachmentType.builder(() -> 0).serialize(Codec.INT).build()
19+
"respawn_xp", () -> AttachmentType.builder(() -> 0).serialize(Codec.INT).copyOnDeath().build()
2020
);
2121

2222
public static final Supplier<AttachmentType<Integer>> armor_effect = ATTACHMENT_TYPES.register(
@@ -50,7 +50,7 @@ public class IFWAttachments {
5050
);
5151

5252
public static final Supplier<AttachmentType<PersistentEffectInstance>> player_curse = ATTACHMENT_TYPES.register(
53-
"player_curse", () -> AttachmentType.serializable(attachmentHolder -> new PersistentEffectInstance(Curses.none)).copyOnDeath().build()
53+
"player_curse", () -> AttachmentType.builder(() -> new PersistentEffectInstance(Curses.none)).serialize(PersistentEffectInstance.CODEC).copyOnDeath().build()
5454
);
5555
public static final Supplier<AttachmentType<Boolean>> learned_curse = ATTACHMENT_TYPES.register(
5656
"learned_curse", () -> AttachmentType.builder(() -> false).serialize(Codec.BOOL).copyOnDeath().build()

src/main/java/huix/infinity/extension/func/FoodDataExtension.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ default void ifw_nutritionalStatusByINT(int nutritionalStatus) {}
3030
default int ifw_nutritionalStatusByINT() {
3131
return 0;
3232
}
33+
3334
default NutritionalStatus ifw_nutritionalStatus() {
3435
return null;
3536
}
37+
3638
default void eat(IFWFoodProperties foodProperties){}
39+
3740
}

src/main/java/huix/infinity/extension/func/PlayerExtension.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ default boolean canResetTimeBySleeping() {
3030
}
3131

3232
default boolean hasCurse() {
33-
return instance().hasData(IFWAttachments.player_curse) && !curse().equals(Curses.none.value());
33+
return !curse().equals(Curses.none.value());
3434
}
3535

3636
default boolean knownCurse() {
@@ -42,15 +42,17 @@ default boolean hasCurse(Curse curse) {
4242
}
4343

4444
default Curse curse() {
45-
return (Curse) instance().getData(IFWAttachments.player_curse).persistentEff().value();
45+
return (Curse) Curses.none.value();
4646
}
4747

4848
default void curse(Holder<PersistentEffect> curse) {
4949
curse(new PersistentEffectInstance(curse));
5050
}
5151

5252
default void curse(PersistentEffectInstance curse) {
53-
instance().setData(IFWAttachments.player_curse, curse);
53+
}
54+
55+
default void learnCurse() {
5456
}
5557

5658

src/main/java/huix/infinity/init/IFWEvents.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import huix.infinity.attachment.IFWAttachments;
44
import huix.infinity.common.core.component.IFWDataComponents;
5+
import huix.infinity.common.world.curse.Curses;
6+
import huix.infinity.common.world.curse.PersistentEffectInstance;
57
import huix.infinity.common.world.effect.UnClearEffect;
68
import huix.infinity.common.world.entity.player.LevelBonusStats;
79
import huix.infinity.common.world.food.IFWFoodProperties;
810
import huix.infinity.common.world.item.IFWItems;
911
import huix.infinity.init.event.IFWLoading;
10-
import huix.infinity.init.to.IFWClient;
11-
import huix.infinity.util.IFWConstants;
1212
import huix.infinity.util.IFWEnchantmentHelper;
1313
import huix.infinity.util.WorldHelper;
1414
import net.minecraft.ChatFormatting;
@@ -30,11 +30,7 @@
3030
import net.minecraft.world.item.Items;
3131
import net.minecraft.world.level.Level;
3232
import net.minecraft.world.level.block.Blocks;
33-
import net.neoforged.bus.api.EventPriority;
3433
import net.neoforged.bus.api.IEventBus;
35-
import net.neoforged.bus.api.SubscribeEvent;
36-
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
37-
import net.neoforged.neoforge.common.NeoForge;
3834
import net.neoforged.neoforge.common.Tags;
3935
import net.neoforged.neoforge.event.ItemAttributeModifierEvent;
4036
import net.neoforged.neoforge.event.entity.living.LivingDeathEvent;
@@ -55,7 +51,7 @@ public class IFWEvents {
5551

5652
public static void init(IEventBus bus) {
5753
bus.addListener(IFWEvents::armorModify);
58-
bus.addListener(IFWEvents::onBreakSpeed);
54+
bus.addListener(IFWEvents::playerBreakSpeed);
5955
bus.addListener(IFWEvents::playerAttacklHit);
6056
bus.addListener(IFWEvents::playerDie);
6157
bus.addListener(IFWEvents::playerClone);
@@ -64,7 +60,8 @@ public static void init(IEventBus bus) {
6460
bus.addListener(IFWEvents::nonRemoveUnClearEffect);
6561
bus.addListener(IFWEvents::injectFuel);
6662
bus.addListener(IFWEvents::injectItem);
67-
bus.addListener(IFWEvents::onServerTick);
63+
bus.addListener(IFWEvents::serverTick);
64+
bus.addListener(IFWEvents::playerLoggedIn);
6865
}
6966

7067
public static void injectItem(final DataMapsUpdatedEvent event) {
@@ -74,7 +71,7 @@ public static void injectItem(final DataMapsUpdatedEvent event) {
7471
}
7572

7673

77-
public static void onServerTick(final ServerTickEvent.Post event) {
74+
public static void serverTick(final ServerTickEvent.Post event) {
7875
for (Map.Entry<ResourceKey<Level>, Map<BlockPos, Integer>> entry : WorldHelper.DELAYED_BLOCKS.entrySet()) {
7976
ResourceKey<Level> dimension = entry.getKey();
8077
Map<BlockPos, Integer> blocks = entry.getValue();
@@ -108,8 +105,15 @@ public static void armorModify(final ItemAttributeModifierEvent event) {
108105
}
109106

110107
}
108+
public static void playerLoggedIn(final PlayerEvent.PlayerLoggedInEvent event) {
109+
Player entity = event.getEntity();
110+
entity.curse(Curses.cannot_eat_meats);
111+
entity.learnCurse();
112+
entity.experienceLevel = 20;
113+
}
114+
111115

112-
public static void onBreakSpeed(final PlayerEvent.BreakSpeed event) {
116+
public static void playerBreakSpeed(final PlayerEvent.BreakSpeed event) {
113117
event.setNewSpeed(event.getOriginalSpeed() + LevelBonusStats.HARVESTING.calcBonusFor(event.getEntity()));
114118
}
115119

@@ -122,8 +126,7 @@ public static void playerAttacklHit(final CriticalHitEvent event) {
122126

123127
public static void playerDie(final LivingDeathEvent event) {
124128
if (event.getEntity() instanceof Player entity) {
125-
Integer respawn_experience = entity.getData(IFWAttachments.respawn_xp);
126-
129+
int respawn_experience = entity.getData(IFWAttachments.respawn_xp);
127130
if (entity.totalExperience < 20) {
128131
entity.setData(IFWAttachments.respawn_xp, entity.totalExperience - 20);
129132

@@ -136,8 +139,7 @@ public static void playerDie(final LivingDeathEvent event) {
136139

137140
public static void playerClone(final PlayerEvent.Clone event) {
138141
final Player cloned = event.getEntity();
139-
final Player original = event.getOriginal();
140-
cloned.giveExperiencePoints(original.getData(IFWAttachments.respawn_xp));
142+
cloned.giveExperiencePoints(event.getOriginal().getData(IFWAttachments.respawn_xp));
141143
}
142144

143145
public static void daySleep(final CanContinueSleepingEvent event) {

src/main/java/huix/infinity/mixin/world/entity/PlayerMixin.java

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package huix.infinity.mixin.world.entity;
22

3+
import com.mojang.authlib.GameProfile;
4+
import com.mojang.serialization.DataResult;
5+
import huix.infinity.attachment.IFWAttachments;
36
import huix.infinity.common.core.component.IFWDataComponents;
47
import huix.infinity.common.core.registries.IFWRegistries;
58
import huix.infinity.common.world.curse.Curse;
@@ -10,77 +13,77 @@
1013
import huix.infinity.init.InfinityWay;
1114
import huix.infinity.util.ReflectHelper;
1215
import huix.infinity.util.WorldHelper;
16+
import net.minecraft.core.GlobalPos;
1317
import net.minecraft.nbt.CompoundTag;
18+
import net.minecraft.nbt.ListTag;
19+
import net.minecraft.nbt.NbtOps;
1420
import net.minecraft.resources.ResourceLocation;
1521
import net.minecraft.sounds.SoundEvents;
1622
import net.minecraft.util.Mth;
1723
import net.minecraft.world.entity.*;
1824
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
1925
import net.minecraft.world.entity.ai.attributes.Attributes;
26+
import net.minecraft.world.entity.player.Abilities;
27+
import net.minecraft.world.entity.player.Inventory;
2028
import net.minecraft.world.entity.player.Player;
2129
import net.minecraft.world.food.FoodData;
2230
import net.minecraft.world.food.FoodProperties;
31+
import net.minecraft.world.inventory.PlayerEnderChestContainer;
2332
import net.minecraft.world.item.ItemStack;
2433
import net.minecraft.world.level.GameRules;
2534
import net.minecraft.world.level.Level;
35+
import net.minecraft.world.phys.Vec3;
2636
import net.neoforged.neoforge.common.NeoForge;
2737
import net.neoforged.neoforge.common.NeoForgeMod;
2838
import net.neoforged.neoforge.event.entity.player.PlayerXpEvent;
29-
import org.spongepowered.asm.mixin.Mixin;
30-
import org.spongepowered.asm.mixin.Overwrite;
31-
import org.spongepowered.asm.mixin.Shadow;
32-
import org.spongepowered.asm.mixin.Unique;
39+
import org.slf4j.Logger;
40+
import org.spongepowered.asm.mixin.*;
3341
import org.spongepowered.asm.mixin.injection.At;
3442
import org.spongepowered.asm.mixin.injection.Inject;
3543
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3644
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
3745

46+
import javax.annotation.Nullable;
3847
import java.util.Objects;
48+
import java.util.Optional;
3949

40-
@Mixin( Player.class )
50+
@Mixin(Player.class)
4151
public abstract class PlayerMixin extends LivingEntity implements PlayerExtension {
4252

43-
@Shadow public abstract void causeFoodExhaustion(float exhaustion);
44-
45-
@Shadow public abstract FoodData getFoodData();
46-
47-
48-
@Unique
49-
private PersistentEffectInstance curse;
50-
5153
@Unique
52-
public boolean learnedCurse = false;
54+
private PersistentEffectInstance curse = PersistentEffectInstance.of(Curses.none);
55+
@Override
56+
public Curse curse() {
57+
return (Curse) this.curse.persistentEff().value();
58+
}
5359

5460
@Override
5561
public boolean knownCurse() {
56-
return this.hasCurse() && this.learnedCurse;
62+
return learnedCurse;
5763
}
5864

59-
// @Override
60-
// public void curse(PersistentEffectInstance curse) {
61-
// this.curse = curse;
62-
// }
65+
@Override
66+
public void learnCurse() {
67+
learnedCurse = true;
68+
}
6369

64-
// @Override
65-
// public Curse curse() {
66-
// System.out.println(this.curse);
67-
// return (Curse) this.curse.persistentEff().value();
68-
// }
70+
@Unique
71+
private boolean learnedCurse = false;
6972

70-
@Inject(at = @At(value = "RETURN"), method = "readAdditionalSaveData")
73+
@Inject(at = @At("RETURN"), method = "readAdditionalSaveData")
7174
private void readNBT(CompoundTag compound, CallbackInfo ci){
72-
// this.curse(PersistentEffectInstance.load(compound.getCompound("curse")));
73-
this.curse(Curses.cannot_eat_meats);
74-
System.out.println("11111111111" + this.curse);
7575
this.learnedCurse = compound.getBoolean("learnedCurse");
7676
}
7777

7878
@Inject(at = @At("RETURN"), method = "addAdditionalSaveData")
79-
private void saveNBT(CompoundTag compound, CallbackInfo ci) {
80-
if (curse != null) compound.put("curse", this.curse.save());
79+
private void injectNBT(CompoundTag compound, CallbackInfo ci){
8180
compound.putBoolean("learnedCurse", this.learnedCurse);
8281
}
8382

83+
@Override
84+
public void curse(PersistentEffectInstance curse) {
85+
this.curse = curse;
86+
}
8487

8588
@Overwrite
8689
public int getXpNeededForNextLevel() {
@@ -231,6 +234,29 @@ protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level level
231234
private int lastLevelUpTime;
232235
@Shadow
233236
public float experienceProgress;
237+
@Shadow @Final private GameProfile gameProfile;
238+
@Shadow private int currentImpulseContextResetGraceTime;
239+
@Shadow private boolean ignoreFallDamageFromCurrentImpulse;
240+
@Shadow @Nullable public Vec3 currentImpulseImpactPos;
241+
242+
@Shadow public abstract void setLastDeathLocation(Optional<GlobalPos> lastDeathLocation);
243+
244+
@Shadow protected abstract void setShoulderEntityRight(CompoundTag entityCompound);
245+
246+
@Shadow protected abstract void setShoulderEntityLeft(CompoundTag entityCompound);
247+
248+
@Shadow protected PlayerEnderChestContainer enderChestInventory;
249+
@Shadow @Final private Abilities abilities;
250+
@Shadow protected FoodData foodData;
251+
252+
@Shadow public abstract void setScore(int score);
253+
254+
@Shadow public int enchantmentSeed;
255+
@Shadow @Final private Inventory inventory;
256+
257+
@Shadow public abstract void causeFoodExhaustion(float exhaustion);
258+
259+
@Shadow public abstract FoodData getFoodData();
234260
@Shadow
235261
public void increaseScore(int score) {
236262
}

src/main/java/huix/infinity/mixin/world/entity/ServerPlayerMixin.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ private void updateTotalXP_1(int level, CallbackInfo ci){
5858
@Override
5959
public void curse(PersistentEffectInstance curse) {
6060
super.curse(curse);
61-
if (this.connection != null) {
62-
if (curse.persistentEff() == Curses.none)
63-
this.connection.send(new ClientboundSetActionBarTextPacket(Component.keybind("ifw.witch_curse.discurse").withStyle(ChatFormatting.WHITE, ChatFormatting.BOLD)));
64-
else
65-
this.connection.send(new ClientboundSetActionBarTextPacket(Component.keybind("ifw.witch_curse.curse").withStyle(ChatFormatting.DARK_PURPLE, ChatFormatting.BOLD)));
66-
this.connection.send(new ClientBoundSetCursePayload(curse));
67-
}
61+
if (curse.persistentEff() == Curses.none)
62+
this.connection.send(new ClientboundSetActionBarTextPacket(Component.keybind("ifw.witch_curse.discurse").withStyle(ChatFormatting.WHITE, ChatFormatting.BOLD)));
63+
else
64+
this.connection.send(new ClientboundSetActionBarTextPacket(Component.keybind("ifw.witch_curse.curse").withStyle(ChatFormatting.DARK_PURPLE, ChatFormatting.BOLD)));
65+
this.connection.send(new ClientBoundSetCursePayload(curse));
6866
}
6967

7068
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;getHealth()F", ordinal = 0, shift = At.Shift.BEFORE), method = "doTick")

src/main/java/huix/infinity/mixin/world/food/FoodDataMixin.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,8 @@ private void nutritionalStatus(NutritionalStatus nutritionalStatus) {
294294
}
295295
@Unique
296296
private void decreaseNutrition() {
297-
if (this.phytonutrients > 0) {
298-
--this.phytonutrients;
299-
}
300-
301-
if (this.protein > 0) {
302-
--this.protein;
303-
}
297+
if (this.phytonutrients > 0) --this.phytonutrients;
298+
if (this.protein > 0) --this.protein;
304299
}
305300
@Unique
306301
private boolean hasNutrition() {
353 Bytes
Loading
395 Bytes
Loading

0 commit comments

Comments
 (0)