| 1 | package net.minecraft.gametest.framework;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import com.mojang.serialization.MapCodec;
|
| 5 | import net.minecraft.ChatFormatting;
|
| 6 | import net.minecraft.core.Holder;
|
| 7 | import net.minecraft.core.Registry;
|
| 8 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 9 | import net.minecraft.core.registries.Registries;
|
| 10 | import net.minecraft.network.chat.Component;
|
| 11 | import net.minecraft.network.chat.MutableComponent;
|
| 12 | import net.minecraft.resources.Identifier;
|
| 13 | import net.minecraft.resources.ResourceKey;
|
| 14 | import net.minecraft.world.level.Level;
|
| 15 | import net.minecraft.world.level.block.Rotation;
|
| 16 |
|
| 17 | public abstract class GameTestInstance {
|
| 18 | public static final Codec<GameTestInstance> DIRECT_CODEC = BuiltInRegistries.TEST_INSTANCE_TYPE.byNameCodec().dispatch(GameTestInstance::codec, i -> i);
|
| 19 | private final TestData<Holder<TestEnvironmentDefinition<?>>> info;
|
| 20 |
|
| 21 | public static MapCodec<? extends GameTestInstance> bootstrap(final Registry<MapCodec<? extends GameTestInstance>> registry) {
|
| 22 | register(registry, "block_based", BlockBasedTestInstance.CODEC);
|
| 23 | return register(registry, "function", FunctionGameTestInstance.CODEC);
|
| 24 | }
|
| 25 |
|
| 26 | private static MapCodec<? extends GameTestInstance> register(
|
| 27 | final Registry<MapCodec<? extends GameTestInstance>> registry, final String name, final MapCodec<? extends GameTestInstance> codec
|
| 28 | ) {
|
| 29 | return Registry.register(registry, ResourceKey.create(Registries.TEST_INSTANCE_TYPE, Identifier.withDefaultNamespace(name)), codec);
|
| 30 | }
|
| 31 |
|
| 32 | protected GameTestInstance(final TestData<Holder<TestEnvironmentDefinition<?>>> info) {
|
| 33 | this.info = info;
|
| 34 | }
|
| 35 |
|
| 36 | public abstract void run(GameTestHelper helper);
|
| 37 |
|
| 38 | public abstract MapCodec<? extends GameTestInstance> codec();
|
| 39 |
|
| 40 | public Holder<TestEnvironmentDefinition<?>> batch() {
|
| 41 | return this.info.environment();
|
| 42 | }
|
| 43 |
|
| 44 | public ResourceKey<Level> dimension() {
|
| 45 | return this.info.dimension();
|
| 46 | }
|
| 47 |
|
| 48 | public Identifier structure() {
|
| 49 | return this.info.structure();
|
| 50 | }
|
| 51 |
|
| 52 | public int maxTicks() {
|
| 53 | return this.info.maxTicks();
|
| 54 | }
|
| 55 |
|
| 56 | public int setupTicks() {
|
| 57 | return this.info.setupTicks();
|
| 58 | }
|
| 59 |
|
| 60 | public boolean required() {
|
| 61 | return this.info.required();
|
| 62 | }
|
| 63 |
|
| 64 | public boolean manualOnly() {
|
| 65 | return this.info.manualOnly();
|
| 66 | }
|
| 67 |
|
| 68 | public int maxAttempts() {
|
| 69 | return this.info.maxAttempts();
|
| 70 | }
|
| 71 |
|
| 72 | public int requiredSuccesses() {
|
| 73 | return this.info.requiredSuccesses();
|
| 74 | }
|
| 75 |
|
| 76 | public boolean skyAccess() {
|
| 77 | return this.info.skyAccess();
|
| 78 | }
|
| 79 |
|
| 80 | public Rotation rotation() {
|
| 81 | return this.info.rotation();
|
| 82 | }
|
| 83 |
|
| 84 | public int padding() {
|
| 85 | return this.info.padding();
|
| 86 | }
|
| 87 |
|
| 88 | protected TestData<Holder<TestEnvironmentDefinition<?>>> info() {
|
| 89 | return this.info;
|
| 90 | }
|
| 91 |
|
| 92 | protected abstract MutableComponent typeDescription();
|
| 93 |
|
| 94 | public Component describe() {
|
| 95 | return this.describeType().append(this.describeInfo());
|
| 96 | }
|
| 97 |
|
| 98 | protected MutableComponent describeType() {
|
| 99 | return this.descriptionRow("test_instance.description.type", this.typeDescription());
|
| 100 | }
|
| 101 |
|
| 102 | protected Component describeInfo() {
|
| 103 | return this.descriptionRow("test_instance.description.structure", this.info.structure().toString())
|
| 104 | .append(this.descriptionRow("test_instance.description.batch", this.info.environment().getRegisteredName()))
|
| 105 | .append(this.descriptionRow("test_instance.description.dimension", this.info.dimension().identifier().toString()));
|
| 106 | }
|
| 107 |
|
| 108 | protected MutableComponent descriptionRow(final String translationKey, final String value) {
|
| 109 | return this.descriptionRow(translationKey, Component.literal(value));
|
| 110 | }
|
| 111 |
|
| 112 | protected MutableComponent descriptionRow(final String translationKey, final MutableComponent value) {
|
| 113 | return Component.translatable(translationKey, value.withStyle(ChatFormatting.BLUE)).append(Component.literal("\n"));
|
| 114 | }
|
| 115 | }
|
| 116 |
|