Reflection on WrappedBlockState to clone it

This commit is contained in:
libraryaddict 2024-06-24 23:29:34 +12:00
parent 817d87e6a3
commit d2fa119613
2 changed files with 14 additions and 6 deletions

View File

@ -33,7 +33,7 @@ public class ParamInfoWrappedBlockData extends ParamInfo {
@RequiredArgsConstructor
@Getter
private static class WrappedData {
private final LinkedHashMap<StateValue, Object> data;
private final Map<StateValue, Object> data;
private final WrappedBlockState block;
private final String blockName;
@ -52,6 +52,7 @@ public class ParamInfoWrappedBlockData extends ParamInfo {
private final List<WrappedData> defaultBlockStates = new ArrayList<>();
private final Method methodGlobalIdNoCache;
private final Method cloneBlockstate;
@SneakyThrows
public ParamInfoWrappedBlockData(Class paramClass, String name, String description) {
@ -65,6 +66,8 @@ public class ParamInfoWrappedBlockData extends ParamInfo {
// If this breaks in the future, I'll probably have a better idea on how to do things
methodGlobalIdNoCache = WrappedBlockState.class.getDeclaredMethod("getGlobalIdNoCache");
methodGlobalIdNoCache.setAccessible(true);
cloneBlockstate = WrappedBlockState.class.getDeclaredMethod("checkIfCloneNeeded");
cloneBlockstate.setAccessible(true);
}
@SneakyThrows
@ -304,6 +307,7 @@ public class ParamInfoWrappedBlockData extends ParamInfo {
}
WrappedBlockState blockState = bData.getBlock().clone();
cloneBlockstate.invoke(blockState);
for (int i = 1; i < parseSplit.size() - 1; i++) {
// This is ensured key=value

14
pom.xml
View File

@ -24,7 +24,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lombok.version>1.18.32</lombok.version>
<packetevents.version>2.3.0</packetevents.version>
<packetevents.version>2.3.1-SNAPSHOT</packetevents.version>
<spigot.version>1.20.6-R0.1-SNAPSHOT</spigot.version>
<junit.version>4.13.2</junit.version>
<junit-jupiter.version>5.9.3</junit-jupiter.version>
@ -43,8 +43,8 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.retrooper.packetevents</groupId>
<artifactId>spigot</artifactId>
<groupId>com.github.retrooper</groupId>
<artifactId>packetevents-spigot</artifactId>
<optional>true</optional>
<scope>compile</scope>
</dependency>
@ -73,8 +73,8 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.github.retrooper.packetevents</groupId>
<artifactId>spigot</artifactId>
<groupId>com.github.retrooper</groupId>
<artifactId>packetevents-spigot</artifactId>
<version>${packetevents.version}</version>
<scope>provided</scope>
</dependency>
@ -124,6 +124,10 @@
<id>codemc-releases</id>
<url>https://repo.codemc.io/repository/maven-releases/</url>
</repository>
<repository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository>
</repositories>
<distributionManagement>