forked from lishid/Orebfuscator
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add support for 1.19.4 * fix: add 1.19.4 to buildtools
- Loading branch information
Showing
22 changed files
with
539 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/JavaVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.imprex.orebfuscator.util; | ||
|
||
public final class JavaVersion { | ||
|
||
private static final int JAVA_VERSION = javaMajorVersion(); | ||
|
||
public static int get() { | ||
return JAVA_VERSION; | ||
} | ||
|
||
private static int javaMajorVersion() { | ||
return majorVersion(System.getProperty("java.specification.version", "1.6")); | ||
} | ||
|
||
/** | ||
* taken from: | ||
* https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/PlatformDependent0.java#L1011 | ||
*/ | ||
private static int majorVersion(final String javaSpecVersion) { | ||
final String[] components = javaSpecVersion.split("\\."); | ||
final int[] version = new int[components.length]; | ||
for (int i = 0; i < components.length; i++) { | ||
version[i] = Integer.parseInt(components[i]); | ||
} | ||
|
||
if (version[0] == 1) { | ||
assert version[1] >= 6; | ||
return version[1]; | ||
} else { | ||
return version[0]; | ||
} | ||
} | ||
|
||
private JavaVersion() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>net.imprex</groupId> | ||
<artifactId>orebfuscator-nms</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>orebfuscator-nms-v1_19_R3</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>net.imprex</groupId> | ||
<artifactId>orebfuscator-nms-api</artifactId> | ||
<version>${revision}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot</artifactId> | ||
<version>1.19.4-R0.1-SNAPSHOT</version> | ||
<classifier>remapped-mojang</classifier> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.comphenix.protocol</groupId> | ||
<artifactId>ProtocolLib-API</artifactId> | ||
<version>${dependency.protocollib.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>specialsource-maven-plugin</artifactId> | ||
<version>${plugin.specialsource.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>remap</goal> | ||
</goals> | ||
<id>remap-obf</id> | ||
<configuration> | ||
<srgIn>org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:txt:maps-mojang</srgIn> | ||
<reverse>true</reverse> | ||
<remappedDependencies>org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies> | ||
<remappedArtifactAttached>true</remappedArtifactAttached> | ||
<remappedClassifierName>remapped-obf</remappedClassifierName> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>remap</goal> | ||
</goals> | ||
<id>remap-spigot</id> | ||
<configuration> | ||
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile> | ||
<srgIn>org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn> | ||
<remappedDependencies>org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
...or-nms-v1_19_R3/src/main/java/net/imprex/orebfuscator/nms/v1_19_R3/BlockStateWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.imprex.orebfuscator.nms.v1_19_R3; | ||
|
||
import org.bukkit.World; | ||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; | ||
|
||
import net.imprex.orebfuscator.nms.AbstractBlockState; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public class BlockStateWrapper extends AbstractBlockState<BlockState> { | ||
|
||
public BlockStateWrapper(int x, int y, int z, World world, BlockState state) { | ||
super(x, y, z, world, state); | ||
} | ||
|
||
@Override | ||
public int getBlockId() { | ||
return Block.getId(this.state); | ||
} | ||
|
||
@Override | ||
public void notifyBlockChange() { | ||
ServerLevel serverLevel = ((CraftWorld) this.world).getHandle(); | ||
serverLevel.getChunkSource().blockChanged(new BlockPos(this.getX(), this.getY(), this.getZ())); | ||
} | ||
} |
152 changes: 152 additions & 0 deletions
152
...bfuscator-nms-v1_19_R3/src/main/java/net/imprex/orebfuscator/nms/v1_19_R3/NmsManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package net.imprex.orebfuscator.nms.v1_19_R3; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; | ||
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; | ||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; | ||
import org.bukkit.entity.Player; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import net.imprex.orebfuscator.config.CacheConfig; | ||
import net.imprex.orebfuscator.config.Config; | ||
import net.imprex.orebfuscator.nms.AbstractBlockState; | ||
import net.imprex.orebfuscator.nms.AbstractNmsManager; | ||
import net.imprex.orebfuscator.nms.AbstractRegionFileCache; | ||
import net.imprex.orebfuscator.nms.ReadOnlyChunk; | ||
import net.imprex.orebfuscator.util.BlockProperties; | ||
import net.imprex.orebfuscator.util.BlockStateProperties; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.server.level.ServerChunkCache; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
|
||
public class NmsManager extends AbstractNmsManager { | ||
|
||
private static ServerLevel level(World world) { | ||
return ((CraftWorld) world).getHandle(); | ||
} | ||
|
||
private static ServerPlayer player(Player player) { | ||
return ((CraftPlayer) player).getHandle(); | ||
} | ||
|
||
private static boolean isChunkLoaded(ServerLevel level, int chunkX, int chunkZ) { | ||
return level.getChunkSource().isChunkLoaded(chunkX, chunkZ); | ||
} | ||
|
||
private static BlockState getBlockState(World world, int x, int y, int z, boolean loadChunk) { | ||
ServerLevel level = level(world); | ||
ServerChunkCache serverChunkCache = level.getChunkSource(); | ||
|
||
if (isChunkLoaded(level, x >> 4, z >> 4) || loadChunk) { | ||
// will load chunk if not loaded already | ||
LevelChunk chunk = serverChunkCache.getChunk(x >> 4, z >> 4, true); | ||
return chunk != null ? chunk.getBlockState(new BlockPos(x, y, z)) : null; | ||
} | ||
return null; | ||
} | ||
|
||
public NmsManager(Config config) { | ||
super(config); | ||
|
||
for (Map.Entry<ResourceKey<Block>, Block> entry : BuiltInRegistries.BLOCK.entrySet()) { | ||
String name = entry.getKey().location().toString(); | ||
Block block = entry.getValue(); | ||
|
||
ImmutableList<BlockState> possibleBlockStates = block.getStateDefinition().getPossibleStates(); | ||
List<BlockStateProperties> possibleBlockStateProperties = new ArrayList<>(); | ||
|
||
for (BlockState blockState : possibleBlockStates) { | ||
Material material = CraftBlockData.fromData(blockState).getMaterial(); | ||
|
||
BlockStateProperties properties = BlockStateProperties.builder(Block.getId(blockState)) | ||
.withIsAir(blockState.isAir()) | ||
// check if material is occluding and use blockData check for rare edge cases like barrier, spawner, slime_block, ... | ||
.withIsOccluding(material.isOccluding() && blockState.canOcclude()) | ||
.withIsBlockEntity(blockState.hasBlockEntity()) | ||
.build(); | ||
|
||
possibleBlockStateProperties.add(properties); | ||
this.registerBlockStateProperties(properties); | ||
} | ||
|
||
int defaultBlockStateId = Block.getId(block.defaultBlockState()); | ||
BlockStateProperties defaultBlockState = getBlockStateProperties(defaultBlockStateId); | ||
|
||
BlockProperties blockProperties = BlockProperties.builder(name) | ||
.withDefaultBlockState(defaultBlockState) | ||
.withPossibleBlockStates(ImmutableList.copyOf(possibleBlockStateProperties)) | ||
.build(); | ||
|
||
this.registerBlockProperties(blockProperties); | ||
} | ||
} | ||
|
||
@Override | ||
protected AbstractRegionFileCache<?> createRegionFileCache(CacheConfig cacheConfig) { | ||
return new RegionFileCache(cacheConfig); | ||
} | ||
|
||
@Override | ||
public int getMaxBitsPerBlock() { | ||
return Mth.ceillog2(Block.BLOCK_STATE_REGISTRY.size()); | ||
} | ||
|
||
@Override | ||
public int getTotalBlockCount() { | ||
return Block.BLOCK_STATE_REGISTRY.size(); | ||
} | ||
|
||
@Override | ||
public ReadOnlyChunk getReadOnlyChunk(World world, int chunkX, int chunkZ) { | ||
ServerChunkCache serverChunkCache = level(world).getChunkSource(); | ||
LevelChunk chunk = serverChunkCache.getChunk(chunkX, chunkZ, true); | ||
return new ReadOnlyChunkWrapper(chunk); | ||
} | ||
|
||
@Override | ||
public AbstractBlockState<?> getBlockState(World world, int x, int y, int z) { | ||
BlockState blockData = getBlockState(world, x, y, z, false); | ||
return blockData != null ? new BlockStateWrapper(x, y, z, world, blockData) : null; | ||
} | ||
|
||
@Override | ||
public boolean sendBlockChange(Player player, int x, int y, int z) { | ||
ServerPlayer serverPlayer = player(player); | ||
ServerLevel level = serverPlayer.getLevel(); | ||
if (!isChunkLoaded(level, x >> 4, z >> 4)) { | ||
return false; | ||
} | ||
|
||
BlockPos position = new BlockPos(x, y, z); | ||
ClientboundBlockUpdatePacket packet = new ClientboundBlockUpdatePacket(level, position); | ||
serverPlayer.connection.send(packet); | ||
updateBlockEntity(serverPlayer, position, packet.blockState); | ||
|
||
return true; | ||
} | ||
|
||
private void updateBlockEntity(ServerPlayer player, BlockPos position, BlockState blockData) { | ||
if (blockData.hasBlockEntity()) { | ||
ServerLevel serverLevel = player.getLevel(); | ||
BlockEntity blockEntity = serverLevel.getBlockEntity(position); | ||
if (blockEntity != null) { | ||
player.connection.send(blockEntity.getUpdatePacket()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.