diff options
| author | Jason Mitchell <mitchej@gmail.com> | 2023-01-29 22:47:18 -0800 |
|---|---|---|
| committer | Jason Mitchell <mitchej@gmail.com> | 2023-01-29 22:47:18 -0800 |
| commit | 960bbb3537d7c8c552050b5826de58bc8d798f04 (patch) | |
| tree | 8006e73e99cc48c8b401cf9b34388f9b293dd43e /src | |
| parent | 1e0349649cf45764435b993bc87339742a025078 (diff) | |
| download | GT5-Unofficial-960bbb3537d7c8c552050b5826de58bc8d798f04.tar.gz GT5-Unofficial-960bbb3537d7c8c552050b5826de58bc8d798f04.tar.bz2 GT5-Unofficial-960bbb3537d7c8c552050b5826de58bc8d798f04.zip | |
[ci skip] spotlessApply with the new settings
Diffstat (limited to 'src')
35 files changed, 4643 insertions, 4398 deletions
diff --git a/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java b/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java index e100f4557f..93900c3efe 100644 --- a/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java +++ b/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java @@ -1,139 +1,143 @@ package bloodasp.galacticgreg; -import gregtech.api.GregTech_API; -import gregtech.api.util.GT_Log; -import gregtech.common.blocks.GT_TileEntity_Ores; -import gregtech.common.blocks.GT_Block_Ores_Abstract; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; + import bloodasp.galacticgreg.api.Enums.ReplaceState; import bloodasp.galacticgreg.api.ModDimensionDef; -import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.util.GT_Log; +import gregtech.common.blocks.GT_Block_Ores_Abstract; +import gregtech.common.blocks.GT_TileEntity_Ores; public class GT_TileEntity_Ores_Space { - - // Renamed function to prevent function shadowing with base GT-code - public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, int pMetaData) { - return setOuterSpaceOreBlock(pDimensionDef, pWorld, pX, pY, pZ, pMetaData, false, -1); - } - - public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, int pMetaData, boolean pAir) { - return setOuterSpaceOreBlock(pDimensionDef, pWorld, pX, pY, pZ, pMetaData, pAir, -1); - } - - /** - * Check if the block at given position may be replaced by an ore - * @param pWorld the world in question - * @param pX X-Cord - * @param pY Y-Cord - * @param pZ Z-Cord - * @return - */ - private static ReplaceState CheckForReplaceableBlock(World pWorld, int pX, int pY, int pZ, ModDimensionDef pDimDef) - { - try - { - ReplaceState tFlag = ReplaceState.Unknown; - - Block targetBlock = pWorld.getBlock(pX, pY, pZ); - int targetBlockMeta = pWorld.getBlockMetadata(pX, pY, pZ); - - if (targetBlock == Blocks.air) - tFlag = ReplaceState.Airblock; - else - tFlag = pDimDef.getReplaceStateForBlock(targetBlock, targetBlockMeta); - return tFlag; - } - catch(Exception e) - { - e.printStackTrace(GT_Log.err); - GalacticGreg.Logger.error("Error while processing CheckForReplaceableBlock(), defaulting to UNKNOWN"); - return ReplaceState.Unknown; - } - } - - /** - * Actually set the OreBlock - * @param pWorld the world in question - * @param pX - * @param pY - * @param pZ - * @param pMetaData GT-Ore metadata - * @param pAir - * @return - */ - public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, int pMetaData, boolean pAir, int pCustomGTOreOffset) - { - if (!pAir) - pY = Math.min(pWorld.getActualHeight(), Math.max(pY, 1)); + // Renamed function to prevent function shadowing with base GT-code + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData) { + return setOuterSpaceOreBlock(pDimensionDef, pWorld, pX, pY, pZ, pMetaData, false, -1); + } + + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData, boolean pAir) { + return setOuterSpaceOreBlock(pDimensionDef, pWorld, pX, pY, pZ, pMetaData, pAir, -1); + } + + /** + * Check if the block at given position may be replaced by an ore + * + * @param pWorld the world in question + * @param pX X-Cord + * @param pY Y-Cord + * @param pZ Z-Cord + * @return + */ + private static ReplaceState CheckForReplaceableBlock(World pWorld, int pX, int pY, int pZ, + ModDimensionDef pDimDef) { + try { + ReplaceState tFlag = ReplaceState.Unknown; + + Block targetBlock = pWorld.getBlock(pX, pY, pZ); + int targetBlockMeta = pWorld.getBlockMetadata(pX, pY, pZ); + + if (targetBlock == Blocks.air) tFlag = ReplaceState.Airblock; + else tFlag = pDimDef.getReplaceStateForBlock(targetBlock, targetBlockMeta); + + return tFlag; + } catch (Exception e) { + e.printStackTrace(GT_Log.err); + GalacticGreg.Logger.error("Error while processing CheckForReplaceableBlock(), defaulting to UNKNOWN"); + return ReplaceState.Unknown; + } + } + + /** + * Actually set the OreBlock + * + * @param pWorld the world in question + * @param pX + * @param pY + * @param pZ + * @param pMetaData GT-Ore metadata + * @param pAir + * @return + */ + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData, boolean pAir, int pCustomGTOreOffset) { + if (!pAir) pY = Math.min(pWorld.getActualHeight(), Math.max(pY, 1)); + + if (pDimensionDef == null) { + GalacticGreg.Logger + .warn("Unknown DimensionID: %d. Will not set anything here", pWorld.provider.dimensionId); + return false; + } + try { + Block tBlock = pWorld.getBlock(pX, pY, pZ); + // If the meta is non-zero, and the target block is either non-air or the air-override is active + if ((pMetaData > 0) && ((tBlock != Blocks.air) || pAir)) { + // make sure we're either going with normal ore-metas, or small ores. + // Probably should do another check for <= 1700 + if (pMetaData < 1000 || pMetaData >= 16000) { + ReplaceState tRS = CheckForReplaceableBlock(pWorld, pX, pY, pZ, pDimensionDef); + + // Unable to lookup replacement state. Means: The block is unknown, and shall not be replaced + if (tRS == ReplaceState.Unknown) { + GalacticGreg.Logger.trace("Not placing ore Meta %d, as target block is unknown", pMetaData); + return false; + } else if (tRS == ReplaceState.Airblock && !pAir) { + GalacticGreg.Logger.trace("Not placing ore Meta %d in midair, as AIR is FALSE", pMetaData); + return false; + } + if (tRS == ReplaceState.CannotReplace) { + // wrong metaData ID for target block + GalacticGreg.Logger.trace("Not placing ore Meta %d, as the state is CANNOTREPLACE", pMetaData); + return false; + } + + if (pCustomGTOreOffset == -1) pMetaData += pDimensionDef.getStoneType().getOffset(); + else pMetaData += pCustomGTOreOffset; + // This fix seems like cargo cult coding...The Abstract class just returns 0 for the harvest level. + // But it aligns with the GT5U method, so yay? + pWorld.setBlock( + pX, + pY, + pZ, + GregTech_API.sBlockOres1, + GT_TileEntity_Ores.getHarvestData( + (short) pMetaData, + ((GT_Block_Ores_Abstract) GregTech_API.sBlockOres1) + .getBaseBlockHarvestLevel(pMetaData % 16000 / 1000)), + 0); + TileEntity tTileEntity = pWorld.getTileEntity(pX, pY, pZ); + if ((tTileEntity instanceof GT_TileEntity_Ores)) { + ((GT_TileEntity_Ores) tTileEntity).mMetaData = ((short) pMetaData); + ((GT_TileEntity_Ores) tTileEntity).mNatural = true; + } else { + // This is somehow triggered randomly, and most times the target block is air, which should + // never happen as we check for air... + // That's why I put this behind a debug config option. If you ever find the reason for it, + // please tell me what caused this + if (GalacticGreg.GalacticConfig.ReportOreGenFailures) GalacticGreg.Logger.warn( + "Something went wrong while placing GT OreTileEntity. Meta: %d X [%d] Y [%d] Z [%d]", + pMetaData, + pX, + pY, + pZ); + } - if (pDimensionDef == null) - { - GalacticGreg.Logger.warn("Unknown DimensionID: %d. Will not set anything here", pWorld.provider.dimensionId); - return false; - } - try - { - Block tBlock = pWorld.getBlock(pX, pY, pZ); - // If the meta is non-zero, and the target block is either non-air or the air-override is active - if ((pMetaData > 0) && ((tBlock != Blocks.air) || pAir)) - { - // make sure we're either going with normal ore-metas, or small ores. - // Probably should do another check for <= 1700 - if (pMetaData < 1000 || pMetaData >= 16000) - { - ReplaceState tRS = CheckForReplaceableBlock(pWorld, pX, pY, pZ, pDimensionDef); - - // Unable to lookup replacement state. Means: The block is unknown, and shall not be replaced - if (tRS == ReplaceState.Unknown) - { - GalacticGreg.Logger.trace("Not placing ore Meta %d, as target block is unknown", pMetaData); - return false; - } - else if(tRS == ReplaceState.Airblock && !pAir) - { - GalacticGreg.Logger.trace("Not placing ore Meta %d in midair, as AIR is FALSE", pMetaData); - return false; - } - if (tRS == ReplaceState.CannotReplace) - { - // wrong metaData ID for target block - GalacticGreg.Logger.trace("Not placing ore Meta %d, as the state is CANNOTREPLACE", pMetaData); - return false; - } - - if (pCustomGTOreOffset == -1) - pMetaData += pDimensionDef.getStoneType().getOffset(); - else - pMetaData += pCustomGTOreOffset; - // This fix seems like cargo cult coding...The Abstract class just returns 0 for the harvest level. But it aligns with the GT5U method, so yay? - pWorld.setBlock(pX, pY, pZ, GregTech_API.sBlockOres1, GT_TileEntity_Ores.getHarvestData((short) pMetaData, ( (GT_Block_Ores_Abstract)GregTech_API.sBlockOres1).getBaseBlockHarvestLevel(pMetaData % 16000 / 1000)), 0); - TileEntity tTileEntity = pWorld.getTileEntity(pX, pY, pZ); - if ((tTileEntity instanceof GT_TileEntity_Ores)) { - ((GT_TileEntity_Ores) tTileEntity).mMetaData = ((short) pMetaData); - ((GT_TileEntity_Ores) tTileEntity).mNatural = true; - } - else - { - // This is somehow triggered randomly, and most times the target block is air, which should never happen as we check for air... - // That's why I put this behind a debug config option. If you ever find the reason for it, please tell me what caused this - if (GalacticGreg.GalacticConfig.ReportOreGenFailures) - GalacticGreg.Logger.warn("Something went wrong while placing GT OreTileEntity. Meta: %d X [%d] Y [%d] Z [%d]", pMetaData, pX, pY, pZ); - } - - return true; - } - else - GalacticGreg.Logger.warn("Not replacing block at pos %d %d %d due unexpected metaData for OreBlock: %d", pX, pY, pZ, pMetaData); - } - } catch (Exception e) - { - if (GalacticGreg.GalacticConfig.ReportOreGenFailures) - e.printStackTrace(); - } - return false; - } + return true; + } else GalacticGreg.Logger.warn( + "Not replacing block at pos %d %d %d due unexpected metaData for OreBlock: %d", + pX, + pY, + pZ, + pMetaData); + } + } catch (Exception e) { + if (GalacticGreg.GalacticConfig.ReportOreGenFailures) e.printStackTrace(); + } + return false; + } } diff --git a/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java b/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java index 97e20e0f54..3f4308e1de 100644 --- a/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java +++ b/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java @@ -1,5 +1,14 @@ package bloodasp.galacticgreg; +import static gregtech.api.enums.GT_Values.oreveinPlacerOres; +import static gregtech.api.enums.GT_Values.oreveinPlacerOresMultiplier; + +import java.util.*; + +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + import bloodasp.galacticgreg.api.ModDimensionDef; import bloodasp.galacticgreg.auxiliary.GTOreGroup; import bloodasp.galacticgreg.bartworks.BW_Worldgen_Ore_Layer_Space; @@ -9,348 +18,377 @@ import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; import gregtech.api.util.GT_Log; import gregtech.api.world.GT_Worldgen; -import gregtech.common.blocks.GT_TileEntity_Ores; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; - -import java.util.*; - -import static gregtech.api.enums.GT_Values.oreveinPlacerOres; -import static gregtech.api.enums.GT_Values.oreveinPlacerOresMultiplier; public class GT_Worldgen_GT_Ore_Layer_Space extends GT_Worldgen { - public static int sWeight = 0; - public final short mMinY; - public final short mMaxY; - public final short mWeight; - public final short mDensity; - public final short mSize; - public final short mPrimaryMeta; - public final short mSecondaryMeta; - public final short mBetweenMeta; - public final short mSporadicMeta; - - private long mProfilingStart; - private long mProfilingEnd; - - private DynamicOreMixWorldConfig _mDynWorldConfig; - - public GT_Worldgen_GT_Ore_Layer_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pWeight, int pDensity, int pSize, Materials pPrimary, Materials pSecondary, Materials pBetween, Materials pSporadic) - { - super(pName, GalacticGreg.oreVeinWorldgenList, pDefault); - mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); - mMaxY = ((short) Math.max(this.mMinY + 5, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); - mWeight = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "RandomWeight", pWeight)); - mDensity = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Density", pDensity)); - mSize = ((short) Math.max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Size", pSize))); - mPrimaryMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OrePrimaryLayer", pPrimary.mMetaItemSubID)); - mSecondaryMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSecondaryLayer", pSecondary.mMetaItemSubID)); - mBetweenMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSporadiclyInbetween", pBetween.mMetaItemSubID)); - mSporadicMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSporaticlyAround", pSporadic.mMetaItemSubID)); - - _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); - _mDynWorldConfig.InitDynamicConfig(); - - GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); - - if (mEnabled) - GT_Worldgen_GT_Ore_Layer_Space.sWeight += this.mWeight; - - } - - public GT_Worldgen_GT_Ore_Layer_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pWeight, int pDensity, int pSize, short pPrimary, short pSecondary, short pBetween, short pSporadic) { - super(pName, GalacticGreg.oreVeinWorldgenList, pDefault); - mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); - mMaxY = ((short) Math.max(this.mMinY + 5, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); - mWeight = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "RandomWeight", pWeight)); - mDensity = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Density", pDensity)); - mSize = ((short) Math.max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Size", pSize))); - mPrimaryMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OrePrimaryLayer", pPrimary)); - mSecondaryMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSecondaryLayer", pSecondary)); - mBetweenMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSporadiclyInbetween", pBetween)); - mSporadicMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSporaticlyAround", pSporadic)); - - _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); - _mDynWorldConfig.InitDynamicConfig(); - - GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); - - if (mEnabled) - sWeight += this.mWeight; - - } - - /** - * Check if *this* orelayer is enabled for pDimensionDef - * @param pDimensionDef the ChunkProvider in question - * @return - */ - public boolean isEnabledForDim(ModDimensionDef pDimensionDef) - { - return _mDynWorldConfig.isEnabledInDim(pDimensionDef); - } - - private static Map<String, Integer> _mBufferedVeinCountList = new HashMap<>(); - - /** - * Get the number of enabled OreMixes for given Dimension. - * This query is buffered and will only consume calculation time on the first run for each dimension - * @param pDimensionDef - * @return - */ - private static int getNumOremixedForDim(ModDimensionDef pDimensionDef) - { - int tVal = 0; - if (_mBufferedVeinCountList.containsKey(pDimensionDef.getDimIdentifier())) - tVal = _mBufferedVeinCountList.get(pDimensionDef.getDimIdentifier()); - else - { - for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) - if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) - tVal++; - - _mBufferedVeinCountList.put(pDimensionDef.getDimIdentifier(), tVal); - } - - return tVal; - } - - - private static Map<String, List<String>> _mBufferedVeinList = new HashMap<>(); - /** - * Get a List of all Veins which are enabled for given Dim. Query is buffered - * @param pDimensionDef - * @return null if nothing is found or error - */ - private static List<String> getOreMixIDsForDim(ModDimensionDef pDimensionDef) - { - List<String> tReturn; - - if (_mBufferedVeinList.containsKey(pDimensionDef.getDimIdentifier())) - tReturn = _mBufferedVeinList.get(pDimensionDef.getDimIdentifier()); - else - { - tReturn = new ArrayList<>(); - for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) - if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) - tReturn.add(tWorldGen.mWorldGenName); - else if (tWorldGen instanceof BW_Worldgen_Ore_Layer_Space && ((BW_Worldgen_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) + + public static int sWeight = 0; + public final short mMinY; + public final short mMaxY; + public final short mWeight; + public final short mDensity; + public final short mSize; + public final short mPrimaryMeta; + public final short mSecondaryMeta; + public final short mBetweenMeta; + public final short mSporadicMeta; + + private long mProfilingStart; + private long mProfilingEnd; + + private DynamicOreMixWorldConfig _mDynWorldConfig; + + public GT_Worldgen_GT_Ore_Layer_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pWeight, + int pDensity, int pSize, Materials pPrimary, Materials pSecondary, Materials pBetween, + Materials pSporadic) { + super(pName, GalacticGreg.oreVeinWorldgenList, pDefault); + mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math.max( + this.mMinY + 5, + GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); + mWeight = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "RandomWeight", pWeight)); + mDensity = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Density", pDensity)); + mSize = ((short) Math.max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Size", pSize))); + mPrimaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OrePrimaryLayer", pPrimary.mMetaItemSubID)); + mSecondaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSecondaryLayer", pSecondary.mMetaItemSubID)); + mBetweenMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSporadiclyInbetween", pBetween.mMetaItemSubID)); + mSporadicMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSporaticlyAround", pSporadic.mMetaItemSubID)); + + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); + _mDynWorldConfig.InitDynamicConfig(); + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); + + if (mEnabled) GT_Worldgen_GT_Ore_Layer_Space.sWeight += this.mWeight; + + } + + public GT_Worldgen_GT_Ore_Layer_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pWeight, + int pDensity, int pSize, short pPrimary, short pSecondary, short pBetween, short pSporadic) { + super(pName, GalacticGreg.oreVeinWorldgenList, pDefault); + mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math.max( + this.mMinY + 5, + GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); + mWeight = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "RandomWeight", pWeight)); + mDensity = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Density", pDensity)); + mSize = ((short) Math.max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Size", pSize))); + mPrimaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OrePrimaryLayer", pPrimary)); + mSecondaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSecondaryLayer", pSecondary)); + mBetweenMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSporadiclyInbetween", pBetween)); + mSporadicMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSporaticlyAround", pSporadic)); + + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); + _mDynWorldConfig.InitDynamicConfig(); + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); + + if (mEnabled) sWeight += this.mWeight; + + } + + /** + * Check if *this* orelayer is enabled for pDimensionDef + * + * @param pDimensionDef the ChunkProvider in question + * @return + */ + public boolean isEnabledForDim(ModDimensionDef pDimensionDef) { + return _mDynWorldConfig.isEnabledInDim(pDimensionDef); + } + + private static Map<String, Integer> _mBufferedVeinCountList = new HashMap<>(); + + /** + * Get the number of enabled OreMixes for given Dimension. This query is buffered and will only consume calculation + * time on the first run for each dimension + * + * @param pDimensionDef + * @return + */ + private static int getNumOremixedForDim(ModDimensionDef pDimensionDef) { + int tVal = 0; + if (_mBufferedVeinCountList.containsKey(pDimensionDef.getDimIdentifier())) + tVal = _mBufferedVeinCountList.get(pDimensionDef.getDimIdentifier()); + else { + for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) + if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space + && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) + tVal++; + + _mBufferedVeinCountList.put(pDimensionDef.getDimIdentifier(), tVal); + } + + return tVal; + } + + private static Map<String, List<String>> _mBufferedVeinList = new HashMap<>(); + + /** + * Get a List of all Veins which are enabled for given Dim. Query is buffered + * + * @param pDimensionDef + * @return null if nothing is found or error + */ + private static List<String> getOreMixIDsForDim(ModDimensionDef pDimensionDef) { + List<String> tReturn; + + if (_mBufferedVeinList.containsKey(pDimensionDef.getDimIdentifier())) + tReturn = _mBufferedVeinList.get(pDimensionDef.getDimIdentifier()); + else { + tReturn = new ArrayList<>(); + for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) + if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space + && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) tReturn.add(tWorldGen.mWorldGenName); - - _mBufferedVeinList.put(pDimensionDef.getDimIdentifier(), tReturn); - } - - return tReturn; - } - - private static short getMaxWeightForDim(ModDimensionDef pDimensionDef) - { - short tVal = 0; - for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) - if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef) && tVal < ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mWeight) - tVal = ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mWeight; - - return tVal; - } - - /** - * Select a random ore-vein from the list - * - * @param pDimensionDef - * @param pRandom - * @return - */ - public static GTOreGroup getRandomOreGroup(ModDimensionDef pDimensionDef, Random pRandom, boolean pIgnoreWeight) - { - short primaryMeta = 0; - short secondaryMeta = 0; - short betweenMeta = 0; - short sporadicMeta = 0; - - //int tRangeSplit = getMaxWeightForDim(pDimensionDef) / 2; - - if (pIgnoreWeight) - { - List<String> tEnabledVeins = getOreMixIDsForDim(pDimensionDef); - int tRnd = pRandom.nextInt(tEnabledVeins.size()); - String tVeinName = tEnabledVeins.get(tRnd); - - // No lambda in Java 1.6 and 1.7 :( - //GT_Worldgen_GT_Ore_Layer_Space tGen = GalacticGreg.oreVeinWorldgenList.stream().filter(p -> p.mWorldGenName == tVeinName).findFirst(); - - GT_Worldgen tGen = null; - for (GT_ |
