Skip to content

Commit

Permalink
Update to 1.17.
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Paul-R committed Jun 12, 2021
1 parent 8eec756 commit 9846358
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.11.3

# Mod Properties
mod_version = 0.1.3-mc1.16.1
mod_version = 0.1.3-mc1.17
maven_group = com.fibermc
archives_base_name = essential_commands

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
Expand Down
35 changes: 17 additions & 18 deletions src/main/java/com/fibermc/essentialcommands/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.fibermc.essentialcommands.types.MinecraftLocation;
import com.google.common.collect.Maps;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.PersistentState;

Expand Down Expand Up @@ -39,8 +39,7 @@ public class PlayerData extends PersistentState {
private int tpCooldown;
private int tpDelay;

public PlayerData(String keyUUID, ServerPlayerEntity player, ManagerLocator managers) {
super(keyUUID);
public PlayerData(ServerPlayerEntity player, ManagerLocator managers) {
this.player = player;
this.pUuid = player.getUuid();
tpTimer = -1;
Expand Down Expand Up @@ -112,14 +111,14 @@ public MinecraftLocation getHomeLocation(String homeName) {
}

// IO
@Override
public void fromTag(CompoundTag tag) {
CompoundTag dataTag = tag.getCompound("data");
// @Override
public void fromTag(NbtCompound tag) {
NbtCompound dataTag = tag.getCompound("data");
this.pUuid = dataTag.getUuid("playerUuid");
ListTag homesListTag = dataTag.getList("homes", 10);
NbtList homesNbtList = dataTag.getList("homes", 10);
HashMap<String, MinecraftLocation> homes = Maps.newHashMap();
for (Tag t : homesListTag) {
CompoundTag homeTag = (CompoundTag) t;
for (NbtElement t : homesNbtList) {
NbtCompound homeTag = (NbtCompound) t;
MinecraftLocation location = new MinecraftLocation(homeTag);
String homeName = homeTag.getString("homeName");
homes.put(homeName, location);
Expand All @@ -128,15 +127,15 @@ public void fromTag(CompoundTag tag) {
}

@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound writeNbt(NbtCompound tag) {
tag.putUuid("playerUuid", pUuid);
ListTag homesListTag = new ListTag();
NbtList homesNbtList = new NbtList();
for (Entry<String, MinecraftLocation> entry : homes.entrySet()) {
CompoundTag homeTag = entry.getValue().toTag(new CompoundTag());
NbtCompound homeTag = entry.getValue().toTag(new NbtCompound());
homeTag.putString("homeName", entry.getKey());
homesListTag.add(homeTag);
homesNbtList.add(homeTag);
}
tag.put("homes", homesListTag);
tag.put("homes", homesNbtList);

return tag;
}
Expand Down Expand Up @@ -191,8 +190,8 @@ public void setTpDelay(int delay) {
// @Override
// public void save(File file) {
// if (this.isDirty()) {
// CompoundTag compoundTag = new CompoundTag();
// compoundTag.put("data", this.toTag(new CompoundTag()));
// NbtCompound compoundTag = new NbtCompound();
// compoundTag.put("data", this.toTag(new NbtCompound()));
// compoundTag.putInt("DataVersion", SharedConstants.getGameVersion().getWorldVersion());

// try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class PlayerDataFactory {
private static ManagerLocator _managers;
public static void init(ManagerLocator managers) { _managers = managers; }
public static PlayerData create(ServerPlayerEntity player) {
return new PlayerData(player.getUuidAsString(), player, _managers);
return new PlayerData(player, _managers);
}
}
28 changes: 14 additions & 14 deletions src/main/java/com/fibermc/essentialcommands/PlayerDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.fibermc.essentialcommands.events.PlayerRespawnCallback;
import com.fibermc.essentialcommands.types.MinecraftLocation;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtIo;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -138,13 +138,13 @@ PlayerData loadPlayerData(ServerPlayerEntity player) throws IOException {
// PushbackInputStream pushbackInputStream = new PushbackInputStream(new FileInputStream(playerDataFile), 2);
// DataInputStream dataInputStream = new DataInputStream(pushbackInputStream);

// CompoundTag compoundTag3 = new CompoundTag();
// NbtCompound NbtCompound3 = new NbtCompound();
// Throwable var8 = null;
// if (this.inputIsCompressed(pushbackInputStream)) {
// compoundTag3 = NbtIo.readCompressed(pushbackInputStream);
// NbtCompound3 = NbtIo.readCompressed(pushbackInputStream);
// } else {
// try {
// compoundTag3 = NbtIo.read(dataInputStream);
// NbtCompound3 = NbtIo.read(dataInputStream);
// } catch (Throwable var31) {
// var8 = var31;
// throw var31;
Expand All @@ -163,35 +163,35 @@ PlayerData loadPlayerData(ServerPlayerEntity player) throws IOException {
//
// }
// }
CompoundTag compoundTag3 = NbtIo.readCompressed(new FileInputStream(playerDataFile));
NbtCompound NbtCompound3 = NbtIo.readCompressed(new FileInputStream(playerDataFile));

//EssentialCommands.log(Level.INFO, "TagData:\n-=-=-=-=-=-\n"+compoundTag3.asString()+"\n-=-=-=-=-=-=-=-");
pData.fromTag(compoundTag3);
//EssentialCommands.log(Level.INFO, "TagData:\n-=-=-=-=-=-\n"+NbtCompound3.asString()+"\n-=-=-=-=-=-=-=-");
pData.fromTag(NbtCompound3);
//Testing:
pData.markDirty();
addPlayerData(pData);
return pData;
}

// @Nullable
// public CompoundTag loadPlayerDataMojang(PlayerEntity playerEntity) {
// CompoundTag compoundTag = null;
// public NbtCompound loadPlayerDataMojang(PlayerEntity playerEntity) {
// NbtCompound NbtCompound = null;
//
// try {
// File file = new File(this.playerDataDir, playerEntity.getUuidAsString() + ".dat");
// if (file.exists() && file.isFile()) {
// compoundTag = NbtIo.readCompressed(new FileInputStream(file));
// NbtCompound = NbtIo.readCompressed(new FileInputStream(file));
// }
// } catch (Exception var4) {
// LOGGER.warn("Failed to load essential_commands player data for {}", playerEntity.getName().getString());
// }
//
// if (compoundTag != null) {
// int i = compoundTag.contains("DataVersion", 3) ? compoundTag.getInt("DataVersion") : -1;
// playerEntity.fromTag(NbtHelper.update(this.dataFixer, DataFixTypes.PLAYER, compoundTag, i));
// if (NbtCompound != null) {
// int i = NbtCompound.contains("DataVersion", 3) ? NbtCompound.getInt("DataVersion") : -1;
// playerEntity.fromTag(NbtHelper.update(this.dataFixer, DataFixTypes.PLAYER, NbtCompound, i));
// }
//
// return compoundTag;
// return NbtCompound;
// }

private boolean inputIsCompressed(PushbackInputStream pushbackInputStream) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity {

public ServerPlayerEntityMixin(World world, BlockPos blockPos, GameProfile profile) {
super(world, blockPos, profile);
public ServerPlayerEntityMixin(World world, BlockPos blockPos, float yaw, GameProfile profile) {
super(world, blockPos, yaw, profile);
}

@Inject(method = "onDeath", at = @At("HEAD"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fibermc.essentialcommands.types;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
Expand Down Expand Up @@ -39,20 +39,20 @@ public MinecraftLocation(ServerPlayerEntity player) {
this.y = player.getY();
this.z = player.getZ();
this.headYaw = player.headYaw;
this.pitch = player.pitch;
this.pitch = player.getPitch();
}

public MinecraftLocation(CompoundTag tag) {
public MinecraftLocation(NbtCompound tag) {
//TODO make this actually work per dimension
this.dim = RegistryKey.of(Registry.DIMENSION, Identifier.tryParse(tag.getString("WorldRegistryKey")));//World.OVERWORLD;//(RegistryKey<World>) Registry.get(Registry.DIMENSION).get(Identifier.tryParse(tag.getString("WorldRegistryKey"));
this.dim = RegistryKey.of(Registry.WORLD_KEY, Identifier.tryParse(tag.getString("WorldRegistryKey")));//World.OVERWORLD;//(RegistryKey<World>) Registry.get(Registry.DIMENSION).get(Identifier.tryParse(tag.getString("WorldRegistryKey"));
this.x = tag.getDouble("x");
this.y = tag.getDouble("y");
this.z = tag.getDouble("z");
this.headYaw = tag.getFloat("headYaw");
this.pitch = tag.getFloat("pitch");
}

public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
tag.putString("WorldRegistryKey", dim.getValue().toString());
tag.putDouble("x", x);
tag.putDouble("y", y);
Expand Down

0 comments on commit 9846358

Please sign in to comment.