Add #setAccessible call to access to private fields

This commit is contained in:
Flowsqy 2021-12-29 15:43:57 +01:00
parent 5efdb35c15
commit b256015c29
2 changed files with 7 additions and 0 deletions

View File

@ -29,10 +29,13 @@ public class FakeArmorStandImpl extends FakeEntityImpl<String> implements FakeAr
static {
try {
final Field dataSharedFlagsId = Entity.class.getDeclaredField("Z"); // DATA_SHARED_FLAGS_ID
dataSharedFlagsId.setAccessible(true);
DATA_SHARED_FLAGS_ID = FakeEntityImpl.forceCast(dataSharedFlagsId.get(null));
final Field dataCustomNameField = Entity.class.getDeclaredField("aJ"); // DATA_CUSTOM_NAME
dataCustomNameField.setAccessible(true);
DATA_CUSTOM_NAME = FakeEntityImpl.forceCast(dataCustomNameField.get(null));
final Field dataCustomNameVisibleField = Entity.class.getDeclaredField("aK"); // DATA_CUSTOM_NAME_VISIBLE
dataCustomNameVisibleField.setAccessible(true);
DATA_CUSTOM_NAME_VISIBLE = FakeEntityImpl.forceCast(dataCustomNameVisibleField.get(null));
} catch (ReflectiveOperationException e){
throw new RuntimeException(e);

View File

@ -30,12 +30,16 @@ public abstract class FakeEntityImpl<T> implements FakeEntity {
static {
try {
final Field entityCounterField = Entity.class.getDeclaredField("b"); // ENTITY_COUNTER
entityCounterField.setAccessible(true);
ENTITY_COUNTER = (AtomicInteger) entityCounterField.get(null);
final Field dataNoGravityField = Entity.class.getDeclaredField("aM"); // DATA_NO_GRAVITY
dataNoGravityField.setAccessible(true);
DATA_NO_GRAVITY = forceCast(dataNoGravityField.get(null));
final Field dataSilentField = Entity.class.getDeclaredField("aL"); // DATA_SILENT
dataSilentField.setAccessible(true);
DATA_SILENT = forceCast(dataSilentField.get(null));
packedItemField = ClientboundSetEntityDataPacket.class.getDeclaredField("b"); // packedItems
packedItemField.setAccessible(true);
}catch (ReflectiveOperationException e){
throw new RuntimeException(e);
}