Skip to content

Commit

Permalink
Config Modify
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Feb 17, 2025
1 parent e58f636 commit a55a620
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Old BlockEntity behaviour


diff --git a/net/minecraft/world/level/block/ChiseledBookShelfBlock.java b/net/minecraft/world/level/block/ChiseledBookShelfBlock.java
index 1411c6b0471281827b9d21958c0c7d962809898f..14da3105d094e7c701e20e57e49bdb4b1791d3fd 100644
index 1411c6b0471281827b9d21958c0c7d962809898f..2aa08b7da25f159640e0640482d40c69b060bb9f 100644
--- a/net/minecraft/world/level/block/ChiseledBookShelfBlock.java
+++ b/net/minecraft/world/level/block/ChiseledBookShelfBlock.java
@@ -192,7 +192,14 @@ public class ChiseledBookShelfBlock extends BaseEntityBlock {
Expand All @@ -14,7 +14,7 @@ index 1411c6b0471281827b9d21958c0c7d962809898f..14da3105d094e7c701e20e57e49bdb4b
chiseledBookShelfBlockEntity.clearContent();
- flag = true;
+ // Leaves start - behaviour 1.21.1-
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldBlockEntityBehaviour) {
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.updater.oldBlockEntityBehaviour) {
+ flag = false;
+ level.updateNeighbourForOutputSignal(pos, this);
+ } else {
Expand All @@ -25,66 +25,66 @@ index 1411c6b0471281827b9d21958c0c7d962809898f..14da3105d094e7c701e20e57e49bdb4b
flag = false;
}
diff --git a/net/minecraft/world/level/block/LecternBlock.java b/net/minecraft/world/level/block/LecternBlock.java
index 82fcae1f8b4149f13adf5118287718812518f8bf..8d5f555421c5856ef8af36136b275c03e4b0a25f 100644
index 82fcae1f8b4149f13adf5118287718812518f8bf..d6e4e2f9d762d512d22a4da3736f997d2cd9624d 100644
--- a/net/minecraft/world/level/block/LecternBlock.java
+++ b/net/minecraft/world/level/block/LecternBlock.java
@@ -237,10 +237,11 @@ public class LecternBlock extends BaseEntityBlock {
this.popBook(state, level, pos);
}

- super.onRemove(state, level, pos, newState, isMoving);
+ if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, isMoving); // Leaves - behaviour 1.21.1-
+ if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.updater.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, isMoving); // Leaves - behaviour 1.21.1-
if (state.getValue(POWERED)) {
updateBelow(level, pos, state);
}
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, isMoving); // Leaves - behaviour 1.21.1-
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.updater.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, isMoving); // Leaves - behaviour 1.21.1-
}
}

diff --git a/net/minecraft/world/level/block/SculkSensorBlock.java b/net/minecraft/world/level/block/SculkSensorBlock.java
index 2fd1bae800b7dca0a58b572095e2c58012412481..bec8053c0f0cb5dad19b1d1e3a03dff7fd76f5eb 100644
index 2fd1bae800b7dca0a58b572095e2c58012412481..237e5a48dc345cae90aa9921251fe48d1c2470e1 100644
--- a/net/minecraft/world/level/block/SculkSensorBlock.java
+++ b/net/minecraft/world/level/block/SculkSensorBlock.java
@@ -138,10 +138,11 @@ public class SculkSensorBlock extends BaseEntityBlock implements SimpleWaterlogg
@Override
protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
if (!state.is(newState.getBlock())) {
- super.onRemove(state, level, pos, newState, movedByPiston);
+ if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, movedByPiston); // Leaves - behaviour 1.21.1-
+ if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.updater.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, movedByPiston); // Leaves - behaviour 1.21.1-
if (getPhase(state) == SculkSensorPhase.ACTIVE) {
updateNeighbours(level, pos, state);
}
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, movedByPiston); // Leaves - behaviour 1.21.1-
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.updater.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, movedByPiston); // Leaves - behaviour 1.21.1-
}
}

