diff options
author | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2019-04-07 16:03:30 +0200 |
---|---|---|
committer | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2019-04-07 16:03:30 +0200 |
commit | 590a9381508f0669913ea54aac8a39868110a6b5 (patch) | |
tree | b55443332efa579fdff1ada404c1bdf5f7259ed9 /src/main/java/com/detrav/utils | |
parent | d3bf79af47974acc0648f85eb112580dd089b25f (diff) | |
download | GT5-Unofficial-590a9381508f0669913ea54aac8a39868110a6b5.tar.gz GT5-Unofficial-590a9381508f0669913ea54aac8a39868110a6b5.tar.bz2 GT5-Unofficial-590a9381508f0669913ea54aac8a39868110a6b5.zip |
refractored code
+added bartworks integration
Diffstat (limited to 'src/main/java/com/detrav/utils')
-rw-r--r-- | src/main/java/com/detrav/utils/BartWorksHelper.java | 17 | ||||
-rw-r--r-- | src/main/java/com/detrav/utils/FluidColors.java | 85 | ||||
-rw-r--r-- | src/main/java/com/detrav/utils/GTppHelper.java | 23 |
3 files changed, 121 insertions, 4 deletions
diff --git a/src/main/java/com/detrav/utils/BartWorksHelper.java b/src/main/java/com/detrav/utils/BartWorksHelper.java new file mode 100644 index 0000000000..5143571087 --- /dev/null +++ b/src/main/java/com/detrav/utils/BartWorksHelper.java @@ -0,0 +1,17 @@ +package com.detrav.utils; + +import com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_Ores; +import net.minecraft.block.Block; +import net.minecraft.world.chunk.Chunk; + +public class BartWorksHelper { + + public static boolean isOre(Block tBlock){ + return tBlock instanceof BW_MetaGenerated_Ores; + } + + public static short getMetaFromBlock(Chunk c, int x, int y, int z, Block tBlock){ + return (short) (tBlock.getDamageValue(c.worldObj,c.xPosition * 16 + x, y, c.zPosition * 16 + z)*-1); + } + +} diff --git a/src/main/java/com/detrav/utils/FluidColors.java b/src/main/java/com/detrav/utils/FluidColors.java new file mode 100644 index 0000000000..d70a348fcc --- /dev/null +++ b/src/main/java/com/detrav/utils/FluidColors.java @@ -0,0 +1,85 @@ +package com.detrav.utils; + +import gregtech.api.enums.Materials; +import net.minecraftforge.fluids.FluidRegistry; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.SplittableRandom; + +public class FluidColors { + + public static final HashMap<Integer, Integer> COLORS = new HashMap<Integer, Integer>(); //contains all FluidIDs and their color counterpath + public static final ArrayList<Integer> USEDC = new ArrayList<Integer>(); //contains all used Colors + + + public static synchronized void setup_colors_from_fluid_registry(){ //should populate COLORS with all the fluids from the Fluid registry and an unique color + if (FluidRegistry.getMaxID()>0){ + for (int i = 0; i < FluidRegistry.getMaxID(); i++) { + if(!USEDC.contains(FluidRegistry.getFluid(i).getColor())) { + USEDC.add(FluidRegistry.getFluid(i).getColor()); + COLORS.put(i,FluidRegistry.getFluid(i).getColor()); + }else{ + int nuclor=getnucolor(); + USEDC.add(nuclor); + COLORS.put(i,nuclor); + } + + } + } + } + + public static synchronized void setup_gt_colors(){ //should populate COLORS with all the fluids from the Materials and an unique color + for (Materials M : Materials.getAll()){ + final int LCOLOR = M.getRGBA()[0]<<24 | M.getRGBA()[1]<<16 | M.getRGBA()[2]<<8 | M.getRGBA()[3]; + + if ( M.mHasGas || //if Material has a Gas + (M.mFluid != null && !M.mFluid.equals(Materials._NULL.mFluid)) || //or a fluid + (M.getMolten(0).getFluid() != null && !M.getMolten(0).equals(Materials._NULL.mFluid))) //or can be molten add it here + if (!addnucolor(M,LCOLOR)){ + boolean nosucess; + do { + nosucess=!addnucolor(M,getnucolor()); + }while (nosucess); + } + } + } + + /** + * + * @return a new and unique color + */ + private static synchronized int getnucolor(){ //gets a new unique color + int nucolor = makenu(); + return !USEDC.contains(nucolor) ? nucolor : getnucolor(); //if the color already is in the list, recall this method and get a new random color. + } + + /** + * + * @return a new random color + */ + private static synchronized int makenu() { + return new SplittableRandom().nextInt(0,256)<<24 & 0xFF | //r + new SplittableRandom().nextInt(0,256)<<16 & 0xFF | //g + new SplittableRandom().nextInt(0,256)<<8 & 0xFF | //b + new SplittableRandom().nextInt(0,256) & 0xFF; //a + } + + /** + * Should add a new and unique Color linked to a Material + * @return if the color was added + */ + private static synchronized boolean addnucolor(Materials M, int color){ + if (!USEDC.contains(color)){ + USEDC.add(color); + if(M.mHasGas) + COLORS.put(M.mGas.getID(), color); + else if (M.mFluid != null && !M.mFluid.equals(Materials._NULL.mFluid)) + COLORS.put(M.mFluid.getID(), color); + else if (M.getMolten(0).getFluid() != null && !M.getMolten(0).equals(Materials._NULL.mFluid)) + COLORS.put(M.getMolten(0).getFluid().getID(), color); + return true; + } + return false; + } +} diff --git a/src/main/java/com/detrav/utils/GTppHelper.java b/src/main/java/com/detrav/utils/GTppHelper.java index e3704671e4..bcd94466f2 100644 --- a/src/main/java/com/detrav/utils/GTppHelper.java +++ b/src/main/java/com/detrav/utils/GTppHelper.java @@ -1,10 +1,11 @@ package com.detrav.utils;
-import java.util.HashMap;
-
-import com.detrav.DetravScannerMod;
-
+import cpw.mods.fml.common.Loader;
+import gtPlusPlus.core.block.base.BlockBaseOre;
import gtPlusPlus.core.material.Material;
+import net.minecraft.block.Block;
+
+import java.util.HashMap;
/**
* Created by bartimaeusnek on 19.04.2018.
@@ -26,4 +27,18 @@ public class GTppHelper { }
}
+
+ public static boolean isGTppBlock(Block tBlock){
+ return tBlock instanceof BlockBaseOre;
+ }
+
+
+ public static short getGTppMeta(Block tBlock){
+ return (short) (GTppHelper.encodeoresGTpp.get(((BlockBaseOre) tBlock).getMaterialEx()) +7000);
+ }
+
+ public static String getGTppVeinName(Block tBlock){
+ return tBlock.getLocalizedName();
+ }
+
}
|