mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 19:39:11 +00:00
添加stepOn
This commit is contained in:
@@ -167,6 +167,9 @@ public final class BlockGenerator {
|
||||
// updateEntityMovementAfterFallOn
|
||||
.method(ElementMatchers.is(CoreReflections.method$Block$updateEntityMovementAfterFallOn))
|
||||
.intercept(MethodDelegation.to(UpdateEntityMovementAfterFallOnInterceptor.INSTANCE))
|
||||
// stepOn
|
||||
.method(ElementMatchers.is(CoreReflections.method$Block$stepOn))
|
||||
.intercept(MethodDelegation.to(StepOnInterceptor.INSTANCE))
|
||||
;
|
||||
// 1.21.5+
|
||||
if (CoreReflections.method$BlockBehaviour$affectNeighborsAfterRemoval != null) {
|
||||
@@ -708,6 +711,20 @@ public final class BlockGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
public static class StepOnInterceptor {
|
||||
public static final StepOnInterceptor INSTANCE = new StepOnInterceptor();
|
||||
|
||||
@RuntimeType
|
||||
public void intercept(@This Object thisObj, @AllArguments Object[] args, @SuperCall Callable<Object> superMethod) {
|
||||
ObjectHolder<BlockBehavior> holder = ((DelegatingBlock) thisObj).behaviorDelegate();
|
||||
try {
|
||||
holder.value().stepOn(thisObj, args, superMethod);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().severe("Failed to run stepOn", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class FallOnInterceptor {
|
||||
public static final FallOnInterceptor INSTANCE = new FallOnInterceptor();
|
||||
|
||||
|
||||
@@ -1687,6 +1687,10 @@ public final class CoreReflections {
|
||||
ReflectionUtils.getDeclaredMethod(clazz$BlockBehaviour, boolean.class, clazz$BlockState, clazz$LevelReader, clazz$BlockPos)
|
||||
);
|
||||
|
||||
public static final Method method$Block$stepOn = requireNonNull(
|
||||
ReflectionUtils.getMethod(clazz$Block, void.class, new String[] {"stepOn", "a"}, clazz$Level, clazz$BlockPos, clazz$BlockState, clazz$Entity)
|
||||
);
|
||||
|
||||
public static final Method method$BlockBehaviour$onExplosionHit = MiscUtils.requireNonNullIf(
|
||||
ReflectionUtils.getDeclaredMethod(clazz$BlockBehaviour, void.class, clazz$BlockState, VersionHelper.isOrAbove1_21_2() ? clazz$ServerLevel : clazz$Level, clazz$BlockPos, clazz$Explosion, BiConsumer.class),
|
||||
VersionHelper.isOrAbove1_21()
|
||||
|
||||
@@ -178,6 +178,11 @@ public abstract class BlockBehavior {
|
||||
public void spawnAfterBreak(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||
}
|
||||
|
||||
// Level level, BlockPos pos, BlockState state, Entity entity
|
||||
public void stepOn(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||
superMethod.call();
|
||||
}
|
||||
|
||||
public ImmutableBlockState updateStateForPlacement(BlockPlaceContext context, ImmutableBlockState state) {
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user