diff options
| author | Tec <daniel112092@gmail.com> | 2020-04-28 19:21:13 +0200 |
|---|---|---|
| committer | Tec <daniel112092@gmail.com> | 2020-04-28 19:21:13 +0200 |
| commit | d58f2055aab235a3f3ead64ef86d1dc39396cae5 (patch) | |
| tree | 1eb36364f2a9a9bad329498c88b753156f4c664d /src/main/java | |
| parent | 0f5cbab6552dfbd514f3183afd4b855f3d1ccb9d (diff) | |
| download | GT5-Unofficial-d58f2055aab235a3f3ead64ef86d1dc39396cae5.tar.gz GT5-Unofficial-d58f2055aab235a3f3ead64ef86d1dc39396cae5.tar.bz2 GT5-Unofficial-d58f2055aab235a3f3ead64ef86d1dc39396cae5.zip | |
Implement new api for collider
Diffstat (limited to 'src/main/java')
10 files changed, 570 insertions, 158 deletions
diff --git a/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java b/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java index 4e1a2eff75..dc282ec0b6 100644 --- a/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java @@ -43,9 +43,9 @@ public class ConstructableLoader implements Runnable { @Override public void construct(ItemStack stackSize, boolean hintsOnly, GT_MetaTileEntity_ElectricBlastFurnace tileEntity, ExtendedFacing aSide) { IGregTechTileEntity base = tileEntity.getBaseMetaTileEntity(); - definition.buildOrHints(tileEntity,"main", base.getWorld(),aSide, - base.getXCoord(),base.getYCoord(),base.getZCoord(), - 1, 3, 0,hintsOnly); + definition.buildOrHints(tileEntity, stackSize, "main", base.getWorld(), + aSide, base.getXCoord(), base.getYCoord(), + base.getZCoord(), 1, 3, 0, hintsOnly); } @Override diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java index 9319b4954b..71305ebd92 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.mechanics.structure; import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; public interface IStructureDefinition<T> { @@ -9,39 +10,39 @@ public interface IStructureDefinition<T> { * @param name same name as for other methods here * @return the array of elements to process */ - IStructureElement<T>[] getElementsFor(String name); + IStructureElement<T>[] getStructureFor(String name); default boolean check(T object,String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, boolean forceCheckAllBlocks){ - return iterate(object,getElementsFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, + return iterate(object, null, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, basePositionA, basePositionB, basePositionC,false,forceCheckAllBlocks); } - default boolean hints(T object,String piece, World world, ExtendedFacing extendedFacing, + default boolean hints(T object, ItemStack trigger,String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC) { - return iterate(object,getElementsFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, + return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, basePositionA, basePositionB, basePositionC,true,null); } - default boolean build(T object,String piece, World world, ExtendedFacing extendedFacing, + default boolean build(T object, ItemStack trigger,String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC) { - return iterate(object,getElementsFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, + return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, basePositionA, basePositionB, basePositionC,false,null); } - default boolean buildOrHints(T object,String piece, World world, ExtendedFacing extendedFacing, + default boolean buildOrHints(T object, ItemStack trigger,String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, boolean hintsOnly){ - return iterate(object,getElementsFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, + return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, basePositionA, basePositionB, basePositionC,hintsOnly,null); } - static <T> boolean iterate(T object, IStructureElement<T>[] elements, World world, ExtendedFacing extendedFacing, + static <T> boolean iterate(T object, ItemStack trigger, IStructureElement<T>[] elements, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, boolean hintsOnly, Boolean checkBlocksIfNotNullForceCheckAllIfTrue){ @@ -115,7 +116,7 @@ public interface IStructureDefinition<T> { xyz[2] += basePositionZ; if (world.blockExists(xyz[0], xyz[1], xyz[2])) { - element.spawnHint(object, world, xyz[0], xyz[1], xyz[2]); + element.spawnHint(object, world, xyz[0], xyz[1], xyz[2], trigger); } abc[0]+=1; } @@ -133,7 +134,7 @@ public interface IStructureDefinition<T> { xyz[2] += basePositionZ; if (world.blockExists(xyz[0], xyz[1], xyz[2])) { - element.placeBlock(object, world, xyz[0], xyz[1], xyz[2]); + element.placeBlock(object, world, xyz[0], xyz[1], xyz[2], trigger); } abc[0]+=1; } diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureElement.java b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureElement.java index f9510910ed..7ed173fbfa 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureElement.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureElement.java @@ -1,5 +1,6 @@ package com.github.technus.tectech.mechanics.structure; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; /** @@ -8,11 +9,11 @@ import net.minecraft.world.World; public interface IStructureElement<T> { boolean check(T t,World world,int x,int y,int z); - default boolean spawnHint(T t,World world,int x,int y,int z){ + default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger){ return false; } - default boolean placeBlock(T t,World world,int x,int y,int z){ + default boolean placeBlock(T t,World world,int x,int y,int z, ItemStack trigger){ return false; } diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureFallback.java b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureFallback.java index 354aaf60e9..1c55753d19 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureFallback.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureFallback.java @@ -1,5 +1,6 @@ package com.github.technus.tectech.mechanics.structure; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; /** @@ -19,9 +20,9 @@ public interface IStructureFallback<T> extends IStructureElement<T> { } @Override - default boolean spawnHint(T t, World world, int x, int y, int z) { + default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { for (IStructureElement<T> fallback : fallbacks()) { - if (fallback.spawnHint(t, world, x, y, z)) { + if (fallback.spawnHint(t, world, x, y, z, trigger)) { return true; } } @@ -29,9 +30,9 @@ public interface IStructureFallback<T> extends IStructureElement<T> { } @Override - default boolean placeBlock(T t, World world, int x, int y, int z) { + default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { for (IStructureElement<T> fallback : fallbacks()) { - if (fallback.placeBlock(t, world, x, y, z)) { + if (fallback.placeBlock(t, world, x, y, z, trigger)) { return true; } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureNavigate.java b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureNavigate.java index 4628c710af..d3f4134cea 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureNavigate.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureNavigate.java @@ -1,5 +1,6 @@ package com.github.technus.tectech.mechanics.structure; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; /** @@ -12,12 +13,12 @@ interface IStructureNavigate<T> extends IStructureElement<T> { } @Override - default boolean spawnHint(T t, World world, int x, int y, int z) { + default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { return true; } @Override - default boolean placeBlock(T t, World world, int x, int y, int z) { + default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { return true; } diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java index 5c54d05e60..9cc82699b9 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java @@ -10,7 +10,7 @@ import static com.github.technus.tectech.mechanics.structure.StructureUtility.*; public class StructureDefinition<T> implements IStructureDefinition<T> { private final Map<Character, IStructureElement<T>> elements; private final Map<String, String> shapes; - private final Map<String, IStructureElement<T>[]> compiled; + private final Map<String, IStructureElement<T>[]> structures; public static <B> Builder<B> builder() { return new Builder<>(); @@ -19,10 +19,10 @@ public class StructureDefinition<T> implements IStructureDefinition<T> { private StructureDefinition( Map<Character, IStructureElement<T>> elements, Map<String, String> shapes, - Map<String, IStructureElement<T>[]> compiled) { + Map<String, IStructureElement<T>[]> structures) { this.elements =elements; this.shapes=shapes; - this.compiled =compiled; + this.structures = structures; } public static class Builder<T> { @@ -48,6 +48,14 @@ public class StructureDefinition<T> implements IStructureDefinition<T> { return shapes; } + /** + * Casings go: 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + * <br/> + * HatchAdders go: space ! " # $ % & ' ( ) * + * @param name + * @param structurePiece + * @return + */ @Deprecated public Builder<T> addShapeOldApi(String name, String[][] structurePiece) { StringBuilder builder = new StringBuilder(); @@ -202,15 +210,46 @@ public class StructureDefinition<T> implements IStructureDefinition<T> { } public IStructureDefinition<T> build() { + Map<String, IStructureElement<T>[]> structures = compileStructureMap(); if(DEBUG_MODE){ - return new StructureDefinition<>(new HashMap<>(elements), new HashMap<>(shapes), compileMap()); + return new StructureDefinition<>(new HashMap<>(elements), new HashMap<>(shapes), structures); }else { - return compileMap()::get; + return structures::get; + } + } + + @SuppressWarnings("unchecked") + private Map<String, IStructureElement<T>[]> compileElementSetMap() { + Set<Integer> mising = new HashSet<>(); + shapes.values().stream().map(CharSequence::chars).forEach(intStream -> intStream.forEach(c -> { + IStructureElement<T> iStructureElement = elements.get((char) c); + if (iStructureElement == null) { + mising.add(c); + } + })); + if (mising.isEmpty()) { + Map<String, IStructureElement<T>[]> map = new HashMap<>(); + shapes.forEach((key, value) -> { + Set<Character> chars=new HashSet<>(); + for (char c : value.toCharArray()) { + chars.add(c); + } + IStructureElement<T>[] compiled = new IStructureElement[chars.size()]; + int i=0; + for (Character aChar : chars) { + compiled[i++]=elements.get(aChar); + } + map.put(key, compiled); + }); + return map; + } else { + throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " + + Arrays.toString(mising.toArray())); } } @SuppressWarnings("unchecked") - private Map<String, IStructureElement<T>[]> compileMap() { + private Map<String, IStructureElement<T>[]> compileStructureMap() { Set<Integer> mising = new HashSet<>(); shapes.values().stream().map(CharSequence::chars).forEach(intStream -> intStream.forEach(c -> { IStructureElement<T> iStructureElement = elements.get((char) c); @@ -243,12 +282,12 @@ public class StructureDefinition<T> implements IStructureDefinition<T> { return shapes; } - public Map<String, IStructureElement<T>[]> getCompiled() { - return compiled; + public Map<String, IStructureElement<T>[]> getStructures() { + return structures; } @Override - public IStructureElement<T>[] getElementsFor(String name) { - return compiled.get(name); + public IStructureElement<T>[] getStructureFor(String name) { + return structures.get(name); } }
\ No newline at end of file diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java index b1be2071a7..1658620d2e 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java @@ -11,11 +11,15 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import java.util.*; +import java.util.function.BiFunction; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sHintCasingsTT; @@ -31,7 +35,7 @@ public class StructureUtility { } @Override - public boolean spawnHint(Object o, World world, int x, int y, int z) { + public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,13); return true; } @@ -44,7 +48,7 @@ public class StructureUtility { } @Override - public boolean spawnHint(Object o, World world, int x, int y, int z) { + public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,14); return true; } @@ -57,7 +61,7 @@ public class StructureUtility { } @Override - public boolean spawnHint(Object o, World world, int x, int y, int z) { + public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,15); return true; } @@ -96,7 +100,7 @@ public class StructureUtility { } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } @@ -122,7 +126,7 @@ public class StructureUtility { } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } @@ -140,7 +144,7 @@ public class StructureUtility { } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } @@ -160,7 +164,7 @@ public class StructureUtility { } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,meta); return true; } @@ -178,7 +182,7 @@ public class StructureUtility { } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } @@ -199,13 +203,13 @@ public class StructureUtility { } @Override - public boolean placeBlock(T t, World world, int x, int y, int z) { + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { world.setBlock(x,y,z,hintBlock,hintMeta,2); return true; } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } @@ -231,13 +235,13 @@ public class StructureUtility { } @Override - public boolean placeBlock(T t, World world, int x, int y, int z) { + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { world.setBlock(x,y,z,hintBlock,hintMeta,2); return true; } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } @@ -255,13 +259,13 @@ public class StructureUtility { } @Override - public boolean placeBlock(T t, World world, int x, int y, int z) { + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { world.setBlock(x,y,z,hintBlock,hintMeta,2); return true; } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } @@ -283,19 +287,44 @@ public class StructureUtility { } @Override - public boolean placeBlock(T t, World world, int x, int y, int z) { + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { world.setBlock(x,y,z,hintBlock,hintMeta,2); return true; } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } }; } + public static <T> IStructureElement<T> ofBlockAdder(IBlockAdder<T> iBlockAdder,int dots){ + int meta=dots-1; + if(iBlockAdder==null ){ + throw new IllegalArgumentException(); + } + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return iBlockAdder.apply(t,world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + world.setBlock(x,y,z,sHintCasingsTT,meta,2); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,meta); + return true; + } + }; + } + public static <T> IStructureElement<T> ofTileAdder(ITileAdder<T> iTileAdder, Block hintBlock, int hintMeta){ if(iTileAdder==null ||hintBlock==null){ throw new IllegalArgumentException(); @@ -308,14 +337,14 @@ public class StructureUtility { } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } }; } - public static <T> IStructureElement<T> ofHatchAdder(IHatchAdder<T> iHatchAdder, Short textureIndex, int dots){ + public static <T> IStructureElement<T> ofHatchAdder(IHatchAdder<T> iHatchAdder, int textureIndex, int dots){ int meta=dots-1; if(iHatchAdder==null){ throw new IllegalArgumentException(); @@ -324,18 +353,18 @@ public class StructureUtility { @Override public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); - return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, textureIndex); + return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, (short)textureIndex); } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,meta); return true; } }; } - public static <T> IStructureElement<T> ofHatchAdder(IHatchAdder<T> iHatchAdder, Short textureIndex, int dots, Block placeCasing,int placeCasingMeta){ + public static <T> IStructureElement<T> ofHatchAdder(IHatchAdder<T> iHatchAdder, int textureIndex, int dots, Block placeCasing,int placeCasingMeta){ int meta=dots-1; if(iHatchAdder==null){ throw new IllegalArgumentException(); @@ -344,24 +373,24 @@ public class StructureUtility { @Override public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); - return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, textureIndex); + return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, (short)textureIndex); } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,meta); return true; } @Override - public boolean placeBlock(T t, World world, int x, int y, int z) { + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { world.setBlock(x,y,z,placeCasing,placeCasingMeta,2); return true; } }; } - public static <T> IStructureElement<T> ofHatchAdder(IHatchAdder<T> iHatchAdder, Short textureIndex, Block hintBlock, int hintMeta){ + public static <T> IStructureElement<T> ofHatchAdder(IHatchAdder<T> iHatchAdder, int textureIndex, Block hintBlock, int hintMeta){ if(iHatchAdder==null ||hintBlock==null){ throw new IllegalArgumentException(); } @@ -369,18 +398,18 @@ public class StructureUtility { @Override public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); - return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, textureIndex); + return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, (short)textureIndex); } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } }; } - public static <T> IStructureElement<T> ofHatchAdder(IHatchAdder<T> iHatchAdder, Short textureIndex, Block hintBlock, int hintMeta, Block placeCasing,int placeCasingMeta){ + public static <T> IStructureElement<T> ofHatchAdder(IHatchAdder<T> iHatchAdder, int textureIndex, Block hintBlock, int hintMeta, Block placeCasing,int placeCasingMeta){ if(iHatchAdder==null ||hintBlock==null){ throw new IllegalArgumentException(); } @@ -388,17 +417,17 @@ public class StructureUtility { @Override public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); - return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, textureIndex); + return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, (short)textureIndex); } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); return true; } @Override - public boolean placeBlock(T t, World world, int x, int y, int z) { + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { world.setBlock(x,y,z,placeCasing,placeCasingMeta,2); return true; } @@ -417,13 +446,13 @@ public class StructureUtility { } @Override - public boolean placeBlock(T t, World world, int x, int y, int z) { - return element.placeBlock(t, world, x, y, z); + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return element.placeBlock(t, world, x, y, z, trigger); } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { - return element.spawnHint(t, world, x, y, z); + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return element.spawnHint(t, world, x, y, z, trigger); } }; } @@ -440,13 +469,381 @@ public class StructureUtility { } @Override - public boolean placeBlock(T t, World world, int x, int y, int z) { - return element.placeBlock(t, world, x, y, z); + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return element.placeBlock(t, world, x, y, z, trigger); } @Override - public boolean spawnHint(T t, World world, int x, int y, int z) { - return element.spawnHint(t, world, x, y, z); + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return element.spawnHint(t, world, x, y, z, trigger); + } + }; + } + + @SafeVarargs + public static <T> IStructureFallback<T> ofElementChain(IStructureElement<T>... elementChain){ + if(elementChain==null || elementChain.length==0){ + throw new IllegalArgumentException(); + } + for (IStructureElement<T> iStructureElement : elementChain) { + if(iStructureElement==null){ + throw new IllegalArgumentException(); + } + } + return () -> elementChain; + } + + public static <T> IStructureElement<T> defer(Supplier<IStructureElement<T>> to){ + if(to==null){ + throw new IllegalArgumentException(); + } + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return to.get().check(t, world, x, y, z); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return to.get().placeBlock(t, world, x, y, z, trigger); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return to.get().spawnHint(t, world, x, y, z, trigger); + } + }; + } + + public static <T> IStructureElement<T> defer(Function<T,IStructureElement<T>> to){ + if(to==null){ + throw new IllegalArgumentException(); + } + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return to.apply(t).check(t, world, x, y, z); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return to.apply(t).placeBlock(t, world, x, y, z, trigger); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return to.apply(t).spawnHint(t, world, x, y, z, trigger); + } + }; + } + + public static <T,K> IStructureElement<T> defer(Function<T,K> keyExtractor,Map<K,IStructureElement<T>> map){ + if(keyExtractor==null||map==null){ + throw new IllegalArgumentException(); + } + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return map.get(keyExtractor.apply(t)).check(t, world, x, y, z); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return map.get(keyExtractor.apply(t)).placeBlock(t, world, x, y, z, trigger); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return map.get(keyExtractor.apply(t)).spawnHint(t, world, x, y, z, trigger); + } + }; + } + + public static <T,K> IStructureElement<T> defer(Function<T,K> keyExtractor,Map<K,IStructureElement<T>> map,IStructureElement<T> defaultElem){ + if(keyExtractor==null||map==null){ + throw new IllegalArgumentException(); + } + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return map.getOrDefault(keyExtractor.app |
