Skip to content

Commit 0a34699

Browse files
authored
Merge pull request #29
Update to 1.21.6
2 parents f450efd + d7218b8 commit 0a34699

4 files changed

Lines changed: 49 additions & 49 deletions

File tree

gradle.properties

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx4G
33

44
# Fabric Properties
55
# check these on https://fabricmc.net/use
6-
minecraft_version=1.21.5
7-
yarn_mappings=1.21.5+build.1
8-
loader_version=0.16.10
9-
#Fabric api
10-
fabric_version=0.119.1+1.21.5
6+
minecraft_version=1.21.6
7+
yarn_mappings=1.21.6+build.1
8+
loader_version=0.16.14
9+
# Fabric API
10+
fabric_version=0.127.0+1.21.6
1111

1212
elmendorf_version = 0.15.0
1313

1414
# Mod Properties
15-
mod_version = 1.13.0
15+
mod_version = 1.14.0
1616
maven_group = io.github.ladysnake
1717
archives_base_name = pal
1818

@@ -22,7 +22,7 @@ display_name = PlayerAbilityLib
2222
license_header = LGPL
2323
gpl_version = 3
2424
curseforge_id = 359522
25-
curseforge_versions = 1.21.5
25+
curseforge_versions = 1.21.6
2626
cf_requirements = fabric-api
2727
modrinth_id = DHQA06r4
2828
release_type = release

src/main/java/io/github/ladysnake/pal/AbilityTracker.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
package io.github.ladysnake.pal;
1919

2020
import net.minecraft.entity.player.PlayerEntity;
21-
import net.minecraft.nbt.NbtCompound;
21+
import net.minecraft.storage.ReadView;
22+
import net.minecraft.storage.WriteView;
2223
import net.minecraft.util.Identifier;
2324
import org.jetbrains.annotations.Contract;
2425
import org.jetbrains.annotations.Nullable;
@@ -104,16 +105,16 @@ public interface AbilityTracker {
104105
/**
105106
* Saves this {@code AbilityTracker} in a serialized form to {@code tag}.
106107
*
107-
* @param tag the tag to write to
108+
* @param view the view to read from
108109
*/
109110
@Contract(mutates = "param")
110-
void save(NbtCompound tag);
111+
void save(WriteView view);
111112

112113
/**
113114
* Loads a serialized form of an {@code AbilityTracker} from {@code tag} into this object.
114115
*
115-
* @param tag the tag to read from
116+
* @param view the view to write to
116117
*/
117118
@Contract(mutates = "this")
118-
void load(NbtCompound tag);
119+
void load(ReadView view);
119120
}

src/main/java/io/github/ladysnake/pal/SimpleAbilityTracker.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
*/
1818
package io.github.ladysnake.pal;
1919

20+
import com.mojang.serialization.Codec;
2021
import io.github.ladysnake.pal.impl.PalInternals;
2122
import io.github.ladysnake.pal.impl.VanillaAbilityTracker;
2223
import net.minecraft.entity.player.PlayerEntity;
23-
import net.minecraft.nbt.NbtCompound;
24-
import net.minecraft.nbt.NbtList;
25-
import net.minecraft.nbt.NbtString;
24+
import net.minecraft.storage.ReadView;
25+
import net.minecraft.storage.WriteView;
2626
import net.minecraft.util.Identifier;
2727

2828
import java.util.SortedSet;
@@ -104,23 +104,22 @@ protected boolean shouldBeEnabled() {
104104
}
105105