diff --git a/net/minecraft/world/level/block/ShulkerBoxBlock.java b/net/minecraft/world/level/block/ShulkerBoxBlock.java
index fca50f68625050daabcae3a3b615cf88cce41111..64a93d68418fbc2228e4de09e2b288e0db503e5c 100644
index fca50f68625050daabcae3a3b615cf88cce41111..a5786b13f21781c2e85a6a7910ce42005f8951c8 100644
--- a/net/minecraft/world/level/block/ShulkerBoxBlock.java
+++ b/net/minecraft/world/level/block/ShulkerBoxBlock.java
@@ -178,10 +178,11 @@ public class ShulkerBoxBlock extends BaseEntityBlock {
protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
if (!state.is(newState.getBlock())) {
BlockEntity blockEntity = level.getBlockEntity(pos);
- super.onRemove(state, level, pos, newState, isMoving);
+ if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, isMoving); // Leaves - behaviour 1.21.1-
+ if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.updater.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, isMoving); // Leaves - behaviour 1.21.1-
if (blockEntity instanceof ShulkerBoxBlockEntity) {
level.updateNeighbourForOutputSignal(pos, state.getBlock());
}
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, isMoving); // Leaves - behaviour 1.21.1-
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.updater.oldBlockEntityBehaviour) super.onRemove(state, level, pos, newState, isMoving); // Leaves - behaviour 1.21.1-
}
}

diff --git a/net/minecraft/world/level/block/entity/BlockEntity.java b/net/minecraft/world/level/block/entity/BlockEntity.java
index 77618757c0e678532dbab814aceed83f7f1cd892..6c6fad160cf206bca2b37a7bbe2a69b508ecac7d 100644
index 77618757c0e678532dbab814aceed83f7f1cd892..fa78fc79b6000832d8623e632d845cf942496428 100644
--- a/net/minecraft/world/level/block/entity/BlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BlockEntity.java
@@ -55,7 +55,7 @@ public abstract class BlockEntity {
}

public boolean isValidBlockState(BlockState state) {
- return this.type.isValid(state);
+ return org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldBlockEntityBehaviour || this.type.isValid(state); // Leaves - behaviour 1.21.1-
+ return org.leavesmc.leaves.LeavesConfig.modify.oldMC.updater.oldBlockEntityBehaviour || this.type.isValid(state); // Leaves - behaviour 1.21.1-
}

public static BlockPos getPosFromTag(CompoundTag tag) {
49 changes: 22 additions & 27 deletions leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ public void verify(Boolean old, Boolean value) throws IllegalArgumentException {
}
}

@RemovedConfig(name = "unable-fakeplayer-names", category = "fakeplayer", convert = ListConfigValidator.STRING.class, transform = true)
@GlobalConfig(value = "unable-fakeplayer-names", validator = ListConfigValidator.STRING.class)
@RemovedConfig(name = "unable-fakeplayer-names", category = "fakeplayer", transform = true)
@GlobalConfig(value = "unable-fakeplayer-names")
public List<String> unableNames = List.of("player-name");

@GlobalConfig(value = "limit", validator = IntConfigValidator.class)
@GlobalConfig(value = "limit")
public int limit = 10;

@GlobalConfig(value = "prefix", validator = StringConfigValidator.class)
@GlobalConfig(value = "prefix")
public String prefix = "";

@GlobalConfig(value = "suffix", validator = StringConfigValidator.class)
@GlobalConfig(value = "suffix")
public String suffix = "";

@GlobalConfig(value = "regen-amount", validator = RegenAmountValidator.class)
Expand Down Expand Up @@ -196,6 +196,10 @@ public static class BlockUpdaterConfig {
@RemovedConfig(name = "redstone-wire-dont-connect-if-on-trapdoor", category = {"modify", "minecraft-old"}, transform = true)
@GlobalConfig("redstone-wire-dont-connect-if-on-trapdoor")
public boolean redstoneDontCantOnTrapDoor = false;

@RemovedConfig(name = "old-block-entity-behaviour", category = {"modify", "minecraft-old"}, transform = true)
@GlobalConfig("old-block-entity-behaviour")
public boolean oldBlockEntityBehaviour = false;
}

