Skip to content

Commit

Permalink
1.20.3 part 3: Initial fixes to be compilable
Browse files Browse the repository at this point in the history
  • Loading branch information
tal5 committed Dec 5, 2023
1 parent 42e0b28 commit d2ed17c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 40 deletions.
Expand Up @@ -9,7 +9,7 @@ public class ReflectionMappingsInfo {
public static String AdvancementList_tasks = "(MISSING)"; // TODO: 1.20.2

// net.minecraft.world.level.block.state.BlockBehaviour
public static String BlockBehaviour_explosionResistance = "aF";
public static String BlockBehaviour_explosionResistance = "aH";

// net.minecraft.core.MappedRegistry
public static String MappedRegistry_frozen = "l";
Expand All @@ -30,11 +30,11 @@ public class ReflectionMappingsInfo {
public static String LivingEntity_setLivingEntityFlag_method = "c";

// net.minecraft.world.entity.player.Player
public static String Player_DATA_PLAYER_ABSORPTION_ID = "e";
public static String Player_DATA_PLAYER_ABSORPTION_ID = "d";
public static String Player_DATA_PLAYER_MODE_CUSTOMISATION = "bM";

// net.minecraft.server.level.ServerPlayer
public static String ServerPlayer_respawnForced = "cU";
public static String ServerPlayer_respawnForced = "cW";

// net.minecraft.world.entity.monster.EnderMan
public static String EnderMan_DATA_CREEPY = "bV";
Expand Down Expand Up @@ -78,7 +78,6 @@ public class ReflectionMappingsInfo {
public static String ServerGamePacketListenerImpl_awaitingTeleport = "C";
public static String ServerGamePacketListenerImpl_chunkSender = "f";


// net.minecraft.server.network.ServerCommonPacketListenerImpl
public static String ServerCommonPacketListenerImpl_connection = "c";

Expand Down Expand Up @@ -143,5 +142,4 @@ public class ReflectionMappingsInfo {

// net.minecraft.server.level.ServerLevel
public static String ServerLevel_sleepStatus = "O";

}
Expand Up @@ -7,16 +7,15 @@
import net.minecraft.advancements.*;
import net.minecraft.advancements.critereon.ImpossibleTrigger;
import net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.ServerAdvancementManager;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey;
import org.bukkit.entity.Player;

import java.util.*;
Expand All @@ -25,7 +24,7 @@ public class AdvancementHelperImpl extends AdvancementHelper {

private static final String IMPOSSIBLE_KEY = "impossible";
private static final Map<String, Criterion<?>> IMPOSSIBLE_CRITERIA = Collections.singletonMap(IMPOSSIBLE_KEY, new Criterion(new ImpossibleTrigger(), new ImpossibleTrigger.TriggerInstance()));
private static final String[][] IMPOSSIBLE_REQUIREMENTS = new String[][]{{IMPOSSIBLE_KEY}};
private static final List<List<String>> IMPOSSIBLE_REQUIREMENTS = List.of(List.of(IMPOSSIBLE_KEY));

public static ServerAdvancementManager getAdvancementDataWorld() {
return ((CraftServer) Bukkit.getServer()).getServer().getAdvancements();
Expand Down Expand Up @@ -115,7 +114,7 @@ public void grantPartial(com.denizenscript.denizen.nms.util.Advancement advancem
Collections.singletonMap(nmsAdvancement.id(), progress)));
}
else {
AdvancementHolder nmsAdvancement = getAdvancementDataWorld().advancements.get(asResourceLocation(advancement.key));
AdvancementHolder nmsAdvancement = getAdvancementDataWorld().advancements.get(CraftNamespacedKey.toMinecraft(advancement.key));
for (int i = 0; i < len; i++) {
((CraftPlayer) player).getHandle().getAdvancements().award(nmsAdvancement, IMPOSSIBLE_KEY + i);
}
Expand All @@ -139,7 +138,7 @@ public void grant(com.denizenscript.denizen.nms.util.Advancement advancement, Pl
Collections.singletonMap(nmsAdvancement.id(), progress)));
}
else {
AdvancementHolder nmsAdvancement = getAdvancementDataWorld().advancements.get(asResourceLocation(advancement.key));
AdvancementHolder nmsAdvancement = getAdvancementDataWorld().advancements.get(CraftNamespacedKey.toMinecraft(advancement.key));
((CraftPlayer) player).getHandle().getAdvancements().award(nmsAdvancement, IMPOSSIBLE_KEY);
}
}
Expand All @@ -149,11 +148,11 @@ public void revoke(com.denizenscript.denizen.nms.util.Advancement advancement, P
if (advancement.temporary) {
PacketHelperImpl.send(player, new ClientboundUpdateAdvancementsPacket(false,
Collections.emptySet(),
Collections.singleton(asResourceLocation(advancement.key)),
Collections.singleton(CraftNamespacedKey.toMinecraft(advancement.key)),
Collections.emptyMap()));
}
else {
AdvancementHolder nmsAdvancement = getAdvancementDataWorld().advancements.get(asResourceLocation(advancement.key));
AdvancementHolder nmsAdvancement = getAdvancementDataWorld().advancements.get(CraftNamespacedKey.toMinecraft(advancement.key));
((CraftPlayer) player).getHandle().getAdvancements().revoke(nmsAdvancement, IMPOSSIBLE_KEY);
}
}
Expand All @@ -172,31 +171,26 @@ public void update(Player player) {
}

private static AdvancementHolder asNMSCopy(com.denizenscript.denizen.nms.util.Advancement advancement) {
ResourceLocation key = asResourceLocation(advancement.key);
AdvancementHolder parent = advancement.parent != null
? getAdvancementDataWorld().advancements.get(asResourceLocation(advancement.parent))
? getAdvancementDataWorld().advancements.get(CraftNamespacedKey.toMinecraft(advancement.parent))
: null;
DisplayInfo display = new DisplayInfo(CraftItemStack.asNMSCopy(advancement.icon),
Handler.componentToNMS(FormattedTextHelper.parse(advancement.title, ChatColor.WHITE)), Handler.componentToNMS(FormattedTextHelper.parse(advancement.description, ChatColor.WHITE)),
asResourceLocation(advancement.background), FrameType.valueOf(advancement.frame.name()),
Optional.ofNullable(advancement.background).map(CraftNamespacedKey::toMinecraft), AdvancementType.valueOf(advancement.frame.name()),
advancement.toast, advancement.announceToChat, advancement.hidden);
display.setLocation(advancement.xOffset, advancement.yOffset);
Map<String, Criterion<?>> criteria = IMPOSSIBLE_CRITERIA;
String[][] requirements = IMPOSSIBLE_REQUIREMENTS;
List<List<String>> requirements = IMPOSSIBLE_REQUIREMENTS;
if (advancement.length > 1) {
criteria = new HashMap<>();
requirements = new String[advancement.length][];
requirements = new ArrayList<>(advancement.length);
for (int i = 0; i < advancement.length; i++) {
criteria.put(IMPOSSIBLE_KEY + i, new Criterion(new ImpossibleTrigger(), new ImpossibleTrigger.TriggerInstance()));
requirements[i] = new String[] { IMPOSSIBLE_KEY + i };
requirements.set(i, List.of(IMPOSSIBLE_KEY + i));
}
}
AdvancementRequirements reqs = new AdvancementRequirements(requirements);
Advancement adv = new Advancement(parent == null ? Optional.empty() : Optional.of(parent.id()), Optional.of(display), AdvancementRewards.EMPTY, criteria, reqs, false); // TODO: 1.20: do we want to ever enable telemetry?
return new AdvancementHolder(key, adv);
}

private static ResourceLocation asResourceLocation(NamespacedKey key) {
return key != null ? new ResourceLocation(key.getNamespace(), key.getKey()) : null;
return new AdvancementHolder(CraftNamespacedKey.toMinecraft(advancement.key), adv);
}
}
@@ -1,13 +1,14 @@
package com.denizenscript.denizen.nms.v1_20.helpers;

