Return a new instance rather than a ConstructorAccessor

This commit is contained in:
Etrayed 2022-07-31 11:16:33 +02:00
parent 26cb7c195b
commit c8919bc1fe
No known key found for this signature in database
GPG Key ID: C96C72C777B1B6AF
2 changed files with 7 additions and 6 deletions

View File

@ -65,9 +65,9 @@ public class StructureCache {
return accessor.invoke(MinecraftReflection.getPacketDataSerializer(new ZeroBuffer()));
} catch (Exception exception) {
// try trick nms around as they want a non-null compound in the map_chunk packet constructor
ConstructorAccessor trickyDataSerializerAccessor = getTrickDataSerializerOrNull();
if (trickyDataSerializerAccessor != null) {
return accessor.invoke(trickyDataSerializerAccessor.invoke(new ZeroBuffer()));
Object trickyDataSerializer = getTrickDataSerializerOrNull();
if (trickyDataSerializer != null) {
return accessor.invoke(trickyDataSerializer);
}
// the tricks are over
throw new IllegalArgumentException("Unable to create packet " + clazz, exception);
@ -127,7 +127,7 @@ public class StructureCache {
*
* @return an accessor to a constructor which creates a data serializer.
*/
public static ConstructorAccessor getTrickDataSerializerOrNull() {
public static Object getTrickDataSerializerOrNull() {
if (TRICKED_DATA_SERIALIZER == null && !TRICK_TRIED) {
// ensure that we only try once to create the class
TRICK_TRIED = true;
@ -152,6 +152,7 @@ public class StructureCache {
// can happen if unsupported
}
}
return TRICKED_DATA_SERIALIZER;
return TRICKED_DATA_SERIALIZER == null ? null : TRICKED_DATA_SERIALIZER.invoke(new ZeroBuffer());
}
}

View File

@ -132,7 +132,7 @@ public final class WrappedLevelChunkData {
* @return a newly created wrapper
*/
public static ChunkData fromValues(NbtCompound heightmapsTag, byte[] buffer, List<BlockEntityInfo> blockEntityInfo) {
ChunkData data = new ChunkData(LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR.invoke(StructureCache.getTrickDataSerializerOrNull().invoke(new ZeroBuffer()), 0, 0));
ChunkData data = new ChunkData(LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR.invoke(StructureCache.getTrickDataSerializerOrNull(), 0, 0));
data.setHeightmapsTag(heightmapsTag);
data.setBuffer(buffer);