@RemovedConfig(name = "shears-in-dispenser-can-zero-amount", category = {}, transform = true)
Expand Down Expand Up @@ -252,9 +256,6 @@ public void verify(Boolean old, Boolean value) throws IllegalArgumentException {
@GlobalConfig("fix-fortress-mob-spawn")
public boolean fixFortressMobSpawn = false;

@GlobalConfig("old-block-entity-behaviour")
public boolean oldBlockEntityBehaviour = false;

@GlobalConfig("old-hopper-suck-in-behavior")
public boolean oldHopperSuckInBehavior = false;

Expand Down Expand Up @@ -283,19 +284,19 @@ public static class ElytraAeronauticsConfig {
@GlobalConfig("no-chunk-load")
public boolean noChunk = false;

@GlobalConfig(value = "no-chunk-height", validator = DoubleConfigValidator.class)
@GlobalConfig(value = "no-chunk-height")
public double noChunkHeight = 500.0D;

@GlobalConfig(value = "no-chunk-speed", validator = DoubleConfigValidator.class)
@GlobalConfig(value = "no-chunk-speed")
public double noChunkSpeed = -1.0D;

@GlobalConfig("message")
public boolean noChunkMes = true;

@GlobalConfig(value = "message-start", validator = StringConfigValidator.class)
@GlobalConfig(value = "message-start")
public String noChunkStartMes = "Flight enter cruise mode";

@GlobalConfig(value = "message-end", validator = StringConfigValidator.class)
@GlobalConfig(value = "message-end")
public String noChunkEndMes = "Flight exit cruise mode";
}

Expand Down Expand Up @@ -692,7 +693,7 @@ public void verify(Boolean old, Boolean value) throws IllegalArgumentException {
@GlobalConfig("quota")
public boolean useQuota = false;

@GlobalConfig(value = "quota-limit", validator = IntConfigValidator.class)
@GlobalConfig(value = "quota-limit")
public int quotaLimit = 40000000;
}

Expand All @@ -713,16 +714,13 @@ public void verify(Boolean old, Boolean value) throws IllegalArgumentException {
}
}

@RemovedConfig(name = "pca-sync-player-entity", category = "protocol", convert = PcaPlayerEntityValidator.class, transform = true)
@GlobalConfig(value = "pca-sync-player-entity", validator = PcaPlayerEntityValidator.class)
@RemovedConfig(name = "pca-sync-player-entity", category = "protocol", transform = true)
@GlobalConfig(value = "pca-sync-player-entity")
public PcaPlayerEntityType syncPlayerEntity = PcaPlayerEntityType.OPS;

public enum PcaPlayerEntityType {
NOBODY, BOT, OPS, OPS_AND_SELF, EVERYONE
}

private static class PcaPlayerEntityValidator extends EnumConfigValidator<PcaPlayerEntityType> {
}
}

public AppleSkinConfig appleskin = new AppleSkinConfig();
Expand Down Expand Up @@ -780,7 +778,7 @@ public void runAfterLoader(AlternativePlaceType value, boolean firstLoad) {
@GlobalConfig("xaero-map-protocol")
public boolean xaeroMapProtocol = false;

@GlobalConfig(value = "xaero-map-server-id", validator = IntConfigValidator.class)
@GlobalConfig(value = "xaero-map-server-id")
public int xaeroMapServerID = new Random().nextInt();

@GlobalConfig("leaves-carpet-support")
Expand Down Expand Up @@ -832,7 +830,7 @@ public List<String> valueSuggest() {
@GlobalConfig("allow-experimental")
public Boolean allowExperimental = false;

@GlobalConfig(value = "time", lock = true, validator = ListConfigValidator.STRING.class)
@GlobalConfig(value = "time", lock = true)
public List<String> updateTime = List.of("14:00", "2:00");
}

Expand Down Expand Up @@ -896,7 +894,7 @@ public List<String> valueSuggest() {
}
}

@GlobalConfig(value = "server-mod-name", validator = StringConfigValidator.class)
@GlobalConfig(value = "server-mod-name")
public String serverModName = "Leaves";

