mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
添加多方块数据包生成支持
This commit is contained in:
@@ -184,6 +184,11 @@ public class DoorBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
|||||||
immutableBlockState.ifPresent(state -> FastNMS.INSTANCE.method$LevelWriter$setBlock(args[0], LocationUtils.above(pos), state.with(this.halfProperty, DoubleBlockHalf.UPPER).customBlockState().literalObject(), UpdateOption.UPDATE_ALL.flags()));
|
immutableBlockState.ifPresent(state -> FastNMS.INSTANCE.method$LevelWriter$setBlock(args[0], LocationUtils.above(pos), state.with(this.halfProperty, DoubleBlockHalf.UPPER).customBlockState().literalObject(), UpdateOption.UPDATE_ALL.flags()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMultiState(ImmutableBlockState baseState) {
|
||||||
|
return baseState.get(this.halfProperty) == DoubleBlockHalf.LOWER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableBlockState updateStateForPlacement(BlockPlaceContext context, ImmutableBlockState state) {
|
public ImmutableBlockState updateStateForPlacement(BlockPlaceContext context, ImmutableBlockState state) {
|
||||||
World world = context.getLevel();
|
World world = context.getLevel();
|
||||||
|
|||||||
@@ -117,6 +117,11 @@ public class DoubleHighBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
|||||||
immutableBlockState.ifPresent(state -> FastNMS.INSTANCE.method$LevelWriter$setBlock(args[0], LocationUtils.above(pos), state.with(this.halfProperty, DoubleBlockHalf.UPPER).customBlockState().literalObject(), UpdateOption.UPDATE_ALL.flags()));
|
immutableBlockState.ifPresent(state -> FastNMS.INSTANCE.method$LevelWriter$setBlock(args[0], LocationUtils.above(pos), state.with(this.halfProperty, DoubleBlockHalf.UPPER).customBlockState().literalObject(), UpdateOption.UPDATE_ALL.flags()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMultiState(ImmutableBlockState baseState) {
|
||||||
|
return baseState.get(this.halfProperty) == DoubleBlockHalf.LOWER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlaceMultiState(BlockAccessor accessor, BlockPos pos, ImmutableBlockState state) {
|
public boolean canPlaceMultiState(BlockAccessor accessor, BlockPos pos, ImmutableBlockState state) {
|
||||||
if (pos.y() >= accessor.worldHeight().getMaxBuildHeight() - 1) {
|
if (pos.y() >= accessor.worldHeight().getMaxBuildHeight() - 1) {
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ public class UnsafeCompositeBlockBehavior extends BukkitBlockBehavior
|
|||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getContainer(Object thisBlock, Object[] args) throws Exception {
|
public Object getContainer(Object thisBlock, Object[] args) throws Exception {
|
||||||
for (AbstractBlockBehavior behavior : this.behaviors) {
|
for (AbstractBlockBehavior behavior : this.behaviors) {
|
||||||
@@ -411,4 +410,14 @@ public class UnsafeCompositeBlockBehavior extends BukkitBlockBehavior
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMultiState(ImmutableBlockState baseState) {
|
||||||
|
for (AbstractBlockBehavior behavior : this.behaviors) {
|
||||||
|
if (behavior.hasMultiState(baseState)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,11 @@ public class BukkitCraftEngine extends CraftEngine {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new InjectionException("Error injecting loot entries", e);
|
throw new InjectionException("Error injecting loot entries", e);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
FeatureInjector.init();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new InjectionException("Error injecting features", e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
BlockStateProviderInjector.init();
|
BlockStateProviderInjector.init();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import java.util.Set;
|
|||||||
|
|
||||||
public final class BlockStateProviderInjector {
|
public final class BlockStateProviderInjector {
|
||||||
|
|
||||||
|
private BlockStateProviderInjector() {}
|
||||||
|
|
||||||
public static void init() throws ReflectiveOperationException {
|
public static void init() throws ReflectiveOperationException {
|
||||||
CoreReflections.field$MappedRegistry$frozen.set(MBuiltInRegistries.BLOCKSTATE_PROVIDER_TYPE, false);
|
CoreReflections.field$MappedRegistry$frozen.set(MBuiltInRegistries.BLOCKSTATE_PROVIDER_TYPE, false);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package net.momirealms.craftengine.bukkit.plugin.injector;
|
||||||
|
|
||||||
|
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||||
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||||
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;
|
||||||
|
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||||
|
import net.momirealms.craftengine.core.util.Key;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public final class FeatureInjector {
|
||||||
|
|
||||||
|
private FeatureInjector() {}
|
||||||
|
|
||||||
|
public static void init() throws ReflectiveOperationException {
|
||||||
|
Object registry = MBuiltInRegistries.FEATURE;
|
||||||
|
CoreReflections.field$MappedRegistry$frozen.set(registry, false);
|
||||||
|
Object resourceLocation = KeyUtils.toResourceLocation(Key.of("craftengine:simple_block"));
|
||||||
|
Object type = FastNMS.INSTANCE.getCraftEngineCustomSimpleBlockFeature();
|
||||||
|
Object holder = CoreReflections.method$Registry$registerForHolder.invoke(null, registry, resourceLocation, type);
|
||||||
|
CoreReflections.method$Holder$Reference$bindValue.invoke(holder, type);
|
||||||
|
CoreReflections.field$Holder$Reference$tags.set(holder, Set.of());
|
||||||
|
CoreReflections.field$MappedRegistry$frozen.set(registry, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,8 @@ import java.lang.reflect.Modifier;
|
|||||||
public final class ProtectedFieldVisitor {
|
public final class ProtectedFieldVisitor {
|
||||||
private static FieldAccessor internalFieldAccessor;
|
private static FieldAccessor internalFieldAccessor;
|
||||||
|
|
||||||
|
private ProtectedFieldVisitor() {}
|
||||||
|
|
||||||
public static void init() throws ReflectiveOperationException {
|
public static void init() throws ReflectiveOperationException {
|
||||||
ByteBuddy byteBuddy = new ByteBuddy(ClassFileVersion.JAVA_V17);
|
ByteBuddy byteBuddy = new ByteBuddy(ClassFileVersion.JAVA_V17);
|
||||||
// InternalFieldAccessor Interface
|
// InternalFieldAccessor Interface
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public final class RecipeInjector {
|
|||||||
private static Class<?> clazz$InjectedRepairItemRecipe;
|
private static Class<?> clazz$InjectedRepairItemRecipe;
|
||||||
private static Class<?> clazz$InjectedFireworkStarFadeRecipe;
|
private static Class<?> clazz$InjectedFireworkStarFadeRecipe;
|
||||||
|
|
||||||
|
private RecipeInjector() {}
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
ByteBuddy byteBuddy = new ByteBuddy(ClassFileVersion.JAVA_V17);
|
ByteBuddy byteBuddy = new ByteBuddy(ClassFileVersion.JAVA_V17);
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ public final class WorldStorageInjector {
|
|||||||
private static Class<?> clazz$InjectedPalettedContainer;
|
private static Class<?> clazz$InjectedPalettedContainer;
|
||||||
private static MethodHandle constructor$InjectedLevelChunkSection;
|
private static MethodHandle constructor$InjectedLevelChunkSection;
|
||||||
|
|
||||||
|
private WorldStorageInjector() {}
|
||||||
|
|
||||||
public static void init() throws ReflectiveOperationException {
|
public static void init() throws ReflectiveOperationException {
|
||||||
ByteBuddy byteBuddy = new ByteBuddy(ClassFileVersion.JAVA_V17);
|
ByteBuddy byteBuddy = new ByteBuddy(ClassFileVersion.JAVA_V17);
|
||||||
// Paletted Container
|
// Paletted Container
|
||||||
|
|||||||
@@ -639,7 +639,6 @@ public final class CoreReflections {
|
|||||||
), VersionHelper.isOrAbove1_21_5());
|
), VersionHelper.isOrAbove1_21_5());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final Method method$Registry$getId = requireNonNull(
|
public static final Method method$Registry$getId = requireNonNull(
|
||||||
ReflectionUtils.getMethod(clazz$Registry, int.class, Object.class)
|
ReflectionUtils.getMethod(clazz$Registry, int.class, Object.class)
|
||||||
);
|
);
|
||||||
@@ -4566,4 +4565,11 @@ public final class CoreReflections {
|
|||||||
"world.level.levelgen.feature.stateproviders.BlockStateProviderType"
|
"world.level.levelgen.feature.stateproviders.BlockStateProviderType"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static final Class<?> clazz$Feature = requireNonNull(
|
||||||
|
BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||||
|
"world.level.levelgen.feature.WorldGenerator",
|
||||||
|
"world.level.levelgen.feature.Feature"
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public final class MBuiltInRegistries {
|
|||||||
public static final Object LOOT_POOL_ENTRY_TYPE;
|
public static final Object LOOT_POOL_ENTRY_TYPE;
|
||||||
public static final Object GAME_EVENT;
|
public static final Object GAME_EVENT;
|
||||||
public static final Object BLOCKSTATE_PROVIDER_TYPE;
|
public static final Object BLOCKSTATE_PROVIDER_TYPE;
|
||||||
|
public static final Object FEATURE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Field[] fields = CoreReflections.clazz$BuiltInRegistries.getDeclaredFields();
|
Field[] fields = CoreReflections.clazz$BuiltInRegistries.getDeclaredFields();
|
||||||
@@ -46,6 +47,7 @@ public final class MBuiltInRegistries {
|
|||||||
Object registries$LootPoolEntryType = null;
|
Object registries$LootPoolEntryType = null;
|
||||||
Object registries$GameEvent = null;
|
Object registries$GameEvent = null;
|
||||||
Object registries$BlockStateProviderType = null;
|
Object registries$BlockStateProviderType = null;
|
||||||
|
Object registries$Feature = null;
|
||||||
|
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
Type fieldType = field.getGenericType();
|
Type fieldType = field.getGenericType();
|
||||||
@@ -63,6 +65,8 @@ public final class MBuiltInRegistries {
|
|||||||
registries$BlockEntityType = field.get(null);
|
registries$BlockEntityType = field.get(null);
|
||||||
} else if (rawType == CoreReflections.clazz$BlockStateProviderType) {
|
} else if (rawType == CoreReflections.clazz$BlockStateProviderType) {
|
||||||
registries$BlockStateProviderType = field.get(null);
|
registries$BlockStateProviderType = field.get(null);
|
||||||
|
} else if (rawType == CoreReflections.clazz$Feature) {
|
||||||
|
registries$Feature = field.get(null);
|
||||||
} else if (VersionHelper.isOrAbove1_20_5() && rawType == CoreReflections.clazz$DataComponentType && registries$DataComponentType == null) {
|
} else if (VersionHelper.isOrAbove1_20_5() && rawType == CoreReflections.clazz$DataComponentType && registries$DataComponentType == null) {
|
||||||
registries$DataComponentType = field.get(null);
|
registries$DataComponentType = field.get(null);
|
||||||
} else if (VersionHelper.isOrAbove1_21_5() && rawType == CoreReflections.clazz$DataComponentPredicate$Type) {
|
} else if (VersionHelper.isOrAbove1_21_5() && rawType == CoreReflections.clazz$DataComponentPredicate$Type) {
|
||||||
@@ -103,6 +107,7 @@ public final class MBuiltInRegistries {
|
|||||||
DATA_COMPONENT_TYPE = registries$DataComponentType;
|
DATA_COMPONENT_TYPE = registries$DataComponentType;
|
||||||
GAME_EVENT = requireNonNull(registries$GameEvent);
|
GAME_EVENT = requireNonNull(registries$GameEvent);
|
||||||
BLOCKSTATE_PROVIDER_TYPE = requireNonNull(registries$BlockStateProviderType);
|
BLOCKSTATE_PROVIDER_TYPE = requireNonNull(registries$BlockStateProviderType);
|
||||||
|
FEATURE = requireNonNull(registries$Feature);
|
||||||
DATA_COMPONENT_PREDICATE_TYPE = registries$DataComponentPredicateType;
|
DATA_COMPONENT_PREDICATE_TYPE = registries$DataComponentPredicateType;
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
throw new ReflectionInitException("Failed to init BuiltInRegistries", e);
|
throw new ReflectionInitException("Failed to init BuiltInRegistries", e);
|
||||||
|
|||||||
@@ -189,15 +189,18 @@ public abstract class BlockBehavior {
|
|||||||
public void onProjectileHit(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
public void onProjectileHit(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack
|
// Level/WorldGenLevel level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack
|
||||||
public void placeMultiState(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
public void placeMultiState(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level level, BlockPos pos, BlockState state
|
|
||||||
public boolean canPlaceMultiState(BlockAccessor accessor, BlockPos pos, ImmutableBlockState state) {
|
public boolean canPlaceMultiState(BlockAccessor accessor, BlockPos pos, ImmutableBlockState state) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasMultiState(ImmutableBlockState baseState) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public ImmutableBlockState updateStateForPlacement(BlockPlaceContext context, ImmutableBlockState state) {
|
public ImmutableBlockState updateStateForPlacement(BlockPlaceContext context, ImmutableBlockState state) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ byte_buddy_version=1.17.8
|
|||||||
ahocorasick_version=0.6.3
|
ahocorasick_version=0.6.3
|
||||||
snake_yaml_version=2.5
|
snake_yaml_version=2.5
|
||||||
anti_grief_version=1.0.4
|
anti_grief_version=1.0.4
|
||||||
nms_helper_version=1.0.132
|
nms_helper_version=1.0.134
|
||||||
evalex_version=3.5.0
|
evalex_version=3.5.0
|
||||||
reactive_streams_version=1.0.4
|
reactive_streams_version=1.0.4
|
||||||
amazon_awssdk_version=2.34.5
|
amazon_awssdk_version=2.34.5
|
||||||
|
|||||||
Reference in New Issue
Block a user