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

14
pom.xml
View File

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