DemoMode.java
net.minecraft.server.level.DemoMode
信息
- 全限定名:net.minecraft.server.level.DemoMode
- 类型:public class
- 包:net.minecraft.server.level
- 源码路径:src/main/java/net/minecraft/server/level/DemoMode.java
- 起始行号:L14
- 继承:ServerPlayerGameMode
- 职责:
TODO
字段/常量
-
DEMO_DAYS- 类型:
int - 修饰符:
public static final - 源码定位:
L15 - 说明:
TODO
- 类型:
-
TOTAL_PLAY_TICKS- 类型:
int - 修饰符:
public static final - 源码定位:
L16 - 说明:
TODO
- 类型:
-
displayedIntro- 类型:
boolean - 修饰符:
private - 源码定位:
L17 - 说明:
TODO
- 类型:
-
demoHasEnded- 类型:
boolean - 修饰符:
private - 源码定位:
L18 - 说明:
TODO
- 类型:
-
demoEndedReminder- 类型:
int - 修饰符:
private - 源码定位:
L19 - 说明:
TODO
- 类型:
-
gameModeTicks- 类型:
int - 修饰符:
private - 源码定位:
L20 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public DemoMode(ServerPlayer player) @ L22
- 构造器名:DemoMode
- 源码定位:L22
- 修饰符:public
参数:
- player: ServerPlayer
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void tick() @ L26
- 方法名:tick
- 源码定位:L26
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private void outputDemoReminder() @ L63
- 方法名:outputDemoReminder
- 源码定位:L63
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
public void handleBlockBreakAction(BlockPos pos, ServerboundPlayerActionPacket.Action action, Direction direction, int maxY, int sequence) @ L70
- 方法名:handleBlockBreakAction
- 源码定位:L70
- 返回类型:void
- 修饰符:public
参数:
- pos: BlockPos
- action: ServerboundPlayerActionPacket.Action
- direction: Direction
- maxY: int
- sequence: int
说明:
TODO
public InteractionResult useItem(ServerPlayer player, Level level, ItemStack itemStack, InteractionHand hand) @ L79
- 方法名:useItem
- 源码定位:L79
- 返回类型:InteractionResult
- 修饰符:public
参数:
- player: ServerPlayer
- level: Level
- itemStack: ItemStack
- hand: InteractionHand
说明:
TODO
public InteractionResult useItemOn(ServerPlayer player, Level level, ItemStack itemStack, InteractionHand hand, BlockHitResult hitResult) @ L89
- 方法名:useItemOn
- 源码定位:L89
- 返回类型:InteractionResult
- 修饰符:public
参数:
- player: ServerPlayer
- level: Level
- itemStack: ItemStack
- hand: InteractionHand
- hitResult: BlockHitResult
说明:
TODO
代码
public class DemoMode extends ServerPlayerGameMode {
public static final int DEMO_DAYS = 5;
public static final int TOTAL_PLAY_TICKS = 120500;
private boolean displayedIntro;
private boolean demoHasEnded;
private int demoEndedReminder;
private int gameModeTicks;
public DemoMode(ServerPlayer player) {
super(player);
}
@Override
public void tick() {
super.tick();
this.gameModeTicks++;
long time = this.level.getGameTime();
long day = time / 24000L + 1L;
if (!this.displayedIntro && this.gameModeTicks > 20) {
this.displayedIntro = true;
this.player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.DEMO_EVENT, 0.0F));
}
this.demoHasEnded = time > 120500L;
if (this.demoHasEnded) {
this.demoEndedReminder++;
}
if (time % 24000L == 500L) {
if (day <= 6L) {
if (day == 6L) {
this.player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.DEMO_EVENT, 104.0F));
} else {
this.player.sendSystemMessage(Component.translatable("demo.day." + day));
}
}
} else if (day == 1L) {
if (time == 100L) {
this.player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.DEMO_EVENT, 101.0F));
} else if (time == 175L) {
this.player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.DEMO_EVENT, 102.0F));
} else if (time == 250L) {
this.player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.DEMO_EVENT, 103.0F));
}
} else if (day == 5L && time % 24000L == 22000L) {
this.player.sendSystemMessage(Component.translatable("demo.day.warning"));
}
}
private void outputDemoReminder() {
if (this.demoEndedReminder > 100) {
this.player.sendSystemMessage(Component.translatable("demo.reminder"));
this.demoEndedReminder = 0;
}
}
@Override
public void handleBlockBreakAction(BlockPos pos, ServerboundPlayerActionPacket.Action action, Direction direction, int maxY, int sequence) {
if (this.demoHasEnded) {
this.outputDemoReminder();
} else {
super.handleBlockBreakAction(pos, action, direction, maxY, sequence);
}
}
@Override
public InteractionResult useItem(ServerPlayer player, Level level, ItemStack itemStack, InteractionHand hand) {
if (this.demoHasEnded) {
this.outputDemoReminder();
return InteractionResult.PASS;
} else {
return super.useItem(player, level, itemStack, hand);
}
}
@Override
public InteractionResult useItemOn(ServerPlayer player, Level level, ItemStack itemStack, InteractionHand hand, BlockHitResult hitResult) {
if (this.demoHasEnded) {
this.outputDemoReminder();
return InteractionResult.PASS;
} else {
return super.useItemOn(player, level, itemStack, hand, hitResult);
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ClientboundGameEventPacket()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: