mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 12:29:15 +00:00
修复1.20.1光照
This commit is contained in:
@@ -92,12 +92,27 @@ public class BukkitCustomBlock extends AbstractCustomBlock {
|
||||
BlockStateUtils.setHardness(mcBlockState, settings.hardness());
|
||||
BlockStateUtils.setPushReaction(mcBlockState, settings.pushReaction());
|
||||
BlockStateUtils.setReplaceable(mcBlockState, settings.replaceable());
|
||||
boolean canOcclude;
|
||||
if (settings.canOcclude() == Tristate.TRUE) {
|
||||
BlockStateUtils.setCanOcclude(mcBlockState, true);
|
||||
canOcclude = true;
|
||||
} else if (settings.canOcclude() == Tristate.FALSE) {
|
||||
BlockStateUtils.setCanOcclude(mcBlockState, false);
|
||||
canOcclude = false;
|
||||
} else {
|
||||
BlockStateUtils.setCanOcclude(mcBlockState, BlockStateUtils.isOcclude(state.vanillaBlockState().handle()));
|
||||
canOcclude = BlockStateUtils.isOcclude(state.vanillaBlockState().handle());
|
||||
BlockStateUtils.setCanOcclude(mcBlockState, canOcclude);
|
||||
}
|
||||
boolean useShapeForLightOcclusion;
|
||||
if (settings.useShapeForLightOcclusion() == Tristate.TRUE) {
|
||||
BlockStateUtils.setUseShapeForLightOcclusion(mcBlockState, true);
|
||||
useShapeForLightOcclusion = true;
|
||||
} else if (settings.useShapeForLightOcclusion() == Tristate.FALSE) {
|
||||
BlockStateUtils.setUseShapeForLightOcclusion(mcBlockState, false);
|
||||
useShapeForLightOcclusion = false;
|
||||
} else {
|
||||
useShapeForLightOcclusion = CoreReflections.field$BlockStateBase$useShapeForLightOcclusion.getBoolean(state.vanillaBlockState().handle());
|
||||
BlockStateUtils.setUseShapeForLightOcclusion(mcBlockState, useShapeForLightOcclusion);
|
||||
}
|
||||
if (settings.isRedstoneConductor() == Tristate.TRUE) {
|
||||
BlockStateUtils.setIsRedstoneConductor(mcBlockState, ALWAYS_TRUE);
|
||||
@@ -144,15 +159,39 @@ public class BukkitCustomBlock extends AbstractCustomBlock {
|
||||
// set block side properties
|
||||
CoreReflections.field$BlockBehaviour$explosionResistance.set(mcBlock, settings.resistance());
|
||||
CoreReflections.field$BlockBehaviour$soundType.set(mcBlock, SoundUtils.toSoundType(settings.sounds()));
|
||||
// 1.21.2以前要在init cache之前设定 isConditionallyFullOpaque
|
||||
if (!VersionHelper.isOrAbove1_21_2()) {
|
||||
boolean isConditionallyFullOpaque = canOcclude & useShapeForLightOcclusion;
|
||||
CoreReflections.field$BlockStateBase$isConditionallyFullOpaque.set(mcBlockState, isConditionallyFullOpaque);
|
||||
}
|
||||
// init cache
|
||||
CoreReflections.method$BlockStateBase$initCache.invoke(mcBlockState);
|
||||
// set block light
|
||||
int blockLight = settings.blockLight() != -1 ? settings.blockLight() : CoreReflections.field$BlockStateBase$lightBlock.getInt(state.vanillaBlockState().handle());
|
||||
// modify cache
|
||||
if (VersionHelper.isOrAbove1_21_2()) {
|
||||
int blockLight = settings.blockLight() != -1 ? settings.blockLight() : CoreReflections.field$BlockStateBase$lightBlock.getInt(state.vanillaBlockState().handle());
|
||||
// set block light
|
||||
CoreReflections.field$BlockStateBase$lightBlock.set(mcBlockState, blockLight);
|
||||
// set propagates skylight
|
||||
if (settings.propagatesSkylightDown() == Tristate.TRUE) {
|
||||
CoreReflections.field$BlockStateBase$propagatesSkylightDown.set(mcBlockState, true);
|
||||
} else if (settings.propagatesSkylightDown() == Tristate.FALSE) {
|
||||
CoreReflections.field$BlockStateBase$propagatesSkylightDown.set(mcBlockState, false);
|
||||
} else {
|
||||
CoreReflections.field$BlockStateBase$propagatesSkylightDown.set(mcBlockState, CoreReflections.field$BlockStateBase$propagatesSkylightDown.getBoolean(state.vanillaBlockState().handle()));
|
||||
}
|
||||
} else {
|
||||
Object cache = CoreReflections.field$BlockStateBase$cache.get(mcBlockState);
|
||||
int blockLight = settings.blockLight() != -1 ? settings.blockLight() : CoreReflections.field$BlockStateBase$Cache$lightBlock.getInt(CoreReflections.field$BlockStateBase$cache.get(state.vanillaBlockState().handle()));
|
||||
// set block light
|
||||
CoreReflections.field$BlockStateBase$Cache$lightBlock.set(cache, blockLight);
|
||||
// set propagates skylight
|
||||
if (settings.propagatesSkylightDown() == Tristate.TRUE) {
|
||||
CoreReflections.field$BlockStateBase$Cache$propagatesSkylightDown.set(cache, true);
|
||||
} else if (settings.propagatesSkylightDown() == Tristate.FALSE) {
|
||||
CoreReflections.field$BlockStateBase$Cache$propagatesSkylightDown.set(cache, false);
|
||||
} else {
|
||||
CoreReflections.field$BlockStateBase$Cache$propagatesSkylightDown.set(cache, CoreReflections.field$BlockStateBase$Cache$propagatesSkylightDown.getBoolean(CoreReflections.field$BlockStateBase$cache.get(state.vanillaBlockState().handle())));
|
||||
}
|
||||
}
|
||||
// set fluid later
|
||||
if (settings.fluidState()) {
|
||||
@@ -162,8 +201,6 @@ public class BukkitCustomBlock extends AbstractCustomBlock {
|
||||
}
|
||||
// set random tick later
|
||||
BlockStateUtils.setIsRandomlyTicking(mcBlockState, settings.isRandomlyTicking());
|
||||
// set propagates skylight
|
||||
BlockStateUtils.setPropagatesSkylightDown(mcBlockState, settings.propagatesSkylightDown());
|
||||
// bind tags
|
||||
Object holder = BukkitCraftEngine.instance().blockManager().getMinecraftBlockHolder(state.customBlockState().registryId());
|
||||
Set<Object> tags = new HashSet<>();
|
||||
|
||||
@@ -1252,6 +1252,10 @@ public final class CoreReflections {
|
||||
ReflectionUtils.getDeclaredField(clazz$BlockStateBase, float.class, 0)
|
||||
);
|
||||
|
||||
public static final Field field$BlockStateBase$useShapeForLightOcclusion = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$BlockStateBase, boolean.class, 0)
|
||||
);
|
||||
|
||||
public static final Field field$BlockStateBase$burnable = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$BlockStateBase, boolean.class, 2)
|
||||
);
|
||||
@@ -1260,10 +1264,20 @@ public final class CoreReflections {
|
||||
ReflectionUtils.getDeclaredField(clazz$BlockStateBase, boolean.class, 9)
|
||||
);
|
||||
|
||||
// 1.21.2以前用
|
||||
public static final Field field$BlockStateBase$isConditionallyFullOpaque = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$BlockStateBase, boolean.class, VersionHelper.isOrAbove1_21() ? 10 : 11)
|
||||
);
|
||||
|
||||
// 1.21.2+,其他版本在cache里
|
||||
public static final Field field$BlockStateBase$propagatesSkylightDown = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$BlockStateBase, boolean.class, 11)
|
||||
);
|
||||
|
||||
public static final Field field$BlockStateBase$Cache$propagatesSkylightDown = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$BlockStateBase$Cache, boolean.class, 2)
|
||||
);
|
||||
|
||||
public static final Field field$BlockStateBase$requiresCorrectToolForDrops = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$BlockStateBase, boolean.class, 5)
|
||||
);
|
||||
|
||||
@@ -197,6 +197,10 @@ public class BlockStateUtils {
|
||||
CoreReflections.field$BlockStateBase$burnable.set(state, burnable);
|
||||
}
|
||||
|
||||
public static void setUseShapeForLightOcclusion(Object state, boolean useShapeForLightOcclusion) throws ReflectiveOperationException {
|
||||
CoreReflections.field$BlockStateBase$useShapeForLightOcclusion.set(state, useShapeForLightOcclusion);
|
||||
}
|
||||
|
||||
public static void setPushReaction(Object state, PushReaction reaction) throws ReflectiveOperationException {
|
||||
Object pushReaction = ((Object[]) CoreReflections.method$PushReaction$values.invoke(null))[reaction.ordinal()];
|
||||
CoreReflections.field$BlockStateBase$pushReaction.set(state, pushReaction);
|
||||
@@ -206,10 +210,6 @@ public class BlockStateUtils {
|
||||
CoreReflections.field$BlockStateBase$isRandomlyTicking.set(state, randomlyTicking);
|
||||
}
|
||||
|
||||
public static void setPropagatesSkylightDown(Object state, boolean propagatesSkylightDown) throws ReflectiveOperationException {
|
||||
CoreReflections.field$BlockStateBase$propagatesSkylightDown.set(state, propagatesSkylightDown);
|
||||
}
|
||||
|
||||
public static void setReplaceable(Object state, boolean replaceable) throws ReflectiveOperationException {
|
||||
CoreReflections.field$BlockStateBase$replaceable.set(state, replaceable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user