GameTestSequence.java
net.minecraft.gametest.framework.GameTestSequence
信息
- 全限定名:net.minecraft.gametest.framework.GameTestSequence
- 类型:public class
- 包:net.minecraft.gametest.framework
- 源码路径:src/main/java/net/minecraft/gametest/framework/GameTestSequence.java
- 起始行号:L10
- 职责:
TODO
字段/常量
-
parent- 类型:
GameTestInfo - 修饰符:
private final - 源码定位:
L11 - 说明:
TODO
- 类型:
-
events- 类型:
List<GameTestEvent> - 修饰符:
private final - 源码定位:
L12 - 说明:
TODO
- 类型:
-
lastTick- 类型:
int - 修饰符:
private - 源码定位:
L13 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.gametest.framework.GameTestSequence.Condition- 类型:
class - 修饰符:
public - 源码定位:
L124 - 说明:
TODO
- 类型:
构造器
GameTestSequence(GameTestInfo parent) @ L15
- 构造器名:GameTestSequence
- 源码定位:L15
- 修饰符:package-private
参数:
- parent: GameTestInfo
说明:
TODO
方法
下面的方法块按源码顺序生成。
public GameTestSequence thenWaitUntil(Runnable assertion) @ L20
- 方法名:thenWaitUntil
- 源码定位:L20
- 返回类型:GameTestSequence
- 修饰符:public
参数:
- assertion: Runnable
说明:
TODO
public GameTestSequence thenWaitUntil(long expectedDelay, Runnable assertion) @ L25
- 方法名:thenWaitUntil
- 源码定位:L25
- 返回类型:GameTestSequence
- 修饰符:public
参数:
- expectedDelay: long
- assertion: Runnable
说明:
TODO
public GameTestSequence thenWaitAtLeast(long minimumDelay, Runnable assertion) @ L30
- 方法名:thenWaitAtLeast
- 源码定位:L30
- 返回类型:GameTestSequence
- 修饰符:public
参数:
- minimumDelay: long
- assertion: Runnable
说明:
TODO
public GameTestSequence thenIdle(int delta) @ L35
- 方法名:thenIdle
- 源码定位:L35
- 返回类型:GameTestSequence
- 修饰符:public
参数:
- delta: int
说明:
TODO
public GameTestSequence thenExecute(Runnable assertion) @ L39
- 方法名:thenExecute
- 源码定位:L39
- 返回类型:GameTestSequence
- 修饰符:public
参数:
- assertion: Runnable
说明:
TODO
public GameTestSequence thenExecuteAfter(int delta, Runnable after) @ L44
- 方法名:thenExecuteAfter
- 源码定位:L44
- 返回类型:GameTestSequence
- 修饰符:public
参数:
- delta: int
- after: Runnable
说明:
TODO
public GameTestSequence thenExecuteFor(int delta, Runnable check) @ L55
- 方法名:thenExecuteFor
- 源码定位:L55
- 返回类型:GameTestSequence
- 修饰符:public
参数:
- delta: int
- check: Runnable
说明:
TODO
public void thenSucceed() @ L65
- 方法名:thenSucceed
- 源码定位:L65
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void thenFail(Supplier<GameTestException> e) @ L69
- 方法名:thenFail
- 源码定位:L69
- 返回类型:void
- 修饰符:public
参数:
- e: Supplier
说明:
TODO
public GameTestSequence.Condition thenTrigger() @ L73
- 方法名:thenTrigger
- 源码定位:L73
- 返回类型:GameTestSequence.Condition
- 修饰符:public
参数:
- 无
说明:
TODO
public void tickAndContinue(int tick) @ L79
- 方法名:tickAndContinue
- 源码定位:L79
- 返回类型:void
- 修饰符:public
参数:
- tick: int
说明:
TODO
public void tickAndFailIfNotComplete(int tick) @ L86
- 方法名:tickAndFailIfNotComplete
- 源码定位:L86
- 返回类型:void
- 修饰符:public
参数:
- tick: int
说明:
TODO
private void executeWithoutFail(Runnable assertion) @ L94
- 方法名:executeWithoutFail
- 源码定位:L94
- 返回类型:void
- 修饰符:private
参数:
- assertion: Runnable
说明:
TODO
private void tick(int tick) @ L102
- 方法名:tick
- 源码定位:L102
- 返回类型:void
- 修饰符:private
参数:
- tick: int
说明:
TODO
代码
public class GameTestSequence {
private final GameTestInfo parent;
private final List<GameTestEvent> events = Lists.newArrayList();
private int lastTick;
GameTestSequence(GameTestInfo parent) {
this.parent = parent;
this.lastTick = parent.getTick();
}
public GameTestSequence thenWaitUntil(Runnable assertion) {
this.events.add(GameTestEvent.create(assertion));
return this;
}
public GameTestSequence thenWaitUntil(long expectedDelay, Runnable assertion) {
this.events.add(GameTestEvent.create(expectedDelay, assertion));
return this;
}
public GameTestSequence thenWaitAtLeast(long minimumDelay, Runnable assertion) {
this.events.add(GameTestEvent.createWithMinimumDelay(minimumDelay, assertion));
return this;
}
public GameTestSequence thenIdle(int delta) {
return this.thenExecuteAfter(delta, () -> {});
}
public GameTestSequence thenExecute(Runnable assertion) {
this.events.add(GameTestEvent.create(() -> this.executeWithoutFail(assertion)));
return this;
}
public GameTestSequence thenExecuteAfter(int delta, Runnable after) {
this.events.add(GameTestEvent.create(() -> {
if (this.parent.getTick() < this.lastTick + delta) {
throw new GameTestAssertException(Component.translatable("test.error.sequence.not_completed"), this.parent.getTick());
} else {
this.executeWithoutFail(after);
}
}));
return this;
}
public GameTestSequence thenExecuteFor(int delta, Runnable check) {
this.events.add(GameTestEvent.create(() -> {
if (this.parent.getTick() < this.lastTick + delta) {
this.executeWithoutFail(check);
throw new GameTestAssertException(Component.translatable("test.error.sequence.not_completed"), this.parent.getTick());
}
}));
return this;
}
public void thenSucceed() {
this.events.add(GameTestEvent.create(this.parent::succeed));
}
public void thenFail(Supplier<GameTestException> e) {
this.events.add(GameTestEvent.create(() -> this.parent.fail(e.get())));
}
public GameTestSequence.Condition thenTrigger() {
GameTestSequence.Condition result = new GameTestSequence.Condition();
this.events.add(GameTestEvent.create(() -> result.trigger(this.parent.getTick())));
return result;
}
public void tickAndContinue(int tick) {
try {
this.tick(tick);
} catch (GameTestAssertException var3) {
}
}
public void tickAndFailIfNotComplete(int tick) {
try {
this.tick(tick);
} catch (GameTestAssertException var3) {
this.parent.fail(var3);
}
}
private void executeWithoutFail(Runnable assertion) {
try {
assertion.run();
} catch (GameTestAssertException var3) {
this.parent.fail(var3);
}
}
private void tick(int tick) {
Iterator<GameTestEvent> iterator = this.events.iterator();
while (iterator.hasNext()) {
GameTestEvent event = iterator.next();
event.assertion.run();
iterator.remove();
int delay = tick - this.lastTick;
int prevTick = this.lastTick;
this.lastTick = tick;
if (event.minimumDelay != null && event.minimumDelay > delay) {
this.parent.fail(new GameTestAssertException(Component.translatable("test.error.sequence.minimum_tick", prevTick + event.minimumDelay), tick));
break;
}
if (event.expectedDelay != null && event.expectedDelay != delay) {
this.parent.fail(new GameTestAssertException(Component.translatable("test.error.sequence.invalid_tick", prevTick + event.expectedDelay), tick));
break;
}
}
}
public class Condition {
private static final int NOT_TRIGGERED = -1;
private int triggerTime;
public Condition() {
Objects.requireNonNull(GameTestSequence.this);
super();
this.triggerTime = -1;
}
void trigger(int time) {
if (this.triggerTime != -1) {
throw new IllegalStateException("Condition already triggered at " + this.triggerTime);
} else {
this.triggerTime = time;
}
}
public void assertTriggeredThisTick() {
int tick = GameTestSequence.this.parent.getTick();
if (this.triggerTime != tick) {
if (this.triggerTime == -1) {
throw new GameTestAssertException(Component.translatable("test.error.sequence.condition_not_triggered"), tick);
} else {
throw new GameTestAssertException(Component.translatable("test.error.sequence.condition_already_triggered", this.triggerTime), tick);
}
}
}
}
}引用的其他类
-
- 引用位置:
构造调用 - 关联成员:
GameTestAssertException()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
GameTestEvent.create(), GameTestEvent.createWithMinimumDelay()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置: