Skip to content

Commit

Permalink
[#276] Add support for 1.19.4 (#277)
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
Ingrim4 authored Mar 15, 2023
1 parent b240a5d commit 7142876
Show file tree
Hide file tree
Showing 22 changed files with 539 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/buildtools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ checkVersion "1.17.1" "17"
checkVersion "1.18.1" "17"
checkVersion "1.18.2" "17"
checkVersion "1.19" "17"
checkVersion "1.19.3" "17"
checkVersion "1.19.3" "17"
checkVersion "1.19.4" "17"
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<img align="right" src="https://user-images.githubusercontent.com/8127996/90168671-bb49c780-dd9d-11ea-989d-479f8c1f3ea3.png" height="200" width="200">

# Orebfuscator - Anti X-Ray
Expand All @@ -15,7 +14,7 @@ Orebfuscator is plugin for Spigot based Minecraft Servers that modifies packets
* Make blocks in a players proximity visible based on their distance an

### Requirements
- Java 8 or higher
- Java 17 or higher
- Spigot and (proably) any other fork of Spigot (1.9.4 or higher)
- [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997) 4.0 or higher

Expand Down Expand Up @@ -48,8 +47,8 @@ Still having trouble getting Orebfuscator to run check out our [common issues](h

## License:

Almost completely rewritten by Imprex-Development to support v1.14 and higher Minecraft version's; these portions as permissible:
Copyright (C) 2020-2022 by Imprex-Development. All rights reserved.
Completely rewritten by Imprex-Development to support v1.14 and higher Minecraft version's; these portions as permissible:
Copyright (C) 2020-2023 by Imprex-Development. All rights reserved.

Released under the same license as original.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public interface WorldConfigBundle {

boolean needsObfuscation();

boolean skipReadSectionIndex(int index);

boolean skipProcessingSectionIndex(int index);

int minSectionIndex();

int maxSectionIndex();
Expand Down
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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,35 @@ public final class MinecraftVersion {

private static final Pattern VERSION_PATTERN = Pattern.compile("org\\.bukkit\\.craftbukkit\\.(v(\\d+)_(\\d+)_R(\\d+))");

private final String nmsVersion;
private final int majorVersion;
private final int minorVersion;
private static final String NMS_VERSION;
private static final int MAJOR_VERSION;
private static final int MINOR_VERSION;

private MinecraftVersion() {
static {
String craftBukkitPackage = Bukkit.getServer().getClass().getPackage().getName();
Matcher matcher = VERSION_PATTERN.matcher(craftBukkitPackage);

if (!matcher.find()) {
throw new RuntimeException("Can't parse craftbukkit package version " + craftBukkitPackage);
}

this.nmsVersion = matcher.group(1);
this.majorVersion = Integer.parseInt(matcher.group(2));
this.minorVersion = Integer.parseInt(matcher.group(3));
NMS_VERSION = matcher.group(1);
MAJOR_VERSION = Integer.parseInt(matcher.group(2));
MINOR_VERSION = Integer.parseInt(matcher.group(3));
}

private static final MinecraftVersion VERSION = new MinecraftVersion();
public static String nmsVersion() {
return NMS_VERSION;
}

public static String getNmsVersion() {
return VERSION.nmsVersion;
public static int majorVersion() {
return MAJOR_VERSION;
}

public static int getMajorVersion() {
return VERSION.majorVersion;
public static int minorVersion() {
return MINOR_VERSION;
}

public static int getMinorVersion() {
return VERSION.minorVersion;
private MinecraftVersion() {
}
}
72 changes: 72 additions & 0 deletions orebfuscator-nms/orebfuscator-nms-v1_19_R3/pom.xml
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>
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()));
}
}
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());
}
}
}
}
Loading

0 comments on commit 7142876

Please sign in to comment.