diff --git a/src/main/java/bartworks/API/VoidMinerDropAdder.java b/src/main/java/bartworks/API/VoidMinerDropAdder.java deleted file mode 100644 index de55ade363f..00000000000 --- a/src/main/java/bartworks/API/VoidMinerDropAdder.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.API; - -import bwcrossmod.galacticgreg.VoidMinerUtility; -import gregtech.api.interfaces.ISubTagContainer; - -public class VoidMinerDropAdder { - - public static void addDropsToDim(int dimID, ISubTagContainer material, float chance) { - VoidMinerUtility.addMaterialToDimensionList(dimID, material, chance); - } -} diff --git a/src/main/java/bartworks/client/renderer/BWBlockOreRenderer.java b/src/main/java/bartworks/client/renderer/BWBlockOreRenderer.java deleted file mode 100644 index 781ead228e3..00000000000 --- a/src/main/java/bartworks/client/renderer/BWBlockOreRenderer.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.client.renderer; - -import static gregtech.common.render.GTRendererBlock.renderNegativeXFacing; -import static gregtech.common.render.GTRendererBlock.renderNegativeYFacing; -import static gregtech.common.render.GTRendererBlock.renderNegativeZFacing; -import static gregtech.common.render.GTRendererBlock.renderPositiveXFacing; -import static gregtech.common.render.GTRendererBlock.renderPositiveYFacing; -import static gregtech.common.render.GTRendererBlock.renderPositiveZFacing; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import com.gtnewhorizons.angelica.api.ThreadSafeISBRH; - -import bartworks.system.material.BWMetaGeneratedBlocks; -import bartworks.system.material.TileEntityMetaGeneratedBlock; -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; -import cpw.mods.fml.client.registry.RenderingRegistry; -import gregtech.GTMod; - -@ThreadSafeISBRH(perThread = true) -public class BWBlockOreRenderer implements ISimpleBlockRenderingHandler { - - public static BWBlockOreRenderer INSTANCE; - public static int renderID; - public static final float blockMin = 0.0F; - public static final float blockMax = 1.0F; - - public static void register() { - renderID = RenderingRegistry.getNextAvailableRenderId(); - INSTANCE = new BWBlockOreRenderer(); - RenderingRegistry.registerBlockHandler(INSTANCE); - } - - @Override - public void renderInventoryBlock(Block aBlock, int aMeta, int modelId, RenderBlocks aRenderer) { - TileEntityMetaGeneratedBlock tTileEntity = ((BWMetaGeneratedBlocks) aBlock).getProperTileEntityForRendering(); - tTileEntity.mMetaData = (short) aMeta; - aRenderer.enableAO = false; - aRenderer.useInventoryTint = true; - aBlock.setBlockBoundsForItemRender(); - aRenderer.setRenderBoundsFromBlock(aBlock); - GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); - GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - renderNegativeYFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - tTileEntity.getTexture(aBlock, ForgeDirection.DOWN), - true); - renderPositiveYFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - tTileEntity.getTexture(aBlock, ForgeDirection.UP), - true); - renderNegativeZFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - tTileEntity.getTexture(aBlock, ForgeDirection.NORTH), - true); - renderPositiveZFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - tTileEntity.getTexture(aBlock, ForgeDirection.SOUTH), - true); - renderNegativeXFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - tTileEntity.getTexture(aBlock, ForgeDirection.WEST), - true); - renderPositiveXFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - tTileEntity.getTexture(aBlock, ForgeDirection.EAST), - true); - aRenderer.setRenderBoundsFromBlock(aBlock); - aBlock.setBlockBounds(blockMin, blockMin, blockMin, blockMax, blockMax, blockMax); - GL11.glTranslatef(0.5F, 0.5F, 0.5F); - aRenderer.useInventoryTint = false; - } - - // spotless:off - @Override - public boolean renderWorldBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, int modelId, RenderBlocks aRenderer) { - BWMetaGeneratedBlocks tBlock = (BWMetaGeneratedBlocks) aBlock; - if(tBlock == null) return false; - - TileEntityMetaGeneratedBlock fakeTileEntity = tBlock.getProperTileEntityForRendering(); // meh - if(fakeTileEntity == null) return false; - - TileEntityMetaGeneratedBlock actualTileEntity = (TileEntityMetaGeneratedBlock) aWorld.getTileEntity(aX, aY, aZ); - if(actualTileEntity == null) return false; - - fakeTileEntity.mMetaData = actualTileEntity.mMetaData; - aRenderer.useInventoryTint = false; - aBlock.setBlockBounds(blockMin, blockMin, blockMin, blockMax, blockMax, blockMax); - aRenderer.enableAO = Minecraft.isAmbientOcclusionEnabled() && GTMod.gregtechproxy.mRenderTileAmbientOcclusion; - aRenderer.setRenderBoundsFromBlock(aBlock); - renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, fakeTileEntity.getTexture(aBlock, ForgeDirection.DOWN), true); - renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, fakeTileEntity.getTexture(aBlock, ForgeDirection.UP), true); - renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, fakeTileEntity.getTexture(aBlock, ForgeDirection.NORTH), true); - renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, fakeTileEntity.getTexture(aBlock, ForgeDirection.SOUTH), true); - renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, fakeTileEntity.getTexture(aBlock, ForgeDirection.WEST), true); - renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, fakeTileEntity.getTexture(aBlock, ForgeDirection.EAST), true); - return true; - } - // spotless:on - - @Override - public boolean shouldRender3DInInventory(int modelId) { - return true; - } - - @Override - public int getRenderId() { - return renderID; - } -} diff --git a/src/main/java/bartworks/common/loaders/StaticRecipeChangeLoaders.java b/src/main/java/bartworks/common/loaders/StaticRecipeChangeLoaders.java index ae1c0375893..d36ab0d898f 100644 --- a/src/main/java/bartworks/common/loaders/StaticRecipeChangeLoaders.java +++ b/src/main/java/bartworks/common/loaders/StaticRecipeChangeLoaders.java @@ -103,7 +103,7 @@ public static void unificationRecipeEnforcer() { for (Werkstoff werkstoff : Werkstoff.werkstoffHashSet) { StaticRecipeChangeLoaders.runMaterialLinker(werkstoff); if (werkstoff.getGenerationFeatures().enforceUnification) { - HashSet oreDictNames = new HashSet<>(werkstoff.getADDITIONAL_OREDICT()); + HashSet oreDictNames = new HashSet<>(werkstoff.getAdditionalOredict()); oreDictNames.add(werkstoff.getVarName()); StaticRecipeChangeLoaders.runMoltenUnificationEnfocement(werkstoff); StaticRecipeChangeLoaders.runUnficationDeleter(werkstoff); diff --git a/src/main/java/bartworks/neiHandler/NEIBWConfig.java b/src/main/java/bartworks/neiHandler/NEIBWConfig.java index 64c91072ee8..cd7c2c5ccc6 100644 --- a/src/main/java/bartworks/neiHandler/NEIBWConfig.java +++ b/src/main/java/bartworks/neiHandler/NEIBWConfig.java @@ -78,7 +78,6 @@ public void loadConfig() { } NEIBWConfig.sIsAdded = false; - new OreNEIHandler(); new BioVatNEIHandler(BartWorksRecipeMaps.bacterialVatRecipes.getDefaultRecipeCategory()); new BioLabNEIHandler(BartWorksRecipeMaps.bioLabRecipes.getDefaultRecipeCategory()); NEIBWConfig.sIsAdded = true; diff --git a/src/main/java/bartworks/neiHandler/OreNEIHandler.java b/src/main/java/bartworks/neiHandler/OreNEIHandler.java deleted file mode 100644 index 3732c56aff1..00000000000 --- a/src/main/java/bartworks/neiHandler/OreNEIHandler.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.neiHandler; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; - -import bartworks.MainMod; -import bartworks.system.material.BWMetaGeneratedOres; -import bartworks.system.material.BWMetaGeneratedSmallOres; -import bartworks.system.material.Werkstoff; -import bartworks.system.oregen.BWOreLayer; -import bartworks.system.oregen.BWWorldGenRoss128b; -import bartworks.system.oregen.BWWorldGenRoss128ba; -import codechicken.lib.gui.GuiDraw; -import codechicken.nei.PositionedStack; -import codechicken.nei.recipe.GuiCraftingRecipe; -import codechicken.nei.recipe.TemplateRecipeHandler; -import cpw.mods.fml.common.event.FMLInterModComms; -import gregtech.api.enums.OrePrefixes; - -public class OreNEIHandler extends TemplateRecipeHandler { - - public OreNEIHandler() { - if (!NEIBWConfig.sIsAdded) { - FMLInterModComms.sendRuntimeMessage( - MainMod.MOD_ID, - "NEIPlugins", - "register-crafting-handler", - MainMod.MOD_ID + "@" + this.getRecipeName() + "@" + this.getOverlayIdentifier()); - GuiCraftingRecipe.craftinghandlers.add(this); - } - } - - @Override - public void drawBackground(int recipe) { - GuiDraw.drawRect(0, 0, 166, 65, 0x888888); - } - - @Override - public void loadTransferRects() { - this.transferRects.add( - new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(0, 40, 40, 120), "quickanddirtyneihandler")); - } - - @Override - public int recipiesPerPage() { - return 1; - } - - @Override - public void loadCraftingRecipes(String outputId, Object... results) { - if ("quickanddirtyneihandler".equalsIgnoreCase(outputId)) { - HashSet result = new HashSet<>(); - Werkstoff.werkstoffHashSet.stream() - .filter(w -> w.hasGenerationFeature(OrePrefixes.ore)) - .forEach(w -> result.add(w.get(OrePrefixes.ore))); - result.forEach(this::loadCraftingRecipes); - result.clear(); - Werkstoff.werkstoffHashSet.stream() - .filter(w -> w.hasGenerationFeature(OrePrefixes.ore)) - .forEach(w -> result.add(w.get(OrePrefixes.oreSmall))); - result.forEach(this::loadCraftingRecipes); - result.clear(); - HashSet hashSet = new HashSet<>(this.arecipes); - this.arecipes.clear(); - this.arecipes.addAll(hashSet); - } - if ("item".equals(outputId)) { - this.loadCraftingRecipes((ItemStack) results[0]); - HashSet hashSet = new HashSet<>(this.arecipes); - this.arecipes.clear(); - this.arecipes.addAll(hashSet); - } - } - - @Override - public void drawExtras(int recipe) { - if (recipe < this.arecipes.size() && this.arecipes.get(recipe) instanceof CachedOreRecipe cachedOreRecipe) { - - if (cachedOreRecipe.getOtherStacks() == null || cachedOreRecipe.getOtherStacks() - .isEmpty()) return; - - if (!cachedOreRecipe.small) { - if (cachedOreRecipe.getOtherStacks() - .get(0) == null - || cachedOreRecipe.getOtherStacks() - .get(0).item == null - || cachedOreRecipe.getOtherStacks() - .get(1) == null - || cachedOreRecipe.getOtherStacks() - .get(2) == null - || cachedOreRecipe.getOtherStacks() - .get(3) == null - || cachedOreRecipe.getOtherStacks() - .get(1).item == null - || cachedOreRecipe.getOtherStacks() - .get(2).item == null - || cachedOreRecipe.getOtherStacks() - .get(3).item == null) - return; - } else if (cachedOreRecipe.getOtherStacks() - .get(0) == null - || cachedOreRecipe.getOtherStacks() - .get(0).item == null) - return; - - if (cachedOreRecipe.worldGen != null) GuiDraw.drawString( - EnumChatFormatting.BOLD + "DIM: " + EnumChatFormatting.RESET + cachedOreRecipe.worldGen.getDimName(), - 0, - 40, - 0, - false); - - GuiDraw.drawString(EnumChatFormatting.BOLD + "Primary:", 0, 50, 0, false); - GuiDraw.drawString( - cachedOreRecipe.getOtherStacks() - .get(0).item.getDisplayName(), - 0, - 60, - 0, - false); - - if (!cachedOreRecipe.small) { - GuiDraw.drawString(EnumChatFormatting.BOLD + "Secondary:", 0, 70, 0, false); - GuiDraw.drawString( - cachedOreRecipe.getOtherStacks() - .get(1).item.getDisplayName(), - 0, - 80, - 0, - false); - GuiDraw.drawString(EnumChatFormatting.BOLD + "InBetween:", 0, 90, 0, false); - GuiDraw.drawString( - cachedOreRecipe.getOtherStacks() - .get(2).item.getDisplayName(), - 0, - 100, - 0, - false); - GuiDraw.drawString(EnumChatFormatting.BOLD + "Sporadic:", 0, 110, 0, false); - GuiDraw.drawString( - cachedOreRecipe.getOtherStacks() - .get(3).item.getDisplayName(), - 0, - 120, - 0, - false); - } else if (cachedOreRecipe.worldGen != null) { - GuiDraw.drawString(EnumChatFormatting.BOLD + "Amount per Chunk:", 0, 70, 0, false); - GuiDraw.drawString(cachedOreRecipe.worldGen.mDensity + "", 0, 80, 0, false); - } - } - super.drawExtras(recipe); - } - - @Override - public void loadCraftingRecipes(ItemStack result) { - Block ore = Block.getBlockFromItem(result.getItem()); - if (ore instanceof BWMetaGeneratedOres) { - BWOreLayer.NEIMAP.get((short) result.getItemDamage()) - .stream() - .filter( - l -> !(ore instanceof BWMetaGeneratedSmallOres) || !l.getClass() - .equals(BWWorldGenRoss128b.class) - && !l.getClass() - .equals(BWWorldGenRoss128ba.class)) - .forEach( - l -> this.arecipes.add(new CachedOreRecipe(l, result, ore instanceof BWMetaGeneratedSmallOres))); - } - } - - @Override - public String getGuiTexture() { - return "textures/gui/container/brewing_stand.png"; - } - - @Override - public String getRecipeName() { - return "BartWorks Ores"; - } - - class CachedOreRecipe extends TemplateRecipeHandler.CachedRecipe { - - public CachedOreRecipe(BWOreLayer worldGen, ItemStack result, boolean smallOres) { - this.worldGen = worldGen; - this.stack = new PositionedStack(result, 0, 0); - this.small = smallOres; - } - - boolean small; - BWOreLayer worldGen; - PositionedStack stack; - - @Override - public PositionedStack getResult() { - return this.stack; - } - - @Override - public List getOtherStacks() { - List ret = new ArrayList<>(); - int x = 0; - for (int i = 0; i < (this.small ? 1 : 4); i++) { - x += 20; - ret.add( - new PositionedStack( - this.worldGen.getStacks() - .get(i), - x, - 12)); - } - return ret; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CachedOreRecipe that)) return false; - return Objects.equals(this.worldGen, that.worldGen); - } - - @Override - public int hashCode() { - return this.worldGen.hashCode(); - } - } -} diff --git a/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java b/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java index 5351824c7cc..0bbc0fb0490 100644 --- a/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java +++ b/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java @@ -68,7 +68,7 @@ public void onPlayerTickEventServer(TickEvent.PlayerTickEvent event) { toReplace = GTOreDictUnificator.get(prefixes, e.getVarName(), stack.stackSize); break loop; } - for (String s : e.getADDITIONAL_OREDICT()) { + for (String s : e.getAdditionalOredict()) { if (oreDictName.contains(s)) { String prefix = oreDictName.replace(s, ""); OrePrefixes prefixes = OrePrefixes.getPrefix(prefix); diff --git a/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java b/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java new file mode 100644 index 00000000000..77eb6c45348 --- /dev/null +++ b/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java @@ -0,0 +1,66 @@ +package bartworks.system.material; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +import gregtech.api.GregTechAPI; +import gregtech.api.enums.OrePrefixes; + +public class BWItemMetaGeneratedOre extends ItemBlock { + + public final BWMetaGeneratedOres blockOre; + + public BWItemMetaGeneratedOre(Block block) { + super(block); + setMaxDamage(0); + setHasSubtypes(true); + setCreativeTab(GregTechAPI.TAB_GREGTECH_MATERIALS); + + blockOre = (BWMetaGeneratedOres) block; + } + + @Override + public int getMetadata(int meta) { + return meta; + } + + private OrePrefixes getOrePrefix() { + return blockOre.isSmall ? OrePrefixes.oreSmall : OrePrefixes.ore; + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return "bw.blocktype." + getOrePrefix().name(); + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + int meta = stack.getItemDamage(); + + Werkstoff werkstoff = Werkstoff.werkstoffHashMap.get((short) meta); + + if (werkstoff == null) { + return blockOre.blockTypeLocalizedName.replace("%material", "Empty"); + } + + return blockOre.blockTypeLocalizedName.replace("%material", werkstoff.getLocalizedName()); + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List desc, boolean advancedTooltips) { + int meta = stack.getItemDamage(); + + Werkstoff werkstoff = Werkstoff.werkstoffHashMap.get((short) meta); + + if (werkstoff != null) { + String tooltip = werkstoff.getLocalizedToolTip(); + if (!tooltip.isEmpty()) { + desc.add(tooltip); + } + } + } +} diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedBlocks.java b/src/main/java/bartworks/system/material/BWMetaGeneratedBlocks.java index 533f16089fa..7cd5a762fba 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedBlocks.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedBlocks.java @@ -24,7 +24,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import bartworks.client.renderer.BWBlockOreRenderer; import bartworks.common.blocks.BWTileEntityContainer; import bartworks.util.BWUtil; import cpw.mods.fml.relauncher.Side; @@ -83,12 +82,6 @@ protected boolean canSilkHarvest() { return false; } - @Override - public int getRenderType() { - if (BWBlockOreRenderer.INSTANCE == null) return super.getRenderType(); - return BWBlockOreRenderer.renderID; - } - @Override public int getDamageValue(World aWorld, int aX, int aY, int aZ) { TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java index 6aca001b13c..2e940b12456 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -13,8 +13,13 @@ package bartworks.system.material; -import java.util.Arrays; +import static bartworks.system.material.BWMetaGeneratedItems.metaTab; + +import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +import javax.annotation.Nullable; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -24,54 +29,66 @@ import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; -import bartworks.util.MathUtils; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IBlockWithTextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.render.TextureFactory; import gregtech.api.util.GTLanguageManager; +import gregtech.api.util.GTOreDictUnificator; +import gregtech.common.ores.BWOreAdapter; +import gregtech.common.ores.OreInfo; +import gregtech.common.render.GTRendererBlock; + +public class BWMetaGeneratedOres extends Block implements IBlockWithTextures { + + public final String blockName; + public final String blockTypeLocalizedName; + public final StoneType stoneType; + public final boolean isSmall, isNatural; + + public BWMetaGeneratedOres(String blockName, StoneType stoneType, boolean small, boolean natural) { + super(Material.rock); + + this.setBlockName(blockName); + this.setHardness(5.0F); + this.setResistance(5.0F); + this.setCreativeTab(metaTab); + + if (small) { + this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( + blockName, + OrePrefixes.oreSmall.mLocalizedMaterialPre + "%material" + OrePrefixes.oreSmall.mLocalizedMaterialPost); + } else { + this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( + blockName, + OrePrefixes.ore.mLocalizedMaterialPre + "%material" + OrePrefixes.ore.mLocalizedMaterialPost); + } -public class BWMetaGeneratedOres extends BWMetaGeneratedBlocks { - - public BWMetaGeneratedOres(Material p_i45386_1_, Class tileEntity, String blockName) { - super(p_i45386_1_, tileEntity, blockName); - this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( - "bw.blocktype." + OrePrefixes.ore, - OrePrefixes.ore.mLocalizedMaterialPre + "%material" + OrePrefixes.ore.mLocalizedMaterialPost); + this.blockName = blockName; + this.stoneType = stoneType; + this.isSmall = small; + this.isNatural = natural; } - @Override - protected void doRegistrationStuff(Werkstoff w) {} - - public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean air, Block block, - int[] aBlockMeta) { - if (!air) { - aY = MathUtils.clamp(aY, 1, aWorld.getActualHeight()); - } + public void registerOredict() { + Werkstoff.werkstoffHashSet.forEach(this::doRegistrationStuff); + } - Block tBlock = aWorld.getBlock(aX, aY, aZ); - Block tOreBlock = WerkstoffLoader.BWOres; - if (aMetaData < 0 || tBlock == Blocks.air && !air - || Block.getIdFromBlock(tBlock) != Block.getIdFromBlock(block)) { - return false; - } - final int aaY = aY; - if (Arrays.stream(aBlockMeta) - .noneMatch(e -> e == aWorld.getBlockMetadata(aX, aaY, aZ))) { - return false; - } + protected void doRegistrationStuff(Werkstoff w) { + if (w == null) return; + if (!w.hasItemType(OrePrefixes.ore)) return; + if ((w.getGenerationFeatures().blacklist & 0b1000) != 0) return; - aWorld.setBlock(aX, aY, aZ, tOreBlock, aMetaData, 0); - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if (tTileEntity instanceof BWTileEntityMetaGeneratedOre metaTE) { - metaTE.mMetaData = (short) aMetaData; - metaTE.mNatural = true; - } + ItemStack self = new ItemStack(this, 1, w.getmID()); + OrePrefixes prefix = isSmall ? OrePrefixes.oreSmall : OrePrefixes.ore; - return true; + GTOreDictUnificator.registerOre(prefix + w.getVarName(), self); } @Override @@ -89,39 +106,66 @@ public int getHarvestLevel(int metadata) { return 3; } + @Override + public int damageDropped(int meta) { + return meta; + } + @Override public String getUnlocalizedName() { - return "bw.blockores.01"; + return blockName; } @Override public void getSubBlocks(Item aItem, CreativeTabs aTab, List aList) { - for (Werkstoff tMaterial : Werkstoff.werkstoffHashSet) { - if (tMaterial != null && tMaterial.hasItemType(OrePrefixes.ore) - && (tMaterial.getGenerationFeatures().blacklist & 0x8) == 0) { - aList.add(new ItemStack(aItem, 1, tMaterial.getmID())); + if (!isNatural) { + for (Werkstoff tMaterial : Werkstoff.werkstoffHashSet) { + if (tMaterial != null && tMaterial.hasItemType(OrePrefixes.ore) + && (tMaterial.getGenerationFeatures().blacklist & 0x8) == 0) { + aList.add(new ItemStack(aItem, 1, tMaterial.getmID())); + } } } } @Override - public void harvestBlock(World worldIn, EntityPlayer player, int x, int y, int z, int meta) { - if (EnchantmentHelper.getSilkTouchModifier(player)) { - BWTileEntityMetaGeneratedOre.shouldSilkTouch = true; - super.harvestBlock(worldIn, player, x, y, z, meta); + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + EntityPlayer harvester = this.harvesters.get(); - if (BWTileEntityMetaGeneratedOre.shouldSilkTouch) { - BWTileEntityMetaGeneratedOre.shouldSilkTouch = false; - } - return; - } + boolean doFortune = !(harvester instanceof FakePlayer); + boolean doSilktouch = harvester != null && EnchantmentHelper.getSilkTouchModifier(harvester); - if (!(player instanceof FakePlayer)) { - BWTileEntityMetaGeneratedOre.shouldFortune = true; + try (OreInfo info = BWOreAdapter.INSTANCE.getOreInfo(this, metadata)) { + return BWOreAdapter.INSTANCE + .getOreDrops(ThreadLocalRandom.current(), info, doSilktouch, doFortune ? fortune : 0); } - super.harvestBlock(worldIn, player, x, y, z, meta); - if (BWTileEntityMetaGeneratedOre.shouldFortune) { - BWTileEntityMetaGeneratedOre.shouldFortune = false; + } + + @Override + public int getRenderType() { + return GTRendererBlock.mRenderID; + } + + @Override + @Nullable + public ITexture[][] getTextures(int metadata) { + Werkstoff material = Werkstoff.werkstoffHashMap.get((short) metadata); + + ITexture[] layers; + + if (material != null) { + ITexture aIconSet = TextureFactory.of( + material.getTexSet().mTextures[isSmall ? OrePrefixes.oreSmall.mTextureIndex + : OrePrefixes.ore.mTextureIndex], + material.getRGBA()); + layers = new ITexture[] { stoneType.getTexture(0), aIconSet }; + } else { + layers = new ITexture[] { stoneType.getTexture(0), + TextureFactory.of( + gregtech.api.enums.TextureSet.SET_NONE.mTextures[isSmall ? OrePrefixes.oreSmall.mTextureIndex + : OrePrefixes.ore.mTextureIndex]) }; } + + return new ITexture[][] { layers, layers, layers, layers, layers, layers }; } } diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java deleted file mode 100644 index a472df634a4..00000000000 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.system.material; - -import java.util.Arrays; - -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 gregtech.api.enums.OrePrefixes; -import gregtech.api.util.GTLanguageManager; - -public class BWMetaGeneratedSmallOres extends BWMetaGeneratedOres { - - public BWMetaGeneratedSmallOres(Material p_i45386_1_, Class tileEntity, String blockName) { - super(p_i45386_1_, tileEntity, blockName); - this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( - "bw.blocktype." + OrePrefixes.oreSmall, - OrePrefixes.oreSmall.mLocalizedMaterialPre + "%material" + OrePrefixes.oreSmall.mLocalizedMaterialPost); - } - - @Override - protected void doRegistrationStuff(Werkstoff w) {} - - @Override - public String getUnlocalizedName() { - return "bw.blockores.02"; - } - - public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean air, Block block, - int[] aBlockMeta) { - if (!air) { - aY = Math.min(aWorld.getActualHeight(), Math.max(aY, 1)); - } - - Block tBlock = aWorld.getBlock(aX, aY, aZ); - Block tOreBlock = WerkstoffLoader.BWSmallOres; - if (aMetaData < 0 || tBlock == Blocks.air && !air - || Block.getIdFromBlock(tBlock) != Block.getIdFromBlock(block)) { - return false; - } - final int aaY = aY; - if (Arrays.stream(aBlockMeta) - .noneMatch(e -> e == aWorld.getBlockMetadata(aX, aaY, aZ))) { - return false; - } - - aWorld.setBlock(aX, aY, aZ, tOreBlock, aMetaData, 0); - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if (tTileEntity instanceof BWTileEntityMetaGeneratedOre metaTE) { - metaTE.mMetaData = (short) aMetaData; - } - - return true; - } -} diff --git a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedBlocksCasing.java b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedBlocksCasing.java index 536bdccf60e..c3b24f54604 100644 --- a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedBlocksCasing.java +++ b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedBlocksCasing.java @@ -27,7 +27,7 @@ public class BWTileEntityMetaGeneratedBlocksCasing extends TileEntityMetaGeneratedBlock { @Override - protected Block GetProperBlock() { + protected Block getProperBlock() { return WerkstoffLoader.BWBlockCasings; } diff --git a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedBlocksCasingAdvanced.java b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedBlocksCasingAdvanced.java index 57399a8f873..1ded8fc7935 100644 --- a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedBlocksCasingAdvanced.java +++ b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedBlocksCasingAdvanced.java @@ -27,7 +27,7 @@ public class BWTileEntityMetaGeneratedBlocksCasingAdvanced extends TileEntityMetaGeneratedBlock { @Override - protected Block GetProperBlock() { + protected Block getProperBlock() { return WerkstoffLoader.BWBlockCasingsAdvanced; } diff --git a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedOre.java b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedOre.java deleted file mode 100644 index 7f7d0716f55..00000000000 --- a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedOre.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.system.material; - -import java.util.ArrayList; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.GTMod; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.interfaces.ITexture; -import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTOreDictUnificator; - -public class BWTileEntityMetaGeneratedOre extends TileEntityMetaGeneratedBlock { - - protected static boolean shouldFortune = false; - protected static boolean shouldSilkTouch = false; - public boolean mNatural = false; - - @Override - public void readFromNBT(NBTTagCompound aNBT) { - super.readFromNBT(aNBT); - this.mNatural = aNBT.getBoolean("n"); - } - - @Override - public void writeToNBT(NBTTagCompound aNBT) { - super.writeToNBT(aNBT); - aNBT.setBoolean("n", this.mNatural); - } - - @Override - public ITexture[] getTexture(Block aBlock, ForgeDirection side) { - Werkstoff aMaterial = Werkstoff.werkstoffHashMap.get(this.mMetaData); - if (aMaterial != null) { - ITexture aIconSet = TextureFactory - .of(aMaterial.getTexSet().mTextures[OrePrefixes.ore.mTextureIndex], aMaterial.getRGBA()); - return new ITexture[] { TextureFactory.of(Blocks.stone), aIconSet }; - } - return new ITexture[] { TextureFactory.of(Blocks.stone), - TextureFactory.of(gregtech.api.enums.TextureSet.SET_NONE.mTextures[OrePrefixes.ore.mTextureIndex]) }; - } - - @Override - protected Block GetProperBlock() { - return WerkstoffLoader.BWOres; - } - - @Override - public ArrayList getDrops(int aFortune) { - ArrayList rList = new ArrayList<>(); - if (this.mMetaData <= 0) { - rList.add(new ItemStack(Blocks.cobblestone, 1, 0)); - return rList; - } - Materials aOreMaterial = Werkstoff.werkstoffHashMap.get(this.mMetaData) - .getBridgeMaterial(); - if (shouldSilkTouch) { - rList.add(new ItemStack(this.GetProperBlock(), 1, this.mMetaData)); - } else { - switch (GTMod.gregtechproxy.oreDropSystem) { - case Item -> { - rList.add(GTOreDictUnificator.get(OrePrefixes.rawOre, aOreMaterial, 1)); - } - case FortuneItem -> { - // if shouldFortune and isNatural then get fortune drops - // if not shouldFortune or not isNatural then get normal drops - // if not shouldFortune and isNatural then get normal drops - // if shouldFortune and not isNatural then get normal drops - if (shouldFortune && this.mNatural && aFortune > 0) { - int aMinAmount = 1; - // Max applicable fortune - if (aFortune > 3) aFortune = 3; - long amount = (long) new Random().nextInt(aFortune) + aMinAmount; - for (int i = 0; i < amount; i++) { - rList.add(GTOreDictUnificator.get(OrePrefixes.rawOre, aOreMaterial, 1)); - } - } else { - rList.add(GTOreDictUnificator.get(OrePrefixes.rawOre, aOreMaterial, 1)); - } - } - case UnifiedBlock -> { - // Unified ore - rList.add(new ItemStack(this.GetProperBlock(), 1, this.mMetaData)); - } - case PerDimBlock -> { - // Per Dimension ore - rList.add(new ItemStack(this.GetProperBlock(), 1, this.mMetaData)); - } - case Block -> { - // Regular ore - rList.add(new ItemStack(this.GetProperBlock(), 1, this.mMetaData)); - } - } - } - return rList; - } -} diff --git a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedSmallOre.java b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedSmallOre.java deleted file mode 100644 index 737b486cf99..00000000000 --- a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedSmallOre.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.system.material; - -import java.util.ArrayList; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.interfaces.ITexture; -import gregtech.api.objects.XSTR; -import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTOreDictUnificator; -import gregtech.api.util.GTUtility; - -public class BWTileEntityMetaGeneratedSmallOre extends BWTileEntityMetaGeneratedOre { - - @Override - public ArrayList getDrops(int aFortune) { - ArrayList rList = new ArrayList<>(); - Materials aMaterial = Werkstoff.werkstoffHashMap.get(this.mMetaData) - .getBridgeMaterial(); - - if (aMaterial != null) { - Random tRandom = new XSTR(this.xCoord ^ this.yCoord ^ this.zCoord); - ArrayList tSelector = new ArrayList<>(); - - ItemStack tStack = GTOreDictUnificator - .get(OrePrefixes.gemExquisite, aMaterial, GTOreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L), 1L); - if (tStack != null) { - for (int i = 0; i < 1; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator - .get(OrePrefixes.gemFlawless, aMaterial, GTOreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L), 1L); - if (tStack != null) { - for (int i = 0; i < 2; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L); - if (tStack != null) { - for (int i = 0; i < 12; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator - .get(OrePrefixes.gemFlawed, aMaterial, GTOreDictUnificator.get(OrePrefixes.crushed, aMaterial, 1L), 1L); - if (tStack != null) { - for (int i = 0; i < 5; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator.get(OrePrefixes.crushed, aMaterial, 1L); - if (tStack != null) { - for (int i = 0; i < 10; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator.get( - OrePrefixes.gemChipped, - aMaterial, - GTOreDictUnificator.get(OrePrefixes.dustImpure, aMaterial, 1L), - 1L); - if (tStack != null) { - for (int i = 0; i < 5; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator.get(OrePrefixes.dustImpure, aMaterial, 1L); - if (tStack != null) { - for (int i = 0; i < 10; i++) { - tSelector.add(tStack); - } - } - if (!tSelector.isEmpty()) { - int i = 0; - - for (int j = Math.max(1, aFortune > 0 ? tRandom.nextInt(1 + aFortune) : 0); i < j; ++i) { - rList.add(GTUtility.copyAmount(1L, tSelector.get(tRandom.nextInt(tSelector.size())))); - } - } - if (tRandom.nextInt(3 + aFortune) > 1) { - rList.add( - GTOreDictUnificator - .get(tRandom.nextInt(3) > 0 ? OrePrefixes.dustImpure : OrePrefixes.dust, Materials.Stone, 1L)); - } - } - return rList; - } - - @Override - public ITexture[] getTexture(Block aBlock, ForgeDirection side) { - Werkstoff aMaterial = Werkstoff.werkstoffHashMap.get(this.mMetaData); - if (aMaterial != null) { - ITexture aIconSet = TextureFactory - .of(aMaterial.getTexSet().mTextures[OrePrefixes.oreSmall.mTextureIndex], aMaterial.getRGBA()); - return new ITexture[] { TextureFactory.of(Blocks.stone), aIconSet }; - } - return new ITexture[] { TextureFactory.of(Blocks.stone), - TextureFactory.of(gregtech.api.enums.TextureSet.SET_NONE.mTextures[OrePrefixes.oreSmall.mTextureIndex]) }; - } - - @Override - protected Block GetProperBlock() { - return WerkstoffLoader.BWSmallOres; - } -} diff --git a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedWerkstoffBlock.java b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedWerkstoffBlock.java index f1fd9789091..002a57a3bf5 100644 --- a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedWerkstoffBlock.java +++ b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedWerkstoffBlock.java @@ -43,7 +43,7 @@ public ITexture[] getTexture(Block aBlock, ForgeDirection side) { } @Override - protected Block GetProperBlock() { + protected Block getProperBlock() { return WerkstoffLoader.BWBlocks; } } diff --git a/src/main/java/bartworks/system/material/TileEntityMetaGeneratedBlock.java b/src/main/java/bartworks/system/material/TileEntityMetaGeneratedBlock.java index 5fe9a705995..7b70927234f 100644 --- a/src/main/java/bartworks/system/material/TileEntityMetaGeneratedBlock.java +++ b/src/main/java/bartworks/system/material/TileEntityMetaGeneratedBlock.java @@ -57,7 +57,7 @@ public Packet getDescriptionPacket() { return null; } - protected abstract Block GetProperBlock(); + protected abstract Block getProperBlock(); public ArrayList getDrops(int aFortune) { ArrayList rList = new ArrayList<>(); @@ -65,7 +65,7 @@ public ArrayList getDrops(int aFortune) { rList.add(new ItemStack(Blocks.cobblestone, 1, 0)); return rList; } - rList.add(new ItemStack(this.GetProperBlock(), 1, this.mMetaData)); + rList.add(new ItemStack(this.getProperBlock(), 1, this.mMetaData)); return rList; } } diff --git a/src/main/java/bartworks/system/material/Werkstoff.java b/src/main/java/bartworks/system/material/Werkstoff.java index 5ae7136934e..2db51bb07c4 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -49,20 +50,26 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.Mods; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; import gregtech.api.enums.SubTag; import gregtech.api.enums.TCAspects; import gregtech.api.enums.TextureSet; import gregtech.api.interfaces.IColorModulationContainer; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneType; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.util.GTLanguageManager; import gregtech.api.util.GTOreDictUnificator; +import it.unimi.dsi.fastutil.shorts.Short2ObjectLinkedOpenHashMap; +import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; import thaumcraft.api.aspects.Aspect; -public class Werkstoff implements IColorModulationContainer, ISubTagContainer { +public class Werkstoff implements IColorModulationContainer, ISubTagContainer, IOreMaterial { public static final LinkedHashSet werkstoffHashSet = new LinkedHashSet<>(); - public static final LinkedHashMap werkstoffHashMap = new LinkedHashMap<>(); + public static final Short2ObjectMap werkstoffHashMap = new Short2ObjectLinkedOpenHashMap<>(); public static final LinkedHashMap werkstoffNameHashMap = new LinkedHashMap<>(); + public static final LinkedHashMap werkstoffVarNameHashMap = new LinkedHashMap<>(); public static final Map modNameOverrides = new HashMap<>() { @@ -83,7 +90,7 @@ public class Werkstoff implements IColorModulationContainer, ISubTagContainer { .disable(); public static Werkstoff default_null_Werkstoff; - private final HashSet ADDITIONAL_OREDICT = new HashSet<>(); + private final HashSet additionalOredict = new HashSet<>(); private final List mOreByProducts = new ArrayList<>(); private final LinkedHashSet> CONTENTS = new LinkedHashSet<>(); private final HashSet SUBTAGS = new HashSet<>(); @@ -378,6 +385,7 @@ public Werkstoff(short[] rgba, String defaultName, String toolTip, Werkstoff.Sta Werkstoff.werkstoffHashSet.add(this); Werkstoff.werkstoffHashMap.put(this.mID, this); Werkstoff.werkstoffNameHashMap.put(this.defaultName, this); + Werkstoff.werkstoffVarNameHashMap.put(this.getVarName(), this); this.owner = this.getMaterialOwner(); } @@ -391,12 +399,12 @@ private static String getFormula(Werkstoff material) { } public Werkstoff addAdditionalOreDict(String s) { - this.ADDITIONAL_OREDICT.add(s); + this.additionalOredict.add(s); return this; } - public HashSet getADDITIONAL_OREDICT() { - return this.ADDITIONAL_OREDICT; + public Set getAdditionalOredict() { + return this.additionalOredict; } public void setTCAspects(Pair... pAspectsArr) { @@ -499,6 +507,7 @@ public String getDefaultName() { return this.defaultName; } + @Override public String getLocalizedName() { return GTLanguageManager.addStringLocalization( String.format("bw.werkstoff.%05d.name", this.mID), @@ -529,6 +538,21 @@ public short getmID() { return this.mID; } + @Override + public int getId() { + return mID; + } + + @Override + public List getValidStones() { + return StoneType.STONE_ONLY; + } + + @Override + public String getInternalName() { + return getVarName(); + } + public short getMixCircuit() { return this.getGenerationFeatures().mixCircuit; } @@ -550,6 +574,11 @@ public short[] getRGBA() { return new short[] { (short) (this.rgb[0] + 128), (short) (this.rgb[1] + 128), (short) (this.rgb[2] + 128), 0 }; } + @Override + public TextureSet getTextureSet() { + return texSet; + } + @Override public boolean contains(SubTag subTag) { if (!subTag.equals(WerkstoffLoader.NOBLE_GAS) && !subTag.equals(WerkstoffLoader.ANAEROBE_GAS) diff --git a/src/main/java/bartworks/system/material/WerkstoffLoader.java b/src/main/java/bartworks/system/material/WerkstoffLoader.java index cc3fdd749e5..40dfe433c3d 100644 --- a/src/main/java/bartworks/system/material/WerkstoffLoader.java +++ b/src/main/java/bartworks/system/material/WerkstoffLoader.java @@ -91,10 +91,8 @@ import com.google.common.collect.HashBiMap; -import bartworks.API.SideReference; import bartworks.API.WerkstoffAdderRegistry; import bartworks.MainMod; -import bartworks.client.renderer.BWBlockOreRenderer; import bartworks.system.material.CircuitGeneration.BWCircuitsLoader; import bartworks.system.material.gtenhancement.GTMetaItemEnhancer; import bartworks.system.material.processingLoaders.AdditionalRecipes; @@ -134,6 +132,8 @@ import gregtech.api.fluid.GTFluidFactory; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.util.GTOreDictUnificator; +import gregtech.common.ores.BWOreAdapter; +import gregtech.common.ores.OreInfo; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputOreDict; import ic2.api.recipe.RecipeOutput; @@ -1635,8 +1635,6 @@ public static void setUp() { public static HashMap items = new HashMap<>(); public static HashBiMap fluids = HashBiMap.create(); public static HashBiMap molten = HashBiMap.create(); - public static Block BWOres; - public static Block BWSmallOres; public static Block BWBlocks; public static Block BWBlockCasings; public static Block BWBlockCasingsAdvanced; @@ -1664,14 +1662,30 @@ public static ItemStack getCorrespondingItemStackUnsafe(OrePrefixes orePrefixes, ret = OreDictHandler.getItemStack(werkstoff.getVarName(), orePrefixes, amount); if (ret != null) return ret; } - if (orePrefixes == ore) return new ItemStack(WerkstoffLoader.BWOres, amount, werkstoff.getmID()); - if (orePrefixes == oreSmall) return new ItemStack(WerkstoffLoader.BWSmallOres, amount, werkstoff.getmID()); - else if (orePrefixes == block) return new ItemStack(WerkstoffLoader.BWBlocks, amount, werkstoff.getmID()); - else if (orePrefixes == OrePrefixes.blockCasing) + + if (orePrefixes == ore || orePrefixes == oreSmall) { + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = werkstoff; + info.isSmall = orePrefixes == oreSmall; + + return BWOreAdapter.INSTANCE.getStack(info, amount); + } + } + + if (orePrefixes == block) { + return new ItemStack(WerkstoffLoader.BWBlocks, amount, werkstoff.getmID()); + } + if (orePrefixes == OrePrefixes.blockCasing) { return new ItemStack(WerkstoffLoader.BWBlockCasings, amount, werkstoff.getmID()); - else if (orePrefixes == OrePrefixes.blockCasingAdvanced) + } + if (orePrefixes == OrePrefixes.blockCasingAdvanced) { return new ItemStack(WerkstoffLoader.BWBlockCasingsAdvanced, amount, werkstoff.getmID()); - else if (WerkstoffLoader.items.get(orePrefixes) == null) return null; + } + + if (WerkstoffLoader.items.get(orePrefixes) == null) { + return null; + } + return new ItemStack(WerkstoffLoader.items.get(orePrefixes), amount, werkstoff.getmID()).copy(); } @@ -1989,24 +2003,14 @@ private static void addItemsForGeneration() { } static void gameRegistryHandler() { - if (SideReference.Side.Client) BWBlockOreRenderer.register(); - - GameRegistry.registerTileEntity(BWTileEntityMetaGeneratedOre.class, "bw.blockoresTE"); - GameRegistry.registerTileEntity(BWTileEntityMetaGeneratedSmallOre.class, "bw.blockoresSmallTE"); GameRegistry.registerTileEntity(BWTileEntityMetaGeneratedWerkstoffBlock.class, "bw.werkstoffblockTE"); GameRegistry.registerTileEntity(BWTileEntityMetaGeneratedBlocksCasing.class, "bw.werkstoffblockcasingTE"); GameRegistry.registerTileEntity( BWTileEntityMetaGeneratedBlocksCasingAdvanced.class, "bw.werkstoffblockscasingadvancedTE"); - WerkstoffLoader.BWOres = new BWMetaGeneratedOres( - Material.rock, - BWTileEntityMetaGeneratedOre.class, - "bw.blockores"); - WerkstoffLoader.BWSmallOres = new BWMetaGeneratedSmallOres( - Material.rock, - BWTileEntityMetaGeneratedSmallOre.class, - "bw.blockoresSmall"); + BWOreAdapter.INSTANCE.init(); + WerkstoffLoader.BWBlocks = new BWMetaGeneratedWerkstoffBlocks( Material.iron, BWTileEntityMetaGeneratedWerkstoffBlock.class, @@ -2022,8 +2026,6 @@ static void gameRegistryHandler() { "bw.werkstoffblockscasingadvanced", OrePrefixes.blockCasingAdvanced); - GameRegistry.registerBlock(WerkstoffLoader.BWOres, BWItemMetaGeneratedBlock.class, "bw.blockores.01"); - GameRegistry.registerBlock(WerkstoffLoader.BWSmallOres, BWItemMetaGeneratedBlock.class, "bw.blockores.02"); GameRegistry.registerBlock(WerkstoffLoader.BWBlocks, BWItemMetaGeneratedBlock.class, "bw.werkstoffblocks.01"); GameRegistry.registerBlock( WerkstoffLoader.BWBlockCasings, @@ -2046,29 +2048,6 @@ private static void runGTItemDataRegistrator() { registration.run(werkstoff); } } - addFakeItemDataToInWorldBlocksAndCleanUpFakeData(); - } - - /** - * very hacky way to make my ores/blocks/small ores detectable by gt association in world, well at least the prefix. - * used for the miners mostly removing this hacky material from the materials map instantly. we only need the item - * data. - */ - private static void addFakeItemDataToInWorldBlocksAndCleanUpFakeData() { - Materials oreMat = new Materials(-1, null, 0, 0, 0, false, "bwores", "bwores", null, true, null); - Materials smallOreMat = new Materials(-1, null, 0, 0, 0, false, "bwsmallores", "bwsmallores", null, true, null); - Materials blockMat = new Materials(-1, null, 0, 0, 0, false, "bwblocks", "bwblocks", null, true, null); - for (int i = 0; i < 16; i++) { - GTOreDictUnificator.addAssociation(ore, oreMat, new ItemStack(BWOres, 1, i), true); - GTOreDictUnificator.addAssociation(oreSmall, smallOreMat, new ItemStack(BWSmallOres, 1, i), true); - GTOreDictUnificator.addAssociation(block, blockMat, new ItemStack(BWBlocks, 1, i), true); - } - Materials.getMaterialsMap() - .remove("bwores"); - Materials.getMaterialsMap() - .remove("bwsmallores"); - Materials.getMaterialsMap() - .remove("bwblocks"); } public static void removeIC2Recipes() { @@ -2096,11 +2075,9 @@ public static void removeIC2Recipes() { private static void runAdditionalOreDict() { for (Werkstoff werkstoff : Werkstoff.werkstoffHashSet) { if (werkstoff.hasItemType(ore)) { - GTOreDictUnificator.registerOre(ore + werkstoff.getVarName(), werkstoff.get(ore)); - GTOreDictUnificator.registerOre(oreSmall + werkstoff.getVarName(), werkstoff.get(oreSmall)); - werkstoff.getADDITIONAL_OREDICT() + werkstoff.getAdditionalOredict() .forEach(e -> OreDictionary.registerOre(ore + e, werkstoff.get(ore))); - werkstoff.getADDITIONAL_OREDICT() + werkstoff.getAdditionalOredict() .forEach(e -> OreDictionary.registerOre(oreSmall + e, werkstoff.get(oreSmall))); } @@ -2110,11 +2087,11 @@ private static void runAdditionalOreDict() { if (werkstoff.hasItemType(gem) || werkstoff.hasItemType(ingot)) { GTOreDictUnificator.registerOre(block + werkstoff.getVarName(), werkstoff.get(block)); - werkstoff.getADDITIONAL_OREDICT() + werkstoff.getAdditionalOredict() .forEach(e -> OreDictionary.registerOre(block + e, werkstoff.get(block))); } - werkstoff.getADDITIONAL_OREDICT() + werkstoff.getAdditionalOredict() .forEach( s -> ENABLED_ORE_PREFIXES.stream() .filter(o -> Objects.nonNull(werkstoff.get(o))) @@ -2122,5 +2099,6 @@ private static void runAdditionalOreDict() { } GTOreDictUnificator.registerOre("craftingIndustrialDiamond", WerkstoffLoader.CubicZirconia.get(gemExquisite)); + BWOreAdapter.INSTANCE.registerOredict(); } } diff --git a/src/main/java/bartworks/system/material/gtenhancement/PlatinumSludgeOverHaul.java b/src/main/java/bartworks/system/material/gtenhancement/PlatinumSludgeOverHaul.java index df806929112..62c769b3dc6 100644 --- a/src/main/java/bartworks/system/material/gtenhancement/PlatinumSludgeOverHaul.java +++ b/src/main/java/bartworks/system/material/gtenhancement/PlatinumSludgeOverHaul.java @@ -121,7 +121,7 @@ import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; -import gregtech.common.blocks.BlockOresAbstract; +import gregtech.common.blocks.GTBlockOre; import gregtech.mixin.interfaces.accessors.IRecipeMutableAccess; import gtPlusPlus.core.block.base.BlockBaseModular; import gtPlusPlus.core.item.base.BaseItemComponent; @@ -1121,7 +1121,7 @@ private static boolean isInBlackList(ItemStack stack, List ITEMLIST_V return true; if (Block.getBlockFromItem(stack.getItem()) instanceof GTGenericBlock - && !(Block.getBlockFromItem(stack.getItem()) instanceof BlockOresAbstract)) return true; + && !(Block.getBlockFromItem(stack.getItem()) instanceof GTBlockOre)) return true; for (ItemStack itemStack : ITEMLIST_VALUES) { if (!BWUtil.checkStackAndPrefix(stack) && GTUtility.areStacksEqual(itemStack, stack, true)) { diff --git a/src/main/java/bartworks/system/oregen/BWOreLayer.java b/src/main/java/bartworks/system/oregen/BWOreLayer.java deleted file mode 100644 index 80cca68d3a0..00000000000 --- a/src/main/java/bartworks/system/oregen/BWOreLayer.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.system.oregen; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; - -import com.google.common.collect.ArrayListMultimap; - -import bartworks.MainMod; -import bartworks.system.material.BWMetaGeneratedOres; -import bartworks.system.material.BWMetaGeneratedSmallOres; -import bartworks.system.material.BWTileEntityMetaGeneratedOre; -import bartworks.system.material.Werkstoff; -import bartworks.system.material.WerkstoffLoader; -import bartworks.util.MurmurHash3; -import bartworks.util.Pair; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.interfaces.ISubTagContainer; -import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.TileEntityOres; - -/** - * Original GT File Stripped and adjusted to work with this mod - */ -public abstract class BWOreLayer extends GTWorldgen { - - public static final List sList = new ArrayList<>(); - public static final ArrayListMultimap NEIMAP = ArrayListMultimap.create(); - private static final boolean logOregenRoss128 = false; - public static int sWeight; - public byte bwOres; - public int mMinY, mWeight, mDensity, mSize, mMaxY, mPrimaryMeta, mSecondaryMeta, mBetweenMeta, mSporadicMeta; - - public abstract Block getDefaultBlockToReplace(); - - public abstract int[] getDefaultDamageToReplace(); - - public abstract String getDimName(); - - public BWOreLayer(String aName, boolean aDefault, int aMinY, int aMaxY, int aWeight, int aDensity, int aSize, - ISubTagContainer top, ISubTagContainer bottom, ISubTagContainer between, ISubTagContainer sprinkled) { - super(aName, BWOreLayer.sList, aDefault); - this.mMinY = (short) aMinY; - this.mMaxY = (short) aMaxY; - this.mWeight = (short) aWeight; - this.mDensity = (short) aDensity; - this.mSize = (short) Math.max(1, aSize); - - if (this.mEnabled) BWOreLayer.sWeight += this.mWeight; - - if (top instanceof Werkstoff) this.bwOres = (byte) (this.bwOres | 0b1000); - if (bottom instanceof Werkstoff) this.bwOres = (byte) (this.bwOres | 0b0100); - if (between instanceof Werkstoff) this.bwOres = (byte) (this.bwOres | 0b0010); - if (sprinkled instanceof Werkstoff) this.bwOres = (byte) (this.bwOres | 0b0001); - - short aPrimary = top instanceof Materials ? (short) ((Materials) top).mMetaItemSubID - : top instanceof Werkstoff ? ((Werkstoff) top).getmID() : 0; - short aSecondary = bottom instanceof Materials ? (short) ((Materials) bottom).mMetaItemSubID - : bottom instanceof Werkstoff ? ((Werkstoff) bottom).getmID() : 0; - short aBetween = between instanceof Materials ? (short) ((Materials) between).mMetaItemSubID - : between instanceof Werkstoff ? ((Werkstoff) between).getmID() : 0; - short aSporadic = sprinkled instanceof Materials ? (short) ((Materials) sprinkled).mMetaItemSubID - : sprinkled instanceof Werkstoff ? ((Werkstoff) sprinkled).getmID() : 0; - this.mPrimaryMeta = aPrimary; - this.mSecondaryMeta = aSecondary; - this.mBetweenMeta = aBetween; - this.mSporadicMeta = aSporadic; - NEIMAP.put((short) this.mPrimaryMeta, this); - NEIMAP.put((short) this.mSecondaryMeta, this); - NEIMAP.put((short) this.mBetweenMeta, this); - NEIMAP.put((short) this.mSporadicMeta, this); - } - - public List getStacks() { - ArrayList ret = new ArrayList<>(); - ret.add( - (this.bwOres & 0b1000) != 0 ? new ItemStack(WerkstoffLoader.BWOres, 1, this.mPrimaryMeta) - : new ItemStack(GregTechAPI.sBlockOres1, 1, this.mPrimaryMeta)); - ret.add( - (this.bwOres & 0b0100) != 0 ? new ItemStack(WerkstoffLoader.BWOres, 1, this.mSecondaryMeta) - : new ItemStack(GregTechAPI.sBlockOres1, 1, this.mSecondaryMeta)); - ret.add( - (this.bwOres & 0b0010) != 0 ? new ItemStack(WerkstoffLoader.BWOres, 1, this.mBetweenMeta) - : new ItemStack(GregTechAPI.sBlockOres1, 1, this.mBetweenMeta)); - ret.add( - (this.bwOres & 0b0001) != 0 ? new ItemStack(WerkstoffLoader.BWOres, 1, this.mSporadicMeta) - : new ItemStack(GregTechAPI.sBlockOres1, 1, this.mSporadicMeta)); - return ret; - } - - public List> getStacksRawData() { - ArrayList> ret = new ArrayList<>(); - ret.add(new Pair<>(this.mPrimaryMeta, (this.bwOres & 0b1000) != 0)); - ret.add(new Pair<>(this.mSecondaryMeta, (this.bwOres & 0b0100) != 0)); - ret.add(new Pair<>(this.mBetweenMeta, (this.bwOres & 0b0010) != 0)); - ret.add(new Pair<>(this.mSporadicMeta, (this.bwOres & 0b0001) != 0)); - return ret; - } - - @Override - public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - { - int tMinY = this.mMinY + aRandom.nextInt(this.mMaxY - this.mMinY - 5); - int cX = aChunkX - aRandom.nextInt(this.mSize); - int eX = aChunkX + 16 + aRandom.nextInt(this.mSize); - - boolean wasPlaced = false; - - for (int tX = cX; tX <= eX; ++tX) { - int cZ = aChunkZ - aRandom.nextInt(this.mSize); - int eZ = aChunkZ + 16 + aRandom.nextInt(this.mSize); - - for (int tZ = cZ; tZ <= eZ; ++tZ) { - int i; - if (this.mSecondaryMeta > 0) { - for (i = tMinY - 1; i < tMinY + 2; ++i) { - if (this.shouldPlace(aRandom, cX, eX, tX, cZ, eZ, tZ)) { - wasPlaced = this.setOreBlock(aWorld, tX, i, tZ, this.mSecondaryMeta, false); - } - } - } - - if (this.mBetweenMeta > 0 && this.shouldPlace(aRandom, cX, eX, tX, cZ, eZ, tZ)) { - wasPlaced = this - .setOreBlock(aWorld, tX, tMinY + 2 + aRandom.nextInt(2), tZ, this.mBetweenMeta, false); - } - - if (this.mPrimaryMeta > 0) { - for (i = tMinY + 3; i < tMinY + 6; ++i) { - if (this.shouldPlace(aRandom, cX, eX, tX, cZ, eZ, tZ)) { - wasPlaced = this.setOreBlock(aWorld, tX, i, tZ, this.mPrimaryMeta, false); - } - } - } - - if (this.mSporadicMeta > 0 && this.shouldPlace(aRandom, cX, eX, tX, cZ, eZ, tZ)) { - wasPlaced = this - .setOreBlock(aWorld, tX, tMinY - 1 + aRandom.nextInt(7), tZ, this.mSporadicMeta, false); - } - } - } - - if (BWOreLayer.logOregenRoss128) { - MainMod.LOGGER.info("Generated Orevein: " + this.mWorldGenName + " " + aChunkX + " " + aChunkZ); - } - - return wasPlaced; - } - } - - private boolean shouldPlace(Random aRandom, int cX, int eX, int tX, int cZ, int eZ, int tZ) { - return aRandom.nextInt( - Math.max(1, Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) / this.mDensity)) == 0 - || aRandom.nextInt( - Math.max(1, Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) / this.mDensity)) == 0; - } - - public boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre) { - // security stuff to prevent crashes with 2 TileEntites on the same Spot - TileEntity te = aWorld.getTileEntity(aX, aY, aZ); - if (te instanceof BWTileEntityMetaGeneratedOre || te instanceof TileEntityOres) return true; - - if (aMetaData == this.mSporadicMeta && (this.bwOres & 0b0001) != 0 - || aMetaData == this.mBetweenMeta && (this.bwOres & 0b0010) != 0 - || aMetaData == this.mPrimaryMeta && (this.bwOres & 0b1000) != 0 - || aMetaData == this.mSecondaryMeta && (this.bwOres & 0b0100) != 0) { - return isSmallOre - ? BWMetaGeneratedSmallOres.setOreBlock( - aWorld, - aX, - aY, - aZ, - aMetaData, - false, - this.getDefaultBlockToReplace(), - this.getDefaultDamageToReplace()) - : BWMetaGeneratedOres.setOreBlock( - aWorld, - aX, - aY, - aZ, - aMetaData, - false, - this.getDefaultBlockToReplace(), - this.getDefaultDamageToReplace()); - } - - return this.setGTOreBlockSpace(aWorld, aX, aY, aZ, aMetaData, this.getDefaultBlockToReplace()); - } - - public boolean setGTOreBlockSpace(World aWorld, int aX, int aY, int aZ, int aMetaData, Block block) { - if (TileEntityOres.setOreBlock(aWorld, aX, aY, aZ, aMetaData, false, false)) return true; - aY = Math.min(aWorld.getActualHeight(), Math.max(aY, 1)); - Block tBlock = aWorld.getBlock(aX, aY, aZ); - Block tOreBlock = GregTechAPI.sBlockOres1; - if (aMetaData < 0 || tBlock == Blocks.air) { - return false; - } else { - if (!tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, block)) { - return false; - } - aMetaData += 5000; - aWorld.setBlock(aX, aY, aZ, tOreBlock, aMetaData, 0); - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if (tTileEntity instanceof TileEntityOres ore) { - ore.mMetaData = (short) aMetaData; - } - return true; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BWOreLayer that)) return false; - - if (this.bwOres != that.bwOres || this.mMinY != that.mMinY - || this.mWeight != that.mWeight - || this.mDensity != that.mDensity) return false; - if (this.mSize != that.mSize) return false; - if (this.mMaxY != that.mMaxY) return false; - if (this.mPrimaryMeta != that.mPrimaryMeta) return false; - if (this.mSecondaryMeta != that.mSecondaryMeta) return false; - if (this.mBetweenMeta != that.mBetweenMeta) return false; - return this.mSporadicMeta == that.mSporadicMeta; - } - - @Override - public int hashCode() { - return MurmurHash3.murmurhash3_x86_32( - ByteBuffer.allocate(37) - .put(this.bwOres) - .putInt(this.mMinY) - .putInt(this.mWeight) - .putInt(this.mDensity) - .putInt(this.mSize) - .putInt(this.mMaxY) - .putInt(this.mPrimaryMeta) - .putInt(this.mSecondaryMeta) - .putInt(this.mBetweenMeta) - .putInt(this.mSporadicMeta) - .array(), - 0, - 37, - 31); - } -} diff --git a/src/main/java/bartworks/system/oregen/BWWordGenerator.java b/src/main/java/bartworks/system/oregen/BWWordGenerator.java deleted file mode 100644 index 909bb0cd942..00000000000 --- a/src/main/java/bartworks/system/oregen/BWWordGenerator.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.system.oregen; - -import java.util.HashSet; -import java.util.Random; - -import net.minecraft.world.ChunkCoordIntPair; -import net.minecraft.world.World; -import net.minecraft.world.WorldProvider; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.IChunkProvider; - -import cpw.mods.fml.common.IWorldGenerator; -import gregtech.api.objects.XSTR; -import gregtech.api.util.GTLog; - -/** - * Original GT File Stripped and adjusted to work with this mod - */ -public class BWWordGenerator implements IWorldGenerator { - - public BWWordGenerator() { - // GT_NH Override... wont be actually registered to force its generation directly in the ChunkProvider - // GameRegistry.registerWorldGenerator(this, 1073741823); - } - - public synchronized void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, - IChunkProvider aChunkProvider) { - new BWWordGenerator.WorldGenContainer( - aX * 16, - aZ * 16, - aWorld.provider, - aWorld, - aChunkGenerator, - aChunkProvider).run(); - } - - public static class WorldGenContainer implements Runnable { - - public static HashSet mGenerated = new HashSet<>(2000); - public final WorldProvider mWorldProvider; - public final World mWorld; - public final IChunkProvider mChunkGenerator; - public final IChunkProvider mChunkProvider; - public int mX; - public int mZ; - - public WorldGenContainer(int aX, int aZ, WorldProvider aWorldProvider, World aWorld, - IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - this.mX = aX; - this.mZ = aZ; - this.mWorldProvider = aWorldProvider; - this.mWorld = aWorld; - this.mChunkGenerator = aChunkGenerator; - this.mChunkProvider = aChunkProvider; - } - - // returns a coordinate of a center chunk of 3x3 square; the argument belongs to this square - public int getVeinCenterCoordinate(int c) { - c += c < 0 ? 1 : 3; - return c - c % 3 - 2; - } - - public boolean surroundingChunksLoaded(int xCenter, int zCenter) { - return this.mWorld.checkChunksExist(xCenter - 16, 0, zCenter - 16, xCenter + 16, 0, zCenter + 16); - } - - public XSTR getRandom(int xChunk, int zChunk) { - long worldSeed = this.mWorld.getSeed(); - XSTR fmlRandom = new XSTR(worldSeed); - long xSeed = fmlRandom.nextLong() >> 2 + 1L; - long zSeed = fmlRandom.nextLong() >> 2 + 1L; - long chunkSeed = xSeed * xChunk + zSeed * zChunk ^ worldSeed; - fmlRandom.setSeed(chunkSeed); - return new XSTR(fmlRandom.nextInt()); - } - - public void run() { - int xCenter = this.getVeinCenterCoordinate(this.mX >> 4); - int zCenter = this.getVeinCenterCoordinate(this.mZ >> 4); - Random random = this.getRandom(xCenter, zCenter); - xCenter <<= 4; - zCenter <<= 4; - ChunkCoordIntPair centerChunk = new ChunkCoordIntPair(xCenter, zCenter); - if (!BWWordGenerator.WorldGenContainer.mGenerated.contains(centerChunk) - && this.surroundingChunksLoaded(xCenter, zCenter)) { - BWWordGenerator.WorldGenContainer.mGenerated.add(centerChunk); - if (BWOreLayer.sWeight > 0 && !BWOreLayer.sList.isEmpty()) { - boolean temp = true; - int tRandomWeight; - for (int i = 0; i < 256 && temp; i++) { - tRandomWeight = random.nextInt(BWOreLayer.sWeight); - for (BWOreLayer tWorldGen : BWOreLayer.sList) { - if (!tWorldGen.isGenerationAllowed(this.mWorld, mWorldProvider.getClass())) continue; - tRandomWeight -= tWorldGen.mWeight; - if (tRandomWeight <= 0) { - try { - boolean placed; - int attempts = 0; - do { - placed = tWorldGen.executeWorldgen( - this.mWorld, - random, - "", - this.mWorldProvider.dimensionId, - xCenter, - zCenter, - this.mChunkGenerator, - this.mChunkProvider); - ++attempts; - } while (!placed && attempts < 25); - temp = false; - break; - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - } - } - } - } - } - Chunk tChunk = this.mWorld.getChunkFromBlockCoords(this.mX, this.mZ); - if (tChunk != null) { - tChunk.isModified = true; - } - } - } -} diff --git a/src/main/java/bartworks/system/oregen/BWWorldGenRoss128b.java b/src/main/java/bartworks/system/oregen/BWWorldGenRoss128b.java deleted file mode 100644 index 8c50a2803e5..00000000000 --- a/src/main/java/bartworks/system/oregen/BWWorldGenRoss128b.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.system.oregen; - -import static gregtech.api.enums.Materials.Bismuth; -import static gregtech.api.enums.Materials.Coal; -import static gregtech.api.enums.Materials.Diamond; -import static gregtech.api.enums.Materials.Graphite; -import static gregtech.api.enums.Materials.Lepidolite; -import static gregtech.api.enums.Materials.Scheelite; -import static gregtech.api.enums.Materials.Spodumene; -import static gregtech.api.enums.Materials.Stibnite; -import static gregtech.api.enums.Materials.Tetrahedrite; -import static gregtech.api.enums.Materials.Uraninite; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.util.StatCollector; -import net.minecraft.world.World; - -import bartworks.common.configs.Configuration; -import bartworks.system.material.WerkstoffLoader; -import bwcrossmod.galacticraft.planets.ross128b.WorldProviderRoss128b; -import gregtech.api.interfaces.ISubTagContainer; - -public class BWWorldGenRoss128b extends BWOreLayer { - - @Override - public Block getDefaultBlockToReplace() { - return Blocks.stone; - } - - @Override - public int[] getDefaultDamageToReplace() { - return new int[] { 0 }; - } - - @Override - public String getDimName() { - return StatCollector.translateToLocal("planet.Ross128b"); - } - - @SuppressWarnings("rawtypes") - @Override - public boolean isGenerationAllowed(World aWorld, Class... aAllowedDimensionTypes) { - for (Class clazz : aAllowedDimensionTypes) { - if (clazz == WorldProviderRoss128b.class) { - return true; - } - } - - return false; - } - - public BWWorldGenRoss128b(String aName, boolean aDefault, int aMinY, int aMaxY, int aWeight, int aDensity, - int aSize, ISubTagContainer top, ISubTagContainer bottom, ISubTagContainer between, - ISubTagContainer sprinkled) { - super(aName, aDefault, aMinY, aMaxY, aWeight, aDensity, aSize, top, bottom, between, sprinkled); - } - - public static void initOres() { - new BWWorldGenRoss128b( - "ore.mix.ross128.Thorianit", - true, - 30, - 60, - 17, - 1, - 16, - WerkstoffLoader.Thorianit, - Uraninite, - Lepidolite, - Spodumene); - new BWWorldGenRoss128b("ore.mix.ross128.carbon", true, 5, 25, 5, 4, 12, Graphite, Diamond, Coal, Graphite); - new BWWorldGenRoss128b( - "ore.mix.ross128.bismuth", - true, - 5, - 80, - 30, - 1, - 16, - WerkstoffLoader.Bismuthinit, - Stibnite, - Bismuth, - WerkstoffLoader.Bismutite); - new BWWorldGenRoss128b( - "ore.mix.ross128.TurmalinAlkali", - true, - 5, - 80, - 15, - 4, - 48, - WerkstoffLoader.Olenit, - WerkstoffLoader.FluorBuergerit, - WerkstoffLoader.ChromoAluminoPovondrait, - WerkstoffLoader.VanadioOxyDravit); - new BWWorldGenRoss128b( - "ore.mix.ross128.Roquesit", - true, - 30, - 50, - 3, - 1, - 12, - WerkstoffLoader.Arsenopyrite, - WerkstoffLoader.Ferberite, - WerkstoffLoader.Loellingit, - WerkstoffLoader.Roquesit); - new BWWorldGenRoss128b( - "ore.mix.ross128.Tungstate", - true, - 5, - 40, - 10, - 4, - 14, - WerkstoffLoader.Ferberite, - WerkstoffLoader.Huebnerit, - WerkstoffLoader.Loellingit, - Scheelite); - new BWWorldGenRoss128b( - "ore.mix.ross128.CopperSulfits", - true, - 40, - 70, - 80, - 3, - 24, - WerkstoffLoader.Djurleit, - WerkstoffLoader.Bornite, - WerkstoffLoader.Wittichenit, - Tetrahedrite); - new BWWorldGenRoss128b( - "ore.mix.ross128.Forsterit", - true, - 20, - 90, - 50, - 2, - 32, - WerkstoffLoader.Forsterit, - WerkstoffLoader.Fayalit, - WerkstoffLoader.DescloiziteCUVO4, - WerkstoffLoader.DescloiziteZNVO4); - new BWWorldGenRoss128b( - "ore.mix.ross128.Hedenbergit", - true, - 20, - 90, - 50, - 2, - 32, - WerkstoffLoader.Hedenbergit, - WerkstoffLoader.Fayalit, - WerkstoffLoader.DescloiziteCUVO4, - WerkstoffLoader.DescloiziteZNVO4); - new BWWorldGenRoss128b( - "ore.mix.ross128.RedZircon", - true, - 10, - 80, - 40, - 3, - 24, - WerkstoffLoader.Fayalit, - WerkstoffLoader.FuchsitAL, - WerkstoffLoader.RedZircon, - WerkstoffLoader.FuchsitCR); - } - - @Override - public boolean isGenerationAllowed(String aDimName, int aDimensionType, int aAllowedDimensionType) { - return aDimensionType == Configuration.crossModInteractions.ross128BID; - } -} diff --git a/src/main/java/bartworks/system/oregen/BWWorldGenRoss128ba.java b/src/main/java/bartworks/system/oregen/BWWorldGenRoss128ba.java deleted file mode 100644 index 74b4ec51ae8..00000000000 --- a/src/main/java/bartworks/system/oregen/BWWorldGenRoss128ba.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.system.oregen; - -import static gregtech.api.enums.Materials.Amethyst; -import static gregtech.api.enums.Materials.Barite; -import static gregtech.api.enums.Materials.Galena; -import static gregtech.api.enums.Materials.NaquadahEnriched; -import static gregtech.api.enums.Materials.Olivine; -import static gregtech.api.enums.Materials.Scheelite; -import static gregtech.api.enums.Materials.Sphalerite; -import static gregtech.api.enums.Materials.Tetrahedrite; - -import net.minecraft.block.Block; -import net.minecraft.util.StatCollector; -import net.minecraft.world.World; - -import bartworks.common.configs.Configuration; -import bartworks.system.material.WerkstoffLoader; -import bwcrossmod.galacticraft.planets.ross128ba.WorldProviderRoss128ba; -import gregtech.api.interfaces.ISubTagContainer; - -public class BWWorldGenRoss128ba extends BWOreLayer { - - public BWWorldGenRoss128ba(String aName, boolean aDefault, int aMinY, int aMaxY, int aWeight, int aDensity, - int aSize, ISubTagContainer top, ISubTagContainer bottom, ISubTagContainer between, - ISubTagContainer sprinkled) { - super(aName, aDefault, aMinY, aMaxY, aWeight, aDensity, aSize, top, bottom, between, sprinkled); - } - - @Override - public Block getDefaultBlockToReplace() { - return Block.getBlockFromName("GalacticraftCore:tile.moonBlock"); - } - - @Override - public int[] getDefaultDamageToReplace() { - int[] ret = new int[12]; - for (int i = 0; i < 12; i++) { - if (i != 5 && i != 3) ret[i] = i; - } - return ret; - } - - @Override - public String getDimName() { - return StatCollector.translateToLocal("moon.Ross128ba"); - } - - @SuppressWarnings("rawtypes") - @Override - public boolean isGenerationAllowed(World aWorld, Class... aAllowedDimensionTypes) { - for (Class clazz : aAllowedDimensionTypes) { - if (clazz == WorldProviderRoss128ba.class) { - return true; - } - } - - return false; - } - - public static void init_Ores() { - new BWWorldGenRoss128ba( - "ore.mix.ross128ba.tib", - true, - 30, - 60, - 6, - 1, - 16, - WerkstoffLoader.Tiberium, - WerkstoffLoader.Tiberium, - NaquadahEnriched, - NaquadahEnriched); - new BWWorldGenRoss128ba( - "ore.mix.ross128ba.Tungstate", - true, - 5, - 40, - 60, - 4, - 14, - WerkstoffLoader.Ferberite, - WerkstoffLoader.Huebnerit, - WerkstoffLoader.Loellingit, - Scheelite); - new BWWorldGenRoss128ba( - "ore.mix.ross128ba.bart", - true, - 30, - 60, - 1, - 1, - 1, - WerkstoffLoader.BArTiMaEuSNeK, - WerkstoffLoader.BArTiMaEuSNeK, - WerkstoffLoader.BArTiMaEuSNeK, - WerkstoffLoader.BArTiMaEuSNeK); - new BWWorldGenRoss128ba( - "ore.mix.ross128ba.TurmalinAlkali", - true, - 5, - 80, - 60, - 4, - 48, - WerkstoffLoader.Olenit, - WerkstoffLoader.FluorBuergerit, - WerkstoffLoader.ChromoAluminoPovondrait, - WerkstoffLoader.VanadioOxyDravit); - new BWWorldGenRoss128ba( - "ore.mix.ross128ba.Amethyst", - true, - 5, - 80, - 35, - 2, - 8, - Amethyst, - Olivine, - WerkstoffLoader.Prasiolite, - WerkstoffLoader.Hedenbergit); - new BWWorldGenRoss128ba( - "ore.mix.ross128ba.CopperSulfits", - true, - 40, - 70, - 80, - 3, - 24, - WerkstoffLoader.Djurleit, - WerkstoffLoader.Bornite, - WerkstoffLoader.Wittichenit, - Tetrahedrite); - new BWWorldGenRoss128ba( - "ore.mix.ross128ba.RedZircon", - true, - 10, - 80, - 40, - 3, - 24, - WerkstoffLoader.Fayalit, - WerkstoffLoader.FuchsitAL, - WerkstoffLoader.RedZircon, - WerkstoffLoader.FuchsitCR); - new BWWorldGenRoss128ba( - "ore.mix.ross128ba.Fluorspar", - true, - 10, - 80, - 35, - 4, - 8, - Galena, - Sphalerite, - WerkstoffLoader.Fluorspar, - Barite); - } - - @Override - public boolean isGenerationAllowed(String aDimName, int aDimensionType, int aAllowedDimensionType) { - return aDimensionType == Configuration.crossModInteractions.ross128BAID; - } -} diff --git a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java index 20651914e66..c1ea72baa6b 100644 --- a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java +++ b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java @@ -24,19 +24,25 @@ import java.util.Map; import java.util.stream.Collectors; -import net.minecraft.block.Block; +import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.gen.ChunkProviderServer; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import com.google.common.collect.ImmutableList; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.enums.DimensionDef; import gregtech.api.enums.GTValues; import gregtech.api.interfaces.IHatchElement; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.XSTR; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; @@ -45,23 +51,18 @@ public abstract class MTEVoidMinerBase extends MTEDrillerBase { + private ModDimensionDef dimensionDef; + private boolean canVoidMine = true; private VoidMinerUtility.DropMap dropMap = null; private VoidMinerUtility.DropMap extraDropMap = null; private float totalWeight; + private int multiplier = 1; protected final byte TIER_MULTIPLIER; private boolean mBlacklist = false; - /** - * @Deprecated Use {@link VoidMinerUtility#addBlockToDimensionList} - */ - @Deprecated - public static void addBlockToDimensionList(int dimId, Block block, int meta, float weight) { - VoidMinerUtility.addBlockToDimensionList(dimId, block, meta, weight); - } - public MTEVoidMinerBase(int aID, String aName, String aNameRegional, int tier) { super(aID, aName, aNameRegional); this.TIER_MULTIPLIER = (byte) Math.max(tier, 1); @@ -115,11 +116,22 @@ public int calculateMaxProgressTime(int tier, boolean simulateWorking) { return 10; } + @Override + protected int tryLowerPipeState(boolean isSimulating) { + if (!canVoidMine) { + return 3; + } + + return super.tryLowerPipeState(isSimulating); + } + @Override protected boolean workingAtBottom(ItemStack aStack, int xDrill, int yDrill, int zDrill, int xPipe, int zPipe, int yHead, int oldYHead) { - // if the dropMap has never been initialised or if the dropMap is empty - if (this.dropMap == null || this.totalWeight == 0) this.calculateDropMap(); + if (!canVoidMine) { + workState = 3; + return false; + } if (this.totalWeight != 0.f) { this.handleFluidConsumption(); @@ -168,6 +180,18 @@ protected MultiblockTooltipBuilder createTooltip() { return tt; } + @Override + protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { + super.drawTexts(screenElements, inventorySlot); + + if (!canVoidMine) { + String dimensionName = dimensionDef == null ? "unknown" + : I18n.format("gtnop.world." + dimensionDef.getDimensionName()); + String text = I18n.format("GT5U.gui.text.no_void_mining", dimensionName); + screenElements.addChild(new TextWidget(text).setTextAlignment(Alignment.TopLeft)); + } + } + @Override protected List> getAllowedHatches() { return ImmutableList.of(InputHatch, InputBus, OutputBus, Maintenance, Energy); @@ -240,35 +264,10 @@ private void handleFluidConsumption() { if (storedNobleGas == null || !this.consumeNobleGas(storedNobleGas)) this.multiplier = this.TIER_MULTIPLIER; } - /** - * Handles the ores added manually with {@link VoidMinerUtility#addMaterialToDimensionList} - * - * @param id the specified dim id - */ - private void handleExtraDrops(int id) { - if (VoidMinerUtility.extraDropsDimMap.containsKey(id)) { - extraDropMap = VoidMinerUtility.extraDropsDimMap.get(id); - } - } - - /** - * Gets the DropMap of the dim for the specified dim id - * - * @param id the dim number - */ - private void handleModDimDef(int id) { - if (VoidMinerUtility.dropMapsByDimId.containsKey(id)) { - this.dropMap = VoidMinerUtility.dropMapsByDimId.get(id); - } else { - String chunkProviderName = ((ChunkProviderServer) this.getBaseMetaTileEntity() - .getWorld() - .getChunkProvider()).currentChunkProvider.getClass() - .getName(); - - if (VoidMinerUtility.dropMapsByChunkProviderName.containsKey(chunkProviderName)) { - this.dropMap = VoidMinerUtility.dropMapsByChunkProviderName.get(chunkProviderName); - } - } + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + calculateDropMap(); } /** @@ -276,12 +275,25 @@ private void handleModDimDef(int id) { * totalWeight for normalisation */ private void calculateDropMap() { - this.dropMap = new VoidMinerUtility.DropMap(); - this.extraDropMap = new VoidMinerUtility.DropMap(); - int id = this.getBaseMetaTileEntity() - .getWorld().provider.dimensionId; - this.handleModDimDef(id); - this.handleExtraDrops(id); + this.dropMap = null; + this.extraDropMap = null; + this.totalWeight = 0; + this.canVoidMine = false; + + dimensionDef = DimensionDef.getDefForWorld( + getBaseMetaTileEntity().getWorld(), + getBaseMetaTileEntity().getXCoord() >> 4, + getBaseMetaTileEntity().getZCoord() >> 4); + + if (dimensionDef == null || !dimensionDef.canBeVoidMined()) return; + + this.canVoidMine = true; + + this.dropMap = VoidMinerUtility.dropMapsByDimName + .getOrDefault(dimensionDef.getDimensionName(), new VoidMinerUtility.DropMap()); + this.extraDropMap = VoidMinerUtility.extraDropsByDimName + .getOrDefault(dimensionDef.getDimensionName(), new VoidMinerUtility.DropMap()); + this.totalWeight = dropMap.getTotalWeight() + extraDropMap.getTotalWeight(); } @@ -293,16 +305,29 @@ private void handleOutputs() { .stream() .filter(GTUtility::isOre) .collect(Collectors.toList()); - final ItemStack output = this.nextOre(); - output.stackSize = multiplier; - if (inputOres.isEmpty() || this.mBlacklist && inputOres.stream() - .noneMatch(is -> GTUtility.areStacksEqual(is, output)) - || !this.mBlacklist && inputOres.stream() - .anyMatch(is -> GTUtility.areStacksEqual(is, output))) - this.addOutput(output); + + if (canVoidMine) { + final ItemStack output = this.nextOre(); + output.stackSize = multiplier; + + boolean matchesFilter = contains(inputOres, output); + + if (inputOres.isEmpty() || (this.mBlacklist ? !matchesFilter : matchesFilter)) { + this.addOutput(output); + } + } + this.updateSlots(); } + private static boolean contains(List list, ItemStack stack) { + for (ItemStack cursor : list) { + if (GTUtility.areStacksEqual(cursor, stack)) return true; + } + + return false; + } + @Override public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { this.mBlacklist = !this.mBlacklist; diff --git a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java index 237b1552746..50039924075 100644 --- a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java +++ b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java @@ -1,15 +1,11 @@ package bwcrossmod.galacticgreg; -import static galacticgreg.registry.GalacticGregRegistry.getModContainers; - import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Predicate; import net.minecraft.block.Block; import net.minecraft.init.Items; @@ -18,21 +14,19 @@ import net.minecraftforge.fluids.FluidStack; import bartworks.common.configs.Configuration; -import bartworks.system.material.Werkstoff; import bartworks.system.material.WerkstoffLoader; -import bartworks.system.oregen.BWOreLayer; import cpw.mods.fml.common.registry.GameRegistry; -import galacticgreg.GalacticGreg; -import galacticgreg.WorldgenOreLayerSpace; -import galacticgreg.WorldgenOreSmallSpace; -import galacticgreg.api.ModContainer; import galacticgreg.api.ModDimensionDef; -import gregtech.api.GregTechAPI; +import galacticgreg.api.enums.DimensionDef; +import galacticgreg.api.enums.DimensionDef.DimNames; +import gregtech.GTMod; import gregtech.api.enums.Materials; -import gregtech.api.interfaces.ISubTagContainer; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.util.GTUtility; import gregtech.common.WorldgenGTOreLayer; import gregtech.common.WorldgenGTOreSmallPieces; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; public class VoidMinerUtility { @@ -61,11 +55,18 @@ public DropMap() { * @param weight the non normalised weight * @param isBWOres true for BW ores, false for GT ores */ - public void addDrop(int meta, float weight, boolean isBWOres) { - if (isBWOres) { - addDrop(WerkstoffLoader.BWOres, meta, weight); - } else { - addDrop(GregTechAPI.sBlockOres1, meta, weight); + public void addDrop(IOreMaterial material, float weight) { + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = material; + + ItemStack stack = OreManager.getStack(info, 1); + + if (stack == null) { + GTMod.GT_FML_LOGGER.error("Could not add ore " + material + " to void miner drop map!"); + return; + } + + addDrop(stack, weight); } } @@ -119,169 +120,70 @@ public Map getInternalMap() { } } - public static final Map dropMapsByDimId = new HashMap<>(); - public static final Map dropMapsByChunkProviderName = new HashMap<>(); - public static final Map extraDropsDimMap = new HashMap<>(); + /** {full dim name: drop map} */ + public static final Map dropMapsByDimName = new HashMap<>(); + /** {full dim name: non-vein drop map} */ + public static final Map extraDropsByDimName = new HashMap<>(); // Adds tellurium to OW to ensure a way to get it, as it's used in Magneto Resonatic // Dust and Circuit Compound MK3 Dust static { - addMaterialToDimensionList(0, Materials.Tellurium, 8.0f); + addMaterialToDimensionList(DimNames.OW, Materials.Tellurium, 8.0f); } /** * Computes the ores of the dims */ public static void generateDropMaps() { - // vanilla dims - dropMapsByDimId.put(-1, getDropMapVanilla(-1)); - dropMapsByDimId.put(0, getDropMapVanilla(0)); - dropMapsByDimId.put(1, getDropMapVanilla(1)); - // Twilight Forest - dropMapsByDimId.put(7, getDropMapVanilla(7)); - - // ross dims - dropMapsByDimId.put( - Configuration.crossModInteractions.ross128BID, - getDropMapRoss(Configuration.crossModInteractions.ross128BID)); - dropMapsByDimId.put( - Configuration.crossModInteractions.ross128BAID, - getDropMapRoss(Configuration.crossModInteractions.ross128BAID)); - - // other space dims - for (ModContainer modContainer : getModContainers()) { - for (ModDimensionDef dimDef : modContainer.getDimensionList()) { - dropMapsByChunkProviderName.put(dimDef.getChunkProviderName(), getDropMapSpace(dimDef)); + for (WorldgenGTOreLayer layer : WorldgenGTOreLayer.sList) { + if (!layer.mEnabled) continue; + + for (String dim : layer.getAllowedDimensions()) { + ModDimensionDef dimensionDef = DimensionDef.getDefByName(dim); + + if (dimensionDef != null && !dimensionDef.canBeVoidMined()) continue; + + DropMap map = dropMapsByDimName.computeIfAbsent(dim, ignored -> new DropMap()); + + map.addDrop(layer.mPrimary, layer.mWeight); + map.addDrop(layer.mSecondary, layer.mWeight); + map.addDrop(layer.mSporadic, layer.mWeight / 8f); + map.addDrop(layer.mBetween, layer.mWeight / 8f); } } - } - /** - * Method to generate a DropMap that contains ores of a vanilla GT worldgen - */ - private static DropMap getDropMapVanilla(int dimId) { - DropMap dropMap = new DropMap(); - - // Ore Veins - Predicate oreLayerPredicate = makeOreLayerPredicate(dimId); - WorldgenGTOreLayer.sList.stream() - .filter(gt_worldgen -> gt_worldgen.mEnabled && oreLayerPredicate.test(gt_worldgen)) - .forEach(element -> { - dropMap.addDrop(element.mPrimaryMeta, element.mWeight, false); - dropMap.addDrop(element.mSecondaryMeta, element.mWeight, false); - dropMap.addDrop(element.mSporadicMeta, element.mWeight / 8f, false); - dropMap.addDrop(element.mBetweenMeta, element.mWeight / 8f, false); - }); - - // Small Ores - Predicate smallOresPredicate = makeSmallOresPredicate(dimId); - WorldgenGTOreSmallPieces.sList.stream() - .filter(gt_worldgen -> gt_worldgen.mEnabled && smallOresPredicate.test(gt_worldgen)) - .forEach(element -> dropMap.addDrop(element.mMeta, element.mAmount, false)); - return dropMap; - } + for (WorldgenGTOreSmallPieces layer : WorldgenGTOreSmallPieces.sList) { + if (!layer.mEnabled) continue; - /** - * Makes a predicate for the GT normal ore veins worldgen - * - * @return the predicate - */ - private static Predicate makeOreLayerPredicate(int dimensionId) { - return switch (dimensionId) { - case -1 -> gt_worldgen -> gt_worldgen.mNether; - case 0 -> gt_worldgen -> gt_worldgen.mOverworld; - case 1 -> gt_worldgen -> gt_worldgen.mEnd || gt_worldgen.mEndAsteroid; - case 7 -> gt_worldgen -> gt_worldgen.twilightForest; - default -> throw new IllegalStateException(); - }; - } + for (String dim : layer.getAllowedDimensions()) { + ModDimensionDef dimensionDef = DimensionDef.getDefByName(dim); - /** - * Makes a predicate for the GT normal small ore worldgen - * - * @return the predicate - */ - private static Predicate makeSmallOresPredicate(int dimensionId) { - return switch (dimensionId) { - case -1 -> gt_worldgen -> gt_worldgen.mNether; - case 0 -> gt_worldgen -> gt_worldgen.mOverworld; - case 1 -> gt_worldgen -> gt_worldgen.mEnd; - case 7 -> gt_worldgen -> gt_worldgen.twilightForest; - default -> throw new IllegalStateException(); - }; - } + if (dimensionDef != null && !dimensionDef.canBeVoidMined()) continue; - /** - * Create a DropMap that contains ores of Ross dims - * - * @param aID dim id of Ross128b or Ross128ba - */ - private static DropMap getDropMapRoss(int aID) { - DropMap dropMap = new DropMap(); - for (BWOreLayer oreLayer : BWOreLayer.sList) { - if (oreLayer.mEnabled && oreLayer.isGenerationAllowed("", aID, 0)) { - List data = oreLayer.getStacks(); - dropMap.addDrop(data.get(0), oreLayer.mWeight); - dropMap.addDrop(data.get(1), oreLayer.mWeight); - dropMap.addDrop(data.get(2), oreLayer.mWeight / 8f); - dropMap.addDrop(data.get(3), oreLayer.mWeight / 8f); + DropMap map = dropMapsByDimName.computeIfAbsent(dim, ignored -> new DropMap()); + + map.addDrop(layer.getMaterial(), layer.mAmount); } } - return dropMap; } - /** - * Create a DropMap contains the ores from the galacticGreg space worldgen corresponding to the target dim - * - * @param finalDef ModDimensionDef corresponding to the target dim - */ - private static DropMap getDropMapSpace(ModDimensionDef finalDef) { - DropMap dropMap = new DropMap(); - - // Normal Ore Veins - GalacticGreg.oreVeinWorldgenList.stream() - .filter( - gt_worldgen -> gt_worldgen.mEnabled && gt_worldgen instanceof WorldgenOreLayerSpace oreLayerSpace - && oreLayerSpace.isEnabledForDim(finalDef)) - .map(gt_worldgen -> (WorldgenOreLayerSpace) gt_worldgen) - .forEach(element -> { - dropMap.addDrop(element.mPrimaryMeta, element.mWeight, false); - dropMap.addDrop(element.mSecondaryMeta, element.mWeight, false); - dropMap.addDrop(element.mSporadicMeta, element.mWeight / 8f, false); - dropMap.addDrop(element.mBetweenMeta, element.mWeight / 8f, false); - }); - - // Normal Small Ores - GalacticGreg.smallOreWorldgenList.stream() - .filter( - gt_worldgen -> gt_worldgen.mEnabled && gt_worldgen instanceof WorldgenOreSmallSpace oreSmallPiecesSpace - && oreSmallPiecesSpace.isEnabledForDim(finalDef)) - .map(gt_worldgen -> (WorldgenOreSmallSpace) gt_worldgen) - .forEach(element -> dropMap.addDrop(element.mMeta, element.mAmount, false)); - return dropMap; - } + public static void addBlockToDimensionList(String dimName, Block block, int meta, float weight) { + DropMap map = dropMapsByDimName.computeIfAbsent(dimName, ignored -> new DropMap()); - public static void addBlockToDimensionList(int dimId, Block block, int meta, float weight) { - if (!extraDropsDimMap.containsKey(dimId)) { - extraDropsDimMap.put(dimId, new DropMap()); - } - extraDropsDimMap.get(dimId) - .addDrop(block, meta, weight); + map.addDrop(block, meta, weight); } /** * Public method giving other mods the ability to add manually a material with an ore version into the external * dropMap for a specified dim id * - * @param DimensionID the dim id targeted - * @param Material the material with an ore version - * @param weight the non normalised version of the given weight + * @param dimName the full dim name of the dim to target + * @param material the material with an ore version + * @param weight the non normalised version of the given weight */ - public static void addMaterialToDimensionList(int DimensionID, ISubTagContainer Material, float weight) { - if (Material instanceof Materials gtMaterial) { - addBlockToDimensionList(DimensionID, GregTechAPI.sBlockOres1, gtMaterial.mMetaItemSubID, weight); - } else if (Material instanceof Werkstoff werkstoff) { - addBlockToDimensionList(DimensionID, WerkstoffLoader.BWOres, werkstoff.getmID(), weight); - } + public static void addMaterialToDimensionList(String dimName, IOreMaterial material, float weight) { + DropMap map = dropMapsByDimName.computeIfAbsent(dimName, ignored -> new DropMap()); + + map.addDrop(material, weight); } } diff --git a/src/main/java/bwcrossmod/galacticraft/GalacticraftProxy.java b/src/main/java/bwcrossmod/galacticraft/GalacticraftProxy.java index 9ad58820d08..6c3ee3a0993 100644 --- a/src/main/java/bwcrossmod/galacticraft/GalacticraftProxy.java +++ b/src/main/java/bwcrossmod/galacticraft/GalacticraftProxy.java @@ -17,8 +17,6 @@ import bartworks.API.SideReference; import bartworks.common.configs.Configuration; -import bartworks.system.oregen.BWWorldGenRoss128b; -import bartworks.system.oregen.BWWorldGenRoss128ba; import bwcrossmod.galacticraft.atmosphere.BWAtmosphereManager; import bwcrossmod.galacticraft.solarsystems.Ross128SolarSystem; import cpw.mods.fml.common.event.FMLInitializationEvent; @@ -52,8 +50,6 @@ private static void serverpreInit(FMLPreInitializationEvent e) {} private static void clientpreInit(FMLPreInitializationEvent e) {} private static void commonpreInit(FMLPreInitializationEvent e) { - BWWorldGenRoss128b.initOres(); - BWWorldGenRoss128ba.init_Ores(); MinecraftForge.EVENT_BUS.register(BWAtmosphereManager.INSTANCE); } diff --git a/src/main/java/bwcrossmod/galacticraft/planets/ross128b/ChunkProviderRoss128b.java b/src/main/java/bwcrossmod/galacticraft/planets/ross128b/ChunkProviderRoss128b.java index ba9414250c6..1d74e36df8e 100644 --- a/src/main/java/bwcrossmod/galacticraft/planets/ross128b/ChunkProviderRoss128b.java +++ b/src/main/java/bwcrossmod/galacticraft/planets/ross128b/ChunkProviderRoss128b.java @@ -38,7 +38,6 @@ import net.minecraftforge.event.terraingen.TerrainGen; import bartworks.common.configs.Configuration; -import bartworks.system.oregen.BWWordGenerator; import bartworks.system.worldgen.MapGenRuins; import bwcrossmod.thaumcraft.util.ThaumcraftHandler; import gregtech.api.objects.XSTR; @@ -47,7 +46,6 @@ public class ChunkProviderRoss128b extends ChunkProviderGenerate { XSTR rand = new XSTR(); private BiomeGenBase[] biomesForGeneration; - public static final BWWordGenerator BWOreGen = new BWWordGenerator(); private final World worldObj; private final MapGenBase caveGenerator = new MapGenCaves(); private final MapGenBase ravineGenerator = new MapGenRavine(); @@ -161,7 +159,6 @@ public void populate(IChunkProvider p_73153_1_, int p_73153_2_, int p_73153_3_) } } - BWOreGen.generate(this.rand, p_73153_2_, p_73153_3_, this.worldObj, this, this); MinecraftForge.EVENT_BUS .post(new PopulateChunkEvent.Post(p_73153_1_, this.worldObj, this.rand, p_73153_2_, p_73153_3_, false)); diff --git a/src/main/java/bwcrossmod/galacticraft/planets/ross128ba/ChunkProviderRoss128ba.java b/src/main/java/bwcrossmod/galacticraft/planets/ross128ba/ChunkProviderRoss128ba.java index 67b776f4736..eb808aa3fc8 100644 --- a/src/main/java/bwcrossmod/galacticraft/planets/ross128ba/ChunkProviderRoss128ba.java +++ b/src/main/java/bwcrossmod/galacticraft/planets/ross128ba/ChunkProviderRoss128ba.java @@ -25,7 +25,6 @@ import net.minecraft.world.chunk.IChunkProvider; import bartworks.util.NoiseUtil.BartsNoise; -import bwcrossmod.galacticraft.planets.ross128b.ChunkProviderRoss128b; import gregtech.api.objects.XSTR; import micdoodle8.mods.galacticraft.api.prefab.world.gen.MapGenBaseMeta; import micdoodle8.mods.galacticraft.core.blocks.GCBlocks; @@ -71,7 +70,6 @@ public void decoratePlanet(World par1World, Random par2Random, int par3, int par public void populate(IChunkProvider par1IChunkProvider, int par2, int par3) { super.populate(par1IChunkProvider, par2, par3); BlockFalling.fallInstantly = true; - ChunkProviderRoss128b.BWOreGen.generate(this.rand, par2, par3, this.worldObj, this, this); BlockFalling.fallInstantly = false; } diff --git a/src/main/java/detrav/commands/DetravScannerCommand.java b/src/main/java/detrav/commands/DetravScannerCommand.java index 774900b2655..6b9cbe15208 100644 --- a/src/main/java/detrav/commands/DetravScannerCommand.java +++ b/src/main/java/detrav/commands/DetravScannerCommand.java @@ -3,32 +3,26 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.function.BiFunction; import net.minecraft.block.Block; import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.chunk.Chunk; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.util.GTLanguageManager; -import gregtech.common.blocks.TileEntityOres; +import com.google.common.collect.ImmutableList; + +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; /** * Created by wital_000 on 17.03.2016. */ public class DetravScannerCommand implements ICommand { - private final List aliases; - - public DetravScannerCommand() { - this.aliases = new ArrayList(); - this.aliases.add("DetravScanner"); - this.aliases.add("dscan"); - } + private final List aliases = ImmutableList.of("DetravScanner", "dscan"); @Override public String getCommandName() { @@ -41,7 +35,7 @@ public String getCommandUsage(ICommandSender sender) { } @Override - public List getCommandAliases() { + public List getCommandAliases() { return this.aliases; } @@ -89,39 +83,35 @@ public void processCommand(ICommandSender sender, String[] args) { private void process(ICommandSender sender, int aX, int aZ, String fName) { Chunk c = sender.getEntityWorld() .getChunkFromChunkCoords(aX, aZ); - if (c == null) sender.addChatMessage(new ChatComponentText("ERROR")); + + if (c == null) { + sender.addChatMessage(new ChatComponentText("ERROR")); + return; + } + HashMap ores = new HashMap<>(); + + BiFunction sum = Integer::sum; + for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { int ySize = c.getHeightValue(x, z); for (int y = 1; y < ySize; y++) { Block b = c.getBlock(x, y, z); - if (b != GregTechAPI.sBlockOres1) { - continue; - } + int meta = c.getBlockMetadata(x, y, z); - TileEntity entity = c.getTileEntityUnsafe(x, y, z); + try (OreInfo info = OreManager.getOreInfo(b, meta)) { + if (info == null || info.isSmall) continue; - if (entity == null) { - continue; - } + String matName = info.material.getLocalizedName(); - TileEntityOres gt_entity = (TileEntityOres) entity; - short meta = gt_entity.getMetaData(); - String name = Materials.getLocalizedNameForItem( - GTLanguageManager.getTranslation(b.getUnlocalizedName() + "." + meta + ".name"), - meta % 1000); - if (name.startsWith("Small")) continue; - if (fName == null || name.toLowerCase() - .contains(fName)) { - if (!ores.containsKey(name)) ores.put(name, 1); - else { - int val = ores.get(name); - ores.put(name, val + 1); + if (fName == null || matName.toLowerCase() + .contains(fName)) { + ores.merge(matName, 1, sum); } } } - } + sender.addChatMessage(new ChatComponentText("*** Detrav Scanner Begin")); for (String key : ores.keySet()) { sender.addChatMessage(new ChatComponentText(String.format("%s : %d", key, ores.get(key)))); @@ -139,10 +129,10 @@ public boolean canCommandSenderUseCommand(ICommandSender p_71519_1_) { } @Override - public List addTabCompletionOptions(ICommandSender sender, String[] args) { + public List addTabCompletionOptions(ICommandSender sender, String[] args) { if (args.length != 1) return null; if ("help".startsWith(args[0].toLowerCase())) { - List result = new ArrayList(); + List result = new ArrayList<>(); result.add("help"); sendHelpMessage(sender); return result; diff --git a/src/main/java/detrav/gui/DetravScannerGUI.java b/src/main/java/detrav/gui/DetravScannerGUI.java index 7e7b4964e35..784c6272bdb 100644 --- a/src/main/java/detrav/gui/DetravScannerGUI.java +++ b/src/main/java/detrav/gui/DetravScannerGUI.java @@ -1,7 +1,6 @@ package detrav.gui; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import net.minecraft.client.gui.GuiScreen; @@ -10,7 +9,10 @@ import org.lwjgl.opengl.GL11; +import com.gtnewhorizon.gtnhlib.util.CoordinatePacker; + import detrav.gui.textures.DetravMapTexture; +import detrav.items.DetravMetaGeneratedTool01; import gregtech.api.util.GTUtility; /** @@ -60,7 +62,7 @@ public void drawScreen(int x, int y, float f) { aY + currentHeight, aX + currentWidth, 10, - map.packet.ores, + map.packet, ((name, invert) -> { if (map != null) map.loadTexture(null, name, invert); })); prevW = width; prevH = height; @@ -91,30 +93,49 @@ public void drawScreen(int x, int y, float f) { for (int i = aY; i < aY + currentHeight; i += 128) drawTexturedModalRect(aX + currentWidth + 100, i, 171, 5, 5, Math.min(128, aY + currentHeight - i)); // right - if (map.packet.ptype == 2) { - HashMap[][] fluidInfo = map.packet.map; - int tX = x - aX; - int tY = y - aY; - if (tX >= 0 && tY >= 0 && tX < fluidInfo.length && tY < fluidInfo[0].length) { + if (map.packet.ptype == DetravMetaGeneratedTool01.MODE_FLUIDS) { + int cX = (x - aX) / 16; + int cZ = (y - aY) / 16; + + if (cX >= 0 && cZ >= 0 && cX < map.packet.size * 2 + 1 && cZ < map.packet.size * 2 + 1) { List info = new ArrayList<>(); - if (fluidInfo[tX][tY] != null) { - short fluidId = fluidInfo[tX][tY].get((byte) 1); - short fluidAmount = fluidInfo[tX][tY].get((byte) 2); - if (fluidId != 0 && fluidAmount > 0) { - info.add( - StatCollector.translateToLocal("gui.detrav.scanner.tooltip.fluid_name") - + map.packet.metaMap.get(fluidId)); - info.add( - StatCollector.translateToLocal("gui.detrav.scanner.tooltip.fluid_amount") - + GTUtility.formatNumbers(fluidAmount) - + " L"); - } else info.add(StatCollector.translateToLocal("gui.detrav.scanner.tooltip.no_fluid")); + + short objectId = map.packet.map.getOrDefault(CoordinatePacker.pack(cX, 0, cZ), (short) -1); + int amount = map.packet.getAmount(cX, cZ); + + if (objectId != -1 && amount > 0) { + var object = map.packet.objects.get(objectId); + + info.add(StatCollector.translateToLocal("gui.detrav.scanner.tooltip.fluid_name") + object.left()); + info.add( + StatCollector.translateToLocal("gui.detrav.scanner.tooltip.fluid_amount") + + GTUtility.formatNumbers(amount) + + " L"); } else { info.add(StatCollector.translateToLocal("gui.detrav.scanner.tooltip.no_fluid")); } func_146283_a(info, x, y); } } - } + if (map.packet.ptype == DetravMetaGeneratedTool01.MODE_POLLUTION) { + int cX = (x - aX) / 16; + int cZ = (y - aY) / 16; + + if (cX >= 0 && cZ >= 0 && cX < map.packet.size * 2 + 1 && cZ < map.packet.size * 2 + 1) { + List info = new ArrayList<>(); + + int amount = map.packet.getAmount(cX, cZ); + + if (amount > 0) { + info.add( + StatCollector.translateToLocal("gui.detrav.scanner.pollution") + ": " + + GTUtility.formatNumbers(amount) + + GTUtility.trans("203", " gibbl")); + } + + func_146283_a(info, x, y); + } + } + } } diff --git a/src/main/java/detrav/gui/OresList.java b/src/main/java/detrav/gui/OresList.java index 91252760eca..9e061dbe60a 100644 --- a/src/main/java/detrav/gui/OresList.java +++ b/src/main/java/detrav/gui/OresList.java @@ -1,19 +1,22 @@ package detrav.gui; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.function.BiConsumer; +import java.util.stream.Collectors; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.StatCollector; import cpw.mods.fml.client.GuiScrollingList; +import detrav.items.DetravMetaGeneratedTool01; +import detrav.net.ProspectingPacket; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; class OresList extends GuiScrollingList { - private final HashMap ores; + private final Object2IntOpenHashMap colors = new Object2IntOpenHashMap<>(); private final List keys; private final GuiScreen parent; private final BiConsumer onSelected; @@ -22,15 +25,32 @@ class OresList extends GuiScrollingList { private int selected = -1; public OresList(GuiScreen parent, int width, int height, int top, int bottom, int left, int entryHeight, - HashMap aOres, BiConsumer onSelected) { + ProspectingPacket packet, BiConsumer onSelected) { super(parent.mc, width, height, top, bottom, left, entryHeight); this.parent = parent; this.onSelected = onSelected; - ores = aOres; - keys = new ArrayList<>(ores.keySet()); + keys = packet.objects.short2ObjectEntrySet() + .stream() + .map( + e -> e.getValue() + .left()) + .collect(Collectors.toList()); Collections.sort(keys); - if (keys.size() > 1) keys.add(0, "All"); + if (packet.ptype == DetravMetaGeneratedTool01.MODE_POLLUTION) { + keys.clear(); + keys.add(StatCollector.translateToLocal("gui.detrav.scanner.pollution")); + } else if (keys.size() > 1) { + keys.add(0, "All"); + } selected = 0; + + for (var e : packet.objects.short2ObjectEntrySet()) { + this.colors.put( + e.getValue() + .left(), + e.getValue() + .rightInt()); + } } @Override @@ -61,6 +81,6 @@ protected void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer parent.mc.fontRenderer.trimStringToWidth(keys.get(slotIdx), listWidth - 10), this.left + 3, slotTop - 1, - ores.getOrDefault(keys.get(slotIdx), 0x7d7b76)); + colors.getOrDefault(keys.get(slotIdx), 0x7d7b76)); } } diff --git a/src/main/java/detrav/gui/textures/DetravMapTexture.java b/src/main/java/detrav/gui/textures/DetravMapTexture.java index 4a316e45233..f2b1695502a 100644 --- a/src/main/java/detrav/gui/textures/DetravMapTexture.java +++ b/src/main/java/detrav/gui/textures/DetravMapTexture.java @@ -3,6 +3,7 @@ import java.awt.Color; import java.awt.image.BufferedImage; import java.awt.image.WritableRaster; +import java.util.Arrays; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.AbstractTexture; @@ -11,7 +12,11 @@ import org.lwjgl.opengl.GL11; +import com.gtnewhorizon.gtnhlib.util.CoordinatePacker; + +import detrav.items.DetravMetaGeneratedTool01; import detrav.net.ProspectingPacket; +import gregtech.api.util.GTUtility; /** * Created by wital_000 on 21.03.2016. @@ -30,55 +35,126 @@ public DetravMapTexture(ProspectingPacket aPacket) { private BufferedImage getImage() { final int backgroundColor = invert ? Color.GRAY.getRGB() : Color.WHITE.getRGB(); - final int wh = (packet.size * 2 + 1) * 16; + final int blockSize = (packet.size * 2 + 1) * 16; + final int chunkSize = packet.size * 2 + 1; - BufferedImage image = new BufferedImage(wh, wh, BufferedImage.TYPE_INT_ARGB); + BufferedImage image = new BufferedImage(blockSize, blockSize, BufferedImage.TYPE_INT_ARGB); WritableRaster raster = image.getRaster(); int playerI = packet.posX - (packet.chunkX - packet.size) * 16 - 1; // Correct player offset int playerJ = packet.posZ - (packet.chunkZ - packet.size) * 16 - 1; - for (int i = 0; i < wh; i++) { - for (int j = 0; j < wh; j++) { - image.setRGB(i, j, backgroundColor); - if (packet.map[i][j] != null) { - if (packet.ptype == 0 || packet.ptype == 1) { - for (short meta : packet.map[i][j].values()) { - final String name = packet.metaMap.get(meta); - if (!selected.equals("All") && !selected.equals(name)) continue; - - image.setRGB(i, j, packet.ores.getOrDefault(name, Color.BLACK.getRGB()) | 0XFF000000); + + for (int y = 0; y < blockSize; y++) { + for (int x = 0; x < blockSize; x++) { + image.setRGB(x, y, backgroundColor); + } + } + + switch (packet.ptype) { + case DetravMetaGeneratedTool01.MODE_BIG_ORES, DetravMetaGeneratedTool01.MODE_ALL_ORES -> { + + short[] depth = new short[blockSize * blockSize]; + Arrays.fill(depth, (short) 0); + + short selectedId = -1; + + if (!selected.equals("All")) { + for (var e : packet.objects.short2ObjectEntrySet()) { + if (selected.equals( + e.getValue() + .left())) { + selectedId = e.getShortKey(); break; } - } else if (packet.ptype == 2) { - final short fluidId = packet.map[i][j].get((byte) 1), - fluidSize = packet.map[i][j].get((byte) 2); - final String name = packet.metaMap.get(fluidId); + } + } + + for (var e : packet.map.long2ShortEntrySet()) { + if (selectedId != -1 && selectedId != e.getShortValue()) continue; + + long coord = e.getLongKey(); + + int x = CoordinatePacker.unpackX(coord); + int y = CoordinatePacker.unpackY(coord); + int z = CoordinatePacker.unpackZ(coord); + + if (y < depth[x + z * blockSize]) continue; + depth[x + z * blockSize] = (short) y; + + var object = packet.objects.get(e.getShortValue()); + + if (object == null) continue; + + image.setRGB(x, z, object.rightInt()); + } + } + case DetravMetaGeneratedTool01.MODE_FLUIDS -> { + for (int cZ = 0; cZ < chunkSize; cZ++) { + for (int cX = 0; cX < chunkSize; cX++) { + int amount = packet.getAmount(cX, cZ); - // Variables used to locate within a chunk. - final int k = (i % 16), l = (j % 16); + var object = packet.objects.get(packet.map.get(CoordinatePacker.pack(cX, 0, cZ))); - if (((k + l * 16) * 3) < (fluidSize + 48) - && (selected.equals("All") || selected.equals(name))) { - image.setRGB(i, j, packet.ores.getOrDefault(name, Color.BLACK.getRGB()) | 0XFF000000); + if (object == null) continue; + + String name = object.left(); + int rgba = object.rightInt(); + + if (!selected.equals("All") && !selected.equals(name)) continue; + + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + if ((x + y * 16) * 3 < amount + 48) { + image.setRGB(cX * 16 + x, cZ * 16 + y, rgba); + } + } } - } else if (packet.ptype == 3) { - final short meta = packet.map[i][j].get((byte) 1); - image.setRGB(i, j, ((meta & 0xFF) << 16) + ((meta & 0xFF) << 8) + ((meta & 0xFF)) | 0XFF000000); } } - // draw player pos - if (i == playerI || j == playerJ) { - raster.setSample(i, j, 0, (raster.getSample(i, j, 0) + 255) / 2); - raster.setSample(i, j, 1, raster.getSample(i, j, 1) / 2); - raster.setSample(i, j, 2, raster.getSample(i, j, 2) / 2); + } + case DetravMetaGeneratedTool01.MODE_POLLUTION -> { + for (int cZ = 0; cZ < chunkSize; cZ++) { + for (int cX = 0; cX < chunkSize; cX++) { + int amount = packet.getAmount(cX, cZ); + + if (amount == 0) continue; + + float mult = amount / 500000f; + + if (!invert) mult = 1f - mult; + + mult = GTUtility.clamp(mult, 0, 1); + + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + int x2 = cX * 16 + x; + int y2 = cZ * 16 + y; + + raster.setSample(x2, y2, 0, (int) (raster.getSample(x2, y2, 0) * mult)); + raster.setSample(x2, y2, 1, (int) (raster.getSample(x2, y2, 1) * mult)); + raster.setSample(x2, y2, 2, (int) (raster.getSample(x2, y2, 2) * mult)); + } + } + } } + } + } + + for (int y = 0; y < blockSize; y++) { + for (int x = 0; x < blockSize; x++) { // draw grid - if ((i) % 16 == 0 || (j) % 16 == 0) { - raster.setSample(i, j, 0, raster.getSample(i, j, 0) / 2); - raster.setSample(i, j, 1, raster.getSample(i, j, 1) / 2); - raster.setSample(i, j, 2, raster.getSample(i, j, 2) / 2); + if (x % 16 == 0 || y % 16 == 0) { + raster.setSample(x, y, 0, raster.getSample(x, y, 0) / 2); + raster.setSample(x, y, 1, raster.getSample(x, y, 1) / 2); + raster.setSample(x, y, 2, raster.getSample(x, y, 2) / 2); } + // draw player pos + if (x == playerI || y == playerJ) { + raster.setSample(x, y, 0, (raster.getSample(x, y, 0) + 255) / 2); + raster.setSample(x, y, 1, raster.getSample(x, y, 1) / 2); + raster.setSample(x, y, 2, raster.getSample(x, y, 2) / 2); + } } } diff --git a/src/main/java/detrav/items/DetravMetaGeneratedTool01.java b/src/main/java/detrav/items/DetravMetaGeneratedTool01.java index 2e6f4bfd93c..213a15216bc 100644 --- a/src/main/java/detrav/items/DetravMetaGeneratedTool01.java +++ b/src/main/java/detrav/items/DetravMetaGeneratedTool01.java @@ -261,6 +261,11 @@ public void addAdditionalToolTips(List aList, ItemStack aStack, EntityPlayer aPl EnumChatFormatting.ITALIC + StatCollector.translateToLocal("tooltip.detrav.scanner.usage.4")); } + public static final int MODE_BIG_ORES = 0; + public static final int MODE_ALL_ORES = 1; + public static final int MODE_FLUIDS = 2; + public static final int MODE_POLLUTION = 3; + public Long getToolGTDetravData(ItemStack aStack) { NBTTagCompound aNBT = aStack.getTagCompound(); if (aNBT != null) { diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java index fb3e4833995..301f9580156 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -1,51 +1,64 @@ package detrav.items.behaviours; +import static detrav.items.DetravMetaGeneratedTool01.MODE_ALL_ORES; +import static detrav.items.DetravMetaGeneratedTool01.MODE_BIG_ORES; +import static detrav.items.DetravMetaGeneratedTool01.MODE_FLUIDS; import static gregtech.api.enums.Mods.VisualProspecting; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.concurrent.Future; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.fluids.FluidStack; +import com.google.common.collect.MapMaker; import com.sinthoras.visualprospecting.VisualProspecting_API; import detrav.items.DetravMetaGeneratedTool01; import detrav.net.DetravNetwork; import detrav.net.ProspectingPacket; -import detrav.utils.BartWorksHelper; -import detrav.utils.GTppHelper; import gregtech.api.items.MetaBaseItem; -import gregtech.api.objects.ItemData; -import gregtech.api.util.GTLanguageManager; -import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.task.CooperativeScheduler; import gregtech.common.UndergroundOil; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; +import gregtech.common.pollution.Pollution; /** * Created by wital_000 on 19.03.2016. */ public class BehaviourDetravToolElectricProspector extends BehaviourDetravToolProspector { + private Map> PENDING_SCANS = new MapMaker().weakValues() + .makeMap(); + public BehaviourDetravToolElectricProspector(int aCosts) { super(aCosts); } public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aWorld, EntityPlayer aPlayer) { if (!aWorld.isRemote) { - int data = DetravMetaGeneratedTool01.INSTANCE.getToolGTDetravData(aStack) - .intValue(); + Future scan = PENDING_SCANS.remove(aPlayer); + + if (scan != null && !scan.isDone()) { + scan.cancel(true); + aPlayer.addChatMessage(new ChatComponentText("Cancelled pending scan")); + } + if (aPlayer.isSneaking()) { + int data = DetravMetaGeneratedTool01.INSTANCE.getToolGTDetravData(aStack) + .intValue(); + data++; if (data > 3) data = 0; aPlayer.addChatMessage( @@ -55,134 +68,108 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW return super.onItemRightClick(aItem, aStack, aWorld, aPlayer); } - final DetravMetaGeneratedTool01 tool = (DetravMetaGeneratedTool01) aItem; + int data = DetravMetaGeneratedTool01.INSTANCE.getToolGTDetravData(aStack) + .intValue(); + final int cX = ((int) aPlayer.posX) >> 4; final int cZ = ((int) aPlayer.posZ) >> 4; - int size = aItem.getHarvestLevel(aStack, "") + 1; final List chunks = new ArrayList<>(); aPlayer.addChatMessage(new ChatComponentText("Scanning...")); - for (int i = -size; i <= size; i++) - for (int j = -size; j <= size; j++) if (i != -size && i != size && j != -size && j != size) - chunks.add(aWorld.getChunkFromChunkCoords(cX + i, cZ + j)); - size = size - 1; + final int radius = aItem.getHarvestLevel(aStack, ""); + + int scanRadius = radius + 1; + for (int i = -scanRadius; i <= scanRadius; i++) { + for (int j = -scanRadius; j <= scanRadius; j++) { + if (i != -scanRadius && i != scanRadius && j != -scanRadius && j != scanRadius) { + chunks.add(aWorld.getChunkFromChunkCoords(cX + i, cZ + j)); + } + } + } + + final DetravMetaGeneratedTool01 tool = (DetravMetaGeneratedTool01) aItem; + if (!aPlayer.capabilities.isCreativeMode) tool.doDamage(aStack, this.mCosts * chunks.size()); final ProspectingPacket packet = new ProspectingPacket( cX, cZ, (int) aPlayer.posX, (int) aPlayer.posZ, - size, + radius, data); - final String small_ore_keyword = StatCollector.translateToLocal("detrav.scanner.small_ore.keyword"); - for (Chunk c : chunks) { - for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { - final int ySize = c.getHeightValue(x, z); - for (int y = 1; y < ySize; y++) { - switch (data) { - case 0, 1 -> { - final Block tBlock = c.getBlock(x, y, z); - short tMetaID = (short) c.getBlockMetadata(x, y, z); - if (tBlock instanceof BlockOresAbstract) { - TileEntity tTileEntity = c.getTileEntityUnsafe(x, y, z); - if ((tTileEntity instanceof TileEntityOres) - && ((TileEntityOres) tTileEntity).mNatural) { - tMetaID = ((TileEntityOres) tTileEntity).getMetaData(); - try { - String name = GTLanguageManager - .getTranslation(tBlock.getUnlocalizedName() + "." + tMetaID + ".name"); - if (data != 1 && name.startsWith(small_ore_keyword)) continue; - packet.addBlock(c.xPosition * 16 + x, y, c.zPosition * 16 + z, tMetaID); - } catch (Exception e) { - String name = tBlock.getUnlocalizedName() + "."; - if (data != 1 && name.contains(".small.")) continue; - packet.addBlock(c.xPosition * 16 + x, y, c.zPosition * 16 + z, tMetaID); + + Future task = CooperativeScheduler.INSTANCE.schedule(ctx -> { + while (!ctx.shouldYield()) { + if (chunks.isEmpty()) { + ctx.stop(null); + break; + } + + Chunk c = chunks.remove(chunks.size() - 1); + + switch (data) { + case MODE_BIG_ORES, MODE_ALL_ORES -> { + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + final int height = c.getHeightValue(x, z); + + for (int y = 1; y < height; y++) { + Block block = c.getBlock(x, y, z); + int meta = c.getBlockMetadata(x, y, z); + + try (OreInfo info = OreManager.getOreInfo(block, meta)) { + if (info == null || !info.isNatural) continue; + if (data != MODE_ALL_ORES && info.isSmall) continue; + + packet.addBlock(c.xPosition * 16 + x, y, c.zPosition * 16 + z, block, meta); + continue; } } - } else if (GTppHelper.isGTppBlock(tBlock)) { - packet.addBlock( - c.xPosition * 16 + x, - y, - c.zPosition * 16 + z, - GTppHelper.getMetaFromBlock(tBlock)); - } else if (BartWorksHelper.isOre(tBlock)) { - if (data != 1 && BartWorksHelper.isSmallOre(tBlock)) continue; - packet.addBlock( - c.xPosition * 16 + x, - y, - c.zPosition * 16 + z, - BartWorksHelper.getMetaFromBlock(c, x, y, z, tBlock)); - } else if (data == 1) { - ItemData tAssotiation = GTOreDictUnificator - .getAssociation(new ItemStack(tBlock, 1, tMetaID)); - if ((tAssotiation != null) && (tAssotiation.mPrefix.toString() - .startsWith("ore"))) { - packet.addBlock( - c.xPosition * 16 + x, - y, - c.zPosition * 16 + z, - (short) tAssotiation.mMaterial.mMaterial.mMetaItemSubID); - } } } - case 2 -> { - if ((x == 0) || (z == 0)) { // Skip doing the locations with the grid on them. - break; - } - FluidStack fStack = UndergroundOil.undergroundOil( - aWorld.getChunkFromBlockCoords(c.xPosition * 16 + x, c.zPosition * 16 + z), - -1); - if (fStack.amount > 0) { - packet.addBlock( - c.xPosition * 16 + x, - 1, - c.zPosition * 16 + z, - (short) fStack.getFluidID()); - packet - .addBlock(c.xPosition * 16 + x, 2, c.zPosition * 16 + z, (short) fStack.amount); - } - } - case 3 -> { - float polution = (float) getPollution( - aWorld, - c.xPosition * 16 + x, - c.zPosition * 16 + z); - polution /= 2000000; - polution *= -0xFF; - if (polution > 0xFF) polution = 0xFF; - polution = 0xFF - polution; - packet.addBlock(c.xPosition * 16 + x, 1, c.zPosition * 16 + z, (short) polution); - } } - if (data > 1) break; + case MODE_FLUIDS -> { + FluidStack fluid = UndergroundOil.undergroundOil(c, -1); + + packet.addFluid(c.xPosition, c.zPosition, fluid); + } + case DetravMetaGeneratedTool01.MODE_POLLUTION -> { + int pollution = Pollution.getPollution(c); + + packet.addPollution(c.xPosition, c.zPosition, pollution); + } } } - } - packet.level = aItem.getHarvestLevel(aStack, ""); - DetravNetwork.INSTANCE.sendToPlayer(packet, (EntityPlayerMP) aPlayer); - if (!aPlayer.capabilities.isCreativeMode) tool.doDamage(aStack, this.mCosts * chunks.size()); + }) + .onFinished(x -> { + PENDING_SCANS.remove(aPlayer); + + DetravNetwork.INSTANCE.sendToPlayer(packet, (EntityPlayerMP) aPlayer); + + if (VisualProspecting.isModLoaded()) { + if (data == MODE_BIG_ORES || data == MODE_ALL_ORES) { + VisualProspecting_API.LogicalServer.sendProspectionResultsToClient( + (EntityPlayerMP) aPlayer, + VisualProspecting_API.LogicalServer.prospectOreVeinsWithinRadius( + aWorld.provider.dimensionId, + (int) aPlayer.posX, + (int) aPlayer.posZ, + radius * 16), + new ArrayList<>()); + } else if (data == MODE_FLUIDS) { + VisualProspecting_API.LogicalServer.sendProspectionResultsToClient( + (EntityPlayerMP) aPlayer, + new ArrayList<>(), + VisualProspecting_API.LogicalServer.prospectUndergroundFluidsWithingRadius( + aWorld, + (int) aPlayer.posX, + (int) aPlayer.posZ, + radius * 16)); + } + } + }); - if (VisualProspecting.isModLoaded()) { - if (data == 0 || data == 1) { - VisualProspecting_API.LogicalServer.sendProspectionResultsToClient( - (EntityPlayerMP) aPlayer, - VisualProspecting_API.LogicalServer.prospectOreVeinsWithinRadius( - aWorld.provider.dimensionId, - (int) aPlayer.posX, - (int) aPlayer.posZ, - size * 16), - new ArrayList<>()); - } else if (data == 2) { - VisualProspecting_API.LogicalServer.sendProspectionResultsToClient( - (EntityPlayerMP) aPlayer, - new ArrayList<>(), - VisualProspecting_API.LogicalServer.prospectUndergroundFluidsWithingRadius( - aWorld, - (int) aPlayer.posX, - (int) aPlayer.posZ, - size * 16)); - } - } + PENDING_SCANS.put(aPlayer, task); } return super.onItemRightClick(aItem, aStack, aWorld, aPlayer); } @@ -198,6 +185,7 @@ void addChatMassageByValue(EntityPlayer aPlayer, int value, String name) { new ChatComponentText(StatCollector.translateToLocal("detrav.scanner.found.texts.6") + name + " " + value)); } + @Override public boolean onItemUse(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float hitX, float hitY, float hitZ) { long data = DetravMetaGeneratedTool01.INSTANCE.getToolGTDetravData(aStack); @@ -223,8 +211,7 @@ public boolean onItemUse(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPla return true; } if (!aWorld.isRemote) { - int polution = getPollution(aWorld, aX, aZ); - addChatMassageByValue(aPlayer, polution, "Pollution"); + addChatMassageByValue(aPlayer, getPollution(aWorld, aX, aZ), "Pollution"); } return true; } diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java index 22a9f7b220c..86e8788385b 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java @@ -14,7 +14,6 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; @@ -24,22 +23,19 @@ import com.sinthoras.visualprospecting.VisualProspecting_API; -import bartworks.system.material.Werkstoff; import cpw.mods.fml.common.registry.LanguageRegistry; import detrav.DetravScannerMod; import detrav.items.DetravMetaGeneratedTool01; -import detrav.utils.BartWorksHelper; -import detrav.utils.GTppHelper; -import gregtech.api.GregTechAPI; import gregtech.api.enums.Materials; import gregtech.api.items.MetaBaseItem; import gregtech.api.objects.ItemData; import gregtech.api.util.GTLanguageManager; import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.util.GTUtility; import gregtech.common.UndergroundOil; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; import gregtech.common.items.behaviors.BehaviourNone; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import gregtech.common.pollution.Pollution; /** @@ -69,17 +65,14 @@ public boolean onItemUse(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPla if (aWorld.isRemote) return false; - if (aWorld.getBlock(aX, aY, aZ) == Blocks.bedrock) { + Block block = aWorld.getBlock(aX, aY, aZ); + int meta = aWorld.getBlockMetadata(aX, aY, aZ); + + if (block == Blocks.bedrock) { if (!aWorld.isRemote && aRandom.nextInt(100) < chance) { FluidStack fStack = UndergroundOil.undergroundOil(aWorld.getChunkFromBlockCoords(aX, aZ), -1); - addChatMassageByValue(aPlayer, fStack.amount / 2, "a Fluid");// fStack.getLocalizedName()); - /* - * boolean fluid = GT_UndergroundOil.undergroundOil(aWorld.getChunkFromBlockCoords(aX, aZ), -1)!=null - * &>_UndergroundOil.undergroundOil(aWorld.getChunkFromBlockCoords(aX, aZ), -1).getFluid()!=null; if - * (fluid) aPlayer.addChatMessage(new - * ChatComponentText(EnumChatFormatting.GREEN+"You found some liquid.")); else - * aPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+"You found no liquid.")); - */ + addChatMassageByValue(aPlayer, fStack.amount / 2, "a Fluid"); + if (!aPlayer.capabilities.isCreativeMode) ((DetravMetaGeneratedTool01) aItem).doDamage(aStack, this.mCosts); @@ -93,16 +86,14 @@ public boolean onItemUse(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPla } return true; } - if (aWorld.getBlock(aX, aY, aZ) - .getMaterial() == Material.rock - || aWorld.getBlock(aX, aY, aZ) - .getMaterial() == Material.ground - || aWorld.getBlock(aX, aY, aZ) == GregTechAPI.sBlockOres1) { - if (!aWorld.isRemote) { - prospectChunks(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, aRandom, chance); - } + + if (block.getMaterial() == Material.rock || block.getMaterial() == Material.ground + || GTUtility.isOre(block, meta)) { + prospectChunks(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, aRandom, chance); + return true; } + return false; } @@ -115,7 +106,7 @@ protected void prospectChunks(MetaBaseItem aItem, ItemStack aStack, EntityPlayer ores = new HashMap<>(); int range = aItem.getHarvestLevel(aStack, "") / 2 + (aStack.getItemDamage() / 4); - if ((range % 2) == 0) { + if (range % 2 == 0) { range += 1; // kinda not needed here, divide takes it out, but we put it back in with the range+1 in the // loop } @@ -126,11 +117,11 @@ protected void prospectChunks(MetaBaseItem aItem, ItemStack aStack, EntityPlayer EnumChatFormatting.GOLD + GTLanguageManager.sEnglishFile .get("LanguageFile", "gt.scanner.prospecting", "Prospecting at ") .getString() + EnumChatFormatting.BLUE + "(" + bX + ", " + bZ + ")")); - for (int x = -(range); x < (range + 1); ++x) { - aX = bX + (x * 16); - for (int z = -(range); z < (range + 1); ++z) { + for (int x = -range; x < range + 1; ++x) { + aX = bX + x * 16; + for (int z = -range; z < range + 1; ++z) { - aZ = bZ + (z * 16); + aZ = bZ + z * 16; int dist = x * x + z * z; for (distTextIndex = 0; distTextIndex < DISTANCEINTS.length; distTextIndex++) { @@ -138,25 +129,29 @@ protected void prospectChunks(MetaBaseItem aItem, ItemStack aStack, EntityPlayer break; } } - if (DetravScannerMod.DEBUG_ENABLED) aPlayer.addChatMessage( - new ChatComponentText( - EnumChatFormatting.YELLOW + "Chunk at " - + aX - + "|" - + aZ - + " to " - + (aX + 16) - + "|" - + (aZ + 16) - + StatCollector.translateToLocal("detrav.scanner.distance.texts." + distTextIndex))); + + if (DetravScannerMod.DEBUG_ENABLED) { + aPlayer.addChatMessage( + new ChatComponentText( + EnumChatFormatting.YELLOW + "Chunk at " + + aX + + "|" + + aZ + + " to " + + (aX + 16) + + "|" + + (aZ + 16) + + StatCollector.translateToLocal("detrav.scanner.distance.texts." + distTextIndex))); + } + processOreProspecting( (DetravMetaGeneratedTool01) aItem, aStack, aPlayer, - aWorld.getChunkFromBlockCoords(aX, aZ), - aWorld.getTileEntity(aX, aY, aZ), - GTOreDictUnificator.getAssociation( - new ItemStack(aWorld.getBlock(aX, aY, aZ), 1, aWorld.getBlockMetadata(aX, aY, aZ))), + aWorld, + aX, + aY, + aZ, aRandom, chance); } @@ -238,10 +233,10 @@ protected void prospectSingleChunk(MetaBaseItem aItem, ItemStack aStack, EntityP (DetravMetaGeneratedTool01) aItem, aStack, aPlayer, - aWorld.getChunkFromBlockCoords(aX, aZ), - aWorld.getTileEntity(aX, aY, aZ), - GTOreDictUnificator - .getAssociation(new ItemStack(aWorld.getBlock(aX, aY, aZ), 1, aWorld.getBlockMetadata(aX, aY, aZ))), + aWorld, + aX, + aY, + aZ, new SplittableRandom(), 1000); @@ -263,108 +258,94 @@ protected void prospectSingleChunk(MetaBaseItem aItem, ItemStack aStack, EntityP } protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack aStack, EntityPlayer aPlayer, - Chunk aChunk, TileEntity aTileEntity, ItemData tAssotiation, SplittableRandom aRandom, int chance)// TileEntity - // aTileEntity) - { - if (aTileEntity != null) { - if (aTileEntity instanceof TileEntityOres gt_entity) { - short meta = gt_entity.getMetaData(); - String format = LanguageRegistry.instance() - .getStringLocalization("gt.blockores." + meta + ".name"); - String name = Materials.getLocalizedNameForItem(format, meta % 1000); - addOreToHashMap(name, aPlayer); - if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts); - return; - } - } else if (tAssotiation != null) { + World world, int x, int y, int z, SplittableRandom aRandom, int chance) { + Chunk chunk = world.getChunkFromBlockCoords(x, z); + + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + ItemStack blockStack = new ItemStack(block, 1, meta); + + if (OreManager.isOre(block, meta)) { + addOreToHashMap(blockStack.getDisplayName(), aPlayer); + if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts); + return; + } + + ItemData itemData = GTOreDictUnificator.getAssociation(blockStack); + + if (itemData != null) { try { - String name = tAssotiation.toString(); + String name = itemData.toString(); addChatMassageByValue(aPlayer, -1, name); if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts); return; } catch (Exception e) { addChatMassageByValue(aPlayer, -1, "ERROR, lol ^_^"); } - } else if (aRandom.nextInt(100) < chance) { + + return; + } + + if (aRandom.nextInt(100) < chance) { final int data = DetravMetaGeneratedTool01.INSTANCE.getToolGTDetravData(aStack) .intValue(); - final String small_ore_keyword = StatCollector.translateToLocal("detrav.scanner.small_ore.keyword"); - for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { - int ySize = aChunk.getHeightValue(x, z); - for (int y = 1; y < ySize; y++) { - - Block tBlock = aChunk.getBlock(x, y, z); - short tMetaID = (short) aChunk.getBlockMetadata(x, y, z); - if (tBlock instanceof BlockOresAbstract) { - TileEntity tTileEntity = aChunk.getTileEntityUnsafe(x, y, z); - if ((tTileEntity instanceof TileEntityOres) && ((TileEntityOres) tTileEntity).mNatural) { - tMetaID = ((TileEntityOres) tTileEntity).getMetaData(); - try { - String format = LanguageRegistry.instance() - .getStringLocalization(tBlock.getUnlocalizedName() + "." + tMetaID + ".name"); - String name = Materials.getLocalizedNameForItem(format, tMetaID % 1000); - if (data != 1 && name.startsWith(small_ore_keyword)) continue; - addOreToHashMap(name, aPlayer); - } catch (Exception e) { - String name = tBlock.getUnlocalizedName() + "."; - if (data != 1 && name.contains(".small.")) continue; - addOreToHashMap(name, aPlayer); + + for (int cx = 0; cx < 16; cx++) { + for (int cz = 0; cz < 16; cz++) { + int ySize = chunk.getHeightValue(cx, cz); + for (int cy = 1; cy < ySize; cy++) { + + Block tBlock = chunk.getBlock(cx, cy, cz); + short tMetaID = (short) chunk.getBlockMetadata(cx, cy, cz); + + try (OreInfo info = OreManager.getOreInfo(tBlock, tMetaID)) { + if (info != null) { + if (!info.isNatural) continue; + if (data != DetravMetaGeneratedTool01.MODE_ALL_ORES && info.isSmall) continue; + + ItemStack blockStack2 = new ItemStack(tBlock, 1, tMetaID); + addOreToHashMap(blockStack2.getDisplayName(), aPlayer); + continue; } } - } else if (GTppHelper.isGTppBlock(tBlock)) { - String name = GTppHelper.getGTppVeinName(tBlock); - if (!name.isEmpty()) addOreToHashMap(name, aPlayer); - } else if (BartWorksHelper.isOre(tBlock)) { - if (data != 1 && BartWorksHelper.isSmallOre(tBlock)) continue; - final Werkstoff werkstoff = Werkstoff.werkstoffHashMap.getOrDefault( - (short) ((BartWorksHelper.getMetaFromBlock(aChunk, x, y, z, tBlock)) * -1), - null); - String type = BartWorksHelper.isSmallOre(tBlock) ? "oreSmall" : "ore"; - String translated = GTLanguageManager.getTranslation("bw.blocktype." + type); - addOreToHashMap(translated.replace("%material", werkstoff.getLocalizedName()), aPlayer); - } else if (data == 1) { - tAssotiation = GTOreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); - if ((tAssotiation != null) && (tAssotiation.mPrefix.toString() - .startsWith("ore"))) { - try { + + if (data == DetravMetaGeneratedTool01.MODE_ALL_ORES) { + itemData = GTOreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); + if (itemData != null && itemData.mPrefix.toString() + .startsWith("ore")) { try { - tMetaID = (short) tAssotiation.mMaterial.mMaterial.mMetaItemSubID; - String format = LanguageRegistry.instance() - .getStringLocalization("gt.blockores." + tMetaID + ".name"); - String name = Materials.getLocalizedNameForItem(format, tMetaID % 1000); - addOreToHashMap(name, aPlayer); - } catch (Exception e1) { - String name = tAssotiation.toString(); - addOreToHashMap(name, aPlayer); - } - } catch (Exception ignored) {} + try { + tMetaID = (short) itemData.mMaterial.mMaterial.mMetaItemSubID; + String format = LanguageRegistry.instance() + .getStringLocalization("gt.blockores." + tMetaID + ".name"); + String name = Materials.getLocalizedNameForItem(format, tMetaID % 1000); + addOreToHashMap(name, aPlayer); + } catch (Exception e1) { + String name = itemData.toString(); + addOreToHashMap(name, aPlayer); + } + } catch (Exception ignored) {} + } } } - } } if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts); return; - } else { - if (DetravScannerMod.DEBUG_ENABLED) - aPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + " Failed on this chunk")); - badluck++; - if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts / 4); } - // addChatMassageByValue(aPlayer,0,null); + + if (DetravScannerMod.DEBUG_ENABLED) + aPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + " Failed on this chunk")); + badluck++; + if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts / 4); } void addOreToHashMap(String orename, EntityPlayer aPlayer) { - String oreDistance = orename + StatCollector.translateToLocal("detrav.scanner.distance.texts." + distTextIndex); // orename - // + - // the - // textual - // distance - // of - // the - // ore + // orename + the textual distance of the ore + String oreDistance = orename + StatCollector.translateToLocal("detrav.scanner.distance.texts." + distTextIndex); if (!ores.containsKey(oreDistance)) { if (DetravScannerMod.DEBUG_ENABLED) aPlayer .addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + " Adding to oremap " + oreDistance)); diff --git a/src/main/java/detrav/net/ProspectingPacket.java b/src/main/java/detrav/net/ProspectingPacket.java index 1b861273e53..d7a96b6d8bf 100644 --- a/src/main/java/detrav/net/ProspectingPacket.java +++ b/src/main/java/detrav/net/ProspectingPacket.java @@ -6,25 +6,25 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.HashMap; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; -import net.minecraft.util.StatCollector; -import net.minecraftforge.fluids.FluidRegistry; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import com.google.common.base.Objects; +import com.gtnewhorizon.gtnhlib.util.CoordinatePacker; -import bartworks.system.material.Werkstoff; import detrav.DetravScannerMod; import detrav.gui.DetravScannerGUI; import detrav.gui.textures.DetravMapTexture; import detrav.utils.FluidColors; -import detrav.utils.GTppHelper; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.util.GTLanguageManager; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.common.ores.OreManager; +import it.unimi.dsi.fastutil.longs.Long2ShortOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; +import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap; /** * Created by wital_000 on 20.03.2016. @@ -37,11 +37,12 @@ public class ProspectingPacket extends DetravPacket { public final int posZ; public final int size; public final int ptype; - public final HashMap[][] map; - public final HashMap ores; - public final HashMap metaMap; - - public int level = -1; + /** {packed x,y,z: object id} */ + public final Long2ShortOpenHashMap map = new Long2ShortOpenHashMap(); + /** {object id: (object name, object rgba)} */ + public final Short2ObjectOpenHashMap> objects = new Short2ObjectOpenHashMap<>(); + /** {object name: object id} */ + private final Object2ShortOpenHashMap nameLookup = new Object2ShortOpenHashMap<>(); public ProspectingPacket(int chunkX, int chunkZ, int posX, int posZ, int size, int ptype) { this.chunkX = chunkX; @@ -50,53 +51,10 @@ public ProspectingPacket(int chunkX, int chunkZ, int posX, int posZ, int size, i this.posZ = posZ; this.size = size; this.ptype = ptype; - this.map = new HashMap[(size * 2 + 1) * 16][(size * 2 + 1) * 16]; - this.ores = new HashMap<>(); - this.metaMap = new HashMap<>(); } - private static void addOre(ProspectingPacket packet, byte y, int i, int j, short meta) { - final short[] rgba; - final String name; - try { - if (packet.ptype == 0 || packet.ptype == 1) { - // Ore or Small Ore - if (meta < 7000 || meta > 7500) { - if (meta > 0) { - Materials tMaterial = GregTechAPI.sGeneratedMaterials[meta % 1000]; - rgba = tMaterial.getRGBA(); - name = tMaterial.getLocalizedNameForItem( - GTLanguageManager.getTranslation("gt.blockores." + meta + ".name")); - } else { - final Werkstoff werkstoff = Werkstoff.werkstoffHashMap.getOrDefault((short) (meta * -1), null); - String translated = GTLanguageManager.getTranslation("bw.blocktype.ore"); - name = translated.replace("%material", werkstoff.getLocalizedName()); - rgba = werkstoff.getRGBA(); - } - } else { - gtPlusPlus.core.material.Material mat = GTppHelper.getMatFromMeta(meta); - rgba = mat.getRGBA(); - name = mat.getLocalizedName() + " Ore"; - } - } else if (packet.ptype == 2) { - // Fluid - rgba = FluidColors.getColor(meta); - name = Objects.firstNonNull( - FluidRegistry.getFluid(meta) - .getLocalizedName(new FluidStack(FluidRegistry.getFluid(meta), 0)), - StatCollector.translateToLocal("gui.detrav.scanner.unknown_fluid")); - } else if (packet.ptype == 3) { - // Pollution - name = StatCollector.translateToLocal("gui.detrav.scanner.pollution"); - rgba = new short[] { 125, 123, 118, 0 }; - } else { - return; - } - } catch (Exception ignored) { - return; - } - packet.ores.put(name, ((rgba[0] & 0xFF) << 16) + ((rgba[1] & 0xFF) << 8) + ((rgba[2] & 0xFF))); - packet.metaMap.put(meta, name); + private static int rgba(short[] rgba) { + return (0xFF << 24) | ((rgba[0] & 0xFF) << 16) + ((rgba[1] & 0xFF) << 8) + ((rgba[2] & 0xFF)); } public static Object decode(InputStream in) throws IOException { @@ -108,24 +66,28 @@ public static Object decode(InputStream in) throws IOException { aData.readInt(), aData.readInt(), aData.readInt()); - packet.level = aData.readInt(); - - int aSize = (packet.size * 2 + 1) * 16; - int checkOut = 0; - for (int i = 0; i < aSize; i++) for (int j = 0; j < aSize; j++) { - byte kSize = aData.readByte(); - if (kSize == 0) continue; - packet.map[i][j] = new HashMap<>(); - for (int k = 0; k < kSize; k++) { - final byte y = aData.readByte(); - final short meta = aData.readShort(); - packet.map[i][j].put(y, meta); - if (packet.ptype != 2 || y == 1) addOre(packet, y, i, j, meta); - checkOut++; - } + + int objectCount = aData.readInt(); + packet.objects.ensureCapacity(objectCount); + + for (int i = 0; i < objectCount; i++) { + short objectId = aData.readShort(); + String name = aData.readUTF(); + int rgba = aData.readInt(); + + packet.objects.put(objectId, ObjectIntPair.of(name, rgba)); } - int checkOut2 = aData.readInt(); - if (checkOut != checkOut2) return null; + + int instanceCount = aData.readInt(); + packet.map.ensureCapacity(instanceCount); + + for (int i = 0; i < instanceCount; i++) { + long coord = aData.readLong(); + short objectId = aData.readShort(); + + packet.map.put(coord, objectId); + } + return packet; } @@ -143,25 +105,26 @@ public void encode(OutputStream out) throws IOException { tOut.writeInt(posZ); tOut.writeInt(size); tOut.writeInt(ptype); - tOut.writeInt(level); - - int aSize = (size * 2 + 1) * 16; - int checkOut = 0; - for (int i = 0; i < aSize; i++) for (int j = 0; j < aSize; j++) { - HashMap data = map[i][j]; - if (data == null) tOut.writeByte(0); - else { - tOut.writeByte( - data.keySet() - .size()); - for (byte key : data.keySet()) { - tOut.writeByte(key); - tOut.writeShort(data.get(key)); - checkOut++; - } - } + + tOut.writeInt(objects.size()); + + for (var obj : objects.short2ObjectEntrySet()) { + tOut.writeShort(obj.getShortKey()); + tOut.writeUTF( + obj.getValue() + .left()); + tOut.writeInt( + obj.getValue() + .rightInt()); + } + + tOut.writeInt(map.size()); + + for (var instance : map.long2ShortEntrySet()) { + tOut.writeLong(instance.getLongKey()); + tOut.writeShort(instance.getShortValue()); } - tOut.writeInt(checkOut); + tOut.close(); } @@ -171,11 +134,77 @@ public void process() { DetravScannerMod.proxy.openProspectorGUI(); } - public void addBlock(int x, int y, int z, short metaData) { + private short nextId = 0; + + public void addBlock(int x, int y, int z, Block block, int meta) { int aX = x - (chunkX - size) * 16; int aZ = z - (chunkZ - size) * 16; - if (map[aX][aZ] == null) map[aX][aZ] = new HashMap<>(); - map[aX][aZ].put((byte) y, metaData); + + ItemStack stack = new ItemStack(block, 1, meta); + + String stackName = stack.getDisplayName(); + + short objectId; + + if (nameLookup.containsKey(stackName)) { + objectId = nameLookup.getShort(stackName); + } else { + objectId = nextId++; + + IOreMaterial mat = OreManager.getMaterial(block, meta); + + short[] rgba = mat == null ? new short[] { 125, 125, 125, 255 } : mat.getRGBA(); + + nameLookup.put(stackName, objectId); + objects.put(objectId, ObjectIntPair.of(stackName, rgba(rgba))); + } + + map.put(CoordinatePacker.pack(aX, y, aZ), objectId); + } + + public void addFluid(int cX, int cZ, FluidStack fluid) { + int aX = cX - (chunkX - size); + int aZ = cZ - (chunkZ - size); + + if (fluid == null || fluid.getFluid() == null) return; + + String stackName = fluid.getLocalizedName(); + + short objectId; + + if (nameLookup.containsKey(stackName)) { + objectId = nameLookup.getShort(stackName); + } else { + objectId = nextId++; + + nameLookup.put(stackName, objectId); + objects.put(objectId, ObjectIntPair.of(stackName, rgba(FluidColors.getColor(fluid.getFluidID())))); + } + + int lower = fluid.amount & 0xFFFF; + int upper = (fluid.amount >> 16) & 0xFFFF; + + map.put(CoordinatePacker.pack(aX, 0, aZ), objectId); + map.put(CoordinatePacker.pack(aX, 1, aZ), (short) lower); + map.put(CoordinatePacker.pack(aX, 2, aZ), (short) upper); + } + + public int getAmount(int absChunkX, int absChunkZ) { + int lower = Short.toUnsignedInt(map.get(CoordinatePacker.pack(absChunkX, 1, absChunkZ))); + int upper = Short.toUnsignedInt(map.get(CoordinatePacker.pack(absChunkX, 2, absChunkZ))); + + return (upper << 16) | lower; + } + + public void addPollution(int cX, int cZ, int amount) { + int aX = cX - (chunkX - size); + int aZ = cZ - (chunkZ - size); + + int lower = amount & 0xFFFF; + int upper = (amount >> 16) & 0xFFFF; + + map.put(CoordinatePacker.pack(aX, 1, aZ), (short) lower); + map.put(CoordinatePacker.pack(aX, 2, aZ), (short) upper); } public int getSize() { diff --git a/src/main/java/detrav/utils/BartWorksHelper.java b/src/main/java/detrav/utils/BartWorksHelper.java deleted file mode 100644 index 1bbadc71c71..00000000000 --- a/src/main/java/detrav/utils/BartWorksHelper.java +++ /dev/null @@ -1,23 +0,0 @@ -package detrav.utils; - -import net.minecraft.block.Block; -import net.minecraft.world.chunk.Chunk; - -import bartworks.system.material.BWMetaGeneratedOres; -import bartworks.system.material.BWMetaGeneratedSmallOres; - -public class BartWorksHelper { - - public static boolean isOre(Block tBlock) { - return tBlock instanceof BWMetaGeneratedOres; - } - - public static boolean isSmallOre(Block tBlock) { - return tBlock instanceof BWMetaGeneratedSmallOres; - } - - 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/galacticgreg/GalacticGreg.java b/src/main/java/galacticgreg/GalacticGreg.java index 03cb4d15697..42e088d3310 100644 --- a/src/main/java/galacticgreg/GalacticGreg.java +++ b/src/main/java/galacticgreg/GalacticGreg.java @@ -16,6 +16,7 @@ import galacticgreg.auxiliary.ProfilingStorage; import galacticgreg.command.AEStorageCommand; import galacticgreg.command.ProfilingCommand; +import galacticgreg.command.WorldgenCommand; import galacticgreg.registry.GalacticGregRegistry; import galacticgreg.schematics.SpaceSchematicHandler; import gregtech.GT_Version; @@ -108,6 +109,8 @@ public void serverLoad(FMLServerStartingEvent pEvent) { if (AppliedEnergistics2.isModLoaded() && GalacticConfig.EnableAEExportCommand && GalacticConfig.SchematicsEnabled) pEvent.registerServerCommand(new AEStorageCommand()); + pEvent.registerServerCommand(new WorldgenCommand()); + Logger.trace("Leaving SERVERLOAD"); } } diff --git a/src/main/java/galacticgreg/SpaceDimRegisterer.java b/src/main/java/galacticgreg/SpaceDimRegisterer.java index 611477f7df2..e280624f549 100644 --- a/src/main/java/galacticgreg/SpaceDimRegisterer.java +++ b/src/main/java/galacticgreg/SpaceDimRegisterer.java @@ -2,14 +2,15 @@ import net.minecraft.init.Blocks; -import galacticgreg.api.AsteroidBlockComb; +import cpw.mods.fml.common.registry.GameRegistry; import galacticgreg.api.Enums; -import galacticgreg.api.GTOreTypes; import galacticgreg.api.ModContainer; import galacticgreg.api.SpecialBlockComb; import galacticgreg.api.enums.DimensionDef; import galacticgreg.api.enums.ModContainers; import galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.enums.Mods; +import gregtech.api.enums.StoneType; /** * In this class, you'll find everything you need in order to tell GGreg what to do and where. Everything is done in @@ -34,15 +35,17 @@ private static ModContainer setupVanilla() { // If you happen to have an asteroid dim, just skip the blocklist, and setDimensionType() to // DimensionType.Asteroid // also don't forget to add at least one asteroid type, or nothing will generate! - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.Netherrack)); - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.EndStone)); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(StoneType.Endstone); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(StoneType.Marble); // These Blocks will randomly be generated DimensionDef.EndAsteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.glowstone)); - DimensionDef.EndAsteroids.modDimensionDef - .addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.lava, Enums.AllowedBlockPosition.AsteroidCore)); + if (Mods.HardcoreEnderExpansion.isModLoaded()) { + DimensionDef.EndAsteroids.modDimensionDef.addSpecialAsteroidBlock( + new SpecialBlockComb( + GameRegistry.findBlock(Mods.HardcoreEnderExpansion.ID, "ender_goo"), + Enums.AllowedBlockPosition.AsteroidCore)); + } ModContainers.Vanilla.modContainer.addDimensionDef(DimensionDef.EndAsteroids.modDimensionDef); @@ -61,13 +64,13 @@ private static ModContainer setupGalactiCraftCore() { * As GalactiCraftPlanets is an optional mod, don't hardlink it here */ private static ModContainer setupGalactiCraftPlanets() { - // Overwrite ore blocks on mars with red granite ones. This will default to regular stone if not set - DimensionDef.Mars.modDimensionDef.setStoneType(GTOreTypes.RedGranite); ModContainers.GalacticraftMars.modContainer.addDimensionDef(DimensionDef.Mars.modDimensionDef); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.Netherrack)); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(StoneType.Moon); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(StoneType.Asteroid); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(StoneType.PackedIce); + ModContainers.GalacticraftMars.modContainer.addDimensionDef(DimensionDef.Asteroids.modDimensionDef); return ModContainers.GalacticraftMars.modContainer; @@ -117,10 +120,16 @@ private static ModContainer setupGalaxySpace() { ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.BarnardF.modDimensionDef); ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.TcetiE.modDimensionDef); ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Miranda.modDimensionDef); + DimensionDef.KuiperBelt.modDimensionDef.setDimensionType(Enums.DimensionType.Asteroid); - DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); - DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(StoneType.RedGranite); + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); + // added twice to double its weight + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(StoneType.PackedIce); + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(StoneType.PackedIce); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.KuiperBelt.modDimensionDef); + return ModContainers.GalaxySpace.modContainer; } @@ -133,8 +142,12 @@ private static ModContainer setupAmunRa() { ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Anubis.modDimensionDef); ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Horus.modDimensionDef); ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Seth.modDimensionDef); - DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(GTOreTypes.BlackGranite); + + DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); + DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(StoneType.Horus); + DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(StoneType.Asteroid); ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.MehenBelt.modDimensionDef); + return ModContainers.AmunRa.modContainer; } } diff --git a/src/main/java/galacticgreg/TileEntitySpaceOres.java b/src/main/java/galacticgreg/TileEntitySpaceOres.java deleted file mode 100644 index 00ad3ba51fb..00000000000 --- a/src/main/java/galacticgreg/TileEntitySpaceOres.java +++ /dev/null @@ -1,144 +0,0 @@ -package galacticgreg; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -import galacticgreg.api.Enums; -import galacticgreg.api.ModDimensionDef; -import gregtech.api.GregTechAPI; -import gregtech.api.util.GTLog; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; - -public class TileEntitySpaceOres { - - // 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 Enums.ReplaceState CheckForReplaceableBlock(World pWorld, int pX, int pY, int pZ, - ModDimensionDef pDimDef) { - try { - Enums.ReplaceState tFlag = Enums.ReplaceState.Unknown; - - Block targetBlock = pWorld.getBlock(pX, pY, pZ); - int targetBlockMeta = pWorld.getBlockMetadata(pX, pY, pZ); - - if (targetBlock == Blocks.air) tFlag = Enums.ReplaceState.Airblock; - else tFlag = pDimDef.getReplaceStateForBlock(targetBlock, targetBlockMeta); - - return tFlag; - } catch (Exception e) { - e.printStackTrace(GTLog.err); - GalacticGreg.Logger.error("Error while processing CheckForReplaceableBlock(), defaulting to UNKNOWN"); - return Enums.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) { - Enums.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 == Enums.ReplaceState.Unknown) { - GalacticGreg.Logger.trace("Not placing ore Meta %d, as target block is unknown", pMetaData); - return false; - } else if (tRS == Enums.ReplaceState.Airblock && !pAir) { - GalacticGreg.Logger.trace("Not placing ore Meta %d in midair, as AIR is FALSE", pMetaData); - return false; - } - if (tRS == Enums.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, - GregTechAPI.sBlockOres1, - TileEntityOres.getHarvestData( - (short) pMetaData, - ((BlockOresAbstract) GregTechAPI.sBlockOres1) - .getBaseBlockHarvestLevel(pMetaData % 16000 / 1000)), - 0); - TileEntity tTileEntity = pWorld.getTileEntity(pX, pY, pZ); - if ((tTileEntity instanceof TileEntityOres)) { - ((TileEntityOres) tTileEntity).mMetaData = ((short) pMetaData); - ((TileEntityOres) 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; - } -} diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 4f760494805..32053caf8a1 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -1,564 +1,503 @@ package galacticgreg; +import static gregtech.api.enums.GTValues.profileWorldGen; + +import java.util.ArrayList; +import java.util.List; import java.util.Random; -import net.minecraft.block.Block; import net.minecraft.inventory.IInventory; -import net.minecraft.util.Vec3; import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; import net.minecraftforge.common.ChestGenHooks; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; import cpw.mods.fml.common.IWorldGenerator; -import cpw.mods.fml.common.eventhandler.EventBus; import cpw.mods.fml.common.registry.GameRegistry; -import galacticgreg.api.AsteroidBlockComb; -import galacticgreg.api.BlockMetaComb; import galacticgreg.api.Enums; -import galacticgreg.api.GTOreTypes; -import galacticgreg.api.ISpaceObjectGenerator; +import galacticgreg.api.Enums.TargetBlockPosition; import galacticgreg.api.ModDimensionDef; import galacticgreg.api.SpecialBlockComb; -import galacticgreg.api.StructureInformation; -import galacticgreg.auxiliary.GTOreGroup; +import galacticgreg.api.enums.DimensionDef; import galacticgreg.dynconfig.DynamicDimensionConfig; -import galacticgreg.registry.GalacticGregRegistry; -import gregtech.api.util.GTLog; -import gregtech.api.world.GTWorldgen; -import gregtech.common.GTWorldgenerator; +import galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; +import gregtech.GTMod; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneType; +import gregtech.api.objects.MurmurHash; +import gregtech.api.objects.XSTR; +import gregtech.common.ores.OreManager; +import gregtech.common.worldgen.IWorldgenLayer; +import gregtech.common.worldgen.WorldgenQuery; public class WorldGeneratorSpace implements IWorldGenerator { - public static boolean sAsteroids = true; - private final EventBus eventBus = new EventBus(); - private World worldObj; - - private int chunkX; - private int chunkZ; - private final int mSize = 100; - - private long mProfilingStart; - private long mProfilingEnd; - public WorldGeneratorSpace() { GameRegistry.registerWorldGenerator(this, Integer.MAX_VALUE); } - public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvider pChunkGenerator, - IChunkProvider pChunkProvider) { - pX *= 16; - pZ *= 16; + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, + IChunkProvider chunkProvider) { - String tBiome = pWorld.getBiomeGenForCoords(pX + 8, pZ + 8).biomeName; - pRandom = new Random(pRandom.nextInt()); - if (tBiome == null) { - tBiome = BiomeGenBase.plains.biomeName; - } - GalacticGreg.Logger - .trace("Triggered generate: [ChunkGenerator %s] [Biome %s]", pChunkGenerator.toString(), tBiome); + GalacticGreg.Logger.trace("Triggered generate: [Dimension %s]", world.provider.getDimensionName()); - ModDimensionDef tDimDef = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); + ModDimensionDef tDimDef = DimensionDef.getDefForWorld(world, chunkX, chunkZ); if (tDimDef == null) { GalacticGreg.Logger.trace( - "Ignoring ChunkGenerator type %s as there is no definition for it in the registry", - pChunkGenerator.toString()); + "Ignoring dimension %s as there is no definition for it in the registry", + world.provider.getDimensionName()); return; } else { GalacticGreg.Logger.trace("Selected DimDef: [%s]", tDimDef.getDimIdentifier()); } - /* - * In some later addons maybe, not for now. Ignoring Biome-based worldgen String tBiome = - * pWorld.getBiomeGenForCoords(pX + 8, pZ + 8).biomeName; pRandom = new Random(pRandom.nextInt()); if (tBiome == - * null) { tBiome = BiomeGenBase.plains.biomeName; } - */ - - if (tDimDef.getDimensionType() != Enums.DimensionType.Planet) { - if (tDimDef.getRandomAsteroidMaterial() == null) GalacticGreg.Logger.error( - "Dimension [%s] is set to Asteroids, but no asteroid material is specified! Nothing will generate", - tDimDef.getDimensionName()); - else Generate_Asteroids(tDimDef, pRandom, pWorld, pX, pZ); - } else if (tDimDef.getDimensionType() != Enums.DimensionType.Asteroid) { - Generate_OreVeins(tDimDef, pRandom, pWorld, pX, pZ, "", pChunkGenerator, pChunkProvider); - } + if (tDimDef.getDimensionType() == Enums.DimensionType.Asteroid) { + long pre = profileWorldGen ? System.nanoTime() : 0; + + int seeds = 0; + + for (int offsetZ = -2; offsetZ <= 2; offsetZ++) { + for (int offsetX = -2; offsetX <= 2; offsetX++) { + AsteroidGenerator gen = AsteroidGenerator.forChunk(world, chunkX + offsetX, chunkZ + offsetZ); + + if (gen == null) continue; + + if (!gen.affectsChunk(chunkX, chunkZ)) continue; + + gen.generateChunk(world, chunkX, chunkZ); + + seeds++; + } + } + + long post = profileWorldGen ? System.nanoTime() : 0; + + if (profileWorldGen) { + GTMod.GT_FML_LOGGER.info( + String.format( + "Generated %d %d in %,d us (%d seeds)", + chunkX, + chunkZ, + (int) ((post - pre) / 1e3), + seeds)); + } - Chunk tChunk = pWorld.getChunkFromBlockCoords(pX, pZ); - if (tChunk != null) { - tChunk.isModified = true; + Chunk tChunk = world.getChunkFromBlockCoords(chunkX, chunkZ); + if (tChunk != null) { + tChunk.isModified = seeds > 0; + } } } - private void Generate_Asteroids(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ) { - GalacticGreg.Logger.trace("Running asteroid-gen in Dim %s", pDimensionDef.getDimIdentifier()); + public static class AsteroidGenerator { - DynamicDimensionConfig.AsteroidConfig tAConf = DynamicDimensionConfig.getAsteroidConfig(pDimensionDef); - if (tAConf == null) { - GalacticGreg.Logger.error( - "Dimension %s is set to asteroid, but no config object can be found. Skipping!", - pDimensionDef.getDimIdentifier()); - return; - } else { - GalacticGreg.Logger.trace("Asteroid probability: %d", tAConf.Probability); - } + private List positive, negative; + private int seedChunkX, seedChunkZ, cX, cY, cZ, radius, size; - if ((tAConf.Probability <= 1) || (pRandom.nextInt(tAConf.Probability) == 0)) { - GalacticGreg.Logger.trace("Generating asteroid NOW"); - // --------------------------- - if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); - // ----------------------------- - - // Get Random position - int tX = pX + pRandom.nextInt(16); - int tY = 50 + pRandom.nextInt(200 - 50); - int tZ = pZ + pRandom.nextInt(16); - - // Check if position is free - if ((pWorld.getBlock(tX, tY, tZ) - .isAir(pWorld, tX, tY, tZ))) { - - int tCustomAsteroidOffset = -1; - int tGraniteMeta = 0; - - // Select Random OreGroup and Asteroid Material - GTOreGroup tOreGroup = WorldgenOreLayerSpace.getRandomOreGroup(pDimensionDef, pRandom, true); - AsteroidBlockComb tABComb = pDimensionDef.getRandomAsteroidMaterial(); - if (tABComb == null) return; - - // Fill Vars for random Asteroid - Block tFinalAsteroidBlock = tABComb.getBlock(); - int tFinalAsteroidBlockMeta = tABComb.getMeta(); - int tFinalOreOffset = tABComb.getOreMaterial() - .getOffset(); - int tFinalUpdateMode = tABComb.getOreMaterial() - .getUpdateMode(); - GalacticGreg.Logger.debug( - "Asteroid will be build with: Block: [%s] OreType: [%s]", - Block.blockRegistry.getNameForObject(tABComb.getBlock()), - tABComb.getOreMaterial() - .toString()); - - // get random Ore-asteroid generator from the list of registered generators - ISpaceObjectGenerator aGen = pDimensionDef.getRandomSOGenerator(Enums.SpaceObjectType.OreAsteroid); - if (aGen == null) { - GalacticGreg.Logger.ot_error( - "GalacticGreg.Generate_Asteroids.NoSOGenFound", - "No SpaceObjectGenerator has been registered for type ORE_ASTEROID in Dimension %s. Nothing will generate", - pDimensionDef.getDimensionName()); - return; + private IStoneType stoneType; + private transient IWorldgenLayer ore; + + public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedChunkZ) { + ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world, seedChunkX, seedChunkZ); + AsteroidConfig asteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); + + if (asteroidConfig == null || !asteroidConfig.Enabled) return null; + + if (!generatesAsteroid( + world.getSeed(), + seedChunkX, + seedChunkZ, + world.provider.dimensionId, + asteroidConfig.Probability)) return null; + + XSTR rng = getRandom(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId); + + IStoneType asteroidStone = dimensionDef.getRandomAsteroidMaterial(rng.clone()); + if (asteroidStone == null) return null; + + IWorldgenLayer oreLayer; + + if (rng.nextInt(5) == 0) { + oreLayer = WorldgenQuery.small() + .inDimension(dimensionDef) + .inStone(asteroidStone.getCategory()) + .find(rng.clone()); + } else { + oreLayer = WorldgenQuery.veins() + .inDimension(dimensionDef) + .inStone(asteroidStone.getCategory()) + .find(rng.clone()); + } + + if (oreLayer == null) return null; + + GalacticGreg.Logger.debug( + "Asteroid will be built with: Stone: [%s] Ore: [%s]", + asteroidStone.getStone(), + oreLayer.getName()); + + int tX = seedChunkX * 16 + rng.nextInt(16); + int tY = asteroidConfig.AsteroidMinY + + rng.nextInt(asteroidConfig.AsteroidMaxY - asteroidConfig.AsteroidMinY); + int tZ = seedChunkZ * 16 + rng.nextInt(16); + + List positive = new ArrayList<>(); + List negative = new ArrayList<>(); + + int radius = asteroidConfig.MinSize + rng.nextInt(asteroidConfig.MinSize - asteroidConfig.MaxSize + 1); + positive.add(new Ellipsoid(0, 0, 0, radius)); + + if (asteroidConfig.PositiveEllipsoids > 0) { + int k = rng.nextInt(2); + for (int i = 0; i < k; i++) { + negative.add( + new Ellipsoid( + radius * (rng.nextFloat() * 2 - 1), + radius * (rng.nextFloat() * 2 - 1), + radius * (rng.nextFloat() * 2 - 1), + radius * (rng.nextFloat() * 0.25f + 0.6f))); } + } - aGen.reset(); - aGen.setCenterPoint(tX, tY, tZ); - aGen.randomize(tAConf.MinSize, tAConf.MaxSize); // Initialize random values and set size - aGen.calculate(); // Calculate structure - - // Random loot-chest somewhere in the asteroid - Vec3 tChestPosition = Vec3.createVectorHelper(0, 0, 0); - boolean tDoLootChest = false; - int tNumLootItems = 0; - if (tAConf.LootChestChance > 0) { - GalacticGreg.Logger.trace("Random loot chest enabled, flipping the coin"); - int tChance = pRandom.nextInt(100); // Loot chest is 1 in 100 (Was: 1:1000 which actually never - // happend) - if (tAConf.LootChestChance >= tChance) { - GalacticGreg.Logger.debug("We got a match. Preparing to generate the loot chest"); - // Get amount of items for the loot chests, randomize it (1-num) if enabled - if (tAConf.RandomizeNumLootItems) tNumLootItems = pRandom.nextInt(tAConf.NumLootItems - 1) + 1; - else tNumLootItems = tAConf.NumLootItems; - - GalacticGreg.Logger - .debug(String.format("Loot chest random item count will be: %d", tNumLootItems)); - - // try to find any block that is not on the asteroids outer-shell - GalacticGreg.Logger.trace("Starting lookup for valid asteroid-block for the chest"); - for (int x = 0; x < 64; x++) // 64 enough? Should be - { - int tRndBlock = pRandom.nextInt( - aGen.getStructure() - .size()); - StructureInformation tChestSI = aGen.getStructure() - .get(tRndBlock); - if (tChestSI.getBlockPosition() != Enums.TargetBlockPosition.AsteroidShell) { - GalacticGreg.Logger.debug( - String.format( - "Chest position found [x:%d y:%d z:%d]", - tChestSI.getX(), - tChestSI.getY(), - tChestSI.getZ())); - // Found valid position "Somewhere" in the asteroid, set position... - tChestPosition = Vec3 - .createVectorHelper(tChestSI.getX(), tChestSI.getY(), tChestSI.getZ()); - // .. and set CreateFlag to true - tDoLootChest = true; - break; - } - } - } + if (asteroidConfig.NegativeEllipsoids > 0 && rng.nextInt(4) == 0) { + int k = rng.nextInt(asteroidConfig.NegativeEllipsoids); + for (int i = 0; i < k; i++) { + positive.add( + new Ellipsoid( + radius * (rng.nextFloat() * 2 - 1), + radius * (rng.nextFloat() * 2 - 1), + radius * (rng.nextFloat() * 2 - 1), + radius * (rng.nextFloat() * 0.25f + 0.6f))); } + } - // Now build the structure - GalacticGreg.Logger.trace("Now generating Space-Structure"); - for (StructureInformation si : aGen.getStructure()) { - // Only replace airblocks - if (pWorld.isAirBlock(si.getX(), si.getY(), si.getZ())) { - // === Loot-chest generator >> - if (tDoLootChest) // If gen-lootchest enabled... - { - // Check if current x/y/z is the location where the chest shall be created - if ((int) tChestPosition.xCoord == si.getX() && (int) tChestPosition.yCoord == si.getY() - && (int) tChestPosition.zCoord == si.getZ()) { - GalacticGreg.Logger.trace("Now generating LootChest and contents"); - // Get items for the configured loot-table - WeightedRandomChestContent[] tRandomLoot = ChestGenHooks - .getItems(DynamicDimensionConfig.getLootChestTable(tAConf), pRandom); - - // Get chest-block to spawn - BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; - - // Place down the chest - if (tTargetChestType.getMeta() > 0) pWorld.setBlock( - si.getX(), - si.getY(), - si.getZ(), - tTargetChestType.getBlock(), - tTargetChestType.getMeta(), - 2); - else pWorld.setBlock(si.getX(), si.getY(), si.getZ(), tTargetChestType.getBlock()); - - // Retrieve the TEs IInventory that should've been created - IInventory entityChestInventory = (IInventory) pWorld - .getTileEntity(si.getX(), si.getY(), si.getZ()); - // If it's not null... - if (entityChestInventory != null) { - // and if we're on the server... - if (!pWorld.isRemote) { - // Fill the chest with stuffz! - WeightedRandomChestContent.generateChestContents( - pRandom, - tRandomLoot, - entityChestInventory, - tNumLootItems); - GalacticGreg.Logger.trace("Loot chest successfully generated"); - } - } else { - // Something made a boo.. - GalacticGreg.Logger.warn( - "Could not create lootchest at X[%d] Y[%d] Z[%d]. getTileEntity() returned null", - si.getX(), - si.getY(), - si.getZ()); - } - // Make sure we never compare coordinates again (for this asteroid/Structure) - tDoLootChest = false; - // Do some debug logging - GalacticGreg.Logger - .debug("Generated LootChest at X[%d] Y[%d] Z[%d]", si.getX(), si.getY(), si.getZ()); - // And skip the rest of this function - continue; - } + AsteroidGenerator gen = new AsteroidGenerator(); + + gen.positive = positive; + gen.negative = negative; + + gen.seedChunkX = seedChunkX; + gen.seedChunkZ = seedChunkZ; + + gen.cX = tX; + gen.cY = tY; + gen.cZ = tZ; + gen.radius = radius; + gen.size = radius * 2; + + gen.stoneType = asteroidStone; + gen.ore = oreLayer; + + return gen; + } + + public boolean affectsChunk(int chunkX, int chunkZ) { + int minX = (cX - size) >> 4; + int maxX = (cX + size + 1) >> 4; + + int minZ = (cZ - size) >> 4; + int maxZ = (cZ + size + 1) >> 4; + + return minX <= chunkX && chunkX <= maxX || minZ <= chunkZ && chunkZ <= maxZ; + } + + public void generateChunk(World world, int chunkX, int chunkZ) { + int minX = Math.max(chunkX * 16, cX - size - 1); + int maxX = Math.min((chunkX + 1) * 16, cX + size + 1); + + int minY = Math.max(0, cY - size - 1); + int maxY = Math.min(255, cY + size + 1); + + int minZ = Math.max(chunkZ * 16, cZ - size - 1); + int maxZ = Math.min((chunkZ + 1) * 16, cZ + size + 1); + + ModDimensionDef def = DimensionDef.getDefForWorld(world, seedChunkX, seedChunkZ); + AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(def); + + MurmurHash hasher = new MurmurHash(); + + for (int y = minY; y < maxY; y++) { + for (int z = minZ; z < maxZ; z++) { + outer: for (int x = minX; x < maxX; x++) { + + if (!world.isAirBlock(x, y, z)) { + continue; } - // << Loot-chest generator === - - // === Ore generator >> - boolean tPlacedOreBlock = false; - // If a valid oregroup has been selected (more than 0 ore-veins are enabled for this dim) - if (tOreGroup != null) { - // GalacticGreg.Logger.trace("tOreGoup is populated, continuing"); - // Choose a number between 0 and 100 - int ranOre = pRandom.nextInt(100); - int tFinalOreMeta = 0; - - // If choosen number is below the configured orechance, do random between and sporadic - if (ranOre < tAConf.OreChance) { - if (pRandom.nextBoolean()) { - // Only take as final value if meta is not zero - if (tOreGroup.SporadicBetweenMeta > 0) - tFinalOreMeta = tOreGroup.SporadicBetweenMeta; - } else { - // Only take as final value if meta is not zero - if (tOreGroup.SporadicAroundMeta > 0) tFinalOreMeta = tOreGroup.SporadicAroundMeta; - } - } - // If choosen number is below the configured orechance, do random primary and secondary - // We use an offset here, so this part is always higher than the first check. - else if (ranOre < tAConf.OreChance + tAConf.OrePrimaryOffset) { - if (pRandom.nextBoolean()) { - // Only take as final value if meta is not zero - if (tOreGroup.PrimaryMeta > 0) tFinalOreMeta = tOreGroup.PrimaryMeta; - } else { - // Only take as final value if meta is not zero - if (tOreGroup.SecondaryMeta > 0) tFinalOreMeta = tOreGroup.SecondaryMeta; - } + + hasher.reset(); + + hasher.feed(world.getSeed()); + hasher.feed(world.provider.dimensionId); + hasher.feed(x); + hasher.feed(y); + hasher.feed(z); + + XSTR rng2 = new XSTR(hasher.finish()); + + for (Ellipsoid e : negative) { + if (e.dist2(rng2, x - cX + 0.5f, y - cY + 0.5f, z - cZ + 0.5f) <= 1) { + continue outer; } + } + + float dist = 2f; - // if the final oreMeta has been found... - // GalacticGreg.Logger.info("tFinalOreMeta is %d", tFinalOreMeta); - if (tFinalOreMeta > 0) { - // make sure we obey the configured "HiddenOres" setting (No ores on the shell) - if (tAConf.HiddenOres - && (si.getBlockPosition() == Enums.TargetBlockPosition.AsteroidShell)) { - // Ore would be placed around the shell, which is disabled (hiddenores) - GalacticGreg.Logger.trace( - "Skipping ore-placement event (HiddenOres=true; TargetBlockPosition=AsteroidShell)"); - } else { - // try to place the ore block. The result is stored in tPlacedOreBlock - tPlacedOreBlock = TileEntitySpaceOres.setOuterSpaceOreBlock( - pDimensionDef, - pWorld, - si.getX(), - si.getY(), - si.getZ(), - tOreGroup.SecondaryMeta, - true, - tFinalOreOffset); - } + for (Ellipsoid e : positive) { + dist = Math.min(dist, e.dist2(rng2, x - cX + 0.5f, y - cY + 0.5f, z - cZ + 0.5f)); + } + + if (dist >= 1) continue; + + boolean placedAnything = false; + + // try to place big ores, if the ore vein creates big ore + if (ore.generatesBigOre()) { + if (!placedAnything) { + placedAnything = generateOreBlock( + dimAsteroidConfig, + rng2, + world, + x, + y, + z, + stoneType, + ore, + radius < 5 ? rng2.nextFloat() : dist, + dist); } } - // << Ore generator === - - // === Additional special blocks >> - // If no ore-block has been placed yet... - if (!tPlacedOreBlock) { - // try to spawn special blocks - boolean tFlag = doGenerateSpecialBlocks( - pDimensionDef, - pRandom, - pWorld, - tAConf, - si.getX(), - si.getY(), - si.getZ(), - si.getBlockPosition()); - - // No special block placed? Try smallores - if (tFlag) tFlag = doGenerateSmallOreBlock( - pDimensionDef, - pRandom, - pWorld, - tAConf, - si.getX(), - si.getY(), - si.getZ(), - tFinalOreOffset); - - // no smallores either? do normal block - if (tFlag) pWorld.setBlock( - si.getX(), - si.getY(), - si.getZ(), - tFinalAsteroidBlock, - tFinalAsteroidBlockMeta, - tFinalUpdateMode); + // try to place any special blocks + if (!placedAnything) { + placedAnything = generateSpecialBlocks( + def, + rng2, + world, + dimAsteroidConfig, + x, + y, + z, + dist < 1f / 3f ? TargetBlockPosition.AsteroidInnerCore + : dist < 2f / 3f ? TargetBlockPosition.AsteroidCore + : TargetBlockPosition.AsteroidShell); + } + + // try to place small ores + if (!placedAnything) { + placedAnything = generateSmallOreBlock( + dimAsteroidConfig, + rng2, + world, + x, + y, + z, + stoneType, + ore, + rng2.nextFloat()); + } + + // no smallores either? do normal block + if (!placedAnything) { + world.setBlock( + x, + y, + z, + stoneType.getStone() + .getBlock(), + stoneType.getStone() + .getBlockMeta(), + 2); } - // << Additional special blocks === } } } - // --------------------------- - // OreGen profiler stuff - if (GalacticGreg.GalacticConfig.ProfileOreGen) { - try { - mProfilingEnd = System.currentTimeMillis(); - long tTotalTime = mProfilingEnd - mProfilingStart; - GalacticGreg.Profiler.AddTimeToList(pDimensionDef, tTotalTime); - GalacticGreg.Logger.debug( - "Done with Asteroid-Worldgen in DimensionType %s. Generation took %d ms", - pDimensionDef.getDimensionName(), - tTotalTime); - } catch (Exception ignored) {} // Silently ignore errors + + if (chunkX == seedChunkX && chunkZ == seedChunkZ) { + generateLootChest(world, dimAsteroidConfig); + } + + for (int z = minZ; z < maxZ; z++) { + for (int x = minX; x < maxX; x++) { + world.markBlocksDirtyVertical(x, z, minY, maxY); + } + } + } + + private void generateLootChest(World world, AsteroidConfig asteroidConfig) { + XSTR rng = getRandom(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId); + + if (asteroidConfig.LootChestChance == 0 || size < 6) return; + + GalacticGreg.Logger.trace("Random loot chest enabled, flipping the coin"); + + // Loot chest is 1 in 100 (Was: 1:1000 which actually never happened) + if (asteroidConfig.LootChestChance < rng.nextInt(100)) return; + + GalacticGreg.Logger.debug("We got a match. Preparing to generate the loot chest"); + + int x = cX, y = cY, z = cZ; + + // Move it one away from the chunk border to prevent cascading + if (x % 16 == 0) x++; + if (x % 16 == 15) x--; + + if (y % 16 == 0) y++; + if (y % 16 == 15) y--; + + if (z % 16 == 0) z++; + if (z % 16 == 15) z--; + + // Make sure it's hidden + for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) { + if (world.isAirBlock(x + d.offsetX, y + d.offsetY, z + d.offsetZ)) { + return; + } + } + + GalacticGreg.Logger.trace("Now generating LootChest and contents"); + + // Get amount of items for the loot chests, randomize it (1-num) if enabled + int tNumLootItems; + if (asteroidConfig.RandomizeNumLootItems) { + tNumLootItems = rng.nextInt(asteroidConfig.NumLootItems - 1) + 1; + } else { + tNumLootItems = asteroidConfig.NumLootItems; + } + + GalacticGreg.Logger.debug(String.format("Loot chest random item count will be: %d", tNumLootItems)); + + // Get items for the configured loot-table + WeightedRandomChestContent[] tRandomLoot = ChestGenHooks + .getItems(DynamicDimensionConfig.getLootChestTable(asteroidConfig), rng); + + // Get chest-block to spawn + ImmutableBlockMeta tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; + + // Place down the chest + world.setBlock(cX, cY, cZ, tTargetChestType.getBlock(), tTargetChestType.getBlockMeta(), 2); + + // Retrieve the TEs IInventory that should've been created + IInventory entityChestInventory = (IInventory) world.getTileEntity(cX, cY, cZ); + + // If it's not null... + if (entityChestInventory != null) { + // and if we're on the server... + if (!world.isRemote) { + // Fill the chest with stuffz! + WeightedRandomChestContent + .generateChestContents(rng, tRandomLoot, entityChestInventory, tNumLootItems); + GalacticGreg.Logger.trace("Loot chest successfully generated"); + } + } else { + // Something made a boo.. + GalacticGreg.Logger + .warn("Could not create lootchest at X[%d] Y[%d] Z[%d]. getTileEntity() returned null", cX, cY, cZ); } - // --------------------------- + + // Do some debug logging + GalacticGreg.Logger.debug("Generated LootChest at X[%d] Y[%d] Z[%d]", cX, cY, cZ); } - GalacticGreg.Logger.trace("Leaving asteroid-gen for Dim %s", pDimensionDef.getDimIdentifier()); + } + + /** A random number which gets added to the XSTR because I felt like it */ + private static final long OFFSET = 588283; + + private static XSTR getRandom(long worldSeed, int chunkX, int chunkZ, int dimId) { + return new XSTR(chunkX * 341873128712L + chunkZ * 132897987541L + dimId + OFFSET + worldSeed); + } + + public static boolean generatesAsteroid(long worldSeed, int chunkX, int chunkZ, int dimId, int asteroidChance) { + return getRandom(worldSeed, chunkX, chunkZ, dimId).nextInt(100) <= asteroidChance; } /** * Generate Special Blocks in asteroids if enabled - * - * @param pDimensionDef - * @param pRandom - * @param pWorld - * @param tAConf - * @param eX - * @param eY - * @param eZ - * @return */ - private boolean doGenerateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, - DynamicDimensionConfig.AsteroidConfig tAConf, int eX, int eY, int eZ, - Enums.TargetBlockPosition pBlockPosition) { - - boolean tFlag = true; + private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Random rng, World world, + AsteroidConfig asteroidConfig, int x, int y, int z, TargetBlockPosition blockPosition) { // Handler to generate special BlockTypes randomly if activated - if (tAConf.SpecialBlockChance > 0) { - if (pRandom.nextInt(100) < tAConf.SpecialBlockChance) { - SpecialBlockComb bmc = pDimensionDef.getRandomSpecialAsteroidBlock(); - if (bmc != null) { - boolean tIsAllowed = false; - - switch (bmc.getBlockPosition()) { - case AsteroidCore: - if (pBlockPosition == Enums.TargetBlockPosition.AsteroidCore) tIsAllowed = true; - break; - case AsteroidCoreAndShell: - if (pBlockPosition == Enums.TargetBlockPosition.AsteroidCore - || pBlockPosition == Enums.TargetBlockPosition.AsteroidShell) tIsAllowed = true; - break; - case AsteroidShell: - if (pBlockPosition == Enums.TargetBlockPosition.AsteroidShell) tIsAllowed = true; - break; - case AsteroidInnerCore: - if (pBlockPosition == Enums.TargetBlockPosition.AsteroidInnerCore) tIsAllowed = true; - break; - default: - break; - } + if (asteroidConfig.SpecialBlockChance > 0) { + if (rng.nextInt(100) < asteroidConfig.SpecialBlockChance) { + SpecialBlockComb bmc = dimensionDef.getRandomSpecialAsteroidBlock(rng); - if (tIsAllowed) { - pWorld.setBlock(eX, eY, eZ, bmc.getBlock(), bmc.getMeta(), 2); - tFlag = false; + if (bmc != null) { + boolean validLocation = switch (bmc.getBlockPosition()) { + case AsteroidCore -> blockPosition == Enums.TargetBlockPosition.AsteroidCore; + case AsteroidCoreAndShell -> blockPosition == Enums.TargetBlockPosition.AsteroidCore + || blockPosition == Enums.TargetBlockPosition.AsteroidShell; + case AsteroidShell -> blockPosition == Enums.TargetBlockPosition.AsteroidShell; + case AsteroidInnerCore -> blockPosition == Enums.TargetBlockPosition.AsteroidInnerCore; + }; + + if (validLocation) { + world.setBlock(x, y, z, bmc.getBlock(), bmc.getBlockMeta(), 3); + return true; } } } } - return tFlag; - } - /** - * Pick a random small-ore block from the list of enabled small ores for this dim - * - * @param pDimDef - * @param pRandom - * @return - */ - private boolean doGenerateSmallOreBlock(ModDimensionDef pDimDef, Random pRandom, World pWorld, - DynamicDimensionConfig.AsteroidConfig pAConf, int pX, int pY, int pZ, int pTargetBlockOffset) { - boolean tFlag = true; - // If smallores are enabled... - if (pAConf.SmallOreChance > 0) { - // ... and we hit the random-chance ... - if (pRandom.nextInt(100) < pAConf.SmallOreChance) { - // Do small ores. - int tRandomWeight; - boolean continueSearch = true; - int tFoundOreMeta = -1; - // First find a small ore... - for (int i = 0; (i < 256) && (continueSearch); i++) { - tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); - for (GTWorldgen tWorldGen : GalacticGreg.smallOreWorldgenList) { - - if (!(tWorldGen instanceof WorldgenOreSmallSpace)) { - continue; - } - // That is enabled for *this* dim... - if (!((WorldgenOreSmallSpace) tWorldGen).isEnabledForDim(pDimDef)) continue; + return false; + } - // And in the correct y-level, of ObeyLimits is true... - if (pAConf.ObeyHeightLimits && !((WorldgenOreSmallSpace) tWorldGen).isAllowedForHeight(pY)) - continue; + private static boolean generateOreBlock(AsteroidConfig asteroidConfig, Random rng, World pWorld, int pX, int pY, + int pZ, IStoneType stoneType, IWorldgenLayer oreLayer, float control, float dist) { + if (rng.nextFloat() <= oreLayer.getDensity() * asteroidConfig.OreDensityMultiplier) { + IOreMaterial mat = oreLayer.getOre(control); - // Care about weight - tRandomWeight -= ((WorldgenOreSmallSpace) tWorldGen).mAmount; - if (tRandomWeight <= 0) { - // And return found ore meta - tFoundOreMeta = ((WorldgenOreSmallSpace) tWorldGen).mMeta; - continueSearch = false; - } - } - } - if (tFoundOreMeta > -1) { - // Make the oreID a small ore with correct type - int tCustomOffset = (GTOreTypes.SmallOres.getOffset() + pTargetBlockOffset); - - // Set the smallOre block - TileEntitySpaceOres - .setOuterSpaceOreBlock(pDimDef, pWorld, pX, pY, pZ, tFoundOreMeta, true, tCustomOffset); - tFlag = false; - } + if (mat != null) { + return OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, false); } } - return tFlag; + + return false; } - /** - * Untested! But should work... Comments are todo - * - * @param pDimensionDef - * @param pRandom - * @param pWorld - * @param pX - * @param pZ - * @param pBiome - * @param pChunkGenerator - * @param pChunkProvider - */ - private void Generate_OreVeins(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ, - String pBiome, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { - GalacticGreg.Logger.trace("Running orevein-gen in Dim %s", pDimensionDef.getDimIdentifier()); - - if (GTWorldgenerator.isOreChunk(pX / 16, pZ / 16)) { - if ((WorldgenOreLayerSpace.sWeight > 0) && (!GalacticGreg.oreVeinWorldgenList.isEmpty())) { - - boolean temp = true; - int tRandomWeight; - for (int i = 0; (i < 256) && (temp); i++) { - tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); - for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) { - if (tWorldGen instanceof WorldgenOreLayerSpace) - tRandomWeight -= ((WorldgenOreLayerSpace) tWorldGen).mWeight; - - if (tRandomWeight <= 0) { - try { - if (tWorldGen.executeWorldgen( - pWorld, - pRandom, - pBiome, - Integer.MIN_VALUE, - pX, - pZ, - pChunkGenerator, - pChunkProvider)) { - temp = false; - } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - break; - } - } - } + private static boolean generateSmallOreBlock(AsteroidConfig asteroidConfig, Random rng, World pWorld, int pX, + int pY, int pZ, IStoneType stoneType, IWorldgenLayer oreLayer, float control) { + if (rng.nextInt(100) < asteroidConfig.SmallOreChance) { + IOreMaterial mat = oreLayer.getOre(control); + + if (mat != null) { + return OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, true); } - // Generate Small Ores - - int i = 0; - for (int tX = pX - 16; i < 3; tX += 16) { - int j = 0; - for (int tZ = pZ - 16; j < 3; tZ += 16) { - for (GTWorldgen tWorldGen : GalacticGreg.smallOreWorldgenList) { - try { - tWorldGen.executeWorldgen( - pWorld, - pRandom, - "", - Integer.MIN_VALUE, - tX, - tZ, - pChunkGenerator, - pChunkProvider); - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - } - j++; - } - i++; + } + + return false; + } + + private static class Ellipsoid { + + public float x, y, z, r; + + public Ellipsoid(float x, float y, float z, float size) { + this.x = x; + this.y = y; + this.z = z; + r = 1 / size; + } + + public float dist2(Random rng, float dx, float dy, float dz) { + float distX = (dx - x) * r; + float distY = (dy - y) * r; + float distZ = (dz - z) * r; + + float dist = distX * distX + distY * distY + distZ * distZ; + + if (dist > 1) return dist; + + if (dist > 0.8) { + float f = rng.nextFloat(); + dist += f * 0.4; } + + return dist; } - GalacticGreg.Logger.trace("Leaving orevein-gen for Dim %s", pDimensionDef.getDimIdentifier()); } } diff --git a/src/main/java/galacticgreg/WorldgenGaGT.java b/src/main/java/galacticgreg/WorldgenGaGT.java deleted file mode 100644 index 5814660fe75..00000000000 --- a/src/main/java/galacticgreg/WorldgenGaGT.java +++ /dev/null @@ -1,28 +0,0 @@ -package galacticgreg; - -import gregtech.api.enums.OreMixes; -import gregtech.api.enums.SmallOres; - -public class WorldgenGaGT implements Runnable { - - @Override - public void run() { - new WorldGeneratorSpace(); - - /* - * This part here enables every GT Small Ore for Space Dims. - */ - for (SmallOres ore : SmallOres.values()) { - ore.addGaGregSmallOre(); - } - - /* - * This part here enables every GT Ore for Space Dims. - */ - - for (OreMixes mix : OreMixes.values()) { - mix.addGaGregOreLayer(); - } - } - -} diff --git a/src/main/java/galacticgreg/WorldgenOreLayerSpace.java b/src/main/java/galacticgreg/WorldgenOreLayerSpace.java deleted file mode 100644 index 10591cb32d1..00000000000 --- a/src/main/java/galacticgreg/WorldgenOreLayerSpace.java +++ /dev/null @@ -1,321 +0,0 @@ -package galacticgreg; - -import static gregtech.api.enums.GTValues.oreveinPlacerOres; -import static gregtech.api.enums.GTValues.oreveinPlacerOresMultiplier; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; - -import galacticgreg.api.ModContainer; -import galacticgreg.api.ModDimensionDef; -import galacticgreg.auxiliary.GTOreGroup; -import galacticgreg.registry.GalacticGregRegistry; -import gregtech.api.util.GTLog; -import gregtech.api.world.GTWorldgen; -import gregtech.common.OreMixBuilder; - -public class WorldgenOreLayerSpace extends GTWorldgen { - - 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 final Map allowedDims; - - public WorldgenOreLayerSpace(OreMixBuilder mix) { - super(mix.oreMixName, GalacticGreg.oreVeinWorldgenList, mix.enabledByDefault); - - mMinY = (short) mix.minY; - mMaxY = (short) Math.max(this.mMinY + 5, mix.maxY); - mWeight = (short) mix.weight; - mDensity = (short) mix.density; - mSize = (short) Math.max(1, mix.size); - mPrimaryMeta = (short) mix.primary.mMetaItemSubID; - mSecondaryMeta = (short) mix.secondary.mMetaItemSubID; - mBetweenMeta = (short) mix.between.mMetaItemSubID; - mSporadicMeta = (short) mix.sporadic.mMetaItemSubID; - - allowedDims = new HashMap<>(); - - for (ModContainer mc : GalacticGregRegistry.getModContainers()) { - if (!mc.isModLoaded()) continue; - - for (ModDimensionDef mdd : mc.getDimensionList()) { - String tDimIdentifier = mdd.getDimIdentifier(); - if (allowedDims.containsKey(tDimIdentifier)) GalacticGreg.Logger.error( - "Found 2 Dimensions with the same Identifier: %s Dimension will not generate Ores", - tDimIdentifier); - else { - boolean tFlag = mix.dimsEnabled.getOrDefault(mdd.getDimensionName(), false); - allowedDims.put(tDimIdentifier, tFlag); - } - } - } - - GalacticGreg.Logger.trace("Initialized new OreLayer: %s", mix.oreMixName); - 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 allowedDims.getOrDefault(pDimensionDef.getDimIdentifier(), false); - } - - private static final Map> _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 getOreMixIDsForDim(ModDimensionDef pDimensionDef) { - List tReturn; - - if (_mBufferedVeinList.containsKey(pDimensionDef.getDimIdentifier())) - tReturn = _mBufferedVeinList.get(pDimensionDef.getDimIdentifier()); - else { - tReturn = new ArrayList<>(); - for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) if (tWorldGen instanceof WorldgenOreLayerSpace - && ((WorldgenOreLayerSpace) tWorldGen).isEnabledForDim(pDimensionDef)) - tReturn.add(tWorldGen.mWorldGenName); - - _mBufferedVeinList.put(pDimensionDef.getDimIdentifier(), tReturn); - } - - return tReturn; - } - - /** - * 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; - - if (pIgnoreWeight) { - List tEnabledVeins = getOreMixIDsForDim(pDimensionDef); - int tRnd = pRandom.nextInt(tEnabledVeins.size()); - String tVeinName = tEnabledVeins.get(tRnd); - - GTWorldgen tGen = null; - for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) - if (tWorldGen instanceof WorldgenOreLayerSpace && tWorldGen.mWorldGenName.equals(tVeinName)) - tGen = tWorldGen; - - if (tGen != null) { - // GT_Worldgen_GT_Ore_Layer_Space tGen = GalacticGreg.oreVeinWorldgenList.get(tRndMix); - GalacticGreg.Logger.trace("Using Oremix %s for asteroid", tGen.mWorldGenName); - primaryMeta = ((WorldgenOreLayerSpace) tGen).mPrimaryMeta; - secondaryMeta = ((WorldgenOreLayerSpace) tGen).mSecondaryMeta; - betweenMeta = ((WorldgenOreLayerSpace) tGen).mBetweenMeta; - sporadicMeta = ((WorldgenOreLayerSpace) tGen).mSporadicMeta; - } - } else { - if ((WorldgenOreLayerSpace.sWeight > 0) && (!GalacticGreg.oreVeinWorldgenList.isEmpty())) { - GalacticGreg.Logger.trace("About to select oremix"); - boolean temp = true; - int tRandomWeight; - for (int i = 0; (i < 256) && (temp); i++) { - tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); - for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) { - if (!(tWorldGen instanceof WorldgenOreLayerSpace)) continue; - - tRandomWeight -= ((WorldgenOreLayerSpace) tWorldGen).mWeight; - if (tRandomWeight <= 0) { - try { - if (((WorldgenOreLayerSpace) tWorldGen).isEnabledForDim(pDimensionDef)) { - GalacticGreg.Logger.trace("Using Oremix %s for asteroid", tWorldGen.mWorldGenName); - primaryMeta = ((WorldgenOreLayerSpace) tWorldGen).mPrimaryMeta; - secondaryMeta = ((WorldgenOreLayerSpace) tWorldGen).mSecondaryMeta; - betweenMeta = ((WorldgenOreLayerSpace) tWorldGen).mBetweenMeta; - sporadicMeta = ((WorldgenOreLayerSpace) tWorldGen).mSporadicMeta; - - temp = false; - break; - } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - } - } - } - } - } - if (primaryMeta != 0 || secondaryMeta != 0 || betweenMeta != 0 || sporadicMeta != 0) - return new GTOreGroup(primaryMeta, secondaryMeta, betweenMeta, sporadicMeta); - else return null; - } - - @Override - public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int pDimensionType, int pChunkX, - int pChunkZ, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { - GalacticGreg.Logger.trace("Entering executeWorldgen for [%s]", mWorldGenName); - ModDimensionDef tMDD = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); - if (tMDD == null) { - GalacticGreg.Logger - .trace("Can't find dimension definition for ChunkProvider %s, skipping", pChunkGenerator.toString()); - return false; - } - - if (!isEnabledForDim(tMDD)) { - GalacticGreg.Logger - .trace("OreGen for %s is disallowed in dimension %s, skipping", mWorldGenName, tMDD.getDimensionName()); - return false; - } - - if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); - // --------------------------- - int tMinY = this.mMinY + pRandom.nextInt(this.mMaxY - this.mMinY - 7); - - int cX = pChunkX - pRandom.nextInt(this.mSize); - int eX = pChunkX + 16 + pRandom.nextInt(this.mSize); - int cZ = pChunkZ - pRandom.nextInt(this.mSize); - int eZ = pChunkZ + 16 + pRandom.nextInt(this.mSize); - for (int tX = cX; tX <= eX; tX++) { - for (int tZ = cZ; tZ <= eZ; tZ++) { - if (this.mSecondaryMeta > 0) { - for (int i = tMinY - 1; i < tMinY + 3; i++) { - int placeX = Math.max( - 1, - Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) - / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); - int placeZ = Math.max( - 1, - Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) - / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); - if ((pRandom.nextInt(placeZ) == 0) || (pRandom.nextInt(placeX) == 0)) { - TileEntitySpaceOres.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mSecondaryMeta); - } - } - } - if (this.mBetweenMeta > 0) { - for (int i = tMinY + 2; i < tMinY + 6; i++) { - int placeX = Math.max( - 1, - Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) - / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); - int placeZ = Math.max( - 1, - Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) - / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); - if (((pRandom.nextInt(placeZ) == 0) || (pRandom.nextInt(placeX) == 0)) - && (pRandom.nextInt(2) == 0)) { - TileEntitySpaceOres.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mBetweenMeta); - } - } - - } - if (this.mPrimaryMeta > 0) { - for (int i = tMinY + 4; i < tMinY + 8; i++) { - int placeX = Math.max( - 1, - Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) - / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); - int placeZ = Math.max( - 1, - Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) - / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); - if ((pRandom.nextInt(placeZ) == 0) || (pRandom.nextInt(placeX) == 0)) { - TileEntitySpaceOres.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mPrimaryMeta); - } - } - } - if (this.mSporadicMeta > 0) { - for (int i = tMinY - 1; i < tMinY + 8; i++) { - int placeX = Math.max( - 1, - Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) - / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); - int placeZ = Math.max( - 1, - Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) - / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); - if (((pRandom.nextInt(placeX) == 0) || (pRandom.nextInt(placeZ) == 0)) - && (pRandom.nextInt(7) == 0)) { - TileEntitySpaceOres.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mSporadicMeta); - } - } - } - } - } - - if (oreveinPlacerOres) { - int nSmallOres = (cX - eX) * (cZ - eZ) * this.mDensity / 10 * oreveinPlacerOresMultiplier; - for (int nSmallOresCount = 0; nSmallOresCount < nSmallOres; nSmallOresCount++) { - int tX = pRandom.nextInt(16) + pChunkX + 2; - int tZ = pRandom.nextInt(16) + pChunkZ + 2; - int tY = pRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. - if (this.mPrimaryMeta > 0) - TileEntitySpaceOres.setOuterSpaceOreBlock(tMDD, pWorld, tX, tY, tZ, this.mPrimaryMeta + 16000); - tX = pRandom.nextInt(16) + pChunkX + 2; - tZ = pRandom.nextInt(16) + pChunkZ + 2; - tY = pRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. - if (this.mSecondaryMeta > 0) - TileEntitySpaceOres.setOuterSpaceOreBlock(tMDD, pWorld, tX, tY, tZ, this.mSecondaryMeta + 16000); - tX = pRandom.nextInt(16) + pChunkX + 2; - tZ = pRandom.nextInt(16) + pChunkZ + 2; - tY = pRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. - if (this.mBetweenMeta > 0) - TileEntitySpaceOres.setOuterSpaceOreBlock(tMDD, pWorld, tX, tY, tZ, this.mBetweenMeta + 16000); - tX = pRandom.nextInt(16) + pChunkX + 2; - tZ = pRandom.nextInt(16) + pChunkZ + 2; - tY = pRandom.nextInt(190) + 10; // Y height can vary from 10 to 200 for small ores. - if (this.mSporadicMeta > 0) - TileEntitySpaceOres.setOuterSpaceOreBlock(tMDD, pWorld, tX, tY, tZ, this.mSporadicMeta + 16000); - } - } - - // --------------------------- - if (GalacticGreg.GalacticConfig.ProfileOreGen) { - try { - mProfilingEnd = System.currentTimeMillis(); - long tTotalTime = mProfilingEnd - mProfilingStart; - GalacticGreg.Profiler.AddTimeToList(tMDD, tTotalTime); - GalacticGreg.Logger.debug( - "Done with OreLayer-Worldgen in DimensionType %s. Generation took %d ms", - tMDD.getDimensionName(), - tTotalTime); - } catch (Exception ignored) {} // Silently ignore errors - } - - GalacticGreg.Logger.trace("Leaving executeWorldgen"); - return true; - } - - public int getDensityFromPos(int aX, int aZ, int aSeedX, int aSeedZ) { - if (aX < 0) aX -= 16; - if (aZ < 0) aZ -= 16; - return Math.max( - 1, - this.mDensity - / ((int) Math.sqrt(2 + Math.pow(aX / 16 - aSeedX / 16, 2) + Math.pow(aZ / 16 - aSeedZ / 16, 2)))); - } -} diff --git a/src/main/java/galacticgreg/WorldgenOreSmallSpace.java b/src/main/java/galacticgreg/WorldgenOreSmallSpace.java deleted file mode 100644 index 40fede19b02..00000000000 --- a/src/main/java/galacticgreg/WorldgenOreSmallSpace.java +++ /dev/null @@ -1,116 +0,0 @@ -package galacticgreg; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; - -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; - -import galacticgreg.api.ModContainer; -import galacticgreg.api.ModDimensionDef; -import galacticgreg.registry.GalacticGregRegistry; -import gregtech.api.world.GTWorldgen; -import gregtech.common.SmallOreBuilder; - -public class WorldgenOreSmallSpace extends GTWorldgen { - - public final short mMinY; - public final short mMaxY; - public final short mAmount; - public final short mMeta; - - private long mProfilingStart; - private long mProfilingEnd; - private final Map allowedDims; - - public WorldgenOreSmallSpace(SmallOreBuilder ore) { - super(ore.smallOreName, GalacticGreg.smallOreWorldgenList, ore.enabledByDefault); - - mMinY = (short) ore.minY; - mMaxY = (short) Math.max(this.mMinY + 1, ore.maxY); - mAmount = (short) Math.max(1, ore.amount); - mMeta = (short) ore.ore.mMetaItemSubID; - - allowedDims = new HashMap<>(); - for (ModContainer mc : GalacticGregRegistry.getModContainers()) { - if (!mc.isModLoaded()) continue; - - for (ModDimensionDef mdd : mc.getDimensionList()) { - String tDimIdentifier = mdd.getDimIdentifier(); - if (allowedDims.containsKey(tDimIdentifier)) GalacticGreg.Logger.error( - "Found 2 Dimensions with the same Identifier: %s Dimension will not generate Ores", - tDimIdentifier); - else { - boolean tFlag = ore.dimsEnabled.getOrDefault(mdd.getDimensionName(), false); - allowedDims.put(tDimIdentifier, tFlag); - } - } - } - - GalacticGreg.Logger.trace("Initialized new OreLayer: %s", ore.smallOreName); - } - - /** - * Check if *this* orelayer is enabled for pDimensionDef - * - * @param pDimensionDef the ChunkProvider in question - * @return - */ - public boolean isEnabledForDim(ModDimensionDef pDimensionDef) { - return allowedDims.getOrDefault(pDimensionDef.getDimIdentifier(), false); - } - - @Override - public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int pDimensionType, int pChunkX, - int pChunkZ, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { - GalacticGreg.Logger.trace("Entering executeWorldgen for [%s]", mWorldGenName); - ModDimensionDef tMDD = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); - if (tMDD == null) { - GalacticGreg.Logger - .trace("Can't find dimension definition for ChunkProvider %s, skipping", pChunkGenerator.toString()); - return false; - } - - if (!isEnabledForDim(tMDD)) { - GalacticGreg.Logger - .trace("OreGen for %s is disallowed in dimension %s, skipping", mWorldGenName, tMDD.getDimensionName()); - return false; - } - - if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); - // --------------------------- - - if (this.mMeta > 0) { - int i = 0; - for (int j = Math.max(1, this.mAmount / 2 + pRandom.nextInt(this.mAmount) / 2); i < j; i++) { - TileEntitySpaceOres.setOuterSpaceOreBlock( - tMDD, - pWorld, - pChunkX + pRandom.nextInt(16), - this.mMinY + pRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), - pChunkZ + pRandom.nextInt(16), - this.mMeta + 16000); - } - } - // --------------------------- - if (GalacticGreg.GalacticConfig.ProfileOreGen) { - try { - mProfilingEnd = System.currentTimeMillis(); - long tTotalTime = mProfilingEnd - mProfilingStart; - GalacticGreg.Profiler.AddTimeToList(tMDD, tTotalTime); - GalacticGreg.Logger.debug( - "Done with SmallOre-Worldgen in DimensionType %s. Generation took %d ms", - tMDD.getDimensionName(), - tTotalTime); - } catch (Exception ignored) {} // Silently ignore errors - } - - GalacticGreg.Logger.trace("Leaving executeWorldgen"); - return true; - } - - public boolean isAllowedForHeight(int pTargetHeight) { - return (pTargetHeight >= mMinY && pTargetHeight <= mMaxY); - } -} diff --git a/src/main/java/galacticgreg/api/AsteroidBlockComb.java b/src/main/java/galacticgreg/api/AsteroidBlockComb.java deleted file mode 100644 index d9961cf8ec2..00000000000 --- a/src/main/java/galacticgreg/api/AsteroidBlockComb.java +++ /dev/null @@ -1,76 +0,0 @@ -package galacticgreg.api; - -import net.minecraft.block.Block; - -/** - * Class for a bit more advanced combinations for Asteroids, which supports Custom Blocks as base material and Values - * required to generate Gregtech ores - */ -public class AsteroidBlockComb extends BlockMetaComb { - - private final GTOreTypes _mGTOreMaterial; - - /** - * Create an advanced definition which uses the GregTech-OreType values for ores, and your own definition of Block - * for the asteroid material - * - * @param pOreType The GregTech oreType - * @param pBlock Your block - */ - public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock) { - super(pBlock, 0); - _mGTOreMaterial = pOreType; - } - - /** - * Create an advanced definition which uses the GregTech-OreType values for ores, and your own definition of Block - * for the asteroid material - * - * @param pOreType The GregTech oreType - * @param pBlock Your block - * @param pMeta The metavalue for your block (If required) - */ - public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock, int pMeta) { - super(pBlock, pMeta); - _mGTOreMaterial = pOreType; - } - - /** - * Create a simple definition which uses the GregTech-OreType values for both asteroidStone and ores - * - * @param pOreType The GregTech oreType - */ - public AsteroidBlockComb(GTOreTypes pOreType) { - super(pOreType.getBlock(), pOreType.getMeta()); - _mGTOreMaterial = pOreType; - } - - /** - * Internal function - * - * @return The GT Material for the oregen - */ - public GTOreTypes getOreMaterial() { - return _mGTOreMaterial; - } - - @Override - public boolean equals(Object other) { - if (other == null) return false; - if (other == this) return true; - if (!(other instanceof AsteroidBlockComb otherObj)) return false; - - boolean tFlag = true; - String otherName = Block.blockRegistry.getNameForObject(otherObj.getBlock()); - String thisName = Block.blockRegistry.getNameForObject(this.getBlock()); - if (otherName != null && thisName != null) { - if (!otherName.equals(thisName)) tFlag = false; - - if (!(otherObj.getMeta() == this.getMeta())) tFlag = false; - - if (!(otherObj.getOreMaterial() == this.getOreMaterial())) tFlag = false; - } else tFlag = false; - - return tFlag; - } -} diff --git a/src/main/java/galacticgreg/api/BlockMetaComb.java b/src/main/java/galacticgreg/api/BlockMetaComb.java deleted file mode 100644 index 47a1ced4f32..00000000000 --- a/src/main/java/galacticgreg/api/BlockMetaComb.java +++ /dev/null @@ -1,50 +0,0 @@ -package galacticgreg.api; - -import net.minecraft.block.Block; - -/** - * Class used for Simple Block - Meta constructs - */ -public class BlockMetaComb { - - private final int mMeta; - private final Block mBlock; - - /** - * Creates a simple instance for a block that has no meta value - * - * @param pBlock The Block in question. 0 is used as meta - */ - public BlockMetaComb(Block pBlock) { - this(pBlock, 0); - } - - /** - * Creates a simple instance for a block with a meta value - * - * @param pBlock The Block in question - * @param pMeta The MetaValue in question ([block]:[meta]) - */ - public BlockMetaComb(Block pBlock, int pMeta) { - mMeta = pMeta; - mBlock = pBlock; - } - - /** - * Internal function - * - * @return The metadata for this block - */ - public int getMeta() { - return mMeta; - } - - /** - * Internal function - * - * @return The block - */ - public Block getBlock() { - return mBlock; - } -} diff --git a/src/main/java/galacticgreg/api/Enums.java b/src/main/java/galacticgreg/api/Enums.java index f60c5602ddf..309d8caf23b 100644 --- a/src/main/java/galacticgreg/api/Enums.java +++ b/src/main/java/galacticgreg/api/Enums.java @@ -22,12 +22,6 @@ public enum AllowedBlockPosition { AsteroidCoreAndShell } - public enum AirReplaceRule { - NeverReplaceAir, - AllowReplaceAir, - OnlyReplaceAir - } - public enum ReplaceState { Unknown, Airblock, diff --git a/src/main/java/galacticgreg/api/ModDimensionDef.java b/src/main/java/galacticgreg/api/ModDimensionDef.java index fbfbd674f3d..9b63221b65c 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -4,9 +4,15 @@ import java.util.List; import java.util.Random; -import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraft.world.WorldProvider; import net.minecraft.world.chunk.IChunkProvider; +import galacticgreg.api.Enums.DimensionType; +import gregtech.api.interfaces.IStoneType; +import gregtech.api.objects.XSTR; +import gregtech.common.config.Gregtech; + // import galacticgreg.GalacticGreg; /** @@ -15,58 +21,72 @@ public class ModDimensionDef { private static final String STR_NOTDEFINED = "iiznotdefined"; - private final String _mDimensionName; - private String _mInternalDimIdentifier; - private final String _mChunkProvider; - private Enums.AirReplaceRule _mDimAirSetting; - private final ArrayList _mReplaceableBlocks; - private Enums.DimensionType _mDimensionType; - - private final List _mSpaceObjectsGenerators; - private final List _mSpaceStructureGenerators; - - // Special Planets config settings - private int _mGroundOreMaxY = 64; - private int _mFloatingAsteroidsMinY = 128; - // ------ + private final String dimensionName; + /** "modname_dimname" */ + private String internalDimIdentifier; + private final String chunkProviderName; + private DimensionType dimensionType; - // Override for stonetype - private GTOreTypes _mStoneType; + private final List spaceObjectGenerators; + private final List spaceStructureGenerators; + + private int oreVeinChance = Gregtech.general.oreveinPercentage; + + // ------ // Asteroid stuff - private final List _mValidAsteroidMaterials; - private final List _mSpecialBlocksForAsteroids; + private final List validAsteroidMaterials; + private final List specialBlocksForAsteroids; + + private final XSTR random = new XSTR(); - private final Random _mRandom = new Random(System.currentTimeMillis()); + private boolean hasEoHRecipe = true; + private boolean canBeVoidMined = true; /** - * Internal function - * - * @return A list of possible asteroid-mixes that shall be generated + * @param pDimensionName The provider dimension name (see {@link World#provider} and + * {@link WorldProvider#getDimensionName()}) + * @param pChunkProvider The chunk provider class + * @param pDimType The dimension type (whether it generates asteroids or ore veins) */ - public List getValidAsteroidMaterials() { - return _mValidAsteroidMaterials; + public ModDimensionDef(String pDimensionName, Class pChunkProvider, + DimensionType pDimType) { + this(pDimensionName, pChunkProvider.getName(), pDimType); } - // ================================================= /** - * Internal function The only purpose of this functions is to get a default config value for this dim, that can be - * altered by the mod author which adds the dimension definition to his mod, but also provide the - * modpack-author/serveradmin to change these values aswell + * @param pDimensionName The provider dimension name (see {@link World#provider} and + * {@link WorldProvider#getDimensionName()}) + * @param pChunkProvider The chunk provider class name + * @param pDimType The dimension type (whether it generates asteroids or ore veins) */ - public int getPreConfiguratedGroundOreMaxY() { - return _mGroundOreMaxY; + public ModDimensionDef(String pDimensionName, String pChunkProviderName, DimensionType pDimType) { + internalDimIdentifier = STR_NOTDEFINED; + dimensionName = pDimensionName; + chunkProviderName = pChunkProviderName; + dimensionType = pDimType; + + validAsteroidMaterials = new ArrayList<>(); + specialBlocksForAsteroids = new ArrayList<>(); + spaceObjectGenerators = new ArrayList<>(); + spaceStructureGenerators = new ArrayList<>(); } /** - * Internal function The only purpose of this functions is to get a default config value for this dim, that can be - * altered by the mod author which adds the dimension definition to his mod, but also provide the - * modpack-author/serveradmin to change these values aswell + * Sets the chance that an ore seed chunk will have a vein + * + * @param chance The chance out of 100. */ - public int getPreConfiguratedFloatingAsteroidMinY() { - return _mFloatingAsteroidsMinY; + public ModDimensionDef setOreVeinChance(int chance) { + oreVeinChance = chance; + return this; } + public int getOreVeinChance() { + return oreVeinChance; + } + + // ================================================= /** * Register new generator for objects in space. You can register as many as you want. If you don't register * anything, no structures will generate and the default Asteroid-Generator will be used @@ -77,10 +97,10 @@ public void registerSpaceObjectGenerator(ISpaceObjectGenerator pSpaceObjectGener Enums.SpaceObjectType tType = pSpaceObjectGenerator.getType(); switch (tType) { case NonOreSchematic: - _mSpaceStructureGenerators.add(pSpaceObjectGenerator); + spaceStructureGenerators.add(pSpaceObjectGenerator); break; case OreAsteroid: - _mSpaceObjectsGenerators.add(pSpaceObjectGenerator); + spaceObjectGenerators.add(pSpaceObjectGenerator); break; default: // GalacticGreg.Logger.error("registerSpaceObjectGenerator() found unhandled generator type %s. Please @@ -99,10 +119,10 @@ public ISpaceObjectGenerator getRandomSOGenerator(Enums.SpaceObjectType pTargetT try { switch (pTargetType) { case NonOreSchematic: - tLst = _mSpaceStructureGenerators; + tLst = spaceStructureGenerators; break; case OreAsteroid: - tLst = _mSpaceObjectsGenerators; + tLst = spaceObjectGenerators; break; default: break; @@ -110,7 +130,7 @@ public ISpaceObjectGenerator getRandomSOGenerator(Enums.SpaceObjectType pTargetT if (tLst != null) { if (tLst.size() == 1) tGen = tLst.get(0); - else if (tLst.size() > 1) tGen = tLst.get(_mRandom.nextInt(tLst.size())); + else if (tLst.size() > 1) tGen = tLst.get(random.nextInt(tLst.size())); } } catch (Exception e) { e.printStackTrace(); @@ -118,24 +138,6 @@ public ISpaceObjectGenerator getRandomSOGenerator(Enums.SpaceObjectType pTargetT return tGen; } - /** - * Define the default values for the floating asteroids and the oregen here. As both generators run in the same - * dimension, and you probably don't want to have asteroids stuck in the ground, both generators are separated from - * each other. Basically, you can go with the default values. If you want to change them, make sure that pOregenMaxY - * is lower than pAsteroidMinY - * - * @param pOregenMaxY The maximum Y-height where ores will be allowed to spawn. Default: 64 - * @param pAsteroidMinY The minimum Y-height that has to be reached before asteroids will spawn. Default: 128 - * @throws IllegalArgumentException if the limits are invalid - * - */ - public void setAsteroidAndPlanetLimits(int pOregenMaxY, int pAsteroidMinY) { - if (pOregenMaxY >= pAsteroidMinY) - throw new IllegalArgumentException("pOregenMaxY must be LOWER than pAsteroidMinY!"); - - _mFloatingAsteroidsMinY = pAsteroidMinY; - _mGroundOreMaxY = pOregenMaxY; - } // ================================================= /** @@ -144,11 +146,11 @@ public void setAsteroidAndPlanetLimits(int pOregenMaxY, int pAsteroidMinY) { * @return A list of all special blocks that shall be used to generate the asteroids. */ public List getSpecialBlocksForAsteroids() { - return _mSpecialBlocksForAsteroids; + return specialBlocksForAsteroids; } public List getSpaceObjectGenerators() { - return _mSpaceObjectsGenerators; + return spaceObjectGenerators; } /** @@ -156,8 +158,8 @@ public List getSpaceObjectGenerators() { * * @return The type for this dimension */ - public Enums.DimensionType getDimensionType() { - return _mDimensionType; + public DimensionType getDimensionType() { + return dimensionType; } /** @@ -166,32 +168,8 @@ public Enums.DimensionType getDimensionType() { * * @param pType The dimensiontype to be used */ - public void setDimensionType(Enums.DimensionType pType) { - _mDimensionType = pType; - } - - /** - * Internal function - * - * @return The configuration for AirBlocks - */ - public Enums.AirReplaceRule getAirSetting() { - return _mDimAirSetting; - } - - /** - * Define how the oregen shall handle air-blocks. These settings should be pretty self-explandatory, but anyways: - * NeverReplaceAir: No matter what, if there is an Air-Block found, it will not replace it. AllowReplaceAir: This - * will generate Ores in Stones (defined by addBlockDefinition()) and air if found OnlyReplaceAir : This will not - * generate Ores in solid blocks, but only in air - *

- * Note that "OnlyReplaceAir" is a special setting if you have a dimension that is not defined as "Asteroids" but - * you still need/want to generate ores in midair. - * - * @param pSetting - */ - public void setAirSetting(Enums.AirReplaceRule pSetting) { - _mDimAirSetting = pSetting; + public void setDimensionType(DimensionType pType) { + dimensionType = pType; } /** @@ -200,29 +178,7 @@ public void setAirSetting(Enums.AirReplaceRule pSetting) { * @return The dimension identifier that is used internally to identify the dimension */ public String getDimIdentifier() { - return _mInternalDimIdentifier; - } - - /** - * Set a manual override for ores that shall be generated. This setting is ignored if getIsAsteroidDimension() - * returns true - *

- * For example, on GalactiCraft Mars, this value is set to GTOreTypes.RedGranite, because it matches the color - * better. If you don't set anything here, it will generate regular stone-ores. - * - * @param pStoneType - */ - public void setStoneType(GTOreTypes pStoneType) { - _mStoneType = pStoneType; - } - - /** - * Internal function - * - * @return The stone override for gregtech ores - */ - public GTOreTypes getStoneType() { - return _mStoneType; + return internalDimIdentifier; } /** @@ -231,23 +187,7 @@ public GTOreTypes getStoneType() { * @return The attached chunk-provider for this dimension */ public String getChunkProviderName() { - return _mChunkProvider; - } - - /** - * Adds a new blockdefinition to this dimension. This block will then later be replaced by ores. You can add as many - * blocks as you want. Just don't add Blocks.Air, as there is another setting for allowing Air-Replacement - * - * @param pBlockDef - * @return - */ - public boolean addBlockDefinition(ModDBMDef pBlockDef) { - if (_mReplaceableBlocks.contains(pBlockDef)) { - return false; - } else { - _mReplaceableBlocks.add(pBlockDef); - return true; - } + return chunkProviderName; } /** @@ -256,82 +196,7 @@ public boolean addBlockDefinition(ModDBMDef pBlockDef) { * @return The DimensionName in a Human-readable format */ public String getDimensionName() { - return _mDimensionName; - } - - /** - * Internal function - * - * @return A list of all defined Blocks that can be replaced while generating ores - */ - public ArrayList getReplaceableBlocks() { - return _mReplaceableBlocks; - } - - /** - * Define a new dimension - * - * @param pDimensionName The human-readable. Spaces will be removed - * @param pChunkProvider The chunkprovider class that shall be observed for the oregen - */ - public ModDimensionDef(String pDimensionName, Class pChunkProvider, - Enums.DimensionType pDimType) { - this( - pDimensionName, - pChunkProvider.toString() - .substring(6), - pDimType, - null); - } - - /** - * Define a new dimension - * - * @param pDimensionName The human-readable. Spaces will be removed - * @param pChunkProvider The chunkprovider class that shall be observed for the oregen - * @param pBlockDefinitions The list of predefined blocks to be replaced by ores - */ - public ModDimensionDef(String pDimensionName, Class pChunkProvider, - Enums.DimensionType pDimType, List pBlockDefinitions) { - this( - pDimensionName, - pChunkProvider.toString() - .substring(6), - pDimType, - pBlockDefinitions); - } - - /** - * Define a new dimension - * - * @param pDimensionName The human-readable DimensionName. Spaces will be removed - * @param pChunkProviderName The human-readable, full-qualified classname for the chunkprovider - */ - public ModDimensionDef(String pDimensionName, String pChunkProviderName, Enums.DimensionType pDimType) { - this(pDimensionName, pChunkProviderName, pDimType, null); - } - - /** - * Define a new dimension - * - * @param pDimensionName The human-readable DimensionName. Spaces will be removed - * @param pChunkProviderName The human-readable, full-qualified classname for the chunkprovider - * @param pBlockDefinitions The list of predefined blocks to be replaced by ores - */ - public ModDimensionDef(String pDimensionName, String pChunkProviderName, Enums.DimensionType pDimType, - List pBlockDefinitions) { - _mInternalDimIdentifier = STR_NOTDEFINED; - _mDimensionName = pDimensionName; - _mChunkProvider = pChunkProviderName; - _mDimensionType = pDimType; - - _mReplaceableBlocks = new ArrayList<>(); - if (pBlockDefinitions != null) _mReplaceableBlocks.addAll(pBlockDefinitions); - - _mValidAsteroidMaterials = new ArrayList<>(); - _mSpecialBlocksForAsteroids = new ArrayList<>(); - _mSpaceObjectsGenerators = new ArrayList<>(); - _mSpaceStructureGenerators = new ArrayList<>(); + return dimensionName; } /** @@ -341,43 +206,14 @@ public ModDimensionDef(String pDimensionName, String pChunkProviderName, Enums.D * Seriously, don't do it. */ protected void setParentModName(String pModName) { - if (_mInternalDimIdentifier.equals(STR_NOTDEFINED)) { - _mInternalDimIdentifier = String.format("%s_%s", pModName, _mDimensionName); + if (internalDimIdentifier.equals(STR_NOTDEFINED)) { + internalDimIdentifier = String.format("%s_%s", pModName, dimensionName); } // Else Don't update, we're already set } - /** - * Internal function - *

- * Check if pBlock can be replaced by an ore - * - * @param pBlock - * @param pMeta - * @return - */ - public Enums.ReplaceState getReplaceStateForBlock(Block pBlock, int pMeta) { - Enums.ReplaceState tFlag = Enums.ReplaceState.Unknown; - - for (ModDBMDef pDef : _mReplaceableBlocks) { - Enums.ReplaceState tResult = pDef.blockEquals(pBlock, pMeta); - if (tResult == Enums.ReplaceState.Unknown) continue; - - if (tResult == Enums.ReplaceState.CanReplace) { - // GalacticGreg.Logger.trace("Targetblock found and metadata match. Replacement allowed"); - tFlag = Enums.ReplaceState.CanReplace; - } else if (tResult == Enums.ReplaceState.CannotReplace) { - // GalacticGreg.Logger.trace("Targetblock found but metadata mismatch. Replacement denied"); - tFlag = Enums.ReplaceState.CannotReplace; - } - break; - } - - return tFlag; - } - /** * Internal function *

@@ -385,12 +221,13 @@ public Enums.ReplaceState getReplaceStateForBlock(Block pBlock, int pMeta) { * * @return */ - public AsteroidBlockComb getRandomAsteroidMaterial() { - if (_mValidAsteroidMaterials.isEmpty()) return null; + public IStoneType getRandomAsteroidMaterial(Random rng) { + if (validAsteroidMaterials.isEmpty()) return null; - if (_mValidAsteroidMaterials.size() == 1) return _mValidAsteroidMaterials.get(0); - else { - return _mValidAsteroidMaterials.get(_mRandom.nextInt(_mValidAsteroidMaterials.size())); + if (validAsteroidMaterials.size() == 1) { + return validAsteroidMaterials.get(0); + } else { + return validAsteroidMaterials.get(rng.nextInt(validAsteroidMaterials.size())); } } @@ -401,32 +238,24 @@ public AsteroidBlockComb getRandomAsteroidMaterial() { * * @return */ - public SpecialBlockComb getRandomSpecialAsteroidBlock() { - if (_mSpecialBlocksForAsteroids.isEmpty()) return null; + public SpecialBlockComb getRandomSpecialAsteroidBlock(Random rng) { + if (specialBlocksForAsteroids.isEmpty()) return null; - if (_mSpecialBlocksForAsteroids.size() == 1) return _mSpecialBlocksForAsteroids.get(0); - else { - return _mSpecialBlocksForAsteroids.get(_mRandom.nextInt(_mSpecialBlocksForAsteroids.size())); + if (specialBlocksForAsteroids.size() == 1) { + return specialBlocksForAsteroids.get(0); + } else { + return specialBlocksForAsteroids.get(rng.nextInt(specialBlocksForAsteroids.size())); } } - /** - * Define the material the asteroid shall be made of. Limited to GT-Based Ores and their stones - * - * @param pMaterial - */ - public void addAsteroidMaterial(GTOreTypes pMaterial) { - addAsteroidMaterial(new AsteroidBlockComb(pMaterial)); - } - /** * Define the material the asteroid shall be made of, more advanced option to specify your own blocks * * @param pBlockComb */ - public void addAsteroidMaterial(AsteroidBlockComb pBlockComb) { - if (!_mValidAsteroidMaterials.contains(pBlockComb)) { - _mValidAsteroidMaterials.add(pBlockComb); + public void addAsteroidMaterial(IStoneType pBlockComb) { + if (!validAsteroidMaterials.contains(pBlockComb)) { + validAsteroidMaterials.add(pBlockComb); } } @@ -438,24 +267,28 @@ public void addAsteroidMaterial(AsteroidBlockComb pBlockComb) { * @param pBlock Block-Meta Combination that shall be used */ public void addSpecialAsteroidBlock(SpecialBlockComb pBlock) { - if (!_mSpecialBlocksForAsteroids.contains(pBlock)) { - _mSpecialBlocksForAsteroids.add(pBlock); + if (!specialBlocksForAsteroids.contains(pBlock)) { + specialBlocksForAsteroids.add(pBlock); } } - /** - * Internal function Called when GalacticGreg will finalize all its internal structures. You should never call this - * yourself - */ - public void finalizeReplaceableBlocks(String pParentModName) { - for (ModDBMDef rpb : _mReplaceableBlocks) { - try { - rpb.updateBlockName(pParentModName); - if (_mStoneType == null) _mStoneType = GTOreTypes.NormalOres; - } catch (Exception e) { - // GalacticGreg.Logger.error("Unable to finalize replaceable block with modname for block %s. Dimension - // %s will probably have problems generating ores", rpb.getBlockName(), _mDimensionName); - } - } + public ModDimensionDef disableEoHRecipe() { + hasEoHRecipe = false; + + return this; + } + + public boolean hasEoHRecipe() { + return hasEoHRecipe; + } + + public ModDimensionDef disableVoidMining() { + canBeVoidMined = false; + + return this; + } + + public boolean canBeVoidMined() { + return canBeVoidMined; } } diff --git a/src/main/java/galacticgreg/api/SpecialBlockComb.java b/src/main/java/galacticgreg/api/SpecialBlockComb.java index bc3d884d3de..86a3f43feb4 100644 --- a/src/main/java/galacticgreg/api/SpecialBlockComb.java +++ b/src/main/java/galacticgreg/api/SpecialBlockComb.java @@ -2,7 +2,9 @@ import net.minecraft.block.Block; -public class SpecialBlockComb extends BlockMetaComb { +import com.gtnewhorizon.gtnhlib.util.data.BlockMeta; + +public class SpecialBlockComb extends BlockMeta { private final Enums.AllowedBlockPosition _mBlockPosition; @@ -49,20 +51,20 @@ public Enums.AllowedBlockPosition getBlockPosition() { } @Override - public boolean equals(Object other) { - if (other == null) return false; - if (other == this) return true; - if (!(other instanceof SpecialBlockComb otherObj)) return false; - - boolean tFlag = true; - String otherName = Block.blockRegistry.getNameForObject(otherObj.getBlock()); - String thisName = Block.blockRegistry.getNameForObject(this.getBlock()); - if (!otherName.equals(thisName)) tFlag = false; - - if (!(otherObj.getMeta() == this.getMeta())) tFlag = false; - - if (!(otherObj.getBlockPosition() == this.getBlockPosition())) tFlag = false; + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((_mBlockPosition == null) ? 0 : _mBlockPosition.hashCode()); + return result; + } - return tFlag; + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!super.equals(obj)) return false; + if (getClass() != obj.getClass()) return false; + SpecialBlockComb other = (SpecialBlockComb) obj; + if (_mBlockPosition != other._mBlockPosition) return false; + return true; } } diff --git a/src/main/java/galacticgreg/api/StructureInformation.java b/src/main/java/galacticgreg/api/StructureInformation.java index 83c47603f59..1704bc3c3a3 100644 --- a/src/main/java/galacticgreg/api/StructureInformation.java +++ b/src/main/java/galacticgreg/api/StructureInformation.java @@ -2,6 +2,8 @@ import net.minecraft.util.Vec3; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + import galacticgreg.api.Enums.TargetBlockPosition; /** @@ -11,7 +13,7 @@ public class StructureInformation { private final Vec3 _mCoordinates; private final TargetBlockPosition _mBlockPosition; - private final BlockMetaComb _mBlockMetaComb; + private final ImmutableBlockMeta _mBlockMetaComb; public TargetBlockPosition getBlockPosition() { return _mBlockPosition; @@ -29,7 +31,7 @@ public int getZ() { return (int) Math.round(_mCoordinates.zCoord); } - public BlockMetaComb getBlock() { + public ImmutableBlockMeta getBlock() { return _mBlockMetaComb; } @@ -50,7 +52,7 @@ public StructureInformation(Vec3 pCoordinates, TargetBlockPosition pPosition) { * @param pPosition The position-enum value * @param pTargetBlock The target block in question */ - public StructureInformation(Vec3 pCoordinates, TargetBlockPosition pPosition, BlockMetaComb pTargetBlock) { + public StructureInformation(Vec3 pCoordinates, TargetBlockPosition pPosition, ImmutableBlockMeta pTargetBlock) { _mCoordinates = pCoordinates; _mBlockPosition = pPosition; _mBlockMetaComb = pTargetBlock; diff --git a/src/main/java/galacticgreg/api/enums/DimensionBlockMetaDefinitionList.java b/src/main/java/galacticgreg/api/enums/DimensionBlockMetaDefinitionList.java deleted file mode 100644 index 72dfd9f5120..00000000000 --- a/src/main/java/galacticgreg/api/enums/DimensionBlockMetaDefinitionList.java +++ /dev/null @@ -1,57 +0,0 @@ -package galacticgreg.api.enums; - -import java.util.Arrays; -import java.util.List; - -import net.minecraft.init.Blocks; - -import galacticgreg.api.ModDBMDef; - -public enum DimensionBlockMetaDefinitionList { - - Moon(new ModDBMDef("tile.moonBlock", 4)), - Mars(new ModDBMDef("tile.mars", 9)), - Phobos(new ModDBMDef("phobosblocks", 2)), - Deimos(new ModDBMDef("deimosblocks", 1)), - Ceres(new ModDBMDef("ceresblocks", 1)), - Io(new ModDBMDef("ioblocks", 2)), - Ganymede(new ModDBMDef("ganymedeblocks", 1)), - Callisto(new ModDBMDef("callistoblocks", 1)), - Venus(new ModDBMDef("venusblocks", 1)), - Mercury(new ModDBMDef("mercuryblocks", 2)), - Enceladus(new ModDBMDef("enceladusblocks", 1)), - Titan(new ModDBMDef("titanblocks", 2)), - Oberon(new ModDBMDef("oberonblocks", 2)), - Proteus(new ModDBMDef("proteusblocks", 2)), - Triton(new ModDBMDef("tritonblocks", 2)), - Pluto(new ModDBMDef("plutoblocks", 5)), - MakeMake(new ModDBMDef("makemakegrunt", 1)), - Haumea(new ModDBMDef("haumeablocks")), - CentauriAlpha(new ModDBMDef("acentauribbsubgrunt")), - VegaB(new ModDBMDef("vegabsubgrunt")), - BarnardaC(new ModDBMDef("barnardaCdirt"), new ModDBMDef(Blocks.stone)), - BarnardaE(new ModDBMDef("barnardaEsubgrunt")), - BarnardaF(new ModDBMDef("barnardaFsubgrunt")), - TcetiE(new ModDBMDef("tcetieblocks", 2)), - Miranda(new ModDBMDef("mirandablocks", 2)), - Europa( - // Europa top layer turned off bc ores are too easy to spot - new ModDBMDef("europagrunt", 1), // Europa Ice Layer ~55-65 without top layer - new ModDBMDef(Blocks.water), new ModDBMDef(Blocks.flowing_water), new ModDBMDef(Blocks.ice), // Generates - // directly over - // bedrock - new ModDBMDef(Blocks.packed_ice), // Generates directly over bedrock - new ModDBMDef("europaunderwatergeyser") // Generates directly over bedrock - ), - Neper(new ModDBMDef(Blocks.stone), new ModDBMDef("tile.baseBlockRock", 10)), - Maahes(new ModDBMDef("tile.baseBlockRock", 1)), - Anubis(new ModDBMDef("tile.baseBlockRock", 1)), - Horus(new ModDBMDef(Blocks.obsidian)), - Seth(new ModDBMDef(Blocks.hardened_clay)); - - public final List DBMDefList; - - DimensionBlockMetaDefinitionList(ModDBMDef... DBMDefArray) { - DBMDefList = Arrays.asList(DBMDefArray); - } -} diff --git a/src/main/java/galacticgreg/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index 6684777bba1..fa860cc87b4 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -1,185 +1,248 @@ package galacticgreg.api.enums; +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.world.World; import net.minecraft.world.gen.ChunkProviderEnd; +import net.minecraft.world.gen.ChunkProviderGenerate; +import net.minecraft.world.gen.ChunkProviderHell; -import galacticgreg.api.Enums; +import galacticgreg.api.Enums.DimensionType; import galacticgreg.api.ModDimensionDef; +import gtPlusPlus.everglades.chunk.ChunkProviderModded; public enum DimensionDef { - EndAsteroids(new ModDimensionDef(DimNames.ENDASTEROIDS, ChunkProviderEnd.class, Enums.DimensionType.Asteroid)), + // spotless:off + Overworld(new ModDimensionDef( + DimNames.OW, + ChunkProviderGenerate.class, + DimensionType.Planet)), + Nether(new ModDimensionDef( + DimNames.NETHER, + ChunkProviderHell.class, + DimensionType.Planet)), + TheEnd(new ModDimensionDef( + DimNames.THE_END, + ChunkProviderEnd.class, + DimensionType.Planet)), + EndAsteroids(new ModDimensionDef( + DimNames.ENDASTEROID, + ChunkProviderEnd.class, + DimensionType.Asteroid)), + TwilightForest(new ModDimensionDef( + DimNames.TWILIGHT_FOREST, + "twilightforest.world.ChunkProviderTwilightForest", + DimensionType.Planet)), + Everglades(new ModDimensionDef( + DimNames.EVERGLADES, + ChunkProviderModded.class, + DimensionType.Planet) + .setOreVeinChance(66) + .disableEoHRecipe()), + + Moon(new ModDimensionDef( DimNames.MOON, "micdoodle8.mods.galacticraft.core.world.gen.ChunkProviderMoon", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Moon.DBMDefList)), + DimensionType.Planet)), Mars(new ModDimensionDef( DimNames.MARS, "micdoodle8.mods.galacticraft.planets.mars.world.gen.ChunkProviderMars", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Mars.DBMDefList)), + DimensionType.Planet)), Asteroids(new ModDimensionDef( DimNames.ASTEROIDS, "micdoodle8.mods.galacticraft.planets.asteroids.world.gen.ChunkProviderAsteroids", - Enums.DimensionType.Asteroid)), + DimensionType.Asteroid) + .disableVoidMining()), + Ross128b(new ModDimensionDef( + DimNames.ROSS128B, + "bwcrossmod.galacticraft.planets.ross128b.ChunkProviderRoss128b", + DimensionType.Planet) + .disableEoHRecipe()), + Ross128ba(new ModDimensionDef( + DimNames.ROSS128BA, + "bwcrossmod.galacticraft.planets.ross128ba.ChunkProviderRoss128ba", + DimensionType.Planet) + .disableEoHRecipe()), Pluto(new ModDimensionDef( DimNames.PLUTO, "galaxyspace.SolarSystem.planets.pluto.dimension.ChunkProviderPluto", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Pluto.DBMDefList)), + DimensionType.Planet)), Triton(new ModDimensionDef( DimNames.TRITON, "galaxyspace.SolarSystem.moons.triton.dimension.ChunkProviderTriton", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Triton.DBMDefList)), + DimensionType.Planet)), Proteus(new ModDimensionDef( DimNames.PROTEUS, "galaxyspace.SolarSystem.moons.proteus.dimension.ChunkProviderProteus", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Proteus.DBMDefList)), + DimensionType.Planet)), Oberon(new ModDimensionDef( DimNames.OBERON, "galaxyspace.SolarSystem.moons.oberon.dimension.ChunkProviderOberon", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Oberon.DBMDefList)), + DimensionType.Planet)), Titan(new ModDimensionDef( DimNames.TITAN, "galaxyspace.SolarSystem.moons.titan.dimension.ChunkProviderTitan", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Titan.DBMDefList)), + DimensionType.Planet)), Callisto(new ModDimensionDef( DimNames.CALLISTO, "galaxyspace.SolarSystem.moons.callisto.dimension.ChunkProviderCallisto", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Callisto.DBMDefList)), + DimensionType.Planet)), Ganymede(new ModDimensionDef( DimNames.GANYMEDE, "galaxyspace.SolarSystem.moons.ganymede.dimension.ChunkProviderGanymede", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Ganymede.DBMDefList)), + DimensionType.Planet)), Ceres(new ModDimensionDef( DimNames.CERES, "galaxyspace.SolarSystem.planets.ceres.dimension.ChunkProviderCeres", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Ceres.DBMDefList)), + DimensionType.Planet)), Deimos(new ModDimensionDef( DimNames.DEIMOS, "galaxyspace.SolarSystem.moons.deimos.dimension.ChunkProviderDeimos", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Deimos.DBMDefList)), + DimensionType.Planet)), Enceladus(new ModDimensionDef( DimNames.ENCELADUS, "galaxyspace.SolarSystem.moons.enceladus.dimension.ChunkProviderEnceladus", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Enceladus.DBMDefList)), + DimensionType.Planet)), Io(new ModDimensionDef( DimNames.IO, "galaxyspace.SolarSystem.moons.io.dimension.ChunkProviderIo", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Io.DBMDefList)), + DimensionType.Planet)), Europa(new ModDimensionDef( DimNames.EUROPA, "galaxyspace.SolarSystem.moons.europa.dimension.ChunkProviderEuropa", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Europa.DBMDefList)), + DimensionType.Planet)), Phobos(new ModDimensionDef( DimNames.PHOBOS, "galaxyspace.SolarSystem.moons.phobos.dimension.ChunkProviderPhobos", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Phobos.DBMDefList)), + DimensionType.Planet)), Venus(new ModDimensionDef( DimNames.VENUS, "galaxyspace.SolarSystem.planets.venus.dimension.ChunkProviderVenus", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Venus.DBMDefList)), + DimensionType.Planet)), Mercury(new ModDimensionDef( DimNames.MERCURY, "galaxyspace.SolarSystem.planets.mercury.dimension.ChunkProviderMercury", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Mercury.DBMDefList)), + DimensionType.Planet)), MakeMake(new ModDimensionDef( DimNames.MAKEMAKE, "galaxyspace.SolarSystem.planets.makemake.dimension.ChunkProviderMakemake", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.MakeMake.DBMDefList)), + DimensionType.Planet)), Haumea(new ModDimensionDef( DimNames.HAUMEA, "galaxyspace.SolarSystem.planets.haumea.dimension.ChunkProviderHaumea", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Haumea.DBMDefList)), + DimensionType.Planet)), CentauriAlpha(new ModDimensionDef( DimNames.CENTAURIA, "galaxyspace.ACentauriSystem.planets.aCentauriBb.dimension.ChunkProviderACentauri", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.CentauriAlpha.DBMDefList)), + DimensionType.Planet)), VegaB(new ModDimensionDef( DimNames.VEGAB, "galaxyspace.VegaSystem.planets.vegaB.dimension.ChunkProviderVegaB", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.VegaB.DBMDefList)), + DimensionType.Planet)), BarnardC(new ModDimensionDef( DimNames.BARNARDC, "galaxyspace.BarnardsSystem.planets.barnardaC.dimension.ChunkProviderBarnardaC", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.BarnardaC.DBMDefList)), + DimensionType.Planet)), BarnardE(new ModDimensionDef( DimNames.BARNARDE, "galaxyspace.BarnardsSystem.planets.barnardaE.dimension.ChunkProviderBarnardaE", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.BarnardaE.DBMDefList)), + DimensionType.Planet)), BarnardF(new ModDimensionDef( DimNames.BARNARDF, "galaxyspace.BarnardsSystem.planets.barnardaF.dimension.ChunkProviderBarnardaF", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.BarnardaF.DBMDefList)), + DimensionType.Planet)), TcetiE(new ModDimensionDef( DimNames.TCETIE, "galaxyspace.TCetiSystem.planets.tcetiE.dimension.ChunkProviderTCetiE", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.TcetiE.DBMDefList)), + DimensionType.Planet)), Miranda(new ModDimensionDef( DimNames.MIRANDA, "galaxyspace.SolarSystem.moons.miranda.dimension.ChunkProviderMiranda", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Miranda.DBMDefList)), + DimensionType.Planet)), KuiperBelt(new ModDimensionDef( DimNames.KUIPERBELT, "galaxyspace.SolarSystem.planets.kuiperbelt.dimension.ChunkProviderKuiper", - Enums.DimensionType.Asteroid)), + DimensionType.Asteroid) + .disableVoidMining()), Neper(new ModDimensionDef( DimNames.NEPER, "de.katzenpapst.amunra.world.neper.NeperChunkProvider", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Neper.DBMDefList)), + DimensionType.Planet)), Maahes(new ModDimensionDef( DimNames.MAAHES, "de.katzenpapst.amunra.world.maahes.MaahesChunkProvider", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Maahes.DBMDefList)), + DimensionType.Planet)), Anubis(new ModDimensionDef( DimNames.ANUBIS, "de.katzenpapst.amunra.world.anubis.AnubisChunkProvider", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Anubis.DBMDefList)), + DimensionType.Planet)), Horus(new ModDimensionDef( DimNames.HORUS, "de.katzenpapst.amunra.world.horus.HorusChunkProvider", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Horus.DBMDefList)), + DimensionType.Planet)), Seth(new ModDimensionDef( DimNames.SETH, "de.katzenpapst.amunra.world.seth.SethChunkProvider", - Enums.DimensionType.Planet, - DimensionBlockMetaDefinitionList.Seth.DBMDefList)), + DimensionType.Planet)), MehenBelt(new ModDimensionDef( DimNames.MEHENBELT, "de.katzenpapst.amunra.world.mehen.MehenChunkProvider", - Enums.DimensionType.Asteroid)); + DimensionType.Asteroid) + .disableVoidMining()), + + DeepDark(new ModDimensionDef( + DimNames.DEEPDARK, + "", + DimensionType.Planet)), + ; + // spotless:on + + public final ModDimensionDef modDimensionDef; + + DimensionDef(ModDimensionDef modDimDef) { + this.modDimensionDef = modDimDef; + } + + private static final Map DEF_BY_WORLD_NAME = new HashMap<>(); + + static { + for (DimensionDef def : values()) { + DEF_BY_WORLD_NAME.put(def.modDimensionDef.getDimensionName(), def.modDimensionDef); + } + } + + public static ModDimensionDef getDefByName(String worldName) { + return DEF_BY_WORLD_NAME.get(worldName); + } + + public static ModDimensionDef getDefForWorld(World world, int chunkX, int chunkZ) { + ModDimensionDef def = DEF_BY_WORLD_NAME.get(world.provider.getDimensionName()); + + if (def == null) return null; + + if (def.getDimensionName() + .equals(DimNames.THE_END)) { + if (chunkX * chunkX + chunkZ * chunkZ > 16 * 16) { + def = DimensionDef.EndAsteroids.modDimensionDef; + } + } + + return def; + } public static class DimNames { - public static final String ENDASTEROIDS = "EndAsteroids"; + public static final String OW = "Overworld"; + public static final String NETHER = "Nether"; + public static final String THE_END = "The End"; + public static final String ENDASTEROID = "EndAsteroid"; + public static final String TWILIGHT_FOREST = "Twilight Forest"; + public static final String EVERGLADES = "dimensionDarkWorld"; + public static final String MOON = "Moon"; public static final String MARS = "Mars"; public static final String ASTEROIDS = "Asteroids"; @@ -209,20 +272,14 @@ public static class DimNames { public static final String BARNARDF = "BarnardF"; public static final String TCETIE = "TcetiE"; public static final String MIRANDA = "Miranda"; - public static final String KUIPERBELT = "Kuiperbelt"; + public static final String KUIPERBELT = "Kuiper Belt"; public static final String NEPER = "Neper"; public static final String MAAHES = "Maahes"; public static final String ANUBIS = "Anubis"; public static final String HORUS = "Horus"; public static final String SETH = "Seth"; - public static final String MEHENBELT = "MehenBelt"; + public static final String MEHENBELT = "Mehen Belt"; public static final String DEEPDARK = "Underdark"; } - - public final ModDimensionDef modDimensionDef; - - DimensionDef(ModDimensionDef modDimDef) { - this.modDimensionDef = modDimDef; - } } diff --git a/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java b/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java index bf5fecc78ad..4af6ed0f4ef 100644 --- a/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java +++ b/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java @@ -2,46 +2,15 @@ public class AsteroidPropertyBuilder { + public boolean enabled = true; public int probability; public int sizeMin, sizeMax; public int specialBlockChance; - public OreSpawnPropertyBuilder oreSpawn; + public float oreDensityMultiplier = 1f; + public int smallOreChance = 10; public LootPropertyBuilder loot; - - public static class OreSpawnPropertyBuilder { - - public int baseOreChance; - public boolean obeyHeighLimits; - public boolean oresOnlyInsideAsteroids; - public int primaryToRareOreOffset; - public int smallOreChance; - - public OreSpawnPropertyBuilder baseOreChance(int baseOreChance) { - this.baseOreChance = baseOreChance; - return this; - } - - public OreSpawnPropertyBuilder doesObeyingHeightLimits(boolean obeyHeighLimits) { - this.obeyHeighLimits = obeyHeighLimits; - return this; - } - - public OreSpawnPropertyBuilder AreOresOnlyInsideAsteroids(boolean oresOnlyInsideAsteroids) { - this.oresOnlyInsideAsteroids = oresOnlyInsideAsteroids; - return this; - } - - public OreSpawnPropertyBuilder primaryToRareOreOffset(int primaryToRareOreOffset) { - this.primaryToRareOreOffset = primaryToRareOreOffset; - return this; - } - - public OreSpawnPropertyBuilder smallOreChance(int smallOreChance) { - this.smallOreChance = smallOreChance; - return this; - } - - } + public int positiveEllipsoids = 2, negativeEllipsoids = 2; + public int asteroidMinY = 50, asteroidMaxY = 100; public static class LootPropertyBuilder { @@ -73,10 +42,14 @@ public LootPropertyBuilder isLootItemCountRandomized(boolean randomizeLootItemCo } public AsteroidPropertyBuilder() { - oreSpawn = new OreSpawnPropertyBuilder(); loot = new LootPropertyBuilder(); } + public AsteroidPropertyBuilder enabled(boolean enabled) { + this.enabled = enabled; + return this; + } + public AsteroidPropertyBuilder probability(int probability) { this.probability = probability; return this; @@ -93,8 +66,29 @@ public AsteroidPropertyBuilder specialBlockChance(int specialBlockChance) { return this; } - public AsteroidPropertyBuilder oreSpawn(OreSpawnPropertyBuilder oreSpawnPropertyBuilder) { - this.oreSpawn = oreSpawnPropertyBuilder; + public AsteroidPropertyBuilder oreDensityMultiplier(float mult) { + this.oreDensityMultiplier = mult; + return this; + } + + public AsteroidPropertyBuilder smallOreChance(int smallOreChance) { + this.smallOreChance = smallOreChance; + return this; + } + + public AsteroidPropertyBuilder positiveEllipsoids(int positiveEllipsoids) { + this.positiveEllipsoids = positiveEllipsoids; + return this; + } + + public AsteroidPropertyBuilder negativeEllipsoids(int negativeEllipsoids) { + this.negativeEllipsoids = negativeEllipsoids; + return this; + } + + public AsteroidPropertyBuilder asteroidYBounds(int minY, int maxY) { + this.asteroidMinY = minY; + this.asteroidMaxY = maxY; return this; } diff --git a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java index 32020506cee..bd816537379 100644 --- a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java +++ b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java @@ -5,65 +5,51 @@ public enum Asteroids { - // spotless : off - EndAsteroids(ModContainers.Vanilla, DimensionDef.EndAsteroids, new AsteroidPropertyBuilder().probability(200) + // spotless:off + EndAsteroids(ModContainers.Vanilla, DimensionDef.EndAsteroids, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) - .oreSpawn( - new AsteroidPropertyBuilder.OreSpawnPropertyBuilder().baseOreChance(5) - .doesObeyingHeightLimits(false) - .AreOresOnlyInsideAsteroids(false) - .primaryToRareOreOffset(5) - .smallOreChance(10)) + .oreDensityMultiplier(0.5f) + .smallOreChance(10) + .negativeEllipsoids(0) .loot( new AsteroidPropertyBuilder.LootPropertyBuilder().lootChestChance(1) .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - KuiperBelt(ModContainers.GalaxySpace, DimensionDef.KuiperBelt, new AsteroidPropertyBuilder().probability(200) + Asteroids(ModContainers.GalacticraftMars, DimensionDef.Asteroids, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) - .oreSpawn( - new AsteroidPropertyBuilder.OreSpawnPropertyBuilder().baseOreChance(5) - .doesObeyingHeightLimits(false) - .AreOresOnlyInsideAsteroids(false) - .primaryToRareOreOffset(5) - .smallOreChance(10)) + .oreDensityMultiplier(0.5f) + .smallOreChance(10) .loot( new AsteroidPropertyBuilder.LootPropertyBuilder().lootChestChance(1) .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - MehenBelt(ModContainers.AmunRa, DimensionDef.MehenBelt, new AsteroidPropertyBuilder().probability(200) + KuiperBelt(ModContainers.GalaxySpace, DimensionDef.KuiperBelt, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) - .oreSpawn( - new AsteroidPropertyBuilder.OreSpawnPropertyBuilder().baseOreChance(5) - .doesObeyingHeightLimits(false) - .AreOresOnlyInsideAsteroids(false) - .primaryToRareOreOffset(5) - .smallOreChance(10)) + .oreDensityMultiplier(0.75f) + .smallOreChance(10) + .asteroidYBounds(50, 200) .loot( new AsteroidPropertyBuilder.LootPropertyBuilder().lootChestChance(1) .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - Asteroids(ModContainers.GalacticraftMars, DimensionDef.Asteroids, new AsteroidPropertyBuilder().probability(200) + MehenBelt(ModContainers.AmunRa, DimensionDef.MehenBelt, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) - .oreSpawn( - new AsteroidPropertyBuilder.OreSpawnPropertyBuilder().baseOreChance(5) - .doesObeyingHeightLimits(false) - .AreOresOnlyInsideAsteroids(false) - .primaryToRareOreOffset(5) - .smallOreChance(10)) + .oreDensityMultiplier(1f) + .smallOreChance(10) .loot( new AsteroidPropertyBuilder.LootPropertyBuilder().lootChestChance(1) .lootChestItemCount(10) .lootChestTable(3) - .isLootItemCountRandomized(true))),; - - // spotless : on + .isLootItemCountRandomized(true))), + ; + // spotless:on public ModContainers modContainers; public DimensionDef dimensionDef; diff --git a/src/main/java/galacticgreg/auxiliary/ConfigManager.java b/src/main/java/galacticgreg/auxiliary/ConfigManager.java index 6a972f24472..1cbff4282d3 100644 --- a/src/main/java/galacticgreg/auxiliary/ConfigManager.java +++ b/src/main/java/galacticgreg/auxiliary/ConfigManager.java @@ -14,7 +14,6 @@ public abstract class ConfigManager { private File _mainconfigDir = null; - private final File _blocksconfigDir = null; private String _mModCollection = ""; private String _mModID = ""; diff --git a/src/main/java/galacticgreg/auxiliary/GTOreGroup.java b/src/main/java/galacticgreg/auxiliary/GTOreGroup.java deleted file mode 100644 index bf5fb39c077..00000000000 --- a/src/main/java/galacticgreg/auxiliary/GTOreGroup.java +++ /dev/null @@ -1,19 +0,0 @@ -package galacticgreg.auxiliary; - -/** - * Just a simple container to wrap 4 GT Ore-Meta ids into one var - */ -public class GTOreGroup { - - public short PrimaryMeta; - public short SecondaryMeta; - public short SporadicBetweenMeta; - public short SporadicAroundMeta; - - public GTOreGroup(short pPrimaryMeta, short pSecondaryMeta, short pSporadicBetweenMeta, short pSporadicAroundMeta) { - PrimaryMeta = pPrimaryMeta; - SecondaryMeta = pSecondaryMeta; - SporadicBetweenMeta = pSporadicBetweenMeta; - SporadicAroundMeta = pSporadicAroundMeta; - } -} diff --git a/src/main/java/galacticgreg/auxiliary/GalacticGregConfig.java b/src/main/java/galacticgreg/auxiliary/GalacticGregConfig.java index 72b6bb87085..305555cc504 100644 --- a/src/main/java/galacticgreg/auxiliary/GalacticGregConfig.java +++ b/src/main/java/galacticgreg/auxiliary/GalacticGregConfig.java @@ -5,9 +5,11 @@ import net.minecraft.block.Block; import net.minecraft.init.Blocks; +import com.gtnewhorizon.gtnhlib.util.data.BlockMeta; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + import cpw.mods.fml.common.registry.GameRegistry; import galacticgreg.GalacticGreg; -import galacticgreg.api.BlockMetaComb; public class GalacticGregConfig extends ConfigManager { @@ -27,7 +29,7 @@ public GalacticGregConfig(File pConfigBaseDirectory, String pModCollectionDirect public String LootChestItemOverride; public boolean QuietMode; - public BlockMetaComb CustomLootChest; + public ImmutableBlockMeta CustomLootChest; @Override protected void PreInit() { @@ -106,7 +108,7 @@ protected void PostInit() { } public boolean serverPostInit() { - CustomLootChest = new BlockMetaComb(Blocks.chest); + CustomLootChest = new BlockMeta(Blocks.chest); try { if (LootChestItemOverride != null && !LootChestItemOverride.isEmpty()) { String[] args = LootChestItemOverride.split(":"); @@ -124,7 +126,7 @@ public boolean serverPostInit() { if (tBlock != null) { GalacticGreg.Logger .debug("Found valid ChestOverride: %s. LootChest replaced", LootChestItemOverride); - CustomLootChest = new BlockMetaComb(tBlock, tMeta); + CustomLootChest = new BlockMeta(tBlock, tMeta); } } } diff --git a/src/main/java/galacticgreg/command/ProfilingCommand.java b/src/main/java/galacticgreg/command/ProfilingCommand.java index 402006d1cab..df24371fee1 100644 --- a/src/main/java/galacticgreg/command/ProfilingCommand.java +++ b/src/main/java/galacticgreg/command/ProfilingCommand.java @@ -50,7 +50,6 @@ public void processCommand(ICommandSender pCommandSender, String[] pArgs) { pCommandSender.addChatMessage(new ChatComponentText("Average OreGen times:")); for (ModContainer mc : GalacticGregRegistry.getModContainers()) { - String tModName = mc.getModName(); for (ModDimensionDef mdd : mc.getDimensionList()) { long tTime = GalacticGreg.Profiler.GetAverageTime(mdd); String tInfo; @@ -85,9 +84,8 @@ public int compareTo(Object o) { return 0; } - @SuppressWarnings("rawtypes") @Override - public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) { + public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) { return null; } diff --git a/src/main/java/galacticgreg/command/WorldgenCommand.java b/src/main/java/galacticgreg/command/WorldgenCommand.java new file mode 100644 index 00000000000..59a29fbd58a --- /dev/null +++ b/src/main/java/galacticgreg/command/WorldgenCommand.java @@ -0,0 +1,114 @@ +package galacticgreg.command; + +import java.util.List; + +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import com.google.common.collect.ImmutableList; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import galacticgreg.WorldGeneratorSpace; +import galacticgreg.WorldGeneratorSpace.AsteroidGenerator; +import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.enums.DimensionDef; +import galacticgreg.dynconfig.DynamicDimensionConfig; +import galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; + +public class WorldgenCommand implements ICommand { + + @Override + public String getCommandName() { + return "asteroid"; + } + + @Override + public String getCommandUsage(ICommandSender pCommandSender) { + return "asteroid"; + } + + @Override + public List getCommandAliases() { + return ImmutableList.of(); + } + + @Override + public void processCommand(ICommandSender pCommandSender, String[] pArgs) { + if (pArgs.length < 1) return; + + World world = pCommandSender.getEntityWorld(); + int chunkX = pCommandSender.getPlayerCoordinates().posX >> 4; + int chunkZ = pCommandSender.getPlayerCoordinates().posZ >> 4; + + ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world, chunkX, chunkZ); + AsteroidConfig asteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); + + switch (pArgs[0]) { + case "spawns" -> { + boolean spawns = WorldGeneratorSpace.generatesAsteroid( + world.getSeed(), + chunkX, + chunkZ, + world.provider.dimensionId, + asteroidConfig.Probability); + + pCommandSender.addChatMessage(new ChatComponentText("spawns: " + spawns)); + } + case "generate" -> { + for (int offsetZ = -2; offsetZ <= 2; offsetZ++) { + for (int offsetX = -2; offsetX <= 2; offsetX++) { + AsteroidGenerator gen = AsteroidGenerator.forChunk(world, chunkX + offsetX, chunkZ + offsetZ); + + if (gen == null) { + continue; + } + + pCommandSender.addChatMessage( + new ChatComponentText( + "found asteroid seed at " + (chunkX + offsetX) + ", " + (chunkZ + offsetZ))); + + gen.generateChunk(world, chunkX, chunkZ); + } + } + } + default -> {} + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) { + if (FMLCommonHandler.instance() + .getEffectiveSide() == Side.SERVER + && !FMLCommonHandler.instance() + .getMinecraftServerInstance() + .isDedicatedServer()) + return true; + + if (pCommandSender instanceof EntityPlayerMP tEP) { + return MinecraftServer.getServer() + .getConfigurationManager() + .func_152596_g(tEP.getGameProfile()); + } + return false; + } + + @Override + public int compareTo(Object o) { + return 0; + } + + @Override + public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) { + return null; + } + + @Override + public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { + return false; + } +} diff --git a/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java b/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java index d63d403971a..6ca5868bd17 100644 --- a/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java +++ b/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java @@ -16,15 +16,18 @@ public class DynamicDimensionConfig { public static class AsteroidConfig { + public boolean Enabled; public int MinSize; public int MaxSize; public int Probability; + public int PositiveEllipsoids; + public int NegativeEllipsoids; + public int AsteroidMinY; + public int AsteroidMaxY; + public float OreDensityMultiplier; public int OreChance; - public int OrePrimaryOffset; - public int SpecialBlockChance; public int SmallOreChance; - public boolean ObeyHeightLimits; - public boolean HiddenOres; + public int SpecialBlockChance; public int LootChestChance; public int LootChestTable; public int NumLootItems; @@ -80,17 +83,18 @@ public static boolean InitDynamicConfig() { AsteroidConfig aConf = new AsteroidConfig(); + aConf.Enabled = AsteroidProperties.asteroidPropertyBuilder.enabled; aConf.MinSize = AsteroidProperties.asteroidPropertyBuilder.sizeMin; aConf.MaxSize = AsteroidProperties.asteroidPropertyBuilder.sizeMax; aConf.Probability = AsteroidProperties.asteroidPropertyBuilder.probability; + aConf.PositiveEllipsoids = AsteroidProperties.asteroidPropertyBuilder.positiveEllipsoids; + aConf.NegativeEllipsoids = AsteroidProperties.asteroidPropertyBuilder.negativeEllipsoids; + aConf.AsteroidMinY = AsteroidProperties.asteroidPropertyBuilder.asteroidMinY; + aConf.AsteroidMaxY = AsteroidProperties.asteroidPropertyBuilder.asteroidMaxY; + aConf.OreDensityMultiplier = AsteroidProperties.asteroidPropertyBuilder.oreDensityMultiplier; + aConf.SmallOreChance = AsteroidProperties.asteroidPropertyBuilder.smallOreChance; aConf.SpecialBlockChance = AsteroidProperties.asteroidPropertyBuilder.specialBlockChance; - aConf.OreChance = AsteroidProperties.asteroidPropertyBuilder.oreSpawn.baseOreChance; - aConf.OrePrimaryOffset = AsteroidProperties.asteroidPropertyBuilder.oreSpawn.primaryToRareOreOffset; - aConf.SmallOreChance = AsteroidProperties.asteroidPropertyBuilder.oreSpawn.smallOreChance; - aConf.ObeyHeightLimits = AsteroidProperties.asteroidPropertyBuilder.oreSpawn.obeyHeighLimits; - aConf.HiddenOres = AsteroidProperties.asteroidPropertyBuilder.oreSpawn.oresOnlyInsideAsteroids; - if (GalacticGreg.GalacticConfig.LootChestsEnabled) { aConf.LootChestChance = AsteroidProperties.asteroidPropertyBuilder.loot.lootChestChance; aConf.LootChestTable = AsteroidProperties.asteroidPropertyBuilder.loot.lootChestTable; diff --git a/src/main/java/galacticgreg/registry/GalacticGregRegistry.java b/src/main/java/galacticgreg/registry/GalacticGregRegistry.java index ee12baeb170..10f3836ba4c 100644 --- a/src/main/java/galacticgreg/registry/GalacticGregRegistry.java +++ b/src/main/java/galacticgreg/registry/GalacticGregRegistry.java @@ -4,14 +4,10 @@ import java.util.HashMap; import java.util.Map; -import net.minecraft.world.chunk.IChunkProvider; - import galacticgreg.GalacticGreg; -import galacticgreg.api.Enums.DimensionType; import galacticgreg.api.ModContainer; import galacticgreg.api.ModDimensionDef; import galacticgreg.dynconfig.DynamicDimensionConfig; -import galacticgreg.generators.GenEllipsoid; /** * GalacticGregs registry @@ -46,35 +42,6 @@ public static void registerModContainer(ModContainer modContainer) { modContainers.put(modContainer.getModName(), modContainer); } - /** - * Lookup the registered dimensions and try to find the DimensionDefinition that has the ChunkProvider that we have - * here - */ - public static ModDimensionDef getDimensionTypeByChunkGenerator(IChunkProvider chunkProvider) { - try { - if (!initializationDone) return null; - - String tFQCPN = chunkProvider.toString() - .split("@")[0]; - ModDimensionDef tReturnMDD = null; - - for (ModContainer mc : modContainers.values()) { - for (ModDimensionDef mdd : mc.getDimensionList()) { - if (mdd.getChunkProviderName() - .equals(tFQCPN)) { - tReturnMDD = mdd; - break; - } - } - } - - return tReturnMDD; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - /** * Get all registered modcontainers. Can only be done after the initialization process is done */ @@ -98,7 +65,7 @@ public static boolean InitRegistry() { } /** - * Parse modcontainers and search for loaded mods. Enable found mods for generation + * Currently only prints some debug logs. Keeping this because it could be useful in the future. */ private static void InitModContainers() { for (ModContainer mc : modContainers.values()) { @@ -114,29 +81,10 @@ private static void InitModContainers() { for (ModDimensionDef md : mc.getDimensionList()) { GalacticGreg.Logger.info( - "ModID: [%s] DimName: [%s] ValidBlocks: [%d] Identifier: [%s] Generators: [%d]", + "ModID: [%s] DimName: [%s] Identifier: [%s]", mc.getModName(), md.getDimensionName(), - md.getReplaceableBlocks() - .size(), - md.getDimIdentifier(), - md.getSpaceObjectGenerators() - .size()); - - // Register default generator if dimension is asteroid and no generator was added - if (md.getDimensionType() == DimensionType.Asteroid) { - if (md.getSpaceObjectGenerators() - .isEmpty()) { - GalacticGreg.Logger.debug("No generators found, adding built-in ellipsoid generator"); - md.registerSpaceObjectGenerator(new GenEllipsoid()); - } - GalacticGreg.Logger.info( - "Asteroid-Enabled dimension. Registered Generators: [%d]", - md.getSpaceObjectGenerators() - .size()); - } - - md.finalizeReplaceableBlocks(mc.getModName()); + md.getDimIdentifier()); } } initializationDone = true; diff --git a/src/main/java/galacticgreg/schematics/SpaceSchematic.java b/src/main/java/galacticgreg/schematics/SpaceSchematic.java index 976b699e858..bed2b0cd294 100644 --- a/src/main/java/galacticgreg/schematics/SpaceSchematic.java +++ b/src/main/java/galacticgreg/schematics/SpaceSchematic.java @@ -90,7 +90,7 @@ public BaseStructureInfo(StructureInformation pSI) { pSI.getBlock() .getBlock()); blockMeta = pSI.getBlock() - .getMeta(); + .getBlockMeta(); } public Vec3 getVec3Pos() { diff --git a/src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java b/src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java index 06ffd079d29..d0871563deb 100644 --- a/src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java +++ b/src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java @@ -6,9 +6,11 @@ import net.minecraft.block.Block; import net.minecraft.util.Vec3; +import com.gtnewhorizon.gtnhlib.util.data.BlockMeta; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + import cpw.mods.fml.common.registry.GameRegistry; import galacticgreg.GalacticGreg; -import galacticgreg.api.BlockMetaComb; import galacticgreg.api.Enums.SpaceObjectType; import galacticgreg.api.Enums.TargetBlockPosition; import galacticgreg.api.ISpaceObjectGenerator; @@ -47,7 +49,7 @@ private void RecalculatePosition() { Block tBlock = GameRegistry.findBlock(tModID, tBlockName); if (tBlock != null) { - BlockMetaComb bmc = new BlockMetaComb(tBlock, bsi.blockMeta); + ImmutableBlockMeta bmc = new BlockMeta(tBlock, bsi.blockMeta); Vec3 tCenteredPos = _mCenter.addVector(bsi.posX, bsi.posY, bsi.posZ); StructureInformation tnewSI = new StructureInformation( tCenteredPos, diff --git a/src/main/java/gregtech/GTMod.java b/src/main/java/gregtech/GTMod.java index 63e7d02c436..925d0c87bc6 100644 --- a/src/main/java/gregtech/GTMod.java +++ b/src/main/java/gregtech/GTMod.java @@ -61,6 +61,7 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.Mods; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; import gregtech.api.enums.Textures; import gregtech.api.gui.modularui.GTUIInfos; import gregtech.api.interfaces.internal.IGTMod; @@ -434,6 +435,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) { new CropLoader().run(); new GTWorldgenloader().run(); new CoverLoader().run(); + StoneType.init(); GTRecipeRegistrator.registerUsagesForMaterials( null, diff --git a/src/main/java/gregtech/api/GregTechAPI.java b/src/main/java/gregtech/api/GregTechAPI.java index a888078cd02..5876cf3c257 100644 --- a/src/main/java/gregtech/api/GregTechAPI.java +++ b/src/main/java/gregtech/api/GregTechAPI.java @@ -227,7 +227,7 @@ public class GregTechAPI { */ public static Block sBlockMachines; - public static Block sBlockOres1, sBlockOresUb1, sBlockOresUb2, sBlockOresUb3, + public static Block sBlockOres1, /* sBlockGem, */ sBlockMetal1, sBlockMetal2, sBlockMetal3, sBlockMetal4, sBlockMetal5, sBlockMetal6, sBlockMetal7, sBlockMetal8, sBlockMetal9, sBlockGem1, sBlockGem2, sBlockGem3, sBlockReinforced; diff --git a/src/main/java/gregtech/api/enums/GTValues.java b/src/main/java/gregtech/api/enums/GTValues.java index 4223a7ed3fe..9b9c6c4311b 100644 --- a/src/main/java/gregtech/api/enums/GTValues.java +++ b/src/main/java/gregtech/api/enums/GTValues.java @@ -366,10 +366,6 @@ public static final class NBT { * For Internal Usage (Network) */ public static IGT_NetworkHandler NW; - /** - * Control percentage of filled 3x3 chunks. Lower number means less oreveins spawn - */ - public static int oreveinPercentage; /** * Control number of attempts to find a valid orevein. Generally this maximum limit isn't hit, selecting a vein is * cheap @@ -407,6 +403,10 @@ public static final class NBT { * Debug parameter for world generation. Tracks chunks added/removed from run queue. */ public static boolean debugWorldGen = false; + /** + * Debug parameter for world generation. Measures amount of time taken to generate oreveins, stone, etc. + */ + public static boolean profileWorldGen = true; /** * Debug parameter for orevein generation. */ diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index 85aeefdf905..c9be9c0ffd5 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -30,6 +30,8 @@ import gregtech.api.fluid.GTFluidFactory; import gregtech.api.interfaces.IColorModulationContainer; import gregtech.api.interfaces.IMaterialHandler; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneType; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.objects.MaterialStack; import gregtech.api.util.GTOreDictUnificator; @@ -47,7 +49,7 @@ import gregtech.loaders.materials.MaterialsInit1; @SuppressWarnings("unused") // API Legitimately has unused Members and Methods -public class Materials implements IColorModulationContainer, ISubTagContainer { +public class Materials implements IColorModulationContainer, ISubTagContainer, IOreMaterial { public static final List mMaterialHandlers = new ArrayList<>(); private static final Map MATERIALS_MAP = new LinkedHashMap<>(); @@ -2518,6 +2520,22 @@ private static void initSubTags() { Boron.add(SubTag.SMELTING_TO_FLUID); MaterialsUEVplus.TranscendentMetal.add(SubTag.BLACK_HOLE); + + Hydrogen.add(SubTag.ICE_ORE); + Nitrogen.add(SubTag.ICE_ORE); + Oxygen.add(SubTag.ICE_ORE); + Methane.add(SubTag.ICE_ORE); + CarbonDioxide.add(SubTag.ICE_ORE); + SulfurDioxide.add(SubTag.ICE_ORE); + Ammonia.add(SubTag.ICE_ORE); + + Hydrogen.setOreMultiplier(4); + Nitrogen.setOreMultiplier(4); + Oxygen.setOreMultiplier(4); + Methane.setOreMultiplier(4); + CarbonDioxide.setOreMultiplier(4); + SulfurDioxide.setOreMultiplier(4); + Ammonia.setOreMultiplier(4); } public static void init() { @@ -3045,11 +3063,48 @@ public short[] getRGBA() { return mRGBa; } + @Override + public TextureSet getTextureSet() { + return mIconSet; + } + @Override public String toString() { return this.mName; } + @Override + public String getLocalizedName() { + return mLocalizedName; + } + + @Override + public int getId() { + return mMetaItemSubID; + } + + public boolean isValidForStone(IStoneType stoneType) { + if (contains(SubTag.ICE_ORE)) { + return stoneType.getCategory() == StoneCategory.Ice; + } else { + return stoneType.getCategory() == StoneCategory.Stone; + } + } + + @Override + public List getValidStones() { + if (contains(SubTag.ICE_ORE)) { + return StoneType.ICES; + } else { + return StoneType.STONES; + } + } + + @Override + public String getInternalName() { + return mName; + } + public String getDefaultLocalizedNameForItem(String aFormat) { try { return String.format( diff --git a/src/main/java/gregtech/api/enums/Mods.java b/src/main/java/gregtech/api/enums/Mods.java index 366ee45eb0b..15a0f84b8fb 100644 --- a/src/main/java/gregtech/api/enums/Mods.java +++ b/src/main/java/gregtech/api/enums/Mods.java @@ -4,9 +4,11 @@ import net.minecraft.util.ResourceLocation; +import com.gtnewhorizon.gtnhlib.util.data.IMod; + import cpw.mods.fml.common.Loader; -public enum Mods { +public enum Mods implements IMod { AE2FluidCraft(Names.A_E2_FLUID_CRAFT), AE2Stuff(Names.AE2STUFF), @@ -110,7 +112,13 @@ public enum Mods { MalisisDoors(Names.MALISIS_DOORS), Mantle(Names.MANTLE), MineAndBladeBattleGear2(Names.MINE_AND_BLADE_BATTLE_GEAR2), - Minecraft(Names.MINECRAFT), + Minecraft(Names.MINECRAFT) { + + @Override + public boolean isModLoaded() { + return true; + } + }, MineTweaker(Names.MINE_TWEAKER), MobsInfo(Names.MOBS_INFO), NEICustomDiagrams(Names.N_E_I_CUSTOM_DIAGRAMS), @@ -382,11 +390,21 @@ public boolean isModLoaded() { return this.modLoaded; } + @Override + public String getID() { + return ID; + } + public String getResourcePath(String... path) { return this.getResourceLocation(path) .toString(); } + @Override + public String getResourceLocation() { + return resourceDomain; + } + public ResourceLocation getResourceLocation(String... path) { return new ResourceLocation(this.resourceDomain, String.join("/", path)); } diff --git a/src/main/java/gregtech/api/enums/OreMixes.java b/src/main/java/gregtech/api/enums/OreMixes.java index bb45886c21d..2e703af3d21 100644 --- a/src/main/java/gregtech/api/enums/OreMixes.java +++ b/src/main/java/gregtech/api/enums/OreMixes.java @@ -1,15 +1,23 @@ package gregtech.api.enums; import static galacticgreg.api.enums.DimensionDef.*; -import static gregtech.common.OreMixBuilder.NETHER; -import static gregtech.common.OreMixBuilder.OW; -import static gregtech.common.OreMixBuilder.THE_END; -import static gregtech.common.OreMixBuilder.TWILIGHT_FOREST; - -import galacticgreg.WorldgenOreLayerSpace; +import static galacticgreg.api.enums.DimensionDef.DimNames.ASTEROIDS; +import static galacticgreg.api.enums.DimensionDef.DimNames.EVERGLADES; +import static galacticgreg.api.enums.DimensionDef.DimNames.KUIPERBELT; +import static galacticgreg.api.enums.DimensionDef.DimNames.NETHER; +import static galacticgreg.api.enums.DimensionDef.DimNames.OW; +import static galacticgreg.api.enums.DimensionDef.DimNames.ROSS128B; +import static galacticgreg.api.enums.DimensionDef.DimNames.ROSS128BA; +import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; +import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; + +import bartworks.system.material.WerkstoffLoader; import galacticgreg.api.enums.DimensionDef; import gregtech.common.OreMixBuilder; import gregtech.common.WorldgenGTOreLayer; +import gtPlusPlus.core.material.MaterialsElements; +import gtPlusPlus.core.material.MaterialsOres; +import gtPlusPlus.core.material.nuclear.MaterialsFluorides; public enum OreMixes { @@ -240,7 +248,7 @@ public enum OreMixes { .weight(5) .density(2) .size(16) - .enableInDim(EndAsteroids, Maahes, MehenBelt) + .enableInDim(EndAsteroids, Asteroids, Maahes, MehenBelt) .primary(Materials.Cooperite) .secondary(Materials.Palladium) .inBetween(Materials.Platinum) @@ -378,7 +386,8 @@ public enum OreMixes { .weight(60) .density(2) .size(16) - .enableInDim(TcetiE.modDimensionDef.getDimensionName(), OW, OreMixBuilder.TWILIGHT_FOREST) + .enableInDim(TcetiE) + .enableInDim(OW, TWILIGHT_FOREST) .primary(Materials.Apatite) .secondary(Materials.Apatite) .inBetween(Materials.TricalciumPhosphate) @@ -413,7 +422,7 @@ public enum OreMixes { .weight(30) .density(2) .size(16) - .enableInDim(OreMixBuilder.NETHER, OreMixBuilder.THE_END) + .enableInDim(NETHER, THE_END) .enableInDim(EndAsteroids, Mars, BarnardF, CentauriAlpha, Ceres, Haumea, MakeMake, Pluto, Titan, Venus) .primary(Materials.Beryllium) .secondary(Materials.Beryllium) @@ -470,7 +479,8 @@ public enum OreMixes { .weight(16) .density(2) .size(16) - .enableInDim(Neper.modDimensionDef.getDimensionName(), OreMixBuilder.TWILIGHT_FOREST) + .enableInDim(Neper) + .enableInDim(TWILIGHT_FOREST) .primary(Materials.InfusedWater) .secondary(Materials.InfusedFire) .inBetween(Materials.Amber) @@ -593,7 +603,7 @@ public enum OreMixes { .weight(10) .density(2) .size(16) - .enableInDim(MehenBelt, Seth, Callisto, Ceres, Ganymede, Io, KuiperBelt, Mercury, Oberon, Pluto) + .enableInDim(Asteroids, MehenBelt, Seth, Callisto, Ceres, Ganymede, Io, KuiperBelt, Mercury, Oberon, Pluto) .primary(Materials.Platinum) .secondary(Materials.Chrome) .inBetween(Materials.Cooperite) @@ -998,7 +1008,485 @@ public enum OreMixes { .primary(Materials.TengamRaw) .secondary(Materials.TengamRaw) .inBetween(Materials.Electrotine) - .sporadic(Materials.Samarium)); + .sporadic(Materials.Samarium)), + + NitrogenIce(new OreMixBuilder().name("ore.mix.nitrogenice") + .heightRange(30, 180) + .weight(80) + .density(2) + .size(16) + .enableInDim(ASTEROIDS, KUIPERBELT) + .primary(Materials.Nitrogen) + .secondary(Materials.Ammonia) + .inBetween(Materials.Hydrogen) + .sporadic(Materials.Hydrogen) + .stoneCategory(StoneCategory.Ice)), + + HydrocarbonIce(new OreMixBuilder().name("ore.mix.hydrocarbonice") + .heightRange(30, 180) + .weight(40) + .density(2) + .size(12) + .enableInDim(ASTEROIDS, KUIPERBELT) + .primary(Materials.Methane) + .secondary(Materials.Hydrogen) + .inBetween(Materials.Carbon) + .sporadic(Materials.Carbon) + .stoneCategory(StoneCategory.Ice)), + + CarbonIce(new OreMixBuilder().name("ore.mix.carbonice") + .heightRange(30, 180) + .weight(40) + .density(2) + .size(12) + .enableInDim(ASTEROIDS, KUIPERBELT) + .primary(Materials.CarbonDioxide) + .secondary(Materials.Oxygen) + .inBetween(Materials.Carbon) + .sporadic(Materials.Carbon) + .stoneCategory(StoneCategory.Ice)), + + HHOIce(new OreMixBuilder().name("ore.mix.hhoice") + .heightRange(30, 180) + .weight(80) + .density(2) + .size(16) + .enableInDim(ASTEROIDS, KUIPERBELT) + .primary(Materials.Oxygen) + .secondary(Materials.Hydrogen) + .inBetween(Materials.Oxygen) + .sporadic(Materials.Hydrogen) + .stoneCategory(StoneCategory.Ice)), + + SulfurIce(new OreMixBuilder().name("ore.mix.sulfurice") + .heightRange(30, 180) + .weight(20) + .density(2) + .size(8) + .enableInDim(ASTEROIDS, KUIPERBELT) + .primary(Materials.SulfurDioxide) + .secondary(Materials.Oxygen) + .inBetween(Materials.Sulfur) + .sporadic(Materials.Oxygen) + .stoneCategory(StoneCategory.Ice)), + + GTPP0(new OreMixBuilder().name("ore.mix.gtpp0") + .heightRange(20, 40) + .weight(1) + .density(1) + .size(128) + .enableInDim(EVERGLADES) + .primary(Materials.Iron) + .secondary(Materials.Iron) + .inBetween(Materials.Iron) + .sporadic(Materials.Iron)), + + GTPP1(new OreMixBuilder().name("ore.mix.gtpp1") + .heightRange(0, 60) + .weight(30) + .density(2) + .size(16) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.AGARDITE_CD) + .secondary(MaterialsOres.AGARDITE_LA) + .inBetween(MaterialsOres.DEMICHELEITE_BR) + .sporadic(MaterialsOres.IRARSITE)), + + GTPP2(new OreMixBuilder().name("ore.mix.gtpp2") + .heightRange(0, 60) + .weight(30) + .density(2) + .size(16) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.AGARDITE_ND) + .secondary(MaterialsOres.AGARDITE_Y) + .inBetween(MaterialsOres.KASHINITE) + .sporadic(MaterialsOres.CERITE)), + + GTPP3(new OreMixBuilder().name("ore.mix.gtpp3") + .heightRange(0, 60) + .weight(30) + .density(3) + .size(32) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.CERITE) + .secondary(MaterialsOres.NICHROMITE) + .inBetween(MaterialsOres.XENOTIME) + .sporadic(MaterialsOres.HIBONITE)), + + GTPP4(new OreMixBuilder().name("ore.mix.gtpp4") + .heightRange(0, 60) + .weight(40) + .density(3) + .size(32) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.GEIKIELITE) + .secondary(MaterialsOres.CRYOLITE) + .inBetween(MaterialsOres.GADOLINITE_CE) + .sporadic(MaterialsOres.AGARDITE_ND)), + + GTPP5(new OreMixBuilder().name("ore.mix.gtpp5") + .heightRange(30, 128) + .weight(20) + .density(2) + .size(48) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.HIBONITE) + .secondary(MaterialsOres.YTTRIALITE) + .inBetween(MaterialsOres.ZIRCONILITE) + .sporadic(MaterialsOres.CERITE)), + + GTPP6(new OreMixBuilder().name("ore.mix.gtpp6") + .heightRange(0, 40) + .weight(20) + .density(2) + .size(48) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.XENOTIME) + .secondary(MaterialsOres.ZIRKELITE) + .inBetween(MaterialsOres.CROCROITE) + .sporadic(MaterialsOres.IRARSITE)), + + GTPP7(new OreMixBuilder().name("ore.mix.gtpp7") + .heightRange(40, 128) + .weight(20) + .density(2) + .size(48) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.HONEAITE) + .secondary(MaterialsOres.MIESSIITE) + .inBetween(MaterialsOres.SAMARSKITE_Y) + .sporadic(MaterialsOres.SAMARSKITE_YB)), + + GTPP8(new OreMixBuilder().name("ore.mix.gtpp8") + .heightRange(0, 40) + .weight(20) + .density(2) + .size(48) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.TITANITE) + .secondary(MaterialsOres.ZIMBABWEITE) + .inBetween(MaterialsOres.ZIRCON) + .sporadic(MaterialsOres.FLORENCITE)), + + GTPP9(new OreMixBuilder().name("ore.mix.gtpp9") + .heightRange(10, 30) + .weight(20) + .density(1) + .size(48) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.LANTHANITE_CE) + .secondary(MaterialsFluorides.FLUORITE) + .inBetween(MaterialsOres.LAFOSSAITE) + .sporadic(MaterialsOres.FLORENCITE)), + + GTPP10(new OreMixBuilder().name("ore.mix.gtpp10") + .heightRange(20, 50) + .weight(20) + .density(2) + .size(32) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.GEIKIELITE) + .secondary(MaterialsOres.YTTROCERITE) + .inBetween(MaterialsOres.LANTHANITE_LA) + .sporadic(MaterialsOres.RADIOBARITE)), + + GTPP11(new OreMixBuilder().name("ore.mix.gtpp11") + .heightRange(30, 70) + .weight(20) + .density(1) + .size(48) + .enableInDim(EVERGLADES) + .primary(MaterialsFluorides.FLUORITE) + .secondary(MaterialsOres.KASHINITE) + .inBetween(MaterialsOres.ZIRCON) + .sporadic(MaterialsOres.CRYOLITE)), + + GTPP12(new OreMixBuilder().name("ore.mix.gtpp12") + .heightRange(40, 80) + .weight(20) + .density(3) + .size(32) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.CERITE) + .secondary(MaterialsOres.ALBURNITE) + .inBetween(MaterialsOres.MIESSIITE) + .sporadic(MaterialsOres.HIBONITE)), + + GTPP13(new OreMixBuilder().name("ore.mix.gtpp13") + .heightRange(5, 15) + .weight(5) + .density(1) + .size(16) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.CRYOLITE) + .secondary(MaterialsOres.RADIOBARITE) + .inBetween(MaterialsOres.HONEAITE) + .sporadic(MaterialsOres.FLORENCITE)), + + GTPP14(new OreMixBuilder().name("ore.mix.gtpp14") + .heightRange(10, 20) + .weight(8) + .density(2) + .size(16) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.DEMICHELEITE_BR) + .secondary(MaterialsOres.PERROUDITE) + .inBetween(MaterialsOres.IRARSITE) + .sporadic(MaterialsOres.RADIOBARITE)), + + GTPP15(new OreMixBuilder().name("ore.mix.gtpp15") + .heightRange(5, 25) + .weight(5) + .density(3) + .size(24) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.FLUORCAPHITE) + .secondary(MaterialsOres.LAFOSSAITE) + .inBetween(MaterialsOres.GADOLINITE_CE) + .sporadic(MaterialsOres.GADOLINITE_Y)), + + GTPP16(new OreMixBuilder().name("ore.mix.gtpp16") + .heightRange(0, 25) + .weight(4) + .density(2) + .size(32) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.YTTROCERITE) + .secondary(MaterialsOres.LEPERSONNITE) + .inBetween(MaterialsOres.LAUTARITE) + .sporadic(MaterialsFluorides.FLUORITE)), + + GTPP17(new OreMixBuilder().name("ore.mix.gtpp17") + .heightRange(10, 35) + .weight(4) + .density(1) + .size(32) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.FLORENCITE) + .secondary(MaterialsOres.LAUTARITE) + .inBetween(MaterialsOres.SAMARSKITE_YB) + .sporadic(MaterialsOres.POLYCRASE)), + + GTPP18(new OreMixBuilder().name("ore.mix.gtpp18") + .heightRange(15, 40) + .weight(4) + .density(1) + .size(48) + .enableInDim(EVERGLADES) + .primary(MaterialsOres.GADOLINITE_CE) + .secondary(MaterialsOres.GADOLINITE_Y) + .inBetween(MaterialsOres.AGARDITE_LA) + .sporadic(MaterialsOres.AGARDITE_CD)), + + GTPP19(new OreMixBuilder().name("ore.mix.gtpp19") + .heightRange(0, 20) + .weight(4) + .density(1) + .size(16) + .enableInDim(EVERGLADES) + .primary(MaterialsElements.STANDALONE.RUNITE) + .secondary(MaterialsElements.STANDALONE.RUNITE) + .inBetween(MaterialsElements.STANDALONE.RUNITE) + .sporadic(MaterialsElements.STANDALONE.RUNITE)), + + Thorianit(new OreMixBuilder().name("ore.mix.ross128.Thorianit") + .heightRange(30, 60) + .weight(17) + .density(1) + .size(16) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Thorianit) + .secondary(Materials.Uraninite) + .inBetween(Materials.Lepidolite) + .sporadic(Materials.Spodumene)), + + RossCarbon(new OreMixBuilder().name("ore.mix.ross128.carbon") + .heightRange(5, 25) + .weight(5) + .density(4) + .size(12) + .enableInDim(ROSS128B) + .primary(Materials.Graphite) + .secondary(Materials.Diamond) + .inBetween(Materials.Coal) + .sporadic(Materials.Graphite)), + + Bismuth(new OreMixBuilder().name("ore.mix.ross128.bismuth") + .heightRange(5, 80) + .weight(30) + .density(1) + .size(16) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Bismuthinit) + .secondary(Materials.Stibnite) + .inBetween(Materials.Bismuth) + .sporadic(WerkstoffLoader.Bismutite)), + + TurmalinAlkali(new OreMixBuilder().name("ore.mix.ross128.TurmalinAlkali") + .heightRange(5, 80) + .weight(15) + .density(4) + .size(48) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Olenit) + .secondary(WerkstoffLoader.FluorBuergerit) + .inBetween(WerkstoffLoader.ChromoAluminoPovondrait) + .sporadic(WerkstoffLoader.VanadioOxyDravit)), + + Roquesit(new OreMixBuilder().name("ore.mix.ross128.Roquesit") + .heightRange(30, 50) + .weight(3) + .density(1) + .size(12) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Arsenopyrite) + .secondary(WerkstoffLoader.Ferberite) + .inBetween(WerkstoffLoader.Loellingit) + .sporadic(WerkstoffLoader.Roquesit)), + + RossTungstate(new OreMixBuilder().name("ore.mix.ross128.Tungstate") + .heightRange(5, 40) + .weight(10) + .density(4) + .size(14) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Ferberite) + .secondary(WerkstoffLoader.Huebnerit) + .inBetween(WerkstoffLoader.Loellingit) + .sporadic(Materials.Scheelite)), + + CopperSulfits(new OreMixBuilder().name("ore.mix.ross128.CopperSulfits") + .heightRange(40, 70) + .weight(80) + .density(3) + .size(24) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Djurleit) + .secondary(WerkstoffLoader.Bornite) + .inBetween(WerkstoffLoader.Wittichenit) + .sporadic(Materials.Tetrahedrite)), + + Forsterit(new OreMixBuilder().name("ore.mix.ross128.Forsterit") + .heightRange(20, 90) + .weight(50) + .density(2) + .size(32) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Forsterit) + .secondary(WerkstoffLoader.Fayalit) + .inBetween(WerkstoffLoader.DescloiziteCUVO4) + .sporadic(WerkstoffLoader.DescloiziteZNVO4)), + + Hedenbergit(new OreMixBuilder().name("ore.mix.ross128.Hedenbergit") + .heightRange(20, 90) + .weight(50) + .density(2) + .size(32) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Hedenbergit) + .secondary(WerkstoffLoader.Fayalit) + .inBetween(WerkstoffLoader.DescloiziteCUVO4) + .sporadic(WerkstoffLoader.DescloiziteZNVO4)), + + RedZircon(new OreMixBuilder().name("ore.mix.ross128.RedZircon") + .heightRange(10, 80) + .weight(40) + .density(3) + .size(24) + .enableInDim(ROSS128B) + .primary(WerkstoffLoader.Fayalit) + .secondary(WerkstoffLoader.FuchsitAL) + .inBetween(WerkstoffLoader.RedZircon) + .sporadic(WerkstoffLoader.FuchsitCR)), + + Tiberium(new OreMixBuilder().name("ore.mix.ross128ba.tib") + .heightRange(30, 60) + .weight(6) + .density(1) + .size(16) + .enableInDim(ROSS128BA) + .primary(WerkstoffLoader.Tiberium) + .secondary(WerkstoffLoader.Tiberium) + .inBetween(Materials.NaquadahEnriched) + .sporadic(Materials.NaquadahEnriched)), + + Ross128baTungstate(new OreMixBuilder().name("ore.mix.ross128ba.Tungstate") + .heightRange(5, 40) + .weight(60) + .density(4) + .size(14) + .enableInDim(ROSS128BA) + .primary(WerkstoffLoader.Ferberite) + .secondary(WerkstoffLoader.Huebnerit) + .inBetween(WerkstoffLoader.Loellingit) + .sporadic(Materials.Scheelite)), + + Bart(new OreMixBuilder().name("ore.mix.ross128ba.bart") + .heightRange(30, 60) + .weight(1) + .density(1) + .size(1) + .enableInDim(ROSS128BA) + .primary(WerkstoffLoader.BArTiMaEuSNeK) + .secondary(WerkstoffLoader.BArTiMaEuSNeK) + .inBetween(WerkstoffLoader.BArTiMaEuSNeK) + .sporadic(WerkstoffLoader.BArTiMaEuSNeK)), + + Ross128baTurmalinAlkali(new OreMixBuilder().name("ore.mix.ross128ba.TurmalinAlkali") + .heightRange(5, 80) + .weight(60) + .density(4) + .size(48) + .enableInDim(ROSS128BA) + .primary(WerkstoffLoader.Olenit) + .secondary(WerkstoffLoader.FluorBuergerit) + .inBetween(WerkstoffLoader.ChromoAluminoPovondrait) + .sporadic(WerkstoffLoader.VanadioOxyDravit)), + + Ross128baAmethyst(new OreMixBuilder().name("ore.mix.ross128ba.Amethyst") + .heightRange(5, 80) + .weight(35) + .density(2) + .size(8) + .enableInDim(ROSS128BA) + .primary(Materials.Amethyst) + .secondary(Materials.Olivine) + .inBetween(WerkstoffLoader.Prasiolite) + .sporadic(WerkstoffLoader.Hedenbergit)), + + Ross128baCopperSulfits(new OreMixBuilder().name("ore.mix.ross128ba.CopperSulfits") + .heightRange(40, 70) + .weight(80) + .density(3) + .size(24) + .enableInDim(ROSS128BA) + .primary(WerkstoffLoader.Djurleit) + .secondary(WerkstoffLoader.Bornite) + .inBetween(WerkstoffLoader.Wittichenit) + .sporadic(Materials.Tetrahedrite)), + + Ross128baRedZircon(new OreMixBuilder().name("ore.mix.ross128ba.RedZircon") + .heightRange(10, 80) + .weight(40) + .density(3) + .size(24) + .enableInDim(ROSS128BA) + .primary(WerkstoffLoader.Fayalit) + .secondary(WerkstoffLoader.FuchsitAL) + .inBetween(WerkstoffLoader.RedZircon) + .sporadic(WerkstoffLoader.FuchsitCR)), + + Fluorspar(new OreMixBuilder().name("ore.mix.ross128ba.Fluorspar") + .heightRange(10, 80) + .weight(35) + .density(4) + .size(8) + .enableInDim(ROSS128BA) + .primary(Materials.Galena) + .secondary(Materials.Sphalerite) + .inBetween(WerkstoffLoader.Fluorspar) + .sporadic(Materials.Barite)); // spotless : on @@ -1011,8 +1499,4 @@ public enum OreMixes { public WorldgenGTOreLayer addGTOreLayer() { return new WorldgenGTOreLayer(this.oreMixBuilder); } - - public WorldgenOreLayerSpace addGaGregOreLayer() { - return new WorldgenOreLayerSpace(this.oreMixBuilder); - } } diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index 81259da9bfd..186251ca04f 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -28,7 +28,6 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.GTUtility.ItemId; import gregtech.loaders.materialprocessing.ProcessingModSupport; -import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; import it.unimi.dsi.fastutil.objects.ObjectSet; @@ -893,6 +892,22 @@ public enum OrePrefixes { dust.mGeneratedItems.addAll(dustRefined.mGeneratedItems); dustTiny.mGeneratedItems.addAll(dust.mGeneratedItems); dustSmall.mGeneratedItems.addAll(dust.mGeneratedItems); + + ore.mGeneratedItems.add(Materials.Hydrogen); + ore.mGeneratedItems.add(Materials.Nitrogen); + ore.mGeneratedItems.add(Materials.Oxygen); + ore.mGeneratedItems.add(Materials.Methane); + ore.mGeneratedItems.add(Materials.CarbonDioxide); + ore.mGeneratedItems.add(Materials.SulfurDioxide); + ore.mGeneratedItems.add(Materials.Ammonia); + + rawOre.mGeneratedItems.add(Materials.Hydrogen); + rawOre.mGeneratedItems.add(Materials.Nitrogen); + rawOre.mGeneratedItems.add(Materials.Oxygen); + rawOre.mGeneratedItems.add(Materials.Methane); + rawOre.mGeneratedItems.add(Materials.CarbonDioxide); + rawOre.mGeneratedItems.add(Materials.SulfurDioxide); + rawOre.mGeneratedItems.add(Materials.Ammonia); // ----- toolHeadFile.mCondition = new ICondition.And<>( @@ -1188,10 +1203,48 @@ public static String stripPrefix(String aOre) { return aOre; } - public static Pair detectPrefix(String oredictName) { + public static class ParsedOreDictName { + + public final OrePrefixes prefix; + public final String material; + + public ParsedOreDictName(OrePrefixes prefix, String material) { + this.prefix = prefix; + this.material = material; + } + + @Override + public String toString() { + return "ParsedOreDictName [prefix=" + prefix + ", material=" + material + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); + result = prime * result + ((material == null) ? 0 : material.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + ParsedOreDictName other = (ParsedOreDictName) obj; + if (prefix != other.prefix) return false; + if (material == null) { + if (other.material != null) return false; + } else if (!material.equals(other.material)) return false; + return true; + } + } + + public static ParsedOreDictName detectPrefix(String oredictName) { for (OrePrefixes prefix : values()) { if (oredictName.startsWith(prefix.name())) { - return Pair.of( + return new ParsedOreDictName( prefix, oredictName.substring( prefix.name() @@ -1202,11 +1255,11 @@ public static Pair detectPrefix(String oredictName) { return null; } - private static final ThreadLocal>>> PREFIX_CACHE = ThreadLocal + private static final ThreadLocal>> PREFIX_CACHE = ThreadLocal .withInitial(Object2ObjectLinkedOpenHashMap::new); - public static ImmutableList> detectPrefix(ItemStack stack) { - Object2ObjectLinkedOpenHashMap>> cache = PREFIX_CACHE.get(); + public static List detectPrefix(ItemStack stack) { + Object2ObjectLinkedOpenHashMap> cache = PREFIX_CACHE.get(); ItemId itemId = ItemId.create(stack); @@ -1214,17 +1267,17 @@ public static ImmutableList> detectPrefix(ItemStack st if (cacheResult != null) return cacheResult; - ImmutableList.Builder> result = ImmutableList.builder(); + ImmutableList.Builder result = ImmutableList.builder(); for (int id : OreDictionary.getOreIDs(stack)) { - Pair p = detectPrefix(OreDictionary.getOreName(id)); + ParsedOreDictName p = detectPrefix(OreDictionary.getOreName(id)); if (p != null) { result.add(p); } } - ImmutableList> prefixes = result.build(); + ImmutableList prefixes = result.build(); cache.putAndMoveToFirst(itemId, prefixes); @@ -1463,6 +1516,19 @@ public String getDefaultLocalNameFormatForItem(Materials aMaterial) { } } } + + if (aMaterial.contains(SubTag.ICE_ORE) && (this == rawOre || this == ore)) { + return mLocalizedMaterialPre + "%material" + " Ice"; + } + + if (this == ore) { + return switch (aMaterial.mName) { + case "InfusedAir", "InfusedDull", "InfusedEarth", "InfusedEntropy", "InfusedFire", "InfusedOrder", "InfusedVis", "InfusedWater" -> "%material Infused Stone"; + case "Vermiculite", "Bentonite", "Kaolinite", "Talc", "BasalticMineralSand", "GraniticMineralSand", "GlauconiteSand", "CassiteriteSand", "GarnetSand", "QuartzSand", "Pitchblende", "FullersEarth" -> "%material"; + default -> mLocalizedMaterialPre + "%material" + mLocalizedMaterialPost; + }; + } + // Use Standard Localization return mLocalizedMaterialPre + "%material" + mLocalizedMaterialPost; } diff --git a/src/main/java/gregtech/api/enums/SmallOres.java b/src/main/java/gregtech/api/enums/SmallOres.java index ec11c211c2a..6bf1c89affe 100644 --- a/src/main/java/gregtech/api/enums/SmallOres.java +++ b/src/main/java/gregtech/api/enums/SmallOres.java @@ -7,6 +7,10 @@ import static galacticgreg.api.enums.DimensionDef.Callisto; import static galacticgreg.api.enums.DimensionDef.Ceres; import static galacticgreg.api.enums.DimensionDef.Deimos; +import static galacticgreg.api.enums.DimensionDef.DimNames.NETHER; +import static galacticgreg.api.enums.DimensionDef.DimNames.OW; +import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; +import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; import static galacticgreg.api.enums.DimensionDef.Enceladus; import static galacticgreg.api.enums.DimensionDef.EndAsteroids; import static galacticgreg.api.enums.DimensionDef.Ganymede; @@ -30,12 +34,7 @@ import static galacticgreg.api.enums.DimensionDef.Triton; import static galacticgreg.api.enums.DimensionDef.VegaB; import static galacticgreg.api.enums.DimensionDef.Venus; -import static gregtech.common.SmallOreBuilder.NETHER; -import static gregtech.common.SmallOreBuilder.OW; -import static gregtech.common.SmallOreBuilder.THE_END; -import static gregtech.common.SmallOreBuilder.TWILIGHT_FOREST; -import galacticgreg.WorldgenOreSmallSpace; import gregtech.common.SmallOreBuilder; import gregtech.common.WorldgenGTOreSmallPieces; @@ -526,17 +525,11 @@ public enum SmallOres { .ore(Materials.DeepIron) .enableInDim(Mercury)), - Redgarnet(new SmallOreBuilder().name("ore.small.redgarnet") - .heightRange(5, 35) - .amount(2) - .ore(Materials.GarnetRed) - .enableInDim(Horus)), - Chargedcertus(new SmallOreBuilder().name("ore.small.chargedcertus") .heightRange(5, 115) .amount(4) .ore(Materials.CertusQuartzCharged) - .enableInDim(Horus)),; + .enableInDim(Horus)); // spotless : on public final SmallOreBuilder smallOreBuilder; @@ -548,8 +541,4 @@ public enum SmallOres { public WorldgenGTOreSmallPieces addGTSmallOre() { return new WorldgenGTOreSmallPieces(this.smallOreBuilder); } - - public WorldgenOreSmallSpace addGaGregSmallOre() { - return new WorldgenOreSmallSpace(this.smallOreBuilder); - } } diff --git a/src/main/java/gregtech/api/enums/StoneCategory.java b/src/main/java/gregtech/api/enums/StoneCategory.java new file mode 100644 index 00000000000..9ee6449781a --- /dev/null +++ b/src/main/java/gregtech/api/enums/StoneCategory.java @@ -0,0 +1,8 @@ +package gregtech.api.enums; + +import gregtech.api.interfaces.IStoneCategory; + +public enum StoneCategory implements IStoneCategory { + Stone, + Ice, +} diff --git a/src/main/java/gregtech/api/enums/StoneType.java b/src/main/java/gregtech/api/enums/StoneType.java new file mode 100644 index 00000000000..722f5c87fb0 --- /dev/null +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -0,0 +1,476 @@ +package gregtech.api.enums; + +import static gregtech.api.enums.GTValues.W; +import static gregtech.api.enums.Mods.GalacticraftAmunRa; +import static gregtech.api.enums.Mods.GalacticraftCore; +import static gregtech.api.enums.Mods.GalacticraftMars; +import static gregtech.api.enums.Mods.GalaxySpace; +import static gregtech.api.enums.Mods.NewHorizonsCoreMod; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import com.google.common.collect.ImmutableList; +import com.gtnewhorizon.gtnhlib.util.data.BlockSupplier; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; +import com.gtnewhorizon.gtnhlib.util.data.LazyBlock; +import com.gtnewhorizon.gtnhlib.util.data.LazyItem; + +import galacticgreg.api.enums.DimensionDef.DimNames; +import gregtech.GTMod; +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.IStoneCategory; +import gregtech.api.interfaces.IStoneType; +import gregtech.api.interfaces.ITexture; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GTOreDictUnificator; + +public enum StoneType implements IStoneType { + + // spotless:off + Stone(new StoneBuilder() + .setCobble(() -> Blocks.cobblestone, 0) + .setMainStone(() -> Blocks.stone, 0) + .setDust(Materials.Stone)), + Netherrack(new StoneBuilder() + .setPrefix(OrePrefixes.oreNetherrack) + .setStoneNoCobble(() -> Blocks.netherrack, 0) + .setDust(Materials.Netherrack)), + Endstone(new StoneBuilder() + .setPrefix(OrePrefixes.oreEndstone) + .setStoneNoCobble(() -> Blocks.end_stone, 0) + .setDust(Materials.Endstone)), + BlackGranite(new StoneBuilder() + .setPrefix(OrePrefixes.oreBlackgranite) + .setCobble(() -> GregTechAPI.sBlockGranites, 1) + .setMainStone(() -> GregTechAPI.sBlockGranites, 0) + .setDust(Materials.GraniteBlack)), + RedGranite(new StoneBuilder() + .setPrefix(OrePrefixes.oreRedgranite) + .setCobble(() -> GregTechAPI.sBlockGranites, 9) + .setMainStone(() -> GregTechAPI.sBlockGranites, 8) + .setDust(Materials.GraniteRed)), + Marble(new StoneBuilder() + .setPrefix(OrePrefixes.oreMarble) + .setCobble(() -> GregTechAPI.sBlockStones, 1) + .setMainStone(() -> GregTechAPI.sBlockStones, 0) + .setDust(Materials.Marble)), + Basalt(new StoneBuilder() + .setPrefix(OrePrefixes.oreBasalt) + .setCobble(() -> GregTechAPI.sBlockStones, 9) + .setMainStone(() -> GregTechAPI.sBlockStones, 8) + .setDust(Materials.Basalt)), + Moon(new StoneBuilder() + .setStoneNoCobble(GalacticraftCore, "tile.moonBlock", 4) + .setCoremodDust("Moon")), + Mars(new StoneBuilder() + .setCobble(GalacticraftMars, "tile.mars", 4) + .setMainStone(GalacticraftMars, "tile.mars", 9) + .addOtherStone(GalacticraftMars, "tile.mars", 6) + .setCoremodDust("Mars")), + Asteroid(new StoneBuilder() + .setStoneNoCobble(GalacticraftMars, "tile.asteroidsBlock", 1) + .setCoremodDust("Asteroids")), + Phobos(StoneBuilder.galaxySpace("Phobos", 2, 1)), + Deimos(StoneBuilder.galaxySpace("Deimos", 1)), + Ceres(StoneBuilder.galaxySpace("Ceres", 1)), + Io(StoneBuilder.galaxySpace("Io", 2)), + Europa(StoneBuilder.galaxySpace("Europa", "grunt", 1)), + Ganymede(StoneBuilder.galaxySpace("Ganymede", 1)), + Callisto(StoneBuilder.galaxySpace("Callisto", 1)), + Enceladus(StoneBuilder.galaxySpace("Enceladus", 1, 3)), + Titan(StoneBuilder.galaxySpace("Titan", 2, 1)), + Miranda(StoneBuilder.galaxySpace("Miranda", 2, 1)), + Oberon(StoneBuilder.galaxySpace("Oberon", 2, 1)), + Proteus(StoneBuilder.galaxySpace("Proteus", 2, 1)), + Triton(StoneBuilder.galaxySpace("Triton", 2, 1)), + Pluto(StoneBuilder.galaxySpace("Pluto", 5, 4)), + Haumea(StoneBuilder.galaxySpace("Haumea", 0)), + MakeMake(StoneBuilder.galaxySpace("MakeMake", "grunt", 1)), + AlphaCentauri(new StoneBuilder() + .setStoneNoCobble(GalaxySpace, "acentauribbsubgrunt", 1) + .setCoremodDust("CentauriA")), + TCetiE(StoneBuilder.galaxySpace("TCetiE", 2, 1)), + VegaB(StoneBuilder.galaxySpace("VegaB", "subgrunt", 0)), + BarnardaE(new StoneBuilder() + .setStoneNoCobble(GalaxySpace, "barnardaEsubgrunt", 0) + .setCoremodDust("BarnardaE")), + BarnardaF(new StoneBuilder() + .setStoneNoCobble(GalaxySpace, "barnardaFsubgrunt", 0) + .setCoremodDust("BarnardaF")), + Horus(new StoneBuilder() + .setStoneNoCobble(() -> Blocks.obsidian, 0) + .addOtherStone(GalacticraftAmunRa, "tile.baseFalling", 1) + .addAllowedDimensions(DimNames.HORUS) + .setDust(Materials.Obsidian)), + AnubisAndMaahes(new StoneBuilder() + .setCobble(GalacticraftAmunRa, "tile.baseBlockRock", 0) + .setMainStone(GalacticraftAmunRa, "tile.baseBlockRock", 1) + .setDust(Materials.Basalt)), + PackedIce(new StoneBuilder() + .setStoneNoCobble(() -> Blocks.packed_ice, 0) + .setDust(Materials.Ice) + .setCategory(StoneCategory.Ice)), + SethIce(new StoneBuilder() + .setStoneNoCobble(() -> Blocks.packed_ice, 0) + .addOtherStone(Mods.Minecraft, () -> Blocks.ice, 0) + .setDust(Materials.Ice) + .setCategory(StoneCategory.Stone) + .addAllowedDimensions(DimNames.SETH)), + SethClay(new StoneBuilder() + .setStoneNoCobble(() -> Blocks.hardened_clay, W) + .addOtherStone(Mods.Minecraft, () -> Blocks.clay, 0) + .setDust(Materials.Clay) + .setCategory(StoneCategory.Stone) + .addAllowedDimensions(DimNames.SETH)), + + ; + // spotless:on + + public static final List STONE_TYPES = ImmutableList.copyOf(values()); + public static final List VISUAL_STONE_TYPES = ImmutableList.copyOf( + Arrays.stream(values()) + .filter(s -> s.builder.enabled && !s.isExtraneous()) + .toArray(StoneType[]::new)); + + public static final List STONE_ONLY = ImmutableList.of(StoneType.Stone); + public static final List STONES = ImmutableList.copyOf( + StoneType.STONE_TYPES.stream() + .filter(s -> s.getCategory() == StoneCategory.Stone) + .toArray(StoneType[]::new)); + public static final List ICES = ImmutableList.copyOf( + StoneType.STONE_TYPES.stream() + .filter(s -> s.getCategory() == StoneCategory.Ice) + .toArray(StoneType[]::new)); + + private final StoneBuilder builder; + + private StoneType(StoneBuilder builder) { + this.builder = builder; + } + + public static void init() { + for (StoneType stoneType : STONE_TYPES) { + StoneBuilder builder = stoneType.builder; + + builder.cobble.get(); + builder.mainStone.get(); + + if (builder.otherStones != null) builder.otherStones.forEach(LazyBlock::get); + + builder.pureDust.get(); + + if (builder.impureDust == null || builder.impureDust.get() == null) { + builder.impureDust = builder.pureDust; + } + } + } + + @Override + public ItemStack getDust(boolean pure, int amount) { + if (pure) { + return builder.pureDust.toStack(amount); + } else { + return builder.impureDust.toStack(amount); + } + } + + @Override + public OrePrefixes getPrefix() { + return builder.oreBlockPrefix; + } + + @Override + public IStoneCategory getCategory() { + return builder.category; + } + + @Override + public ImmutableBlockMeta getCobblestone() { + return builder.cobble; + } + + @Override + public ImmutableBlockMeta getStone() { + return builder.mainStone; + } + + @Override + public ITexture getTexture(int side) { + IIconContainer container = switch (this) { + case BlackGranite -> BlockIcons.GRANITE_BLACK_STONE; + case RedGranite -> BlockIcons.GRANITE_RED_STONE; + case Marble -> BlockIcons.MARBLE_STONE; + case Basalt -> BlockIcons.BASALT_STONE; + default -> new IIconContainer() { + + @Override + public IIcon getIcon() { + return StoneType.this.getIcon(side); + } + + @Override + public IIcon getOverlayIcon() { + return null; + } + + @Override + public ResourceLocation getTextureFile() { + return TextureMap.locationBlocksTexture; + } + }; + }; + + return TextureFactory.builder() + .addIcon(container) + .stdOrient() + .build(); + } + + @Override + public IIcon getIcon(int side) { + if (!builder.enabled) { + return Blocks.stone.getIcon(side, 0); + } + + return switch (this) { + case Stone -> Blocks.stone.getIcon(side, 0); + case Netherrack -> Blocks.netherrack.getIcon(side, 0); + case Endstone -> Blocks.end_stone.getIcon(side, 0); + case BlackGranite -> BlockIcons.GRANITE_BLACK_STONE.getIcon(); + case RedGranite -> BlockIcons.GRANITE_RED_STONE.getIcon(); + case Marble -> BlockIcons.MARBLE_STONE.getIcon(); + case Basalt -> BlockIcons.BASALT_STONE.getIcon(); + default -> builder.mainStone.getBlock() + .getIcon(side, builder.mainStone.getBlockMeta()); + }; + } + + @Override + public boolean isRich() { + return switch (this) { + case Netherrack -> GTMod.gregtechproxy.mNetherOreYieldMultiplier; + case Endstone -> GTMod.gregtechproxy.mEndOreYieldMultiplier; + default -> false; + }; + } + + @Override + public boolean isDimensionSpecific() { + return switch (this) { + case Stone -> false; + case BlackGranite -> false; + case RedGranite -> false; + case Marble -> false; + case Basalt -> false; + default -> true; + }; + } + + @Override + public boolean isExtraneous() { + if (this == Stone) return false; + if (this == Netherrack) return false; + if (this == Endstone) return false; + if (this == PackedIce) return false; + + return true; + } + + @Override + public boolean isEnabled() { + return builder.enabled; + } + + @Override + public boolean contains(Block block, int meta) { + if (builder.mainStone.matches(block, meta)) return true; + + if (builder.otherStones != null) { + for (ImmutableBlockMeta other : builder.otherStones) { + if (other.matches(block, meta)) return true; + } + } + + return false; + } + + @Override + public boolean canGenerateInWorld(World world) { + return builder.allowedDimensions == null + || builder.allowedDimensions.contains(world.provider.getDimensionName()); + } + + @Nullable + public static StoneType findStoneType(World world, int x, int y, int z) { + return findStoneType(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + } + + @Nullable + public static StoneType findStoneType(Block block, int meta) { + for (StoneType stoneType : STONE_TYPES) { + if (stoneType.builder.enabled && stoneType.contains(block, meta)) { + return stoneType; + } + } + + return null; + } + + private static class StoneBuilder { + + private static final LazyBlock AIR = new LazyBlock(Mods.Minecraft, "air"); + + public boolean enabled = true; + + public LazyBlock cobble = AIR; + public LazyBlock mainStone = AIR; + public List otherStones; + + public OrePrefixes oreBlockPrefix = OrePrefixes.ore; + + public LazyItem pureDust = new LazyItem( + Mods.GregTech, + () -> GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1)); + public LazyItem impureDust = new LazyItem( + Mods.GregTech, + () -> GTOreDictUnificator.get(OrePrefixes.dustImpure, Materials.Stone, 1)); + + public StoneCategory category = StoneCategory.Stone; + public HashSet allowedDimensions = null; + + public static StoneBuilder galaxySpace(String name, int mainStone, int... extraStones) { + return galaxySpace(name, "blocks", mainStone, extraStones); + } + + public static StoneBuilder galaxySpace(String name, String suffix, int mainStone, int... extraStones) { + StoneBuilder builder = new StoneBuilder() + .setStoneNoCobble(GalaxySpace, name.toLowerCase() + suffix, mainStone) + .setCoremodDust(name); + + for (int extra : extraStones) { + builder.addOtherStone(GalaxySpace, name.toLowerCase() + suffix, extra); + } + + return builder; + } + + public StoneBuilder setCobble(BlockSupplier block, int meta) { + Objects.requireNonNull(block); + + cobble = new LazyBlock(Mods.Minecraft, block, meta); + + return this; + } + + public StoneBuilder setCobble(Mods owner, String blockName, int meta) { + enabled &= owner.isModLoaded(); + + if (enabled) { + cobble = new LazyBlock(owner, blockName, meta); + } + + return this; + } + + public StoneBuilder setStoneNoCobble(Mods owner, String blockName, int meta) { + enabled &= owner.isModLoaded(); + + if (enabled) { + cobble = mainStone = new LazyBlock(owner, blockName, meta); + } + + return this; + } + + public StoneBuilder setStoneNoCobble(BlockSupplier block, int meta) { + cobble = mainStone = new LazyBlock(Mods.Minecraft, block, meta); + + return this; + } + + public StoneBuilder setMainStone(Mods owner, String blockName, int meta) { + enabled &= owner.isModLoaded(); + + if (enabled) { + mainStone = new LazyBlock(owner, blockName, meta); + } + + return this; + } + + public StoneBuilder setMainStone(BlockSupplier block, int meta) { + mainStone = new LazyBlock(Mods.Minecraft, block, meta); + + return this; + } + + public StoneBuilder addOtherStone(Mods owner, String blockName, int meta) { + if (owner.isModLoaded()) { + if (otherStones == null) otherStones = new ArrayList<>(); + otherStones.add(new LazyBlock(owner, blockName, meta)); + } + + return this; + } + + public StoneBuilder addOtherStone(Mods owner, BlockSupplier block, int meta) { + if (owner.isModLoaded()) { + if (otherStones == null) otherStones = new ArrayList<>(); + otherStones.add(new LazyBlock(owner, block, meta)); + } + + return this; + } + + public StoneBuilder setCoremodDust(String name) { + if (NewHorizonsCoreMod.isModLoaded()) { + pureDust = impureDust = new LazyItem(NewHorizonsCoreMod, "item." + name + "StoneDust"); + } + + return this; + } + + public StoneBuilder setDust(Materials mat) { + pureDust = new LazyItem(Mods.GregTech, () -> mat.getDust(1)); + impureDust = new LazyItem(Mods.GregTech, () -> GTOreDictUnificator.get(OrePrefixes.dustImpure, mat, 1)); + + return this; + } + + public StoneBuilder setPrefix(OrePrefixes prefix) { + this.oreBlockPrefix = prefix; + + return this; + } + + public StoneBuilder setCategory(StoneCategory cat) { + this.category = cat; + + return this; + } + + public StoneBuilder addAllowedDimensions(String... dimNames) { + if (allowedDimensions == null) allowedDimensions = new HashSet<>(); + + allowedDimensions.addAll(Arrays.asList(dimNames)); + + return this; + } + } +} diff --git a/src/main/java/gregtech/api/enums/SubTag.java b/src/main/java/gregtech/api/enums/SubTag.java index a21197d1b1e..d903bb58466 100644 --- a/src/main/java/gregtech/api/enums/SubTag.java +++ b/src/main/java/gregtech/api/enums/SubTag.java @@ -244,6 +244,10 @@ public final class SubTag implements ICondition { * If this material cannot be made superdense using the HIP unit */ public static final SubTag BLACK_HOLE = getNewSubTag("BLACK_HOLE"); + /** + * This material has ice ores, but not rock ores or ore items + */ + public static final SubTag ICE_ORE = getNewSubTag("ICE_ORE"); public final Collection mRelevantTaggedItems = new HashSet<>(1); diff --git a/src/main/java/gregtech/api/events/GTEventBus.java b/src/main/java/gregtech/api/events/GTEventBus.java new file mode 100644 index 00000000000..c33f8c57731 --- /dev/null +++ b/src/main/java/gregtech/api/events/GTEventBus.java @@ -0,0 +1,14 @@ +package gregtech.api.events; + +import cpw.mods.fml.common.eventhandler.EventBus; + +public final class GTEventBus { + + private static final EventBus BUS = new EventBus(); + + private GTEventBus() {} + + public static EventBus bus() { + return BUS; + } +} diff --git a/src/main/java/gregtech/api/interfaces/IBlockWithTextures.java b/src/main/java/gregtech/api/interfaces/IBlockWithTextures.java new file mode 100644 index 00000000000..057dbf17158 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IBlockWithTextures.java @@ -0,0 +1,12 @@ +package gregtech.api.interfaces; + +import javax.annotation.Nullable; + +public interface IBlockWithTextures { + + /** + * @return Texture[forge direction ordinal][layer] + */ + @Nullable + public ITexture[][] getTextures(int metadata); +} diff --git a/src/main/java/gregtech/api/interfaces/IOreMaterial.java b/src/main/java/gregtech/api/interfaces/IOreMaterial.java new file mode 100644 index 00000000000..2966e0ae8c9 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IOreMaterial.java @@ -0,0 +1,41 @@ +package gregtech.api.interfaces; + +import java.util.List; + +import bartworks.system.material.Werkstoff; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TextureSet; +import gtPlusPlus.core.material.Material; + +/** + * A temporary material interface to unify the three material systems. + * Once the new material system is finished, this should be removed and all the code referencing this should be migrated + * to the new system. + */ +public interface IOreMaterial { + + String getLocalizedName(); + + int getId(); + + String getInternalName(); + + short[] getRGBA(); + + TextureSet getTextureSet(); + + List getValidStones(); + + public static IOreMaterial findMaterial(String name) { + Werkstoff bw = Werkstoff.werkstoffVarNameHashMap.get(name); + + if (bw != null) return bw; + + IOreMaterial gtpp = Material.mMaterialsByName.get(name); + + if (gtpp != null) return gtpp; + + return Materials.getMaterialsMap() + .get(name); + } +} diff --git a/src/main/java/gregtech/api/interfaces/IStoneCategory.java b/src/main/java/gregtech/api/interfaces/IStoneCategory.java new file mode 100644 index 00000000000..390409de84f --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IStoneCategory.java @@ -0,0 +1,5 @@ +package gregtech.api.interfaces; + +public interface IStoneCategory { + +} diff --git a/src/main/java/gregtech/api/interfaces/IStoneType.java b/src/main/java/gregtech/api/interfaces/IStoneType.java new file mode 100644 index 00000000000..af43f2c73bd --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IStoneType.java @@ -0,0 +1,54 @@ +package gregtech.api.interfaces; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + +import gregtech.api.enums.OrePrefixes; +import gregtech.common.GTProxy; +import gregtech.common.GTProxy.OreDropSystem; + +public interface IStoneType { + + /** Checks if this stone type contains this specific block. */ + public boolean contains(Block block, int meta); + + /** Gets the oredict prefix for this stone type (usually just {@code ore}) */ + public OrePrefixes getPrefix(); + + /** Gets the stone category for this stone. */ + public IStoneCategory getCategory(); + + /** Gets the dust version of this stone */ + public ItemStack getDust(boolean pure, int amount); + + /** Gets the cobblestone block for this stone. */ + public ImmutableBlockMeta getCobblestone(); + + /** Gets the stone block for this stone. */ + public ImmutableBlockMeta getStone(); + + /** Gets the texture for this stone. */ + public ITexture getTexture(int side); + + /** Gets the icon for this stone. */ + public IIcon getIcon(int side); + + /** If this stone drops double the ore. */ + public boolean isRich(); + + /** If this stone should be kept when the {@link GTProxy#oreDropSystem} is {@link OreDropSystem#PerDimBlock}. */ + public boolean isDimensionSpecific(); + + /** If this stone should be hidden in NEI. */ + public boolean isExtraneous(); + + /** If this stone's parent mod is loaded. */ + public boolean isEnabled(); + + /** If this stone can generate in the given world. */ + public boolean canGenerateInWorld(World world); +} diff --git a/src/main/java/gregtech/api/net/GTPacketTypes.java b/src/main/java/gregtech/api/net/GTPacketTypes.java index a29d3da9e4f..f00f3b2d315 100644 --- a/src/main/java/gregtech/api/net/GTPacketTypes.java +++ b/src/main/java/gregtech/api/net/GTPacketTypes.java @@ -7,7 +7,6 @@ import bartworks.common.net.PacketEIC; import bartworks.common.net.PacketOreDictCache; import bartworks.common.net.PacketServerJoined; -import gregtech.common.blocks.PacketOres; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; /** @@ -18,7 +17,6 @@ public enum GTPacketTypes { TILE_ENTITY(0, new GTPacketTileEntity()), SOUND(1, new GTPacketSound()), BLOCK_EVENT(2, new GTPacketBlockEvent()), - ORES(3, new PacketOres()), POLLUTION(4, new GTPacketPollution()), CLIENT_PREFERENCE(9, new GTPacketClientPreference()), SET_CONFIGURATION_CIRCUIT(12, new GTPacketSetConfigurationCircuit()), diff --git a/src/main/java/gregtech/api/objects/MurmurHash.java b/src/main/java/gregtech/api/objects/MurmurHash.java new file mode 100644 index 00000000000..b1904d799ac --- /dev/null +++ b/src/main/java/gregtech/api/objects/MurmurHash.java @@ -0,0 +1,188 @@ +package gregtech.api.objects; + +/** + * An implementation of Murmur3_32 that works well enough. No guarantees that it actually works properly though + * :tootroll:. + */ +public class MurmurHash { + + private static final int MURMURHASH2A_R = 24; + private static final int MURMURHASH2A_MULTIPLIER = 0x5bd1e995; + private static final int MURMURHASH2A_SEED = 0x811c9dc5; // No seed suggested, so using FNV32_OFFSET_BASIS + + private int hash = MURMURHASH2A_SEED; + + public MurmurHash reset() { + hash = MURMURHASH2A_SEED; + + return this; + } + + public MurmurHash feed(byte value) { + return feed((int) value); + } + + public MurmurHash feed(short value) { + return feed((int) value); + } + + public MurmurHash feed(int value) { + int hash = this.hash; + + int mmh2ak = value * MURMURHASH2A_MULTIPLIER; + mmh2ak ^= mmh2ak >> MURMURHASH2A_R; + mmh2ak *= MURMURHASH2A_MULTIPLIER; + hash *= MURMURHASH2A_MULTIPLIER; + hash ^= mmh2ak; + + this.hash = hash; + + return this; + } + + public MurmurHash feed(long value) { + feed((int) value); + feed((int) (value >> 32)); + + return this; + } + + public MurmurHash feed(float value) { + return feed(Float.floatToIntBits(value)); + } + + public MurmurHash feed(double value) { + return feed(Double.doubleToLongBits(value)); + } + + public MurmurHash feed(String str) { + return feed(str, 0, str.length()); + } + + public MurmurHash feed(String str, int offset, int length) { + int hash = this.hash; + + for (int i = offset; i < length; i++) { + int mmh2ak = str.charAt(i) * MURMURHASH2A_MULTIPLIER; + mmh2ak ^= mmh2ak >> MURMURHASH2A_R; + mmh2ak *= MURMURHASH2A_MULTIPLIER; + hash *= MURMURHASH2A_MULTIPLIER; + hash ^= mmh2ak; + } + + this.hash = hash; + + return this; + } + + public MurmurHash feed(byte[] data) { + return feed(data, 0, data.length); + } + + public MurmurHash feed(byte[] data, int offset, int length) { + int hash = this.hash; + + int i = offset; + + for (; i + 4 < length; i += 4) { + int value = data[i + 0] | data[i + 1] << 8 | data[i + 2] << 16 | data[i + 3] << 24; + + int mmh2ak = value * MURMURHASH2A_MULTIPLIER; + mmh2ak ^= mmh2ak >> MURMURHASH2A_R; + mmh2ak *= MURMURHASH2A_MULTIPLIER; + hash *= MURMURHASH2A_MULTIPLIER; + hash ^= mmh2ak; + } + + for (; i < length; i++) { + int mmh2ak = data[i] * MURMURHASH2A_MULTIPLIER; + mmh2ak ^= mmh2ak >> MURMURHASH2A_R; + mmh2ak *= MURMURHASH2A_MULTIPLIER; + hash *= MURMURHASH2A_MULTIPLIER; + hash ^= mmh2ak; + } + + this.hash = hash; + + return this; + } + + public MurmurHash feed(int[] data) { + return feed(data, 0, data.length); + } + + public MurmurHash feed(int[] data, int offset, int length) { + int hash = this.hash; + + for (int i = offset; i < length; i++) { + int mmh2ak = data[i] * MURMURHASH2A_MULTIPLIER; + mmh2ak ^= mmh2ak >> MURMURHASH2A_R; + mmh2ak *= MURMURHASH2A_MULTIPLIER; + hash *= MURMURHASH2A_MULTIPLIER; + hash ^= mmh2ak; + } + + this.hash = hash; + + return this; + } + + public MurmurHash feed(long[] data) { + return feed(data, 0, data.length); + } + + public MurmurHash feed(long[] data, int offset, int length) { + int hash = this.hash; + + for (int i = offset; i < length; i++) { + long value = data[i]; + + int mmh2ak = ((int) value) * MURMURHASH2A_MULTIPLIER; + mmh2ak ^= mmh2ak >> MURMURHASH2A_R; + mmh2ak *= MURMURHASH2A_MULTIPLIER; + hash *= MURMURHASH2A_MULTIPLIER; + hash ^= mmh2ak; + + mmh2ak = ((int) (value >> 32)) * MURMURHASH2A_MULTIPLIER; + mmh2ak ^= mmh2ak >> MURMURHASH2A_R; + mmh2ak *= MURMURHASH2A_MULTIPLIER; + hash *= MURMURHASH2A_MULTIPLIER; + hash ^= mmh2ak; + } + + this.hash = hash; + + return this; + } + + public MurmurHash feed(Object obj) { + return feed(obj == null ? 0 : obj.hashCode()); + } + + public int finish() { + int hash = this.hash; + + hash ^= hash >> 13; + hash *= MURMURHASH2A_MULTIPLIER; + hash ^= hash >> 15; + + return hash; + } + + @Override + public int hashCode() { + return finish(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MurmurHash other)) return false; + + return hash == other.hash; + } + + @Override + public String toString() { + return "MurmurHash [hash=" + hash + "]"; + } +} diff --git a/src/main/java/gregtech/api/task/CoopTask.java b/src/main/java/gregtech/api/task/CoopTask.java new file mode 100644 index 00000000000..104130ef355 --- /dev/null +++ b/src/main/java/gregtech/api/task/CoopTask.java @@ -0,0 +1,7 @@ +package gregtech.api.task; + +@FunctionalInterface +public interface CoopTask { + + public void run(ICoopTaskContext ctx); +} diff --git a/src/main/java/gregtech/api/task/CooperativeScheduler.java b/src/main/java/gregtech/api/task/CooperativeScheduler.java new file mode 100644 index 00000000000..1de35285898 --- /dev/null +++ b/src/main/java/gregtech/api/task/CooperativeScheduler.java @@ -0,0 +1,213 @@ +package gregtech.api.task; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import cpw.mods.fml.common.gameevent.TickEvent.Type; +import gregtech.GTMod; +import gregtech.api.util.GTUtility; +import gregtech.common.config.Gregtech; + +/** + * A simple cooperative scheduler that will run expensive tasks in the background without multithreading. + * + * This cooperative scheduler differs from typical schedulers in that it will try to run the oldest tasks first, without + * considering newer tasks. + * This is to prevent it from becoming clogged if something's generating bad tasks. + */ +public final class CooperativeScheduler { + + public static final CooperativeScheduler INSTANCE = new CooperativeScheduler(); + + private final LinkedHashMap> tasks = new LinkedHashMap<>(); + private final List> newTasks = new ArrayList<>(); + + private long start, end; + + private CooperativeScheduler() { + FMLCommonHandler.instance() + .bus() + .register(this); + } + + @SubscribeEvent + public void tick(TickEvent.ServerTickEvent event) { + if (event.phase != Phase.END || event.type != Type.SERVER) return; + + if (tasks.isEmpty() && newTasks.isEmpty()) return; + + start = System.nanoTime(); + end = 0; + + // we intentionally don't return to the previous ran task here + Iterator> iter = tasks.values() + .iterator(); + + while (iter.hasNext()) { + CoopFuture future = iter.next(); + + long start2 = 0; + + if (Gregtech.general.schedulerProfileLevel >= 2) { + start2 = System.nanoTime(); + } + + if (!future.running) { + iter.remove(); + continue; + } + + try { + future.run(); + } catch (Throwable t) { + GTMod.GT_FML_LOGGER.error( + "Caught error while running task; it will be cancelled (" + future.name + " " + future.task + ")", + t); + future.cancel(true); + } + + if (!future.running) { + iter.remove(); + } + + // poll the time if the task hasn't + if (end == 0) end = System.nanoTime(); + + if (Gregtech.general.schedulerProfileLevel >= 2) { + GTMod.GT_FML_LOGGER.info( + "Task " + future.name + + " " + + future.task + + " took " + + GTUtility.formatNumbers((end - start2) / 1e3) + + " microseconds"); + } + + if ((end - start) > Gregtech.general.schedulerDuration) { + break; + } + } + + if (Gregtech.general.schedulerProfileLevel >= 1) { + GTMod.GT_FML_LOGGER.info( + "Task scheduler took " + GTUtility.formatNumbers((System.nanoTime() - start) / 1e3) + " microseconds"); + } + + for (CoopFuture future : newTasks) { + future = tasks.put(future.name, future); + + if (future != null) { + future.cancelled = true; + future.running = false; + } + } + + newTasks.clear(); + } + + public CoopFuture schedule(CoopTask task) { + CoopFuture future = new CoopFuture<>(); + + future.name = UUID.randomUUID() + .toString(); + future.task = task; + + newTasks.add(future); + + return future; + } + + public CoopFuture schedule(String name, CoopTask task) { + CoopFuture future = new CoopFuture<>(); + + future.name = name; + future.task = task; + + newTasks.add(future); + + return future; + } + + public class CoopFuture implements Future, ICoopTaskContext { + + public String name; + public CoopTask task; + + public boolean running = true, cancelled = false; + public T value; + public Consumer callback; + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + if (running) { + running = false; + cancelled = true; + return true; + } else { + return false; + } + } + + @Override + public T get() { + if (running) { + throw new IllegalStateException("cannot call get() if the task hasn't finished"); + } + + return value; + } + + @Override + public T get(long timeout, TimeUnit unit) { + if (running) { + throw new IllegalStateException("cannot call get() if the task hasn't finished"); + } + + return value; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public boolean isDone() { + return !running; + } + + public void run() { + task.run(this); + } + + @Override + public boolean shouldYield() { + return (end = System.nanoTime()) - start + > (Gregtech.general.schedulerDuration / Math.min(tasks.size(), Gregtech.general.maxTaskCount)); + } + + @Override + public void stop(T value) { + running = false; + this.value = value; + if (callback != null) { + callback.accept(value); + } + } + + public CoopFuture onFinished(Consumer callback) { + this.callback = callback; + return this; + } + } +} diff --git a/src/main/java/gregtech/api/task/ICoopTaskContext.java b/src/main/java/gregtech/api/task/ICoopTaskContext.java new file mode 100644 index 00000000000..c65a65465a0 --- /dev/null +++ b/src/main/java/gregtech/api/task/ICoopTaskContext.java @@ -0,0 +1,8 @@ +package gregtech.api.task; + +public interface ICoopTaskContext { + + public boolean shouldYield(); + + public void stop(T value); +} diff --git a/src/main/java/gregtech/api/util/GTBaseCrop.java b/src/main/java/gregtech/api/util/GTBaseCrop.java index 0cc0e800367..249e7a759fa 100644 --- a/src/main/java/gregtech/api/util/GTBaseCrop.java +++ b/src/main/java/gregtech/api/util/GTBaseCrop.java @@ -11,16 +11,13 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import gregtech.GTMod; -import gregtech.api.GregTechAPI; import gregtech.api.enums.ConfigCategories; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.objects.ItemData; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; import ic2.api.crops.CropCard; import ic2.api.crops.Crops; import ic2.api.crops.ICropTile; @@ -244,22 +241,13 @@ public boolean isBlockBelow(ICropTile aCrop) { for (int i = 1; i < this.getrootslength(aCrop); i++) { Block tBlock = aCrop.getWorld() .getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); - if ((tBlock instanceof BlockOresAbstract)) { - TileEntity tTileEntity = aCrop.getWorld() - .getTileEntity(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); - if ((tTileEntity instanceof TileEntityOres)) { - Materials tMaterial = GregTechAPI.sGeneratedMaterials[(((TileEntityOres) tTileEntity).mMetaData - % 1000)]; - if ((tMaterial != null) && (tMaterial != Materials._NULL)) { - return tMaterial == mBlock; - } - } - } else { - int tMetaID = aCrop.getWorld() - .getBlockMetadata(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); - if (isBlockBelow(new ItemStack(tBlock, 1, tMetaID))) { - return true; - } + int tMetaID = aCrop.getWorld() + .getBlockMetadata(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); + + if (OreManager.getMaterial(tBlock, tMetaID) instanceof Materials gtMat) { + return gtMat == mBlock; + } else if (isBlockBelow(new ItemStack(tBlock, 1, tMetaID))) { + return true; } } return false; diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index c4a94424027..61f62a07953 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -119,7 +119,6 @@ import com.google.auto.value.AutoValue; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.collect.SetMultimap; import com.gtnewhorizon.structurelib.alignment.IAlignment; @@ -169,7 +168,7 @@ import gregtech.api.recipe.RecipeMaps; import gregtech.api.threads.RunnableSound; import gregtech.api.util.extensions.ArrayExt; -import gregtech.common.blocks.BlockOresAbstract; +import gregtech.common.ores.OreManager; import gregtech.common.pollution.Pollution; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; @@ -2338,6 +2337,26 @@ public static boolean arrayContainsNonNull(T... aArray) { return false; } + public static int indexOf(A[] array, B value) { + for (int i = 0; i < array.length; i++) { + if (array[i] == value) return i; + } + + return -1; + } + + public static boolean contains(A[] array, B value) { + return indexOf(array, value) != -1; + } + + public static T getIndexSafe(T[] array, int index) { + return index < 0 || index >= array.length ? null : array[index]; + } + + public static T getIndexSafe(List list, int index) { + return index < 0 || index >= list.size() ? null : list.get(index); + } + /** * Note: use {@link ArrayExt#withoutNulls(Object[], IntFunction)} if you want an array as a result. */ @@ -3917,6 +3936,14 @@ public static FakePlayer getFakePlayer(IGregTechTileEntity aBaseMetaTileEntity) return null; } + public static int hashCode(int... values) { + return Arrays.hashCode(values); + } + + public static long hashCode(long... values) { + return Arrays.hashCode(values); + } + public static boolean eraseBlockByFakePlayer(FakePlayer aPlayer, int aX, int aY, int aZ, boolean isSimulate) { if (aPlayer == null) return false; World aWorld = aPlayer.worldObj; @@ -4329,16 +4356,10 @@ public static boolean isPartOfOrePrefix(ItemStack aStack, OrePrefixes aPrefix) { && GTOreDictUnificator.getAssociation(aStack).mPrefix.equals(aPrefix); } - public static final ImmutableSet ORE_BLOCK_CLASSES = ImmutableSet.of( - "bartworks.system.material.BWMetaGeneratedOres", - "bartworks.system.material.BWMetaGeneratedSmallOres", - "gtPlusPlus.core.block.base.BlockBaseOre"); + public static boolean isOre(Block block, int meta) { + if (OreManager.isOre(block, meta)) return true; - public static boolean isOre(Block aBlock, int aMeta) { - return (aBlock instanceof BlockOresAbstract) || isOre(new ItemStack(aBlock, 1, aMeta)) - || ORE_BLOCK_CLASSES.contains( - aBlock.getClass() - .getName()); + return isOre(new ItemStack(block, 1, meta)); } public static boolean isOre(ItemStack aStack) { @@ -4518,6 +4539,10 @@ public static int clamp(int val, int lo, int hi) { return MathHelper.clamp_int(val, lo, hi); } + public static float clamp(float val, float lo, float hi) { + return val < lo ? lo : val > hi ? hi : val; + } + public static int min(int first, int... rest) { for (int i = 0; i < rest.length; i++) { int l = rest[i]; diff --git a/src/main/java/gregtech/api/util/LRUCache.java b/src/main/java/gregtech/api/util/LRUCache.java new file mode 100644 index 00000000000..1922340bc2f --- /dev/null +++ b/src/main/java/gregtech/api/util/LRUCache.java @@ -0,0 +1,31 @@ +package gregtech.api.util; + +import java.util.Optional; +import java.util.function.Function; + +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; + +public class LRUCache { + + public Object2ObjectLinkedOpenHashMap> map = new Object2ObjectLinkedOpenHashMap<>(); + public int capacity; + public Function lookup; + + public LRUCache(int capacity, Function lookup) { + this.capacity = capacity; + this.lookup = lookup; + } + + public V get(K key) { + Optional v = map.getAndMoveToFirst(key); + + if (v == null) { + v = Optional.ofNullable(lookup.apply(key)); + map.putAndMoveToFirst(key, v); + + while (map.size() > capacity) map.removeLast(); + } + + return v.orElse(null); + } +} diff --git a/src/main/java/gregtech/api/util/Lazy.java b/src/main/java/gregtech/api/util/Lazy.java new file mode 100644 index 00000000000..296b28138a4 --- /dev/null +++ b/src/main/java/gregtech/api/util/Lazy.java @@ -0,0 +1,32 @@ +package gregtech.api.util; + +import java.util.function.Supplier; + +public class Lazy implements Supplier { + + private boolean hasValue = false; + private T value; + + private Supplier getter; + + public Lazy(Supplier getter) { + this.getter = getter; + } + + public synchronized void set(T value) { + hasValue = true; + this.value = value; + getter = null; + } + + @Override + public synchronized T get() { + if (!hasValue) { + value = getter.get(); + getter = null; + hasValue = true; + } + + return value; + } +} diff --git a/src/main/java/gregtech/api/world/GTWorldgen.java b/src/main/java/gregtech/api/world/GTWorldgen.java index 07c76e0e3a5..2a18bbd553f 100644 --- a/src/main/java/gregtech/api/world/GTWorldgen.java +++ b/src/main/java/gregtech/api/world/GTWorldgen.java @@ -15,6 +15,13 @@ public abstract class GTWorldgen { public final boolean mEnabled; private final Map mDimensionMap = new ConcurrentHashMap<>(); + public static final int WRONG_BIOME = 0; + public static final int WRONG_DIMENSION = 1; + public static final int NO_ORE_IN_BOTTOM_LAYER = 2; + public static final int NO_OVERLAP = 3; + public static final int ORE_PLACED = 4; + public static final int NO_OVERLAP_AIR_BLOCK = 5; + @SuppressWarnings({ "unchecked", "rawtypes" }) // The adding of "this" needs a List which does not exist public GTWorldgen(String aName, List aList, boolean aDefault) { mWorldGenName = aName; @@ -31,14 +38,14 @@ public GTWorldgen(String aName, List aList, boolean aDefault) { * @param aChunkZ zCoord of the Chunk * @return if the Worldgeneration has been successfully completed */ - public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aChunkX, int aChunkZ, + IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { return false; } - public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, int seedX, int seedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - return 4; // This is for the empty Orevein + public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aChunkX, int aChunkZ, + int seedX, int seedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + return ORE_PLACED; // This is for the empty Orevein } /** diff --git a/src/main/java/gregtech/common/GTProxy.java b/src/main/java/gregtech/common/GTProxy.java index a1ca9b3eab6..25502eabe90 100644 --- a/src/main/java/gregtech/common/GTProxy.java +++ b/src/main/java/gregtech/common/GTProxy.java @@ -611,10 +611,15 @@ public abstract class GTProxy implements IGTMod, IFuelHandler { public boolean crashOnNullRecipeInput = false; public enum OreDropSystem { + /** Will always drop the block version. */ Block, + /** Will drop the dimension-specific block version, or stone. */ PerDimBlock, + /** Will always drop the stone block version. */ UnifiedBlock, + /** Drops raw ore, and is affected by fortune. */ FortuneItem, + /** Drops raw ore, and is not affected by fortune. */ Item } diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index 17cba343690..5069b3281c4 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -4,16 +4,15 @@ import static gregtech.api.enums.GTValues.debugWorldGen; import static gregtech.api.enums.GTValues.oreveinAttempts; import static gregtech.api.enums.GTValues.oreveinMaxPlacementAttempts; -import static gregtech.api.enums.GTValues.oreveinPercentage; +import static gregtech.api.enums.GTValues.profileWorldGen; -import java.util.ArrayList; -import java.util.HashSet; +import java.util.Collections; import java.util.Hashtable; +import java.util.LinkedList; import java.util.List; import java.util.Random; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; @@ -26,6 +25,10 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent; import cpw.mods.fml.common.registry.GameRegistry; +import galacticgreg.api.Enums.DimensionType; +import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.enums.DimensionDef; +import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; @@ -33,18 +36,14 @@ import gregtech.api.objects.XSTR; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.TileEntityOres; -import gregtech.common.config.Worldgen; +import gregtech.common.worldgen.WorldgenQuery; public class GTWorldgenerator implements IWorldGenerator { - private static int mEndAsteroidProbability = 300; - private static int mSize = 100; - private static int endMinSize = 50; - private static int endMaxSize = 200; - private static boolean endAsteroids = true; - public static List mList = new ArrayList<>(); - public static HashSet ProcChunks = new HashSet<>(); + private static final int MAX_VEIN_SIZE = 2; // in chunks + + private static final List PENDING_TASKS = Collections.synchronizedList(new LinkedList<>()); + // This is probably not going to work. Trying to create a fake orevein to put into hashtable when there will be no // ores in a vein. public static WorldgenGTOreLayer noOresInVein = new WorldgenGTOreLayer( @@ -61,14 +60,9 @@ public class GTWorldgenerator implements IWorldGenerator { public static Hashtable validOreveins = new Hashtable<>(1024); public boolean mIsGenerating = false; - public static final Object listLock = new Object(); public static OregenPattern oregenPattern = OregenPattern.AXISSYMMETRICAL; public GTWorldgenerator() { - endAsteroids = Worldgen.endAsteroids.generateEndAsteroids; - endMinSize = Worldgen.endAsteroids.EndAsteroidMinSize; - endMaxSize = Worldgen.endAsteroids.EndAsteroidMaxSize; - mEndAsteroidProbability = Worldgen.endAsteroids.EndAsteroidProbability; GameRegistry.registerWorldGenerator(this, 1073741823); if (debugWorldGen) { GTLog.out.println("GTWorldgenerator created"); @@ -78,52 +72,55 @@ public GTWorldgenerator() { @Override public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - synchronized (listLock) { - mList.add( - new WorldGenContainer( - new XSTR(Math.abs(aRandom.nextInt()) + 1), - aX, - aZ, - aWorld.provider.dimensionId, - aWorld, - aChunkGenerator, - aChunkProvider, - aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); - if (debugWorldGen) GTLog.out.println( - "ADD WorldSeed:" + aWorld.getSeed() - + " DimId" - + aWorld.provider.dimensionId - + " chunk x:" - + aX - + " z:" - + aZ - + " SIZE: " - + mList.size()); + + ModDimensionDef def = DimensionDef.getDefForWorld(aWorld, aX >> 4, aZ >> 4); + + if (def == null || def.getDimensionType() != DimensionType.Planet) { + return; } + PENDING_TASKS.add( + new WorldGenContainer( + new XSTR(Math.abs(aRandom.nextInt()) + 1), + aX, + aZ, + aWorld, + aChunkGenerator, + aChunkProvider, + aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); + if (debugWorldGen) GTLog.out.println( + "ADD WorldSeed:" + aWorld.getSeed() + + " DimName" + + aWorld.provider.getDimensionName() + + " chunk x:" + + aX + + " z:" + + aZ + + " SIZE: " + + PENDING_TASKS.size()); + + // hack to prevent cascading worldgen lag if (!this.mIsGenerating) { this.mIsGenerating = true; - int mList_sS = mList.size(); - mList_sS = Math.min(mList_sS, 5); // Run a maximum of 5 chunks at a time through worldgen. Extra chunks get - // done later. - for (int i = 0; i < mList_sS; i++) { - WorldGenContainer toRun = (WorldGenContainer) mList.get(0); + + // Run a maximum of 5 chunks at a time through worldgen. Extra chunks get done later. + for (int i = 0; i < Math.min(PENDING_TASKS.size(), 5); i++) { + WorldGenContainer task = PENDING_TASKS.remove(0); + if (debugWorldGen) GTLog.out.println( "RUN WorldSeed:" + aWorld.getSeed() + " DimId" + aWorld.provider.dimensionId + " chunk x:" - + toRun.mX + + task.mX + " z:" - + toRun.mZ + + task.mZ + " SIZE: " - + mList.size() + + PENDING_TASKS.size() + " i: " + i); - synchronized (listLock) { - mList.remove(0); - } - toRun.run(); + + task.run(); } this.mIsGenerating = false; } @@ -212,7 +209,6 @@ public static class WorldGenContainer implements Runnable { public final Random mRandom; public final int mX; public final int mZ; - public final int mDimensionType; public final World mWorld; public final IChunkProvider mChunkGenerator; public final IChunkProvider mChunkProvider; @@ -220,42 +216,12 @@ public static class WorldGenContainer implements Runnable { // Used for outputting orevein weights and bins // static int test=0; - // Local class to track which orevein seeds must be checked when doing chunkified worldgen - static class NearbySeeds { - - public int mX; - public int mZ; - - NearbySeeds(int x, int z) { - this.mX = x; - this.mZ = z; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NearbySeeds that)) return false; - if (this.mX != that.mX) return false; - return this.mZ == that.mZ; - } - - @Override - public int hashCode() { - int result = this.mX; - result = 31 * result + this.mZ; - return result; - } - } - - public static ArrayList seedList = new ArrayList<>(); - // aX and aZ are now the by-chunk X and Z for the chunk of interest - public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, World aWorld, - IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider, String aBiome) { + public WorldGenContainer(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, + IChunkProvider aChunkProvider, String aBiome) { this.mRandom = aRandom; this.mX = aX; this.mZ = aZ; - this.mDimensionType = aDimensionType; this.mWorld = aWorld; this.mChunkGenerator = aChunkGenerator; this.mChunkProvider = aChunkProvider; @@ -278,7 +244,7 @@ public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, Wor // oremixes, ie ore.mix.diamond, to check how many appear in the list. // - For more complex work, import file into Excel, and sort based on oremix // column. Drag select the oremix names, in the bottom right will be how many - // entries to add in a seperate tab to calculate %ages. + // entries to add in a separate tab to calculate %ages. // // When using the ore weights, discount or remove the high altitude veins since // their high weight are offset by their rareness. I usually just use zero for them. @@ -286,7 +252,7 @@ public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, Wor // in the dimension. For example veins that range above and below the average height // will be less, and veins that are completely above the average height will be much less. - public void worldGenFindVein(int oreseedX, int oreseedZ) { + public void generateVein(int oreseedX, int oreseedZ) { // Explanation of oreveinseed implementation. // (long)this.mWorld.getSeed()<<16) Deep Dark does two oregen passes, one with getSeed set to +1 the // original world seed. This pushes that +1 off the low bits of oreseedZ, so that the hashes are far apart @@ -303,12 +269,10 @@ public void worldGenFindVein(int oreseedX, int oreseedZ) { // called for // this oreseed. XSTR oreveinRNG = new XSTR(oreveinSeed); + int oreveinPercentageRoll = oreveinRNG.nextInt(100); // Roll the dice, see if we get an orevein here at all - int noOrePlacedCount = 0; - String tDimensionName = ""; - if (debugOrevein) { - tDimensionName = this.mWorld.provider.getDimensionName(); - } + + String dimensionName = this.mWorld.provider.getDimensionName(); if (debugOrevein) GTLog.out.println( " Finding oreveins for oreveinSeed=" + oreveinSeed @@ -324,166 +288,27 @@ public void worldGenFindVein(int oreseedX, int oreseedZ) { + this.mWorld.getSeed()); // Search for a valid orevein for this dimension - if (!validOreveins.containsKey(oreveinSeed)) { - if ((oreveinPercentageRoll < oreveinPercentage) && (WorldgenGTOreLayer.sWeight > 0) - && (!WorldgenGTOreLayer.sList.isEmpty())) { - int placementAttempts = 0; - boolean oreveinFound = false; - int i; - - // Used for outputting orevein weights and bins - /* - * if( test==0 ) { test = 1; GTLog.out.println( "sWeight = " + GT_Worldgen_GT_Ore_Layer.sWeight ); - * for (GT_Worldgen_GT_Ore_Layer tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) { GTLog.out.println( ( - * tWorldGen).mWorldGenName + " mWeight = " + ( tWorldGen).mWeight + " mSize = " + (tWorldGen).mSize - * ); } } - */ - for (i = 0; (i < oreveinAttempts) && (!oreveinFound) - && (placementAttempts < oreveinMaxPlacementAttempts); i++) { - int tRandomWeight = oreveinRNG.nextInt(WorldgenGTOreLayer.sWeight); - for (WorldgenGTOreLayer tWorldGen : WorldgenGTOreLayer.sList) { - tRandomWeight -= (tWorldGen).mWeight; - if (tRandomWeight <= 0) { - try { - // Adjust the seed so that this layer has a series of unique random numbers. - // Otherwise multiple attempts at this same oreseed will get the same offset and X/Z - // values. If an orevein failed, any orevein with the - // same minimum heights would fail as well. This prevents that, giving each orevein - // a unique height each pass through here. - int placementResult = tWorldGen.executeWorldgenChunkified( - this.mWorld, - new XSTR(oreveinSeed ^ (tWorldGen.mPrimaryMeta)), - this.mBiome, - this.mDimensionType, - this.mX * 16, - this.mZ * 16, - oreseedX * 16, - oreseedZ * 16, - this.mChunkGenerator, - this.mChunkProvider); - switch (placementResult) { - case WorldgenGTOreLayer.ORE_PLACED -> { - if (debugOrevein) GTLog.out.println( - " Added near oreveinSeed=" + oreveinSeed - + " " - + (tWorldGen).mWorldGenName - + " tries at oremix=" - + i - + " placementAttempts=" - + placementAttempts - + " dimensionName=" - + tDimensionName); - validOreveins.put(oreveinSeed, tWorldGen); - oreveinFound = true; - } - case WorldgenGTOreLayer.NO_ORE_IN_BOTTOM_LAYER -> placementAttempts++; - - // SHould do retry in this case until out of chances - case WorldgenGTOreLayer.NO_OVERLAP -> { - if (debugOrevein) GTLog.out.println( - " Added far oreveinSeed=" + oreveinSeed - + " " - + (tWorldGen).mWorldGenName - + " tries at oremix=" - + i - + " placementAttempts=" - + placementAttempts - + " dimensionName=" - + tDimensionName); - validOreveins.put(oreveinSeed, tWorldGen); - oreveinFound = true; - } - case WorldgenGTOreLayer.NO_OVERLAP_AIR_BLOCK -> { - if (debugOrevein) GTLog.out.println( - " No overlap and air block in test spot=" + oreveinSeed - + " " - + (tWorldGen).mWorldGenName - + " tries at oremix=" - + i - + " placementAttempts=" - + placementAttempts - + " dimensionName=" - + tDimensionName); - // SHould do retry in this case until out of chances - placementAttempts++; - } - } - break; // Try the next orevein - } catch (Throwable e) { - if (debugOrevein) GTLog.out.println( - "Exception occurred on oreVein" + tWorldGen - + " oreveinSeed=" - + oreveinSeed - + " mX=" - + this.mX - + " mZ=" - + this.mZ - + " oreseedX=" - + oreseedX - + " oreseedZ=" - + oreseedZ); - e.printStackTrace(GTLog.err); - } - } - } - } - // Only add an empty orevein if unable to place a vein at the oreseed chunk. - if ((!oreveinFound) && (this.mX == oreseedX) && (this.mZ == oreseedZ)) { - if (debugOrevein) GTLog.out.println( - " Empty oreveinSeed=" + oreveinSeed - + " mX=" - + this.mX - + " mZ=" - + this.mZ - + " oreseedX=" - + oreseedX - + " oreseedZ=" - + oreseedZ - + " tries at oremix=" - + i - + " placementAttempts=" - + placementAttempts - + " dimensionName=" - + tDimensionName); - validOreveins.put(oreveinSeed, noOresInVein); - } - } else if (oreveinPercentageRoll >= oreveinPercentage) { - if (debugOrevein) GTLog.out.println( - " Skipped oreveinSeed=" + oreveinSeed - + " mX=" - + this.mX - + " mZ=" - + this.mZ - + " oreseedX=" - + oreseedX - + " oreseedZ=" - + oreseedZ - + " RNG=" - + oreveinPercentageRoll - + " %=" - + oreveinPercentage - + " dimensionName=" - + tDimensionName); - validOreveins.put(oreveinSeed, noOresInVein); - } - } else { + + if (validOreveins.containsKey(oreveinSeed)) { // oreseed is located in the previously processed table if (debugOrevein) GTLog.out .print(" Valid oreveinSeed=" + oreveinSeed + " validOreveins.size()=" + validOreveins.size() + " "); WorldgenGTOreLayer tWorldGen = validOreveins.get(oreveinSeed); - oreveinRNG.setSeed(oreveinSeed ^ (tWorldGen.mPrimaryMeta)); // Reset RNG to only be based on oreseed X/Z - // and type of vein + + // Reset RNG to only be based on oreseed X/Z and type of vein + oreveinRNG.setSeed(oreveinSeed ^ tWorldGen.mPrimary.getId()); + int placementResult = tWorldGen.executeWorldgenChunkified( this.mWorld, oreveinRNG, this.mBiome, - this.mDimensionType, this.mX * 16, this.mZ * 16, oreseedX * 16, oreseedZ * 16, this.mChunkGenerator, this.mChunkProvider); + switch (placementResult) { case WorldgenGTOreLayer.NO_ORE_IN_BOTTOM_LAYER -> { if (debugOrevein) GTLog.out.println(" No ore in bottom layer"); @@ -492,6 +317,155 @@ public void worldGenFindVein(int oreseedX, int oreseedZ) { if (debugOrevein) GTLog.out.println(" No overlap"); } } + + return; + } + + ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(mWorld, oreseedX, oreseedZ); + + if (oreveinPercentageRoll < dimensionDef.getOreVeinChance()) { + int placementAttempts = 0; + boolean oreveinFound = false; + int i = 0; + + // Used for outputting orevein weights and bins + /* + * if( test==0 ) { test = 1; GTLog.out.println( "sWeight = " + GT_Worldgen_GT_Ore_Layer.sWeight ); + * for (GT_Worldgen_GT_Ore_Layer tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) { GTLog.out.println( ( + * tWorldGen).mWorldGenName + " mWeight = " + ( tWorldGen).mWeight + " mSize = " + (tWorldGen).mSize + * ); } } + */ + + for (i = 0; i < oreveinAttempts && placementAttempts < oreveinMaxPlacementAttempts + && !oreveinFound; i++) { + WorldgenGTOreLayer oreLayer = WorldgenQuery.veins() + .inDimension(dimensionName) + .find(oreveinRNG); + + // there aren't any veins in this dimension so there's no point in retrying + if (oreLayer == null) break; + + int placementResult = 0; + + try { + // Adjust the seed so that this layer has a series of unique random numbers. + // Otherwise multiple attempts at this same oreseed will get the same offset and X/Z + // values. If an orevein failed, any orevein with the + // same minimum heights would fail as well. This prevents that, giving each orevein + // a unique height each pass through here. + placementResult = oreLayer.executeWorldgenChunkified( + this.mWorld, + new XSTR(oreveinSeed ^ (oreLayer.mPrimary.getId())), + this.mBiome, + this.mX * 16, + this.mZ * 16, + oreseedX * 16, + oreseedZ * 16, + this.mChunkGenerator, + this.mChunkProvider); + } catch (Throwable e) { + if (debugOrevein) GTLog.out.println( + "Exception occurred on oreVein" + oreLayer + + " oreveinSeed=" + + oreveinSeed + + " mX=" + + this.mX + + " mZ=" + + this.mZ + + " oreseedX=" + + oreseedX + + " oreseedZ=" + + oreseedZ); + e.printStackTrace(GTLog.err); + } + + switch (placementResult) { + case WorldgenGTOreLayer.ORE_PLACED -> { + if (debugOrevein) GTLog.out.println( + " Added near oreveinSeed=" + oreveinSeed + + " " + + oreLayer.mWorldGenName + + " tries at oremix=" + + i + + " placementAttempts=" + + placementAttempts + + " dimensionName=" + + dimensionName); + validOreveins.put(oreveinSeed, oreLayer); + oreveinFound = true; + } + case WorldgenGTOreLayer.NO_ORE_IN_BOTTOM_LAYER -> placementAttempts++; + + // Should retry in this case until out of chances + case WorldgenGTOreLayer.NO_OVERLAP -> { + if (debugOrevein) GTLog.out.println( + " Added far oreveinSeed=" + oreveinSeed + + " " + + oreLayer.mWorldGenName + + " tries at oremix=" + + i + + " placementAttempts=" + + placementAttempts + + " dimensionName=" + + dimensionName); + validOreveins.put(oreveinSeed, oreLayer); + oreveinFound = true; + } + case WorldgenGTOreLayer.NO_OVERLAP_AIR_BLOCK -> { + if (debugOrevein) GTLog.out.println( + " No overlap and air block in test spot=" + oreveinSeed + + " " + + oreLayer.mWorldGenName + + " tries at oremix=" + + i + + " placementAttempts=" + + placementAttempts + + " dimensionName=" + + dimensionName); + // Should retry in this case until out of chances + placementAttempts++; + } + } + } + + // Only add an empty orevein if unable to place a vein at the oreseed chunk. + if (!oreveinFound && this.mX == oreseedX && this.mZ == oreseedZ) { + if (debugOrevein) GTLog.out.println( + " Empty oreveinSeed=" + oreveinSeed + + " mX=" + + this.mX + + " mZ=" + + this.mZ + + " oreseedX=" + + oreseedX + + " oreseedZ=" + + oreseedZ + + " tries at oremix=" + + i + + " placementAttempts=" + + placementAttempts + + " dimensionName=" + + dimensionName); + validOreveins.put(oreveinSeed, noOresInVein); + } + } else if (oreveinPercentageRoll >= dimensionDef.getOreVeinChance()) { + if (debugOrevein) GTLog.out.println( + " Skipped oreveinSeed=" + oreveinSeed + + " mX=" + + this.mX + + " mZ=" + + this.mZ + + " oreseedX=" + + oreseedX + + " oreseedZ=" + + oreseedZ + + " RNG=" + + oreveinPercentageRoll + + " %=" + + dimensionDef.getOreVeinChance() + + " dimensionName=" + + dimensionName); + validOreveins.put(oreveinSeed, noOresInVein); } } @@ -500,8 +474,6 @@ public void run() { long startTime = System.nanoTime(); Chunk tChunk = this.mWorld.getChunkFromChunkCoords(this.mX, this.mZ); - int oreveinMaxSize; - // Do GT_Stones and GT_small_ores oregen for this chunk try { for (GTWorldgen tWorldGen : GregTechAPI.sWorldgenList) { @@ -512,7 +484,6 @@ public void run() { this.mWorld, this.mRandom, this.mBiome, - this.mDimensionType, this.mX * 16, this.mZ * 16, this.mChunkGenerator, @@ -521,165 +492,41 @@ public void run() { } catch (Throwable e) { e.printStackTrace(GTLog.err); } - long leftOverTime = System.nanoTime(); - // Determine bounding box on how far out to check for oreveins affecting this chunk - // For now, manually reducing oreveinMaxSize when not in the Underdark for performance - if (this.mWorld.provider.getDimensionName() - .equals("Underdark")) { - oreveinMaxSize = 32; // Leave Deep Dark/Underdark max oregen at 32, instead of 64 - } else { - oreveinMaxSize = 32; - } + long stonegenTime = System.nanoTime(); - int wXbox = this.mX - (oreveinMaxSize / 16); - int eXbox = this.mX + (oreveinMaxSize / 16 + 1); // Need to add 1 since it is compared using a < - int nZbox = this.mZ - (oreveinMaxSize / 16); - int sZbox = this.mZ + (oreveinMaxSize / 16 + 1); + int chunkMinX = this.mX - MAX_VEIN_SIZE; + int chunkMaxX = this.mX + MAX_VEIN_SIZE + 1; // Need to add 1 since it is compared using a < + int chunkMinZ = this.mZ - MAX_VEIN_SIZE; + int chunkMaxZ = this.mZ + MAX_VEIN_SIZE + 1; // Search for orevein seeds and add to the list; - for (int x = wXbox; x < eXbox; x++) { - for (int z = nZbox; z < sZbox; z++) { + for (int x = chunkMinX; x < chunkMaxX; x++) { + for (int z = chunkMinZ; z < chunkMaxZ; z++) { // Determine if this X/Z is an orevein seed if (isOreChunk(x, z)) { - if (debugWorldGen) GTLog.out.println("Adding seed x=" + x + " z=" + z); - seedList.add(new NearbySeeds(x, z)); + if (debugWorldGen) GTLog.out.println("Processing seed x=" + x + " z=" + z); + generateVein(x, z); } } } - // Now process each oreseed vs this requested chunk - for (; !seedList.isEmpty(); seedList.remove(0)) { - if (debugWorldGen) - GTLog.out.println("Processing seed x=" + seedList.get(0).mX + " z=" + seedList.get(0).mZ); - worldGenFindVein(seedList.get(0).mX, seedList.get(0).mZ); - } - long oregenTime = System.nanoTime(); - // Asteroid Worldgen - int tDimensionType = this.mWorld.provider.dimensionId; - // String tDimensionName = this.mWorld.provider.getDimensionName(); - // if (((tDimensionType == 1) && endAsteroids && ((mEndAsteroidProbability <= 1) || - // (aRandom.nextInt(mEndAsteroidProbability) == 0))) || ((tDimensionName.equals("Asteroids")) && gcAsteroids - // && ((mGCAsteroidProbability <= 1) || (aRandom.nextInt(mGCAsteroidProbability) == 0)))) { - if ((tDimensionType == 1 /* the end */) && endAsteroids) { - XSTR random = new XSTR( - mWorld.getSeed() + mX * mX * 91777L + mZ * mZ * 137413L + mX * mZ * 1853L + mX * 3L + mZ * 17L); - - if (mEndAsteroidProbability <= 1 || random.nextInt(mEndAsteroidProbability) == 0) { - generateAsteroid(mWorld, random, mX, mZ); - } - } - if (tChunk != null) { tChunk.isModified = true; } + long endTime = System.nanoTime(); - long duration = (endTime - startTime); - if (debugWorldGen) { - GTLog.out.println( - " Oregen took " + (oregenTime - leftOverTime) - + " Leftover gen took " - + (leftOverTime - startTime) - + " Worldgen took " - + duration - + " nanoseconds"); - } - } - private void generateAsteroid(World world, Random random, int chunkX, int chunkZ) { - short primaryMeta = 0; - short secondaryMeta = 0; - short betweenMeta = 0; - short sporadicMeta = 0; - if ((WorldgenGTOreLayer.sWeight > 0) && (!WorldgenGTOreLayer.sList.isEmpty())) { - boolean temp = true; - int tRandomWeight; - for (int i = 0; (i < oreveinAttempts) && (temp); i++) { - tRandomWeight = random.nextInt(WorldgenGTOreLayer.sWeight); - for (WorldgenGTOreLayer tWorldGen : WorldgenGTOreLayer.sList) { - tRandomWeight -= tWorldGen.mWeight; - if (tRandomWeight <= 0) { - try { - if (tWorldGen.mEndAsteroid) { - primaryMeta = tWorldGen.mPrimaryMeta; - secondaryMeta = tWorldGen.mSecondaryMeta; - betweenMeta = tWorldGen.mBetweenMeta; - sporadicMeta = tWorldGen.mSporadicMeta; - temp = false; - break; - } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - } - } - } - } - // if(GT_Values.D1)GT_FML_LOGGER.info("do asteroid gen: "+this.mX+" "+this.mZ); - int tX = chunkX * 16 + random.nextInt(16); - int tY = 50 + random.nextInt(200 - 50); - int tZ = chunkZ * 16 + random.nextInt(16); - mSize = endMinSize + random.nextInt(endMaxSize - endMinSize + 1); - - if ((world.getBlock(tX, tY, tZ) - .isAir(world, tX, tY, tZ))) { - float randomRadian = random.nextFloat() * (float) Math.PI; - double xBase = tX + 8 + MathHelper.sin(randomRadian) * mSize / 8.0F; - double xFactor = tX + 8 - MathHelper.sin(randomRadian) * mSize / 8.0F; - double zBase = tZ + 8 + MathHelper.cos(randomRadian) * mSize / 8.0F; - double zFactor = tZ + 8 - MathHelper.cos(randomRadian) * mSize / 8.0F; - double yBase = tY + random.nextInt(3) - 2; - double yFactor = tY + random.nextInt(3) - 2; - - for (int i = 0; i <= mSize; i++) { - double xCenter = xBase + (xFactor - xBase) * i / mSize; - double yCenter = yBase + (yFactor - yBase) * i / mSize; - double zCenter = zBase + (zFactor - zBase) * i / mSize; - double randomDistance = random.nextDouble() * mSize / 16.0D; - double halfLength = (MathHelper.sin(i * (float) Math.PI / mSize) + 1.0F) * randomDistance + 1.0D; - double halfHeight = (MathHelper.sin(i * (float) Math.PI / mSize) + 1.0F) * randomDistance + 1.0D; - int tMinX = MathHelper.floor_double(xCenter - halfLength / 2.0D); - int tMinY = MathHelper.floor_double(yCenter - halfHeight / 2.0D); - int tMinZ = MathHelper.floor_double(zCenter - halfLength / 2.0D); - int tMaxX = MathHelper.floor_double(xCenter + halfLength / 2.0D); - int tMaxY = MathHelper.floor_double(yCenter + halfHeight / 2.0D); - int tMaxZ = MathHelper.floor_double(zCenter + halfLength / 2.0D); - - for (int eX = tMinX; eX <= tMaxX; eX++) { - double xChance = (eX + 0.5D - xCenter) / (halfLength / 2.0D); - if (xChance * xChance < 1.0D) { - for (int eY = tMinY; eY <= tMaxY; eY++) { - double yChance = (eY + 0.5D - yCenter) / (halfHeight / 2.0D); - if (xChance * xChance + yChance * yChance < 1.0D) { - for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) { - double zChance = (eZ + 0.5D - zCenter) / (halfLength / 2.0D); - if (xChance * xChance + yChance * yChance + zChance * zChance >= 1.0D) { - continue; - } - if (!world.getBlock(tX, tY, tZ) - .isAir(world, tX, tY, tZ)) { - continue; - } - int ranOre = random.nextInt(50); - if (ranOre < 3) { - TileEntityOres.setOreBlock(world, eX, eY, eZ, primaryMeta, false); - } else if (ranOre < 6) { - TileEntityOres.setOreBlock(world, eX, eY, eZ, secondaryMeta, false); - } else if (ranOre < 8) { - TileEntityOres.setOreBlock(world, eX, eY, eZ, betweenMeta, false); - } else if (ranOre < 10) { - TileEntityOres.setOreBlock(world, eX, eY, eZ, sporadicMeta, false); - } else { - world.setBlock(eX, eY, eZ, Blocks.end_stone, 0, 0); - } - } - } - } - } - } - } + if (debugWorldGen || profileWorldGen) { + GTMod.GT_FML_LOGGER.info( + " Oregen took " + (oregenTime - stonegenTime) / 1e3 + + "us Stonegen took " + + (stonegenTime - startTime) / 1e3 + + "us Worldgen took " + + (endTime - startTime) / 1e3 + + "us"); } } } diff --git a/src/main/java/gregtech/common/OreMixBuilder.java b/src/main/java/gregtech/common/OreMixBuilder.java index 86453ca0a8f..896c0cbb08b 100644 --- a/src/main/java/gregtech/common/OreMixBuilder.java +++ b/src/main/java/gregtech/common/OreMixBuilder.java @@ -1,24 +1,26 @@ package gregtech.common; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; import galacticgreg.api.enums.DimensionDef; import gregtech.api.enums.Materials; +import gregtech.api.enums.StoneCategory; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneCategory; public class OreMixBuilder { - public static final String OW = "Overworld"; - public static final String NETHER = "Nether"; - public static final String THE_END = "TheEnd"; - public static final String TWILIGHT_FOREST = "Twilight Forest"; public String oreMixName; public boolean enabledByDefault = true; - public Map dimsEnabled = new HashMap<>(); + /** {full dim name} */ + public Set dimsEnabled = new HashSet<>(); public int minY, maxY, weight, density, size; - public Materials primary, secondary, between, sporadic, representative; + public IOreMaterial primary, secondary, between, sporadic, representative; public String localizedName; + public Set stoneCategories = new HashSet<>(Arrays.asList(StoneCategory.Stone)); + public boolean defaultStoneCategories = true; public OreMixBuilder name(String name) { this.oreMixName = name; @@ -32,14 +34,14 @@ public OreMixBuilder disabledByDefault() { public OreMixBuilder enableInDim(DimensionDef... dims) { for (DimensionDef dim : dims) { - this.dimsEnabled.put(dim.modDimensionDef.getDimensionName(), true); + this.dimsEnabled.add(dim.modDimensionDef.getDimensionName()); } return this; } public OreMixBuilder enableInDim(String... dims) { for (String dim : dims) { - this.dimsEnabled.put(dim, true); + this.dimsEnabled.add(dim); } return this; } @@ -65,30 +67,41 @@ public OreMixBuilder size(int size) { return this; } - public OreMixBuilder primary(Materials primary) { + public OreMixBuilder primary(IOreMaterial primary) { this.primary = primary; if (representative == null || localizedName == null) { representative = primary; - localizedName = primary.mLocalizedName; + localizedName = primary.getLocalizedName(); } return this; } - public OreMixBuilder secondary(Materials secondary) { + public OreMixBuilder secondary(IOreMaterial secondary) { this.secondary = secondary; return this; } - public OreMixBuilder inBetween(Materials between) { + public OreMixBuilder inBetween(IOreMaterial between) { this.between = between; return this; } - public OreMixBuilder sporadic(Materials sporadic) { + public OreMixBuilder sporadic(IOreMaterial sporadic) { this.sporadic = sporadic; return this; } + public OreMixBuilder stoneCategory(IStoneCategory... stoneCategories) { + if (defaultStoneCategories) { + this.stoneCategories = new HashSet<>(); + defaultStoneCategories = false; + } + + this.stoneCategories.addAll(Arrays.asList(stoneCategories)); + + return this; + } + /** * Sets the localized name for the ore mix based on the provided materials. * If more than one material is provided, their localized names are concatenated diff --git a/src/main/java/gregtech/common/SmallOreBuilder.java b/src/main/java/gregtech/common/SmallOreBuilder.java index 727ea98fc6b..d990044e6f9 100644 --- a/src/main/java/gregtech/common/SmallOreBuilder.java +++ b/src/main/java/gregtech/common/SmallOreBuilder.java @@ -1,22 +1,23 @@ package gregtech.common; -import java.util.HashMap; -import java.util.Map; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import galacticgreg.api.enums.DimensionDef; -import gregtech.api.enums.Materials; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneCategory; public class SmallOreBuilder { - public static final String OW = "Overworld"; - public static final String NETHER = "Nether"; - public static final String THE_END = "TheEnd"; - public static final String TWILIGHT_FOREST = "Twilight Forest"; public String smallOreName; public boolean enabledByDefault = true; - public Map dimsEnabled = new HashMap<>(); + /** {full dimension name} */ + public Set dimsEnabled = new HashSet<>(); public int minY, maxY, amount; - public Materials ore; + public IOreMaterial ore; + public Set stoneCategories; + public boolean defaultStoneCategories = true; public SmallOreBuilder name(String name) { this.smallOreName = name; @@ -30,14 +31,14 @@ public SmallOreBuilder disabledByDefault() { public SmallOreBuilder enableInDim(DimensionDef... dims) { for (DimensionDef dim : dims) { - this.dimsEnabled.put(dim.modDimensionDef.getDimensionName(), true); + this.dimsEnabled.add(dim.modDimensionDef.getDimensionName()); } return this; } public SmallOreBuilder enableInDim(String... dims) { for (String dim : dims) { - this.dimsEnabled.put(dim, true); + this.dimsEnabled.add(dim); } return this; } @@ -53,8 +54,19 @@ public SmallOreBuilder amount(int amount) { return this; } - public SmallOreBuilder ore(Materials ore) { + public SmallOreBuilder ore(IOreMaterial ore) { this.ore = ore; return this; } + + public SmallOreBuilder stoneType(IStoneCategory... stoneCategories) { + if (defaultStoneCategories) { + this.stoneCategories = new HashSet<>(); + defaultStoneCategories = false; + } + + this.stoneCategories.addAll(Arrays.asList(stoneCategories)); + + return this; + } } diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 0e7c69b867a..37872587afa 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -5,69 +5,44 @@ import static gregtech.api.enums.GTValues.oreveinPlacerOresMultiplier; import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; import java.util.Random; +import java.util.Set; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import net.minecraft.world.WorldProviderEnd; -import net.minecraft.world.WorldProviderHell; -import net.minecraft.world.WorldProviderSurface; import net.minecraft.world.chunk.IChunkProvider; -import galacticgreg.api.enums.DimensionDef; -import gregtech.api.GregTechAPI; +import gregtech.api.enums.StoneType; +import gregtech.api.events.GTEventBus; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneCategory; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; +import gregtech.common.worldgen.IWorldgenLayer; +import gregtech.common.worldgen.VeinGenerateEvent; -public class WorldgenGTOreLayer extends GTWorldgen { +public class WorldgenGTOreLayer extends GTWorldgen implements IWorldgenLayer { - public static ArrayList sList = new ArrayList<>(); - public static int sWeight = 0; + public static final ArrayList sList = new ArrayList<>(); 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; + public final IOreMaterial mPrimary; + public final IOreMaterial mSecondary; + public final IOreMaterial mBetween; + public final IOreMaterial mSporadic; public final String mRestrictBiome; - public final boolean mOverworld; - public final boolean mNether; - public final boolean mEnd; - public final boolean mEndAsteroid; - public final boolean twilightForest; - public static final int WRONG_BIOME = 0; - public static final int WRONG_DIMENSION = 1; - public static final int NO_ORE_IN_BOTTOM_LAYER = 2; - public static final int NO_OVERLAP = 3; - public static final int ORE_PLACED = 4; - public static final int NO_OVERLAP_AIR_BLOCK = 5; + /** {full dim name} */ + private final Set mAllowedDimensions; + private final Set mAllowedStone; public final String aTextWorldgen = "worldgen."; - public Class[] mAllowedProviders; - public String[] blackListedProviders; - public static Class tfProviderClass; - - static { - try { - tfProviderClass = Class.forName("twilightforest.world.WorldProviderTwilightForest"); - } catch (ClassNotFoundException ignored) {} - } - public WorldgenGTOreLayer(OreMixBuilder mix) { super(mix.oreMixName, sList, mix.enabledByDefault); - this.mOverworld = mix.dimsEnabled.getOrDefault(OreMixBuilder.OW, false); - this.mNether = mix.dimsEnabled.getOrDefault(OreMixBuilder.NETHER, false); - this.mEnd = mix.dimsEnabled.getOrDefault(OreMixBuilder.THE_END, false); - this.mEndAsteroid = mix.dimsEnabled - .getOrDefault(DimensionDef.EndAsteroids.modDimensionDef.getDimensionName(), false); - this.twilightForest = mix.dimsEnabled.getOrDefault(OreMixBuilder.TWILIGHT_FOREST, false); + this.mAllowedDimensions = new HashSet<>(mix.dimsEnabled); this.mMinY = ((short) mix.minY); short mMaxY = ((short) mix.maxY); if (mMaxY < (this.mMinY + 9)) { @@ -78,102 +53,146 @@ public WorldgenGTOreLayer(OreMixBuilder mix) { this.mWeight = (short) mix.weight; this.mDensity = (short) mix.density; this.mSize = (short) Math.max(1, mix.size); - this.mPrimaryMeta = (short) mix.primary.mMetaItemSubID; - this.mSecondaryMeta = (short) mix.secondary.mMetaItemSubID; - this.mBetweenMeta = (short) mix.between.mMetaItemSubID; - this.mSporadicMeta = (short) mix.sporadic.mMetaItemSubID; + this.mPrimary = mix.primary; + this.mSecondary = mix.secondary; + this.mBetween = mix.between; + this.mSporadic = mix.sporadic; + this.mAllowedStone = mix.stoneCategories == null ? null : new HashSet<>(mix.stoneCategories); this.mRestrictBiome = "None"; + } - if (this.mEnabled) { - sWeight += this.mWeight; - } + @Override + public int getMinY() { + return mMinY; + } - List allowedProviders = new ArrayList<>(); - if (this.mNether) { - allowedProviders.add(WorldProviderHell.class); - } + @Override + public int getMaxY() { + return mMaxY; + } - if (this.mOverworld) { - allowedProviders.add(WorldProviderSurface.class); - if (!this.twilightForest) { - blackListedProviders = new String[] { "twilightforest.world.WorldProviderTwilightForest" }; - } + @Override + public int getWeight() { + return mWeight; + } + + @Override + public float getDensity() { + return 1f / (float) mDensity; + } + + @Override + public boolean canGenerateIn(String dimName) { + return mAllowedDimensions.contains(dimName); + } + + @Override + public boolean canGenerateIn(IStoneCategory stoneType) { + return mAllowedStone != null && mAllowedStone.contains(stoneType); + } + + @Override + public boolean isStoneSpecific() { + return mAllowedStone != null; + } + + @Override + public boolean contains(IOreMaterial material) { + return mPrimary == material || mBetween == material || mSecondary == material || mSporadic == material; + } + + @Override + public IOreMaterial getOre(float k) { + if (k < 1.0 / 7.0) { + return mSporadic; } - if (tfProviderClass != null && this.twilightForest) { - allowedProviders.add(tfProviderClass); + if (k < 3.0 / 7.0) { + return mBetween; } - if (this.mEnd) { - allowedProviders.add(WorldProviderEnd.class); + if (k < 5.0 / 7.0) { + return mSecondary; } - mAllowedProviders = allowedProviders.toArray(new Class[0]); + + return mPrimary; + } + + @Override + public String getName() { + return mWorldGenName; } @Override - public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, int aSeedX, int aSeedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + public boolean generatesBigOre() { + return true; + } + + public Set getAllowedDimensions() { + return mAllowedDimensions; + } + + @Override + public int executeWorldgenChunkified(World world, Random rng, String biome, int chunkX, int chunkZ, int seedX, + int seedZ, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + VeinGenerateEvent event = new VeinGenerateEvent(world, chunkX, chunkZ, seedX, seedZ, this); + + if (GTEventBus.bus() + .post(event)) { + return event.getOreGenResult(); + } + if (mWorldGenName.equals("NoOresInVein")) { if (debugOrevein) GTLog.out.println(" NoOresInVein"); // Return a special empty orevein return ORE_PLACED; } - if (!isGenerationAllowed(aWorld, blackListedProviders, mAllowedProviders)) { + if (!mAllowedDimensions.contains(world.provider.getDimensionName())) { // The following code can be used for debugging, but it spams in logs // if (debugOrevein) { GTLog.out.println( "Wrong dimension" ); } return WRONG_DIMENSION; } - if (!this.mRestrictBiome.equals("None") && !(this.mRestrictBiome.equals(aBiome))) { + if (!this.mRestrictBiome.equals("None") && !this.mRestrictBiome.equals(biome)) { return WRONG_BIOME; } - // For optimal performance, this should be done upstream. Meh - String tDimensionName = aWorld.provider.getDimensionName(); - boolean isUnderdark = tDimensionName.equals("Underdark"); int[] placeCount = new int[4]; - int tMinY = mMinY + aRandom.nextInt(mMaxY - mMinY - 5); + int veinMinY = mMinY + rng.nextInt(mMaxY - mMinY - 5); // Determine West/East ends of orevein - int wXVein = aSeedX - aRandom.nextInt(mSize); // West side - int eXVein = aSeedX + 16 + aRandom.nextInt(mSize); + int veinWestX = seedX - rng.nextInt(mSize); // West side + int veinEastX = seedX + 16 + rng.nextInt(mSize); // Limit Orevein to only blocks present in current chunk - int wX = Math.max(wXVein, aChunkX + 2); // Bias placement by 2 blocks to prevent worldgen cascade. - int eX = Math.min(eXVein, aChunkX + 2 + 16); - - // Get a block at the center of the chunk and the bottom of the orevein. - Block tBlock = aWorld.getBlock(aChunkX + 7, tMinY, aChunkZ + 9); - - if (wX >= eX) { // No overlap between orevein and this chunk exists in X - if (tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, Blocks.stone) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, Blocks.netherrack) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, Blocks.end_stone) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, GregTechAPI.sBlockGranites) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, GregTechAPI.sBlockStones)) { + int limitWestX = Math.max(veinWestX, chunkX + 2); // Bias placement by 2 blocks to prevent worldgen cascade. + int limitEastX = Math.min(veinEastX, chunkX + 2 + 16); + + if (limitWestX >= limitEastX) { // No overlap between orevein and this chunk exists in X + // Check for stone at the center of the chunk and the bottom of the orevein. + if (StoneType.findStoneType(world, chunkX + 7, veinMinY, chunkZ + 9) != null) { // Didn't reach, but could have placed. Save orevein for future use. return NO_OVERLAP; } else { - // Didn't reach, but couldn't place in test spot anywys, try for another orevein + // Didn't reach, but couldn't place in test spot anyways, try for another orevein return NO_OVERLAP_AIR_BLOCK; } } + // Determine North/Sound ends of orevein - int nZVein = aSeedZ - aRandom.nextInt(mSize); - int sZVein = aSeedZ + 16 + aRandom.nextInt(mSize); - - int nZ = Math.max(nZVein, aChunkZ + 2); // Bias placement by 2 blocks to prevent worldgen cascade. - int sZ = Math.min(sZVein, aChunkZ + 2 + 16); - if (nZ >= sZ) { // No overlap between orevein and this chunk exists in Z - if (tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, Blocks.stone) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, Blocks.netherrack) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, Blocks.end_stone) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, GregTechAPI.sBlockGranites) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 7, tMinY, aChunkZ + 9, GregTechAPI.sBlockStones)) { + int veinNorthZ = seedZ - rng.nextInt(mSize); + int veinSouthZ = seedZ + 16 + rng.nextInt(mSize); + + int limitNorthZ = Math.max(veinNorthZ, chunkZ + 2); // Bias placement by 2 blocks to prevent worldgen cascade. + int limitSouthZ = Math.min(veinSouthZ, chunkZ + 2 + 16); + + if (limitNorthZ >= limitSouthZ) { // No overlap between orevein and this chunk exists in Z + // Check for stone at the center of the chunk and the bottom of the orevein. + if (StoneType.findStoneType(world, chunkX + 7, veinMinY, chunkZ + 9) != null) { // Didn't reach, but could have placed. Save orevein for future use. return NO_OVERLAP; } else { - // Didn't reach, but couldn't place in test spot anywys, try for another orevein + // Didn't reach, but couldn't place in test spot anyways, try for another orevein return NO_OVERLAP_AIR_BLOCK; } } @@ -182,259 +201,110 @@ public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome GTLog.out.print( "Trying Orevein:" + this.mWorldGenName + " Dimension=" - + tDimensionName + + world.provider.getDimensionName() + " mX=" - + aChunkX / 16 + + chunkX / 16 + " mZ=" - + aChunkZ / 16 + + chunkZ / 16 + " oreseedX=" - + aSeedX / 16 + + seedX / 16 + " oreseedZ=" - + aSeedZ / 16 + + seedZ / 16 + " cY=" - + tMinY); + + veinMinY); } + // Adjust the density down the more chunks we are away from the oreseed. The 5 chunks surrounding the seed // should always be max density due to truncation of Math.sqrt(). int localDensity = Math.max( 1, - this.mDensity / ((int) Math - .sqrt(2 + Math.pow(aChunkX / 16 - aSeedX / 16, 2) + Math.pow(aChunkZ / 16 - aSeedZ / 16, 2)))); + this.mDensity + / ((int) Math.sqrt(2 + Math.pow(chunkX / 16 - seedX / 16, 2) + Math.pow(chunkZ / 16 - seedZ / 16, 2)))); + + LayerGenerator generator = new LayerGenerator(); + + generator.world = world; + generator.rng = rng; + generator.limitWestX = limitWestX; + generator.limitEastX = limitEastX; + generator.limitSouthZ = limitSouthZ; + generator.limitNorthZ = limitNorthZ; + generator.veinWestX = veinWestX; + generator.veinEastX = veinEastX; + generator.veinSouthZ = veinSouthZ; + generator.veinNorthZ = veinNorthZ; + generator.localDensity = localDensity; + // Dunno why, but the first layer is actually played one below tMinY. Go figure. + generator.level = veinMinY - 1; + generator.placeCount = placeCount; // To allow for early exit due to no ore placed in the bottom layer (probably because we are in the sky), unroll // 1 pass through the loop // Now we do bottom-level-first oregen, and work our way upwards. - // Layer -1 Secondary and Sporadic - int level = tMinY - 1; // Dunno why, but the first layer is actually played one below tMinY. Go figure. - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSecondaryMeta > 0)) { - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, isUnderdark)) { - placeCount[1]++; - } - } else - if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta > 0)) { // Sporadics are reduce by 1/7 to compensate - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, isUnderdark)) - placeCount[3]++; - } - } - } + + generator.generateLayer(true, false, false); // layer -1 + if ((placeCount[1] + placeCount[3]) == 0) { if (debugOrevein) GTLog.out.println(" No ore in bottom layer"); return NO_ORE_IN_BOTTOM_LAYER; // Exit early, didn't place anything in the bottom layer } - // Layers 0 & 1 Secondary and Sporadic - for (level = tMinY; level < (tMinY + 2); level++) { - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max( - 1, - Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSecondaryMeta > 0)) { - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, isUnderdark)) { - placeCount[1]++; - } - } else if ((aRandom.nextInt(7) == 0) - && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta > 0)) { // Sporadics are reduce by 1/7 to compensate - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, isUnderdark)) - placeCount[3]++; - } - } - } - } - // Layer 2 is Secondary, in-between, and sporadic - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mBetweenMeta > 0)) { // Between are reduce by 1/2 to compensate - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, isUnderdark)) { - placeCount[2]++; - } - } else if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSecondaryMeta > 0)) { - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, isUnderdark)) { - placeCount[1]++; - } - } else - if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta > 0)) { // Sporadics are reduce by 1/7 to compensate - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, isUnderdark)) - placeCount[3]++; - } - } - } - level++; // Increment level to next layer - // Layer 3 is In-between, and sporadic - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mBetweenMeta > 0)) { // Between are reduce by 1/2 to compensate - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, isUnderdark)) { - placeCount[2]++; - } - } else - if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta > 0)) { // Sporadics are reduce by 1/7 to compensate - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, isUnderdark)) - placeCount[3]++; - } - } - } - level++; // Increment level to next layer - // Layer 4 is In-between, Primary and sporadic - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mBetweenMeta > 0)) { // Between are reduce by 1/2 to compensate - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, isUnderdark)) { - placeCount[2]++; - } - } else - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mPrimaryMeta > 0)) { - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, isUnderdark)) { - placeCount[1]++; - } - } else if ((aRandom.nextInt(7) == 0) - && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta > 0)) { // Sporadics are reduce by 1/7 to compensate - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, isUnderdark)) - placeCount[3]++; - } - } - } - level++; // Increment level to next layer - // Layer 5 is In-between, Primary and sporadic - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mBetweenMeta > 0)) { // Between are reduce by 1/2 to compensate - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, isUnderdark)) { - placeCount[2]++; - } - } else - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mPrimaryMeta > 0)) { - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, isUnderdark)) { - placeCount[1]++; - } - } else if ((aRandom.nextInt(7) == 0) - && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta > 0)) { // Sporadics are reduce by 1/7 to compensate - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, isUnderdark)) - placeCount[3]++; - } - } - } - level++; // Increment level to next layer - // Layer 6 is Primary and sporadic - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mPrimaryMeta > 0)) { - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, isUnderdark)) { - placeCount[1]++; - } - } else - if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta > 0)) { // Sporadics are reduce by 1/7 to compensate - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, isUnderdark)) - placeCount[3]++; - } - } - } - level++; // Increment level to next layer - // Layer 7 is Primary and sporadic - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mPrimaryMeta > 0)) { - if (TileEntityOres.setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, isUnderdark)) { - placeCount[1]++; - } - } else - if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta > 0)) { // Sporadics are reduce by 1/7 to compensate - if (TileEntityOres - .setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, isUnderdark)) - placeCount[3]++; - } - } - } + + generator.generateLayer(true, false, false); // layer 0 + generator.generateLayer(true, false, false); // layer 1 + generator.generateLayer(true, true, false); // layer 2 + generator.generateLayer(false, true, false); // layer 3 + generator.generateLayer(false, true, true); // layer 4 + generator.generateLayer(false, true, true); // layer 5 + generator.generateLayer(false, false, true); // layer 6 + generator.generateLayer(false, false, true); // layer 7 + // Place small ores for the vein if (oreveinPlacerOres) { - int nSmallOres = (eX - wX) * (sZ - nZ) * this.mDensity / 10 * oreveinPlacerOresMultiplier; + int smallOresToGenerate = (limitEastX - limitWestX) * (limitSouthZ - limitNorthZ) + * this.mDensity + / 10 + * oreveinPlacerOresMultiplier; // Small ores are placed in the whole chunk in which the vein appears. - for (int nSmallOresCount = 0; nSmallOresCount < nSmallOres; nSmallOresCount++) { - int tX = aRandom.nextInt(16) + aChunkX + 2; - int tZ = aRandom.nextInt(16) + aChunkZ + 2; - int tY = aRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. - if (this.mPrimaryMeta > 0) - TileEntityOres.setOreBlock(aWorld, tX, tY, tZ, this.mPrimaryMeta, true, isUnderdark); - tX = aRandom.nextInt(16) + aChunkX + 2; - tZ = aRandom.nextInt(16) + aChunkZ + 2; - tY = aRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. - if (this.mSecondaryMeta > 0) - TileEntityOres.setOreBlock(aWorld, tX, tY, tZ, this.mSecondaryMeta, true, isUnderdark); - tX = aRandom.nextInt(16) + aChunkX + 2; - tZ = aRandom.nextInt(16) + aChunkZ + 2; - tY = aRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. - if (this.mBetweenMeta > 0) - TileEntityOres.setOreBlock(aWorld, tX, tY, tZ, this.mBetweenMeta, true, isUnderdark); - tX = aRandom.nextInt(16) + aChunkX + 2; - tZ = aRandom.nextInt(16) + aChunkZ + 2; - tY = aRandom.nextInt(190) + 10; // Y height can vary from 10 to 200 for small ores. - if (this.mSporadicMeta > 0) - TileEntityOres.setOreBlock(aWorld, tX, tY, tZ, this.mSporadicMeta, true, isUnderdark); + + for (int i = 0; i < smallOresToGenerate; i++) { + int tX = rng.nextInt(16) + chunkX + 2; + int tZ = rng.nextInt(16) + chunkZ + 2; + int tY = rng.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. + if (mPrimary != null) { + OreManager.setOreForWorldGen(world, tX, tY, tZ, null, mPrimary, true); + } + + tX = rng.nextInt(16) + chunkX + 2; + tZ = rng.nextInt(16) + chunkZ + 2; + tY = rng.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. + if (mSecondary != null) { + OreManager.setOreForWorldGen(world, tX, tY, tZ, null, mSecondary, true); + } + + tX = rng.nextInt(16) + chunkX + 2; + tZ = rng.nextInt(16) + chunkZ + 2; + tY = rng.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. + if (mBetween != null) { + OreManager.setOreForWorldGen(world, tX, tY, tZ, null, mBetween, true); + } + + tX = rng.nextInt(16) + chunkX + 2; + tZ = rng.nextInt(16) + chunkZ + 2; + tY = rng.nextInt(190) + 10; // Y height can vary from 10 to 200 for small ores. + if (mSporadic != null) { + OreManager.setOreForWorldGen(world, tX, tY, tZ, null, mSporadic, true); + } } } if (debugOrevein) { GTLog.out.println( - " wXVein" + wXVein + " wXVein" + veinWestX + " eXVein" - + eXVein + + veinEastX + " nZVein" - + nZVein + + veinNorthZ + " sZVein" - + sZVein + + veinSouthZ + " locDen=" + localDensity + " Den=" @@ -451,4 +321,62 @@ public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome // Something (at least the bottom layer must have 1 block) must have been placed, return true return ORE_PLACED; } + + private class LayerGenerator { + + World world; + Random rng; + int limitWestX, limitEastX, limitSouthZ, limitNorthZ; + int veinWestX, veinEastX, veinSouthZ, veinNorthZ; + int localDensity, level; + int[] placeCount; + + private void generateLayer(boolean secondary, boolean between, boolean primary) { + for (int tX = limitWestX; tX < limitEastX; tX++) { + int chanceX = Math.max(1, Math.max(Math.abs(veinWestX - tX), Math.abs(veinEastX - tX)) / localDensity); + + for (int tZ = limitNorthZ; tZ < limitSouthZ; tZ++) { + int chanceZ = Math + .max(1, Math.max(Math.abs(veinSouthZ - tZ), Math.abs(veinNorthZ - tZ)) / localDensity); + + if (primary) { + if ((rng.nextInt(chanceZ) == 0 || rng.nextInt(chanceX) == 0) && mPrimary != null) { + if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mPrimary, false)) { + placeCount[0]++; + } + continue; + } + } + + if (between) { + if ((rng.nextInt(chanceZ) == 0 || rng.nextInt(chanceX) == 0) && mBetween != null) { + if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mBetween, false)) { + placeCount[2]++; + } + continue; + } + } + + if (secondary) { + if ((rng.nextInt(chanceZ) == 0 || rng.nextInt(chanceX) == 0) && mSecondary != null) { + if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mSecondary, false)) { + placeCount[1]++; + } + continue; + } + } + + if (rng.nextInt(7) == 0 && (rng.nextInt(chanceZ) == 0 || rng.nextInt(chanceX) == 0) + && mSporadic != null) { // Sporadics are reduced by 1/7 to compensate + if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mSporadic, false)) { + placeCount[3]++; + } + continue; + } + } + } + + level++; + } + } } diff --git a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java index e3be59a6287..5f06929db62 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java +++ b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java @@ -3,117 +3,149 @@ import static gregtech.api.enums.GTValues.debugSmallOres; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Random; +import java.util.Set; import net.minecraft.world.World; -import net.minecraft.world.WorldProviderEnd; -import net.minecraft.world.WorldProviderHell; -import net.minecraft.world.WorldProviderSurface; import net.minecraft.world.chunk.IChunkProvider; import gregtech.api.GregTechAPI; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneCategory; import gregtech.api.util.GTLog; +import gregtech.api.util.GTUtility; import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; +import gregtech.common.worldgen.IWorldgenLayer; -public class WorldgenGTOreSmallPieces extends GTWorldgen { +public class WorldgenGTOreSmallPieces extends GTWorldgen implements IWorldgenLayer { + public static final List sList = new ArrayList<>(); public final short mMinY; public final short mMaxY; public final short mAmount; - public final short mMeta; - public final boolean mOverworld; - public final boolean mNether; - public final boolean mEnd; - public final boolean twilightForest; - public final String mBiome; - public static ArrayList sList = new ArrayList<>(); - - public Class[] mAllowedProviders; - public String[] blackListedProviders; - public static Class tfProviderClass; + private final IOreMaterial mMaterial; - static { - try { - tfProviderClass = Class.forName("twilightforest.world.WorldProviderTwilightForest"); - } catch (ClassNotFoundException ignored) {} - } + public final String mBiome; + private final Set mAllowedDimensions; + private final Set mAllowedStone; public WorldgenGTOreSmallPieces(SmallOreBuilder ore) { super(ore.smallOreName, GregTechAPI.sWorldgenList, ore.enabledByDefault); - this.mOverworld = ore.dimsEnabled.getOrDefault(SmallOreBuilder.OW, false); - this.mNether = ore.dimsEnabled.getOrDefault(SmallOreBuilder.NETHER, false); - this.mEnd = ore.dimsEnabled.getOrDefault(SmallOreBuilder.THE_END, false); - this.twilightForest = ore.dimsEnabled.getOrDefault(SmallOreBuilder.TWILIGHT_FOREST, false); this.mMinY = (short) ore.minY; this.mMaxY = (short) Math.max(this.mMinY + 1, ore.maxY); this.mAmount = (short) Math.max(1, ore.amount); - this.mMeta = (short) ore.ore.mMetaItemSubID; + this.mMaterial = ore.ore; this.mBiome = "None"; + this.mAllowedDimensions = new HashSet<>(ore.dimsEnabled); + this.mAllowedStone = ore.stoneCategories == null ? null : new HashSet<>(ore.stoneCategories); if (this.mEnabled) sList.add(this); + } - List allowedProviders = new ArrayList<>(); - if (this.mNether) { - allowedProviders.add(WorldProviderHell.class); - } + @Override + public int getMinY() { + return mMinY; + } - if (this.mOverworld) { - allowedProviders.add(WorldProviderSurface.class); - if (!this.twilightForest) { - blackListedProviders = new String[] { "twilightforest.world.WorldProviderTwilightForest" }; - } - } + @Override + public int getMaxY() { + return mMaxY; + } - if (tfProviderClass != null && this.twilightForest) { - allowedProviders.add(tfProviderClass); - } + @Override + public int getWeight() { + return mAmount; + } - if (this.mEnd) { - allowedProviders.add(WorldProviderEnd.class); - } - mAllowedProviders = allowedProviders.toArray(new Class[0]); + @Override + public float getDensity() { + return GTUtility.clamp(mAmount / 64.0f, 0f, 1f); + } + + @Override + public boolean canGenerateIn(String dimName) { + return mAllowedDimensions.contains(dimName); + } + + @Override + public boolean canGenerateIn(IStoneCategory stoneType) { + return mAllowedStone != null && mAllowedStone.contains(stoneType); } @Override - public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - if (!this.mBiome.equals("None") && !(this.mBiome.equals(aBiome))) { + public boolean isStoneSpecific() { + return mAllowedStone != null; + } + + @Override + public boolean contains(IOreMaterial material) { + return material == mMaterial; + } + + @Override + public IOreMaterial getOre(float k) { + return mMaterial; + } + + @Override + public String getName() { + return mWorldGenName; + } + + @Override + public boolean generatesBigOre() { + return false; + } + + public Set getAllowedDimensions() { + return mAllowedDimensions; + } + + public IOreMaterial getMaterial() { + return mMaterial; + } + + @Override + public boolean executeWorldgen(World world, Random random, String biome, int chunkX, int chunkZ, + IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + if (!this.mBiome.equals("None") && !(this.mBiome.equals(biome))) { return false; // Not the correct biome for ore mix } - if (!isGenerationAllowed(aWorld, mAllowedProviders)) { + + if (!mAllowedDimensions.contains(world.provider.getDimensionName())) { return false; } + int count = 0; - // For optimal performance, this should be done upstream. Meh - String tDimensionName = aWorld.provider.getDimensionName(); - boolean isUnderdark = tDimensionName.equals("Underdark"); - - if (this.mMeta > 0) { - int j = Math.max(1, this.mAmount / 2 + aRandom.nextInt(this.mAmount) / 2); - for (int i = 0; i < j; i++) { - TileEntityOres.setOreBlock( - aWorld, - aChunkX + 8 + aRandom.nextInt(16), - this.mMinY + aRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), - aChunkZ + 8 + aRandom.nextInt(16), - this.mMeta, - true, - isUnderdark); + + if (this.mMaterial != null) { + int smallOresToGenerate = Math.max(1, this.mAmount / 2 + random.nextInt(this.mAmount) / 2); + + for (int i = 0; i < smallOresToGenerate; i++) { + OreManager.setOreForWorldGen( + world, + chunkX + 8 + random.nextInt(16), + this.mMinY + random.nextInt(Math.max(1, this.mMaxY - this.mMinY)), + chunkZ + 8 + random.nextInt(16), + null, + mMaterial, + true); count++; } } if (debugSmallOres) { GTLog.out.println( "Small Ore:" + this.mWorldGenName - + " @ dim=" - + aDimensionType + + " @ DimName=" + + world.provider.getDimensionName() + " mX=" - + aChunkX / 16 + + chunkX / 16 + " mZ=" - + aChunkZ / 16 + + chunkZ / 16 + " ore=" + count); } diff --git a/src/main/java/gregtech/common/WorldgenStone.java b/src/main/java/gregtech/common/WorldgenStone.java index dd42146ea70..844e9bf1646 100644 --- a/src/main/java/gregtech/common/WorldgenStone.java +++ b/src/main/java/gregtech/common/WorldgenStone.java @@ -9,16 +9,16 @@ import net.minecraft.block.Block; import net.minecraft.init.Blocks; -import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import gregtech.api.GregTechAPI; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IStoneType; import gregtech.api.objects.XSTR; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; public class WorldgenStone extends GTWorldgen { @@ -78,8 +78,8 @@ public WorldgenStone(StoneBuilder stone) { } @Override - public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aChunkX, int aChunkZ, + IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { XSTR stoneRNG = new XSTR(); ArrayList stones = new ArrayList<>(); @@ -129,6 +129,8 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int } } + IStoneType stoneType = StoneType.findStoneType(mBlock, mBlockMeta); + boolean result = !stones.isEmpty(); // Now process each oreseed vs this requested chunk for (; !stones.isEmpty(); stones.remove(0)) { @@ -164,7 +166,7 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int // 1 = full size, 1.333 = 75%, 2 = 50%, 4 = 25% // (x * Sx)^2 + (y * Sy)^2 + (z * sZ)^2 <= (mSize)^2 - // So, we setup the intial boundaries to be the size of the boulder plus a block in each direction + // So, we setup the initial boundaries to be the size of the boulder plus a block in each direction int tMinX = tX - (int) (realSize / xSize - 1.0); int tMaxX = tX + (int) (realSize / xSize + 2.0); int tMinY = tY - (int) (realSize / ySize - 1.0); @@ -209,33 +211,35 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int int sZ = Math.max(tMinZ, aChunkZ + 8); int nZ = Math.min(tMaxZ, aChunkZ + 8 + 16); - if (debugStones) GTLog.out.println( - mWorldGenName + " tX=" - + tX - + " tY=" - + tY - + " tZ=" - + tZ - + " realSize=" - + realSize - + " xSize=" - + realSize / xSize - + " ySize=" - + realSize / ySize - + " zSize=" - + realSize / zSize - + " wX=" - + wX - + " eX=" - + eX - + " tMinY=" - + tMinY - + " tMaxY=" - + tMaxY - + " sZ=" - + sZ - + " nZ=" - + nZ); + if (debugStones) { + GTLog.out.println( + mWorldGenName + " tX=" + + tX + + " tY=" + + tY + + " tZ=" + + tZ + + " realSize=" + + realSize + + " xSize=" + + realSize / xSize + + " ySize=" + + realSize / ySize + + " zSize=" + + realSize / zSize + + " wX=" + + wX + + " eX=" + + eX + + " tMinY=" + + tMinY + + " tMaxY=" + + tMaxY + + " sZ=" + + sZ + + " nZ=" + + nZ); + } double rightHandSide = realSize * realSize + 1; // Precalc the right hand side for (int iY = tMinY; iY < tMaxY; iY++) { // Do placement from the bottom up layer up. Maybe better on @@ -260,31 +264,26 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int leftHandSize = zCalc + xCalc + yCalc; if (leftHandSize <= rightHandSide) { // Yay! We can actually place a block now. (this part copied from original code) + if (!this.mAllowToGenerateinVoid && aWorld.isAirBlock(iX, iY, iZ)) continue; + Block tTargetedBlock = aWorld.getBlock(iX, iY, iZ); - if (tTargetedBlock instanceof BlockOresAbstract) { - TileEntity tTileEntity = aWorld.getTileEntity(iX, iY, iZ); - if ((tTileEntity instanceof TileEntityOres)) { - if (tTargetedBlock != GregTechAPI.sBlockOres1) { - ((TileEntityOres) tTileEntity).convertOreBlock(aWorld, iX, iY, iZ); - } - ((TileEntityOres) tTileEntity) - .overrideOreBlockMaterial(this.mBlock, (byte) this.mBlockMeta); - } - } else if (((this.mAllowToGenerateinVoid) && (aWorld.getBlock(iX, iY, iZ) - .isAir(aWorld, iX, iY, iZ))) - || ((tTargetedBlock != null) && ((tTargetedBlock - .isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.stone)) - || (tTargetedBlock - .isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.stained_hardened_clay)) - || (tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.cobblestone)) - || (tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.end_stone)) - || (tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.netherrack)) - || (tTargetedBlock - .isReplaceableOreGen(aWorld, iX, iY, iZ, GregTechAPI.sBlockGranites)) - || (tTargetedBlock - .isReplaceableOreGen(aWorld, iX, iY, iZ, GregTechAPI.sBlockStones))))) { - aWorld.setBlock(iX, iY, iZ, this.mBlock, this.mBlockMeta, 0); - } + + // spotless:off + if ( tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.stone) || + tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.stained_hardened_clay) || + tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.cobblestone) || + tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.end_stone) || + tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.netherrack) || + tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, GregTechAPI.sBlockGranites) || + tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, GregTechAPI.sBlockStones)) { + aWorld.setBlock(iX, iY, iZ, this.mBlock, this.mBlockMeta, 0); + continue; + } + // spotless:on + + if (OreManager.setExistingOreStoneType(aWorld, iX, iY, iZ, stoneType)) { + continue; + } } } } diff --git a/src/main/java/gregtech/common/blocks/BlockFrameBox.java b/src/main/java/gregtech/common/blocks/BlockFrameBox.java index 305919c9482..2b1494e67ee 100644 --- a/src/main/java/gregtech/common/blocks/BlockFrameBox.java +++ b/src/main/java/gregtech/common/blocks/BlockFrameBox.java @@ -28,6 +28,7 @@ import gregtech.api.enums.Dyes; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; +import gregtech.api.interfaces.IBlockWithTextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -41,7 +42,7 @@ import gregtech.api.util.GTUtility; import gregtech.common.render.GTRendererBlock; -public class BlockFrameBox extends BlockContainer { +public class BlockFrameBox extends BlockContainer implements IBlockWithTextures { protected final String mUnlocalizedName; @@ -52,6 +53,9 @@ public class BlockFrameBox extends BlockContainer { // properly call getDrops() on it private static final ThreadLocal mTemporaryTileEntity = new ThreadLocal<>(); + // Texture[meta][side][layer] + private ITexture[][][] textures = new ITexture[1000][][]; + public BlockFrameBox() { super(new MaterialMachines()); this.mUnlocalizedName = "gt.blockframes"; @@ -68,6 +72,12 @@ public BlockFrameBox() { GTLanguageManager.i18nPlaceholder ? getLocalizedNameFormat(material) : getLocalizedName(material)); GTLanguageManager .addStringLocalization(getUnlocalizedName() + "." + meta + DOT_TOOLTIP, material.getToolTip()); + + ITexture[] texture = { TextureFactory.of( + material.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex], + Dyes.getModulation(-1, material.mRGBa)) }; + + textures[meta] = new ITexture[][] { texture, texture, texture, texture, texture, texture }; } } } @@ -442,12 +452,9 @@ public IIcon getIcon(int side, int meta) { return material.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex].getIcon(); } - public ITexture[] getTexture(int meta) { - Materials material = getMaterial(meta); - if (material == null) return null; - return new ITexture[] { TextureFactory.of( - material.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex], - Dyes.getModulation(-1, material.mRGBa)) }; + @Override + public ITexture[][] getTextures(int meta) { + return meta < 0 || meta >= 1000 ? null : textures[meta]; } @Override diff --git a/src/main/java/gregtech/common/blocks/BlockOres.java b/src/main/java/gregtech/common/blocks/BlockOres.java deleted file mode 100644 index f2ae18f1958..00000000000 --- a/src/main/java/gregtech/common/blocks/BlockOres.java +++ /dev/null @@ -1,154 +0,0 @@ -package gregtech.common.blocks; - -import static gregtech.api.enums.Textures.BlockIcons.BASALT_STONE; -import static gregtech.api.enums.Textures.BlockIcons.GRANITE_BLACK_STONE; -import static gregtech.api.enums.Textures.BlockIcons.GRANITE_RED_STONE; -import static gregtech.api.enums.Textures.BlockIcons.MARBLE_STONE; - -import java.util.Arrays; - -import net.minecraft.block.Block; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.common.util.ForgeDirection; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.GTMod; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.interfaces.ITexture; -import gregtech.api.render.TextureFactory; - -public class BlockOres extends BlockOresAbstract { - - private static final String UNLOCALIZED_NAME = "gt.blockores"; - - public BlockOres() { - super(UNLOCALIZED_NAME, 7, false, Material.rock); - } - - @Override - public String getUnlocalizedName() { - return UNLOCALIZED_NAME; - } - - @Override - public OrePrefixes[] getProcessingPrefix() { // Must have 8 entries; an entry can be null to disable automatic - // recipes. - return new OrePrefixes[] { OrePrefixes.ore, OrePrefixes.oreNetherrack, OrePrefixes.oreEndstone, - OrePrefixes.oreBlackgranite, OrePrefixes.oreRedgranite, OrePrefixes.oreMarble, OrePrefixes.oreBasalt, - null }; - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(int ordinalSide, int meta) { - int index = ((meta / 1000) % 16); - return switch (index) { - case 1 -> Blocks.netherrack.getIcon(ordinalSide, 0); - case 2 -> Blocks.end_stone.getIcon(ordinalSide, 0); - case 3 -> GRANITE_BLACK_STONE.getIcon(); - case 4 -> GRANITE_RED_STONE.getIcon(); - case 5 -> MARBLE_STONE.getIcon(); - case 6 -> BASALT_STONE.getIcon(); - default -> Blocks.stone.getIcon(ordinalSide, 0); - }; - } - - /** - * @inheritDoc - */ - @Override - public boolean isFireSource(World world, int x, int y, int z, ForgeDirection side) { - return (side == ForgeDirection.UP && getDamageValue(world, x, y, z) / 1000 % 16 == 1); - } - - /** - * @inheritDoc - */ - @Override - public MapColor getMapColor(int meta) { - return meta == 1 ? MapColor.netherrackColor : MapColor.stoneColor; - } - - @Override - public int getBaseBlockHarvestLevel(int aMeta) { - return switch (aMeta) { - case 3, 4 -> 3; - default -> 0; - }; - } - - @Override - public Block getDroppedBlock() { - return GregTechAPI.sBlockOres1; - } - - @Override - public Materials[] getDroppedDusts() { // Must have 8 entries; can be null. - return new Materials[] { Materials.Stone, Materials.Netherrack, Materials.Endstone, Materials.GraniteBlack, - Materials.GraniteRed, Materials.Marble, Materials.Basalt, Materials.Stone }; - } - - @Override - public boolean[] getEnabledMetas() { - return new boolean[] { true, true, true, GTMod.gregtechproxy.enableBlackGraniteOres, - GTMod.gregtechproxy.enableRedGraniteOres, GTMod.gregtechproxy.enableMarbleOres, - GTMod.gregtechproxy.enableBasaltOres, true }; - } - - @Override - public ITexture[] getTextureSet() { - final ITexture[] rTextures = new ITexture[16]; // Must have 16 entries. - Arrays.fill(rTextures, TextureFactory.of(Blocks.stone)); - rTextures[1] = TextureFactory.of(Blocks.netherrack); - rTextures[2] = TextureFactory.of(Blocks.end_stone); - rTextures[3] = TextureFactory.builder() - .addIcon(GRANITE_BLACK_STONE) - .stdOrient() - .build(); - rTextures[4] = TextureFactory.builder() - .addIcon(GRANITE_RED_STONE) - .stdOrient() - .build(); - rTextures[5] = TextureFactory.builder() - .addIcon(MARBLE_STONE) - .stdOrient() - .build(); - rTextures[6] = TextureFactory.builder() - .addIcon(BASALT_STONE) - .stdOrient() - .build(); - return rTextures; - } - - @Override - public void harvestBlock(World worldIn, EntityPlayer player, int x, int y, int z, int meta) { - - if (EnchantmentHelper.getSilkTouchModifier(player)) { - TileEntityOres.shouldSilkTouch = true; - super.harvestBlock(worldIn, player, x, y, z, meta); - - if (TileEntityOres.shouldSilkTouch) { - TileEntityOres.shouldSilkTouch = false; - } - return; - } - - if (!(player instanceof FakePlayer)) { - TileEntityOres.shouldFortune = true; - } - super.harvestBlock(worldIn, player, x, y, z, meta); - if (TileEntityOres.shouldFortune) { - TileEntityOres.shouldFortune = false; - } - } -} diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java deleted file mode 100644 index 4c194152f00..00000000000 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ /dev/null @@ -1,327 +0,0 @@ -package gregtech.common.blocks; - -import static gregtech.api.enums.Mods.NotEnoughItems; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import net.minecraft.block.Block; -import net.minecraft.block.ITileEntityProvider; -import net.minecraft.block.material.Material; -import net.minecraft.client.particle.EffectRenderer; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; -import net.minecraft.entity.boss.EntityDragon; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.StatCollector; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.GTMod; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.interfaces.ITexture; -import gregtech.api.items.GTGenericBlock; -import gregtech.api.util.GTLanguageManager; -import gregtech.api.util.GTOreDictUnificator; -import gregtech.api.util.GTUtility; -import gregtech.common.render.GTRendererBlock; - -public abstract class BlockOresAbstract extends GTGenericBlock implements ITileEntityProvider { - - private static final String DOT_NAME = ".name"; - private static final String DOT_TOOLTIP = ".tooltip"; - public static ThreadLocal mTemporaryTileEntity = new ThreadLocal<>(); - public static boolean FUCKING_LOCK = false; - public static boolean tHideOres; - public static Set aBlockedOres = new HashSet<>(); - - protected BlockOresAbstract(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta, - Material aMaterial) { - super(ItemOres.class, aUnlocalizedName, aMaterial); - this.isBlockContainer = true; - setStepSound(soundTypeStone); - setCreativeTab(GregTechAPI.TAB_GREGTECH_ORES); - tHideOres = NotEnoughItems.isModLoaded() && GTMod.gregtechproxy.mHideUnusedOres; - if (aOreMetaCount > 8 || aOreMetaCount < 0) aOreMetaCount = 8; - - for (int i = 1; i < GregTechAPI.sGeneratedMaterials.length; i++) { - if (GregTechAPI.sGeneratedMaterials[i] != null) { - for (int j = 0; j < aOreMetaCount; j++) { - if (!this.getEnabledMetas()[j]) continue; - GTLanguageManager.addStringLocalization( - getUnlocalizedName() + "." + (i + (j * 1000)) + DOT_NAME, - GTLanguageManager.i18nPlaceholder ? getLocalizedNameFormat(GregTechAPI.sGeneratedMaterials[i]) - : getLocalizedName(GregTechAPI.sGeneratedMaterials[i])); - GTLanguageManager.addStringLocalization( - getUnlocalizedName() + "." + (i + (j * 1000)) + DOT_TOOLTIP, - GregTechAPI.sGeneratedMaterials[i].getToolTip()); - GTLanguageManager.addStringLocalization( - getUnlocalizedName() + "." + ((i + 16000) + (j * 1000)) + DOT_NAME, - "Small " + (GTLanguageManager.i18nPlaceholder - ? getLocalizedNameFormat(GregTechAPI.sGeneratedMaterials[i]) - : getLocalizedName(GregTechAPI.sGeneratedMaterials[i]))); - GTLanguageManager.addStringLocalization( - getUnlocalizedName() + "." + ((i + 16000) + (j * 1000)) + DOT_TOOLTIP, - GregTechAPI.sGeneratedMaterials[i].getToolTip()); - if ((GregTechAPI.sGeneratedMaterials[i].mTypes & 0x8) != 0 - && !aBlockedOres.contains(GregTechAPI.sGeneratedMaterials[i])) { - if (this.getProcessingPrefix()[j] != null && this.getProcessingPrefix()[j].mIsUnificatable) { - GTOreDictUnificator.set( - this.getProcessingPrefix()[j], - GregTechAPI.sGeneratedMaterials[i], - new ItemStack(this, 1, i + (j * 1000))); - } else { - GTOreDictUnificator.registerOre( - this.getProcessingPrefix()[j] != null - ? this.getProcessingPrefix()[j].get(GregTechAPI.sGeneratedMaterials[i]) - : "", - new ItemStack(this, 1, i + (j * 1000))); - } - if (tHideOres) { - if (!(j == 0 && !aHideFirstMeta)) { - codechicken.nei.api.API.hideItem(new ItemStack(this, 1, i + (j * 1000))); - } - codechicken.nei.api.API.hideItem(new ItemStack(this, 1, (i + 16000) + (j * 1000))); - } - } - } - } - } - } - - public int getBaseBlockHarvestLevel(int aMeta) { - return 0; - } - - @Override - public void onNeighborChange(IBlockAccess aWorld, int aX, int aY, int aZ, int aTileX, int aTileY, int aTileZ) { - if (!FUCKING_LOCK) { - FUCKING_LOCK = true; - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if ((tTileEntity instanceof TileEntityOres)) { - ((TileEntityOres) tTileEntity).onUpdated(); - } - } - FUCKING_LOCK = false; - } - - @Override - public void onNeighborBlockChange(World aWorld, int aX, int aY, int aZ, Block aBlock) { - if (!FUCKING_LOCK) { - FUCKING_LOCK = true; - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if ((tTileEntity instanceof TileEntityOres)) { - ((TileEntityOres) tTileEntity).onUpdated(); - } - } - FUCKING_LOCK = false; - } - - public String getLocalizedNameFormat(Materials aMaterial) { - return switch (aMaterial.mName) { - case "InfusedAir", "InfusedDull", "InfusedEarth", "InfusedEntropy", "InfusedFire", "InfusedOrder", "InfusedVis", "InfusedWater" -> "%material Infused Stone"; - case "Vermiculite", "Bentonite", "Kaolinite", "Talc", "BasalticMineralSand", "GraniticMineralSand", "GlauconiteSand", "CassiteriteSand", "GarnetSand", "QuartzSand", "Pitchblende", "FullersEarth" -> "%material"; - default -> "%material" + OrePrefixes.ore.mLocalizedMaterialPost; - }; - } - - public String getLocalizedName(Materials aMaterial) { - return aMaterial.getDefaultLocalizedNameForItem(getLocalizedNameFormat(aMaterial)); - } - - @Override - public boolean onBlockActivated(World aWorld, int aX, int aY, int aZ, EntityPlayer aPlayer, int ordinalSide, - float aOffsetX, float aOffsetY, float aOffsetZ) { - if (!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode) { - return false; - } - - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if (!(tTileEntity instanceof TileEntityOres)) { - return false; - } - - boolean tNatural = (((TileEntityOres) tTileEntity).mNatural = !((TileEntityOres) tTileEntity).mNatural); - GTUtility.sendChatToPlayer(aPlayer, "Ore \"mNatural\" flag set to: " + tNatural); - return true; - } - - @Override - public boolean onBlockEventReceived(World p_149696_1_, int p_149696_2_, int p_149696_3_, int p_149696_4_, - int p_149696_5_, int p_149696_6_) { - super.onBlockEventReceived(p_149696_1_, p_149696_2_, p_149696_3_, p_149696_4_, p_149696_5_, p_149696_6_); - TileEntity tileentity = p_149696_1_.getTileEntity(p_149696_2_, p_149696_3_, p_149696_4_); - return tileentity != null && tileentity.receiveClientEvent(p_149696_5_, p_149696_6_); - } - - @Override - public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) { - return (!(entity instanceof EntityDragon)) && (super.canEntityDestroy(world, x, y, z, entity)); - } - - @Override - public String getHarvestTool(int aMeta) { - return aMeta < 8 ? "pickaxe" : "shovel"; - } - - @Override - public int getHarvestLevel(int aMeta) { - return aMeta == 5 || aMeta == 6 ? 2 : aMeta % 8; - } - - @Override - public float getBlockHardness(World aWorld, int aX, int aY, int aZ) { - return 1.0F + getHarvestLevel(aWorld.getBlockMetadata(aX, aY, aZ)) * 1.0F; - } - - @Override - public float getExplosionResistance(Entity entity, World aWorld, int aX, int aY, int aZ, double explosionX, - double explosionY, double explosionZ) { - return 1.0F + getHarvestLevel(aWorld.getBlockMetadata(aX, aY, aZ)) * 1.0F; - } - - @Override - protected boolean canSilkHarvest() { - return false; - } - - @Override - public abstract String getUnlocalizedName(); - - @Override - public String getLocalizedName() { - return StatCollector.translateToLocal(getUnlocalizedName() + DOT_NAME); - } - - @Override - public int getRenderType() { - if (GTRendererBlock.INSTANCE == null) { - return super.getRenderType(); - } - return GTRendererBlock.mRenderID; - } - - @Override - public boolean canBeReplacedByLeaves(IBlockAccess aWorld, int aX, int aY, int aZ) { - return false; - } - - @Override - public boolean isNormalCube(IBlockAccess aWorld, int aX, int aY, int aZ) { - return true; - } - - @Override - public boolean hasTileEntity(int aMeta) { - return true; - } - - @Override - public TileEntity createNewTileEntity(World aWorld, int aMeta) { - return createTileEntity(aWorld, aMeta); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(IBlockAccess aIBlockAccess, int aX, int aY, int aZ, int ordinalSide) { - return Blocks.stone.getIcon(0, 0); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(int ordinalSide, int aMeta) { - return Blocks.stone.getIcon(0, 0); - } - - @Override - @SideOnly(Side.CLIENT) - public void registerBlockIcons(IIconRegister aIconRegister) {} - - @Override - @SideOnly(Side.CLIENT) - public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) { - GTRendererBlock - .addHitEffects(effectRenderer, this, worldObj, target.blockX, target.blockY, target.blockZ, target.sideHit); - return true; - } - - @Override - @SideOnly(Side.CLIENT) - public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) { - GTRendererBlock.addDestroyEffects(effectRenderer, this, world, x, y, z); - return true; - } - - @Override - public int getDamageValue(World aWorld, int aX, int aY, int aZ) { - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if (((tTileEntity instanceof TileEntityOres))) { - return ((TileEntityOres) tTileEntity).getMetaData(); - } - return 0; - } - - @Override - public void breakBlock(World aWorld, int aX, int aY, int aZ, Block aBlock, int aMetadata) { - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if ((tTileEntity instanceof TileEntityOres)) { - mTemporaryTileEntity.set((TileEntityOres) tTileEntity); - } - super.breakBlock(aWorld, aX, aY, aZ, aBlock, aMetadata); - aWorld.removeTileEntity(aX, aY, aZ); - } - - public abstract OrePrefixes[] getProcessingPrefix(); // Must have 8 entries; an entry can be null to disable - // automatic recipes. - - public abstract boolean[] getEnabledMetas(); // Must have 8 entries. - - public abstract Block getDroppedBlock(); - - public abstract Materials[] getDroppedDusts(); // Must have 8 entries; can be null. - - @Override - public ArrayList getDrops(World aWorld, int aX, int aY, int aZ, int aMeta, int aFortune) { - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if ((tTileEntity instanceof TileEntityOres)) { - return ((TileEntityOres) tTileEntity).getDrops(getDroppedBlock(), aFortune); - } - return mTemporaryTileEntity.get() == null ? new ArrayList<>() - : mTemporaryTileEntity.get() - .getDrops(getDroppedBlock(), aFortune); - } - - @Override - public TileEntity createTileEntity(World aWorld, int aMeta) { - return new TileEntityOres(); - } - - public abstract ITexture[] getTextureSet(); // Must have 16 entries. - - @Override - @SideOnly(Side.CLIENT) - public void getSubBlocks(Item aItem, CreativeTabs aTab, List aList) { - for (int i = 0; i < GregTechAPI.sGeneratedMaterials.length; i++) { - Materials tMaterial = GregTechAPI.sGeneratedMaterials[i]; - if ((tMaterial != null) && ((tMaterial.mTypes & 0x8) != 0) && !aBlockedOres.contains(tMaterial)) { - for (int meta = i; meta < 23000 + i; meta += 1000) { - if (!(new ItemStack(aItem, 1, meta).getDisplayName() - .contains(DOT_NAME))) aList.add(new ItemStack(aItem, 1, meta)); - } - } - } - } -} diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstractLegacy.java b/src/main/java/gregtech/common/blocks/BlockOresAbstractLegacy.java new file mode 100644 index 00000000000..975d3f00353 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstractLegacy.java @@ -0,0 +1,52 @@ +package gregtech.common.blocks; + +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.items.GTGenericBlock; + +/** + * The legacy ores. Must still be registered so that postea can transform them into the new ore blocks. + */ +public abstract class BlockOresAbstractLegacy extends GTGenericBlock implements ITileEntityProvider { + + protected BlockOresAbstractLegacy(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta, + Material aMaterial) { + super(ItemOresLegacy.class, aUnlocalizedName, aMaterial); + this.isBlockContainer = true; + } + + @Override + public boolean hasTileEntity(int aMeta) { + return true; + } + + @Override + public TileEntity createNewTileEntity(World aWorld, int aMeta) { + return createTileEntity(aWorld, aMeta); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess aIBlockAccess, int aX, int aY, int aZ, int ordinalSide) { + return Blocks.stone.getIcon(0, 0); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int ordinalSide, int aMeta) { + return Blocks.stone.getIcon(0, 0); + } + + @Override + public TileEntity createTileEntity(World aWorld, int aMeta) { + return new TileEntityOres(); + } +} diff --git a/src/main/java/gregtech/common/blocks/BlockOresLegacy.java b/src/main/java/gregtech/common/blocks/BlockOresLegacy.java new file mode 100644 index 00000000000..42389e583f0 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/BlockOresLegacy.java @@ -0,0 +1,39 @@ +package gregtech.common.blocks; + +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * The legacy ores. Must still be registered so that postea can transform them into the new ore blocks. + */ +public class BlockOresLegacy extends BlockOresAbstractLegacy { + + private static final String UNLOCALIZED_NAME = "gt.blockores"; + + public BlockOresLegacy() { + super(UNLOCALIZED_NAME, 7, false, Material.rock); + } + + @Override + public String getUnlocalizedName() { + return UNLOCALIZED_NAME; + } + + /** + * @inheritDoc + */ + @Override + public boolean isFireSource(World world, int x, int y, int z, ForgeDirection side) { + return (side == ForgeDirection.UP && getDamageValue(world, x, y, z) / 1000 % 16 == 1); + } + + /** + * @inheritDoc + */ + @Override + public MapColor getMapColor(int meta) { + return meta == 1 ? MapColor.netherrackColor : MapColor.stoneColor; + } +} diff --git a/src/main/java/gregtech/common/blocks/GTBlockOre.java b/src/main/java/gregtech/common/blocks/GTBlockOre.java new file mode 100644 index 00000000000..21e530f6b45 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/GTBlockOre.java @@ -0,0 +1,397 @@ +package gregtech.common.blocks; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.material.Material; +import net.minecraft.client.particle.EffectRenderer; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.Entity; +import net.minecraft.entity.boss.EntityDragon; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.GTMod; +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneCategory; +import gregtech.api.enums.StoneType; +import gregtech.api.enums.SubTag; +import gregtech.api.enums.TextureSet; +import gregtech.api.interfaces.IBlockWithTextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.items.GTGenericBlock; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GTLanguageManager; +import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.util.GTUtility; +import gregtech.common.ores.GTOreAdapter; +import gregtech.common.ores.OreInfo; +import gregtech.common.render.GTRendererBlock; +import gregtech.nei.NEIGTConfig; + +public class GTBlockOre extends GTGenericBlock implements IBlockWithTextures { + + public final List stoneTypes; + + public GTBlockOre(int series, StoneType[] stoneTypes) { + super(GTItemOre.class, "gt.blockores" + series, Material.rock); + setStepSound(soundTypeStone); + setCreativeTab(GregTechAPI.TAB_GREGTECH_ORES); + + if (stoneTypes.length > 8) throw new IllegalArgumentException("stoneTypes.length must be <= 8"); + + for (int i = 0; i < stoneTypes.length; i++) { + if (!stoneTypes[i].isEnabled()) { + stoneTypes[i] = null; + } + } + + this.stoneTypes = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(stoneTypes))); + + for (StoneType stoneType : stoneTypes) { + if (stoneType != null) { + GTOreAdapter.INSTANCE.registerOre(stoneType, this); + } + } + + for (int matId = 0; matId < 1000; matId++) { + Materials mat = getMaterial(matId); + + if (mat == null) continue; + + GTLanguageManager + .addStringLocalization(mUnlocalizedName + "." + (matId) + ".name", getLocalizedNameFormat(mat)); + GTLanguageManager.addStringLocalization( + mUnlocalizedName + "." + (matId + GTOreAdapter.SMALL_ORE_META_OFFSET) + ".name", + "Small " + getLocalizedNameFormat(mat)); + + GTLanguageManager.addStringLocalization(mUnlocalizedName + "." + (matId) + ".tooltip", mat.getToolTip()); + GTLanguageManager.addStringLocalization( + mUnlocalizedName + "." + (matId + GTOreAdapter.SMALL_ORE_META_OFFSET) + ".tooltip", + mat.getToolTip()); + } + + OreInfo info = new OreInfo<>(); + + for (int matId = 0; matId < 1000; matId++) { + info.material = getMaterial(matId); + info.stoneType = null; + + if (!GTOreAdapter.INSTANCE.supports(info)) continue; + + for (StoneType stoneType : stoneTypes) { + if (stoneType == null) continue; + + info.stoneType = stoneType; + + if (stoneType.getPrefix().mIsUnificatable) { + GTOreDictUnificator + .set(stoneType.getPrefix(), info.material, GTOreAdapter.INSTANCE.getStack(info, 1)); + } else { + GTOreDictUnificator.registerOre(stoneType.getPrefix(), GTOreAdapter.INSTANCE.getStack(info, 1)); + } + } + } + } + + @Override + public String getUnlocalizedName() { + return mUnlocalizedName; + } + + /** + * The first stack with meta = 0 is always hidden in {@link NEIGTConfig} to prevent extraneous ores from showing up + * in nei. + */ + @Override + public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { + // always add meta = 0, because NEI does weird stuff when your item doesn't have subblocks + // meta = 0 is always hidden in the nei plugin + list.add(new ItemStack(this, 1, 0)); + + OreInfo info = new OreInfo<>(); + + for (int matId = 0; matId < 1000; matId++) { + info.material = getMaterial(matId); + info.stoneType = null; + + if (!GTOreAdapter.INSTANCE.supports(info)) continue; + + for (StoneType stoneType : stoneTypes) { + if (stoneType == null) continue; + + if (info.material.contains(SubTag.ICE_ORE)) { + // if this material only has ice ore, we only want to show the ice variants + if (stoneType.getCategory() != StoneCategory.Ice) continue; + if (stoneType.isExtraneous()) continue; + + info.stoneType = stoneType; + + list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + } else { + // if this material doesn't have ice ore, we only want to show the stone variants + if (stoneType.getCategory() != StoneCategory.Stone) continue; + if (stoneType.isExtraneous()) continue; + + info.stoneType = stoneType; + + list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + } + } + } + + info.isSmall = true; + + for (int matId = 0; matId < 1000; matId++) { + info.material = getMaterial(matId); + info.stoneType = null; + + if (!GTOreAdapter.INSTANCE.supports(info)) continue; + + for (StoneType stoneType : stoneTypes) { + if (stoneType == null) continue; + + if (info.material.contains(SubTag.ICE_ORE)) { + // if this material only has ice ore, we only want to show the ice variants + if (stoneType.getCategory() != StoneCategory.Ice) continue; + + info.stoneType = stoneType; + + list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + } else { + // if this material doesn't jabe ice ore, we only want to show the stone variants + if (stoneType.getCategory() != StoneCategory.Stone) continue; + if (stoneType.isExtraneous()) continue; + + info.stoneType = stoneType; + + list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + } + } + } + } + + @Override + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + EntityPlayer harvester = this.harvesters.get(); + + boolean doFortune = !(harvester instanceof FakePlayer); + boolean doSilktouch = harvester != null && EnchantmentHelper.getSilkTouchModifier(harvester); + + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, metadata)) { + if (info == null) return new ArrayList<>(); + + return GTOreAdapter.INSTANCE + .getOreDrops(ThreadLocalRandom.current(), info, doSilktouch, doFortune ? fortune : 0); + } + } + + @Override + public ITexture[][] getTextures(int metadata) { + StoneType stoneType = getStoneType(metadata); + Materials mat = getMaterial(metadata); + boolean small = isSmallOre(metadata); + + ITexture[] textures; + + if (stoneType == null) stoneType = StoneType.Stone; + + if (mat != null) { + ITexture iTexture = TextureFactory.builder() + .addIcon( + mat.mIconSet.mTextures[small ? OrePrefixes.oreSmall.mTextureIndex : OrePrefixes.ore.mTextureIndex]) + .setRGBA(mat.mRGBa) + .stdOrient() + .build(); + + textures = new ITexture[] { stoneType.getTexture(0), iTexture }; + } else { + textures = new ITexture[] { stoneType.getTexture(0), TextureFactory.builder() + .addIcon(TextureSet.SET_NONE.mTextures[OrePrefixes.ore.mTextureIndex]) + .stdOrient() + .build() }; + } + + return new ITexture[][] { textures, textures, textures, textures, textures, textures }; + } + + @Override + public IIcon getIcon(int side, int meta) { + StoneType stoneType = getStoneType(meta); + + return stoneType == null ? StoneType.Stone.getIcon(side) : stoneType.getIcon(side); + } + + @Override + public int getRenderType() { + return GTRendererBlock.mRenderID; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) { + GTRendererBlock + .addHitEffects(effectRenderer, this, worldObj, target.blockX, target.blockY, target.blockZ, target.sideHit); + return true; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) { + GTRendererBlock.addDestroyEffects(effectRenderer, this, world, x, y, z); + return true; + } + + public String getLocalizedNameFormat(Materials material) { + String base = OrePrefixes.ore.getDefaultLocalNameForItem(material); + + if (GTLanguageManager.i18nPlaceholder) { + return base; + } else { + return material.getDefaultLocalizedNameForItem(base); + } + } + + @Override + public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) { + if (entity instanceof EntityDragon) return false; + + return super.canEntityDestroy(world, x, y, z, entity); + } + + @Override + public boolean isToolEffective(String type, int metadata) { + return "pickaxe".equals(type); + } + + @Override + public String getHarvestTool(int aMeta) { + return "pickaxe"; + } + + @Override + public int damageDropped(int meta) { + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, meta)) { + if (info == null) return 0; + + info.isNatural = false; + + return GTOreAdapter.INSTANCE.getBlock(info) + .getBlockMeta(); + } + } + + @Override + public int getHarvestLevel(int meta) { + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, meta)) { + if (info == null) return 0; + + int smallOreBonus = info.isSmall ? -1 : 0; + + int harvestLevel = GTMod.gregtechproxy.mChangeHarvestLevels + ? GTMod.gregtechproxy.mHarvestLevel[info.material.mMetaItemSubID] + : info.material.mToolQuality; + + return GTUtility.clamp(harvestLevel + smallOreBonus, 0, GTMod.gregtechproxy.mMaxHarvestLevel); + } + } + + @Override + public float getBlockHardness(World world, int x, int y, int z) { + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(world, x, y, z)) { + return info.stoneType.getStone() + .getBlock().blockHardness; + } + } + + @Override + public float getExplosionResistance(Entity entity, World world, int x, int y, int z, double explosionX, + double explosionY, double explosionZ) { + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(world, x, y, z)) { + return info.stoneType.getStone() + .getBlock() + .getExplosionResistance(entity); + } + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX, + float subY, float subZ) { + if (!world.isRemote && player.capabilities.isCreativeMode && player.getHeldItem() == null) { + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(world, x, y, z);) { + info.isNatural = !info.isNatural; + + world.setBlockMetadataWithNotify( + x, + y, + z, + GTOreAdapter.INSTANCE.getBlock(info) + .getBlockMeta(), + 3); + GTUtility.sendChatToPlayer(player, "Set ore natural flag to " + info.isNatural); + } + + return true; + } else { + return false; + } + } + + @Override + protected boolean canSilkHarvest() { + return false; + } + + @Override + public boolean isFireSource(World world, int x, int y, int z, ForgeDirection side) { + return side == ForgeDirection.UP && getStoneType(getDamageValue(world, x, y, z)) == StoneType.Netherrack; + } + + public static final int SMALL_ORE_META_OFFSET = 16000, NATURAL_ORE_META_OFFSET = 8000; + + public int getMaterialIndex(int meta) { + return meta % 1000; + } + + public int getStoneIndex(int meta) { + meta %= SMALL_ORE_META_OFFSET; + meta %= NATURAL_ORE_META_OFFSET; + + return meta / 1000; + } + + public boolean isSmallOre(int meta) { + return meta >= SMALL_ORE_META_OFFSET; + } + + public boolean isNatural(int meta) { + return (meta % SMALL_ORE_META_OFFSET) >= NATURAL_ORE_META_OFFSET; + } + + public Materials getMaterial(int meta) { + return GregTechAPI.sGeneratedMaterials[getMaterialIndex(meta)]; + } + + public StoneType getStoneType(int meta) { + int stoneType = getStoneIndex(meta); + + if (stoneType < 0 || stoneType >= stoneTypes.size()) return null; + + return stoneTypes.get(stoneType); + } +} diff --git a/src/main/java/gregtech/common/blocks/GTItemOre.java b/src/main/java/gregtech/common/blocks/GTItemOre.java new file mode 100644 index 00000000000..f3161ded4f6 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/GTItemOre.java @@ -0,0 +1,56 @@ +package gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; + +import org.apache.commons.lang3.StringUtils; + +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Materials; + +public class GTItemOre extends ItemBlock { + + public final GTBlockOre blockOre; + + public GTItemOre(Block block) { + super(block); + setMaxDamage(0); + setHasSubtypes(true); + setCreativeTab(GregTechAPI.TAB_GREGTECH_MATERIALS); + + blockOre = (GTBlockOre) block; + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + int metadata = stack.getItemDamage(); + + int matId = blockOre.getMaterialIndex(metadata); + boolean small = blockOre.isSmallOre(metadata); + + return this.field_150939_a.getUnlocalizedName() + "." + + (matId + (small ? GTBlockOre.SMALL_ORE_META_OFFSET : 0)); + } + + @Override + public int getMetadata(int meta) { + return meta; + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + String aName = super.getItemStackDisplayName(stack); + return Materials.getLocalizedNameForItem(aName, blockOre.getMaterialIndex(stack.getItemDamage())); + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List desc, boolean advancedTooltips) { + String formula = StatCollector.translateToLocal(getUnlocalizedName(stack) + ".tooltip"); + if (!StringUtils.isBlank(formula)) desc.add(formula); + } +} diff --git a/src/main/java/gregtech/common/blocks/ItemOres.java b/src/main/java/gregtech/common/blocks/ItemOres.java deleted file mode 100644 index 0691142bc35..00000000000 --- a/src/main/java/gregtech/common/blocks/ItemOres.java +++ /dev/null @@ -1,81 +0,0 @@ -package gregtech.common.blocks; - -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemBlock; -import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; -import net.minecraft.world.World; - -import org.apache.commons.lang3.StringUtils; - -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; - -public class ItemOres extends ItemBlock { - - public ItemOres(Block block) { - super(block); - setMaxDamage(0); - setHasSubtypes(true); - setCreativeTab(GregTechAPI.TAB_GREGTECH_MATERIALS); - } - - @Override - public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, - int ordinalSide, float hitX, float hitY, float hitZ) { - return false; - } - - @Override - public String getUnlocalizedName(ItemStack aStack) { - return this.field_150939_a.getUnlocalizedName() + "." + getDamage(aStack); - } - - @Override - public String getItemStackDisplayName(ItemStack aStack) { - String aName = super.getItemStackDisplayName(aStack); - if (this.field_150939_a instanceof BlockOresAbstract) { - aName = Materials.getLocalizedNameForItem(aName, aStack.getItemDamage() % 1000); - } - return aName; - } - - @Override - public boolean placeBlockAt(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, - int ordinalSide, float hitX, float hitY, float hitZ, int aMeta) { - short tDamage = (short) getDamage(aStack); - if (tDamage > 0) { - if (!aWorld.setBlock( - aX, - aY, - aZ, - this.field_150939_a, - TileEntityOres.getHarvestData( - tDamage, - ((BlockOresAbstract) field_150939_a).getBaseBlockHarvestLevel(aMeta % 16000 / 1000)), - 3)) { - return false; - } - TileEntityOres tTileEntity = (TileEntityOres) aWorld.getTileEntity(aX, aY, aZ); - tTileEntity.mMetaData = tDamage; - tTileEntity.mNatural = false; - } else if (!aWorld.setBlock(aX, aY, aZ, this.field_150939_a, 0, 3)) { - return false; - } - if (aWorld.getBlock(aX, aY, aZ) == this.field_150939_a) { - this.field_150939_a.onBlockPlacedBy(aWorld, aX, aY, aZ, aPlayer, aStack); - this.field_150939_a.onPostBlockPlaced(aWorld, aX, aY, aZ, tDamage); - } - return true; - } - - @Override - public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { - String formula = StatCollector - .translateToLocal(field_150939_a.getUnlocalizedName() + '.' + getDamage(aStack) + ".tooltip"); - if (!StringUtils.isBlank(formula)) aList.add(formula); - } -} diff --git a/src/main/java/gregtech/common/blocks/ItemOresLegacy.java b/src/main/java/gregtech/common/blocks/ItemOresLegacy.java new file mode 100644 index 00000000000..48494a35576 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/ItemOresLegacy.java @@ -0,0 +1,16 @@ +package gregtech.common.blocks; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemBlock; + +/** + * The legacy ores. Must still be registered so that postea can transform them into the new ore blocks. + */ +public class ItemOresLegacy extends ItemBlock { + + public ItemOresLegacy(Block block) { + super(block); + setMaxDamage(0); + setHasSubtypes(true); + } +} diff --git a/src/main/java/gregtech/common/blocks/PacketOres.java b/src/main/java/gregtech/common/blocks/PacketOres.java deleted file mode 100644 index 18a5672c55f..00000000000 --- a/src/main/java/gregtech/common/blocks/PacketOres.java +++ /dev/null @@ -1,62 +0,0 @@ -package gregtech.common.blocks; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - -import com.google.common.io.ByteArrayDataInput; - -import gregtech.api.net.GTPacket; -import gregtech.api.net.GTPacketTypes; -import io.netty.buffer.ByteBuf; - -public class PacketOres extends GTPacket { - - private int mX; - private int mZ; - private short mY; - private short mMetaData; - - public PacketOres() { - super(); - } - - public PacketOres(int aX, short aY, int aZ, short aMetaData) { - super(); - this.mX = aX; - this.mY = aY; - this.mZ = aZ; - this.mMetaData = aMetaData; - } - - @Override - public void encode(ByteBuf aOut) { - aOut.writeInt(this.mX); - aOut.writeShort(this.mY); - aOut.writeInt(this.mZ); - aOut.writeShort(this.mMetaData); - } - - @Override - public GTPacket decode(ByteArrayDataInput aData) { - return new PacketOres(aData.readInt(), aData.readShort(), aData.readInt(), aData.readShort()); - } - - @Override - public void process(IBlockAccess aWorld) { - if (aWorld != null) { - TileEntity tTileEntity = aWorld.getTileEntity(this.mX, this.mY, this.mZ); - if ((tTileEntity instanceof TileEntityOres)) { - ((TileEntityOres) tTileEntity).mMetaData = this.mMetaData; - } - if (((aWorld instanceof World)) && (((World) aWorld).isRemote)) { - ((World) aWorld).markBlockForUpdate(this.mX, this.mY, this.mZ); - } - } - } - - @Override - public byte getPacketID() { - return GTPacketTypes.ORES.id; - } -} diff --git a/src/main/java/gregtech/common/blocks/TileEntityOres.java b/src/main/java/gregtech/common/blocks/TileEntityOres.java index 0dbdcec1a2b..ef9b127bf0a 100644 --- a/src/main/java/gregtech/common/blocks/TileEntityOres.java +++ b/src/main/java/gregtech/common/blocks/TileEntityOres.java @@ -1,141 +1,12 @@ package gregtech.common.blocks; -import static gregtech.api.enums.TextureSet.SET_NONE; - -import java.util.ArrayList; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -import org.jetbrains.annotations.NotNull; -import gregtech.GTMod; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.GTValues; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IAllSidedTexturedTileEntity; -import gregtech.api.objects.XSTR; -import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTOreDictUnificator; -import gregtech.api.util.GTUtility; - -public class TileEntityOres extends TileEntity implements IAllSidedTexturedTileEntity { +public class TileEntityOres extends TileEntity { public short mMetaData = 0; - protected static boolean shouldFortune = false; - protected static boolean shouldSilkTouch = false; public boolean mNatural = false; - public boolean mBlocked = true; - public boolean mBlockedChecked = false; - private short mMetadataForCachedTexture = -1; - private ITexture[] mCachedTexture; - - public static byte getHarvestData(short aMetaData, int aBaseBlockHarvestLevel) { - Materials aMaterial = GregTechAPI.sGeneratedMaterials[(aMetaData % 1000)]; - byte tByte = aMaterial == null ? 0 - : (byte) Math - .max(aBaseBlockHarvestLevel, Math.min(7, aMaterial.mToolQuality - (aMetaData < 16000 ? 0 : 1))); - if (GTMod.gregtechproxy.mChangeHarvestLevels) { - tByte = aMaterial == null ? 0 - : (byte) Math.max( - aBaseBlockHarvestLevel, - Math.min( - GTMod.gregtechproxy.mMaxHarvestLevel, - GTMod.gregtechproxy.mHarvestLevel[aMaterial.mMetaItemSubID] - (aMetaData < 16000 ? 0 : 1))); - } - return tByte; - } - - public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre) { - return setOreBlock(aWorld, aX, aY, aZ, aMetaData, isSmallOre, true); - } - - public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre, - boolean air) { - if (!air) { - aY = Math.min(aWorld.getActualHeight(), Math.max(aY, 1)); - } - Block tBlock = aWorld.getBlock(aX, aY, aZ); - Block tOreBlock = GregTechAPI.sBlockOres1; - int BlockMeta = aWorld.getBlockMetadata(aX, aY, aZ); - String BlockName = tBlock.getUnlocalizedName(); - aMetaData += isSmallOre ? 16000 : 0; - if ((aMetaData > 0) && ((tBlock != Blocks.air) || air)) { - if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone)) { - // Do nothing, stone background is default background. - // Do this comparison first since stone is most common - } else if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.netherrack)) { - aMetaData += 1000; - } else if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.end_stone)) { - aMetaData += 2000; - } else if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTechAPI.sBlockGranites)) { - if (tBlock == GregTechAPI.sBlockGranites) { - if (aWorld.getBlockMetadata(aX, aY, aZ) < 8) { - aMetaData += 3000; - } else { - aMetaData += 4000; - } - } else { - aMetaData += 3000; - } - } else if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTechAPI.sBlockStones)) { - if (tBlock == GregTechAPI.sBlockStones) { - if (aWorld.getBlockMetadata(aX, aY, aZ) < 8) { - aMetaData += 5000; - } else { - aMetaData += 6000; - } - } else { - aMetaData += 5000; - } - } else if (BlockName.equals("tile.igneousStone")) { - if (GregTechAPI.sBlockOresUb1 != null) { - tOreBlock = GregTechAPI.sBlockOresUb1; - aMetaData += (BlockMeta * 1000); - // GT_FML_LOGGER.info("Block changed to UB1"); - } - } else if (BlockName.equals("tile.metamorphicStone")) { - if (GregTechAPI.sBlockOresUb2 != null) { - tOreBlock = GregTechAPI.sBlockOresUb2; - aMetaData += (BlockMeta * 1000); - // GT_FML_LOGGER.info("Block changed to UB2"); - } - } else if (BlockName.equals("tile.sedimentaryStone")) { - if (GregTechAPI.sBlockOresUb3 != null) { - tOreBlock = GregTechAPI.sBlockOresUb3; - aMetaData += (BlockMeta * 1000); - // GT_FML_LOGGER.info("Block changed to UB3"); - } - } else { - return false; - } - // GT_FML_LOGGER.info(tOreBlock); - aWorld.setBlock( - aX, - aY, - aZ, - tOreBlock, - getHarvestData( - (short) aMetaData, - ((BlockOresAbstract) tOreBlock).getBaseBlockHarvestLevel(aMetaData % 16000 / 1000)), - 0); - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if ((tTileEntity instanceof TileEntityOres)) { - ((TileEntityOres) tTileEntity).mMetaData = ((short) aMetaData); - ((TileEntityOres) tTileEntity).mNatural = true; - } - return true; - } - return false; - } @Override public void readFromNBT(NBTTagCompound aNBT) { @@ -151,340 +22,8 @@ public void writeToNBT(NBTTagCompound aNBT) { aNBT.setBoolean("n", this.mNatural); } - public void onUpdated() { - if ((!this.worldObj.isRemote) && (this.mBlocked)) { - this.mBlocked = false; - GTValues.NW.sendPacketToAllPlayersInRange( - this.worldObj, - new PacketOres(this.xCoord, (short) this.yCoord, this.zCoord, this.mMetaData), - this.xCoord, - this.zCoord); - } - } - - @Override - public Packet getDescriptionPacket() { - if (!this.worldObj.isRemote) { - boolean sendUpdate = mBlockedChecked ? !mBlocked : checkBlocked(); - if (sendUpdate) { - GTValues.NW.sendPacketToAllPlayersInRange( - this.worldObj, - new PacketOres(this.xCoord, (short) this.yCoord, this.zCoord, this.mMetaData), - this.xCoord, - this.zCoord); - } - } - return null; - } - - private boolean checkBlocked() { - // this is called very frequently and is performance critical. unroll the loop. - mBlockedChecked = true; - if (!worldObj.blockExists(xCoord + 1, yCoord, zCoord)) { - mBlockedChecked = false; - } else if (!GTUtility.isOpaqueBlock(worldObj, xCoord + 1, yCoord, zCoord)) { - mBlocked = false; - return true; - } - if (!worldObj.blockExists(xCoord - 1, yCoord, zCoord)) { - mBlockedChecked = false; - } else if (!GTUtility.isOpaqueBlock(worldObj, xCoord - 1, yCoord, zCoord)) { - mBlocked = false; - return true; - } - if (!worldObj.blockExists(xCoord, yCoord + 1, zCoord)) { - mBlockedChecked = false; - } else if (!GTUtility.isOpaqueBlock(worldObj, xCoord, yCoord + 1, zCoord)) { - mBlocked = false; - return true; - } - if (!worldObj.blockExists(xCoord, yCoord - 1, zCoord)) { - mBlockedChecked = false; - } else if (!GTUtility.isOpaqueBlock(worldObj, xCoord, yCoord - 1, zCoord)) { - mBlocked = false; - return true; - } - if (!worldObj.blockExists(xCoord, yCoord, zCoord + 1)) { - mBlockedChecked = false; - } else if (!GTUtility.isOpaqueBlock(worldObj, xCoord, yCoord, zCoord + 1)) { - mBlocked = false; - return true; - } - if (!worldObj.blockExists(xCoord, yCoord, zCoord - 1)) { - mBlockedChecked = false; - } else if (!GTUtility.isOpaqueBlock(worldObj, xCoord, yCoord, zCoord - 1)) { - mBlocked = false; - return true; - } - mBlocked = true; - return false; - } - - public void overrideOreBlockMaterial(Block aOverridingStoneBlock, byte aOverridingStoneMeta) { - if (this.worldObj == null || blockType == null) return; - this.mMetaData = ((short) (int) (this.mMetaData % 1000L + this.mMetaData / 16000L * 16000L)); - if (aOverridingStoneBlock - .isReplaceableOreGen(this.worldObj, this.xCoord, this.yCoord, this.zCoord, Blocks.netherrack)) { - this.mMetaData = ((short) (this.mMetaData + 1000)); - } else if (aOverridingStoneBlock - .isReplaceableOreGen(this.worldObj, this.xCoord, this.yCoord, this.zCoord, Blocks.end_stone)) { - this.mMetaData = ((short) (this.mMetaData + 2000)); - } else if (aOverridingStoneBlock.isReplaceableOreGen( - this.worldObj, - this.xCoord, - this.yCoord, - this.zCoord, - GregTechAPI.sBlockGranites)) { - if (aOverridingStoneBlock == GregTechAPI.sBlockGranites) { - if (aOverridingStoneMeta < 8) { - this.mMetaData = ((short) (this.mMetaData + 3000)); - } else { - this.mMetaData = ((short) (this.mMetaData + 4000)); - } - } else { - this.mMetaData = ((short) (this.mMetaData + 3000)); - } - } else if (aOverridingStoneBlock.isReplaceableOreGen( - this.worldObj, - this.xCoord, - this.yCoord, - this.zCoord, - GregTechAPI.sBlockStones)) { - if (aOverridingStoneBlock == GregTechAPI.sBlockStones) { - if (aOverridingStoneMeta < 8) { - this.mMetaData = ((short) (this.mMetaData + 5000)); - } else { - this.mMetaData = ((short) (this.mMetaData + 6000)); - } - } else { - this.mMetaData = ((short) (this.mMetaData + 5000)); - } - } - this.worldObj.setBlockMetadataWithNotify( - this.xCoord, - this.yCoord, - this.zCoord, - getHarvestData( - this.mMetaData, - ((BlockOresAbstract) blockType).getBaseBlockHarvestLevel(mMetaData % 16000 / 1000)), - 0); - } - - public void convertOreBlock(World aWorld, int aX, int aY, int aZ) { - short aMeta = ((short) (this.mMetaData % 1000 + (this.mMetaData / 16000 * 16000))); - aWorld.setBlock(aX, aY, aZ, GregTechAPI.sBlockOres1); - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if (tTileEntity instanceof TileEntityOres) { - ((TileEntityOres) tTileEntity).mMetaData = aMeta; - this.worldObj.setBlockMetadataWithNotify( - this.xCoord, - this.yCoord, - this.zCoord, - getHarvestData( - aMeta, - ((BlockOresAbstract) tTileEntity.blockType).getBaseBlockHarvestLevel(aMeta % 16000 / 1000)), - 0); - } - } - - public short getMetaData() { - return this.mMetaData; - } - @Override public boolean canUpdate() { return false; } - - public ArrayList getDrops(Block aDroppedOre, int aFortune) { - ArrayList rList = new ArrayList<>(); - if (this.mMetaData <= 0) { - rList.add(new ItemStack(Blocks.cobblestone, 1, 0)); - return rList; - } - Materials aOreMaterial = GregTechAPI.sGeneratedMaterials[(this.mMetaData % 1000)]; - if (this.mMetaData < 16000) { - boolean tIsRich = false; - - // For Sake of god of balance! - - // Dense ore - - // NetherOre - if (GTMod.gregtechproxy.mNetherOreYieldMultiplier && !tIsRich) { - tIsRich = (this.mMetaData >= 1000 && this.mMetaData < 2000); - } - // EndOre - if (GTMod.gregtechproxy.mEndOreYieldMultiplier && !tIsRich) { - tIsRich = (this.mMetaData >= 2000 && this.mMetaData < 3000); - } - - // Silk Touch - if (shouldSilkTouch) { - rList.add(new ItemStack(aDroppedOre, 1, this.mMetaData)); - - } else { - switch (GTMod.gregtechproxy.oreDropSystem) { - case Item -> { - rList.add(GTOreDictUnificator.get(OrePrefixes.rawOre, aOreMaterial, (tIsRich ? 2 : 1))); - } - // TODO: Test - case FortuneItem -> { - // if shouldFortune and isNatural then get fortune drops - // if not shouldFortune or not isNatural then get normal drops - // if not shouldFortune and isNatural then get normal drops - // if shouldFortune and not isNatural then get normal drops - if (shouldFortune && this.mNatural && aFortune > 0) { - int aMinAmount = 1; - // Max applicable fortune - if (aFortune > 3) aFortune = 3; - int amount = aMinAmount - + Math.max(worldObj.rand.nextInt(aFortune * (tIsRich ? 2 : 1) + 2) - 1, 0); - for (int i = 0; i < amount; i++) { - rList.add(GTOreDictUnificator.get(OrePrefixes.rawOre, aOreMaterial, 1)); - } - } else { - for (int i = 0; i < (tIsRich ? 2 : 1); i++) { - rList.add(GTOreDictUnificator.get(OrePrefixes.rawOre, aOreMaterial, 1)); - } - } - } - case UnifiedBlock -> { - // Unified ore - for (int i = 0; i < (tIsRich ? 2 : 1); i++) { - rList.add(new ItemStack(aDroppedOre, 1, this.mMetaData % 1000)); - } - } - case PerDimBlock -> { - // Per Dimension ore - if (tIsRich) { - rList.add(new ItemStack(aDroppedOre, 1, this.mMetaData)); - } else { - rList.add(new ItemStack(aDroppedOre, 1, this.mMetaData % 1000)); - } - } - case Block -> { - // Regular ore - rList.add(new ItemStack(aDroppedOre, 1, this.mMetaData)); - } - } - } - return rList; - } - - // Everyone gets a free small fortune boost - aFortune += 1; - if (!this.mNatural) { - aFortune = 0; - } - if (aOreMaterial != null) { - Random tRandom = new XSTR(this.xCoord ^ this.yCoord ^ this.zCoord); - ArrayList tSelector = new ArrayList<>(); - - Materials aMaterial = aOreMaterial.mOreReplacement; - - ItemStack tStack = GTOreDictUnificator - .get(OrePrefixes.gemExquisite, aMaterial, GTOreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L), 1L); - if (tStack != null) { - for (int i = 0; i < 1; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator - .get(OrePrefixes.gemFlawless, aMaterial, GTOreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L), 1L); - if (tStack != null) { - for (int i = 0; i < 2; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L); - if (tStack != null) { - for (int i = 0; i < 12; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator - .get(OrePrefixes.gemFlawed, aMaterial, GTOreDictUnificator.get(OrePrefixes.crushed, aMaterial, 1L), 1L); - if (tStack != null) { - for (int i = 0; i < 5; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator.get(OrePrefixes.crushed, aMaterial, 1L); - if (tStack != null) { - for (int i = 0; i < 10; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator.get( - OrePrefixes.gemChipped, - aMaterial, - GTOreDictUnificator.get(OrePrefixes.dustImpure, aMaterial, 1L), - 1L); - if (tStack != null) { - for (int i = 0; i < 5; i++) { - tSelector.add(tStack); - } - } - tStack = GTOreDictUnificator.get(OrePrefixes.dustImpure, aMaterial, 1L); - if (tStack != null) { - for (int i = 0; i < 10; i++) { - tSelector.add(tStack); - } - } - if (!tSelector.isEmpty()) { - int i = 0; - for (int j = Math.max( - 1, - aMaterial.mOreMultiplier - + (aFortune > 0 ? tRandom.nextInt(1 + aFortune * aMaterial.mOreMultiplier) : 0) / 2); i - < j; i++) { - rList.add(GTUtility.copyAmount(1, tSelector.get(tRandom.nextInt(tSelector.size())))); - } - } - if (tRandom.nextInt(3 + aFortune) > 1) { - Materials dustMat = ((BlockOresAbstract) aDroppedOre).getDroppedDusts()[this.mMetaData / 1000 % 16]; - if (dustMat != null) rList.add( - GTOreDictUnificator - .get(tRandom.nextInt(3) > 0 ? OrePrefixes.dustImpure : OrePrefixes.dust, dustMat, 1L)); - } - } - return rList; - } - - public ArrayList getSilkTouchDrops(Block aDroppedOre) { - final boolean tShouldSilkTouch = TileEntityOres.shouldSilkTouch; - TileEntityOres.shouldSilkTouch = true; - final ArrayList tDrops = getDrops(aDroppedOre, 0); - TileEntityOres.shouldSilkTouch = tShouldSilkTouch; - return tDrops; - } - - @Override - public ITexture[] getTexture(Block aBlock) { - if (mMetadataForCachedTexture == mMetaData && mCachedTexture != null) return mCachedTexture; - - mMetadataForCachedTexture = mMetaData; - mCachedTexture = getTextureInternal(aBlock); - return mCachedTexture; - } - - private ITexture @NotNull [] getTextureInternal(Block aBlock) { - Materials aMaterial = GregTechAPI.sGeneratedMaterials[(this.mMetaData % 1000)]; - if ((aMaterial != null) && (this.mMetaData < 32000) && (aBlock instanceof BlockOresAbstract)) { - ITexture iTexture = TextureFactory.builder() - .addIcon( - aMaterial.mIconSet.mTextures[this.mMetaData / 16000 == 0 ? OrePrefixes.ore.mTextureIndex - : OrePrefixes.oreSmall.mTextureIndex]) - .setRGBA(aMaterial.mRGBa) - .stdOrient() - .build(); - return new ITexture[] { ((BlockOresAbstract) aBlock).getTextureSet()[((this.mMetaData / 1000) % 16)], - iTexture }; - } - return new ITexture[] { TextureFactory.of(Blocks.stone, 0), TextureFactory.builder() - .addIcon(SET_NONE.mTextures[OrePrefixes.ore.mTextureIndex]) - .stdOrient() - .build() }; - } } diff --git a/src/main/java/gregtech/common/config/Gregtech.java b/src/main/java/gregtech/common/config/Gregtech.java index c9aeb841ad6..b16bb08873d 100644 --- a/src/main/java/gregtech/common/config/Gregtech.java +++ b/src/main/java/gregtech/common/config/Gregtech.java @@ -372,6 +372,21 @@ public static class General { @Config.DefaultBoolean(true) @Config.RequiresMcRestart public boolean loggingExplosions; + + @Config.Comment("The maximum number of nanoseconds that the cooperative scheduler will run for each tick.") + @Config.DefaultInt(10_000_000) // 10 ms + @Config.Name("Scheduler Max Duration (ns)") + public int schedulerDuration; + + @Config.Comment("The maximum number of tasks that the scheduler will try to run per tick (not a hard limit).") + @Config.DefaultInt(5) + @Config.Name("Scheduler Target Task Count") + public int maxTaskCount; + + @Config.Comment("0 = No Profiling. 1 = Print the time taken by the scheduler. 2 = Print the time taken by each task.") + @Config.DefaultInt(0) + @Config.Name("Scheduler Profiling") + public int schedulerProfileLevel; } @Config.LangKey("GT5U.gui.config.gregtech.harvest_level") diff --git a/src/main/java/gregtech/common/config/Worldgen.java b/src/main/java/gregtech/common/config/Worldgen.java index 274d59a7744..e1219c8f62f 100644 --- a/src/main/java/gregtech/common/config/Worldgen.java +++ b/src/main/java/gregtech/common/config/Worldgen.java @@ -13,31 +13,6 @@ public class Worldgen { public static General general = new General(); - public static EndAsteroids endAsteroids = new EndAsteroids(); - - @Config.LangKey("GT5U.gui.config.worldgen.end_asteroids") - public static class EndAsteroids { - - @Config.Comment("The maximum size for the end asteroids.") - @Config.DefaultInt(200) - @Config.RequiresMcRestart - public int EndAsteroidMaxSize; - - @Config.Comment("The minimum size for the end asteroids.") - @Config.DefaultInt(200) - @Config.RequiresMcRestart - public int EndAsteroidMinSize; - - @Config.Comment("The probability weight to generate end asteroids.") - @Config.DefaultInt(300) - @Config.RequiresMcRestart - public int EndAsteroidProbability; - - @Config.Comment("if true, enables end asteroids.") - @Config.DefaultBoolean(true) - @Config.RequiresMcRestart - public boolean generateEndAsteroids; - } @Config.LangKey("GT5U.gui.config.worldgen.general") public static class General { diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java index 98aed597f93..1466dca3abb 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java @@ -5,17 +5,17 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; +import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.IFluidBlock; -import gregtech.api.GregTechAPI; import gregtech.api.enums.Materials; import gregtech.api.enums.SoundResource; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.items.MetaBaseItem; import gregtech.api.items.MetaGeneratedTool; import gregtech.api.objects.ItemData; @@ -24,8 +24,7 @@ import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; public class BehaviourProspecting extends BehaviourNone { @@ -39,114 +38,117 @@ public BehaviourProspecting(int aVanillaCosts, int aEUCosts) { this.mEUCosts = aEUCosts; } + private static Materials getOreMaterial(Block block, int meta) { + ItemData association = GTOreDictUnificator.getAssociation(new ItemStack(block, 1, meta)); + if (association == null) return null; + if (association.mPrefix == null) return null; + if (association.mMaterial == null) return null; + if (!association.mPrefix.toString() + .startsWith("ore")) return null; + + return association.mMaterial.mMaterial; + } + @Override public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, ForgeDirection side, float hitX, float hitY, float hitZ) { if (aWorld.isRemote) { return false; } + Block aBlock = aWorld.getBlock(aX, aY, aZ); - if (aBlock == null) { + if (aBlock.isAir(aWorld, aX, aY, aZ)) { return false; } - byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); - ItemData tAssociation = GTOreDictUnificator.getAssociation(new ItemStack(aBlock, 1, aMeta)); - if (tAssociation != null && tAssociation.mPrefix != null - && tAssociation.mMaterial != null - && tAssociation.mPrefix.toString() - .startsWith("ore")) { + int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); + + IOreMaterial mat = OreManager.getMaterial(aBlock, aMeta); + if (mat != null) { + GTUtility.sendChatToPlayer( + aPlayer, + GTUtility.trans("100", "This is ") + mat.getLocalizedName() + GTUtility.trans("101", " Ore.")); + GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); + return true; + } + + Materials oreMat = getOreMaterial(aBlock, aMeta); + + if (oreMat != null) { GTUtility.sendChatToPlayer( aPlayer, - GTUtility.trans("100", "This is ") + tAssociation.mMaterial.mMaterial.mDefaultLocalName - + GTUtility.trans("101", " Ore.")); + GTUtility.trans("100", "This is ") + oreMat.mDefaultLocalName + GTUtility.trans("101", " Ore.")); GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); return true; } - if (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone) - || aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.netherrack) - || aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.end_stone) - || aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTechAPI.sBlockStones) - || aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTechAPI.sBlockGranites) - || aBlock == GregTechAPI.sBlockOresUb1 - || aBlock == GregTechAPI.sBlockOresUb2 - || aBlock == GregTechAPI.sBlockOresUb3 - || aBlock == GregTechAPI.sBlockOres1) { - if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) { - GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); - int tMetaID; - int tQuality = aItem instanceof MetaGeneratedTool ? aItem.getHarvestLevel(aStack, "") : 0; - int tX = aX, tY = aY, tZ = aZ; - Block tBlock; - for (int i = 0, j = 6 + tQuality; i < j; i++) { - tX -= side.offsetX; - tY -= side.offsetY; - tZ -= side.offsetZ; - - tBlock = aWorld.getBlock(tX, tY, tZ); - if (tBlock == Blocks.lava || tBlock == Blocks.flowing_lava) { - GTUtility.sendChatToPlayer(aPlayer, GTUtility.trans("102", "There is Lava behind this Rock.")); - break; - } - if (tBlock instanceof BlockLiquid || tBlock instanceof IFluidBlock) { - GTUtility - .sendChatToPlayer(aPlayer, GTUtility.trans("103", "There is a Liquid behind this Rock.")); - break; - } - if (tBlock == Blocks.monster_egg || !GTUtility.hasBlockHitBox(aWorld, tX, tY, tZ)) { - GTUtility.sendChatToPlayer( - aPlayer, - GTUtility.trans("104", "There is an Air Pocket behind this Rock.")); - break; - } - if (tBlock != aBlock) { - if (i < 4) GTUtility.sendChatToPlayer( - aPlayer, - GTUtility.trans("105", "Material is changing behind this Rock.")); - break; - } + if (aBlock.getMaterial() == Material.rock || aBlock.getMaterial() == Material.ground + || OreManager.isOre(aBlock, aMeta)) { + if (!GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) return false; + + GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); + int toolQuality = aItem instanceof MetaGeneratedTool ? aItem.getHarvestLevel(aStack, "") : 0; + int tX = aX, tY = aY, tZ = aZ; + for (int i = 0, j = 6 + toolQuality; i < j; i++) { + tX -= side.offsetX; + tY -= side.offsetY; + tZ -= side.offsetZ; + + Block tBlock = aWorld.getBlock(tX, tY, tZ); + + if (tBlock == Blocks.lava || tBlock == Blocks.flowing_lava) { + GTUtility.sendChatToPlayer(aPlayer, GTUtility.trans("102", "There is Lava behind this Rock.")); + break; + } + if (tBlock instanceof BlockLiquid || tBlock instanceof IFluidBlock) { + GTUtility.sendChatToPlayer(aPlayer, GTUtility.trans("103", "There is a Liquid behind this Rock.")); + break; + } + if (tBlock == Blocks.monster_egg || !GTUtility.hasBlockHitBox(aWorld, tX, tY, tZ)) { + GTUtility + .sendChatToPlayer(aPlayer, GTUtility.trans("104", "There is an Air Pocket behind this Rock.")); + break; + } + if (tBlock != aBlock) { + if (i < 4) GTUtility + .sendChatToPlayer(aPlayer, GTUtility.trans("105", "Material is changing behind this Rock.")); + break; + } + } + + final Random tRandom = new XSTR(aX ^ aY ^ aZ ^ side.ordinal()); + for (int i = 0, j = 9 + 2 * toolQuality; i < j; i++) { + tX = aX - 4 - toolQuality + tRandom.nextInt(j); + tY = aY - 4 - toolQuality + tRandom.nextInt(j); + tZ = aZ - 4 - toolQuality + tRandom.nextInt(j); + + Block tBlock = aWorld.getBlock(tX, tY, tZ); + int tMeta = aWorld.getBlockMetadata(tX, tY, tZ); + + mat = OreManager.getMaterial(tBlock, tMeta); + if (mat != null) { + GTUtility.sendChatToPlayer( + aPlayer, + GTUtility.trans("106", "Found traces of ") + mat.getLocalizedName() + + GTUtility.trans("101", " Ore.")); + return true; } - final Random tRandom = new XSTR(aX ^ aY ^ aZ ^ side.ordinal()); - for (int i = 0, j = 9 + 2 * tQuality; i < j; i++) { - tX = aX - 4 - tQuality + tRandom.nextInt(j); - tY = aY - 4 - tQuality + tRandom.nextInt(j); - tZ = aZ - 4 - tQuality + tRandom.nextInt(j); - tBlock = aWorld.getBlock(tX, tY, tZ); - if (tBlock instanceof BlockOresAbstract) { - final TileEntity tTileEntity = aWorld.getTileEntity(tX, tY, tZ); - if (tTileEntity instanceof TileEntityOres) { - final Materials tMaterial = GregTechAPI.sGeneratedMaterials[((TileEntityOres) tTileEntity).mMetaData - % 1000]; - if (tMaterial != null && tMaterial != Materials._NULL) { - GTUtility.sendChatToPlayer( - aPlayer, - GTUtility.trans("106", "Found traces of ") + tMaterial.mDefaultLocalName - + GTUtility.trans("101", " Ore.")); - return true; - } - } - } else { - tMetaID = aWorld.getBlockMetadata(tX, tY, tZ); - tAssociation = GTOreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); - if (tAssociation != null && tAssociation.mPrefix != null - && tAssociation.mMaterial != null - && tAssociation.mPrefix.toString() - .startsWith("ore")) { - GTUtility.sendChatToPlayer( - aPlayer, - GTUtility.trans("106", "Found traces of ") - + tAssociation.mMaterial.mMaterial.mDefaultLocalName - + GTUtility.trans("101", " Ore.")); - return true; - } - } + oreMat = getOreMaterial(tBlock, tMeta); + + if (oreMat != null) { + GTUtility.sendChatToPlayer( + aPlayer, + GTUtility.trans("106", "Found traces of ") + oreMat.mDefaultLocalName + + GTUtility.trans("101", " Ore.")); + return true; } - GTUtility.sendChatToPlayer(aPlayer, GTUtility.trans("107", "No Ores found.")); - return true; } + + GTUtility.sendChatToPlayer(aPlayer, GTUtility.trans("107", "No Ores found.")); + return true; } + return false; } diff --git a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java index c52141f9bca..e351d577da6 100644 --- a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java +++ b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java @@ -7,14 +7,14 @@ import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.FakePlayer; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.XSTR; import gregtech.api.util.GTLog; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTUtility; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; /** @author Relvl on 27.01.2022 */ @SuppressWarnings("ObjectEquality") @@ -162,35 +162,24 @@ public void mineBlock(IGregTechTileEntity te, Block block, int x, int y, int z) return; } - List drops = getBlockDrops(block, x, y, z); + XSTR rng = new XSTR(); + + // see if we can store all of the outputs + List drops = OreManager + .mineBlock(rng, te.getWorld(), x, y, z, false, owner.getMachineTier(), true, true); - boolean canFitDrops = true; for (ItemStack drop : drops) { - canFitDrops &= owner.pushOutputs(drop, drop.stackSize, true, false); - } - if (!canFitDrops) { - return; + if (!owner.pushOutputs(drop, drop.stackSize, true, false)) { + return; + } } + for (ItemStack drop : drops) { owner.pushOutputs(drop, drop.stackSize, false, false); } - short metaData = 0; - TileEntity tTileEntity = owner.getBaseMetaTileEntity() - .getTileEntity(x, y, z); - if (tTileEntity instanceof TileEntityOres) { - metaData = ((TileEntityOres) tTileEntity).mMetaData; - } - - ItemStack cobble = GTUtility.getCobbleForOre(block, metaData); - te.getWorld() - .setBlock( - x, - y, - z, - Block.getBlockFromItem(cobble.getItem()), - cobble.getItemDamage(), /* cause updates(1) + send to client(2) */ - 3); + // actually mine it + OreManager.mineBlock(rng, te.getWorld(), x, y, z, false, owner.getMachineTier(), false, true); } /** @@ -236,19 +225,6 @@ public boolean canFakePlayerInteract(IGregTechTileEntity te, int xCoord, int yCo .setBlockByFakePlayer(getFakePlayer(te), xCoord, yCoord, zCoord, MINING_PIPE_TIP_BLOCK, 0, true); } - /** Get target block drops. We need to encapsulate everyting of mining in this class. */ - private List getBlockDrops(final Block oreBlock, int posX, int posY, int posZ) { - return oreBlock.getDrops( - owner.getBaseMetaTileEntity() - .getWorld(), - posX, - posY, - posZ, - owner.getBaseMetaTileEntity() - .getMetaID(posX, posY, posZ), - owner.getMachineTier()); - } - /** Can the owner continue doing its work? If we await new pipes - it cannot. */ public boolean canContinueDrilling(long tick) { if (isWaitingForPipeItem) { diff --git a/src/main/java/gregtech/common/ores/BWOreAdapter.java b/src/main/java/gregtech/common/ores/BWOreAdapter.java new file mode 100644 index 00000000000..c880d0a6fa0 --- /dev/null +++ b/src/main/java/gregtech/common/ores/BWOreAdapter.java @@ -0,0 +1,293 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.gtnhlib.util.data.BlockMeta; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; +import com.gtnewhorizons.postea.api.TileEntityReplacementManager; +import com.gtnewhorizons.postea.utility.BlockInfo; + +import bartworks.system.material.BWItemMetaGeneratedOre; +import bartworks.system.material.BWMetaGeneratedOres; +import bartworks.system.material.Werkstoff; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.GTMod; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IStoneType; +import gregtech.api.util.GTUtility; +import gregtech.api.util.GTUtility.ItemId; +import gregtech.common.GTProxy.OreDropSystem; + +public final class BWOreAdapter implements IOreAdapter { + + public static BWOreAdapter INSTANCE = new BWOreAdapter(); + + private BWOreAdapter() {} + + private final EnumMap ores = new EnumMap<>(StoneType.class); + + private static class Ores { + + public BWMetaGeneratedOres big, bigNatural, small, smallNatural; + + public Ores(StoneType stoneType, String bigSuffix, String smallSuffix) { + big = new BWMetaGeneratedOres("bw.blockores", stoneType, false, false); + bigNatural = new BWMetaGeneratedOres("bw.blockores.natural", stoneType, false, true); + small = new BWMetaGeneratedOres("bw.blockoresSmall", stoneType, true, false); + smallNatural = new BWMetaGeneratedOres("bw.blockoresSmall.natural", stoneType, true, true); + + GameRegistry.registerBlock(big, BWItemMetaGeneratedOre.class, "bw.blockores." + bigSuffix); + GameRegistry.registerBlock(bigNatural, BWItemMetaGeneratedOre.class, "bw.blockores.natural." + bigSuffix); + GameRegistry.registerBlock(small, BWItemMetaGeneratedOre.class, "bw.blockores." + smallSuffix); + GameRegistry + .registerBlock(smallNatural, BWItemMetaGeneratedOre.class, "bw.blockores.natural." + smallSuffix); + } + + public void registerOredict() { + big.registerOredict(); + bigNatural.registerOredict(); + small.registerOredict(); + smallNatural.registerOredict(); + } + + public BWMetaGeneratedOres get(boolean small, boolean natural) { + if (small) { + if (natural) { + return this.smallNatural; + } else { + return this.small; + } + } else { + if (natural) { + return this.bigNatural; + } else { + return this.big; + } + } + } + } + + public void init() { + Ores stoneOres; + ores.put(StoneType.Stone, stoneOres = new Ores(StoneType.Stone, "01", "02")); + ores.put(StoneType.Moon, new Ores(StoneType.Moon, "03", "04")); + + TileEntityReplacementManager.tileEntityTransformer("bw.blockoresTE", (tag, world) -> { + int id = tag.getInteger("m"); + boolean natural = tag.getBoolean("n"); + + Block block = stoneOres.get(false, natural); + + return new BlockInfo(block, id); + }); + + TileEntityReplacementManager.tileEntityTransformer("bw.blockoresSmallTE", (tag, world) -> { + int id = tag.getInteger("m"); + boolean natural = tag.getBoolean("n"); + + Block block = stoneOres.get(true, natural); + + return new BlockInfo(block, id); + }); + } + + public void registerOredict() { + ores.values() + .forEach(Ores::registerOredict); + } + + @Override + public boolean supports(Block block, int meta) { + return block instanceof BWMetaGeneratedOres; + } + + @Override + public boolean supports(OreInfo info) { + IStoneType stone = info.stoneType; + if (stone == null) stone = StoneType.Stone; + if (!(stone instanceof StoneType stoneType)) return false; + if (!this.ores.containsKey(stoneType)) return false; + + if (!(info.material instanceof Werkstoff w)) return false; + if (!w.hasItemType(OrePrefixes.ore)) return false; + if ((w.getGenerationFeatures().blacklist & 0b1000) != 0) return false; + + return true; + } + + @Override + public OreInfo getOreInfo(Block block, int meta) { + if (!supports(block, meta)) return null; + + BWMetaGeneratedOres oreBlock = (BWMetaGeneratedOres) block; + + OreInfo info = OreInfo.getNewInfo(); + + info.stoneType = oreBlock.stoneType; + info.material = Werkstoff.werkstoffHashMap.get((short) meta); + info.isSmall = oreBlock.isSmall; + info.isNatural = oreBlock.isNatural; + + return info; + } + + @Override + public ImmutableBlockMeta getBlock(OreInfo info) { + IStoneType stone = info.stoneType; + if (stone == null) stone = StoneType.Stone; + + if (!(stone instanceof StoneType stoneType)) return null; + if (!(info.material instanceof Werkstoff w)) return null; + if (!w.hasItemType(OrePrefixes.ore)) return null; + if ((w.getGenerationFeatures().blacklist & 0b1000) != 0) return null; + + Ores ores = this.ores.get(stoneType); + if (ores == null) return null; + + return new BlockMeta(ores.get(info.isSmall, info.isNatural), w.getmID()); + } + + @Override + public ArrayList getOreDrops(Random random, OreInfo info2, boolean silktouch, int fortune) { + if (!supports(info2)) return new ArrayList<>(); + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + IStoneType stone = info.stoneType; + if (stone == null) stone = StoneType.Stone; + if (!(stone instanceof StoneType stoneType)) return new ArrayList<>(); + if (!this.ores.containsKey(stoneType)) return new ArrayList<>(); + + if (!info.isNatural) fortune = 0; + + if (info.isSmall) { + return getSmallOreDrops(random, info, fortune); + } else { + OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; + + if (silktouch) oreDropSystem = OreDropSystem.Block; + + return getBigOreDrops(random, oreDropSystem, info, fortune); + } + } + + @Override + public List getPotentialDrops(OreInfo info2) { + if (!supports(info2)) return new ArrayList<>(); + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + if (info.isSmall) { + ArrayList drops = new ArrayList<>(); + + for (ItemStack stack : SmallOreDrops.getDropList(info.material.getBridgeMaterial())) { + ItemId id = ItemId.create(stack); + + if (!drops.contains(id)) drops.add(id); + } + + ArrayList drops2 = new ArrayList<>(); + + for (ItemId id : drops) { + drops2.add(id.getItemStack()); + } + + return drops2; + } else { + return getBigOreDrops(ThreadLocalRandom.current(), GTMod.gregtechproxy.oreDropSystem, info, 0); + } + } + + private ArrayList getSmallOreDrops(Random random, OreInfo info, int fortune) { + Materials bridge = info.material.getBridgeMaterial(); + + ArrayList possibleDrops = SmallOreDrops.getDropList(bridge); + ArrayList drops = new ArrayList<>(); + + if (!possibleDrops.isEmpty()) { + int dropCount = Math.max( + 1, + bridge.mOreMultiplier + (fortune > 0 ? random.nextInt(1 + fortune * bridge.mOreMultiplier) : 0) / 2); + + for (int i = 0; i < dropCount; i++) { + drops.add(GTUtility.copyAmount(1, possibleDrops.get(random.nextInt(possibleDrops.size())))); + } + } + + if (random.nextInt(3 + fortune) > 1) { + drops.add(info.stoneType.getDust(random.nextInt(3) == 0, 1)); + } + + return drops; + } + + private ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + int fortune) { + ArrayList drops = new ArrayList<>(); + + // For Sake of god of balance! + + switch (oreDropMode) { + case Item -> { + drops.add(info.material.get(OrePrefixes.rawOre, info.stoneType.isRich() ? 2 : 1)); + } + case FortuneItem -> { + if (fortune > 0) { + // Max applicable fortune + if (fortune > 3) fortune = 3; + + int amount = 1 + Math.max(random.nextInt(fortune * (info.stoneType.isRich() ? 2 : 1) + 2) - 1, 0); + + for (int i = 0; i < amount; i++) { + drops.add(info.material.get(OrePrefixes.rawOre, 1)); + } + } else { + for (int i = 0; i < (info.stoneType.isRich() ? 2 : 1); i++) { + drops.add(info.material.get(OrePrefixes.rawOre, 1)); + } + } + } + case UnifiedBlock -> { + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + for (int i = 0; i < (info2.stoneType.isRich() ? 2 : 1); i++) { + info2.stoneType = StoneType.Stone; + drops.add(getStack(info2, 1)); + } + } + } + case PerDimBlock -> { + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + if (!info2.stoneType.isDimensionSpecific()) { + info2.stoneType = StoneType.Stone; + } + + drops.add(getStack(info2, 1)); + } + } + case Block -> { + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + drops.add(getStack(info2, 1)); + } + } + } + + return drops; + } +} diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java new file mode 100644 index 00000000000..684c1367fd0 --- /dev/null +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -0,0 +1,368 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.gtnhlib.util.data.BlockMeta; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; +import com.gtnewhorizons.postea.api.ItemStackReplacementManager; +import com.gtnewhorizons.postea.api.TileEntityReplacementManager; +import com.gtnewhorizons.postea.utility.BlockInfo; + +import codechicken.nei.api.API; +import gregtech.GTMod; +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneCategory; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IStoneType; +import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.util.GTUtility; +import gregtech.api.util.GTUtility.ItemId; +import gregtech.common.GTProxy.OreDropSystem; +import gregtech.common.blocks.GTBlockOre; + +public final class GTOreAdapter implements IOreAdapter { + + public static GTOreAdapter INSTANCE = new GTOreAdapter(); + + private GTOreAdapter() {} + + private final Map oreBlocksByStoneType = new EnumMap<>(StoneType.class); + + private GTBlockOre[] ores; + + public void init() { + // spotless:off + GTBlockOre ores1 = new GTBlockOre(2, new StoneType[] { + StoneType.Stone, + StoneType.Netherrack, + StoneType.Endstone, + StoneType.BlackGranite, + StoneType.RedGranite, + StoneType.Marble, + StoneType.Basalt, + StoneType.Moon, + }); + GTBlockOre ores2 = new GTBlockOre(3, new StoneType[] { + StoneType.Mars, + StoneType.Asteroid, + StoneType.Phobos, + StoneType.Deimos, + StoneType.Ceres, + StoneType.Io, + StoneType.Europa, + StoneType.Ganymede, + }); + GTBlockOre ores3 = new GTBlockOre(4, new StoneType[] { + StoneType.Callisto, + StoneType.Enceladus, + StoneType.Titan, + StoneType.Miranda, + StoneType.Oberon, + StoneType.Proteus, + StoneType.Triton, + StoneType.Pluto, + }); + GTBlockOre ores4 = new GTBlockOre(5, new StoneType[] { + StoneType.Callisto, + StoneType.Enceladus, + StoneType.Titan, + StoneType.Miranda, + StoneType.Oberon, + StoneType.Proteus, + StoneType.Triton, + StoneType.Pluto, + }); + GTBlockOre ores5 = new GTBlockOre(6, new StoneType[] { + StoneType.Haumea, + StoneType.MakeMake, + StoneType.AlphaCentauri, + StoneType.TCetiE, + StoneType.VegaB, + StoneType.BarnardaE, + StoneType.BarnardaF, + StoneType.Horus, + }); + GTBlockOre ores6 = new GTBlockOre(7, new StoneType[] { + StoneType.AnubisAndMaahes, + StoneType.PackedIce, + StoneType.SethIce, + StoneType.SethClay, + }); + + ores = new GTBlockOre[] { ores1, ores2, ores3, ores4, ores5, ores6 }; + + StoneType[] legacyStones = { + StoneType.Stone, + StoneType.Netherrack, + StoneType.Endstone, + StoneType.BlackGranite, + StoneType.RedGranite, + StoneType.Marble, + StoneType.Basalt, + }; + // spotless:on + + TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world) -> { + int meta = tag.getInteger("m"); + boolean natural = tag.getBoolean("n"); + + try (OreInfo info = OreInfo.getNewInfo()) { + info.stoneType = GTUtility.getIndexSafe(legacyStones, (meta % 16000) / 1000); + info.material = GregTechAPI.sGeneratedMaterials[meta % 1000]; + info.isSmall = meta >= 16000; + info.isNatural = natural; + + if (!INSTANCE.supports(info)) { + return new BlockInfo(Blocks.air, 0); + } else { + ImmutableBlockMeta bm = INSTANCE.getBlock(info); + + return new BlockInfo(bm.getBlock(), bm.getBlockMeta()); + } + } + }); + + ItemStackReplacementManager.addItemReplacement("gregtech:gt.blockores", (tag) -> { + int itemId = Item.getIdFromItem(Item.getItemFromBlock(ores1)); + tag.setInteger("id", itemId); + return tag; + }); + } + + public void registerOre(StoneType stoneType, GTBlockOre oreBlock) { + oreBlocksByStoneType.put(stoneType, oreBlock); + } + + public void hideOres() { + for (GTBlockOre ore : ores) { + API.hideItem(new ItemStack(ore, 1, 0)); + } + } + + @Override + public boolean supports(Block block, int meta) { + return GTUtility.contains(ores, block); + } + + @Override + public boolean supports(OreInfo info) { + if (!(info.material instanceof Materials gtMat)) return false; + if (!OrePrefixes.ore.doGenerateItem(gtMat)) return false; + + IStoneType stoneType = info.stoneType == null ? gtMat.getValidStones() + .get(0) : info.stoneType; + + if (!(stoneType instanceof StoneType stoneType2)) return false; + if (!oreBlocksByStoneType.containsKey(stoneType2)) return false; + if (!stoneType2.isEnabled()) return false; + if (!gtMat.isValidForStone(stoneType2)) return false; + if (stoneType2.getCategory() == StoneCategory.Ice && info.isSmall) return false; + + return true; + } + + public static final int SMALL_ORE_META_OFFSET = 16000; + public static final int NATURAL_ORE_META_OFFSET = 8000; + + @Override + public OreInfo getOreInfo(Block block, int meta) { + if (!(block instanceof GTBlockOre oreBlock)) return null; + + if (meta < 0) throw new IllegalArgumentException( + "illegal metadata: " + meta + "; a tool may be casting an int to a byte, which is incompatible with NEID"); + + int matId = meta % 1000; + int stoneId = ((meta % SMALL_ORE_META_OFFSET) % NATURAL_ORE_META_OFFSET) / 1000; + boolean small = meta >= SMALL_ORE_META_OFFSET; + boolean natural = (meta % SMALL_ORE_META_OFFSET) >= NATURAL_ORE_META_OFFSET; + + Materials mat = GregTechAPI.sGeneratedMaterials[matId]; + + if (!OrePrefixes.ore.doGenerateItem(mat)) return null; + + StoneType stoneType = GTUtility.getIndexSafe(oreBlock.stoneTypes, stoneId); + if (stoneType == null || !stoneType.isEnabled()) return null; + if (stoneType.getCategory() == StoneCategory.Ice && small) return null; + + OreInfo info = OreInfo.getNewInfo(); + + info.material = mat; + info.stoneType = stoneType; + info.isSmall = small; + info.isNatural = natural; + + return info; + } + + @Override + public ImmutableBlockMeta getBlock(OreInfo info) { + if (info.stoneType == null) info.stoneType = StoneType.Stone; + + if (!(info.material instanceof Materials gtMat)) return null; + if (!OrePrefixes.ore.doGenerateItem(gtMat)) return null; + + if (!(info.stoneType instanceof StoneType stoneType)) return null; + if (!stoneType.isEnabled()) return null; + if (stoneType.getCategory() == StoneCategory.Ice && info.isSmall) return null; + + GTBlockOre oreBlock = oreBlocksByStoneType.get(stoneType); + + if (oreBlock == null) return null; + int stoneIndex = oreBlock.stoneTypes.indexOf(stoneType); + if (stoneIndex == -1) return null; + + int meta = gtMat.mMetaItemSubID; + meta += stoneIndex * 1000; + if (info.isSmall) meta += SMALL_ORE_META_OFFSET; + if (info.isNatural) meta += NATURAL_ORE_META_OFFSET; + + return new BlockMeta(oreBlock, meta); + } + + @Override + public ArrayList getOreDrops(Random random, OreInfo info2, boolean silktouch, int fortune) { + if (!supports(info2)) return new ArrayList<>(); + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + if (info.stoneType == null) info.stoneType = StoneType.Stone; + + GTBlockOre oreBlock = oreBlocksByStoneType.get(info.stoneType); + + if (oreBlock == null) return new ArrayList<>(); + + if (!info.isNatural) fortune = 0; + + if (info.isSmall) { + return getSmallOreDrops(random, info, fortune); + } else { + OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; + + if (silktouch) oreDropSystem = OreDropSystem.Block; + + return getBigOreDrops(random, oreDropSystem, info, fortune); + } + } + + @Override + public List getPotentialDrops(OreInfo info2) { + if (!supports(info2)) return new ArrayList<>(); + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + if (info.isSmall) { + ArrayList drops = new ArrayList<>(); + + for (ItemStack stack : SmallOreDrops.getDropList(info.material)) { + ItemId id = ItemId.create(stack); + + if (!drops.contains(id)) drops.add(id); + } + + ArrayList drops2 = new ArrayList<>(); + + for (ItemId id : drops) { + drops2.add(id.getItemStack()); + } + + return drops2; + } else { + return getBigOreDrops(ThreadLocalRandom.current(), GTMod.gregtechproxy.oreDropSystem, info, 0); + } + } + + private ArrayList getSmallOreDrops(Random random, OreInfo info, int fortune) { + ArrayList possibleDrops = SmallOreDrops.getDropList(info.material); + ArrayList drops = new ArrayList<>(); + + if (!possibleDrops.isEmpty()) { + int dropCount = Math.max( + 1, + info.material.mOreMultiplier + + (fortune > 0 ? random.nextInt(1 + fortune * info.material.mOreMultiplier) : 0) / 2); + + for (int i = 0; i < dropCount; i++) { + drops.add(GTUtility.copyAmount(1, possibleDrops.get(random.nextInt(possibleDrops.size())))); + } + } + + if (random.nextInt(3 + fortune) > 1) { + drops.add(info.stoneType.getDust(random.nextInt(3) == 0, 1)); + } + + return drops; + } + + private ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + int fortune) { + ArrayList drops = new ArrayList<>(); + + // For Sake of god of balance! + + switch (oreDropMode) { + case Item -> { + drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, info.material, info.stoneType.isRich() ? 2 : 1)); + } + case FortuneItem -> { + if (fortune > 0) { + // Max applicable fortune + if (fortune > 3) fortune = 3; + + int amount = 1 + Math.max(random.nextInt(fortune * (info.stoneType.isRich() ? 2 : 1) + 2) - 1, 0); + + for (int i = 0; i < amount; i++) { + drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, info.material, 1)); + } + } else { + for (int i = 0; i < (info.stoneType.isRich() ? 2 : 1); i++) { + drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, info.material, 1)); + } + } + } + case UnifiedBlock -> { + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + for (int i = 0; i < (info2.stoneType.isRich() ? 2 : 1); i++) { + info2.stoneType = StoneType.Stone; + drops.add(getStack(info2, 1)); + } + } + } + case PerDimBlock -> { + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + if (!info2.stoneType.isDimensionSpecific()) { + info2.stoneType = StoneType.Stone; + } + + drops.add(getStack(info2, 1)); + } + } + case Block -> { + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + drops.add(getStack(info2, 1)); + } + } + } + + return drops; + } +} diff --git a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java new file mode 100644 index 00000000000..385fc222f82 --- /dev/null +++ b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java @@ -0,0 +1,123 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.gtnhlib.util.data.BlockMeta; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + +import gregtech.GTMod; +import gregtech.api.enums.StoneType; +import gregtech.common.GTProxy.OreDropSystem; +import gtPlusPlus.core.block.base.BlockBaseOre; +import gtPlusPlus.core.material.Material; + +public final class GTPPOreAdapter implements IOreAdapter { + + public static GTPPOreAdapter INSTANCE = new GTPPOreAdapter(); + + private GTPPOreAdapter() {} + + @Override + public boolean supports(Block block, int meta) { + return block instanceof BlockBaseOre; + } + + @Override + public boolean supports(OreInfo info) { + if (info.stoneType != null && info.stoneType != StoneType.Stone) return false; + if (!(info.material instanceof Material)) return false; + if (info.isSmall) return false; + + return true; + } + + @Override + public OreInfo getOreInfo(Block block, int meta) { + if (!(block instanceof BlockBaseOre gtppOre)) return null; + + OreInfo info = OreInfo.getNewInfo(); + + info.stoneType = StoneType.Stone; + info.material = gtppOre.getMaterialEx(); + info.isNatural = true; + + return info; + } + + @Override + public ImmutableBlockMeta getBlock(OreInfo info) { + if (!supports(info)) return null; + + if (!(info.material instanceof Material gtppMat)) return null; + + Block ore = gtppMat.getOreBlock(1); + + if (ore == null) return null; + + return new BlockMeta(ore, 0); + } + + @Override + public ArrayList getOreDrops(Random random, OreInfo info2, boolean silktouch, int fortune) { + if (!supports(info2)) return new ArrayList<>(); + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + if (info.stoneType == null) info.stoneType = StoneType.Stone; + + OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; + + if (silktouch) oreDropSystem = OreDropSystem.Block; + + return getBigOreDrops(random, oreDropSystem, info, fortune); + } + + @Override + public List getPotentialDrops(OreInfo info2) { + if (!supports(info2)) return new ArrayList<>(); + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + return getBigOreDrops(ThreadLocalRandom.current(), GTMod.gregtechproxy.oreDropSystem, info, 0); + } + + private ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + int fortune) { + ArrayList drops = new ArrayList<>(); + + switch (oreDropMode) { + case Item -> drops.add(info.material.getRawOre(1)); + case FortuneItem -> { + // if shouldFortune and isNatural then get fortune drops + // if not shouldFortune or not isNatural then get normal drops + // if not shouldFortune and isNatural then get normal drops + // if shouldFortune and not isNatural then get normal drops + if (fortune > 0) { + int aMinAmount = 1; + // Max applicable fortune + if (fortune > 3) fortune = 3; + long amount = (long) random.nextInt(fortune) + aMinAmount; + for (int i = 0; i < amount; i++) { + drops.add(info.material.getRawOre(1)); + } + } else { + drops.add(info.material.getRawOre(1)); + } + } + // Unified ore, Per Dimension ore, Regular ore + case UnifiedBlock, PerDimBlock, Block -> { + drops.add(info.material.getOre(1)); + } + } + + return drops; + } +} diff --git a/src/main/java/gregtech/common/ores/IOreAdapter.java b/src/main/java/gregtech/common/ores/IOreAdapter.java new file mode 100644 index 00000000000..2a60482749b --- /dev/null +++ b/src/main/java/gregtech/common/ores/IOreAdapter.java @@ -0,0 +1,102 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Items; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IOreMaterial; + +public interface IOreAdapter { + + /** + * A fast check to see if this adapter can support this block/meta combination. + * This function can return false positives, but never false negatives. + */ + public boolean supports(Block block, int meta); + + /** + * Checks if this adapter can support the requested ore combination. + * If this returns true, methods that take an OreInfo in this adapter must return a valid value. + * If this returns false, methods that take an OreInfo must return an 'invalid' value (see method comments for what + * this entails). + */ + public boolean supports(OreInfo info); + + /** + * Analyzes the given block + meta and returns an OreInfo with its information, or null if the combination is + * invalid. + * Calling {@link #getBlock(OreInfo)} with the returned info must give back the same block/meta combination. + */ + public OreInfo getOreInfo(Block block, int meta); + + /** + * Analyzes the block at the given coordinates and returns an OreInfo with its information, or null if the block is + * invalid. + * Calling {@link #getBlock(OreInfo)} with the returned info must give back the same block/meta combination. + */ + public default OreInfo getOreInfo(World world, int x, int y, int z) { + return getOreInfo(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + } + + /** + * Analyzes the block stored in the stack and returns an OreInfo with its information, or null if the stack is + * invalid. + * Calling {@link #getBlock(OreInfo)} with the returned info must give back the same block/meta combination. + */ + public default OreInfo getOreInfo(ItemStack stack) { + if (!(stack.getItem() instanceof ItemBlock itemBlock)) return null; + + return getOreInfo(itemBlock.field_150939_a, Items.feather.getDamage(stack)); + } + + /** + * Gets a block that represents the given OreInfo, or null if the OreInfo is invalid. + */ + public ImmutableBlockMeta getBlock(OreInfo info); + + /** + * Gets a stack of the block for the given OreInfo, or null if the OreInfo is invalid. + * If the first operation fails, this tries again with the stoneType set to {@link StoneType#Stone}. + */ + public default ItemStack getStack(OreInfo info, int amount) { + ImmutableBlockMeta bm = getBlock(info); + + if (bm != null) { + return new ItemStack(bm.getBlock(), amount, bm.getBlockMeta()); + } + + if (info.stoneType != StoneType.Stone) { + try (OreInfo info2 = info.clone()) { + info2.stoneType = StoneType.Stone; + + bm = getBlock(info2); + + if (bm != null) { + return new ItemStack(bm.getBlock(), amount, bm.getBlockMeta()); + } + } + } + + return null; + } + + /** + * Gets the drops for a block. This returns an ArrayList due to the return type of + * {@link Block#getDrops(World, int, int, int, int, int)}. + */ + public ArrayList getOreDrops(Random rng, OreInfo info, boolean silktouch, int fortune); + + /** + * Gets the potential drops for a block. Used for the NEI addon. + */ + public List getPotentialDrops(OreInfo info); +} diff --git a/src/main/java/gregtech/common/ores/OreInfo.java b/src/main/java/gregtech/common/ores/OreInfo.java new file mode 100644 index 00000000000..0f6b5399409 --- /dev/null +++ b/src/main/java/gregtech/common/ores/OreInfo.java @@ -0,0 +1,131 @@ +package gregtech.common.ores; + +import com.gtnewhorizon.gtnhlib.util.ObjectPooler; + +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneType; + +/** + * This class represents an ore block. Not all combinations are valid, it depends on what the ore adapters support. + * + *

+ * + * This class comes with a built-in pooling mechanism since these objects are used in several hot-paths. + * Any time the {@link OreManager} returns an {@link OreInfo}, it should be enclosed in a try-with-resources to release + * the object back to the pool automatically. If a try-with-resources clutters the code significantly, you can call + * {@link OreInfo#release()} manually. You should call {@link OreInfo#release()} unless you have a good reason not to + * (like making thousands of objects at a time, which would cause a memory leak). + * + *

+ * + * If you don't know for certain what kind of ore you're dealing with, everything should be done through the + * {@link OreManager} where possible, and the ore adapter should be retrieved via + * {@link OreManager#getAdapter(OreInfo)}. It's fine to refer to a concrete ore adapter if you know the ore type for + * certain. + * + *

+ * {@code
+ *  void foo(Block block, int meta) {
+ *   try (OreInfo info = OreManager.getOreInfo(block, meta)) {
+ *     // do something with info
+ *   }
+ * }
+ * 
+ */ +public class OreInfo implements AutoCloseable { + + /** + * The cached adapter that produced this info. May not be valid, so use {@link OreManager#getAdapter(OreInfo)} + * instead. + */ + IOreAdapter cachedAdapter; + + public TMat material; + public IStoneType stoneType; + public boolean isSmall; + /** Natural ores can be mined by machines and can be fortuned. Ores placed by the player aren't natural. */ + public boolean isNatural; + + static final ObjectPooler> ORE_INFO_POOL = new ObjectPooler<>(OreInfo::new); + + @SuppressWarnings("unchecked") + public static OreInfo getNewInfo() { + synchronized (ORE_INFO_POOL) { + return (OreInfo) ORE_INFO_POOL.getInstance(); + } + } + + public static void releaseInfo(OreInfo info) { + synchronized (ORE_INFO_POOL) { + ORE_INFO_POOL.releaseInstance(info.reset()); + } + } + + @Override + public void close() { + release(); + } + + public void release() { + releaseInfo(this); + } + + public OreInfo reset() { + cachedAdapter = null; + material = null; + stoneType = null; + isSmall = false; + isNatural = false; + return this; + } + + public OreInfo clone() { + OreInfo dup = getNewInfo(); + dup.cachedAdapter = this.cachedAdapter; + dup.material = this.material; + dup.stoneType = this.stoneType; + dup.isSmall = this.isSmall; + dup.isNatural = this.isNatural; + return dup; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((material == null) ? 0 : material.hashCode()); + result = prime * result + ((stoneType == null) ? 0 : stoneType.hashCode()); + result = prime * result + (isSmall ? 1231 : 1237); + result = prime * result + (isNatural ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + OreInfo other = (OreInfo) obj; + if (material == null) { + if (other.material != null) return false; + } else if (!material.equals(other.material)) return false; + if (stoneType == null) { + if (other.stoneType != null) return false; + } else if (!stoneType.equals(other.stoneType)) return false; + if (isSmall != other.isSmall) return false; + if (isNatural != other.isNatural) return false; + return true; + } + + @Override + public String toString() { + return "OreInfo [material=" + material + + ", stoneType=" + + stoneType + + ", isSmall=" + + isSmall + + ", isNatural=" + + isNatural + + "]"; + } +} diff --git a/src/main/java/gregtech/common/ores/OreManager.java b/src/main/java/gregtech/common/ores/OreManager.java new file mode 100644 index 00000000000..3ffdf6c9b11 --- /dev/null +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -0,0 +1,251 @@ +package gregtech.common.ores; + +import java.util.List; +import java.util.Random; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import com.google.common.collect.ImmutableList; +import com.gtnewhorizon.gtnhlib.util.data.BlockMeta; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneType; + +public final class OreManager { + + private OreManager() {} + + private static final List> ORE_ADAPTERS = ImmutableList + .of(GTOreAdapter.INSTANCE, GTPPOreAdapter.INSTANCE, BWOreAdapter.INSTANCE); + + public static boolean isOre(Block block, int meta) { + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + + try (OreInfo info = oreAdapter.getOreInfo(block, meta)) { + if (info != null && info.isNatural) return true; + } + } + + return false; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static OreInfo getOreInfo(Block block, int meta) { + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + + OreInfo info = oreAdapter.getOreInfo(block, meta); + if (info != null) { + info.cachedAdapter = oreAdapter; + return info; + } + } + + return null; + } + + public static OreInfo getOreInfo(ItemStack stack) { + if (!(stack.getItem() instanceof ItemBlock itemBlock)) return null; + + return getOreInfo(itemBlock.field_150939_a, Items.feather.getDamage(stack)); + } + + public static IOreAdapter getAdapter(OreInfo info) { + if (info.cachedAdapter != null && info.cachedAdapter.supports(info)) return info.cachedAdapter; + + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + + if (oreAdapter.supports(info)) return oreAdapter; + } + + return null; + } + + public static boolean setOreForWorldGen(World world, int x, int y, int z, IStoneType defaultStone, + IOreMaterial material, boolean small) { + if (y < 0 || y >= world.getActualHeight()) return false; + + IStoneType existingStone = StoneType.findStoneType(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + + if (existingStone != null && !existingStone.canGenerateInWorld(world)) return false; + + if (existingStone == null) { + if (defaultStone != null) { + existingStone = defaultStone; + } else { + return false; + } + } + + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = material; + info.stoneType = existingStone; + info.isSmall = small; + info.isNatural = true; + + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + + ImmutableBlockMeta oreBlock = oreAdapter.getBlock(info); + + if (oreBlock != null) { + world.setBlock(x, y, z, oreBlock.getBlock(), oreBlock.getBlockMeta(), 3); + + return true; + } + } + + return false; + } + } + + public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneType stoneType, + IOreMaterial material, boolean small) { + if (y < 0 || y >= world.getActualHeight()) return false; + + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = material; + info.stoneType = stoneType; + info.isSmall = small; + info.isNatural = true; + + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + + ImmutableBlockMeta oreBlock = oreAdapter.getBlock(info); + + if (oreBlock != null) { + world.setBlock(x, y, z, oreBlock.getBlock(), oreBlock.getBlockMeta(), 2); + + return true; + } + } + + return false; + } + } + + public static boolean setExistingOreStoneType(World world, int x, int y, int z, IStoneType newStoneType) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + try (OreInfo info = getOreInfo(block, meta)) { + if (info == null) return false; + + info.stoneType = newStoneType; + + ImmutableBlockMeta oreBlock = getAdapter(info).getBlock(info); + + if (oreBlock == null) return false; + + world.setBlock(x, y, z, oreBlock.getBlock(), oreBlock.getBlockMeta(), 2); + + return true; + } + } + + public static List mineBlock(Random random, World world, int x, int y, int z, boolean silktouch, + int fortune, boolean simulate, boolean replaceWithCobblestone) { + Block ore = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + List oreBlockDrops; + ImmutableBlockMeta replacement; + + try (OreInfo info = getOreInfo(ore, meta)) { + if (info != null) { + oreBlockDrops = info.cachedAdapter.getOreDrops(random, info, silktouch, fortune); + + replacement = info.stoneType.getCobblestone(); + } else { + if (silktouch && ore.canSilkHarvest(world, null, x, y, z, meta)) { + oreBlockDrops = ImmutableList.of(new ItemStack(ore, 1, meta)); + } else { + // Regular ore + oreBlockDrops = ImmutableList.copyOf(ore.getDrops(world, x, y, z, meta, fortune)); + } + + replacement = new BlockMeta(Blocks.cobblestone, 0); + } + } + + if (!simulate) { + if (replaceWithCobblestone) { + world.setBlock(x, y, z, replacement.getBlock(), replacement.getBlockMeta(), 3); + } else { + world.setBlockToAir(x, y, z); + } + } + + return oreBlockDrops; + } + + public static IOreMaterial getMaterial(ItemStack stack) { + if (!(stack.getItem() instanceof ItemBlock itemBlock)) return null; + + return getMaterial(itemBlock.field_150939_a, Items.feather.getDamage(stack)); + } + + public static IOreMaterial getMaterial(Block block, int meta) { + try (OreInfo info = getOreInfo(block, meta)) { + return info == null ? null : info.material; + } + } + + public static ItemStack getStack(OreInfo info, int amount) { + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + + ItemStack stack = oreAdapter.getStack(info, amount); + + if (stack != null) return stack; + } + + return null; + } + + public static String getLocalizedName(OreInfo info) { + ItemStack stack = getStack(info, 1); + + if (stack == null) return ""; + + return stack.getDisplayName(); + } + + public static List getPotentialDrops(OreInfo info) { + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + + if (oreAdapter.supports(info)) { + return oreAdapter.getPotentialDrops(info); + } + } + + return null; + } +} diff --git a/src/main/java/gregtech/common/ores/SmallOreDrops.java b/src/main/java/gregtech/common/ores/SmallOreDrops.java new file mode 100644 index 00000000000..64918af0a12 --- /dev/null +++ b/src/main/java/gregtech/common/ores/SmallOreDrops.java @@ -0,0 +1,52 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; + +import com.google.common.collect.ImmutableList; + +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GTOreDictUnificator; + +public enum SmallOreDrops { + + gemExquisite(OrePrefixes.gemExquisite, OrePrefixes.gem, 1), + gemFlawless(OrePrefixes.gemFlawless, OrePrefixes.gem, 2), + gem(OrePrefixes.gem, null, 12), + gemFlawed(OrePrefixes.gemFlawed, OrePrefixes.crushed, 5), + crushed(OrePrefixes.crushed, null, 10), + gemChipped(OrePrefixes.gemChipped, OrePrefixes.dustImpure, 5), + dustImpure(OrePrefixes.dustImpure, null, 10); + + public static final List DROPS = ImmutableList.copyOf(values()); + + private final OrePrefixes primary; + private final OrePrefixes fallback; + private final int weight; + + private SmallOreDrops(OrePrefixes primary, OrePrefixes fallback, int weight) { + this.primary = primary; + this.fallback = fallback; + this.weight = weight; + } + + public static ArrayList getDropList(Materials material) { + ArrayList drops = new ArrayList<>(); + + for (SmallOreDrops drop : DROPS) { + ItemStack fallback = drop.fallback == null ? null : GTOreDictUnificator.get(drop.fallback, material, 1L); + ItemStack primary = GTOreDictUnificator.get(drop.primary, material, fallback, 1L); + + if (primary != null) { + for (int i = 0; i < drop.weight; i++) { + drops.add(primary); + } + } + } + + return drops; + } +} diff --git a/src/main/java/gregtech/common/render/GTRendererBlock.java b/src/main/java/gregtech/common/render/GTRendererBlock.java index b4caab35b89..febe89b873f 100644 --- a/src/main/java/gregtech/common/render/GTRendererBlock.java +++ b/src/main/java/gregtech/common/render/GTRendererBlock.java @@ -44,6 +44,7 @@ import cpw.mods.fml.relauncher.SideOnly; import gregtech.GTMod; import gregtech.api.GregTechAPI; +import gregtech.api.interfaces.IBlockWithTextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IAllSidedTexturedTileEntity; @@ -52,10 +53,9 @@ import gregtech.api.interfaces.tileentity.ITexturedTileEntity; import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.objects.XSTR; +import gregtech.api.util.GTUtility; import gregtech.common.blocks.BlockFrameBox; import gregtech.common.blocks.BlockMachines; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; @ThreadSafeISBRH(perThread = true) public class GTRendererBlock implements ISimpleBlockRenderingHandler { @@ -543,7 +543,11 @@ public static void addDestroyEffects(EffectRenderer effectRenderer, Block block, } } - final TileEntityOres tTileEntity = new TileEntityOres(); + private IMetaTileEntity getMTE(Block block, int meta) { + if (!(block instanceof BlockMachines)) return null; + + return GTUtility.getIndexSafe(GregTechAPI.METATILEENTITIES, meta); + } @Override public void renderInventoryBlock(Block aBlock, int aMeta, int aModelID, RenderBlocks aRenderer) { @@ -552,38 +556,23 @@ public void renderInventoryBlock(Block aBlock, int aMeta, int aModelID, RenderBl GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - if (aBlock instanceof BlockOresAbstract) { - tTileEntity.mMetaData = ((short) aMeta); - aBlock.setBlockBoundsForItemRender(); - aRenderer.setRenderBoundsFromBlock(aBlock); - // spotless:off - ITexture[] texture = tTileEntity.getTexture(aBlock); - renderNegativeYFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - // spotless:on - } else if (aMeta > 0 && (aMeta < GregTechAPI.METATILEENTITIES.length) - && aBlock instanceof BlockMachines - && (GregTechAPI.METATILEENTITIES[aMeta] != null) - && (!GregTechAPI.METATILEENTITIES[aMeta].renderInInventory(aBlock, aMeta, aRenderer))) { - renderNormalInventoryMetaTileEntity(aBlock, aMeta, aRenderer); - } else if (aBlock instanceof BlockFrameBox) { - ITexture[] texture = ((BlockFrameBox) aBlock).getTexture(aMeta); + IMetaTileEntity imte = getMTE(aBlock, aMeta); + if (imte != null && !imte.renderInInventory(aBlock, aMeta, aRenderer)) { + renderNormalInventoryMetaTileEntity(aBlock, aMeta, imte, aRenderer); + } else if (aBlock instanceof IBlockWithTextures texturedBlock) { + ITexture[][] texture = texturedBlock.getTextures(aMeta); + if (texture != null) { aBlock.setBlockBoundsForItemRender(); aRenderer.setRenderBoundsFromBlock(aBlock); - // spotless:off - renderNegativeYFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, texture, true); - // spotless:on + renderNegativeYFacing(null, aRenderer, aBlock, 0, 0, 0, texture[ForgeDirection.DOWN.ordinal()], true); + renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, texture[ForgeDirection.UP.ordinal()], true); + renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, texture[ForgeDirection.NORTH.ordinal()], true); + renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, texture[ForgeDirection.SOUTH.ordinal()], true); + renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, texture[ForgeDirection.WEST.ordinal()], true); + renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, texture[ForgeDirection.EAST.ordinal()], true); } + } aBlock.setBlockBounds(blockMin, blockMin, blockMin, blockMax, blockMax, blockMax); aRenderer.setRenderBoundsFromBlock(aBlock); @@ -592,41 +581,34 @@ public void renderInventoryBlock(Block aBlock, int aMeta, int aModelID, RenderBl aRenderer.useInventoryTint = false; } - private static void renderNormalInventoryMetaTileEntity(Block aBlock, int aMeta, RenderBlocks aRenderer) { - if ((aMeta <= 0) || (aMeta >= GregTechAPI.METATILEENTITIES.length)) { - return; - } - final IMetaTileEntity tMetaTileEntity = GregTechAPI.METATILEENTITIES[aMeta]; - if (tMetaTileEntity == null) { - return; - } + private static void renderNormalInventoryMetaTileEntity(Block aBlock, int aMeta, IMetaTileEntity imte, + RenderBlocks aRenderer) { aBlock.setBlockBoundsForItemRender(); aRenderer.setRenderBoundsFromBlock(aBlock); - final IGregTechTileEntity iGregTechTileEntity = tMetaTileEntity.getBaseMetaTileEntity(); + final IGregTechTileEntity igte = imte.getBaseMetaTileEntity(); // spotless:off - if ((iGregTechTileEntity instanceof IPipeRenderedTileEntity renderedPipe) - && (tMetaTileEntity instanceof MetaPipeEntity pipeEntity)) { + if (igte instanceof IPipeRenderedTileEntity renderedPipe && imte instanceof MetaPipeEntity pipeEntity) { final float tThickness = renderedPipe.getThickNess(); final float pipeMin = (blockMax - tThickness) / 2.0F; final float pipeMax = blockMax - pipeMin; aBlock.setBlockBounds(blockMin, pipeMin, pipeMin, blockMax, pipeMax, pipeMax); aRenderer.setRenderBoundsFromBlock(aBlock); - renderNegativeYFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(iGregTechTileEntity, DOWN, (CONNECTED_WEST | CONNECTED_EAST), -1, false, false), true); - renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(iGregTechTileEntity, UP, (CONNECTED_WEST | CONNECTED_EAST), -1, false, false), true); - renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(iGregTechTileEntity, NORTH, (CONNECTED_WEST | CONNECTED_EAST), -1, false, false), true); - renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(iGregTechTileEntity, SOUTH, (CONNECTED_WEST | CONNECTED_EAST), -1, false, false), true); - renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(iGregTechTileEntity, WEST, (CONNECTED_WEST | CONNECTED_EAST), -1, true, false), true); - renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(iGregTechTileEntity, EAST, (CONNECTED_WEST | CONNECTED_EAST), -1, true, false), true); + renderNegativeYFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(igte, DOWN, (CONNECTED_WEST | CONNECTED_EAST), -1, false, false), true); + renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(igte, UP, (CONNECTED_WEST | CONNECTED_EAST), -1, false, false), true); + renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(igte, NORTH, (CONNECTED_WEST | CONNECTED_EAST), -1, false, false), true); + renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(igte, SOUTH, (CONNECTED_WEST | CONNECTED_EAST), -1, false, false), true); + renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(igte, WEST, (CONNECTED_WEST | CONNECTED_EAST), -1, true, false), true); + renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, pipeEntity.getTexture(igte, EAST, (CONNECTED_WEST | CONNECTED_EAST), -1, true, false), true); } else { - renderNegativeYFacing(null, aRenderer, aBlock, 0, 0, 0, tMetaTileEntity.getTexture(iGregTechTileEntity, DOWN, WEST, -1, true, false), true); - renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, tMetaTileEntity.getTexture(iGregTechTileEntity, UP, WEST, -1, true, false), true); - renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, tMetaTileEntity.getTexture(iGregTechTileEntity, NORTH, WEST, -1, true, false), true); - renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, tMetaTileEntity.getTexture(iGregTechTileEntity, SOUTH, WEST, -1, true, false), true); - renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, tMetaTileEntity.getTexture(iGregTechTileEntity, WEST, WEST, -1, true, false), true); - renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, tMetaTileEntity.getTexture(iGregTechTileEntity, EAST, WEST, -1, true, false), true); + renderNegativeYFacing(null, aRenderer, aBlock, 0, 0, 0, imte.getTexture(igte, DOWN, WEST, -1, true, false), true); + renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, imte.getTexture(igte, UP, WEST, -1, true, false), true); + renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, imte.getTexture(igte, NORTH, WEST, -1, true, false), true); + renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, imte.getTexture(igte, SOUTH, WEST, -1, true, false), true); + renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, imte.getTexture(igte, WEST, WEST, -1, true, false), true); + renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, imte.getTexture(igte, EAST, WEST, -1, true, false), true); } // spotless:on } @@ -733,15 +715,17 @@ public boolean renderWorldBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Blo // Otherwise, render the TE instead. if (tileEntity == null && aBlock instanceof BlockFrameBox frameBlock) { int meta = aWorld.getBlockMetadata(aX, aY, aZ); - ITexture[] texture = frameBlock.getTexture(meta); + ITexture[][] texture = frameBlock.getTextures(meta); if (texture == null) return false; - textureArray[0] = texture; - textureArray[1] = texture; - textureArray[2] = texture; - textureArray[3] = texture; - textureArray[4] = texture; - textureArray[5] = texture; - renderStandardBlock(aWorld, aX, aY, aZ, aBlock, aRenderer, textureArray); + renderStandardBlock(aWorld, aX, aY, aZ, aBlock, aRenderer, texture); + return true; + } + + if (aBlock instanceof IBlockWithTextures texturedBlock) { + int meta = aWorld.getBlockMetadata(aX, aY, aZ); + ITexture[][] texture = texturedBlock.getTextures(meta); + if (texture == null) return false; + renderStandardBlock(aWorld, aX, aY, aZ, aBlock, aRenderer, texture); return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/MTEAdvSeismicProspector.java b/src/main/java/gregtech/common/tileentities/machines/basic/MTEAdvSeismicProspector.java index fc4aefcf144..fc0d91e4f6e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/MTEAdvSeismicProspector.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/MTEAdvSeismicProspector.java @@ -28,12 +28,10 @@ import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.fluids.FluidStack; -import gregtech.api.GregTechAPI; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.interfaces.ITexture; @@ -44,8 +42,7 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; import ic2.core.Ic2Items; public class MTEAdvSeismicProspector extends MTEBasicMachine { @@ -273,21 +270,12 @@ private void prospectHole(int i, int k, Map aOres) { private String checkForOre(int x, int y, int z) { Block tBlock = this.getBaseMetaTileEntity() .getBlock(x, y, z); + int tMetaID = getBaseMetaTileEntity().getWorld() + .getBlockMetadata(x, y, z); - if (tBlock instanceof BlockOresAbstract) { - TileEntity tTileEntity = getBaseMetaTileEntity().getWorld() - .getTileEntity(x, y, z); - - if ((tTileEntity instanceof TileEntityOres) && (((TileEntityOres) tTileEntity).mMetaData < 16000)) { // Filtering - // small - // ores - Materials tMaterial = GregTechAPI.sGeneratedMaterials[((TileEntityOres) tTileEntity).mMetaData % 1000]; - - if ((tMaterial != null) && (tMaterial != Materials._NULL)) return tMaterial.mDefaultLocalName; - } + if (OreManager.getMaterial(tBlock, tMetaID) instanceof Materials gtMat) { + return gtMat.mDefaultLocalName; } else { - int tMetaID = getBaseMetaTileEntity().getWorld() - .getBlockMetadata(x, y, z); ItemStack is = new ItemStack(tBlock, 1, tMetaID); ItemData association = GTOreDictUnificator.getAssociation(is); if ((association != null) && (association.mPrefix.toString() diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/MTEMiner.java b/src/main/java/gregtech/common/tileentities/machines/basic/MTEMiner.java index d799955c19b..64f9107f777 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/MTEMiner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/MTEMiner.java @@ -10,7 +10,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraft.world.ChunkPosition; @@ -29,8 +28,6 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; import gregtech.common.misc.DrillingLogicDelegate; import gregtech.common.misc.IDrillingLogicDelegateOwner; @@ -276,13 +273,7 @@ private void fillOreList(IGregTechTileEntity aBaseMetaTileEntity) { Block block = aBaseMetaTileEntity.getBlockOffset(x, pipe.getTipDepth(), z); int blockMeta = aBaseMetaTileEntity.getMetaIDOffset(x, pipe.getTipDepth(), z); - // todo some weird checks. refactorings needed - if (block instanceof BlockOresAbstract) { - TileEntity oreEntity = aBaseMetaTileEntity.getTileEntityOffset(x, pipe.getTipDepth(), z); - if (oreEntity instanceof TileEntityOres && ((TileEntityOres) oreEntity).mNatural) { - oreBlockPositions.add(new ChunkPosition(x, pipe.getTipDepth(), z)); - } - } else if (GTUtility.isOre(block, blockMeta)) { + if (GTUtility.isOre(block, blockMeta)) { oreBlockPositions.add(new ChunkPosition(x, pipe.getTipDepth(), z)); } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java index 15caeb1a2e7..35c63c84b09 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java @@ -9,10 +9,8 @@ import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -22,13 +20,14 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraft.world.ChunkCoordIntPair; -import net.minecraft.world.ChunkPosition; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; import com.google.common.collect.ImmutableList; +import com.gtnewhorizon.gtnhlib.util.CoordinatePacker; import com.gtnewhorizons.modularui.api.NumberFormatMUI; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.math.Alignment; @@ -44,6 +43,7 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SoundResource; +import gregtech.api.enums.SubTag; import gregtech.api.gui.modularui.GTUITextures; import gregtech.api.gui.widgets.LockedWhileActiveButton; import gregtech.api.interfaces.IHatchElement; @@ -55,14 +55,18 @@ import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; +import gregtech.api.util.GTUtility.ItemId; +import gregtech.api.util.LRUCache; import gregtech.api.util.MultiblockTooltipBuilder; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; import gregtech.crossmod.visualprospecting.VisualProspectingDatabase; +import it.unimi.dsi.fastutil.longs.LongArrayList; +import it.unimi.dsi.fastutil.longs.LongIterator; +import it.unimi.dsi.fastutil.longs.LongList; public abstract class MTEOreDrillingPlantBase extends MTEDrillerBase implements IMetricsExporter { - private final List oreBlockPositions = new ArrayList<>(); + private final LongList oreBlockPositions = new LongArrayList(); protected int mTier = 1; private int chunkRadiusConfig = getRadiusInChunks(); private boolean replaceWithCobblestone = true; @@ -222,63 +226,64 @@ private boolean tryProcessOreList() { } private boolean processOreList(boolean simulate) { - ChunkPosition oreBlockPos = null; - List oreBlockPositions = simulate ? copyOreBlockPositions(this.oreBlockPositions) - : this.oreBlockPositions; - int x = 0, y = 0, z = 0; - Block oreBlock = null; - int oreBlockMetadata = 0; - - while ((oreBlock == null || !GTUtility.isOre(oreBlock, oreBlockMetadata)) && !oreBlockPositions.isEmpty()) { - oreBlockPos = oreBlockPositions.remove(0); - x = oreBlockPos.chunkPosX; - y = oreBlockPos.chunkPosY; - z = oreBlockPos.chunkPosZ; - if (GTUtility.eraseBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), x, y, z, true)) - oreBlock = getBaseMetaTileEntity().getBlock(x, y, z); - oreBlockMetadata = getBaseMetaTileEntity().getWorld() - .getBlockMetadata(x, y, z); - } + World world = getBaseMetaTileEntity().getWorld(); - if (!tryConsumeDrillingFluid(simulate)) { - oreBlockPositions.add(0, oreBlockPos); - setRuntimeFailureReason(CheckRecipeResultRegistry.NO_DRILLING_FLUID); - return false; - } - if (oreBlock != null && GTUtility.isOre(oreBlock, oreBlockMetadata)) { - short metaData = 0; - TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntity(x, y, z); - if (tTileEntity instanceof TileEntityOres) { - metaData = ((TileEntityOres) tTileEntity).mMetaData; + LongIterator iter = oreBlockPositions.iterator(); + + while (iter.hasNext()) { + long pos = iter.nextLong(); + + int x = CoordinatePacker.unpackX(pos); + int y = CoordinatePacker.unpackY(pos); + int z = CoordinatePacker.unpackZ(pos); + + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + if (!GTUtility.isOre(block, meta)) { + // always remove non-ore blocks, even if we're simulating + iter.remove(); + continue; } - Collection oreBlockDrops = getBlockDrops(oreBlock, x, y, z); - ItemStack cobble = GTUtility.getCobbleForOre(oreBlock, metaData); - if (!simulate) { - if (replaceWithCobblestone) { - getBaseMetaTileEntity().getWorld() - .setBlock(x, y, z, Block.getBlockFromItem(cobble.getItem()), cobble.getItemDamage(), 3); - } else { - getBaseMetaTileEntity().getWorld() - .setBlockToAir(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); - } + if (!world.canMineBlock(getFakePlayer(getBaseMetaTileEntity()), x, y, z)) { + // always remove protected blocks - if the fake player can't remove it now, they won't be able to remove + // it later + iter.remove(); + continue; + } + + if (!tryConsumeDrillingFluid(simulate)) { + setRuntimeFailureReason(CheckRecipeResultRegistry.NO_DRILLING_FLUID); + return false; } + + List oreBlockDrops = OreManager.mineBlock( + ThreadLocalRandom.current(), + world, + x, + y, + z, + true, + mTier + 3, + simulate, + replaceWithCobblestone); + ItemStack[] toOutput = getOutputByDrops(oreBlockDrops); + if (simulate && !canOutputAll(toOutput)) { setRuntimeFailureReason(CheckRecipeResultRegistry.ITEM_OUTPUT_FULL); return false; } + + if (!simulate) iter.remove(); + mOutputItems = toOutput; - } - return true; - } - private static List copyOreBlockPositions(List oreBlockPositions) { - List ret = new ArrayList<>(); - for (ChunkPosition chunkPosition : oreBlockPositions) { - ret.add(new ChunkPosition(chunkPosition.chunkPosX, chunkPosition.chunkPosY, chunkPosition.chunkPosZ)); + return true; } - return ret; + + return false; } @Override @@ -494,29 +499,41 @@ public int calculateMaxProgressTime(int tier, boolean simulateWorking) { : 80) / Math.pow(2, tier)); } - private ItemStack[] getOutputByDrops(Collection oreBlockDrops) { + private LRUCache maceratorRecipes = new LRUCache<>(64, this::findRecipe); + + private GTRecipe findRecipe(ItemId id) { long voltage = getMaxInputVoltage(); - Collection outputItems = new HashSet<>(); - oreBlockDrops.forEach(currentItem -> { + + return RecipeMaps.maceratorRecipes.findRecipeQuery() + .items(id.getItemStack()) + .voltage(voltage) + .find(); + } + + private ItemStack[] getOutputByDrops(List oreBlockDrops) { + List outputItems = new ArrayList<>(); + + for (ItemStack currentItem : oreBlockDrops) { if (!doUseMaceratorRecipe(currentItem)) { outputItems.add(multiplyStackSize(currentItem)); - return; + continue; } - GTRecipe tRecipe = RecipeMaps.maceratorRecipes.findRecipeQuery() - .items(currentItem) - .voltage(voltage) - .find(); + + GTRecipe tRecipe = maceratorRecipes.get(ItemId.create(currentItem)); + if (tRecipe == null) { outputItems.add(currentItem); - return; + continue; } + for (int i = 0; i < tRecipe.mOutputs.length; i++) { ItemStack recipeOutput = tRecipe.mOutputs[i].copy(); if (getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(i)) multiplyStackSize(recipeOutput); outputItems.add(recipeOutput); } - }); + } + return outputItems.toArray(new ItemStack[0]); } @@ -529,7 +546,8 @@ private boolean doUseMaceratorRecipe(ItemStack currentItem) { && itemData.mPrefix != OrePrefixes.gemExquisite && itemData.mPrefix != OrePrefixes.gemFlawed && itemData.mPrefix != OrePrefixes.gemFlawless - && itemData.mMaterial.mMaterial != Materials.Oilsands; + && itemData.mMaterial.mMaterial != Materials.Oilsands + && !itemData.mMaterial.mMaterial.contains(SubTag.ICE_ORE); } private ItemStack multiplyStackSize(ItemStack itemStack) { @@ -537,27 +555,6 @@ private ItemStack multiplyStackSize(ItemStack itemStack) { return itemStack; } - private Collection getBlockDrops(final Block oreBlock, int posX, int posY, int posZ) { - final int blockMeta = getBaseMetaTileEntity().getMetaID(posX, posY, posZ); - if (oreBlock.canSilkHarvest(getBaseMetaTileEntity().getWorld(), null, posX, posY, posZ, blockMeta)) { - return Collections.singleton(new ItemStack(oreBlock, 1, blockMeta)); - } - if (oreBlock instanceof BlockOresAbstract) { - TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntity(posX, posY, posZ); - if (tTileEntity instanceof TileEntityOres tTileEntityOres) { - if (tTileEntityOres.mMetaData >= 16000) { - // Small ore - return oreBlock - .getDrops(getBaseMetaTileEntity().getWorld(), posX, posY, posZ, blockMeta, mTier + 3); - } else { - return tTileEntityOres.getSilkTouchDrops(oreBlock); - } - } - } - // Regular ore - return oreBlock.getDrops(getBaseMetaTileEntity().getWorld(), posX, posY, posZ, blockMeta, 0); - } - private boolean tryConsumeDrillingFluid(boolean simulate) { return depleteInput(new FluidStack(ItemList.sDrillingFluid, 2000), simulate); } @@ -593,13 +590,11 @@ private void fillMineListIfEmpty(int xDrill, int yDrill, int zDrill, int xPipe, private void tryAddOreBlockToMineList(int x, int y, int z) { Block block = getBaseMetaTileEntity().getBlock(x, y, z); int blockMeta = getBaseMetaTileEntity().getMetaID(x, y, z); - ChunkPosition blockPos = new ChunkPosition(x, y, z); - if (!oreBlockPositions.contains(blockPos)) { - if (block instanceof BlockOresAbstract) { - TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntity(x, y, z); - if (tTileEntity instanceof TileEntityOres && ((TileEntityOres) tTileEntity).mNatural) - oreBlockPositions.add(blockPos); - } else if (GTUtility.isOre(block, blockMeta)) oreBlockPositions.add(blockPos); + + long pos = CoordinatePacker.pack(x, y, z); + + if (!oreBlockPositions.contains(pos)) { + if (GTUtility.isOre(block, blockMeta)) oreBlockPositions.add(pos); } } diff --git a/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java b/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java new file mode 100644 index 00000000000..8a8efec4d92 --- /dev/null +++ b/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java @@ -0,0 +1,43 @@ +package gregtech.common.worldgen; + +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneCategory; + +/** A worldgen layer that generates ore. */ +public interface IWorldgenLayer { + + int getMinY(); + + int getMaxY(); + + /** Gets the RNG weight. */ + int getWeight(); + + /** Gets the density. 1 = 100%, 0.5 = 50%, 0 = 0% */ + float getDensity(); + + /** Checks if this layer can generate in the given dimension. */ + boolean canGenerateIn(String dimName); + + /** Checks if this layer can generate in the given stone category. */ + boolean canGenerateIn(IStoneCategory stoneType); + + /** Whether this layer can only generate in specific stone types. */ + boolean isStoneSpecific(); + + /** If this layer generates big ore. Ignores small ore. */ + boolean generatesBigOre(); + + /** Checks if this layer contains this material */ + boolean contains(IOreMaterial ore); + + /** + * Selects an ore for worldgen. + * + * @param k The weight, 0-1. + * @return The ore. + */ + IOreMaterial getOre(float k); + + String getName(); +} diff --git a/src/main/java/gregtech/common/worldgen/VeinGenerateEvent.java b/src/main/java/gregtech/common/worldgen/VeinGenerateEvent.java new file mode 100644 index 00000000000..41bfa9aea13 --- /dev/null +++ b/src/main/java/gregtech/common/worldgen/VeinGenerateEvent.java @@ -0,0 +1,38 @@ +package gregtech.common.worldgen; + +import net.minecraft.world.World; + +import cpw.mods.fml.common.eventhandler.Event; +import gregtech.common.WorldgenGTOreLayer; + +public class VeinGenerateEvent extends Event { + + public final World world; + public final int chunkX, chunkZ, oreSeedX, oreSeedZ; + public final WorldgenGTOreLayer layer; + + private int result = -1; + + public VeinGenerateEvent(World world, int chunkX, int chunkZ, int oreSeedX, int oreSeedZ, + WorldgenGTOreLayer layer) { + this.world = world; + this.chunkX = chunkX; + this.chunkZ = chunkZ; + this.oreSeedX = oreSeedX; + this.oreSeedZ = oreSeedZ; + this.layer = layer; + } + + @Override + public boolean isCancelable() { + return true; + } + + public void setOreGenResult(int result) { + this.result = result; + } + + public int getOreGenResult() { + return result; + } +} diff --git a/src/main/java/gregtech/common/worldgen/WorldgenQuery.java b/src/main/java/gregtech/common/worldgen/WorldgenQuery.java new file mode 100644 index 00000000000..aa8bbcbc056 --- /dev/null +++ b/src/main/java/gregtech/common/worldgen/WorldgenQuery.java @@ -0,0 +1,191 @@ +package gregtech.common.worldgen; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import javax.annotation.Nullable; + +import net.minecraft.world.World; + +import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.enums.DimensionDef; +import gregtech.api.enums.StoneCategory; +import gregtech.api.interfaces.IStoneCategory; +import gregtech.common.WorldgenGTOreLayer; +import gregtech.common.WorldgenGTOreSmallPieces; + +public class WorldgenQuery { + + public List list; + public int minY = -1, maxY = -1; + public boolean checkWeight = true; + public Set dimensions; + public Set stoneCategories = new HashSet<>(Arrays.asList(StoneCategory.Stone)); + public boolean defaultStoneCategories = true; + + public WorldgenQuery(List list) { + this.list = list; + } + + public static WorldgenQuery veins() { + return new WorldgenQuery<>(WorldgenGTOreLayer.sList); + } + + public static WorldgenQuery small() { + return new WorldgenQuery<>(WorldgenGTOreSmallPieces.sList); + } + + public WorldgenQuery withMinY(int minY) { + this.minY = minY; + return this; + } + + public WorldgenQuery withMaxY(int maxY) { + this.maxY = maxY; + return this; + } + + public WorldgenQuery withoutWeight() { + this.checkWeight = false; + return this; + } + + public WorldgenQuery inDimension(String dimName) { + if (dimensions == null) dimensions = new HashSet<>(); + + dimensions.add(dimName); + + return this; + } + + public WorldgenQuery inDimension(World world) { + if (dimensions == null) dimensions = new HashSet<>(); + + dimensions.add(world.provider.getDimensionName()); + + return this; + } + + public WorldgenQuery inDimension(ModDimensionDef def) { + if (dimensions == null) dimensions = new HashSet<>(); + + dimensions.add(def.getDimensionName()); + + return this; + } + + public WorldgenQuery inDimension(DimensionDef def) { + if (dimensions == null) dimensions = new HashSet<>(); + + dimensions.add(def.modDimensionDef.getDimensionName()); + + return this; + } + + public WorldgenQuery inStone(IStoneCategory stoneCategories) { + if (defaultStoneCategories) { + this.stoneCategories = new HashSet<>(); + defaultStoneCategories = false; + } + + this.stoneCategories.addAll(Arrays.asList(stoneCategories)); + + return this; + } + + @Nullable + public TLayer find(Random random) { + if (checkWeight) { + return findWithWeight(random); + } else { + return findWithoutWeight(random); + } + } + + private TLayer findWithWeight(Random random) { + int totalAmount = 0; + + for (TLayer layer : list) { + if (matches(layer)) { + totalAmount += layer.getWeight(); + } + } + + if (totalAmount == 0) return null; + + int remainingAmount = random.nextInt(totalAmount); + + for (TLayer layer : list) { + if (!matches(layer)) continue; + + remainingAmount -= layer.getWeight(); + + if (remainingAmount <= 0) return layer; + } + + return null; + } + + private TLayer findWithoutWeight(Random random) { + int count = 0; + + for (TLayer layer : list) { + if (matches(layer)) { + count++; + } + } + + if (count == 0) return null; + + int remainingAmount = random.nextInt(count); + + for (TLayer layer : list) { + if (!matches(layer)) continue; + + remainingAmount--; + + if (remainingAmount <= 0) return layer; + } + + return null; + } + + public boolean matches(TLayer layer) { + if (minY != -1 && minY < layer.getMinY()) return false; + if (maxY != -1 && maxY > layer.getMaxY()) return false; + + if (dimensions != null) { + boolean any = false; + + for (String dimName : dimensions) { + if (layer.canGenerateIn(dimName)) { + any = true; + break; + } + } + + if (!any) return false; + } + + boolean mustBeStoneSpecific = stoneCategories != null; + if (layer.isStoneSpecific() != mustBeStoneSpecific) return false; + + if (stoneCategories != null) { + boolean any = false; + + for (IStoneCategory stoneCategory : stoneCategories) { + if (layer.canGenerateIn(stoneCategory)) { + any = true; + break; + } + } + + if (!any) return false; + } + + return true; + } +} diff --git a/src/main/java/gregtech/loaders/materials/MaterialsInit1.java b/src/main/java/gregtech/loaders/materials/MaterialsInit1.java index 19117f2b18a..6c50b078dd0 100644 --- a/src/main/java/gregtech/loaders/materials/MaterialsInit1.java +++ b/src/main/java/gregtech/loaders/materials/MaterialsInit1.java @@ -180,7 +180,7 @@ public static void load() { Materials.Boron = new Materials( 9, TextureSet.SET_DULL , 1.0F, 0, 2, 1 |32 , 210, 250, 210, 0, "Boron" , "Boron" , 0, 0, 2349, 0, false, false, 1, 1, 1, Dyes.dyeWhite , Element.B , Collections.singletonList(new TCAspects.TC_AspectStack(TCAspects.VITREUS, 3))); Materials.Caesium = new Materials( 62, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1|2 |8 |32 , 176, 196, 222, 0, "Caesium" , "Caesium" , 0, 0, 301, 0, false, false, 4, 1, 1, Dyes._NULL , Element.Cs , Arrays.asList(new TCAspects.TC_AspectStack(TCAspects.METALLUM, 2), new TCAspects.TC_AspectStack(TCAspects.RADIO, 1))); Materials.Calcium = new Materials( 26, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1 |32 , 255, 245, 245, 0, "Calcium" , "Calcium" , 0, 0, 1115, 1115, true, false, 4, 1, 1, Dyes.dyePink , Element.Ca , Arrays.asList(new TCAspects.TC_AspectStack(TCAspects.SANO, 1), new TCAspects.TC_AspectStack(TCAspects.TUTAMEN, 1))); - Materials.Carbon = new Materials( 10, TextureSet.SET_DULL , 1.0F, 64, 2, 1|2 |16|32|64|128 , 20, 20, 20, 0, "Carbon" , "Carbon" , 0, 0, 3800, 0, false, false, 2, 1, 1, Dyes.dyeBlack , Element.C , Arrays.asList(new TCAspects.TC_AspectStack(TCAspects.VITREUS, 1), new TCAspects.TC_AspectStack(TCAspects.IGNIS, 1))); + Materials.Carbon = new Materials( 10, TextureSet.SET_DULL , 1.0F, 64, 2, 1|2 |8|16|32|64|128 , 20, 20, 20, 0, "Carbon" , "Carbon" , 0, 0, 3800, 0, false, false, 2, 1, 1, Dyes.dyeBlack , Element.C , Arrays.asList(new TCAspects.TC_AspectStack(TCAspects.VITREUS, 1), new TCAspects.TC_AspectStack(TCAspects.IGNIS, 1))); Materials.Cadmium = new Materials( 55, TextureSet.SET_SHINY , 1.0F, 0, 2, 1 |8 |32 , 50, 50, 60, 0, "Cadmium" , "Cadmium" , 0, 0, 594, 0, false, false, 3, 1, 1, Dyes.dyeGray , Element.Cd , Arrays.asList(new TCAspects.TC_AspectStack(TCAspects.METALLUM, 1), new TCAspects.TC_AspectStack(TCAspects.POTENTIA, 1), new TCAspects.TC_AspectStack(TCAspects.VENENUM, 1))); Materials.Cerium = new Materials( 65, TextureSet.SET_METALLIC , 1.0F, 0, 2, 1|2 |8 |32 , 123, 212, 144, 0, "Cerium" , "Cerium" , 0, 0, 1068, 1068, true, false, 4, 1, 1, Dyes._NULL , Element.Ce , Arrays.asList(new TCAspects.TC_AspectStack(TCAspects.METALLUM, 2), new TCAspects.TC_AspectStack(TCAspects.RADIO, 1))); Materials.Chlorine = new Materials( 23, TextureSet.SET_FLUID , 1.0F, 0, 2, 16|32 , 255, 255, 255, 0, "Chlorine" , "Chlorine" , 0, 0, 171, 0, false, false, 2, 1, 1, Dyes.dyeCyan , Element.Cl , Arrays.asList(new TCAspects.TC_AspectStack(TCAspects.AQUA, 2), new TCAspects.TC_AspectStack(TCAspects.PANNUS, 1))); diff --git a/src/main/java/gregtech/loaders/oreprocessing/ProcessingOre.java b/src/main/java/gregtech/loaders/oreprocessing/ProcessingOre.java index 9fd78466fd0..56ef96f7e08 100644 --- a/src/main/java/gregtech/loaders/oreprocessing/ProcessingOre.java +++ b/src/main/java/gregtech/loaders/oreprocessing/ProcessingOre.java @@ -17,6 +17,7 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SubTag; import gregtech.api.enums.TierEU; +import gregtech.api.recipe.RecipeMaps; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; @@ -57,7 +58,14 @@ public void registerOre(OrePrefixes aPrefix, Materials aMaterial, String aOreDic tIsRich = (aPrefix == OrePrefixes.oreEndstone) || (aPrefix == OrePrefixes.oreEnd); } - if (aMaterial == Materials.Oilsands) { + if (aMaterial.contains(SubTag.ICE_ORE)) { + GTValues.RA.stdBuilder() + .itemInputs(GTUtility.copyAmount(1, aStack)) + .fluidOutputs(aMaterial.getGas((tIsRich ? 2000L : 1000L) * aMaterial.mOreMultiplier)) + .duration(5 * SECONDS) + .eut(TierEU.RECIPE_MV) + .addTo(RecipeMaps.fluidExtractionRecipes); + } else if (aMaterial == Materials.Oilsands) { GTValues.RA.stdBuilder() .itemInputs(GTUtility.copyAmount(1, aStack)) .itemOutputs(new ItemStack(net.minecraft.init.Blocks.sand, 1, 0)) diff --git a/src/main/java/gregtech/loaders/oreprocessing/ProcessingRawOre.java b/src/main/java/gregtech/loaders/oreprocessing/ProcessingRawOre.java index 6897e704e50..1a51dbc109a 100644 --- a/src/main/java/gregtech/loaders/oreprocessing/ProcessingRawOre.java +++ b/src/main/java/gregtech/loaders/oreprocessing/ProcessingRawOre.java @@ -15,6 +15,7 @@ import gregtech.api.enums.SubTag; import gregtech.api.enums.TierEU; import gregtech.api.enums.ToolDictNames; +import gregtech.api.recipe.RecipeMaps; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; @@ -34,7 +35,14 @@ public void registerOre(OrePrefixes aPrefix, Materials aMaterial, String aOreDic return; } - if (aMaterial == Materials.Oilsands) { + if (aMaterial.contains(SubTag.ICE_ORE)) { + GTValues.RA.stdBuilder() + .itemInputs(GTUtility.copyAmount(1, aStack)) + .fluidOutputs(aMaterial.getGas(1000L * aMaterial.mOreMultiplier)) + .duration(2 * SECONDS) + .eut(TierEU.RECIPE_MV) + .addTo(RecipeMaps.fluidExtractionRecipes); + } else if (aMaterial == Materials.Oilsands) { GTValues.RA.stdBuilder() .itemInputs(GTUtility.copyAmount(1, aStack)) .itemOutputs(new ItemStack(net.minecraft.init.Blocks.sand, 1, 0)) diff --git a/src/main/java/gregtech/loaders/postload/GTWorldgenloader.java b/src/main/java/gregtech/loaders/postload/GTWorldgenloader.java index 85e81a1ec04..673e59ffbd6 100644 --- a/src/main/java/gregtech/loaders/postload/GTWorldgenloader.java +++ b/src/main/java/gregtech/loaders/postload/GTWorldgenloader.java @@ -1,6 +1,6 @@ package gregtech.loaders.postload; -import galacticgreg.WorldgenGaGT; +import galacticgreg.WorldGeneratorSpace; import gregtech.api.enums.GTStones; import gregtech.api.enums.OreMixes; import gregtech.api.enums.SmallOres; @@ -11,6 +11,7 @@ public class GTWorldgenloader implements Runnable { public void run() { new GTWorldgenerator(); + new WorldGeneratorSpace(); // GT Stones for (GTStones stone : GTStones.values()) { @@ -27,7 +28,6 @@ public void run() { oreMix.addGTOreLayer(); } - new WorldgenGaGT().run(); GTLog.out.println("Started Galactic Greg ore gen code"); } } diff --git a/src/main/java/gregtech/loaders/preload/GTPreLoad.java b/src/main/java/gregtech/loaders/preload/GTPreLoad.java index f884ddcfecc..8171bc6d0e8 100644 --- a/src/main/java/gregtech/loaders/preload/GTPreLoad.java +++ b/src/main/java/gregtech/loaders/preload/GTPreLoad.java @@ -354,7 +354,6 @@ public static void loadConfig() { GTValues.debugBlockPump = Gregtech.debug.debugBlockPump; GTValues.debugEntityCramming = Gregtech.debug.debugEntityCramming; GTValues.debugWorldData = Gregtech.debug.debugWorldData; - GTValues.oreveinPercentage = Gregtech.general.oreveinPercentage; GTValues.oreveinAttempts = Gregtech.general.oreveinAttempts; GTValues.oreveinMaxPlacementAttempts = Gregtech.general.oreveinMaxPlacementAttempts; GTValues.oreveinPlacerOres = Gregtech.general.oreveinPlacerOres; diff --git a/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java b/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java index 22866098213..bc4733f6472 100644 --- a/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java +++ b/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java @@ -74,7 +74,7 @@ import gregtech.common.blocks.BlockLaser; import gregtech.common.blocks.BlockMachines; import gregtech.common.blocks.BlockMetal; -import gregtech.common.blocks.BlockOres; +import gregtech.common.blocks.BlockOresLegacy; import gregtech.common.blocks.BlockReinforced; import gregtech.common.blocks.BlockStones; import gregtech.common.blocks.BlockTintedIndustrialGlass; @@ -95,6 +95,7 @@ import gregtech.common.items.MetaGeneratedItem98; import gregtech.common.items.MetaGeneratedItem99; import gregtech.common.items.MetaGeneratedTool01; +import gregtech.common.ores.GTOreAdapter; import gregtech.common.tileentities.render.TileEntityBlackhole; import gregtech.common.tileentities.render.TileEntityDrone; import gregtech.common.tileentities.render.TileEntityLaser; @@ -550,7 +551,7 @@ public void run() { GregTechAPI.sBlockLongDistancePipes = new BlockLongDistancePipe(); GregTechAPI.sBlockConcretes = new BlockConcretes(); GregTechAPI.sBlockStones = new BlockStones(); - GregTechAPI.sBlockOres1 = new BlockOres(); + GregTechAPI.sBlockOres1 = new BlockOresLegacy(); GregTechAPI.sBlockFrames = new BlockFrameBox(); GregTechAPI.sDroneRender = new BlockDrone(); GregTechAPI.sBlockGlass1 = new BlockGlass1(); @@ -559,6 +560,8 @@ public void run() { GregTechAPI.sWormholeRender = new BlockWormholeRender(); GregTechAPI.sBlackholeRender = new BlockBlackholeRenderer(); + GTOreAdapter.INSTANCE.init(); + // meta ID order, DO NOT CHANGE ORDER GregTechAPI.sBlockMetal1 = new BlockMetal( diff --git a/src/main/java/gregtech/nei/NEIGTConfig.java b/src/main/java/gregtech/nei/NEIGTConfig.java index ab81530e1fe..664d34e4afc 100644 --- a/src/main/java/gregtech/nei/NEIGTConfig.java +++ b/src/main/java/gregtech/nei/NEIGTConfig.java @@ -29,6 +29,7 @@ import gregtech.common.items.MetaGeneratedItem01; import gregtech.common.items.MetaGeneratedItem02; import gregtech.common.items.MetaGeneratedItem03; +import gregtech.common.ores.GTOreAdapter; import gregtech.nei.dumper.BatchModeSupportDumper; import gregtech.nei.dumper.InputSeparationSupportDumper; import gregtech.nei.dumper.MaterialDumper; @@ -76,6 +77,7 @@ public void loadConfig() { registerCatalysts(); registerItemEntries(); registerDumpers(); + hideItems(); sIsAdded = true; } @@ -121,6 +123,10 @@ private void registerDumpers() { API.addOption(new RecipeLockingSupportDumper()); } + private void hideItems() { + GTOreAdapter.INSTANCE.hideOres(); + } + @SubscribeEvent public void registerHandlerInfo(NEIRegisterHandlerInfosEvent event) { if (RECIPE_CATALYST_INDEX == null) { diff --git a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java index bc4f4b25a6a..da8f9bf84a9 100644 --- a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java +++ b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java @@ -1,9 +1,10 @@ package gtPlusPlus.core.block.base; import java.util.ArrayList; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +import javax.annotation.Nullable; -import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.EnumCreatureType; @@ -14,28 +15,25 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.GTMod; import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.Textures; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IBlockWithTextures; import gregtech.api.interfaces.ITexture; +import gregtech.api.render.TextureFactory; import gregtech.api.util.GTOreDictUnificator; -import gtPlusPlus.api.interfaces.ITexturedBlock; -import gtPlusPlus.core.client.renderer.CustomOreBlockRenderer; +import gregtech.common.ores.GTPPOreAdapter; +import gregtech.common.ores.OreInfo; +import gregtech.common.render.GTRendererBlock; import gtPlusPlus.core.item.base.itemblock.ItemBlockOre; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.xmod.gregtech.api.objects.GTPPCopiedBlockTexture; -import gtPlusPlus.xmod.gregtech.api.objects.GTPPRenderedTexture; -public class BlockBaseOre extends BasicBlock implements ITexturedBlock { +public class BlockBaseOre extends BasicBlock implements IBlockWithTextures { private final Material blockMaterial; - protected static boolean shouldFortune = false; - protected static boolean shouldSilkTouch = false; public BlockBaseOre(final Material material, final BlockTypes blockType) { super( @@ -75,18 +73,6 @@ public Material getMaterialEx() { return this.blockMaterial; } - @Override - public int getRenderType() { - try { - if (CustomOreBlockRenderer.INSTANCE != null) { - return CustomOreBlockRenderer.INSTANCE.mRenderID; - } - return super.getRenderType(); - } catch (NullPointerException n) { - return 0; - } - } - @Override public IIcon getIcon(IBlockAccess aIBlockAccess, int aX, int aY, int aZ, int ordinalSide) { return Blocks.stone.getIcon(0, 0); @@ -98,87 +84,37 @@ public IIcon getIcon(int ordinalSide, int aMeta) { } @Override - public ITexture[] getTexture(ForgeDirection side) { - return getTexture(null, side); + public int getRenderType() { + return GTRendererBlock.mRenderID; } @Override - public ITexture[] getTexture(Block block, ForgeDirection side) { - if (this.blockMaterial != null) { - GTPPRenderedTexture aIconSet = new GTPPRenderedTexture( - blockMaterial.getTextureSet().mTextures[OrePrefixes.ore.mTextureIndex], - this.blockMaterial.getRGBA()); - return new ITexture[] { new GTPPCopiedBlockTexture(Blocks.stone, 0, 0), aIconSet }; - } - return new ITexture[] { - new GTPPRenderedTexture(Textures.BlockIcons.STONES[0], new short[] { 240, 240, 240, 0 }) }; + @Nullable + public ITexture[][] getTextures(int metadata) { + ITexture[] layers; + + ITexture aIconSet = TextureFactory + .of(blockMaterial.getTextureSet().mTextures[OrePrefixes.ore.mTextureIndex], blockMaterial.getRGBA()); + layers = new ITexture[] { StoneType.Stone.getTexture(0), aIconSet }; + + return new ITexture[][] { layers, layers, layers, layers, layers, layers }; } @Override public void registerBlockIcons(IIconRegister p_149651_1_) {} @Override - public void harvestBlock(World worldIn, EntityPlayer player, int x, int y, int z, int meta) { - if (EnchantmentHelper.getSilkTouchModifier(player)) { - shouldSilkTouch = true; - super.harvestBlock(worldIn, player, x, y, z, meta); - if (shouldSilkTouch) { - shouldSilkTouch = false; - } - return; - } + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + EntityPlayer harvester = this.harvesters.get(); - if (!(player instanceof FakePlayer)) { - shouldFortune = true; - } - super.harvestBlock(worldIn, player, x, y, z, meta); - if (shouldFortune) { - shouldFortune = false; - } - } + boolean doFortune = !(harvester instanceof FakePlayer); + boolean doSilktouch = harvester != null && EnchantmentHelper.getSilkTouchModifier(harvester); - @Override - public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { - ArrayList drops = new ArrayList<>(); - if (shouldSilkTouch) { - drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); - } else { - switch (GTMod.gregtechproxy.oreDropSystem) { - case Item -> drops.add( - ItemUtils - .getItemStackOfAmountFromOreDictNoBroken("oreRaw" + this.blockMaterial.getLocalizedName(), 1)); - case FortuneItem -> { - // if shouldFortune and isNatural then get fortune drops - // if not shouldFortune or not isNatural then get normal drops - // if not shouldFortune and isNatural then get normal drops - // if shouldFortune and not isNatural then get normal drops - if (shouldFortune && fortune > 0) { - int aMinAmount = 1; - // Max applicable fortune - if (fortune > 3) fortune = 3; - long amount = (long) new Random().nextInt(fortune) + aMinAmount; - for (int i = 0; i < amount; i++) { - drops.add( - ItemUtils.getItemStackOfAmountFromOreDictNoBroken( - "oreRaw" + this.blockMaterial.getLocalizedName(), - 1)); - } - } else { - drops.add( - ItemUtils.getItemStackOfAmountFromOreDictNoBroken( - "oreRaw" + this.blockMaterial.getLocalizedName(), - 1)); - } - } - // Unified ore - case UnifiedBlock -> drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); - // Per Dimension ore - case PerDimBlock -> drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); - // Regular ore - case Block -> drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); - } + try (OreInfo info = GTPPOreAdapter.INSTANCE.getOreInfo(this, metadata)) { + if (info == null) return new ArrayList<>(); + + return GTPPOreAdapter.INSTANCE + .getOreDrops(ThreadLocalRandom.current(), info, doSilktouch, doFortune ? fortune : 0); } - return drops; } - } diff --git a/src/main/java/gtPlusPlus/core/client/renderer/CustomOreBlockRenderer.java b/src/main/java/gtPlusPlus/core/client/renderer/CustomOreBlockRenderer.java deleted file mode 100644 index a32dd2da8f4..00000000000 --- a/src/main/java/gtPlusPlus/core/client/renderer/CustomOreBlockRenderer.java +++ /dev/null @@ -1,2467 +0,0 @@ -package gtPlusPlus.core.client.renderer; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; -import cpw.mods.fml.client.registry.RenderingRegistry; -import gregtech.api.interfaces.ITexture; -import gtPlusPlus.api.interfaces.ITexturedBlock; -import gtPlusPlus.api.objects.Logger; - -public class CustomOreBlockRenderer implements ISimpleBlockRenderingHandler { - - public static CustomOreBlockRenderer INSTANCE; - public final int mRenderID; - - public CustomOreBlockRenderer() { - INSTANCE = this; - this.mRenderID = RenderingRegistry.getNextAvailableRenderId(); - RenderingRegistry.registerBlockHandler(this); - Logger.INFO("Registered Custom Ore Block Renderer."); - } - - public boolean renderStandardBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, - RenderBlocks aRenderer) { - if ((aBlock instanceof ITexturedBlock)) { - return renderStandardBlock( - aWorld, - aX, - aY, - aZ, - aBlock, - aRenderer, - new ITexture[][] { ((ITexturedBlock) aBlock).getTexture(ForgeDirection.DOWN), - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.UP), - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.NORTH), - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.SOUTH), - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.WEST), - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.EAST) }); - } - return false; - } - - public boolean renderStandardBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, - RenderBlocks aRenderer, ITexture[][] aTextures) { - aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); - aRenderer.setRenderBoundsFromBlock(aBlock); - int l = aBlock.colorMultiplier(aWorld, aX, aY, aZ); - float RED = (float) (l >> 16 & 255) / 255.0F; - float GREEN = (float) (l >> 8 & 255) / 255.0F; - float BLUE = (float) (l & 255) / 255.0F; - - if (Minecraft.isAmbientOcclusionEnabled() && aBlock.getLightValue() == 0) { - if (RenderBlocks.getInstance().partialRenderBounds) { - return INSTANCE.renderStandardBlockWithAmbientOcclusionPartial( - aWorld, - aRenderer, - aTextures, - aBlock, - aX, - aY, - aZ, - RED, - GREEN, - BLUE); - } else { - return INSTANCE.renderStandardBlockWithAmbientOcclusion( - aWorld, - aRenderer, - aTextures, - aBlock, - aX, - aY, - aZ, - RED, - GREEN, - BLUE); - } - } else { - renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[0], true); - renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[1], true); - renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[2], true); - renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[3], true); - renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[4], true); - renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[5], true); - } - return true; - } - - public static void renderFaceYNeg(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ, - ITexture[][] aIcon) { - renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aIcon[0], true); - } - - public static void renderFaceYPos(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ, - ITexture[][] aIcon) { - renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aIcon[1], true); - } - - public static void renderFaceZNeg(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ, - ITexture[][] aIcon) { - renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aIcon[2], true); - } - - public static void renderFaceZPos(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ, - ITexture[][] aIcon) { - renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aIcon[3], true); - } - - public static void renderFaceXNeg(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ, - ITexture[][] aIcon) { - renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aIcon[4], true); - } - - public static void renderFaceXPos(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ, - ITexture[][] aIcon) { - renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aIcon[5], true); - } - - public static void renderNegativeYFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, - int aZ, ITexture[] aIcon, boolean aFullBlock) { - if (aWorld != null) { - if ((aFullBlock) && (!aBlock.shouldSideBeRendered(aWorld, aX, aY - 1, aZ, 0))) { - return; - } - Tessellator.instance - .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aFullBlock ? aY - 1 : aY, aZ)); - } - if (aIcon != null) { - for (ITexture iTexture : aIcon) { - if (iTexture != null) { - iTexture.renderYNeg(aRenderer, aBlock, aX, aY, aZ); - } - } - } - aRenderer.flipTexture = false; - } - - public static void renderPositiveYFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, - int aZ, ITexture[] aIcon, boolean aFullBlock) { - if (aWorld != null) { - if ((aFullBlock) && (!aBlock.shouldSideBeRendered(aWorld, aX, aY + 1, aZ, 1))) { - return; - } - Tessellator.instance - .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aFullBlock ? aY + 1 : aY, aZ)); - } - if (aIcon != null) { - for (ITexture iTexture : aIcon) { - if (iTexture != null) { - iTexture.renderYPos(aRenderer, aBlock, aX, aY, aZ); - } - } - } - aRenderer.flipTexture = false; - } - - public static void renderNegativeZFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, - int aZ, ITexture[] aIcon, boolean aFullBlock) { - if (aWorld != null) { - if ((aFullBlock) && (!aBlock.shouldSideBeRendered(aWorld, aX, aY, aZ - 1, 2))) { - return; - } - Tessellator.instance - .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aY, aFullBlock ? aZ - 1 : aZ)); - } - aRenderer.flipTexture = (!aFullBlock); - if (aIcon != null) { - for (ITexture iTexture : aIcon) { - if (iTexture != null) { - iTexture.renderZNeg(aRenderer, aBlock, aX, aY, aZ); - } - } - } - aRenderer.flipTexture = false; - } - - public static void renderPositiveZFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, - int aZ, ITexture[] aIcon, boolean aFullBlock) { - if (aWorld != null) { - if ((aFullBlock) && (!aBlock.shouldSideBeRendered(aWorld, aX, aY, aZ + 1, 3))) { - return; - } - Tessellator.instance - .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aY, aFullBlock ? aZ + 1 : aZ)); - } - if (aIcon != null) { - for (ITexture iTexture : aIcon) { - if (iTexture != null) { - iTexture.renderZPos(aRenderer, aBlock, aX, aY, aZ); - } - } - } - aRenderer.flipTexture = false; - } - - public static void renderNegativeXFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, - int aZ, ITexture[] aIcon, boolean aFullBlock) { - if (aWorld != null) { - if ((aFullBlock) && (!aBlock.shouldSideBeRendered(aWorld, aX - 1, aY, aZ, 4))) { - return; - } - Tessellator.instance - .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aFullBlock ? aX - 1 : aX, aY, aZ)); - } - if (aIcon != null) { - for (ITexture iTexture : aIcon) { - if (iTexture != null) { - iTexture.renderXNeg(aRenderer, aBlock, aX, aY, aZ); - } - } - } - aRenderer.flipTexture = false; - } - - public static void renderPositiveXFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, - int aZ, ITexture[] aIcon, boolean aFullBlock) { - if (aWorld != null) { - if ((aFullBlock) && (!aBlock.shouldSideBeRendered(aWorld, aX + 1, aY, aZ, 5))) { - return; - } - Tessellator.instance - .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aFullBlock ? aX + 1 : aX, aY, aZ)); - } - aRenderer.flipTexture = (!aFullBlock); - if (aIcon != null) { - for (ITexture iTexture : aIcon) { - if (iTexture != null) { - iTexture.renderXPos(aRenderer, aBlock, aX, aY, aZ); - } - } - } - aRenderer.flipTexture = false; - } - - @Override - public void renderInventoryBlock(Block aBlock, int aMeta, int aModelID, RenderBlocks aRenderer) { - aBlock.setBlockBoundsForItemRender(); - aRenderer.setRenderBoundsFromBlock(aBlock); - GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); - GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - Tessellator.instance.startDrawingQuads(); - Tessellator.instance.setNormal(0.0F, -1.0F, 0.0F); - renderNegativeYFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.DOWN), - true); - Tessellator.instance.draw(); - Tessellator.instance.startDrawingQuads(); - Tessellator.instance.setNormal(0.0F, 1.0F, 0.0F); - renderPositiveYFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.UP), - true); - Tessellator.instance.draw(); - Tessellator.instance.startDrawingQuads(); - Tessellator.instance.setNormal(0.0F, 0.0F, -1.0F); - renderNegativeZFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.NORTH), - true); - Tessellator.instance.draw(); - Tessellator.instance.startDrawingQuads(); - Tessellator.instance.setNormal(0.0F, 0.0F, 1.0F); - renderPositiveZFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.SOUTH), - true); - Tessellator.instance.draw(); - Tessellator.instance.startDrawingQuads(); - Tessellator.instance.setNormal(-1.0F, 0.0F, 0.0F); - renderNegativeXFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.WEST), - true); - Tessellator.instance.draw(); - Tessellator.instance.startDrawingQuads(); - Tessellator.instance.setNormal(1.0F, 0.0F, 0.0F); - renderPositiveXFacing( - null, - aRenderer, - aBlock, - 0, - 0, - 0, - ((ITexturedBlock) aBlock).getTexture(ForgeDirection.EAST), - true); - Tessellator.instance.draw(); - aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); - aRenderer.setRenderBoundsFromBlock(aBlock); - GL11.glTranslatef(0.5F, 0.5F, 0.5F); - } - - @Override - public boolean renderWorldBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, int aModelID, - RenderBlocks aRenderer) { - blockAccess = aWorld; - return renderStandardBlock(aWorld, aX, aY, aZ, aBlock, aRenderer); - } - - @Override - public boolean shouldRender3DInInventory(int aModel) { - return true; - } - - @Override - public int getRenderId() { - return this.mRenderID; - } - - public void setRenderBounds(double p_147782_1_, double p_147782_3_, double p_147782_5_, double p_147782_7_, - double p_147782_9_, double p_147782_11_) { - if (!this.lockBlockBounds) { - this.renderMinX = p_147782_1_; - this.renderMaxX = p_147782_7_; - this.renderMinY = p_147782_3_; - this.renderMaxY = p_147782_9_; - this.renderMinZ = p_147782_5_; - this.renderMaxZ = p_147782_11_; - this.partialRenderBounds = this.minecraftRB.gameSettings.ambientOcclusion >= 2 - && (this.renderMinX > 0.0D || this.renderMaxX < 1.0D - || this.renderMinY > 0.0D - || this.renderMaxY < 1.0D - || this.renderMinZ > 0.0D - || this.renderMaxZ < 1.0D); - } - } - - /** - * Like setRenderBounds, but automatically pulling the bounds from the given Block. - */ - public void setRenderBoundsFromBlock(Block block) { - if (!this.lockBlockBounds) { - this.renderMinX = block.getBlockBoundsMinX(); - this.renderMaxX = block.getBlockBoundsMaxX(); - this.renderMinY = block.getBlockBoundsMinY(); - this.renderMaxY = block.getBlockBoundsMaxY(); - this.renderMinZ = block.getBlockBoundsMinZ(); - this.renderMaxZ = block.getBlockBoundsMaxZ(); - this.partialRenderBounds = this.minecraftRB.gameSettings.ambientOcclusion >= 2 - && (this.renderMinX > 0.0D || this.renderMaxX < 1.0D - || this.renderMinY > 0.0D - || this.renderMaxY < 1.0D - || this.renderMinZ > 0.0D - || this.renderMaxZ < 1.0D); - } - } - - /** - * Vanilla Variables - */ - - /** The minimum X value for rendering (default 0.0). */ - public double renderMinX; - /** The maximum X value for rendering (default 1.0). */ - public double renderMaxX; - /** The minimum Y value for rendering (default 0.0). */ - public double renderMinY; - /** The maximum Y value for rendering (default 1.0). */ - public double renderMaxY; - /** The minimum Z value for rendering (default 0.0). */ - public double renderMinZ; - /** The maximum Z value for rendering (default 1.0). */ - public double renderMaxZ; - - public boolean lockBlockBounds; - public boolean partialRenderBounds; - public final Minecraft minecraftRB = RenderBlocks.getInstance().minecraftRB; - public int uvRotateEast; - public int uvRotateWest; - public int uvRotateSouth; - public int uvRotateNorth; - public int uvRotateTop; - public int uvRotateBottom; - /** Whether ambient occlusion is enabled or not */ - public boolean enableAO; - /** Used as a scratch variable for ambient occlusion on the north/bottom/east corner. */ - public float aoLightValueScratchXYZNNN; - /** Used as a scratch variable for ambient occlusion between the bottom face and the north face. */ - public float aoLightValueScratchXYNN; - /** Used as a scratch variable for ambient occlusion on the north/bottom/west corner. */ - public float aoLightValueScratchXYZNNP; - /** Used as a scratch variable for ambient occlusion between the bottom face and the east face. */ - public float aoLightValueScratchYZNN; - /** Used as a scratch variable for ambient occlusion between the bottom face and the west face. */ - public float aoLightValueScratchYZNP; - /** Used as a scratch variable for ambient occlusion on the south/bottom/east corner. */ - public float aoLightValueScratchXYZPNN; - /** Used as a scratch variable for ambient occlusion between the bottom face and the south face. */ - public float aoLightValueScratchXYPN; - /** Used as a scratch variable for ambient occlusion on the south/bottom/west corner. */ - public float aoLightValueScratchXYZPNP; - /** Used as a scratch variable for ambient occlusion on the north/top/east corner. */ - public float aoLightValueScratchXYZNPN; - /** Used as a scratch variable for ambient occlusion between the top face and the north face. */ - public float aoLightValueScratchXYNP; - /** Used as a scratch variable for ambient occlusion on the north/top/west corner. */ - public float aoLightValueScratchXYZNPP; - /** Used as a scratch variable for ambient occlusion between the top face and the east face. */ - public float aoLightValueScratchYZPN; - /** Used as a scratch variable for ambient occlusion on the south/top/east corner. */ - public float aoLightValueScratchXYZPPN; - /** Used as a scratch variable for ambient occlusion between the top face and the south face. */ - public float aoLightValueScratchXYPP; - /** Used as a scratch variable for ambient occlusion between the top face and the west face. */ - public float aoLightValueScratchYZPP; - /** Used as a scratch variable for ambient occlusion on the south/top/west corner. */ - public float aoLightValueScratchXYZPPP; - /** Used as a scratch variable for ambient occlusion between the north face and the east face. */ - public float aoLightValueScratchXZNN; - /** Used as a scratch variable for ambient occlusion between the south face and the east face. */ - public float aoLightValueScratchXZPN; - /** Used as a scratch variable for ambient occlusion between the north face and the west face. */ - public float aoLightValueScratchXZNP; - /** Used as a scratch variable for ambient occlusion between the south face and the west face. */ - public float aoLightValueScratchXZPP; - /** Ambient occlusion brightness XYZNNN */ - public int aoBrightnessXYZNNN; - /** Ambient occlusion brightness XYNN */ - public int aoBrightnessXYNN; - /** Ambient occlusion brightness XYZNNP */ - public int aoBrightnessXYZNNP; - /** Ambient occlusion brightness YZNN */ - public int aoBrightnessYZNN; - /** Ambient occlusion brightness YZNP */ - public int aoBrightnessYZNP; - /** Ambient occlusion brightness XYZPNN */ - public int aoBrightnessXYZPNN; - /** Ambient occlusion brightness XYPN */ - public int aoBrightnessXYPN; - /** Ambient occlusion brightness XYZPNP */ - public int aoBrightnessXYZPNP; - /** Ambient occlusion brightness XYZNPN */ - public int aoBrightnessXYZNPN; - /** Ambient occlusion brightness XYNP */ - public int aoBrightnessXYNP; - /** Ambient occlusion brightness XYZNPP */ - public int aoBrightnessXYZNPP; - /** Ambient occlusion brightness YZPN */ - public int aoBrightnessYZPN; - /** Ambient occlusion brightness XYZPPN */ - public int aoBrightnessXYZPPN; - /** Ambient occlusion brightness XYPP */ - public int aoBrightnessXYPP; - /** Ambient occlusion brightness YZPP */ - public int aoBrightnessYZPP; - /** Ambient occlusion brightness XYZPPP */ - public int aoBrightnessXYZPPP; - /** Ambient occlusion brightness XZNN */ - public int aoBrightnessXZNN; - /** Ambient occlusion brightness XZPN */ - public int aoBrightnessXZPN; - /** Ambient occlusion brightness XZNP */ - public int aoBrightnessXZNP; - /** Ambient occlusion brightness XZPP */ - public int aoBrightnessXZPP; - /** Brightness top left */ - public int brightnessTopLeft; - /** Brightness bottom left */ - public int brightnessBottomLeft; - /** Brightness bottom right */ - public int brightnessBottomRight; - /** Brightness top right */ - public int brightnessTopRight; - /** Red color value for the top left corner */ - public float colorRedTopLeft; - /** Red color value for the bottom left corner */ - public float colorRedBottomLeft; - /** Red color value for the bottom right corner */ - public float colorRedBottomRight; - /** Red color value for the top right corner */ - public float colorRedTopRight; - /** Green color value for the top left corner */ - public float colorGreenTopLeft; - /** Green color value for the bottom left corner */ - public float colorGreenBottomLeft; - /** Green color value for the bottom right corner */ - public float colorGreenBottomRight; - /** Green color value for the top right corner */ - public float colorGreenTopRight; - /** Blue color value for the top left corner */ - public float colorBlueTopLeft; - /** Blue color value for the bottom left corner */ - public float colorBlueBottomLeft; - /** Blue color value for the bottom right corner */ - public float colorBlueBottomRight; - /** Blue color value for the top right corner */ - public float colorBlueTopRight; - /** If set to >=0, all block faces will be rendered using this texture index */ - public IIcon overrideBlockTexture; - - /** - * Clear override block texture - */ - public void clearOverrideBlockTexture() { - this.overrideBlockTexture = null; - } - - public boolean hasOverrideBlockTexture() { - return this.overrideBlockTexture != null; - } - - public IIcon getBlockIcon(Block block, IBlockAccess access, int x, int y, int z, int side) { - return this.getIconSafe(block.getIcon(access, x, y, z, side)); - } - - public IIcon getBlockIconFromSideAndMetadata(Block block, int side, int meta) { - return this.getIconSafe(block.getIcon(side, meta)); - } - - public IIcon getBlockIconFromSide(Block block, int side) { - return this.getIconSafe(block.getBlockTextureFromSide(side)); - } - - public IIcon getBlockIcon(Block block) { - return this.getIconSafe(block.getBlockTextureFromSide(1)); - } - - public IIcon getIconSafe(IIcon iicon) { - if (iicon == null) { - iicon = ((TextureMap) Minecraft.getMinecraft() - .getTextureManager() - .getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno"); - } - return iicon; - } - - IBlockAccess blockAccess = RenderBlocks.getInstance().blockAccess; - - public boolean renderStandardBlockWithAmbientOcclusion(IBlockAccess aWorld, RenderBlocks aRenderer, - ITexture[][] aTextures, Block block, int xPos, int yPos, int zPos, float R, float G, float B) { - this.enableAO = true; - boolean flag = false; - float f3 = 0.0F; - float f4 = 0.0F; - float f5 = 0.0F; - float f6 = 0.0F; - boolean flag1 = true; - int l = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos); - Tessellator tessellator = Tessellator.instance; - tessellator.setBrightness(983055); - - if (this.getBlockIcon(block) - .getIconName() - .equals("grass_top")) { - flag1 = false; - } else if (this.hasOverrideBlockTexture()) { - flag1 = false; - } - - boolean flag2; - boolean flag3; - boolean flag4; - boolean flag5; - int i1; - float f7; - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos, yPos - 1, zPos, 0)) { - if (this.renderMinY <= 0.0D) { - --yPos; - } - - this.aoBrightnessXYNN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - this.aoBrightnessYZNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - this.aoBrightnessYZNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - this.aoBrightnessXYPN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - this.aoLightValueScratchXYNN = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZNN = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZNP = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXYPN = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - flag2 = blockAccess.getBlock(xPos + 1, yPos - 1, zPos) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos - 1, zPos) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos, yPos - 1, zPos + 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos, yPos - 1, zPos - 1) - .getCanBlockGrass(); - - if (!flag5 && !flag3) { - this.aoLightValueScratchXYZNNN = this.aoLightValueScratchXYNN; - this.aoBrightnessXYZNNN = this.aoBrightnessXYNN; - } else { - this.aoLightValueScratchXYZNNN = blockAccess.getBlock(xPos - 1, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos - 1); - } - - if (!flag4 && !flag3) { - this.aoLightValueScratchXYZNNP = this.aoLightValueScratchXYNN; - this.aoBrightnessXYZNNP = this.aoBrightnessXYNN; - } else { - this.aoLightValueScratchXYZNNP = blockAccess.getBlock(xPos - 1, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos + 1); - } - - if (!flag5 && !flag2) { - this.aoLightValueScratchXYZPNN = this.aoLightValueScratchXYPN; - this.aoBrightnessXYZPNN = this.aoBrightnessXYPN; - } else { - this.aoLightValueScratchXYZPNN = blockAccess.getBlock(xPos + 1, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos - 1); - } - - if (!flag4 && !flag2) { - this.aoLightValueScratchXYZPNP = this.aoLightValueScratchXYPN; - this.aoBrightnessXYZPNP = this.aoBrightnessXYPN; - } else { - this.aoLightValueScratchXYZPNP = blockAccess.getBlock(xPos + 1, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos + 1); - } - - if (this.renderMinY <= 0.0D) { - ++yPos; - } - - i1 = l; - - if (this.renderMinY <= 0.0D || !blockAccess.getBlock(xPos, yPos - 1, zPos) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - } - - f7 = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - f3 = (this.aoLightValueScratchXYZNNP + this.aoLightValueScratchXYNN + this.aoLightValueScratchYZNP + f7) - / 4.0F; - f6 = (this.aoLightValueScratchYZNP + f7 + this.aoLightValueScratchXYZPNP + this.aoLightValueScratchXYPN) - / 4.0F; - f5 = (f7 + this.aoLightValueScratchYZNN + this.aoLightValueScratchXYPN + this.aoLightValueScratchXYZPNN) - / 4.0F; - f4 = (this.aoLightValueScratchXYNN + this.aoLightValueScratchXYZNNN + f7 + this.aoLightValueScratchYZNN) - / 4.0F; - this.brightnessTopLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNNP, this.aoBrightnessXYNN, this.aoBrightnessYZNP, i1); - this.brightnessTopRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZNP, this.aoBrightnessXYZPNP, this.aoBrightnessXYPN, i1); - this.brightnessBottomRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZNN, this.aoBrightnessXYPN, this.aoBrightnessXYZPNN, i1); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYNN, this.aoBrightnessXYZNNN, this.aoBrightnessYZNN, i1); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.5F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.5F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.5F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.5F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.5F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.5F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - CustomOreBlockRenderer.renderFaceYNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - flag = true; - } - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos, yPos + 1, zPos, 1)) { - if (this.renderMaxY >= 1.0D) { - ++yPos; - } - - this.aoBrightnessXYNP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - this.aoBrightnessXYPP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - this.aoBrightnessYZPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - this.aoBrightnessYZPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - this.aoLightValueScratchXYNP = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXYPP = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZPN = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZPP = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - flag2 = blockAccess.getBlock(xPos + 1, yPos + 1, zPos) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos + 1, zPos) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos, yPos + 1, zPos + 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos, yPos + 1, zPos - 1) - .getCanBlockGrass(); - - if (!flag5 && !flag3) { - this.aoLightValueScratchXYZNPN = this.aoLightValueScratchXYNP; - this.aoBrightnessXYZNPN = this.aoBrightnessXYNP; - } else { - this.aoLightValueScratchXYZNPN = blockAccess.getBlock(xPos - 1, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos - 1); - } - - if (!flag5 && !flag2) { - this.aoLightValueScratchXYZPPN = this.aoLightValueScratchXYPP; - this.aoBrightnessXYZPPN = this.aoBrightnessXYPP; - } else { - this.aoLightValueScratchXYZPPN = blockAccess.getBlock(xPos + 1, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos - 1); - } - - if (!flag4 && !flag3) { - this.aoLightValueScratchXYZNPP = this.aoLightValueScratchXYNP; - this.aoBrightnessXYZNPP = this.aoBrightnessXYNP; - } else { - this.aoLightValueScratchXYZNPP = blockAccess.getBlock(xPos - 1, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos + 1); - } - - if (!flag4 && !flag2) { - this.aoLightValueScratchXYZPPP = this.aoLightValueScratchXYPP; - this.aoBrightnessXYZPPP = this.aoBrightnessXYPP; - } else { - this.aoLightValueScratchXYZPPP = blockAccess.getBlock(xPos + 1, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos + 1); - } - - if (this.renderMaxY >= 1.0D) { - --yPos; - } - - i1 = l; - - if (this.renderMaxY >= 1.0D || !blockAccess.getBlock(xPos, yPos + 1, zPos) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - } - - f7 = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - f6 = (this.aoLightValueScratchXYZNPP + this.aoLightValueScratchXYNP + this.aoLightValueScratchYZPP + f7) - / 4.0F; - f3 = (this.aoLightValueScratchYZPP + f7 + this.aoLightValueScratchXYZPPP + this.aoLightValueScratchXYPP) - / 4.0F; - f4 = (f7 + this.aoLightValueScratchYZPN + this.aoLightValueScratchXYPP + this.aoLightValueScratchXYZPPN) - / 4.0F; - f5 = (this.aoLightValueScratchXYNP + this.aoLightValueScratchXYZNPN + f7 + this.aoLightValueScratchYZPN) - / 4.0F; - this.brightnessTopRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNPP, this.aoBrightnessXYNP, this.aoBrightnessYZPP, i1); - this.brightnessTopLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZPP, this.aoBrightnessXYZPPP, this.aoBrightnessXYPP, i1); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZPN, this.aoBrightnessXYPP, this.aoBrightnessXYZPPN, i1); - this.brightnessBottomRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYNP, this.aoBrightnessXYZNPN, this.aoBrightnessYZPN, i1); - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B; - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - CustomOreBlockRenderer.renderFaceYPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - flag = true; - } - - IIcon iicon; - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos, yPos, zPos - 1, 2)) { - if (this.renderMinZ <= 0.0D) { - --zPos; - } - - this.aoLightValueScratchXZNN = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZNN = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZPN = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZPN = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXZNN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - this.aoBrightnessYZNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - this.aoBrightnessYZPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - this.aoBrightnessXZPN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - flag2 = blockAccess.getBlock(xPos + 1, yPos, zPos - 1) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos, zPos - 1) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos, yPos + 1, zPos - 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos, yPos - 1, zPos - 1) - .getCanBlockGrass(); - - if (!flag3 && !flag5) { - this.aoLightValueScratchXYZNNN = this.aoLightValueScratchXZNN; - this.aoBrightnessXYZNNN = this.aoBrightnessXZNN; - } else { - this.aoLightValueScratchXYZNNN = blockAccess.getBlock(xPos - 1, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos - 1, zPos); - } - - if (!flag3 && !flag4) { - this.aoLightValueScratchXYZNPN = this.aoLightValueScratchXZNN; - this.aoBrightnessXYZNPN = this.aoBrightnessXZNN; - } else { - this.aoLightValueScratchXYZNPN = blockAccess.getBlock(xPos - 1, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos + 1, zPos); - } - - if (!flag2 && !flag5) { - this.aoLightValueScratchXYZPNN = this.aoLightValueScratchXZPN; - this.aoBrightnessXYZPNN = this.aoBrightnessXZPN; - } else { - this.aoLightValueScratchXYZPNN = blockAccess.getBlock(xPos + 1, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos - 1, zPos); - } - - if (!flag2 && !flag4) { - this.aoLightValueScratchXYZPPN = this.aoLightValueScratchXZPN; - this.aoBrightnessXYZPPN = this.aoBrightnessXZPN; - } else { - this.aoLightValueScratchXYZPPN = blockAccess.getBlock(xPos + 1, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos + 1, zPos); - } - - if (this.renderMinZ <= 0.0D) { - ++zPos; - } - - i1 = l; - - if (this.renderMinZ <= 0.0D || !blockAccess.getBlock(xPos, yPos, zPos - 1) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - } - - f7 = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - f3 = (this.aoLightValueScratchXZNN + this.aoLightValueScratchXYZNPN + f7 + this.aoLightValueScratchYZPN) - / 4.0F; - f4 = (f7 + this.aoLightValueScratchYZPN + this.aoLightValueScratchXZPN + this.aoLightValueScratchXYZPPN) - / 4.0F; - f5 = (this.aoLightValueScratchYZNN + f7 + this.aoLightValueScratchXYZPNN + this.aoLightValueScratchXZPN) - / 4.0F; - f6 = (this.aoLightValueScratchXYZNNN + this.aoLightValueScratchXZNN + this.aoLightValueScratchYZNN + f7) - / 4.0F; - this.brightnessTopLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZNN, this.aoBrightnessXYZNPN, this.aoBrightnessYZPN, i1); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZPN, this.aoBrightnessXZPN, this.aoBrightnessXYZPPN, i1); - this.brightnessBottomRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZNN, this.aoBrightnessXYZPNN, this.aoBrightnessXZPN, i1); - this.brightnessTopRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNNN, this.aoBrightnessXZNN, this.aoBrightnessYZNN, i1); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.8F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.8F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.8F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.8F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.8F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.8F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - iicon = this.getBlockIcon(block, blockAccess, xPos, yPos, zPos, 2); - CustomOreBlockRenderer.renderFaceZNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - - RenderBlocks.getInstance(); - if (RenderBlocks.fancyGrass && iicon.getIconName() - .equals("grass_side") && !this.hasOverrideBlockTexture()) { - this.colorRedTopLeft *= R; - this.colorRedBottomLeft *= R; - this.colorRedBottomRight *= R; - this.colorRedTopRight *= R; - this.colorGreenTopLeft *= G; - this.colorGreenBottomLeft *= G; - this.colorGreenBottomRight *= G; - this.colorGreenTopRight *= G; - this.colorBlueTopLeft *= B; - this.colorBlueBottomLeft *= B; - this.colorBlueBottomRight *= B; - this.colorBlueTopRight *= B; - CustomOreBlockRenderer.renderFaceZNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - } - - flag = true; - } - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos, yPos, zPos + 1, 3)) { - if (this.renderMaxZ >= 1.0D) { - ++zPos; - } - - this.aoLightValueScratchXZNP = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZPP = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZNP = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZPP = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXZNP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - this.aoBrightnessXZPP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - this.aoBrightnessYZNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - this.aoBrightnessYZPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - flag2 = blockAccess.getBlock(xPos + 1, yPos, zPos + 1) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos, zPos + 1) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos, yPos + 1, zPos + 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos, yPos - 1, zPos + 1) - .getCanBlockGrass(); - - if (!flag3 && !flag5) { - this.aoLightValueScratchXYZNNP = this.aoLightValueScratchXZNP; - this.aoBrightnessXYZNNP = this.aoBrightnessXZNP; - } else { - this.aoLightValueScratchXYZNNP = blockAccess.getBlock(xPos - 1, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos - 1, zPos); - } - - if (!flag3 && !flag4) { - this.aoLightValueScratchXYZNPP = this.aoLightValueScratchXZNP; - this.aoBrightnessXYZNPP = this.aoBrightnessXZNP; - } else { - this.aoLightValueScratchXYZNPP = blockAccess.getBlock(xPos - 1, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos + 1, zPos); - } - - if (!flag2 && !flag5) { - this.aoLightValueScratchXYZPNP = this.aoLightValueScratchXZPP; - this.aoBrightnessXYZPNP = this.aoBrightnessXZPP; - } else { - this.aoLightValueScratchXYZPNP = blockAccess.getBlock(xPos + 1, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos - 1, zPos); - } - - if (!flag2 && !flag4) { - this.aoLightValueScratchXYZPPP = this.aoLightValueScratchXZPP; - this.aoBrightnessXYZPPP = this.aoBrightnessXZPP; - } else { - this.aoLightValueScratchXYZPPP = blockAccess.getBlock(xPos + 1, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos + 1, zPos); - } - - if (this.renderMaxZ >= 1.0D) { - --zPos; - } - - i1 = l; - - if (this.renderMaxZ >= 1.0D || !blockAccess.getBlock(xPos, yPos, zPos + 1) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - } - - f7 = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - f3 = (this.aoLightValueScratchXZNP + this.aoLightValueScratchXYZNPP + f7 + this.aoLightValueScratchYZPP) - / 4.0F; - f6 = (f7 + this.aoLightValueScratchYZPP + this.aoLightValueScratchXZPP + this.aoLightValueScratchXYZPPP) - / 4.0F; - f5 = (this.aoLightValueScratchYZNP + f7 + this.aoLightValueScratchXYZPNP + this.aoLightValueScratchXZPP) - / 4.0F; - f4 = (this.aoLightValueScratchXYZNNP + this.aoLightValueScratchXZNP + this.aoLightValueScratchYZNP + f7) - / 4.0F; - this.brightnessTopLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZNP, this.aoBrightnessXYZNPP, this.aoBrightnessYZPP, i1); - this.brightnessTopRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZPP, this.aoBrightnessXZPP, this.aoBrightnessXYZPPP, i1); - this.brightnessBottomRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZNP, this.aoBrightnessXYZPNP, this.aoBrightnessXZPP, i1); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNNP, this.aoBrightnessXZNP, this.aoBrightnessYZNP, i1); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.8F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.8F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.8F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.8F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.8F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.8F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - iicon = this.getBlockIcon(block, blockAccess, xPos, yPos, zPos, 3); - CustomOreBlockRenderer.renderFaceZPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - - RenderBlocks.getInstance(); - if (RenderBlocks.fancyGrass && iicon.getIconName() - .equals("grass_side") && !this.hasOverrideBlockTexture()) { - this.colorRedTopLeft *= R; - this.colorRedBottomLeft *= R; - this.colorRedBottomRight *= R; - this.colorRedTopRight *= R; - this.colorGreenTopLeft *= G; - this.colorGreenBottomLeft *= G; - this.colorGreenBottomRight *= G; - this.colorGreenTopRight *= G; - this.colorBlueTopLeft *= B; - this.colorBlueBottomLeft *= B; - this.colorBlueBottomRight *= B; - this.colorBlueTopRight *= B; - CustomOreBlockRenderer.renderFaceZPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - } - - flag = true; - } - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos - 1, yPos, zPos, 4)) { - if (this.renderMinX <= 0.0D) { - --xPos; - } - - this.aoLightValueScratchXYNN = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZNN = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZNP = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXYNP = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - this.aoBrightnessXZNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - this.aoBrightnessXZNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - this.aoBrightnessXYNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - flag2 = blockAccess.getBlock(xPos - 1, yPos + 1, zPos) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos - 1, zPos) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos - 1, yPos, zPos - 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos - 1, yPos, zPos + 1) - .getCanBlockGrass(); - - if (!flag4 && !flag3) { - this.aoLightValueScratchXYZNNN = this.aoLightValueScratchXZNN; - this.aoBrightnessXYZNNN = this.aoBrightnessXZNN; - } else { - this.aoLightValueScratchXYZNNN = blockAccess.getBlock(xPos, yPos - 1, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos - 1); - } - - if (!flag5 && !flag3) { - this.aoLightValueScratchXYZNNP = this.aoLightValueScratchXZNP; - this.aoBrightnessXYZNNP = this.aoBrightnessXZNP; - } else { - this.aoLightValueScratchXYZNNP = blockAccess.getBlock(xPos, yPos - 1, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos + 1); - } - - if (!flag4 && !flag2) { - this.aoLightValueScratchXYZNPN = this.aoLightValueScratchXZNN; - this.aoBrightnessXYZNPN = this.aoBrightnessXZNN; - } else { - this.aoLightValueScratchXYZNPN = blockAccess.getBlock(xPos, yPos + 1, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos - 1); - } - - if (!flag5 && !flag2) { - this.aoLightValueScratchXYZNPP = this.aoLightValueScratchXZNP; - this.aoBrightnessXYZNPP = this.aoBrightnessXZNP; - } else { - this.aoLightValueScratchXYZNPP = blockAccess.getBlock(xPos, yPos + 1, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos + 1); - } - - if (this.renderMinX <= 0.0D) { - ++xPos; - } - - i1 = l; - - if (this.renderMinX <= 0.0D || !blockAccess.getBlock(xPos - 1, yPos, zPos) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - } - - f7 = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - f6 = (this.aoLightValueScratchXYNN + this.aoLightValueScratchXYZNNP + f7 + this.aoLightValueScratchXZNP) - / 4.0F; - f3 = (f7 + this.aoLightValueScratchXZNP + this.aoLightValueScratchXYNP + this.aoLightValueScratchXYZNPP) - / 4.0F; - f4 = (this.aoLightValueScratchXZNN + f7 + this.aoLightValueScratchXYZNPN + this.aoLightValueScratchXYNP) - / 4.0F; - f5 = (this.aoLightValueScratchXYZNNN + this.aoLightValueScratchXYNN + this.aoLightValueScratchXZNN + f7) - / 4.0F; - this.brightnessTopRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYNN, this.aoBrightnessXYZNNP, this.aoBrightnessXZNP, i1); - this.brightnessTopLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZNP, this.aoBrightnessXYNP, this.aoBrightnessXYZNPP, i1); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZNN, this.aoBrightnessXYZNPN, this.aoBrightnessXYNP, i1); - this.brightnessBottomRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNNN, this.aoBrightnessXYNN, this.aoBrightnessXZNN, i1); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.6F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.6F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.6F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.6F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.6F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.6F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - iicon = this.getBlockIcon(block, blockAccess, xPos, yPos, zPos, 4); - CustomOreBlockRenderer.renderFaceXNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - - RenderBlocks.getInstance(); - if (RenderBlocks.fancyGrass && iicon.getIconName() - .equals("grass_side") && !this.hasOverrideBlockTexture()) { - this.colorRedTopLeft *= R; - this.colorRedBottomLeft *= R; - this.colorRedBottomRight *= R; - this.colorRedTopRight *= R; - this.colorGreenTopLeft *= G; - this.colorGreenBottomLeft *= G; - this.colorGreenBottomRight *= G; - this.colorGreenTopRight *= G; - this.colorBlueTopLeft *= B; - this.colorBlueBottomLeft *= B; - this.colorBlueBottomRight *= B; - this.colorBlueTopRight *= B; - CustomOreBlockRenderer.renderFaceXNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - } - - flag = true; - } - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos + 1, yPos, zPos, 5)) { - if (this.renderMaxX >= 1.0D) { - ++xPos; - } - - this.aoLightValueScratchXYPN = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZPN = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZPP = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXYPP = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - this.aoBrightnessXZPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - this.aoBrightnessXZPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - this.aoBrightnessXYPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - flag2 = blockAccess.getBlock(xPos + 1, yPos + 1, zPos) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos + 1, yPos - 1, zPos) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos + 1, yPos, zPos + 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos + 1, yPos, zPos - 1) - .getCanBlockGrass(); - - if (!flag3 && !flag5) { - this.aoLightValueScratchXYZPNN = this.aoLightValueScratchXZPN; - this.aoBrightnessXYZPNN = this.aoBrightnessXZPN; - } else { - this.aoLightValueScratchXYZPNN = blockAccess.getBlock(xPos, yPos - 1, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos - 1); - } - - if (!flag3 && !flag4) { - this.aoLightValueScratchXYZPNP = this.aoLightValueScratchXZPP; - this.aoBrightnessXYZPNP = this.aoBrightnessXZPP; - } else { - this.aoLightValueScratchXYZPNP = blockAccess.getBlock(xPos, yPos - 1, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos + 1); - } - - if (!flag2 && !flag5) { - this.aoLightValueScratchXYZPPN = this.aoLightValueScratchXZPN; - this.aoBrightnessXYZPPN = this.aoBrightnessXZPN; - } else { - this.aoLightValueScratchXYZPPN = blockAccess.getBlock(xPos, yPos + 1, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos - 1); - } - - if (!flag2 && !flag4) { - this.aoLightValueScratchXYZPPP = this.aoLightValueScratchXZPP; - this.aoBrightnessXYZPPP = this.aoBrightnessXZPP; - } else { - this.aoLightValueScratchXYZPPP = blockAccess.getBlock(xPos, yPos + 1, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos + 1); - } - - if (this.renderMaxX >= 1.0D) { - --xPos; - } - - i1 = l; - - if (this.renderMaxX >= 1.0D || !blockAccess.getBlock(xPos + 1, yPos, zPos) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - } - - f7 = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - f3 = (this.aoLightValueScratchXYPN + this.aoLightValueScratchXYZPNP + f7 + this.aoLightValueScratchXZPP) - / 4.0F; - f4 = (this.aoLightValueScratchXYZPNN + this.aoLightValueScratchXYPN + this.aoLightValueScratchXZPN + f7) - / 4.0F; - f5 = (this.aoLightValueScratchXZPN + f7 + this.aoLightValueScratchXYZPPN + this.aoLightValueScratchXYPP) - / 4.0F; - f6 = (f7 + this.aoLightValueScratchXZPP + this.aoLightValueScratchXYPP + this.aoLightValueScratchXYZPPP) - / 4.0F; - this.brightnessTopLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYPN, this.aoBrightnessXYZPNP, this.aoBrightnessXZPP, i1); - this.brightnessTopRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZPP, this.aoBrightnessXYPP, this.aoBrightnessXYZPPP, i1); - this.brightnessBottomRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZPN, this.aoBrightnessXYZPPN, this.aoBrightnessXYPP, i1); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZPNN, this.aoBrightnessXYPN, this.aoBrightnessXZPN, i1); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.6F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.6F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.6F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.6F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.6F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.6F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - iicon = this.getBlockIcon(block, blockAccess, xPos, yPos, zPos, 5); - CustomOreBlockRenderer.renderFaceXPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - - RenderBlocks.getInstance(); - if (RenderBlocks.fancyGrass && iicon.getIconName() - .equals("grass_side") && !this.hasOverrideBlockTexture()) { - this.colorRedTopLeft *= R; - this.colorRedBottomLeft *= R; - this.colorRedBottomRight *= R; - this.colorRedTopRight *= R; - this.colorGreenTopLeft *= G; - this.colorGreenBottomLeft *= G; - this.colorGreenBottomRight *= G; - this.colorGreenTopRight *= G; - this.colorBlueTopLeft *= B; - this.colorBlueBottomLeft *= B; - this.colorBlueBottomRight *= B; - this.colorBlueTopRight *= B; - CustomOreBlockRenderer.renderFaceXPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - } - - flag = true; - } - - this.enableAO = false; - return flag; - } - - /** - * Renders non-full-cube block with ambient occusion. Args: block, x, y, z, red, green, blue (lighting) - */ - public boolean renderStandardBlockWithAmbientOcclusionPartial(IBlockAccess aWorld, RenderBlocks aRenderer, - ITexture[][] aTextures, Block block, int xPos, int yPos, int zPos, float R, float G, float B) { - this.enableAO = true; - boolean flag = false; - float f3 = 0.0F; - float f4 = 0.0F; - float f5 = 0.0F; - float f6 = 0.0F; - boolean flag1 = true; - int l = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos); - Tessellator tessellator = Tessellator.instance; - tessellator.setBrightness(983055); - - if (this.getBlockIcon(block) - .getIconName() - .equals("grass_top")) { - flag1 = false; - } else if (this.hasOverrideBlockTexture()) { - flag1 = false; - } - - boolean flag2; - boolean flag3; - boolean flag4; - boolean flag5; - int i1; - float f7; - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos, yPos - 1, zPos, 0)) { - if (this.renderMinY <= 0.0D) { - --yPos; - } - - this.aoBrightnessXYNN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - this.aoBrightnessYZNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - this.aoBrightnessYZNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - this.aoBrightnessXYPN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - this.aoLightValueScratchXYNN = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZNN = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZNP = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXYPN = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - flag2 = blockAccess.getBlock(xPos + 1, yPos - 1, zPos) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos - 1, zPos) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos, yPos - 1, zPos + 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos, yPos - 1, zPos - 1) - .getCanBlockGrass(); - - if (!flag5 && !flag3) { - this.aoLightValueScratchXYZNNN = this.aoLightValueScratchXYNN; - this.aoBrightnessXYZNNN = this.aoBrightnessXYNN; - } else { - this.aoLightValueScratchXYZNNN = blockAccess.getBlock(xPos - 1, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos - 1); - } - - if (!flag4 && !flag3) { - this.aoLightValueScratchXYZNNP = this.aoLightValueScratchXYNN; - this.aoBrightnessXYZNNP = this.aoBrightnessXYNN; - } else { - this.aoLightValueScratchXYZNNP = blockAccess.getBlock(xPos - 1, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos + 1); - } - - if (!flag5 && !flag2) { - this.aoLightValueScratchXYZPNN = this.aoLightValueScratchXYPN; - this.aoBrightnessXYZPNN = this.aoBrightnessXYPN; - } else { - this.aoLightValueScratchXYZPNN = blockAccess.getBlock(xPos + 1, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos - 1); - } - - if (!flag4 && !flag2) { - this.aoLightValueScratchXYZPNP = this.aoLightValueScratchXYPN; - this.aoBrightnessXYZPNP = this.aoBrightnessXYPN; - } else { - this.aoLightValueScratchXYZPNP = blockAccess.getBlock(xPos + 1, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos + 1); - } - - if (this.renderMinY <= 0.0D) { - ++yPos; - } - - i1 = l; - - if (this.renderMinY <= 0.0D || !blockAccess.getBlock(xPos, yPos - 1, zPos) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - } - - f7 = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - f3 = (this.aoLightValueScratchXYZNNP + this.aoLightValueScratchXYNN + this.aoLightValueScratchYZNP + f7) - / 4.0F; - f6 = (this.aoLightValueScratchYZNP + f7 + this.aoLightValueScratchXYZPNP + this.aoLightValueScratchXYPN) - / 4.0F; - f5 = (f7 + this.aoLightValueScratchYZNN + this.aoLightValueScratchXYPN + this.aoLightValueScratchXYZPNN) - / 4.0F; - f4 = (this.aoLightValueScratchXYNN + this.aoLightValueScratchXYZNNN + f7 + this.aoLightValueScratchYZNN) - / 4.0F; - this.brightnessTopLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNNP, this.aoBrightnessXYNN, this.aoBrightnessYZNP, i1); - this.brightnessTopRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZNP, this.aoBrightnessXYZPNP, this.aoBrightnessXYPN, i1); - this.brightnessBottomRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZNN, this.aoBrightnessXYPN, this.aoBrightnessXYZPNN, i1); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYNN, this.aoBrightnessXYZNNN, this.aoBrightnessYZNN, i1); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.5F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.5F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.5F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.5F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.5F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.5F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - CustomOreBlockRenderer.renderFaceYNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - flag = true; - } - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos, yPos + 1, zPos, 1)) { - if (this.renderMaxY >= 1.0D) { - ++yPos; - } - - this.aoBrightnessXYNP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - this.aoBrightnessXYPP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - this.aoBrightnessYZPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - this.aoBrightnessYZPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - this.aoLightValueScratchXYNP = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXYPP = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZPN = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZPP = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - flag2 = blockAccess.getBlock(xPos + 1, yPos + 1, zPos) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos + 1, zPos) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos, yPos + 1, zPos + 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos, yPos + 1, zPos - 1) - .getCanBlockGrass(); - - if (!flag5 && !flag3) { - this.aoLightValueScratchXYZNPN = this.aoLightValueScratchXYNP; - this.aoBrightnessXYZNPN = this.aoBrightnessXYNP; - } else { - this.aoLightValueScratchXYZNPN = blockAccess.getBlock(xPos - 1, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos - 1); - } - - if (!flag5 && !flag2) { - this.aoLightValueScratchXYZPPN = this.aoLightValueScratchXYPP; - this.aoBrightnessXYZPPN = this.aoBrightnessXYPP; - } else { - this.aoLightValueScratchXYZPPN = blockAccess.getBlock(xPos + 1, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos - 1); - } - - if (!flag4 && !flag3) { - this.aoLightValueScratchXYZNPP = this.aoLightValueScratchXYNP; - this.aoBrightnessXYZNPP = this.aoBrightnessXYNP; - } else { - this.aoLightValueScratchXYZNPP = blockAccess.getBlock(xPos - 1, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos + 1); - } - - if (!flag4 && !flag2) { - this.aoLightValueScratchXYZPPP = this.aoLightValueScratchXYPP; - this.aoBrightnessXYZPPP = this.aoBrightnessXYPP; - } else { - this.aoLightValueScratchXYZPPP = blockAccess.getBlock(xPos + 1, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos + 1); - } - - if (this.renderMaxY >= 1.0D) { - --yPos; - } - - i1 = l; - - if (this.renderMaxY >= 1.0D || !blockAccess.getBlock(xPos, yPos + 1, zPos) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - } - - f7 = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - f6 = (this.aoLightValueScratchXYZNPP + this.aoLightValueScratchXYNP + this.aoLightValueScratchYZPP + f7) - / 4.0F; - f3 = (this.aoLightValueScratchYZPP + f7 + this.aoLightValueScratchXYZPPP + this.aoLightValueScratchXYPP) - / 4.0F; - f4 = (f7 + this.aoLightValueScratchYZPN + this.aoLightValueScratchXYPP + this.aoLightValueScratchXYZPPN) - / 4.0F; - f5 = (this.aoLightValueScratchXYNP + this.aoLightValueScratchXYZNPN + f7 + this.aoLightValueScratchYZPN) - / 4.0F; - this.brightnessTopRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNPP, this.aoBrightnessXYNP, this.aoBrightnessYZPP, i1); - this.brightnessTopLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZPP, this.aoBrightnessXYZPPP, this.aoBrightnessXYPP, i1); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZPN, this.aoBrightnessXYPP, this.aoBrightnessXYZPPN, i1); - this.brightnessBottomRight = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYNP, this.aoBrightnessXYZNPN, this.aoBrightnessYZPN, i1); - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B; - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - CustomOreBlockRenderer.renderFaceYPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - flag = true; - } - - float f8; - float f9; - float f10; - float f11; - int j1; - int k1; - int l1; - int i2; - IIcon iicon; - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos, yPos, zPos - 1, 2)) { - if (this.renderMinZ <= 0.0D) { - --zPos; - } - - this.aoLightValueScratchXZNN = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZNN = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZPN = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZPN = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXZNN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - this.aoBrightnessYZNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - this.aoBrightnessYZPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - this.aoBrightnessXZPN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - flag2 = blockAccess.getBlock(xPos + 1, yPos, zPos - 1) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos, zPos - 1) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos, yPos + 1, zPos - 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos, yPos - 1, zPos - 1) - .getCanBlockGrass(); - - if (!flag3 && !flag5) { - this.aoLightValueScratchXYZNNN = this.aoLightValueScratchXZNN; - this.aoBrightnessXYZNNN = this.aoBrightnessXZNN; - } else { - this.aoLightValueScratchXYZNNN = blockAccess.getBlock(xPos - 1, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos - 1, zPos); - } - - if (!flag3 && !flag4) { - this.aoLightValueScratchXYZNPN = this.aoLightValueScratchXZNN; - this.aoBrightnessXYZNPN = this.aoBrightnessXZNN; - } else { - this.aoLightValueScratchXYZNPN = blockAccess.getBlock(xPos - 1, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos + 1, zPos); - } - - if (!flag2 && !flag5) { - this.aoLightValueScratchXYZPNN = this.aoLightValueScratchXZPN; - this.aoBrightnessXYZPNN = this.aoBrightnessXZPN; - } else { - this.aoLightValueScratchXYZPNN = blockAccess.getBlock(xPos + 1, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos - 1, zPos); - } - - if (!flag2 && !flag4) { - this.aoLightValueScratchXYZPPN = this.aoLightValueScratchXZPN; - this.aoBrightnessXYZPPN = this.aoBrightnessXZPN; - } else { - this.aoLightValueScratchXYZPPN = blockAccess.getBlock(xPos + 1, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos + 1, zPos); - } - - if (this.renderMinZ <= 0.0D) { - ++zPos; - } - - i1 = l; - - if (this.renderMinZ <= 0.0D || !blockAccess.getBlock(xPos, yPos, zPos - 1) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - } - - f7 = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - f8 = (this.aoLightValueScratchXZNN + this.aoLightValueScratchXYZNPN + f7 + this.aoLightValueScratchYZPN) - / 4.0F; - f9 = (f7 + this.aoLightValueScratchYZPN + this.aoLightValueScratchXZPN + this.aoLightValueScratchXYZPPN) - / 4.0F; - f10 = (this.aoLightValueScratchYZNN + f7 + this.aoLightValueScratchXYZPNN + this.aoLightValueScratchXZPN) - / 4.0F; - f11 = (this.aoLightValueScratchXYZNNN + this.aoLightValueScratchXZNN + this.aoLightValueScratchYZNN + f7) - / 4.0F; - f3 = (float) ((double) f8 * this.renderMaxY * (1.0D - this.renderMinX) - + (double) f9 * this.renderMaxY * this.renderMinX - + (double) f10 * (1.0D - this.renderMaxY) * this.renderMinX - + (double) f11 * (1.0D - this.renderMaxY) * (1.0D - this.renderMinX)); - f4 = (float) ((double) f8 * this.renderMaxY * (1.0D - this.renderMaxX) - + (double) f9 * this.renderMaxY * this.renderMaxX - + (double) f10 * (1.0D - this.renderMaxY) * this.renderMaxX - + (double) f11 * (1.0D - this.renderMaxY) * (1.0D - this.renderMaxX)); - f5 = (float) ((double) f8 * this.renderMinY * (1.0D - this.renderMaxX) - + (double) f9 * this.renderMinY * this.renderMaxX - + (double) f10 * (1.0D - this.renderMinY) * this.renderMaxX - + (double) f11 * (1.0D - this.renderMinY) * (1.0D - this.renderMaxX)); - f6 = (float) ((double) f8 * this.renderMinY * (1.0D - this.renderMinX) - + (double) f9 * this.renderMinY * this.renderMinX - + (double) f10 * (1.0D - this.renderMinY) * this.renderMinX - + (double) f11 * (1.0D - this.renderMinY) * (1.0D - this.renderMinX)); - j1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZNN, this.aoBrightnessXYZNPN, this.aoBrightnessYZPN, i1); - k1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZPN, this.aoBrightnessXZPN, this.aoBrightnessXYZPPN, i1); - l1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZNN, this.aoBrightnessXYZPNN, this.aoBrightnessXZPN, i1); - i2 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNNN, this.aoBrightnessXZNN, this.aoBrightnessYZNN, i1); - this.brightnessTopLeft = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - k1, - l1, - i2, - this.renderMaxY * (1.0D - this.renderMinX), - this.renderMaxY * this.renderMinX, - (1.0D - this.renderMaxY) * this.renderMinX, - (1.0D - this.renderMaxY) * (1.0D - this.renderMinX)); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - k1, - l1, - i2, - this.renderMaxY * (1.0D - this.renderMaxX), - this.renderMaxY * this.renderMaxX, - (1.0D - this.renderMaxY) * this.renderMaxX, - (1.0D - this.renderMaxY) * (1.0D - this.renderMaxX)); - this.brightnessBottomRight = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - k1, - l1, - i2, - this.renderMinY * (1.0D - this.renderMaxX), - this.renderMinY * this.renderMaxX, - (1.0D - this.renderMinY) * this.renderMaxX, - (1.0D - this.renderMinY) * (1.0D - this.renderMaxX)); - this.brightnessTopRight = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - k1, - l1, - i2, - this.renderMinY * (1.0D - this.renderMinX), - this.renderMinY * this.renderMinX, - (1.0D - this.renderMinY) * this.renderMinX, - (1.0D - this.renderMinY) * (1.0D - this.renderMinX)); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.8F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.8F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.8F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.8F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.8F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.8F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - iicon = this.getBlockIcon(block, blockAccess, xPos, yPos, zPos, 2); - CustomOreBlockRenderer.renderFaceZNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - - RenderBlocks.getInstance(); - if (RenderBlocks.fancyGrass && iicon.getIconName() - .equals("grass_side") && !this.hasOverrideBlockTexture()) { - this.colorRedTopLeft *= R; - this.colorRedBottomLeft *= R; - this.colorRedBottomRight *= R; - this.colorRedTopRight *= R; - this.colorGreenTopLeft *= G; - this.colorGreenBottomLeft *= G; - this.colorGreenBottomRight *= G; - this.colorGreenTopRight *= G; - this.colorBlueTopLeft *= B; - this.colorBlueBottomLeft *= B; - this.colorBlueBottomRight *= B; - this.colorBlueTopRight *= B; - CustomOreBlockRenderer.renderFaceZNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - } - - flag = true; - } - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos, yPos, zPos + 1, 3)) { - if (this.renderMaxZ >= 1.0D) { - ++zPos; - } - - this.aoLightValueScratchXZNP = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZPP = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZNP = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchYZPP = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXZNP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - this.aoBrightnessXZPP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - this.aoBrightnessYZNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - this.aoBrightnessYZPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - flag2 = blockAccess.getBlock(xPos + 1, yPos, zPos + 1) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos, zPos + 1) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos, yPos + 1, zPos + 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos, yPos - 1, zPos + 1) - .getCanBlockGrass(); - - if (!flag3 && !flag5) { - this.aoLightValueScratchXYZNNP = this.aoLightValueScratchXZNP; - this.aoBrightnessXYZNNP = this.aoBrightnessXZNP; - } else { - this.aoLightValueScratchXYZNNP = blockAccess.getBlock(xPos - 1, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos - 1, zPos); - } - - if (!flag3 && !flag4) { - this.aoLightValueScratchXYZNPP = this.aoLightValueScratchXZNP; - this.aoBrightnessXYZNPP = this.aoBrightnessXZNP; - } else { - this.aoLightValueScratchXYZNPP = blockAccess.getBlock(xPos - 1, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos + 1, zPos); - } - - if (!flag2 && !flag5) { - this.aoLightValueScratchXYZPNP = this.aoLightValueScratchXZPP; - this.aoBrightnessXYZPNP = this.aoBrightnessXZPP; - } else { - this.aoLightValueScratchXYZPNP = blockAccess.getBlock(xPos + 1, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos - 1, zPos); - } - - if (!flag2 && !flag4) { - this.aoLightValueScratchXYZPPP = this.aoLightValueScratchXZPP; - this.aoBrightnessXYZPPP = this.aoBrightnessXZPP; - } else { - this.aoLightValueScratchXYZPPP = blockAccess.getBlock(xPos + 1, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos + 1, zPos); - } - - if (this.renderMaxZ >= 1.0D) { - --zPos; - } - - i1 = l; - - if (this.renderMaxZ >= 1.0D || !blockAccess.getBlock(xPos, yPos, zPos + 1) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - } - - f7 = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - f8 = (this.aoLightValueScratchXZNP + this.aoLightValueScratchXYZNPP + f7 + this.aoLightValueScratchYZPP) - / 4.0F; - f9 = (f7 + this.aoLightValueScratchYZPP + this.aoLightValueScratchXZPP + this.aoLightValueScratchXYZPPP) - / 4.0F; - f10 = (this.aoLightValueScratchYZNP + f7 + this.aoLightValueScratchXYZPNP + this.aoLightValueScratchXZPP) - / 4.0F; - f11 = (this.aoLightValueScratchXYZNNP + this.aoLightValueScratchXZNP + this.aoLightValueScratchYZNP + f7) - / 4.0F; - f3 = (float) ((double) f8 * this.renderMaxY * (1.0D - this.renderMinX) - + (double) f9 * this.renderMaxY * this.renderMinX - + (double) f10 * (1.0D - this.renderMaxY) * this.renderMinX - + (double) f11 * (1.0D - this.renderMaxY) * (1.0D - this.renderMinX)); - f4 = (float) ((double) f8 * this.renderMinY * (1.0D - this.renderMinX) - + (double) f9 * this.renderMinY * this.renderMinX - + (double) f10 * (1.0D - this.renderMinY) * this.renderMinX - + (double) f11 * (1.0D - this.renderMinY) * (1.0D - this.renderMinX)); - f5 = (float) ((double) f8 * this.renderMinY * (1.0D - this.renderMaxX) - + (double) f9 * this.renderMinY * this.renderMaxX - + (double) f10 * (1.0D - this.renderMinY) * this.renderMaxX - + (double) f11 * (1.0D - this.renderMinY) * (1.0D - this.renderMaxX)); - f6 = (float) ((double) f8 * this.renderMaxY * (1.0D - this.renderMaxX) - + (double) f9 * this.renderMaxY * this.renderMaxX - + (double) f10 * (1.0D - this.renderMaxY) * this.renderMaxX - + (double) f11 * (1.0D - this.renderMaxY) * (1.0D - this.renderMaxX)); - j1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZNP, this.aoBrightnessXYZNPP, this.aoBrightnessYZPP, i1); - k1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZPP, this.aoBrightnessXZPP, this.aoBrightnessXYZPPP, i1); - l1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessYZNP, this.aoBrightnessXYZPNP, this.aoBrightnessXZPP, i1); - i2 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNNP, this.aoBrightnessXZNP, this.aoBrightnessYZNP, i1); - this.brightnessTopLeft = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - i2, - l1, - k1, - this.renderMaxY * (1.0D - this.renderMinX), - (1.0D - this.renderMaxY) * (1.0D - this.renderMinX), - (1.0D - this.renderMaxY) * this.renderMinX, - this.renderMaxY * this.renderMinX); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - i2, - l1, - k1, - this.renderMinY * (1.0D - this.renderMinX), - (1.0D - this.renderMinY) * (1.0D - this.renderMinX), - (1.0D - this.renderMinY) * this.renderMinX, - this.renderMinY * this.renderMinX); - this.brightnessBottomRight = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - i2, - l1, - k1, - this.renderMinY * (1.0D - this.renderMaxX), - (1.0D - this.renderMinY) * (1.0D - this.renderMaxX), - (1.0D - this.renderMinY) * this.renderMaxX, - this.renderMinY * this.renderMaxX); - this.brightnessTopRight = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - i2, - l1, - k1, - this.renderMaxY * (1.0D - this.renderMaxX), - (1.0D - this.renderMaxY) * (1.0D - this.renderMaxX), - (1.0D - this.renderMaxY) * this.renderMaxX, - this.renderMaxY * this.renderMaxX); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.8F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.8F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.8F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.8F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.8F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.8F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - iicon = this.getBlockIcon(block, blockAccess, xPos, yPos, zPos, 3); - CustomOreBlockRenderer.renderFaceZPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - - RenderBlocks.getInstance(); - if (RenderBlocks.fancyGrass && iicon.getIconName() - .equals("grass_side") && !this.hasOverrideBlockTexture()) { - this.colorRedTopLeft *= R; - this.colorRedBottomLeft *= R; - this.colorRedBottomRight *= R; - this.colorRedTopRight *= R; - this.colorGreenTopLeft *= G; - this.colorGreenBottomLeft *= G; - this.colorGreenBottomRight *= G; - this.colorGreenTopRight *= G; - this.colorBlueTopLeft *= B; - this.colorBlueBottomLeft *= B; - this.colorBlueBottomRight *= B; - this.colorBlueTopRight *= B; - CustomOreBlockRenderer.renderFaceZPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - } - - flag = true; - } - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos - 1, yPos, zPos, 4)) { - if (this.renderMinX <= 0.0D) { - --xPos; - } - - this.aoLightValueScratchXYNN = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZNN = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZNP = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXYNP = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - this.aoBrightnessXZNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - this.aoBrightnessXZNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - this.aoBrightnessXYNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - flag2 = blockAccess.getBlock(xPos - 1, yPos + 1, zPos) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos - 1, yPos - 1, zPos) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos - 1, yPos, zPos - 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos - 1, yPos, zPos + 1) - .getCanBlockGrass(); - - if (!flag4 && !flag3) { - this.aoLightValueScratchXYZNNN = this.aoLightValueScratchXZNN; - this.aoBrightnessXYZNNN = this.aoBrightnessXZNN; - } else { - this.aoLightValueScratchXYZNNN = blockAccess.getBlock(xPos, yPos - 1, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos - 1); - } - - if (!flag5 && !flag3) { - this.aoLightValueScratchXYZNNP = this.aoLightValueScratchXZNP; - this.aoBrightnessXYZNNP = this.aoBrightnessXZNP; - } else { - this.aoLightValueScratchXYZNNP = blockAccess.getBlock(xPos, yPos - 1, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos + 1); - } - - if (!flag4 && !flag2) { - this.aoLightValueScratchXYZNPN = this.aoLightValueScratchXZNN; - this.aoBrightnessXYZNPN = this.aoBrightnessXZNN; - } else { - this.aoLightValueScratchXYZNPN = blockAccess.getBlock(xPos, yPos + 1, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos - 1); - } - - if (!flag5 && !flag2) { - this.aoLightValueScratchXYZNPP = this.aoLightValueScratchXZNP; - this.aoBrightnessXYZNPP = this.aoBrightnessXZNP; - } else { - this.aoLightValueScratchXYZNPP = blockAccess.getBlock(xPos, yPos + 1, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos + 1); - } - - if (this.renderMinX <= 0.0D) { - ++xPos; - } - - i1 = l; - - if (this.renderMinX <= 0.0D || !blockAccess.getBlock(xPos - 1, yPos, zPos) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos - 1, yPos, zPos); - } - - f7 = blockAccess.getBlock(xPos - 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - f8 = (this.aoLightValueScratchXYNN + this.aoLightValueScratchXYZNNP + f7 + this.aoLightValueScratchXZNP) - / 4.0F; - f9 = (f7 + this.aoLightValueScratchXZNP + this.aoLightValueScratchXYNP + this.aoLightValueScratchXYZNPP) - / 4.0F; - f10 = (this.aoLightValueScratchXZNN + f7 + this.aoLightValueScratchXYZNPN + this.aoLightValueScratchXYNP) - / 4.0F; - f11 = (this.aoLightValueScratchXYZNNN + this.aoLightValueScratchXYNN + this.aoLightValueScratchXZNN + f7) - / 4.0F; - f3 = (float) ((double) f9 * this.renderMaxY * this.renderMaxZ - + (double) f10 * this.renderMaxY * (1.0D - this.renderMaxZ) - + (double) f11 * (1.0D - this.renderMaxY) * (1.0D - this.renderMaxZ) - + (double) f8 * (1.0D - this.renderMaxY) * this.renderMaxZ); - f4 = (float) ((double) f9 * this.renderMaxY * this.renderMinZ - + (double) f10 * this.renderMaxY * (1.0D - this.renderMinZ) - + (double) f11 * (1.0D - this.renderMaxY) * (1.0D - this.renderMinZ) - + (double) f8 * (1.0D - this.renderMaxY) * this.renderMinZ); - f5 = (float) ((double) f9 * this.renderMinY * this.renderMinZ - + (double) f10 * this.renderMinY * (1.0D - this.renderMinZ) - + (double) f11 * (1.0D - this.renderMinY) * (1.0D - this.renderMinZ) - + (double) f8 * (1.0D - this.renderMinY) * this.renderMinZ); - f6 = (float) ((double) f9 * this.renderMinY * this.renderMaxZ - + (double) f10 * this.renderMinY * (1.0D - this.renderMaxZ) - + (double) f11 * (1.0D - this.renderMinY) * (1.0D - this.renderMaxZ) - + (double) f8 * (1.0D - this.renderMinY) * this.renderMaxZ); - j1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYNN, this.aoBrightnessXYZNNP, this.aoBrightnessXZNP, i1); - k1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZNP, this.aoBrightnessXYNP, this.aoBrightnessXYZNPP, i1); - l1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZNN, this.aoBrightnessXYZNPN, this.aoBrightnessXYNP, i1); - i2 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZNNN, this.aoBrightnessXYNN, this.aoBrightnessXZNN, i1); - this.brightnessTopLeft = RenderBlocks.getInstance() - .mixAoBrightness( - k1, - l1, - i2, - j1, - this.renderMaxY * this.renderMaxZ, - this.renderMaxY * (1.0D - this.renderMaxZ), - (1.0D - this.renderMaxY) * (1.0D - this.renderMaxZ), - (1.0D - this.renderMaxY) * this.renderMaxZ); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .mixAoBrightness( - k1, - l1, - i2, - j1, - this.renderMaxY * this.renderMinZ, - this.renderMaxY * (1.0D - this.renderMinZ), - (1.0D - this.renderMaxY) * (1.0D - this.renderMinZ), - (1.0D - this.renderMaxY) * this.renderMinZ); - this.brightnessBottomRight = RenderBlocks.getInstance() - .mixAoBrightness( - k1, - l1, - i2, - j1, - this.renderMinY * this.renderMinZ, - this.renderMinY * (1.0D - this.renderMinZ), - (1.0D - this.renderMinY) * (1.0D - this.renderMinZ), - (1.0D - this.renderMinY) * this.renderMinZ); - this.brightnessTopRight = RenderBlocks.getInstance() - .mixAoBrightness( - k1, - l1, - i2, - j1, - this.renderMinY * this.renderMaxZ, - this.renderMinY * (1.0D - this.renderMaxZ), - (1.0D - this.renderMinY) * (1.0D - this.renderMaxZ), - (1.0D - this.renderMinY) * this.renderMaxZ); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.6F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.6F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.6F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.6F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.6F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.6F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - iicon = this.getBlockIcon(block, blockAccess, xPos, yPos, zPos, 4); - CustomOreBlockRenderer.renderFaceXNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - - RenderBlocks.getInstance(); - if (RenderBlocks.fancyGrass && iicon.getIconName() - .equals("grass_side") && !this.hasOverrideBlockTexture()) { - this.colorRedTopLeft *= R; - this.colorRedBottomLeft *= R; - this.colorRedBottomRight *= R; - this.colorRedTopRight *= R; - this.colorGreenTopLeft *= G; - this.colorGreenBottomLeft *= G; - this.colorGreenBottomRight *= G; - this.colorGreenTopRight *= G; - this.colorBlueTopLeft *= B; - this.colorBlueBottomLeft *= B; - this.colorBlueBottomRight *= B; - this.colorBlueTopRight *= B; - CustomOreBlockRenderer.renderFaceXNeg(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - } - - flag = true; - } - - if (RenderBlocks.getInstance().renderAllFaces - || block.shouldSideBeRendered(blockAccess, xPos + 1, yPos, zPos, 5)) { - if (this.renderMaxX >= 1.0D) { - ++xPos; - } - - this.aoLightValueScratchXYPN = blockAccess.getBlock(xPos, yPos - 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZPN = blockAccess.getBlock(xPos, yPos, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXZPP = blockAccess.getBlock(xPos, yPos, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoLightValueScratchXYPP = blockAccess.getBlock(xPos, yPos + 1, zPos) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos); - this.aoBrightnessXZPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos - 1); - this.aoBrightnessXZPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos, zPos + 1); - this.aoBrightnessXYPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos); - flag2 = blockAccess.getBlock(xPos + 1, yPos + 1, zPos) - .getCanBlockGrass(); - flag3 = blockAccess.getBlock(xPos + 1, yPos - 1, zPos) - .getCanBlockGrass(); - flag4 = blockAccess.getBlock(xPos + 1, yPos, zPos + 1) - .getCanBlockGrass(); - flag5 = blockAccess.getBlock(xPos + 1, yPos, zPos - 1) - .getCanBlockGrass(); - - if (!flag3 && !flag5) { - this.aoLightValueScratchXYZPNN = this.aoLightValueScratchXZPN; - this.aoBrightnessXYZPNN = this.aoBrightnessXZPN; - } else { - this.aoLightValueScratchXYZPNN = blockAccess.getBlock(xPos, yPos - 1, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos - 1); - } - - if (!flag3 && !flag4) { - this.aoLightValueScratchXYZPNP = this.aoLightValueScratchXZPP; - this.aoBrightnessXYZPNP = this.aoBrightnessXZPP; - } else { - this.aoLightValueScratchXYZPNP = blockAccess.getBlock(xPos, yPos - 1, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos - 1, zPos + 1); - } - - if (!flag2 && !flag5) { - this.aoLightValueScratchXYZPPN = this.aoLightValueScratchXZPN; - this.aoBrightnessXYZPPN = this.aoBrightnessXZPN; - } else { - this.aoLightValueScratchXYZPPN = blockAccess.getBlock(xPos, yPos + 1, zPos - 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos - 1); - } - - if (!flag2 && !flag4) { - this.aoLightValueScratchXYZPPP = this.aoLightValueScratchXZPP; - this.aoBrightnessXYZPPP = this.aoBrightnessXZPP; - } else { - this.aoLightValueScratchXYZPPP = blockAccess.getBlock(xPos, yPos + 1, zPos + 1) - .getAmbientOcclusionLightValue(); - this.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(blockAccess, xPos, yPos + 1, zPos + 1); - } - - if (this.renderMaxX >= 1.0D) { - --xPos; - } - - i1 = l; - - if (this.renderMaxX >= 1.0D || !blockAccess.getBlock(xPos + 1, yPos, zPos) - .isOpaqueCube()) { - i1 = block.getMixedBrightnessForBlock(blockAccess, xPos + 1, yPos, zPos); - } - - f7 = blockAccess.getBlock(xPos + 1, yPos, zPos) - .getAmbientOcclusionLightValue(); - f8 = (this.aoLightValueScratchXYPN + this.aoLightValueScratchXYZPNP + f7 + this.aoLightValueScratchXZPP) - / 4.0F; - f9 = (this.aoLightValueScratchXYZPNN + this.aoLightValueScratchXYPN + this.aoLightValueScratchXZPN + f7) - / 4.0F; - f10 = (this.aoLightValueScratchXZPN + f7 + this.aoLightValueScratchXYZPPN + this.aoLightValueScratchXYPP) - / 4.0F; - f11 = (f7 + this.aoLightValueScratchXZPP + this.aoLightValueScratchXYPP + this.aoLightValueScratchXYZPPP) - / 4.0F; - f3 = (float) ((double) f8 * (1.0D - this.renderMinY) * this.renderMaxZ - + (double) f9 * (1.0D - this.renderMinY) * (1.0D - this.renderMaxZ) - + (double) f10 * this.renderMinY * (1.0D - this.renderMaxZ) - + (double) f11 * this.renderMinY * this.renderMaxZ); - f4 = (float) ((double) f8 * (1.0D - this.renderMinY) * this.renderMinZ - + (double) f9 * (1.0D - this.renderMinY) * (1.0D - this.renderMinZ) - + (double) f10 * this.renderMinY * (1.0D - this.renderMinZ) - + (double) f11 * this.renderMinY * this.renderMinZ); - f5 = (float) ((double) f8 * (1.0D - this.renderMaxY) * this.renderMinZ - + (double) f9 * (1.0D - this.renderMaxY) * (1.0D - this.renderMinZ) - + (double) f10 * this.renderMaxY * (1.0D - this.renderMinZ) - + (double) f11 * this.renderMaxY * this.renderMinZ); - f6 = (float) ((double) f8 * (1.0D - this.renderMaxY) * this.renderMaxZ - + (double) f9 * (1.0D - this.renderMaxY) * (1.0D - this.renderMaxZ) - + (double) f10 * this.renderMaxY * (1.0D - this.renderMaxZ) - + (double) f11 * this.renderMaxY * this.renderMaxZ); - j1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYPN, this.aoBrightnessXYZPNP, this.aoBrightnessXZPP, i1); - k1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZPP, this.aoBrightnessXYPP, this.aoBrightnessXYZPPP, i1); - l1 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXZPN, this.aoBrightnessXYZPPN, this.aoBrightnessXYPP, i1); - i2 = RenderBlocks.getInstance() - .getAoBrightness(this.aoBrightnessXYZPNN, this.aoBrightnessXYPN, this.aoBrightnessXZPN, i1); - this.brightnessTopLeft = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - i2, - l1, - k1, - (1.0D - this.renderMinY) * this.renderMaxZ, - (1.0D - this.renderMinY) * (1.0D - this.renderMaxZ), - this.renderMinY * (1.0D - this.renderMaxZ), - this.renderMinY * this.renderMaxZ); - this.brightnessBottomLeft = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - i2, - l1, - k1, - (1.0D - this.renderMinY) * this.renderMinZ, - (1.0D - this.renderMinY) * (1.0D - this.renderMinZ), - this.renderMinY * (1.0D - this.renderMinZ), - this.renderMinY * this.renderMinZ); - this.brightnessBottomRight = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - i2, - l1, - k1, - (1.0D - this.renderMaxY) * this.renderMinZ, - (1.0D - this.renderMaxY) * (1.0D - this.renderMinZ), - this.renderMaxY * (1.0D - this.renderMinZ), - this.renderMaxY * this.renderMinZ); - this.brightnessTopRight = RenderBlocks.getInstance() - .mixAoBrightness( - j1, - i2, - l1, - k1, - (1.0D - this.renderMaxY) * this.renderMaxZ, - (1.0D - this.renderMaxY) * (1.0D - this.renderMaxZ), - this.renderMaxY * (1.0D - this.renderMaxZ), - this.renderMaxY * this.renderMaxZ); - - if (flag1) { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = R - * 0.6F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = G - * 0.6F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = B - * 0.6F; - } else { - this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = 0.6F; - this.colorGreenTopLeft = this.colorGreenBottomLeft = this.colorGreenBottomRight = this.colorGreenTopRight = 0.6F; - this.colorBlueTopLeft = this.colorBlueBottomLeft = this.colorBlueBottomRight = this.colorBlueTopRight = 0.6F; - } - - this.colorRedTopLeft *= f3; - this.colorGreenTopLeft *= f3; - this.colorBlueTopLeft *= f3; - this.colorRedBottomLeft *= f4; - this.colorGreenBottomLeft *= f4; - this.colorBlueBottomLeft *= f4; - this.colorRedBottomRight *= f5; - this.colorGreenBottomRight *= f5; - this.colorBlueBottomRight *= f5; - this.colorRedTopRight *= f6; - this.colorGreenTopRight *= f6; - this.colorBlueTopRight *= f6; - iicon = this.getBlockIcon(block, blockAccess, xPos, yPos, zPos, 5); - CustomOreBlockRenderer.renderFaceXPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - - RenderBlocks.getInstance(); - if (RenderBlocks.fancyGrass && iicon.getIconName() - .equals("grass_side") && !this.hasOverrideBlockTexture()) { - this.colorRedTopLeft *= R; - this.colorRedBottomLeft *= R; - this.colorRedBottomRight *= R; - this.colorRedTopRight *= R; - this.colorGreenTopLeft *= G; - this.colorGreenBottomLeft *= G; - this.colorGreenBottomRight *= G; - this.colorGreenTopRight *= G; - this.colorBlueTopLeft *= B; - this.colorBlueBottomLeft *= B; - this.colorBlueBottomRight *= B; - this.colorBlueTopRight *= B; - CustomOreBlockRenderer.renderFaceXPos(aWorld, aRenderer, block, xPos, yPos, zPos, aTextures); - } - - flag = true; - } - - this.enableAO = false; - return flag; - } -} diff --git a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java index 538436d6108..0e6a08ec77e 100644 --- a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java @@ -1,11 +1,12 @@ package gtPlusPlus.core.item.base.itemblock; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import net.minecraft.block.Block; +import net.minecraft.client.resources.I18n; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; @@ -13,13 +14,14 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.common.WorldgenGTOreLayer; import gtPlusPlus.core.block.base.BlockBaseOre; import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.MaterialStack; import gtPlusPlus.core.util.minecraft.EntityUtils; import gtPlusPlus.core.util.sys.KeyboardUtils; -import gtPlusPlus.everglades.gen.gt.WorldGen_GT_Ore_Layer; public class ItemBlockOre extends ItemBlock { @@ -40,32 +42,27 @@ public ItemBlockOre(final Block block) { } } - private static final Map> mMapOreBlockItemToDimName = new LinkedHashMap<>(); + private static final Map> mMapOreBlockItemToDimName = new LinkedHashMap<>(); private static boolean mInitOres_Everglades = false; - private HashSet mDimsForThisOre = new HashSet<>(); + + private static void initVeinInfo() { + for (WorldgenGTOreLayer oreLayer : WorldgenGTOreLayer.sList) { + IOreMaterial[] mats = { oreLayer.mPrimary, oreLayer.mSecondary, oreLayer.mBetween, oreLayer.mSporadic }; + + for (IOreMaterial mat : mats) { + if (mat instanceof Material gtppMat) { + mMapOreBlockItemToDimName.put(gtppMat, oreLayer.getAllowedDimensions()); + } + } + } + } @Override public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { if (!mInitOres_Everglades) { - for (WorldGen_GT_Ore_Layer f : gtPlusPlus.everglades.gen.gt.WorldGen_Ores.validOreveins.values()) { - Material[] m2 = new Material[] { f.mPrimary, f.mSecondary, f.mBetween, f.mSporadic }; - for (Material m1 : m2) { - HashSet aMap = mMapOreBlockItemToDimName.get( - m1.getUnlocalizedName() - .toLowerCase()); - if (aMap == null) { - aMap = new HashSet<>(); - } - String aDimName = "Everglades"; - aMap.add(aDimName); - mMapOreBlockItemToDimName.put( - m1.getUnlocalizedName() - .toLowerCase(), - aMap); - } - } + initVeinInfo(); mInitOres_Everglades = true; } @@ -102,19 +99,12 @@ public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, fi } } - if (mDimsForThisOre.isEmpty()) { - HashSet A = mMapOreBlockItemToDimName.get( - this.mThisMaterial.getUnlocalizedName() - .toLowerCase()); - if (A != null) { - mDimsForThisOre = A; - } - } + Set dims = mMapOreBlockItemToDimName.get(this.mThisMaterial); - list.add("Found: "); - if (!mDimsForThisOre.isEmpty()) { - for (String m : mDimsForThisOre) { - list.add("- " + m); + list.add("Found:"); + if (dims != null && !dims.isEmpty()) { + for (String m : dims) { + list.add("- " + I18n.format("gtnop.world." + m)); } } else { list.add("- Unknown"); diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java index 01294556f7e..2363b33195b 100644 --- a/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java @@ -56,7 +56,7 @@ public BaseOreComponent(final Material material, final ComponentTypes componentT GameRegistry.registerItem(this, this.unlocalName); registerComponent(); GTOreDictUnificator - .registerOre(componentType.getComponent() + material.getUnlocalizedName(), ItemUtils.getSimpleStack(this)); + .registerOre(componentType.getOrePrefix() + material.getUnlocalizedName(), ItemUtils.getSimpleStack(this)); } public boolean registerComponent() { @@ -227,22 +227,25 @@ public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { public enum ComponentTypes { - DUST("dust", "", " Dust", true), - DUSTIMPURE("dustImpure", "Impure ", " Dust", true), - DUSTPURE("dustPure", "Purified ", " Dust", true), - CRUSHED("crushed", "Crushed ", " Ore", true), - CRUSHEDCENTRIFUGED("crushedCentrifuged", "Centrifuged Crushed ", " Ore", true), - CRUSHEDPURIFIED("crushedPurified", "Purified Crushed ", " Ore", true), - RAWORE("oreRaw", "Raw ", " Ore", true), - MILLED("milled", "Milled ", " Ore", true); + DUST("dust", OrePrefixes.dust, "", " Dust", true), + DUSTIMPURE("dustImpure", OrePrefixes.dustImpure, "Impure ", " Dust", true), + DUSTPURE("dustPure", OrePrefixes.dustPure, "Purified ", " Dust", true), + CRUSHED("crushed", OrePrefixes.crushed, "Crushed ", " Ore", true), + CRUSHEDCENTRIFUGED("crushedCentrifuged", OrePrefixes.crushedCentrifuged, "Centrifuged Crushed ", " Ore", true), + CRUSHEDPURIFIED("crushedPurified", OrePrefixes.crushedPurified, "Purified Crushed ", " Ore", true), + RAWORE("oreRaw", OrePrefixes.rawOre, "Raw ", " Ore", true), + MILLED("milled", OrePrefixes.milled, "Milled ", " Ore", true); private final String COMPONENT_NAME; private final String PREFIX; private final String DISPLAY_NAME; private final boolean HAS_OVERLAY; + private final String orePrefix; - ComponentTypes(final String LocalName, final String prefix, final String DisplayName, final boolean overlay) { + ComponentTypes(final String LocalName, final OrePrefixes orePrefix, final String prefix, + final String DisplayName, final boolean overlay) { this.COMPONENT_NAME = LocalName; + this.orePrefix = orePrefix.name(); this.PREFIX = prefix; this.DISPLAY_NAME = DisplayName; this.HAS_OVERLAY = overlay; @@ -254,6 +257,10 @@ public String getComponent() { return this.COMPONENT_NAME; } + public String getOrePrefix() { + return orePrefix; + } + public String getName() { return this.DISPLAY_NAME; } diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index 0e69ba88d59..f0d16f74a30 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -19,8 +20,12 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; import gregtech.api.enums.TextureSet; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTLanguageManager; +import gregtech.api.util.GTUtility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes; import gtPlusPlus.core.item.base.cell.BaseItemCell; @@ -33,10 +38,11 @@ import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; -public class Material { +public class Material implements IOreMaterial { public static final Set mMaterialMap = new HashSet<>(); public static HashMap mMaterialCache = new HashMap<>(); + public static HashMap mMaterialsByName = new HashMap<>(); public static final Map> mComponentMap = new HashMap<>(); @@ -89,6 +95,9 @@ public class Material { public static ArrayList invalidMaterials = new ArrayList<>(); + /** A cache field for raw ores to prevent constant map lookups. */ + private ItemStack rawOre; + public Material(final String materialName, final MaterialState defaultState, final MaterialStack... inputs) { this(materialName, defaultState, null, inputs); } @@ -383,6 +392,7 @@ public Material(final String materialName, final MaterialState defaultState, fin this.translatedName = GTLanguageManager .addStringLocalization("gtplusplus.material." + unlocalizedName, localizedName); mMaterialCache.put(getLocalizedName().toLowerCase(), this); + mMaterialsByName.put(unlocalizedName, this); Logger.INFO("Stored " + getLocalizedName() + " to cache with key: " + getLocalizedName().toLowerCase()); this.materialState = defaultState; @@ -725,6 +735,7 @@ private static void checkForCellAndGenerate(Material material) { } } + @Override public final TextureSet getTextureSet() { synchronized (this) { return textureSet; @@ -836,6 +847,7 @@ public TextureSet setTextureSet(TextureSet set, int aTier) { return Materials.Gold.mIconSet; } + @Override public final String getLocalizedName() { if (this.localizedName != null) { return this.localizedName; @@ -843,6 +855,33 @@ public final String getLocalizedName() { return "ERROR BAD LOCALIZED NAME"; } + @Override + public int getId() { + ItemStack dust = getDust(1); + + if (dust != null) return Item.getIdFromItem(dust.getItem()); + + ItemStack ingot = getIngot(1); + + if (ingot != null) return Item.getIdFromItem(ingot.getItem()); + + ItemStack ore = getOre(1); + + if (ore != null) return Item.getIdFromItem(ore.getItem()); + + return 0; + } + + @Override + public List getValidStones() { + return StoneType.STONE_ONLY; + } + + @Override + public String getInternalName() { + return getUnlocalizedName(); + } + public final String getUnlocalizedName() { if (this.unlocalizedName != null) { return this.unlocalizedName; @@ -868,6 +907,7 @@ public final short[] getRGB() { return new short[] { 255, 0, 0 }; } + @Override public final short[] getRGBA() { if (this.RGBA != null) { if (this.RGBA.length == 4) { @@ -1118,15 +1158,20 @@ public final ItemStack getCable16(final int stacksize) { return getComponentByPrefix(OrePrefixes.cableGt16, stacksize); } + private ItemStack ore; + /** * Ore Components * * @return */ public final ItemStack getOre(final int stacksize) { - return ItemUtils.getItemStackOfAmountFromOreDictNoBroken( - "ore" + Utils.sanitizeString(this.getUnlocalizedName()), - stacksize); + if (ore == null) { + ore = ItemUtils + .getItemStackOfAmountFromOreDictNoBroken("ore" + Utils.sanitizeString(this.getUnlocalizedName()), 1); + } + + return GTUtility.copyAmount(stacksize, ore); } public final Block getOreBlock(final int stacksize) { @@ -1181,7 +1226,11 @@ public final ItemStack getMilled(final int stacksize) { } public final ItemStack getRawOre(final int stacksize) { - return getComponentByPrefix(OrePrefixes.rawOre, stacksize); + if (rawOre == null) { + rawOre = getComponentByPrefix(OrePrefixes.rawOre, 1); + } + + return GTUtility.copyAmount(stacksize, rawOre); } public final boolean hasSolidForm() { diff --git a/src/main/java/gtPlusPlus/core/proxy/ClientProxy.java b/src/main/java/gtPlusPlus/core/proxy/ClientProxy.java index bfbb891ea1f..3ab3c609b34 100644 --- a/src/main/java/gtPlusPlus/core/proxy/ClientProxy.java +++ b/src/main/java/gtPlusPlus/core/proxy/ClientProxy.java @@ -24,7 +24,6 @@ import gtPlusPlus.GTplusplus; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.client.renderer.CustomItemBlockRenderer; -import gtPlusPlus.core.client.renderer.CustomOreBlockRenderer; import gtPlusPlus.core.client.renderer.RenderDecayChest; import gtPlusPlus.core.client.renderer.RenderMiningExplosivesPrimed; import gtPlusPlus.core.client.renderer.RenderSickBlaze; @@ -54,7 +53,6 @@ public void preInit(final FMLPreInitializationEvent e) { @Override public void init(final FMLInitializationEvent e) { - new CustomOreBlockRenderer(); new CustomItemBlockRenderer(); new MachineBlockRenderer(); new FlaskRenderer(); diff --git a/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java b/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java index 55bb39bd3e5..3bd59855169 100644 --- a/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java +++ b/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java @@ -2,30 +2,22 @@ import static gregtech.api.enums.Mods.GTPlusPlusEverglades; -import net.minecraft.block.Block; import net.minecraftforge.common.DimensionManager; -import bwcrossmod.galacticgreg.MTEVoidMinerBase; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; -import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.enums.Mods; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.config.ASMConfiguration; -import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.lib.GTPPCore.Everglades; import gtPlusPlus.core.material.MaterialGenerator; import gtPlusPlus.core.material.MaterialsOres; import gtPlusPlus.everglades.biome.BiomeEverglades; import gtPlusPlus.everglades.block.DarkWorldContentLoader; import gtPlusPlus.everglades.dimension.DimensionEverglades; -import gtPlusPlus.everglades.gen.gt.WorldGen_GT_Base; -import gtPlusPlus.everglades.gen.gt.WorldGen_GT_Ore_Layer; -import gtPlusPlus.everglades.gen.gt.WorldGen_Ores; @Mod( modid = Mods.Names.G_T_PLUS_PLUS_EVERGLADES, @@ -64,10 +56,8 @@ public void load(final FMLInitializationEvent e) { Logger.INFO("Begin resource allocation for " + GTPlusPlusEverglades.ID + " V" + Everglades.VERSION); // Load World and Biome - GameRegistry.registerWorldGenerator(new WorldGen_GT_Base(), Short.MAX_VALUE); getEvergladesBiome().load(); Everglades_Dimension.load(); - addToVoidMinerDrops(); } public static synchronized void GenerateOreMaterials() { @@ -124,33 +114,9 @@ protected synchronized void setVars(FMLPreInitializationEvent event) { DimensionEverglades.DIMID = DimensionManager.getNextFreeDimId(); } - /* - * Set World Generation Values - */ - WorldGen_Ores.generateValidOreVeins(); - WorldGen_GT_Base.oreveinPercentage = 64; - WorldGen_GT_Base.oreveinAttempts = 16; - WorldGen_GT_Base.oreveinMaxPlacementAttempts = 4; - if (ASMConfiguration.debug.debugMode || GTPPCore.DEVENV) { - WorldGen_GT_Base.debugWorldGen = true; - } DarkWorldContentLoader.run(); } - public void addToVoidMinerDrops() { - for (WorldGen_GT_Ore_Layer t : WorldGen_Ores.validOreveins.values()) { - addVMDrop(t.mPrimaryMeta, 0, t.mWeight); - addVMDrop(t.mSecondaryMeta, 0, t.mWeight); - addVMDrop(t.mBetweenMeta, 0, t.mWeight / 8f); - addVMDrop(t.mSporadicMeta, 0, t.mWeight / 8f); - } - } - - public void addVMDrop(Block block, int meta, float weight) { - MTEVoidMinerBase - .addBlockToDimensionList(gtPlusPlus.core.config.Configuration.worldgen.EVERGLADES_ID, block, meta, weight); - } - @EventHandler public void serverLoad(FMLServerStartingEvent event) { getEvergladesBiome().serverLoad(event); diff --git a/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java b/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java index 409e3f150a7..d1d9740de4f 100644 --- a/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java +++ b/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java @@ -31,6 +31,7 @@ import net.minecraftforge.event.terraingen.PopulateChunkEvent; import net.minecraftforge.event.terraingen.TerrainGen; +import gregtech.api.objects.XSTR; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.everglades.dimension.DimensionEverglades; @@ -107,7 +108,7 @@ public ChunkProviderModded(World par1World, long par2) { this.worldObj = par1World; this.field_147435_p = par1World.getWorldInfo() .getTerrainType(); - this.rand = new Random(par2); + this.rand = new XSTR(par2); this.field_147431_j = new NoiseGeneratorOctaves(this.rand, 16); this.field_147432_k = new NoiseGeneratorOctaves(this.rand, 16); this.field_147429_l = new NoiseGeneratorOctaves(this.rand, 8); diff --git a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT.java b/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT.java deleted file mode 100644 index 670b6b889ab..00000000000 --- a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT.java +++ /dev/null @@ -1,46 +0,0 @@ -package gtPlusPlus.everglades.gen.gt; - -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.ConcurrentHashMap; - -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; - -public abstract class WorldGen_GT { - - public final String mWorldGenName; - public final boolean mEnabled; - private final Map mDimensionMap = new ConcurrentHashMap<>(); - - public WorldGen_GT(String aName, List aList, boolean aDefault) { - this.mWorldGenName = aName; - this.mEnabled = aDefault; - if (this.mEnabled) { - aList.add(this); - } - } - - public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - return false; - } - - public boolean executeCavegen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - return false; - } - - public boolean isGenerationAllowed(World aWorld, int aDimensionType, int aAllowedDimensionType) { - String aDimName = aWorld.provider.getDimensionName(); - Boolean tAllowed = this.mDimensionMap.get(aDimName); - if (tAllowed == null) { - boolean tValue = (aDimensionType == aAllowedDimensionType); - this.mDimensionMap.put(aDimName, tValue); - return tValue; - } else { - return tAllowed; - } - } -} diff --git a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Base.java b/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Base.java deleted file mode 100644 index bb1916adea3..00000000000 --- a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Base.java +++ /dev/null @@ -1,578 +0,0 @@ -package gtPlusPlus.everglades.gen.gt; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.List; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.feature.WorldGenMinable; - -import cpw.mods.fml.common.IWorldGenerator; -import gregtech.api.objects.XSTR; -import gregtech.api.util.GTLog; -import gregtech.common.GTWorldgenerator; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.material.MaterialsElements; -import gtPlusPlus.everglades.dimension.DimensionEverglades; -import gtPlusPlus.xmod.gregtech.HandlerGT; - -public class WorldGen_GT_Base implements IWorldGenerator { - - /** - * Class Variables - */ - - /** - * Control percentage of filled 3x3 chunks. Lower number means less oreveins spawn - */ - public static int oreveinPercentage; - /** - * Control number of attempts to find a valid orevein. Generally this maximum limit isn't hit, selecting a vein is - * cheap - */ - public static int oreveinAttempts; - /** - * Control number of attempts to place a valid orevein. If a vein wasn't placed due to height restrictions, - * completely in the water, etc, another attempt is tried. - */ - public static int oreveinMaxPlacementAttempts; - /** - * Debug parameter for world generation. Tracks chunks added/removed from run queue. - */ - public static boolean debugWorldGen = false; - /** - * Try re-implement Richard Hendrick's Chunk by Chunk Ore Generation from his GT5u fork. - */ - public static List mList = new ArrayList<>(); - - public static HashSet ProcChunks = new HashSet<>(); - // This is probably not going to work. Trying to create a fake orevein to - // put into hashtable when there will be no ores in a vein. - public static WorldGen_GT_Ore_Layer noOresInVein = new WorldGen_GT_Ore_Layer( - "vein0", - 0, - 255, - 0, - 0, - 0, - MaterialsElements.getInstance().IRON, - MaterialsElements.getInstance().IRON, - MaterialsElements.getInstance().IRON, - MaterialsElements.getInstance().IRON); - - public static Hashtable validOreveins = new Hashtable<>(1024); - - public boolean mIsGenerating = false; - public static final Object listLock = new Object(); - // private static boolean gcAsteroids = true; - - public WorldGen_GT_Base() { - if (debugWorldGen) { - GTLog.out.println("GTPP_Worldgenerator created"); - } - } - - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, - IChunkProvider chunkProvider) { - if (world.provider.dimensionId == DimensionEverglades.DIMID) { - generateSafely(random, chunkX, chunkZ, world, chunkGenerator, chunkProvider); - } - } - - public synchronized void generateSafely(Random random, int chunkX, int chunkZ, World world, - IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { - int xDim = DimensionEverglades.DIMID; - switch (world.provider.dimensionId) { - case -1: // Nether - // generateNether(world, random, chunkX * 16, chunkZ * 16); - break; - case 0: // Overworld - // generateSurface(world, random, chunkX * 16, chunkZ * 16); - break; - case 1: // End - // generateEnd(world, random, chunkX * 16, chunkZ * 16); - break; - default: // Any other dimension - if (world.provider.dimensionId == xDim) { - generateEverglades(random, chunkX, chunkZ, world, chunkGenerator, chunkProvider); - } - break; - } - } - - private synchronized void generateEverglades(Random aRandom, int aX, int aZ, World aWorld, - IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - Logger.WORLD("Trying to Generate Dimension."); - synchronized (listLock) { - Logger.WORLD("Locked List addition."); - if (WorldGen_GT_Base.mList.add( - new WorldGenContainer( - new XSTR(Math.abs(aRandom.nextInt()) + 1), - aX, - aZ, - DimensionEverglades.DIMID, - aWorld, - aChunkGenerator, - aChunkProvider, - aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName))) { - Logger.WORLD("Locked List addition. Success."); - } else { - Logger.WORLD("Locked List addition. Fail."); - } - if (debugWorldGen) GTLog.out.println( - "ADD WorldSeed:" + aWorld.getSeed() - + " DimId" - + aWorld.provider.dimensionId - + " chunk x:" - + aX - + " z:" - + aZ - + " SIZE: " - + WorldGen_GT_Base.mList.size()); - } - - if (!this.mIsGenerating) { - Logger.WORLD("Is not generating."); - this.mIsGenerating = true; - Logger.WORLD("Setting Generation to true."); - int mList_sS = WorldGen_GT_Base.mList.size(); - mList_sS = Math.min(mList_sS, 3); // Run a maximum of 3 chunks at a - // time through worldgen. Extra - // chunks get done later. - for (int i = 0; i < mList_sS; i++) { - WorldGenContainer toRun = (WorldGenContainer) WorldGen_GT_Base.mList.get(0); - if (debugWorldGen) GTLog.out.println( - "RUN WorldSeed:" + aWorld.getSeed() - + " DimId" - + aWorld.provider.dimensionId - + " chunk x:" - + toRun.mX - + " z:" - + toRun.mZ - + " SIZE: " - + WorldGen_GT_Base.mList.size() - + " i: " - + i); - synchronized (listLock) { - Logger.WORLD("Locked List Removal."); - WorldGen_GT_Base.mList.remove(0); - } - toRun.run(); - } - this.mIsGenerating = false; - Logger.WORLD("Is Generating now set to false.."); - } - } - - public void generateOre(Block block, World world, Random random, int chunk_x, int chunk_z, int maxX, int maxZ, - int maxVeinSize, int chancesToSpawn, int minY, int maxY, Block generateIn) { - int heightRange = maxY - minY; - WorldGenMinable worldgenminable = new WorldGenMinable(block, maxVeinSize, generateIn); - for (int k1 = 0; k1 < chancesToSpawn; ++k1) { - int xrand = random.nextInt(16); - int yrand = random.nextInt(heightRange) + minY; - int zrand = random.nextInt(16); - worldgenminable.generate(world, random, chunk_x + xrand, yrand, chunk_z + zrand); - } - } - - public static class WorldGenContainer implements Runnable { - - public final Random mRandom; - public final int mX; - public final int mZ; - public final int mDimensionType; - public final World mWorld; - public final IChunkProvider mChunkGenerator; - public final IChunkProvider mChunkProvider; - public final String mBiome; - - // Local class to track which orevein seeds must be checked when doing - // chunkified worldgen - static class NearbySeeds { - - public int mX; - public int mZ; - - NearbySeeds(int x, int z) { - this.mX = x; - this.mZ = z; - } - } - - public static ArrayList seedList = new ArrayList<>(); - - // aX and aZ are now the by-chunk X and Z for the chunk of interest - public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, World aWorld, - IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider, String aBiome) { - this.mRandom = aRandom; - this.mX = aX; - this.mZ = aZ; - this.mDimensionType = aDimensionType; - this.mWorld = aWorld; - this.mChunkGenerator = aChunkGenerator; - this.mChunkProvider = aChunkProvider; - this.mBiome = aBiome; - } - - public void worldGenFindVein(int oreseedX, int oreseedZ) { - // Explanation of oreveinseed implementation. - // (long)this.mWorld.getSeed()<<16) Deep Dark does two oregen - // passes, one with getSeed set to +1 the original world seed. This - // pushes that +1 off the low bits of oreseedZ, so that the hashes - // are far apart for the two passes. - // ((this.mWorld.provider.dimensionId & 0xffL)<<56) Puts the - // dimension in the top bits of the hash, to make sure to get unique - // hashes per dimension - // ((long)oreseedX & 0x000000000fffffffL) << 28) Puts the chunk X in - // the bits 29-55. Cuts off the top few bits of the chunk so we have - // bits for dimension. - // ( (long)oreseedZ & 0x000000000fffffffL )) Puts the chunk Z in the - // bits 0-27. Cuts off the top few bits of the chunk so we have bits - // for dimension. - long oreveinSeed = (this.mWorld.getSeed() << 16) - ^ ((this.mWorld.provider.dimensionId & 0xffL) << 56 | ((oreseedX & 0x000000000fffffffL) << 28) - | (oreseedZ & 0x000000000fffffffL)); // Use - // an - // RNG - // that - // is - // identical - // every - // time - // it - // is - // called - // for - // this - // oreseed. - XSTR oreveinRNG = new XSTR(oreveinSeed); - int oreveinPercentageRoll = oreveinRNG.nextInt(100); // Roll the - // dice, see - // if we get - // an - // orevein - // here at - // all - int noOrePlacedCount = 0; - String tDimensionName = ""; - if (debugWorldGen) { - tDimensionName = this.mWorld.provider.getDimensionName(); - } - - if (debugWorldGen) { - GTLog.out.println( - " Finding oreveins for oreveinSeed=" + oreveinSeed - + " mX=" - + this.mX - + " mZ=" - + this.mZ - + " oreseedX=" - + oreseedX - + " oreseedZ=" - + oreseedZ - + " worldSeed=" - + this.mWorld.getSeed()); - } - - Logger - .INFO("[World Generation Debug] !validOreveins.containsKey(oreveinSeed) | oreveinSeed: " + oreveinSeed); - // Search for a valid orevein for this dimension - if (!validOreveins.containsKey(oreveinSeed)) { - - Logger.INFO( - "[World Generation Debug] oreveinPercentageRoll < oreveinPercentage? " - + ((oreveinPercentageRoll < oreveinPercentage))); - Logger.INFO( - "[World Generation Debug] WorldGen_GT_Ore_Layer.sWeight > 0? " - + (WorldGen_GT_Ore_Layer.sWeight > 0)); - Logger.INFO( - "[World Generation Debug] WorldGen_GT_Ore_Layer.sList.size() > 0? " - + (!WorldGen_GT_Ore_Layer.sList.isEmpty())); - if ((oreveinPercentageRoll < oreveinPercentage) && (WorldGen_GT_Ore_Layer.sWeight > 0) - && (!WorldGen_GT_Ore_Layer.sList.isEmpty())) { - int placementAttempts = 0; - boolean oreveinFound = false; - int i; - for (i = 0; (i < oreveinAttempts) && (!oreveinFound) - && (placementAttempts < oreveinMaxPlacementAttempts); i++) { - Logger.INFO("[World Generation Debug] i: " + i); - Logger.INFO("[World Generation Debug] placementAttempts: " + placementAttempts); - Logger.INFO("[World Generation Debug] oreveinAttempts: " + oreveinAttempts); - Logger.INFO( - "[World Generation Debug] (placementAttempts < oreveinMaxPlacementAttempts): " - + (placementAttempts < oreveinMaxPlacementAttempts)); - Logger.INFO("[World Generation Debug] oreveinFound: " + oreveinFound); - int tRandomWeight = oreveinRNG.nextInt(WorldGen_GT_Ore_Layer.sWeight); - for (WorldGen_GT_Ore_Layer tWorldGen : WorldGen_GT_Ore_Layer.sList) { - Logger.INFO( - "[World Generation Debug] Iterating sList - Size: " - + WorldGen_GT_Ore_Layer.sList.size()); - tRandomWeight -= (tWorldGen).mWeight; - if (tRandomWeight <= 0) { - try { - // Adjust the seed so that this layer has a - // series of unique random numbers. - // Otherwise multiple attempts at this same - // oreseed will get the same offset and X/Z - // values. If an orevein failed, any orevein - // with the - // same minimum heights would fail as well. - // This prevents that, giving each orevein a - // unique height each pass through here. - int placementResult = tWorldGen.executeWorldgenChunkified( - this.mWorld, - new XSTR(oreveinSeed ^ (Block.getIdFromBlock(tWorldGen.mPrimaryMeta))), - this.mBiome, - this.mDimensionType, - this.mX * 16, - this.mZ * 16, - oreseedX * 16, - oreseedZ * 16, - this.mChunkGenerator, - this.mChunkProvider); - switch (placementResult) { - case WorldGen_GT_Ore_Layer.ORE_PLACED -> { - if (debugWorldGen) GTLog.out.println( - " Added oreveinSeed=" + oreveinSeed - + " tries at oremix=" - + i - + " placementAttempts=" - + placementAttempts - + " dimensionName=" - + tDimensionName); - validOreveins.put(oreveinSeed, tWorldGen); - oreveinFound = true; - Logger.INFO("[World Generation Debug] ORE_PLACED"); - } - case WorldGen_GT_Ore_Layer.NO_ORE_IN_BOTTOM_LAYER -> { - placementAttempts++; - Logger.INFO( - "[World Generation Debug] NO_ORE_IN_BOTTOM_LAYER | Attempts: " - + placementAttempts); - } - // SHould do retry in this case - // until out of chances - case WorldGen_GT_Ore_Layer.NO_OVERLAP -> { - // Orevein didn't reach this chunk, - // can't add it yet to the hash - Logger.INFO("[World Generation Debug] NO_OVERLAP"); - if (debugWorldGen) GTLog.out.println( - " Added far oreveinSeed=" + oreveinSeed - + " " - + (tWorldGen).mWorldGenName - + " tries at oremix=" - + i - + " placementAttempts=" - + placementAttempts - + " dimensionName=" - + tDimensionName); - validOreveins.put(oreveinSeed, tWorldGen); - oreveinFound = true; - } - case WorldGen_GT_Ore_Layer.NO_OVERLAP_AIR_BLOCK -> { - if (debugWorldGen) GTLog.out.println( - " No overlap and air block in test spot=" + oreveinSeed - + " " - + (tWorldGen).mWorldGenName - + " tries at oremix=" - + i - + " placementAttempts=" - + placementAttempts - + " dimensionName=" - + tDimensionName); - // SHould do retry in this case until out of chances - Logger.INFO("[World Generation Debug] NO_OVERLAP_AIR_BLOCK"); - placementAttempts++; - } - } - break; // Try the next orevein - } catch (Throwable e) { - if (debugWorldGen) GTLog.out.println( - "Exception occurred on oreVein" + tWorldGen - + " oreveinSeed=" - + oreveinSeed - + " mX=" - + this.mX - + " mZ=" - + this.mZ - + " oreseedX=" - + oreseedX - + " oreseedZ=" - + oreseedZ); - e.printStackTrace(GTLog.err); - } - } - } - } - // Only add an empty orevein if are unable to place a vein - // at the oreseed chunk. - if ((!oreveinFound) && (this.mX == oreseedX) && (this.mZ == oreseedZ)) { - if (debugWorldGen) GTLog.out.println( - " Empty oreveinSeed=" + oreveinSeed - + " mX=" - + this.mX - + " mZ=" - + this.mZ - + " oreseedX=" - + oreseedX - + " oreseedZ=" - + oreseedZ - + " tries at oremix=" - + i - + " placementAttempts=" - + placementAttempts - + " dimensionName=" - + tDimensionName); - validOreveins.put(oreveinSeed, noOresInVein); - } - } else if (oreveinPercentageRoll >= oreveinPercentage) { - if (debugWorldGen) GTLog.out.println( - " Skipped oreveinSeed=" + oreveinSeed - + " mX=" - + this.mX - + " mZ=" - + this.mZ - + " oreseedX=" - + oreseedX - + " oreseedZ=" - + oreseedZ - + " RNG=" - + oreveinPercentageRoll - + " %=" - + oreveinPercentage - + " dimensionName=" - + tDimensionName); - validOreveins.put(oreveinSeed, noOresInVein); - } - } else { - // oreseed is located in the previously processed table - if (debugWorldGen) GTLog.out - .print(" Valid oreveinSeed=" + oreveinSeed + " validOreveins.size()=" + validOreveins.size() + " "); - WorldGen_GT_Ore_Layer tWorldGen = validOreveins.get(oreveinSeed); - oreveinRNG.setSeed(oreveinSeed ^ (Block.getIdFromBlock(tWorldGen.mPrimaryMeta))); // Reset - // RNG - // to - // only - // be - // based - // on - // oreseed - // X/Z - // and - // type - // of - // vein - int placementResult = tWorldGen.executeWorldgenChunkified( - this.mWorld, - oreveinRNG, - this.mBiome, - this.mDimensionType, - this.mX * 16, - this.mZ * 16, - oreseedX * 16, - oreseedZ * 16, - this.mChunkGenerator, - this.mChunkProvider); - switch (placementResult) { - case WorldGen_GT_Ore_Layer.NO_ORE_IN_BOTTOM_LAYER -> { - if (debugWorldGen) GTLog.out.println(" No ore in bottom layer"); - } - case WorldGen_GT_Ore_Layer.NO_OVERLAP -> { - if (debugWorldGen) GTLog.out.println(" No overlap"); - } - } - } - } - - @Override - public void run() { - long startTime = System.nanoTime(); - int oreveinMaxSize; - - // Determine bounding box on how far out to check for oreveins - // affecting this chunk - // For now, manually reducing oreveinMaxSize when not in the - // Underdark for performance - if (this.mWorld.provider.getDimensionName() - .equals("Underdark")) { - oreveinMaxSize = 24; // Leave Deep Dark/Underdark max oregen at - // 32, instead of 64 - } else { - oreveinMaxSize = 48; - } - - int wXbox = this.mX - (oreveinMaxSize / 16); - int eXbox = this.mX + (oreveinMaxSize / 16 + 1); // Need to add 1 - // since it is - // compared - // using a < - int nZbox = this.mZ - (oreveinMaxSize / 16); - int sZbox = this.mZ + (oreveinMaxSize / 16 + 1); - - // Search for orevein seeds and add to the list; - for (int x = wXbox; x < eXbox; x++) { - for (int z = nZbox; z < sZbox; z++) { - // Determine if this X/Z is an orevein seed - if (GTWorldgenerator.isOreChunk(x, z)) { - if (debugWorldGen) GTLog.out.println("Adding seed x=" + x + " z=" + z); - seedList.add(new NearbySeeds(x, z)); - } - } - } - - // Now process each oreseed vs this requested chunk - for (; !seedList.isEmpty(); seedList.remove(0)) { - if (debugWorldGen) - GTLog.out.println("Processing seed x=" + seedList.get(0).mX + " z=" + seedList.get(0).mZ); - worldGenFindVein(seedList.get(0).mX, seedList.get(0).mZ); - } - - long oregenTime = System.nanoTime(); - - // Do leftover worldgen for this chunk (GT_Stones and GT_small_ores) - try { - for (WorldGen_GT tWorldGen : HandlerGT.sWorldgenListEverglades) { - /* - * if (debugWorldGen) GTLog.out.println( "tWorldGen.mWorldGenName="+tWorldGen.mWorldGenName ); - */ - tWorldGen.executeWorldgen( - this.mWorld, - this.mRandom, - this.mBiome, - this.mDimensionType, - this.mX * 16, - this.mZ * 16, - this.mChunkGenerator, - this.mChunkProvider); - } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - - long leftOverTime = System.nanoTime(); - - Chunk tChunk = this.mWorld.getChunkFromBlockCoords(this.mX, this.mZ); - if (tChunk != null) { - tChunk.isModified = true; - } - long endTime = System.nanoTime(); - long duration = (endTime - startTime); - if (debugWorldGen) { - GTLog.out.println( - " Oregen took " + (oregenTime - startTime) - + " Leftover gen took " - + (leftOverTime - oregenTime) - + " Worldgen took " - + duration - + " nanoseconds"); - } - } - } -} diff --git a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java b/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java deleted file mode 100644 index 9153264185a..00000000000 --- a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java +++ /dev/null @@ -1,494 +0,0 @@ -package gtPlusPlus.everglades.gen.gt; - -import static gtPlusPlus.everglades.gen.gt.WorldGen_GT_Base.debugWorldGen; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; - -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.util.GTLog; -import gregtech.common.blocks.BlockOres; -import gregtech.common.blocks.TileEntityOres; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.everglades.dimension.DimensionEverglades; - -public class WorldGen_GT_Ore_Layer extends WorldGen_GT { - - public static ArrayList sList = new ArrayList<>(); - 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 Block mPrimaryMeta; - public Block mSecondaryMeta; - public Block mBetweenMeta; - public Block mSporadicMeta; - public final Material mPrimary; - public final Material mSecondary; - public final Material mBetween; - public final Material mSporadic; - - // public final String mBiome; - public final String mRestrictBiome; - public final boolean mOverworld; - public final boolean mNether; - public final boolean mEnd; - public static final int WRONG_BIOME = 0; - public static final int WRONG_DIMENSION = 1; - public static final int NO_ORE_IN_BOTTOM_LAYER = 2; - public static final int NO_OVERLAP = 3; - public static final int ORE_PLACED = 4; - public static final int NO_OVERLAP_AIR_BLOCK = 5; - - public final String aTextWorldgen = "worldgen."; - - public WorldGen_GT_Ore_Layer(String aName, int aMinY, int aMaxY, int aWeight, int aDensity, int aSize, - Material aPrimary, Material aSecondary, Material aBetween, Material aSporadic) { - this( - aName, - true, - aMinY, - aMaxY, - aWeight, - aDensity, - aSize, - false, - false, - false, - false, - false, - false, - aPrimary, - aSecondary, - aBetween, - aSporadic); - } - - public WorldGen_GT_Ore_Layer(String aName, boolean aDefault, int aMinY, int aMaxY, int aWeight, int aDensity, - int aSize, boolean aOverworld, boolean aNether, boolean aEnd, boolean GC_UNUSED1, boolean GC_UNUSED2, - boolean GC_UNUSED3, Material aPrimary, Material aSecondary, Material aBetween, Material aSporadic) { - super(aName, sList, aDefault); - Logger.WORLD("Creating Ore Layer Object"); - this.mOverworld = aOverworld; - this.mNether = aNether; - this.mEnd = aEnd; - this.mMinY = 5; - this.mMaxY = 14; - this.mWeight = (short) aWeight; - this.mDensity = (short) aDensity; - this.mSize = (short) Math.max(1, aSize); - this.mPrimary = aPrimary; - this.mSecondary = aSecondary; - this.mBetween = aBetween; - this.mSporadic = aSporadic; - this.mPrimaryMeta = aPrimary.getOreBlock(1); - this.mSecondaryMeta = aSecondary.getOreBlock(1); - this.mBetweenMeta = aBetween.getOreBlock(1); - this.mSporadicMeta = aSporadic.getOreBlock(1); - this.mRestrictBiome = "None"; - - if (this.mEnabled) { - sWeight += this.mWeight; - } - } - - public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, - int aChunkZ, int aSeedX, int aSeedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - // Debug Handler - // This handles Variables that are null during Init - if (this.mPrimaryMeta == Blocks.stone || this.mSecondaryMeta == Blocks.stone - || this.mBetweenMeta == Blocks.stone - || this.mSporadicMeta == Blocks.stone) { - this.mPrimaryMeta = this.mPrimary.getOreBlock(1); - this.mSecondaryMeta = this.mSecondary.getOreBlock(1); - this.mBetweenMeta = this.mBetween.getOreBlock(1); - this.mSporadicMeta = this.mSporadic.getOreBlock(1); - Logger.WORLD( - "[Vein Generator] An Ore in a Vein had defaulted back to a default value, so they have now been reset to correct values."); - } - - if (mWorldGenName.equals("vein0")) { - if (debugWorldGen) GTLog.out.println(" NoOresInVein-vein0"); - // This is a special empty orevein - Logger.WORLD("[World Generation Debug] Special Empty Vein placed."); - return ORE_PLACED; - } - if (aDimensionType != DimensionEverglades.DIMID) { - /* - * // Debug code, but spams log if (debugWorldGen) { GTLog.out.println( "Wrong dimension" ); } - */ - Logger.WORLD("[World Generation Debug] Wrong dimension."); - return WRONG_DIMENSION; - } - if (!this.mRestrictBiome.equals("None") && !(this.mRestrictBiome.equals(aBiome))) { - return WRONG_BIOME; - } - int[] placeCount = new int[4]; - - int tMinY = mMinY + aRandom.nextInt(mMaxY - mMinY - 5); - // Determine West/East ends of orevein - int wXVein = aSeedX - aRandom.nextInt(mSize); // West side - int eXVein = aSeedX + 16 + aRandom.nextInt(mSize); - // Limit Orevein to only blocks present in current chunk - int wX = Math.max(wXVein, aChunkX + 2); // Bias placement by 2 blocks to prevent worldgen cascade. - int eX = Math.min(eXVein, aChunkX + 2 + 16); - if (wX >= eX) { // No overlap between orevein and this chunk exists in X - Block tBlock = aWorld.getBlock(aChunkX + 8, tMinY, aChunkZ + 8); - if (tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, Blocks.stone) - || tBlock - .isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, DimensionEverglades.blockSecondLayer) - || tBlock - .isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, DimensionEverglades.blockMainFiller) - || tBlock.isReplaceableOreGen( - aWorld, - aChunkX + 8, - tMinY, - aChunkZ + 8, - DimensionEverglades.blockSecondaryFiller) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, Blocks.netherrack) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, Blocks.end_stone) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, GregTechAPI.sBlockGranites) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, GregTechAPI.sBlockStones)) { - // Didn't reach, but could have placed. Save orevein for future use. - return NO_OVERLAP; - } else { - // Didn't reach, but couldn't place in test spot anywys, try for another orevein - return NO_OVERLAP_AIR_BLOCK; - } - } - // Determine North/Sound ends of orevein - int nZVein = aSeedZ - aRandom.nextInt(mSize); - int sZVein = aSeedZ + 16 + aRandom.nextInt(mSize); - - int nZ = Math.max(nZVein, aChunkZ + 2); // Bias placement by 2 blocks to prevent worldgen cascade. - int sZ = Math.min(sZVein, aChunkZ + 2 + 16); - if (nZ >= sZ) { // No overlap between orevein and this chunk exists in Z - Block tBlock = aWorld.getBlock(aChunkX + 8, tMinY, aChunkZ + 8); - if (tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, Blocks.stone) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, Blocks.netherrack) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, Blocks.end_stone) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, GregTechAPI.sBlockGranites) - || tBlock.isReplaceableOreGen(aWorld, aChunkX + 8, tMinY, aChunkZ + 8, GregTechAPI.sBlockStones)) { - // Didn't reach, but could have placed. Save orevein for future use. - return NO_OVERLAP; - } else { - // Didn't reach, but couldn't place in test spot anywys, try for another orevein - return NO_OVERLAP_AIR_BLOCK; - } - } - - if (debugWorldGen) { - String tDimensionName = aWorld.provider.getDimensionName(); - GTLog.out.print( - "Trying Orevein:" + this.mWorldGenName - + " Dimension=" - + tDimensionName - + " mX=" - + aChunkX / 16 - + " mZ=" - + aChunkZ / 16 - + " oreseedX=" - + aSeedX / 16 - + " oreseedZ=" - + aSeedZ / 16 - + " cY=" - + tMinY); - } - // Adjust the density down the more chunks we are away from the oreseed. The 5 chunks surrounding the seed - // should always be max density due to truncation of Math.sqrt(). - int localDensity = (Math.max( - 1, - this.mDensity / ((int) Math - .sqrt(2 + Math.pow(aChunkX / 16 - aSeedX / 16, 2) + Math.pow(aChunkZ / 16 - aSeedZ / 16, 2))))); - - // To allow for early exit due to no ore placed in the bottom layer (probably because we are in the sky), unroll - // 1 pass through the loop - // Now we do bottom-level-first oregen, and work our way upwards. - int level = tMinY - 1; // Dunno why, but the first layer is actually played one below tMinY. Go figure. - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSecondaryMeta != null)) { - if (setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { - placeCount[1]++; - } - } else - if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta != null)) { // Sporadics are only 1 per vertical column normally, - // reduce by 1/7 to - // compensate - if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; - } - } - } - /* - * if ((placeCount[1]+placeCount[3])==0) { if (debugWorldGen) GTLog.out.println( " No ore in bottom layer" ); - * return NO_ORE_IN_BOTTOM_LAYER; // Exit early, didn't place anything in the bottom layer } - */ - Logger.WORLD("[World Generation Debug] Trying to set Ores?"); - for (level = tMinY; level < (tMinY - 1 + 3); level++) { - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max( - 1, - Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSecondaryMeta != null)) { - if (setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { - placeCount[1]++; - } - } else if ((aRandom.nextInt(7) == 0) - && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta != null)) { // Sporadics are only 1 per vertical column normally, - // reduce by 1/7 to - // compensate - if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; - } - } - } - } - // Low Middle layer is between + sporadic - // level should be = tMinY-1+3 from end of for loop - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mBetweenMeta != null)) { // Between are only 1 per vertical column, reduce by 1/2 to - // compensate - if (setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { - placeCount[2]++; - } - } else - if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta != null)) { // Sporadics are only 1 per vertical column normally, - // reduce by 1/7 to - // compensate - if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; - } - } - } - // High Middle layer is between + primary + sporadic - level++; // Increment level to next layer - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math - .max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mBetweenMeta != null)) { // Between are only 1 per vertical column, reduce by 1/2 to - // compensate - if (setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { - placeCount[2]++; - } - } else if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mPrimaryMeta != null)) { - if (setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, false)) { - placeCount[0]++; - } - } else - if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta != null)) { // Sporadics are only 1 per vertical column normally, - // reduce by 1/7 to - // compensate - if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; - } - } - } - // Top two layers are primary + sporadic - level++; // Increment level to next layer - for (; level < (tMinY + 6); level++) { // should do two layers - for (int tX = wX; tX < eX; tX++) { - int placeX = Math - .max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX)) / localDensity); - for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max( - 1, - Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ)) / localDensity); - if (((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mPrimaryMeta != null)) { - if (setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, false)) { - placeCount[0]++; - } - } else if ((aRandom.nextInt(7) == 0) - && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) - && (this.mSporadicMeta != null)) { // Sporadics are only 1 per vertical column normally, - // reduce by 1/7 to - // compensate - if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; - } - } - } - } - if (debugWorldGen) { - String tDimensionName = aWorld.provider.getDimensionName(); - GTLog.out.println( - "Generated Orevein:" + this.mWorldGenName - + " Dimension=" - + tDimensionName - + " mX=" - + aChunkX / 16 - + " mZ=" - + aChunkZ / 16 - + " oreseedX=" - + aSeedX / 16 - + " oreseedZ=" - + aSeedZ / 16 - + " cY=" - + tMinY - + " wXVein" - + wXVein - + " eXVein" - + eXVein - + " nZVein" - + nZVein - + " sZVein" - + sZVein - + " locDen=" - + localDensity - + " Den=" - + this.mDensity - + " Sec=" - + placeCount[1] - + " Spo=" - + placeCount[3] - + " Bet=" - + placeCount[2] - + " Pri=" - + placeCount[0]); - } - // Something (at least the bottom layer must have 1 block) must have been placed, return true - return ORE_PLACED; - } - - private String ore1String = "unset"; - private String ore2String = "unset"; - private String ore3String = "unset"; - private String ore4String = "unset"; - Map gtOreMap = new HashMap<>(); - - public boolean setOreBlock(World aWorld, int aX, int aY, int aZ, Block aMetaData, boolean isSmallOre, boolean air) { - if (!air) { - aY = Math.min(aWorld.getActualHeight(), Math.max(aY, 1)); - } - - // Set GT ORE - if (aMetaData instanceof BlockOres) { - if (ore1String.equals("unset")) { - ore1String = Utils.sanitizeString( - this.mPrimary.getLocalizedName() - .toLowerCase()); - } - if (ore2String.equals("unset")) { - ore2String = Utils.sanitizeString( - this.mSecondaryMeta.getLocalizedName() - .toLowerCase()); - } - if (ore3String.equals("unset")) { - ore3String = Utils.sanitizeString( - this.mBetweenMeta.getLocalizedName() - .toLowerCase()); - } - if (ore4String.equals("unset")) { - ore4String = Utils.sanitizeString( - this.mSporadicMeta.getLocalizedName() - .toLowerCase()); - } - - String fString; - if (this.mPrimaryMeta == aMetaData) { - for (Materials f : Materials.values()) { - if (!gtOreMap.containsKey(f)) { - gtOreMap.put(f, Utils.sanitizeString(f.mName.toLowerCase())); - } - fString = gtOreMap.get(f); - if (fString.contains(ore1String)) { - int r = f.mMetaItemSubID; - if (TileEntityOres.setOreBlock(aWorld, aX, aY, aZ, r, false)) { - return true; - } - } - } - } - if (this.mSecondaryMeta == aMetaData) { - for (Materials f : Materials.values()) { - if (!gtOreMap.containsKey(f)) { - gtOreMap.put(f, Utils.sanitizeString(f.mName.toLowerCase())); - } - fString = gtOreMap.get(f); - if (fString.contains(ore2String)) { - int r = f.mMetaItemSubID; - if (TileEntityOres.setOreBlock(aWorld, aX, aY, aZ, r, false)) { - return true; - } - } - } - } - if (this.mBetweenMeta == aMetaData) { - for (Materials f : Materials.values()) { - if (!gtOreMap.containsKey(f)) { - gtOreMap.put(f, Utils.sanitizeString(f.mName.toLowerCase())); - } - fString = gtOreMap.get(f); - if (fString.contains(ore3String)) { - int r = f.mMetaItemSubID; - if (TileEntityOres.setOreBlock(aWorld, aX, aY, aZ, r, false)) { - return true; - } - } - } - } - if (this.mSporadicMeta == aMetaData) { - for (Materials f : Materials.values()) { - if (!gtOreMap.containsKey(f)) { - gtOreMap.put(f, Utils.sanitizeString(f.mName.toLowerCase())); - } - fString = gtOreMap.get(f); - if (fString.contains(ore4String)) { - int r = f.mMetaItemSubID; - if (TileEntityOres.setOreBlock(aWorld, aX, aY, aZ, r, false)) { - return true; - } - } - } - } - } - - Block tBlock = aWorld.getBlock(aX, aY, aZ); - if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone) - || tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.sand) - || tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.dirt) - || tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTechAPI.sBlockGranites) - || tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTechAPI.sBlockStones) - || tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, DimensionEverglades.blockSecondLayer) - || tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, DimensionEverglades.blockMainFiller) - || tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, DimensionEverglades.blockSecondaryFiller) - || tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.sandstone)) { - - return aWorld.setBlock(aX, aY, aZ, aMetaData, 0, 3); - } - return false; - } -} diff --git a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java b/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java deleted file mode 100644 index 87c89b5d203..00000000000 --- a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java +++ /dev/null @@ -1,275 +0,0 @@ -package gtPlusPlus.everglades.gen.gt; - -import java.util.Hashtable; - -import gtPlusPlus.core.material.MaterialsElements; -import gtPlusPlus.core.material.MaterialsOres; -import gtPlusPlus.core.material.nuclear.MaterialsFluorides; - -public class WorldGen_Ores { - - public static WorldGen_GT_Ore_Layer BaseVein = new WorldGen_GT_Ore_Layer( - "veinA", - 20, - 40, - 1, - 1, - 128, - MaterialsElements.getInstance().IRON, - MaterialsElements.getInstance().IRON, - MaterialsElements.getInstance().IRON, - MaterialsElements.getInstance().IRON); - - /** - * Custom ore Veins - */ - public static WorldGen_GT_Ore_Layer Vein1 = new WorldGen_GT_Ore_Layer( - "vein1", - 0, - 60, - 30, - 2, - 16, - MaterialsOres.AGARDITE_CD, - MaterialsOres.AGARDITE_LA, - MaterialsOres.DEMICHELEITE_BR, - MaterialsOres.IRARSITE); - - public static WorldGen_GT_Ore_Layer Vein2 = new WorldGen_GT_Ore_Layer( - "vein2", - 0, - 60, - 30, - 2, - 16, - MaterialsOres.AGARDITE_ND, - MaterialsOres.AGARDITE_Y, - MaterialsOres.KASHINITE, - MaterialsOres.CERITE); - - public static WorldGen_GT_Ore_Layer Vein3 = new WorldGen_GT_Ore_Layer( - "vein3", - 0, - 60, - 30, - 3, - 32, - MaterialsOres.CERITE, - MaterialsOres.NICHROMITE, - MaterialsOres.XENOTIME, - MaterialsOres.HIBONITE); - - public static WorldGen_GT_Ore_Layer Vein4 = new WorldGen_GT_Ore_Layer( - "vein4", - 0, - 60, - 40, - 3, - 32, - MaterialsOres.GEIKIELITE, - MaterialsOres.CRYOLITE, - MaterialsOres.GADOLINITE_CE, - MaterialsOres.AGARDITE_ND); - - public static WorldGen_GT_Ore_Layer Vein5 = new WorldGen_GT_Ore_Layer( - "vein5", - 30, - 128, - 20, - 2, - 48, - MaterialsOres.HIBONITE, - MaterialsOres.YTTRIALITE, - MaterialsOres.ZIRCONILITE, - MaterialsOres.CERITE); - public static WorldGen_GT_Ore_Layer Vein6 = new WorldGen_GT_Ore_Layer( - "vein6", - 0, - 40, - 20, - 2, - 48, - MaterialsOres.XENOTIME, - MaterialsOres.ZIRKELITE, - MaterialsOres.CROCROITE, - MaterialsOres.IRARSITE); - public static WorldGen_GT_Ore_Layer Vein7 = new WorldGen_GT_Ore_Layer( - "vein7", - 40, - 128, - 20, - 2, - 48, - MaterialsOres.HONEAITE, - MaterialsOres.MIESSIITE, - MaterialsOres.SAMARSKITE_Y, - MaterialsOres.SAMARSKITE_YB); - public static WorldGen_GT_Ore_Layer Vein8 = new WorldGen_GT_Ore_Layer( - "vein8", - 0, - 40, - 20, - 2, - 48, - MaterialsOres.TITANITE, - MaterialsOres.ZIMBABWEITE, - MaterialsOres.ZIRCON, - MaterialsOres.FLORENCITE); - - public static WorldGen_GT_Ore_Layer Vein9 = new WorldGen_GT_Ore_Layer( - "vein9", - 10, - 30, - 20, - 1, - 48, - MaterialsOres.LANTHANITE_CE, - MaterialsFluorides.FLUORITE, - MaterialsOres.LAFOSSAITE, - MaterialsOres.FLORENCITE); - public static WorldGen_GT_Ore_Layer Vein10 = new WorldGen_GT_Ore_Layer( - "vein10", - 20, - 50, - 20, - 2, - 32, - MaterialsOres.GEIKIELITE, - MaterialsOres.YTTROCERITE, - MaterialsOres.LANTHANITE_LA, - MaterialsOres.RADIOBARITE); - public static WorldGen_GT_Ore_Layer Vein11 = new WorldGen_GT_Ore_Layer( - "vein11", - 30, - 70, - 20, - 1, - 48, - MaterialsFluorides.FLUORITE, - MaterialsOres.KASHINITE, - MaterialsOres.ZIRCON, - MaterialsOres.CRYOLITE); - public static WorldGen_GT_Ore_Layer Vein12 = new WorldGen_GT_Ore_Layer( - "vein12", - 40, - 80, - 20, - 3, - 32, - MaterialsOres.CERITE, - MaterialsOres.ALBURNITE, - MaterialsOres.MIESSIITE, - MaterialsOres.HIBONITE); - - /** - * Best Rarest Veins 2017 - */ - public static WorldGen_GT_Ore_Layer Vein13 = new WorldGen_GT_Ore_Layer( - "vein13", - 5, - 15, - 5, - 1, - 16, - MaterialsOres.CRYOLITE, - MaterialsOres.RADIOBARITE, - MaterialsOres.HONEAITE, - MaterialsOres.FLORENCITE); - - public static WorldGen_GT_Ore_Layer Vein14 = new WorldGen_GT_Ore_Layer( - "vein14", - 10, - 20, - 8, - 2, - 16, - MaterialsOres.DEMICHELEITE_BR, - MaterialsOres.PERROUDITE, - MaterialsOres.IRARSITE, - MaterialsOres.RADIOBARITE); - - public static WorldGen_GT_Ore_Layer Vein15 = new WorldGen_GT_Ore_Layer( - "vein15", - 5, - 25, - 5, - 3, - 24, - MaterialsOres.FLUORCAPHITE, - MaterialsOres.LAFOSSAITE, - MaterialsOres.GADOLINITE_CE, - MaterialsOres.GADOLINITE_Y); - - public static WorldGen_GT_Ore_Layer Vein16 = new WorldGen_GT_Ore_Layer( - "vein16", - 0, - 25, - 4, - 2, - 32, - MaterialsOres.YTTROCERITE, - MaterialsOres.LEPERSONNITE, - MaterialsOres.LAUTARITE, - MaterialsFluorides.FLUORITE); - - public static WorldGen_GT_Ore_Layer Vein17 = new WorldGen_GT_Ore_Layer( - "vein17", - 10, - 35, - 4, - 1, - 32, - MaterialsOres.FLORENCITE, - MaterialsOres.LAUTARITE, - MaterialsOres.SAMARSKITE_YB, - MaterialsOres.POLYCRASE); - public static WorldGen_GT_Ore_Layer Vein18 = new WorldGen_GT_Ore_Layer( - "vein18", - 15, - 40, - 4, - 1, - 48, - MaterialsOres.GADOLINITE_CE, - MaterialsOres.GADOLINITE_Y, - MaterialsOres.AGARDITE_LA, - MaterialsOres.AGARDITE_CD); - - public static WorldGen_GT_Ore_Layer Vein19 = new WorldGen_GT_Ore_Layer( - "vein19", - 0, - 20, - 4, - 1, - 16, - MaterialsElements.STANDALONE.RUNITE, - MaterialsElements.STANDALONE.RUNITE, - MaterialsElements.STANDALONE.RUNITE, - MaterialsElements.STANDALONE.RUNITE); - public static Hashtable validOreveins = new Hashtable<>(1024); - - static long ID = 0; - - public static void generateValidOreVeins() { - validOreveins.put(ID++, BaseVein); - validOreveins.put(ID++, Vein1); - validOreveins.put(ID++, Vein2); - validOreveins.put(ID++, Vein3); - validOreveins.put(ID++, Vein4); - validOreveins.put(ID++, Vein5); - validOreveins.put(ID++, Vein6); - validOreveins.put(ID++, Vein7); - validOreveins.put(ID++, Vein8); - validOreveins.put(ID++, Vein9); - validOreveins.put(ID++, Vein10); - validOreveins.put(ID++, Vein11); - validOreveins.put(ID++, Vein12); - validOreveins.put(ID++, Vein13); - validOreveins.put(ID++, Vein14); - validOreveins.put(ID++, Vein15); - validOreveins.put(ID++, Vein16); - validOreveins.put(ID++, Vein17); - validOreveins.put(ID++, Vein18); - validOreveins.put(ID++, Vein19); - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java b/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java index 15ed5c2abc0..ead2fe61629 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java @@ -1,15 +1,11 @@ package gtPlusPlus.xmod.gregtech; -import java.util.ArrayList; -import java.util.List; - import cpw.mods.fml.common.event.FMLLoadCompleteEvent; import gregtech.api.GregTechAPI; import gregtech.api.items.MetaGeneratedTool; import gregtech.api.util.GTConfig; import gtPlusPlus.core.handler.CompatHandler; import gtPlusPlus.core.recipe.common.CI; -import gtPlusPlus.everglades.gen.gt.WorldGen_GT; import gtPlusPlus.recipes.CokeAndPyrolyseOven; import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; @@ -28,7 +24,6 @@ public class HandlerGT { public static GTConfig mMaterialProperties = null; - public static final List sWorldgenListEverglades = new ArrayList<>(); public static MetaGeneratedTool sMetaGeneratedToolInstance; public static void preInit() { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Choocher.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Choocher.java deleted file mode 100644 index 5a1bb0eba59..00000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Choocher.java +++ /dev/null @@ -1,91 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.items.behaviours; - -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.items.MetaBaseItem; -import gregtech.api.util.GTLanguageManager; -import gregtech.common.items.behaviors.BehaviourNone; -import gregtech.common.items.behaviors.BehaviourWrench; -import gtPlusPlus.core.util.minecraft.NBTUtils; -import gtPlusPlus.core.util.minecraft.PlayerUtils; - -public class Behaviour_Choocher extends BehaviourNone { - - private final boolean isWrench = true; - private final BehaviourWrench wrench = new BehaviourWrench(150); - private final Behaviour_Prospecting_Ex prospecting = new Behaviour_Prospecting_Ex(10, 1250); - private final String mTooltip1 = GTLanguageManager - .addStringLocalization("gt.behaviour.choochering1", "Current tool mode: "); - private final String mTooltip2 = GTLanguageManager - .addStringLocalization("gt.behaviour.choochering2", "Change tool mode using Shift+Rightclick."); - private final String mTooltipH = GTLanguageManager - .addStringLocalization("gt.behaviour.prospectingEx", "Usable for Prospecting large areas."); - private final String mTooltipW = GTLanguageManager - .addStringLocalization("gt.behaviour.wrench", "Rotates Blocks on Rightclick."); - - public Behaviour_Choocher() {} - - @Override - public boolean onItemUseFirst(final MetaBaseItem aItem, final ItemStack aStack, final EntityPlayer aPlayer, - final World aWorld, final int aX, final int aY, final int aZ, final ForgeDirection side, final float hitX, - final float hitY, final float hitZ) { - if (aWorld.isRemote) { - return false; - } - - boolean inWrenchMode; - if (NBTUtils.hasKey(aStack, "aMode")) { - inWrenchMode = NBTUtils.getBoolean(aStack, "aMode"); - } else { - aStack.getTagCompound() - .setBoolean("aMode", true); - inWrenchMode = true; - } - - if (aPlayer.isSneaking()) { - boolean aModeNew = !inWrenchMode; - aStack.getTagCompound() - .setBoolean("aMode", aModeNew); - PlayerUtils.messagePlayer(aPlayer, "Mode: " + (aModeNew ? "Wrench" : "Hammer")); - return true; - } else { - if (inWrenchMode) { - return this.wrench.onItemUseFirst(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, side, hitZ, hitZ, hitZ); - } else { - return this.prospecting - .onItemUseFirst(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, side, hitX, hitY, hitZ); - } - } - } - - @Override - public List getAdditionalToolTips(final MetaBaseItem aItem, final List aList, - final ItemStack aStack) { - - boolean inWrenchMode; - if (NBTUtils.hasKey(aStack, "aMode")) { - inWrenchMode = NBTUtils.getBoolean(aStack, "aMode"); - } else { - NBTUtils.setBoolean(aStack, "aMode", true); - aStack.getTagCompound() - .setBoolean("aMode", true); - inWrenchMode = true; - } - - if (inWrenchMode) { - aList.add(this.mTooltip1 + "Wrench"); - aList.add(this.mTooltipW); - } else { - aList.add(this.mTooltip1 + "Prospecting"); - aList.add(this.mTooltipH); - } - aList.add(this.mTooltip2); - - return aList; - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Prospecting_Ex.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Prospecting_Ex.java deleted file mode 100644 index 4196d399a1c..00000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Prospecting_Ex.java +++ /dev/null @@ -1,138 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.items.behaviours; - -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.IFluidBlock; - -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.enums.SoundResource; -import gregtech.api.items.MetaBaseItem; -import gregtech.api.items.MetaGeneratedTool; -import gregtech.api.objects.ItemData; -import gregtech.api.util.GTModHandler; -import gregtech.api.util.GTOreDictUnificator; -import gregtech.api.util.GTUtility; -import gregtech.common.blocks.BlockOres; -import gregtech.common.blocks.TileEntityOres; -import gregtech.common.items.behaviors.BehaviourProspecting; - -public class Behaviour_Prospecting_Ex extends BehaviourProspecting { - - private final int mVanillaCosts; - private final int mEUCosts; - - public Behaviour_Prospecting_Ex(final int aVanillaCosts, final int aEUCosts) { - super(aVanillaCosts, aEUCosts); - this.mVanillaCosts = aVanillaCosts; - this.mEUCosts = aEUCosts; - } - - @Override - public boolean onItemUseFirst(final MetaBaseItem aItem, final ItemStack aStack, final EntityPlayer aPlayer, - final World aWorld, final int aX, final int aY, final int aZ, final ForgeDirection side, final float hitX, - final float hitY, final float hitZ) { - if (aWorld.isRemote) { - return false; - } - final Block aBlock = aWorld.getBlock(aX, aY, aZ); - if (aBlock == null) { - return false; - } - final byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); - - ItemData tAssotiation = GTOreDictUnificator.getAssociation(new ItemStack(aBlock, 1, aMeta)); - if ((tAssotiation != null) && (tAssotiation.mPrefix.toString() - .startsWith("ore"))) { - GTUtility - .sendChatToPlayer(aPlayer, "This is " + tAssotiation.mMaterial.mMaterial.mDefaultLocalName + " Ore."); - GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); - return true; - } - if ((aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone)) - || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTechAPI.sBlockGranites)) - || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.netherrack)) - || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.end_stone)) - || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.dirt)) - || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.grass))) { - if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) { - GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); - int tX = aX; - int tY = aY; - int tZ = aZ; - int tMetaID = 0; - final int tQuality = ((aItem instanceof MetaGeneratedTool) ? aItem.getHarvestLevel(aStack, "") : 0) * 3; - - int i = 0; - for (final int j = 6 + tQuality; i < j; i++) { - tX -= side.offsetX; - tY -= side.offsetY; - tZ -= side.offsetZ; - - final Block tBlock = aWorld.getBlock(tX, tY, tZ); - if ((tBlock == Blocks.lava) || (tBlock == Blocks.flowing_lava)) { - GTUtility.sendChatToPlayer(aPlayer, "There is Lava behind this Block."); - break; - } - if ((tBlock == Blocks.water) || (tBlock == Blocks.flowing_water) - || ((tBlock instanceof IFluidBlock))) { - GTUtility.sendChatToPlayer(aPlayer, "There is a Liquid behind this Block."); - break; - } - if ((tBlock == Blocks.monster_egg) || (!GTUtility.hasBlockHitBox(aWorld, tX, tY, tZ))) { - GTUtility.sendChatToPlayer(aPlayer, "There is an Air Pocket behind this Block."); - break; - } - if (tBlock != aBlock) { - if (i >= 4) { - break; - } - GTUtility.sendChatToPlayer(aPlayer, "Material is changing behind this Block."); - break; - } - } - final Random tRandom = new Random(aX ^ aY ^ aZ ^ side.ordinal()); - i = 0; - for (final int j = 9 + (2 * tQuality); i < j; i++) { - tX = (aX - 4 - tQuality) + tRandom.nextInt(j); - tY = (aY - 4 - tQuality) + tRandom.nextInt(j); - tZ = (aZ - 4 - tQuality) + tRandom.nextInt(j); - final Block tBlock = aWorld.getBlock(tX, tY, tZ); - if ((tBlock instanceof BlockOres)) { - final TileEntity tTileEntity = aWorld.getTileEntity(tX, tY, tZ); - if ((tTileEntity instanceof TileEntityOres)) { - final Materials tMaterial = GregTechAPI.sGeneratedMaterials[(((TileEntityOres) tTileEntity).mMetaData - % 1000)]; - if ((tMaterial != null) && (tMaterial != Materials._NULL)) { - GTUtility.sendChatToPlayer( - aPlayer, - "Found traces of " + tMaterial.mDefaultLocalName + " Ore."); - return true; - } - } - } else { - tMetaID = aWorld.getBlockMetadata(tX, tY, tZ); - tAssotiation = GTOreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); - if ((tAssotiation != null) && (tAssotiation.mPrefix.toString() - .startsWith("ore"))) { - GTUtility.sendChatToPlayer( - aPlayer, - "Found traces of " + tAssotiation.mMaterial.mMaterial.mDefaultLocalName + " Ore."); - return true; - } - } - } - GTUtility.sendChatToPlayer(aPlayer, "No Ores found."); - } - return true; - } - return false; - } -} diff --git a/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java b/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java index d325a1085fd..c3341c512b0 100644 --- a/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java +++ b/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java @@ -14,8 +14,9 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.enums.StoneType; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import gtneioreplugin.GTNEIOrePlugin; import gtneioreplugin.plugin.gregtech5.PluginGT5SmallOreStat; import gtneioreplugin.plugin.gregtech5.PluginGT5UndergroundFluid; @@ -62,8 +63,21 @@ public void registerHandlerInfo(NEIRegisterHandlerInfosEvent event) { // Though first two handlers are already registered in NEI jar, we need to re-register // because new DimensionDisplayItems made tabs a bit taller. Map handlers = new HashMap<>(); - handlers.put("PluginGT5VeinStat", GTOreDictUnificator.get(OrePrefixes.ore, Materials.Manyullyn, 1)); - handlers.put("PluginGT5SmallOreStat", GTOreDictUnificator.get(OrePrefixes.ore, Materials.Platinum, 1)); + + OreInfo info = OreInfo.getNewInfo(); + + info.stoneType = StoneType.Stone; + info.material = Materials.Manyullyn; + + handlers.put("PluginGT5VeinStat", OreManager.getStack(info, 1)); + + info.material = Materials.Platinum; + info.isSmall = true; + + handlers.put("PluginGT5SmallOreStat", OreManager.getStack(info, 1)); + + info.release(); + handlers.put("PluginGT5UndergroundFluid", ItemList.Electric_Pump_UEV.get(1)); for (Map.Entry handler : handlers.entrySet()) { event.registerHandlerInfo( diff --git a/src/main/java/gtneioreplugin/plugin/block/BlockDimensionDisplay.java b/src/main/java/gtneioreplugin/plugin/block/BlockDimensionDisplay.java index 055172ebe4f..6dae6c45e91 100644 --- a/src/main/java/gtneioreplugin/plugin/block/BlockDimensionDisplay.java +++ b/src/main/java/gtneioreplugin/plugin/block/BlockDimensionDisplay.java @@ -41,6 +41,7 @@ public void registerBlockIcons(IIconRegister iconRegister) { this.icons[5] = iconRegister.registerIcon("gtneioreplugin:" + dimension + "_right"); } + /** Gets the abbreviated dimension name for this block. */ public String getDimension() { return this.dimension; } diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java index 859ea87bb26..b1b17520f7d 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -4,33 +4,34 @@ import codechicken.lib.gui.GuiDraw; import gregtech.api.enums.Materials; -import gregtech.api.util.GTLanguageManager; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.PluginBase; public abstract class PluginGT5Base extends PluginBase { - public static String getGTOreLocalizedName(short index) { - String name = Materials - .getLocalizedNameForItem(GTLanguageManager.getTranslation(getGTOreUnlocalizedName(index)), index % 1000); - if (!name.contains("Awakened")) return name; - else return "Aw. Draconium Ore"; - } + protected String getGTOreLocalizedName(IOreMaterial ore, boolean small) { + if (ore == Materials.DraconiumAwakened) return "Aw. Draconium Ore"; - protected static String getGTOreUnlocalizedName(short index) { - return "gt.blockores." + index + ".name"; - } + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = ore; + info.isSmall = small; - static void drawLine(String lineKey, String value, int x, int y) { - GuiDraw.drawString(I18n.format(lineKey) + ": " + value, x, y, 0x404040, false); + return OreManager.getLocalizedName(info); + } } - protected int getMaximumMaterialIndex(short meta, boolean smallOre) { - int offset = smallOre ? 16000 : 0; - if (!getGTOreLocalizedName((short) (meta + offset + 5000)) - .equals(getGTOreUnlocalizedName((short) (meta + offset + 5000)))) return 7; - else if (!getGTOreLocalizedName((short) (meta + offset + 5000)) - .equals(getGTOreUnlocalizedName((short) (meta + offset + 5000)))) return 6; - else return 5; + protected void drawLine(String lineKey, String value, int x, int y) { + String text = I18n.format(lineKey) + ": " + value; + + String text2 = text; + + if (GuiDraw.fontRenderer.getStringWidth(text) > getGuiWidth()) { + text2 = GuiDraw.fontRenderer.trimStringToWidth(text, getGuiWidth() - 10); + } + + GuiDraw.drawString(text2 + (text2.length() < text.length() ? "..." : ""), x, y, 0x404040, false); } /** diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java index fb5b298b7b9..3e452c5ef2d 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java @@ -1,8 +1,6 @@ package gtneioreplugin.plugin.gregtech5; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; import java.util.List; import net.minecraft.client.resources.I18n; @@ -10,16 +8,19 @@ import codechicken.nei.PositionedStack; import gregtech.api.enums.OrePrefixes; -import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.enums.OrePrefixes.ParsedOreDictName; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.common.ores.IOreAdapter; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.item.ItemDimensionDisplay; -import gtneioreplugin.util.DimensionHelper; import gtneioreplugin.util.GT5OreSmallHelper; import gtneioreplugin.util.GT5OreSmallHelper.OreSmallWrapper; +import gtneioreplugin.util.GT5OreSmallHelper.SmallOreDimensionWrapper; public class PluginGT5SmallOreStat extends PluginGT5Base { - private static final int SMALL_ORE_BASE_META = 16000; - @Override public void drawExtras(int recipe) { OreSmallWrapper oreSmall = getSmallOre(recipe); @@ -33,90 +34,115 @@ public void drawExtras(int recipe) { } private void drawSmallOreName(OreSmallWrapper oreSmall) { - String oreName = getGTOreLocalizedName((short) (oreSmall.oreMeta + SMALL_ORE_BASE_META)); + String oreName = getGTOreLocalizedName(oreSmall.material, true); drawLine("gtnop.gui.nei.oreName", oreName, 2, 18); } private void drawSmallOreInfo(OreSmallWrapper oreSmall) { drawLine("gtnop.gui.nei.genHeight", oreSmall.worldGenHeightRange, 2, 31); drawLine("gtnop.gui.nei.amount", String.valueOf(oreSmall.amountPerChunk), 2, 44); - drawLine("gtnop.gui.nei.chanceDrops", "", 2, 83 + getRestrictBiomeOffset()); + drawLine("gtnop.gui.nei.chanceDrops", "", 2, 70); drawLine("gtnop.gui.nei.worldNames", "", 2, 100); } private OreSmallWrapper getSmallOre(int recipe) { CachedOreSmallRecipe crecipe = (CachedOreSmallRecipe) this.arecipes.get(recipe); - return GT5OreSmallHelper.mapOreSmallWrapper.get(crecipe.oreGenName); - } - - public int getRestrictBiomeOffset() { - return GT5OreSmallHelper.restrictBiomeSupport ? 0 : -13; + return GT5OreSmallHelper.SMALL_ORES_BY_NAME.get(crecipe.oreGenName); } @Override public void loadCraftingRecipes(String outputId, Object... results) { - if (outputId.equals(getOutputId())) - for (ItemStack stack : GT5OreSmallHelper.oreSmallList) loadCraftingRecipes(stack); - else super.loadCraftingRecipes(outputId, results); + if (outputId.equals(getOutputId())) { + for (ItemStack stack : GT5OreSmallHelper.SMALL_ORE_LIST) { + loadCraftingRecipes(stack); + } + } else { + super.loadCraftingRecipes(outputId, results); + } } @Override public void loadCraftingRecipes(ItemStack stack) { - if (stack.getUnlocalizedName() - .startsWith("gt.blockores")) { - short oreMeta = (short) (stack.getItemDamage() % 1000); - loadSmallOre(oreMeta, getMaximumMaterialIndex(oreMeta, true)); - } else if (GT5OreSmallHelper.mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { - short oreMeta = GT5OreSmallHelper.mapOreDropUnlocalizedNameToOreMeta.get(stack.getUnlocalizedName()); - loadSmallOre(oreMeta, 7); - } else super.loadCraftingRecipes(stack); - } + IOreMaterial mat = OreManager.getMaterial(stack); - @Override - public void loadUsageRecipes(ItemStack stack) { - String dimension = ItemDimensionDisplay.getDimension(stack); - if (dimension == null) { + if (mat == null) { + mat = GT5OreSmallHelper.ORE_DROP_TO_MAT.get(stack.getUnlocalizedName()); + } + + if (mat != null) { + loadSmallOre(mat); return; } - for (OreSmallWrapper oreVein : GT5OreSmallHelper.mapOreSmallWrapper.values()) { - if (Arrays.asList(getDimNameArrayFromVeinName(oreVein.oreGenName)) - .contains(dimension)) { - addSmallOre(oreVein, 7); + boolean isMatItem = false; + + for (ParsedOreDictName oredict : OrePrefixes.detectPrefix(stack)) { + if (!PluginGT5VeinStat.PREFIX_WHITELIST.contains(oredict.prefix)) continue; + + mat = IOreMaterial.findMaterial(oredict.material); + + if (mat != null) { + isMatItem |= loadSmallOre(mat); } } + + if (isMatItem) return; + + super.loadCraftingRecipes(stack); + } + + @Override + public void loadUsageRecipes(ItemStack stack) { + String abbr = ItemDimensionDisplay.getDimension(stack); + if (abbr == null) return; + + SmallOreDimensionWrapper wrapper = GT5OreSmallHelper.getSmallOrebyDim(abbr); + if (wrapper == null) return; + + for (OreSmallWrapper oreVein : wrapper.smallOres) { + addSmallOre(oreVein); + } } - private void loadSmallOre(short oreMeta, int maximumIndex) { - OreSmallWrapper smallOre = getSmallOre(oreMeta); + private boolean loadSmallOre(IOreMaterial material) { + OreSmallWrapper smallOre = GT5OreSmallHelper.SMALL_ORES_BY_MAT.get(material); + if (smallOre != null) { - addSmallOre(smallOre, maximumIndex); + addSmallOre(smallOre); + + return true; + } else { + return false; } } - private OreSmallWrapper getSmallOre(short oreMeta) { - for (OreSmallWrapper oreSmallWorldGen : GT5OreSmallHelper.mapOreSmallWrapper.values()) { - if (oreSmallWorldGen.oreMeta == oreMeta) { - return oreSmallWorldGen; + private void addSmallOre(OreSmallWrapper smallOre) { + + List ores = smallOre.getOreVariants(); + List dusts = new ArrayList<>(); + + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = smallOre.material; + info.isSmall = true; + + IOreAdapter adapter = OreManager.getAdapter(info); + + for (StoneType stoneType : StoneType.STONE_TYPES) { + info.stoneType = stoneType; + + if (adapter.supports(info)) { + ores.add(adapter.getStack(info, 1)); + dusts.add(stoneType.getDust(true, 1)); + } } } - return null; - } - private void addSmallOre(OreSmallWrapper smallOre, int maximumIndex) { this.arecipes.add( new CachedOreSmallRecipe( smallOre.oreGenName, - smallOre.getMaterialDrops(maximumIndex), - getStoneDusts(maximumIndex), - GT5OreSmallHelper.mapOreMetaToOreDrops.get(smallOre.oreMeta))); - } - - private List getStoneDusts(int maximumIndex) { - List materialDustStackList = new ArrayList<>(); - for (int i = 0; i < maximumIndex; i++) materialDustStackList - .add(GTOreDictUnificator.get(OrePrefixes.dust, GT5OreSmallHelper.getDroppedDusts()[i], 1L)); - return materialDustStackList; + ores, + dusts, + GT5OreSmallHelper.ORE_MAT_TO_DROPS.get(smallOre.material))); } @Override @@ -129,19 +155,6 @@ public String getRecipeName() { return I18n.format("gtnop.gui.smallOreStat.name"); } - private String[] getDimNameArrayFromVeinName(String veinName) { - OreSmallWrapper oreSmall = GT5OreSmallHelper.mapOreSmallWrapper.get(veinName); - String[] dims = GT5OreSmallHelper.bufferedDims.get(oreSmall) - .keySet() - .toArray(new String[0]); - Arrays.sort( - dims, - Comparator.comparingInt( - s -> Arrays.asList(DimensionHelper.DimNameDisplayed) - .indexOf(s))); - return dims; - } - public class CachedOreSmallRecipe extends CachedRecipe { public final String oreGenName; @@ -154,14 +167,12 @@ public CachedOreSmallRecipe(String oreGenName, List stackList, List dropStackList) { this.oreGenName = oreGenName; this.positionedStackOreSmall = new PositionedStack(stackList, 2, 0); - this.positionedStackMaterialDust = new PositionedStack( - materialDustStackList, - 43, - 79 + getRestrictBiomeOffset()); + this.positionedStackMaterialDust = new PositionedStack(materialDustStackList, 43, 66); List positionedDropStackList = new ArrayList<>(); int i = 1; - for (ItemStack stackDrop : dropStackList) positionedDropStackList.add( - new PositionedStack(stackDrop, 43 + 20 * (i % 4), 79 + 16 * ((i++) / 4) + getRestrictBiomeOffset())); + for (ItemStack stackDrop : dropStackList) { + positionedDropStackList.add(new PositionedStack(stackDrop, 43 + 20 * (i % 4), 66 + 16 * ((i++) / 4))); + } this.positionedDropStackList = positionedDropStackList; setDimensionDisplayItems(); } @@ -172,8 +183,11 @@ private void setDimensionDisplayItems() { int count = 0; int itemsPerLine = 9; int itemSize = 18; - for (String dim : getDimNameArrayFromVeinName(this.oreGenName)) { - ItemStack item = ItemDimensionDisplay.getItem(dim); + + OreSmallWrapper wrapper = GT5OreSmallHelper.SMALL_ORES_BY_NAME.get(this.oreGenName); + + for (String abbrDimName : wrapper.enabledDims) { + ItemStack item = ItemDimensionDisplay.getItem(abbrDimName); if (item != null) { int xPos = x + itemSize * (count % itemsPerLine); int yPos = y + itemSize * (count / itemsPerLine); diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index cb89a0bc7b3..a920fbd2062 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -9,7 +9,14 @@ import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; +import com.google.common.collect.ImmutableList; + import codechicken.nei.PositionedStack; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.OrePrefixes.ParsedOreDictName; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.util.GTUtility; +import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.item.ItemDimensionDisplay; import gtneioreplugin.util.DimensionHelper; import gtneioreplugin.util.GT5OreLayerHelper; @@ -18,29 +25,81 @@ public class PluginGT5VeinStat extends PluginGT5Base { + // spotless:off + public static final List PREFIX_WHITELIST = ImmutableList.of( + OrePrefixes.dust, + OrePrefixes.dustPure, + OrePrefixes.dustImpure, + OrePrefixes.oreBlackgranite, + OrePrefixes.oreRedgranite, + OrePrefixes.oreMarble, + OrePrefixes.oreBasalt, + OrePrefixes.oreNetherrack, + OrePrefixes.oreNether, + OrePrefixes.oreEndstone, + OrePrefixes.oreEnd, + OrePrefixes.ore, + OrePrefixes.crushedCentrifuged, + OrePrefixes.crushedPurified, + OrePrefixes.crushed, + OrePrefixes.rawOre, + OrePrefixes.gemChipped, + OrePrefixes.gemFlawed, + OrePrefixes.gemFlawless, + OrePrefixes.gemExquisite, + OrePrefixes.gem + ); + // spotless:on + @Override public void loadCraftingRecipes(String outputId, Object... results) { if (outputId.equals(getOutputId())) { for (OreLayerWrapper oreVein : getAllVeins()) { - addVeinWithLayers(oreVein, 7); + addVeinWithLayers(oreVein); } - } else super.loadCraftingRecipes(outputId, results); + } else { + super.loadCraftingRecipes(outputId, results); + } } @Override public void loadCraftingRecipes(ItemStack stack) { - if (stack.getUnlocalizedName() - .startsWith("gt.blockores")) { - loadMatchingVeins((short) (stack.getItemDamage() % 1000)); - } else super.loadCraftingRecipes(stack); + IOreMaterial mat = OreManager.getMaterial(stack); + + if (mat != null) { + loadMatchingVeins(mat); + + return; + } + + boolean isMatItem = false; + + for (ParsedOreDictName oredict : OrePrefixes.detectPrefix(stack)) { + if (!PREFIX_WHITELIST.contains(oredict.prefix)) continue; + + mat = IOreMaterial.findMaterial(oredict.material); + + if (mat != null) { + isMatItem |= loadMatchingVeins(mat); + } + } + + if (isMatItem) return; + + super.loadCraftingRecipes(stack); } - private void loadMatchingVeins(short oreId) { + private boolean loadMatchingVeins(IOreMaterial ore) { + boolean foundAny = false; + for (OreLayerWrapper oreVein : getAllVeins()) { - if (oreVein.containsOre(oreId)) { - addVeinWithLayers(oreVein, getMaximumMaterialIndex(oreId, false)); + if (oreVein.containsOre(ore)) { + addVeinWithLayers(oreVein); + foundAny = true; } } + + return foundAny; } @Override @@ -53,23 +112,24 @@ public void loadUsageRecipes(ItemStack stack) { for (OreLayerWrapper oreVein : getAllVeins()) { if (Arrays.asList(getDimNameArrayFromVeinName(oreVein.veinName)) .contains(dimension)) { - addVeinWithLayers(oreVein, getMaximumMaterialIndex((short) (stack.getItemDamage() % 1000), false)); + addVeinWithLayers(oreVein); } } } - private void addVeinWithLayers(OreLayerWrapper oreVein, int maximumMaterialIndex) { + private void addVeinWithLayers(OreLayerWrapper oreVein) { this.arecipes.add( new CachedVeinStatRecipe( oreVein.veinName, - oreVein.getVeinLayerOre(maximumMaterialIndex, OreVeinLayer.VEIN_PRIMARY), - oreVein.getVeinLayerOre(maximumMaterialIndex, OreVeinLayer.VEIN_SECONDARY), - oreVein.getVeinLayerOre(maximumMaterialIndex, OreVeinLayer.VEIN_BETWEEN), - oreVein.getVeinLayerOre(maximumMaterialIndex, OreVeinLayer.VEIN_SPORADIC))); + oreVein.getVeinLayerOre(OreVeinLayer.VEIN_PRIMARY), + oreVein.getVeinLayerOre(OreVeinLayer.VEIN_SECONDARY), + oreVein.getVeinLayerOre(OreVeinLayer.VEIN_BETWEEN), + oreVein.getVeinLayerOre(OreVeinLayer.VEIN_SPORADIC))); } private Collection getAllVeins() { - return GT5OreLayerHelper.mapOreLayerWrapper.values(); + return GT5OreLayerHelper.getOreVeinsByName() + .values(); } @Override @@ -87,33 +147,33 @@ public void drawExtras(int recipe) { private OreLayerWrapper getOreLayer(int recipe) { CachedVeinStatRecipe crecipe = (CachedVeinStatRecipe) this.arecipes.get(recipe); - return GT5OreLayerHelper.mapOreLayerWrapper.get(crecipe.veinName); + return GT5OreLayerHelper.getVeinByName(crecipe.veinName); } - private static void drawVeinName(OreLayerWrapper oreLayer) { + private void drawVeinName(OreLayerWrapper oreLayer) { drawVeinNameLine(oreLayer.localizedName + " "); } - private static void drawVeinNameLine(String veinName) { + private void drawVeinNameLine(String veinName) { drawLine("gtnop.gui.nei.veinName", veinName + I18n.format("gtnop.gui" + ".nei.vein"), 2, 20); } - private static void drawVeinLayerNames(OreLayerWrapper oreLayer) { + private void drawVeinLayerNames(OreLayerWrapper oreLayer) { drawVeinLayerNameLine(oreLayer, OreVeinLayer.VEIN_PRIMARY, 50); drawVeinLayerNameLine(oreLayer, OreVeinLayer.VEIN_SECONDARY, 60); drawVeinLayerNameLine(oreLayer, OreVeinLayer.VEIN_BETWEEN, 70); drawVeinLayerNameLine(oreLayer, OreVeinLayer.VEIN_SPORADIC, 80); } - private static void drawVeinLayerNameLine(OreLayerWrapper oreLayer, int veinLayer, int height) { + private void drawVeinLayerNameLine(OreLayerWrapper oreLayer, int veinLayer, int height) { drawLine( OreVeinLayer.getOreVeinLayerName(veinLayer), - getGTOreLocalizedName(oreLayer.Meta[veinLayer]), + getGTOreLocalizedName(oreLayer.ores[veinLayer], false), 2, height); } - private static void drawVeinInfo(OreLayerWrapper oreLayer) { + private void drawVeinInfo(OreLayerWrapper oreLayer) { drawLine("gtnop.gui.nei.genHeight", oreLayer.worldGenHeightRange, 2, 90); drawLine("gtnop.gui.nei.weightedChance", Integer.toString(oreLayer.randomWeight), 100, 90); } @@ -129,15 +189,9 @@ public String getRecipeName() { } private String[] getDimNameArrayFromVeinName(String veinName) { - OreLayerWrapper oreLayer = GT5OreLayerHelper.mapOreLayerWrapper.get(veinName); - String[] dims = (GT5OreLayerHelper.bufferedDims.get(oreLayer) - .keySet() - .toArray(new String[0])); - Arrays.sort( - dims, - Comparator.comparingInt( - s -> Arrays.asList(DimensionHelper.DimNameDisplayed) - .indexOf(s))); + OreLayerWrapper oreLayer = GT5OreLayerHelper.getVeinByName(veinName); + String[] dims = oreLayer.abbrDimNames.toArray(new String[0]); + Arrays.sort(dims, Comparator.comparingInt(s -> GTUtility.indexOf(DimensionHelper.DimNameDisplayed, s))); return dims; } @@ -191,9 +245,9 @@ public PositionedStack getResult() { public List getOtherStacks() { List outputs = new ArrayList<>(); positionedStackPrimary.setPermutationToRender((cycleticks / 20) % positionedStackPrimary.items.length); - positionedStackSecondary.setPermutationToRender((cycleticks / 20) % positionedStackPrimary.items.length); - positionedStackBetween.setPermutationToRender((cycleticks / 20) % positionedStackPrimary.items.length); - positionedStackSporadic.setPermutationToRender((cycleticks / 20) % positionedStackPrimary.items.length); + positionedStackSecondary.setPermutationToRender((cycleticks / 20) % positionedStackSecondary.items.length); + positionedStackBetween.setPermutationToRender((cycleticks / 20) % positionedStackBetween.items.length); + positionedStackSporadic.setPermutationToRender((cycleticks / 20) % positionedStackSporadic.items.length); outputs.add(positionedStackPrimary); outputs.add(positionedStackSecondary); outputs.add(positionedStackBetween); diff --git a/src/main/java/gtneioreplugin/plugin/item/ItemDimensionDisplay.java b/src/main/java/gtneioreplugin/plugin/item/ItemDimensionDisplay.java index 9c7c7b06fe6..13889107ac8 100644 --- a/src/main/java/gtneioreplugin/plugin/item/ItemDimensionDisplay.java +++ b/src/main/java/gtneioreplugin/plugin/item/ItemDimensionDisplay.java @@ -35,6 +35,7 @@ public static ItemStack getItem(String dimension) { return null; } + /** Gets the abbreviated dimension name for this block. */ public static String getDimension(ItemStack stack) { if (stack.getItem() instanceof ItemDimensionDisplay) { return ((BlockDimensionDisplay) Block.getBlockFromItem(stack.getItem())).getDimension(); diff --git a/src/main/java/gtneioreplugin/plugin/renderer/ItemDimensionDisplayRenderer.java b/src/main/java/gtneioreplugin/plugin/renderer/ItemDimensionDisplayRenderer.java index 547ad529511..036c4d32ef6 100644 --- a/src/main/java/gtneioreplugin/plugin/renderer/ItemDimensionDisplayRenderer.java +++ b/src/main/java/gtneioreplugin/plugin/renderer/ItemDimensionDisplayRenderer.java @@ -61,7 +61,7 @@ public void renderItem(ItemRenderType type, ItemStack stack, Object... data) { // See DimensionHelper.DimNameDisplayed for real names of these. public static long getPrefix(String dimName) { return switch (dimName) { - case "Ow", "Ne", "TF", "ED", "VA", "EA" -> 0L; + case "Ow", "Ne", "TF", "ED", "VA", "EA", "Eg" -> 0L; case "Mo" -> 1L; case "De", "Ma", "Ph" -> 2L; case "As", "Ca", "Ce", "Eu", "Ga", "Rb" -> 3L; diff --git a/src/main/java/gtneioreplugin/util/CSVMaker.java b/src/main/java/gtneioreplugin/util/CSVMaker.java index 814b684aacb..d215d74d5dd 100644 --- a/src/main/java/gtneioreplugin/util/CSVMaker.java +++ b/src/main/java/gtneioreplugin/util/CSVMaker.java @@ -7,10 +7,10 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import gtneioreplugin.Config; import gtneioreplugin.GTNEIOrePlugin; -import gtneioreplugin.plugin.gregtech5.PluginGT5VeinStat; import gtneioreplugin.util.GT5OreLayerHelper.OreLayerWrapper; // todo: yeet any opencsv usage. @@ -18,7 +18,7 @@ public class CSVMaker implements Runnable { public void runSmallOres() { try { - Iterator> it = GT5OreSmallHelper.mapOreSmallWrapper + Iterator> it = GT5OreSmallHelper.SMALL_ORES_BY_NAME .entrySet() .iterator(); List SmallOreVeins = new ArrayList<>(); @@ -28,13 +28,11 @@ public void runSmallOres() { Map.Entry pair = it.next(); GT5OreSmallHelper.OreSmallWrapper oreLayer = pair.getValue(); - Map Dims = GT5OreSmallHelper.bufferedDims.get(oreLayer); - oremix.setOreName(oreLayer.oreGenName); - oremix.setOreMeta(oreLayer.oreMeta); + oremix.setOreMaterial(oreLayer.material.getInternalName()); oremix.setHeight(oreLayer.worldGenHeightRange); oremix.setAmount(oreLayer.amountPerChunk); - oremix.setDims(Dims); + oremix.setDims(oreLayer.enabledDims); SmallOreVeins.add(oremix); @@ -68,31 +66,32 @@ public void run() { public void runVeins() { try { - Iterator> it = GT5OreLayerHelper.mapOreLayerWrapper.entrySet() + Iterator> it = GT5OreLayerHelper.getOreVeinsByName() + .entrySet() .iterator(); List OreVeins = new ArrayList<>(); while (it.hasNext()) { Oremix oremix = new Oremix(); Map.Entry pair = it.next(); - Map Dims = GT5OreLayerHelper.bufferedDims.get(pair.getValue()); + Set Dims = pair.getValue().abbrDimNames; OreLayerWrapper oreLayer = pair.getValue(); oremix.setOreMixName(oreLayer.veinName); - oremix.setPrimary(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.Meta[0])); - oremix.setSecondary(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.Meta[1])); - oremix.setInbetween(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.Meta[2])); - oremix.setSporadic(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.Meta[3])); + oremix.setPrimary(oreLayer.ores[0].getInternalName()); + oremix.setSecondary(oreLayer.ores[1].getInternalName()); + oremix.setInbetween(oreLayer.ores[2].getInternalName()); + oremix.setSporadic(oreLayer.ores[3].getInternalName()); oremix.setSize(oreLayer.size); oremix.setHeight(oreLayer.worldGenHeightRange); oremix.setDensity(oreLayer.density); oremix.setWeight(oreLayer.randomWeight); oremix.setOreMixIDs( - Integer.toString(oreLayer.Meta[0]) + "|" - + Integer.toString(oreLayer.Meta[1]) + oreLayer.ores[0].getInternalName() + "|" + + oreLayer.ores[1].getInternalName() + "|" - + Integer.toString(oreLayer.Meta[2]) + + oreLayer.ores[2].getInternalName() + "|" - + Integer.toString(oreLayer.Meta[3])); + + oreLayer.ores[3].getInternalName()); oremix.setDims(Dims); OreVeins.add(oremix); diff --git a/src/main/java/gtneioreplugin/util/DimensionHelper.java b/src/main/java/gtneioreplugin/util/DimensionHelper.java index d7725844ef0..c46e48d21c1 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -11,8 +11,9 @@ import static galacticgreg.api.enums.DimensionDef.DimNames.DEEPDARK; import static galacticgreg.api.enums.DimensionDef.DimNames.DEIMOS; import static galacticgreg.api.enums.DimensionDef.DimNames.ENCELADUS; -import static galacticgreg.api.enums.DimensionDef.DimNames.ENDASTEROIDS; +import static galacticgreg.api.enums.DimensionDef.DimNames.ENDASTEROID; import static galacticgreg.api.enums.DimensionDef.DimNames.EUROPA; +import static galacticgreg.api.enums.DimensionDef.DimNames.EVERGLADES; import static galacticgreg.api.enums.DimensionDef.DimNames.GANYMEDE; import static galacticgreg.api.enums.DimensionDef.DimNames.HAUMEA; import static galacticgreg.api.enums.DimensionDef.DimNames.HORUS; @@ -26,7 +27,9 @@ import static galacticgreg.api.enums.DimensionDef.DimNames.MIRANDA; import static galacticgreg.api.enums.DimensionDef.DimNames.MOON; import static galacticgreg.api.enums.DimensionDef.DimNames.NEPER; +import static galacticgreg.api.enums.DimensionDef.DimNames.NETHER; import static galacticgreg.api.enums.DimensionDef.DimNames.OBERON; +import static galacticgreg.api.enums.DimensionDef.DimNames.OW; import static galacticgreg.api.enums.DimensionDef.DimNames.PHOBOS; import static galacticgreg.api.enums.DimensionDef.DimNames.PLUTO; import static galacticgreg.api.enums.DimensionDef.DimNames.PROTEUS; @@ -34,26 +37,28 @@ import static galacticgreg.api.enums.DimensionDef.DimNames.ROSS128BA; import static galacticgreg.api.enums.DimensionDef.DimNames.SETH; import static galacticgreg.api.enums.DimensionDef.DimNames.TCETIE; +import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; import static galacticgreg.api.enums.DimensionDef.DimNames.TITAN; import static galacticgreg.api.enums.DimensionDef.DimNames.TRITON; +import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; import static galacticgreg.api.enums.DimensionDef.DimNames.VEGAB; import static galacticgreg.api.enums.DimensionDef.DimNames.VENUS; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; -import java.util.Map; +import java.util.Set; import net.minecraft.util.StatCollector; -import gregtech.common.OreMixBuilder; import gtneioreplugin.Config; public class DimensionHelper { public static final String[] DimName = { // Non GC dimensions in progression order instead of alphabetical - "Overworld", "Nether", "Twilight", "TheEnd", "EndAsteroid", + "Overworld", "Nether", "Twilight", "The End", "EndAsteroid", "dimensionDarkWorld", // T1 "GalacticraftCore_Moon", // T2 @@ -93,8 +98,9 @@ public class DimensionHelper { "Ow", // Overworld "Ne", // Nether "TF", // Twilight - "ED", // TheEnd because En = Encalus + "ED", // The End because En = Encalus "EA", // EndAsteroid + "Eg", // Everglades // T1 "Mo", // GalacticraftCore_Moon // T2 @@ -161,9 +167,9 @@ private static List computeString(String line) { case "Io", "Mercury", "Venus" -> "T4: " + s; case "Enceladus", "Miranda", "Oberon", "Titan", "Ross128ba" -> "T5: " + s; case "Proteus", "Triton" -> "T6: " + s; - case "Haumea", "Kuiperbelt", "MakeMake", "Pluto" -> "T7: " + s; + case "Haumea", "Kuiper Belt", "MakeMake", "Pluto" -> "T7: " + s; case "BarnardC", "BarnardE", "BarnardF", "CentauriA", "TcetiE", "VegaB" -> "T8: " + s; - case "Anubis", "Horus", "Maahes", "MehenBelt", "Neper", "Seth" -> "T9: " + s; + case "Anubis", "Horus", "Maahes", "Mehen Belt", "Neper", "Seth" -> "T9: " + s; case "Underdark" -> "T10: " + s; default -> s; }; @@ -194,30 +200,16 @@ public static String[] parseDimNames(String line) { return dims; } - public static Map getDims(GT5OreLayerHelper.OreLayerWrapper oreLayer) { - Map enabledDims = new HashMap<>(); - Map origNames = oreLayer.allowedDimWithOrigNames; + public static Set getDims(GT5OreLayerHelper.OreLayerWrapper oreLayer) { + Set enabledDims = new HashSet<>(); + Set origNames = oreLayer.allowedDimWithOrigNames; - for (String dimName : origNames.keySet()) { + for (String dimName : origNames) { String abbr = getDimAbbreviatedName(dimName); - if (!origNames.getOrDefault(dimName, false)) { + if (!origNames.contains(dimName)) { continue; } - enabledDims.put(abbr, true); - } - return enabledDims; - } - - public static Map getDims(GT5OreSmallHelper.OreSmallWrapper ore) { - Map enabledDims = new HashMap<>(); - Map origNames = ore.allowedDimWithOrigNames; - - for (String dimName : origNames.keySet()) { - String abbr = getDimAbbreviatedName(dimName); - if (!origNames.getOrDefault(dimName, false)) { - continue; - } - enabledDims.put(abbr, true); + enabledDims.add(abbr); } return enabledDims; } @@ -225,11 +217,12 @@ public static Map getDims(GT5OreSmallHelper.OreSmallWrapper ore public static String getDimAbbreviatedName(String dimName) { String abbreviatedName; switch (dimName) { - case (OreMixBuilder.OW) -> abbreviatedName = "Ow"; // Overworld - case OreMixBuilder.NETHER -> abbreviatedName = "Ne"; // Nether - case OreMixBuilder.TWILIGHT_FOREST -> abbreviatedName = "TF"; // Twilight - case OreMixBuilder.THE_END -> abbreviatedName = "ED"; // TheEnd because En = Encalus - case ENDASTEROIDS -> abbreviatedName = "EA"; // EndAsteroid + case OW -> abbreviatedName = "Ow"; // Overworld + case NETHER -> abbreviatedName = "Ne"; // Nether + case TWILIGHT_FOREST -> abbreviatedName = "TF"; // Twilight + case THE_END -> abbreviatedName = "ED"; // The End because En = Encalus + case ENDASTEROID -> abbreviatedName = "EA"; // EndAsteroid + case EVERGLADES -> abbreviatedName = "Eg"; // T1 case MOON -> abbreviatedName = "Mo"; // GalacticraftCore_Moon // T2 @@ -284,14 +277,15 @@ public static String getDimAbbreviatedName(String dimName) { return abbreviatedName; } - public static String getFullName(String dimName) { + public static String getFullName(String abbrDimName) { - return switch (dimName) { - case "Ow" -> (OreMixBuilder.OW); // Overworld - case "Ne" -> OreMixBuilder.NETHER; // Nether - case "TF" -> OreMixBuilder.TWILIGHT_FOREST; // Twilight - case "ED" -> OreMixBuilder.THE_END; // TheEnd because En = Encalus - case "EA" -> ENDASTEROIDS; // EndAsteroid + return switch (abbrDimName) { + case "Ow" -> OW; // Overworld + case "Ne" -> NETHER; // Nether + case "TF" -> TWILIGHT_FOREST; // Twilight + case "ED" -> THE_END; // The End because En = Encalus + case "EA" -> ENDASTEROID; // EndAsteroid + case "Eg" -> EVERGLADES; // T1 case "Mo" -> MOON; // GalacticraftCore_Moon // T2 @@ -340,7 +334,7 @@ public static String getFullName(String dimName) { // T10 case "DD" -> DEEPDARK; // Underdark default -> { - throw new IllegalStateException("String: " + dimName + " has no abbredged name!"); + throw new IllegalStateException("String: " + abbrDimName + " has no abbredged name!"); } }; } diff --git a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java index 0e8e5b34621..fcdcd2ab051 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -5,89 +5,90 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; import net.minecraft.item.ItemStack; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; +import com.google.common.collect.ImmutableMap; + import gregtech.api.enums.OreMixes; +import gregtech.api.interfaces.IOreMaterial; +import gregtech.api.interfaces.IStoneType; import gregtech.common.OreMixBuilder; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; public class GT5OreLayerHelper { - public static class NormalOreDimensionWrapper { + /** {vein ore mix name: wrapper} */ + private static Map ORE_VEINS_BY_NAME; - public final ArrayList internalDimOreList = new ArrayList<>(); - public final HashMap oreVeinToProbabilityInDimension = new HashMap<>(); + /** {abbr dim name: wrapper} */ + private static Map ORE_VEINS_BY_DIM; - // Calculate all weights of ore veins once dimension is initialised. - private void calculateWeights() { - int totalWeight = 0; - for (OreLayerWrapper oreVein : internalDimOreList) { - totalWeight += oreVein.randomWeight; - } - for (OreLayerWrapper oreVein : internalDimOreList) { - oreVeinToProbabilityInDimension.put(oreVein, ((double) oreVein.randomWeight) / ((double) totalWeight)); + public static void init() { + HashMap byName = new HashMap<>(); + HashMap byDim = new HashMap<>(); + + for (OreMixes mix : OreMixes.values()) { + OreLayerWrapper wrapper = new OreLayerWrapper(mix.oreMixBuilder); + byName.put(mix.oreMixBuilder.oreMixName, wrapper); + + for (String dim : wrapper.abbrDimNames) { + NormalOreDimensionWrapper dimensionOres = byDim.getOrDefault(dim, new NormalOreDimensionWrapper()); + dimensionOres.oreVeins.add(wrapper); + byDim.put(dim, dimensionOres); } } - } - private static final int DIMENSION_COUNT = 33; - public static final Integer[] weightPerWorld = new Integer[DIMENSION_COUNT]; - public static final Integer[] DimIDs = new Integer[DIMENSION_COUNT]; - public static final HashMap mapOreLayerWrapper = new HashMap<>(); - public static final HashMap> bufferedDims = new HashMap<>(); - public static final HashMap dimToOreWrapper = new HashMap<>(); + // Calculate probabilities for each dim. + byDim.values() + .forEach(NormalOreDimensionWrapper::calculateWeights); - public static void init() { - Arrays.fill(weightPerWorld, 0); - Arrays.fill(DimIDs, 0); - for (OreMixes mix : OreMixes.values()) - mapOreLayerWrapper.put(mix.oreMixBuilder.oreMixName, new OreLayerWrapper(mix.oreMixBuilder)); - for (OreLayerWrapper layer : mapOreLayerWrapper.values()) { - bufferedDims.put(layer, DimensionHelper.getDims(layer)); - } + ORE_VEINS_BY_NAME = ImmutableMap.copyOf(byName); + ORE_VEINS_BY_DIM = ImmutableMap.copyOf(byDim); + } - // --- Handling of dimToOreWrapper --- + public static OreLayerWrapper getVeinByName(String name) { + return ORE_VEINS_BY_NAME.get(name); + } - // Get dims as "Ow,Ne,Ma" etc. - bufferedDims.forEach((veinInfo, dims) -> { + public static NormalOreDimensionWrapper getVeinByDim(String abbrName) { + return ORE_VEINS_BY_DIM.get(abbrName); + } - for (String dim : dims.keySet()) { - NormalOreDimensionWrapper dimensionOres = dimToOreWrapper - .getOrDefault(dim, new NormalOreDimensionWrapper()); - dimensionOres.internalDimOreList.add(veinInfo); - dimToOreWrapper.put(dim, dimensionOres); - } + public static Map getOreVeinsByName() { + return ORE_VEINS_BY_NAME; + } - // Calculate probabilities for each dim. - for (String dim : dimToOreWrapper.keySet()) { - dimToOreWrapper.get(dim) - .calculateWeights(); - } - }); - // --- End of handling for dimToOreWrapper --- + public static Map getOreVeinsByDim() { + return ORE_VEINS_BY_DIM; } public static class OreLayerWrapper { public final String veinName, worldGenHeightRange, localizedName; - public final short[] Meta = new short[4]; + public final IOreMaterial[] ores = new IOreMaterial[4]; public final short randomWeight, size, density; - public final Map allowedDimWithOrigNames; + /** {full dim name} */ + public final Set allowedDimWithOrigNames; + /** {abbr dim name} */ + public final Set abbrDimNames; - public final Materials mPrimaryVeinMaterial; - public final Materials mSecondaryMaterial; - public final Materials mBetweenMaterial; - public final Materials mSporadicMaterial; + public final IOreMaterial mPrimaryVeinMaterial; + public final IOreMaterial mSecondaryMaterial; + public final IOreMaterial mBetweenMaterial; + public final IOreMaterial mSporadicMaterial; public OreLayerWrapper(OreMixBuilder mix) { this.veinName = mix.oreMixName; this.localizedName = mix.localizedName; - this.Meta[0] = (short) mix.primary.mMetaItemSubID; - this.Meta[1] = (short) mix.secondary.mMetaItemSubID; - this.Meta[2] = (short) mix.between.mMetaItemSubID; - this.Meta[3] = (short) mix.sporadic.mMetaItemSubID; + this.ores[0] = mix.primary; + this.ores[1] = mix.secondary; + this.ores[2] = mix.between; + this.ores[3] = mix.sporadic; this.mPrimaryVeinMaterial = mix.primary; this.mSecondaryMaterial = mix.secondary; @@ -100,25 +101,53 @@ public OreLayerWrapper(OreMixBuilder mix) { this.randomWeight = (short) mix.weight; this.allowedDimWithOrigNames = mix.dimsEnabled; + this.abbrDimNames = mix.dimsEnabled.stream() + .map(DimensionHelper::getDimAbbreviatedName) + .collect(Collectors.toSet()); } - public List getVeinLayerOre(int maximumMaterialIndex, int veinLayer) { + public List getVeinLayerOre(int veinLayer) { List stackList = new ArrayList<>(); - for (int i = 0; i < maximumMaterialIndex; i++) { - stackList.add(getLayerOre(veinLayer, i)); + for (IStoneType stoneType : ores[veinLayer].getValidStones()) { + if (!stoneType.isExtraneous()) { + stackList.add(getLayerOre(veinLayer, stoneType)); + } } return stackList; } - public ItemStack getLayerOre(int veinLayer, int materialIndex) { - return new ItemStack(GregTechAPI.sBlockOres1, 1, Meta[veinLayer] + materialIndex * 1000); + public ItemStack getLayerOre(int veinLayer, IStoneType stoneType) { + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = ores[veinLayer]; + info.stoneType = stoneType; + + return Objects.requireNonNull( + OreManager.getStack(info, 1), + "getLayerOre: " + veinLayer + ", " + stoneType + ", " + Arrays.toString(ores)); + } } - public boolean containsOre(short materialIndex) { - return Meta[OreVeinLayer.VEIN_PRIMARY] == materialIndex - || Meta[OreVeinLayer.VEIN_SECONDARY] == materialIndex - || Meta[OreVeinLayer.VEIN_BETWEEN] == materialIndex - || Meta[OreVeinLayer.VEIN_SPORADIC] == materialIndex; + public boolean containsOre(IOreMaterial material) { + return ores[OreVeinLayer.VEIN_PRIMARY] == material || ores[OreVeinLayer.VEIN_SECONDARY] == material + || ores[OreVeinLayer.VEIN_BETWEEN] == material + || ores[OreVeinLayer.VEIN_SPORADIC] == material; + } + } + + public static class NormalOreDimensionWrapper { + + public final ArrayList oreVeins = new ArrayList<>(); + public final HashMap oreVeinToProbabilityInDimension = new HashMap<>(); + + // Calculate all weights of ore veins once dimension is initialised. + private void calculateWeights() { + int totalWeight = 0; + for (OreLayerWrapper oreVein : oreVeins) { + totalWeight += oreVein.randomWeight; + } + for (OreLayerWrapper oreVein : oreVeins) { + oreVeinToProbabilityInDimension.put(oreVein, ((double) oreVein.randomWeight) / ((double) totalWeight)); + } } } } diff --git a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java index f00e1100209..f3af50d77d0 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java @@ -2,182 +2,177 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import net.minecraft.item.ItemStack; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Multimap; +import com.google.common.collect.MultimapBuilder; + import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SmallOres; -import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.world.GTWorldgen; import gregtech.common.SmallOreBuilder; import gregtech.common.WorldgenGTOreSmallPieces; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; public class GT5OreSmallHelper { - private static final int SMALL_ORE_BASE_META = 16000; - public static boolean restrictBiomeSupport = false; - public static final List oreSmallList = new ArrayList<>(); - public static final HashMap mapOreSmallWrapper = new HashMap<>(); - public static final HashMap mapOreDropUnlocalizedNameToOreMeta = new HashMap<>(); - public static final HashMap> mapOreMetaToOreDrops = new HashMap<>(); - public static final HashMap> bufferedDims = new HashMap<>(); - public static final HashMap dimToSmallOreWrapper = new HashMap<>(); - - public static class SmallOreDimensionWrapper { - - public final ArrayList internalDimOreList = new ArrayList<>(); - public final HashMap oreVeinToProbabilityInDimension = new HashMap<>(); - - // Calculate all weights of ore veins once dimension is initialised. - private void calculateWeights() { - int totalWeight = 0; - for (OreSmallWrapper oreVein : internalDimOreList) { - totalWeight += oreVein.amountPerChunk; - } - for (OreSmallWrapper oreVein : internalDimOreList) { - oreVeinToProbabilityInDimension - .put(oreVein, ((double) oreVein.amountPerChunk) / ((double) totalWeight)); - } - } - } + public static final List SMALL_ORE_LIST = new ArrayList<>(); + public static final HashMap SMALL_ORES_BY_NAME = new HashMap<>(); + public static final HashMap SMALL_ORES_BY_MAT = new HashMap<>(); + public static final HashMap ORE_DROP_TO_MAT = new HashMap<>(); + public static final HashMap> ORE_MAT_TO_DROPS = new HashMap<>(); + /** {abbr dim name: wrapper} */ + private static Map SMALL_ORES_BY_DIM; public static void init() { - ItemStack stack; - Materials material; - short meta; Map smallOreDefMap = new HashMap<>(); for (SmallOres ore : SmallOres.values()) { smallOreDefMap.put(ore.smallOreBuilder.smallOreName, ore.smallOreBuilder); } + Multimap oreSpawning = MultimapBuilder.hashKeys() + .arrayListValues() + .build(); + + OreInfo info = OreInfo.getNewInfo(); + for (GTWorldgen worldGen : GregTechAPI.sWorldgenList) { - if (!worldGen.mWorldGenName.startsWith("ore.small.") - || !(worldGen instanceof WorldgenGTOreSmallPieces worldGenSmallPieces)) { - continue; - } + if (!(worldGen instanceof WorldgenGTOreSmallPieces smallOreWorldGen)) continue; - meta = worldGenSmallPieces.mMeta; - if (meta < 0) break; - material = GregTechAPI.sGeneratedMaterials[meta]; - mapOreSmallWrapper.put( - worldGen.mWorldGenName, - new OreSmallWrapper(smallOreDefMap.get(worldGenSmallPieces.mWorldGenName))); - if (mapOreMetaToOreDrops.containsKey(meta)) { - continue; - } + IOreMaterial material = smallOreWorldGen.getMaterial(); - List stackList = new ArrayList<>(); - stack = GTOreDictUnificator - .get(OrePrefixes.gemExquisite, material, GTOreDictUnificator.get(OrePrefixes.gem, material, 1L), 1L); - if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { - mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta); - stackList.add(stack); - } - stack = GTOreDictUnificator - .get(OrePrefixes.gemFlawless, material, GTOreDictUnificator.get(OrePrefixes.gem, material, 1L), 1L); - if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { - mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta); - stackList.add(stack); - } - stack = GTOreDictUnificator.get(OrePrefixes.gem, material, 1L); - if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { - mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta); - stackList.add(stack); - } - stack = GTOreDictUnificator - .get(OrePrefixes.gemFlawed, material, GTOreDictUnificator.get(OrePrefixes.crushed, material, 1L), 1L); - if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { - mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta); - stackList.add(stack); - } - stack = GTOreDictUnificator.get(OrePrefixes.crushed, material, 1L); - if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { - mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta); - stackList.add(stack); + OreSmallWrapper wrapper = new OreSmallWrapper(smallOreDefMap.get(smallOreWorldGen.mWorldGenName)); + SMALL_ORES_BY_NAME.put(worldGen.mWorldGenName, wrapper); + SMALL_ORES_BY_MAT.put(smallOreWorldGen.getMaterial(), wrapper); + + if (ORE_MAT_TO_DROPS.containsKey(smallOreWorldGen.getMaterial())) { + throw new IllegalStateException( + "Duplicate small ore world gen for material " + smallOreWorldGen.getMaterial()); } - stack = GTOreDictUnificator.get( - OrePrefixes.gemChipped, - material, - GTOreDictUnificator.get(OrePrefixes.dustImpure, material, 1L), - 1L); - if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { - mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta); - stackList.add(stack); + + for (String abbrDimName : wrapper.enabledDims) { + oreSpawning.put(abbrDimName, wrapper); } - stack = GTOreDictUnificator.get(OrePrefixes.dustImpure, material, 1L); - if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { - mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta); - stackList.add(stack); + + info.stoneType = null; + info.material = material; + info.isSmall = true; + + List stackList = OreManager.getPotentialDrops(info); + + ORE_MAT_TO_DROPS.put(material, stackList); + + for (ItemStack stack : stackList) { + ORE_DROP_TO_MAT.put(stack.getUnlocalizedName(), material); } - oreSmallList.add(new ItemStack(GregTechAPI.sBlockOres1, 1, meta + SMALL_ORE_BASE_META)); - mapOreMetaToOreDrops.put(meta, stackList); + info.stoneType = null; + SMALL_ORE_LIST.add(OreManager.getStack(info, 1)); + } + + info.release(); + + HashMap byDim = new HashMap<>(); + + for (String abbrDimName : oreSpawning.keySet()) { + byDim.put(abbrDimName, new SmallOreDimensionWrapper()); } - for (OreSmallWrapper oreSmallWrapper : mapOreSmallWrapper.values()) { - bufferedDims.put(oreSmallWrapper, DimensionHelper.getDims(oreSmallWrapper)); + + for (var e : oreSpawning.entries()) { + byDim.get(e.getKey()).smallOres.add(e.getValue()); } - // --- Handling of dimToOreWrapper --- + byDim.values() + .forEach(SmallOreDimensionWrapper::calculateWeights); - // Get dims as "Ow,Ne,Ma" etc. - bufferedDims.forEach((veinInfo, dims) -> { - for (String dim : dims.keySet()) { - SmallOreDimensionWrapper dimensionSmallOres = dimToSmallOreWrapper - .getOrDefault(dim, new SmallOreDimensionWrapper()); - dimensionSmallOres.internalDimOreList.add(veinInfo); - dimToSmallOreWrapper.put(dim, dimensionSmallOres); - } + SMALL_ORES_BY_DIM = ImmutableMap.copyOf(byDim); + } - // Calculate probabilities for each dim. - for (String dim : dimToSmallOreWrapper.keySet()) { - dimToSmallOreWrapper.get(dim) - .calculateWeights(); - } - }); - // --- End of handling for dimToOreWrapper --- + public static Map getSmallOresByDim() { + return SMALL_ORES_BY_DIM; } - public static Materials[] getDroppedDusts() { - return new Materials[] { Materials.Stone, Materials.Netherrack, Materials.Endstone, Materials.GraniteBlack, - Materials.GraniteRed, Materials.Marble, Materials.Basalt, Materials.Stone }; + public static SmallOreDimensionWrapper getSmallOrebyDim(String abbrName) { + return SMALL_ORES_BY_DIM.get(abbrName); } public static class OreSmallWrapper { public final String oreGenName; - public final short oreMeta; + public final IOreMaterial material; public final String worldGenHeightRange; public final short amountPerChunk; - public final Map allowedDimWithOrigNames; - - @SuppressWarnings("unused") - public Materials getOreMaterial() { - return oreMaterial; - } - - private final Materials oreMaterial; + /** {dimension name: enabled} */ + public final Set allowedDimWithOrigNames; + /** set of: abbriviated dim name */ + public final Set enabledDims; public OreSmallWrapper(SmallOreBuilder ore) { this.oreGenName = ore.smallOreName; - this.oreMeta = (short) ore.ore.mMetaItemSubID; + this.material = ore.ore; this.worldGenHeightRange = ore.minY + "-" + ore.maxY; this.amountPerChunk = (short) ore.amount; - this.oreMaterial = ore.ore; this.allowedDimWithOrigNames = ore.dimsEnabled; + + this.enabledDims = new HashSet<>(); + + for (String dimName : ore.dimsEnabled) { + if (!ore.dimsEnabled.contains(dimName)) { + continue; + } + + this.enabledDims.add(DimensionHelper.getDimAbbreviatedName(dimName)); + } } - public List getMaterialDrops(int maximumIndex) { - List stackList = new ArrayList<>(); - for (int i = 0; i < maximumIndex; i++) - stackList.add(new ItemStack(GregTechAPI.sBlockOres1, 1, oreMeta + SMALL_ORE_BASE_META + i * 1000)); - return stackList; + public List getOreVariants() { + List oreVariants = new ArrayList<>(); + + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = material; + info.isSmall = true; + + for (StoneType stoneType : StoneType.VISUAL_STONE_TYPES) { + info.stoneType = stoneType; + oreVariants.add(OreManager.getStack(info, 1)); + } + } + + return oreVariants; + } + + public boolean generatesInDimension(String abbr) { + return enabledDims.contains(abbr); + } + } + + /** Per-dimension small ore metadata for the EoH. */ + public static class SmallOreDimensionWrapper { + + public final ArrayList smallOres = new ArrayList<>(); + public final HashMap oreVeinProbabilities = new HashMap<>(); + + /** Calculate all weights of ore veins once dimension is initialised. */ + private void calculateWeights() { + int totalWeight = 0; + for (OreSmallWrapper oreVein : smallOres) { + totalWeight += oreVein.amountPerChunk; + } + for (OreSmallWrapper oreVein : smallOres) { + oreVeinProbabilities.put(oreVein, ((double) oreVein.amountPerChunk) / ((double) totalWeight)); + } } } } diff --git a/src/main/java/gtneioreplugin/util/Oremix.java b/src/main/java/gtneioreplugin/util/Oremix.java index be6826110e2..ba2f9e1812f 100644 --- a/src/main/java/gtneioreplugin/util/Oremix.java +++ b/src/main/java/gtneioreplugin/util/Oremix.java @@ -1,6 +1,6 @@ package gtneioreplugin.util; -import java.util.Map; +import java.util.Set; public class Oremix implements Comparable { @@ -26,9 +26,9 @@ public class Oremix implements Comparable { private static final int sizeData = 10; // hors dims - private Map dimensions; + private Set dimensions; - public void setDims(Map dims) { + public void setDims(Set dims) { this.dimensions = dims; } @@ -112,8 +112,7 @@ public String getCsvEntry() { values[8] = Integer.toString(size); values[9] = Integer.toString(weight); for (int i = 0; i < DimensionHelper.DimNameDisplayed.length; i++) { - values[sizeData + i] = Boolean - .toString(dimensions.getOrDefault(DimensionHelper.DimNameDisplayed[i], false)); + values[sizeData + i] = Boolean.toString(dimensions.contains(DimensionHelper.DimNameDisplayed[i])); } return String.join(",", values); } diff --git a/src/main/java/gtneioreplugin/util/SmallOre.java b/src/main/java/gtneioreplugin/util/SmallOre.java index 769ce63b3e8..8e8efa0e026 100644 --- a/src/main/java/gtneioreplugin/util/SmallOre.java +++ b/src/main/java/gtneioreplugin/util/SmallOre.java @@ -2,20 +2,20 @@ import static gtneioreplugin.util.DimensionHelper.DimNameDisplayed; -import java.util.Map; +import java.util.Set; @SuppressWarnings("unused") public class SmallOre implements Comparable { private String oreName; - private int oreMeta; + private String oreMaterial; private int amount; private String height = ""; private static final int sizeData = 4; // hors dims - private Map dimensions; + private Set dimensions; - public void setDims(Map dims) { + public void setDims(Set dims) { this.dimensions = dims; } @@ -27,12 +27,12 @@ public void setOreName(String s) { this.oreName = s; } - public int getOreMeta() { - return this.oreMeta; + public String getOreMaterial() { + return this.oreMaterial; } - public void setOreMeta(int meta) { - this.oreMeta = meta; + public void setOreMaterial(String mat) { + this.oreMaterial = mat; } public String getHeight() { @@ -66,11 +66,11 @@ public static String getCsvHeader() { public String getCsvEntry() { String[] values = new String[sizeData + DimNameDisplayed.length]; values[0] = oreName; - values[1] = Integer.toString(oreMeta); + values[1] = oreMaterial; values[2] = getHeight(); values[3] = Integer.toString(amount); for (int i = 0; i < DimNameDisplayed.length; i++) { - values[sizeData + i] = Boolean.toString(dimensions.getOrDefault(DimNameDisplayed[i], false)); + values[sizeData + i] = Boolean.toString(dimensions.contains(DimNameDisplayed[i])); } return String.join(",", values); } diff --git a/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java index 3314e89356c..1cf5df29621 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java @@ -16,11 +16,12 @@ import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + import gregtech.api.GregTechAPI; import gregtech.api.enums.ItemList; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.ItemOres; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import ic2.api.crops.CropCard; import ic2.api.crops.Crops; import ic2.core.Ic2Items; @@ -394,21 +395,22 @@ private static boolean setBlock(ItemStack stack, int x, int y, int z, World worl Block b = Block.getBlockFromItem(item); if (b == Blocks.air || !(item instanceof ItemBlock)) return false; short tDamage = (short) item.getDamage(stack); - if (item instanceof ItemOres && tDamage > 0) { - if (!world.setBlock( - x, - y, - z, - b, - TileEntityOres - .getHarvestData(tDamage, ((BlockOresAbstract) b).getBaseBlockHarvestLevel(tDamage % 16000 / 1000)), - 0)) { - return false; + + try (OreInfo info = OreManager.getOreInfo(b, tDamage)) { + if (info != null) { + info.isNatural = true; + + ImmutableBlockMeta oreBlock = OreManager.getAdapter(info) + .getBlock(info); + + world.setBlock(x, y, z, oreBlock.getBlock(), oreBlock.getBlockMeta(), 3); + + if (oreBlock.matches(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z))) return true; } - TileEntityOres tTileEntity = (TileEntityOres) world.getTileEntity(x, y, z); - tTileEntity.mMetaData = tDamage; - tTileEntity.mNatural = false; - } else world.setBlock(x, y, z, b, tDamage, 0); + } + + world.setBlock(x, y, z, b, tDamage, 0); + return true; } diff --git a/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java b/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java index 90acd630480..9d9a71621dc 100644 --- a/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java +++ b/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java @@ -355,19 +355,25 @@ private static ArrayList> processDimension( if (normalOreDimWrapper != null) { normalOreDimWrapper.oreVeinToProbabilityInDimension.forEach((veinInfo, probability) -> { - processHelper(outputMap, veinInfo.mPrimaryVeinMaterial, mainMultiplier, probability); - processHelper(outputMap, veinInfo.mSecondaryMaterial, mainMultiplier, probability); + if (veinInfo.mPrimaryVeinMaterial instanceof Materials gtMat) + processHelper(outputMap, gtMat, mainMultiplier, probability); + if (veinInfo.mSecondaryMaterial instanceof Materials gtMat) + processHelper(outputMap, gtMat, mainMultiplier, probability); // 8.0 to replicate void miner getDropsVanillaVeins method yields. - processHelper(outputMap, veinInfo.mBetweenMaterial, mainMultiplier / 8.0, probability); - processHelper(outputMap, veinInfo.mSporadicMaterial, mainMultiplier / 8.0, probability); + if (veinInfo.mBetweenMaterial instanceof Materials gtMat) + processHelper(outputMap, gtMat, mainMultiplier / 8.0, probability); + if (veinInfo.mSporadicMaterial instanceof Materials gtMat) + processHelper(outputMap, gtMat, mainMultiplier / 8.0, probability); }); } // Iterate over small ores in dimension and add them, kinda hacky but works and is close enough. if (smallOreDimWrapper != null) { - smallOreDimWrapper.oreVeinToProbabilityInDimension.forEach( - (veinInfo, - probability) -> processHelper(outputMap, veinInfo.getOreMaterial(), mainMultiplier, probability)); + smallOreDimWrapper.oreVeinProbabilities.forEach( + (veinInfo, probability) -> { + if (veinInfo.material instanceof Materials gtMat) + processHelper(outputMap, gtMat, mainMultiplier, probability); + }); } ArrayList> outputList = new ArrayList<>(); diff --git a/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java b/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java index 9d891fd3ad9..e4df8d3c90b 100644 --- a/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java +++ b/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java @@ -16,6 +16,8 @@ import com.google.common.math.LongMath; +import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.enums.DimensionDef; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; import gregtech.api.enums.MaterialsUEVplus; @@ -25,7 +27,9 @@ import gtneioreplugin.plugin.block.ModBlocks; import gtneioreplugin.util.DimensionHelper; import gtneioreplugin.util.GT5OreLayerHelper; +import gtneioreplugin.util.GT5OreLayerHelper.NormalOreDimensionWrapper; import gtneioreplugin.util.GT5OreSmallHelper; +import gtneioreplugin.util.GT5OreSmallHelper.SmallOreDimensionWrapper; import tectech.util.FluidStackLong; import tectech.util.ItemStackLong; @@ -53,14 +57,17 @@ public class EyeOfHarmonyRecipeStorage { BlockDimensionDisplay blockDimensionDisplay = (BlockDimensionDisplay) ModBlocks.blocks .get(dimAbbreviation); + ModDimensionDef dimensionDef = DimensionDef.getDefByName(DimensionHelper.getFullName(dimAbbreviation)); + + if (dimensionDef != null && !dimensionDef.hasEoHRecipe()) continue; + if (dimAbbreviation.equals("DD")) { specialDeepDarkRecipe(this, blockDimensionDisplay); } else { - GT5OreLayerHelper.NormalOreDimensionWrapper normalOre = GT5OreLayerHelper.dimToOreWrapper - .getOrDefault(dimAbbreviation, null); - GT5OreSmallHelper.SmallOreDimensionWrapper smallOre = GT5OreSmallHelper.dimToSmallOreWrapper - .getOrDefault(dimAbbreviation, null); + NormalOreDimensionWrapper normalOre = GT5OreLayerHelper.getVeinByDim(dimAbbreviation); + SmallOreDimensionWrapper smallOre = GT5OreSmallHelper.getSmallOrebyDim(dimAbbreviation); + if (normalOre == null && smallOre == null) { // No ores are generated in this dimension. Fail silently. continue; diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index 2478fdc8188..9034a7bf665 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -622,6 +622,7 @@ GT5U.gui.text.out_of_fluid=§4No following fluids supplied: §b%s§f x §6%s L GT5U.gui.text.out_of_item=§4No following items supplied: §b%s§f x §6%s GT5U.gui.text.out_of_stuff=§4No following stuffs supplied: §b%s§f x §6%s GT5U.gui.text.power_loss=§4Shut down due to power loss. +GT5U.gui.text.no_void_mining=§4Cannot void mine this dimension (%s). GT5U.gui.text.pollution_fail=§4Failed to output the pollution. GT5U.gui.text.structure_incomplete=§4Shut down due to incomplete structure. GT5U.gui.text.no_repair=§4Shut down due to machine damage. @@ -660,7 +661,6 @@ GT5U.gui.config.machine_stats.mass_fabricator=Mass Fabricator GT5U.gui.config.machine_stats.teleporter=Teleporter GT5U.gui.config.machine_stats.cleanroom=Cleanroom GT5U.gui.config.worldgen=Worldgen -GT5U.gui.config.worldgen.end_asteroids=End Asteroids GT5U.gui.config.worldgen.general=General # Note to translators: this translation entry is supposed to be a number indicating how many taunts you define here diff --git a/src/main/resources/assets/gtneioreplugin/lang/en_US.lang b/src/main/resources/assets/gtneioreplugin/lang/en_US.lang index c8437cc9306..936ebbc60ca 100644 --- a/src/main/resources/assets/gtneioreplugin/lang/en_US.lang +++ b/src/main/resources/assets/gtneioreplugin/lang/en_US.lang @@ -41,10 +41,11 @@ gtnop.nei.genPositionInfo=In the center of each chunk # world names gtnop.world.Overworld=Overworld gtnop.world.Nether=Nether -gtnop.world.TheEnd=The End +gtnop.world.The End=The End gtnop.world.Twilight=Twilight Forest gtnop.world.EndAsteroid=Far End Asteroids gtnop.world.Vanilla EndAsteroids=Vanilla End Asteroids +gtnop.world.dimensionDarkWorld=The Toxic Everglades gtnop.world.Moon=Moon gtnop.world.Mars=Mars gtnop.world.Phobos=Phobos @@ -76,7 +77,7 @@ gtnop.world.BarnardE=Barnard E gtnop.world.BarnardF=Barnard F gtnop.world.TcetiE=T Ceti E gtnop.world.Anubis=Anubis -gtnop.world.MehenBelt=Mehen Belt +gtnop.world.Mehen Belt=Mehen Belt gtnop.world.Horus=Horus gtnop.world.Maahes=Maahes gtnop.world.Neper=Neper diff --git a/src/main/resources/assets/gtneioreplugin/lang/zh_CN.lang b/src/main/resources/assets/gtneioreplugin/lang/zh_CN.lang index 4fe6e5fe324..d9f99637378 100644 --- a/src/main/resources/assets/gtneioreplugin/lang/zh_CN.lang +++ b/src/main/resources/assets/gtneioreplugin/lang/zh_CN.lang @@ -41,7 +41,7 @@ gtnop.nei.genPositionInfo=各个区块的正中心 # world names gtnop.world.Overworld=主世界 gtnop.world.Nether=下界 -gtnop.world.TheEnd=末地 +gtnop.world.The End=末地 gtnop.world.Twilight=暮色森林 gtnop.world.EndAsteroid=末地小行星 gtnop.world.Vanilla EndAsteroids=原版末地小行星