Skip to content

Commit

Permalink
1.19 step 3: bare minimum changes to make it compile, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 7, 2022
1 parent bb3f608 commit f10d970
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 144 deletions.
Expand Up @@ -301,7 +301,7 @@ public int getExpDrop(Block block, org.bukkit.inventory.ItemStack item) {
return 0;
}
return blockType.getExpDrop(((CraftBlock) block).getNMS(), ((CraftBlock) block).getCraftWorld().getHandle(), ((CraftBlock) block).getPosition(),
item == null ? null : CraftItemStack.asNMSCopy(item));
item == null ? null : CraftItemStack.asNMSCopy(item), true);
}

@Override
Expand Down
Expand Up @@ -103,7 +103,7 @@ public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
LevelHeightAccessor levelheightaccessor = nmsChunk.getHeightAccessorForGeneration();
for(int k = levelheightaccessor.getMinSection(); k < levelheightaccessor.getMaxSection(); ++k) {
LevelChunkSection chunksection = nmsChunk.getSection(nmsChunk.getSectionIndexFromSectionY(k));
PalettedContainer<Holder<Biome>> datapaletteblock = chunksection.getBiomes();
PalettedContainer<Holder<Biome>> datapaletteblock = (PalettedContainer<Holder<Biome>>) chunksection.getBiomes();
datapaletteblock.acquire();
for(int l = 0; l < 4; ++l) {
for(int i1 = 0; i1 < 4; ++i1) {
Expand Down
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.stats.RecipeBook;
import net.minecraft.stats.ServerRecipeBook;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.CombatRules;
import net.minecraft.world.damagesource.DamageSource;
Expand Down Expand Up @@ -643,11 +644,15 @@ public boolean internalLook(Player player, Location at) {
return true;
}

public static long entityToPacket(double x) {
return Mth.lfloor(x * 4096.0D);
}

@Override
public void fakeMove(Entity entity, Vector vector) {
long x = ClientboundMoveEntityPacket.entityToPacket(vector.getX());
long y = ClientboundMoveEntityPacket.entityToPacket(vector.getY());
long z = ClientboundMoveEntityPacket.entityToPacket(vector.getZ());
long x = entityToPacket(vector.getX());
long y = entityToPacket(vector.getY());
long z = entityToPacket(vector.getZ());
ClientboundMoveEntityPacket packet = new ClientboundMoveEntityPacket.Pos(entity.getEntityId(), (short) x, (short) y, (short) z, entity.isOnGround());
for (Player player : getPlayersThatSee(entity)) {
PacketHelperImpl.send(player, packet);
Expand Down
Expand Up @@ -183,7 +183,7 @@ else if (entityType == EntityType.ENDERMAN) {

// Spectating an entity then immediately respawning the player prevents a client shader update,
// allowing the player to retain whatever vision the mob they spectated had.
send(player, new ClientboundAddMobPacket(entity));
send(player, new ClientboundAddEntityPacket(entity));
send(player, new ClientboundSetCameraPacket(entity));
((CraftServer) Bukkit.getServer()).getHandle().respawn(((CraftPlayer) player).getHandle(),
((CraftWorld) player.getWorld()).getHandle(), true, player.getLocation(), false);
Expand Down
Expand Up @@ -412,15 +412,15 @@ public void sendPlayerInfoAddPacket(Player player, ProfileEditMode mode, String
if (texture != null) {
profile.getProperties().put("textures", new Property("textures", texture, signature));
}
packet.getEntries().add(new ClientboundPlayerInfoPacket.PlayerUpdate(profile, latency, GameType.byName(CoreUtilities.toLowerCase(gameMode.name())), display == null ? null : Handler.componentToNMS(FormattedTextHelper.parse(display, ChatColor.WHITE))));
packet.getEntries().add(new ClientboundPlayerInfoPacket.PlayerUpdate(profile, latency, GameType.byName(CoreUtilities.toLowerCase(gameMode.name())), display == null ? null : Handler.componentToNMS(FormattedTextHelper.parse(display, ChatColor.WHITE)), null));
PacketHelperImpl.send(player, packet);
}

@Override
public void sendPlayerRemovePacket(Player player, UUID id) {
ClientboundPlayerInfoPacket packet = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER);
GameProfile profile = new GameProfile(id, "name");
packet.getEntries().add(new ClientboundPlayerInfoPacket.PlayerUpdate(profile, 0, null, null));
packet.getEntries().add(new ClientboundPlayerInfoPacket.PlayerUpdate(profile, 0, null, null, null));
PacketHelperImpl.send(player, packet);
}
}
Expand Up @@ -38,7 +38,7 @@ public float getLocalDifficulty(Location location) {
@Override
public Location getNearestBiomeLocation(Location start, BiomeTag biome) {
Pair<BlockPos, Holder<Biome>> result = ((CraftWorld) start.getWorld()).getHandle()
.findNearestBiome(b -> b.is(((BiomeNMSImpl) biome.getBiome()).biomeBase.unwrapKey().get()), new BlockPos(start.getBlockX(), start.getBlockY(), start.getBlockZ()), 6400, 8);
.findClosestBiome3d(b -> b.is(((BiomeNMSImpl) biome.getBiome()).biomeBase.unwrapKey().get()), new BlockPos(start.getBlockX(), start.getBlockY(), start.getBlockZ()), 6400, 32, 64);
if (result == null || result.getFirst() == null) {
return null;
}
Expand Down
Expand Up @@ -105,7 +105,7 @@ public static boolean handleAlteredProfiles(ClientboundPlayerInfoPacket packet,
}
String listRename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), true);
Component displayName = listRename != null ? Handler.componentToNMS(FormattedTextHelper.parse(listRename, ChatColor.WHITE)) : data.getDisplayName();
ClientboundPlayerInfoPacket.PlayerUpdate newData = new ClientboundPlayerInfoPacket.PlayerUpdate(patchedProfile, data.getLatency(), data.getGameMode(), displayName);
ClientboundPlayerInfoPacket.PlayerUpdate newData = new ClientboundPlayerInfoPacket.PlayerUpdate(patchedProfile, data.getLatency(), data.getGameMode(), displayName, data.getProfilePublicKey());
newPacketDataList.add(newData);
manager.oldManager.send(newPacket);
}
Expand Down
Expand Up @@ -18,7 +18,7 @@
public class EntityFakePlayerImpl extends ServerPlayer {

public EntityFakePlayerImpl(MinecraftServer minecraftserver, ServerLevel worldserver, GameProfile gameprofile, boolean doAdd) {
super(minecraftserver, worldserver, gameprofile);
super(minecraftserver, worldserver, gameprofile, null);
try {
Handler.ENTITY_BUKKITYENTITY.set(this, new CraftFakePlayerImpl((CraftServer) Bukkit.getServer(), this));
}
Expand Down
Expand Up @@ -274,7 +274,7 @@ else if (packet instanceof ClientboundRemoveEntitiesPacket) {
public void send(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
if (!Bukkit.isPrimaryThread()) {
if (Settings.cache_warnOnAsyncPackets
&& !(packet instanceof ClientboundChatPacket) // Vanilla supports an async chat system, though it's normally disabled, some plugins use this as justification for sending messages async
&& !(packet instanceof ClientboundSystemChatPacket) && !(packet instanceof ClientboundPlayerChatPacket) // Vanilla supports an async chat system, though it's normally disabled, some plugins use this as justification for sending messages async
&& !(packet instanceof ClientboundCommandSuggestionsPacket)) { // Async tab complete is wholly unsupported in Spigot (and will cause an exception), however Paper explicitly adds async support (for unclear reasons), so let it through too
Debug.echoError("Warning: packet sent off main thread! This is completely unsupported behavior! Denizen network interceptor ignoring packet to avoid crash. Packet class: "
+ packet.getClass().getCanonicalName() + " sent to " + player.getScoreboardName() + " identify the sender of the packet from the stack trace:");
Expand Down Expand Up @@ -373,7 +373,7 @@ public boolean processTablistPacket(Packet<?> packet, GenericFutureListener<? ex
newProfile.getProperties().put("textures", new Property("textures", data.texture, data.signature));
}
newPacket.getEntries().add(new ClientboundPlayerInfoPacket.PlayerUpdate(newProfile, data.latency, GameType.byName(CoreUtilities.toLowerCase(data.gamemode)),
data.display == null ? null : Handler.componentToNMS(FormattedTextHelper.parse(data.display, ChatColor.WHITE))));
data.display == null ? null : Handler.componentToNMS(FormattedTextHelper.parse(data.display, ChatColor.WHITE)), update.getProfilePublicKey()));
oldManager.send(newPacket, genericfuturelistener);
}
}
Expand Down Expand Up @@ -636,9 +636,6 @@ public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<
else if (packet instanceof ClientboundAddEntityPacket) {
ider = ((ClientboundAddEntityPacket) packet).getId();
}
else if (packet instanceof ClientboundAddMobPacket) {
ider = ((ClientboundAddMobPacket) packet).getId();
}
if (ider != -1) {
Entity e = player.getLevel().getEntity(ider);
if (e == null) {
Expand Down Expand Up @@ -1033,12 +1030,6 @@ public boolean processHiddenEntitiesForPacket(Packet<?> packet) {
else if (packet instanceof ClientboundAddEntityPacket) {
ider = ((ClientboundAddEntityPacket) packet).getId();
}
else if (packet instanceof ClientboundAddMobPacket) {
ider = ((ClientboundAddMobPacket) packet).getId();
}
else if (packet instanceof ClientboundAddPaintingPacket) {
ider = ((ClientboundAddPaintingPacket) packet).getId();
}
else if (packet instanceof ClientboundAddExperienceOrbPacket) {
ider = ((ClientboundAddExperienceOrbPacket) packet).getId();
}
Expand Down Expand Up @@ -1100,10 +1091,12 @@ public boolean processMirrorForPacket(Packet<?> packet) {
}

public boolean processPacketHandlerForPacket(Packet<?> packet) {
// TODO: 1.19: New chat system, probably needs event changes?
/*
if (packet instanceof ClientboundChatPacket && DenizenPacketHandler.instance.shouldInterceptChatPacket()) {
return DenizenPacketHandler.instance.sendPacket(player.getBukkitEntity(), new PacketOutChatImpl((ClientboundChatPacket) packet));
}
else if (packet instanceof ClientboundSetEntityDataPacket && DenizenPacketHandler.instance.shouldInterceptMetadata()) {
else */if (packet instanceof ClientboundSetEntityDataPacket && DenizenPacketHandler.instance.shouldInterceptMetadata()) {
return DenizenPacketHandler.instance.sendPacket(player.getBukkitEntity(), new PacketOutEntityMetadataImpl((ClientboundSetEntityDataPacket) packet));
}
return false;
Expand Down Expand Up @@ -1172,16 +1165,18 @@ else if (packet instanceof ClientboundBlockUpdatePacket) {
return true;
}
}
else if (packet instanceof ClientboundBlockBreakAckPacket) {
ClientboundBlockBreakAckPacket origPack = (ClientboundBlockBreakAckPacket) packet;
else if (packet instanceof ClientboundBlockChangedAckPacket) {
// TODO: 1.19: Can no longer determine what block this packet is for. Would have to track separately? Possibly from the inbound packet rather than the outbound one.
/*
ClientboundBlockChangedAckPacket origPack = (ClientboundBlockChangedAckPacket) packet;
BlockPos pos = origPack.pos();
LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
if (block != null) {
ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(origPack.pos(), FakeBlockHelper.getNMSState(block), origPack.action(), false);
ClientboundBlockChangedAckPacket newPacket = new ClientboundBlockChangedAckPacket(origPack.pos(), FakeBlockHelper.getNMSState(block), origPack.action(), false);
oldManager.send(newPacket, genericfuturelistener);
return true;
}
}*/
}
}
catch (Throwable ex) {
Expand Down

This file was deleted.

0 comments on commit f10d970

Please sign in to comment.