mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
修复按钮行为在1.21.11触发游戏事件的时候报错
This commit is contained in:
@@ -148,7 +148,7 @@ public class ButtonBlockBehavior extends BukkitBlockBehavior {
|
|||||||
updateNeighbours(thisBlock, blockState, level, pos);
|
updateNeighbours(thisBlock, blockState, level, pos);
|
||||||
playSound(level, pos, on);
|
playSound(level, pos, on);
|
||||||
Object gameEvent = VersionHelper.isOrAbove1_20_5()
|
Object gameEvent = VersionHelper.isOrAbove1_20_5()
|
||||||
? FastNMS.INSTANCE.method$Holder$direct(on ? MGameEvents.BLOCK_ACTIVATE : MGameEvents.BLOCK_DEACTIVATE)
|
? on ? MGameEvents.BLOCK_ACTIVATE$holder : MGameEvents.BLOCK_DEACTIVATE$holder
|
||||||
: on ? MGameEvents.BLOCK_ACTIVATE : MGameEvents.BLOCK_DEACTIVATE;
|
: on ? MGameEvents.BLOCK_ACTIVATE : MGameEvents.BLOCK_DEACTIVATE;
|
||||||
FastNMS.INSTANCE.method$LevelAccessor$gameEvent(level, arrow, gameEvent, pos);
|
FastNMS.INSTANCE.method$LevelAccessor$gameEvent(level, arrow, gameEvent, pos);
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ public class ButtonBlockBehavior extends BukkitBlockBehavior {
|
|||||||
FastNMS.INSTANCE.method$LevelWriter$setBlock(level, pos, state.with(this.poweredProperty, true).customBlockState().literalObject(), UpdateOption.UPDATE_ALL.flags());
|
FastNMS.INSTANCE.method$LevelWriter$setBlock(level, pos, state.with(this.poweredProperty, true).customBlockState().literalObject(), UpdateOption.UPDATE_ALL.flags());
|
||||||
FastNMS.INSTANCE.method$ScheduledTickAccess$scheduleBlockTick(level, pos, thisBlock, this.ticksToStayPressed);
|
FastNMS.INSTANCE.method$ScheduledTickAccess$scheduleBlockTick(level, pos, thisBlock, this.ticksToStayPressed);
|
||||||
playSound(level, pos, true);
|
playSound(level, pos, true);
|
||||||
Object gameEvent = VersionHelper.isOrAbove1_20_5() ? FastNMS.INSTANCE.method$Holder$direct(MGameEvents.BLOCK_ACTIVATE) : MGameEvents.BLOCK_ACTIVATE;
|
Object gameEvent = VersionHelper.isOrAbove1_20_5() ? MGameEvents.BLOCK_ACTIVATE$holder : MGameEvents.BLOCK_ACTIVATE;
|
||||||
FastNMS.INSTANCE.method$LevelAccessor$gameEvent(level, player, gameEvent, pos);
|
FastNMS.INSTANCE.method$LevelAccessor$gameEvent(level, player, gameEvent, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,17 @@ public final class MGameEvents {
|
|||||||
private MGameEvents() {}
|
private MGameEvents() {}
|
||||||
|
|
||||||
public static final Object BLOCK_ACTIVATE = getById("block_activate");
|
public static final Object BLOCK_ACTIVATE = getById("block_activate");
|
||||||
|
public static final Object BLOCK_ACTIVATE$holder = getHolderById("block_activate");
|
||||||
public static final Object BLOCK_DEACTIVATE = getById("block_deactivate");
|
public static final Object BLOCK_DEACTIVATE = getById("block_deactivate");
|
||||||
|
public static final Object BLOCK_DEACTIVATE$holder = getHolderById("block_deactivate");
|
||||||
|
|
||||||
private static Object getById(String id) {
|
private static Object getById(String id) {
|
||||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.GAME_EVENT, rl);
|
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.GAME_EVENT, rl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Object getHolderById(String id) {
|
||||||
|
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||||
|
return FastNMS.INSTANCE.method$Registry$getHolderByResourceLocation(MBuiltInRegistries.GAME_EVENT, rl).orElseThrow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user