Skip to content

Commit

Permalink
Pathetic now supports 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Metaphoriker committed Apr 23, 2024
1 parent c2d2a04 commit 3b2d4a2
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pathetic-nms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.patheloper</groupId>
<artifactId>v1_20_R4</artifactId>
<version>2.4.1</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.patheloper</groupId>
<artifactId>v1_20_R3</artifactId>
Expand Down
6 changes: 5 additions & 1 deletion pathetic-nms/src/main/java/org/patheloper/nms/NMSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.patheloper.nms.v1_20_R1.OneTwentyOneNMSInterface;
import org.patheloper.nms.v1_20_R2.OneTwentyTwoNMSInterface;
import org.patheloper.nms.v1_20_R3.OneTwentyThreeNMSInterface;
import org.patheloper.nms.v1_20_R4.OneTwentyFourNMSInterface;
import org.patheloper.nms.v1_8.OneEightNMSInterface;

public class NMSUtils {
Expand All @@ -21,7 +22,10 @@ public class NMSUtils {
public NMSUtils(int major, int minor) {
switch (major) {
case 20:
if (minor == 3 || minor == 4) {
if (minor == 5) {
nmsInterface = new OneTwentyFourNMSInterface();
break;
} else if (minor == 3 || minor == 4) {
nmsInterface = new OneTwentyThreeNMSInterface();
break;
} else if (minor == 2) {
Expand Down
43 changes: 43 additions & 0 deletions pathetic-nms/v1_20_R4/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.patheloper</groupId>
<artifactId>pathetic-main</artifactId>
<version>2.4.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>v1_20_R4</artifactId>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/nms/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.patheloper</groupId>
<artifactId>pathetic-api</artifactId>
<version>2.4.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.patheloper.nms.v1_20_R4;

import net.minecraft.server.level.WorldServer;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.chunk.DataPaletteBlock;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import org.bukkit.ChunkSnapshot;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.v1_20_R4.CraftChunk;
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
import org.patheloper.api.snapshot.NMSInterface;

import java.lang.reflect.Field;

public class OneTwentyFourNMSInterface implements NMSInterface {

private static final Field blockIDField;

static {
try {
blockIDField = CraftChunk.class.getDeclaredField("emptyBlockIDs");
blockIDField.setAccessible(true);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}

@Override
@SuppressWarnings("unchecked")
public ChunkSnapshot getSnapshot(World world, int chunkX, int chunkZ) {
try {

WorldServer server = ((CraftWorld) world).getHandle();
CraftChunk newCraftChunk = new CraftChunk(server, chunkX, chunkZ);

server.l().a(chunkX, chunkZ, ChunkStatus.n, true);
DataPaletteBlock<IBlockData> dataDataPaletteBlock =
(DataPaletteBlock<IBlockData>) blockIDField.get(newCraftChunk);

dataDataPaletteBlock.b();
dataDataPaletteBlock.a();
ChunkSnapshot chunkSnapshot = newCraftChunk.getChunkSnapshot();
dataDataPaletteBlock.b();

return chunkSnapshot;

} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
}
}

@Override
public BlockState getBlockState(ChunkSnapshot snapshot, int x, int y, int z) {
return snapshot.getBlockData(x, y, z).createBlockState();
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<module>pathetic-example</module>
<module>pathetic-mapping</module>
<module>pathetic-nms</module>
<module>pathetic-nms/v1_20_R4</module>
<module>pathetic-nms/v1_20_R3</module>
<module>pathetic-nms/v1_20_R2</module>
<module>pathetic-nms/v1_20_R1</module>
Expand Down

0 comments on commit 3b2d4a2

Please sign in to comment.