Skip to content

Commit

Permalink
Update to 21w18a
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed May 6, 2021
1 parent fd17158 commit 3d049da
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
------------------------------------------------------
Version 1.3.0
------------------------------------------------------
- Updated to 21w10a
- Updated to 21w18a

------------------------------------------------------
Version 1.2.1
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=21w10a
yarn_mappings=21w10a+build.2
loader_version=0.11.2
minecraft_version=21w18a
yarn_mappings=21w18a+build.3
loader_version=0.11.3
#Fabric api
fabric_version=0.32.1+1.17
fabric_version=0.34.2+1.17

# Mod Properties
mod_version = 1.3.0-nightly.21w10a
mod_version = 1.3.0-nightly.21w18a
maven_group = io.github.ladysnake
archives_base_name = Pal

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/github/ladysnake/pal/AbilityTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package io.github.ladysnake.pal;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Contract;

/**
Expand Down Expand Up @@ -87,13 +87,13 @@ public interface AbilityTracker {
* @param tag the tag to write to
*/
@Contract(mutates = "param")
void save(CompoundTag tag);
void save(NbtCompound tag);

/**
* Loads a serialized form of an {@code AbilityTracker} from {@code tag} into this object.
*
* @param tag the tag to read from
*/
@Contract(mutates = "this")
void load(CompoundTag tag);
void load(NbtCompound tag);
}
6 changes: 4 additions & 2 deletions src/main/java/io/github/ladysnake/pal/Pal.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package io.github.ladysnake.pal;

import com.google.common.base.Suppliers;
import io.github.ladysnake.pal.impl.PalInternals;
import net.fabricmc.api.ModInitializer;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -26,6 +27,7 @@

import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Supplier;

/**
* Player Ability Lib's main class. Provides static methods to interact with player abilities.
Expand Down Expand Up @@ -172,8 +174,8 @@ public static boolean isAbilityRegistered(@Nullable Identifier abilityId) {
* @return a lazy supplier for a player ability registered with the given {@code abilityId}
* @throws NullPointerException if {@code abilityId} is null
*/
public static Lazy<PlayerAbility> provideRegisteredAbility(Identifier abilityId) {
return new Lazy<>(() -> Objects.requireNonNull(PalInternals.getAbility(abilityId), abilityId + " has not been registered"));
public static Supplier<PlayerAbility> provideRegisteredAbility(Identifier abilityId) {
return Suppliers.memoize(() -> Objects.requireNonNull(PalInternals.getAbility(abilityId), abilityId + " has not been registered"));
}

@Override
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/io/github/ladysnake/pal/SimpleAbilityTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import io.github.ladysnake.pal.impl.VanillaAbilityTracker;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.util.Identifier;

import java.util.HashSet;
Expand Down Expand Up @@ -99,17 +99,17 @@ protected boolean shouldBeEnabled() {
}

@Override
public void save(CompoundTag tag) {
ListTag list = new ListTag();
public void save(NbtCompound tag) {
NbtList list = new NbtList();
for (AbilitySource abilitySource : this.abilitySources) {
list.add(StringTag.of(abilitySource.getId().toString()));
list.add(NbtString.of(abilitySource.getId().toString()));
}
tag.put("ability_sources", list);
}

@Override
public void load(CompoundTag tag) {
ListTag list = tag.getList("ability_sources", NbtType.STRING);
public void load(NbtCompound tag) {
NbtList list = tag.getList("ability_sources", NbtType.STRING);
for (int i = 0; i < list.size(); i++) {
Identifier sourceId = Identifier.tryParse(list.getString(i));
if (sourceId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
import io.github.ladysnake.pal.impl.VanillaAbilityTracker;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.ServerPlayerInteractionManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -93,10 +92,10 @@ private void checkAbilityConsistency(CallbackInfo ci) {
}

@Inject(method = "writeCustomDataToNbt", at = @At("RETURN"))
private void writeAbilitiesToTag(CompoundTag tag, CallbackInfo ci) {
ListTag list = new ListTag();
private void writeAbilitiesToTag(NbtCompound tag, CallbackInfo ci) {
NbtList list = new NbtList();
for (Map.Entry<PlayerAbility, AbilityTracker> entry : this.palAbilities.entrySet()) {
CompoundTag abilityTag = new CompoundTag();
NbtCompound abilityTag = new NbtCompound();
abilityTag.putString("ability_id", entry.getKey().getId().toString());
entry.getValue().save(abilityTag);
list.add(abilityTag);
Expand All @@ -106,11 +105,11 @@ private void writeAbilitiesToTag(CompoundTag tag, CallbackInfo ci) {

@Inject(
method = "readCustomDataFromNbt",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;readCustomDataFromNbt(Lnet/minecraft/nbt/CompoundTag;)V", shift = At.Shift.AFTER)
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;readCustomDataFromNbt(Lnet/minecraft/nbt/NbtCompound;)V", shift = At.Shift.AFTER)
)
private void readAbilitiesFromTag(CompoundTag tag, CallbackInfo ci) {
for (Tag t : tag.getList("playerabilitylib:abilities", NbtType.COMPOUND)) {
CompoundTag abilityTag = ((CompoundTag) t);
private void readAbilitiesFromTag(NbtCompound tag, CallbackInfo ci) {
for (NbtElement t : tag.getList("playerabilitylib:abilities", NbtType.COMPOUND)) {
NbtCompound abilityTag = ((NbtCompound) t);
if (abilityTag.contains("ability_id")) {
Identifier abilityId = Identifier.tryParse(abilityTag.getString("ability_id"));
if (abilityId != null) {
Expand Down

0 comments on commit 3d049da

Please sign in to comment.