9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

自定义哪些方块支持deceive

This commit is contained in:
XiaoMoMi
2025-10-23 21:31:38 +08:00
parent 21a89a818b
commit efb45c2325
4 changed files with 64 additions and 30 deletions

View File

@@ -31,6 +31,7 @@ import net.momirealms.craftengine.core.util.Tristate;
import net.momirealms.craftengine.core.util.VersionHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -416,19 +417,26 @@ public final class BukkitBlockManager extends AbstractBlockManager {
@SuppressWarnings("unchecked")
private void deceiveBukkitRegistry() {
try {
Material material;
try {
material = Material.valueOf(Config.deceiveBukkitMaterial().value().toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
this.plugin.logger().warn(Config.deceiveBukkitMaterial() + " is not a valid material", e);
material = Material.STONE;
}
if (!material.isBlock()) {
this.plugin.logger().warn(Config.deceiveBukkitMaterial() + " is not a valid bukkit block material");
material = Material.STONE;
}
Map<Object, Material> magicMap = (Map<Object, Material>) CraftBukkitReflections.field$CraftMagicNumbers$BLOCK_MATERIAL.get(null);
for (DelegatingBlock customBlock : this.customBlocks) {
Set<String> invalid = new HashSet<>();
for (int i = 0; i < this.customBlocks.length; i++) {
DelegatingBlock customBlock = this.customBlocks[i];
String value = Config.deceiveBukkitMaterial(i).value();
Material material;
try {
material = Material.valueOf(value.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
if (invalid.add(value)) {
this.plugin.logger().warn("Cannot load 'deceive-bukkit-material'. '" + value + "' is an invalid bukkit material", e);
}
material = Material.BRICKS;
}
if (!material.isBlock()) {
if (invalid.add(value)) {
this.plugin.logger().warn("Cannot load 'deceive-bukkit-material'. '" + value + "' is an invalid bukkit block material");
}
material = Material.BRICKS;
}
magicMap.put(customBlock, material);
}
} catch (ReflectiveOperationException e) {

View File

@@ -90,15 +90,15 @@ resource-pack:
# You should strive to make your resource pack more standardized after gaining some experience with resource packs.
fix-atlas: true
# Optimize your resource pack by reducing its size
optimization:
enable: true
png:
color-quantization: true
lossless-bit-depth: true
remove-metadata: true
model:
minimize: true
bypass-textures: []
# optimization:
# enable: true
# png:
# color-quantization: true
# lossless-bit-depth: true
# remove-metadata: true
# model:
# minimize: true
# bypass-textures: []
# Protect your resource pack from being cracked by others
protection:
# Prevent thieves from extracting your resource pack. These options will crash their software.
@@ -221,7 +221,7 @@ equipment:
block:
# This decides the amount of real blocks on serverside. You should only consider increasing this value when your server state is insufficient.
# It is recommended to increase it by 500 each time. This option requires a restart to apply.
# It is recommended to increase it by 1000 each time. This option requires a restart to apply.
serverside-blocks: 2000
# Enables the sound system, which prevents the client from hearing some non-custom block sounds and improves the client experience.
sound-system:
@@ -251,7 +251,14 @@ block:
extended-interaction-range: 0.5
# Defines the value returned by Bukkit block.getMaterial()
# If another plugin causes incompatibility due to its reliance on this method, try changing this option to a different vanilla block.
deceive-bukkit-material: stone
deceive-bukkit-material:
default: bricks
# The numbers here represent the internal real IDs of the blocks.
# This means that overriding certain blocks needs to be done under the condition of forcibly assigning internal IDs.
# A restart is required to apply the changes.
overrides:
0: bricks
1~8: bricks
furniture:
# Hide technical entities used for storing furniture metadata.

View File

@@ -126,7 +126,8 @@ public class Config {
protected int block$predict_breaking_interval;
protected double block$extended_interaction_range;
protected boolean block$chunk_relighter;
protected Key block$deceive_bukkit_material;
protected Key block$deceive_bukkit_material$default;
protected Map<Integer, Key> block$deceive_bukkit_material$overrides;
protected int block$serverside_blocks = -1;
protected boolean recipe$enable;
@@ -250,6 +251,7 @@ public class Config {
.addIgnoredRoute(PluginProperties.getValue("config"), "chunk-system.process-invalid-blocks.convert", '.')
.addIgnoredRoute(PluginProperties.getValue("config"), "chunk-system.process-invalid-furniture.convert", '.')
.addIgnoredRoute(PluginProperties.getValue("config"), "item.custom-model-data-starting-value.overrides", '.')
.addIgnoredRoute(PluginProperties.getValue("config"), "block.deceive-bukkit-material.overrides", '.')
.build());
}
try {
@@ -439,8 +441,25 @@ public class Config {
block$predict_breaking_interval = Math.max(config.getInt("block.predict-breaking.interval", 10), 1);
block$extended_interaction_range = Math.max(config.getDouble("block.predict-breaking.extended-interaction-range", 0.5), 0.0);
block$chunk_relighter = config.getBoolean("block.chunk-relighter", true);
block$deceive_bukkit_material = Key.of(config.getString("block.deceive-bukkit-material", "stone"));
if (firstTime) {
block$deceive_bukkit_material$default = Key.of(config.getString("block.deceive-bukkit-material.default", "bricks"));
block$deceive_bukkit_material$overrides = new HashMap<>();
Section overridesSection = config.getSection("block.deceive-bukkit-material.overrides");
if (overridesSection != null) {
for (Map.Entry<String, Object> entry : overridesSection.getStringRouteMappedValues(false).entrySet()) {
String key = entry.getKey();
Key value = Key.of(String.valueOf(entry.getValue()));
if (key.contains("~")) {
int min = Integer.parseInt(key.split("~")[0]);
int max = Integer.parseInt(key.split("~")[1]);
for (int i = min; i <= max; i++) {
block$deceive_bukkit_material$overrides.put(i, value);
}
} else {
block$deceive_bukkit_material$overrides.put(Integer.valueOf(key), value);
}
}
}
block$serverside_blocks = Math.min(config.getInt("block.serverside-blocks", 2000), 10_0000);
if (block$serverside_blocks < 0) block$serverside_blocks = 0;
}
@@ -774,8 +793,8 @@ public class Config {
return instance.resource_pack$protection$obfuscation$resource_location$bypass_equipments;
}
public static Key deceiveBukkitMaterial() {
return instance.block$deceive_bukkit_material;
public static Key deceiveBukkitMaterial(int id) {
return instance.block$deceive_bukkit_material$overrides.getOrDefault(id, instance.block$deceive_bukkit_material$default);
}
public static boolean generateModAssets() {

View File

@@ -2,9 +2,9 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.64.19
config_version=49
lang_version=35
project_version=0.0.64.20
config_version=50
lang_version=36
project_group=net.momirealms
latest_supported_version=1.21.10