mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-08 12:34:50 +00:00
Make IStructureElement contravariant.
This commit is contained in:
6 files changed
+32
-29
No files matched your search
@@ -67,7 +67,7 @@ public interface IStructureDefinition<T> {
|
||||
* @throws java.util.NoSuchElementException if the given structure piece is not found and the moon phase perfectly
|
||||
* matches
|
||||
*/
|
||||
IStructureElement<T>[] getStructureFor(String name);
|
||||
IStructureElement<? super T>[] getStructureFor(String name);
|
||||
|
||||
boolean isContainedInStructure(String name, int offsetA, int offsetB, int offsetC);
|
||||
|
||||
@@ -356,7 +356,7 @@ public interface IStructureDefinition<T> {
|
||||
* @return true if iteration completed successfully.
|
||||
* @param <T> type of context object.
|
||||
*/
|
||||
static <T> boolean iterate(T object, ItemStack trigger, IStructureElement<T>[] elements, World world,
|
||||
static <T> boolean iterate(T object, ItemStack trigger, IStructureElement<? super T>[] elements, World world,
|
||||
ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA,
|
||||
int basePositionB, int basePositionC, boolean hintsOnly, Boolean checkBlocksIfNotNullForceCheckAllIfTrue) {
|
||||
if (!world.isRemote && hintsOnly) {
|
||||
|
||||
@@ -28,6 +28,9 @@ import com.gtnewhorizon.structurelib.util.ItemStackPredicate.NBTMode;
|
||||
/**
|
||||
* Use StructureUtility to instantiate. These are the building blocks for your {@link IStructureDefinition}. It
|
||||
* represents what a particular element can be and how this particular element should be autoplaced.
|
||||
*
|
||||
* @param <T> Type of the context object. {@link IStructureElement} is contravariant over T, so parameters and fields of
|
||||
* type {@link IStructureElement} should be declared as {@code IStructureElement<? super T>}
|
||||
*/
|
||||
public interface IStructureElement<T> {
|
||||
|
||||
@@ -213,7 +216,7 @@ public interface IStructureElement<T> {
|
||||
* Forget the messed up class dependency graph for now. this is just so convenient.
|
||||
*/
|
||||
default IStructureElementNoPlacement<T> noPlacement() {
|
||||
return new IStructureElementNoPlacement<T>() {
|
||||
return new IStructureElementNoPlacement<>() {
|
||||
|
||||
@Override
|
||||
public boolean check(T t, World world, int x, int y, int z) {
|
||||
|
||||
@@ -21,23 +21,23 @@ public interface IStructureWalker<T> {
|
||||
* @param c The relative C position of the element in structure-local coordinates (pre transform)
|
||||
* @return False to stop iterating, true to continue.
|
||||
*/
|
||||
boolean visit(IStructureElement<T> element, World world, int x, int y, int z, int a, int b, int c);
|
||||
boolean visit(IStructureElement<? super T> element, World world, int x, int y, int z, int a, int b, int c);
|
||||
|
||||
default boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z, int a, int b,
|
||||
default boolean blockNotLoaded(IStructureElement<? super T> element, World world, int x, int y, int z, int a, int b,
|
||||
int c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static <T> IStructureWalker<T> ignoreBlockUnloaded(IStructureWalker<T> walker) {
|
||||
return new IStructureWalker<T>() {
|
||||
return new IStructureWalker<>() {
|
||||
|
||||
@Override
|
||||
public boolean visit(IStructureElement<T> element, World world, int x, int y, int z, int a, int b, int c) {
|
||||
public boolean visit(IStructureElement<? super T> element, World world, int x, int y, int z, int a, int b, int c) {
|
||||
return walker.visit(element, world, x, y, z, a, b, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z, int a, int b,
|
||||
public boolean blockNotLoaded(IStructureElement<? super T> element, World world, int x, int y, int z, int a, int b,
|
||||
int c) {
|
||||
return walker.visit(element, world, x, y, z, a, b, c);
|
||||
}
|
||||
@@ -45,15 +45,15 @@ public interface IStructureWalker<T> {
|
||||
}
|
||||
|
||||
static <T> IStructureWalker<T> skipBlockUnloaded(IStructureWalker<T> walker) {
|
||||
return new IStructureWalker<T>() {
|
||||
return new IStructureWalker<>() {
|
||||
|
||||
@Override
|
||||
public boolean visit(IStructureElement<T> element, World world, int x, int y, int z, int a, int b, int c) {
|
||||
public boolean visit(IStructureElement<? super T> element, World world, int x, int y, int z, int a, int b, int c) {
|
||||
return walker.visit(element, world, x, y, z, a, b, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z, int a, int b,
|
||||
public boolean blockNotLoaded(IStructureElement<? super T> element, World world, int x, int y, int z, int a, int b,
|
||||
int c) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@ import com.gtnewhorizon.structurelib.util.Vec3Impl;
|
||||
|
||||
public class StructureDefinition<T> implements IStructureDefinition<T> {
|
||||
|
||||
private final Map<Character, IStructureElement<T>> elements;
|
||||
private final Map<Character, IStructureElement<? super T>> elements;
|
||||
private final Map<String, String> shapes;
|
||||
private final Map<String, IStructureElement<T>[]> structures;
|
||||
private final Map<String, IStructureElement<? super T>[]> structures;
|
||||
private final Map<String, Set<Vec3Impl>> occupiedSpaces;
|
||||
|
||||
public static <B> Builder<B> builder() {
|
||||
return new Builder<>();
|
||||
}
|
||||
|
||||
private StructureDefinition(Map<Character, IStructureElement<T>> elements, Map<String, String> shapes,
|
||||
Map<String, IStructureElement<T>[]> structures, Map<String, Set<Vec3Impl>> occupiedSpaces) {
|
||||
private StructureDefinition(Map<Character, IStructureElement<? super T>> elements, Map<String, String> shapes,
|
||||
Map<String, IStructureElement<? super T>[]> structures, Map<String, Set<Vec3Impl>> occupiedSpaces) {
|
||||
this.elements = elements;
|
||||
this.shapes = shapes;
|
||||
this.structures = structures;
|
||||
@@ -40,7 +40,7 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
|
||||
private static final char C = '\uC000';
|
||||
private char d = '\uD000';
|
||||
private final Map<Vec3Impl, Character> navigates;
|
||||
private final Map<Character, IStructureElement<T>> elements;
|
||||
private final Map<Character, IStructureElement<? super T>> elements;
|
||||
private final Map<String, String> shapes;
|
||||
private final Map<String, Set<Vec3Impl>> occupiedSpaces;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
|
||||
occupiedSpaces = new HashMap<>();
|
||||
}
|
||||
|
||||
public Map<Character, IStructureElement<T>> getElements() {
|
||||
public Map<Character, IStructureElement<? super T>> getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
@@ -181,18 +181,18 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
|
||||
* @deprecated use the unboxed version
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder<T> addElement(Character name, IStructureElement<T> structurePiece) {
|
||||
public Builder<T> addElement(Character name, IStructureElement<? super T> structurePiece) {
|
||||
elements.putIfAbsent(name, structurePiece);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> addElement(char name, IStructureElement<T> structurePiece) {
|
||||
public Builder<T> addElement(char name, IStructureElement<? super T> structurePiece) {
|
||||
elements.putIfAbsent(name, structurePiece);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IStructureDefinition<T> build() {
|
||||
Map<String, IStructureElement<T>[]> structures = compileStructureMap();
|
||||
Map<String, IStructureElement<? super T>[]> structures = compileStructureMap();
|
||||
return new StructureDefinition<>(
|
||||
new HashMap<>(elements),
|
||||
new HashMap<>(shapes),
|
||||
@@ -201,7 +201,7 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, IStructureElement<T>[]> compileElementSetMap() {
|
||||
private Map<String, IStructureElement<? super T>[]> compileElementSetMap() {
|
||||
Set<Integer> missing = findMissing();
|
||||
if (missing.isEmpty()) {
|
||||
return shapes.entrySet().stream().collect(
|
||||
@@ -217,7 +217,7 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, IStructureElement<T>[]> compileStructureMap() {
|
||||
private Map<String, IStructureElement<? super T>[]> compileStructureMap() {
|
||||
Set<Integer> missing = findMissing();
|
||||
if (missing.isEmpty()) {
|
||||
return shapes.entrySet().stream().collect(
|
||||
@@ -238,7 +238,7 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Character, IStructureElement<T>> getElements() {
|
||||
public Map<Character, IStructureElement<? super T>> getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
@@ -246,13 +246,13 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
|
||||
return shapes;
|
||||
}
|
||||
|
||||
public Map<String, IStructureElement<T>[]> getStructures() {
|
||||
public Map<String, IStructureElement<? super T>[]> getStructures() {
|
||||
return structures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStructureElement<T>[] getStructureFor(String name) {
|
||||
IStructureElement<T>[] elements = structures.get(name);
|
||||
public IStructureElement<? super T>[] getStructureFor(String name) {
|
||||
IStructureElement<? super T>[] elements = structures.get(name);
|
||||
if (elements == null) throw new NoSuchElementException(name);
|
||||
return elements;
|
||||
}
|
||||
|
||||
@@ -3325,7 +3325,7 @@ public class StructureUtility {
|
||||
return (builder.toString().replaceAll("\"\"", "E"));
|
||||
}
|
||||
|
||||
static <T> boolean iterateV2(IStructureElement<T>[] elements, World world, ExtendedFacing extendedFacing,
|
||||
static <T> boolean iterateV2(IStructureElement<? super T>[] elements, World world, ExtendedFacing extendedFacing,
|
||||
int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB,
|
||||
int basePositionC, IStructureWalker<T> predicate, String iterateType) {
|
||||
// change base position to base offset
|
||||
@@ -3336,7 +3336,7 @@ public class StructureUtility {
|
||||
int[] abc = new int[] { basePositionA, basePositionB, basePositionC };
|
||||
int[] xyz = new int[3];
|
||||
|
||||
for (IStructureElement<T> element : elements) {
|
||||
for (IStructureElement<? super T> element : elements) {
|
||||
if (element.isNavigating()) {
|
||||
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
|
||||
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ class SurvivalBuildStructureWalker<T> implements IStructureWalker<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IStructureElement<T> element, World world, int x, int y, int z, int a, int b, int c) {
|
||||
public boolean visit(IStructureElement<? super T> element, World world, int x, int y, int z, int a, int b, int c) {
|
||||
env.offsetABC[0] = a;
|
||||
env.offsetABC[1] = b;
|
||||
env.offsetABC[2] = c;
|
||||
|
||||
Reference in new issue
Block a user