forked from SteamWar/SteamWar
Refactor to align with Minecraft 1.21.5 API changes
This commit is contained in:
@@ -21,41 +21,39 @@ package de.steamwar.bausystem.utils;
|
|||||||
|
|
||||||
import de.steamwar.Reflection;
|
import de.steamwar.Reflection;
|
||||||
import de.steamwar.bausystem.features.util.NoClipCommand;
|
import de.steamwar.bausystem.features.util.NoClipCommand;
|
||||||
import net.minecraft.core.component.DataComponents;
|
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||||
import net.minecraft.nbt.NBTBase;
|
import io.papermc.paper.datacomponent.item.ItemContainerContents;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot;
|
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutExplosion;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange;
|
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
import net.minecraft.world.entity.player.Abilities;
|
||||||
import net.minecraft.server.level.PlayerInteractManager;
|
import net.minecraft.world.level.GameType;
|
||||||
import net.minecraft.world.entity.player.EntityHuman;
|
|
||||||
import net.minecraft.world.entity.player.PlayerAbilities;
|
|
||||||
import net.minecraft.world.item.component.CustomData;
|
|
||||||
import net.minecraft.world.level.EnumGamemode;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class NMSWrapper21 implements NMSWrapper {
|
public class NMSWrapper21 implements NMSWrapper {
|
||||||
|
|
||||||
private static final Reflection.Field<PlayerInteractManager> playerInteractManager = Reflection.getField(EntityPlayer.class, null, PlayerInteractManager.class);
|
private static final Reflection.Field<ServerPlayerGameMode> playerInteractManager = Reflection.getField(ServerPlayer.class, null, ServerPlayerGameMode.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInternalGameMode(Player player, GameMode gameMode) {
|
public void setInternalGameMode(Player player, GameMode gameMode) {
|
||||||
playerInteractManager.get(((CraftPlayer) player).getHandle()).a(EnumGamemode.a(gameMode.getValue()));
|
playerInteractManager.get(((CraftPlayer) player).getHandle()).changeGameModeForPlayer(GameType.byId(gameMode.getValue()), PlayerGameModeChangeEvent.Cause.UNKNOWN, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSlotToItemStack(Player player, Object o) {
|
public void setSlotToItemStack(Player player, Object o) {
|
||||||
PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o;
|
ClientboundContainerSetSlotPacket packetPlayInSetCreativeSlot = (ClientboundContainerSetSlotPacket) o;
|
||||||
int index = packetPlayInSetCreativeSlot.b();
|
int index = packetPlayInSetCreativeSlot.getSlot();
|
||||||
if (index >= 36 && index <= 44) {
|
if (index >= 36 && index <= 44) {
|
||||||
index -= 36;
|
index -= 36;
|
||||||
} else if (index > 44) {
|
} else if (index > 44) {
|
||||||
@@ -63,25 +61,23 @@ public class NMSWrapper21 implements NMSWrapper {
|
|||||||
} else if (index <= 8) {
|
} else if (index <= 8) {
|
||||||
index = index - 8 + 36;
|
index = index - 8 + 36;
|
||||||
}
|
}
|
||||||
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.e()));
|
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.getItem()));
|
||||||
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Reflection.Field<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
|
private static final Reflection.Field<ClientboundGameEventPacket.Type> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, ClientboundGameEventPacket.Type.class, 12);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGameStateChangeReason(Object packet) {
|
public void setGameStateChangeReason(Object packet) {
|
||||||
gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d);
|
gameStateChangeReason.set(packet, ClientboundGameEventPacket.CHANGE_GAME_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Reflection.Field<PlayerAbilities> playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPlayerBuildAbilities(Player player) {
|
public void setPlayerBuildAbilities(Player player) {
|
||||||
PlayerAbilities abilities = playerAbilities.get(((CraftPlayer) player).getHandle());
|
Abilities abilities = (((CraftPlayer) player).getHandle()).getAbilities();
|
||||||
abilities.d = true;
|
abilities.mayBuild = true;
|
||||||
abilities.e = true;
|
abilities.mayfly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,49 +89,45 @@ public class NMSWrapper21 implements NMSWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkItemStack(ItemStack item) {
|
public boolean checkItemStack(ItemStack item) {
|
||||||
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
ItemContainerContents data = item.getData(DataComponentTypes.CONTAINER);
|
||||||
NBTTagCompound tag = nmsItem.a(DataComponents.b, CustomData.a).c();
|
if (data == null) {
|
||||||
if (tag.e("BlockEntityTag")) {
|
return false;
|
||||||
NBTTagCompound blockTag = tag.p("BlockEntityTag");
|
|
||||||
if (blockTag.e("Items")) {
|
|
||||||
return drillDown(blockTag.c("Items", 10), 0, 0) > threshold;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return drillDown(data.contents(), 0, 0) <= threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int drillDown(NBTTagList items, int layer, int start) {
|
private int drillDown(List<ItemStack> items, int layer, int start) {
|
||||||
if (layer > 2) return start + threshold;
|
if (layer > 2) return start + threshold;
|
||||||
int invalid = start;
|
int invalid = start;
|
||||||
for (NBTBase nbtBase : items) {
|
for (int i = start; i < items.size(); i++) {
|
||||||
if (!(nbtBase instanceof NBTTagCompound slot))
|
ItemStack item = items.get(i);
|
||||||
|
if (item.isEmpty()) continue;
|
||||||
|
|
||||||
|
invalid += item.getAmount();
|
||||||
|
|
||||||
|
ItemContainerContents data = item.getData(DataComponentTypes.CONTAINER);
|
||||||
|
if (data == null) {
|
||||||
continue;
|
continue;
|
||||||
if (slot.e("tag")) {
|
|
||||||
invalid += slot.f("Count");
|
|
||||||
NBTTagCompound iTag = slot.p("tag");
|
|
||||||
if (iTag.e("BlockEntityTag")) {
|
|
||||||
NBTTagCompound blockTag = iTag.p("BlockEntityTag");
|
|
||||||
if (blockTag.e("Items")) {
|
|
||||||
invalid = drillDown(blockTag.c("Items", 10), layer + 1, invalid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (invalid > threshold)
|
|
||||||
break;
|
List<ItemStack> subItems = data.contents();
|
||||||
|
if (subItems.size() > 1) {
|
||||||
|
invalid = drillDown(subItems, layer + 1, invalid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return invalid;
|
return invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resetExplosionKnockback(Object packet) {
|
public Object resetExplosionKnockback(Object packet) {
|
||||||
PacketPlayOutExplosion explosion = (PacketPlayOutExplosion) packet;
|
ClientboundExplodePacket explosion = (ClientboundExplodePacket) packet;
|
||||||
|
|
||||||
return new PacketPlayOutExplosion(
|
return new ClientboundExplodePacket(
|
||||||
explosion.b(),
|
explosion.center(),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
explosion.f(),
|
explosion.explosionParticle(),
|
||||||
explosion.g()
|
explosion.explosionSound()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -25,6 +25,6 @@ public class CraftbukkitWrapper21 extends CraftbukkitWrapper18 {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float headRotation(Entity e) {
|
public float headRotation(Entity e) {
|
||||||
return getEntity(e).bS();
|
return getEntity(e).getYHeadRot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ package de.steamwar.core;
|
|||||||
|
|
||||||
import de.steamwar.Reflection;
|
import de.steamwar.Reflection;
|
||||||
import net.minecraft.world.entity.PositionMoveRotation;
|
import net.minecraft.world.entity.PositionMoveRotation;
|
||||||
import net.minecraft.world.phys.Vec3D;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
public class BountifulWrapper21 extends BountifulWrapper9 {
|
public class BountifulWrapper21 extends BountifulWrapper9 {
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public class BountifulWrapper21 extends BountifulWrapper9 {
|
|||||||
return (packet, x, y, z, pitch, yaw) -> {
|
return (packet, x, y, z, pitch, yaw) -> {
|
||||||
PositionMoveRotation pos = field.get(packet);
|
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) {
|
} catch (IllegalArgumentException e) {
|
||||||
return super.getPositionSetter(packetClass, fieldOffset);
|
return super.getPositionSetter(packetClass, fieldOffset);
|
||||||
|
|||||||
@@ -19,26 +19,26 @@
|
|||||||
|
|
||||||
package de.steamwar.core;
|
package de.steamwar.core;
|
||||||
|
|
||||||
import net.minecraft.network.chat.IChatMutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.network.chat.contents.LiteralContents;
|
import net.minecraft.network.chat.contents.PlainTextContents;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
|
||||||
import net.minecraft.network.syncher.DataWatcher;
|
import net.minecraft.network.syncher.SynchedEntityData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ChatWrapper21 implements ChatWrapper {
|
public class ChatWrapper21 implements ChatWrapper {
|
||||||
@Override
|
@Override
|
||||||
public Object stringToChatComponent(String text) {
|
public Object stringToChatComponent(String text) {
|
||||||
return IChatMutableComponent.a(LiteralContents.a(text));
|
return MutableComponent.create(PlainTextContents.create(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) {
|
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) {
|
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 de.steamwar.Reflection;
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
import net.minecraft.world.level.World;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import net.minecraft.world.level.chunk.Chunk;
|
|
||||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
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;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class CraftbukkitWrapper21 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
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 getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle", ChunkStatus.class);
|
||||||
private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendChunk(Player p, int chunkX, int chunkZ) {
|
public void sendChunk(Player p, int chunkX, int chunkZ) {
|
||||||
Chunk chunk = (Chunk) getHandle.invoke(p.getWorld().getChunkAt(chunkX, chunkZ), ChunkStatus.n);
|
LevelChunk chunk = (LevelChunk) ((CraftChunk) p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(ChunkStatus.FULL);
|
||||||
TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, (LevelLightEngine) getLightEngine.invoke(chunk.r), null, null, true));
|
TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, chunk.level.getLightEngine(), null, null, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -111,7 +111,7 @@ dependencyResolutionManagement {
|
|||||||
library("spigotapi", "org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT")
|
library("spigotapi", "org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT")
|
||||||
library("spigotannotations", "org.spigotmc:plugin-annotations:1.2.3-SNAPSHOT")
|
library("spigotannotations", "org.spigotmc:plugin-annotations:1.2.3-SNAPSHOT")
|
||||||
library("paperapi", "io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
|
library("paperapi", "io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
|
||||||
library("paperapi21", "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
library("paperapi21", "io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||||
library("authlib", "com.mojang:authlib:1.5.25")
|
library("authlib", "com.mojang:authlib:1.5.25")
|
||||||
library("datafixer", "com.mojang:datafixerupper:4.0.26")
|
library("datafixer", "com.mojang:datafixerupper:4.0.26")
|
||||||
library("brigadier", "com.mojang:brigadier:1.0.18")
|
library("brigadier", "com.mojang:brigadier:1.0.18")
|
||||||
@@ -126,7 +126,7 @@ dependencyResolutionManagement {
|
|||||||
library("nms18", "de.steamwar:spigot:1.18")
|
library("nms18", "de.steamwar:spigot:1.18")
|
||||||
library("nms19", "de.steamwar:spigot:1.19")
|
library("nms19", "de.steamwar:spigot:1.19")
|
||||||
library("nms20", "de.steamwar:spigot:1.20")
|
library("nms20", "de.steamwar:spigot:1.20")
|
||||||
library("nms21", "de.steamwar:spigot:1.21")
|
library("nms21", "de.steamwar:spigot:1.21.5")
|
||||||
|
|
||||||
library("axiom", "de.steamwar:axiompaper:RELEASE")
|
library("axiom", "de.steamwar:axiompaper:RELEASE")
|
||||||
library("worldedit12", "de.steamwar:worldedit:1.12")
|
library("worldedit12", "de.steamwar:worldedit:1.12")
|
||||||
|
|||||||
Reference in New Issue
Block a user