aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTec <daniel112092@gmail.com>2020-04-26 10:54:31 +0200
committerTec <daniel112092@gmail.com>2020-04-26 10:54:31 +0200
commitf1d6a097d4bbe66de07e78a9997eb7f2d6ac2cb6 (patch)
tree4dc2d4d5af74cae5688a48cb0bb1c0df1e78d1f7 /src
parentc601ecf8cd72b76f88fe0b020305a79405a484a5 (diff)
downloadGT5-Unofficial-f1d6a097d4bbe66de07e78a9997eb7f2d6ac2cb6.tar.gz
GT5-Unofficial-f1d6a097d4bbe66de07e78a9997eb7f2d6ac2cb6.tar.bz2
GT5-Unofficial-f1d6a097d4bbe66de07e78a9997eb7f2d6ac2cb6.zip
Remove more old api, add compat, fix typos,add hint only
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java32
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java16
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java25
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java91
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java16
5 files changed, 136 insertions, 44 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 2cd4f04fc8..537bbf8cca 100644
--- a/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java
+++ b/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java
@@ -2,13 +2,16 @@ package com.github.technus.tectech.loader;
import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing;
import com.github.technus.tectech.mechanics.constructable.IMultiblockInfoContainer;
-import com.github.technus.tectech.mechanics.structure.Structure;
+import com.github.technus.tectech.mechanics.structure.IStructureDefinition;
+import com.github.technus.tectech.mechanics.structure.StructureDefinition;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_ElectricBlastFurnace;
-import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import static com.github.technus.tectech.mechanics.constructable.IMultiblockInfoContainer.registerMetaClass;
+import static com.github.technus.tectech.mechanics.structure.StructureUtility.ofBlock;
+import static com.github.technus.tectech.mechanics.structure.StructureUtility.ofHintOnly;
import static gregtech.api.GregTech_API.sBlockCasings1;
public class ConstructableLoader implements Runnable {
@@ -17,13 +20,18 @@ public class ConstructableLoader implements Runnable {
public void run() {
registerMetaClass(GT_MetaTileEntity_ElectricBlastFurnace.class, new IMultiblockInfoContainer<GT_MetaTileEntity_ElectricBlastFurnace>() {
//region Structure
- private final String[][] shape = new String[][]{
- {"000","\"\"\"","\"\"\""," . ",},
- {"0!0","\"A\"","\"A\""," ",},
- {"000","\"\"\"","\"\"\""," ",},
- };
- private final Block[] blockType = new Block[]{sBlockCasings1};
- private final byte[] blockMeta = new byte[]{11};
+ private final IStructureDefinition<GT_MetaTileEntity_ElectricBlastFurnace> definition=
+ StructureDefinition.<GT_MetaTileEntity_ElectricBlastFurnace>builder()
+ .addShapeOldApi("main",new String[][]{
+ {"000","\"\"\"","\"\"\""," . ",},
+ {"0!0","\"A\"","\"A\""," ",},
+ {"000","\"\"\"","\"\"\""," ",},
+ })
+ .addElement('0', ofBlock(sBlockCasings1,11))
+ .addElement('\"', ofHintOnly(3))
+ .addElement('!', ofHintOnly(2))
+ .addElement(' ', ofHintOnly(1))
+ .build();
private final String[] desc=new String[]{
EnumChatFormatting.AQUA+"Hint Details:",
"1 - Classic Hatches or Heat Proof Casing",
@@ -34,8 +42,10 @@ public class ConstructableLoader implements Runnable {
@Override
public void construct(ItemStack stackSize, boolean hintsOnly, GT_MetaTileEntity_ElectricBlastFurnace tileEntity, ExtendedFacing aSide) {
- Structure.builder(shape, blockType, blockMeta, 1, 3, 0,
- tileEntity.getBaseMetaTileEntity(), aSide, hintsOnly);
+ IGregTechTileEntity base = tileEntity.getBaseMetaTileEntity();
+ definition.buildOrHints(tileEntity,"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 ef6ead0eed..9319b4954b 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
@@ -62,8 +62,8 @@ public interface IStructureDefinition<T> {
for (IStructureElement<T> element : elements) {
if(element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
- abc[1] = (element.resetB() ? basePositionA : abc[1]) + element.getStepB();
- abc[2] = (element.resetC() ? basePositionA : abc[2]) + element.getStepC();
+ abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
+ abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
}else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
@@ -84,8 +84,8 @@ public interface IStructureDefinition<T> {
for (IStructureElement<T> element : elements) {
if(element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
- abc[1] = (element.resetB() ? basePositionA : abc[1]) + element.getStepB();
- abc[2] = (element.resetC() ? basePositionA : abc[2]) + element.getStepC();
+ abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
+ abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
}else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
@@ -106,8 +106,8 @@ public interface IStructureDefinition<T> {
for (IStructureElement<T> element : elements) {
if(element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
- abc[1] = (element.resetB() ? basePositionA : abc[1]) + element.getStepB();
- abc[2] = (element.resetC() ? basePositionA : abc[2]) + element.getStepC();
+ abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
+ abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
}else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
@@ -124,8 +124,8 @@ public interface IStructureDefinition<T> {
for (IStructureElement<T> element : elements) {
if(element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
- abc[1] = (element.resetB() ? basePositionA : abc[1]) + element.getStepB();
- abc[2] = (element.resetC() ? basePositionA : abc[2]) + element.getStepC();
+ abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
+ abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
}else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java b/src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java
index 4bab18bd28..e7769b3e04 100644
--- a/src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java
+++ b/src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java
@@ -9,7 +9,6 @@ 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.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@@ -154,26 +153,10 @@ public class Structure {
byte[] blockMeta,//use numbers 0-9 for casing types
int horizontalOffset, int verticalOffset, int depthOffset,
IGregTechTileEntity tileEntity, ExtendedFacing extendedFacing, boolean hintsOnly) {
- return builder(structure, blockType, blockMeta, horizontalOffset, verticalOffset, depthOffset,
- tileEntity.getWorld(), tileEntity.getXCoord(), tileEntity.getYCoord(), tileEntity.getZCoord(),
- extendedFacing, hintsOnly);
- }
-
- public static boolean builder(String[][] structure,//0-9 casing, +- air no air, A... ignore 'A'-CHAR+1 blocks
- Block[] blockType,//use numbers 0-9 for casing types
- byte[] blockMeta,//use numbers 0-9 for casing types
- int horizontalOffset, int verticalOffset, int depthOffset,
- TileEntity tileEntity, ExtendedFacing extendedFacing, boolean hintsOnly) {
- return builder(structure, blockType, blockMeta, horizontalOffset, verticalOffset, depthOffset,
- tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord,
- extendedFacing, hintsOnly);
- }
-
- public static boolean builder(String[][] structure,//0-9 casing, +- air no air, A... ignore 'A'-CHAR+1 blocks
- Block[] blockType,//use numbers 0-9 for casing types
- byte[] blockMeta,//use numbers 0-9 for casing types
- int horizontalOffset, int verticalOffset, int depthOffset,
- World world, int baseX, int baseY, int baseZ, ExtendedFacing extendedFacing, boolean hintsOnly) {
+ World world=tileEntity.getWorld();
+ int baseX=tileEntity.getXCoord();
+ int baseY=tileEntity.getYCoord();
+ int baseZ=tileEntity.getZCoord();
if (world == null || (!world.isRemote && hintsOnly)) {
return false;
}
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 c8262e8473..5c54d05e60 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
@@ -1,5 +1,7 @@
package com.github.technus.tectech.mechanics.structure;
+import com.github.technus.tectech.util.Vec3Impl;
+
import java.util.*;
import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE;
@@ -28,10 +30,12 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
private static final char B='\uB000';
private static final char C='\uC000';
private static final char D='\uD000';
+ private final Map<Vec3Impl,Character> navigates;
private final Map<Character, IStructureElement<T>> elements;
private final Map<String, String> shapes;
private Builder() {
+ navigates=new HashMap<>();
elements = new HashMap<>();
shapes = new HashMap<>();
}
@@ -44,6 +48,79 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
return shapes;
}
+ @Deprecated
+ public Builder<T> addShapeOldApi(String name, String[][] structurePiece) {
+ StringBuilder builder = new StringBuilder();
+ if (structurePiece.length > 0) {
+ for (String[] strings : structurePiece) {
+ if (strings.length > 0) {
+ for (String string : strings) {
+ for (int i = 0; i < string.length(); i++) {
+ char ch = string.charAt(i);
+ if(ch<' '){
+ for (int c = 0; c < ch; c++) {
+ builder.append(B);
+ }
+ }else if(ch>'@'){
+ for (int c = '@'; c < ch; c++) {
+ builder.append(A);
+ }
+ }else{
+ builder.append(ch);
+ }
+ }
+ builder.append(B);
+ }
+ builder.setLength(builder.length() - 1);
+ }
+ builder.append(C);
+ }
+ builder.setLength(builder.length() - 1);
+ }
+ int a=0,b=0,c=0;
+ char d=D;
+ for (int i = 0; i < builder.length(); i++) {
+ char ch = builder.charAt(i);
+ if(ch =='.'){
+ builder.setCharAt(i,A);
+ ch=A;
+ }
+ if(ch==A){
+ a++;
+ }else if(ch==B){
+ a=0;
+ b++;
+ }else if(ch==C){
+ a=0;
+ b=0;
+ c++;
+ }else if(a!=0 || b!=0 || c!=0){
+ Vec3Impl vec3 = new Vec3Impl(a, b, c);
+ Character navigate = navigates.get(vec3);
+ if(navigate==null){
+ navigate=d++;
+ navigates.put(vec3,navigate);
+ addElement(navigate,step(vec3));
+ }
+ builder.setCharAt(i-1,navigate);
+ a=0;
+ b=0;
+ c=0;
+ }
+ }
+
+ String built = builder.toString().replaceAll("[\\uA000\\uB000\\uC000]","");
+
+ if(built.contains("+")){
+ addElement('+',notAir());
+ }
+ if (built.contains("-")) {
+ addElement('-', isAir());
+ }
+ shapes.put(name, built);
+ return this;
+ }
+
/**
* Adds shape
* +- is air/no air checks
@@ -92,8 +169,14 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
b=0;
c++;
}else if(a!=0 || b!=0 || c!=0){
- builder.setCharAt(i-1,d);
- addElement(d,step(a,b,c));
+ Vec3Impl vec3 = new Vec3Impl(a, b, c);
+ Character navigate = navigates.get(vec3);
+ if(navigate==null){
+ navigate=d++;
+ navigates.put(vec3,navigate);
+ addElement(navigate,step(vec3));
+ }
+ builder.setCharAt(i-1,navigate);
a=0;
b=0;
c=0;
@@ -114,7 +197,7 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
}
public Builder<T> addElement(Character name, IStructureElement<T> structurePiece) {
- elements.put(name, structurePiece);
+ elements.putIfAbsent(name, structurePiece);
return this;
}
@@ -128,7 +211,7 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
@SuppressWarnings("unchecked")
private Map<String, IStructureElement<T>[]> compileMap() {
- List<Integer> mising = new ArrayList<>();
+ 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) {
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 a953cf277f..40b1793f93 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
@@ -151,6 +151,22 @@ public class StructureUtility {
return ofHint(block, meta,block,meta);
}
+ public static <T> IStructureElement<T> ofHintOnly(int dots){
+ int meta=dots-1;
+ return new IStructureElement<T>() {
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ return false;
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z) {
+ TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,meta);
+ return true;
+ }
+ };
+ }
+
public static <T> IStructureElement<T> ofHintAdder(IBlockAdder<T> iBlockAdder, Block hintBlock, int hintMeta){
if(iBlockAdder==null ||hintBlock==null){
throw new IllegalArgumentException();