forked from SteamWar/SteamWar
Unreflect more stuff
This commit is contained in:
@@ -19,292 +19,13 @@
|
||||
|
||||
package de.steamwar;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public final class Reflection {
|
||||
|
||||
public static final int MAJOR_VERSION;
|
||||
public static final int MINOR_VERSION;
|
||||
|
||||
static {
|
||||
String[] version = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\.");
|
||||
MAJOR_VERSION = Integer.parseInt(version[1]);
|
||||
MINOR_VERSION = version.length > 2 ? Integer.parseInt(version[2]) : 0;
|
||||
}
|
||||
|
||||
private static final String ORG_BUKKIT_CRAFTBUKKIT = Bukkit.getServer().getClass().getPackage().getName();
|
||||
public static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
||||
|
||||
private static final Map<String, String> spigotClassnames = new HashMap<>();
|
||||
|
||||
static {
|
||||
// See https://mappings.dev for complete mappings
|
||||
spigotClassnames.put("net.minecraft.Util", "net.minecraft.SystemUtils");
|
||||
|
||||
spigotClassnames.put("net.minecraft.core.BlockPos", "net.minecraft.core.BlockPosition");
|
||||
spigotClassnames.put("net.minecraft.core.DefaultedRegistry", "net.minecraft.core.RegistryBlocks");
|
||||
spigotClassnames.put("net.minecraft.core.IdMapper", "net.minecraft.core.RegistryBlockID");
|
||||
spigotClassnames.put("net.minecraft.core.Vec3i", "net.minecraft.core.BaseBlockPosition");
|
||||
|
||||
spigotClassnames.put("net.minecraft.nbt.CompoundTag", "net.minecraft.nbt.NBTTagCompound");
|
||||
|
||||
spigotClassnames.put("net.minecraft.network.Connection", "net.minecraft.network.NetworkManager");
|
||||
|
||||
spigotClassnames.put("net.minecraft.network.chat.Component", "net.minecraft.network.chat.IChatBaseComponent");
|
||||
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAddEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket", "net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAnimatePacket", "net.minecraft.network.protocol.game.PacketPlayOutAnimation");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockBreak");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket", "net.minecraft.network.protocol.game.PacketPlayOutTileEntityData");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockAction");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockChange");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundContainerClosePacket", "net.minecraft.network.protocol.game.PacketPlayOutCloseWindow");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundEntityEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityStatus");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundExplodePacket", "net.minecraft.network.protocol.game.PacketPlayOutExplosion");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundGameEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutGameStateChange");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo", "net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutWorldEvent");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket", "net.minecraft.network.protocol.game.PacketPlayOutWorldParticles");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntity");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMove");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutEntityLook");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket", "net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundRotateHeadPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetObjectivePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetScorePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSoundPacket", "net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport");
|
||||
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");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket", "net.minecraft.network.protocol.game.PacketPlayInBlockDig");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket", "net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayInUpdateSign");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundUseItemPacket", "net.minecraft.network.protocol.game.PacketPlayInBlockPlace");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket", "net.minecraft.network.protocol.game.PacketPlayInUseItem");
|
||||
|
||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataAccessor", "net.minecraft.network.syncher.DataWatcherObject");
|
||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataSerializer", "net.minecraft.network.syncher.DataWatcherSerializer");
|
||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataSerializers", "net.minecraft.network.syncher.DataWatcherRegistry");
|
||||
spigotClassnames.put("net.minecraft.network.syncher.SynchedEntityData$DataItem", "net.minecraft.network.syncher.DataWatcher$Item");
|
||||
|
||||
spigotClassnames.put("net.minecraft.server.ServerScoreboard$Method", "net.minecraft.server.ScoreboardServer$Action");
|
||||
|
||||
spigotClassnames.put("net.minecraft.server.level.ChunkMap", "net.minecraft.server.level.PlayerChunkMap");
|
||||
spigotClassnames.put("net.minecraft.server.level.ChunkMap$TrackedEntity", "net.minecraft.server.level.PlayerChunkMap$EntityTracker");
|
||||
spigotClassnames.put("net.minecraft.server.level.ServerChunkCache", "net.minecraft.server.level.ChunkProviderServer");
|
||||
spigotClassnames.put("net.minecraft.server.level.ServerLevel", "net.minecraft.server.level.WorldServer");
|
||||
spigotClassnames.put("net.minecraft.server.level.ServerPlayer", "net.minecraft.server.level.EntityPlayer");
|
||||
|
||||
spigotClassnames.put("net.minecraft.server.network.ServerConnectionListener", "net.minecraft.server.network.ServerConnection");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.InteractionHand", "net.minecraft.world.EnumHand");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.entity.EntityType", "net.minecraft.world.entity.EntityTypes");
|
||||
spigotClassnames.put("net.minecraft.world.entity.Pose", "net.minecraft.world.entity.EntityPose");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.entity.item.PrimedTnt", "net.minecraft.world.entity.item.EntityTNTPrimed");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.entity.projectile.AbstractArrow", "net.minecraft.world.entity.projectile.EntityArrow");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.level.GameType", "net.minecraft.world.level.EnumGamemode");
|
||||
spigotClassnames.put("net.minecraft.world.level.LevelAccessor", "net.minecraft.world.level.GeneratorAccess");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.level.block.state.BlockState", "net.minecraft.world.level.block.state.IBlockData");
|
||||
spigotClassnames.put("net.minecraft.world.level.block.state.StateDefinition", "net.minecraft.world.level.block.state.BlockStateList");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.level.chunk.LevelChunk", "net.minecraft.world.level.chunk.Chunk");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.level.material.FlowingFluid", "net.minecraft.world.level.material.FluidTypeFlowing");
|
||||
spigotClassnames.put("net.minecraft.world.level.material.Fluids", "net.minecraft.world.level.material.FluidTypes");
|
||||
spigotClassnames.put("net.minecraft.world.level.material.FluidState", "net.minecraft.world.level.material.Fluid");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.phys.BlockHitResult", "net.minecraft.world.phys.MovingObjectPositionBlock");
|
||||
spigotClassnames.put("net.minecraft.world.phys.Vec3", "net.minecraft.world.phys.Vec3D");
|
||||
|
||||
spigotClassnames.put("net.minecraft.resources.ResourceLocation", "net.minecraft.resources.MinecraftKey");
|
||||
|
||||
spigotClassnames.put("net.minecraft.util.ProgressListener", "net.minecraft.util.IProgressUpdate");
|
||||
}
|
||||
|
||||
public static Class<?> getClass(String name) {
|
||||
try {
|
||||
if (name.startsWith("org.bukkit.craftbukkit")) {
|
||||
return Class.forName(ORG_BUKKIT_CRAFTBUKKIT + name.substring(22));
|
||||
} else if (MAJOR_VERSION < 17 && name.startsWith("net.minecraft")) {
|
||||
return Class.forName(LEGACY_NET_MINECRAFT_SERVER + "." + spigotClassnames.getOrDefault(name, name).split("[.](?=[^.]*$)")[1]);
|
||||
} else if (MAJOR_VERSION < 21 || MINOR_VERSION < 4) {
|
||||
return Class.forName(spigotClassnames.getOrDefault(name, name));
|
||||
} else {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = Class.forName(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
if (clazz != null && clazz.getName().equals(name)) {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
try {
|
||||
return Core.class.getClassLoader().getParent().loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (clazz == null) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException("Cannot find " + name, e);
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public static class Field<T> {
|
||||
private final java.lang.reflect.Field f;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T get(Object target) {
|
||||
try {
|
||||
return (T) f.get(target);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException("Cannot read field", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(Object target, Object value) {
|
||||
try {
|
||||
f.set(target, value);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException("Cannot write field", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Field<T> getField(Class<?> target, String name, Class<T> fieldType) {
|
||||
return getField(target, name, fieldType, 0);
|
||||
}
|
||||
|
||||
public static <T> Field<T> getField(Class<?> target, Class<T> fieldType, int index) {
|
||||
return getField(target, null, fieldType, index);
|
||||
}
|
||||
|
||||
public static <T> Field<T> getField(Class<?> target, Class<T> fieldType, int index, Class<?>... parameters) {
|
||||
return getField(target, null, fieldType, index, parameters);
|
||||
}
|
||||
|
||||
private static <T> Field<T> getField(Class<?> target, String name, Class<T> fieldType, int index, Class<?>... parameters) {
|
||||
for (final java.lang.reflect.Field field : target.getDeclaredFields()) {
|
||||
if (matching(field, name, fieldType, parameters) && index-- <= 0) {
|
||||
field.setAccessible(true);
|
||||
return new Field<>(field);
|
||||
}
|
||||
}
|
||||
|
||||
// Search in parent classes
|
||||
if (target.getSuperclass() != null) {
|
||||
return getField(target.getSuperclass(), name, fieldType, index);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Cannot find field with type " + fieldType);
|
||||
}
|
||||
|
||||
private static <T> boolean matching(java.lang.reflect.Field field, String name, Class<T> fieldType, Class<?>... parameters) {
|
||||
if (name != null && !field.getName().equals(name)) return false;
|
||||
|
||||
if (!fieldType.isAssignableFrom(field.getType())) return false;
|
||||
|
||||
if (parameters.length > 0) {
|
||||
Type[] arguments = ((ParameterizedType) field.getGenericType()).getActualTypeArguments();
|
||||
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
if (arguments[i] instanceof ParameterizedType ? ((ParameterizedType) arguments[i]).getRawType() != parameters[i] : arguments[i] != parameters[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public static class Method {
|
||||
private final java.lang.reflect.Method m;
|
||||
|
||||
public Object invoke(Object target, Object... arguments) {
|
||||
try {
|
||||
return m.invoke(target, arguments);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Cannot invoke method " + m, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Method getTypedMethod(Class<?> clazz, String methodName, Class<?> returnType, Class<?>... params) {
|
||||
for (final java.lang.reflect.Method method : clazz.getDeclaredMethods()) {
|
||||
if ((methodName == null || method.getName().equals(methodName))
|
||||
&& (returnType == null || method.getReturnType().equals(returnType))
|
||||
&& Arrays.equals(method.getParameterTypes(), params)) {
|
||||
method.setAccessible(true);
|
||||
return new Method(method);
|
||||
}
|
||||
}
|
||||
|
||||
// Search in every superclass
|
||||
if (clazz.getSuperclass() != null) {
|
||||
return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("Cannot find method %s (%s).", methodName, Arrays.asList(params)));
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public static class Constructor {
|
||||
private final java.lang.reflect.Constructor<?> c;
|
||||
|
||||
public Object invoke(Object... arguments) {
|
||||
try {
|
||||
return c.newInstance(arguments);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Cannot invoke constructor " + c, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Constructor getConstructor(Class<?> clazz, Class<?>... params) {
|
||||
for (final java.lang.reflect.Constructor<?> constructor : clazz.getDeclaredConstructors()) {
|
||||
if (Arrays.equals(constructor.getParameterTypes(), params)) {
|
||||
constructor.setAccessible(true);
|
||||
return new Constructor(constructor);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params)));
|
||||
}
|
||||
|
||||
public static Object newInstance(Class<?> clazz) {
|
||||
try {
|
||||
return Unsafe.getUnsafe().allocateInstance(clazz);
|
||||
|
||||
@@ -19,13 +19,8 @@
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializer;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -40,15 +35,4 @@ public class BountifulWrapper {
|
||||
if (type == ChatMessageType.CHAT) type = ChatMessageType.SYSTEM;
|
||||
player.spigot().sendMessage(type, msg);
|
||||
}
|
||||
|
||||
private static final Class<?> dataWatcherRegistry = EntityDataSerializers.class;
|
||||
private static final Class<?> dataWatcherSerializer = EntityDataSerializer.class;
|
||||
|
||||
public Object getDataWatcherObject(int index, Class<?> type) {
|
||||
return new EntityDataAccessor<>(index, (EntityDataSerializer<Object>) Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null));
|
||||
}
|
||||
|
||||
public Object getDataWatcherItem(Object dwo, Object value) {
|
||||
return new SynchedEntityData.DataItem<>((EntityDataAccessor<Object>) dwo, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* the Free Software Foundation, either versionStrings 3 of the License, or
|
||||
* (at your option) any later versionStrings.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
@@ -20,7 +20,6 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.command.SWTypeMapperCreator;
|
||||
import de.steamwar.command.TabCompletionCache;
|
||||
@@ -49,9 +48,13 @@ public class Core extends JavaPlugin {
|
||||
|
||||
public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader());
|
||||
|
||||
@Getter
|
||||
@Deprecated
|
||||
public static int getVersion() {
|
||||
return Reflection.MAJOR_VERSION;
|
||||
private static final int version;
|
||||
|
||||
static {
|
||||
String[] versionStrings = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\.");
|
||||
version = Integer.parseInt(versionStrings[1]);
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.contents.PlainTextContents;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@UtilityClass
|
||||
public class FlatteningWrapper {
|
||||
|
||||
public Object formatDisplayName(String displayName) {
|
||||
return displayName != null ? Optional.of((Object) MutableComponent.create(PlainTextContents.create(displayName))) : Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class RArmorStand extends REntity implements RInteractableEntity<RArmorSt
|
||||
super.spawn(packetSink);
|
||||
|
||||
if (size != null && size != Size.NORMAL) {
|
||||
packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value));
|
||||
entityDataPacket().add(sizeWatcher, size.value).send(packetSink);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,9 +61,9 @@ public class RBlockDisplay extends RDisplay {
|
||||
|
||||
private static final EntityDataAccessor<BlockState> blockWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.BLOCK_STATE);
|
||||
|
||||
private void getBlock(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getBlock(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) {
|
||||
packetSink.accept(blockWatcher, ((CraftBlockData) block).getState());
|
||||
packetSink.add(blockWatcher, ((CraftBlockData) block).getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,18 +89,13 @@ public abstract class RDisplay extends REntity {
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, BiConsumer<Object, Object>>... dataSinkSinks) {
|
||||
List<Object> keyValueData = new ArrayList<>();
|
||||
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, EntityDataPacketBuilder>... dataSinkSinks) {
|
||||
EntityDataPacketBuilder builder = entityDataPacket();
|
||||
boolean ignoreDefault = packetSink == updatePacketSink;
|
||||
for (BiConsumer<Boolean, BiConsumer<Object, Object>> dataSinkSink : dataSinkSinks) {
|
||||
dataSinkSink.accept(ignoreDefault, (dataWatcher, value) -> {
|
||||
keyValueData.add(dataWatcher);
|
||||
keyValueData.add(value);
|
||||
});
|
||||
}
|
||||
if (!keyValueData.isEmpty()) {
|
||||
packetSink.accept(getDataWatcherPacket(keyValueData.toArray()));
|
||||
for (BiConsumer<Boolean, EntityDataPacketBuilder> dataSinkSink : dataSinkSinks) {
|
||||
dataSinkSink.accept(ignoreDefault, builder);
|
||||
}
|
||||
if (!builder.isEmpty()) builder.send(packetSink);
|
||||
}
|
||||
|
||||
public void setTransform(@NonNull Transformation transform) {
|
||||
@@ -113,12 +108,12 @@ public abstract class RDisplay extends REntity {
|
||||
private static final EntityDataAccessor<Vector3f> scaleWatcher = new EntityDataAccessor<>(12, EntityDataSerializers.VECTOR3);
|
||||
private static final EntityDataAccessor<Quaternionf> rightRotationWatcher = new EntityDataAccessor<>(14, EntityDataSerializers.QUATERNION);
|
||||
|
||||
private void getTransformData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
||||
private void getTransformData(boolean ignoreDefault, EntityDataPacketBuilder dataSink) {
|
||||
if (ignoreDefault || !transform.equals(DEFAULT_TRANSFORM)) {
|
||||
dataSink.accept(translationWatcher, transform.getTranslation());
|
||||
dataSink.accept(leftRotationWatcher, transform.getLeftRotation());
|
||||
dataSink.accept(scaleWatcher, transform.getScale());
|
||||
dataSink.accept(rightRotationWatcher, transform.getRightRotation());
|
||||
dataSink.add(translationWatcher, transform.getTranslation());
|
||||
dataSink.add(leftRotationWatcher, transform.getLeftRotation());
|
||||
dataSink.add(scaleWatcher, transform.getScale());
|
||||
dataSink.add(rightRotationWatcher, transform.getRightRotation());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,10 +125,10 @@ public abstract class RDisplay extends REntity {
|
||||
private static final EntityDataAccessor<Integer> transformationInterpolationDurationWatcher = new EntityDataAccessor<>(9, EntityDataSerializers.INT);
|
||||
private static final EntityDataAccessor<Integer> positionOrRotationInterpolationDurationWatcher = new EntityDataAccessor<>(10, EntityDataSerializers.INT);
|
||||
|
||||
private void getInterpolationDuration(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getInterpolationDuration(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || interpolationDelay != 0) {
|
||||
packetSink.accept(transformationInterpolationDurationWatcher, interpolationDuration);
|
||||
packetSink.accept(positionOrRotationInterpolationDurationWatcher, interpolationDuration);
|
||||
packetSink.add(transformationInterpolationDurationWatcher, interpolationDuration);
|
||||
packetSink.add(positionOrRotationInterpolationDurationWatcher, interpolationDuration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,9 +139,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Float> viewRangeWatcher = new EntityDataAccessor<>(17, EntityDataSerializers.FLOAT);
|
||||
|
||||
private void getViewRange(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getViewRange(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || viewRange != 1.0F) {
|
||||
packetSink.accept(viewRangeWatcher, viewRange);
|
||||
packetSink.add(viewRangeWatcher, viewRange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,9 +152,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Float> shadowRadiusWatcher = new EntityDataAccessor<>(18, EntityDataSerializers.FLOAT);
|
||||
|
||||
private void getShadowRadius(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getShadowRadius(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || shadowRadius != 0.0F) {
|
||||
packetSink.accept(shadowRadiusWatcher, shadowRadius);
|
||||
packetSink.add(shadowRadiusWatcher, shadowRadius);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,9 +165,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Float> shadowStrengthWatcher = new EntityDataAccessor<>(19, EntityDataSerializers.FLOAT);
|
||||
|
||||
private void getShadowStrength(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getShadowStrength(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || shadowStrength != 1.0F) {
|
||||
packetSink.accept(shadowStrengthWatcher, shadowStrength);
|
||||
packetSink.add(shadowStrengthWatcher, shadowStrength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,9 +178,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Float> displayWidthWatcher = new EntityDataAccessor<>(20, EntityDataSerializers.FLOAT);
|
||||
|
||||
private void getDisplayWidth(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getDisplayWidth(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || displayWidth != 0.0F) {
|
||||
packetSink.accept(displayWidthWatcher, displayWidth);
|
||||
packetSink.add(displayWidthWatcher, displayWidth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,9 +191,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Float> displayHeightWatcher = new EntityDataAccessor<>(21, EntityDataSerializers.FLOAT);
|
||||
|
||||
private void getDisplayHeight(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getDisplayHeight(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || displayHeight != 0.0F) {
|
||||
packetSink.accept(displayHeightWatcher, displayHeight);
|
||||
packetSink.add(displayHeightWatcher, displayHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,9 +204,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Integer> interpolationDelayWatcher = new EntityDataAccessor<>(8, EntityDataSerializers.INT);
|
||||
|
||||
private void getInterpolationDelay(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getInterpolationDelay(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || interpolationDelay != 0) {
|
||||
packetSink.accept(interpolationDelayWatcher, interpolationDelay);
|
||||
packetSink.add(interpolationDelayWatcher, interpolationDelay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,9 +217,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Byte> billboardWatcher = new EntityDataAccessor<>(15, EntityDataSerializers.BYTE);
|
||||
|
||||
private void getBillboard(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getBillboard(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || billboard != Display.Billboard.FIXED) {
|
||||
packetSink.accept(billboardWatcher, (byte) billboard.ordinal());
|
||||
packetSink.add(billboardWatcher, (byte) billboard.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,9 +230,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Integer> glowColorOverrideWatcher = new EntityDataAccessor<>(22, EntityDataSerializers.INT);
|
||||
|
||||
private void getGlowColorOverride(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getGlowColorOverride(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || glowColorOverride != null) {
|
||||
packetSink.accept(glowColorOverrideWatcher, glowColorOverride == null ? -1 : glowColorOverride.asARGB());
|
||||
packetSink.add(glowColorOverrideWatcher, glowColorOverride == null ? -1 : glowColorOverride.asARGB());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,9 +243,9 @@ public abstract class RDisplay extends REntity {
|
||||
|
||||
private static final EntityDataAccessor<Integer> brightnessWatcher = new EntityDataAccessor<>(16, EntityDataSerializers.INT);
|
||||
|
||||
private void getBrightness(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getBrightness(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || brightness != null) {
|
||||
packetSink.accept(brightnessWatcher, brightness == null ? -1 : brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20);
|
||||
packetSink.add(brightnessWatcher, brightness == null ? -1 : brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ package de.steamwar.entity;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.FlatteningWrapper;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.contents.PlainTextContents;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
@@ -193,12 +193,12 @@ public class REntity {
|
||||
|
||||
public void setPose(Pose pose) {
|
||||
this.pose = pose;
|
||||
server.updateEntity(this, getDataWatcherPacket(poseDataWatcher, pose));
|
||||
server.updateEntity(this, entityDataPacket().add(poseDataWatcher, pose).build());
|
||||
}
|
||||
|
||||
public void setOnFire(boolean perma) {
|
||||
fireTick = perma ? -1 : 21;
|
||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
||||
server.updateEntity(this, entityDataPacket().add(entityStatusWatcher, getEntityStatus()).build());
|
||||
}
|
||||
|
||||
public boolean isOnFire() {
|
||||
@@ -207,20 +207,18 @@ public class REntity {
|
||||
|
||||
public void setInvisible(boolean invisible) {
|
||||
this.invisible = invisible;
|
||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
||||
server.updateEntity(this, entityDataPacket().add(entityStatusWatcher, getEntityStatus()).build());
|
||||
}
|
||||
|
||||
public void setBowDrawn(boolean drawn, boolean offHand) {
|
||||
bowDrawn = drawn;
|
||||
server.updateEntity(this, getDataWatcherPacket(poseDataWatcher, Pose.SHOOTING));
|
||||
server.updateEntity(this, entityDataPacket().add(poseDataWatcher, Pose.SHOOTING).build());
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
server.updateEntity(this, getDataWatcherPacket(
|
||||
nameWatcher, FlatteningWrapper.formatDisplayName(displayName),
|
||||
nameVisibleWatcher, displayName != null
|
||||
));
|
||||
server.updateEntity(this, entityDataPacket().add(nameWatcher, formatDisplayName(displayName))
|
||||
.add(nameVisibleWatcher, displayName != null).build());
|
||||
}
|
||||
|
||||
public void setItem(Object slot, ItemStack stack) {
|
||||
@@ -234,12 +232,12 @@ public class REntity {
|
||||
|
||||
public void setNoGravity(boolean noGravity) {
|
||||
this.noGravity = noGravity;
|
||||
server.updateEntity(this, getDataWatcherPacket(noGravityDataWatcher, noGravity));
|
||||
server.updateEntity(this, entityDataPacket().add(noGravityDataWatcher, noGravity).build());
|
||||
}
|
||||
|
||||
public void setGlowing(boolean glowing) {
|
||||
this.isGlowing = glowing;
|
||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
||||
server.updateEntity(this, entityDataPacket().add(entityStatusWatcher, getEntityStatus()).build());
|
||||
}
|
||||
|
||||
private ClientboundAddEntityPacket spawnPacketGenerator() {
|
||||
@@ -263,20 +261,22 @@ public class REntity {
|
||||
}
|
||||
|
||||
if (pose != Pose.STANDING) {
|
||||
packetSink.accept(getDataWatcherPacket(poseDataWatcher, pose));
|
||||
entityDataPacket().add(poseDataWatcher, pose).send(packetSink);
|
||||
}
|
||||
|
||||
byte status = getEntityStatus();
|
||||
if (status != 0) {
|
||||
packetSink.accept(getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
||||
entityDataPacket().add(entityStatusWatcher, getEntityStatus()).send(packetSink);
|
||||
}
|
||||
|
||||
if (displayName != null) {
|
||||
packetSink.accept(getDataWatcherPacket(nameWatcher, FlatteningWrapper.formatDisplayName(displayName), nameVisibleWatcher, true));
|
||||
entityDataPacket().add(nameWatcher, formatDisplayName(displayName))
|
||||
.add(nameVisibleWatcher, true)
|
||||
.send(packetSink);
|
||||
}
|
||||
|
||||
if (noGravity) {
|
||||
packetSink.accept(getDataWatcherPacket(noGravityDataWatcher, true));
|
||||
entityDataPacket().add(noGravityDataWatcher, true).send(packetSink);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ public class REntity {
|
||||
if (fireTick > 0) {
|
||||
fireTick--;
|
||||
if (fireTick == 0) {
|
||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
||||
server.updateEntity(this, entityDataPacket().add(entityStatusWatcher, getEntityStatus()).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,13 +315,29 @@ public class REntity {
|
||||
return status;
|
||||
}
|
||||
|
||||
protected Object getDataWatcherPacket(Object... dataWatcherKeyValues) {
|
||||
ArrayList<SynchedEntityData.DataValue<?>> nativeWatchers = new ArrayList<>(1);
|
||||
for (int i = 0; i < dataWatcherKeyValues.length; i += 2) {
|
||||
nativeWatchers.add(((SynchedEntityData.DataItem<?>) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i + 1])).value());
|
||||
protected EntityDataPacketBuilder entityDataPacket() {
|
||||
return new EntityDataPacketBuilder();
|
||||
}
|
||||
|
||||
public class EntityDataPacketBuilder {
|
||||
private List<SynchedEntityData.DataValue<?>> values = new ArrayList<>();
|
||||
|
||||
public <T> EntityDataPacketBuilder add(EntityDataAccessor<T> accessor, T value) {
|
||||
values.add(new SynchedEntityData.DataItem<>(accessor, value).value());
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ClientboundSetEntityDataPacket(entityId, nativeWatchers);
|
||||
public boolean isEmpty() {
|
||||
return values.isEmpty();
|
||||
}
|
||||
|
||||
public ClientboundSetEntityDataPacket build() {
|
||||
return new ClientboundSetEntityDataPacket(entityId, values);
|
||||
}
|
||||
|
||||
public void send(Consumer<Object> packetSink) {
|
||||
packetSink.accept(build());
|
||||
}
|
||||
}
|
||||
|
||||
private Object getTeleportPacket() {
|
||||
@@ -364,4 +380,8 @@ public class REntity {
|
||||
private int calcVelocity(double value) {
|
||||
return (int) (Math.max(-3.9, Math.min(value, 3.9)) * 8000);
|
||||
}
|
||||
|
||||
private static Optional<Component> formatDisplayName(String displayName) {
|
||||
return displayName != null ? Optional.of(MutableComponent.create(PlainTextContents.create(displayName))) : Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,13 @@
|
||||
|
||||
package de.steamwar.entity;
|
||||
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -61,18 +60,13 @@ public class RInteraction extends REntity implements RInteractableEntity<RIntera
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, BiConsumer<Object, Object>>... dataSinkSinks) {
|
||||
List<Object> keyValueData = new ArrayList<>();
|
||||
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, EntityDataPacketBuilder>... dataSinkSinks) {
|
||||
EntityDataPacketBuilder builder = entityDataPacket();
|
||||
boolean ignoreDefault = packetSink == updatePacketSink;
|
||||
for (BiConsumer<Boolean, BiConsumer<Object, Object>> dataSinkSink : dataSinkSinks) {
|
||||
dataSinkSink.accept(ignoreDefault, (dataWatcher, value) -> {
|
||||
keyValueData.add(dataWatcher);
|
||||
keyValueData.add(value);
|
||||
});
|
||||
}
|
||||
if (!keyValueData.isEmpty()) {
|
||||
packetSink.accept(getDataWatcherPacket(keyValueData.toArray()));
|
||||
for (BiConsumer<Boolean, EntityDataPacketBuilder> dataSinkSink : dataSinkSinks) {
|
||||
dataSinkSink.accept(ignoreDefault, builder);
|
||||
}
|
||||
if (!builder.isEmpty()) builder.send(packetSink);
|
||||
}
|
||||
|
||||
public void setInteractionWidth(float interactionWidth) {
|
||||
@@ -80,11 +74,11 @@ public class RInteraction extends REntity implements RInteractableEntity<RIntera
|
||||
sendPacket(updatePacketSink, this::getInteractionWidthData);
|
||||
}
|
||||
|
||||
private static final Object interactionWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Float.class);
|
||||
private static final EntityDataAccessor<Float> interactionWidthWatcher = new EntityDataAccessor<>(8, EntityDataSerializers.FLOAT);
|
||||
|
||||
private void getInteractionWidthData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
||||
private void getInteractionWidthData(boolean ignoreDefault, EntityDataPacketBuilder dataSink) {
|
||||
if (ignoreDefault || interactionWidth != 1.0) {
|
||||
dataSink.accept(interactionWidthWatcher, interactionWidth);
|
||||
dataSink.add(interactionWidthWatcher, interactionWidth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +87,11 @@ public class RInteraction extends REntity implements RInteractableEntity<RIntera
|
||||
sendPacket(updatePacketSink, this::getInteractionHeightData);
|
||||
}
|
||||
|
||||
private static final Object interactionHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Float.class);
|
||||
private static final EntityDataAccessor<Float> interactionHeightWatcher = new EntityDataAccessor<>(9, EntityDataSerializers.FLOAT);
|
||||
|
||||
private void getInteractionHeightData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
||||
private void getInteractionHeightData(boolean ignoreDefault, EntityDataPacketBuilder dataSink) {
|
||||
if (ignoreDefault || interactionHeight != 1.0) {
|
||||
dataSink.accept(interactionHeightWatcher, interactionHeight);
|
||||
dataSink.add(interactionHeightWatcher, interactionHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,11 +100,11 @@ public class RInteraction extends REntity implements RInteractableEntity<RIntera
|
||||
sendPacket(updatePacketSink, this::getResponsiveData);
|
||||
}
|
||||
|
||||
private static final Object responsiveWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Boolean.class);
|
||||
private static final EntityDataAccessor<Boolean> responsiveWatcher = new EntityDataAccessor<>(10, EntityDataSerializers.BOOLEAN);
|
||||
|
||||
private void getResponsiveData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
||||
private void getResponsiveData(boolean ignoreDefault, EntityDataPacketBuilder dataSink) {
|
||||
if (ignoreDefault || !responsive) {
|
||||
dataSink.accept(responsiveWatcher, responsive);
|
||||
dataSink.add(responsiveWatcher, responsive);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,9 +63,9 @@ public class RItemDisplay extends RDisplay {
|
||||
|
||||
private static final EntityDataAccessor<net.minecraft.world.item.ItemStack> itemStackWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.ITEM_STACK);
|
||||
|
||||
private void getItemStack(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getItemStack(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || !itemStack.equals(DEFAULT_ITEM_STACK)) {
|
||||
packetSink.accept(itemStackWatcher, CraftItemStack.asNMSCopy(itemStack));
|
||||
packetSink.add(itemStackWatcher, CraftItemStack.asNMSCopy(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,9 +76,9 @@ public class RItemDisplay extends RDisplay {
|
||||
sendPacket(updatePacketSink, this::getItemDisplayTransform);
|
||||
}
|
||||
|
||||
private void getItemDisplayTransform(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getItemDisplayTransform(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || itemDisplayTransform != ItemDisplay.ItemDisplayTransform.NONE) {
|
||||
packetSink.accept(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal());
|
||||
packetSink.add(itemDisplayTransformWatcher, (byte) itemDisplayTransform.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ package de.steamwar.entity;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.ProtocolWrapper;
|
||||
import de.steamwar.network.CoreNetworkHandler;
|
||||
import de.steamwar.network.NetworkSender;
|
||||
@@ -29,6 +28,8 @@ import de.steamwar.network.packets.common.PlayerSkinRequestPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@@ -42,7 +43,7 @@ import java.util.function.Consumer;
|
||||
|
||||
public class RPlayer extends REntity implements RInteractableEntity<RPlayer> {
|
||||
|
||||
private static final Object skinPartsDataWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Byte.class);
|
||||
private static final EntityDataAccessor<Byte> skinPartsDataWatcher = new EntityDataAccessor<>(17, EntityDataSerializers.BYTE);
|
||||
|
||||
@Getter
|
||||
private final UUID actualUUID;
|
||||
@@ -85,7 +86,7 @@ public class RPlayer extends REntity implements RInteractableEntity<RPlayer> {
|
||||
@Override
|
||||
void spawn(Consumer<Object> packetSink) {
|
||||
packetSink.accept(getNamedSpawnPacket());
|
||||
packetSink.accept(getDataWatcherPacket(skinPartsDataWatcher, (byte) 0x7F));
|
||||
entityDataPacket().add(skinPartsDataWatcher, (byte) 0x7F).send(packetSink);
|
||||
|
||||
for (Map.Entry<Object, ItemStack> entry : itemSlots.entrySet()) {
|
||||
packetSink.accept(getEquipmentPacket(entry.getKey(), entry.getValue()));
|
||||
|
||||
@@ -77,9 +77,9 @@ public class RTextDisplay extends RDisplay {
|
||||
|
||||
private static final EntityDataAccessor<Component> textWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.COMPONENT);
|
||||
|
||||
private void getText(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getText(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || !text.isEmpty()) {
|
||||
packetSink.accept(textWatcher, MutableComponent.create(PlainTextContents.create(text)));
|
||||
packetSink.add(textWatcher, MutableComponent.create(PlainTextContents.create(text)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +90,9 @@ public class RTextDisplay extends RDisplay {
|
||||
|
||||
private static final EntityDataAccessor<Integer> lineWidthWatcher = new EntityDataAccessor<>(24, EntityDataSerializers.INT);
|
||||
|
||||
private void getLineWidth(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getLineWidth(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || lineWidth != 200) {
|
||||
packetSink.accept(lineWidthWatcher, lineWidth);
|
||||
packetSink.add(lineWidthWatcher, lineWidth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +103,9 @@ public class RTextDisplay extends RDisplay {
|
||||
|
||||
private static final EntityDataAccessor<Byte> textOpacityWatcher = new EntityDataAccessor<>(26, EntityDataSerializers.BYTE);
|
||||
|
||||
private void getTextOpacity(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getTextOpacity(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || textOpacity != (byte) -1) {
|
||||
packetSink.accept(textOpacityWatcher, textOpacity);
|
||||
packetSink.add(textOpacityWatcher, textOpacity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,9 +126,9 @@ public class RTextDisplay extends RDisplay {
|
||||
|
||||
private static final EntityDataAccessor<Integer> backgroundColorWatcher = new EntityDataAccessor<>(25, EntityDataSerializers.INT);
|
||||
|
||||
private void getBackgroundColor(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getBackgroundColor(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
if (ignoreDefault || backgroundColor != null) {
|
||||
packetSink.accept(backgroundColorWatcher, backgroundColor);
|
||||
packetSink.add(backgroundColorWatcher, backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class RTextDisplay extends RDisplay {
|
||||
|
||||
private static final EntityDataAccessor<Byte> textStatusWatcher = new EntityDataAccessor<>(27, EntityDataSerializers.BYTE);
|
||||
|
||||
private void getTextStatus(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
|
||||
private void getTextStatus(boolean ignoreDefault, EntityDataPacketBuilder packetSink) {
|
||||
byte status = 0;
|
||||
|
||||
if (shadowed) {
|
||||
@@ -167,7 +167,7 @@ public class RTextDisplay extends RDisplay {
|
||||
}
|
||||
|
||||
if (ignoreDefault || status != 0) {
|
||||
packetSink.accept(textStatusWatcher, status);
|
||||
packetSink.add(textStatusWatcher, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,13 @@
|
||||
|
||||
package de.steamwar.techhider.legacy;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.techhider.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.SimpleBitStorage;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -85,12 +82,9 @@ public class ChunkHider {
|
||||
};
|
||||
}
|
||||
|
||||
private static final Registry<BlockEntityType<?>> registry = Reflection.getField(BuiltInRegistries.class, "BLOCK_ENTITY_TYPE", Registry.class).get(null);
|
||||
private static final Reflection.Method getKey = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.core.Registry"), "getKey", ResourceLocation.class, Object.class);
|
||||
|
||||
protected boolean tileEntityVisible(Set<String> hiddenBlockEntities, ClientboundLevelChunkPacketData.BlockEntityInfo tile) {
|
||||
BlockEntityType<?> type = tile.type;
|
||||
String path = ((ResourceLocation) getKey.invoke(registry, type)).getPath();
|
||||
String path = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(type).getPath();
|
||||
return !hiddenBlockEntities.contains(path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user