Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a46f10f8b |
@ -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 Vec3D(x, y, z), pos == null ? new Vec3D(0, 0, 0) : pos.b(), yaw, pitch));
|
||||||
};
|
};
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return super.getPositionSetter(packetClass, fieldOffset);
|
return super.getPositionSetter(packetClass, fieldOffset);
|
||||||
|
|||||||
@ -177,9 +177,30 @@ public final class Reflection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void set(Object target, Object value) {
|
public void set(Object target, Object value) {
|
||||||
|
// This now works for Fields in records!
|
||||||
try {
|
try {
|
||||||
f.set(target, value);
|
long offset = Unsafe.getUnsafe().objectFieldOffset(f);
|
||||||
} catch (IllegalAccessException e) {
|
Class<?> type = f.getType();
|
||||||
|
if (type == int.class) {
|
||||||
|
Unsafe.getUnsafe().putInt(target, offset, (Integer) value);
|
||||||
|
} else if (type == float.class) {
|
||||||
|
Unsafe.getUnsafe().putFloat(target, offset, (Float) value);
|
||||||
|
} else if (type == double.class) {
|
||||||
|
Unsafe.getUnsafe().putDouble(target, offset, (Double) value);
|
||||||
|
} else if (type == boolean.class) {
|
||||||
|
Unsafe.getUnsafe().putBoolean(target, offset, (Boolean) value);
|
||||||
|
} else if (type == byte.class) {
|
||||||
|
Unsafe.getUnsafe().putByte(target, offset, (Byte) value);
|
||||||
|
} else if (type == char.class) {
|
||||||
|
Unsafe.getUnsafe().putChar(target, offset, (Character) value);
|
||||||
|
} else if (type == short.class) {
|
||||||
|
Unsafe.getUnsafe().putShort(target, offset, (Short) value);
|
||||||
|
} else if (type == long.class) {
|
||||||
|
Unsafe.getUnsafe().putLong(target, offset, (Long) value);
|
||||||
|
} else {
|
||||||
|
Unsafe.getUnsafe().putReference(target, offset, value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("Cannot write field", e);
|
throw new IllegalArgumentException("Cannot write field", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -396,10 +396,26 @@ public class REntity {
|
|||||||
public static final Class<?> teleportPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket");
|
public static final Class<?> teleportPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket");
|
||||||
public static final Reflection.Field<Integer> teleportEntity = Reflection.getField(teleportPacket, int.class, 0);
|
public static final Reflection.Field<Integer> teleportEntity = Reflection.getField(teleportPacket, int.class, 0);
|
||||||
public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0);
|
public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0);
|
||||||
|
public static final Class<?> relative;
|
||||||
|
public static final Reflection.Field<Set> relatives;
|
||||||
|
static {
|
||||||
|
if (Core.getVersion() >= 21) {
|
||||||
|
relative = Reflection.getClass("net.minecraft.world.entity.Relative");
|
||||||
|
relatives = Reflection.getField(teleportPacket, Set.class, 0);
|
||||||
|
} else {
|
||||||
|
relative = null;
|
||||||
|
relatives = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
private Object getTeleportPacket(){
|
private Object getTeleportPacket(){
|
||||||
Object packet = Reflection.newInstance(teleportPacket);
|
Object packet = Reflection.newInstance(teleportPacket);
|
||||||
teleportEntity.set(packet, entityId);
|
teleportEntity.set(packet, entityId);
|
||||||
teleportPosition.set(packet, x, y, z, pitch, yaw);
|
teleportPosition.set(packet, x, y, z, pitch, yaw);
|
||||||
|
if (Core.getVersion() >= 21) {
|
||||||
|
// https://mappings.dev/1.21.3/net/minecraft/world/entity/Relative.html
|
||||||
|
Object[] constants = relative.getEnumConstants();
|
||||||
|
relatives.set(packet, new HashSet<>(Arrays.asList(constants[0], constants[1], constants[2], constants[3], constants[4], constants[5])));
|
||||||
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user