import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.nms.interfaces.EnchantmentHelper;
import com.denizenscript.denizen.nms.v1_20.Handler;
import com.denizenscript.denizen.nms.v1_20.ReflectionMappingsInfo;
import com.denizenscript.denizen.scripts.containers.core.EnchantmentScriptContainer;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -32,9 +33,6 @@
import java.util.Map;

public class EnchantmentHelperImpl extends EnchantmentHelper {

public static final Map<NamespacedKey, Enchantment> ENCHANTMENTS_BY_KEY = ReflectionHelper.getFieldValue(org.bukkit.enchantments.Enchantment.class, "byKey", null);
public static final Map<String, org.bukkit.enchantments.Enchantment> ENCHANTMENTS_BY_NAME = ReflectionHelper.getFieldValue(org.bukkit.enchantments.Enchantment.class, "byName", null);
public static final Field REGISTRY_FROZEN = ReflectionHelper.getFields(MappedRegistry.class).get(ReflectionMappingsInfo.MappedRegistry_frozen, boolean.class);
public static final Field REGISTRY_INTRUSIVE_HOLDERS = ReflectionHelper.getFields(MappedRegistry.class).get(ReflectionMappingsInfo.MappedRegistry_unregisteredIntrusiveHolders, Map.class);

Expand Down Expand Up @@ -137,9 +135,10 @@ public boolean isDiscoverable() {
return script.script.isDiscoverable;
}
};
NamespacedKey enchantmentKey = new NamespacedKey(Denizen.getInstance(), script.script.id);
Registry.register(BuiltInRegistries.ENCHANTMENT, enchantmentKey.toString(), nmsEnchant);
String enchName = CoreUtilities.toUpperCase(script.script.id);
Registry.register(BuiltInRegistries.ENCHANTMENT, "denizen:" + script.script.id, nmsEnchant);
CraftEnchantment ench = new CraftEnchantment(nmsEnchant) {
CraftEnchantment ench = new CraftEnchantment(enchantmentKey, nmsEnchant) {
@Override
public String getName() {
return enchName;
Expand All @@ -149,8 +148,6 @@ public String getName() {
if (wasFrozen) {
BuiltInRegistries.ENCHANTMENT.freeze();
}
ENCHANTMENTS_BY_KEY.put(ench.getKey(), ench);
ENCHANTMENTS_BY_NAME.put(enchName, ench);
return ench;
}
catch (Throwable ex) {
Expand Down
Expand Up @@ -56,6 +56,7 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
Expand Down Expand Up @@ -479,7 +480,7 @@ private static HitResult rayTrace(World world, Vector start, Vector end) {
NMSHandler.chunkHelper.changeChunkServerThread(world);
return ((CraftWorld) world).getHandle().clip(new ClipContext(new Vec3(start.getX(), start.getY(), start.getZ()),
new Vec3(end.getX(), end.getY(), end.getZ()),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, null));
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, CollisionContext.empty()));
}
finally {
NMSHandler.chunkHelper.restoreServerThread(world);
Expand Down Expand Up @@ -709,7 +710,7 @@ public void setFallingBlockType(FallingBlock fallingBlock, BlockData block) {
public EntityTag getMobSpawnerDisplayEntity(CreatureSpawner spawner) {
SpawnerBlockEntity nmsSpawner = BlockHelperImpl.getTE((CraftCreatureSpawner) spawner);
ServerLevel level = ((CraftWorld) spawner.getWorld()).getHandle();
net.minecraft.world.entity.Entity nmsEntity = nmsSpawner.getSpawner().getOrCreateDisplayEntity(level, level.random, nmsSpawner.getBlockPos());
net.minecraft.world.entity.Entity nmsEntity = nmsSpawner.getSpawner().getOrCreateDisplayEntity(level, nmsSpawner.getBlockPos());
return new EntityTag(nmsEntity.getBukkitEntity());
}

Expand Down
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizen.nms.v1_20.impl.jnbt.CompoundTagImpl;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtAccounter;
import net.minecraft.nbt.NbtIo;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeMap;
Expand Down Expand Up @@ -124,7 +125,7 @@ protected boolean loadPlayerData(UUID uuid) {
for (org.bukkit.World w : Bukkit.getWorlds()) {
this.file = new File(w.getWorldFolder(), "playerdata" + File.separator + this.player + ".dat");
if (this.file.exists()) {
this.compound = CompoundTagImpl.fromNMSTag(NbtIo.readCompressed(new FileInputStream(this.file)));
this.compound = CompoundTagImpl.fromNMSTag(NbtIo.readCompressed(new FileInputStream(this.file), NbtAccounter.unlimitedHeap()));
return true;
}
}
Expand Down
Expand Up @@ -6,12 +6,13 @@
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.md_5.bungee.api.ChatColor;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.numbers.StyledFormat;
import net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket;
import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket;
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.network.protocol.game.ClientboundSetScorePacket;
import net.minecraft.server.ServerScoreboard;
import net.minecraft.world.scores.DisplaySlot;
import net.minecraft.world.scores.Objective;
import net.minecraft.world.scores.PlayerTeam;
Expand All @@ -25,6 +26,8 @@

public class SidebarImpl extends Sidebar {

// TODO: 1.20.3: the scoreboard system saw significant changes, there is likely a better way to do this now

public static Scoreboard dummyScoreboard = new Scoreboard();
public static ObjectiveCriteria dummyCriteria;

Expand All @@ -45,8 +48,8 @@ public class SidebarImpl extends Sidebar {
public SidebarImpl(Player player) {
super(player);
MutableComponent chatComponentTitle = Handler.componentToNMS(FormattedTextHelper.parse(title, ChatColor.WHITE));
this.obj1 = new Objective(dummyScoreboard, "dummy_1", dummyCriteria, chatComponentTitle, ObjectiveCriteria.RenderType.INTEGER);
this.obj2 = new Objective(dummyScoreboard, "dummy_2", dummyCriteria, chatComponentTitle, ObjectiveCriteria.RenderType.INTEGER);
this.obj1 = new Objective(dummyScoreboard, "dummy_1", dummyCriteria, chatComponentTitle, ObjectiveCriteria.RenderType.INTEGER, false, StyledFormat.SIDEBAR_DEFAULT);
this.obj2 = new Objective(dummyScoreboard, "dummy_2", dummyCriteria, chatComponentTitle, ObjectiveCriteria.RenderType.INTEGER, false, StyledFormat.SIDEBAR_DEFAULT);
}

@Override
Expand Down Expand Up @@ -77,7 +80,7 @@ public void sendUpdate() {
team.setPlayerPrefix(Handler.componentToNMS(FormattedTextHelper.parse(line, ChatColor.WHITE)));
generatedTeams.add(team);
PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true));
PacketHelperImpl.send(player, new ClientboundSetScorePacket(ServerScoreboard.Method.CHANGE, obj1.getName(), lineId, this.scores[i]));
PacketHelperImpl.send(player, new ClientboundSetScorePacket(lineId, obj1.getName(), this.scores[i], Component.empty(), StyledFormat.SIDEBAR_DEFAULT));
}
PacketHelperImpl.send(player, new ClientboundSetDisplayObjectivePacket(DisplaySlot.SIDEBAR, this.obj1));
PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj2, 1));
Expand Down
Expand Up @@ -13,6 +13,6 @@ public PacketInResourcePackStatusImpl(ServerboundResourcePackPacket internal) {

@Override
public String getStatus() {
return internal.getAction().name();
return internal.action().name();
}
}
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.md_5.bungee.chat.ComponentSerializer;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;

Expand All @@ -22,7 +23,7 @@ public class PacketOutChatImpl extends PacketOutChat {

public PacketOutChatImpl(ClientboundSystemChatPacket internal) {
systemPacket = internal;
rawJson = internal.content();
rawJson = Component.Serializer.toJson(internal.content());
if (rawJson == null && convertComponentToJsonString != null) {
try {
if (paperTextField == null) {
Expand Down

0 comments on commit d2ed17c

Please sign in to comment.