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

added block light

This commit is contained in:
XiaoMoMi
2025-03-25 04:29:22 +08:00
parent 6d45ae6cc3
commit 322cf1474d
6 changed files with 63 additions and 2 deletions

View File

@@ -722,6 +722,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
if (plugin.hasMod()) {
newRealBlock = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$BLOCK, resourceLocation);
newBlockState = getOnlyBlockState(newRealBlock);
@SuppressWarnings("unchecked")
Optional<Object> optionalHolder = (Optional<Object>) Reflections.method$Registry$getHolder0.invoke(Reflections.instance$BuiltInRegistries$BLOCK, resourceLocation);
blockHolder = optionalHolder.get();

View File

@@ -11,6 +11,7 @@ import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.Tristate;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.shared.ObjectHolder;
import net.momirealms.craftengine.shared.block.BlockBehavior;
import org.bukkit.inventory.ItemStack;
@@ -103,6 +104,15 @@ public class BukkitCustomBlock extends CustomBlock {
Reflections.field$BlockBehaviour$soundType.set(mcBlock, SoundUtils.toSoundType(settings.sounds()));
// init cache
Reflections.method$BlockStateBase$initCache.invoke(mcBlockState);
// set block light
if (settings.blockLight() != -1) {
if (VersionHelper.isVersionNewerThan1_21_2()) {
Reflections.field$BlockStateBase$lightBlock.set(mcBlockState, settings.blockLight());
} else {
Object cache = Reflections.field$BlockStateBase$cache.get(mcBlockState);
Reflections.field$BlockStateBase$Cache$lightBlock.set(cache, settings.blockLight());
}
}
// set fluid later
if (settings.fluidState()) {
Reflections.field$BlockStateBase$fluidState.set(mcBlockState, Reflections.method$FlowingFluid$getSource.invoke(Reflections.instance$Fluids$WATER, false));

View File

@@ -2225,6 +2225,25 @@ public class Reflections {
)
);
public static final Class<?> clazz$BlockStateBase$Cache = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("world.level.block.state.BlockBehaviour$BlockStateBase$Cache"),
BukkitReflectionUtils.assembleMCClass("world.level.block.state.BlockBase$BlockData$Cache")
)
);
public static final Field field$BlockStateBase$cache = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$BlockStateBase, clazz$BlockStateBase$Cache, 0
)
);
// 1.20-1.21.1
public static final Field field$BlockStateBase$Cache$lightBlock =
ReflectionUtils.getInstanceDeclaredField(
clazz$BlockStateBase$Cache, int.class, 0
);
public static final Method method$BlockStateBase$initCache = requireNonNull(
ReflectionUtils.getMethod(
clazz$BlockStateBase, void.class, new String[] { "initCache", "a" }
@@ -2309,6 +2328,12 @@ public class Reflections {
)
);
// 1.21.2+
public static final Field field$BlockStateBase$lightBlock =
ReflectionUtils.getInstanceDeclaredField(
clazz$BlockStateBase, int.class, 1
);
public static final Class<?> clazz$AABB = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("world.phys.AABB"),