| 1 | package net.minecraft.world.level.levelgen.structure.pools;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableMap;
|
| 4 | import com.google.common.collect.ImmutableMap.Builder;
|
| 5 | import com.mojang.serialization.Dynamic;
|
| 6 | import com.mojang.serialization.DynamicOps;
|
| 7 |
|
| 8 | public class JigsawJunction {
|
| 9 | private final int sourceX;
|
| 10 | private final int sourceGroundY;
|
| 11 | private final int sourceZ;
|
| 12 | private final int deltaY;
|
| 13 | private final StructureTemplatePool.Projection destProjection;
|
| 14 |
|
| 15 | public JigsawJunction(final int sourceX, final int sourceGroundY, final int sourceZ, final int deltaY, final StructureTemplatePool.Projection destProjection) {
|
| 16 | this.sourceX = sourceX;
|
| 17 | this.sourceGroundY = sourceGroundY;
|
| 18 | this.sourceZ = sourceZ;
|
| 19 | this.deltaY = deltaY;
|
| 20 | this.destProjection = destProjection;
|
| 21 | }
|
| 22 |
|
| 23 | public int getSourceX() {
|
| 24 | return this.sourceX;
|
| 25 | }
|
| 26 |
|
| 27 | public int getSourceGroundY() {
|
| 28 | return this.sourceGroundY;
|
| 29 | }
|
| 30 |
|
| 31 | public int getSourceZ() {
|
| 32 | return this.sourceZ;
|
| 33 | }
|
| 34 |
|
| 35 | public int getDeltaY() {
|
| 36 | return this.deltaY;
|
| 37 | }
|
| 38 |
|
| 39 | public StructureTemplatePool.Projection getDestProjection() {
|
| 40 | return this.destProjection;
|
| 41 | }
|
| 42 |
|
| 43 | public <T> Dynamic<T> serialize(final DynamicOps<T> ops) {
|
| 44 | Builder<T, T> builder = ImmutableMap.builder();
|
| 45 | builder.put(ops.createString("source_x"), ops.createInt(this.sourceX))
|
| 46 | .put(ops.createString("source_ground_y"), ops.createInt(this.sourceGroundY))
|
| 47 | .put(ops.createString("source_z"), ops.createInt(this.sourceZ))
|
| 48 | .put(ops.createString("delta_y"), ops.createInt(this.deltaY))
|
| 49 | .put(ops.createString("dest_proj"), ops.createString(this.destProjection.getName()));
|
| 50 | return new Dynamic<>(ops, ops.createMap(builder.build()));
|
| 51 | }
|
| 52 |
|
| 53 | public static <T> JigsawJunction deserialize(final Dynamic<T> input) {
|
| 54 | return new JigsawJunction(
|
| 55 | input.get("source_x").asInt(0),
|
| 56 | input.get("source_ground_y").asInt(0),
|
| 57 | input.get("source_z").asInt(0),
|
| 58 | input.get("delta_y").asInt(0),
|
| 59 | StructureTemplatePool.Projection.byName(input.get("dest_proj").asString(""))
|
| 60 | );
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public boolean equals(final Object o) {
|
| 65 | if (this == o) {
|
| 66 | return true;
|
| 67 | }
|
| 68 |
|
| 69 | if (o != null && this.getClass() == o.getClass()) {
|
| 70 | JigsawJunction that = (JigsawJunction)o;
|
| 71 | if (this.sourceX != that.sourceX) {
|
| 72 | return false;
|
| 73 | } else if (this.sourceZ != that.sourceZ) {
|
| 74 | return false;
|
| 75 | } else {
|
| 76 | return this.deltaY != that.deltaY ? false : this.destProjection == that.destProjection;
|
| 77 | }
|
| 78 | } else {
|
| 79 | return false;
|
| 80 | }
|
| 81 | }
|
| 82 |
|
| 83 | @Override
|
| 84 | public int hashCode() {
|
| 85 | int result = this.sourceX;
|
| 86 | result = 31 * result + this.sourceGroundY;
|
| 87 | result = 31 * result + this.sourceZ;
|
| 88 | result = 31 * result + this.deltaY;
|
| 89 | return 31 * result + this.destProjection.hashCode();
|
| 90 | }
|
| 91 |
|
| 92 | @Override
|
| 93 | public String toString() {
|
| 94 | return "JigsawJunction{sourceX="
|
| 95 | + this.sourceX
|
| 96 | + ", sourceGroundY="
|
| 97 | + this.sourceGroundY
|
| 98 | + ", sourceZ="
|
| 99 | + this.sourceZ
|
| 100 | + ", deltaY="
|
| 101 | + this.deltaY
|
| 102 | + ", destProjection="
|
| 103 | + this.destProjection
|
| 104 | + "}";
|
| 105 | }
|
| 106 | }
|
| 107 |
|