Refactor to align with Minecraft 1.21.5 API changes

This commit is contained in:
2025-04-24 13:10:48 +02:00
parent a38f9222dd
commit bb97d80c18
6 changed files with 63 additions and 73 deletions
@@ -21,7 +21,7 @@ package de.steamwar.core;
import de.steamwar.Reflection;
import net.minecraft.world.entity.PositionMoveRotation;
import net.minecraft.world.phys.Vec3D;
import net.minecraft.world.phys.Vec3;
public class BountifulWrapper21 extends BountifulWrapper9 {
@@ -33,7 +33,7 @@ public class BountifulWrapper21 extends BountifulWrapper9 {
return (packet, x, y, z, pitch, yaw) -> {
PositionMoveRotation pos = field.get(packet);
field.set(packet, new PositionMoveRotation(new Vec3D(x, y, z), pos.b(), yaw, pitch));
field.set(packet, new PositionMoveRotation(new Vec3(x, y, z), pos.deltaMovement(), yaw, pitch));
};
} catch (IllegalArgumentException e) {
return super.getPositionSetter(packetClass, fieldOffset);
@@ -19,26 +19,26 @@
package de.steamwar.core;
import net.minecraft.network.chat.IChatMutableComponent;
import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
import net.minecraft.network.syncher.DataWatcher;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.syncher.SynchedEntityData;
import java.util.ArrayList;
public class ChatWrapper21 implements ChatWrapper {
@Override
public Object stringToChatComponent(String text) {
return IChatMutableComponent.a(LiteralContents.a(text));
return MutableComponent.create(PlainTextContents.create(text));
}
@Override
public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) {
ArrayList<DataWatcher.c<?>> nativeWatchers = new ArrayList<>(1);
ArrayList<SynchedEntityData.DataValue<?>> nativeWatchers = new ArrayList<>(1);
for(int i = 0; i < dataWatcherKeyValues.length; i+=2) {
nativeWatchers.add(((DataWatcher.Item<?>) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1])).e());
nativeWatchers.add(((SynchedEntityData.DataItem<?>) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1])).value());
}
return new PacketPlayOutEntityMetadata(entityId, nativeWatchers);
return new ClientboundSetEntityDataPacket(entityId, nativeWatchers);
}
}
@@ -22,20 +22,18 @@ package de.steamwar.core;
import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.world.level.World;
import net.minecraft.world.level.chunk.Chunk;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.lighting.LevelLightEngine;
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.entity.Player;
public class CraftbukkitWrapper21 implements CraftbukkitWrapper.ICraftbukkitWrapper {
private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle", ChunkStatus.class);
private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class);
@Override
public void sendChunk(Player p, int chunkX, int chunkZ) {
Chunk chunk = (Chunk) getHandle.invoke(p.getWorld().getChunkAt(chunkX, chunkZ), ChunkStatus.n);
TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, (LevelLightEngine) getLightEngine.invoke(chunk.r), null, null, true));
LevelChunk chunk = (LevelChunk) ((CraftChunk) p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(ChunkStatus.FULL);
TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, chunk.level.getLightEngine(), null, null, true));
}
}