106106
@Override
107-
public void save(NbtCompound tag) {
108-
NbtList list = new NbtList();
107+
public void save(WriteView view) {
108+
var list = view.getListAppender("ability_sources", Codec.STRING);
109109
for (AbilitySource abilitySource : this.abilitySources) {
110-
list.add(NbtString.of(abilitySource.getId().toString()));
110+
list.add(abilitySource.getId().toString());
111111
}
112-
tag.put("ability_sources", list);
113112
}
114113

115114
@Override
116-
public void load(NbtCompound tag) {
117-
NbtList list = tag.getListOrEmpty("ability_sources");
118-
for (int i = 0; i < list.size(); i++) {
119-
AbilitySource source = list.getString(i).map(x -> PalInternals.getSource(Identifier.tryParse(x))).orElse(null);
115+
public void load(ReadView view) {
116+
var list = view.getTypedListView("ability_sources", Codec.STRING);
117+
for (var string : list) {
118+
AbilitySource source = PalInternals.getSource(Identifier.tryParse(string));
120119
if (source != null) {
121120
this.addSource(source);
122121
} else {
123-
PalInternals.LOGGER.warn("Unknown ability source {} attached to {} for {}", list.getString(i), this.player, this.ability);
122+
PalInternals.LOGGER.warn("Unknown ability source {} attached to {} for {}", string, this.player, this.ability);
124123
}
125124
}
126125
}

src/main/java/io/github/ladysnake/pal/impl/mixin/ServerPlayerEntityMixin.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@
3232
import net.minecraft.server.MinecraftServer;
3333
import net.minecraft.server.network.ServerPlayerEntity;
3434
import net.minecraft.server.world.ServerWorld;
35+
import net.minecraft.storage.NbtReadView;
36+
import net.minecraft.storage.NbtWriteView;
37+
import net.minecraft.storage.ReadView;
38+
import net.minecraft.storage.WriteView;
39+
import net.minecraft.util.ErrorReporter;
3540
import net.minecraft.util.Identifier;
36-
import net.minecraft.util.math.BlockPos;
3741
import net.minecraft.world.World;
3842
import org.spongepowered.asm.mixin.Mixin;
3943
import org.spongepowered.asm.mixin.Unique;
@@ -50,8 +54,8 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntity implements Pl
5054
@Unique
5155
private final Map<PlayerAbility, AbilityTracker> palAbilities = new LinkedHashMap<>();
5256

53-
public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile gameProfile) {
54-
super(world, pos, yaw, gameProfile);
57+
public ServerPlayerEntityMixin(World world, GameProfile gameProfile) {
58+
super(world, gameProfile);
5559
}
5660

5761

@@ -85,10 +89,10 @@ public void refreshAllPalAbilities(boolean syncVanilla) {
8589
@Inject(method = "copyFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;setGameMode(Lnet/minecraft/world/GameMode;Lnet/minecraft/world/GameMode;)V", shift = At.Shift.AFTER))
8690
private void copyAbilitiesAfterRespawn(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo ci) {
8791
if (alive) {
88-
NbtCompound nbt = new NbtCompound();
92+
var writeView = NbtWriteView.create(ErrorReporter.EMPTY, oldPlayer.getRegistryManager());
8993
//noinspection ConstantConditions
90-
((ServerPlayerEntityMixin) (Object) oldPlayer).writeAbilitiesToTag(nbt, null);
91-
this.readAbilitiesFromTag(nbt, null);
94+
((ServerPlayerEntityMixin) (Object) oldPlayer).writeAbilitiesToData(writeView, null);
95+
this.readAbilitiesFromData(NbtReadView.create(ErrorReporter.EMPTY, oldPlayer.getRegistryManager(), writeView.getNbt()), null);
9296
}
9397
}
9498

@@ -102,33 +106,29 @@ private void checkAbilityConsistency(CallbackInfo ci) {
102106
}
103107
}
104108

105-
@Inject(method = "writeCustomDataToNbt", at = @At("RETURN"))
106-
private void writeAbilitiesToTag(NbtCompound tag, CallbackInfo ci) {
107-
NbtList list = new NbtList();
109+
@Inject(method = "writeCustomData", at = @At("RETURN"))
110+
private void writeAbilitiesToData(WriteView view, CallbackInfo ci) {
111+
var list = view.getList("playerabilitylib:abilities");
108112
for (Map.Entry<PlayerAbility, AbilityTracker> entry : this.palAbilities.entrySet()) {
109-
NbtCompound abilityTag = new NbtCompound();
113+
var abilityTag = list.add();
110114
abilityTag.putString("ability_id", entry.getKey().getId().toString());
111115
entry.getValue().save(abilityTag);
112-
list.add(abilityTag);
113116
}
114-
tag.put("playerabilitylib:abilities", list);
115117
}
116118

117119
@Inject(
118-
method = "readCustomDataFromNbt",
119-
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;readCustomDataFromNbt(Lnet/minecraft/nbt/NbtCompound;)V", shift = At.Shift.AFTER)
120+
method = "readCustomData",
121+
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;readCustomData(Lnet/minecraft/storage/ReadView;)V", shift = At.Shift.AFTER)
120122
)
121-
private void readAbilitiesFromTag(NbtCompound tag, CallbackInfo ci) {
122-
for (NbtElement t : tag.getListOrEmpty("playerabilitylib:abilities")) {
123-
if (t instanceof NbtCompound abilityTag) {
124-
if (abilityTag.contains("ability_id")) {
125-
String abilityId = abilityTag.getString("ability_id", "");
126-
AbilityTracker tracker = this.palAbilities.get(PalInternals.getAbility(Identifier.tryParse(abilityId)));
127-
if (tracker != null) {
128-
tracker.load(abilityTag);
129-
} else {
130-
PalInternals.LOGGER.warn("Encountered unknown ability {} while deserializing data for {}", abilityId, this);
131-
}
123+
private void readAbilitiesFromData(ReadView view, CallbackInfo ci) {
124+
for (var abilityTag : view.getListReadView("playerabilitylib:abilities")) {
125+
String abilityId = abilityTag.getString("ability_id", "");
126+
if (!abilityId.isEmpty()) {
127+
AbilityTracker tracker = this.palAbilities.get(PalInternals.getAbility(Identifier.tryParse(abilityId)));
128+
if (tracker != null) {
129+
tracker.load(abilityTag);
130+
} else {
131+
PalInternals.LOGGER.warn("Encountered unknown ability {} while deserializing data for {}", abilityId, this);
132132
}
133133
}
134134
}

0 commit comments

Comments
 (0)