Add lombok
This commit is contained in:
@@ -141,6 +141,9 @@ dependencies {
|
||||
// http://www.gradle.org/docs/current/userguide/dependency_management.html
|
||||
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.34'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.34'
|
||||
|
||||
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
|
||||
testAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
|
||||
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.5.0"))
|
||||
|
||||
@@ -5,8 +5,11 @@ import com.imbgt.ibg.util.FootprintSpec;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public final class MachineSets {
|
||||
|
||||
public static final String NS = "gtceu";
|
||||
@@ -27,8 +30,6 @@ public final class MachineSets {
|
||||
.partOutline(Shapes.box(0, 0, 0, 1, 14.0 / 16.0, 1))
|
||||
.build()));
|
||||
|
||||
private MachineSets() {}
|
||||
|
||||
/** Does this machine belong to any configured family? */
|
||||
public static boolean matches(ResourceLocation id) {
|
||||
return DEFINITIONS.stream().anyMatch(f -> f.matches(id));
|
||||
|
||||
@@ -4,11 +4,14 @@ import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** Declarative footprint for a multiblock: relative part offsets and local outlines. */
|
||||
@Value
|
||||
public final class FootprintSpec {
|
||||
|
||||
/** Relative positions (in block cells) of parts, defined for facing = NORTH. */
|
||||
@@ -18,24 +21,6 @@ public final class FootprintSpec {
|
||||
/** Per-cell outline for each part, in local [0,1] coords. Used for selection outline only. */
|
||||
private final VoxelShape partOutline;
|
||||
|
||||
private FootprintSpec(List<Cell> parts, VoxelShape masterOutline, VoxelShape partOutline) {
|
||||
this.parts = List.copyOf(parts);
|
||||
this.masterOutline = masterOutline;
|
||||
this.partOutline = partOutline;
|
||||
}
|
||||
|
||||
public List<Cell> parts() {
|
||||
return parts;
|
||||
}
|
||||
|
||||
public VoxelShape masterOutline() {
|
||||
return masterOutline;
|
||||
}
|
||||
|
||||
public VoxelShape partOutline() {
|
||||
return partOutline;
|
||||
}
|
||||
|
||||
/** Builder with sane defaults. */
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
|
||||
@@ -6,23 +6,25 @@ import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Registry + helpers to compute world positions and a continuous outline shape.
|
||||
*/
|
||||
|
||||
@UtilityClass
|
||||
public final class Footprints {
|
||||
|
||||
private Footprints() {}
|
||||
|
||||
/** All part world positions for a given master and facing. */
|
||||
public static List<BlockPos> partPositions(BlockPos master, Direction facing, FootprintSpec spec) {
|
||||
return spec.parts().stream()
|
||||
public List<BlockPos> partPositions(BlockPos master, Direction facing, FootprintSpec spec) {
|
||||
return spec.getParts().stream()
|
||||
.map(c -> master.offset(rotateDx(c.dx(), c.dz(), facing), c.dy(), rotateDz(c.dx(), c.dz(), facing)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static VoxelShape rotateOutline(VoxelShape shape, Direction facing) {
|
||||
public VoxelShape rotateOutline(VoxelShape shape, Direction facing) {
|
||||
return rotateY(shape, quarters(facing));
|
||||
}
|
||||
|
||||
@@ -30,15 +32,15 @@ public final class Footprints {
|
||||
* A single continuous selection outline for the whole multiblock, anchored at
|
||||
* the master.
|
||||
*/
|
||||
public static VoxelShape combinedOutline(Direction facing, FootprintSpec spec) {
|
||||
public VoxelShape combinedOutline(Direction facing, FootprintSpec spec) {
|
||||
int q = quarters(facing);
|
||||
VoxelShape result = rotateY(spec.masterOutline(), q);
|
||||
VoxelShape result = rotateY(spec.getMasterOutline(), q);
|
||||
|
||||
for (var cell : spec.parts()) {
|
||||
for (var cell : spec.getParts()) {
|
||||
// rotate the cell offset then translate the part shape by 1 * offset
|
||||
int rx = rotateDx(cell.dx(), cell.dz(), facing);
|
||||
int rz = rotateDz(cell.dx(), cell.dz(), facing);
|
||||
VoxelShape rotatedPart = rotateY(spec.partOutline(), q);
|
||||
VoxelShape rotatedPart = rotateY(spec.getPartOutline(), q);
|
||||
result = Shapes.or(result, move(rotatedPart, rx, cell.dy(), rz));
|
||||
}
|
||||
return result.optimize();
|
||||
@@ -50,7 +52,7 @@ public final class Footprints {
|
||||
* Rotate a local shape by 0/90/180/270 degrees around Y, within a single cell's
|
||||
* [0,1] space.
|
||||
*/
|
||||
private static VoxelShape rotateY(VoxelShape shape, int quarters) {
|
||||
private VoxelShape rotateY(VoxelShape shape, int quarters) {
|
||||
if (quarters == 0)
|
||||
return shape;
|
||||
VoxelShape out = Shapes.empty();
|
||||
@@ -71,14 +73,14 @@ public final class Footprints {
|
||||
* Translate a shape by world-space units. For cross-cell outline we use
|
||||
* multiples of 1.
|
||||
*/
|
||||
private static VoxelShape move(VoxelShape s, double dx, double dy, double dz) {
|
||||
private VoxelShape move(VoxelShape s, double dx, double dy, double dz) {
|
||||
VoxelShape out = Shapes.empty();
|
||||
for (AABB a : s.toAabbs())
|
||||
out = Shapes.or(out, Shapes.create(a.move(dx, dy, dz)));
|
||||
return out;
|
||||
}
|
||||
|
||||
private static int rotateDx(int dx, int dz, Direction facing) {
|
||||
private int rotateDx(int dx, int dz, Direction facing) {
|
||||
return switch (quarters(facing)) {
|
||||
case 0 -> dx; // NORTH
|
||||
case 1 -> -dz; // EAST
|
||||
@@ -88,7 +90,7 @@ public final class Footprints {
|
||||
};
|
||||
}
|
||||
|
||||
private static int rotateDz(int dx, int dz, Direction facing) {
|
||||
private int rotateDz(int dx, int dz, Direction facing) {
|
||||
return switch (quarters(facing)) {
|
||||
case 0 -> dz; // NORTH
|
||||
case 1 -> dx; // EAST
|
||||
@@ -98,7 +100,7 @@ public final class Footprints {
|
||||
};
|
||||
}
|
||||
|
||||
private static int quarters(Direction facing) {
|
||||
private int quarters(Direction facing) {
|
||||
return switch (facing) {
|
||||
case NORTH -> 0;
|
||||
case EAST -> 1;
|
||||
|
||||
Reference in New Issue
Block a user