forked from SteamWar/SteamWar
Merge pull request 'Update to support Minecraft 1.21.6 version' (#52) from update/1.21.5 into main
Reviewed-on: SteamWar/SteamWar#52
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,11 +85,12 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
|
||||
@Override
|
||||
public BountifulWrapper.PositionSetter getRelMoveSetter(Class<?> packetClass) {
|
||||
Class<?> type = Core.getVersion() > 12 ? short.class : int.class;
|
||||
Reflection.Field<?> moveX = Reflection.getField(packetClass, "b", type);
|
||||
Reflection.Field<?> moveY = Reflection.getField(packetClass, "c", type);
|
||||
Reflection.Field<?> moveZ = Reflection.getField(packetClass, "d", type);
|
||||
Reflection.Field<Byte> moveYaw = Reflection.getField(packetClass, "e", byte.class);
|
||||
Reflection.Field<Byte> movePitch = Reflection.getField(packetClass, "f", byte.class);
|
||||
int fieldOffset = Core.getVersion() > 12 ? 0 : 1;
|
||||
Reflection.Field<?> moveX = Reflection.getField(packetClass, type, 0 + fieldOffset);
|
||||
Reflection.Field<?> moveY = Reflection.getField(packetClass, type, 1 + fieldOffset);
|
||||
Reflection.Field<?> moveZ = Reflection.getField(packetClass, type, 2 + fieldOffset);
|
||||
Reflection.Field<Byte> moveYaw = Reflection.getField(packetClass, byte.class, 0);
|
||||
Reflection.Field<Byte> movePitch = Reflection.getField(packetClass, byte.class, 1);
|
||||
|
||||
return (packet, x, y, z, pitch, yaw) -> {
|
||||
moveX.set(packet, (short)(x*4096));
|
||||
|
||||
@@ -94,6 +94,7 @@ public final class Reflection {
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundContainerClickPacket", "net.minecraft.network.protocol.game.PacketPlayInWindowClick");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket", "net.minecraft.network.protocol.game.PacketPlayInUseEntity");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$b");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInLook");
|
||||
|
||||
@@ -50,11 +50,12 @@ public class REntityServer implements Listener {
|
||||
private static final Class<?> useEntity = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket");
|
||||
private static final Reflection.Field<Integer> useEntityTarget = Reflection.getField(useEntity, int.class, 0);
|
||||
private static final Class<?> useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action");
|
||||
private static final Class<?> useEntityEnumActionType = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType");
|
||||
private static final Reflection.Field<?> useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0);
|
||||
private static final Function<Object, Integer> getEntityAction;
|
||||
static {
|
||||
if(Core.getVersion() > 15) {
|
||||
Reflection.Method useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a");
|
||||
Reflection.Method useEntityGetAction = Reflection.getTypedMethod(useEntityEnumAction, null, useEntityEnumActionType);
|
||||
getEntityAction = value -> ((Enum<?>) useEntityGetAction.invoke(value)).ordinal();
|
||||
} else {
|
||||
getEntityAction = value -> ((Enum<?>) value).ordinal();
|
||||
|
||||
Reference in New Issue
Block a user