@GlobalConfig("bstats-privacy-mode")
Expand Down Expand Up @@ -929,16 +927,13 @@ public void verify(RegionFileFormat old, RegionFileFormat value) throws IllegalA
@GlobalConfigCategory("linear")
public static class LinearConfig {

@GlobalConfig(value = "version", lock = true, validator = LinearVersionValidator.class)
@GlobalConfig(value = "version", lock = true)
public org.leavesmc.leaves.region.linear.LinearVersion version = org.leavesmc.leaves.region.linear.LinearVersion.V2;

private static class LinearVersionValidator extends EnumConfigValidator<org.leavesmc.leaves.region.linear.LinearVersion> {
}

@GlobalConfig(value = "auto-convert-anvil-to-linear", lock = true)
public boolean autoConvertAnvilToLinear = false;

@GlobalConfig(value = "flush-max-threads", lock = true, validator = IntConfigValidator.class)
@GlobalConfig(value = "flush-max-threads", lock = true)
public int flushThreads = 6;

public int getLinearFlushThreads() {
Expand All @@ -949,7 +944,7 @@ public int getLinearFlushThreads() {
}
}

@GlobalConfig(value = "flush-delay-ms", lock = true, validator = IntConfigValidator.class)
@GlobalConfig(value = "flush-delay-ms", lock = true)
public int flushDelayMs = 100;

@GlobalConfig(value = "use-virtual-thread", lock = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.leavesmc.leaves.config;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;

public class AutoConfigTransformer implements ConfigTransformer<Object, Object> {

@NotNull
@Contract("_ -> new")
public static ConfigTransformer<?, ?> createValidator(@NotNull Field field) {
return new SimpleConfigTransformer(AutoConfigValidator.createValidator(field));
}

@Override
public Object transform(Object from) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public Object stringConvert(String value) throws IllegalArgumentException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public Class<Object> getFieldClass() {
throw new UnsupportedOperationException("Not supported yet.");
}

@SuppressWarnings({"unchecked", "rawtypes"})
public static class SimpleConfigTransformer implements ConfigTransformer<Object, Object> {

private final ConfigValidator validator;

public SimpleConfigTransformer(ConfigValidator<?> validator) {
this.validator = validator;
}

@Override
public Object transform(Object o) {
return o;
}

@Override
public Object stringConvert(String value) throws IllegalArgumentException {
return validator.stringConvert(value);
}

@Override
public Object loadConvert(Object value) throws IllegalArgumentException {
return validator.loadConvert(value);
}

@Override
public Object saveConvert(Object value) {
return validator.saveConvert(value);
}

@Override
public Class<Object> getFieldClass() {
return validator.getFieldClass();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.leavesmc.leaves.config;

import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

public final class AutoConfigValidator implements ConfigValidator<Object> {

private static final Map<Class<?>, Supplier<ConfigValidator<?>>> BASE_VALIDATOR = new HashMap<>();

static {
BASE_VALIDATOR.put(Boolean.class, ConfigValidatorImpl.BooleanConfigValidator::new);
BASE_VALIDATOR.put(boolean.class, ConfigValidatorImpl.BooleanConfigValidator::new);

BASE_VALIDATOR.put(Integer.class, ConfigValidatorImpl.IntConfigValidator::new);
BASE_VALIDATOR.put(int.class, ConfigValidatorImpl.IntConfigValidator::new);

BASE_VALIDATOR.put(Double.class, ConfigValidatorImpl.DoubleConfigValidator::new);
BASE_VALIDATOR.put(double.class, ConfigValidatorImpl.DoubleConfigValidator::new);

BASE_VALIDATOR.put(String.class, ConfigValidatorImpl.StringConfigValidator::new);
}

@SuppressWarnings({"unchecked", "rawtypes"})
public static ConfigValidator<?> createValidator(@NotNull Field field) {
Class<?> fieldType = field.getType();

if (BASE_VALIDATOR.containsKey(fieldType)) {
return BASE_VALIDATOR.get(fieldType).get();
}

if (List.class.isAssignableFrom(fieldType)) {
Type genericType = field.getGenericType();
if (genericType instanceof ParameterizedType parameterizedType) {
Type[] typeArgs = parameterizedType.getActualTypeArguments();
if (typeArgs.length > 0 && typeArgs[0] instanceof Class<?> genericClass) {
if (genericClass.equals(String.class)) {
return new ConfigValidatorImpl.ListConfigValidator.STRING();
}
throw new IllegalArgumentException("List type " + genericClass.getTypeName() + " is not supported.");
}
}
throw new IllegalArgumentException("List type " + genericType.getTypeName() + " is not supported.");
}

if (fieldType.isEnum()) {
return new ConfigValidatorImpl.EnumConfigValidator<>((Class<Enum>) fieldType);
}

throw new IllegalArgumentException("Can't find validator for type " + fieldType.getName());
}

@Override
public Object stringConvert(String value) throws IllegalArgumentException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public Class<Object> getFieldClass() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.leavesmc.leaves.config;

public interface ConfigConverter<E> {
E convert(String value) throws IllegalArgumentException;

E stringConvert(String value) throws IllegalArgumentException;

@SuppressWarnings("unchecked")
default E loadConvert(Object value) throws IllegalArgumentException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.leavesmc.leaves.config;

public interface ConfigTransformer<FROM, TO> extends ConfigConverter<FROM> {
TO transform(FROM from);
}
Loading

0 comments on commit a55a620

Please sign in to comment.