From 467cd63f7661a0e5179777dc783532f8e2a497b2 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Tue, 3 Dec 2024 18:06:21 -0500 Subject: [PATCH 01/47] ore block --- src/main/java/gregtech/api/GregTechAPI.java | 2 +- .../gregtech/api/interfaces/IBlockOre.java | 12 + .../api/interfaces/IBlockWithTextures.java | 12 + src/main/java/gregtech/common/GTProxy.java | 5 + .../gregtech/common/blocks/BlockFrameBox.java | 23 +- .../gregtech/common/blocks/BlockOres2.java | 554 ++++++++++++++++++ .../gregtech/common/blocks/ItemOres2.java | 46 ++ .../common/render/GTRendererBlock.java | 51 +- .../loaders/preload/LoaderGTBlockFluid.java | 2 + 9 files changed, 674 insertions(+), 33 deletions(-) create mode 100644 src/main/java/gregtech/api/interfaces/IBlockOre.java create mode 100644 src/main/java/gregtech/api/interfaces/IBlockWithTextures.java create mode 100644 src/main/java/gregtech/common/blocks/BlockOres2.java create mode 100644 src/main/java/gregtech/common/blocks/ItemOres2.java diff --git a/src/main/java/gregtech/api/GregTechAPI.java b/src/main/java/gregtech/api/GregTechAPI.java index 70d1a0c2ce9..827931faa43 100644 --- a/src/main/java/gregtech/api/GregTechAPI.java +++ b/src/main/java/gregtech/api/GregTechAPI.java @@ -233,7 +233,7 @@ public class GregTechAPI { sBlockMetal9, sBlockGem1, sBlockGem2, sBlockGem3, sBlockReinforced; public static Block sBlockGranites, sBlockConcretes, sBlockStones; public static Block sBlockCasings1, sBlockCasings2, sBlockCasings3, sBlockCasings4, sBlockCasings5, sBlockCasings6, - sBlockCasings8, sBlockCasings9, sBlockCasings10, sBlockCasings11, sSolenoidCoilCasings; + sBlockCasings8, sBlockCasings9, sBlockCasings10, sBlockCasings11, sSolenoidCoilCasings, sBlockOres2; public static Block sBlockLongDistancePipes; public static Block sDroneRender; public static Block sBlockFrames; diff --git a/src/main/java/gregtech/api/interfaces/IBlockOre.java b/src/main/java/gregtech/api/interfaces/IBlockOre.java new file mode 100644 index 00000000000..41412491bdb --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IBlockOre.java @@ -0,0 +1,12 @@ +package gregtech.api.interfaces; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IBlockOre { + + /** Works like the vanilla getDrops, except it doesn't check to make sure a player is breaking the block. */ + public List getDropsForMachine(World world, int x, int y, int z, int metadata, boolean silktouch, int fortune); +} 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..4ac1ad04670 --- /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/common/GTProxy.java b/src/main/java/gregtech/common/GTProxy.java index ed5ffeb4c8f..a303d1bb042 100644 --- a/src/main/java/gregtech/common/GTProxy.java +++ b/src/main/java/gregtech/common/GTProxy.java @@ -612,10 +612,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/blocks/BlockFrameBox.java b/src/main/java/gregtech/common/blocks/BlockFrameBox.java index 305919c9482..06c13ec596e 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,14 @@ 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 +454,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/BlockOres2.java b/src/main/java/gregtech/common/blocks/BlockOres2.java new file mode 100644 index 00000000000..e60de68f6fc --- /dev/null +++ b/src/main/java/gregtech/common/blocks/BlockOres2.java @@ -0,0 +1,554 @@ +package gregtech.common.blocks; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import com.google.common.collect.ImmutableList; + +import gregtech.GTMod; +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TextureSet; +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.interfaces.IBlockOre; +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.GTProxy.OreDropSystem; +import gregtech.common.render.GTRendererBlock; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +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.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; + +public class BlockOres2 extends GTGenericBlock implements IBlockOre, IBlockWithTextures { + + /** Don't generate ores for these materials. */ + public final static Set DISABLED_ORES = new HashSet<>(); + + public BlockOres2() { + super(ItemOres2.class, "gt.blockores2", Material.rock); + setStepSound(soundTypeStone); + setCreativeTab(GregTechAPI.TAB_GREGTECH_ORES); + + for (StoneType stoneType : StoneType.STONE_TYPES) { + for (int matId = 0; matId < 1000; matId++) { + Materials mat = getMaterial(matId); + + if (mat == null) continue; + + GTLanguageManager.addStringLocalization(getUnlocalizedName() + "." + getMeta(stoneType, matId, false, false) + ".name", getLocalizedNameFormat(mat)); + GTLanguageManager.addStringLocalization(getUnlocalizedName() + "." + getMeta(stoneType, matId, true, false) + ".name", "Small " + getLocalizedNameFormat(mat)); + + GTLanguageManager.addStringLocalization(getUnlocalizedName() + "." + getMeta(stoneType, matId, false, false) + ".tooltip", mat.getToolTip()); + GTLanguageManager.addStringLocalization(getUnlocalizedName() + "." + getMeta(stoneType, matId, true, false) + ".tooltip", mat.getToolTip()); + + if ((mat.mTypes & 0x8) == 0) continue; + if (DISABLED_ORES.contains(mat)) continue; + + if (stoneType.prefix.mIsUnificatable) { + GTOreDictUnificator.set( + stoneType.prefix, + mat, + new ItemStack(this, 1, getMeta(stoneType, matId, false, false))); + } else { + GTOreDictUnificator.registerOre( + stoneType.prefix, + new ItemStack(this, 1, getMeta(stoneType, matId, false, false))); + } + } + } + } + + @Override + public String getUnlocalizedName() { + return "gt.blockores2"; + } + + @Override + public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { + for (int matId = 0; matId < 1000; matId++) { + for (StoneType stoneType : StoneType.STONE_TYPES) { + Materials mat = getMaterial(matId); + + if (mat == null) continue; + if ((mat.mTypes & 0x8) == 0) continue; + if (DISABLED_ORES.contains(mat)) continue; + + list.add(new ItemStack(this, 1, getMeta(stoneType, matId, false, false))); + } + } + + for (int matId = 0; matId < 1000; matId++) { + for (StoneType stoneType : StoneType.STONE_TYPES) { + Materials mat = getMaterial(matId); + + if (mat == null) continue; + if ((mat.mTypes & 0x8) == 0) continue; + if (DISABLED_ORES.contains(mat)) continue; + + list.add(new ItemStack(this, 1, getMeta(stoneType, matId, true, false))); + } + } + } + + @Override + public ITexture[][] getTextures(int metadata) { + StoneType stoneType = getStoneType(metadata); + int matId = getMaterialId(metadata); + boolean small = isSmallOre(metadata); + + Materials mat = getMaterial(matId); + + ITexture[] textures; + + 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(), + iTexture + }; + } else { + textures = new ITexture[] { + stoneType.getTexture(), + 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 switch(stoneType) { + 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(); + }; + } + + @Override + public int getRenderType() { + return GTRendererBlock.mRenderID; + } + + public String getLocalizedNameFormat(Materials material) { + String base = switch (material.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; + }; + + 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) { + return withNaturalFlag(meta, false); + } + + @Override + public int getHarvestLevel(int meta) { + Materials mat = getMaterial(meta); + + int smallOreBonus = isSmallOre(meta) ? -1 : 0; + + int harvestLevel = GTMod.gregtechproxy.mChangeHarvestLevels ? GTMod.gregtechproxy.mHarvestLevel[mat.mMetaItemSubID] : mat.mToolQuality; + + return GTUtility.clamp(harvestLevel + smallOreBonus, 0, GTMod.gregtechproxy.mMaxHarvestLevel); + } + + @Override + public float getBlockHardness(World world, int x, int y, int z) { + int meta = world.getBlockMetadata(x, y, z); + + return 1.0F + getHarvestLevel(meta); + } + + @Override + public float getExplosionResistance(Entity entity, World world, int x, int y, int z, double explosionX, + double explosionY, double explosionZ) { + int meta = world.getBlockMetadata(x, y, z); + + return 1.0F + getHarvestLevel(meta); + } + + @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) { + int meta = world.getBlockMetadata(x, y, z); + StoneType stone = BlockOres2.getStoneType(meta); + int matId = BlockOres2.getMaterialId(meta); + boolean small = BlockOres2.isSmallOre(meta); + + meta = getMeta(stone, matId, small, true); + + world.setBlockMetadataWithNotify(x, y, z, meta, 3); + GTUtility.sendChatToPlayer(player, "Set ore natural flag to true."); + return true; + } else { + return false; + } + } + + @Override + public boolean canSilkHarvest(World world, EntityPlayer player, int x, int y, int z, int metadata) { + return !isSmallOre(metadata); + } + + @Override + protected boolean canSilkHarvest() { + return false; + } + + public static final int SMALL_ORE_META_OFFSET = 16000, NATURAL_ORE_META_OFFSET = 8000; + + public static int getMeta(StoneType stone, int materialId, boolean small, boolean natural) { + int meta = GTUtility.clamp(materialId, 0, 999); + + meta += stone.offset; + + if (small) meta += SMALL_ORE_META_OFFSET; + if (natural) meta += NATURAL_ORE_META_OFFSET; + + return meta; + } + + public static int withNaturalFlag(int meta, boolean natural) { + StoneType stone = BlockOres2.getStoneType(meta); + int matId = BlockOres2.getMaterialId(meta); + boolean small = BlockOres2.isSmallOre(meta); + + return getMeta(stone, matId, small, natural); + } + + public static ItemStack getStack(StoneType stoneType, Materials material, boolean small, boolean natural, int amount) { + return new ItemStack(GregTechAPI.sBlockOres2, amount, getMeta(stoneType, material.mMetaItemSubID, small, natural)); + } + + public static void setOre(World world, int x, int y, int z, StoneType stone, Materials material, boolean small, boolean natural) { + world.setBlock(x, y, z, GregTechAPI.sBlockOres2, getMeta(stone, material.mMetaItemSubID, small, natural), 3); + } + + public static boolean setOreForWorldGen(World world, int x, int y, int z, Materials material, boolean small) { + if (y < 0 || y >= world.getActualHeight()) return false; + + StoneType existing = StoneType.fromWorldBlock(world, x, y, z); + + if (existing == null) return false; + + world.setBlock(x, y, z, GregTechAPI.sBlockOres2, getMeta(existing, material.mMetaItemSubID, small, true), 3); + + return true; + } + + public static boolean isSmallOre(int meta) { + return meta >= SMALL_ORE_META_OFFSET; + } + + public static boolean isNatural(int meta) { + return (meta % SMALL_ORE_META_OFFSET) >= NATURAL_ORE_META_OFFSET; + } + + public static int getMaterialId(int meta) { + return meta % 1000; + } + + public static Materials getMaterial(int meta) { + return GregTechAPI.sGeneratedMaterials[getMaterialId(meta)]; + } + + public static StoneType getStoneType(int meta) { + meta %= SMALL_ORE_META_OFFSET; + meta %= NATURAL_ORE_META_OFFSET; + + int stoneType = meta / 1000; + + if (stoneType < 0 || stoneType >= StoneType.STONE_TYPES.size()) return null; + + return StoneType.STONE_TYPES.get(stoneType); + } + + public static enum StoneType { + Stone(0, OrePrefixes.ore, Materials.Stone), + Netherrack(1000, OrePrefixes.oreNetherrack, Materials.Netherrack), + Endstone(2000, OrePrefixes.oreEndstone, Materials.Endstone), + BlackGranite(3000, OrePrefixes.oreBlackgranite, Materials.GraniteBlack), + RedGranite(4000, OrePrefixes.oreRedgranite, Materials.GraniteRed), + Marble(5000, OrePrefixes.oreMarble, Materials.Marble), + Basalt(6000, OrePrefixes.oreBasalt, Materials.Basalt); + + public static final ImmutableList STONE_TYPES = ImmutableList.copyOf(values()); + + public final int offset; + public final OrePrefixes prefix; + public final Materials material; + + private StoneType(int offset, OrePrefixes prefix, Materials material) { + this.offset = offset; + this.prefix = prefix; + this.material = material; + } + + public ITexture getTexture() { + return switch (this) { + case Stone -> TextureFactory.of(Blocks.stone); + case Netherrack -> TextureFactory.of(Blocks.netherrack); + case Endstone -> TextureFactory.of(Blocks.end_stone); + case BlackGranite -> TextureFactory.builder().addIcon(BlockIcons.GRANITE_BLACK_STONE).stdOrient().build(); + case RedGranite -> TextureFactory.builder().addIcon(BlockIcons.GRANITE_RED_STONE).stdOrient().build(); + case Marble -> TextureFactory.builder().addIcon(BlockIcons.MARBLE_STONE).stdOrient().build(); + case Basalt -> TextureFactory.builder().addIcon(BlockIcons.BASALT_STONE).stdOrient().build(); + }; + } + + public static StoneType fromWorldBlock(World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + if (block.isReplaceableOreGen(world, x, y, z, Blocks.stone)) { + return StoneType.Stone; + } + + if (block.isReplaceableOreGen(world, x, y, z, Blocks.netherrack)) { + return StoneType.Netherrack; + } + + if (block.isReplaceableOreGen(world, x, y, z, Blocks.end_stone)) { + return StoneType.Endstone; + } + + if (block.isReplaceableOreGen(world, x, y, z, GregTechAPI.sBlockGranites)) { + return meta < 8 ? StoneType.BlackGranite : StoneType.RedGranite; + } + + if (block.isReplaceableOreGen(world, x, y, z, GregTechAPI.sBlockStones)) { + return meta < 8 ? StoneType.Marble : StoneType.Basalt; + } + + return null; + } + + public static StoneType fromHypotheticalWorldBlock(World world, int x, int y, int z, Block potentialBlock, int potentialMeta) { + if (potentialBlock.isReplaceableOreGen(world, x, y, z, Blocks.stone)) { + return StoneType.Stone; + } + + if (potentialBlock.isReplaceableOreGen(world, x, y, z, Blocks.netherrack)) { + return StoneType.Netherrack; + } + + if (potentialBlock.isReplaceableOreGen(world, x, y, z, Blocks.end_stone)) { + return StoneType.Endstone; + } + + if (potentialBlock.isReplaceableOreGen(world, x, y, z, GregTechAPI.sBlockGranites)) { + return potentialMeta < 8 ? StoneType.BlackGranite : StoneType.RedGranite; + } + + if (potentialBlock.isReplaceableOreGen(world, x, y, z, GregTechAPI.sBlockStones)) { + return potentialMeta < 8 ? StoneType.Marble : StoneType.Basalt; + } + + return null; + } + } + + @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); + + return (ArrayList) getDropsForMachine(world, x, y, z, metadata, doSilktouch, doFortune ? fortune : 0); + } + + @Override + public List getDropsForMachine(World world, int x, int y, int z, int metadata, boolean silktouch, int fortune) { + boolean isNatural = isNatural(metadata); + + return getDrops(world.rand, GTMod.gregtechproxy.oreDropSystem, this, metadata, silktouch, isNatural ? fortune : 0); + } + + public static ArrayList getDrops(Random random, OreDropSystem oreDropMode, Block oreBlock, int meta, boolean silktouch, int fortune) { + if (meta <= 0) { + ArrayList drops = new ArrayList<>(); + drops.add(new ItemStack(Blocks.cobblestone, 1, 0)); + return drops; + } + + StoneType stone = getStoneType(meta); + Materials material = getMaterial(meta); + + if (isSmallOre(meta)) { + return getSmallOreDrops(random, stone, material, fortune); + } else { + return getBigOreDrops(random, oreDropMode, oreBlock, stone, material, silktouch, fortune); + } + } + + private static 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 ImmutableList DROPS = ImmutableList.copyOf(values()); + + public final OrePrefixes primary; + public final OrePrefixes fallback; + public 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; + } + } + + public static ArrayList getSmallOreDrops(Random random, StoneType stone, Materials material, int fortune) { + ArrayList possibleDrops = SmallOreDrops.getDropList(material); + ArrayList drops = new ArrayList<>(); + + if (!possibleDrops.isEmpty()) { + int dropCount = Math.max(1, material.mOreMultiplier + (fortune > 0 ? random.nextInt(1 + fortune * 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(GTOreDictUnificator.get(random.nextInt(3) > 0 ? OrePrefixes.dustImpure : OrePrefixes.dust, stone.material, 1L)); + } + + return drops; + } + + public static ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, Block oreBlock, StoneType stone, Materials material, boolean silktouch, int fortune) { + ArrayList drops = new ArrayList<>(); + + // For Sake of god of balance! + + boolean isRich = switch (stone) { + case Netherrack -> GTMod.gregtechproxy.mNetherOreYieldMultiplier; + case Endstone -> GTMod.gregtechproxy.mEndOreYieldMultiplier; + default -> false; + }; + + if (silktouch) oreDropMode = OreDropSystem.Block; + + switch (oreDropMode) { + case Item -> { + drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, material, isRich ? 2 : 1)); + } + case FortuneItem -> { + if (fortune > 0) { + // Max applicable fortune + if (fortune > 3) fortune = 3; + + int amount = 1 + Math.max(random.nextInt(fortune * (isRich ? 2 : 1) + 2) - 1, 0); + + for (int i = 0; i < amount; i++) { + drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, material, 1)); + } + } else { + for (int i = 0; i < (isRich ? 2 : 1); i++) { + drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, material, 1)); + } + } + } + case UnifiedBlock -> { + for (int i = 0; i < (isRich ? 2 : 1); i++) { + drops.add(new ItemStack(oreBlock, 1, material.mMetaItemSubID)); + } + } + case PerDimBlock -> { + if (stone == StoneType.Netherrack || stone == StoneType.Endstone) { + drops.add(new ItemStack(oreBlock, 1, getMeta(stone, material.mMetaItemSubID, false, false))); + } else { + drops.add(new ItemStack(oreBlock, 1, material.mMetaItemSubID)); + } + } + case Block -> { + drops.add(new ItemStack(oreBlock, 1, getMeta(stone, material.mMetaItemSubID, false, false))); + } + } + + return drops; + } +} diff --git a/src/main/java/gregtech/common/blocks/ItemOres2.java b/src/main/java/gregtech/common/blocks/ItemOres2.java new file mode 100644 index 00000000000..16781bf48ba --- /dev/null +++ b/src/main/java/gregtech/common/blocks/ItemOres2.java @@ -0,0 +1,46 @@ +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 ItemOres2 extends ItemBlock { + + public ItemOres2(Block block) { + super(block); + setMaxDamage(0); + setHasSubtypes(true); + setCreativeTab(GregTechAPI.TAB_GREGTECH_MATERIALS); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return this.field_150939_a.getUnlocalizedName() + "." + BlockOres2.withNaturalFlag(stack.getItemDamage(), false); + } + + @Override + public int getMetadata(int meta) { + return meta; + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + String aName = super.getItemStackDisplayName(stack); + return Materials.getLocalizedNameForItem(aName, BlockOres2.getMaterialId(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/render/GTRendererBlock.java b/src/main/java/gregtech/common/render/GTRendererBlock.java index b4caab35b89..86f59ca63f3 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; @@ -552,12 +553,13 @@ 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); + // spotless:off 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); @@ -565,25 +567,22 @@ public void renderInventoryBlock(Block aBlock, int aMeta, int aModelID, RenderBl 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); + } 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 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); } + } + // spotless:on aBlock.setBlockBounds(blockMin, blockMin, blockMin, blockMax, blockMax, blockMax); aRenderer.setRenderBoundsFromBlock(aBlock); @@ -733,15 +732,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/loaders/preload/LoaderGTBlockFluid.java b/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java index c05ff7523ec..c287f24f778 100644 --- a/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java +++ b/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java @@ -74,6 +74,7 @@ import gregtech.common.blocks.BlockMachines; import gregtech.common.blocks.BlockMetal; import gregtech.common.blocks.BlockOres; +import gregtech.common.blocks.BlockOres2; import gregtech.common.blocks.BlockReinforced; import gregtech.common.blocks.BlockStones; import gregtech.common.blocks.BlockTintedIndustrialGlass; @@ -549,6 +550,7 @@ public void run() { GregTechAPI.sBlockConcretes = new BlockConcretes(); GregTechAPI.sBlockStones = new BlockStones(); GregTechAPI.sBlockOres1 = new BlockOres(); + GregTechAPI.sBlockOres2 = new BlockOres2(); GregTechAPI.sBlockFrames = new BlockFrameBox(); GregTechAPI.sDroneRender = new BlockDrone(); GregTechAPI.sBlockGlass1 = new BlockGlass1(); From fdd8abeddd6237a5e1d8888cf7258f0a02cc16f8 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Tue, 3 Dec 2024 23:32:55 -0500 Subject: [PATCH 02/47] refactor work --- .../galacticgreg/VoidMinerUtility.java | 6 +- ...BehaviourDetravToolElectricProspector.java | 26 +-- .../BehaviourDetravToolProspector.java | 163 ++++++------- .../java/detrav/net/ProspectingPacket.java | 4 +- .../galacticgreg/WorldgenOreSmallSpace.java | 21 +- .../java/gregtech/api/enums/SmallOres.java | 9 +- .../java/gregtech/api/enums/StoneType.java | 99 ++++++++ .../gregtech/api/interfaces/IStoneType.java | 17 ++ .../java/gregtech/api/util/GTUtility.java | 31 ++- .../java/gregtech/common/SmallOreBuilder.java | 11 +- .../common/WorldgenGTOreSmallPieces.java | 33 ++- .../java/gregtech/common/WorldgenStone.java | 29 ++- .../gregtech/common/blocks/BlockOres2.java | 23 ++ .../common/blocks/TileEntityOres.java | 16 +- .../items/behaviors/BehaviourProspecting.java | 186 ++++++++------- .../multi/MTEOreDrillingPlantBase.java | 18 +- .../plugin/block/BlockDimensionDisplay.java | 1 + .../plugin/gregtech5/PluginGT5Base.java | 25 +- .../gregtech5/PluginGT5SmallOreStat.java | 96 ++++---- .../plugin/gregtech5/PluginGT5VeinStat.java | 41 ++-- .../java/gtneioreplugin/util/CSVMaker.java | 24 +- .../gtneioreplugin/util/DimensionHelper.java | 14 -- .../util/GT5OreLayerHelper.java | 71 +++--- .../util/GT5OreSmallHelper.java | 215 ++++++++---------- .../java/gtneioreplugin/util/SmallOre.java | 7 +- .../tectech/recipe/EyeOfHarmonyRecipe.java | 4 +- .../recipe/EyeOfHarmonyRecipeStorage.java | 2 +- 27 files changed, 633 insertions(+), 559 deletions(-) create mode 100644 src/main/java/gregtech/api/enums/StoneType.java create mode 100644 src/main/java/gregtech/api/interfaces/IStoneType.java diff --git a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java index 237b1552746..5ff821375be 100644 --- a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java +++ b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java @@ -33,6 +33,8 @@ import gregtech.api.util.GTUtility; import gregtech.common.WorldgenGTOreLayer; import gregtech.common.WorldgenGTOreSmallPieces; +import gregtech.common.blocks.BlockOres2; +import gregtech.common.blocks.BlockOres2.StoneType; public class VoidMinerUtility { @@ -65,7 +67,7 @@ public void addDrop(int meta, float weight, boolean isBWOres) { if (isBWOres) { addDrop(WerkstoffLoader.BWOres, meta, weight); } else { - addDrop(GregTechAPI.sBlockOres1, meta, weight); + addDrop(GregTechAPI.sBlockOres2, meta, weight); } } @@ -177,7 +179,7 @@ private static DropMap getDropMapVanilla(int dimId) { 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)); + .forEach(element -> dropMap.addDrop(BlockOres2.getMeta(StoneType.Stone, element.mMaterial.mMetaItemSubID, true, true), element.mAmount, false)); return dropMap; } diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java index fb3e4833995..9b512c59611 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -10,7 +10,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.StatCollector; import net.minecraft.world.World; @@ -26,11 +25,9 @@ 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.common.UndergroundOil; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.blocks.BlockOres2; /** * Created by wital_000 on 19.03.2016. @@ -83,22 +80,11 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW 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); - } - } + if (tBlock instanceof BlockOres2) { + if (!BlockOres2.isNatural(tMetaID)) continue; + if (data != 1 && BlockOres2.isSmallOre(tMetaID)) continue; + + packet.addBlock(c.xPosition * 16 + x, y, c.zPosition * 16 + z, tMetaID); } else if (GTppHelper.isGTppBlock(tBlock)) { packet.addBlock( c.xPosition * 16 + x, diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java index 22a9f7b220c..a9d0427b8ba 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; @@ -37,8 +36,7 @@ import gregtech.api.util.GTLanguageManager; import gregtech.api.util.GTOreDictUnificator; import gregtech.common.UndergroundOil; -import gregtech.common.blocks.BlockOresAbstract; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.blocks.BlockOres2; import gregtech.common.items.behaviors.BehaviourNone; import gregtech.common.pollution.Pollution; @@ -72,14 +70,8 @@ public boolean onItemUse(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPla if (aWorld.getBlock(aX, aY, aZ) == 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,11 +85,9 @@ 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.getBlock(aX, aY, aZ).getMaterial() == Material.rock + || aWorld.getBlock(aX, aY, aZ).getMaterial() == Material.ground + || aWorld.getBlock(aX, aY, aZ) == GregTechAPI.sBlockOres2) { if (!aWorld.isRemote) { prospectChunks(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, aRandom, chance); } @@ -138,8 +128,9 @@ protected void prospectChunks(MetaBaseItem aItem, ItemStack aStack, EntityPlayer break; } } - if (DetravScannerMod.DEBUG_ENABLED) aPlayer.addChatMessage( - new ChatComponentText( + if (DetravScannerMod.DEBUG_ENABLED) { + aPlayer.addChatMessage( + new ChatComponentText( EnumChatFormatting.YELLOW + "Chunk at " + aX + "|" @@ -149,14 +140,15 @@ protected void prospectChunks(MetaBaseItem aItem, ItemStack aStack, EntityPlayer + "|" + (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 +230,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,22 +255,23 @@ 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) + World world, int x, int y, int z, SplittableRandom aRandom, int chance) { - 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) { + 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); + ItemData itemData = GTOreDictUnificator.getAssociation(blockStack); + + if (block instanceof BlockOres2) { + addOreToHashMap(blockStack.getDisplayName(), aPlayer); + if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts); + return; + } else 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; @@ -289,58 +282,50 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack 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); - } - } - } 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 { + 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); + + if (tBlock instanceof BlockOres2) { + if (!BlockOres2.isNatural(tMetaID)) continue; + if (data != 1 && BlockOres2.isSmallOre(tMetaID)) continue; + + ItemStack blockStack2 = new ItemStack(tBlock, 1, tMetaID); + addOreToHashMap(blockStack2.getDisplayName(), aPlayer); + } 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(chunk, cx, cy, cz, 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) { + 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) {} + } } } - } } diff --git a/src/main/java/detrav/net/ProspectingPacket.java b/src/main/java/detrav/net/ProspectingPacket.java index 1b861273e53..920ee425ad2 100644 --- a/src/main/java/detrav/net/ProspectingPacket.java +++ b/src/main/java/detrav/net/ProspectingPacket.java @@ -25,6 +25,8 @@ import gregtech.api.GregTechAPI; import gregtech.api.enums.Materials; import gregtech.api.util.GTLanguageManager; +import gregtech.common.blocks.BlockOres2; +import gregtech.common.blocks.BlockOres2.StoneType; /** * Created by wital_000 on 20.03.2016. @@ -66,7 +68,7 @@ private static void addOre(ProspectingPacket packet, byte y, int i, int j, short Materials tMaterial = GregTechAPI.sGeneratedMaterials[meta % 1000]; rgba = tMaterial.getRGBA(); name = tMaterial.getLocalizedNameForItem( - GTLanguageManager.getTranslation("gt.blockores." + meta + ".name")); + GTLanguageManager.getTranslation("gt.blockores2." + BlockOres2.getMeta(StoneType.Stone, meta % 1000, false, false) + ".name")); } else { final Werkstoff werkstoff = Werkstoff.werkstoffHashMap.getOrDefault((short) (meta * -1), null); String translated = GTLanguageManager.getTranslation("bw.blocktype.ore"); diff --git a/src/main/java/galacticgreg/WorldgenOreSmallSpace.java b/src/main/java/galacticgreg/WorldgenOreSmallSpace.java index 40fede19b02..32737b69d3a 100644 --- a/src/main/java/galacticgreg/WorldgenOreSmallSpace.java +++ b/src/main/java/galacticgreg/WorldgenOreSmallSpace.java @@ -1,8 +1,8 @@ package galacticgreg; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; import java.util.Random; +import java.util.Set; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; @@ -22,7 +22,7 @@ public class WorldgenOreSmallSpace extends GTWorldgen { private long mProfilingStart; private long mProfilingEnd; - private final Map allowedDims; + private final Set allowedDims; public WorldgenOreSmallSpace(SmallOreBuilder ore) { super(ore.smallOreName, GalacticGreg.smallOreWorldgenList, ore.enabledByDefault); @@ -32,18 +32,15 @@ public WorldgenOreSmallSpace(SmallOreBuilder ore) { mAmount = (short) Math.max(1, ore.amount); mMeta = (short) ore.ore.mMetaItemSubID; - allowedDims = new HashMap<>(); + allowedDims = new HashSet<>(); 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); + String dimId = mdd.getDimIdentifier(); + + if (ore.dimsEnabled.contains(dimId)) { + allowedDims.add(dimId); } } } @@ -58,7 +55,7 @@ public WorldgenOreSmallSpace(SmallOreBuilder ore) { * @return */ public boolean isEnabledForDim(ModDimensionDef pDimensionDef) { - return allowedDims.getOrDefault(pDimensionDef.getDimIdentifier(), false); + return allowedDims.contains(pDimensionDef.getDimIdentifier()); } @Override diff --git a/src/main/java/gregtech/api/enums/SmallOres.java b/src/main/java/gregtech/api/enums/SmallOres.java index ec11c211c2a..6cf7970205a 100644 --- a/src/main/java/gregtech/api/enums/SmallOres.java +++ b/src/main/java/gregtech/api/enums/SmallOres.java @@ -526,17 +526,12 @@ 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; 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..535b863d000 --- /dev/null +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -0,0 +1,99 @@ +package gregtech.api.enums; + +import com.google.common.collect.ImmutableList; + +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.interfaces.IStoneType; +import gregtech.api.interfaces.ITexture; +import gregtech.api.render.TextureFactory; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; + +public enum StoneType implements IStoneType { + Stone(OrePrefixes.ore, Materials.Stone) { + @Override + public boolean contains(Block block, int meta) { + return block == Blocks.stone; + } + }, + Netherrack(OrePrefixes.oreNetherrack, Materials.Netherrack) { + @Override + public boolean contains(Block block, int meta) { + return block == Blocks.netherrack; + } + }, + Endstone(OrePrefixes.oreEndstone, Materials.Endstone) { + @Override + public boolean contains(Block block, int meta) { + return block == Blocks.end_stone; + } + }, + BlackGranite(OrePrefixes.oreBlackgranite, Materials.GraniteBlack) { + @Override + public boolean contains(Block block, int meta) { + return block == GregTechAPI.sBlockGranites && meta < 8; + } + }, + RedGranite(OrePrefixes.oreRedgranite, Materials.GraniteRed) { + @Override + public boolean contains(Block block, int meta) { + return block == GregTechAPI.sBlockGranites && meta >= 8; + } + }, + Marble(OrePrefixes.oreMarble, Materials.Marble) { + @Override + public boolean contains(Block block, int meta) { + return block == GregTechAPI.sBlockStones && meta < 8; + } + }, + Basalt(OrePrefixes.oreBasalt, Materials.Basalt) { + @Override + public boolean contains(Block block, int meta) { + return block == GregTechAPI.sBlockStones && meta >= 8; + } + }; + + public static final ImmutableList STONE_TYPES = ImmutableList.copyOf(values()); + + public final OrePrefixes prefix; + public final Materials material; + + private StoneType(OrePrefixes prefix, Materials material) { + this.prefix = prefix; + this.material = material; + } + + @Override + public Materials getMaterial() { + return material; + } + + @Override + public OrePrefixes getPrefix() { + return prefix; + } + + @Override + public ITexture getTexture() { + return switch (this) { + case Stone -> TextureFactory.of(Blocks.stone); + case Netherrack -> TextureFactory.of(Blocks.netherrack); + case Endstone -> TextureFactory.of(Blocks.end_stone); + case BlackGranite -> TextureFactory.builder().addIcon(BlockIcons.GRANITE_BLACK_STONE).stdOrient().build(); + case RedGranite -> TextureFactory.builder().addIcon(BlockIcons.GRANITE_RED_STONE).stdOrient().build(); + case Marble -> TextureFactory.builder().addIcon(BlockIcons.MARBLE_STONE).stdOrient().build(); + case Basalt -> TextureFactory.builder().addIcon(BlockIcons.BASALT_STONE).stdOrient().build(); + }; + } + + public static StoneType findStoneType(Block block, int meta) { + for (StoneType stoneType : STONE_TYPES) { + if (stoneType.contains(block, meta)) { + return stoneType; + } + } + + return null; + } +} 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..29d1fa1915b --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IStoneType.java @@ -0,0 +1,17 @@ +package gregtech.api.interfaces; + +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import net.minecraft.block.Block; + +public interface IStoneType { + + /** Checks if this stone type contains this specific block. */ + public boolean contains(Block block, int meta); + + public OrePrefixes getPrefix(); + + public Materials getMaterial(); + + public ITexture getTexture(); +} diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index da805f995db..667ab6c2b0e 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -124,6 +124,8 @@ import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; import com.mojang.authlib.GameProfile; +import bartworks.system.material.BWMetaGeneratedOres; +import bartworks.system.material.BWMetaGeneratedSmallOres; import buildcraft.api.transport.IPipeTile; import cofh.api.energy.IEnergyReceiver; import cofh.api.transport.IItemDuct; @@ -167,8 +169,10 @@ import gregtech.api.recipe.RecipeMaps; import gregtech.api.threads.RunnableSound; import gregtech.api.util.extensions.ArrayExt; +import gregtech.common.blocks.BlockOres2; import gregtech.common.blocks.BlockOresAbstract; import gregtech.common.pollution.Pollution; +import gtPlusPlus.core.block.base.BlockBaseOre; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; import ic2.api.recipe.RecipeInputOreDict; @@ -2336,6 +2340,18 @@ public static boolean arrayContainsNonNull(T... aArray) { return false; } + public static int indexOf(T[] array, T value) { + for (int i = 0; i < array.length; i++) { + if (array[i] == value) return i; + } + + return -1; + } + + public static boolean contains(T[] array, T value) { + return indexOf(array, value) != -1; + } + /** * Note: use {@link ArrayExt#withoutNulls(Object[], IntFunction)} if you want an array as a result. */ @@ -4327,16 +4343,13 @@ 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 (block instanceof BlockOres2) return true; + if (block instanceof BWMetaGeneratedOres) return true; + if (block instanceof BWMetaGeneratedSmallOres) return true; + if (block instanceof BlockBaseOre) 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) { diff --git a/src/main/java/gregtech/common/SmallOreBuilder.java b/src/main/java/gregtech/common/SmallOreBuilder.java index 727ea98fc6b..d36dd9aa1d4 100644 --- a/src/main/java/gregtech/common/SmallOreBuilder.java +++ b/src/main/java/gregtech/common/SmallOreBuilder.java @@ -1,7 +1,7 @@ package gregtech.common; -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; @@ -14,7 +14,8 @@ public class SmallOreBuilder { public static final String TWILIGHT_FOREST = "Twilight Forest"; public String smallOreName; public boolean enabledByDefault = true; - public Map dimsEnabled = new HashMap<>(); + /** {full dimension name: enabled} */ + public Set dimsEnabled = new HashSet<>(); public int minY, maxY, amount; public Materials ore; @@ -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; } diff --git a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java index e3be59a6287..1ceafc32305 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java +++ b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java @@ -13,16 +13,17 @@ import net.minecraft.world.chunk.IChunkProvider; import gregtech.api.GregTechAPI; +import gregtech.api.enums.Materials; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.blocks.BlockOres2; public class WorldgenGTOreSmallPieces extends GTWorldgen { public final short mMinY; public final short mMaxY; public final short mAmount; - public final short mMeta; + public final Materials mMaterial; public final boolean mOverworld; public final boolean mNether; public final boolean mEnd; @@ -30,9 +31,9 @@ public class WorldgenGTOreSmallPieces extends GTWorldgen { public final String mBiome; public static ArrayList sList = new ArrayList<>(); - public Class[] mAllowedProviders; + public Class[] mAllowedProviders; public String[] blackListedProviders; - public static Class tfProviderClass; + public static Class tfProviderClass; static { try { @@ -42,20 +43,20 @@ public class WorldgenGTOreSmallPieces extends GTWorldgen { 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.mOverworld = ore.dimsEnabled.contains(SmallOreBuilder.OW); + this.mNether = ore.dimsEnabled.contains(SmallOreBuilder.NETHER); + this.mEnd = ore.dimsEnabled.contains(SmallOreBuilder.THE_END); + this.twilightForest = ore.dimsEnabled.contains(SmallOreBuilder.TWILIGHT_FOREST); 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"; if (this.mEnabled) sList.add(this); - List allowedProviders = new ArrayList<>(); + List> allowedProviders = new ArrayList<>(); if (this.mNether) { allowedProviders.add(WorldProviderHell.class); } @@ -87,21 +88,17 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int 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) { + if (this.mMaterial != null) { int j = Math.max(1, this.mAmount / 2 + aRandom.nextInt(this.mAmount) / 2); for (int i = 0; i < j; i++) { - TileEntityOres.setOreBlock( + BlockOres2.setOreForWorldGen( 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); + mMaterial, + true); count++; } } diff --git a/src/main/java/gregtech/common/WorldgenStone.java b/src/main/java/gregtech/common/WorldgenStone.java index dd42146ea70..268fdc6ff8f 100644 --- a/src/main/java/gregtech/common/WorldgenStone.java +++ b/src/main/java/gregtech/common/WorldgenStone.java @@ -9,7 +9,6 @@ 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; @@ -17,8 +16,8 @@ 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.blocks.BlockOres2; +import gregtech.common.blocks.BlockOres2.StoneType; public class WorldgenStone extends GTWorldgen { @@ -209,8 +208,9 @@ 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=" + if (debugStones) { + GTLog.out.println( + mWorldGenName + " tX=" + tX + " tY=" + tY @@ -236,6 +236,7 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int + 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 @@ -261,18 +262,14 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int if (leftHandSize <= rightHandSide) { // Yay! We can actually place a block now. (this part copied from original code) 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); + if (tTargetedBlock == GregTechAPI.sBlockOres2) { + StoneType stoneType = StoneType.fromHypotheticalWorldBlock(aWorld, iX, iY, iZ, mBlock, mBlockMeta); + + if (stoneType != null) { + BlockOres2.setExistingOreStoneType(aWorld, iX, iY, iZ, stoneType); } - } else if (((this.mAllowToGenerateinVoid) && (aWorld.getBlock(iX, iY, iZ) - .isAir(aWorld, iX, iY, iZ))) - || ((tTargetedBlock != null) && ((tTargetedBlock + } else if ((this.mAllowToGenerateinVoid && aWorld.isAirBlock(iX, iY, iZ)) + || (tTargetedBlock != null && ((tTargetedBlock .isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.stone)) || (tTargetedBlock .isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.stained_hardened_clay)) diff --git a/src/main/java/gregtech/common/blocks/BlockOres2.java b/src/main/java/gregtech/common/blocks/BlockOres2.java index e60de68f6fc..acff0a45c11 100644 --- a/src/main/java/gregtech/common/blocks/BlockOres2.java +++ b/src/main/java/gregtech/common/blocks/BlockOres2.java @@ -20,6 +20,7 @@ import gregtech.api.items.GTGenericBlock; import gregtech.api.render.TextureFactory; import gregtech.api.util.GTLanguageManager; +import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; import gregtech.common.GTProxy.OreDropSystem; @@ -295,6 +296,20 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, Materi return true; } + public static boolean setExistingOreStoneType(World world, int x, int y, int z, StoneType newStoneType) { + if (world.getBlock(x, y, z) != GregTechAPI.sBlockOres2) return false; + + int meta = world.getBlockMetadata(x, y, z); + + int matId = getMaterialId(meta); + boolean small = isSmallOre(meta); + boolean natural = isNatural(meta); + + world.setBlock(x, y, z, GregTechAPI.sBlockOres2, getMeta(newStoneType, matId, small, natural), 3); + + return true; + } + public static boolean isSmallOre(int meta) { return meta >= SMALL_ORE_META_OFFSET; } @@ -424,6 +439,14 @@ public List getDropsForMachine(World world, int x, int y, int z, int return getDrops(world.rand, GTMod.gregtechproxy.oreDropSystem, this, metadata, silktouch, isNatural ? fortune : 0); } + public static List getPotentialDrops(Materials material, boolean small) { + if (small) { + return SmallOreDrops.getDropList(material); + } else { + return getBigOreDrops(null, OreDropSystem.Item, GregTechAPI.sBlockOres2, StoneType.Stone, material, false, 0); + } + } + public static ArrayList getDrops(Random random, OreDropSystem oreDropMode, Block oreBlock, int meta, boolean silktouch, int fortune) { if (meta <= 0) { ArrayList drops = new ArrayList<>(); diff --git a/src/main/java/gregtech/common/blocks/TileEntityOres.java b/src/main/java/gregtech/common/blocks/TileEntityOres.java index 0dbdcec1a2b..151be9b243a 100644 --- a/src/main/java/gregtech/common/blocks/TileEntityOres.java +++ b/src/main/java/gregtech/common/blocks/TileEntityOres.java @@ -26,6 +26,7 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; +import gregtech.common.blocks.BlockOres2.StoneType; public class TileEntityOres extends TileEntity implements IAllSidedTexturedTileEntity { @@ -293,7 +294,20 @@ public short getMetaData() { @Override public boolean canUpdate() { - return false; + return true; + } + + private boolean recursed = false; + + @Override + public void updateEntity() { + if (!recursed) { + recursed = true; + + int meta = BlockOres2.getMeta(StoneType.STONE_TYPES.get(mMetaData % 16000 / 1000), mMetaData % 1000, mMetaData >= 16000, mNatural); + + worldObj.setBlock(xCoord, yCoord, zCoord, GregTechAPI.sBlockOres2, meta, 3); + } } public ArrayList getDrops(Block aDroppedOre, int aFortune) { diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java index 98aed597f93..d4b48006402 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java @@ -8,7 +8,6 @@ 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; @@ -24,8 +23,8 @@ 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.blocks.BlockOres2; +import gregtech.common.blocks.BlockOres2.StoneType; public class BehaviourProspecting extends BehaviourNone { @@ -39,114 +38,129 @@ 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); + + if (aBlock instanceof BlockOres2) { + final Materials tMaterial = BlockOres2.getMaterial(aMeta); + if (tMaterial != null && tMaterial != Materials._NULL) { + GTUtility.sendChatToPlayer( + aPlayer, + GTUtility.trans("100", "This is ") + tMaterial.mDefaultLocalName + + 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("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)) { + StoneType stoneType = StoneType.fromWorldBlock(aWorld, aX, aY, aZ); + + if (stoneType != null + || aBlock == GregTechAPI.sBlockOres1 + || aBlock == GregTechAPI.sBlockOres2) { + 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); + + if (tBlock instanceof BlockOres2) { + final Materials tMaterial = BlockOres2.getMaterial(tMeta); + if (tMaterial != null && tMaterial != Materials._NULL) { 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; + GTUtility.trans("106", "Found traces of ") + tMaterial.mDefaultLocalName + + 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/tileentities/machines/multi/MTEOreDrillingPlantBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java index 13a7396b8b2..93374490873 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java @@ -47,6 +47,7 @@ import gregtech.api.enums.SoundResource; import gregtech.api.gui.modularui.GTUITextures; import gregtech.api.gui.widgets.LockedWhileActiveButton; +import gregtech.api.interfaces.IBlockOre; import gregtech.api.interfaces.IHatchElement; import gregtech.api.interfaces.metatileentity.IMetricsExporter; import gregtech.api.objects.GTChunkManager; @@ -537,22 +538,13 @@ private ItemStack multiplyStackSize(ItemStack itemStack) { } private Collection getBlockDrops(final Block oreBlock, int posX, int posY, int posZ) { - final int blockMeta = getBaseMetaTileEntity().getMetaID(posX, posY, posZ); + final int blockMeta = getBaseMetaTileEntity().getWorld().getBlockMetadata(posX, posY, posZ); + if (oreBlock instanceof IBlockOre machineMinable) { + return machineMinable.getDropsForMachine(getBaseMetaTileEntity().getWorld(), posX, posY, posZ, blockMeta, false, mTier + 3); + } 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); } 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..51e39247048 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -5,34 +5,27 @@ import codechicken.lib.gui.GuiDraw; import gregtech.api.enums.Materials; import gregtech.api.util.GTLanguageManager; +import gregtech.common.blocks.BlockOres2; +import gregtech.common.blocks.BlockOres2.StoneType; 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"; + public static String getGTOreLocalizedName(Materials ore, boolean small) { + if (ore == Materials.DraconiumAwakened) return "Aw. Draconium Ore"; + + String name = GTLanguageManager.getTranslation(getGTOreUnlocalizedName(ore, small)); + return ore.getLocalizedNameForItem(name); } - protected static String getGTOreUnlocalizedName(short index) { - return "gt.blockores." + index + ".name"; + protected static String getGTOreUnlocalizedName(Materials ore, boolean small) { + return "gt.blockores2." + BlockOres2.getMeta(StoneType.Stone, ore.mMetaItemSubID, small, false) + ".name"; } static void drawLine(String lineKey, String value, int x, int y) { GuiDraw.drawString(I18n.format(lineKey) + ": " + value, x, y, 0x404040, false); } - 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; - } - /** * Draw the dimension header and the dimension names over up to 3 lines * diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java index fb5b298b7b9..c0c23536a2b 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java @@ -1,25 +1,24 @@ 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; import net.minecraft.item.ItemStack; import codechicken.nei.PositionedStack; +import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GTOreDictUnificator; +import gregtech.common.blocks.BlockOres2; +import gregtech.common.blocks.ItemOres2; +import gregtech.common.blocks.BlockOres2.StoneType; import gtneioreplugin.plugin.item.ItemDimensionDisplay; -import gtneioreplugin.util.DimensionHelper; import gtneioreplugin.util.GT5OreSmallHelper; import gtneioreplugin.util.GT5OreSmallHelper.OreSmallWrapper; 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,7 +32,7 @@ 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); } @@ -46,7 +45,7 @@ private void drawSmallOreInfo(OreSmallWrapper oreSmall) { private OreSmallWrapper getSmallOre(int recipe) { CachedOreSmallRecipe crecipe = (CachedOreSmallRecipe) this.arecipes.get(recipe); - return GT5OreSmallHelper.mapOreSmallWrapper.get(crecipe.oreGenName); + return GT5OreSmallHelper.SMALL_ORES_BY_NAME.get(crecipe.oreGenName); } public int getRestrictBiomeOffset() { @@ -56,67 +55,64 @@ public int getRestrictBiomeOffset() { @Override public void loadCraftingRecipes(String outputId, Object... results) { if (outputId.equals(getOutputId())) - for (ItemStack stack : GT5OreSmallHelper.oreSmallList) loadCraftingRecipes(stack); + 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); + if (stack.getItem() instanceof ItemOres2) { + loadSmallOre(BlockOres2.getMaterial(stack.getItemDamage())); + } else if (GT5OreSmallHelper.ORE_DROP_TO_MAT.containsKey(stack.getUnlocalizedName())) { + loadSmallOre(GT5OreSmallHelper.ORE_DROP_TO_MAT.get(stack.getUnlocalizedName())); + } else { + super.loadCraftingRecipes(stack); + } } @Override public void loadUsageRecipes(ItemStack stack) { - String dimension = ItemDimensionDisplay.getDimension(stack); - if (dimension == null) { - return; - } + String abbr = ItemDimensionDisplay.getDimension(stack); + if (abbr == null) return; - for (OreSmallWrapper oreVein : GT5OreSmallHelper.mapOreSmallWrapper.values()) { - if (Arrays.asList(getDimNameArrayFromVeinName(oreVein.oreGenName)) - .contains(dimension)) { - addSmallOre(oreVein, 7); - } + for (OreSmallWrapper oreVein : GT5OreSmallHelper.SMALL_ORES_BY_DIM.get(abbr).smallOres) { + addSmallOre(oreVein); } } - private void loadSmallOre(short oreMeta, int maximumIndex) { - OreSmallWrapper smallOre = getSmallOre(oreMeta); + private void loadSmallOre(Materials material) { + OreSmallWrapper smallOre = getSmallOre(material); if (smallOre != null) { - addSmallOre(smallOre, maximumIndex); + addSmallOre(smallOre); } } - private OreSmallWrapper getSmallOre(short oreMeta) { - for (OreSmallWrapper oreSmallWorldGen : GT5OreSmallHelper.mapOreSmallWrapper.values()) { - if (oreSmallWorldGen.oreMeta == oreMeta) { + private OreSmallWrapper getSmallOre(Materials material) { + for (OreSmallWrapper oreSmallWorldGen : GT5OreSmallHelper.SMALL_ORES_BY_NAME.values()) { + if (oreSmallWorldGen.material == material) { return oreSmallWorldGen; } } return null; } - private void addSmallOre(OreSmallWrapper smallOre, int maximumIndex) { + private void addSmallOre(OreSmallWrapper smallOre) { this.arecipes.add( new CachedOreSmallRecipe( smallOre.oreGenName, - smallOre.getMaterialDrops(maximumIndex), - getStoneDusts(maximumIndex), - GT5OreSmallHelper.mapOreMetaToOreDrops.get(smallOre.oreMeta))); + smallOre.getMaterialDrops(), + getStoneDusts(), + GT5OreSmallHelper.ORE_MAT_TO_DROPS.get(smallOre.material))); } - 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; + private List getStoneDusts() { + List stoneDusts = new ArrayList<>(); + + for (StoneType stoneType : StoneType.STONE_TYPES) { + stoneDusts.add(GTOreDictUnificator.get(OrePrefixes.dust, stoneType.material, 1)); + } + + return stoneDusts; } @Override @@ -129,19 +125,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; @@ -172,8 +155,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..4d8b9264729 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -10,6 +10,9 @@ import net.minecraft.item.ItemStack; import codechicken.nei.PositionedStack; +import gregtech.api.enums.Materials; +import gregtech.common.blocks.BlockOres2; +import gregtech.common.blocks.ItemOres2; import gtneioreplugin.plugin.item.ItemDimensionDisplay; import gtneioreplugin.util.DimensionHelper; import gtneioreplugin.util.GT5OreLayerHelper; @@ -22,23 +25,26 @@ public class PluginGT5VeinStat extends PluginGT5Base { 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); + if (stack.getItem() instanceof ItemOres2) { + loadMatchingVeins(BlockOres2.getMaterial(stack.getItemDamage())); + } else { + super.loadCraftingRecipes(stack); + } } - private void loadMatchingVeins(short oreId) { + private void loadMatchingVeins(Materials ore) { for (OreLayerWrapper oreVein : getAllVeins()) { - if (oreVein.containsOre(oreId)) { - addVeinWithLayers(oreVein, getMaximumMaterialIndex(oreId, false)); + if (oreVein.containsOre(ore)) { + addVeinWithLayers(oreVein); } } } @@ -51,21 +57,20 @@ 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)); + if (Arrays.asList(getDimNameArrayFromVeinName(oreVein.veinName)).contains(dimension)) { + 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() { @@ -108,7 +113,7 @@ private static void drawVeinLayerNames(OreLayerWrapper oreLayer) { private static void drawVeinLayerNameLine(OreLayerWrapper oreLayer, int veinLayer, int height) { drawLine( OreVeinLayer.getOreVeinLayerName(veinLayer), - getGTOreLocalizedName(oreLayer.Meta[veinLayer]), + getGTOreLocalizedName(oreLayer.ores[veinLayer], false), 2, height); } diff --git a/src/main/java/gtneioreplugin/util/CSVMaker.java b/src/main/java/gtneioreplugin/util/CSVMaker.java index 814b684aacb..b477903d160 100644 --- a/src/main/java/gtneioreplugin/util/CSVMaker.java +++ b/src/main/java/gtneioreplugin/util/CSVMaker.java @@ -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.setOreMeta(oreLayer.material.mMetaItemSubID); oremix.setHeight(oreLayer.worldGenHeightRange); oremix.setAmount(oreLayer.amountPerChunk); - oremix.setDims(Dims); + oremix.setDims(oreLayer.enabledDims); SmallOreVeins.add(oremix); @@ -78,21 +76,21 @@ public void runVeins() { Map Dims = GT5OreLayerHelper.bufferedDims.get(pair.getValue()); 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(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.ores[0], false)); + oremix.setSecondary(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.ores[1], false)); + oremix.setInbetween(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.ores[2], false)); + oremix.setSporadic(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.ores[3], false)); 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]) + Integer.toString(oreLayer.ores[0].mMetaItemSubID) + "|" + + Integer.toString(oreLayer.ores[1].mMetaItemSubID) + "|" - + Integer.toString(oreLayer.Meta[2]) + + Integer.toString(oreLayer.ores[2].mMetaItemSubID) + "|" - + Integer.toString(oreLayer.Meta[3])); + + Integer.toString(oreLayer.ores[3].mMetaItemSubID)); 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..4020e19d30b 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -208,20 +208,6 @@ public static Map getDims(GT5OreLayerHelper.OreLayerWrapper ore 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); - } - return enabledDims; - } - public static String getDimAbbreviatedName(String dimName) { String abbreviatedName; switch (dimName) { diff --git a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java index 0e8e5b34621..6fd3f2f5ff7 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -8,30 +8,14 @@ import net.minecraft.item.ItemStack; -import gregtech.api.GregTechAPI; import gregtech.api.enums.Materials; import gregtech.api.enums.OreMixes; import gregtech.common.OreMixBuilder; +import gregtech.common.blocks.BlockOres2; +import gregtech.common.blocks.BlockOres2.StoneType; public class GT5OreLayerHelper { - public static class NormalOreDimensionWrapper { - - 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 (OreLayerWrapper oreVein : internalDimOreList) { - totalWeight += oreVein.randomWeight; - } - for (OreLayerWrapper oreVein : internalDimOreList) { - oreVeinToProbabilityInDimension.put(oreVein, ((double) oreVein.randomWeight) / ((double) totalWeight)); - } - } - } - 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]; @@ -42,8 +26,10 @@ private void calculateWeights() { public static void init() { Arrays.fill(weightPerWorld, 0); Arrays.fill(DimIDs, 0); - for (OreMixes mix : OreMixes.values()) + 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)); } @@ -72,7 +58,7 @@ public static void init() { public static class OreLayerWrapper { public final String veinName, worldGenHeightRange, localizedName; - public final short[] Meta = new short[4]; + public final Materials[] ores = new Materials[4]; public final short randomWeight, size, density; public final Map allowedDimWithOrigNames; @@ -84,10 +70,10 @@ public static class OreLayerWrapper { 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; @@ -102,23 +88,40 @@ public OreLayerWrapper(OreMixBuilder mix) { this.allowedDimWithOrigNames = mix.dimsEnabled; } - 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 (StoneType stoneType : StoneType.STONE_TYPES) { + 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, StoneType stoneType) { + return BlockOres2.getStack(stoneType, ores[veinLayer], false, false, 1); } - 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(Materials 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 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 (OreLayerWrapper oreVein : internalDimOreList) { + totalWeight += oreVein.randomWeight; + } + for (OreLayerWrapper oreVein : internalDimOreList) { + 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..4373589f0fa 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java @@ -2,182 +2,149 @@ 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 com.google.common.collect.Multimap; +import com.google.common.collect.MultimapBuilder; import net.minecraft.item.ItemStack; 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.world.GTWorldgen; import gregtech.common.SmallOreBuilder; import gregtech.common.WorldgenGTOreSmallPieces; +import gregtech.common.blocks.BlockOres2; +import gregtech.common.blocks.BlockOres2.StoneType; 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 ORE_DROP_TO_MAT = new HashMap<>(); + public static final HashMap> ORE_MAT_TO_DROPS = new HashMap<>(); + /** {abbr dim name: wrapper} */ + public static final HashMap SMALL_ORES_BY_DIM = new HashMap<>(); 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(); + for (GTWorldgen worldGen : GregTechAPI.sWorldgenList) { - if (!worldGen.mWorldGenName.startsWith("ore.small.") - || !(worldGen instanceof WorldgenGTOreSmallPieces worldGenSmallPieces)) { - continue; - } + if (!worldGen.mWorldGenName.startsWith("ore.small.")) 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; - } + Materials material = smallOreWorldGen.mMaterial; - 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); - } - 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); + OreSmallWrapper wrapper = new OreSmallWrapper(smallOreDefMap.get(smallOreWorldGen.mWorldGenName)); + SMALL_ORES_BY_NAME.put(worldGen.mWorldGenName, wrapper); + + if (ORE_MAT_TO_DROPS.containsKey(smallOreWorldGen.mMaterial)) { + throw new IllegalStateException("Duplicate small ore world gen for material " + smallOreWorldGen.mMaterial); } - stack = GTOreDictUnificator.get(OrePrefixes.dustImpure, material, 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); } - oreSmallList.add(new ItemStack(GregTechAPI.sBlockOres1, 1, meta + SMALL_ORE_BASE_META)); - mapOreMetaToOreDrops.put(meta, stackList); - } - for (OreSmallWrapper oreSmallWrapper : mapOreSmallWrapper.values()) { - bufferedDims.put(oreSmallWrapper, DimensionHelper.getDims(oreSmallWrapper)); - } + List stackList = BlockOres2.getPotentialDrops(material, true); - // --- Handling of dimToOreWrapper --- + ORE_MAT_TO_DROPS.put(material, stackList); - // 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); + for (ItemStack stack : stackList) { + ORE_DROP_TO_MAT.put(stack.getUnlocalizedName(), material); } - // Calculate probabilities for each dim. - for (String dim : dimToSmallOreWrapper.keySet()) { - dimToSmallOreWrapper.get(dim) - .calculateWeights(); + for (StoneType stoneType : StoneType.STONE_TYPES) { + SMALL_ORE_LIST.add(BlockOres2.getStack(stoneType, material, true, true, 1)); } - }); - // --- End of handling for dimToOreWrapper --- - } + } - public static Materials[] getDroppedDusts() { - return new Materials[] { Materials.Stone, Materials.Netherrack, Materials.Endstone, Materials.GraniteBlack, - Materials.GraniteRed, Materials.Marble, Materials.Basalt, Materials.Stone }; + for (String abbrDimName : oreSpawning.keySet()) { + SMALL_ORES_BY_DIM.put(abbrDimName, new SmallOreDimensionWrapper()); + } + + for (var e : oreSpawning.entries()) { + SMALL_ORES_BY_DIM.get(e.getKey()).smallOres.add(e.getValue()); + } + + SMALL_ORES_BY_DIM.values().forEach(SmallOreDimensionWrapper::calculateWeights); } public static class OreSmallWrapper { + public final SmallOreBuilder builder; public final String oreGenName; - public final short oreMeta; + public final Materials 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.builder = 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 getMaterialDrops() { + List oreVariants = new ArrayList<>(); + + for (StoneType stoneType : StoneType.STONE_TYPES) { + oreVariants.add(BlockOres2.getStack(stoneType, material, true, false, 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/SmallOre.java b/src/main/java/gtneioreplugin/util/SmallOre.java index 769ce63b3e8..66da646f6cc 100644 --- a/src/main/java/gtneioreplugin/util/SmallOre.java +++ b/src/main/java/gtneioreplugin/util/SmallOre.java @@ -3,6 +3,7 @@ import static gtneioreplugin.util.DimensionHelper.DimNameDisplayed; import java.util.Map; +import java.util.Set; @SuppressWarnings("unused") public class SmallOre implements Comparable { @@ -13,9 +14,9 @@ public class SmallOre implements Comparable { 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; } @@ -70,7 +71,7 @@ public String getCsvEntry() { 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/tectech/recipe/EyeOfHarmonyRecipe.java b/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java index 90acd630480..0ab4c5e8b67 100644 --- a/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java +++ b/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java @@ -365,9 +365,9 @@ private static ArrayList> processDimension( // Iterate over small ores in dimension and add them, kinda hacky but works and is close enough. if (smallOreDimWrapper != null) { - smallOreDimWrapper.oreVeinToProbabilityInDimension.forEach( + smallOreDimWrapper.oreVeinProbabilities.forEach( (veinInfo, - probability) -> processHelper(outputMap, veinInfo.getOreMaterial(), mainMultiplier, probability)); + probability) -> processHelper(outputMap, veinInfo.material, 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..f90356d706a 100644 --- a/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java +++ b/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java @@ -59,7 +59,7 @@ public class EyeOfHarmonyRecipeStorage { GT5OreLayerHelper.NormalOreDimensionWrapper normalOre = GT5OreLayerHelper.dimToOreWrapper .getOrDefault(dimAbbreviation, null); - GT5OreSmallHelper.SmallOreDimensionWrapper smallOre = GT5OreSmallHelper.dimToSmallOreWrapper + GT5OreSmallHelper.SmallOreDimensionWrapper smallOre = GT5OreSmallHelper.SMALL_ORES_BY_DIM .getOrDefault(dimAbbreviation, null); if (normalOre == null && smallOre == null) { // No ores are generated in this dimension. Fail silently. From aadf642c4f8699956fadcd6813f13d62f09c4901 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Fri, 6 Dec 2024 23:33:08 -0500 Subject: [PATCH 03/47] tons of changes --- .../bartworks/API/VoidMinerDropAdder.java | 24 - .../bartworks/neiHandler/NEIBWConfig.java | 1 - .../bartworks/neiHandler/OreNEIHandler.java | 246 -------- .../system/material/BWMetaGeneratedOres.java | 71 +-- .../material/BWMetaGeneratedSmallOres.java | 31 +- ...BWTileEntityMetaGeneratedBlocksCasing.java | 2 +- ...tityMetaGeneratedBlocksCasingAdvanced.java | 2 +- .../BWTileEntityMetaGeneratedOre.java | 61 +- .../BWTileEntityMetaGeneratedSmallOre.java | 2 +- ...TileEntityMetaGeneratedWerkstoffBlock.java | 2 +- .../TileEntityMetaGeneratedBlock.java | 4 +- .../bartworks/system/material/Werkstoff.java | 14 +- .../system/material/WerkstoffLoader.java | 22 +- .../bartworks/system/oregen/BWOreLayer.java | 271 -------- .../system/oregen/BWWordGenerator.java | 140 ----- .../system/oregen/BWWorldGenRoss128b.java | 188 ------ .../system/oregen/BWWorldGenRoss128ba.java | 176 ------ .../galacticgreg/MTEVoidMinerBase.java | 83 +-- .../galacticgreg/VoidMinerUtility.java | 216 ++----- .../galacticraft/GalacticraftProxy.java | 4 - .../ross128b/ChunkProviderRoss128b.java | 3 - .../ross128ba/ChunkProviderRoss128ba.java | 2 - .../detrav/commands/DetravScannerCommand.java | 64 +- .../java/detrav/gui/DetravScannerGUI.java | 64 +- src/main/java/detrav/gui/OresList.java | 29 +- .../detrav/gui/textures/DetravMapTexture.java | 136 ++++- .../items/DetravMetaGeneratedTool01.java | 5 + ...BehaviourDetravToolElectricProspector.java | 124 ++-- .../BehaviourDetravToolProspector.java | 96 +-- .../java/detrav/net/ProspectingPacket.java | 220 ++++--- .../java/galacticgreg/SpaceDimRegisterer.java | 36 +- .../galacticgreg/TileEntitySpaceOres.java | 144 ----- .../galacticgreg/WorldGeneratorSpace.java | 218 +++---- .../galacticgreg/WorldgenOreLayerSpace.java | 100 +-- .../galacticgreg/WorldgenOreSmallSpace.java | 15 +- .../galacticgreg/api/AsteroidBlockComb.java | 23 +- .../galacticgreg/api/ModDimensionDef.java | 6 +- .../galacticgreg/api/enums/DimensionDef.java | 12 +- .../galacticgreg/auxiliary/GTOreGroup.java | 20 +- src/main/java/gregtech/api/GregTechAPI.java | 2 +- .../java/gregtech/api/enums/Materials.java | 18 +- .../java/gregtech/api/enums/OreMixes.java | 463 +++++++++++++- .../java/gregtech/api/enums/OrePrefixes.java | 51 ++ .../java/gregtech/api/enums/StoneType.java | 399 ++++++++++-- .../gregtech/api/interfaces/IBlockOre.java | 6 +- .../gregtech/api/interfaces/IDimension.java | 10 + .../gregtech/api/interfaces/IMaterial.java | 13 + .../api/interfaces/IRedstoneCircuitBlock.java | 2 +- .../gregtech/api/interfaces/IStoneType.java | 17 +- .../tileentity/IHasWorldObjectAndCoords.java | 8 +- .../api/metatileentity/BaseTileEntity.java | 8 +- .../java/gregtech/api/net/GTPacketTypes.java | 2 - .../java/gregtech/api/util/GTBaseCrop.java | 31 +- .../java/gregtech/api/util/GTUtility.java | 29 +- .../java/gregtech/api/world/GTWorldgen.java | 4 +- .../gregtech/common/GTWorldgenerator.java | 87 ++- .../java/gregtech/common/OreMixBuilder.java | 28 +- .../java/gregtech/common/SmallOreBuilder.java | 6 +- .../gregtech/common/WorldgenGTOreLayer.java | 493 ++++++--------- .../common/WorldgenGTOreSmallPieces.java | 86 +-- .../java/gregtech/common/WorldgenStone.java | 46 +- .../gregtech/common/blocks/BlockOres.java | 154 ----- .../gregtech/common/blocks/BlockOres2.java | 577 ----------------- .../common/blocks/BlockOresAbstract.java | 466 +++++++------- .../common/blocks/BlockOresAbstractOld.java | 51 ++ .../gregtech/common/blocks/BlockOresOld.java | 46 ++ .../java/gregtech/common/blocks/ItemOres.java | 62 +- .../gregtech/common/blocks/ItemOres2.java | 46 -- .../gregtech/common/blocks/ItemOresOld.java | 13 + .../gregtech/common/blocks/PacketOres.java | 62 -- .../common/blocks/TileEntityOres.java | 471 +------------- .../items/behaviors/BehaviourProspecting.java | 46 +- .../common/misc/DrillingLogicDelegate.java | 45 +- .../gregtech/common/ores/BWOreAdapter.java | 207 +++++++ .../gregtech/common/ores/GTOreAdapter.java | 304 +++++++++ .../gregtech/common/ores/GTPPOreAdapter.java | 122 ++++ .../gregtech/common/ores/IOreAdapter.java | 55 ++ .../java/gregtech/common/ores/OreInfo.java | 118 ++++ .../java/gregtech/common/ores/OreManager.java | 240 ++++++++ .../gregtech/common/ores/SmallOreDrops.java | 49 ++ .../common/render/GTRendererBlock.java | 19 +- .../basic/MTEAdvSeismicProspector.java | 24 +- .../tileentities/machines/basic/MTEMiner.java | 13 +- .../MTELongDistancePipelineBase.java | 2 +- .../machines/multi/MTEOilCracker.java | 2 +- .../multi/MTEOreDrillingPlantBase.java | 78 +-- .../loaders/preload/LoaderGTBlockFluid.java | 9 +- src/main/java/gregtech/nei/NEIGTConfig.java | 14 + .../api/interfaces/ILazyCoverable.java | 8 +- .../core/block/base/BlockBaseOre.java | 1 - .../item/base/itemblock/ItemBlockOre.java | 53 +- .../gtPlusPlus/core/material/Material.java | 28 +- .../tileentities/base/TileEntityBase.java | 8 +- .../gtPlusPlus/everglades/GTPPEverglades.java | 32 +- .../everglades/gen/gt/WorldGen_GT.java | 46 -- .../everglades/gen/gt/WorldGen_GT_Base.java | 578 ------------------ .../gen/gt/WorldGen_GT_Ore_Layer.java | 480 +-------------- .../everglades/gen/gt/WorldGen_Ores.java | 25 - .../gtPlusPlus/xmod/gregtech/HandlerGT.java | 2 - .../items/behaviours/Behaviour_Choocher.java | 91 --- .../behaviours/Behaviour_Prospecting_Ex.java | 138 ----- .../processing/MTEIndustrialWashPlant.java | 2 +- .../production/MTEIndustrialFishingPond.java | 4 +- .../production/algae/MTEAlgaePondBase.java | 4 +- ...aTileEntity_PowerSubStationController.java | 2 +- .../redstone/MTERedstoneCircuitBlock.java | 2 +- .../java/gtneioreplugin/GTNEIOrePlugin.java | 19 +- .../plugin/gregtech5/PluginGT5Base.java | 19 +- .../gregtech5/PluginGT5SmallOreStat.java | 84 +-- .../plugin/gregtech5/PluginGT5VeinStat.java | 22 +- .../ItemDimensionDisplayRenderer.java | 2 +- .../java/gtneioreplugin/util/CSVMaker.java | 22 +- .../gtneioreplugin/util/DimensionHelper.java | 41 +- .../util/GT5OreLayerHelper.java | 45 +- .../util/GT5OreSmallHelper.java | 43 +- src/main/java/gtneioreplugin/util/Oremix.java | 8 +- .../java/gtneioreplugin/util/SmallOre.java | 12 +- .../multiblock/eigbuckets/EIGIC2Bucket.java | 35 +- .../tectech/recipe/EyeOfHarmonyRecipe.java | 14 +- .../assets/gtneioreplugin/lang/en_US.lang | 1 + 120 files changed, 3839 insertions(+), 6013 deletions(-) delete mode 100644 src/main/java/bartworks/API/VoidMinerDropAdder.java delete mode 100644 src/main/java/bartworks/neiHandler/OreNEIHandler.java delete mode 100644 src/main/java/bartworks/system/oregen/BWOreLayer.java delete mode 100644 src/main/java/bartworks/system/oregen/BWWordGenerator.java delete mode 100644 src/main/java/bartworks/system/oregen/BWWorldGenRoss128b.java delete mode 100644 src/main/java/bartworks/system/oregen/BWWorldGenRoss128ba.java delete mode 100644 src/main/java/galacticgreg/TileEntitySpaceOres.java create mode 100644 src/main/java/gregtech/api/interfaces/IDimension.java create mode 100644 src/main/java/gregtech/api/interfaces/IMaterial.java delete mode 100644 src/main/java/gregtech/common/blocks/BlockOres.java delete mode 100644 src/main/java/gregtech/common/blocks/BlockOres2.java create mode 100644 src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java create mode 100644 src/main/java/gregtech/common/blocks/BlockOresOld.java delete mode 100644 src/main/java/gregtech/common/blocks/ItemOres2.java create mode 100644 src/main/java/gregtech/common/blocks/ItemOresOld.java delete mode 100644 src/main/java/gregtech/common/blocks/PacketOres.java create mode 100644 src/main/java/gregtech/common/ores/BWOreAdapter.java create mode 100644 src/main/java/gregtech/common/ores/GTOreAdapter.java create mode 100644 src/main/java/gregtech/common/ores/GTPPOreAdapter.java create mode 100644 src/main/java/gregtech/common/ores/IOreAdapter.java create mode 100644 src/main/java/gregtech/common/ores/OreInfo.java create mode 100644 src/main/java/gregtech/common/ores/OreManager.java create mode 100644 src/main/java/gregtech/common/ores/SmallOreDrops.java delete mode 100644 src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT.java delete mode 100644 src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Base.java delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Choocher.java delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Prospecting_Ex.java 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/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/system/material/BWMetaGeneratedOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java index c74c3f01cba..6c3dab3bbe1 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -13,10 +13,9 @@ package bartworks.system.material; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.enchantment.EnchantmentHelper; @@ -29,19 +28,22 @@ 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.util.GTLanguageManager; import gregtech.api.util.GTModHandler; +import gregtech.common.ores.BWOreAdapter; +import gregtech.common.ores.OreInfo; public class BWMetaGeneratedOres extends BWMetaGeneratedBlocks { - public BWMetaGeneratedOres(Material p_i45386_1_, Class tileEntity, String blockName) { + public final boolean isNatural; + + public BWMetaGeneratedOres(Material p_i45386_1_, Class tileEntity, String blockName, boolean natural) { super(p_i45386_1_, tileEntity, blockName); this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( "bw.blocktype." + OrePrefixes.ore, OrePrefixes.ore.mLocalizedMaterialPre + "%material" + OrePrefixes.ore.mLocalizedMaterialPost); + this.isNatural = natural; } @Override @@ -52,34 +54,6 @@ 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()); - } - - 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; - } - - 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; - } - - return true; - } - @Override public IIcon getIcon(int side, int meta) { return Blocks.stone.getIcon(0, 0); @@ -102,32 +76,25 @@ public String getUnlocalizedName() { @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; - } - super.harvestBlock(worldIn, player, x, y, z, meta); - if (BWTileEntityMetaGeneratedOre.shouldFortune) { - BWTileEntityMetaGeneratedOre.shouldFortune = false; + try (OreInfo info = BWOreAdapter.INSTANCE.getOreInfo(this, metadata);) { + return (ArrayList) BWOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); } } } diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java index 5025f4ac77b..75ae9418c29 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java @@ -27,8 +27,8 @@ public class BWMetaGeneratedSmallOres extends BWMetaGeneratedOres { - public BWMetaGeneratedSmallOres(Material p_i45386_1_, Class tileEntity, String blockName) { - super(p_i45386_1_, tileEntity, blockName); + public BWMetaGeneratedSmallOres(Material p_i45386_1_, Class tileEntity, String blockName, boolean natural) { + super(p_i45386_1_, tileEntity, blockName, natural); this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( "bw.blocktype." + OrePrefixes.oreSmall, OrePrefixes.oreSmall.mLocalizedMaterialPre + "%material" + OrePrefixes.oreSmall.mLocalizedMaterialPost); @@ -46,31 +46,4 @@ protected void doRegistrationStuff(Werkstoff w) { 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 index 7f7d0716f55..07cd71ff833 100644 --- a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedOre.java +++ b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedOre.java @@ -13,26 +13,17 @@ 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 @@ -60,57 +51,7 @@ public ITexture[] getTexture(Block aBlock, ForgeDirection side) { } @Override - protected Block GetProperBlock() { + 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 index 737b486cf99..91f97aa4e59 100644 --- a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedSmallOre.java +++ b/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedSmallOre.java @@ -119,7 +119,7 @@ public ITexture[] getTexture(Block aBlock, ForgeDirection side) { } @Override - protected Block GetProperBlock() { + 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..b3b6785bee1 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -53,12 +53,13 @@ import gregtech.api.enums.TCAspects; import gregtech.api.enums.TextureSet; import gregtech.api.interfaces.IColorModulationContainer; +import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.util.GTLanguageManager; import gregtech.api.util.GTOreDictUnificator; import thaumcraft.api.aspects.Aspect; -public class Werkstoff implements IColorModulationContainer, ISubTagContainer { +public class Werkstoff implements IColorModulationContainer, ISubTagContainer, IMaterial { public static final LinkedHashSet werkstoffHashSet = new LinkedHashSet<>(); public static final LinkedHashMap werkstoffHashMap = new LinkedHashMap<>(); @@ -499,6 +500,7 @@ public String getDefaultName() { return this.defaultName; } + @Override public String getLocalizedName() { return GTLanguageManager.addStringLocalization( String.format("bw.werkstoff.%05d.name", this.mID), @@ -529,6 +531,16 @@ public short getmID() { return this.mID; } + @Override + public int getId() { + return mID; + } + + @Override + public String getInternalName() { + return getVarName(); + } + public short getMixCircuit() { return this.getGenerationFeatures().mixCircuit; } diff --git a/src/main/java/bartworks/system/material/WerkstoffLoader.java b/src/main/java/bartworks/system/material/WerkstoffLoader.java index 079238c28a4..d0bd41d20bb 100644 --- a/src/main/java/bartworks/system/material/WerkstoffLoader.java +++ b/src/main/java/bartworks/system/material/WerkstoffLoader.java @@ -1573,8 +1573,8 @@ 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 BWOres, BWOresNatural; + public static Block BWSmallOres, BWSmallOresNatural; public static Block BWBlocks; public static Block BWBlockCasings; public static Block BWBlockCasingsAdvanced; @@ -1940,11 +1940,23 @@ static void gameRegistryHandler() { WerkstoffLoader.BWOres = new BWMetaGeneratedOres( Material.rock, BWTileEntityMetaGeneratedOre.class, - "bw.blockores"); + "bw.blockores", + false); + WerkstoffLoader.BWOresNatural = new BWMetaGeneratedOres( + Material.rock, + BWTileEntityMetaGeneratedOre.class, + "bw.blockores.natural", + true); WerkstoffLoader.BWSmallOres = new BWMetaGeneratedSmallOres( Material.rock, BWTileEntityMetaGeneratedSmallOre.class, - "bw.blockoresSmall"); + "bw.blockoresSmall", + false); + WerkstoffLoader.BWSmallOresNatural = new BWMetaGeneratedSmallOres( + Material.rock, + BWTileEntityMetaGeneratedSmallOre.class, + "bw.blockoresSmall.natural", + true); WerkstoffLoader.BWBlocks = new BWMetaGeneratedWerkstoffBlocks( Material.iron, BWTileEntityMetaGeneratedWerkstoffBlock.class, @@ -1961,7 +1973,9 @@ static void gameRegistryHandler() { OrePrefixes.blockCasingAdvanced); GameRegistry.registerBlock(WerkstoffLoader.BWOres, BWItemMetaGeneratedBlock.class, "bw.blockores.01"); + GameRegistry.registerBlock(WerkstoffLoader.BWOresNatural, BWItemMetaGeneratedBlock.class, "bw.blockores.natural.01"); GameRegistry.registerBlock(WerkstoffLoader.BWSmallOres, BWItemMetaGeneratedBlock.class, "bw.blockores.02"); + GameRegistry.registerBlock(WerkstoffLoader.BWSmallOresNatural, BWItemMetaGeneratedBlock.class, "bw.blockores.natural.02"); GameRegistry.registerBlock(WerkstoffLoader.BWBlocks, BWItemMetaGeneratedBlock.class, "bw.werkstoffblocks.01"); GameRegistry.registerBlock( WerkstoffLoader.BWBlockCasings, 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 8e5b4a75216..09a49eed421 100644 --- a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java +++ b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java @@ -24,15 +24,6 @@ import java.util.Map; import java.util.stream.Collectors; -import net.minecraft.block.Block; -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 gregtech.api.enums.GTValues; @@ -42,6 +33,12 @@ import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gregtech.common.tileentities.machines.multi.MTEDrillerBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; public abstract class MTEVoidMinerBase extends MTEDrillerBase { @@ -54,14 +51,6 @@ public abstract class MTEVoidMinerBase extends MTEDrillerBase { 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); @@ -235,48 +224,15 @@ 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); - } - } - } - /** * Computes first the ores related to the dim the VM is in, then the ores added manually, then it computes the * 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); + String dimName = this.getBaseMetaTileEntity().getWorld().provider.getDimensionName(); + this.dropMap = VoidMinerUtility.dropMapsByDimName.getOrDefault(dimName, new VoidMinerUtility.DropMap()); + this.extraDropMap = VoidMinerUtility.extraDropsByDimName.getOrDefault(dimName, new VoidMinerUtility.DropMap()); + this.totalWeight = dropMap.getTotalWeight() + extraDropMap.getTotalWeight(); } @@ -288,16 +244,27 @@ 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))) + + 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 5ff821375be..cb3645022c1 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,23 +14,17 @@ 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.DimNames; +import gregtech.GTMod; import gregtech.api.enums.Materials; -import gregtech.api.interfaces.ISubTagContainer; +import gregtech.api.interfaces.IMaterial; import gregtech.api.util.GTUtility; import gregtech.common.WorldgenGTOreLayer; import gregtech.common.WorldgenGTOreSmallPieces; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; public class VoidMinerUtility { @@ -63,11 +53,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.sBlockOres2, meta, weight); + public void addDrop(IMaterial 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); } } @@ -121,169 +118,78 @@ 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)); + outer: for (WorldgenGTOreLayer layer : WorldgenGTOreLayer.sList) { + if (!layer.mEnabled) continue; + + for (String dim : layer.mAllowedDimensions) { + if (dim.equals(DimNames.ENDASTEROIDS)) { + if (layer.mAllowedDimensions.contains(DimNames.THE_END)) { + continue outer; + } else { + dim = DimNames.THE_END; + } + } + + 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(BlockOres2.getMeta(StoneType.Stone, element.mMaterial.mMetaItemSubID, true, true), element.mAmount, false)); - return dropMap; - } + outer: 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.mAllowedDimensions) { + if (dim.equals(DimNames.ENDASTEROIDS)) { + if (layer.mAllowedDimensions.contains(DimNames.THE_END)) { + continue outer; + } else { + dim = DimNames.THE_END; + } + } - /** - * 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(); - }; - } + DropMap map = dropMapsByDimName.computeIfAbsent(dim, ignored -> new DropMap()); - /** - * 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); + map.addDrop(layer.mMaterial, 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 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, IMaterial 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..b84e932fc78 100644 --- a/src/main/java/detrav/commands/DetravScannerCommand.java +++ b/src/main/java/detrav/commands/DetravScannerCommand.java @@ -1,34 +1,27 @@ package detrav.commands; import java.util.ArrayList; +import java.util.Arrays; 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 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 = new ArrayList<>(Arrays.asList("DetravScanner", "dscan")); @Override public String getCommandName() { @@ -41,7 +34,7 @@ public String getCommandUsage(ICommandSender sender) { } @Override - public List getCommandAliases() { + public List getCommandAliases() { return this.aliases; } @@ -89,39 +82,38 @@ 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); + var p = OreManager.getOreInfo(b, meta); - if (entity == null) { - continue; - } + if (p == null) continue; - 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); + try (OreInfo info = p.right()) { + if (info.isSmall) continue; + + String matName = info.material.getLocalizedName(); + + 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 +131,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..e6c63713fde 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,52 @@ 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..139b16b9e82 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.client.resources.I18n; +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,23 @@ 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 +72,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..8cfd7431b5d 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,120 @@ 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(); - // Variables used to locate within a chunk. - final int k = (i % 16), l = (j % 16); + int x = CoordinatePacker.unpackX(coord); + int y = CoordinatePacker.unpackY(coord); + int z = CoordinatePacker.unpackZ(coord); - 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 (y < depth[x + z * blockSize]) continue; + depth[x + z * blockSize] = (short) y; + + var object = packet.objects.get(e.getShortValue()); + + 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); + + var object = packet.objects.get(packet.map.get(CoordinatePacker.pack(cX, 0, cZ))); + + 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 75788a5bfbc..e013647e276 100644 --- a/src/main/java/detrav/items/DetravMetaGeneratedTool01.java +++ b/src/main/java/detrav/items/DetravMetaGeneratedTool01.java @@ -271,6 +271,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 9b512c59611..ab348710037 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -1,5 +1,8 @@ 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; @@ -21,13 +24,11 @@ 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.GTOreDictUnificator; import gregtech.common.UndergroundOil; -import gregtech.common.blocks.BlockOres2; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; +import gregtech.common.pollution.Pollution; /** * Created by wital_000 on 19.03.2016. @@ -71,85 +72,57 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW (int) aPlayer.posZ, size, 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 BlockOres2) { - if (!BlockOres2.isNatural(tMetaID)) continue; - if (data != 1 && BlockOres2.isSmallOre(tMetaID)) continue; - - packet.addBlock(c.xPosition * 16 + x, y, c.zPosition * 16 + z, tMetaID); - } 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); + + switch (data) { + case MODE_BIG_ORES, MODE_ALL_ORES -> { + for (Chunk c : chunks) { + 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); + + if (OreManager.getStoneType(block, meta) != null) continue; + + var p = OreManager.getOreInfo(block, meta); + + if (p != null) { + try (OreInfo info = p.right()) { + if (!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; + } } } } - 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 -> { + for (Chunk c : chunks) { + FluidStack fluid = UndergroundOil.undergroundOil(c, -1); + + packet.addFluid(c.xPosition, c.zPosition, fluid); + } + } + case DetravMetaGeneratedTool01.MODE_POLLUTION -> { + for (Chunk c : chunks) { + 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()); if (VisualProspecting.isModLoaded()) { - if (data == 0 || data == 1) { + if (data == MODE_BIG_ORES || data == MODE_ALL_ORES) { VisualProspecting_API.LogicalServer.sendProspectionResultsToClient( (EntityPlayerMP) aPlayer, VisualProspecting_API.LogicalServer.prospectOreVeinsWithinRadius( @@ -158,7 +131,7 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW (int) aPlayer.posZ, size * 16), new ArrayList<>()); - } else if (data == 2) { + } else if (data == MODE_FLUIDS) { VisualProspecting_API.LogicalServer.sendProspectionResultsToClient( (EntityPlayerMP) aPlayer, new ArrayList<>(), @@ -209,8 +182,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 a9d0427b8ba..d67fa49e59a 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java @@ -29,15 +29,16 @@ 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.BlockOres2; import gregtech.common.items.behaviors.BehaviourNone; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import gregtech.common.pollution.Pollution; /** @@ -67,7 +68,10 @@ 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"); @@ -85,14 +89,13 @@ 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.sBlockOres2) { - if (!aWorld.isRemote) { - prospectChunks(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, aRandom, chance); - } + + if (block.getMaterial() == Material.rock || block.getMaterial() == Material.ground || GTUtility.isMinable(block, meta)) { + prospectChunks(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, aRandom, chance); + return true; } + return false; } @@ -105,7 +108,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 } @@ -116,11 +119,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++) { @@ -128,6 +131,7 @@ protected void prospectChunks(MetaBaseItem aItem, ItemStack aStack, EntityPlayer break; } } + if (DetravScannerMod.DEBUG_ENABLED) { aPlayer.addChatMessage( new ChatComponentText( @@ -141,6 +145,7 @@ protected void prospectChunks(MetaBaseItem aItem, ItemStack aStack, EntityPlayer + (aZ + 16) + StatCollector.translateToLocal("detrav.scanner.distance.texts." + distTextIndex))); } + processOreProspecting( (DetravMetaGeneratedTool01) aItem, aStack, @@ -263,13 +268,16 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack int meta = world.getBlockMetadata(x, y, z); ItemStack blockStack = new ItemStack(block, 1, meta); - ItemData itemData = GTOreDictUnificator.getAssociation(blockStack); - if (block instanceof BlockOres2) { + if (OreManager.isOre(block, meta)) { addOreToHashMap(blockStack.getDisplayName(), aPlayer); if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts); return; - } else if (itemData != null) { + } + + ItemData itemData = GTOreDictUnificator.getAssociation(blockStack); + + if (itemData != null) { try { String name = itemData.toString(); addChatMassageByValue(aPlayer, -1, name); @@ -278,10 +286,14 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack } 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 cx = 0; cx < 16; cx++) { for (int cz = 0; cz < 16; cz++) { int ySize = chunk.getHeightValue(cx, cz); @@ -290,27 +302,28 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack Block tBlock = chunk.getBlock(cx, cy, cz); short tMetaID = (short) chunk.getBlockMetadata(cx, cy, cz); - if (tBlock instanceof BlockOres2) { - if (!BlockOres2.isNatural(tMetaID)) continue; - if (data != 1 && BlockOres2.isSmallOre(tMetaID)) continue; + var p = OreManager.getOreInfo(tBlock, tMetaID); - ItemStack blockStack2 = new ItemStack(tBlock, 1, tMetaID); - addOreToHashMap(blockStack2.getDisplayName(), aPlayer); + if (p != null) { + try (OreInfo info = p.right()) { + if (!info.isNatural) continue; + if (data != DetravMetaGeneratedTool01.MODE_ALL_ORES && info.isSmall) continue; + + ItemStack blockStack2 = new ItemStack(tBlock, 1, tMetaID); + addOreToHashMap(blockStack2.getDisplayName(), aPlayer); + } } 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(chunk, cx, cy, cz, tBlock)) * -1), - null); + if (data != DetravMetaGeneratedTool01.MODE_ALL_ORES && BartWorksHelper.isSmallOre(tBlock)) continue; + final Werkstoff werkstoff = Werkstoff.werkstoffHashMap.getOrDefault((short) ((BartWorksHelper.getMetaFromBlock(chunk, cx, cy, cz, 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) { + } else if (data == DetravMetaGeneratedTool01.MODE_ALL_ORES) { itemData = GTOreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); - if ((itemData != null) && (itemData.mPrefix.toString() - .startsWith("ore"))) { + if (itemData != null && itemData.mPrefix.toString().startsWith("ore")) { try { try { tMetaID = (short) itemData.mMaterial.mMaterial.mMetaItemSubID; @@ -332,24 +345,17 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack 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 920ee425ad2..1d32ee88669 100644 --- a/src/main/java/detrav/net/ProspectingPacket.java +++ b/src/main/java/detrav/net/ProspectingPacket.java @@ -6,27 +6,26 @@ 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.items.DetravMetaGeneratedTool01; import detrav.utils.FluidColors; -import detrav.utils.GTppHelper; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.util.GTLanguageManager; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.api.interfaces.IMaterial; +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. @@ -39,11 +38,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; @@ -52,53 +52,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.blockores2." + BlockOres2.getMeta(StoneType.Stone, meta % 1000, false, false) + ".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 { @@ -110,24 +67,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; } @@ -145,25 +106,22 @@ 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(checkOut); + + tOut.writeInt(map.size()); + + for (var instance : map.long2ShortEntrySet()) { + tOut.writeLong(instance.getLongKey()); + tOut.writeShort(instance.getShortValue()); + } + tOut.close(); } @@ -173,11 +131,75 @@ 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++; + + IMaterial 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); + + 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/galacticgreg/SpaceDimRegisterer.java b/src/main/java/galacticgreg/SpaceDimRegisterer.java index 611477f7df2..7a75d12e60a 100644 --- a/src/main/java/galacticgreg/SpaceDimRegisterer.java +++ b/src/main/java/galacticgreg/SpaceDimRegisterer.java @@ -7,9 +7,11 @@ import galacticgreg.api.GTOreTypes; import galacticgreg.api.ModContainer; import galacticgreg.api.SpecialBlockComb; +import galacticgreg.api.Enums.AllowedBlockPosition; import galacticgreg.api.enums.DimensionDef; import galacticgreg.api.enums.ModContainers; import galacticgreg.registry.GalacticGregRegistry; +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 +36,14 @@ 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(new AsteroidBlockComb(StoneType.Netherrack)); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.RedGranite)); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.BlackGranite)); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Endstone)); // 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)); + DimensionDef.EndAsteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.lava, Enums.AllowedBlockPosition.AsteroidCore)); ModContainers.Vanilla.modContainer.addDimensionDef(DimensionDef.EndAsteroids.modDimensionDef); @@ -65,9 +66,13 @@ private static ModContainer setupGalactiCraftPlanets() { 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(new AsteroidBlockComb(StoneType.BlackGranite)); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.RedGranite)); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Moon)); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Asteroid)); + DimensionDef.Asteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.packed_ice, AllowedBlockPosition.AsteroidCoreAndShell)); + DimensionDef.Asteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.ice, AllowedBlockPosition.AsteroidCoreAndShell)); + ModContainers.GalacticraftMars.modContainer.addDimensionDef(DimensionDef.Asteroids.modDimensionDef); return ModContainers.GalacticraftMars.modContainer; @@ -117,10 +122,15 @@ 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(new AsteroidBlockComb(StoneType.RedGranite)); + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.BlackGranite)); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Moon)); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Asteroid)); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.KuiperBelt.modDimensionDef); + return ModContainers.GalaxySpace.modContainer; } @@ -133,8 +143,10 @@ 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); 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..8f6a7cc7b3e 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -18,7 +18,6 @@ import galacticgreg.api.AsteroidBlockComb; import galacticgreg.api.BlockMetaComb; import galacticgreg.api.Enums; -import galacticgreg.api.GTOreTypes; import galacticgreg.api.ISpaceObjectGenerator; import galacticgreg.api.ModDimensionDef; import galacticgreg.api.SpecialBlockComb; @@ -26,20 +25,14 @@ import galacticgreg.auxiliary.GTOreGroup; import galacticgreg.dynconfig.DynamicDimensionConfig; import galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.interfaces.IMaterial; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; import gregtech.common.GTWorldgenerator; +import gregtech.common.ores.OreManager; 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; @@ -47,6 +40,7 @@ public WorldGeneratorSpace() { GameRegistry.registerWorldGenerator(this, Integer.MAX_VALUE); } + @Override public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { pX *= 16; @@ -81,9 +75,9 @@ public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvide 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 generateAsteroids(tDimDef, pRandom, pWorld, pX, pZ); } else if (tDimDef.getDimensionType() != Enums.DimensionType.Asteroid) { - Generate_OreVeins(tDimDef, pRandom, pWorld, pX, pZ, "", pChunkGenerator, pChunkProvider); + generateOreVeins(tDimDef, pRandom, pWorld, pX, pZ, "", pChunkGenerator, pChunkProvider); } Chunk tChunk = pWorld.getChunkFromBlockCoords(pX, pZ); @@ -92,20 +86,21 @@ public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvide } } - private void Generate_Asteroids(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ) { + private void generateAsteroids(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ) { GalacticGreg.Logger.trace("Running asteroid-gen in Dim %s", pDimensionDef.getDimIdentifier()); - DynamicDimensionConfig.AsteroidConfig tAConf = DynamicDimensionConfig.getAsteroidConfig(pDimensionDef); - if (tAConf == null) { + DynamicDimensionConfig.AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(pDimensionDef); + + if (dimAsteroidConfig == 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); + GalacticGreg.Logger.trace("Asteroid probability: %d", dimAsteroidConfig.Probability); } - if ((tAConf.Probability <= 1) || (pRandom.nextInt(tAConf.Probability) == 0)) { + if (dimAsteroidConfig.Probability <= 1 || pRandom.nextInt(dimAsteroidConfig.Probability) == 0) { GalacticGreg.Logger.trace("Generating asteroid NOW"); // --------------------------- if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); @@ -117,28 +112,18 @@ private void Generate_Asteroids(ModDimensionDef pDimensionDef, Random pRandom, W 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; + if (pWorld.isAirBlock(tX, tY, tZ)) { // 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(); + GTOreGroup oreGroup = WorldgenOreLayerSpace.getRandomOreGroup(pDimensionDef, pRandom, true); + + AsteroidBlockComb asteroidStone = pDimensionDef.getRandomAsteroidMaterial(); + if (asteroidStone == null) return; + GalacticGreg.Logger.debug( "Asteroid will be build with: Block: [%s] OreType: [%s]", - Block.blockRegistry.getNameForObject(tABComb.getBlock()), - tABComb.getOreMaterial() + Block.blockRegistry.getNameForObject(asteroidStone.getBlock()), + asteroidStone.getStone() .toString()); // get random Ore-asteroid generator from the list of registered generators @@ -153,22 +138,22 @@ private void Generate_Asteroids(ModDimensionDef pDimensionDef, Random pRandom, W aGen.reset(); aGen.setCenterPoint(tX, tY, tZ); - aGen.randomize(tAConf.MinSize, tAConf.MaxSize); // Initialize random values and set size + aGen.randomize(dimAsteroidConfig.MinSize, dimAsteroidConfig.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) { + if (dimAsteroidConfig.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) { + // happened) + if (dimAsteroidConfig.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; + if (dimAsteroidConfig.RandomizeNumLootItems) tNumLootItems = pRandom.nextInt(dimAsteroidConfig.NumLootItems - 1) + 1; + else tNumLootItems = dimAsteroidConfig.NumLootItems; GalacticGreg.Logger .debug(String.format("Loot chest random item count will be: %d", tNumLootItems)); @@ -214,7 +199,7 @@ private void Generate_Asteroids(ModDimensionDef pDimensionDef, Random pRandom, W GalacticGreg.Logger.trace("Now generating LootChest and contents"); // Get items for the configured loot-table WeightedRandomChestContent[] tRandomLoot = ChestGenHooks - .getItems(DynamicDimensionConfig.getLootChestTable(tAConf), pRandom); + .getItems(DynamicDimensionConfig.getLootChestTable(dimAsteroidConfig), pRandom); // Get chest-block to spawn BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; @@ -264,97 +249,99 @@ private void Generate_Asteroids(ModDimensionDef pDimensionDef, Random pRandom, W // << Loot-chest generator === // === Ore generator >> - boolean tPlacedOreBlock = false; + boolean tPlacedAnything = 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"); + if (oreGroup != null) { + // GalacticGreg.Logger.trace("tOreGroup is populated, continuing"); // Choose a number between 0 and 100 int ranOre = pRandom.nextInt(100); - int tFinalOreMeta = 0; + IMaterial ore = null; - // If choosen number is below the configured orechance, do random between and sporadic - if (ranOre < tAConf.OreChance) { + // If chosen number is below the configured orechance, do random between and sporadic + if (ranOre < dimAsteroidConfig.OreChance) { if (pRandom.nextBoolean()) { // Only take as final value if meta is not zero - if (tOreGroup.SporadicBetweenMeta > 0) - tFinalOreMeta = tOreGroup.SporadicBetweenMeta; + if (oreGroup.SporadicBetween != null) + ore = oreGroup.SporadicBetween; } else { // Only take as final value if meta is not zero - if (tOreGroup.SporadicAroundMeta > 0) tFinalOreMeta = tOreGroup.SporadicAroundMeta; + if (oreGroup.SporadicAround != null) ore = oreGroup.SporadicAround; } } - // If choosen number is below the configured orechance, do random primary and secondary + // If chosen 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) { + else if (ranOre < dimAsteroidConfig.OreChance + dimAsteroidConfig.OrePrimaryOffset) { if (pRandom.nextBoolean()) { // Only take as final value if meta is not zero - if (tOreGroup.PrimaryMeta > 0) tFinalOreMeta = tOreGroup.PrimaryMeta; + if (oreGroup.Primary != null) ore = oreGroup.Primary; } else { // Only take as final value if meta is not zero - if (tOreGroup.SecondaryMeta > 0) tFinalOreMeta = tOreGroup.SecondaryMeta; + if (oreGroup.Secondary != null) ore = oreGroup.Secondary; } } // if the final oreMeta has been found... // GalacticGreg.Logger.info("tFinalOreMeta is %d", tFinalOreMeta); - if (tFinalOreMeta > 0) { + if (ore != null) { // make sure we obey the configured "HiddenOres" setting (No ores on the shell) - if (tAConf.HiddenOres - && (si.getBlockPosition() == Enums.TargetBlockPosition.AsteroidShell)) { + if (dimAsteroidConfig.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, + // try to place the ore block + tPlacedAnything = OreManager.setOreForWorldGen( pWorld, si.getX(), si.getY(), si.getZ(), - tOreGroup.SecondaryMeta, - true, - tFinalOreOffset); + asteroidStone.getStone(), + oreGroup.Secondary, + false); } } } // << Ore generator === // === Additional special blocks >> - // If no ore-block has been placed yet... - if (!tPlacedOreBlock) { - // try to spawn special blocks - boolean tFlag = doGenerateSpecialBlocks( + + if (!tPlacedAnything) { + tPlacedAnything = generateSpecialBlocks( pDimensionDef, pRandom, pWorld, - tAConf, + dimAsteroidConfig, si.getX(), si.getY(), si.getZ(), si.getBlockPosition()); + } - // No special block placed? Try smallores - if (tFlag) tFlag = doGenerateSmallOreBlock( + + // No special block placed? Try smallores + if (!tPlacedAnything) { + tPlacedAnything = generateSmallOreBlock( pDimensionDef, pRandom, pWorld, - tAConf, + dimAsteroidConfig, si.getX(), si.getY(), si.getZ(), - tFinalOreOffset); + asteroidStone); + } - // no smallores either? do normal block - if (tFlag) pWorld.setBlock( + // no smallores either? do normal block + if (!tPlacedAnything) { + pWorld.setBlock( si.getX(), si.getY(), si.getZ(), - tFinalAsteroidBlock, - tFinalAsteroidBlockMeta, - tFinalUpdateMode); - + asteroidStone.getBlock(), + asteroidStone.getMeta(), + 3); } + // << Additional special blocks === } } @@ -389,11 +376,10 @@ else if (ranOre < tAConf.OreChance + tAConf.OrePrimaryOffset) { * @param eZ * @return */ - private boolean doGenerateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, + private boolean generateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, DynamicDimensionConfig.AsteroidConfig tAConf, int eX, int eY, int eZ, Enums.TargetBlockPosition pBlockPosition) { - boolean tFlag = true; // Handler to generate special BlockTypes randomly if activated if (tAConf.SpecialBlockChance > 0) { if (pRandom.nextInt(100) < tAConf.SpecialBlockChance) { @@ -421,12 +407,13 @@ private boolean doGenerateSpecialBlocks(ModDimensionDef pDimensionDef, Random pR if (tIsAllowed) { pWorld.setBlock(eX, eY, eZ, bmc.getBlock(), bmc.getMeta(), 2); - tFlag = false; + return true; } } } } - return tFlag; + + return false; } /** @@ -436,78 +423,51 @@ private boolean doGenerateSpecialBlocks(ModDimensionDef pDimensionDef, Random pR * @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; + private boolean generateSmallOreBlock(ModDimensionDef pDimDef, Random pRandom, World pWorld, + DynamicDimensionConfig.AsteroidConfig pAConf, int pX, int pY, int pZ, AsteroidBlockComb asteroidStone) { // 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 (int i = 0; (i < 256); i++) { + int tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); for (GTWorldgen tWorldGen : GalacticGreg.smallOreWorldgenList) { - if (!(tWorldGen instanceof WorldgenOreSmallSpace)) { - continue; - } + if (!(tWorldGen instanceof WorldgenOreSmallSpace oreSmallSpace)) continue; + // That is enabled for *this* dim... - if (!((WorldgenOreSmallSpace) tWorldGen).isEnabledForDim(pDimDef)) continue; + if (!oreSmallSpace.isEnabledForDim(pDimDef)) continue; // And in the correct y-level, of ObeyLimits is true... - if (pAConf.ObeyHeightLimits && !((WorldgenOreSmallSpace) tWorldGen).isAllowedForHeight(pY)) + if (pAConf.ObeyHeightLimits && oreSmallSpace.isAllowedForHeight(pY)) continue; // Care about weight - tRandomWeight -= ((WorldgenOreSmallSpace) tWorldGen).mAmount; + tRandomWeight -= oreSmallSpace.mAmount; if (tRandomWeight <= 0) { - // And return found ore meta - tFoundOreMeta = ((WorldgenOreSmallSpace) tWorldGen).mMeta; - continueSearch = false; + OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, asteroidStone.getStone(), oreSmallSpace.mMaterial, true); + return true; } } } - 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; - } } } - 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, + private void generateOreVeins(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())) { + if (WorldgenOreLayerSpace.sWeight > 0 && !GalacticGreg.oreVeinWorldgenList.isEmpty()) { + + outer: for (int i = 0; i < 256; i++) { + int tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); - 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; @@ -523,7 +483,7 @@ private void Generate_OreVeins(ModDimensionDef pDimensionDef, Random pRandom, Wo pZ, pChunkGenerator, pChunkProvider)) { - temp = false; + break outer; } } catch (Throwable e) { e.printStackTrace(GTLog.err); diff --git a/src/main/java/galacticgreg/WorldgenOreLayerSpace.java b/src/main/java/galacticgreg/WorldgenOreLayerSpace.java index 10591cb32d1..595bfe3a3ab 100644 --- a/src/main/java/galacticgreg/WorldgenOreLayerSpace.java +++ b/src/main/java/galacticgreg/WorldgenOreLayerSpace.java @@ -17,9 +17,11 @@ import galacticgreg.api.ModDimensionDef; import galacticgreg.auxiliary.GTOreGroup; import galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.interfaces.IMaterial; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; import gregtech.common.OreMixBuilder; +import gregtech.common.ores.OreManager; public class WorldgenOreLayerSpace extends GTWorldgen { @@ -29,10 +31,10 @@ public class WorldgenOreLayerSpace extends GTWorldgen { 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 IMaterial mPrimary; + public final IMaterial mSecondary; + public final IMaterial mBetween; + public final IMaterial mSporadic; private long mProfilingStart; private long mProfilingEnd; @@ -46,10 +48,10 @@ public WorldgenOreLayerSpace(OreMixBuilder mix) { 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; + mPrimary = mix.primary; + mSecondary = mix.secondary; + mBetween = mix.between; + mSporadic = mix.sporadic; allowedDims = new HashMap<>(); @@ -62,7 +64,7 @@ public WorldgenOreLayerSpace(OreMixBuilder mix) { "Found 2 Dimensions with the same Identifier: %s Dimension will not generate Ores", tDimIdentifier); else { - boolean tFlag = mix.dimsEnabled.getOrDefault(mdd.getDimensionName(), false); + boolean tFlag = mix.dimsEnabled.contains(mdd.getDimensionName()); allowedDims.put(tDimIdentifier, tFlag); } } @@ -115,10 +117,10 @@ private static List getOreMixIDsForDim(ModDimensionDef pDimensionDef) { * @return */ public static GTOreGroup getRandomOreGroup(ModDimensionDef pDimensionDef, Random pRandom, boolean pIgnoreWeight) { - short primaryMeta = 0; - short secondaryMeta = 0; - short betweenMeta = 0; - short sporadicMeta = 0; + IMaterial primary = null; + IMaterial secondary = null; + IMaterial between = null; + IMaterial sporadic = null; if (pIgnoreWeight) { List tEnabledVeins = getOreMixIDsForDim(pDimensionDef); @@ -126,20 +128,23 @@ public static GTOreGroup getRandomOreGroup(ModDimensionDef pDimensionDef, Random String tVeinName = tEnabledVeins.get(tRnd); GTWorldgen tGen = null; - for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) - if (tWorldGen instanceof WorldgenOreLayerSpace && tWorldGen.mWorldGenName.equals(tVeinName)) + + for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) { + if (tWorldGen instanceof WorldgenOreLayerSpace && tWorldGen.mWorldGenName.equals(tVeinName)) { tGen = tWorldGen; + break; + } + } 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; + primary = ((WorldgenOreLayerSpace) tGen).mPrimary; + secondary = ((WorldgenOreLayerSpace) tGen).mSecondary; + between = ((WorldgenOreLayerSpace) tGen).mBetween; + sporadic = ((WorldgenOreLayerSpace) tGen).mSporadic; } } else { - if ((WorldgenOreLayerSpace.sWeight > 0) && (!GalacticGreg.oreVeinWorldgenList.isEmpty())) { + if (WorldgenOreLayerSpace.sWeight > 0 && !GalacticGreg.oreVeinWorldgenList.isEmpty()) { GalacticGreg.Logger.trace("About to select oremix"); boolean temp = true; int tRandomWeight; @@ -153,10 +158,10 @@ public static GTOreGroup getRandomOreGroup(ModDimensionDef pDimensionDef, Random 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; + primary = ((WorldgenOreLayerSpace) tWorldGen).mPrimary; + secondary = ((WorldgenOreLayerSpace) tWorldGen).mSecondary; + between = ((WorldgenOreLayerSpace) tWorldGen).mBetween; + sporadic = ((WorldgenOreLayerSpace) tWorldGen).mSporadic; temp = false; break; @@ -169,9 +174,12 @@ public static GTOreGroup getRandomOreGroup(ModDimensionDef pDimensionDef, Random } } } - if (primaryMeta != 0 || secondaryMeta != 0 || betweenMeta != 0 || sporadicMeta != 0) - return new GTOreGroup(primaryMeta, secondaryMeta, betweenMeta, sporadicMeta); - else return null; + + if (primary != null || secondary != null || between != null || sporadic != null) { + return new GTOreGroup(primary, secondary, between, sporadic); + } else { + return null; + } } @Override @@ -201,7 +209,7 @@ public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int 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) { + if (this.mSecondary != null) { for (int i = tMinY - 1; i < tMinY + 3; i++) { int placeX = Math.max( 1, @@ -212,11 +220,11 @@ public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int 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); + OreManager.setOreForWorldGen(pWorld, tX, i, tZ, null, mSecondary, false); } } } - if (this.mBetweenMeta > 0) { + if (this.mBetween != null) { for (int i = tMinY + 2; i < tMinY + 6; i++) { int placeX = Math.max( 1, @@ -228,12 +236,12 @@ public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int / 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); + OreManager.setOreForWorldGen(pWorld, tX, i, tZ, null, mBetween, false); } } } - if (this.mPrimaryMeta > 0) { + if (this.mPrimary != null) { for (int i = tMinY + 4; i < tMinY + 8; i++) { int placeX = Math.max( 1, @@ -244,11 +252,11 @@ public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int 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); + OreManager.setOreForWorldGen(pWorld, tX, i, tZ, null, mPrimary, false); } } } - if (this.mSporadicMeta > 0) { + if (this.mSporadic != null) { for (int i = tMinY - 1; i < tMinY + 8; i++) { int placeX = Math.max( 1, @@ -260,7 +268,7 @@ public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int / 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); + OreManager.setOreForWorldGen(pWorld, tX, i, tZ, null, mSporadic, false); } } } @@ -273,23 +281,27 @@ public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int 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); + if (mPrimary != null) { + OreManager.setOreForWorldGen(pWorld, tX, tY, tZ, null, mPrimary, true); + } 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); + if (mSecondary != null) { + OreManager.setOreForWorldGen(pWorld, tX, tY, tZ, null, mSecondary, true); + } 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); + if (mBetween != null) { + OreManager.setOreForWorldGen(pWorld, tX, tY, tZ, null, mBetween, true); + } 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 (mSporadic != null) { + OreManager.setOreForWorldGen(pWorld, tX, tY, tZ, null, mSporadic, true); + } } } diff --git a/src/main/java/galacticgreg/WorldgenOreSmallSpace.java b/src/main/java/galacticgreg/WorldgenOreSmallSpace.java index 32737b69d3a..a095b303ce3 100644 --- a/src/main/java/galacticgreg/WorldgenOreSmallSpace.java +++ b/src/main/java/galacticgreg/WorldgenOreSmallSpace.java @@ -10,15 +10,17 @@ import galacticgreg.api.ModContainer; import galacticgreg.api.ModDimensionDef; import galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.interfaces.IMaterial; import gregtech.api.world.GTWorldgen; import gregtech.common.SmallOreBuilder; +import gregtech.common.ores.OreManager; public class WorldgenOreSmallSpace extends GTWorldgen { public final short mMinY; public final short mMaxY; public final short mAmount; - public final short mMeta; + public final IMaterial mMaterial; private long mProfilingStart; private long mProfilingEnd; @@ -30,7 +32,7 @@ public WorldgenOreSmallSpace(SmallOreBuilder ore) { 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; + mMaterial = ore.ore; allowedDims = new HashSet<>(); for (ModContainer mc : GalacticGregRegistry.getModContainers()) { @@ -78,16 +80,17 @@ public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); // --------------------------- - if (this.mMeta > 0) { + if (mMaterial != null) { int i = 0; for (int j = Math.max(1, this.mAmount / 2 + pRandom.nextInt(this.mAmount) / 2); i < j; i++) { - TileEntitySpaceOres.setOuterSpaceOreBlock( - tMDD, + OreManager.setOreForWorldGen( pWorld, pChunkX + pRandom.nextInt(16), this.mMinY + pRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), pChunkZ + pRandom.nextInt(16), - this.mMeta + 16000); + null, + mMaterial, + true); } } // --------------------------- diff --git a/src/main/java/galacticgreg/api/AsteroidBlockComb.java b/src/main/java/galacticgreg/api/AsteroidBlockComb.java index d9961cf8ec2..ba85da820e5 100644 --- a/src/main/java/galacticgreg/api/AsteroidBlockComb.java +++ b/src/main/java/galacticgreg/api/AsteroidBlockComb.java @@ -1,5 +1,6 @@ package galacticgreg.api; +import gregtech.api.interfaces.IStoneType; import net.minecraft.block.Block; /** @@ -8,7 +9,7 @@ */ public class AsteroidBlockComb extends BlockMetaComb { - private final GTOreTypes _mGTOreMaterial; + private final IStoneType stoneType; /** * Create an advanced definition which uses the GregTech-OreType values for ores, and your own definition of Block @@ -17,9 +18,9 @@ public class AsteroidBlockComb extends BlockMetaComb { * @param pOreType The GregTech oreType * @param pBlock Your block */ - public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock) { + public AsteroidBlockComb(IStoneType stoneType, Block pBlock) { super(pBlock, 0); - _mGTOreMaterial = pOreType; + this.stoneType = stoneType; } /** @@ -30,9 +31,9 @@ public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock) { * @param pBlock Your block * @param pMeta The metavalue for your block (If required) */ - public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock, int pMeta) { + public AsteroidBlockComb(IStoneType stoneType, Block pBlock, int pMeta) { super(pBlock, pMeta); - _mGTOreMaterial = pOreType; + this.stoneType = stoneType; } /** @@ -40,9 +41,9 @@ public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock, int pMeta) { * * @param pOreType The GregTech oreType */ - public AsteroidBlockComb(GTOreTypes pOreType) { - super(pOreType.getBlock(), pOreType.getMeta()); - _mGTOreMaterial = pOreType; + public AsteroidBlockComb(IStoneType stoneType) { + super(stoneType.getStone().left(), stoneType.getStone().rightInt()); + this.stoneType = stoneType; } /** @@ -50,8 +51,8 @@ public AsteroidBlockComb(GTOreTypes pOreType) { * * @return The GT Material for the oregen */ - public GTOreTypes getOreMaterial() { - return _mGTOreMaterial; + public IStoneType getStone() { + return stoneType; } @Override @@ -68,7 +69,7 @@ public boolean equals(Object other) { if (!(otherObj.getMeta() == this.getMeta())) tFlag = false; - if (!(otherObj.getOreMaterial() == this.getOreMaterial())) tFlag = false; + if (!(otherObj.getStone() == this.getStone())) tFlag = false; } else tFlag = false; return tFlag; diff --git a/src/main/java/galacticgreg/api/ModDimensionDef.java b/src/main/java/galacticgreg/api/ModDimensionDef.java index fbfbd674f3d..382f8a951d1 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.Random; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IStoneType; import net.minecraft.block.Block; import net.minecraft.world.chunk.IChunkProvider; @@ -415,8 +417,8 @@ public SpecialBlockComb getRandomSpecialAsteroidBlock() { * * @param pMaterial */ - public void addAsteroidMaterial(GTOreTypes pMaterial) { - addAsteroidMaterial(new AsteroidBlockComb(pMaterial)); + public void addAsteroidMaterial(IStoneType stoneType) { + addAsteroidMaterial(new AsteroidBlockComb(stoneType)); } /** diff --git a/src/main/java/galacticgreg/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index 6684777bba1..162817d6cf3 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -7,7 +7,11 @@ public enum DimensionDef { - EndAsteroids(new ModDimensionDef(DimNames.ENDASTEROIDS, ChunkProviderEnd.class, Enums.DimensionType.Asteroid)), + EndAsteroids(new ModDimensionDef( + DimNames.ENDASTEROIDS, + ChunkProviderEnd.class, + Enums.DimensionType.Asteroid)), + Moon(new ModDimensionDef( DimNames.MOON, "micdoodle8.mods.galacticraft.core.world.gen.ChunkProviderMoon", @@ -179,7 +183,13 @@ public enum DimensionDef { public static class DimNames { + public static final String OW = "Overworld"; + public static final String NETHER = "Nether"; + public static final String THE_END = "TheEnd"; public static final String ENDASTEROIDS = "EndAsteroids"; + 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"; diff --git a/src/main/java/galacticgreg/auxiliary/GTOreGroup.java b/src/main/java/galacticgreg/auxiliary/GTOreGroup.java index bf5fb39c077..d19480fdd82 100644 --- a/src/main/java/galacticgreg/auxiliary/GTOreGroup.java +++ b/src/main/java/galacticgreg/auxiliary/GTOreGroup.java @@ -1,19 +1,21 @@ package galacticgreg.auxiliary; +import gregtech.api.interfaces.IMaterial; + /** * 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 IMaterial Primary; + public IMaterial Secondary; + public IMaterial SporadicBetween; + public IMaterial SporadicAround; - public GTOreGroup(short pPrimaryMeta, short pSecondaryMeta, short pSporadicBetweenMeta, short pSporadicAroundMeta) { - PrimaryMeta = pPrimaryMeta; - SecondaryMeta = pSecondaryMeta; - SporadicBetweenMeta = pSporadicBetweenMeta; - SporadicAroundMeta = pSporadicAroundMeta; + public GTOreGroup(IMaterial pPrimary, IMaterial pSecondary, IMaterial pSporadicBetween, IMaterial pSporadicAround) { + Primary = pPrimary; + Secondary = pSecondary; + SporadicBetween = pSporadicBetween; + SporadicAround = pSporadicAround; } } diff --git a/src/main/java/gregtech/api/GregTechAPI.java b/src/main/java/gregtech/api/GregTechAPI.java index 827931faa43..70d1a0c2ce9 100644 --- a/src/main/java/gregtech/api/GregTechAPI.java +++ b/src/main/java/gregtech/api/GregTechAPI.java @@ -233,7 +233,7 @@ public class GregTechAPI { sBlockMetal9, sBlockGem1, sBlockGem2, sBlockGem3, sBlockReinforced; public static Block sBlockGranites, sBlockConcretes, sBlockStones; public static Block sBlockCasings1, sBlockCasings2, sBlockCasings3, sBlockCasings4, sBlockCasings5, sBlockCasings6, - sBlockCasings8, sBlockCasings9, sBlockCasings10, sBlockCasings11, sSolenoidCoilCasings, sBlockOres2; + sBlockCasings8, sBlockCasings9, sBlockCasings10, sBlockCasings11, sSolenoidCoilCasings; public static Block sBlockLongDistancePipes; public static Block sDroneRender; public static Block sBlockFrames; diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index 9417ea0aa36..81d8e754b7f 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -29,6 +29,7 @@ import gregtech.api.enums.TCAspects.TC_AspectStack; import gregtech.api.fluid.GTFluidFactory; import gregtech.api.interfaces.IColorModulationContainer; +import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IMaterialHandler; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.objects.MaterialStack; @@ -47,7 +48,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, IMaterial { public static final List mMaterialHandlers = new ArrayList<>(); private static final Map MATERIALS_MAP = new LinkedHashMap<>(); @@ -3053,6 +3054,21 @@ public String toString() { return this.mName; } + @Override + public String getLocalizedName() { + return mLocalizedName; + } + + @Override + public int getId() { + return mMetaItemSubID; + } + + @Override + public String getInternalName() { + return mName; + } + public String getDefaultLocalizedNameForItem(String aFormat) { try { return String.format( diff --git a/src/main/java/gregtech/api/enums/OreMixes.java b/src/main/java/gregtech/api/enums/OreMixes.java index f012937ecc9..5fd7db25916 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 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.NETHER; +import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; +import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; +import static galacticgreg.api.enums.DimensionDef.DimNames.EVERGLADES; + +import bartworks.system.material.WerkstoffLoader; import galacticgreg.WorldgenOreLayerSpace; 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 { @@ -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) @@ -998,7 +1008,444 @@ public enum OreMixes { .primary(Materials.TengamRaw) .secondary(Materials.TengamRaw) .inBetween(Materials.Electrotine) - .sporadic(Materials.Samarium)); + .sporadic(Materials.Samarium)), + + 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 diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index 73a502bf4e8..62e1f52aae1 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -12,6 +12,7 @@ import java.util.List; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; import com.google.common.collect.ImmutableList; @@ -25,7 +26,10 @@ import gregtech.api.objects.MaterialStack; import gregtech.api.util.GTLog; 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; @@ -1213,6 +1217,53 @@ public static String stripPrefix(String aOre) { return aOre; } + public static Pair detectPrefix(String oredictName) { + for (OrePrefixes prefix : values()) { + if (oredictName.startsWith(prefix.name())) { + return Pair.of( + prefix, + oredictName.substring( + prefix.name() + .length())); + } + } + + return null; + } + + private static final ThreadLocal>>> PREFIX_CACHE = ThreadLocal + .withInitial(Object2ObjectLinkedOpenHashMap::new); + + public static ImmutableList> detectPrefix(ItemStack stack) { + Object2ObjectLinkedOpenHashMap>> cache = PREFIX_CACHE.get(); + + ItemId itemId = ItemId.create(stack); + + var cacheResult = cache.getAndMoveToFirst(itemId); + + if (cacheResult != null) return cacheResult; + + ImmutableList.Builder> result = ImmutableList.builder(); + + for (int id : OreDictionary.getOreIDs(stack)) { + Pair p = detectPrefix(OreDictionary.getOreName(id)); + + if (p != null) { + result.add(p); + } + } + + ImmutableList> prefixes = result.build(); + + cache.putAndMoveToFirst(itemId, prefixes); + + while (cache.size() > 1024) { + cache.removeLast(); + } + + return prefixes; + } + public static String replacePrefix(String aOre, OrePrefixes aPrefix) { for (OrePrefixes tPrefix : values()) { if (aOre.startsWith(tPrefix.toString())) { diff --git a/src/main/java/gregtech/api/enums/StoneType.java b/src/main/java/gregtech/api/enums/StoneType.java index 535b863d000..cedc9e927af 100644 --- a/src/main/java/gregtech/api/enums/StoneType.java +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -1,99 +1,380 @@ package gregtech.api.enums; +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.List; +import java.util.Objects; + import com.google.common.collect.ImmutableList; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.IStoneType; import gregtech.api.interfaces.ITexture; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.util.GTUtility; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; public enum StoneType implements IStoneType { - Stone(OrePrefixes.ore, Materials.Stone) { - @Override - public boolean contains(Block block, int meta) { - return block == Blocks.stone; - } - }, - Netherrack(OrePrefixes.oreNetherrack, Materials.Netherrack) { - @Override - public boolean contains(Block block, int meta) { - return block == Blocks.netherrack; - } - }, - Endstone(OrePrefixes.oreEndstone, Materials.Endstone) { - @Override - public boolean contains(Block block, int meta) { - return block == Blocks.end_stone; - } - }, - BlackGranite(OrePrefixes.oreBlackgranite, Materials.GraniteBlack) { - @Override - public boolean contains(Block block, int meta) { - return block == GregTechAPI.sBlockGranites && meta < 8; - } - }, - RedGranite(OrePrefixes.oreRedgranite, Materials.GraniteRed) { - @Override - public boolean contains(Block block, int meta) { - return block == GregTechAPI.sBlockGranites && meta >= 8; - } - }, - Marble(OrePrefixes.oreMarble, Materials.Marble) { - @Override - public boolean contains(Block block, int meta) { - return block == GregTechAPI.sBlockStones && meta < 8; - } - }, - Basalt(OrePrefixes.oreBasalt, Materials.Basalt) { - @Override - public boolean contains(Block block, int meta) { - return block == GregTechAPI.sBlockStones && meta >= 8; - } - }; + 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.sBlockGranites, 1) + .setMainStone(GregTechAPI.sBlockGranites, 0) + .setDust(Materials.Marble)), + Basalt(new StoneBuilder() + .setPrefix(OrePrefixes.oreBasalt) + .setCobble(GregTechAPI.sBlockGranites, 9) + .setMainStone(GregTechAPI.sBlockGranites, 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", 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", 0) + .setDust(Materials.Obsidian)), + Anubis(new StoneBuilder() + .setCobble(GalacticraftAmunRa, "tile.baseBlockRock", 0) + .setMainStone(GalacticraftAmunRa, "tile.baseBlockRock", 1) + .setDust(Materials.Basalt)), + ; public static final ImmutableList STONE_TYPES = ImmutableList.copyOf(values()); + public static final ImmutableList VISUAL_STONE_TYPES = ImmutableList.copyOf(Arrays.stream(values()).filter(s -> s.builder.enabled && !s.isExtraneous()).toArray(StoneType[]::new)); - public final OrePrefixes prefix; - public final Materials material; + private final StoneBuilder builder; - private StoneType(OrePrefixes prefix, Materials material) { - this.prefix = prefix; - this.material = material; + private StoneType(StoneBuilder builder) { + this.builder = builder; } @Override - public Materials getMaterial() { - return material; + public ItemStack getDust(boolean pure, int amount) { + return GTUtility.copyAmount(amount, pure ? builder.pureDust : builder.impureDust); } @Override public OrePrefixes getPrefix() { - return prefix; + return builder.oreBlockPrefix; } @Override - public ITexture getTexture() { + public ObjectIntPair getCobblestone() { + return ObjectIntPair.of(builder.cobble.block, builder.cobble.meta); + } + + @Override + public ObjectIntPair getStone() { + return ObjectIntPair.of(builder.mainStone.block, builder.mainStone.meta); + } + + @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.block.getIcon(side, builder.mainStone.meta); + }; + } + + @Override + public boolean isRich() { return switch (this) { - case Stone -> TextureFactory.of(Blocks.stone); - case Netherrack -> TextureFactory.of(Blocks.netherrack); - case Endstone -> TextureFactory.of(Blocks.end_stone); - case BlackGranite -> TextureFactory.builder().addIcon(BlockIcons.GRANITE_BLACK_STONE).stdOrient().build(); - case RedGranite -> TextureFactory.builder().addIcon(BlockIcons.GRANITE_RED_STONE).stdOrient().build(); - case Marble -> TextureFactory.builder().addIcon(BlockIcons.MARBLE_STONE).stdOrient().build(); - case Basalt -> TextureFactory.builder().addIcon(BlockIcons.BASALT_STONE).stdOrient().build(); + 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() { + return this.ordinal() > Endstone.ordinal(); + } + + @Override + public boolean isEnabled() { + return builder.enabled; + } + + @Override + public boolean contains(Block block, int meta) { + if (block == builder.mainStone.block && meta == builder.mainStone.meta) return true; + + for (BlockMeta other : builder.otherStones) { + if (block == other.block && meta == other.meta) return true; + } + + return false; + } + + public static StoneType findStoneType(World world, int x, int y, int z) { + return findStoneType(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + } + public static StoneType findStoneType(Block block, int meta) { for (StoneType stoneType : STONE_TYPES) { - if (stoneType.contains(block, meta)) { + if (stoneType.builder.enabled && stoneType.contains(block, meta)) { return stoneType; } } return null; } + + private static class BlockMeta { + public Block block; + public int meta; + + public BlockMeta(Block block, int meta) { + this.block = block; + this.meta = meta; + } + } + + private static class StoneBuilder { + public boolean enabled = true; + public BlockMeta cobble, mainStone; + public List otherStones = new ArrayList<>(); + public OrePrefixes oreBlockPrefix = OrePrefixes.ore; + public ItemStack pureDust = GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1); + public ItemStack impureDust = GTOreDictUnificator.get(OrePrefixes.dustImpure, Materials.Stone, 1); + + 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() + "blocks", extra); + } + + return builder; + } + + public StoneBuilder setCobble(Block block, int meta) { + Objects.requireNonNull(block); + + cobble = new BlockMeta(block, meta); + + return this; + } + + public StoneBuilder setCobble(Mods owner, String blockName, int meta) { + enabled &= owner.isModLoaded(); + + Block block = GameRegistry.findBlock(owner.ID, blockName); + + if (block != null) { + cobble = new BlockMeta(block, meta); + } else { + cobble = null; + } + + return this; + } + + public StoneBuilder setStoneNoCobble(Mods owner, String blockName, int meta) { + enabled &= owner.isModLoaded(); + + Block block = GameRegistry.findBlock(owner.ID, blockName); + + if (block != null) { + cobble = mainStone = new BlockMeta(block, meta); + } else { + cobble = mainStone = null; + } + + return this; + } + + public StoneBuilder setStoneNoCobble(Block block, int meta) { + Objects.requireNonNull(block); + + cobble = mainStone = new BlockMeta(block, meta); + + return this; + } + + public StoneBuilder setMainStone(Mods owner, String blockName, int meta) { + enabled &= owner.isModLoaded(); + + Block block = GameRegistry.findBlock(owner.ID, blockName); + + if (block != null) { + mainStone = new BlockMeta(block, meta); + } else { + mainStone = null; + } + + return this; + } + + public StoneBuilder setMainStone(Block block, int meta) { + Objects.requireNonNull(block); + + mainStone = new BlockMeta(block, meta); + + return this; + } + + public StoneBuilder addOtherStone(Mods owner, String blockName, int meta) { + Block block = GameRegistry.findBlock(owner.ID, blockName); + + if (block != null) { + otherStones.add(new BlockMeta(block, meta)); + } + + return this; + } + + public StoneBuilder setCoremodDust(String name) { + if (NewHorizonsCoreMod.isModLoaded()) { + Item dust = GameRegistry.findItem(NewHorizonsCoreMod.ID, "item." + name + "StoneDust"); + pureDust = impureDust = new ItemStack(Objects.requireNonNull(dust, "Could not find " + "item." + name + "StoneDust"), 1); + } + + return this; + } + + public StoneBuilder setDust(Materials mat) { + pureDust = mat.getDust(1); + impureDust = GTOreDictUnificator.get(OrePrefixes.dustImpure, mat, 1); + + return this; + } + + public StoneBuilder setPrefix(OrePrefixes prefix) { + this.oreBlockPrefix = prefix; + + return this; + } + } } diff --git a/src/main/java/gregtech/api/interfaces/IBlockOre.java b/src/main/java/gregtech/api/interfaces/IBlockOre.java index 41412491bdb..3b0ed75cfab 100644 --- a/src/main/java/gregtech/api/interfaces/IBlockOre.java +++ b/src/main/java/gregtech/api/interfaces/IBlockOre.java @@ -8,5 +8,9 @@ public interface IBlockOre { /** Works like the vanilla getDrops, except it doesn't check to make sure a player is breaking the block. */ - public List getDropsForMachine(World world, int x, int y, int z, int metadata, boolean silktouch, int fortune); + public List getDropsForMachine(World world, int x, int y, int z, boolean silktouch, int fortune); + + public boolean isSmall(World world, int x, int y, int z); + public boolean isNatural(World world, int x, int y, int z); + public String getOreUnlocalizedName(World world, int x, int y, int z); } diff --git a/src/main/java/gregtech/api/interfaces/IDimension.java b/src/main/java/gregtech/api/interfaces/IDimension.java new file mode 100644 index 00000000000..0e0857778af --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IDimension.java @@ -0,0 +1,10 @@ +package gregtech.api.interfaces; + +import net.minecraft.world.World; + +public interface IDimension { + + public String getWorldName(); + + public boolean matches(World world); +} diff --git a/src/main/java/gregtech/api/interfaces/IMaterial.java b/src/main/java/gregtech/api/interfaces/IMaterial.java new file mode 100644 index 00000000000..1f72456f078 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IMaterial.java @@ -0,0 +1,13 @@ +package gregtech.api.interfaces; + +public interface IMaterial { + + public String getLocalizedName(); + + public int getId(); + + public String getInternalName(); + + public short[] getRGBA(); + +} diff --git a/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java b/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java index a0a362c4e51..328da78bf44 100644 --- a/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java +++ b/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java @@ -50,7 +50,7 @@ public interface IRedstoneCircuitBlock { /** * returns whatever Meta-Value is adjacent to the Redstone Circuit Block */ - byte getMetaIDAtSide(ForgeDirection side); + int getMetaIDAtSide(ForgeDirection side); /** * returns whatever TileEntity is adjacent to the Redstone Circuit Block diff --git a/src/main/java/gregtech/api/interfaces/IStoneType.java b/src/main/java/gregtech/api/interfaces/IStoneType.java index 29d1fa1915b..5ae4c7fbfd7 100644 --- a/src/main/java/gregtech/api/interfaces/IStoneType.java +++ b/src/main/java/gregtech/api/interfaces/IStoneType.java @@ -1,8 +1,10 @@ package gregtech.api.interfaces; -import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; public interface IStoneType { @@ -11,7 +13,16 @@ public interface IStoneType { public OrePrefixes getPrefix(); - public Materials getMaterial(); + public ItemStack getDust(boolean pure, int amount); - public ITexture getTexture(); + public ObjectIntPair getCobblestone(); + public ObjectIntPair getStone(); + + public ITexture getTexture(int side); + public IIcon getIcon(int side); + + public boolean isRich(); + public boolean isDimensionSpecific(); + public boolean isExtraneous(); + public boolean isEnabled(); } diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java b/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java index b62c3e92cf9..429cfe39536 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java @@ -79,13 +79,13 @@ default ChunkCoordinates getCoords() { Block getBlockAtSideAndDistance(ForgeDirection side, int aDistance); - byte getMetaID(int aX, int aY, int aZ); + int getMetaID(int aX, int aY, int aZ); - byte getMetaIDOffset(int aX, int aY, int aZ); + int getMetaIDOffset(int aX, int aY, int aZ); - byte getMetaIDAtSide(ForgeDirection side); + int getMetaIDAtSide(ForgeDirection side); - byte getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance); + int getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance); byte getLightLevel(int aX, int aY, int aZ); diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index f2b5278e49d..5c0cc59f2c9 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -221,17 +221,17 @@ public final Block getBlockAtSideAndDistance(ForgeDirection side, int distance) } @Override - public final byte getMetaIDOffset(int x, int y, int z) { + public final int getMetaIDOffset(int x, int y, int z) { return getMetaID(xCoord + x, yCoord + y, zCoord + z); } @Override - public final byte getMetaIDAtSide(ForgeDirection side) { + public final int getMetaIDAtSide(ForgeDirection side) { return getMetaIDAtSideAndDistance(side, 1); } @Override - public final byte getMetaIDAtSideAndDistance(ForgeDirection side, int distance) { + public final int getMetaIDAtSideAndDistance(ForgeDirection side, int distance) { return getMetaID(getOffsetX(side, distance), getOffsetY(side, distance), getOffsetZ(side, distance)); } @@ -404,7 +404,7 @@ public Block getBlock(ChunkCoordinates aCoords) { } @Override - public final byte getMetaID(int x, int y, int z) { + public final int getMetaID(int x, int y, int z) { if (ignoreUnloadedChunks && crossedChunkBorder(x, z) && !worldObj.blockExists(x, y, z)) return 0; return (byte) worldObj.getBlockMetadata(x, y, z); } diff --git a/src/main/java/gregtech/api/net/GTPacketTypes.java b/src/main/java/gregtech/api/net/GTPacketTypes.java index 915d03b88ee..18beef27fae 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/util/GTBaseCrop.java b/src/main/java/gregtech/api/util/GTBaseCrop.java index 0cc0e800367..4817b3f8043 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; @@ -242,24 +239,14 @@ public boolean isBlockBelow(ICropTile aCrop) { return false; } 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; - } + Block tBlock = aCrop.getWorld().getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); + 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 667ab6c2b0e..089f214e1c1 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -117,7 +117,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,8 +168,8 @@ import gregtech.api.recipe.RecipeMaps; import gregtech.api.threads.RunnableSound; import gregtech.api.util.extensions.ArrayExt; -import gregtech.common.blocks.BlockOres2; import gregtech.common.blocks.BlockOresAbstract; +import gregtech.common.ores.OreManager; import gregtech.common.pollution.Pollution; import gtPlusPlus.core.block.base.BlockBaseOre; import ic2.api.recipe.IRecipeInput; @@ -2340,7 +2339,7 @@ public static boolean arrayContainsNonNull(T... aArray) { return false; } - public static int indexOf(T[] array, T value) { + public static int indexOf(A[] array, B value) { for (int i = 0; i < array.length; i++) { if (array[i] == value) return i; } @@ -2348,10 +2347,18 @@ public static int indexOf(T[] array, T value) { return -1; } - public static boolean contains(T[] array, T value) { + 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. */ @@ -4343,11 +4350,8 @@ public static boolean isPartOfOrePrefix(ItemStack aStack, OrePrefixes aPrefix) { && GTOreDictUnificator.getAssociation(aStack).mPrefix.equals(aPrefix); } - public static boolean isOre(Block block, int meta) { - if (block instanceof BlockOres2) return true; - if (block instanceof BWMetaGeneratedOres) return true; - if (block instanceof BWMetaGeneratedSmallOres) return true; - if (block instanceof BlockBaseOre) return true; + public static boolean isMinable(Block block, int meta) { + if (OreManager.isOre(block, meta)) return true; return isOre(new ItemStack(block, 1, meta)); } @@ -4358,8 +4362,7 @@ public static boolean isOre(ItemStack aStack) { return sOreTable.get(tItem); } for (int id : OreDictionary.getOreIDs(aStack)) { - if (OreDictionary.getOreName(id) - .startsWith("ore")) { + if (OreDictionary.getOreName(id).startsWith("ore")) { sOreTable.put(tItem, true); return true; } @@ -4529,6 +4532,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 long min(long first, long... rest) { for (int i = 0; i < rest.length; i++) { long l = rest[i]; diff --git a/src/main/java/gregtech/api/world/GTWorldgen.java b/src/main/java/gregtech/api/world/GTWorldgen.java index 07c76e0e3a5..df60150e609 100644 --- a/src/main/java/gregtech/api/world/GTWorldgen.java +++ b/src/main/java/gregtech/api/world/GTWorldgen.java @@ -106,9 +106,7 @@ public boolean isGenerationAllowed(World aWorld, String[] blackListedProviders, if (tAllowed == null) { if (blackListedProviders != null) { for (String dimClass : blackListedProviders) { - if (dimClass.equals( - aWorld.provider.getClass() - .getName())) { + if (dimClass.equals(aWorld.provider.getClass().getName())) { return false; } } diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index 17cba343690..48ee0d1f881 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -29,12 +29,13 @@ import gregtech.api.GregTechAPI; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; +import gregtech.api.enums.StoneType; import gregtech.api.net.GTPacketSendOregenPattern; 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.ores.OreManager; public class GTWorldgenerator implements IWorldGenerator { @@ -278,7 +279,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. @@ -304,7 +305,6 @@ public void worldGenFindVein(int oreseedX, int oreseedZ) { // 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(); @@ -352,7 +352,7 @@ public void worldGenFindVein(int oreseedX, int oreseedZ) { // a unique height each pass through here. int placementResult = tWorldGen.executeWorldgenChunkified( this.mWorld, - new XSTR(oreveinSeed ^ (tWorldGen.mPrimaryMeta)), + new XSTR(oreveinSeed ^ (tWorldGen.mPrimary.hashCode())), this.mBiome, this.mDimensionType, this.mX * 16, @@ -471,7 +471,7 @@ public void worldGenFindVein(int oreseedX, int oreseedZ) { 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 + oreveinRNG.setSeed(oreveinSeed ^ (tWorldGen.mPrimary.hashCode())); // Reset RNG to only be based on oreseed X/Z // and type of vein int placementResult = tWorldGen.executeWorldgenChunkified( this.mWorld, @@ -559,10 +559,7 @@ public void run() { // 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); @@ -589,26 +586,19 @@ public void run() { } 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; + WorldgenGTOreLayer selectedOreLayer = null; + + if (WorldgenGTOreLayer.sWeight > 0 && !WorldgenGTOreLayer.sList.isEmpty()) { int tRandomWeight; - for (int i = 0; (i < oreveinAttempts) && (temp); i++) { + outer: for (int i = 0; i < oreveinAttempts; 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; + if (tWorldGen.mAllowedDimensions.contains("EndAsteroid")) { + selectedOreLayer = tWorldGen; + break outer; } } catch (Throwable e) { e.printStackTrace(GTLog.err); @@ -617,14 +607,16 @@ private void generateAsteroid(World world, Random random, int chunkX, int chunkZ } } } - // if(GT_Values.D1)GT_FML_LOGGER.info("do asteroid gen: "+this.mX+" "+this.mZ); + + // should never happen, but let's be safe + if (selectedOreLayer == null) return; + 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))) { + if (world.isAirBlock(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; @@ -634,43 +626,50 @@ private void generateAsteroid(World world, Random random, int chunkX, int chunkZ double yFactor = tY + random.nextInt(3) - 2; for (int i = 0; i <= mSize; i++) { + double randomDistance = random.nextDouble() * mSize / 16.0D; + + double halfLength = ((MathHelper.sin(i * (float) Math.PI / mSize) + 1.0F) * randomDistance + 1.0D) / 2.0; + double halfHeight = ((MathHelper.sin(i * (float) Math.PI / mSize) + 1.0F) * randomDistance + 1.0D) / 2.0; + 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); + + int tMinX = MathHelper.floor_double(xCenter - halfLength); + int tMinY = MathHelper.floor_double(yCenter - halfHeight); + int tMinZ = MathHelper.floor_double(zCenter - halfLength); + int tMaxX = MathHelper.floor_double(xCenter + halfLength); + int tMaxY = MathHelper.floor_double(yCenter + halfHeight); + int tMaxZ = MathHelper.floor_double(zCenter + halfLength); for (int eX = tMinX; eX <= tMaxX; eX++) { - double xChance = (eX + 0.5D - xCenter) / (halfLength / 2.0D); + + double xChance = (eX + 0.5D - xCenter) / halfLength; if (xChance * xChance < 1.0D) { for (int eY = tMinY; eY <= tMaxY; eY++) { - double yChance = (eY + 0.5D - yCenter) / (halfHeight / 2.0D); + + double yChance = (eY + 0.5D - yCenter) / halfHeight; if (xChance * xChance + yChance * yChance < 1.0D) { for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) { - double zChance = (eZ + 0.5D - zCenter) / (halfLength / 2.0D); + + double zChance = (eZ + 0.5D - zCenter) / halfLength; if (xChance * xChance + yChance * yChance + zChance * zChance >= 1.0D) { continue; } - if (!world.getBlock(tX, tY, tZ) - .isAir(world, tX, tY, tZ)) { + + if (!world.isAirBlock(tX, tY, tZ)) { continue; } + int ranOre = random.nextInt(50); if (ranOre < 3) { - TileEntityOres.setOreBlock(world, eX, eY, eZ, primaryMeta, false); + OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mPrimary, false); } else if (ranOre < 6) { - TileEntityOres.setOreBlock(world, eX, eY, eZ, secondaryMeta, false); + OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mSecondary, false); } else if (ranOre < 8) { - TileEntityOres.setOreBlock(world, eX, eY, eZ, betweenMeta, false); + OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mBetween, false); } else if (ranOre < 10) { - TileEntityOres.setOreBlock(world, eX, eY, eZ, sporadicMeta, false); + OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mSporadic, false); } else { world.setBlock(eX, eY, eZ, Blocks.end_stone, 0, 0); } diff --git a/src/main/java/gregtech/common/OreMixBuilder.java b/src/main/java/gregtech/common/OreMixBuilder.java index 86453ca0a8f..221cc52156e 100644 --- a/src/main/java/gregtech/common/OreMixBuilder.java +++ b/src/main/java/gregtech/common/OreMixBuilder.java @@ -1,23 +1,21 @@ 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.interfaces.IMaterial; 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 IMaterial primary, secondary, between, sporadic, representative; public String localizedName; public OreMixBuilder name(String name) { @@ -32,14 +30,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,26 +63,26 @@ public OreMixBuilder size(int size) { return this; } - public OreMixBuilder primary(Materials primary) { + public OreMixBuilder primary(IMaterial 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(IMaterial secondary) { this.secondary = secondary; return this; } - public OreMixBuilder inBetween(Materials between) { + public OreMixBuilder inBetween(IMaterial between) { this.between = between; return this; } - public OreMixBuilder sporadic(Materials sporadic) { + public OreMixBuilder sporadic(IMaterial sporadic) { this.sporadic = sporadic; return this; } diff --git a/src/main/java/gregtech/common/SmallOreBuilder.java b/src/main/java/gregtech/common/SmallOreBuilder.java index d36dd9aa1d4..2797a01bc75 100644 --- a/src/main/java/gregtech/common/SmallOreBuilder.java +++ b/src/main/java/gregtech/common/SmallOreBuilder.java @@ -4,7 +4,7 @@ import java.util.Set; import galacticgreg.api.enums.DimensionDef; -import gregtech.api.enums.Materials; +import gregtech.api.interfaces.IMaterial; public class SmallOreBuilder { @@ -17,7 +17,7 @@ public class SmallOreBuilder { /** {full dimension name: enabled} */ public Set dimsEnabled = new HashSet<>(); public int minY, maxY, amount; - public Materials ore; + public IMaterial ore; public SmallOreBuilder name(String name) { this.smallOreName = name; @@ -54,7 +54,7 @@ public SmallOreBuilder amount(int amount) { return this; } - public SmallOreBuilder ore(Materials ore) { + public SmallOreBuilder ore(IMaterial ore) { this.ore = ore; return this; } diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 0e7c69b867a..15be6acb1fb 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -5,23 +5,17 @@ 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.interfaces.IMaterial; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.TileEntityOres; +import gregtech.common.ores.OreManager; public class WorldgenGTOreLayer extends GTWorldgen { @@ -32,16 +26,13 @@ public class WorldgenGTOreLayer extends GTWorldgen { 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 IMaterial mPrimary; + public final IMaterial mSecondary; + public final IMaterial mBetween; + public final IMaterial 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; + /** {full dim name} */ + public final Set mAllowedDimensions; public static final int WRONG_BIOME = 0; public static final int WRONG_DIMENSION = 1; public static final int NO_ORE_IN_BOTTOM_LAYER = 2; @@ -50,24 +41,9 @@ public class WorldgenGTOreLayer extends GTWorldgen { public static final int NO_OVERLAP_AIR_BLOCK = 5; 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 +54,70 @@ 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.mRestrictBiome = "None"; if (this.mEnabled) { sWeight += this.mWeight; } - - List allowedProviders = new ArrayList<>(); - if (this.mNether) { - allowedProviders.add(WorldProviderHell.class); - } - - if (this.mOverworld) { - allowedProviders.add(WorldProviderSurface.class); - if (!this.twilightForest) { - blackListedProviders = new String[] { "twilightforest.world.WorldProviderTwilightForest" }; - } - } - - if (tfProviderClass != null && this.twilightForest) { - allowedProviders.add(tfProviderClass); - } - - if (this.mEnd) { - allowedProviders.add(WorldProviderEnd.class); - } - mAllowedProviders = allowedProviders.toArray(new Class[0]); } @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 int executeWorldgenChunkified(World world, Random rng, String biome, int dimId, int chunkX, int chunkY, int seedX, int seedZ, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { 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, chunkY + 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, chunkY + 2); // Bias placement by 2 blocks to prevent worldgen cascade. + int limitSouthZ = Math.min(veinSouthZ, chunkY + 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, chunkY + 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 +126,105 @@ 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 + + chunkY / 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)))); + int localDensity = Math.max(1, this.mDensity / ((int) Math.sqrt(2 + Math.pow(chunkX / 16 - seedX / 16, 2) + Math.pow(chunkY / 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) + chunkY + 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) + chunkY + 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) + chunkY + 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) + chunkY + 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 +241,63 @@ 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; } + + public boolean contains(IMaterial material) { + return mPrimary == material || mBetween == material || mSecondary == material || mSporadic == material; + } + + 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 placeX = Math.max(1, Math.max(Math.abs(veinWestX - tX), Math.abs(veinEastX - tX)) / localDensity); + + for (int tZ = limitNorthZ; tZ < limitSouthZ; tZ++) { + int placeZ = Math.max(1, Math.max(Math.abs(veinSouthZ - tZ), Math.abs(veinNorthZ - tZ)) / localDensity); + + if (primary) { + if ((rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mPrimary != null) { + if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mPrimary, false)) { + placeCount[0]++; + } + continue; + } + } + + if (between) { + if ((rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mBetween != null) { + if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mBetween, false)) { + placeCount[2]++; + } + continue; + } + } + + if (secondary) { + if ((rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mSecondary != null) { + if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mSecondary, false)) { + placeCount[1]++; + } + continue; + } + } + + if (rng.nextInt(7) == 0 && (rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mSporadic != null) { // Sporadics are reduce 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 1ceafc32305..9a67a03300a 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java +++ b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java @@ -3,100 +3,64 @@ import static gregtech.api.enums.GTValues.debugSmallOres; import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; 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.enums.Materials; +import gregtech.api.interfaces.IMaterial; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.BlockOres2; +import gregtech.common.ores.OreManager; public class WorldgenGTOreSmallPieces extends GTWorldgen { public final short mMinY; public final short mMaxY; public final short mAmount; - public final Materials mMaterial; - public final boolean mOverworld; - public final boolean mNether; - public final boolean mEnd; - public final boolean twilightForest; + public final IMaterial mMaterial; public final String mBiome; + public final Set mAllowedDimensions; public static ArrayList sList = new ArrayList<>(); - public Class[] mAllowedProviders; - public String[] blackListedProviders; - public static Class tfProviderClass; - - static { - try { - tfProviderClass = Class.forName("twilightforest.world.WorldProviderTwilightForest"); - } catch (ClassNotFoundException ignored) {} - } - public WorldgenGTOreSmallPieces(SmallOreBuilder ore) { super(ore.smallOreName, GregTechAPI.sWorldgenList, ore.enabledByDefault); - this.mOverworld = ore.dimsEnabled.contains(SmallOreBuilder.OW); - this.mNether = ore.dimsEnabled.contains(SmallOreBuilder.NETHER); - this.mEnd = ore.dimsEnabled.contains(SmallOreBuilder.THE_END); - this.twilightForest = ore.dimsEnabled.contains(SmallOreBuilder.TWILIGHT_FOREST); this.mMinY = (short) ore.minY; this.mMaxY = (short) Math.max(this.mMinY + 1, ore.maxY); this.mAmount = (short) Math.max(1, ore.amount); this.mMaterial = ore.ore; this.mBiome = "None"; + this.mAllowedDimensions = new HashSet<>(ore.dimsEnabled); if (this.mEnabled) sList.add(this); - - List> allowedProviders = new ArrayList<>(); - if (this.mNether) { - allowedProviders.add(WorldProviderHell.class); - } - - if (this.mOverworld) { - allowedProviders.add(WorldProviderSurface.class); - if (!this.twilightForest) { - blackListedProviders = new String[] { "twilightforest.world.WorldProviderTwilightForest" }; - } - } - - if (tfProviderClass != null && this.twilightForest) { - allowedProviders.add(tfProviderClass); - } - - if (this.mEnd) { - allowedProviders.add(WorldProviderEnd.class); - } - mAllowedProviders = allowedProviders.toArray(new Class[0]); } @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 executeWorldgen(World world, Random random, String biome, int dimId, 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; if (this.mMaterial != null) { - int j = Math.max(1, this.mAmount / 2 + aRandom.nextInt(this.mAmount) / 2); - for (int i = 0; i < j; i++) { - BlockOres2.setOreForWorldGen( - aWorld, - aChunkX + 8 + aRandom.nextInt(16), - this.mMinY + aRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), - aChunkZ + 8 + aRandom.nextInt(16), + 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++; @@ -106,11 +70,11 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int GTLog.out.println( "Small Ore:" + this.mWorldGenName + " @ dim=" - + aDimensionType + + dimId + " 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 268fdc6ff8f..a7d4154690f 100644 --- a/src/main/java/gregtech/common/WorldgenStone.java +++ b/src/main/java/gregtech/common/WorldgenStone.java @@ -13,11 +13,11 @@ import net.minecraft.world.chunk.IChunkProvider; import gregtech.api.GregTechAPI; +import gregtech.api.interfaces.IStoneType; import gregtech.api.objects.XSTR; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.common.ores.OreManager; public class WorldgenStone extends GTWorldgen { @@ -128,6 +128,8 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int } } + IStoneType stoneType = OreManager.getStoneType(mBlock, mBlockMeta); + boolean result = !stones.isEmpty(); // Now process each oreseed vs this requested chunk for (; !stones.isEmpty(); stones.remove(0)) { @@ -262,26 +264,26 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int if (leftHandSize <= rightHandSide) { // Yay! We can actually place a block now. (this part copied from original code) Block tTargetedBlock = aWorld.getBlock(iX, iY, iZ); - if (tTargetedBlock == GregTechAPI.sBlockOres2) { - StoneType stoneType = StoneType.fromHypotheticalWorldBlock(aWorld, iX, iY, iZ, mBlock, mBlockMeta); - - if (stoneType != null) { - BlockOres2.setExistingOreStoneType(aWorld, iX, iY, iZ, stoneType); - } - } else if ((this.mAllowToGenerateinVoid && aWorld.isAirBlock(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); - } + + if (OreManager.setExistingOreStoneType(aWorld, iX, iY, iZ, stoneType)) { + continue; + } + + if (!this.mAllowToGenerateinVoid && aWorld.isAirBlock(iX, iY, iZ)) continue; + + if (tTargetedBlock == null) continue; + + // 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); + } + // spotless:on } } } 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/BlockOres2.java b/src/main/java/gregtech/common/blocks/BlockOres2.java deleted file mode 100644 index acff0a45c11..00000000000 --- a/src/main/java/gregtech/common/blocks/BlockOres2.java +++ /dev/null @@ -1,577 +0,0 @@ -package gregtech.common.blocks; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Random; -import java.util.Set; - -import com.google.common.collect.ImmutableList; - -import gregtech.GTMod; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.TextureSet; -import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.interfaces.IBlockOre; -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.GTModHandler; -import gregtech.api.util.GTOreDictUnificator; -import gregtech.api.util.GTUtility; -import gregtech.common.GTProxy.OreDropSystem; -import gregtech.common.render.GTRendererBlock; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -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.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.util.FakePlayer; - -public class BlockOres2 extends GTGenericBlock implements IBlockOre, IBlockWithTextures { - - /** Don't generate ores for these materials. */ - public final static Set DISABLED_ORES = new HashSet<>(); - - public BlockOres2() { - super(ItemOres2.class, "gt.blockores2", Material.rock); - setStepSound(soundTypeStone); - setCreativeTab(GregTechAPI.TAB_GREGTECH_ORES); - - for (StoneType stoneType : StoneType.STONE_TYPES) { - for (int matId = 0; matId < 1000; matId++) { - Materials mat = getMaterial(matId); - - if (mat == null) continue; - - GTLanguageManager.addStringLocalization(getUnlocalizedName() + "." + getMeta(stoneType, matId, false, false) + ".name", getLocalizedNameFormat(mat)); - GTLanguageManager.addStringLocalization(getUnlocalizedName() + "." + getMeta(stoneType, matId, true, false) + ".name", "Small " + getLocalizedNameFormat(mat)); - - GTLanguageManager.addStringLocalization(getUnlocalizedName() + "." + getMeta(stoneType, matId, false, false) + ".tooltip", mat.getToolTip()); - GTLanguageManager.addStringLocalization(getUnlocalizedName() + "." + getMeta(stoneType, matId, true, false) + ".tooltip", mat.getToolTip()); - - if ((mat.mTypes & 0x8) == 0) continue; - if (DISABLED_ORES.contains(mat)) continue; - - if (stoneType.prefix.mIsUnificatable) { - GTOreDictUnificator.set( - stoneType.prefix, - mat, - new ItemStack(this, 1, getMeta(stoneType, matId, false, false))); - } else { - GTOreDictUnificator.registerOre( - stoneType.prefix, - new ItemStack(this, 1, getMeta(stoneType, matId, false, false))); - } - } - } - } - - @Override - public String getUnlocalizedName() { - return "gt.blockores2"; - } - - @Override - public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { - for (int matId = 0; matId < 1000; matId++) { - for (StoneType stoneType : StoneType.STONE_TYPES) { - Materials mat = getMaterial(matId); - - if (mat == null) continue; - if ((mat.mTypes & 0x8) == 0) continue; - if (DISABLED_ORES.contains(mat)) continue; - - list.add(new ItemStack(this, 1, getMeta(stoneType, matId, false, false))); - } - } - - for (int matId = 0; matId < 1000; matId++) { - for (StoneType stoneType : StoneType.STONE_TYPES) { - Materials mat = getMaterial(matId); - - if (mat == null) continue; - if ((mat.mTypes & 0x8) == 0) continue; - if (DISABLED_ORES.contains(mat)) continue; - - list.add(new ItemStack(this, 1, getMeta(stoneType, matId, true, false))); - } - } - } - - @Override - public ITexture[][] getTextures(int metadata) { - StoneType stoneType = getStoneType(metadata); - int matId = getMaterialId(metadata); - boolean small = isSmallOre(metadata); - - Materials mat = getMaterial(matId); - - ITexture[] textures; - - 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(), - iTexture - }; - } else { - textures = new ITexture[] { - stoneType.getTexture(), - 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 switch(stoneType) { - 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(); - }; - } - - @Override - public int getRenderType() { - return GTRendererBlock.mRenderID; - } - - public String getLocalizedNameFormat(Materials material) { - String base = switch (material.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; - }; - - 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) { - return withNaturalFlag(meta, false); - } - - @Override - public int getHarvestLevel(int meta) { - Materials mat = getMaterial(meta); - - int smallOreBonus = isSmallOre(meta) ? -1 : 0; - - int harvestLevel = GTMod.gregtechproxy.mChangeHarvestLevels ? GTMod.gregtechproxy.mHarvestLevel[mat.mMetaItemSubID] : mat.mToolQuality; - - return GTUtility.clamp(harvestLevel + smallOreBonus, 0, GTMod.gregtechproxy.mMaxHarvestLevel); - } - - @Override - public float getBlockHardness(World world, int x, int y, int z) { - int meta = world.getBlockMetadata(x, y, z); - - return 1.0F + getHarvestLevel(meta); - } - - @Override - public float getExplosionResistance(Entity entity, World world, int x, int y, int z, double explosionX, - double explosionY, double explosionZ) { - int meta = world.getBlockMetadata(x, y, z); - - return 1.0F + getHarvestLevel(meta); - } - - @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) { - int meta = world.getBlockMetadata(x, y, z); - StoneType stone = BlockOres2.getStoneType(meta); - int matId = BlockOres2.getMaterialId(meta); - boolean small = BlockOres2.isSmallOre(meta); - - meta = getMeta(stone, matId, small, true); - - world.setBlockMetadataWithNotify(x, y, z, meta, 3); - GTUtility.sendChatToPlayer(player, "Set ore natural flag to true."); - return true; - } else { - return false; - } - } - - @Override - public boolean canSilkHarvest(World world, EntityPlayer player, int x, int y, int z, int metadata) { - return !isSmallOre(metadata); - } - - @Override - protected boolean canSilkHarvest() { - return false; - } - - public static final int SMALL_ORE_META_OFFSET = 16000, NATURAL_ORE_META_OFFSET = 8000; - - public static int getMeta(StoneType stone, int materialId, boolean small, boolean natural) { - int meta = GTUtility.clamp(materialId, 0, 999); - - meta += stone.offset; - - if (small) meta += SMALL_ORE_META_OFFSET; - if (natural) meta += NATURAL_ORE_META_OFFSET; - - return meta; - } - - public static int withNaturalFlag(int meta, boolean natural) { - StoneType stone = BlockOres2.getStoneType(meta); - int matId = BlockOres2.getMaterialId(meta); - boolean small = BlockOres2.isSmallOre(meta); - - return getMeta(stone, matId, small, natural); - } - - public static ItemStack getStack(StoneType stoneType, Materials material, boolean small, boolean natural, int amount) { - return new ItemStack(GregTechAPI.sBlockOres2, amount, getMeta(stoneType, material.mMetaItemSubID, small, natural)); - } - - public static void setOre(World world, int x, int y, int z, StoneType stone, Materials material, boolean small, boolean natural) { - world.setBlock(x, y, z, GregTechAPI.sBlockOres2, getMeta(stone, material.mMetaItemSubID, small, natural), 3); - } - - public static boolean setOreForWorldGen(World world, int x, int y, int z, Materials material, boolean small) { - if (y < 0 || y >= world.getActualHeight()) return false; - - StoneType existing = StoneType.fromWorldBlock(world, x, y, z); - - if (existing == null) return false; - - world.setBlock(x, y, z, GregTechAPI.sBlockOres2, getMeta(existing, material.mMetaItemSubID, small, true), 3); - - return true; - } - - public static boolean setExistingOreStoneType(World world, int x, int y, int z, StoneType newStoneType) { - if (world.getBlock(x, y, z) != GregTechAPI.sBlockOres2) return false; - - int meta = world.getBlockMetadata(x, y, z); - - int matId = getMaterialId(meta); - boolean small = isSmallOre(meta); - boolean natural = isNatural(meta); - - world.setBlock(x, y, z, GregTechAPI.sBlockOres2, getMeta(newStoneType, matId, small, natural), 3); - - return true; - } - - public static boolean isSmallOre(int meta) { - return meta >= SMALL_ORE_META_OFFSET; - } - - public static boolean isNatural(int meta) { - return (meta % SMALL_ORE_META_OFFSET) >= NATURAL_ORE_META_OFFSET; - } - - public static int getMaterialId(int meta) { - return meta % 1000; - } - - public static Materials getMaterial(int meta) { - return GregTechAPI.sGeneratedMaterials[getMaterialId(meta)]; - } - - public static StoneType getStoneType(int meta) { - meta %= SMALL_ORE_META_OFFSET; - meta %= NATURAL_ORE_META_OFFSET; - - int stoneType = meta / 1000; - - if (stoneType < 0 || stoneType >= StoneType.STONE_TYPES.size()) return null; - - return StoneType.STONE_TYPES.get(stoneType); - } - - public static enum StoneType { - Stone(0, OrePrefixes.ore, Materials.Stone), - Netherrack(1000, OrePrefixes.oreNetherrack, Materials.Netherrack), - Endstone(2000, OrePrefixes.oreEndstone, Materials.Endstone), - BlackGranite(3000, OrePrefixes.oreBlackgranite, Materials.GraniteBlack), - RedGranite(4000, OrePrefixes.oreRedgranite, Materials.GraniteRed), - Marble(5000, OrePrefixes.oreMarble, Materials.Marble), - Basalt(6000, OrePrefixes.oreBasalt, Materials.Basalt); - - public static final ImmutableList STONE_TYPES = ImmutableList.copyOf(values()); - - public final int offset; - public final OrePrefixes prefix; - public final Materials material; - - private StoneType(int offset, OrePrefixes prefix, Materials material) { - this.offset = offset; - this.prefix = prefix; - this.material = material; - } - - public ITexture getTexture() { - return switch (this) { - case Stone -> TextureFactory.of(Blocks.stone); - case Netherrack -> TextureFactory.of(Blocks.netherrack); - case Endstone -> TextureFactory.of(Blocks.end_stone); - case BlackGranite -> TextureFactory.builder().addIcon(BlockIcons.GRANITE_BLACK_STONE).stdOrient().build(); - case RedGranite -> TextureFactory.builder().addIcon(BlockIcons.GRANITE_RED_STONE).stdOrient().build(); - case Marble -> TextureFactory.builder().addIcon(BlockIcons.MARBLE_STONE).stdOrient().build(); - case Basalt -> TextureFactory.builder().addIcon(BlockIcons.BASALT_STONE).stdOrient().build(); - }; - } - - public static StoneType fromWorldBlock(World world, int x, int y, int z) { - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - - if (block.isReplaceableOreGen(world, x, y, z, Blocks.stone)) { - return StoneType.Stone; - } - - if (block.isReplaceableOreGen(world, x, y, z, Blocks.netherrack)) { - return StoneType.Netherrack; - } - - if (block.isReplaceableOreGen(world, x, y, z, Blocks.end_stone)) { - return StoneType.Endstone; - } - - if (block.isReplaceableOreGen(world, x, y, z, GregTechAPI.sBlockGranites)) { - return meta < 8 ? StoneType.BlackGranite : StoneType.RedGranite; - } - - if (block.isReplaceableOreGen(world, x, y, z, GregTechAPI.sBlockStones)) { - return meta < 8 ? StoneType.Marble : StoneType.Basalt; - } - - return null; - } - - public static StoneType fromHypotheticalWorldBlock(World world, int x, int y, int z, Block potentialBlock, int potentialMeta) { - if (potentialBlock.isReplaceableOreGen(world, x, y, z, Blocks.stone)) { - return StoneType.Stone; - } - - if (potentialBlock.isReplaceableOreGen(world, x, y, z, Blocks.netherrack)) { - return StoneType.Netherrack; - } - - if (potentialBlock.isReplaceableOreGen(world, x, y, z, Blocks.end_stone)) { - return StoneType.Endstone; - } - - if (potentialBlock.isReplaceableOreGen(world, x, y, z, GregTechAPI.sBlockGranites)) { - return potentialMeta < 8 ? StoneType.BlackGranite : StoneType.RedGranite; - } - - if (potentialBlock.isReplaceableOreGen(world, x, y, z, GregTechAPI.sBlockStones)) { - return potentialMeta < 8 ? StoneType.Marble : StoneType.Basalt; - } - - return null; - } - } - - @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); - - return (ArrayList) getDropsForMachine(world, x, y, z, metadata, doSilktouch, doFortune ? fortune : 0); - } - - @Override - public List getDropsForMachine(World world, int x, int y, int z, int metadata, boolean silktouch, int fortune) { - boolean isNatural = isNatural(metadata); - - return getDrops(world.rand, GTMod.gregtechproxy.oreDropSystem, this, metadata, silktouch, isNatural ? fortune : 0); - } - - public static List getPotentialDrops(Materials material, boolean small) { - if (small) { - return SmallOreDrops.getDropList(material); - } else { - return getBigOreDrops(null, OreDropSystem.Item, GregTechAPI.sBlockOres2, StoneType.Stone, material, false, 0); - } - } - - public static ArrayList getDrops(Random random, OreDropSystem oreDropMode, Block oreBlock, int meta, boolean silktouch, int fortune) { - if (meta <= 0) { - ArrayList drops = new ArrayList<>(); - drops.add(new ItemStack(Blocks.cobblestone, 1, 0)); - return drops; - } - - StoneType stone = getStoneType(meta); - Materials material = getMaterial(meta); - - if (isSmallOre(meta)) { - return getSmallOreDrops(random, stone, material, fortune); - } else { - return getBigOreDrops(random, oreDropMode, oreBlock, stone, material, silktouch, fortune); - } - } - - private static 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 ImmutableList DROPS = ImmutableList.copyOf(values()); - - public final OrePrefixes primary; - public final OrePrefixes fallback; - public 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; - } - } - - public static ArrayList getSmallOreDrops(Random random, StoneType stone, Materials material, int fortune) { - ArrayList possibleDrops = SmallOreDrops.getDropList(material); - ArrayList drops = new ArrayList<>(); - - if (!possibleDrops.isEmpty()) { - int dropCount = Math.max(1, material.mOreMultiplier + (fortune > 0 ? random.nextInt(1 + fortune * 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(GTOreDictUnificator.get(random.nextInt(3) > 0 ? OrePrefixes.dustImpure : OrePrefixes.dust, stone.material, 1L)); - } - - return drops; - } - - public static ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, Block oreBlock, StoneType stone, Materials material, boolean silktouch, int fortune) { - ArrayList drops = new ArrayList<>(); - - // For Sake of god of balance! - - boolean isRich = switch (stone) { - case Netherrack -> GTMod.gregtechproxy.mNetherOreYieldMultiplier; - case Endstone -> GTMod.gregtechproxy.mEndOreYieldMultiplier; - default -> false; - }; - - if (silktouch) oreDropMode = OreDropSystem.Block; - - switch (oreDropMode) { - case Item -> { - drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, material, isRich ? 2 : 1)); - } - case FortuneItem -> { - if (fortune > 0) { - // Max applicable fortune - if (fortune > 3) fortune = 3; - - int amount = 1 + Math.max(random.nextInt(fortune * (isRich ? 2 : 1) + 2) - 1, 0); - - for (int i = 0; i < amount; i++) { - drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, material, 1)); - } - } else { - for (int i = 0; i < (isRich ? 2 : 1); i++) { - drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, material, 1)); - } - } - } - case UnifiedBlock -> { - for (int i = 0; i < (isRich ? 2 : 1); i++) { - drops.add(new ItemStack(oreBlock, 1, material.mMetaItemSubID)); - } - } - case PerDimBlock -> { - if (stone == StoneType.Netherrack || stone == StoneType.Endstone) { - drops.add(new ItemStack(oreBlock, 1, getMeta(stone, material.mMetaItemSubID, false, false))); - } else { - drops.add(new ItemStack(oreBlock, 1, material.mMetaItemSubID)); - } - } - case Block -> { - drops.add(new ItemStack(oreBlock, 1, getMeta(stone, material.mMetaItemSubID, false, false))); - } - } - - return drops; - } -} diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java index ef17deb6c8e..aa206f8e92a 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java @@ -1,30 +1,9 @@ package gregtech.common.blocks; -import static gregtech.api.enums.Mods.NotEnoughItems; - import java.util.ArrayList; -import java.util.HashSet; +import java.util.Arrays; +import java.util.Collections; 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; @@ -32,300 +11,345 @@ import gregtech.api.GregTechAPI; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; +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.GTModHandler; 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 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; -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<>(); +public class BlockOresAbstract extends GTGenericBlock implements IBlockWithTextures { + + public final List stoneTypes; - protected BlockOresAbstract(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta, - Material aMaterial) { - super(ItemOres.class, aUnlocalizedName, aMaterial); - this.isBlockContainer = true; + public BlockOresAbstract(int series, StoneType[] stoneTypes) { + super(ItemOres.class, "gt.blockores" + series, Material.rock); setStepSound(soundTypeStone); setCreativeTab(GregTechAPI.TAB_GREGTECH_ORES); - tHideOres = NotEnoughItems.isModLoaded() && GTMod.gregtechproxy.mHideUnusedOres; - if (aOreMetaCount > 8 || aOreMetaCount < 0) aOreMetaCount = 8; - for (int i = 0; i < 16; i++) { - GTModHandler.addValuableOre(this, i, 1); + 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; + } } - 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))); - } - } - } + + this.stoneTypes = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(stoneTypes))); + + for (StoneType stoneType : stoneTypes) { + if (stoneType != null) { + GTOreAdapter.INSTANCE.registerOre(stoneType, this); } } - } - public int getBaseBlockHarvestLevel(int aMeta) { - return 0; - } + for (int matId = 0; matId < 1000; matId++) { + Materials mat = getMaterial(matId); - @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(); + 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)); + } } } - 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(); + public String getUnlocalizedName() { + return mUnlocalizedName; + } + + @Override + public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { + 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 || stoneType.isExtraneous()) continue; + + info.stoneType = stoneType; + + list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); } } - 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; - }; - } + info.isSmall = true; - public String getLocalizedName(Materials aMaterial) { - return aMaterial.getDefaultLocalizedNameForItem(getLocalizedNameFormat(aMaterial)); - } + for (int matId = 0; matId < 1000; matId++) { + info.material = getMaterial(matId); + info.stoneType = null; - @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; + if (!GTOreAdapter.INSTANCE.supports(info)) continue; + + for (StoneType stoneType : stoneTypes) { + if (stoneType == null || stoneType.isExtraneous()) continue; + + info.stoneType = stoneType; + + list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + } } + } + + public boolean isExtraneous() { + for (StoneType stoneType : stoneTypes) { + if (stoneType == null || stoneType.isExtraneous()) continue; - 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_); - } + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + EntityPlayer harvester = this.harvesters.get(); - @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)); - } + boolean doFortune = !(harvester instanceof FakePlayer); + boolean doSilktouch = harvester != null && EnchantmentHelper.getSilkTouchModifier(harvester); - @Override - public String getHarvestTool(int aMeta) { - return aMeta < 8 ? "pickaxe" : "shovel"; + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, metadata);) { + return (ArrayList) GTOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); + } } @Override - public int getHarvestLevel(int aMeta) { - return aMeta == 5 || aMeta == 6 ? 2 : aMeta % 8; - } + 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() + }; + } - @Override - public float getBlockHardness(World aWorld, int aX, int aY, int aZ) { - return 1.0F + getHarvestLevel(aWorld.getBlockMetadata(aX, aY, aZ)) * 1.0F; + return new ITexture[][] { textures, textures, textures, textures, textures, textures }; } @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; + public IIcon getIcon(int side, int meta) { + StoneType stoneType = getStoneType(meta); + + return stoneType == null ? null : stoneType.getIcon(side); } @Override - protected boolean canSilkHarvest() { - return false; + public int getRenderType() { + return GTRendererBlock.mRenderID; } @Override - public abstract String getUnlocalizedName(); + @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 - public String getLocalizedName() { - return StatCollector.translateToLocal(getUnlocalizedName() + DOT_NAME); + @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 getRenderType() { - if (GTRendererBlock.INSTANCE == null) { - return super.getRenderType(); + public String getLocalizedNameFormat(Materials material) { + String base = switch (material.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; + }; + + if (GTLanguageManager.i18nPlaceholder) { + return base; + } else { + return material.getDefaultLocalizedNameForItem(base); } - return GTRendererBlock.mRenderID; } @Override - public boolean canBeReplacedByLeaves(IBlockAccess aWorld, int aX, int aY, int aZ) { - return false; + 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 isNormalCube(IBlockAccess aWorld, int aX, int aY, int aZ) { - return true; + public boolean isToolEffective(String type, int metadata) { + return "pickaxe".equals(type); } @Override - public boolean hasTileEntity(int aMeta) { - return true; + public String getHarvestTool(int aMeta) { + return "pickaxe"; } @Override - public TileEntity createNewTileEntity(World aWorld, int aMeta) { - return createTileEntity(aWorld, aMeta); + public int damageDropped(int meta) { + try(OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, meta)) { + if (info == null) return 0; + + return GTOreAdapter.INSTANCE.getBlock(info.setNatural(false)).rightInt(); + } } @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(IBlockAccess aIBlockAccess, int aX, int aY, int aZ, int ordinalSide) { - return Blocks.stone.getIcon(0, 0); + public int getHarvestLevel(int meta) { + try(OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, meta)) { + 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 - @SideOnly(Side.CLIENT) - public IIcon getIcon(int ordinalSide, int aMeta) { - return Blocks.stone.getIcon(0, 0); + public float getBlockHardness(World world, int x, int y, int z) { + int meta = world.getBlockMetadata(x, y, z); + + return 1.0F + getHarvestLevel(meta); } @Override - @SideOnly(Side.CLIENT) - public void registerBlockIcons(IIconRegister aIconRegister) {} + public float getExplosionResistance(Entity entity, World world, int x, int y, int z, double explosionX, + double explosionY, double explosionZ) { + int meta = world.getBlockMetadata(x, y, z); - @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; + return 1.0F + getHarvestLevel(meta); } @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 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.setNatural(!info.isNatural); + + world.setBlockMetadataWithNotify(x, y, z, GTOreAdapter.INSTANCE.getBlock(info).rightInt(), 3); + GTUtility.sendChatToPlayer(player, "Set ore natural flag to " + info.isNatural); + } + + return true; + } else { + return false; + } } @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; + protected boolean canSilkHarvest() { + return false; } @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 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 abstract OrePrefixes[] getProcessingPrefix(); // Must have 8 entries; an entry can be null to disable - // automatic recipes. + public static final int SMALL_ORE_META_OFFSET = 16000, NATURAL_ORE_META_OFFSET = 8000; - public abstract boolean[] getEnabledMetas(); // Must have 8 entries. + public int getMaterialIndex(int meta) { + return meta % 1000; + } - public abstract Block getDroppedBlock(); + public int getStoneIndex(int meta) { + meta %= SMALL_ORE_META_OFFSET; + meta %= NATURAL_ORE_META_OFFSET; - public abstract Materials[] getDroppedDusts(); // Must have 8 entries; can be null. + return meta / 1000; + } - @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); + public boolean isSmallOre(int meta) { + return meta >= SMALL_ORE_META_OFFSET; } - @Override - public TileEntity createTileEntity(World aWorld, int aMeta) { - return new TileEntityOres(); + public boolean isNatural(int meta) { + return (meta % SMALL_ORE_META_OFFSET) >= NATURAL_ORE_META_OFFSET; } - public abstract ITexture[] getTextureSet(); // Must have 16 entries. + public Materials getMaterial(int meta) { + return GregTechAPI.sGeneratedMaterials[getMaterialIndex(meta)]; + } - @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)); - } - } - } + 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/BlockOresAbstractOld.java b/src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java new file mode 100644 index 00000000000..de42e163735 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java @@ -0,0 +1,51 @@ +package gregtech.common.blocks; + +import java.util.HashSet; +import java.util.Set; + +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; + +public abstract class BlockOresAbstractOld extends GTGenericBlock implements ITileEntityProvider { + + protected BlockOresAbstractOld(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta, Material aMaterial) { + super(ItemOresOld.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/BlockOresOld.java b/src/main/java/gregtech/common/blocks/BlockOresOld.java new file mode 100644 index 00000000000..649b76f89a8 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/BlockOresOld.java @@ -0,0 +1,46 @@ +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 net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockOresOld extends BlockOresAbstractOld { + + private static final String UNLOCALIZED_NAME = "gt.blockores"; + + public BlockOresOld() { + 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/ItemOres.java b/src/main/java/gregtech/common/blocks/ItemOres.java index 0691142bc35..05bd47bd145 100644 --- a/src/main/java/gregtech/common/blocks/ItemOres.java +++ b/src/main/java/gregtech/common/blocks/ItemOres.java @@ -7,7 +7,6 @@ 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; @@ -16,66 +15,41 @@ public class ItemOres extends ItemBlock { + public final BlockOresAbstract blockOre; + 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; + blockOre = (BlockOresAbstract) block; } @Override - public String getUnlocalizedName(ItemStack aStack) { - return this.field_150939_a.getUnlocalizedName() + "." + getDamage(aStack); + 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 ? BlockOresAbstract.SMALL_ORE_META_OFFSET : 0)); } @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; + public int getMetadata(int meta) { + return meta; } @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; + public String getItemStackDisplayName(ItemStack stack) { + String aName = super.getItemStackDisplayName(stack); + return Materials.getLocalizedNameForItem(aName, blockOre.getMaterialIndex(stack.getItemDamage())); } @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); + 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/ItemOres2.java b/src/main/java/gregtech/common/blocks/ItemOres2.java deleted file mode 100644 index 16781bf48ba..00000000000 --- a/src/main/java/gregtech/common/blocks/ItemOres2.java +++ /dev/null @@ -1,46 +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 org.apache.commons.lang3.StringUtils; - -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; - -public class ItemOres2 extends ItemBlock { - - public ItemOres2(Block block) { - super(block); - setMaxDamage(0); - setHasSubtypes(true); - setCreativeTab(GregTechAPI.TAB_GREGTECH_MATERIALS); - } - - @Override - public String getUnlocalizedName(ItemStack stack) { - return this.field_150939_a.getUnlocalizedName() + "." + BlockOres2.withNaturalFlag(stack.getItemDamage(), false); - } - - @Override - public int getMetadata(int meta) { - return meta; - } - - @Override - public String getItemStackDisplayName(ItemStack stack) { - String aName = super.getItemStackDisplayName(stack); - return Materials.getLocalizedNameForItem(aName, BlockOres2.getMaterialId(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/ItemOresOld.java b/src/main/java/gregtech/common/blocks/ItemOresOld.java new file mode 100644 index 00000000000..79893c17d26 --- /dev/null +++ b/src/main/java/gregtech/common/blocks/ItemOresOld.java @@ -0,0 +1,13 @@ +package gregtech.common.blocks; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemBlock; + +public class ItemOresOld extends ItemBlock { + + public ItemOresOld(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 151be9b243a..21c4e724bfd 100644 --- a/src/main/java/gregtech/common/blocks/TileEntityOres.java +++ b/src/main/java/gregtech/common/blocks/TileEntityOres.java @@ -1,142 +1,18 @@ 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; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.api.enums.StoneType; +import gregtech.common.ores.GTOreAdapter; +import gregtech.common.ores.OreInfo; -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) { @@ -152,146 +28,6 @@ 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 true; @@ -304,201 +40,16 @@ public void updateEntity() { if (!recursed) { recursed = true; - int meta = BlockOres2.getMeta(StoneType.STONE_TYPES.get(mMetaData % 16000 / 1000), mMetaData % 1000, mMetaData >= 16000, mNatural); - - worldObj.setBlock(xCoord, yCoord, zCoord, GregTechAPI.sBlockOres2, meta, 3); - } - } - - 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<>(); + try(OreInfo info = OreInfo.getNewInfo()) { + info.stoneType = StoneType.STONE_TYPES.get(mMetaData % 16000 / 1000); + info.material = GregTechAPI.sGeneratedMaterials[mMetaData % 1000]; + info.isSmall = mMetaData >= 16000; + info.isNatural = mNatural; - Materials aMaterial = aOreMaterial.mOreReplacement; + var p = GTOreAdapter.INSTANCE.getBlock(info); - 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); - } + worldObj.setBlock(xCoord, yCoord, zCoord, p.left(), p.rightInt(), 3); } - 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/items/behaviors/BehaviourProspecting.java b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java index d4b48006402..1f5280a6aa6 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java @@ -5,6 +5,7 @@ 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; @@ -12,9 +13,9 @@ 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.IMaterial; import gregtech.api.items.MetaBaseItem; import gregtech.api.items.MetaGeneratedTool; import gregtech.api.objects.ItemData; @@ -23,8 +24,7 @@ import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.common.ores.OreManager; public class BehaviourProspecting extends BehaviourNone { @@ -62,16 +62,14 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); - if (aBlock instanceof BlockOres2) { - final Materials tMaterial = BlockOres2.getMaterial(aMeta); - if (tMaterial != null && tMaterial != Materials._NULL) { - GTUtility.sendChatToPlayer( - aPlayer, - GTUtility.trans("100", "This is ") + tMaterial.mDefaultLocalName - + GTUtility.trans("101", " Ore.")); - GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); - return true; - } + IMaterial 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); @@ -85,11 +83,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer return true; } - StoneType stoneType = StoneType.fromWorldBlock(aWorld, aX, aY, aZ); - - if (stoneType != null - || aBlock == GregTechAPI.sBlockOres1 - || aBlock == GregTechAPI.sBlockOres2) { + 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); @@ -134,15 +128,13 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer Block tBlock = aWorld.getBlock(tX, tY, tZ); int tMeta = aWorld.getBlockMetadata(tX, tY, tZ); - if (tBlock instanceof BlockOres2) { - final Materials tMaterial = BlockOres2.getMaterial(tMeta); - if (tMaterial != null && tMaterial != Materials._NULL) { - GTUtility.sendChatToPlayer( - aPlayer, - GTUtility.trans("106", "Found traces of ") + tMaterial.mDefaultLocalName - + GTUtility.trans("101", " Ore.")); - return true; - } + 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; } oreMat = getOreMaterial(tBlock, tMeta); diff --git a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java index c52141f9bca..0e40af39d26 100644 --- a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java +++ b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java @@ -7,14 +7,12 @@ 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.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 +160,19 @@ public void mineBlock(IGregTechTileEntity te, Block block, int x, int y, int z) return; } - List drops = getBlockDrops(block, x, y, z); + List drops = OreManager.mineBlock(te.getWorld(), x, y, z, 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); + OreManager.mineBlock(te.getWorld(), x, y, z, owner.getMachineTier(), false, true); } /** @@ -236,19 +218,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..fea3ee32fa9 --- /dev/null +++ b/src/main/java/gregtech/common/ores/BWOreAdapter.java @@ -0,0 +1,207 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +import bartworks.system.material.BWMetaGeneratedOres; +import bartworks.system.material.BWMetaGeneratedSmallOres; +import bartworks.system.material.Werkstoff; +import bartworks.system.material.WerkstoffLoader; +import gregtech.GTMod; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; +import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.util.GTUtility; +import gregtech.api.util.GTUtility.ItemId; +import gregtech.common.GTProxy.OreDropSystem; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +public enum BWOreAdapter implements IOreAdapter { + INSTANCE; + + @Override + public boolean supports(Block block, int meta) { + return block instanceof BWMetaGeneratedOres; + } + + @Override + public boolean supports(OreInfo info) { + if (info.stoneType != null && info.stoneType != StoneType.Stone) 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; + + OreInfo info = OreInfo.getNewInfo(); + + info.stoneType = StoneType.Stone; + info.material = Werkstoff.werkstoffHashMap.get((Short) (short) meta); + info.isSmall = block instanceof BWMetaGeneratedSmallOres; + info.isNatural = ((BWMetaGeneratedOres) block).isNatural; + + return info; + } + + @Override + public ObjectIntPair getBlock(OreInfo info) { + if (info.stoneType != null && info.stoneType != StoneType.Stone) 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; + + Block block; + + if (info.isSmall) { + if (info.isNatural) { + block = WerkstoffLoader.BWSmallOresNatural; + } else { + block = WerkstoffLoader.BWSmallOres; + } + } else { + if (info.isNatural) { + block = WerkstoffLoader.BWOresNatural; + } else { + block = WerkstoffLoader.BWOres; + } + } + + return ObjectIntPair.of(block, w.getmID()); + } + + @Override + public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { + if (!supports(info2)) return null; + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + if (info.stoneType == null) info.stoneType = StoneType.Stone; + if (info.stoneType != StoneType.Stone) return null; + + if (!info.isNatural) fortune = 0; + + if (info.isSmall) { + return getSmallOreDrops(ThreadLocalRandom.current(), info, fortune); + } else { + OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; + + if (silktouch) oreDropSystem = OreDropSystem.Block; + + return getBigOreDrops(ThreadLocalRandom.current(), oreDropSystem, info, fortune); + } + } + + @Override + public List getPotentialDrops(OreInfo info2) { + if (!supports(info2)) return null; + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + if (info.isSmall) { + List drops = new ArrayList<>(); + + for (ItemStack stack : SmallOreDrops.getDropList(info.material.getBridgeMaterial())) { + ItemId id = ItemId.create(stack); + + if (!drops.contains(id)) drops.add(id); + } + + List drops2 = new ArrayList<>(); + + for (ItemId id : drops) { + drops2.add(id.getItemStack()); + } + + return drops2; + } else { + return getBigOreDrops(ThreadLocalRandom.current(), GTMod.gregtechproxy.oreDropSystem, info, 0); + } + } + + public 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; + } + + public 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 -> { + OreInfo info2 = info.clone(); + + for (int i = 0; i < (info.stoneType.isRich() ? 2 : 1); i++) { + info.stoneType = StoneType.Stone; + drops.add(getStack(info, 1)); + } + + info2.release(); + } + case PerDimBlock -> { + OreInfo info2 = info.clone(); + + if (!info.stoneType.isDimensionSpecific()) { + info2.stoneType = StoneType.Stone; + } + + drops.add(getStack(info, 1)); + + info2.release(); + } + case Block -> { + drops.add(getStack(info, 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..d2a61e0fb37 --- /dev/null +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -0,0 +1,304 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; + +import gregtech.GTMod; +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; +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.BlockOresAbstract; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +public enum GTOreAdapter implements IOreAdapter { + INSTANCE; + + /** Don't generate ores for these materials. */ + public final static Set DISABLED_ORES = new HashSet<>(); + + private final Map oreBlocksByStoneType = new EnumMap<>(StoneType.class); + + public BlockOresAbstract ores1, ores2, ores3, ores4, ores5, ores6; + + public BlockOresAbstract[] ores; + + public void init() { + ores1 = new BlockOresAbstract(2, new StoneType[] { + StoneType.Stone, + StoneType.Netherrack, + StoneType.Endstone, + StoneType.BlackGranite, + StoneType.RedGranite, + StoneType.Marble, + StoneType.Basalt, + StoneType.Moon, + }); + ores2 = new BlockOresAbstract(3, new StoneType[] { + StoneType.Mars, + StoneType.Asteroid, + StoneType.Phobos, + StoneType.Deimos, + StoneType.Ceres, + StoneType.Io, + StoneType.Europa, + StoneType.Ganymede, + }); + ores3 = new BlockOresAbstract(4, new StoneType[] { + StoneType.Callisto, + StoneType.Enceladus, + StoneType.Titan, + StoneType.Miranda, + StoneType.Oberon, + StoneType.Proteus, + StoneType.Triton, + StoneType.Pluto, + }); + ores4 = new BlockOresAbstract(5, new StoneType[] { + StoneType.Callisto, + StoneType.Enceladus, + StoneType.Titan, + StoneType.Miranda, + StoneType.Oberon, + StoneType.Proteus, + StoneType.Triton, + StoneType.Pluto, + }); + ores5 = new BlockOresAbstract(6, new StoneType[] { + StoneType.Haumea, + StoneType.MakeMake, + StoneType.AlphaCentauri, + StoneType.TCetiE, + StoneType.VegaB, + StoneType.BarnardaE, + StoneType.BarnardaF, + StoneType.Horus, + }); + ores6 = new BlockOresAbstract(7, new StoneType[] { + StoneType.Anubis, + }); + + ores = new BlockOresAbstract[] { ores1, ores2, ores3, ores4, ores5, ores6 }; + } + + public void registerOre(StoneType stoneType, BlockOresAbstract oreBlock) { + oreBlocksByStoneType.put(stoneType, oreBlock); + } + + @Override + public boolean supports(Block block, int meta) { + return GTUtility.contains(ores, block); + } + + @Override + public boolean supports(OreInfo info) { + if (info.stoneType != null) { + if (!(info.stoneType instanceof StoneType stoneType)) return false; + if (!oreBlocksByStoneType.containsKey(stoneType)) return false; + if (!stoneType.isEnabled()) return false; + } + + if (!(info.material instanceof Materials gtMat)) return false; + if (gtMat.mMetaItemSubID < 0 || gtMat.mMetaItemSubID >= 1000) return false; + if ((gtMat.mTypes & 0x8) == 0) return false; + if (DISABLED_ORES.contains(gtMat)) 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 BlockOresAbstract oreBlock)) return null; + + 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 (mat.mMetaItemSubID < 0 || mat.mMetaItemSubID >= 1000) return null; + if ((mat.mTypes & 0x8) == 0) return null; + if (DISABLED_ORES.contains(mat)) return null; + + StoneType stoneType = GTUtility.getIndexSafe(oreBlock.stoneTypes, stoneId); + if (!stoneType.isEnabled()) return null; + + OreInfo info = OreInfo.getNewInfo(); + + info.material = mat; + info.stoneType = stoneType; + info.isSmall = small; + info.isNatural = natural; + + return info; + } + + @Override + public ObjectIntPair getBlock(OreInfo info) { + if (info.stoneType == null) info.stoneType = StoneType.Stone; + + BlockOresAbstract oreBlock = oreBlocksByStoneType.get(info.stoneType); + + if (oreBlock == null) return null; + if (!(info.material instanceof Materials gtMat)) return null; + if (gtMat.mMetaItemSubID < 0 || gtMat.mMetaItemSubID >= 1000) return null; + if ((gtMat.mTypes & 0x8) == 0) return null; + if (DISABLED_ORES.contains(gtMat)) return null; + + if (!(info.stoneType instanceof StoneType stoneType)) return null; + if (!stoneType.isEnabled()) 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 ObjectIntPair.of(oreBlock, meta); + } + + @Override + public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { + if (!supports(info2)) return null; + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + if (info.stoneType == null) info.stoneType = StoneType.Stone; + + BlockOresAbstract oreBlock = oreBlocksByStoneType.get(info.stoneType); + + if (oreBlock == null) return null; + + if (!info.isNatural) fortune = 0; + + if (info.isSmall) { + return getSmallOreDrops(ThreadLocalRandom.current(), info, fortune); + } else { + OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; + + if (silktouch) oreDropSystem = OreDropSystem.Block; + + return getBigOreDrops(ThreadLocalRandom.current(), oreDropSystem, info, fortune); + } + } + + @Override + public List getPotentialDrops(OreInfo info2) { + if (!supports(info2)) return null; + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + if (info.isSmall) { + List drops = new ArrayList<>(); + + for (ItemStack stack : SmallOreDrops.getDropList(info.material)) { + ItemId id = ItemId.create(stack); + + if (!drops.contains(id)) drops.add(id); + } + + List drops2 = new ArrayList<>(); + + for (ItemId id : drops) { + drops2.add(id.getItemStack()); + } + + return drops2; + } else { + return getBigOreDrops(ThreadLocalRandom.current(), GTMod.gregtechproxy.oreDropSystem, info, 0); + } + } + + public 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; + } + + public 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 -> { + OreInfo info2 = info.clone(); + + for (int i = 0; i < (info.stoneType.isRich() ? 2 : 1); i++) { + info.stoneType = StoneType.Stone; + drops.add(getStack(info, 1)); + } + + info2.release(); + } + case PerDimBlock -> { + OreInfo info2 = info.clone(); + + if (!info.stoneType.isDimensionSpecific()) { + info2.stoneType = StoneType.Stone; + } + + drops.add(getStack(info, 1)); + + info2.release(); + } + case Block -> { + drops.add(getStack(info, 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..02e2893b40f --- /dev/null +++ b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java @@ -0,0 +1,122 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +import gregtech.GTMod; +import gregtech.api.enums.StoneType; +import gregtech.common.GTProxy.OreDropSystem; +import gtPlusPlus.core.block.base.BlockBaseOre; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +public enum GTPPOreAdapter implements IOreAdapter { + INSTANCE; + + @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; + + 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 ObjectIntPair getBlock(OreInfo info) { + if (!(info.material instanceof Material gtppMat)) return null; + + Block ore = gtppMat.getOreBlock(1); + + if (ore == null) return null; + + return ObjectIntPair.of(ore, 0); + } + + @Override + public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { + if (!supports(info2)) return null; + + @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(ThreadLocalRandom.current(), oreDropSystem, info, fortune); + } + + @Override + public List getPotentialDrops(OreInfo info2) { + if (!supports(info2)) return null; + + @SuppressWarnings("unchecked") + OreInfo info = (OreInfo) info2; + + return getBigOreDrops(ThreadLocalRandom.current(), GTMod.gregtechproxy.oreDropSystem, info, 0); + } + + public List getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, int fortune) { + ArrayList drops = new ArrayList<>(); + + switch (oreDropMode) { + case Item -> drops.add( + ItemUtils + .getItemStackOfAmountFromOreDictNoBroken("oreRaw" + info.material.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 (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( + ItemUtils.getItemStackOfAmountFromOreDictNoBroken( + "oreRaw" + info.material.getLocalizedName(), + 1)); + } + } else { + drops.add( + ItemUtils.getItemStackOfAmountFromOreDictNoBroken( + "oreRaw" + info.material.getLocalizedName(), + 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..9e9f4680e49 --- /dev/null +++ b/src/main/java/gregtech/common/ores/IOreAdapter.java @@ -0,0 +1,55 @@ +package gregtech.common.ores; + +import java.util.List; + +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IMaterial; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; +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; + +public interface IOreAdapter { + + public boolean supports(Block block, int meta); + public boolean supports(OreInfo info); + + public OreInfo getOreInfo(Block block, int meta); + public default OreInfo getOreInfo(World world, int x, int y, int z) { + return getOreInfo(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + } + public default OreInfo getOreInfo(ItemStack stack) { + if (!(stack.getItem() instanceof ItemBlock itemBlock)) return null; + + return getOreInfo(itemBlock.field_150939_a, Items.feather.getDamage(stack)); + } + + public ObjectIntPair getBlock(OreInfo info); + + public default ItemStack getStack(OreInfo info, int amount) { + ObjectIntPair p = getBlock(info); + + if (p != null) { + return new ItemStack(p.left(), amount, p.rightInt()); + } + + if (info.stoneType != StoneType.Stone) { + try(OreInfo info2 = info.clone()) { + info2.stoneType = StoneType.Stone; + + p = getBlock(info); + + if (p != null) { + return new ItemStack(p.left(), amount, p.rightInt()); + } + } + } + + return null; + } + + public List getOreDrops(OreInfo info, boolean silktouch, int fortune); + 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..a90a9341494 --- /dev/null +++ b/src/main/java/gregtech/common/ores/OreInfo.java @@ -0,0 +1,118 @@ +package gregtech.common.ores; + +import com.gtnewhorizon.gtnhlib.util.ObjectPooler; + +import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneType; + +public class OreInfo implements AutoCloseable { + + public TMat material; + public IStoneType stoneType; + public boolean isSmall; + 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() { + material = null; + stoneType = null; + isSmall = false; + isNatural = false; + return this; + } + + public OreInfo clone() { + OreInfo dup = getNewInfo(); + dup.material = this.material; + dup.stoneType = this.stoneType; + dup.isSmall = this.isSmall; + dup.isNatural = this.isNatural; + return dup; + } + + public OreInfo setMaterial(TMat material) { + this.material = material; + return this; + } + + public OreInfo setStoneType(IStoneType stoneType) { + this.stoneType = stoneType; + return this; + } + + public OreInfo setSmall(boolean isSmall) { + this.isSmall = isSmall; + return this; + } + + public OreInfo setNatural(boolean isNatural) { + this.isNatural = isNatural; + return this; + } + + @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..d9f9129235e --- /dev/null +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -0,0 +1,240 @@ +package gregtech.common.ores; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Nullable; + +import com.google.common.collect.ImmutableList; + +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneType; +import it.unimi.dsi.fastutil.Pair; +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; + +public class OreManager { + + private OreManager() { } + + public static final ImmutableList> ORE_ADAPTERS = ImmutableList.of( + GTOreAdapter.INSTANCE, + GTPPOreAdapter.INSTANCE, + BWOreAdapter.INSTANCE); + + public static IStoneType getStoneType(Block block, int meta) { + IStoneType stoneType = StoneType.findStoneType(block, meta); + + if (stoneType != null) return stoneType; + + return null; + } + + public static boolean isOre(Block block, int meta) { + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + try (OreInfo info = oreAdapter.getOreInfo(block, meta)) { + if (info != null && info.isNatural) return true; + } + } + + return false; + } + + public static Pair, OreInfo> getOreInfo(Block block, int meta) { + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + OreInfo info = oreAdapter.getOreInfo(block, meta); + if (info != null) return Pair.of(oreAdapter, info); + } + + return null; + } + + public static Pair, 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) { + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + if (oreAdapter.supports(info)) return oreAdapter; + } + + return null; + } + + public static boolean setOreForWorldGen(World world, int x, int y, int z, IStoneType defaultStone, IMaterial material, boolean small) { + if (y < 0 || y >= world.getActualHeight()) return false; + + IStoneType existingStone = getStoneType(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + + 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; + + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + var block = oreAdapter.getBlock(info); + + if (block != null) { + world.setBlock(x, y, z, block.left(), block.rightInt(), 3); + + return true; + } + } + + return false; + } + } + + public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneType stoneType, IMaterial 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; + + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + var block = oreAdapter.getBlock(info); + + if (block != null) { + world.setBlock(x, y, z, block.left(), block.rightInt(), 3); + + return true; + } + } + + return false; + } + } + + public static boolean setExistingOreStoneType(World world, int x, int y, int z, IStoneType newStoneType) { + var p = getOreInfo(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + + if (p == null) return false; + + IOreAdapter oreAdapter = p.left(); + OreInfo info = p.right(); + + info.stoneType = newStoneType; + + var block = oreAdapter.getBlock(info); + + if (block == null) return false; + + world.setBlock(x, y, z, block.left(), block.rightInt(), 3); + + return true; + } + + public static List mineBlock(World world, int x, int y, int z, int fortune, boolean simulate, boolean replaceWithCobblestone) { + Block ore = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + var p = getOreInfo(ore, meta); + + List oreBlockDrops; + Block replacement; + int replacementMeta; + + if (p != null) { + try (OreInfo info = p.right()) { + oreBlockDrops = p.left().getOreDrops(info, false, fortune); + + var cobble = info.stoneType.getCobblestone(); + + replacement = cobble.left(); + replacementMeta = cobble.rightInt(); + } + } else { + if (ore.canSilkHarvest(world, null, x, y, z, meta)) { + oreBlockDrops = new ArrayList<>(Arrays.asList(new ItemStack(ore, 1, meta))); + } else { + // Regular ore + oreBlockDrops = ore.getDrops(world, x, y, z, meta, fortune); + } + + replacement = Blocks.cobblestone; + replacementMeta = 0; + } + + if (!simulate) { + if (replaceWithCobblestone) { + world.setBlock(x, y, z, replacement, replacementMeta, 3); + } else { + world.setBlockToAir(x, y, z); + } + } + + return oreBlockDrops; + } + + public static IMaterial getMaterial(ItemStack stack) { + if (!(stack.getItem() instanceof ItemBlock itemBlock)) return null; + + return getMaterial(itemBlock.field_150939_a, Items.feather.getDamage(stack)); + } + + public static IMaterial getMaterial(Block block, int meta) { + var p = getOreInfo(block, meta); + + return p == null ? null : p.right().material; + } + + public static ItemStack getStack(OreInfo info, int amount) { + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + 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 getDrops(Block block, int meta, boolean silktouch, int fortune) { + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + try (OreInfo info = oreAdapter.getOreInfo(block, meta)) { + if (info != null) { + return oreAdapter.getOreDrops(info, silktouch, fortune); + } + } + } + + return null; + } + + public static List getPotentialDrops(OreInfo info) { + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + 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..3d7ddaa8a2a --- /dev/null +++ b/src/main/java/gregtech/common/ores/SmallOreDrops.java @@ -0,0 +1,49 @@ +package gregtech.common.ores; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableList; + +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GTOreDictUnificator; +import net.minecraft.item.ItemStack; + +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 ImmutableList DROPS = ImmutableList.copyOf(values()); + + public final OrePrefixes primary; + public final OrePrefixes fallback; + public 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; + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/common/render/GTRendererBlock.java b/src/main/java/gregtech/common/render/GTRendererBlock.java index 86f59ca63f3..a9b00532756 100644 --- a/src/main/java/gregtech/common/render/GTRendererBlock.java +++ b/src/main/java/gregtech/common/render/GTRendererBlock.java @@ -55,8 +55,6 @@ import gregtech.api.objects.XSTR; 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 { @@ -544,8 +542,6 @@ public static void addDestroyEffects(EffectRenderer effectRenderer, Block block, } } - final TileEntityOres tTileEntity = new TileEntityOres(); - @Override public void renderInventoryBlock(Block aBlock, int aMeta, int aModelID, RenderBlocks aRenderer) { aRenderer.enableAO = false; @@ -554,20 +550,7 @@ 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); // spotless:off - if (aBlock instanceof BlockOresAbstract) { - tTileEntity.mMetaData = ((short) aMeta); - - aBlock.setBlockBoundsForItemRender(); - aRenderer.setRenderBoundsFromBlock(aBlock); - - 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); - } else if (aMeta > 0 && (aMeta < GregTechAPI.METATILEENTITIES.length) && aBlock instanceof BlockMachines && (GregTechAPI.METATILEENTITIES[aMeta] != null) && (!GregTechAPI.METATILEENTITIES[aMeta].renderInInventory(aBlock, aMeta, aRenderer))) { + 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 IBlockWithTextures texturedBlock) { ITexture[][] texture = texturedBlock.getTextures(aMeta); 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..b79becaf1e7 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,26 +270,17 @@ 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() .startsWith("ore"))) return association.mMaterial.mMaterial.mDefaultLocalName; - else if (GTUtility.isOre(tBlock, tMetaID)) return tBlock.getLocalizedName(); + else if (GTUtility.isMinable(tBlock, tMetaID)) return tBlock.getLocalizedName(); } return null; } 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..4df3c45191a 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; @@ -251,7 +248,7 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { x = aBaseMetaTileEntity.getXCoord() + oreBlockPos.chunkPosX; y = aBaseMetaTileEntity.getYCoord() + oreBlockPos.chunkPosY; z = aBaseMetaTileEntity.getZCoord() + oreBlockPos.chunkPosZ; - isOre = GTUtility.isOre( + isOre = GTUtility.isMinable( oreBlock, aBaseMetaTileEntity.getWorld() .getBlockMetadata(x, y, z)); @@ -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.isMinable(block, blockMeta)) { oreBlockPositions.add(new ChunkPosition(x, pipe.getTipDepth(), z)); } } diff --git a/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java index 259988c16aa..e3f270e8a28 100644 --- a/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java @@ -215,7 +215,7 @@ protected void scanPipes() { Block aBlock = gtTile.getBlockAtSide(gtTile.getBackFacing()); if (aBlock instanceof BlockLongDistancePipe) { - byte aMetaData = gtTile.getMetaIDAtSide(gtTile.getBackFacing()); + int aMetaData = gtTile.getMetaIDAtSide(gtTile.getBackFacing()); if (aMetaData != getPipeMeta()) return; HashSet tVisited = new HashSet<>(Collections.singletonList(getCoords())), diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java index 32651313a31..885d9e90fe0 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java @@ -304,7 +304,7 @@ private void replaceDeprecatedCoils(IGregTechTileEntity aBaseMetaTileEntity) { for (int yPos = tY - 1; yPos <= tY + 1; yPos++) for (int zPos = tZ - 1; zPos <= tZ + 1; zPos += (xDir != 0 ? 2 : 1)) { if ((yPos == tY) && (xPos == tX || zPos == tZ)) continue; - final byte tUsedMeta = aBaseMetaTileEntity.getMetaID(xPos, yPos, zPos); + final int tUsedMeta = aBaseMetaTileEntity.getMetaID(xPos, yPos, zPos); if (tUsedMeta < 12) continue; if (tUsedMeta > 14) continue; if (aBaseMetaTileEntity.getBlock(xPos, yPos, zPos) != GregTechAPI.sBlockCasings1) continue; 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 93374490873..73f7802c4b9 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java @@ -14,9 +14,11 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Objects; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -24,6 +26,7 @@ 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; @@ -47,7 +50,6 @@ import gregtech.api.enums.SoundResource; import gregtech.api.gui.modularui.GTUITextures; import gregtech.api.gui.widgets.LockedWhileActiveButton; -import gregtech.api.interfaces.IBlockOre; import gregtech.api.interfaces.IHatchElement; import gregtech.api.interfaces.metatileentity.IMetricsExporter; import gregtech.api.objects.GTChunkManager; @@ -58,8 +60,7 @@ import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; 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; public abstract class MTEOreDrillingPlantBase extends MTEDrillerBase implements IMetricsExporter { @@ -224,54 +225,50 @@ private boolean tryProcessOreList() { } private boolean processOreList(boolean simulate) { + List oreBlockPositions = simulate ? copyOreBlockPositions(this.oreBlockPositions) : this.oreBlockPositions; + 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()) { + World world = getBaseMetaTileEntity().getWorld(); + + while ((oreBlock == null || !GTUtility.isMinable(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); + int x = oreBlockPos.chunkPosX; + int y = oreBlockPos.chunkPosY; + int z = oreBlockPos.chunkPosZ; + if (GTUtility.eraseBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), x, y, z, true)) { + oreBlock = world.getBlock(x, y, z); + oreBlockMetadata = world.getBlockMetadata(x, y, z); + } } + if (oreBlock == null) return false; + Objects.requireNonNull(oreBlockPos); + 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; - } - 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 (GTUtility.isMinable(oreBlock, oreBlockMetadata) || OreManager.isOre(oreBlock, oreBlockMetadata)) { + int x = oreBlockPos.chunkPosX; + int y = oreBlockPos.chunkPosY; + int z = oreBlockPos.chunkPosZ; + + List oreBlockDrops = OreManager.mineBlock(world, x, y, z, mTier + 3, simulate, replaceWithCobblestone); + ItemStack[] toOutput = getOutputByDrops(oreBlockDrops); if (simulate && !canOutputAll(toOutput)) { setRuntimeFailureReason(CheckRecipeResultRegistry.ITEM_OUTPUT_FULL); return false; } + mOutputItems = toOutput; } + return true; } @@ -537,18 +534,6 @@ private ItemStack multiplyStackSize(ItemStack itemStack) { return itemStack; } - private Collection getBlockDrops(final Block oreBlock, int posX, int posY, int posZ) { - final int blockMeta = getBaseMetaTileEntity().getWorld().getBlockMetadata(posX, posY, posZ); - if (oreBlock instanceof IBlockOre machineMinable) { - return machineMinable.getDropsForMachine(getBaseMetaTileEntity().getWorld(), posX, posY, posZ, blockMeta, false, mTier + 3); - } - if (oreBlock.canSilkHarvest(getBaseMetaTileEntity().getWorld(), null, posX, posY, posZ, blockMeta)) { - return Collections.singleton(new ItemStack(oreBlock, 1, blockMeta)); - } - // 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); } @@ -585,12 +570,9 @@ 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); + if (GTUtility.isMinable(block, blockMeta)) oreBlockPositions.add(blockPos); } } diff --git a/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java b/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java index c287f24f778..1da45671707 100644 --- a/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java +++ b/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java @@ -73,8 +73,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.BlockOres2; +import gregtech.common.blocks.BlockOresOld; import gregtech.common.blocks.BlockReinforced; import gregtech.common.blocks.BlockStones; import gregtech.common.blocks.BlockTintedIndustrialGlass; @@ -95,6 +94,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; @@ -549,8 +549,7 @@ public void run() { GregTechAPI.sBlockLongDistancePipes = new BlockLongDistancePipe(); GregTechAPI.sBlockConcretes = new BlockConcretes(); GregTechAPI.sBlockStones = new BlockStones(); - GregTechAPI.sBlockOres1 = new BlockOres(); - GregTechAPI.sBlockOres2 = new BlockOres2(); + GregTechAPI.sBlockOres1 = new BlockOresOld(); GregTechAPI.sBlockFrames = new BlockFrameBox(); GregTechAPI.sDroneRender = new BlockDrone(); GregTechAPI.sBlockGlass1 = new BlockGlass1(); @@ -559,6 +558,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..6a989e9f616 100644 --- a/src/main/java/gregtech/nei/NEIGTConfig.java +++ b/src/main/java/gregtech/nei/NEIGTConfig.java @@ -26,9 +26,11 @@ import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.RecipeMaps; import gregtech.api.util.GTModHandler; +import gregtech.common.blocks.BlockOresAbstract; 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; @@ -36,6 +38,7 @@ import gregtech.nei.dumper.MetaTileEntityDumper; import gregtech.nei.dumper.RecipeLockingSupportDumper; import gregtech.nei.dumper.VoidProtectionSupportDumper; +import net.minecraft.item.ItemStack; public class NEIGTConfig implements IConfigureNEI { @@ -76,6 +79,7 @@ public void loadConfig() { registerCatalysts(); registerItemEntries(); registerDumpers(); + hideItems(); sIsAdded = true; } @@ -121,6 +125,16 @@ private void registerDumpers() { API.addOption(new RecipeLockingSupportDumper()); } + private void hideItems() { + for (BlockOresAbstract ore : GTOreAdapter.INSTANCE.ores) { + if (ore.isExtraneous()) { + for (int i = 0; i < 16; i++) { + API.hideItem(new ItemStack(ore, i)); + } + } + } + } + @SubscribeEvent public void registerHandlerInfo(NEIRegisterHandlerInfosEvent event) { if (RECIPE_CATALYST_INDEX == null) { diff --git a/src/main/java/gtPlusPlus/api/interfaces/ILazyCoverable.java b/src/main/java/gtPlusPlus/api/interfaces/ILazyCoverable.java index d2a1e34f99d..d8b04fc2463 100644 --- a/src/main/java/gtPlusPlus/api/interfaces/ILazyCoverable.java +++ b/src/main/java/gtPlusPlus/api/interfaces/ILazyCoverable.java @@ -110,22 +110,22 @@ default IGregTechTileEntity getIGregTechTileEntityAtSideAndDistance(ForgeDirecti } @Override - default byte getMetaID(int arg0, int arg1, int arg2) { + default int getMetaID(int arg0, int arg1, int arg2) { return 0; } @Override - default byte getMetaIDOffset(int arg0, int arg1, int arg2) { + default int getMetaIDOffset(int arg0, int arg1, int arg2) { return 0; } @Override - default byte getMetaIDAtSide(ForgeDirection side) { + default int getMetaIDAtSide(ForgeDirection side) { return 0; } @Override - default byte getMetaIDAtSideAndDistance(ForgeDirection side, int arg1) { + default int getMetaIDAtSideAndDistance(ForgeDirection side, int arg1) { return 0; } diff --git a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java index bc4f4b25a6a..4980c649da9 100644 --- a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java +++ b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java @@ -15,7 +15,6 @@ 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; 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..fd301d36f15 100644 --- a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java @@ -1,10 +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 gregtech.api.interfaces.IMaterial; +import gregtech.common.WorldgenGTOreLayer; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -19,7 +21,6 @@ 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 +41,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) { + IMaterial[] mats = { oreLayer.mPrimary, oreLayer.mSecondary, oreLayer.mBetween, oreLayer.mSporadic }; + + for (IMaterial mat : mats) { + if (mat instanceof Material gtppMat) { + mMapOreBlockItemToDimName.put(gtppMat, oreLayer.mAllowedDimensions); + } + } + } + } @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,18 +98,11 @@ 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("Found:"); + if (dims != null && !dims.isEmpty()) { + for (String m : dims) { list.add("- " + m); } } else { diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index 0e69ba88d59..9902e8a2eb2 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -12,6 +12,7 @@ import net.minecraft.block.Block; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; @@ -20,6 +21,7 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.TextureSet; +import gregtech.api.interfaces.IMaterial; import gregtech.api.util.GTLanguageManager; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes; @@ -33,7 +35,7 @@ import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; -public class Material { +public class Material implements IMaterial { public static final Set mMaterialMap = new HashSet<>(); public static HashMap mMaterialCache = new HashMap<>(); @@ -836,6 +838,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 +846,28 @@ 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 String getInternalName() { + return getUnlocalizedName(); + } + public final String getUnlocalizedName() { if (this.unlocalizedName != null) { return this.unlocalizedName; @@ -868,6 +893,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) { diff --git a/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java b/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java index 811fb0cab13..84b708e7c3b 100644 --- a/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java +++ b/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java @@ -567,17 +567,17 @@ public final Block getBlockAtSideAndDistance(ForgeDirection side, int aDistance) } @Override - public final byte getMetaIDOffset(int aX, int aY, int aZ) { + public final int getMetaIDOffset(int aX, int aY, int aZ) { return this.getMetaID(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ); } @Override - public final byte getMetaIDAtSide(ForgeDirection side) { + public final int getMetaIDAtSide(ForgeDirection side) { return this.getMetaIDAtSideAndDistance(side, 1); } @Override - public final byte getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance) { + public final int getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance) { return this.getMetaID( this.getOffsetX(side, aDistance), this.getOffsetY(side, aDistance), @@ -750,7 +750,7 @@ public final Block getBlock(int aX, int aY, int aZ) { } @Override - public final byte getMetaID(int aX, int aY, int aZ) { + public final int getMetaID(int aX, int aY, int aZ) { return this.ignoreUnloadedChunks && this.crossedChunkBorder(aX, aZ) && !this.worldObj.blockExists(aX, aY, aZ) ? 0 : (byte) this.worldObj.getBlockMetadata(aX, aY, aZ); diff --git a/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java b/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java index 55bb39bd3e5..0e4f003a271 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() { @@ -127,30 +117,10 @@ protected synchronized void setVars(FMLPreInitializationEvent event) { /* * 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; - } + // WorldGen_GT_Base.oreveinPercentage = 64; 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/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 index 9153264185a..33107781879 100644 --- 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 @@ -1,494 +1,16 @@ 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 class WorldGen_GT_Ore_Layer { 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 index 87c89b5d203..12f7df12657 100644 --- a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java +++ b/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java @@ -246,30 +246,5 @@ public class WorldGen_Ores { 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 c42061478db..9e8b85a2ffe 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java @@ -9,7 +9,6 @@ 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; @@ -27,7 +26,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/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java index 0f9fa3497e7..9087eb5ed72 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java @@ -303,7 +303,7 @@ public boolean checkForWater() { for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { for (int h = 0; h < 2; ++h) { Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + int tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == Blocks.water) { if (this.getStoredFluids() != null) { for (FluidStack stored : this.getStoredFluids()) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java index d98e53e2da4..93f2e92bd95 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java @@ -316,7 +316,7 @@ private boolean checkForWater() { for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { for (int h = 0; h < 2; h++) { Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + int tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); if (isNotStaticWater(tBlock, tMeta)) { if (this.getStoredFluids() != null) { for (FluidStack stored : this.getStoredFluids()) { @@ -350,7 +350,7 @@ private boolean checkForWater() { return tAmount >= 60; } - private boolean isNotStaticWater(Block block, byte meta) { + private boolean isNotStaticWater(Block block, int meta) { return block == Blocks.air || block == Blocks.flowing_water || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java index 779148199e4..e6a70c320ba 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java @@ -262,7 +262,7 @@ public boolean checkForWater() { for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { for (int h = 0; h < 2; h++) { Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + int tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); if (isNotStaticWater(tBlock, tMeta)) { if (this.getStoredFluids() != null) { for (FluidStack stored : this.getStoredFluids()) { @@ -301,7 +301,7 @@ public boolean checkForWater() { } } - private boolean isNotStaticWater(Block block, byte meta) { + private boolean isNotStaticWater(Block block, int meta) { return block == Blocks.air || block == Blocks.flowing_water || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 0cbf255fa56..b2d2f1ecf76 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -165,7 +165,7 @@ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlaye private void checkMachineProblem(String msg, int xOff, int yOff, int zOff) { final IGregTechTileEntity te = this.getBaseMetaTileEntity(); final Block tBlock = te.getBlockOffset(xOff, yOff, zOff); - final byte tMeta = te.getMetaIDOffset(xOff, yOff, zOff); + final int tMeta = te.getMetaIDOffset(xOff, yOff, zOff); String name = tBlock.getLocalizedName(); String problem = msg + ": (" + xOff + ", " + yOff + ", " + zOff + ") " + name + ":" + tMeta; checkMachineProblem(problem); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java index fceebe62d37..4e0510bf333 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java @@ -380,7 +380,7 @@ public Block getBlockAtSide(ForgeDirection side) { } @Override - public byte getMetaIDAtSide(ForgeDirection side) { + public int getMetaIDAtSide(ForgeDirection side) { return getBaseMetaTileEntity().getMetaIDAtSide(side); } diff --git a/src/main/java/gtneioreplugin/GTNEIOrePlugin.java b/src/main/java/gtneioreplugin/GTNEIOrePlugin.java index 5c970fd032a..469cf9a9710 100644 --- a/src/main/java/gtneioreplugin/GTNEIOrePlugin.java +++ b/src/main/java/gtneioreplugin/GTNEIOrePlugin.java @@ -4,6 +4,7 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; @@ -17,9 +18,13 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLLoadCompleteEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gregtech.GT_Version; +import gregtech.api.enums.Materials; +import gregtech.common.ores.GTOreAdapter; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.NEIPluginConfig; import gtneioreplugin.plugin.block.ModBlocks; import gtneioreplugin.util.CSVMaker; @@ -49,10 +54,18 @@ public class GTNEIOrePlugin { public static File instanceDir; public static final CreativeTabs creativeTab = new CreativeTabs(MODID) { + @SideOnly(Side.CLIENT) + public ItemStack getIconItemStack() { + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = Materials.Manyullyn; + + return OreManager.getStack(info, 1); + } + }; + @Override public Item getTabIconItem() { - return GameRegistry.makeItemStack("gregtech:gt.blockores", 386, 1, null) - .getItem(); + return Item.getItemFromBlock(GTOreAdapter.INSTANCE.ores1); } }; diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java index 51e39247048..6687ac83565 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -1,25 +1,24 @@ package gtneioreplugin.plugin.gregtech5; import net.minecraft.client.resources.I18n; - import codechicken.lib.gui.GuiDraw; import gregtech.api.enums.Materials; -import gregtech.api.util.GTLanguageManager; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.api.interfaces.IMaterial; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.PluginBase; public abstract class PluginGT5Base extends PluginBase { - public static String getGTOreLocalizedName(Materials ore, boolean small) { + protected static String getGTOreLocalizedName(IMaterial ore, boolean small) { if (ore == Materials.DraconiumAwakened) return "Aw. Draconium Ore"; - String name = GTLanguageManager.getTranslation(getGTOreUnlocalizedName(ore, small)); - return ore.getLocalizedNameForItem(name); - } + try (OreInfo info = OreInfo.getNewInfo()) { + info.material = ore; + info.isSmall = small; - protected static String getGTOreUnlocalizedName(Materials ore, boolean small) { - return "gt.blockores2." + BlockOres2.getMeta(StoneType.Stone, ore.mMetaItemSubID, small, false) + ".name"; + return OreManager.getLocalizedName(info); + } } static void drawLine(String lineKey, String value, int x, int y) { diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java index c0c23536a2b..0e8bfef6c57 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java @@ -7,12 +7,11 @@ import net.minecraft.item.ItemStack; import codechicken.nei.PositionedStack; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.util.GTOreDictUnificator; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.ItemOres2; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IMaterial; +import gregtech.common.ores.IOreAdapter; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.item.ItemDimensionDisplay; import gtneioreplugin.util.GT5OreSmallHelper; import gtneioreplugin.util.GT5OreSmallHelper.OreSmallWrapper; @@ -39,7 +38,7 @@ private void drawSmallOreName(OreSmallWrapper oreSmall) { 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); } @@ -48,23 +47,27 @@ private OreSmallWrapper getSmallOre(int recipe) { return GT5OreSmallHelper.SMALL_ORES_BY_NAME.get(crecipe.oreGenName); } - public int getRestrictBiomeOffset() { - return GT5OreSmallHelper.restrictBiomeSupport ? 0 : -13; - } - @Override public void loadCraftingRecipes(String outputId, Object... results) { - if (outputId.equals(getOutputId())) - for (ItemStack stack : GT5OreSmallHelper.SMALL_ORE_LIST) 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.getItem() instanceof ItemOres2) { - loadSmallOre(BlockOres2.getMaterial(stack.getItemDamage())); - } else if (GT5OreSmallHelper.ORE_DROP_TO_MAT.containsKey(stack.getUnlocalizedName())) { - loadSmallOre(GT5OreSmallHelper.ORE_DROP_TO_MAT.get(stack.getUnlocalizedName())); + IMaterial mat = OreManager.getMaterial(stack); + + if (mat == null) { + mat = GT5OreSmallHelper.ORE_DROP_TO_MAT.get(stack.getUnlocalizedName()); + } + + if (mat != null) { + loadSmallOre(mat); } else { super.loadCraftingRecipes(stack); } @@ -80,14 +83,14 @@ public void loadUsageRecipes(ItemStack stack) { } } - private void loadSmallOre(Materials material) { + private void loadSmallOre(IMaterial material) { OreSmallWrapper smallOre = getSmallOre(material); if (smallOre != null) { addSmallOre(smallOre); } } - private OreSmallWrapper getSmallOre(Materials material) { + private OreSmallWrapper getSmallOre(IMaterial material) { for (OreSmallWrapper oreSmallWorldGen : GT5OreSmallHelper.SMALL_ORES_BY_NAME.values()) { if (oreSmallWorldGen.material == material) { return oreSmallWorldGen; @@ -97,22 +100,32 @@ private OreSmallWrapper getSmallOre(Materials material) { } private void addSmallOre(OreSmallWrapper smallOre) { - this.arecipes.add( - new CachedOreSmallRecipe( - smallOre.oreGenName, - smallOre.getMaterialDrops(), - getStoneDusts(), - GT5OreSmallHelper.ORE_MAT_TO_DROPS.get(smallOre.material))); - } - private List getStoneDusts() { - List stoneDusts = new ArrayList<>(); + 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) { - stoneDusts.add(GTOreDictUnificator.get(OrePrefixes.dust, stoneType.material, 1)); + 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 stoneDusts; + this.arecipes.add( + new CachedOreSmallRecipe( + smallOre.oreGenName, + ores, + dusts, + GT5OreSmallHelper.ORE_MAT_TO_DROPS.get(smallOre.material))); } @Override @@ -140,11 +153,12 @@ public CachedOreSmallRecipe(String oreGenName, List stackList, 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(); } diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index 4d8b9264729..6701e4a32a8 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -10,9 +10,8 @@ import net.minecraft.item.ItemStack; import codechicken.nei.PositionedStack; -import gregtech.api.enums.Materials; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.ItemOres2; +import gregtech.api.interfaces.IMaterial; +import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.item.ItemDimensionDisplay; import gtneioreplugin.util.DimensionHelper; import gtneioreplugin.util.GT5OreLayerHelper; @@ -34,14 +33,15 @@ public void loadCraftingRecipes(String outputId, Object... results) { @Override public void loadCraftingRecipes(ItemStack stack) { - if (stack.getItem() instanceof ItemOres2) { - loadMatchingVeins(BlockOres2.getMaterial(stack.getItemDamage())); + IMaterial mat = OreManager.getMaterial(stack); + if (mat != null) { + loadMatchingVeins(mat); } else { super.loadCraftingRecipes(stack); } } - private void loadMatchingVeins(Materials ore) { + private void loadMatchingVeins(IMaterial ore) { for (OreLayerWrapper oreVein : getAllVeins()) { if (oreVein.containsOre(ore)) { addVeinWithLayers(oreVein); @@ -135,14 +135,8 @@ 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))); + String[] dims = GT5OreLayerHelper.bufferedDims.get(oreLayer).toArray(new String[0]); + Arrays.sort(dims, Comparator.comparingInt(s -> Arrays.asList(DimensionHelper.DimNameDisplayed).indexOf(s))); return dims; } 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 b477903d160..78e3fd9c68f 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. @@ -29,7 +29,7 @@ public void runSmallOres() { GT5OreSmallHelper.OreSmallWrapper oreLayer = pair.getValue(); oremix.setOreName(oreLayer.oreGenName); - oremix.setOreMeta(oreLayer.material.mMetaItemSubID); + oremix.setOreMaterial(oreLayer.material.getInternalName()); oremix.setHeight(oreLayer.worldGenHeightRange); oremix.setAmount(oreLayer.amountPerChunk); oremix.setDims(oreLayer.enabledDims); @@ -73,24 +73,24 @@ public void runVeins() { Oremix oremix = new Oremix(); Map.Entry pair = it.next(); - Map Dims = GT5OreLayerHelper.bufferedDims.get(pair.getValue()); + Set Dims = GT5OreLayerHelper.bufferedDims.get(pair.getValue()); OreLayerWrapper oreLayer = pair.getValue(); oremix.setOreMixName(oreLayer.veinName); - oremix.setPrimary(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.ores[0], false)); - oremix.setSecondary(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.ores[1], false)); - oremix.setInbetween(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.ores[2], false)); - oremix.setSporadic(PluginGT5VeinStat.getGTOreLocalizedName(oreLayer.ores[3], false)); + 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.ores[0].mMetaItemSubID) + "|" - + Integer.toString(oreLayer.ores[1].mMetaItemSubID) + oreLayer.ores[0].getInternalName() + "|" + + oreLayer.ores[1].getInternalName() + "|" - + Integer.toString(oreLayer.ores[2].mMetaItemSubID) + + oreLayer.ores[2].getInternalName() + "|" - + Integer.toString(oreLayer.ores[3].mMetaItemSubID)); + + 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 4020e19d30b..6a993e0c506 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -1,5 +1,10 @@ package gtneioreplugin.util; +import static galacticgreg.api.enums.DimensionDef.DimNames.OW; +import static galacticgreg.api.enums.DimensionDef.DimNames.NETHER; +import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; +import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; +import static galacticgreg.api.enums.DimensionDef.DimNames.EVERGLADES; import static galacticgreg.api.enums.DimensionDef.DimNames.ANUBIS; import static galacticgreg.api.enums.DimensionDef.DimNames.ASTEROIDS; import static galacticgreg.api.enums.DimensionDef.DimNames.BARNARDC; @@ -41,19 +46,19 @@ 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", "TheEnd", "EndAsteroid", "dimensionDarkWorld", // T1 "GalacticraftCore_Moon", // T2 @@ -95,6 +100,7 @@ public class DimensionHelper { "TF", // Twilight "ED", // TheEnd because En = Encalus "EA", // EndAsteroid + "Eg", // Everglades // T1 "Mo", // GalacticraftCore_Moon // T2 @@ -194,16 +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); + enabledDims.add(abbr); } return enabledDims; } @@ -211,11 +217,12 @@ public static Map getDims(GT5OreLayerHelper.OreLayerWrapper 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 OW -> abbreviatedName = "Ow"; // Overworld + case NETHER -> abbreviatedName = "Ne"; // Nether + case TWILIGHT_FOREST -> abbreviatedName = "TF"; // Twilight + case THE_END -> abbreviatedName = "ED"; // TheEnd because En = Encalus case ENDASTEROIDS -> abbreviatedName = "EA"; // EndAsteroid + case EVERGLADES -> abbreviatedName = "Eg"; // T1 case MOON -> abbreviatedName = "Mo"; // GalacticraftCore_Moon // T2 @@ -273,10 +280,10 @@ public static String getDimAbbreviatedName(String dimName) { public static String getFullName(String dimName) { 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 "Ow" -> OW; // Overworld + case "Ne" -> NETHER; // Nether + case "TF" -> TWILIGHT_FOREST; // Twilight + case "ED" -> THE_END; // TheEnd because En = Encalus case "EA" -> ENDASTEROIDS; // EndAsteroid // T1 case "Mo" -> MOON; // GalacticraftCore_Moon diff --git a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java index 6fd3f2f5ff7..69795ac5402 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -4,28 +4,26 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.Objects; +import java.util.Set; import net.minecraft.item.ItemStack; -import gregtech.api.enums.Materials; import gregtech.api.enums.OreMixes; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneType; import gregtech.common.OreMixBuilder; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; public class GT5OreLayerHelper { - 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> bufferedDims = new HashMap<>(); public static final HashMap dimToOreWrapper = new HashMap<>(); 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)); } @@ -39,7 +37,7 @@ public static void init() { // Get dims as "Ow,Ne,Ma" etc. bufferedDims.forEach((veinInfo, dims) -> { - for (String dim : dims.keySet()) { + for (String dim : dims) { NormalOreDimensionWrapper dimensionOres = dimToOreWrapper .getOrDefault(dim, new NormalOreDimensionWrapper()); dimensionOres.internalDimOreList.add(veinInfo); @@ -58,14 +56,14 @@ public static void init() { public static class OreLayerWrapper { public final String veinName, worldGenHeightRange, localizedName; - public final Materials[] ores = new Materials[4]; + public final IMaterial[] ores = new IMaterial[4]; public final short randomWeight, size, density; - public final Map allowedDimWithOrigNames; + public final Set allowedDimWithOrigNames; - public final Materials mPrimaryVeinMaterial; - public final Materials mSecondaryMaterial; - public final Materials mBetweenMaterial; - public final Materials mSporadicMaterial; + public final IMaterial mPrimaryVeinMaterial; + public final IMaterial mSecondaryMaterial; + public final IMaterial mBetweenMaterial; + public final IMaterial mSporadicMaterial; public OreLayerWrapper(OreMixBuilder mix) { this.veinName = mix.oreMixName; @@ -90,17 +88,22 @@ public OreLayerWrapper(OreMixBuilder mix) { public List getVeinLayerOre(int veinLayer) { List stackList = new ArrayList<>(); - for (StoneType stoneType : StoneType.STONE_TYPES) { + for (StoneType stoneType : StoneType.VISUAL_STONE_TYPES) { stackList.add(getLayerOre(veinLayer, stoneType)); } return stackList; } - public ItemStack getLayerOre(int veinLayer, StoneType stoneType) { - return BlockOres2.getStack(stoneType, ores[veinLayer], false, false, 1); + 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(Materials material) { + public boolean containsOre(IMaterial material) { return ores[OreVeinLayer.VEIN_PRIMARY] == material || ores[OreVeinLayer.VEIN_SECONDARY] == material || ores[OreVeinLayer.VEIN_BETWEEN] == material diff --git a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java index 4373589f0fa..ed2993d9eca 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java @@ -13,21 +13,21 @@ import net.minecraft.item.ItemStack; import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; import gregtech.api.enums.SmallOres; +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IMaterial; import gregtech.api.world.GTWorldgen; import gregtech.common.SmallOreBuilder; import gregtech.common.WorldgenGTOreSmallPieces; -import gregtech.common.blocks.BlockOres2; -import gregtech.common.blocks.BlockOres2.StoneType; +import gregtech.common.ores.OreInfo; +import gregtech.common.ores.OreManager; public class GT5OreSmallHelper { - public static boolean restrictBiomeSupport = false; public static final List SMALL_ORE_LIST = new ArrayList<>(); public static final HashMap SMALL_ORES_BY_NAME = new HashMap<>(); - public static final HashMap ORE_DROP_TO_MAT = new HashMap<>(); - public static final HashMap> ORE_MAT_TO_DROPS = 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} */ public static final HashMap SMALL_ORES_BY_DIM = new HashMap<>(); @@ -40,11 +40,13 @@ public static void init() { Multimap oreSpawning = MultimapBuilder.hashKeys().arrayListValues().build(); + OreInfo info = OreInfo.getNewInfo(); + for (GTWorldgen worldGen : GregTechAPI.sWorldgenList) { if (!worldGen.mWorldGenName.startsWith("ore.small.")) continue; if (!(worldGen instanceof WorldgenGTOreSmallPieces smallOreWorldGen)) continue; - Materials material = smallOreWorldGen.mMaterial; + IMaterial material = smallOreWorldGen.mMaterial; OreSmallWrapper wrapper = new OreSmallWrapper(smallOreDefMap.get(smallOreWorldGen.mWorldGenName)); SMALL_ORES_BY_NAME.put(worldGen.mWorldGenName, wrapper); @@ -57,7 +59,11 @@ public static void init() { oreSpawning.put(abbrDimName, wrapper); } - List stackList = BlockOres2.getPotentialDrops(material, true); + info.stoneType = null; + info.material = material; + info.isSmall = true; + + List stackList = OreManager.getPotentialDrops(info); ORE_MAT_TO_DROPS.put(material, stackList); @@ -65,11 +71,12 @@ public static void init() { ORE_DROP_TO_MAT.put(stack.getUnlocalizedName(), material); } - for (StoneType stoneType : StoneType.STONE_TYPES) { - SMALL_ORE_LIST.add(BlockOres2.getStack(stoneType, material, true, true, 1)); - } + info.stoneType = null; + SMALL_ORE_LIST.add(OreManager.getStack(info, 1)); } + info.release(); + for (String abbrDimName : oreSpawning.keySet()) { SMALL_ORES_BY_DIM.put(abbrDimName, new SmallOreDimensionWrapper()); } @@ -85,7 +92,7 @@ public static class OreSmallWrapper { public final SmallOreBuilder builder; public final String oreGenName; - public final Materials material; + public final IMaterial material; public final String worldGenHeightRange; public final short amountPerChunk; @@ -114,11 +121,17 @@ public OreSmallWrapper(SmallOreBuilder ore) { } } - public List getMaterialDrops() { + public List getOreVariants() { List oreVariants = new ArrayList<>(); - for (StoneType stoneType : StoneType.STONE_TYPES) { - oreVariants.add(BlockOres2.getStack(stoneType, material, true, false, 1)); + 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; diff --git a/src/main/java/gtneioreplugin/util/Oremix.java b/src/main/java/gtneioreplugin/util/Oremix.java index be6826110e2..45b158886c6 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; } @@ -113,7 +113,7 @@ public String getCsvEntry() { 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)); + .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 66da646f6cc..ea0ae7a0bdd 100644 --- a/src/main/java/gtneioreplugin/util/SmallOre.java +++ b/src/main/java/gtneioreplugin/util/SmallOre.java @@ -9,7 +9,7 @@ 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 @@ -28,12 +28,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() { @@ -67,7 +67,7 @@ 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++) { 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..8fa8983cc27 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java @@ -18,9 +18,8 @@ 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 +393,23 @@ 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; + + var p = OreManager.getOreInfo(b, tDamage); + + if (p != null) { + try (OreInfo info = p.right()) { + info.isNatural = true; + + var oreBlock = p.left().getBlock(info); + + world.setBlock(x, y, z, oreBlock.left(), oreBlock.rightInt(), 3); + + if (world.getBlock(x, y, z) == oreBlock.left() && world.getBlockMetadata(x, y, z) == oreBlock.rightInt()) 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 0ab4c5e8b67..ffdf2020ccf 100644 --- a/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java +++ b/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java @@ -355,19 +355,19 @@ 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.oreVeinProbabilities.forEach( - (veinInfo, - probability) -> processHelper(outputMap, veinInfo.material, 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/resources/assets/gtneioreplugin/lang/en_US.lang b/src/main/resources/assets/gtneioreplugin/lang/en_US.lang index c8437cc9306..e219982921a 100644 --- a/src/main/resources/assets/gtneioreplugin/lang/en_US.lang +++ b/src/main/resources/assets/gtneioreplugin/lang/en_US.lang @@ -45,6 +45,7 @@ gtnop.world.TheEnd=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 From babf488d0eaea770483d711ce4448bc02e3e28e0 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 8 Dec 2024 01:38:59 -0500 Subject: [PATCH 04/47] asteroids --- .../bartworks/system/material/Werkstoff.java | 14 + ...BehaviourDetravToolElectricProspector.java | 1 + .../java/galacticgreg/SpaceDimRegisterer.java | 33 +- .../galacticgreg/WorldGeneratorSpace.java | 391 ++++++------ src/main/java/galacticgreg/WorldgenGaGT.java | 28 - .../galacticgreg/WorldgenOreLayerSpace.java | 333 ----------- .../galacticgreg/WorldgenOreSmallSpace.java | 116 ---- .../galacticgreg/api/ModDimensionDef.java | 278 ++++----- .../galacticgreg/api/enums/DimensionDef.java | 54 +- .../api/enums/properties/Asteroids.java | 8 +- .../registry/GalacticGregRegistry.java | 6 +- .../java/gregtech/api/enums/GTValues.java | 4 + .../java/gregtech/api/enums/Materials.java | 29 + .../java/gregtech/api/enums/OreMixes.java | 55 +- .../java/gregtech/api/enums/OrePrefixes.java | 16 + .../java/gregtech/api/enums/SmallOres.java | 5 - .../gregtech/api/enums/StoneCategory.java | 8 + .../java/gregtech/api/enums/StoneType.java | 25 +- src/main/java/gregtech/api/enums/SubTag.java | 4 + .../gregtech/api/interfaces/IMaterial.java | 5 + .../api/interfaces/IStoneCategory.java | 5 + .../gregtech/api/interfaces/IStoneType.java | 1 + .../gregtech/common/GTWorldgenerator.java | 557 +++++++----------- .../java/gregtech/common/OreMixBuilder.java | 15 + .../java/gregtech/common/SmallOreBuilder.java | 19 +- .../gregtech/common/WorldgenGTOreLayer.java | 103 +++- .../common/WorldgenGTOreSmallPieces.java | 80 ++- .../java/gregtech/common/WorldgenStone.java | 2 +- .../common/blocks/BlockOresAbstract.java | 52 +- .../gregtech/common/ores/GTOreAdapter.java | 38 +- .../gregtech/common/ores/IOreAdapter.java | 2 +- .../common/worldgen/IWorldgenLayer.java | 25 + .../common/worldgen/WorldgenQuery.java | 183 ++++++ .../loaders/materials/MaterialsInit1.java | 2 +- .../loaders/oreprocessing/ProcessingOre.java | 10 +- .../oreprocessing/ProcessingRawOre.java | 10 +- .../loaders/postload/GTWorldgenloader.java | 4 +- .../gtPlusPlus/core/material/Material.java | 14 + .../plugin/gregtech5/PluginGT5VeinStat.java | 6 +- .../gtneioreplugin/util/DimensionHelper.java | 8 +- .../util/GT5OreLayerHelper.java | 8 +- .../assets/gtneioreplugin/lang/en_US.lang | 2 +- .../assets/gtneioreplugin/lang/zh_CN.lang | 2 +- 43 files changed, 1291 insertions(+), 1270 deletions(-) delete mode 100644 src/main/java/galacticgreg/WorldgenGaGT.java delete mode 100644 src/main/java/galacticgreg/WorldgenOreLayerSpace.java delete mode 100644 src/main/java/galacticgreg/WorldgenOreSmallSpace.java create mode 100644 src/main/java/gregtech/api/enums/StoneCategory.java create mode 100644 src/main/java/gregtech/api/interfaces/IStoneCategory.java create mode 100644 src/main/java/gregtech/common/worldgen/IWorldgenLayer.java create mode 100644 src/main/java/gregtech/common/worldgen/WorldgenQuery.java diff --git a/src/main/java/bartworks/system/material/Werkstoff.java b/src/main/java/bartworks/system/material/Werkstoff.java index b3b6785bee1..e59fc2e9f03 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -31,6 +31,8 @@ import java.util.Objects; import java.util.Optional; +import com.google.common.collect.ImmutableList; + import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -49,11 +51,13 @@ 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.IMaterial; +import gregtech.api.interfaces.IStoneType; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.util.GTLanguageManager; import gregtech.api.util.GTOreDictUnificator; @@ -536,6 +540,16 @@ public int getId() { return mID; } + @Override + public boolean isValidForStone(IStoneType stoneType) { + return stoneType == StoneType.Stone; + } + + @Override + public ImmutableList getValidStones() { + return StoneType.STONE_ONLY; + } + @Override public String getInternalName() { return getVarName(); diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java index ab348710037..e85ec7ab102 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -157,6 +157,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); diff --git a/src/main/java/galacticgreg/SpaceDimRegisterer.java b/src/main/java/galacticgreg/SpaceDimRegisterer.java index 7a75d12e60a..ceb9690ff8e 100644 --- a/src/main/java/galacticgreg/SpaceDimRegisterer.java +++ b/src/main/java/galacticgreg/SpaceDimRegisterer.java @@ -2,12 +2,9 @@ import net.minecraft.init.Blocks; -import galacticgreg.api.AsteroidBlockComb; import galacticgreg.api.Enums; -import galacticgreg.api.GTOreTypes; import galacticgreg.api.ModContainer; import galacticgreg.api.SpecialBlockComb; -import galacticgreg.api.Enums.AllowedBlockPosition; import galacticgreg.api.enums.DimensionDef; import galacticgreg.api.enums.ModContainers; import galacticgreg.registry.GalacticGregRegistry; @@ -36,10 +33,10 @@ 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(StoneType.Netherrack)); - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.RedGranite)); - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.BlackGranite)); - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Endstone)); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(StoneType.Netherrack); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(StoneType.RedGranite); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(StoneType.Endstone); // These Blocks will randomly be generated DimensionDef.EndAsteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.glowstone)); @@ -62,16 +59,12 @@ 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(StoneType.BlackGranite)); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.RedGranite)); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Moon)); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Asteroid)); - DimensionDef.Asteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.packed_ice, AllowedBlockPosition.AsteroidCoreAndShell)); - DimensionDef.Asteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.ice, AllowedBlockPosition.AsteroidCoreAndShell)); + 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); @@ -124,10 +117,8 @@ private static ModContainer setupGalaxySpace() { ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Miranda.modDimensionDef); DimensionDef.KuiperBelt.modDimensionDef.setDimensionType(Enums.DimensionType.Asteroid); - DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.RedGranite)); - DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.BlackGranite)); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Moon)); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(StoneType.Asteroid)); + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(StoneType.RedGranite); + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.KuiperBelt.modDimensionDef); @@ -145,8 +136,10 @@ private static ModContainer setupAmunRa() { ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Seth.modDimensionDef); DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); + DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(StoneType.Horus); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(StoneType.Asteroid); ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.MehenBelt.modDimensionDef); - + return ModContainers.AmunRa.modContainer; } } diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 8f6a7cc7b3e..bb73782660d 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -2,18 +2,17 @@ import java.util.Random; -import net.minecraft.block.Block; +import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; +import net.minecraft.util.MathHelper; 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 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; @@ -22,67 +21,90 @@ import galacticgreg.api.ModDimensionDef; import galacticgreg.api.SpecialBlockComb; import galacticgreg.api.StructureInformation; -import galacticgreg.auxiliary.GTOreGroup; +import galacticgreg.api.enums.DimensionDef; +import galacticgreg.api.enums.DimensionDef.DimNames; import galacticgreg.dynconfig.DynamicDimensionConfig; -import galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; -import gregtech.api.util.GTLog; -import gregtech.api.world.GTWorldgen; -import gregtech.common.GTWorldgenerator; +import gregtech.api.objects.XSTR; +import gregtech.common.WorldgenGTOreLayer; +import gregtech.common.config.Worldgen; import gregtech.common.ores.OreManager; +import gregtech.common.worldgen.IWorldgenLayer; +import gregtech.common.worldgen.WorldgenQuery; public class WorldGeneratorSpace implements IWorldGenerator { private long mProfilingStart; private long mProfilingEnd; + private static boolean generateEndAsteroids = true; + private static int mEndAsteroidProbability = 300; + private static int mEndAsteroidMinSize = 50; + private static int mEndAsteroidMaxSize = 200; + public WorldGeneratorSpace() { GameRegistry.registerWorldGenerator(this, Integer.MAX_VALUE); + + generateEndAsteroids = Worldgen.endAsteroids.generateEndAsteroids; + mEndAsteroidProbability = Worldgen.endAsteroids.EndAsteroidProbability; + mEndAsteroidMinSize = Worldgen.endAsteroids.EndAsteroidMinSize; + mEndAsteroidMaxSize = Worldgen.endAsteroids.EndAsteroidMaxSize; } + private static final int END_ASTEROID_DISTANCE = 16; + @Override public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { + + int cX = pX; + int cZ = pZ; pX *= 16; pZ *= 16; - 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); + .trace("Triggered generate: [ChunkGenerator %s]", pChunkGenerator.toString()); - ModDimensionDef tDimDef = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); + ModDimensionDef tDimDef = DimensionDef.getDefForWorld(pWorld); + + if (tDimDef.getDimensionName().equals(DimNames.THE_END)) { + if (pX * pX + pZ * pZ > END_ASTEROID_DISTANCE * END_ASTEROID_DISTANCE) { + tDimDef = DimensionDef.EndAsteroids.modDimensionDef; + } + } 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", + pWorld.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 generateAsteroids(tDimDef, pRandom, pWorld, pX, pZ); - } else if (tDimDef.getDimensionType() != Enums.DimensionType.Asteroid) { - generateOreVeins(tDimDef, pRandom, pWorld, pX, pZ, "", pChunkGenerator, pChunkProvider); - } + if (tDimDef.getDimensionType() == Enums.DimensionType.Asteroid) { + if (tDimDef.getDimensionName().equals(DimNames.ENDASTEROIDS) && generateEndAsteroids) { + XSTR random = new XSTR( + pWorld.getSeed() + cX * cX * 91777L + cZ * cZ * 137413L + cX * cZ * 1853L + cX * 3L + cZ * 17L); - Chunk tChunk = pWorld.getChunkFromBlockCoords(pX, pZ); - if (tChunk != null) { - tChunk.isModified = true; + if (mEndAsteroidProbability <= 1 || random.nextInt(mEndAsteroidProbability) == 0) { + generateEndAsteroid(tDimDef, pWorld, random, cX, cZ); + } + } else 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 { + generateAsteroids(tDimDef, pRandom, pWorld, pX, pZ); + } + + Chunk tChunk = pWorld.getChunkFromBlockCoords(pX, pZ); + if (tChunk != null) { + tChunk.isModified = true; + } } } @@ -106,26 +128,47 @@ private void generateAsteroids(ModDimensionDef pDimensionDef, Random pRandom, Wo if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); // ----------------------------- + AsteroidBlockComb asteroidStone = pDimensionDef.getRandomAsteroidMaterial(); + if (asteroidStone == null) return; + + // Select Random OreGroup and Asteroid Material + IWorldgenLayer oreLayer; + + int minY, maxY; + + if (pRandom.nextInt(5) == 0) { + oreLayer = WorldgenQuery.small() + .inDimension(pDimensionDef) + .inStone(asteroidStone.getStone().getCategory()) + .find(pRandom); + + minY = oreLayer == null ? 50 : oreLayer.getMinY(); + maxY = oreLayer == null ? 200 : oreLayer.getMaxY(); + } else { + oreLayer = WorldgenQuery.veins() + .inDimension(pDimensionDef) + .inStone(asteroidStone.getStone().getCategory()) + .find(pRandom); + + minY = oreLayer == null ? 50 : oreLayer.getMinY(); + maxY = oreLayer == null ? 200 : oreLayer.getMaxY(); + } + + if (oreLayer == null) return; + // Get Random position int tX = pX + pRandom.nextInt(16); - int tY = 50 + pRandom.nextInt(200 - 50); + int tY = minY + pRandom.nextInt(maxY - minY); int tZ = pZ + pRandom.nextInt(16); + GalacticGreg.Logger.debug( + "Asteroid will be build with: Stone: [%s] Ore: [%s]", + asteroidStone.getStone(), + oreLayer.getName()); + // Check if position is free if (pWorld.isAirBlock(tX, tY, tZ)) { - // Select Random OreGroup and Asteroid Material - GTOreGroup oreGroup = WorldgenOreLayerSpace.getRandomOreGroup(pDimensionDef, pRandom, true); - - AsteroidBlockComb asteroidStone = pDimensionDef.getRandomAsteroidMaterial(); - if (asteroidStone == null) return; - - GalacticGreg.Logger.debug( - "Asteroid will be build with: Block: [%s] OreType: [%s]", - Block.blockRegistry.getNameForObject(asteroidStone.getBlock()), - asteroidStone.getStone() - .toString()); - // get random Ore-asteroid generator from the list of registered generators ISpaceObjectGenerator aGen = pDimensionDef.getRandomSOGenerator(Enums.SpaceObjectType.OreAsteroid); if (aGen == null) { @@ -138,7 +181,7 @@ private void generateAsteroids(ModDimensionDef pDimensionDef, Random pRandom, Wo aGen.reset(); aGen.setCenterPoint(tX, tY, tZ); - aGen.randomize(dimAsteroidConfig.MinSize, dimAsteroidConfig.MaxSize); // Initialize random values and set size + aGen.randomize((int) oreLayer.getSize(), (int) oreLayer.getSize() * 2); // Initialize random values and set size aGen.calculate(); // Calculate structure // Random loot-chest somewhere in the asteroid @@ -248,63 +291,26 @@ private void generateAsteroids(ModDimensionDef pDimensionDef, Random pRandom, Wo } // << Loot-chest generator === - // === Ore generator >> boolean tPlacedAnything = false; - // If a valid oregroup has been selected (more than 0 ore-veins are enabled for this dim) - if (oreGroup != null) { - // GalacticGreg.Logger.trace("tOreGroup is populated, continuing"); - // Choose a number between 0 and 100 - int ranOre = pRandom.nextInt(100); - IMaterial ore = null; - - // If chosen number is below the configured orechance, do random between and sporadic - if (ranOre < dimAsteroidConfig.OreChance) { - if (pRandom.nextBoolean()) { - // Only take as final value if meta is not zero - if (oreGroup.SporadicBetween != null) - ore = oreGroup.SporadicBetween; - } else { - // Only take as final value if meta is not zero - if (oreGroup.SporadicAround != null) ore = oreGroup.SporadicAround; - } - } - // If chosen 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 < dimAsteroidConfig.OreChance + dimAsteroidConfig.OrePrimaryOffset) { - if (pRandom.nextBoolean()) { - // Only take as final value if meta is not zero - if (oreGroup.Primary != null) ore = oreGroup.Primary; - } else { - // Only take as final value if meta is not zero - if (oreGroup.Secondary != null) ore = oreGroup.Secondary; - } - } - // if the final oreMeta has been found... - // GalacticGreg.Logger.info("tFinalOreMeta is %d", tFinalOreMeta); - if (ore != null) { - // make sure we obey the configured "HiddenOres" setting (No ores on the shell) - if (dimAsteroidConfig.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 - tPlacedAnything = OreManager.setOreForWorldGen( - pWorld, - si.getX(), - si.getY(), - si.getZ(), - asteroidStone.getStone(), - oreGroup.Secondary, - false); - } + boolean canPlaceOre = !dimAsteroidConfig.HiddenOres || si.getBlockPosition() == Enums.TargetBlockPosition.AsteroidShell; + + // try to place big ores, if the ore vein creates big ore + if (canPlaceOre && oreLayer.generatesBigOre()) { + if (!tPlacedAnything) { + tPlacedAnything = generateOreBlock( + pRandom, + pWorld, + si.getX(), + si.getY(), + si.getZ(), + asteroidStone, + oreLayer, + false); } } - // << Ore generator === - - // === Additional special blocks >> + // try to place any special blocks if (!tPlacedAnything) { tPlacedAnything = generateSpecialBlocks( pDimensionDef, @@ -317,18 +323,19 @@ else if (ranOre < dimAsteroidConfig.OreChance + dimAsteroidConfig.OrePrimaryOffs si.getBlockPosition()); } - - // No special block placed? Try smallores - if (!tPlacedAnything) { - tPlacedAnything = generateSmallOreBlock( - pDimensionDef, - pRandom, - pWorld, - dimAsteroidConfig, - si.getX(), - si.getY(), - si.getZ(), - asteroidStone); + // try to place small ores + if (canPlaceOre) { + if (!tPlacedAnything) { + tPlacedAnything = generateOreBlock( + pRandom, + pWorld, + si.getX(), + si.getY(), + si.getZ(), + asteroidStone, + oreLayer, + true); + } } // no smallores either? do normal block @@ -416,109 +423,95 @@ private boolean generateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRan return false; } - /** - * Pick a random small-ore block from the list of enabled small ores for this dim - * - * @param pDimDef - * @param pRandom - * @return - */ - private boolean generateSmallOreBlock(ModDimensionDef pDimDef, Random pRandom, World pWorld, - DynamicDimensionConfig.AsteroidConfig pAConf, int pX, int pY, int pZ, AsteroidBlockComb asteroidStone) { - // If smallores are enabled... - if (pAConf.SmallOreChance > 0) { - // ... and we hit the random-chance ... - if (pRandom.nextInt(100) < pAConf.SmallOreChance) { - - // First find a small ore... - for (int i = 0; (i < 256); i++) { - int tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); - for (GTWorldgen tWorldGen : GalacticGreg.smallOreWorldgenList) { - - if (!(tWorldGen instanceof WorldgenOreSmallSpace oreSmallSpace)) continue; - - // That is enabled for *this* dim... - if (!oreSmallSpace.isEnabledForDim(pDimDef)) continue; - - // And in the correct y-level, of ObeyLimits is true... - if (pAConf.ObeyHeightLimits && oreSmallSpace.isAllowedForHeight(pY)) - continue; - - // Care about weight - tRandomWeight -= oreSmallSpace.mAmount; - if (tRandomWeight <= 0) { - OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, asteroidStone.getStone(), oreSmallSpace.mMaterial, true); - return true; - } - } - } + private boolean generateOreBlock(Random pRandom, World pWorld, int pX, int pY, int pZ, AsteroidBlockComb asteroidStone, IWorldgenLayer oreLayer, boolean small) { + if (pRandom.nextFloat() <= oreLayer.getDensity()) { + IMaterial mat = oreLayer.getOre(pRandom.nextFloat()); + + if (mat != null) { + OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, asteroidStone.getStone(), mat, small); + return true; } } return false; } - private void generateOreVeins(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()) { + private void generateEndAsteroid(ModDimensionDef tDimDef, World world, Random random, int chunkX, int chunkZ) { + int tX = chunkX * 16 + random.nextInt(16); + int tY = 50 + random.nextInt(200 - 50); + int tZ = chunkZ * 16 + random.nextInt(16); + int asteroidSize = mEndAsteroidMinSize + random.nextInt(mEndAsteroidMaxSize - mEndAsteroidMinSize + 1); - outer: for (int i = 0; i < 256; i++) { - int tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); + WorldgenGTOreLayer selectedOreLayer = WorldgenQuery.veins() + .inDimension(tDimDef) + .find(random); + + // should never happen, but let's be safe + if (selectedOreLayer == null) return; + + if (world.isAirBlock(tX, tY, tZ)) { + float randomRadian = random.nextFloat() * (float) Math.PI; + double xBase = tX + 8 + MathHelper.sin(randomRadian) * asteroidSize / 8.0F; + double xFactor = tX + 8 - MathHelper.sin(randomRadian) * asteroidSize / 8.0F; + double zBase = tZ + 8 + MathHelper.cos(randomRadian) * asteroidSize / 8.0F; + double zFactor = tZ + 8 - MathHelper.cos(randomRadian) * asteroidSize / 8.0F; + double yBase = tY + random.nextInt(3) - 2; + double yFactor = tY + random.nextInt(3) - 2; + + for (int i = 0; i <= asteroidSize; i++) { + double randomDistance = random.nextDouble() * asteroidSize / 16.0D; + + double halfLength = ((MathHelper.sin(i * (float) Math.PI / asteroidSize) + 1.0F) * randomDistance + 1.0D) / 2.0; + double halfHeight = ((MathHelper.sin(i * (float) Math.PI / asteroidSize) + 1.0F) * randomDistance + 1.0D) / 2.0; + + double xCenter = xBase + (xFactor - xBase) * i / asteroidSize; + double yCenter = yBase + (yFactor - yBase) * i / asteroidSize; + double zCenter = zBase + (zFactor - zBase) * i / asteroidSize; + + int tMinX = MathHelper.floor_double(xCenter - halfLength); + int tMinY = MathHelper.floor_double(yCenter - halfHeight); + int tMinZ = MathHelper.floor_double(zCenter - halfLength); + int tMaxX = MathHelper.floor_double(xCenter + halfLength); + int tMaxY = MathHelper.floor_double(yCenter + halfHeight); + int tMaxZ = MathHelper.floor_double(zCenter + halfLength); + + for (int eX = tMinX; eX <= tMaxX; eX++) { + + double xChance = (eX + 0.5D - xCenter) / halfLength; + if (xChance * xChance < 1.0D) { + for (int eY = tMinY; eY <= tMaxY; eY++) { + + double yChance = (eY + 0.5D - yCenter) / halfHeight; + if (xChance * xChance + yChance * yChance < 1.0D) { + for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) { + + double zChance = (eZ + 0.5D - zCenter) / halfLength; + if (xChance * xChance + yChance * yChance + zChance * zChance >= 1.0D) { + continue; + } - for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) { - if (tWorldGen instanceof WorldgenOreLayerSpace) - tRandomWeight -= ((WorldgenOreLayerSpace) tWorldGen).mWeight; + if (!world.isAirBlock(tX, tY, tZ)) { + continue; + } - if (tRandomWeight <= 0) { - try { - if (tWorldGen.executeWorldgen( - pWorld, - pRandom, - pBiome, - Integer.MIN_VALUE, - pX, - pZ, - pChunkGenerator, - pChunkProvider)) { - break outer; + int ranOre = random.nextInt(50); + if (ranOre < 3) { + OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mPrimary, false); + } else if (ranOre < 6) { + OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mSecondary, false); + } else if (ranOre < 8) { + OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mBetween, false); + } else if (ranOre < 10) { + OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mSporadic, false); + } else { + world.setBlock(eX, eY, eZ, Blocks.end_stone, 0, 0); + } } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); } - break; - } - } - } - } - // 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++; } } - 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 595bfe3a3ab..00000000000 --- a/src/main/java/galacticgreg/WorldgenOreLayerSpace.java +++ /dev/null @@ -1,333 +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.interfaces.IMaterial; -import gregtech.api.util.GTLog; -import gregtech.api.world.GTWorldgen; -import gregtech.common.OreMixBuilder; -import gregtech.common.ores.OreManager; - -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 IMaterial mPrimary; - public final IMaterial mSecondary; - public final IMaterial mBetween; - public final IMaterial mSporadic; - - 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); - mPrimary = mix.primary; - mSecondary = mix.secondary; - mBetween = mix.between; - mSporadic = mix.sporadic; - - 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.contains(mdd.getDimensionName()); - 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) { - IMaterial primary = null; - IMaterial secondary = null; - IMaterial between = null; - IMaterial sporadic = null; - - 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; - break; - } - } - - if (tGen != null) { - GalacticGreg.Logger.trace("Using Oremix %s for asteroid", tGen.mWorldGenName); - primary = ((WorldgenOreLayerSpace) tGen).mPrimary; - secondary = ((WorldgenOreLayerSpace) tGen).mSecondary; - between = ((WorldgenOreLayerSpace) tGen).mBetween; - sporadic = ((WorldgenOreLayerSpace) tGen).mSporadic; - } - } 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); - primary = ((WorldgenOreLayerSpace) tWorldGen).mPrimary; - secondary = ((WorldgenOreLayerSpace) tWorldGen).mSecondary; - between = ((WorldgenOreLayerSpace) tWorldGen).mBetween; - sporadic = ((WorldgenOreLayerSpace) tWorldGen).mSporadic; - - temp = false; - break; - } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - } - } - } - } - } - - if (primary != null || secondary != null || between != null || sporadic != null) { - return new GTOreGroup(primary, secondary, between, sporadic); - } 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.mSecondary != null) { - 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)) { - OreManager.setOreForWorldGen(pWorld, tX, i, tZ, null, mSecondary, false); - } - } - } - if (this.mBetween != null) { - 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)) { - OreManager.setOreForWorldGen(pWorld, tX, i, tZ, null, mBetween, false); - } - } - - } - if (this.mPrimary != null) { - 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)) { - OreManager.setOreForWorldGen(pWorld, tX, i, tZ, null, mPrimary, false); - } - } - } - if (this.mSporadic != null) { - 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)) { - OreManager.setOreForWorldGen(pWorld, tX, i, tZ, null, mSporadic, false); - } - } - } - } - } - - 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 (mPrimary != null) { - OreManager.setOreForWorldGen(pWorld, tX, tY, tZ, null, mPrimary, true); - } - 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 (mSecondary != null) { - OreManager.setOreForWorldGen(pWorld, tX, tY, tZ, null, mSecondary, true); - } - 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 (mBetween != null) { - OreManager.setOreForWorldGen(pWorld, tX, tY, tZ, null, mBetween, true); - } - 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 (mSporadic != null) { - OreManager.setOreForWorldGen(pWorld, tX, tY, tZ, null, mSporadic, true); - } - } - } - - // --------------------------- - 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 a095b303ce3..00000000000 --- a/src/main/java/galacticgreg/WorldgenOreSmallSpace.java +++ /dev/null @@ -1,116 +0,0 @@ -package galacticgreg; - -import java.util.HashSet; -import java.util.Random; -import java.util.Set; - -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.interfaces.IMaterial; -import gregtech.api.world.GTWorldgen; -import gregtech.common.SmallOreBuilder; -import gregtech.common.ores.OreManager; - -public class WorldgenOreSmallSpace extends GTWorldgen { - - public final short mMinY; - public final short mMaxY; - public final short mAmount; - public final IMaterial mMaterial; - - private long mProfilingStart; - private long mProfilingEnd; - private final Set 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); - mMaterial = ore.ore; - - allowedDims = new HashSet<>(); - for (ModContainer mc : GalacticGregRegistry.getModContainers()) { - if (!mc.isModLoaded()) continue; - - for (ModDimensionDef mdd : mc.getDimensionList()) { - String dimId = mdd.getDimIdentifier(); - - if (ore.dimsEnabled.contains(dimId)) { - allowedDims.add(dimId); - } - } - } - - 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.contains(pDimensionDef.getDimIdentifier()); - } - - @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 (mMaterial != null) { - int i = 0; - for (int j = Math.max(1, this.mAmount / 2 + pRandom.nextInt(this.mAmount) / 2); i < j; i++) { - OreManager.setOreForWorldGen( - pWorld, - pChunkX + pRandom.nextInt(16), - this.mMinY + pRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), - pChunkZ + pRandom.nextInt(16), - null, - mMaterial, - true); - } - } - // --------------------------- - 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/ModDimensionDef.java b/src/main/java/galacticgreg/api/ModDimensionDef.java index 382f8a951d1..dcb717a4fc5 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.Random; -import gregtech.api.enums.StoneType; +import galacticgreg.api.Enums.DimensionType; import gregtech.api.interfaces.IStoneType; import net.minecraft.block.Block; import net.minecraft.world.chunk.IChunkProvider; @@ -17,29 +17,91 @@ 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 String dimensionName; + /** "modname_dimname" */ + private String internalDimIdentifier; + private final String chunkProviderName; + private Enums.AirReplaceRule airReplaceSetting; + private final ArrayList replaceableBlocks; + private DimensionType dimensionType; - private final List _mSpaceObjectsGenerators; - private final List _mSpaceStructureGenerators; + private final List spaceObjectGenerators; + private final List spaceStructureGenerators; // Special Planets config settings - private int _mGroundOreMaxY = 64; - private int _mFloatingAsteroidsMinY = 128; + private int groundOreMaxY = 64; + private int floatingAsteroidsMinY = 128; // ------ - // Override for stonetype - private GTOreTypes _mStoneType; - // Asteroid stuff - private final List _mValidAsteroidMaterials; - private final List _mSpecialBlocksForAsteroids; + private final List validAsteroidMaterials; + private final List specialBlocksForAsteroids; + + private final Random random = new Random(System.currentTimeMillis()); + + /** + * 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, + DimensionType pDimType) { + this( + pDimensionName, + pChunkProvider.getName(), + 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, + DimensionType pDimType, List pBlockDefinitions) { + this( + pDimensionName, + pChunkProvider.getName(), + pDimType, + pBlockDefinitions); + } - private final Random _mRandom = new Random(System.currentTimeMillis()); + /** + * 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, 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, DimensionType pDimType, + List pBlockDefinitions) { + internalDimIdentifier = STR_NOTDEFINED; + dimensionName = pDimensionName; + chunkProviderName = pChunkProviderName; + dimensionType = pDimType; + + replaceableBlocks = new ArrayList<>(); + if (pBlockDefinitions != null) replaceableBlocks.addAll(pBlockDefinitions); + + validAsteroidMaterials = new ArrayList<>(); + specialBlocksForAsteroids = new ArrayList<>(); + spaceObjectGenerators = new ArrayList<>(); + spaceStructureGenerators = new ArrayList<>(); + } /** * Internal function @@ -47,7 +109,7 @@ public class ModDimensionDef { * @return A list of possible asteroid-mixes that shall be generated */ public List getValidAsteroidMaterials() { - return _mValidAsteroidMaterials; + return validAsteroidMaterials; } // ================================================= @@ -56,8 +118,8 @@ public List getValidAsteroidMaterials() { * 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 */ - public int getPreConfiguratedGroundOreMaxY() { - return _mGroundOreMaxY; + public int getPreConfiguredGroundOreMaxY() { + return groundOreMaxY; } /** @@ -65,8 +127,8 @@ public int getPreConfiguratedGroundOreMaxY() { * 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 */ - public int getPreConfiguratedFloatingAsteroidMinY() { - return _mFloatingAsteroidsMinY; + public int getPreConfiguredFloatingAsteroidMinY() { + return floatingAsteroidsMinY; } /** @@ -79,10 +141,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 @@ -101,10 +163,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; @@ -112,7 +174,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(); @@ -135,8 +197,8 @@ public void setAsteroidAndPlanetLimits(int pOregenMaxY, int pAsteroidMinY) { if (pOregenMaxY >= pAsteroidMinY) throw new IllegalArgumentException("pOregenMaxY must be LOWER than pAsteroidMinY!"); - _mFloatingAsteroidsMinY = pAsteroidMinY; - _mGroundOreMaxY = pOregenMaxY; + floatingAsteroidsMinY = pAsteroidMinY; + groundOreMaxY = pOregenMaxY; } // ================================================= @@ -146,11 +208,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; } /** @@ -158,8 +220,8 @@ public List getSpaceObjectGenerators() { * * @return The type for this dimension */ - public Enums.DimensionType getDimensionType() { - return _mDimensionType; + public DimensionType getDimensionType() { + return dimensionType; } /** @@ -168,8 +230,8 @@ public Enums.DimensionType getDimensionType() { * * @param pType The dimensiontype to be used */ - public void setDimensionType(Enums.DimensionType pType) { - _mDimensionType = pType; + public void setDimensionType(DimensionType pType) { + dimensionType = pType; } /** @@ -178,7 +240,7 @@ public void setDimensionType(Enums.DimensionType pType) { * @return The configuration for AirBlocks */ public Enums.AirReplaceRule getAirSetting() { - return _mDimAirSetting; + return airReplaceSetting; } /** @@ -193,7 +255,7 @@ public Enums.AirReplaceRule getAirSetting() { * @param pSetting */ public void setAirSetting(Enums.AirReplaceRule pSetting) { - _mDimAirSetting = pSetting; + airReplaceSetting = pSetting; } /** @@ -202,29 +264,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; } /** @@ -233,7 +273,7 @@ public GTOreTypes getStoneType() { * @return The attached chunk-provider for this dimension */ public String getChunkProviderName() { - return _mChunkProvider; + return chunkProviderName; } /** @@ -244,10 +284,10 @@ public String getChunkProviderName() { * @return */ public boolean addBlockDefinition(ModDBMDef pBlockDef) { - if (_mReplaceableBlocks.contains(pBlockDef)) { + if (replaceableBlocks.contains(pBlockDef)) { return false; } else { - _mReplaceableBlocks.add(pBlockDef); + replaceableBlocks.add(pBlockDef); return true; } } @@ -258,7 +298,7 @@ public boolean addBlockDefinition(ModDBMDef pBlockDef) { * @return The DimensionName in a Human-readable format */ public String getDimensionName() { - return _mDimensionName; + return dimensionName; } /** @@ -267,73 +307,7 @@ public String getDimensionName() { * @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 replaceableBlocks; } /** @@ -343,8 +317,8 @@ 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 @@ -363,7 +337,7 @@ protected void setParentModName(String pModName) { public Enums.ReplaceState getReplaceStateForBlock(Block pBlock, int pMeta) { Enums.ReplaceState tFlag = Enums.ReplaceState.Unknown; - for (ModDBMDef pDef : _mReplaceableBlocks) { + for (ModDBMDef pDef : replaceableBlocks) { Enums.ReplaceState tResult = pDef.blockEquals(pBlock, pMeta); if (tResult == Enums.ReplaceState.Unknown) continue; @@ -388,11 +362,12 @@ public Enums.ReplaceState getReplaceStateForBlock(Block pBlock, int pMeta) { * @return */ public AsteroidBlockComb getRandomAsteroidMaterial() { - if (_mValidAsteroidMaterials.isEmpty()) return null; + 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(random.nextInt(validAsteroidMaterials.size())); } } @@ -404,11 +379,12 @@ public AsteroidBlockComb getRandomAsteroidMaterial() { * @return */ public SpecialBlockComb getRandomSpecialAsteroidBlock() { - if (_mSpecialBlocksForAsteroids.isEmpty()) return null; + 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(random.nextInt(specialBlocksForAsteroids.size())); } } @@ -427,8 +403,8 @@ public void addAsteroidMaterial(IStoneType stoneType) { * @param pBlockComb */ public void addAsteroidMaterial(AsteroidBlockComb pBlockComb) { - if (!_mValidAsteroidMaterials.contains(pBlockComb)) { - _mValidAsteroidMaterials.add(pBlockComb); + if (!validAsteroidMaterials.contains(pBlockComb)) { + validAsteroidMaterials.add(pBlockComb); } } @@ -440,8 +416,8 @@ 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); } } @@ -450,14 +426,8 @@ public void addSpecialAsteroidBlock(SpecialBlockComb pBlock) { * 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); - } + for (ModDBMDef rpb : replaceableBlocks) { + rpb.updateBlockName(pParentModName); } } } diff --git a/src/main/java/galacticgreg/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index 162817d6cf3..de47114a83c 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -1,16 +1,44 @@ package galacticgreg.api.enums; +import net.minecraft.world.World; import net.minecraft.world.gen.ChunkProviderEnd; +import net.minecraft.world.gen.ChunkProviderHell; + +import java.util.HashMap; +import java.util.Map; import galacticgreg.api.Enums; import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.Enums.DimensionType; +import gtPlusPlus.everglades.chunk.ChunkProviderModded; public enum DimensionDef { + Overworld(new ModDimensionDef( + DimNames.OW, + "", + 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.ENDASTEROIDS, ChunkProviderEnd.class, Enums.DimensionType.Asteroid)), + TwilightForest(new ModDimensionDef( + DimNames.TWILIGHT_FOREST, + "", + DimensionType.Planet)), + Everglades(new ModDimensionDef( + DimNames.EVERGLADES, + ChunkProviderModded.class, + DimensionType.Planet)), + Moon(new ModDimensionDef( DimNames.MOON, @@ -181,11 +209,29 @@ public enum DimensionDef { "de.katzenpapst.amunra.world.mehen.MehenChunkProvider", Enums.DimensionType.Asteroid)); + 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 getDefForWorld(World world) { + return DEF_BY_WORLD_NAME.get(world.provider.getDimensionName()); + } + public static class DimNames { public static final String OW = "Overworld"; public static final String NETHER = "Nether"; - public static final String THE_END = "TheEnd"; + public static final String THE_END = "The End"; public static final String ENDASTEROIDS = "EndAsteroids"; public static final String TWILIGHT_FOREST = "Twilight Forest"; public static final String EVERGLADES = "dimensionDarkWorld"; @@ -229,10 +275,4 @@ public static class DimNames { 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/Asteroids.java b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java index 32020506cee..984c1f63cb4 100644 --- a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java +++ b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java @@ -6,7 +6,7 @@ public enum Asteroids { // spotless : off - EndAsteroids(ModContainers.Vanilla, DimensionDef.EndAsteroids, new AsteroidPropertyBuilder().probability(200) + EndAsteroids(ModContainers.Vanilla, DimensionDef.EndAsteroids, new AsteroidPropertyBuilder().probability(100) .sizeRange(5, 15) .specialBlockChance(5) .oreSpawn( @@ -20,7 +20,7 @@ public enum Asteroids { .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - KuiperBelt(ModContainers.GalaxySpace, DimensionDef.KuiperBelt, new AsteroidPropertyBuilder().probability(200) + KuiperBelt(ModContainers.GalaxySpace, DimensionDef.KuiperBelt, new AsteroidPropertyBuilder().probability(100) .sizeRange(5, 15) .specialBlockChance(5) .oreSpawn( @@ -34,7 +34,7 @@ public enum Asteroids { .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - MehenBelt(ModContainers.AmunRa, DimensionDef.MehenBelt, new AsteroidPropertyBuilder().probability(200) + MehenBelt(ModContainers.AmunRa, DimensionDef.MehenBelt, new AsteroidPropertyBuilder().probability(100) .sizeRange(5, 15) .specialBlockChance(5) .oreSpawn( @@ -48,7 +48,7 @@ public enum Asteroids { .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - Asteroids(ModContainers.GalacticraftMars, DimensionDef.Asteroids, new AsteroidPropertyBuilder().probability(200) + Asteroids(ModContainers.GalacticraftMars, DimensionDef.Asteroids, new AsteroidPropertyBuilder().probability(100) .sizeRange(5, 15) .specialBlockChance(5) .oreSpawn( diff --git a/src/main/java/galacticgreg/registry/GalacticGregRegistry.java b/src/main/java/galacticgreg/registry/GalacticGregRegistry.java index ee12baeb170..4b1d18df82f 100644 --- a/src/main/java/galacticgreg/registry/GalacticGregRegistry.java +++ b/src/main/java/galacticgreg/registry/GalacticGregRegistry.java @@ -117,11 +117,9 @@ private static void InitModContainers() { "ModID: [%s] DimName: [%s] ValidBlocks: [%d] Identifier: [%s] Generators: [%d]", mc.getModName(), md.getDimensionName(), - md.getReplaceableBlocks() - .size(), + md.getReplaceableBlocks().size(), md.getDimIdentifier(), - md.getSpaceObjectGenerators() - .size()); + md.getSpaceObjectGenerators().size()); // Register default generator if dimension is asteroid and no generator was added if (md.getDimensionType() == DimensionType.Asteroid) { diff --git a/src/main/java/gregtech/api/enums/GTValues.java b/src/main/java/gregtech/api/enums/GTValues.java index 4223a7ed3fe..669ac084c36 100644 --- a/src/main/java/gregtech/api/enums/GTValues.java +++ b/src/main/java/gregtech/api/enums/GTValues.java @@ -407,6 +407,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 81d8e754b7f..d531740ddc3 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -18,6 +18,8 @@ import javax.annotation.Nonnull; +import com.google.common.collect.ImmutableList; + import net.minecraft.enchantment.Enchantment; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; @@ -31,6 +33,7 @@ import gregtech.api.interfaces.IColorModulationContainer; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IMaterialHandler; +import gregtech.api.interfaces.IStoneType; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.objects.MaterialStack; import gregtech.api.util.GTOreDictUnificator; @@ -2522,6 +2525,14 @@ 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); } public static void init() { @@ -3064,6 +3075,24 @@ public int getId() { return mMetaItemSubID; } + @Override + public boolean isValidForStone(IStoneType stoneType) { + if (contains(SubTag.ICE_ORE)) { + return stoneType.getCategory() == StoneCategory.Ice; + } else { + return stoneType.getCategory() == StoneCategory.Stone; + } + } + + @Override + public ImmutableList getValidStones() { + if (contains(SubTag.ICE_ORE)) { + return StoneType.ICES; + } else { + return StoneType.STONES; + } + } + @Override public String getInternalName() { return mName; diff --git a/src/main/java/gregtech/api/enums/OreMixes.java b/src/main/java/gregtech/api/enums/OreMixes.java index 5fd7db25916..93e4d495144 100644 --- a/src/main/java/gregtech/api/enums/OreMixes.java +++ b/src/main/java/gregtech/api/enums/OreMixes.java @@ -7,11 +7,12 @@ import static galacticgreg.api.enums.DimensionDef.DimNames.NETHER; import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; +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 bartworks.system.material.WerkstoffLoader; -import galacticgreg.WorldgenOreLayerSpace; import galacticgreg.api.enums.DimensionDef; import gregtech.common.OreMixBuilder; import gregtech.common.WorldgenGTOreLayer; @@ -1010,6 +1011,54 @@ public enum OreMixes { .inBetween(Materials.Electrotine) .sporadic(Materials.Samarium)), + NitrogenIce(new OreMixBuilder().name("ore.mix.nitrogenice") + .heightRange(30, 180) + .weight(80) + .density(16) + .size(16) + .enableInDim(ASTEROIDS, KUIPERBELT) + .primary(Materials.Nitrogen) + .secondary(Materials.Nitrogen) + .inBetween(Materials.Ammonia) + .sporadic(Materials.Ammonia) + .stoneCategory(StoneCategory.Ice)), + + CarbonIce(new OreMixBuilder().name("ore.mix.carbonice") + .heightRange(30, 180) + .weight(40) + .density(16) + .size(12) + .enableInDim(ASTEROIDS, KUIPERBELT) + .primary(Materials.Methane) + .secondary(Materials.CarbonDioxide) + .inBetween(Materials.Carbon) + .sporadic(Materials.Carbon) + .stoneCategory(StoneCategory.Ice)), + + HHOIce(new OreMixBuilder().name("ore.mix.hhoice") + .heightRange(30, 180) + .weight(80) + .density(24) + .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(16) + .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) @@ -1458,8 +1507,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 62e1f52aae1..bdb7079e1ef 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -914,6 +914,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<>( diff --git a/src/main/java/gregtech/api/enums/SmallOres.java b/src/main/java/gregtech/api/enums/SmallOres.java index 6cf7970205a..f6a31b743af 100644 --- a/src/main/java/gregtech/api/enums/SmallOres.java +++ b/src/main/java/gregtech/api/enums/SmallOres.java @@ -35,7 +35,6 @@ 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; @@ -543,8 +542,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 index cedc9e927af..f25599424ef 100644 --- a/src/main/java/gregtech/api/enums/StoneType.java +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -18,6 +18,7 @@ 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; @@ -112,11 +113,19 @@ public enum StoneType implements IStoneType { .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)), ; public static final ImmutableList STONE_TYPES = ImmutableList.copyOf(values()); public static final ImmutableList VISUAL_STONE_TYPES = ImmutableList.copyOf(Arrays.stream(values()).filter(s -> s.builder.enabled && !s.isExtraneous()).toArray(StoneType[]::new)); + public static final ImmutableList STONE_ONLY = ImmutableList.of(StoneType.Stone); + public static final ImmutableList STONES = ImmutableList.copyOf(StoneType.STONE_TYPES.stream().filter(s -> s.getCategory() == StoneCategory.Stone).toArray(StoneType[]::new)); + public static final ImmutableList ICES = ImmutableList.copyOf(StoneType.STONE_TYPES.stream().filter(s -> s.getCategory() == StoneCategory.Ice).toArray(StoneType[]::new)); + private final StoneBuilder builder; private StoneType(StoneBuilder builder) { @@ -133,6 +142,11 @@ public OrePrefixes getPrefix() { return builder.oreBlockPrefix; } + @Override + public IStoneCategory getCategory() { + return builder.category; + } + @Override public ObjectIntPair getCobblestone() { return ObjectIntPair.of(builder.cobble.block, builder.cobble.meta); @@ -212,7 +226,7 @@ public boolean isDimensionSpecific() { @Override public boolean isExtraneous() { - return this.ordinal() > Endstone.ordinal(); + return this.ordinal() > Endstone.ordinal() && this != PackedIce; } @Override @@ -262,6 +276,7 @@ private static class StoneBuilder { public OrePrefixes oreBlockPrefix = OrePrefixes.ore; public ItemStack pureDust = GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1); public ItemStack impureDust = GTOreDictUnificator.get(OrePrefixes.dustImpure, Materials.Stone, 1); + public StoneCategory category = StoneCategory.Stone; public static StoneBuilder galaxySpace(String name, int mainStone, int... extraStones) { return galaxySpace(name, "blocks", mainStone, extraStones); @@ -368,6 +383,8 @@ public StoneBuilder setDust(Materials mat) { pureDust = mat.getDust(1); impureDust = GTOreDictUnificator.get(OrePrefixes.dustImpure, mat, 1); + if (impureDust == null) impureDust = pureDust; + return this; } @@ -376,5 +393,11 @@ public StoneBuilder setPrefix(OrePrefixes prefix) { return this; } + + public StoneBuilder setCategory(StoneCategory cat) { + this.category = cat; + + 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/interfaces/IMaterial.java b/src/main/java/gregtech/api/interfaces/IMaterial.java index 1f72456f078..8da07f3de00 100644 --- a/src/main/java/gregtech/api/interfaces/IMaterial.java +++ b/src/main/java/gregtech/api/interfaces/IMaterial.java @@ -1,5 +1,7 @@ package gregtech.api.interfaces; +import com.google.common.collect.ImmutableList; + public interface IMaterial { public String getLocalizedName(); @@ -10,4 +12,7 @@ public interface IMaterial { public short[] getRGBA(); + public boolean isValidForStone(IStoneType stoneType); + + public ImmutableList getValidStones(); } 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..498df5d1d01 --- /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 index 5ae4c7fbfd7..b7bfcc18f6d 100644 --- a/src/main/java/gregtech/api/interfaces/IStoneType.java +++ b/src/main/java/gregtech/api/interfaces/IStoneType.java @@ -12,6 +12,7 @@ public interface IStoneType { public boolean contains(Block block, int meta); public OrePrefixes getPrefix(); + public IStoneCategory getCategory(); public ItemStack getDust(boolean pure, int amount); diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index 48ee0d1f881..bcd0a5dee17 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -5,15 +5,15 @@ 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,26 +26,25 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent; import cpw.mods.fml.common.registry.GameRegistry; +import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.Enums.DimensionType; +import galacticgreg.api.enums.DimensionDef; +import galacticgreg.api.enums.DimensionDef.DimNames; import gregtech.api.GregTechAPI; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; -import gregtech.api.enums.StoneType; import gregtech.api.net.GTPacketSendOregenPattern; import gregtech.api.objects.XSTR; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; -import gregtech.common.config.Worldgen; -import gregtech.common.ores.OreManager; +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 int maxVeinSize = 2; // in chunks + + public static List pendingTasks = 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( @@ -62,69 +61,75 @@ 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"); } } + private static final int END_ASTEROID_DISTANCE = 16; + @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); + + if (def.getDimensionName().equals(DimNames.THE_END)) { + if (aX * aX + aZ * aZ > END_ASTEROID_DISTANCE * END_ASTEROID_DISTANCE) { + def = DimensionDef.EndAsteroids.modDimensionDef; + } } + if (def != null && def.getDimensionType() == DimensionType.Asteroid) { + return; + } + + pendingTasks.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: " + + pendingTasks.size()); + 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(pendingTasks.size(), 5); i++) { + WorldGenContainer task = pendingTasks.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() + + pendingTasks.size() + " i: " + i); - synchronized (listLock) { - mList.remove(0); - } - toRun.run(); + + task.run(); } this.mIsGenerating = false; } @@ -248,7 +253,7 @@ public int hashCode() { } } - public static ArrayList seedList = new ArrayList<>(); + public static List seedList = new LinkedList<>(); // 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, @@ -287,7 +292,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 @@ -304,11 +309,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 - 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,155 +328,16 @@ 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.mPrimary.hashCode())), - 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.mPrimary.hashCode())); // 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.hashCode()); + int placementResult = tWorldGen.executeWorldgenChunkified( this.mWorld, oreveinRNG, @@ -484,6 +349,7 @@ public void worldGenFindVein(int oreseedX, int oreseedZ) { 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 +358,152 @@ public void worldGenFindVein(int oreseedX, int oreseedZ) { if (debugOrevein) GTLog.out.println(" No overlap"); } } + + return; + } + + if (oreveinPercentageRoll < oreveinPercentage) { + 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 && placementAttempts < oreveinMaxPlacementAttempts; i++) { + WorldgenGTOreLayer oreLayer = WorldgenQuery.veins() + .inDimension(dimensionName) + .find(oreveinRNG); + + 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.hashCode())), + this.mBiome, + this.mDimensionType, + 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; + break; + } + 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; + break; + } + 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 >= oreveinPercentage) { + if (debugOrevein) GTLog.out.println( + " Skipped oreveinSeed=" + oreveinSeed + + " mX=" + + this.mX + + " mZ=" + + this.mZ + + " oreseedX=" + + oreseedX + + " oreseedZ=" + + oreseedZ + + " RNG=" + + oreveinPercentageRoll + + " %=" + + oreveinPercentage + + " dimensionName=" + + dimensionName); + validOreveins.put(oreveinSeed, noOresInVein); } } @@ -500,8 +512,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) { @@ -521,21 +531,13 @@ 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 wXbox = this.mX - maxVeinSize; + int eXbox = this.mX + maxVeinSize + 1; // Need to add 1 since it is compared using a < + int nZbox = this.mZ - maxVeinSize; + int sZbox = this.mZ + maxVeinSize + 1; // Search for orevein seeds and add to the list; for (int x = wXbox; x < eXbox; x++) { @@ -552,134 +554,27 @@ public void run() { 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); + generateVein(seedList.get(0).mX, seedList.get(0).mZ); } long oregenTime = System.nanoTime(); - // Asteroid Worldgen - int tDimensionType = this.mWorld.provider.dimensionId; - - 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) { + + if (debugWorldGen || profileWorldGen) { GTLog.out.println( - " Oregen took " + (oregenTime - leftOverTime) - + " Leftover gen took " - + (leftOverTime - startTime) + " Oregen took " + (oregenTime - stonegenTime) + + " Stonegen took " + + (stonegenTime - startTime) + " Worldgen took " + duration + " nanoseconds"); } } - - private void generateAsteroid(World world, Random random, int chunkX, int chunkZ) { - WorldgenGTOreLayer selectedOreLayer = null; - - if (WorldgenGTOreLayer.sWeight > 0 && !WorldgenGTOreLayer.sList.isEmpty()) { - int tRandomWeight; - outer: for (int i = 0; i < oreveinAttempts; i++) { - tRandomWeight = random.nextInt(WorldgenGTOreLayer.sWeight); - for (WorldgenGTOreLayer tWorldGen : WorldgenGTOreLayer.sList) { - tRandomWeight -= tWorldGen.mWeight; - if (tRandomWeight <= 0) { - try { - if (tWorldGen.mAllowedDimensions.contains("EndAsteroid")) { - selectedOreLayer = tWorldGen; - break outer; - } - } catch (Throwable e) { - e.printStackTrace(GTLog.err); - } - } - } - } - } - - // should never happen, but let's be safe - if (selectedOreLayer == null) return; - - 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.isAirBlock(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 randomDistance = random.nextDouble() * mSize / 16.0D; - - double halfLength = ((MathHelper.sin(i * (float) Math.PI / mSize) + 1.0F) * randomDistance + 1.0D) / 2.0; - double halfHeight = ((MathHelper.sin(i * (float) Math.PI / mSize) + 1.0F) * randomDistance + 1.0D) / 2.0; - - double xCenter = xBase + (xFactor - xBase) * i / mSize; - double yCenter = yBase + (yFactor - yBase) * i / mSize; - double zCenter = zBase + (zFactor - zBase) * i / mSize; - - int tMinX = MathHelper.floor_double(xCenter - halfLength); - int tMinY = MathHelper.floor_double(yCenter - halfHeight); - int tMinZ = MathHelper.floor_double(zCenter - halfLength); - int tMaxX = MathHelper.floor_double(xCenter + halfLength); - int tMaxY = MathHelper.floor_double(yCenter + halfHeight); - int tMaxZ = MathHelper.floor_double(zCenter + halfLength); - - for (int eX = tMinX; eX <= tMaxX; eX++) { - - double xChance = (eX + 0.5D - xCenter) / halfLength; - if (xChance * xChance < 1.0D) { - for (int eY = tMinY; eY <= tMaxY; eY++) { - - double yChance = (eY + 0.5D - yCenter) / halfHeight; - if (xChance * xChance + yChance * yChance < 1.0D) { - for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) { - - double zChance = (eZ + 0.5D - zCenter) / halfLength; - if (xChance * xChance + yChance * yChance + zChance * zChance >= 1.0D) { - continue; - } - - if (!world.isAirBlock(tX, tY, tZ)) { - continue; - } - - int ranOre = random.nextInt(50); - if (ranOre < 3) { - OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mPrimary, false); - } else if (ranOre < 6) { - OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mSecondary, false); - } else if (ranOre < 8) { - OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mBetween, false); - } else if (ranOre < 10) { - OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mSporadic, false); - } else { - world.setBlock(eX, eY, eZ, Blocks.end_stone, 0, 0); - } - } - } - } - } - } - } - } - } } } diff --git a/src/main/java/gregtech/common/OreMixBuilder.java b/src/main/java/gregtech/common/OreMixBuilder.java index 221cc52156e..cf4f7801ac0 100644 --- a/src/main/java/gregtech/common/OreMixBuilder.java +++ b/src/main/java/gregtech/common/OreMixBuilder.java @@ -6,7 +6,9 @@ import galacticgreg.api.enums.DimensionDef; import gregtech.api.enums.Materials; +import gregtech.api.enums.StoneCategory; import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneCategory; public class OreMixBuilder { @@ -17,6 +19,8 @@ public class OreMixBuilder { public int minY, maxY, weight, density, size; public IMaterial 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; @@ -87,6 +91,17 @@ public OreMixBuilder sporadic(IMaterial 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 2797a01bc75..98980a58a7a 100644 --- a/src/main/java/gregtech/common/SmallOreBuilder.java +++ b/src/main/java/gregtech/common/SmallOreBuilder.java @@ -1,23 +1,27 @@ package gregtech.common; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; import galacticgreg.api.enums.DimensionDef; import gregtech.api.interfaces.IMaterial; +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 THE_END = "The End"; public static final String TWILIGHT_FOREST = "Twilight Forest"; public String smallOreName; public boolean enabledByDefault = true; - /** {full dimension name: enabled} */ + /** {full dimension name} */ public Set dimsEnabled = new HashSet<>(); public int minY, maxY, amount; public IMaterial ore; + public Set stoneCategories; + public boolean defaultStoneCategories = true; public SmallOreBuilder name(String name) { this.smallOreName = name; @@ -58,4 +62,15 @@ public SmallOreBuilder ore(IMaterial 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 15be6acb1fb..352d6e180db 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -9,15 +9,21 @@ import java.util.Random; import java.util.Set; +import com.google.common.collect.ImmutableList; + import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneCategory; +import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTLog; +import gregtech.api.util.GTUtility; import gregtech.api.world.GTWorldgen; import gregtech.common.ores.OreManager; +import gregtech.common.worldgen.IWorldgenLayer; -public class WorldgenGTOreLayer extends GTWorldgen { +public class WorldgenGTOreLayer extends GTWorldgen implements IWorldgenLayer { public static ArrayList sList = new ArrayList<>(); public static int sWeight = 0; @@ -33,6 +39,7 @@ public class WorldgenGTOreLayer extends GTWorldgen { public final String mRestrictBiome; /** {full dim name} */ public final Set mAllowedDimensions; + public final Set mAllowedStone; public static final int WRONG_BIOME = 0; public static final int WRONG_DIMENSION = 1; public static final int NO_ORE_IN_BOTTOM_LAYER = 2; @@ -58,6 +65,7 @@ public WorldgenGTOreLayer(OreMixBuilder mix) { 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) { @@ -65,6 +73,95 @@ public WorldgenGTOreLayer(OreMixBuilder mix) { } } + @Override + public int getMinY() { + return mMinY; + } + + @Override + public int getMaxY() { + return mMaxY; + } + + @Override + public int getWeight() { + return mWeight; + } + + @Override + public float getSize() { + return mSize / 2; + } + + @Override + public float getDensity() { + return GTUtility.clamp(mDensity / 64.0f, 0f, 1f); + } + + @Override + public boolean canGenerateIn(String dimName) { + return mAllowedDimensions.contains(dimName); + } + + @Override + public boolean canGenerateIn(IStoneType stoneType) { + return mAllowedStone != null && mAllowedStone.contains(stoneType.getCategory()); + } + + @Override + public boolean canGenerateIn(IStoneCategory stoneType) { + return mAllowedStone != null && mAllowedStone.contains(stoneType); + } + + @Override + public boolean isStoneSpecific() { + return mAllowedStone != null; + } + + @Override + public boolean contains(IMaterial material) { + return mPrimary == material || mBetween == material || mSecondary == material || mSporadic == material; + } + + @Override + public ImmutableList getOres() { + ImmutableList.Builder ores = ImmutableList.builder(); + + if (mPrimary != null) ores.add(mPrimary); + if (mBetween != null) ores.add(mBetween); + if (mSecondary != null) ores.add(mSecondary); + if (mSporadic != null) ores.add(mSporadic); + + return ores.build(); + } + + @Override + public IMaterial getOre(float k) { + if (k < 1.0 / 7.0) { + return mSporadic; + } + + if (k < 3.0 / 7.0) { + return mBetween; + } + + if (k < 5.0 / 7.0) { + return mSecondary; + } + + return mPrimary; + } + + @Override + public String getName() { + return mWorldGenName; + } + + @Override + public boolean generatesBigOre() { + return true; + } + @Override public int executeWorldgenChunkified(World world, Random rng, String biome, int dimId, int chunkX, int chunkY, int seedX, int seedZ, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { if (mWorldGenName.equals("NoOresInVein")) { @@ -242,10 +339,6 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int return ORE_PLACED; } - public boolean contains(IMaterial material) { - return mPrimary == material || mBetween == material || mSecondary == material || mSporadic == material; - } - private class LayerGenerator { World world; Random rng; diff --git a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java index 9a67a03300a..b029146ab4f 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java +++ b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java @@ -7,15 +7,21 @@ import java.util.Random; import java.util.Set; +import com.google.common.collect.ImmutableList; + import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import gregtech.api.GregTechAPI; import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneCategory; +import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTLog; +import gregtech.api.util.GTUtility; import gregtech.api.world.GTWorldgen; import gregtech.common.ores.OreManager; +import gregtech.common.worldgen.IWorldgenLayer; -public class WorldgenGTOreSmallPieces extends GTWorldgen { +public class WorldgenGTOreSmallPieces extends GTWorldgen implements IWorldgenLayer { public final short mMinY; public final short mMaxY; @@ -23,6 +29,7 @@ public class WorldgenGTOreSmallPieces extends GTWorldgen { public final IMaterial mMaterial; public final String mBiome; public final Set mAllowedDimensions; + public final Set mAllowedStone; public static ArrayList sList = new ArrayList<>(); public WorldgenGTOreSmallPieces(SmallOreBuilder ore) { @@ -34,10 +41,81 @@ public WorldgenGTOreSmallPieces(SmallOreBuilder ore) { 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); } + @Override + public int getMinY() { + return mMinY; + } + + @Override + public int getMaxY() { + return mMaxY; + } + + @Override + public int getWeight() { + return mAmount; + } + + @Override + public float getSize() { + return mAmount / 2; + } + + @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(IStoneType stoneType) { + return mAllowedStone != null && mAllowedStone.contains(stoneType.getCategory()); + } + + @Override + public boolean canGenerateIn(IStoneCategory stoneType) { + return mAllowedStone != null && mAllowedStone.contains(stoneType); + } + + @Override + public boolean isStoneSpecific() { + return mAllowedStone != null; + } + + @Override + public boolean contains(IMaterial material) { + return material == mMaterial; + } + + @Override + public ImmutableList getOres() { + return mMaterial == null ? ImmutableList.of() : ImmutableList.of(mMaterial); + } + + @Override + public IMaterial getOre(float k) { + return mMaterial; + } + + @Override + public String getName() { + return mWorldGenName; + } + + @Override + public boolean generatesBigOre() { + return false; + } + @Override public boolean executeWorldgen(World world, Random random, String biome, int dimId, int chunkX, int chunkZ, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { diff --git a/src/main/java/gregtech/common/WorldgenStone.java b/src/main/java/gregtech/common/WorldgenStone.java index a7d4154690f..7a69253af8f 100644 --- a/src/main/java/gregtech/common/WorldgenStone.java +++ b/src/main/java/gregtech/common/WorldgenStone.java @@ -165,7 +165,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); diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java index aa206f8e92a..de2e528a2a7 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java @@ -12,6 +12,7 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; 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; @@ -119,11 +120,20 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { if (!GTOreAdapter.INSTANCE.supports(info)) continue; for (StoneType stoneType : stoneTypes) { - if (stoneType == null || stoneType.isExtraneous()) continue; - - info.stoneType = stoneType; - - list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + // if this material only has ice ore, we only want to show the ice variants + if (info.material.contains(SubTag.ICE_ORE)) { + if (stoneType == StoneType.PackedIce) { + info.stoneType = stoneType; + + list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + } + } else { + if (stoneType == null || stoneType.isExtraneous()) continue; + + info.stoneType = stoneType; + + list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + } } } @@ -133,6 +143,8 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { info.material = getMaterial(matId); info.stoneType = null; + if (info.material != null && info.material.contains(SubTag.ICE_ORE)) continue; + if (!GTOreAdapter.INSTANCE.supports(info)) continue; for (StoneType stoneType : stoneTypes) { @@ -162,8 +174,16 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad boolean doFortune = !(harvester instanceof FakePlayer); boolean doSilktouch = harvester != null && EnchantmentHelper.getSilkTouchModifier(harvester); - try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, metadata);) { - return (ArrayList) GTOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, metadata)) { + if (info == null) return new ArrayList<>(); + + ArrayList drops = (ArrayList) GTOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); + + if (drops == null) return new ArrayList<>(); + + drops.remove(null); + + return drops; } } @@ -229,11 +249,17 @@ public boolean addDestroyEffects(World world, int x, int y, int z, int meta, Eff } public String getLocalizedNameFormat(Materials material) { - String base = switch (material.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; - }; + String base; + + if (material.contains(SubTag.ICE_ORE)) { + base = "%material Ice"; + } else { + base = switch (material.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; + }; + } if (GTLanguageManager.i18nPlaceholder) { return base; @@ -271,6 +297,8 @@ public int damageDropped(int meta) { @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; diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index d2a61e0fb37..683f131727a 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -2,11 +2,9 @@ import java.util.ArrayList; import java.util.EnumMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; -import java.util.Set; import java.util.concurrent.ThreadLocalRandom; import gregtech.GTMod; @@ -14,6 +12,7 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; 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; @@ -26,9 +25,6 @@ public enum GTOreAdapter implements IOreAdapter { INSTANCE; - /** Don't generate ores for these materials. */ - public final static Set DISABLED_ORES = new HashSet<>(); - private final Map oreBlocksByStoneType = new EnumMap<>(StoneType.class); public BlockOresAbstract ores1, ores2, ores3, ores4, ores5, ores6; @@ -88,6 +84,7 @@ public void init() { }); ores6 = new BlockOresAbstract(7, new StoneType[] { StoneType.Anubis, + StoneType.PackedIce, }); ores = new BlockOresAbstract[] { ores1, ores2, ores3, ores4, ores5, ores6 }; @@ -104,16 +101,15 @@ public boolean supports(Block block, int meta) { @Override public boolean supports(OreInfo info) { - if (info.stoneType != null) { - if (!(info.stoneType instanceof StoneType stoneType)) return false; - if (!oreBlocksByStoneType.containsKey(stoneType)) return false; - if (!stoneType.isEnabled()) return false; - } - if (!(info.material instanceof Materials gtMat)) return false; - if (gtMat.mMetaItemSubID < 0 || gtMat.mMetaItemSubID >= 1000) return false; - if ((gtMat.mTypes & 0x8) == 0) return false; - if (DISABLED_ORES.contains(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 (!info.material.isValidForStone(stoneType2)) return false; return true; } @@ -132,9 +128,7 @@ public OreInfo getOreInfo(Block block, int meta) { Materials mat = GregTechAPI.sGeneratedMaterials[matId]; - if (mat.mMetaItemSubID < 0 || mat.mMetaItemSubID >= 1000) return null; - if ((mat.mTypes & 0x8) == 0) return null; - if (DISABLED_ORES.contains(mat)) return null; + if (!OrePrefixes.ore.doGenerateItem(mat)) return null; StoneType stoneType = GTUtility.getIndexSafe(oreBlock.stoneTypes, stoneId); if (!stoneType.isEnabled()) return null; @@ -153,17 +147,15 @@ public OreInfo getOreInfo(Block block, int meta) { public ObjectIntPair getBlock(OreInfo info) { if (info.stoneType == null) info.stoneType = StoneType.Stone; - BlockOresAbstract oreBlock = oreBlocksByStoneType.get(info.stoneType); - - if (oreBlock == null) return null; if (!(info.material instanceof Materials gtMat)) return null; - if (gtMat.mMetaItemSubID < 0 || gtMat.mMetaItemSubID >= 1000) return null; - if ((gtMat.mTypes & 0x8) == 0) return null; - if (DISABLED_ORES.contains(gtMat)) return null; + if (!OrePrefixes.ore.doGenerateItem(gtMat)) return null; if (!(info.stoneType instanceof StoneType stoneType)) return null; if (!stoneType.isEnabled()) return null; + BlockOresAbstract oreBlock = oreBlocksByStoneType.get(stoneType); + + if (oreBlock == null) return null; int stoneIndex = oreBlock.stoneTypes.indexOf(stoneType); if (stoneIndex == -1) return null; diff --git a/src/main/java/gregtech/common/ores/IOreAdapter.java b/src/main/java/gregtech/common/ores/IOreAdapter.java index 9e9f4680e49..120de9aa88a 100644 --- a/src/main/java/gregtech/common/ores/IOreAdapter.java +++ b/src/main/java/gregtech/common/ores/IOreAdapter.java @@ -39,7 +39,7 @@ public default ItemStack getStack(OreInfo info, int amount) { try(OreInfo info2 = info.clone()) { info2.stoneType = StoneType.Stone; - p = getBlock(info); + p = getBlock(info2); if (p != null) { return new ItemStack(p.left(), amount, p.rightInt()); 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..4a55ab4916f --- /dev/null +++ b/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java @@ -0,0 +1,25 @@ +package gregtech.common.worldgen; + +import com.google.common.collect.ImmutableList; + +import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneCategory; +import gregtech.api.interfaces.IStoneType; + +public interface IWorldgenLayer { + + public int getMinY(); + public int getMaxY(); + public int getWeight(); + public float getSize(); + public float getDensity(); + public boolean canGenerateIn(String dimName); + public boolean canGenerateIn(IStoneType stoneType); + public boolean canGenerateIn(IStoneCategory stoneType); + public boolean isStoneSpecific(); + public boolean generatesBigOre(); + public boolean contains(IMaterial ore); + public ImmutableList getOres(); + public IMaterial getOre(float k); + public String getName(); +} 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..b69efa6d253 --- /dev/null +++ b/src/main/java/gregtech/common/worldgen/WorldgenQuery.java @@ -0,0 +1,183 @@ +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 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; +import net.minecraft.world.World; + +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 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 stoneType) { + if (stoneCategories == null) stoneCategories = new HashSet<>(); + + stoneCategories.add(stoneType); + + return this; + } + + 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 df57d074af4..933d9c90779 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 61a740579c0..c63925694a6 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)) + .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 12446b8ba76..aa997339da3 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(5000L)) + .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/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index 9902e8a2eb2..1f497d50143 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -10,6 +10,8 @@ import java.util.Map; import java.util.Set; +import com.google.common.collect.ImmutableList; + import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -20,8 +22,10 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; import gregtech.api.enums.TextureSet; import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTLanguageManager; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes; @@ -863,6 +867,16 @@ public int getId() { return 0; } + @Override + public boolean isValidForStone(IStoneType stoneType) { + return stoneType == StoneType.Stone; + } + + @Override + public ImmutableList getValidStones() { + return StoneType.STONE_ONLY; + } + @Override public String getInternalName() { return getUnlocalizedName(); diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index 6701e4a32a8..829768944fe 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -190,9 +190,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/util/DimensionHelper.java b/src/main/java/gtneioreplugin/util/DimensionHelper.java index 6a993e0c506..7e61f9b198d 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -58,7 +58,7 @@ public class DimensionHelper { public static final String[] DimName = { // Non GC dimensions in progression order instead of alphabetical - "Overworld", "Nether", "Twilight", "TheEnd", "EndAsteroid", "dimensionDarkWorld", + "Overworld", "Nether", "Twilight", "The End", "EndAsteroid", "dimensionDarkWorld", // T1 "GalacticraftCore_Moon", // T2 @@ -98,7 +98,7 @@ 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 @@ -220,7 +220,7 @@ public static String getDimAbbreviatedName(String dimName) { case OW -> abbreviatedName = "Ow"; // Overworld case NETHER -> abbreviatedName = "Ne"; // Nether case TWILIGHT_FOREST -> abbreviatedName = "TF"; // Twilight - case THE_END -> abbreviatedName = "ED"; // TheEnd because En = Encalus + case THE_END -> abbreviatedName = "ED"; // The End because En = Encalus case ENDASTEROIDS -> abbreviatedName = "EA"; // EndAsteroid case EVERGLADES -> abbreviatedName = "Eg"; // T1 @@ -283,7 +283,7 @@ public static String getFullName(String dimName) { case "Ow" -> OW; // Overworld case "Ne" -> NETHER; // Nether case "TF" -> TWILIGHT_FOREST; // Twilight - case "ED" -> THE_END; // TheEnd because En = Encalus + case "ED" -> THE_END; // The End because En = Encalus case "EA" -> ENDASTEROIDS; // EndAsteroid // T1 case "Mo" -> MOON; // GalacticraftCore_Moon diff --git a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java index 69795ac5402..fe0c895dfc1 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -8,9 +8,7 @@ import java.util.Set; import net.minecraft.item.ItemStack; - import gregtech.api.enums.OreMixes; -import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneType; import gregtech.common.OreMixBuilder; @@ -88,8 +86,10 @@ public OreLayerWrapper(OreMixBuilder mix) { public List getVeinLayerOre(int veinLayer) { List stackList = new ArrayList<>(); - for (StoneType stoneType : StoneType.VISUAL_STONE_TYPES) { - stackList.add(getLayerOre(veinLayer, stoneType)); + for (IStoneType stoneType : ores[veinLayer].getValidStones()) { + if (!stoneType.isExtraneous()) { + stackList.add(getLayerOre(veinLayer, stoneType)); + } } return stackList; } diff --git a/src/main/resources/assets/gtneioreplugin/lang/en_US.lang b/src/main/resources/assets/gtneioreplugin/lang/en_US.lang index e219982921a..2c511ab337b 100644 --- a/src/main/resources/assets/gtneioreplugin/lang/en_US.lang +++ b/src/main/resources/assets/gtneioreplugin/lang/en_US.lang @@ -41,7 +41,7 @@ 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 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=原版末地小行星 From 7cd1e7499ce78c871519eb53319113e42fbf47cc Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 8 Dec 2024 04:27:31 -0500 Subject: [PATCH 05/47] better asteroids --- .../galacticgreg/WorldGeneratorSpace.java | 206 ++++++++++++------ .../java/gregtech/common/config/Worldgen.java | 6 +- 2 files changed, 145 insertions(+), 67 deletions(-) diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index bb73782660d..97f2abc674e 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -1,5 +1,9 @@ package galacticgreg; +import static gregtech.api.enums.GTValues.profileWorldGen; + +import java.util.ArrayList; +import java.util.List; import java.util.Random; import net.minecraft.init.Blocks; @@ -24,6 +28,8 @@ import galacticgreg.api.enums.DimensionDef; import galacticgreg.api.enums.DimensionDef.DimNames; import galacticgreg.dynconfig.DynamicDimensionConfig; +import gregtech.GTMod; +import gregtech.api.enums.GTValues; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; import gregtech.api.objects.XSTR; @@ -39,9 +45,9 @@ public class WorldGeneratorSpace implements IWorldGenerator { private long mProfilingEnd; private static boolean generateEndAsteroids = true; - private static int mEndAsteroidProbability = 300; - private static int mEndAsteroidMinSize = 50; - private static int mEndAsteroidMaxSize = 200; + private static int mEndAsteroidProbability; + private static int mEndAsteroidMinSize; + private static int mEndAsteroidMaxSize; public WorldGeneratorSpace() { GameRegistry.registerWorldGenerator(this, Integer.MAX_VALUE); @@ -91,7 +97,13 @@ public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvide pWorld.getSeed() + cX * cX * 91777L + cZ * cZ * 137413L + cX * cZ * 1853L + cX * 3L + cZ * 17L); if (mEndAsteroidProbability <= 1 || random.nextInt(mEndAsteroidProbability) == 0) { + long pre = System.nanoTime(); generateEndAsteroid(tDimDef, pWorld, random, cX, cZ); + long post = System.nanoTime(); + + if (GTValues.profileWorldGen) { + GTMod.GT_FML_LOGGER.info("Generated asteroid in " + (post - pre)/1e6 + "ms"); + } } } else if (tDimDef.getRandomAsteroidMaterial() == null) { GalacticGreg.Logger.error( @@ -125,7 +137,7 @@ private void generateAsteroids(ModDimensionDef pDimensionDef, Random pRandom, Wo if (dimAsteroidConfig.Probability <= 1 || pRandom.nextInt(dimAsteroidConfig.Probability) == 0) { GalacticGreg.Logger.trace("Generating asteroid NOW"); // --------------------------- - if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); + if (GalacticGreg.GalacticConfig.ProfileOreGen || profileWorldGen) mProfilingStart = System.currentTimeMillis(); // ----------------------------- AsteroidBlockComb asteroidStone = pDimensionDef.getRandomAsteroidMaterial(); @@ -355,12 +367,12 @@ private void generateAsteroids(ModDimensionDef pDimensionDef, Random pRandom, Wo } // --------------------------- // OreGen profiler stuff - if (GalacticGreg.GalacticConfig.ProfileOreGen) { + if (GalacticGreg.GalacticConfig.ProfileOreGen || profileWorldGen) { try { mProfilingEnd = System.currentTimeMillis(); long tTotalTime = mProfilingEnd - mProfilingStart; GalacticGreg.Profiler.AddTimeToList(pDimensionDef, tTotalTime); - GalacticGreg.Logger.debug( + GalacticGreg.Logger.info( "Done with Asteroid-Worldgen in DimensionType %s. Generation took %d ms", pDimensionDef.getDimensionName(), tTotalTime); @@ -436,11 +448,13 @@ private boolean generateOreBlock(Random pRandom, World pWorld, int pX, int pY, i return false; } - private void generateEndAsteroid(ModDimensionDef tDimDef, World world, Random random, int chunkX, int chunkZ) { + private void generateEndAsteroid(ModDimensionDef tDimDef, World world, Random random2, int chunkX, int chunkZ) { + XSTR random = new XSTR(random2.nextLong()); + int tX = chunkX * 16 + random.nextInt(16); - int tY = 50 + random.nextInt(200 - 50); + int tY = 50 + random.nextInt(100 - 50); int tZ = chunkZ * 16 + random.nextInt(16); - int asteroidSize = mEndAsteroidMinSize + random.nextInt(mEndAsteroidMaxSize - mEndAsteroidMinSize + 1); + int asteroidSize = (mEndAsteroidMinSize + random.nextInt(mEndAsteroidMaxSize - mEndAsteroidMinSize + 1)) / 2; WorldgenGTOreLayer selectedOreLayer = WorldgenQuery.veins() .inDimension(tDimDef) @@ -450,68 +464,132 @@ private void generateEndAsteroid(ModDimensionDef tDimDef, World world, Random ra if (selectedOreLayer == null) return; if (world.isAirBlock(tX, tY, tZ)) { - float randomRadian = random.nextFloat() * (float) Math.PI; - double xBase = tX + 8 + MathHelper.sin(randomRadian) * asteroidSize / 8.0F; - double xFactor = tX + 8 - MathHelper.sin(randomRadian) * asteroidSize / 8.0F; - double zBase = tZ + 8 + MathHelper.cos(randomRadian) * asteroidSize / 8.0F; - double zFactor = tZ + 8 - MathHelper.cos(randomRadian) * asteroidSize / 8.0F; - double yBase = tY + random.nextInt(3) - 2; - double yFactor = tY + random.nextInt(3) - 2; - - for (int i = 0; i <= asteroidSize; i++) { - double randomDistance = random.nextDouble() * asteroidSize / 16.0D; - - double halfLength = ((MathHelper.sin(i * (float) Math.PI / asteroidSize) + 1.0F) * randomDistance + 1.0D) / 2.0; - double halfHeight = ((MathHelper.sin(i * (float) Math.PI / asteroidSize) + 1.0F) * randomDistance + 1.0D) / 2.0; - - double xCenter = xBase + (xFactor - xBase) * i / asteroidSize; - double yCenter = yBase + (yFactor - yBase) * i / asteroidSize; - double zCenter = zBase + (zFactor - zBase) * i / asteroidSize; - - int tMinX = MathHelper.floor_double(xCenter - halfLength); - int tMinY = MathHelper.floor_double(yCenter - halfHeight); - int tMinZ = MathHelper.floor_double(zCenter - halfLength); - int tMaxX = MathHelper.floor_double(xCenter + halfLength); - int tMaxY = MathHelper.floor_double(yCenter + halfHeight); - int tMaxZ = MathHelper.floor_double(zCenter + halfLength); - - for (int eX = tMinX; eX <= tMaxX; eX++) { - - double xChance = (eX + 0.5D - xCenter) / halfLength; - if (xChance * xChance < 1.0D) { - for (int eY = tMinY; eY <= tMaxY; eY++) { - - double yChance = (eY + 0.5D - yCenter) / halfHeight; - if (xChance * xChance + yChance * yChance < 1.0D) { - for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) { - - double zChance = (eZ + 0.5D - zCenter) / halfLength; - if (xChance * xChance + yChance * yChance + zChance * zChance >= 1.0D) { - continue; - } - if (!world.isAirBlock(tX, tY, tZ)) { - continue; - } + List positive = new ArrayList<>(); + List negative = new ArrayList<>(); - int ranOre = random.nextInt(50); - if (ranOre < 3) { - OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mPrimary, false); - } else if (ranOre < 6) { - OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mSecondary, false); - } else if (ranOre < 8) { - OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mBetween, false); - } else if (ranOre < 10) { - OreManager.setOreForWorldGen(world, eX, eY, eZ, StoneType.Endstone, selectedOreLayer.mSporadic, false); - } else { - world.setBlock(eX, eY, eZ, Blocks.end_stone, 0, 0); - } - } + { + int radius = random.nextInt(asteroidSize); + positive.add(new Ellipsoid(0, 0, 0, radius)); + + int k = random.nextInt(2); + for (int i = 0; i < k; i++) { + negative.add(new Ellipsoid( + radius * (random.nextFloat() * 2 - 1), + radius * (random.nextFloat() * 2 - 1), + radius * (random.nextFloat() * 2 - 1), + radius * (random.nextFloat() * 0.25f + 0.6f))); + } + + k = random.nextInt(2); + for (int i = 0; i < k; i++) { + positive.add(new Ellipsoid( + radius * (random.nextFloat() * 2 - 1), + radius * (random.nextFloat() * 2 - 1), + radius * (random.nextFloat() * 2 - 1), + radius * (random.nextFloat() * 0.25f + 0.6f))); + } + } + + for (int x = -asteroidSize * 2; x < asteroidSize * 2; x++) { + for (int z = -asteroidSize * 2; z < asteroidSize * 2; z++) { + y: for (int y = -asteroidSize * 2; y < asteroidSize * 2; y++) { + + if (y + tY < 0) continue; + if (y + tY >= 255) continue; + + for (Ellipsoid e : negative) { + if (e.contains(random, x, y, z)) { + continue y; } } + + boolean place = false; + + for (Ellipsoid e : positive) { + if (e.contains(random, x, y, z)) { + place = true; + break; + } + } + + if (!place) continue; + + if (!world.isAirBlock(tX + x, tY + y, tZ + z)) { + continue; + } + + int ranOre = random.nextInt(50); + if (ranOre < 3) { + OreManager.setOreForWorldGen( + world, + tX + x, + tY + y, + tZ + z, + StoneType.Endstone, + selectedOreLayer.mPrimary, + false); + } else if (ranOre < 6) { + OreManager.setOreForWorldGen( + world, + tX + x, + tY + y, + tZ + z, + StoneType.Endstone, + selectedOreLayer.mSecondary, + false); + } else if (ranOre < 8) { + OreManager.setOreForWorldGen( + world, + tX + x, + tY + y, + tZ + z, + StoneType.Endstone, + selectedOreLayer.mBetween, + false); + } else if (ranOre < 10) { + OreManager.setOreForWorldGen( + world, + tX + x, + tY + y, + tZ + z, + StoneType.Endstone, + selectedOreLayer.mSporadic, + false); + } else { + world.setBlock(tX + x, tY + y, tZ + z, Blocks.end_stone, 0, 3); + } } } } } } + + 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 boolean contains(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 false; + + if (dist > 0.8) { + float f = rng.nextFloat(); + dist += f * 0.4; + } + + return dist < 1; + } + } } diff --git a/src/main/java/gregtech/common/config/Worldgen.java b/src/main/java/gregtech/common/config/Worldgen.java index 274d59a7744..2c93e3f65aa 100644 --- a/src/main/java/gregtech/common/config/Worldgen.java +++ b/src/main/java/gregtech/common/config/Worldgen.java @@ -19,17 +19,17 @@ public class Worldgen { public static class EndAsteroids { @Config.Comment("The maximum size for the end asteroids.") - @Config.DefaultInt(200) + @Config.DefaultInt(30) @Config.RequiresMcRestart public int EndAsteroidMaxSize; @Config.Comment("The minimum size for the end asteroids.") - @Config.DefaultInt(200) + @Config.DefaultInt(15) @Config.RequiresMcRestart public int EndAsteroidMinSize; @Config.Comment("The probability weight to generate end asteroids.") - @Config.DefaultInt(300) + @Config.DefaultInt(25) @Config.RequiresMcRestart public int EndAsteroidProbability; From 667fcb00d93d0a64798e89212fed0f934e2e3476 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Tue, 10 Dec 2024 22:57:00 -0500 Subject: [PATCH 06/47] chunkified asteroid generator --- .../galacticgreg/WorldGeneratorSpace.java | 786 +++++++++--------- .../galacticgreg/api/AsteroidBlockComb.java | 12 +- .../galacticgreg/api/ModDimensionDef.java | 11 +- .../java/gregtech/api/util/GTUtility.java | 23 + .../gregtech/common/ores/GTOreAdapter.java | 2 +- .../java/gregtech/common/ores/OreManager.java | 6 +- 6 files changed, 409 insertions(+), 431 deletions(-) diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 97f2abc674e..7440aba018c 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -6,44 +6,47 @@ import java.util.List; import java.util.Random; -import net.minecraft.init.Blocks; -import net.minecraft.inventory.IInventory; -import net.minecraft.util.MathHelper; -import net.minecraft.util.Vec3; -import net.minecraft.util.WeightedRandomChestContent; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraftforge.common.ChestGenHooks; +import org.joml.Vector2i; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Multimap; +import com.google.common.collect.MultimapBuilder; import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.registry.GameRegistry; import galacticgreg.api.AsteroidBlockComb; import galacticgreg.api.BlockMetaComb; import galacticgreg.api.Enums; -import galacticgreg.api.ISpaceObjectGenerator; +import galacticgreg.api.Enums.TargetBlockPosition; import galacticgreg.api.ModDimensionDef; import galacticgreg.api.SpecialBlockComb; -import galacticgreg.api.StructureInformation; import galacticgreg.api.enums.DimensionDef; import galacticgreg.api.enums.DimensionDef.DimNames; import galacticgreg.dynconfig.DynamicDimensionConfig; +import galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; import gregtech.GTMod; import gregtech.api.enums.GTValues; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneType; import gregtech.api.objects.XSTR; +import gregtech.api.util.GTUtility; import gregtech.common.WorldgenGTOreLayer; import gregtech.common.config.Worldgen; import gregtech.common.ores.OreManager; import gregtech.common.worldgen.IWorldgenLayer; import gregtech.common.worldgen.WorldgenQuery; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.IInventory; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.ChestGenHooks; +import net.minecraftforge.common.util.ForgeDirection; public class WorldGeneratorSpace implements IWorldGenerator { - private long mProfilingStart; - private long mProfilingEnd; - private static boolean generateEndAsteroids = true; private static int mEndAsteroidProbability; private static int mEndAsteroidMinSize; @@ -61,23 +64,16 @@ public WorldGeneratorSpace() { private static final int END_ASTEROID_DISTANCE = 16; @Override - public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvider pChunkGenerator, - IChunkProvider pChunkProvider) { - - int cX = pX; - int cZ = pZ; - pX *= 16; - pZ *= 16; - - pRandom = new Random(pRandom.nextInt()); + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, + IChunkProvider chunkProvider) { GalacticGreg.Logger - .trace("Triggered generate: [ChunkGenerator %s]", pChunkGenerator.toString()); + .trace("Triggered generate: [Dimension %s]", world.provider.getDimensionName()); - ModDimensionDef tDimDef = DimensionDef.getDefForWorld(pWorld); + ModDimensionDef tDimDef = DimensionDef.getDefForWorld(world); if (tDimDef.getDimensionName().equals(DimNames.THE_END)) { - if (pX * pX + pZ * pZ > END_ASTEROID_DISTANCE * END_ASTEROID_DISTANCE) { + if (chunkX * chunkX + chunkZ * chunkZ > END_ASTEROID_DISTANCE * END_ASTEROID_DISTANCE) { tDimDef = DimensionDef.EndAsteroids.modDimensionDef; } } @@ -85,347 +81,422 @@ public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvide if (tDimDef == null) { GalacticGreg.Logger.trace( "Ignoring dimension %s as there is no definition for it in the registry", - pWorld.provider.getDimensionName()); + world.provider.getDimensionName()); return; } else { GalacticGreg.Logger.trace("Selected DimDef: [%s]", tDimDef.getDimIdentifier()); } if (tDimDef.getDimensionType() == Enums.DimensionType.Asteroid) { - if (tDimDef.getDimensionName().equals(DimNames.ENDASTEROIDS) && generateEndAsteroids) { - XSTR random = new XSTR( - pWorld.getSeed() + cX * cX * 91777L + cZ * cZ * 137413L + cX * cZ * 1853L + cX * 3L + cZ * 17L); + boolean modified = false; - if (mEndAsteroidProbability <= 1 || random.nextInt(mEndAsteroidProbability) == 0) { - long pre = System.nanoTime(); - generateEndAsteroid(tDimDef, pWorld, random, cX, cZ); - long post = System.nanoTime(); + long pre = System.nanoTime(); - if (GTValues.profileWorldGen) { - GTMod.GT_FML_LOGGER.info("Generated asteroid in " + (post - pre)/1e6 + "ms"); - } + 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); + + modified = true; } - } else 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 { - generateAsteroids(tDimDef, pRandom, pWorld, pX, pZ); } - Chunk tChunk = pWorld.getChunkFromBlockCoords(pX, pZ); + long post = System.nanoTime(); + + GalacticGreg.Logger.info("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3); + + Chunk tChunk = world.getChunkFromBlockCoords(chunkX, chunkZ); if (tChunk != null) { - tChunk.isModified = true; + tChunk.isModified = modified; } } } - private void generateAsteroids(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ) { - GalacticGreg.Logger.trace("Running asteroid-gen in Dim %s", pDimensionDef.getDimIdentifier()); + private static class AsteroidGenerator { + public List positive, negative; + public int cX, cY, cZ, radius; + public long seed; - DynamicDimensionConfig.AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(pDimensionDef); - - if (dimAsteroidConfig == 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", dimAsteroidConfig.Probability); - } + public StoneType stoneType; + public transient IWorldgenLayer ore; - if (dimAsteroidConfig.Probability <= 1 || pRandom.nextInt(dimAsteroidConfig.Probability) == 0) { - GalacticGreg.Logger.trace("Generating asteroid NOW"); - // --------------------------- - if (GalacticGreg.GalacticConfig.ProfileOreGen || profileWorldGen) mProfilingStart = System.currentTimeMillis(); - // ----------------------------- + public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedChunkZ) { + ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world); + AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); + + if (!generatesAsteroid(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId, dimAsteroidConfig.Probability)) return null; - AsteroidBlockComb asteroidStone = pDimensionDef.getRandomAsteroidMaterial(); - if (asteroidStone == null) return; + XSTR rng = getRandom(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId); - // Select Random OreGroup and Asteroid Material - IWorldgenLayer oreLayer; + AsteroidBlockComb asteroidStone = dimensionDef.getRandomAsteroidMaterial(rng); + if (asteroidStone == null) return null; int minY, maxY; + IWorldgenLayer oreLayer; - if (pRandom.nextInt(5) == 0) { + if (rng.nextInt(5) == 0) { oreLayer = WorldgenQuery.small() - .inDimension(pDimensionDef) + .inDimension(dimensionDef) .inStone(asteroidStone.getStone().getCategory()) - .find(pRandom); + .find(rng.clone()); minY = oreLayer == null ? 50 : oreLayer.getMinY(); maxY = oreLayer == null ? 200 : oreLayer.getMaxY(); } else { oreLayer = WorldgenQuery.veins() - .inDimension(pDimensionDef) + .inDimension(dimensionDef) .inStone(asteroidStone.getStone().getCategory()) - .find(pRandom); + .find(rng.clone()); minY = oreLayer == null ? 50 : oreLayer.getMinY(); maxY = oreLayer == null ? 200 : oreLayer.getMaxY(); } - if (oreLayer == null) return; + if (oreLayer == null) return null; - // Get Random position - int tX = pX + pRandom.nextInt(16); - int tY = minY + pRandom.nextInt(maxY - minY); - int tZ = pZ + pRandom.nextInt(16); - GalacticGreg.Logger.debug( - "Asteroid will be build with: Stone: [%s] Ore: [%s]", + "Asteroid will be built with: Stone: [%s] Ore: [%s]", asteroidStone.getStone(), oreLayer.getName()); - // Check if position is free - if (pWorld.isAirBlock(tX, tY, tZ)) { - - // 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; - } + int tX = seedChunkX * 16 + rng.nextInt(16); + int tY = minY + rng.nextInt(maxY - minY); + int tZ = seedChunkZ * 16 + rng.nextInt(16); - aGen.reset(); - aGen.setCenterPoint(tX, tY, tZ); - aGen.randomize((int) oreLayer.getSize(), (int) oreLayer.getSize() * 2); // 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 (dimAsteroidConfig.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 - // happened) - if (dimAsteroidConfig.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 (dimAsteroidConfig.RandomizeNumLootItems) tNumLootItems = pRandom.nextInt(dimAsteroidConfig.NumLootItems - 1) + 1; - else tNumLootItems = dimAsteroidConfig.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 (!world.isAirBlock(tX, tY, tZ)) return null; + + int asteroidSize = (mEndAsteroidMinSize + rng.nextInt(mEndAsteroidMaxSize - mEndAsteroidMinSize + 1)); + + List positive = new ArrayList<>(); + List negative = new ArrayList<>(); + + int radius = rng.nextInt(asteroidSize / 4); + positive.add(new Ellipsoid(0, 0, 0, radius)); + + 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))); + } + + k = rng.nextInt(2); + 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))); + } + + AsteroidGenerator gen = new AsteroidGenerator(); + + gen.positive = positive; + gen.negative = negative; + + gen.cX = tX; + gen.cY = tY; + gen.cZ = tZ; + gen.radius = asteroidSize; + + gen.seed = rng.nextLong(); + + gen.stoneType = asteroidStone.getStone(); + gen.ore = oreLayer; + + return gen; + } + + public boolean affectsChunk(int chunkX, int chunkZ) { + int minX = getChunkCoord(cX - radius); + int maxX = getChunkCoord(cX + radius + 1); + + int minZ = getChunkCoord(cZ - radius); + int maxZ = getChunkCoord(cZ + radius + 1); + + 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 - radius); + int maxX = Math.min((chunkX + 1) * 16, cX + radius + 1); + + int minY = Math.max(0, cY - radius); + int maxY = Math.min(255, cY + radius + 1); + + int minZ = Math.max(chunkZ * 16, cZ - radius); + int maxZ = Math.min((chunkZ + 1) * 16, cZ + radius + 1); + + XSTR rng = new XSTR(seed); + + ModDimensionDef def = DimensionDef.getDefForWorld(world); + AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(def); + + 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; } - } - } - // 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(dimAsteroidConfig), 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; + for (Ellipsoid e : negative) { + if (e.dist2(rng, x - cX + 0.5f, y - cY + 0.5f, z - cZ + 0.5f) <= 1) { + continue outer; } } - // << Loot-chest generator === - boolean tPlacedAnything = false; + float dist = 2f; + + for (Ellipsoid e : positive) { + dist = Math.min(dist, e.dist2(rng, x - cX + 0.5f, y - cY + 0.5f, z - cZ + 0.5f)); + } - boolean canPlaceOre = !dimAsteroidConfig.HiddenOres || si.getBlockPosition() == Enums.TargetBlockPosition.AsteroidShell; + if (dist >= 1) continue; + + boolean placedAnything = false; // try to place big ores, if the ore vein creates big ore - if (canPlaceOre && oreLayer.generatesBigOre()) { - if (!tPlacedAnything) { - tPlacedAnything = generateOreBlock( - pRandom, - pWorld, - si.getX(), - si.getY(), - si.getZ(), - asteroidStone, - oreLayer, - false); + if (ore.generatesBigOre()) { + if (!placedAnything) { + placedAnything = generateOreBlock(rng, world, x, y, z, stoneType, ore, false, dist); } } // try to place any special blocks - if (!tPlacedAnything) { - tPlacedAnything = generateSpecialBlocks( - pDimensionDef, - pRandom, - pWorld, + if (!placedAnything) { + placedAnything = generateSpecialBlocks( + def, + rng, + world, dimAsteroidConfig, - si.getX(), - si.getY(), - si.getZ(), - si.getBlockPosition()); + x, + y, + z, + dist < 1f / 3f ? TargetBlockPosition.AsteroidInnerCore : dist < 2f / 3f ? TargetBlockPosition.AsteroidCore : TargetBlockPosition.AsteroidShell); } // try to place small ores - if (canPlaceOre) { - if (!tPlacedAnything) { - tPlacedAnything = generateOreBlock( - pRandom, - pWorld, - si.getX(), - si.getY(), - si.getZ(), - asteroidStone, - oreLayer, - true); - } + if (!placedAnything) { + placedAnything = generateOreBlock( + rng, + world, + x, + y, + z, + stoneType, + ore, + true, + rng.nextFloat()); } // no smallores either? do normal block - if (!tPlacedAnything) { - pWorld.setBlock( - si.getX(), - si.getY(), - si.getZ(), - asteroidStone.getBlock(), - asteroidStone.getMeta(), - 3); + if (!placedAnything) { + world.setBlock( + x, + y, + z, + stoneType.getStone().left(), + stoneType.getStone().rightInt(), + 2); } - - // << Additional special blocks === } } } - // --------------------------- - // OreGen profiler stuff - if (GalacticGreg.GalacticConfig.ProfileOreGen || profileWorldGen) { - try { - mProfilingEnd = System.currentTimeMillis(); - long tTotalTime = mProfilingEnd - mProfilingStart; - GalacticGreg.Profiler.AddTimeToList(pDimensionDef, tTotalTime); - GalacticGreg.Logger.info( - "Done with Asteroid-Worldgen in DimensionType %s. Generation took %d ms", - pDimensionDef.getDimensionName(), - tTotalTime); - } catch (Exception ignored) {} // Silently ignore errors - } - // --------------------------- } - GalacticGreg.Logger.trace("Leaving asteroid-gen for Dim %s", pDimensionDef.getDimIdentifier()); } + private static int getChunkCoord(int k) { + if (k < 0) { + return GTUtility.ceilDiv2(k, 16); + } else { + return k / 16; + } + } + + /** 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; + } + + // private void generateAsteroids(World world, int chunkX, int chunkZ, long seed) { + // ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world); + + // GalacticGreg.Logger.trace("Running asteroid-gen in Dim %s", dimensionDef.getDimIdentifier()); + + // DynamicDimensionConfig.AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); + + // if (dimAsteroidConfig == null) { + // GalacticGreg.Logger.error( + // "Dimension %s is set to asteroid, but no config object can be found. Skipping!", + // dimensionDef.getDimIdentifier()); + // return; + // } else { + // GalacticGreg.Logger.trace("Asteroid probability: %d", dimAsteroidConfig.Probability); + // } + + // XSTR random = new XSTR(seed); + + // if (dimAsteroidConfig.Probability <= 1 || random.nextInt(dimAsteroidConfig.Probability) == 0) { + // GalacticGreg.Logger.trace("Generating asteroid NOW"); + + // long startTime = 0; + + // if (GalacticGreg.GalacticConfig.ProfileOreGen || profileWorldGen) { + // startTime = System.currentTimeMillis(); + // } + + // AsteroidGenerator generators = AsteroidGenerator.generate(world, chunkX, chunkZ, dimensionDef, random.nextLong()); + + // if (generators == null) { + // GalacticGreg.Logger.trace("Not generating asteroid"); + // return; + // } + + // world.getChunkProvider().loadChunk(0, 0); + + // // Check if position is free + // if (world.isAirBlock(tX, tY, tZ)) { + // boolean tDoLootChest = dimAsteroidConfig.LootChestChance > 0 && asteroidSize > 6; + + // if (tDoLootChest) { + // GalacticGreg.Logger.trace("Random loot chest enabled, flipping the coin"); + // // Loot chest is 1 in 100 (Was: 1:1000 which actually never happened) + // int tChance = pRandom.nextInt(100); + + // if (dimAsteroidConfig.LootChestChance >= tChance) { + // GalacticGreg.Logger.debug("We got a match. Preparing to generate the loot chest"); + + // for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) { + // if (world.isAirBlock(tX + d.offsetX, tY + d.offsetY, tZ + d.offsetZ)) { + // tDoLootChest = false; + // break; + // } + // } + // } else { + // tDoLootChest = false; + // } + // } + + // if (tDoLootChest) { + // 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 (dimAsteroidConfig.RandomizeNumLootItems) { + // tNumLootItems = pRandom.nextInt(dimAsteroidConfig.NumLootItems - 1) + 1; + // } else { + // tNumLootItems = dimAsteroidConfig.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(dimAsteroidConfig), pRandom); + + // // Get chest-block to spawn + // BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; + + // // Place down the chest + // world.setBlock( + // tX, + // tY, + // tZ, + // tTargetChestType.getBlock(), + // tTargetChestType.getMeta(), + // 2); + + // // Retrieve the TEs IInventory that should've been created + // IInventory entityChestInventory = (IInventory) world.getTileEntity(tX, tY, tZ); + + // // 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( + // 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", + // tX, + // tY, + // tZ); + // } + + // // Do some debug logging + // GalacticGreg.Logger + // .debug("Generated LootChest at X[%d] Y[%d] Z[%d]", tX, tY, tZ); + // } + // } + + // // --------------------------- + // // OreGen profiler stuff + // if (GalacticGreg.GalacticConfig.ProfileOreGen || profileWorldGen) { + // try { + // long endTime = System.currentTimeMillis(); + // long tTotalTime = endTime - startTime; + // GalacticGreg.Profiler.AddTimeToList(dimensionDef, tTotalTime); + // GalacticGreg.Logger.info( + // "Done with Asteroid-Worldgen in DimensionType %s. Generation took %d ms", + // dimensionDef.getDimensionName(), + // tTotalTime); + // } catch (Exception ignored) {} // Silently ignore errors + // } + // // --------------------------- + // } + // GalacticGreg.Logger.trace("Leaving asteroid-gen for Dim %s", dimensionDef.getDimIdentifier()); + // } + /** * Generate Special Blocks in asteroids if enabled * - * @param pDimensionDef - * @param pRandom - * @param pWorld - * @param tAConf - * @param eX - * @param eY - * @param eZ + * @param dimensionDef + * @param rng + * @param world + * @param asteroidConfig + * @param x + * @param y + * @param z * @return */ - private boolean generateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, - DynamicDimensionConfig.AsteroidConfig tAConf, int eX, int eY, int eZ, - Enums.TargetBlockPosition pBlockPosition) { - + 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); + 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.getMeta(), 2); return true; } } @@ -435,12 +506,12 @@ private boolean generateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRan return false; } - private boolean generateOreBlock(Random pRandom, World pWorld, int pX, int pY, int pZ, AsteroidBlockComb asteroidStone, IWorldgenLayer oreLayer, boolean small) { - if (pRandom.nextFloat() <= oreLayer.getDensity()) { - IMaterial mat = oreLayer.getOre(pRandom.nextFloat()); + private static boolean generateOreBlock(Random rng, World pWorld, int pX, int pY, int pZ, IStoneType stoneType, IWorldgenLayer oreLayer, boolean small, float control) { + if (rng.nextFloat() <= oreLayer.getDensity()) { + IMaterial mat = oreLayer.getOre(control); if (mat != null) { - OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, asteroidStone.getStone(), mat, small); + OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, small); return true; } } @@ -448,123 +519,6 @@ private boolean generateOreBlock(Random pRandom, World pWorld, int pX, int pY, i return false; } - private void generateEndAsteroid(ModDimensionDef tDimDef, World world, Random random2, int chunkX, int chunkZ) { - XSTR random = new XSTR(random2.nextLong()); - - int tX = chunkX * 16 + random.nextInt(16); - int tY = 50 + random.nextInt(100 - 50); - int tZ = chunkZ * 16 + random.nextInt(16); - int asteroidSize = (mEndAsteroidMinSize + random.nextInt(mEndAsteroidMaxSize - mEndAsteroidMinSize + 1)) / 2; - - WorldgenGTOreLayer selectedOreLayer = WorldgenQuery.veins() - .inDimension(tDimDef) - .find(random); - - // should never happen, but let's be safe - if (selectedOreLayer == null) return; - - if (world.isAirBlock(tX, tY, tZ)) { - - List positive = new ArrayList<>(); - List negative = new ArrayList<>(); - - { - int radius = random.nextInt(asteroidSize); - positive.add(new Ellipsoid(0, 0, 0, radius)); - - int k = random.nextInt(2); - for (int i = 0; i < k; i++) { - negative.add(new Ellipsoid( - radius * (random.nextFloat() * 2 - 1), - radius * (random.nextFloat() * 2 - 1), - radius * (random.nextFloat() * 2 - 1), - radius * (random.nextFloat() * 0.25f + 0.6f))); - } - - k = random.nextInt(2); - for (int i = 0; i < k; i++) { - positive.add(new Ellipsoid( - radius * (random.nextFloat() * 2 - 1), - radius * (random.nextFloat() * 2 - 1), - radius * (random.nextFloat() * 2 - 1), - radius * (random.nextFloat() * 0.25f + 0.6f))); - } - } - - for (int x = -asteroidSize * 2; x < asteroidSize * 2; x++) { - for (int z = -asteroidSize * 2; z < asteroidSize * 2; z++) { - y: for (int y = -asteroidSize * 2; y < asteroidSize * 2; y++) { - - if (y + tY < 0) continue; - if (y + tY >= 255) continue; - - for (Ellipsoid e : negative) { - if (e.contains(random, x, y, z)) { - continue y; - } - } - - boolean place = false; - - for (Ellipsoid e : positive) { - if (e.contains(random, x, y, z)) { - place = true; - break; - } - } - - if (!place) continue; - - if (!world.isAirBlock(tX + x, tY + y, tZ + z)) { - continue; - } - - int ranOre = random.nextInt(50); - if (ranOre < 3) { - OreManager.setOreForWorldGen( - world, - tX + x, - tY + y, - tZ + z, - StoneType.Endstone, - selectedOreLayer.mPrimary, - false); - } else if (ranOre < 6) { - OreManager.setOreForWorldGen( - world, - tX + x, - tY + y, - tZ + z, - StoneType.Endstone, - selectedOreLayer.mSecondary, - false); - } else if (ranOre < 8) { - OreManager.setOreForWorldGen( - world, - tX + x, - tY + y, - tZ + z, - StoneType.Endstone, - selectedOreLayer.mBetween, - false); - } else if (ranOre < 10) { - OreManager.setOreForWorldGen( - world, - tX + x, - tY + y, - tZ + z, - StoneType.Endstone, - selectedOreLayer.mSporadic, - false); - } else { - world.setBlock(tX + x, tY + y, tZ + z, Blocks.end_stone, 0, 3); - } - } - } - } - } - } - private static class Ellipsoid { public float x, y, z, r; @@ -575,21 +529,21 @@ public Ellipsoid(float x, float y, float z, float size) { r = 1 / size; } - public boolean contains(Random rng, float dx, float dy, float dz) { + 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 false; + if (dist > 1) return dist; if (dist > 0.8) { float f = rng.nextFloat(); dist += f * 0.4; } - return dist < 1; + return dist; } } } diff --git a/src/main/java/galacticgreg/api/AsteroidBlockComb.java b/src/main/java/galacticgreg/api/AsteroidBlockComb.java index ba85da820e5..28a98ee2699 100644 --- a/src/main/java/galacticgreg/api/AsteroidBlockComb.java +++ b/src/main/java/galacticgreg/api/AsteroidBlockComb.java @@ -1,6 +1,6 @@ package galacticgreg.api; -import gregtech.api.interfaces.IStoneType; +import gregtech.api.enums.StoneType; import net.minecraft.block.Block; /** @@ -9,7 +9,7 @@ */ public class AsteroidBlockComb extends BlockMetaComb { - private final IStoneType stoneType; + private final StoneType stoneType; /** * Create an advanced definition which uses the GregTech-OreType values for ores, and your own definition of Block @@ -18,7 +18,7 @@ public class AsteroidBlockComb extends BlockMetaComb { * @param pOreType The GregTech oreType * @param pBlock Your block */ - public AsteroidBlockComb(IStoneType stoneType, Block pBlock) { + public AsteroidBlockComb(StoneType stoneType, Block pBlock) { super(pBlock, 0); this.stoneType = stoneType; } @@ -31,7 +31,7 @@ public AsteroidBlockComb(IStoneType stoneType, Block pBlock) { * @param pBlock Your block * @param pMeta The metavalue for your block (If required) */ - public AsteroidBlockComb(IStoneType stoneType, Block pBlock, int pMeta) { + public AsteroidBlockComb(StoneType stoneType, Block pBlock, int pMeta) { super(pBlock, pMeta); this.stoneType = stoneType; } @@ -41,7 +41,7 @@ public AsteroidBlockComb(IStoneType stoneType, Block pBlock, int pMeta) { * * @param pOreType The GregTech oreType */ - public AsteroidBlockComb(IStoneType stoneType) { + public AsteroidBlockComb(StoneType stoneType) { super(stoneType.getStone().left(), stoneType.getStone().rightInt()); this.stoneType = stoneType; } @@ -51,7 +51,7 @@ public AsteroidBlockComb(IStoneType stoneType) { * * @return The GT Material for the oregen */ - public IStoneType getStone() { + public StoneType getStone() { return stoneType; } diff --git a/src/main/java/galacticgreg/api/ModDimensionDef.java b/src/main/java/galacticgreg/api/ModDimensionDef.java index dcb717a4fc5..de08718a440 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -5,6 +5,7 @@ import java.util.Random; import galacticgreg.api.Enums.DimensionType; +import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IStoneType; import net.minecraft.block.Block; import net.minecraft.world.chunk.IChunkProvider; @@ -361,13 +362,13 @@ public Enums.ReplaceState getReplaceStateForBlock(Block pBlock, int pMeta) { * * @return */ - public AsteroidBlockComb getRandomAsteroidMaterial() { + public AsteroidBlockComb getRandomAsteroidMaterial(Random rng) { if (validAsteroidMaterials.isEmpty()) return null; if (validAsteroidMaterials.size() == 1) { return validAsteroidMaterials.get(0); } else { - return validAsteroidMaterials.get(random.nextInt(validAsteroidMaterials.size())); + return validAsteroidMaterials.get(rng.nextInt(validAsteroidMaterials.size())); } } @@ -378,13 +379,13 @@ public AsteroidBlockComb getRandomAsteroidMaterial() { * * @return */ - public SpecialBlockComb getRandomSpecialAsteroidBlock() { + public SpecialBlockComb getRandomSpecialAsteroidBlock(Random rng) { if (specialBlocksForAsteroids.isEmpty()) return null; if (specialBlocksForAsteroids.size() == 1) { return specialBlocksForAsteroids.get(0); } else { - return specialBlocksForAsteroids.get(random.nextInt(specialBlocksForAsteroids.size())); + return specialBlocksForAsteroids.get(rng.nextInt(specialBlocksForAsteroids.size())); } } @@ -393,7 +394,7 @@ public SpecialBlockComb getRandomSpecialAsteroidBlock() { * * @param pMaterial */ - public void addAsteroidMaterial(IStoneType stoneType) { + public void addAsteroidMaterial(StoneType stoneType) { addAsteroidMaterial(new AsteroidBlockComb(stoneType)); } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 089f214e1c1..5ccd7809d42 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -4560,6 +4560,29 @@ public static long ceilDiv(long lhs, long rhs) { return (lhs + rhs - 1) / rhs; } + /** Handles negatives properly, but it's slower than {@link #ceilDiv(int, int)}. */ + public static int ceilDiv2(int lhs, int rhs) { + int sign = signum(lhs) * signum(rhs); + + if (lhs == 0) return 0; + if (rhs == 0) throw new ArithmeticException("/ by zero"); + + lhs = Math.abs(lhs); + rhs = Math.abs(rhs); + + int unsigned = 1 + ((lhs - 1) / rhs); + + return unsigned * sign; + } + + public static int signum(int x) { + return x < 0 ? -1 : x > 0 ? 1 : 0; + } + + public static long signum(long x) { + return x < 0 ? -1 : x > 0 ? 1 : 0; + } + /** * Hash an item stack for the purpose of storing hash across launches */ diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index 683f131727a..216898423b8 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -131,7 +131,7 @@ public OreInfo getOreInfo(Block block, int meta) { if (!OrePrefixes.ore.doGenerateItem(mat)) return null; StoneType stoneType = GTUtility.getIndexSafe(oreBlock.stoneTypes, stoneId); - if (!stoneType.isEnabled()) return null; + if (stoneType == null || !stoneType.isEnabled()) return null; OreInfo info = OreInfo.getNewInfo(); diff --git a/src/main/java/gregtech/common/ores/OreManager.java b/src/main/java/gregtech/common/ores/OreManager.java index d9f9129235e..1db36d104b3 100644 --- a/src/main/java/gregtech/common/ores/OreManager.java +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -92,7 +92,7 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone var block = oreAdapter.getBlock(info); if (block != null) { - world.setBlock(x, y, z, block.left(), block.rightInt(), 3); + world.setBlock(x, y, z, block.left(), block.rightInt(), 2); return true; } @@ -115,7 +115,7 @@ public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneT var block = oreAdapter.getBlock(info); if (block != null) { - world.setBlock(x, y, z, block.left(), block.rightInt(), 3); + world.setBlock(x, y, z, block.left(), block.rightInt(), 2); return true; } @@ -139,7 +139,7 @@ public static boolean setExistingOreStoneType(World world, int x, int y, int z, if (block == null) return false; - world.setBlock(x, y, z, block.left(), block.rightInt(), 3); + world.setBlock(x, y, z, block.left(), block.rightInt(), 2); return true; } From 63b918397334c505fd79dced57f88256b7062cd6 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Wed, 11 Dec 2024 14:38:24 -0500 Subject: [PATCH 07/47] fix tools casting meta to byte --- .../items/tools/DetravToolElectricProspectorBase.java | 6 +++--- src/main/java/gregtech/api/interfaces/IToolStats.java | 8 ++++---- src/main/java/gregtech/api/items/MetaGeneratedTool.java | 4 ++-- src/main/java/gregtech/api/util/GTToolHarvestHelper.java | 2 +- src/main/java/gregtech/common/GTProxy.java | 6 +++--- .../gregtech/common/items/behaviors/BehaviourCrowbar.java | 2 +- .../common/items/behaviors/BehaviourScrewdriver.java | 2 +- .../common/items/behaviors/BehaviourSoftHammer.java | 2 +- src/main/java/gregtech/common/tools/GTTool.java | 4 ++-- src/main/java/gregtech/common/tools/ToolAxe.java | 6 +++--- src/main/java/gregtech/common/tools/ToolBranchCutter.java | 4 ++-- .../java/gregtech/common/tools/ToolButcheryKnife.java | 2 +- src/main/java/gregtech/common/tools/ToolBuzzSaw.java | 2 +- src/main/java/gregtech/common/tools/ToolChainsawLV.java | 4 ++-- src/main/java/gregtech/common/tools/ToolCrowbar.java | 2 +- src/main/java/gregtech/common/tools/ToolDrillLV.java | 2 +- src/main/java/gregtech/common/tools/ToolFile.java | 2 +- src/main/java/gregtech/common/tools/ToolHardHammer.java | 4 ++-- src/main/java/gregtech/common/tools/ToolHoe.java | 2 +- src/main/java/gregtech/common/tools/ToolJackHammer.java | 4 ++-- src/main/java/gregtech/common/tools/ToolMortar.java | 2 +- src/main/java/gregtech/common/tools/ToolPickaxe.java | 2 +- src/main/java/gregtech/common/tools/ToolPlow.java | 6 +++--- src/main/java/gregtech/common/tools/ToolPlunger.java | 2 +- src/main/java/gregtech/common/tools/ToolRollingPin.java | 2 +- src/main/java/gregtech/common/tools/ToolSaw.java | 4 ++-- src/main/java/gregtech/common/tools/ToolScoop.java | 2 +- src/main/java/gregtech/common/tools/ToolScrewdriver.java | 2 +- src/main/java/gregtech/common/tools/ToolSense.java | 6 +++--- src/main/java/gregtech/common/tools/ToolShovel.java | 2 +- src/main/java/gregtech/common/tools/ToolSoftHammer.java | 2 +- .../java/gregtech/common/tools/ToolSolderingIron.java | 2 +- src/main/java/gregtech/common/tools/ToolSword.java | 2 +- src/main/java/gregtech/common/tools/ToolTurbine.java | 2 +- .../java/gregtech/common/tools/ToolUniversalSpade.java | 2 +- src/main/java/gregtech/common/tools/ToolWireCutter.java | 2 +- src/main/java/gregtech/common/tools/ToolWrench.java | 6 +++--- .../gregtech/common/tools/pocket/ToolPocketMultitool.java | 2 +- .../xmod/gregtech/api/interfaces/internal/IToolStats.java | 4 ++-- .../gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java | 2 +- .../xmod/gregtech/common/tools/ToolAngleGrinder.java | 4 ++-- 41 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java b/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java index 66d38c39ea9..67742c349c8 100644 --- a/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java +++ b/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java @@ -138,14 +138,14 @@ public boolean isMiningTool() { return false; } - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } @Override public int convertBlockDrops(List list, ItemStack itemStack, EntityPlayer entityPlayer, Block block, - int i, int i1, int i2, byte b, int i3, boolean b1, BlockEvent.HarvestDropsEvent harvestDropsEvent) { + int i, int i1, int i2, int b, int i3, boolean b1, BlockEvent.HarvestDropsEvent harvestDropsEvent) { return 0; } @@ -193,7 +193,7 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase + EnumChatFormatting.WHITE); } - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ) { return aDefault; } diff --git a/src/main/java/gregtech/api/interfaces/IToolStats.java b/src/main/java/gregtech/api/interfaces/IToolStats.java index 64fc81196c8..052dccfc521 100644 --- a/src/main/java/gregtech/api/interfaces/IToolStats.java +++ b/src/main/java/gregtech/api/interfaces/IToolStats.java @@ -47,7 +47,7 @@ public interface IToolStats { * @param tile TileEntity of the block if exist * @param event the event, cancel it to prevent the block from being broken */ - default void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, byte metadata, + default void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, int metadata, @Nullable TileEntity tile, @Nonnull BlockEvent.BreakEvent event) {} /** @@ -164,7 +164,7 @@ default boolean isScrewdriver() { * @return If this is a minable Block. Tool Quality checks (like Diamond Tier or something) are separate from this * check. */ - boolean isMinableBlock(Block aBlock, byte aMetaData); + boolean isMinableBlock(Block aBlock, int aMetaData); /** * This lets you modify the Drop List, when this type of Tool has been used. @@ -172,7 +172,7 @@ default boolean isScrewdriver() { * @return the Amount of modified Items, used to determine the extra durability cost */ int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, int aY, - int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); + int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); /** * @return Returns a broken Version of the Item. @@ -193,7 +193,7 @@ int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPl short[] getRGBa(boolean aIsToolHead, ItemStack aStack); - float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, + float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, int aY, int aZ); default String getToolTypeName() { diff --git a/src/main/java/gregtech/api/items/MetaGeneratedTool.java b/src/main/java/gregtech/api/items/MetaGeneratedTool.java index eaa1fe7c8d5..9901ff1c533 100644 --- a/src/main/java/gregtech/api/items/MetaGeneratedTool.java +++ b/src/main/java/gregtech/api/items/MetaGeneratedTool.java @@ -256,7 +256,7 @@ public final ItemStack getToolWithStats(int aToolID, int aAmount, Materials aPri */ @Mod.EventHandler public void onHarvestBlockEvent(ArrayList aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, - int aX, int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aX, int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { IToolStats tStats = getToolStats(aStack); if (isItemStackUsable(aStack) && getDigSpeed(aStack, aBlock, aMetaData) > 0.0F) doDamage( aStack, @@ -267,7 +267,7 @@ public void onHarvestBlockEvent(ArrayList aDrops, ItemStack aStack, E @Mod.EventHandler public float onBlockBreakSpeedEvent(float aDefault, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, PlayerEvent.BreakSpeed aEvent) { + int aY, int aZ, int aMetaData, PlayerEvent.BreakSpeed aEvent) { IToolStats tStats = getToolStats(aStack); return tStats == null ? aDefault : tStats.getMiningSpeed(aBlock, aMetaData, aDefault, aPlayer, aPlayer.worldObj, aX, aY, aZ); diff --git a/src/main/java/gregtech/api/util/GTToolHarvestHelper.java b/src/main/java/gregtech/api/util/GTToolHarvestHelper.java index 8dd5d6b93c4..5a09aaf6538 100644 --- a/src/main/java/gregtech/api/util/GTToolHarvestHelper.java +++ b/src/main/java/gregtech/api/util/GTToolHarvestHelper.java @@ -12,7 +12,7 @@ public class GTToolHarvestHelper { - public static boolean isAppropriateTool(Block aBlock, byte aMetaData, String... tTools) { + public static boolean isAppropriateTool(Block aBlock, int aMetaData, String... tTools) { if (aBlock == null || tTools == null) { return false; diff --git a/src/main/java/gregtech/common/GTProxy.java b/src/main/java/gregtech/common/GTProxy.java index a303d1bb042..8f8b3188941 100644 --- a/src/main/java/gregtech/common/GTProxy.java +++ b/src/main/java/gregtech/common/GTProxy.java @@ -1562,7 +1562,7 @@ public void onBlockBreakingEvent(BlockEvent.BreakEvent event) { if (stats == null) return; TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z); - stats.onBreakBlock(player, event.x, event.y, event.z, event.block, (byte) event.blockMetadata, tile, event); + stats.onBreakBlock(player, event.x, event.y, event.z, event.block, event.blockMetadata, tile, event); } @SubscribeEvent @@ -1581,7 +1581,7 @@ public void onBlockHarvestingEvent(BlockEvent.HarvestDropsEvent aEvent) { aEvent.x, aEvent.y, aEvent.z, - (byte) aEvent.blockMetadata, + aEvent.blockMetadata, aEvent.fortuneLevel, aEvent.isSilkTouching, aEvent); @@ -2722,7 +2722,7 @@ public void onBlockBreakSpeedEvent(PlayerEvent.BreakSpeed aEvent) { aEvent.x, aEvent.y, aEvent.z, - (byte) aEvent.metadata, + aEvent.metadata, aEvent); } } diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java b/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java index 76c215bfd00..da9b3f336a3 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java @@ -37,7 +37,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (aBlock == null) { return false; } - byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); + int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); if (aBlock == Blocks.rail) { if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) { aWorld.isRemote = true; diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourScrewdriver.java b/src/main/java/gregtech/common/items/behaviors/BehaviourScrewdriver.java index 599398349f8..029f94fc5c8 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourScrewdriver.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourScrewdriver.java @@ -32,7 +32,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (aBlock == null) { return false; } - byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); + int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); if ((aBlock == Blocks.unpowered_repeater) || (aBlock == Blocks.powered_repeater)) { if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) { aWorld.setBlockMetadataWithNotify(aX, aY, aZ, aMeta / 4 * 4 + (aMeta % 4 + 1) % 4, 3); diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourSoftHammer.java b/src/main/java/gregtech/common/items/behaviors/BehaviourSoftHammer.java index 83e458276db..72c930ac60f 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourSoftHammer.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourSoftHammer.java @@ -35,7 +35,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (aBlock == null) { return false; } - byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); + int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); if (aBlock == Blocks.lit_redstone_lamp) { if ((aPlayer.capabilities.isCreativeMode) || (((MetaGeneratedTool) aItem).doDamage(aStack, this.mCosts))) { aWorld.isRemote = true; diff --git a/src/main/java/gregtech/common/tools/GTTool.java b/src/main/java/gregtech/common/tools/GTTool.java index 436ec767a99..78fc28883f9 100644 --- a/src/main/java/gregtech/common/tools/GTTool.java +++ b/src/main/java/gregtech/common/tools/GTTool.java @@ -142,7 +142,7 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { return 0; } @@ -184,7 +184,7 @@ public float getMagicDamageAgainstEntity(float aOriginalDamage, Entity aEntity, } @Override - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, int aY, int aZ) { return aDefault; } diff --git a/src/main/java/gregtech/common/tools/ToolAxe.java b/src/main/java/gregtech/common/tools/ToolAxe.java index 03b761227c7..5ae172f4ea8 100644 --- a/src/main/java/gregtech/common/tools/ToolAxe.java +++ b/src/main/java/gregtech/common/tools/ToolAxe.java @@ -93,7 +93,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "axe") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.wood) || GTToolHarvestHelper.isSpecialBlock(aBlock, Blocks.ladder); @@ -101,7 +101,7 @@ public boolean isMinableBlock(Block aBlock, byte aMetaData) { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rAmount = 0; if ((GregTechAPI.sTimber) && (!aPlayer.isSneaking()) && (OrePrefixes.log.contains(new ItemStack(aBlock, 1, aMetaData)))) { @@ -118,7 +118,7 @@ public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPla } @Override - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ) { if (aBlock.isWood(aPlayer.worldObj, aX, aY, aZ) diff --git a/src/main/java/gregtech/common/tools/ToolBranchCutter.java b/src/main/java/gregtech/common/tools/ToolBranchCutter.java index c9ad255a457..54a17c9f9c2 100644 --- a/src/main/java/gregtech/common/tools/ToolBranchCutter.java +++ b/src/main/java/gregtech/common/tools/ToolBranchCutter.java @@ -45,7 +45,7 @@ public boolean isGrafter() { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { if (aBlock.getMaterial() == Material.leaves) { aEvent.dropChance = Math.min( 1.0F, @@ -72,7 +72,7 @@ public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPla } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "grafter") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.leaves); } diff --git a/src/main/java/gregtech/common/tools/ToolButcheryKnife.java b/src/main/java/gregtech/common/tools/ToolButcheryKnife.java index 43323b84047..926a1440aaa 100644 --- a/src/main/java/gregtech/common/tools/ToolButcheryKnife.java +++ b/src/main/java/gregtech/common/tools/ToolButcheryKnife.java @@ -98,7 +98,7 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } } diff --git a/src/main/java/gregtech/common/tools/ToolBuzzSaw.java b/src/main/java/gregtech/common/tools/ToolBuzzSaw.java index 7e62ab7bb42..e47b1c00742 100644 --- a/src/main/java/gregtech/common/tools/ToolBuzzSaw.java +++ b/src/main/java/gregtech/common/tools/ToolBuzzSaw.java @@ -50,7 +50,7 @@ public String getMiningSound() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } diff --git a/src/main/java/gregtech/common/tools/ToolChainsawLV.java b/src/main/java/gregtech/common/tools/ToolChainsawLV.java index ad47ae2cdc0..3ce73a6f29c 100644 --- a/src/main/java/gregtech/common/tools/ToolChainsawLV.java +++ b/src/main/java/gregtech/common/tools/ToolChainsawLV.java @@ -106,7 +106,7 @@ public void onToolCrafted(ItemStack aStack, EntityPlayer aPlayer) { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rAmount = 0; if ((aBlock.getMaterial() == Material.leaves) && ((aBlock instanceof IShearable))) { aPlayer.worldObj.setBlock(aX, aY, aZ, aBlock, aMetaData, 0); @@ -137,7 +137,7 @@ public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPla } @Override - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ) { if (aBlock.isWood(aPlayer.worldObj, aX, aY, aZ) && OrePrefixes.log.contains(new ItemStack(aBlock, 1, aMetaData))) { diff --git a/src/main/java/gregtech/common/tools/ToolCrowbar.java b/src/main/java/gregtech/common/tools/ToolCrowbar.java index db72d65a6dc..516c0138161 100644 --- a/src/main/java/gregtech/common/tools/ToolCrowbar.java +++ b/src/main/java/gregtech/common/tools/ToolCrowbar.java @@ -90,7 +90,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { if (aBlock.getMaterial() == Material.circuits) { return true; } diff --git a/src/main/java/gregtech/common/tools/ToolDrillLV.java b/src/main/java/gregtech/common/tools/ToolDrillLV.java index 1c6dfd7de3c..db8d46addd0 100644 --- a/src/main/java/gregtech/common/tools/ToolDrillLV.java +++ b/src/main/java/gregtech/common/tools/ToolDrillLV.java @@ -90,7 +90,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "pickaxe", "shovel") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, diff --git a/src/main/java/gregtech/common/tools/ToolFile.java b/src/main/java/gregtech/common/tools/ToolFile.java index 8e64dafdd21..6118f1597ea 100644 --- a/src/main/java/gregtech/common/tools/ToolFile.java +++ b/src/main/java/gregtech/common/tools/ToolFile.java @@ -85,7 +85,7 @@ public boolean isMiningTool() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "file"); } diff --git a/src/main/java/gregtech/common/tools/ToolHardHammer.java b/src/main/java/gregtech/common/tools/ToolHardHammer.java index a5b0a38ee56..323a1637c3e 100644 --- a/src/main/java/gregtech/common/tools/ToolHardHammer.java +++ b/src/main/java/gregtech/common/tools/ToolHardHammer.java @@ -120,7 +120,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "hammer", "pickaxe") || GTToolHarvestHelper .isAppropriateMaterial(aBlock, Material.rock, Material.glass, Material.ice, Material.packedIce) @@ -129,7 +129,7 @@ public boolean isMinableBlock(Block aBlock, byte aMetaData) { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rConversions = 0; GTRecipe tRecipe = RecipeMaps.hammerRecipes.findRecipeQuery() .items(new ItemStack(aBlock, 1, aMetaData)) diff --git a/src/main/java/gregtech/common/tools/ToolHoe.java b/src/main/java/gregtech/common/tools/ToolHoe.java index 8c68d41b44c..e461a9838ba 100644 --- a/src/main/java/gregtech/common/tools/ToolHoe.java +++ b/src/main/java/gregtech/common/tools/ToolHoe.java @@ -83,7 +83,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "hoe") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.gourd); } diff --git a/src/main/java/gregtech/common/tools/ToolJackHammer.java b/src/main/java/gregtech/common/tools/ToolJackHammer.java index bc0a7ddcc0b..24c4815d00d 100644 --- a/src/main/java/gregtech/common/tools/ToolJackHammer.java +++ b/src/main/java/gregtech/common/tools/ToolJackHammer.java @@ -63,7 +63,7 @@ public float getMaxDurabilityMultiplier() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "pickaxe") // || GTToolHarvestHelper.isAppropriateMaterial( aBlock, // @@ -76,7 +76,7 @@ public boolean isMinableBlock(Block aBlock, byte aMetaData) { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rConversions = 0; GTRecipe tRecipe = RecipeMaps.hammerRecipes.findRecipeQuery() .items(new ItemStack(aBlock, 1, aMetaData)) diff --git a/src/main/java/gregtech/common/tools/ToolMortar.java b/src/main/java/gregtech/common/tools/ToolMortar.java index e67e5924de6..c7223807ccc 100644 --- a/src/main/java/gregtech/common/tools/ToolMortar.java +++ b/src/main/java/gregtech/common/tools/ToolMortar.java @@ -85,7 +85,7 @@ public boolean isMiningTool() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } diff --git a/src/main/java/gregtech/common/tools/ToolPickaxe.java b/src/main/java/gregtech/common/tools/ToolPickaxe.java index 91be7dae29f..01102033a66 100644 --- a/src/main/java/gregtech/common/tools/ToolPickaxe.java +++ b/src/main/java/gregtech/common/tools/ToolPickaxe.java @@ -83,7 +83,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "pickaxe") // || GTToolHarvestHelper.isAppropriateMaterial( aBlock, // diff --git a/src/main/java/gregtech/common/tools/ToolPlow.java b/src/main/java/gregtech/common/tools/ToolPlow.java index e0f25fa2f13..0d6167c0591 100644 --- a/src/main/java/gregtech/common/tools/ToolPlow.java +++ b/src/main/java/gregtech/common/tools/ToolPlow.java @@ -36,13 +36,13 @@ public float getBaseDamage() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "plow") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.snow, Material.craftedSnow); } @Override - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, int aY, int aZ) { // Speed nerf for using AOE tools to break single block if (aPlayer != null && aPlayer.isSneaking()) { @@ -53,7 +53,7 @@ public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, Entity @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rConversions = 0; if ((this.sIsHarvestingRightNow.get() == null) && ((aPlayer instanceof EntityPlayerMP))) { this.sIsHarvestingRightNow.set(this); diff --git a/src/main/java/gregtech/common/tools/ToolPlunger.java b/src/main/java/gregtech/common/tools/ToolPlunger.java index 5cb9bcff482..422825833fe 100644 --- a/src/main/java/gregtech/common/tools/ToolPlunger.java +++ b/src/main/java/gregtech/common/tools/ToolPlunger.java @@ -45,7 +45,7 @@ public String getMiningSound() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "plunger"); } diff --git a/src/main/java/gregtech/common/tools/ToolRollingPin.java b/src/main/java/gregtech/common/tools/ToolRollingPin.java index 1af17f3072b..4e7cb251600 100644 --- a/src/main/java/gregtech/common/tools/ToolRollingPin.java +++ b/src/main/java/gregtech/common/tools/ToolRollingPin.java @@ -40,7 +40,7 @@ public float getBaseDamage() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } diff --git a/src/main/java/gregtech/common/tools/ToolSaw.java b/src/main/java/gregtech/common/tools/ToolSaw.java index ca1ec81b137..78942744cf1 100644 --- a/src/main/java/gregtech/common/tools/ToolSaw.java +++ b/src/main/java/gregtech/common/tools/ToolSaw.java @@ -79,7 +79,7 @@ public String getMiningSound() { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { if ((aBlock.getMaterial() == Material.leaves) && ((aBlock instanceof IShearable))) { aPlayer.worldObj.setBlock(aX, aY, aZ, aBlock, aMetaData, 0); if (((IShearable) aBlock).isShearable(aStack, aPlayer.worldObj, aX, aY, aZ)) { @@ -101,7 +101,7 @@ public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPla } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "axe", "saw") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, diff --git a/src/main/java/gregtech/common/tools/ToolScoop.java b/src/main/java/gregtech/common/tools/ToolScoop.java index 6f740da95eb..1ab4c0f9fcf 100644 --- a/src/main/java/gregtech/common/tools/ToolScoop.java +++ b/src/main/java/gregtech/common/tools/ToolScoop.java @@ -87,7 +87,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "scoop") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, sBeeHiveMaterial); } diff --git a/src/main/java/gregtech/common/tools/ToolScrewdriver.java b/src/main/java/gregtech/common/tools/ToolScrewdriver.java index b73f1371aab..6c772842d5a 100644 --- a/src/main/java/gregtech/common/tools/ToolScrewdriver.java +++ b/src/main/java/gregtech/common/tools/ToolScrewdriver.java @@ -117,7 +117,7 @@ public boolean isScrewdriver() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "screwdriver") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.circuits); } diff --git a/src/main/java/gregtech/common/tools/ToolSense.java b/src/main/java/gregtech/common/tools/ToolSense.java index 55a3882db54..1720f47e4c7 100644 --- a/src/main/java/gregtech/common/tools/ToolSense.java +++ b/src/main/java/gregtech/common/tools/ToolSense.java @@ -34,13 +34,13 @@ public float getMaxDurabilityMultiplier() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "sense", "scythe") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.plants, Material.leaves); } @Override - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, int aY, int aZ) { // Speed nerf for using AOE tools to break single block if (aPlayer != null && aPlayer.isSneaking()) { @@ -51,7 +51,7 @@ public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, Entity @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rConversions = 0; if ((this.sIsHarvestingRightNow.get() == null) && ((aPlayer instanceof EntityPlayerMP))) { this.sIsHarvestingRightNow.set(this); diff --git a/src/main/java/gregtech/common/tools/ToolShovel.java b/src/main/java/gregtech/common/tools/ToolShovel.java index d4676efeedb..15d17c2af4d 100644 --- a/src/main/java/gregtech/common/tools/ToolShovel.java +++ b/src/main/java/gregtech/common/tools/ToolShovel.java @@ -80,7 +80,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "shovel") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, diff --git a/src/main/java/gregtech/common/tools/ToolSoftHammer.java b/src/main/java/gregtech/common/tools/ToolSoftHammer.java index 0cd3aa2eac6..9e812b59f1e 100644 --- a/src/main/java/gregtech/common/tools/ToolSoftHammer.java +++ b/src/main/java/gregtech/common/tools/ToolSoftHammer.java @@ -97,7 +97,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "softhammer"); } diff --git a/src/main/java/gregtech/common/tools/ToolSolderingIron.java b/src/main/java/gregtech/common/tools/ToolSolderingIron.java index 9ae4fade4c7..b00e97bee63 100644 --- a/src/main/java/gregtech/common/tools/ToolSolderingIron.java +++ b/src/main/java/gregtech/common/tools/ToolSolderingIron.java @@ -112,7 +112,7 @@ public boolean isMiningTool() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "soldering_iron") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.circuits); } diff --git a/src/main/java/gregtech/common/tools/ToolSword.java b/src/main/java/gregtech/common/tools/ToolSword.java index 03c76f92c6f..cfbbee071d1 100644 --- a/src/main/java/gregtech/common/tools/ToolSword.java +++ b/src/main/java/gregtech/common/tools/ToolSword.java @@ -84,7 +84,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "sword") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, diff --git a/src/main/java/gregtech/common/tools/ToolTurbine.java b/src/main/java/gregtech/common/tools/ToolTurbine.java index ace22b06bac..ceb2eb6df20 100644 --- a/src/main/java/gregtech/common/tools/ToolTurbine.java +++ b/src/main/java/gregtech/common/tools/ToolTurbine.java @@ -16,7 +16,7 @@ public abstract class ToolTurbine extends GTTool { public abstract float getBaseDamage(); @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } diff --git a/src/main/java/gregtech/common/tools/ToolUniversalSpade.java b/src/main/java/gregtech/common/tools/ToolUniversalSpade.java index 9333e1f19ca..03b551d2636 100644 --- a/src/main/java/gregtech/common/tools/ToolUniversalSpade.java +++ b/src/main/java/gregtech/common/tools/ToolUniversalSpade.java @@ -89,7 +89,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "shovel", "axe", "saw", "sword", "crowbar") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, diff --git a/src/main/java/gregtech/common/tools/ToolWireCutter.java b/src/main/java/gregtech/common/tools/ToolWireCutter.java index 6009504d804..edbf21c3b93 100644 --- a/src/main/java/gregtech/common/tools/ToolWireCutter.java +++ b/src/main/java/gregtech/common/tools/ToolWireCutter.java @@ -81,7 +81,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "cutter"); } diff --git a/src/main/java/gregtech/common/tools/ToolWrench.java b/src/main/java/gregtech/common/tools/ToolWrench.java index 3d2adf48962..cbab13b401e 100644 --- a/src/main/java/gregtech/common/tools/ToolWrench.java +++ b/src/main/java/gregtech/common/tools/ToolWrench.java @@ -126,7 +126,7 @@ public boolean isWrench() { } @Override - public boolean isMinableBlock(Block block, byte aMetaData) { + public boolean isMinableBlock(Block block, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(block, aMetaData, "wrench") || GTToolHarvestHelper.isAppropriateMaterial(block, Material.piston) || block instanceof AEBaseTileBlock @@ -194,7 +194,7 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase private boolean LastEventFromThis = false; @Override - public void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, byte metadata, + public void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, int metadata, TileEntity tile, @Nonnull BlockEvent.BreakEvent event) { if (tile instanceof IWrenchable wrenchable) { if (!wrenchable.wrenchCanRemove(player)) { @@ -246,7 +246,7 @@ public void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Non @Override public int convertBlockDrops(List drops, ItemStack Stack, EntityPlayer player, Block block, int x, int y, - int z, byte metaData, int fortune, boolean silkTouch, BlockEvent.HarvestDropsEvent event) { + int z, int metaData, int fortune, boolean silkTouch, BlockEvent.HarvestDropsEvent event) { ItemStack drop = null; int modified = 0; if (wrenchableDrop != null) { diff --git a/src/main/java/gregtech/common/tools/pocket/ToolPocketMultitool.java b/src/main/java/gregtech/common/tools/pocket/ToolPocketMultitool.java index e55671d486f..e4cc20be246 100644 --- a/src/main/java/gregtech/common/tools/pocket/ToolPocketMultitool.java +++ b/src/main/java/gregtech/common/tools/pocket/ToolPocketMultitool.java @@ -44,7 +44,7 @@ public float getBaseDamage() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IToolStats.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IToolStats.java index 1a61814f559..5e37c0cb649 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IToolStats.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IToolStats.java @@ -156,7 +156,7 @@ public interface IToolStats extends gregtech.api.interfaces.IToolStats { * check. */ @Override - boolean isMinableBlock(Block aBlock, byte aMetaData); + boolean isMinableBlock(Block aBlock, int aMetaData); /** * This lets you modify the Drop List, when this type of Tool has been used. @@ -165,7 +165,7 @@ public interface IToolStats extends gregtech.api.interfaces.IToolStats { */ @Override int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, int aY, - int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); + int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); /** * @return Returns a broken Version of the Item. diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java index f47ef56e9a9..d1a57dc0cf0 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java @@ -78,7 +78,7 @@ public GTMetaTool(final String aUnlocalized) { */ @Override public void onHarvestBlockEvent(final ArrayList aDrops, final ItemStack aStack, - final EntityPlayer aPlayer, final Block aBlock, final int aX, final int aY, final int aZ, final byte aMetaData, + final EntityPlayer aPlayer, final Block aBlock, final int aX, final int aY, final int aZ, final int aMetaData, final int aFortune, final boolean aSilkTouch, final BlockEvent.HarvestDropsEvent aEvent) { final gregtech.api.interfaces.IToolStats tStats = this.getToolStats(aStack); if (this.isItemStackUsable(aStack) && (this.getDigSpeed(aStack, aBlock, aMetaData) > 0.0F)) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/ToolAngleGrinder.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/ToolAngleGrinder.java index f65b3162f8a..65d2fa09152 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/ToolAngleGrinder.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/ToolAngleGrinder.java @@ -115,14 +115,14 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(final Block aBlock, final byte aMetaData) { + public boolean isMinableBlock(final Block aBlock, final int aMetaData) { final String tTool = aBlock.getHarvestTool(aMetaData); return (tTool != null) && (tTool.equals("sword") || tTool.equals("file")); } @Override public int convertBlockDrops(final List aDrops, final ItemStack aStack, final EntityPlayer aPlayer, - final Block aBlock, final int aX, final int aY, final int aZ, final byte aMetaData, final int aFortune, + final Block aBlock, final int aX, final int aY, final int aZ, final int aMetaData, final int aFortune, final boolean aSilkTouch, final BlockEvent.HarvestDropsEvent aEvent) { return 0; } From 8765a216a5032c1060d10c23d72d1b8443e3bb4c Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Wed, 11 Dec 2024 14:41:32 -0500 Subject: [PATCH 08/47] unify asteroid config + fixes --- src/main/java/galacticgreg/GalacticGreg.java | 3 + .../galacticgreg/WorldGeneratorSpace.java | 84 +++++++------- .../properties/AsteroidPropertyBuilder.java | 12 +- .../api/enums/properties/Asteroids.java | 8 +- .../galacticgreg/command/WorldgenCommand.java | 107 ++++++++++++++++++ .../dynconfig/DynamicDimensionConfig.java | 4 +- .../java/gregtech/api/enums/Materials.java | 8 ++ .../java/gregtech/api/enums/OreMixes.java | 26 +++-- .../common/blocks/BlockOresAbstract.java | 5 +- .../java/gregtech/common/config/Worldgen.java | 25 ---- .../gregtech/common/ores/GTOreAdapter.java | 6 + .../common/worldgen/WorldgenQuery.java | 10 +- .../resources/assets/gregtech/lang/en_US.lang | 1 - 13 files changed, 208 insertions(+), 91 deletions(-) create mode 100644 src/main/java/galacticgreg/command/WorldgenCommand.java 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/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 7440aba018c..c75dc0c644d 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -47,18 +47,8 @@ public class WorldGeneratorSpace implements IWorldGenerator { - private static boolean generateEndAsteroids = true; - private static int mEndAsteroidProbability; - private static int mEndAsteroidMinSize; - private static int mEndAsteroidMaxSize; - public WorldGeneratorSpace() { GameRegistry.registerWorldGenerator(this, Integer.MAX_VALUE); - - generateEndAsteroids = Worldgen.endAsteroids.generateEndAsteroids; - mEndAsteroidProbability = Worldgen.endAsteroids.EndAsteroidProbability; - mEndAsteroidMinSize = Worldgen.endAsteroids.EndAsteroidMinSize; - mEndAsteroidMaxSize = Worldgen.endAsteroids.EndAsteroidMaxSize; } private static final int END_ASTEROID_DISTANCE = 16; @@ -117,7 +107,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP } } - private static class AsteroidGenerator { + public static class AsteroidGenerator { public List positive, negative; public int cX, cY, cZ, radius; public long seed; @@ -127,9 +117,11 @@ private static class AsteroidGenerator { public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedChunkZ) { ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world); - AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); + AsteroidConfig asteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); - if (!generatesAsteroid(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId, dimAsteroidConfig.Probability)) return null; + if (!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); @@ -168,14 +160,10 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh int tY = minY + rng.nextInt(maxY - minY); int tZ = seedChunkZ * 16 + rng.nextInt(16); - if (!world.isAirBlock(tX, tY, tZ)) return null; - - int asteroidSize = (mEndAsteroidMinSize + rng.nextInt(mEndAsteroidMaxSize - mEndAsteroidMinSize + 1)); - List positive = new ArrayList<>(); List negative = new ArrayList<>(); - int radius = rng.nextInt(asteroidSize / 4); + int radius = (asteroidConfig.MinSize + rng.nextInt(asteroidConfig.MinSize - asteroidConfig.MaxSize + 1)); positive.add(new Ellipsoid(0, 0, 0, radius)); int k = rng.nextInt(2); @@ -204,7 +192,7 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh gen.cX = tX; gen.cY = tY; gen.cZ = tZ; - gen.radius = asteroidSize; + gen.radius = radius * 2; gen.seed = rng.nextLong(); @@ -215,27 +203,25 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh } public boolean affectsChunk(int chunkX, int chunkZ) { - int minX = getChunkCoord(cX - radius); - int maxX = getChunkCoord(cX + radius + 1); + int minX = (cX - radius) >> 4; + int maxX = (cX + radius + 1) >> 4; - int minZ = getChunkCoord(cZ - radius); - int maxZ = getChunkCoord(cZ + radius + 1); + int minZ = (cZ - radius) >> 4; + int maxZ = (cZ + radius + 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 - radius); + int minX = Math.max(chunkX * 16, cX - radius - 1); int maxX = Math.min((chunkX + 1) * 16, cX + radius + 1); - int minY = Math.max(0, cY - radius); + int minY = Math.max(0, cY - radius - 1); int maxY = Math.min(255, cY + radius + 1); - int minZ = Math.max(chunkZ * 16, cZ - radius); + int minZ = Math.max(chunkZ * 16, cZ - radius - 1); int maxZ = Math.min((chunkZ + 1) * 16, cZ + radius + 1); - XSTR rng = new XSTR(seed); - ModDimensionDef def = DimensionDef.getDefForWorld(world); AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(def); @@ -247,8 +233,18 @@ public void generateChunk(World world, int chunkX, int chunkZ) { continue; } + long seed = world.getSeed(); + seed = seed * 12289 + chunkX; + seed = seed * 12289 + chunkZ; + seed = seed * 12289 + world.provider.dimensionId; + seed = seed * 12289 + x; + seed = seed * 12289 + y; + seed = seed * 12289 + z; + + XSTR rng2 = new XSTR(seed); + for (Ellipsoid e : negative) { - if (e.dist2(rng, x - cX + 0.5f, y - cY + 0.5f, z - cZ + 0.5f) <= 1) { + if (e.dist2(rng2, x - cX + 0.5f, y - cY + 0.5f, z - cZ + 0.5f) <= 1) { continue outer; } } @@ -256,7 +252,7 @@ public void generateChunk(World world, int chunkX, int chunkZ) { float dist = 2f; for (Ellipsoid e : positive) { - dist = Math.min(dist, e.dist2(rng, x - cX + 0.5f, y - cY + 0.5f, z - cZ + 0.5f)); + dist = Math.min(dist, e.dist2(rng2, x - cX + 0.5f, y - cY + 0.5f, z - cZ + 0.5f)); } if (dist >= 1) continue; @@ -266,7 +262,14 @@ public void generateChunk(World world, int chunkX, int chunkZ) { // try to place big ores, if the ore vein creates big ore if (ore.generatesBigOre()) { if (!placedAnything) { - placedAnything = generateOreBlock(rng, world, x, y, z, stoneType, ore, false, dist); + placedAnything = generateOreBlock( + rng2, + world, + x, y, z, + stoneType, + ore, + false, + radius / 4 < 15 ? rng2.nextFloat() : dist); } } @@ -274,7 +277,7 @@ public void generateChunk(World world, int chunkX, int chunkZ) { if (!placedAnything) { placedAnything = generateSpecialBlocks( def, - rng, + rng2, world, dimAsteroidConfig, x, @@ -286,7 +289,7 @@ public void generateChunk(World world, int chunkX, int chunkZ) { // try to place small ores if (!placedAnything) { placedAnything = generateOreBlock( - rng, + rng2, world, x, y, @@ -294,7 +297,7 @@ public void generateChunk(World world, int chunkX, int chunkZ) { stoneType, ore, true, - rng.nextFloat()); + rng2.nextFloat()); } // no smallores either? do normal block @@ -313,18 +316,10 @@ public void generateChunk(World world, int chunkX, int chunkZ) { } } - private static int getChunkCoord(int k) { - if (k < 0) { - return GTUtility.ceilDiv2(k, 16); - } else { - return k / 16; - } - } - /** 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) { + public static XSTR getRandom(long worldSeed, int chunkX, int chunkZ, int dimId) { return new XSTR(chunkX * 341873128712L + chunkZ * 132897987541L + dimId + OFFSET + worldSeed); } @@ -511,8 +506,7 @@ private static boolean generateOreBlock(Random rng, World pWorld, int pX, int pY IMaterial mat = oreLayer.getOre(control); if (mat != null) { - OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, small); - return true; + return OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, small); } } diff --git a/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java b/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java index bf5fecc78ad..b6c9f9be4e3 100644 --- a/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java +++ b/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java @@ -2,6 +2,7 @@ public class AsteroidPropertyBuilder { + public boolean enabled = true; public int probability; public int sizeMin, sizeMax; public int specialBlockChance; @@ -11,7 +12,7 @@ public class AsteroidPropertyBuilder { public static class OreSpawnPropertyBuilder { public int baseOreChance; - public boolean obeyHeighLimits; + public boolean obeyHeightLimits; public boolean oresOnlyInsideAsteroids; public int primaryToRareOreOffset; public int smallOreChance; @@ -21,8 +22,8 @@ public OreSpawnPropertyBuilder baseOreChance(int baseOreChance) { return this; } - public OreSpawnPropertyBuilder doesObeyingHeightLimits(boolean obeyHeighLimits) { - this.obeyHeighLimits = obeyHeighLimits; + public OreSpawnPropertyBuilder doesObeyingHeightLimits(boolean obeyHeightLimits) { + this.obeyHeightLimits = obeyHeightLimits; return this; } @@ -77,6 +78,11 @@ public AsteroidPropertyBuilder() { loot = new LootPropertyBuilder(); } + public AsteroidPropertyBuilder enabled(boolean enabled) { + this.enabled = enabled; + return this; + } + public AsteroidPropertyBuilder probability(int probability) { this.probability = probability; 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 984c1f63cb4..e060b27b5d6 100644 --- a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java +++ b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java @@ -6,7 +6,7 @@ public enum Asteroids { // spotless : off - EndAsteroids(ModContainers.Vanilla, DimensionDef.EndAsteroids, new AsteroidPropertyBuilder().probability(100) + EndAsteroids(ModContainers.Vanilla, DimensionDef.EndAsteroids, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) .oreSpawn( @@ -20,7 +20,7 @@ public enum Asteroids { .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - KuiperBelt(ModContainers.GalaxySpace, DimensionDef.KuiperBelt, new AsteroidPropertyBuilder().probability(100) + KuiperBelt(ModContainers.GalaxySpace, DimensionDef.KuiperBelt, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) .oreSpawn( @@ -34,7 +34,7 @@ public enum Asteroids { .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - MehenBelt(ModContainers.AmunRa, DimensionDef.MehenBelt, new AsteroidPropertyBuilder().probability(100) + MehenBelt(ModContainers.AmunRa, DimensionDef.MehenBelt, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) .oreSpawn( @@ -48,7 +48,7 @@ public enum Asteroids { .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - Asteroids(ModContainers.GalacticraftMars, DimensionDef.Asteroids, new AsteroidPropertyBuilder().probability(100) + Asteroids(ModContainers.GalacticraftMars, DimensionDef.Asteroids, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) .oreSpawn( diff --git a/src/main/java/galacticgreg/command/WorldgenCommand.java b/src/main/java/galacticgreg/command/WorldgenCommand.java new file mode 100644 index 00000000000..e68a4371ae0 --- /dev/null +++ b/src/main/java/galacticgreg/command/WorldgenCommand.java @@ -0,0 +1,107 @@ +package galacticgreg.command; + +import java.util.List; + +import com.google.common.collect.ImmutableList; + +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 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); + 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; + } + + @SuppressWarnings("rawtypes") + @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..a11c124d406 100644 --- a/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java +++ b/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java @@ -16,6 +16,7 @@ public class DynamicDimensionConfig { public static class AsteroidConfig { + public boolean Enabled; public int MinSize; public int MaxSize; public int Probability; @@ -80,6 +81,7 @@ 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; @@ -88,7 +90,7 @@ public static boolean InitDynamicConfig() { 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.ObeyHeightLimits = AsteroidProperties.asteroidPropertyBuilder.oreSpawn.obeyHeightLimits; aConf.HiddenOres = AsteroidProperties.asteroidPropertyBuilder.oreSpawn.oresOnlyInsideAsteroids; if (GalacticGreg.GalacticConfig.LootChestsEnabled) { diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index d531740ddc3..71d6553e5ad 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -2533,6 +2533,14 @@ private static void initSubTags() { 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() { diff --git a/src/main/java/gregtech/api/enums/OreMixes.java b/src/main/java/gregtech/api/enums/OreMixes.java index 93e4d495144..ea823c855d3 100644 --- a/src/main/java/gregtech/api/enums/OreMixes.java +++ b/src/main/java/gregtech/api/enums/OreMixes.java @@ -249,7 +249,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) @@ -604,7 +604,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) @@ -1018,19 +1018,31 @@ public enum OreMixes { .size(16) .enableInDim(ASTEROIDS, KUIPERBELT) .primary(Materials.Nitrogen) - .secondary(Materials.Nitrogen) - .inBetween(Materials.Ammonia) - .sporadic(Materials.Ammonia) + .secondary(Materials.Ammonia) + .inBetween(Materials.Hydrogen) + .sporadic(Materials.Hydrogen) .stoneCategory(StoneCategory.Ice)), - CarbonIce(new OreMixBuilder().name("ore.mix.carbonice") + HydrocarbonIce(new OreMixBuilder().name("ore.mix.hydrocarbonice") .heightRange(30, 180) .weight(40) .density(16) .size(12) .enableInDim(ASTEROIDS, KUIPERBELT) .primary(Materials.Methane) - .secondary(Materials.CarbonDioxide) + .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(16) + .size(12) + .enableInDim(ASTEROIDS, KUIPERBELT) + .primary(Materials.CarbonDioxide) + .secondary(Materials.Oxygen) .inBetween(Materials.Carbon) .sporadic(Materials.Carbon) .stoneCategory(StoneCategory.Ice)), diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java index de2e528a2a7..915074a78c9 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java @@ -11,6 +11,7 @@ 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; @@ -122,7 +123,7 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { for (StoneType stoneType : stoneTypes) { // if this material only has ice ore, we only want to show the ice variants if (info.material.contains(SubTag.ICE_ORE)) { - if (stoneType == StoneType.PackedIce) { + if (stoneType.getCategory() == StoneCategory.Ice) { info.stoneType = stoneType; list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); @@ -225,7 +226,7 @@ public ITexture[][] getTextures(int metadata) { public IIcon getIcon(int side, int meta) { StoneType stoneType = getStoneType(meta); - return stoneType == null ? null : stoneType.getIcon(side); + return stoneType == null ? StoneType.Stone.getIcon(side) : stoneType.getIcon(side); } @Override diff --git a/src/main/java/gregtech/common/config/Worldgen.java b/src/main/java/gregtech/common/config/Worldgen.java index 2c93e3f65aa..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(30) - @Config.RequiresMcRestart - public int EndAsteroidMaxSize; - - @Config.Comment("The minimum size for the end asteroids.") - @Config.DefaultInt(15) - @Config.RequiresMcRestart - public int EndAsteroidMinSize; - - @Config.Comment("The probability weight to generate end asteroids.") - @Config.DefaultInt(25) - @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/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index 216898423b8..2d6a6af1d34 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -11,6 +11,7 @@ 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; @@ -110,6 +111,7 @@ public boolean supports(OreInfo info) { if (!oreBlocksByStoneType.containsKey(stoneType2)) return false; if (!stoneType2.isEnabled()) return false; if (!info.material.isValidForStone(stoneType2)) return false; + if (stoneType2.getCategory() == StoneCategory.Ice && info.isSmall) return false; return true; } @@ -121,6 +123,8 @@ public boolean supports(OreInfo info) { public OreInfo getOreInfo(Block block, int meta) { if (!(block instanceof BlockOresAbstract 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; @@ -132,6 +136,7 @@ public OreInfo getOreInfo(Block block, int meta) { 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(); @@ -152,6 +157,7 @@ public ObjectIntPair getBlock(OreInfo info) { if (!(info.stoneType instanceof StoneType stoneType)) return null; if (!stoneType.isEnabled()) return null; + if (stoneType.getCategory() == StoneCategory.Ice && info.isSmall) return null; BlockOresAbstract oreBlock = oreBlocksByStoneType.get(stoneType); diff --git a/src/main/java/gregtech/common/worldgen/WorldgenQuery.java b/src/main/java/gregtech/common/worldgen/WorldgenQuery.java index b69efa6d253..e6a2579b1bb 100644 --- a/src/main/java/gregtech/common/worldgen/WorldgenQuery.java +++ b/src/main/java/gregtech/common/worldgen/WorldgenQuery.java @@ -21,6 +21,7 @@ public class WorldgenQuery { 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; @@ -81,10 +82,13 @@ public WorldgenQuery inDimension(DimensionDef def) { return this; } - public WorldgenQuery inStone(IStoneCategory stoneType) { - if (stoneCategories == null) stoneCategories = new HashSet<>(); + public WorldgenQuery inStone(IStoneCategory stoneCategories) { + if (defaultStoneCategories) { + this.stoneCategories = new HashSet<>(); + defaultStoneCategories = false; + } - stoneCategories.add(stoneType); + this.stoneCategories.addAll(Arrays.asList(stoneCategories)); return this; } diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index 0ed55b6ee28..f78dc2edd34 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -616,7 +616,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 From 993eef553cde10f27d769c3f2a9fa51bb8e109cb Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Wed, 11 Dec 2024 22:05:14 -0500 Subject: [PATCH 09/47] bartworks ores --- .../client/renderer/BWBlockOreRenderer.java | 159 ------------------ .../material/BWItemMetaGeneratedOre.java | 61 +++++++ .../material/BWMetaGeneratedBlocks.java | 7 - .../system/material/BWMetaGeneratedOres.java | 86 ++++++++-- .../material/BWMetaGeneratedSmallOres.java | 49 ------ .../BWTileEntityMetaGeneratedOre.java | 57 ------- .../BWTileEntityMetaGeneratedSmallOre.java | 125 -------------- .../bartworks/system/material/Werkstoff.java | 2 + .../system/material/WerkstoffLoader.java | 60 +------ src/main/java/detrav/gui/OresList.java | 1 - .../BehaviourDetravToolProspector.java | 12 -- .../java/detrav/net/ProspectingPacket.java | 1 - .../java/detrav/utils/BartWorksHelper.java | 23 --- .../galacticgreg/api/enums/DimensionDef.java | 8 + .../gregtech/api/interfaces/IMaterial.java | 16 ++ .../java/gregtech/api/util/GTUtility.java | 2 - .../gregtech/common/GTWorldgenerator.java | 18 +- .../common/blocks/BlockOresAbstract.java | 10 +- .../gregtech/common/ores/BWOreAdapter.java | 138 +++++++++++---- .../gregtech/common/ores/GTOreAdapter.java | 6 +- .../gregtech/common/ores/GTPPOreAdapter.java | 5 +- .../plugin/NEIPluginConfig.java | 20 ++- .../gregtech5/PluginGT5SmallOreStat.java | 42 +++-- .../plugin/gregtech5/PluginGT5VeinStat.java | 55 +++++- .../util/GT5OreSmallHelper.java | 2 + 25 files changed, 396 insertions(+), 569 deletions(-) delete mode 100644 src/main/java/bartworks/client/renderer/BWBlockOreRenderer.java create mode 100644 src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java delete mode 100644 src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java delete mode 100644 src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedOre.java delete mode 100644 src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedSmallOre.java delete mode 100644 src/main/java/detrav/utils/BartWorksHelper.java 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/system/material/BWItemMetaGeneratedOre.java b/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java new file mode 100644 index 00000000000..81f5de72fc3 --- /dev/null +++ b/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java @@ -0,0 +1,61 @@ +package bartworks.system.material; + +import java.util.List; + +import gregtech.api.GregTechAPI; +import gregtech.api.enums.OrePrefixes; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +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; + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return blockOre.isSmall ? "bw.blocktype." + OrePrefixes.oreSmall : "bw.blocktype." + OrePrefixes.ore; + } + + @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 6c3dab3bbe1..987a8fbc933 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -13,9 +13,14 @@ package bartworks.system.material; +import static bartworks.system.material.BWMetaGeneratedItems.metaTab; + import java.util.ArrayList; import java.util.List; +import javax.annotation.Nullable; + +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.enchantment.EnchantmentHelper; @@ -23,30 +28,52 @@ 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 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.GTModHandler; import gregtech.common.ores.BWOreAdapter; import gregtech.common.ores.OreInfo; +import gregtech.common.render.GTRendererBlock; + +public class BWMetaGeneratedOres extends Block implements IBlockWithTextures { -public class BWMetaGeneratedOres extends BWMetaGeneratedBlocks { + 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( + "bw.blocktype." + OrePrefixes.oreSmall, + OrePrefixes.oreSmall.mLocalizedMaterialPre + "%material" + OrePrefixes.oreSmall.mLocalizedMaterialPost); + } else { + this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( + "bw.blocktype." + OrePrefixes.ore, + OrePrefixes.ore.mLocalizedMaterialPre + "%material" + OrePrefixes.ore.mLocalizedMaterialPost); + } - public final boolean isNatural; + Werkstoff.werkstoffHashSet.forEach(this::doRegistrationStuff); - public BWMetaGeneratedOres(Material p_i45386_1_, Class tileEntity, String blockName, boolean natural) { - super(p_i45386_1_, tileEntity, blockName); - this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( - "bw.blocktype." + OrePrefixes.ore, - OrePrefixes.ore.mLocalizedMaterialPre + "%material" + OrePrefixes.ore.mLocalizedMaterialPost); + this.stoneType = stoneType; + this.isSmall = small; this.isNatural = natural; } - @Override protected void doRegistrationStuff(Werkstoff w) { if (w != null) { if (!w.hasItemType(OrePrefixes.ore) || (w.getGenerationFeatures().blacklist & 0b1000) != 0) return; @@ -69,9 +96,18 @@ public int getHarvestLevel(int metadata) { return 3; } + @Override + public int damageDropped(int meta) { + return meta; + } + @Override public String getUnlocalizedName() { - return "bw.blockores.01"; + if (isSmall) { + return "bw.blockores.02"; + } else { + return "bw.blockores.01"; + } } @Override @@ -93,8 +129,36 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad boolean doFortune = !(harvester instanceof FakePlayer); boolean doSilktouch = harvester != null && EnchantmentHelper.getSilkTouchModifier(harvester); - try (OreInfo info = BWOreAdapter.INSTANCE.getOreInfo(this, metadata);) { + try (OreInfo info = BWOreAdapter.INSTANCE.getOreInfo(this, metadata)) { return (ArrayList) BWOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); } } + + @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 75ae9418c29..00000000000 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedSmallOres.java +++ /dev/null @@ -1,49 +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; -import gregtech.api.util.GTModHandler; - -public class BWMetaGeneratedSmallOres extends BWMetaGeneratedOres { - - public BWMetaGeneratedSmallOres(Material p_i45386_1_, Class tileEntity, String blockName, boolean natural) { - super(p_i45386_1_, tileEntity, blockName, natural); - this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( - "bw.blocktype." + OrePrefixes.oreSmall, - OrePrefixes.oreSmall.mLocalizedMaterialPre + "%material" + OrePrefixes.oreSmall.mLocalizedMaterialPost); - } - - @Override - protected void doRegistrationStuff(Werkstoff w) { - if (w != null) { - if (!w.hasItemType(OrePrefixes.ore) || (w.getGenerationFeatures().blacklist & 0b1000) != 0) return; - GTModHandler.addValuableOre(this, w.getmID(), 1); - } - } - - @Override - public String getUnlocalizedName() { - return "bw.blockores.02"; - } -} 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 07cd71ff833..00000000000 --- a/src/main/java/bartworks/system/material/BWTileEntityMetaGeneratedOre.java +++ /dev/null @@ -1,57 +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 net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.enums.OrePrefixes; -import gregtech.api.interfaces.ITexture; -import gregtech.api.render.TextureFactory; - -public class BWTileEntityMetaGeneratedOre extends TileEntityMetaGeneratedBlock { - - 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; - } -} 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 91f97aa4e59..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/Werkstoff.java b/src/main/java/bartworks/system/material/Werkstoff.java index e59fc2e9f03..9880f9e17d2 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -68,6 +68,7 @@ public class Werkstoff implements IColorModulationContainer, ISubTagContainer, I public static final LinkedHashSet werkstoffHashSet = new LinkedHashSet<>(); public static final LinkedHashMap werkstoffHashMap = new LinkedHashMap<>(); public static final LinkedHashMap werkstoffNameHashMap = new LinkedHashMap<>(); + public static final LinkedHashMap werkstoffVarNameHashMap = new LinkedHashMap<>(); public static final Map modNameOverrides = new HashMap<>() { @@ -383,6 +384,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(); } diff --git a/src/main/java/bartworks/system/material/WerkstoffLoader.java b/src/main/java/bartworks/system/material/WerkstoffLoader.java index d0bd41d20bb..91419495e55 100644 --- a/src/main/java/bartworks/system/material/WerkstoffLoader.java +++ b/src/main/java/bartworks/system/material/WerkstoffLoader.java @@ -90,11 +90,12 @@ import org.apache.logging.log4j.Level; import com.google.common.collect.HashBiMap; +import com.gtnewhorizons.postea.api.TileEntityReplacementManager; +import com.gtnewhorizons.postea.utility.BlockInfo; 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; @@ -125,8 +126,10 @@ import codechicken.nei.api.API; import cpw.mods.fml.common.ProgressManager; import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTechAPI; import gregtech.api.enums.Element; import gregtech.api.enums.FluidState; +import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SubTag; @@ -134,6 +137,8 @@ import gregtech.api.fluid.GTFluidFactory; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.util.GTOreDictUnificator; +import gregtech.common.ores.BWOreAdapter; +import gregtech.loaders.postload.PosteaTransformers; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputOreDict; import ic2.api.recipe.RecipeOutput; @@ -1927,36 +1932,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", - false); - WerkstoffLoader.BWOresNatural = new BWMetaGeneratedOres( - Material.rock, - BWTileEntityMetaGeneratedOre.class, - "bw.blockores.natural", - true); - WerkstoffLoader.BWSmallOres = new BWMetaGeneratedSmallOres( - Material.rock, - BWTileEntityMetaGeneratedSmallOre.class, - "bw.blockoresSmall", - false); - WerkstoffLoader.BWSmallOresNatural = new BWMetaGeneratedSmallOres( - Material.rock, - BWTileEntityMetaGeneratedSmallOre.class, - "bw.blockoresSmall.natural", - true); + BWOreAdapter.INSTANCE.init(); + WerkstoffLoader.BWBlocks = new BWMetaGeneratedWerkstoffBlocks( Material.iron, BWTileEntityMetaGeneratedWerkstoffBlock.class, @@ -1972,10 +1955,6 @@ static void gameRegistryHandler() { "bw.werkstoffblockscasingadvanced", OrePrefixes.blockCasingAdvanced); - GameRegistry.registerBlock(WerkstoffLoader.BWOres, BWItemMetaGeneratedBlock.class, "bw.blockores.01"); - GameRegistry.registerBlock(WerkstoffLoader.BWOresNatural, BWItemMetaGeneratedBlock.class, "bw.blockores.natural.01"); - GameRegistry.registerBlock(WerkstoffLoader.BWSmallOres, BWItemMetaGeneratedBlock.class, "bw.blockores.02"); - GameRegistry.registerBlock(WerkstoffLoader.BWSmallOresNatural, BWItemMetaGeneratedBlock.class, "bw.blockores.natural.02"); GameRegistry.registerBlock(WerkstoffLoader.BWBlocks, BWItemMetaGeneratedBlock.class, "bw.werkstoffblocks.01"); GameRegistry.registerBlock( WerkstoffLoader.BWBlockCasings, @@ -1998,29 +1977,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() { diff --git a/src/main/java/detrav/gui/OresList.java b/src/main/java/detrav/gui/OresList.java index 139b16b9e82..095c5683a1d 100644 --- a/src/main/java/detrav/gui/OresList.java +++ b/src/main/java/detrav/gui/OresList.java @@ -7,7 +7,6 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.resources.I18n; import net.minecraft.util.StatCollector; import cpw.mods.fml.client.GuiScrollingList; import detrav.items.DetravMetaGeneratedTool01; diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java index d67fa49e59a..0441bbde625 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java @@ -23,12 +23,9 @@ 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.enums.Materials; import gregtech.api.items.MetaBaseItem; import gregtech.api.objects.ItemData; @@ -312,15 +309,6 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack ItemStack blockStack2 = new ItemStack(tBlock, 1, tMetaID); addOreToHashMap(blockStack2.getDisplayName(), aPlayer); } - } else if (GTppHelper.isGTppBlock(tBlock)) { - String name = GTppHelper.getGTppVeinName(tBlock); - if (!name.isEmpty()) addOreToHashMap(name, aPlayer); - } else if (BartWorksHelper.isOre(tBlock)) { - if (data != DetravMetaGeneratedTool01.MODE_ALL_ORES && BartWorksHelper.isSmallOre(tBlock)) continue; - final Werkstoff werkstoff = Werkstoff.werkstoffHashMap.getOrDefault((short) ((BartWorksHelper.getMetaFromBlock(chunk, cx, cy, cz, 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 == DetravMetaGeneratedTool01.MODE_ALL_ORES) { itemData = GTOreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); if (itemData != null && itemData.mPrefix.toString().startsWith("ore")) { diff --git a/src/main/java/detrav/net/ProspectingPacket.java b/src/main/java/detrav/net/ProspectingPacket.java index 1d32ee88669..85f4957c0b0 100644 --- a/src/main/java/detrav/net/ProspectingPacket.java +++ b/src/main/java/detrav/net/ProspectingPacket.java @@ -18,7 +18,6 @@ import detrav.DetravScannerMod; import detrav.gui.DetravScannerGUI; import detrav.gui.textures.DetravMapTexture; -import detrav.items.DetravMetaGeneratedTool01; import detrav.utils.FluidColors; import gregtech.api.interfaces.IMaterial; import gregtech.common.ores.OreManager; 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/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index de47114a83c..285517a2b78 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -54,6 +54,14 @@ public enum DimensionDef { DimNames.ASTEROIDS, "micdoodle8.mods.galacticraft.planets.asteroids.world.gen.ChunkProviderAsteroids", Enums.DimensionType.Asteroid)), + Ross128b(new ModDimensionDef( + DimNames.ROSS128B, + "bwcrossmod.galacticraft.planets.ross128b.ChunkProviderRoss128b", + Enums.DimensionType.Planet)), + Ross128ba(new ModDimensionDef( + DimNames.ROSS128BA, + "bwcrossmod.galacticraft.planets.ross128ba.ChunkProviderRoss128ba", + Enums.DimensionType.Planet)), Pluto(new ModDimensionDef( DimNames.PLUTO, "galaxyspace.SolarSystem.planets.pluto.dimension.ChunkProviderPluto", diff --git a/src/main/java/gregtech/api/interfaces/IMaterial.java b/src/main/java/gregtech/api/interfaces/IMaterial.java index 8da07f3de00..01c9573082f 100644 --- a/src/main/java/gregtech/api/interfaces/IMaterial.java +++ b/src/main/java/gregtech/api/interfaces/IMaterial.java @@ -2,6 +2,10 @@ import com.google.common.collect.ImmutableList; +import bartworks.system.material.Werkstoff; +import gregtech.api.enums.Materials; +import gtPlusPlus.core.material.Material; + public interface IMaterial { public String getLocalizedName(); @@ -15,4 +19,16 @@ public interface IMaterial { public boolean isValidForStone(IStoneType stoneType); public ImmutableList getValidStones(); + + public static IMaterial findMaterial(String name) { + Werkstoff bw = Werkstoff.werkstoffVarNameHashMap.get(name); + + if (bw != null) return bw; + + IMaterial gtpp = Material.mMaterialCache.get(name); + + if (gtpp != null) return gtpp; + + return Materials.getMaterialsMap().get(name); + } } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 5ccd7809d42..4e1022e8944 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -123,8 +123,6 @@ import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; import com.mojang.authlib.GameProfile; -import bartworks.system.material.BWMetaGeneratedOres; -import bartworks.system.material.BWMetaGeneratedSmallOres; import buildcraft.api.transport.IPipeTile; import cofh.api.energy.IEnergyReceiver; import cofh.api.transport.IItemDuct; diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index bcd0a5dee17..2411c61ebf3 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -30,6 +30,7 @@ import galacticgreg.api.Enums.DimensionType; import galacticgreg.api.enums.DimensionDef; import galacticgreg.api.enums.DimensionDef.DimNames; +import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; @@ -84,7 +85,7 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide } } - if (def != null && def.getDimensionType() == DimensionType.Asteroid) { + if (def == null || def.getDimensionType() != DimensionType.Planet) { return; } @@ -109,6 +110,7 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide + " SIZE: " + pendingTasks.size()); + // hack to prevent cascading worldgen if (!this.mIsGenerating) { this.mIsGenerating = true; @@ -567,13 +569,13 @@ public void run() { long duration = (endTime - startTime); if (debugWorldGen || profileWorldGen) { - GTLog.out.println( - " Oregen took " + (oregenTime - stonegenTime) - + " Stonegen took " - + (stonegenTime - startTime) - + " Worldgen took " - + duration - + " nanoseconds"); + GTMod.GT_FML_LOGGER.info( + " Oregen took " + (oregenTime - stonegenTime) / 1e3 + + "us Stonegen took " + + (stonegenTime - startTime) / 1e3 + + "us Worldgen took " + + duration / 1e3 + + "us"); } } } diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java index 915074a78c9..68739e34e84 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java @@ -123,7 +123,7 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { for (StoneType stoneType : stoneTypes) { // if this material only has ice ore, we only want to show the ice variants if (info.material.contains(SubTag.ICE_ORE)) { - if (stoneType.getCategory() == StoneCategory.Ice) { + if (stoneType != null && stoneType.getCategory() == StoneCategory.Ice) { info.stoneType = stoneType; list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); @@ -178,13 +178,7 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, metadata)) { if (info == null) return new ArrayList<>(); - ArrayList drops = (ArrayList) GTOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); - - if (drops == null) return new ArrayList<>(); - - drops.remove(null); - - return drops; + return (ArrayList) GTOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); } } diff --git a/src/main/java/gregtech/common/ores/BWOreAdapter.java b/src/main/java/gregtech/common/ores/BWOreAdapter.java index fea3ee32fa9..5855fe98f85 100644 --- a/src/main/java/gregtech/common/ores/BWOreAdapter.java +++ b/src/main/java/gregtech/common/ores/BWOreAdapter.java @@ -1,19 +1,23 @@ 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 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.BWMetaGeneratedSmallOres; import bartworks.system.material.Werkstoff; -import bartworks.system.material.WerkstoffLoader; +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.util.GTOreDictUnificator; +import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTUtility; import gregtech.api.util.GTUtility.ItemId; import gregtech.common.GTProxy.OreDropSystem; @@ -24,6 +28,80 @@ public enum BWOreAdapter implements IOreAdapter { INSTANCE; + 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 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); + }); + } + @Override public boolean supports(Block block, int meta) { return block instanceof BWMetaGeneratedOres; @@ -31,7 +109,11 @@ public boolean supports(Block block, int meta) { @Override public boolean supports(OreInfo info) { - if (info.stoneType != null && info.stoneType != StoneType.Stone) return false; + 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; @@ -43,51 +125,45 @@ public boolean supports(OreInfo info) { public OreInfo getOreInfo(Block block, int meta) { if (!supports(block, meta)) return null; + BWMetaGeneratedOres oreBlock = (BWMetaGeneratedOres) block; + OreInfo info = OreInfo.getNewInfo(); - info.stoneType = StoneType.Stone; + info.stoneType = oreBlock.stoneType; info.material = Werkstoff.werkstoffHashMap.get((Short) (short) meta); - info.isSmall = block instanceof BWMetaGeneratedSmallOres; - info.isNatural = ((BWMetaGeneratedOres) block).isNatural; + info.isSmall = oreBlock.isSmall; + info.isNatural = oreBlock.isNatural; return info; } @Override public ObjectIntPair getBlock(OreInfo info) { - if (info.stoneType != null && info.stoneType != StoneType.Stone) return null; + 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; - Block block; - - if (info.isSmall) { - if (info.isNatural) { - block = WerkstoffLoader.BWSmallOresNatural; - } else { - block = WerkstoffLoader.BWSmallOres; - } - } else { - if (info.isNatural) { - block = WerkstoffLoader.BWOresNatural; - } else { - block = WerkstoffLoader.BWOres; - } - } + Ores ores = this.ores.get(stoneType); + if (ores == null) return null; - return ObjectIntPair.of(block, w.getmID()); + return ObjectIntPair.of(ores.get(info.isSmall, info.isNatural), w.getmID()); } @Override public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { - if (!supports(info2)) return null; + if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") OreInfo info = (OreInfo) info2; - if (info.stoneType == null) info.stoneType = StoneType.Stone; - if (info.stoneType != StoneType.Stone) return null; + IStoneType stone = info.stoneType; + if (stone == null) stone = StoneType.Stone; + if (!(stone instanceof StoneType stoneType)) return null; + if (!this.ores.containsKey(stoneType)) return null; if (!info.isNatural) fortune = 0; @@ -104,7 +180,7 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort @Override public List getPotentialDrops(OreInfo info2) { - if (!supports(info2)) return null; + if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") OreInfo info = (OreInfo) info2; @@ -158,7 +234,7 @@ public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropM switch (oreDropMode) { case Item -> { - drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, info.material, info.stoneType.isRich() ? 2 : 1)); + drops.add(info.material.get(OrePrefixes.rawOre, info.stoneType.isRich() ? 2 : 1)); } case FortuneItem -> { if (fortune > 0) { @@ -168,11 +244,11 @@ public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropM 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)); + drops.add(info.material.get(OrePrefixes.rawOre, 1)); } } else { for (int i = 0; i < (info.stoneType.isRich() ? 2 : 1); i++) { - drops.add(GTOreDictUnificator.get(OrePrefixes.rawOre, info.material, 1)); + drops.add(info.material.get(OrePrefixes.rawOre, 1)); } } } diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index 2d6a6af1d34..f26ff578eb6 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -175,7 +175,7 @@ public ObjectIntPair getBlock(OreInfo info) { @Override public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { - if (!supports(info2)) return null; + if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") OreInfo info = (OreInfo) info2; @@ -184,7 +184,7 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort BlockOresAbstract oreBlock = oreBlocksByStoneType.get(info.stoneType); - if (oreBlock == null) return null; + if (oreBlock == null) return new ArrayList<>(); if (!info.isNatural) fortune = 0; @@ -201,7 +201,7 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort @Override public List getPotentialDrops(OreInfo info2) { - if (!supports(info2)) return null; + if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") OreInfo info = (OreInfo) info2; diff --git a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java index 02e2893b40f..241a491feb7 100644 --- a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java @@ -1,6 +1,7 @@ package gregtech.common.ores; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -57,7 +58,7 @@ public ObjectIntPair getBlock(OreInfo info) { @Override public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { - if (!supports(info2)) return null; + if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") OreInfo info = (OreInfo) info2; @@ -73,7 +74,7 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort @Override public List getPotentialDrops(OreInfo info2) { - if (!supports(info2)) return null; + if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") OreInfo info = (OreInfo) info2; diff --git a/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java b/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java index d325a1085fd..d5856adc99e 100644 --- a/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java +++ b/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java @@ -15,7 +15,10 @@ import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.StoneType; import gregtech.api.util.GTOreDictUnificator; +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 +65,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/gregtech5/PluginGT5SmallOreStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java index 0e8bfef6c57..e2c4937ea41 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java @@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack; import codechicken.nei.PositionedStack; +import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; import gregtech.common.ores.IOreAdapter; @@ -15,6 +16,7 @@ import gtneioreplugin.plugin.item.ItemDimensionDisplay; import gtneioreplugin.util.GT5OreSmallHelper; import gtneioreplugin.util.GT5OreSmallHelper.OreSmallWrapper; +import gtneioreplugin.util.GT5OreSmallHelper.SmallOreDimensionWrapper; public class PluginGT5SmallOreStat extends PluginGT5Base { @@ -68,9 +70,24 @@ public void loadCraftingRecipes(ItemStack stack) { if (mat != null) { loadSmallOre(mat); - } else { - super.loadCraftingRecipes(stack); + return; + } + + boolean isMatItem = false; + + for (var p : OrePrefixes.detectPrefix(stack)) { + if (!PluginGT5VeinStat.PREFIX_WHITELIST.contains(p.left())) continue; + + mat = IMaterial.findMaterial(p.right()); + + if (mat != null) { + isMatItem |= loadSmallOre(mat); + } } + + if (isMatItem) return; + + super.loadCraftingRecipes(stack); } @Override @@ -78,25 +95,24 @@ public void loadUsageRecipes(ItemStack stack) { String abbr = ItemDimensionDisplay.getDimension(stack); if (abbr == null) return; - for (OreSmallWrapper oreVein : GT5OreSmallHelper.SMALL_ORES_BY_DIM.get(abbr).smallOres) { + SmallOreDimensionWrapper wrapper = GT5OreSmallHelper.SMALL_ORES_BY_DIM.get(abbr); + if (wrapper == null) return; + + for (OreSmallWrapper oreVein : wrapper.smallOres) { addSmallOre(oreVein); } } - private void loadSmallOre(IMaterial material) { - OreSmallWrapper smallOre = getSmallOre(material); + private boolean loadSmallOre(IMaterial material) { + OreSmallWrapper smallOre = GT5OreSmallHelper.SMALL_ORES_BY_MAT.get(material); + if (smallOre != null) { addSmallOre(smallOre); - } - } - private OreSmallWrapper getSmallOre(IMaterial material) { - for (OreSmallWrapper oreSmallWorldGen : GT5OreSmallHelper.SMALL_ORES_BY_NAME.values()) { - if (oreSmallWorldGen.material == material) { - return oreSmallWorldGen; - } + return true; + } else { + return false; } - return null; } private void addSmallOre(OreSmallWrapper smallOre) { diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index 829768944fe..fd14e7997dd 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -6,10 +6,13 @@ import java.util.Comparator; import java.util.List; +import com.google.common.collect.ImmutableList; + import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; import codechicken.nei.PositionedStack; +import gregtech.api.enums.OrePrefixes; import gregtech.api.interfaces.IMaterial; import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.item.ItemDimensionDisplay; @@ -20,6 +23,30 @@ public class PluginGT5VeinStat extends PluginGT5Base { + public static final ImmutableList PREFIX_WHITELIST = ImmutableList.copyOf(new OrePrefixes[] { + 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, + }); + @Override public void loadCraftingRecipes(String outputId, Object... results) { if (outputId.equals(getOutputId())) { @@ -34,19 +61,41 @@ public void loadCraftingRecipes(String outputId, Object... results) { @Override public void loadCraftingRecipes(ItemStack stack) { IMaterial mat = OreManager.getMaterial(stack); + if (mat != null) { loadMatchingVeins(mat); - } else { - super.loadCraftingRecipes(stack); + + return; + } + + boolean isMatItem = false; + + for (var p : OrePrefixes.detectPrefix(stack)) { + if (!PREFIX_WHITELIST.contains(p.left())) continue; + + mat = IMaterial.findMaterial(p.right()); + + if (mat != null) { + isMatItem |= loadMatchingVeins(mat); + } } + + if (isMatItem) return; + + super.loadCraftingRecipes(stack); } - private void loadMatchingVeins(IMaterial ore) { + private boolean loadMatchingVeins(IMaterial ore) { + boolean foundAny = false; + for (OreLayerWrapper oreVein : getAllVeins()) { if (oreVein.containsOre(ore)) { addVeinWithLayers(oreVein); + foundAny = true; } } + + return foundAny; } @Override diff --git a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java index ed2993d9eca..bfbef5eeff2 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java @@ -26,6 +26,7 @@ public class GT5OreSmallHelper { 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} */ @@ -50,6 +51,7 @@ public static void init() { OreSmallWrapper wrapper = new OreSmallWrapper(smallOreDefMap.get(smallOreWorldGen.mWorldGenName)); SMALL_ORES_BY_NAME.put(worldGen.mWorldGenName, wrapper); + SMALL_ORES_BY_MAT.put(smallOreWorldGen.mMaterial, wrapper); if (ORE_MAT_TO_DROPS.containsKey(smallOreWorldGen.mMaterial)) { throw new IllegalStateException("Duplicate small ore world gen for material " + smallOreWorldGen.mMaterial); From 0365ef3cb4cdb9c722d31637324076a4c1414bcc Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Wed, 11 Dec 2024 22:48:29 -0500 Subject: [PATCH 10/47] fix prospector freezing server --- ...BehaviourDetravToolElectricProspector.java | 166 +++++++++------ src/main/java/gregtech/api/task/CoopTask.java | 7 + .../api/task/CooperativeScheduler.java | 191 ++++++++++++++++++ .../gregtech/api/task/ICoopTaskContext.java | 8 + .../java/gregtech/common/config/Gregtech.java | 15 ++ 5 files changed, 321 insertions(+), 66 deletions(-) create mode 100644 src/main/java/gregtech/api/task/CoopTask.java create mode 100644 src/main/java/gregtech/api/task/CooperativeScheduler.java create mode 100644 src/main/java/gregtech/api/task/ICoopTaskContext.java diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java index e85ec7ab102..02a5d3ebb6d 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -7,6 +7,8 @@ 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; @@ -19,12 +21,14 @@ 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 gregtech.api.items.MetaBaseItem; +import gregtech.api.task.CooperativeScheduler; import gregtech.common.UndergroundOil; import gregtech.common.ores.OreInfo; import gregtech.common.ores.OreManager; @@ -35,15 +39,25 @@ */ 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( @@ -53,17 +67,27 @@ 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; + int size; + + { + int size2 = aItem.getHarvestLevel(aStack, "") + 1; + for (int i = -size2; i <= size2; i++) + for (int j = -size2; j <= size2; j++) if (i != -size2 && i != size2 && j != -size2 && j != size2) + chunks.add(aWorld.getChunkFromChunkCoords(cX + i, cZ + j)); + + size = size2 - 1; + } + + final DetravMetaGeneratedTool01 tool = (DetravMetaGeneratedTool01) aItem; + if (!aPlayer.capabilities.isCreativeMode) tool.doDamage(aStack, this.mCosts * chunks.size()); final ProspectingPacket packet = new ProspectingPacket( cX, @@ -73,75 +97,85 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW size, data); - switch (data) { - case MODE_BIG_ORES, MODE_ALL_ORES -> { - for (Chunk c : chunks) { - 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); - - if (OreManager.getStoneType(block, meta) != null) continue; - - var p = OreManager.getOreInfo(block, meta); + Future task = CooperativeScheduler.INSTANCE.schedule( + ctx -> { + while (!ctx.shouldYield()) { + if (chunks.isEmpty()) { + ctx.stop(null); + break; + } - if (p != null) { - try (OreInfo info = p.right()) { - if (!info.isNatural) continue; - if (data != MODE_ALL_ORES && info.isSmall) continue; + 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); + + if (OreManager.getStoneType(block, meta) != null) continue; - packet.addBlock(c.xPosition * 16 + x, y, c.zPosition * 16 + z, block, meta); - continue; + var p = OreManager.getOreInfo(block, meta); + + if (p != null) { + try (OreInfo info = p.right()) { + if (!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; + } + } } } } } + 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); + } } } - } - case MODE_FLUIDS -> { - for (Chunk c : chunks) { - FluidStack fluid = UndergroundOil.undergroundOil(c, -1); - - packet.addFluid(c.xPosition, c.zPosition, fluid); - } - } - case DetravMetaGeneratedTool01.MODE_POLLUTION -> { - for (Chunk c : chunks) { - int pollution = Pollution.getPollution(c); + }) + .onFinished(x -> { + PENDING_SCANS.remove(aPlayer); - packet.addPollution(c.xPosition, c.zPosition, pollution); + 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, + size * 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, + size * 16)); + } } - } - } - - DetravNetwork.INSTANCE.sendToPlayer(packet, (EntityPlayerMP) aPlayer); - if (!aPlayer.capabilities.isCreativeMode) tool.doDamage(aStack, this.mCosts * chunks.size()); + }); - 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, - size * 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, - size * 16)); - } - } + PENDING_SCANS.put(aPlayer, task); } return super.onItemRightClick(aItem, aStack, aWorld, aPlayer); } 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..9df01160da5 --- /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..49831561902 --- /dev/null +++ b/src/main/java/gregtech/api/task/CooperativeScheduler.java @@ -0,0 +1,191 @@ +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 enum CooperativeScheduler { + INSTANCE; + + 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; + } + + future.run(); + + if (!future.running) { + iter.remove(); + } + + 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..0e8f18c9faa --- /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/common/config/Gregtech.java b/src/main/java/gregtech/common/config/Gregtech.java index 63a1057e960..685eaa5efde 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") From df05e6348149c84d9f8898653df70586d2100a17 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Wed, 11 Dec 2024 23:28:26 -0500 Subject: [PATCH 11/47] gt++ fixes --- .../detrav/gui/textures/DetravMapTexture.java | 4 ++++ .../java/detrav/net/ProspectingPacket.java | 2 ++ .../gregtech/api/interfaces/IMaterial.java | 2 +- .../item/base/itemblock/ItemBlockOre.java | 3 ++- .../core/item/base/ore/BaseOreComponent.java | 20 +++++++++++++++++-- .../gtPlusPlus/core/material/Material.java | 2 ++ 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/detrav/gui/textures/DetravMapTexture.java b/src/main/java/detrav/gui/textures/DetravMapTexture.java index 8cfd7431b5d..cb4fc497cc7 100644 --- a/src/main/java/detrav/gui/textures/DetravMapTexture.java +++ b/src/main/java/detrav/gui/textures/DetravMapTexture.java @@ -81,6 +81,8 @@ private BufferedImage getImage() { var object = packet.objects.get(e.getShortValue()); + if (object == null) continue; + image.setRGB(x, z, object.rightInt()); } } @@ -91,6 +93,8 @@ private BufferedImage getImage() { var object = packet.objects.get(packet.map.get(CoordinatePacker.pack(cX, 0, cZ))); + if (object == null) continue; + String name = object.left(); int rgba = object.rightInt(); diff --git a/src/main/java/detrav/net/ProspectingPacket.java b/src/main/java/detrav/net/ProspectingPacket.java index 85f4957c0b0..86742809e4b 100644 --- a/src/main/java/detrav/net/ProspectingPacket.java +++ b/src/main/java/detrav/net/ProspectingPacket.java @@ -162,6 +162,8 @@ 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; diff --git a/src/main/java/gregtech/api/interfaces/IMaterial.java b/src/main/java/gregtech/api/interfaces/IMaterial.java index 01c9573082f..b3c1a79993d 100644 --- a/src/main/java/gregtech/api/interfaces/IMaterial.java +++ b/src/main/java/gregtech/api/interfaces/IMaterial.java @@ -25,7 +25,7 @@ public static IMaterial findMaterial(String name) { if (bw != null) return bw; - IMaterial gtpp = Material.mMaterialCache.get(name); + IMaterial gtpp = Material.mMaterialsByName.get(name); if (gtpp != null) return gtpp; 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 fd301d36f15..e6d32941d38 100644 --- a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java @@ -8,6 +8,7 @@ import gregtech.api.interfaces.IMaterial; import gregtech.common.WorldgenGTOreLayer; 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; @@ -103,7 +104,7 @@ public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, fi list.add("Found:"); if (dims != null && !dims.isEmpty()) { for (String m : dims) { - list.add("- " + m); + 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..71b8cc68306 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() { @@ -233,16 +233,28 @@ public enum ComponentTypes { CRUSHED("crushed", "Crushed ", " Ore", true), CRUSHEDCENTRIFUGED("crushedCentrifuged", "Centrifuged Crushed ", " Ore", true), CRUSHEDPURIFIED("crushedPurified", "Purified Crushed ", " Ore", true), - RAWORE("oreRaw", "Raw ", " Ore", true), + RAWORE("oreRaw", OrePrefixes.rawOre, "Raw ", " Ore", true), MILLED("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) { this.COMPONENT_NAME = LocalName; + this.orePrefix = LocalName; + this.PREFIX = prefix; + this.DISPLAY_NAME = DisplayName; + this.HAS_OVERLAY = overlay; + // dust + Dirty, Impure, Pure, Refined + // crushed + centrifuged, purified + } + + 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 +266,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 1f497d50143..982f238cbb0 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -43,6 +43,7 @@ public class Material implements IMaterial { 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<>(); @@ -389,6 +390,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; From 17557b338615564087220793b61511de95a00d26 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Thu, 12 Dec 2024 00:22:31 -0500 Subject: [PATCH 12/47] gt++ optimization --- .../java/gregtech/common/WorldgenGTOreLayer.java | 1 - .../java/gtPlusPlus/core/material/Material.java | 13 ++++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 352d6e180db..34afa1769e9 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -260,7 +260,6 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int // 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 generator.generateLayer(true, false, false); // layer -1 diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index 982f238cbb0..bae1be81eea 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -27,6 +27,7 @@ import gregtech.api.interfaces.IMaterial; 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; @@ -1160,15 +1161,21 @@ 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) { From 85cd8bb22490250b66c76204b4819ba3a5b4affd Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Thu, 12 Dec 2024 01:27:09 -0500 Subject: [PATCH 13/47] more fixes & optimizations --- .../java/gregtech/api/enums/StoneType.java | 9 +- .../gregtech/api/objects/MolecularRandom.java | 162 ++ .../gregtech/common/ores/GTPPOreAdapter.java | 8 +- .../core/block/base/BlockBaseOre.java | 51 +- .../renderer/CustomOreBlockRenderer.java | 2467 ----------------- .../gtPlusPlus/core/material/Material.java | 8 +- .../gtPlusPlus/core/proxy/ClientProxy.java | 2 - .../everglades/chunk/ChunkProviderModded.java | 3 +- 8 files changed, 201 insertions(+), 2509 deletions(-) create mode 100644 src/main/java/gregtech/api/objects/MolecularRandom.java delete mode 100644 src/main/java/gtPlusPlus/core/client/renderer/CustomOreBlockRenderer.java diff --git a/src/main/java/gregtech/api/enums/StoneType.java b/src/main/java/gregtech/api/enums/StoneType.java index f25599424ef..828f52f9795 100644 --- a/src/main/java/gregtech/api/enums/StoneType.java +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -238,8 +238,10 @@ public boolean isEnabled() { public boolean contains(Block block, int meta) { if (block == builder.mainStone.block && meta == builder.mainStone.meta) return true; - for (BlockMeta other : builder.otherStones) { - if (block == other.block && meta == other.meta) return true; + if (builder.otherStones != null) { + for (BlockMeta other : builder.otherStones) { + if (block == other.block && meta == other.meta) return true; + } } return false; @@ -272,7 +274,7 @@ public BlockMeta(Block block, int meta) { private static class StoneBuilder { public boolean enabled = true; public BlockMeta cobble, mainStone; - public List otherStones = new ArrayList<>(); + public List otherStones; public OrePrefixes oreBlockPrefix = OrePrefixes.ore; public ItemStack pureDust = GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1); public ItemStack impureDust = GTOreDictUnificator.get(OrePrefixes.dustImpure, Materials.Stone, 1); @@ -364,6 +366,7 @@ public StoneBuilder addOtherStone(Mods owner, String blockName, int meta) { Block block = GameRegistry.findBlock(owner.ID, blockName); if (block != null) { + if (otherStones == null) otherStones = new ArrayList<>(); otherStones.add(new BlockMeta(block, meta)); } diff --git a/src/main/java/gregtech/api/objects/MolecularRandom.java b/src/main/java/gregtech/api/objects/MolecularRandom.java new file mode 100644 index 00000000000..d0d6aaacc61 --- /dev/null +++ b/src/main/java/gregtech/api/objects/MolecularRandom.java @@ -0,0 +1,162 @@ +package gregtech.api.objects; + +import java.util.Random; + +/** + * A standard {@link Random}, but without the atomics and synchronization. + * Useful in cases where you need to swap out a random instance without changing its results. + */ +public class MolecularRandom extends Random { + + private long seed; + private double nextNextGaussian; + private boolean haveNextNextGaussian; + + public MolecularRandom(long var1) { + this.haveNextNextGaussian = false; + this.seed = initialScramble(var1); + } + + private static long initialScramble(long var0) { + return (var0 ^ 25214903917L) & 281474976710655L; + } + + public void setSeed(long var1) { + this.seed = initialScramble(var1); + this.haveNextNextGaussian = false; + } + + protected int next(int var1) { + seed = seed * 25214903917L + 11L & 281474976710655L; + + return (int)(seed >>> 48 - var1); + } + + public void nextBytes(byte[] var1) { + int var2 = 0; + int var3 = var1.length; + + while(var2 < var3) { + int var4 = this.nextInt(); + + for(int var5 = Math.min(var3 - var2, 4); var5-- > 0; var4 >>= 8) { + var1[var2++] = (byte)var4; + } + } + + } + + final long internalNextLong(long var1, long var3) { + long var5 = this.nextLong(); + if (var1 < var3) { + long var7 = var3 - var1; + long var9 = var7 - 1L; + if ((var7 & var9) == 0L) { + var5 = (var5 & var9) + var1; + } else if (var7 > 0L) { + for(long var11 = var5 >>> 1; var11 + var9 - (var5 = var11 % var7) < 0L; var11 = this.nextLong() >>> 1) { + } + + var5 += var1; + } else { + while(var5 < var1 || var5 >= var3) { + var5 = this.nextLong(); + } + } + } + + return var5; + } + + final int internalNextInt(int var1, int var2) { + if (var1 >= var2) { + return this.nextInt(); + } else { + int var3 = var2 - var1; + if (var3 > 0) { + return this.nextInt(var3) + var1; + } else { + int var4; + do { + do { + var4 = this.nextInt(); + } while(var4 < var1); + } while(var4 >= var2); + + return var4; + } + } + } + + final double internalNextDouble(double var1, double var3) { + double var5 = this.nextDouble(); + if (var1 < var3) { + var5 = var5 * (var3 - var1) + var1; + if (var5 >= var3) { + var5 = Double.longBitsToDouble(Double.doubleToLongBits(var3) - 1L); + } + } + + return var5; + } + + public int nextInt() { + return this.next(32); + } + + public int nextInt(int var1) { + if (var1 <= 0) { + throw new IllegalArgumentException("bound must be positive"); + } else { + int var2 = this.next(31); + int var3 = var1 - 1; + if ((var1 & var3) == 0) { + var2 = (int)((long)var1 * (long)var2 >> 31); + } else { + for(int var4 = var2; var4 - (var2 = var4 % var1) + var3 < 0; var4 = this.next(31)) { + } + } + + return var2; + } + } + + public long nextLong() { + return ((long)this.next(32) << 32) + (long)this.next(32); + } + + public boolean nextBoolean() { + return this.next(1) != 0; + } + + public float nextFloat() { + return (float)this.next(24) / 1.6777216E7F; + } + + public double nextDouble() { + return (double)(((long)this.next(26) << 27) + (long)this.next(27)) * 1.1102230246251565E-16; + } + + public double nextGaussian() { + if (this.haveNextNextGaussian) { + this.haveNextNextGaussian = false; + return this.nextNextGaussian; + } else { + double var1; + double var3; + double var5; + do { + do { + var1 = 2.0 * this.nextDouble() - 1.0; + var3 = 2.0 * this.nextDouble() - 1.0; + var5 = var1 * var1 + var3 * var3; + } while(var5 >= 1.0); + } while(var5 == 0.0); + + double var7 = StrictMath.sqrt(-2.0 * StrictMath.log(var5) / var5); + this.nextNextGaussian = var3 * var7; + this.haveNextNextGaussian = true; + return var1 * var7; + } + } +} diff --git a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java index 241a491feb7..4677e212ef5 100644 --- a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java @@ -1,7 +1,6 @@ package gregtech.common.ores; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -28,6 +27,7 @@ public boolean supports(Block block, int meta) { 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; } @@ -47,6 +47,8 @@ public OreInfo getOreInfo(Block block, int meta) { @Override public ObjectIntPair getBlock(OreInfo info) { + if (!supports(info)) return null; + if (!(info.material instanceof Material gtppMat)) return null; Block ore = gtppMat.getOreBlock(1); @@ -86,9 +88,7 @@ public List getBigOreDrops(Random random, OreDropSystem oreDropMode, ArrayList drops = new ArrayList<>(); switch (oreDropMode) { - case Item -> drops.add( - ItemUtils - .getItemStackOfAmountFromOreDictNoBroken("oreRaw" + info.material.getLocalizedName(), 1)); + 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 diff --git a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java index 4980c649da9..9d4decfdeac 100644 --- a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java +++ b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java @@ -3,7 +3,8 @@ import java.util.ArrayList; import java.util.Random; -import net.minecraft.block.Block; +import javax.annotation.Nullable; + import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.EnumCreatureType; @@ -14,23 +15,21 @@ 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.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; @@ -74,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); @@ -97,20 +84,22 @@ 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 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/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index bae1be81eea..23590d392fc 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -1229,8 +1229,14 @@ public final ItemStack getMilled(final int stacksize) { return getComponentByPrefix(OrePrefixes.milled, stacksize); } + ItemStack rawOre; + 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/chunk/ChunkProviderModded.java b/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java index 409e3f150a7..ec85ace1ebf 100644 --- a/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java +++ b/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.Random; +import gregtech.api.objects.MolecularRandom; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; import net.minecraft.entity.EnumCreatureType; @@ -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 MolecularRandom(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); From ccd512ddfc1d2d643e2beaa8f12b38892eb3558a Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Thu, 12 Dec 2024 16:12:23 -0500 Subject: [PATCH 14/47] gt transformer --- src/main/java/gregtech/api/GregTechAPI.java | 2 +- .../gregtech/common/ores/GTOreAdapter.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/GregTechAPI.java b/src/main/java/gregtech/api/GregTechAPI.java index 70d1a0c2ce9..d949e6ea900 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/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index f26ff578eb6..cd9aa2d1b14 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -7,6 +7,9 @@ import java.util.Random; import java.util.concurrent.ThreadLocalRandom; +import com.gtnewhorizons.postea.api.TileEntityReplacementManager; +import com.gtnewhorizons.postea.utility.BlockInfo; + import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.Materials; @@ -21,6 +24,7 @@ import gregtech.common.blocks.BlockOresAbstract; import it.unimi.dsi.fastutil.objects.ObjectIntPair; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; public enum GTOreAdapter implements IOreAdapter { @@ -89,6 +93,36 @@ public void init() { }); ores = new BlockOresAbstract[] { ores1, ores2, ores3, ores4, ores5, ores6 }; + + StoneType[] legacyStones = { + StoneType.Stone, + StoneType.Netherrack, + StoneType.Endstone, + StoneType.BlackGranite, + StoneType.RedGranite, + StoneType.Marble, + StoneType.Basalt, + }; + + 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 { + var p = INSTANCE.getBlock(info); + + return new BlockInfo(p.left(), p.rightInt()); + } + } + }); } public void registerOre(StoneType stoneType, BlockOresAbstract oreBlock) { From 43e29e8ca7511a000fb0d6a961514cb53d9edca3 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Thu, 12 Dec 2024 16:26:58 -0500 Subject: [PATCH 15/47] fix merge problems --- src/main/java/gregtech/common/tools/ToolKnife.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/tools/ToolKnife.java b/src/main/java/gregtech/common/tools/ToolKnife.java index c5b8273d254..3005c746207 100644 --- a/src/main/java/gregtech/common/tools/ToolKnife.java +++ b/src/main/java/gregtech/common/tools/ToolKnife.java @@ -72,7 +72,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "sword") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, From c3f80a4aad07be84b948bce2228fef812a34b71d Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Mon, 16 Dec 2024 13:27:30 -0500 Subject: [PATCH 16/47] misc cleanup + impl --- .../galacticgreg/WorldGeneratorSpace.java | 102 ++++++- src/main/java/galacticgreg/api/Enums.java | 6 - .../galacticgreg/api/ModDimensionDef.java | 81 ++---- .../galacticgreg/api/enums/DimensionDef.java | 10 +- .../java/gregtech/api/enums/GTValues.java | 4 - .../java/gregtech/api/enums/SmallOres.java | 8 +- .../java/gregtech/api/enums/StoneType.java | 4 + .../gregtech/common/GTWorldgenerator.java | 28 +- .../java/gregtech/common/SmallOreBuilder.java | 4 - .../common/blocks/BlockOresAbstract.java | 52 +++- .../loaders/oreprocessing/ProcessingOre.java | 2 +- .../oreprocessing/ProcessingRawOre.java | 2 +- .../gregtech/loaders/preload/GTPreLoad.java | 1 - src/main/java/gregtech/nei/NEIGTConfig.java | 6 +- .../gtPlusPlus/core/material/Material.java | 1 - .../gtPlusPlus/everglades/GTPPEverglades.java | 4 - .../gen/gt/WorldGen_GT_Ore_Layer.java | 16 -- .../everglades/gen/gt/WorldGen_Ores.java | 250 ------------------ 18 files changed, 184 insertions(+), 397 deletions(-) delete mode 100644 src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java delete mode 100644 src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index c75dc0c644d..13b0c218875 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -88,7 +88,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP if (gen == null) continue; - // if (!gen.affectsChunk(chunkX, chunkZ)) continue; + if (!gen.affectsChunk(chunkX, chunkZ)) continue; gen.generateChunk(world, chunkX, chunkZ); @@ -98,7 +98,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP long post = System.nanoTime(); - GalacticGreg.Logger.info("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3); + if (profileWorldGen) GTMod.GT_FML_LOGGER.info("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3); Chunk tChunk = world.getChunkFromBlockCoords(chunkX, chunkZ); if (tChunk != null) { @@ -109,7 +109,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP public static class AsteroidGenerator { public List positive, negative; - public int cX, cY, cZ, radius; + public int seedChunkX, seedChunkZ, cX, cY, cZ, radius; public long seed; public StoneType stoneType; @@ -189,6 +189,9 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh gen.positive = positive; gen.negative = negative; + gen.seedChunkX = seedChunkX; + gen.seedChunkZ = seedChunkZ; + gen.cX = tX; gen.cY = tY; gen.cZ = tZ; @@ -313,6 +316,99 @@ public void generateChunk(World world, int chunkX, int chunkZ) { } } } + + if (chunkX == seedChunkX && chunkZ == seedChunkZ) { + generateLootChest(world, dimAsteroidConfig); + } + } + + private void generateLootChest(World world, AsteroidConfig asteroidConfig) { + XSTR rng = getRandom(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId); + + if (asteroidConfig.LootChestChance == 0 || radius < 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 + BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; + + // Place down the chest + world.setBlock( + cX, + cY, + cZ, + tTargetChestType.getBlock(), + tTargetChestType.getMeta(), + 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); } } 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 de08718a440..48854a6f8eb 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -6,7 +6,7 @@ import galacticgreg.api.Enums.DimensionType; import gregtech.api.enums.StoneType; -import gregtech.api.interfaces.IStoneType; +import gregtech.common.config.Gregtech; import net.minecraft.block.Block; import net.minecraft.world.chunk.IChunkProvider; @@ -22,16 +22,14 @@ public class ModDimensionDef { /** "modname_dimname" */ private String internalDimIdentifier; private final String chunkProviderName; - private Enums.AirReplaceRule airReplaceSetting; private final ArrayList replaceableBlocks; private DimensionType dimensionType; private final List spaceObjectGenerators; private final List spaceStructureGenerators; - // Special Planets config settings - private int groundOreMaxY = 64; - private int floatingAsteroidsMinY = 128; + private int oreVeinChance = Gregtech.general.oreveinPercentage; + // ------ // Asteroid stuff @@ -105,33 +103,28 @@ public ModDimensionDef(String pDimensionName, String pChunkProviderName, Dimensi } /** - * Internal function - * - * @return A list of possible asteroid-mixes that shall be generated + * Sets the chance that an ore seed chunk will have a vein + * @param chance The chance out of 100. */ - public List getValidAsteroidMaterials() { - return validAsteroidMaterials; + public ModDimensionDef setOreVeinChance(int chance) { + oreVeinChance = chance; + return this; } - // ================================================= - /** - * 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 - */ - public int getPreConfiguredGroundOreMaxY() { - return groundOreMaxY; + public int getOreVeinChance() { + return oreVeinChance; } /** - * 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 + * Internal function + * + * @return A list of possible asteroid-mixes that shall be generated */ - public int getPreConfiguredFloatingAsteroidMinY() { - return floatingAsteroidsMinY; + public List getValidAsteroidMaterials() { + return validAsteroidMaterials; } + // ================================================= /** * 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 @@ -183,24 +176,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!"); - - floatingAsteroidsMinY = pAsteroidMinY; - groundOreMaxY = pOregenMaxY; - } // ================================================= /** @@ -235,30 +210,6 @@ public void setDimensionType(DimensionType pType) { dimensionType = pType; } - /** - * Internal function - * - * @return The configuration for AirBlocks - */ - public Enums.AirReplaceRule getAirSetting() { - return airReplaceSetting; - } - - /** - * 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) { - airReplaceSetting = pSetting; - } - /** * Internal function * diff --git a/src/main/java/galacticgreg/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index 285517a2b78..a0edc752db9 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -2,6 +2,7 @@ import net.minecraft.world.World; import net.minecraft.world.gen.ChunkProviderEnd; +import net.minecraft.world.gen.ChunkProviderGenerate; import net.minecraft.world.gen.ChunkProviderHell; import java.util.HashMap; @@ -14,9 +15,10 @@ public enum DimensionDef { + // spotless:off Overworld(new ModDimensionDef( DimNames.OW, - "", + ChunkProviderGenerate.class, DimensionType.Planet)), Nether(new ModDimensionDef( DimNames.NETHER, @@ -32,12 +34,13 @@ public enum DimensionDef { Enums.DimensionType.Asteroid)), TwilightForest(new ModDimensionDef( DimNames.TWILIGHT_FOREST, - "", + "twilightforest.world.ChunkProviderTwilightForest", DimensionType.Planet)), Everglades(new ModDimensionDef( DimNames.EVERGLADES, ChunkProviderModded.class, - DimensionType.Planet)), + DimensionType.Planet) + .setOreVeinChance(66)), Moon(new ModDimensionDef( @@ -216,6 +219,7 @@ public enum DimensionDef { DimNames.MEHENBELT, "de.katzenpapst.amunra.world.mehen.MehenChunkProvider", Enums.DimensionType.Asteroid)); + // spotless:on public final ModDimensionDef modDimensionDef; diff --git a/src/main/java/gregtech/api/enums/GTValues.java b/src/main/java/gregtech/api/enums/GTValues.java index 669ac084c36..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 diff --git a/src/main/java/gregtech/api/enums/SmallOres.java b/src/main/java/gregtech/api/enums/SmallOres.java index f6a31b743af..24bf608e45e 100644 --- a/src/main/java/gregtech/api/enums/SmallOres.java +++ b/src/main/java/gregtech/api/enums/SmallOres.java @@ -30,10 +30,10 @@ 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 static galacticgreg.api.enums.DimensionDef.DimNames.OW; +import static galacticgreg.api.enums.DimensionDef.DimNames.NETHER; +import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; +import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; import gregtech.common.SmallOreBuilder; import gregtech.common.WorldgenGTOreSmallPieces; diff --git a/src/main/java/gregtech/api/enums/StoneType.java b/src/main/java/gregtech/api/enums/StoneType.java index 828f52f9795..a43a30d6040 100644 --- a/src/main/java/gregtech/api/enums/StoneType.java +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -35,6 +35,8 @@ import net.minecraft.world.World; public enum StoneType implements IStoneType { + + // spotless:off Stone(new StoneBuilder() .setCobble(Blocks.cobblestone, 0) .setMainStone(Blocks.stone, 0) @@ -117,7 +119,9 @@ public enum StoneType implements IStoneType { .setStoneNoCobble(Blocks.packed_ice, 0) .setDust(Materials.Ice) .setCategory(StoneCategory.Ice)), + ; + // spotless:on public static final ImmutableList STONE_TYPES = ImmutableList.copyOf(values()); public static final ImmutableList VISUAL_STONE_TYPES = ImmutableList.copyOf(Arrays.stream(values()).filter(s -> s.builder.enabled && !s.isExtraneous()).toArray(StoneType[]::new)); diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index 2411c61ebf3..f986f4e49b8 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -4,7 +4,6 @@ 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.Collections; @@ -42,7 +41,8 @@ public class GTWorldgenerator implements IWorldGenerator { - private static int maxVeinSize = 2; // in chunks + private static final int MAX_VEIN_SIZE = 2; // in chunks + private static final int END_ASTEROID_DISTANCE = 16; // in chunks public static List pendingTasks = Collections.synchronizedList(new LinkedList<>()); @@ -71,8 +71,6 @@ public GTWorldgenerator() { } } - private static final int END_ASTEROID_DISTANCE = 16; - @Override public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { @@ -110,7 +108,7 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide + " SIZE: " + pendingTasks.size()); - // hack to prevent cascading worldgen + // hack to prevent cascading worldgen lag if (!this.mIsGenerating) { this.mIsGenerating = true; @@ -364,7 +362,9 @@ public void generateVein(int oreseedX, int oreseedZ) { return; } - if (oreveinPercentageRoll < oreveinPercentage) { + ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(mWorld); + + if (oreveinPercentageRoll < dimensionDef.getOreVeinChance()) { int placementAttempts = 0; boolean oreveinFound = false; int i; @@ -422,7 +422,7 @@ public void generateVein(int oreseedX, int oreseedZ) { if (debugOrevein) GTLog.out.println( " Added near oreveinSeed=" + oreveinSeed + " " - + (oreLayer).mWorldGenName + + oreLayer.mWorldGenName + " tries at oremix=" + i + " placementAttempts=" @@ -431,7 +431,6 @@ public void generateVein(int oreseedX, int oreseedZ) { + dimensionName); validOreveins.put(oreveinSeed, oreLayer); oreveinFound = true; - break; } case WorldgenGTOreLayer.NO_ORE_IN_BOTTOM_LAYER -> placementAttempts++; @@ -449,7 +448,6 @@ public void generateVein(int oreseedX, int oreseedZ) { + dimensionName); validOreveins.put(oreveinSeed, oreLayer); oreveinFound = true; - break; } case WorldgenGTOreLayer.NO_OVERLAP_AIR_BLOCK -> { if (debugOrevein) GTLog.out.println( @@ -488,7 +486,7 @@ public void generateVein(int oreseedX, int oreseedZ) { + dimensionName); validOreveins.put(oreveinSeed, noOresInVein); } - } else if (oreveinPercentageRoll >= oreveinPercentage) { + } else if (oreveinPercentageRoll >= dimensionDef.getOreVeinChance()) { if (debugOrevein) GTLog.out.println( " Skipped oreveinSeed=" + oreveinSeed + " mX=" @@ -502,7 +500,7 @@ public void generateVein(int oreseedX, int oreseedZ) { + " RNG=" + oreveinPercentageRoll + " %=" - + oreveinPercentage + + dimensionDef.getOreVeinChance() + " dimensionName=" + dimensionName); validOreveins.put(oreveinSeed, noOresInVein); @@ -536,10 +534,10 @@ public void run() { long stonegenTime = System.nanoTime(); - int wXbox = this.mX - maxVeinSize; - int eXbox = this.mX + maxVeinSize + 1; // Need to add 1 since it is compared using a < - int nZbox = this.mZ - maxVeinSize; - int sZbox = this.mZ + maxVeinSize + 1; + int wXbox = this.mX - MAX_VEIN_SIZE; + int eXbox = this.mX + MAX_VEIN_SIZE + 1; // Need to add 1 since it is compared using a < + int nZbox = this.mZ - MAX_VEIN_SIZE; + int sZbox = this.mZ + MAX_VEIN_SIZE + 1; // Search for orevein seeds and add to the list; for (int x = wXbox; x < eXbox; x++) { diff --git a/src/main/java/gregtech/common/SmallOreBuilder.java b/src/main/java/gregtech/common/SmallOreBuilder.java index 98980a58a7a..635b0383761 100644 --- a/src/main/java/gregtech/common/SmallOreBuilder.java +++ b/src/main/java/gregtech/common/SmallOreBuilder.java @@ -10,10 +10,6 @@ public class SmallOreBuilder { - public static final String OW = "Overworld"; - public static final String NETHER = "Nether"; - public static final String THE_END = "The End"; - public static final String TWILIGHT_FOREST = "Twilight Forest"; public String smallOreName; public boolean enabledByDefault = true; /** {full dimension name} */ diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java index 68739e34e84..24a4dd21856 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java @@ -25,6 +25,7 @@ import gregtech.common.ores.GTOreAdapter; import gregtech.common.ores.OreInfo; import gregtech.common.render.GTRendererBlock; +import gregtech.nei.NEIGTConfig; import net.minecraft.block.material.Material; import net.minecraft.client.particle.EffectRenderer; import net.minecraft.creativetab.CreativeTabs; @@ -110,8 +111,15 @@ 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++) { @@ -121,16 +129,21 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { if (!GTOreAdapter.INSTANCE.supports(info)) continue; for (StoneType stoneType : stoneTypes) { - // if this material only has ice ore, we only want to show the ice variants + if (stoneType == null) continue; + if (info.material.contains(SubTag.ICE_ORE)) { - if (stoneType != null && stoneType.getCategory() == StoneCategory.Ice) { - info.stoneType = stoneType; - - list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); - } - } else { - if (stoneType == null || stoneType.isExtraneous()) continue; + // 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)); @@ -144,16 +157,27 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { info.material = getMaterial(matId); info.stoneType = null; - if (info.material != null && info.material.contains(SubTag.ICE_ORE)) continue; - if (!GTOreAdapter.INSTANCE.supports(info)) continue; for (StoneType stoneType : stoneTypes) { - if (stoneType == null || stoneType.isExtraneous()) continue; - - info.stoneType = stoneType; + if (stoneType == null) continue; - list.add(GTOreAdapter.INSTANCE.getStack(info, 1)); + 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)); + } } } } diff --git a/src/main/java/gregtech/loaders/oreprocessing/ProcessingOre.java b/src/main/java/gregtech/loaders/oreprocessing/ProcessingOre.java index c63925694a6..9621a6aa83f 100644 --- a/src/main/java/gregtech/loaders/oreprocessing/ProcessingOre.java +++ b/src/main/java/gregtech/loaders/oreprocessing/ProcessingOre.java @@ -61,7 +61,7 @@ public void registerOre(OrePrefixes aPrefix, Materials aMaterial, String aOreDic if (aMaterial.contains(SubTag.ICE_ORE)) { GTValues.RA.stdBuilder() .itemInputs(GTUtility.copyAmount(1, aStack)) - .fluidOutputs(aMaterial.getGas(tIsRich ? 2000L : 1000L)) + .fluidOutputs(aMaterial.getGas((tIsRich ? 2000L : 1000L) * aMaterial.mOreMultiplier)) .duration(5 * SECONDS) .eut(TierEU.RECIPE_MV) .addTo(RecipeMaps.fluidExtractionRecipes); diff --git a/src/main/java/gregtech/loaders/oreprocessing/ProcessingRawOre.java b/src/main/java/gregtech/loaders/oreprocessing/ProcessingRawOre.java index aa997339da3..328895d138f 100644 --- a/src/main/java/gregtech/loaders/oreprocessing/ProcessingRawOre.java +++ b/src/main/java/gregtech/loaders/oreprocessing/ProcessingRawOre.java @@ -38,7 +38,7 @@ public void registerOre(OrePrefixes aPrefix, Materials aMaterial, String aOreDic if (aMaterial.contains(SubTag.ICE_ORE)) { GTValues.RA.stdBuilder() .itemInputs(GTUtility.copyAmount(1, aStack)) - .fluidOutputs(aMaterial.getGas(5000L)) + .fluidOutputs(aMaterial.getGas(1000L * aMaterial.mOreMultiplier)) .duration(2 * SECONDS) .eut(TierEU.RECIPE_MV) .addTo(RecipeMaps.fluidExtractionRecipes); diff --git a/src/main/java/gregtech/loaders/preload/GTPreLoad.java b/src/main/java/gregtech/loaders/preload/GTPreLoad.java index 929660c0b71..2313e9735a8 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/nei/NEIGTConfig.java b/src/main/java/gregtech/nei/NEIGTConfig.java index 6a989e9f616..c9e03c8e345 100644 --- a/src/main/java/gregtech/nei/NEIGTConfig.java +++ b/src/main/java/gregtech/nei/NEIGTConfig.java @@ -127,11 +127,7 @@ private void registerDumpers() { private void hideItems() { for (BlockOresAbstract ore : GTOreAdapter.INSTANCE.ores) { - if (ore.isExtraneous()) { - for (int i = 0; i < 16; i++) { - API.hideItem(new ItemStack(ore, i)); - } - } + API.hideItem(new ItemStack(ore, 1, 0)); } } diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index 23590d392fc..fabc029c554 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -14,7 +14,6 @@ import net.minecraft.block.Block; import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; diff --git a/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java b/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java index 0e4f003a271..3bd59855169 100644 --- a/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java +++ b/src/main/java/gtPlusPlus/everglades/GTPPEverglades.java @@ -114,10 +114,6 @@ protected synchronized void setVars(FMLPreInitializationEvent event) { DimensionEverglades.DIMID = DimensionManager.getNextFreeDimId(); } - /* - * Set World Generation Values - */ - // WorldGen_GT_Base.oreveinPercentage = 64; DarkWorldContentLoader.run(); } 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 33107781879..00000000000 --- a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_GT_Ore_Layer.java +++ /dev/null @@ -1,16 +0,0 @@ -package gtPlusPlus.everglades.gen.gt; - -import gtPlusPlus.core.material.Material; - -public class WorldGen_GT_Ore_Layer { - - 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) { - } - - 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) { - - } -} 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 12f7df12657..00000000000 --- a/src/main/java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java +++ /dev/null @@ -1,250 +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); - -} From 99f0c0a84e1c0c703070e8daccb7fb0c55955e88 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Mon, 16 Dec 2024 22:24:48 -0500 Subject: [PATCH 17/47] revert accidental change to XSTR seed --- src/main/java/gregtech/common/GTWorldgenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index f986f4e49b8..762813dd92b 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -392,7 +392,7 @@ public void generateVein(int oreseedX, int oreseedZ) { // a unique height each pass through here. placementResult = oreLayer.executeWorldgenChunkified( this.mWorld, - new XSTR(oreveinSeed ^ (oreLayer.mPrimary.hashCode())), + new XSTR(oreveinSeed ^ (oreLayer.mPrimary.getId())), this.mBiome, this.mDimensionType, this.mX * 16, From a3057764e44b0bf0a01d0c8dc843e44e7adbb6d5 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Tue, 17 Dec 2024 13:20:44 -0500 Subject: [PATCH 18/47] clean + spotless --- .../material/BWItemMetaGeneratedOre.java | 5 +- .../system/material/BWMetaGeneratedOres.java | 21 +- .../bartworks/system/material/Werkstoff.java | 4 +- .../system/material/WerkstoffLoader.java | 6 - .../galacticgreg/MTEVoidMinerBase.java | 16 +- .../galacticgreg/VoidMinerUtility.java | 6 +- .../detrav/commands/DetravScannerCommand.java | 7 +- .../java/detrav/gui/DetravScannerGUI.java | 7 +- src/main/java/detrav/gui/OresList.java | 14 +- .../detrav/gui/textures/DetravMapTexture.java | 8 +- ...BehaviourDetravToolElectricProspector.java | 93 +++--- .../BehaviourDetravToolProspector.java | 37 +-- .../DetravToolElectricProspectorBase.java | 4 +- .../java/detrav/net/ProspectingPacket.java | 10 +- .../java/galacticgreg/SpaceDimRegisterer.java | 5 +- .../galacticgreg/WorldGeneratorSpace.java | 280 +++++------------ .../galacticgreg/api/AsteroidBlockComb.java | 9 +- .../galacticgreg/api/ModDimensionDef.java | 18 +- .../galacticgreg/api/enums/DimensionDef.java | 10 +- .../galacticgreg/command/WorldgenCommand.java | 16 +- .../registry/GalacticGregRegistry.java | 6 +- .../java/gregtech/api/enums/Materials.java | 4 +- .../java/gregtech/api/enums/OreMixes.java | 152 ++++----- .../java/gregtech/api/enums/SmallOres.java | 11 +- .../java/gregtech/api/enums/StoneType.java | 46 ++- .../gregtech/api/interfaces/IBlockOre.java | 16 - .../api/interfaces/IBlockWithTextures.java | 2 +- .../gregtech/api/interfaces/IDimension.java | 10 - .../gregtech/api/interfaces/IMaterial.java | 7 +- .../api/interfaces/IStoneCategory.java | 2 +- .../gregtech/api/interfaces/IStoneType.java | 13 +- .../gregtech/api/objects/MolecularRandom.java | 293 +++++++++--------- src/main/java/gregtech/api/task/CoopTask.java | 2 +- .../api/task/CooperativeScheduler.java | 32 +- .../gregtech/api/task/ICoopTaskContext.java | 2 +- .../java/gregtech/api/util/GTBaseCrop.java | 3 +- .../java/gregtech/api/util/GTUtility.java | 7 +- .../java/gregtech/api/world/GTWorldgen.java | 4 +- .../gregtech/common/GTWorldgenerator.java | 31 +- .../gregtech/common/WorldgenGTOreLayer.java | 31 +- .../common/WorldgenGTOreSmallPieces.java | 9 +- .../java/gregtech/common/WorldgenStone.java | 50 +-- .../gregtech/common/blocks/BlockFrameBox.java | 8 +- .../common/blocks/BlockOresAbstract.java | 118 +++---- .../common/blocks/BlockOresAbstractOld.java | 6 +- .../gregtech/common/blocks/BlockOresOld.java | 10 - .../java/gregtech/common/blocks/ItemOres.java | 3 +- .../common/blocks/TileEntityOres.java | 28 +- .../items/behaviors/BehaviourProspecting.java | 28 +- .../common/misc/DrillingLogicDelegate.java | 1 + .../gregtech/common/ores/BWOreAdapter.java | 57 ++-- .../gregtech/common/ores/GTOreAdapter.java | 36 ++- .../gregtech/common/ores/GTPPOreAdapter.java | 24 +- .../gregtech/common/ores/IOreAdapter.java | 15 +- .../java/gregtech/common/ores/OreInfo.java | 43 ++- .../java/gregtech/common/ores/OreManager.java | 61 ++-- .../gregtech/common/ores/SmallOreDrops.java | 6 +- .../multi/MTEOreDrillingPlantBase.java | 10 +- .../gregtech/common/tools/ToolChainsawLV.java | 4 +- .../common/worldgen/IWorldgenLayer.java | 15 +- .../common/worldgen/WorldgenQuery.java | 5 +- src/main/java/gregtech/nei/NEIGTConfig.java | 3 +- .../core/block/base/BlockBaseOre.java | 9 +- .../item/base/itemblock/ItemBlockOre.java | 6 +- .../core/item/base/ore/BaseOreComponent.java | 3 +- .../gtPlusPlus/core/material/Material.java | 9 +- .../everglades/chunk/ChunkProviderModded.java | 2 +- .../gtPlusPlus/xmod/gregtech/HandlerGT.java | 3 - .../plugin/NEIPluginConfig.java | 4 +- .../plugin/gregtech5/PluginGT5Base.java | 1 + .../gregtech5/PluginGT5SmallOreStat.java | 7 +- .../plugin/gregtech5/PluginGT5VeinStat.java | 18 +- .../gtneioreplugin/util/DimensionHelper.java | 10 +- .../util/GT5OreLayerHelper.java | 10 +- .../util/GT5OreSmallHelper.java | 21 +- src/main/java/gtneioreplugin/util/Oremix.java | 3 +- .../java/gtneioreplugin/util/SmallOre.java | 1 - .../multiblock/eigbuckets/EIGIC2Bucket.java | 10 +- .../tectech/recipe/EyeOfHarmonyRecipe.java | 20 +- 79 files changed, 910 insertions(+), 1017 deletions(-) delete mode 100644 src/main/java/gregtech/api/interfaces/IBlockOre.java delete mode 100644 src/main/java/gregtech/api/interfaces/IDimension.java diff --git a/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java b/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java index 81f5de72fc3..3ef9cd7b00c 100644 --- a/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java +++ b/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java @@ -2,13 +2,14 @@ import java.util.List; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.OrePrefixes; 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; diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java index 987a8fbc933..588540e7e55 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -32,6 +32,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; + import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IBlockWithTextures; @@ -51,7 +52,7 @@ public class BWMetaGeneratedOres extends Block implements IBlockWithTextures { public BWMetaGeneratedOres(String blockName, StoneType stoneType, boolean small, boolean natural) { super(Material.rock); - + this.setBlockName(blockName); this.setHardness(5.0F); this.setResistance(5.0F); @@ -147,16 +148,16 @@ public ITexture[][] getTextures(int 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 - }; + 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]) - }; + 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/Werkstoff.java b/src/main/java/bartworks/system/material/Werkstoff.java index 9880f9e17d2..a111b56690e 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -31,11 +31,11 @@ import java.util.Objects; import java.util.Optional; -import com.google.common.collect.ImmutableList; - import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; +import com.google.common.collect.ImmutableList; + import bartworks.MainMod; import bartworks.system.oredict.OreDictHandler; import bartworks.util.BWColorUtil; diff --git a/src/main/java/bartworks/system/material/WerkstoffLoader.java b/src/main/java/bartworks/system/material/WerkstoffLoader.java index 7d5c4e3901f..484e3628303 100644 --- a/src/main/java/bartworks/system/material/WerkstoffLoader.java +++ b/src/main/java/bartworks/system/material/WerkstoffLoader.java @@ -90,10 +90,7 @@ import org.apache.logging.log4j.Level; import com.google.common.collect.HashBiMap; -import com.gtnewhorizons.postea.api.TileEntityReplacementManager; -import com.gtnewhorizons.postea.utility.BlockInfo; -import bartworks.API.SideReference; import bartworks.API.WerkstoffAdderRegistry; import bartworks.MainMod; import bartworks.system.material.CircuitGeneration.BWCircuitsLoader; @@ -126,10 +123,8 @@ import codechicken.nei.api.API; import cpw.mods.fml.common.ProgressManager; import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.api.GregTechAPI; import gregtech.api.enums.Element; import gregtech.api.enums.FluidState; -import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SubTag; @@ -138,7 +133,6 @@ import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.util.GTOreDictUnificator; import gregtech.common.ores.BWOreAdapter; -import gregtech.loaders.postload.PosteaTransformers; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputOreDict; import ic2.api.recipe.RecipeOutput; diff --git a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java index 09a49eed421..0f4984ff021 100644 --- a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java +++ b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java @@ -24,6 +24,13 @@ import java.util.Map; import java.util.stream.Collectors; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + import com.google.common.collect.ImmutableList; import gregtech.api.enums.GTValues; @@ -33,12 +40,6 @@ import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gregtech.common.tileentities.machines.multi.MTEDrillerBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; public abstract class MTEVoidMinerBase extends MTEDrillerBase { @@ -229,7 +230,8 @@ private void handleFluidConsumption() { * totalWeight for normalisation */ private void calculateDropMap() { - String dimName = this.getBaseMetaTileEntity().getWorld().provider.getDimensionName(); + String dimName = this.getBaseMetaTileEntity() + .getWorld().provider.getDimensionName(); this.dropMap = VoidMinerUtility.dropMapsByDimName.getOrDefault(dimName, new VoidMinerUtility.DropMap()); this.extraDropMap = VoidMinerUtility.extraDropsByDimName.getOrDefault(dimName, new VoidMinerUtility.DropMap()); diff --git a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java index cb3645022c1..38a3467c711 100644 --- a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java +++ b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java @@ -183,9 +183,9 @@ public static void addBlockToDimensionList(String dimName, Block block, int meta * 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 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 + * @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(String dimName, IMaterial material, float weight) { DropMap map = dropMapsByDimName.computeIfAbsent(dimName, ignored -> new DropMap()); diff --git a/src/main/java/detrav/commands/DetravScannerCommand.java b/src/main/java/detrav/commands/DetravScannerCommand.java index b84e932fc78..b74385c8e2d 100644 --- a/src/main/java/detrav/commands/DetravScannerCommand.java +++ b/src/main/java/detrav/commands/DetravScannerCommand.java @@ -104,10 +104,11 @@ private void process(ICommandSender sender, int aX, int aZ, String fName) { try (OreInfo info = p.right()) { if (info.isSmall) continue; - + String matName = info.material.getLocalizedName(); - - if (fName == null || matName.toLowerCase().contains(fName)) { + + if (fName == null || matName.toLowerCase() + .contains(fName)) { ores.merge(matName, 1, sum); } } diff --git a/src/main/java/detrav/gui/DetravScannerGUI.java b/src/main/java/detrav/gui/DetravScannerGUI.java index e6c63713fde..784c6272bdb 100644 --- a/src/main/java/detrav/gui/DetravScannerGUI.java +++ b/src/main/java/detrav/gui/DetravScannerGUI.java @@ -106,9 +106,7 @@ public void drawScreen(int x, int y, float f) { 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_name") + object.left()); info.add( StatCollector.translateToLocal("gui.detrav.scanner.tooltip.fluid_amount") + GTUtility.formatNumbers(amount) @@ -131,8 +129,7 @@ public void drawScreen(int x, int y, float f) { if (amount > 0) { info.add( - StatCollector.translateToLocal("gui.detrav.scanner.pollution") - + ": " + StatCollector.translateToLocal("gui.detrav.scanner.pollution") + ": " + GTUtility.formatNumbers(amount) + GTUtility.trans("203", " gibbl")); } diff --git a/src/main/java/detrav/gui/OresList.java b/src/main/java/detrav/gui/OresList.java index 095c5683a1d..9e061dbe60a 100644 --- a/src/main/java/detrav/gui/OresList.java +++ b/src/main/java/detrav/gui/OresList.java @@ -8,6 +8,7 @@ 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; @@ -28,7 +29,12 @@ public OresList(GuiScreen parent, int width, int height, int top, int bottom, in super(parent.mc, width, height, top, bottom, left, entryHeight); this.parent = parent; this.onSelected = onSelected; - keys = packet.objects.short2ObjectEntrySet().stream().map(e -> e.getValue().left()).collect(Collectors.toList()); + keys = packet.objects.short2ObjectEntrySet() + .stream() + .map( + e -> e.getValue() + .left()) + .collect(Collectors.toList()); Collections.sort(keys); if (packet.ptype == DetravMetaGeneratedTool01.MODE_POLLUTION) { keys.clear(); @@ -39,7 +45,11 @@ public OresList(GuiScreen parent, int width, int height, int top, int bottom, in selected = 0; for (var e : packet.objects.short2ObjectEntrySet()) { - this.colors.put(e.getValue().left(), e.getValue().rightInt()); + this.colors.put( + e.getValue() + .left(), + e.getValue() + .rightInt()); } } diff --git a/src/main/java/detrav/gui/textures/DetravMapTexture.java b/src/main/java/detrav/gui/textures/DetravMapTexture.java index cb4fc497cc7..f2b1695502a 100644 --- a/src/main/java/detrav/gui/textures/DetravMapTexture.java +++ b/src/main/java/detrav/gui/textures/DetravMapTexture.java @@ -60,7 +60,9 @@ private BufferedImage getImage() { if (!selected.equals("All")) { for (var e : packet.objects.short2ObjectEntrySet()) { - if (selected.equals(e.getValue().left())) { + if (selected.equals( + e.getValue() + .left())) { selectedId = e.getShortKey(); break; } @@ -90,7 +92,7 @@ private BufferedImage getImage() { for (int cZ = 0; cZ < chunkSize; cZ++) { for (int cX = 0; cX < chunkSize; cX++) { int amount = packet.getAmount(cX, cZ); - + var object = packet.objects.get(packet.map.get(CoordinatePacker.pack(cX, 0, cZ))); if (object == null) continue; @@ -151,7 +153,7 @@ private BufferedImage getImage() { 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); + raster.setSample(x, y, 2, raster.getSample(x, y, 2) / 2); } } } diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java index 02a5d3ebb6d..60e8b04a3a7 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -39,7 +39,8 @@ */ public class BehaviourDetravToolElectricProspector extends BehaviourDetravToolProspector { - private Map> PENDING_SCANS = new MapMaker().weakValues().makeMap(); + private Map> PENDING_SCANS = new MapMaker().weakValues() + .makeMap(); public BehaviourDetravToolElectricProspector(int aCosts) { super(aCosts); @@ -97,61 +98,65 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW size, data); - Future task = CooperativeScheduler.INSTANCE.schedule( - ctx -> { - while (!ctx.shouldYield()) { - if (chunks.isEmpty()) { - ctx.stop(null); - break; - } + 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); + + if (OreManager.getStoneType(block, meta) != null) continue; + + var p = OreManager.getOreInfo(block, meta); + + if (p != null) { + try (OreInfo info = p.right()) { + if (!info.isNatural) continue; + if (data != MODE_ALL_ORES && info.isSmall) continue; - 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); - - if (OreManager.getStoneType(block, meta) != null) continue; - - var p = OreManager.getOreInfo(block, meta); - - if (p != null) { - try (OreInfo info = p.right()) { - if (!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; - } + packet.addBlock( + c.xPosition * 16 + x, + y, + c.zPosition * 16 + z, + block, + meta); + continue; } } } } } - 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); - } + } + 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); } } - }) + } + }) .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( diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java index 0441bbde625..3f12a10f5c8 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java @@ -87,7 +87,8 @@ public boolean onItemUse(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPla return true; } - if (block.getMaterial() == Material.rock || block.getMaterial() == Material.ground || GTUtility.isMinable(block, meta)) { + if (block.getMaterial() == Material.rock || block.getMaterial() == Material.ground + || GTUtility.isMinable(block, meta)) { prospectChunks(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, aRandom, chance); return true; @@ -132,15 +133,15 @@ protected void prospectChunks(MetaBaseItem aItem, ItemStack aStack, EntityPlayer 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))); + EnumChatFormatting.YELLOW + "Chunk at " + + aX + + "|" + + aZ + + " to " + + (aX + 16) + + "|" + + (aZ + 16) + + StatCollector.translateToLocal("detrav.scanner.distance.texts." + distTextIndex))); } processOreProspecting( @@ -257,8 +258,7 @@ protected void prospectSingleChunk(MetaBaseItem aItem, ItemStack aStack, EntityP } protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack aStack, EntityPlayer aPlayer, - World world, int x, int y, int z, SplittableRandom aRandom, int chance) - { + 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); @@ -271,9 +271,9 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack if (!aPlayer.capabilities.isCreativeMode) aItem.doDamage(aStack, this.mCosts); return; } - + ItemData itemData = GTOreDictUnificator.getAssociation(blockStack); - + if (itemData != null) { try { String name = itemData.toString(); @@ -286,7 +286,7 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack return; } - + if (aRandom.nextInt(100) < chance) { final int data = DetravMetaGeneratedTool01.INSTANCE.getToolGTDetravData(aStack) .intValue(); @@ -295,7 +295,7 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack 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); @@ -305,13 +305,14 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack try (OreInfo info = p.right()) { if (!info.isNatural) continue; if (data != DetravMetaGeneratedTool01.MODE_ALL_ORES && info.isSmall) continue; - + ItemStack blockStack2 = new ItemStack(tBlock, 1, tMetaID); addOreToHashMap(blockStack2.getDisplayName(), aPlayer); } } else if (data == DetravMetaGeneratedTool01.MODE_ALL_ORES) { itemData = GTOreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); - if (itemData != null && itemData.mPrefix.toString().startsWith("ore")) { + if (itemData != null && itemData.mPrefix.toString() + .startsWith("ore")) { try { try { tMetaID = (short) itemData.mMaterial.mMaterial.mMetaItemSubID; diff --git a/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java b/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java index 67742c349c8..994b6a34ef8 100644 --- a/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java +++ b/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java @@ -193,8 +193,8 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase + EnumChatFormatting.WHITE); } - public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, - int aX, int aY, int aZ) { + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, + int aY, int aZ) { return aDefault; } } diff --git a/src/main/java/detrav/net/ProspectingPacket.java b/src/main/java/detrav/net/ProspectingPacket.java index 86742809e4b..e8803b26585 100644 --- a/src/main/java/detrav/net/ProspectingPacket.java +++ b/src/main/java/detrav/net/ProspectingPacket.java @@ -110,8 +110,12 @@ public void encode(OutputStream out) throws IOException { for (var obj : objects.short2ObjectEntrySet()) { tOut.writeShort(obj.getShortKey()); - tOut.writeUTF(obj.getValue().left()); - tOut.writeInt(obj.getValue().rightInt()); + tOut.writeUTF( + obj.getValue() + .left()); + tOut.writeInt( + obj.getValue() + .rightInt()); } tOut.writeInt(map.size()); @@ -149,7 +153,7 @@ public void addBlock(int x, int y, int z, Block block, int meta) { IMaterial mat = OreManager.getMaterial(block, meta); - short[] rgba = mat == null ? new short[] {125, 125, 125, 255} : mat.getRGBA(); + short[] rgba = mat == null ? new short[] { 125, 125, 125, 255 } : mat.getRGBA(); nameLookup.put(stackName, objectId); objects.put(objectId, ObjectIntPair.of(stackName, rgba(rgba))); diff --git a/src/main/java/galacticgreg/SpaceDimRegisterer.java b/src/main/java/galacticgreg/SpaceDimRegisterer.java index ceb9690ff8e..b21c1315445 100644 --- a/src/main/java/galacticgreg/SpaceDimRegisterer.java +++ b/src/main/java/galacticgreg/SpaceDimRegisterer.java @@ -40,7 +40,8 @@ private static ModContainer setupVanilla() { // 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)); + DimensionDef.EndAsteroids.modDimensionDef + .addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.lava, Enums.AllowedBlockPosition.AsteroidCore)); ModContainers.Vanilla.modContainer.addDimensionDef(DimensionDef.EndAsteroids.modDimensionDef); @@ -119,7 +120,7 @@ private static ModContainer setupGalaxySpace() { DimensionDef.KuiperBelt.modDimensionDef.setDimensionType(Enums.DimensionType.Asteroid); DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(StoneType.RedGranite); DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); - + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.KuiperBelt.modDimensionDef); return ModContainers.GalaxySpace.modContainer; diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 13b0c218875..5e29cb409b7 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -6,11 +6,13 @@ import java.util.List; import java.util.Random; -import org.joml.Vector2i; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Multimap; -import com.google.common.collect.MultimapBuilder; +import net.minecraft.inventory.IInventory; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.ChestGenHooks; +import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.registry.GameRegistry; @@ -25,25 +27,13 @@ import galacticgreg.dynconfig.DynamicDimensionConfig; import galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; import gregtech.GTMod; -import gregtech.api.enums.GTValues; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneType; import gregtech.api.objects.XSTR; -import gregtech.api.util.GTUtility; -import gregtech.common.WorldgenGTOreLayer; -import gregtech.common.config.Worldgen; import gregtech.common.ores.OreManager; import gregtech.common.worldgen.IWorldgenLayer; import gregtech.common.worldgen.WorldgenQuery; -import net.minecraft.init.Blocks; -import net.minecraft.inventory.IInventory; -import net.minecraft.util.WeightedRandomChestContent; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraftforge.common.ChestGenHooks; -import net.minecraftforge.common.util.ForgeDirection; public class WorldGeneratorSpace implements IWorldGenerator { @@ -57,12 +47,12 @@ public WorldGeneratorSpace() { public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { - GalacticGreg.Logger - .trace("Triggered generate: [Dimension %s]", world.provider.getDimensionName()); + GalacticGreg.Logger.trace("Triggered generate: [Dimension %s]", world.provider.getDimensionName()); ModDimensionDef tDimDef = DimensionDef.getDefForWorld(world); - if (tDimDef.getDimensionName().equals(DimNames.THE_END)) { + if (tDimDef.getDimensionName() + .equals(DimNames.THE_END)) { if (chunkX * chunkX + chunkZ * chunkZ > END_ASTEROID_DISTANCE * END_ASTEROID_DISTANCE) { tDimDef = DimensionDef.EndAsteroids.modDimensionDef; } @@ -98,7 +88,8 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP long post = System.nanoTime(); - if (profileWorldGen) GTMod.GT_FML_LOGGER.info("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3); + if (profileWorldGen) + GTMod.GT_FML_LOGGER.info("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3); Chunk tChunk = world.getChunkFromBlockCoords(chunkX, chunkZ); if (tChunk != null) { @@ -108,6 +99,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP } public static class AsteroidGenerator { + public List positive, negative; public int seedChunkX, seedChunkZ, cX, cY, cZ, radius; public long seed; @@ -118,10 +110,15 @@ public static class AsteroidGenerator { public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedChunkZ) { ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world); AsteroidConfig asteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); - + if (!asteroidConfig.Enabled) return null; - if (!generatesAsteroid(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId, asteroidConfig.Probability)) 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); @@ -134,7 +131,9 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh if (rng.nextInt(5) == 0) { oreLayer = WorldgenQuery.small() .inDimension(dimensionDef) - .inStone(asteroidStone.getStone().getCategory()) + .inStone( + asteroidStone.getStone() + .getCategory()) .find(rng.clone()); minY = oreLayer == null ? 50 : oreLayer.getMinY(); @@ -142,19 +141,21 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh } else { oreLayer = WorldgenQuery.veins() .inDimension(dimensionDef) - .inStone(asteroidStone.getStone().getCategory()) + .inStone( + asteroidStone.getStone() + .getCategory()) .find(rng.clone()); - + minY = oreLayer == null ? 50 : oreLayer.getMinY(); maxY = oreLayer == null ? 200 : oreLayer.getMaxY(); } if (oreLayer == null) return null; - + GalacticGreg.Logger.debug( "Asteroid will be built with: Stone: [%s] Ore: [%s]", - asteroidStone.getStone(), - oreLayer.getName()); + asteroidStone.getStone(), + oreLayer.getName()); int tX = seedChunkX * 16 + rng.nextInt(16); int tY = minY + rng.nextInt(maxY - minY); @@ -168,27 +169,29 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh 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))); + 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))); } k = rng.nextInt(2); 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))); + 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))); } AsteroidGenerator gen = new AsteroidGenerator(); gen.positive = positive; gen.negative = negative; - + gen.seedChunkX = seedChunkX; gen.seedChunkZ = seedChunkZ; @@ -227,7 +230,7 @@ public void generateChunk(World world, int chunkX, int chunkZ) { ModDimensionDef def = DimensionDef.getDefForWorld(world); AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(def); - + for (int y = minY; y < maxY; y++) { for (int z = minZ; z < maxZ; z++) { outer: for (int x = minX; x < maxX; x++) { @@ -268,7 +271,9 @@ public void generateChunk(World world, int chunkX, int chunkZ) { placedAnything = generateOreBlock( rng2, world, - x, y, z, + x, + y, + z, stoneType, ore, false, @@ -286,7 +291,9 @@ public void generateChunk(World world, int chunkX, int chunkZ) { x, y, z, - dist < 1f / 3f ? TargetBlockPosition.AsteroidInnerCore : dist < 2f / 3f ? TargetBlockPosition.AsteroidCore : TargetBlockPosition.AsteroidShell); + dist < 1f / 3f ? TargetBlockPosition.AsteroidInnerCore + : dist < 2f / 3f ? TargetBlockPosition.AsteroidCore + : TargetBlockPosition.AsteroidShell); } // try to place small ores @@ -294,9 +301,9 @@ public void generateChunk(World world, int chunkX, int chunkZ) { placedAnything = generateOreBlock( rng2, world, - x, - y, - z, + x, + y, + z, stoneType, ore, true, @@ -309,8 +316,10 @@ public void generateChunk(World world, int chunkX, int chunkZ) { x, y, z, - stoneType.getStone().left(), - stoneType.getStone().rightInt(), + stoneType.getStone() + .left(), + stoneType.getStone() + .rightInt(), 2); } } @@ -363,8 +372,7 @@ private void generateLootChest(World world, AsteroidConfig asteroidConfig) { tNumLootItems = asteroidConfig.NumLootItems; } - GalacticGreg.Logger - .debug(String.format("Loot chest random item count will be: %d", tNumLootItems)); + GalacticGreg.Logger.debug(String.format("Loot chest random item count will be: %d", tNumLootItems)); // Get items for the configured loot-table WeightedRandomChestContent[] tRandomLoot = ChestGenHooks @@ -374,13 +382,7 @@ private void generateLootChest(World world, AsteroidConfig asteroidConfig) { BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; // Place down the chest - world.setBlock( - cX, - cY, - cZ, - tTargetChestType.getBlock(), - tTargetChestType.getMeta(), - 2); + world.setBlock(cX, cY, cZ, tTargetChestType.getBlock(), tTargetChestType.getMeta(), 2); // Retrieve the TEs IInventory that should've been created IInventory entityChestInventory = (IInventory) world.getTileEntity(cX, cY, cZ); @@ -390,25 +392,18 @@ private void generateLootChest(World world, AsteroidConfig asteroidConfig) { // and if we're on the server... if (!world.isRemote) { // Fill the chest with stuffz! - WeightedRandomChestContent.generateChestContents( - rng, - tRandomLoot, - entityChestInventory, - tNumLootItems); + 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); + 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.debug("Generated LootChest at X[%d] Y[%d] Z[%d]", cX, cY, cZ); } } @@ -423,143 +418,6 @@ public static boolean generatesAsteroid(long worldSeed, int chunkX, int chunkZ, return getRandom(worldSeed, chunkX, chunkZ, dimId).nextInt(100) <= asteroidChance; } - // private void generateAsteroids(World world, int chunkX, int chunkZ, long seed) { - // ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world); - - // GalacticGreg.Logger.trace("Running asteroid-gen in Dim %s", dimensionDef.getDimIdentifier()); - - // DynamicDimensionConfig.AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); - - // if (dimAsteroidConfig == null) { - // GalacticGreg.Logger.error( - // "Dimension %s is set to asteroid, but no config object can be found. Skipping!", - // dimensionDef.getDimIdentifier()); - // return; - // } else { - // GalacticGreg.Logger.trace("Asteroid probability: %d", dimAsteroidConfig.Probability); - // } - - // XSTR random = new XSTR(seed); - - // if (dimAsteroidConfig.Probability <= 1 || random.nextInt(dimAsteroidConfig.Probability) == 0) { - // GalacticGreg.Logger.trace("Generating asteroid NOW"); - - // long startTime = 0; - - // if (GalacticGreg.GalacticConfig.ProfileOreGen || profileWorldGen) { - // startTime = System.currentTimeMillis(); - // } - - // AsteroidGenerator generators = AsteroidGenerator.generate(world, chunkX, chunkZ, dimensionDef, random.nextLong()); - - // if (generators == null) { - // GalacticGreg.Logger.trace("Not generating asteroid"); - // return; - // } - - // world.getChunkProvider().loadChunk(0, 0); - - // // Check if position is free - // if (world.isAirBlock(tX, tY, tZ)) { - // boolean tDoLootChest = dimAsteroidConfig.LootChestChance > 0 && asteroidSize > 6; - - // if (tDoLootChest) { - // GalacticGreg.Logger.trace("Random loot chest enabled, flipping the coin"); - // // Loot chest is 1 in 100 (Was: 1:1000 which actually never happened) - // int tChance = pRandom.nextInt(100); - - // if (dimAsteroidConfig.LootChestChance >= tChance) { - // GalacticGreg.Logger.debug("We got a match. Preparing to generate the loot chest"); - - // for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) { - // if (world.isAirBlock(tX + d.offsetX, tY + d.offsetY, tZ + d.offsetZ)) { - // tDoLootChest = false; - // break; - // } - // } - // } else { - // tDoLootChest = false; - // } - // } - - // if (tDoLootChest) { - // 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 (dimAsteroidConfig.RandomizeNumLootItems) { - // tNumLootItems = pRandom.nextInt(dimAsteroidConfig.NumLootItems - 1) + 1; - // } else { - // tNumLootItems = dimAsteroidConfig.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(dimAsteroidConfig), pRandom); - - // // Get chest-block to spawn - // BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; - - // // Place down the chest - // world.setBlock( - // tX, - // tY, - // tZ, - // tTargetChestType.getBlock(), - // tTargetChestType.getMeta(), - // 2); - - // // Retrieve the TEs IInventory that should've been created - // IInventory entityChestInventory = (IInventory) world.getTileEntity(tX, tY, tZ); - - // // 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( - // 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", - // tX, - // tY, - // tZ); - // } - - // // Do some debug logging - // GalacticGreg.Logger - // .debug("Generated LootChest at X[%d] Y[%d] Z[%d]", tX, tY, tZ); - // } - // } - - // // --------------------------- - // // OreGen profiler stuff - // if (GalacticGreg.GalacticConfig.ProfileOreGen || profileWorldGen) { - // try { - // long endTime = System.currentTimeMillis(); - // long tTotalTime = endTime - startTime; - // GalacticGreg.Profiler.AddTimeToList(dimensionDef, tTotalTime); - // GalacticGreg.Logger.info( - // "Done with Asteroid-Worldgen in DimensionType %s. Generation took %d ms", - // dimensionDef.getDimensionName(), - // tTotalTime); - // } catch (Exception ignored) {} // Silently ignore errors - // } - // // --------------------------- - // } - // GalacticGreg.Logger.trace("Leaving asteroid-gen for Dim %s", dimensionDef.getDimIdentifier()); - // } - /** * Generate Special Blocks in asteroids if enabled * @@ -572,7 +430,8 @@ public static boolean generatesAsteroid(long worldSeed, int chunkX, int chunkZ, * @param z * @return */ - private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Random rng, World world, AsteroidConfig asteroidConfig, int x, int y, int z, TargetBlockPosition blockPosition) { + 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 (asteroidConfig.SpecialBlockChance > 0) { if (rng.nextInt(100) < asteroidConfig.SpecialBlockChance) { @@ -581,7 +440,8 @@ private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Rando 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 AsteroidCoreAndShell -> blockPosition == Enums.TargetBlockPosition.AsteroidCore + || blockPosition == Enums.TargetBlockPosition.AsteroidShell; case AsteroidShell -> blockPosition == Enums.TargetBlockPosition.AsteroidShell; case AsteroidInnerCore -> blockPosition == Enums.TargetBlockPosition.AsteroidInnerCore; }; @@ -597,7 +457,8 @@ private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Rando return false; } - private static boolean generateOreBlock(Random rng, World pWorld, int pX, int pY, int pZ, IStoneType stoneType, IWorldgenLayer oreLayer, boolean small, float control) { + private static boolean generateOreBlock(Random rng, World pWorld, int pX, int pY, int pZ, IStoneType stoneType, + IWorldgenLayer oreLayer, boolean small, float control) { if (rng.nextFloat() <= oreLayer.getDensity()) { IMaterial mat = oreLayer.getOre(control); @@ -610,6 +471,7 @@ private static boolean generateOreBlock(Random rng, World pWorld, int pX, int pY } private static class Ellipsoid { + public float x, y, z, r; public Ellipsoid(float x, float y, float z, float size) { diff --git a/src/main/java/galacticgreg/api/AsteroidBlockComb.java b/src/main/java/galacticgreg/api/AsteroidBlockComb.java index 28a98ee2699..34040a00681 100644 --- a/src/main/java/galacticgreg/api/AsteroidBlockComb.java +++ b/src/main/java/galacticgreg/api/AsteroidBlockComb.java @@ -1,8 +1,9 @@ package galacticgreg.api; -import gregtech.api.enums.StoneType; import net.minecraft.block.Block; +import gregtech.api.enums.StoneType; + /** * Class for a bit more advanced combinations for Asteroids, which supports Custom Blocks as base material and Values * required to generate Gregtech ores @@ -42,7 +43,11 @@ public AsteroidBlockComb(StoneType stoneType, Block pBlock, int pMeta) { * @param pOreType The GregTech oreType */ public AsteroidBlockComb(StoneType stoneType) { - super(stoneType.getStone().left(), stoneType.getStone().rightInt()); + super( + stoneType.getStone() + .left(), + stoneType.getStone() + .rightInt()); this.stoneType = stoneType; } diff --git a/src/main/java/galacticgreg/api/ModDimensionDef.java b/src/main/java/galacticgreg/api/ModDimensionDef.java index 48854a6f8eb..5ad376e304a 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -4,11 +4,12 @@ import java.util.List; import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.world.chunk.IChunkProvider; + import galacticgreg.api.Enums.DimensionType; import gregtech.api.enums.StoneType; import gregtech.common.config.Gregtech; -import net.minecraft.block.Block; -import net.minecraft.world.chunk.IChunkProvider; // import galacticgreg.GalacticGreg; @@ -46,11 +47,7 @@ public class ModDimensionDef { */ public ModDimensionDef(String pDimensionName, Class pChunkProvider, DimensionType pDimType) { - this( - pDimensionName, - pChunkProvider.getName(), - pDimType, - null); + this(pDimensionName, pChunkProvider.getName(), pDimType, null); } /** @@ -62,11 +59,7 @@ public ModDimensionDef(String pDimensionName, Class pC */ public ModDimensionDef(String pDimensionName, Class pChunkProvider, DimensionType pDimType, List pBlockDefinitions) { - this( - pDimensionName, - pChunkProvider.getName(), - pDimType, - pBlockDefinitions); + this(pDimensionName, pChunkProvider.getName(), pDimType, pBlockDefinitions); } /** @@ -104,6 +97,7 @@ public ModDimensionDef(String pDimensionName, String pChunkProviderName, Dimensi /** * Sets the chance that an ore seed chunk will have a vein + * * @param chance The chance out of 100. */ public ModDimensionDef setOreVeinChance(int chance) { diff --git a/src/main/java/galacticgreg/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index a0edc752db9..767d08a7dcd 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -1,16 +1,16 @@ 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 java.util.HashMap; -import java.util.Map; - import galacticgreg.api.Enums; -import galacticgreg.api.ModDimensionDef; import galacticgreg.api.Enums.DimensionType; +import galacticgreg.api.ModDimensionDef; import gtPlusPlus.everglades.chunk.ChunkProviderModded; public enum DimensionDef { @@ -247,7 +247,7 @@ public static class DimNames { public static final String ENDASTEROIDS = "EndAsteroids"; 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"; diff --git a/src/main/java/galacticgreg/command/WorldgenCommand.java b/src/main/java/galacticgreg/command/WorldgenCommand.java index e68a4371ae0..5b61fc9f3a7 100644 --- a/src/main/java/galacticgreg/command/WorldgenCommand.java +++ b/src/main/java/galacticgreg/command/WorldgenCommand.java @@ -2,14 +2,15 @@ import java.util.List; -import com.google.common.collect.ImmutableList; - 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; @@ -49,7 +50,12 @@ public void processCommand(ICommandSender pCommandSender, String[] pArgs) { switch (pArgs[0]) { case "spawns" -> { - boolean spawns = WorldGeneratorSpace.generatesAsteroid(world.getSeed(), chunkX, chunkZ, world.provider.dimensionId, asteroidConfig.Probability); + boolean spawns = WorldGeneratorSpace.generatesAsteroid( + world.getSeed(), + chunkX, + chunkZ, + world.provider.dimensionId, + asteroidConfig.Probability); pCommandSender.addChatMessage(new ChatComponentText("spawns: " + spawns)); } @@ -62,7 +68,9 @@ public void processCommand(ICommandSender pCommandSender, String[] pArgs) { continue; } - pCommandSender.addChatMessage(new ChatComponentText("found asteroid seed at " + (chunkX + offsetX) + ", " + (chunkZ + offsetZ))); + pCommandSender.addChatMessage( + new ChatComponentText( + "found asteroid seed at " + (chunkX + offsetX) + ", " + (chunkZ + offsetZ))); gen.generateChunk(world, chunkX, chunkZ); } diff --git a/src/main/java/galacticgreg/registry/GalacticGregRegistry.java b/src/main/java/galacticgreg/registry/GalacticGregRegistry.java index 4b1d18df82f..ee12baeb170 100644 --- a/src/main/java/galacticgreg/registry/GalacticGregRegistry.java +++ b/src/main/java/galacticgreg/registry/GalacticGregRegistry.java @@ -117,9 +117,11 @@ private static void InitModContainers() { "ModID: [%s] DimName: [%s] ValidBlocks: [%d] Identifier: [%s] Generators: [%d]", mc.getModName(), md.getDimensionName(), - md.getReplaceableBlocks().size(), + md.getReplaceableBlocks() + .size(), md.getDimIdentifier(), - md.getSpaceObjectGenerators().size()); + md.getSpaceObjectGenerators() + .size()); // Register default generator if dimension is asteroid and no generator was added if (md.getDimensionType() == DimensionType.Asteroid) { diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index 71d6553e5ad..2835de566f9 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -18,14 +18,14 @@ import javax.annotation.Nonnull; -import com.google.common.collect.ImmutableList; - import net.minecraft.enchantment.Enchantment; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import com.google.common.collect.ImmutableList; + import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.TCAspects.TC_AspectStack; diff --git a/src/main/java/gregtech/api/enums/OreMixes.java b/src/main/java/gregtech/api/enums/OreMixes.java index db98637a543..0acebd6fda5 100644 --- a/src/main/java/gregtech/api/enums/OreMixes.java +++ b/src/main/java/gregtech/api/enums/OreMixes.java @@ -1,18 +1,17 @@ package gregtech.api.enums; import static galacticgreg.api.enums.DimensionDef.*; +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.NETHER; -import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; -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.TWILIGHT_FOREST; import bartworks.system.material.WerkstoffLoader; - import galacticgreg.api.enums.DimensionDef; import gregtech.common.OreMixBuilder; import gregtech.common.WorldgenGTOreLayer; @@ -1010,7 +1009,7 @@ public enum OreMixes { .secondary(Materials.TengamRaw) .inBetween(Materials.Electrotine) .sporadic(Materials.Samarium)), - + NitrogenIce(new OreMixBuilder().name("ore.mix.nitrogenice") .heightRange(30, 180) .weight(80) @@ -1022,7 +1021,7 @@ public enum OreMixes { .inBetween(Materials.Hydrogen) .sporadic(Materials.Hydrogen) .stoneCategory(StoneCategory.Ice)), - + HydrocarbonIce(new OreMixBuilder().name("ore.mix.hydrocarbonice") .heightRange(30, 180) .weight(40) @@ -1034,7 +1033,7 @@ public enum OreMixes { .inBetween(Materials.Carbon) .sporadic(Materials.Carbon) .stoneCategory(StoneCategory.Ice)), - + CarbonIce(new OreMixBuilder().name("ore.mix.carbonice") .heightRange(30, 180) .weight(40) @@ -1046,7 +1045,7 @@ public enum OreMixes { .inBetween(Materials.Carbon) .sporadic(Materials.Carbon) .stoneCategory(StoneCategory.Ice)), - + HHOIce(new OreMixBuilder().name("ore.mix.hhoice") .heightRange(30, 180) .weight(80) @@ -1058,7 +1057,7 @@ public enum OreMixes { .inBetween(Materials.Oxygen) .sporadic(Materials.Hydrogen) .stoneCategory(StoneCategory.Ice)), - + SulfurIce(new OreMixBuilder().name("ore.mix.sulfurice") .heightRange(30, 180) .weight(20) @@ -1070,7 +1069,7 @@ public enum OreMixes { .inBetween(Materials.Sulfur) .sporadic(Materials.Oxygen) .stoneCategory(StoneCategory.Ice)), - + GTPP0(new OreMixBuilder().name("ore.mix.gtpp0") .heightRange(20, 40) .weight(1) @@ -1081,7 +1080,7 @@ public enum OreMixes { .secondary(Materials.Iron) .inBetween(Materials.Iron) .sporadic(Materials.Iron)), - + GTPP1(new OreMixBuilder().name("ore.mix.gtpp1") .heightRange(0, 60) .weight(30) @@ -1092,7 +1091,7 @@ public enum OreMixes { .secondary(MaterialsOres.AGARDITE_LA) .inBetween(MaterialsOres.DEMICHELEITE_BR) .sporadic(MaterialsOres.IRARSITE)), - + GTPP2(new OreMixBuilder().name("ore.mix.gtpp2") .heightRange(0, 60) .weight(30) @@ -1103,7 +1102,7 @@ public enum OreMixes { .secondary(MaterialsOres.AGARDITE_Y) .inBetween(MaterialsOres.KASHINITE) .sporadic(MaterialsOres.CERITE)), - + GTPP3(new OreMixBuilder().name("ore.mix.gtpp3") .heightRange(0, 60) .weight(30) @@ -1114,7 +1113,7 @@ public enum OreMixes { .secondary(MaterialsOres.NICHROMITE) .inBetween(MaterialsOres.XENOTIME) .sporadic(MaterialsOres.HIBONITE)), - + GTPP4(new OreMixBuilder().name("ore.mix.gtpp4") .heightRange(0, 60) .weight(40) @@ -1125,7 +1124,7 @@ public enum OreMixes { .secondary(MaterialsOres.CRYOLITE) .inBetween(MaterialsOres.GADOLINITE_CE) .sporadic(MaterialsOres.AGARDITE_ND)), - + GTPP5(new OreMixBuilder().name("ore.mix.gtpp5") .heightRange(30, 128) .weight(20) @@ -1136,7 +1135,7 @@ public enum OreMixes { .secondary(MaterialsOres.YTTRIALITE) .inBetween(MaterialsOres.ZIRCONILITE) .sporadic(MaterialsOres.CERITE)), - + GTPP6(new OreMixBuilder().name("ore.mix.gtpp6") .heightRange(0, 40) .weight(20) @@ -1147,7 +1146,7 @@ public enum OreMixes { .secondary(MaterialsOres.ZIRKELITE) .inBetween(MaterialsOres.CROCROITE) .sporadic(MaterialsOres.IRARSITE)), - + GTPP7(new OreMixBuilder().name("ore.mix.gtpp7") .heightRange(40, 128) .weight(20) @@ -1158,7 +1157,7 @@ public enum OreMixes { .secondary(MaterialsOres.MIESSIITE) .inBetween(MaterialsOres.SAMARSKITE_Y) .sporadic(MaterialsOres.SAMARSKITE_YB)), - + GTPP8(new OreMixBuilder().name("ore.mix.gtpp8") .heightRange(0, 40) .weight(20) @@ -1169,7 +1168,7 @@ public enum OreMixes { .secondary(MaterialsOres.ZIMBABWEITE) .inBetween(MaterialsOres.ZIRCON) .sporadic(MaterialsOres.FLORENCITE)), - + GTPP9(new OreMixBuilder().name("ore.mix.gtpp9") .heightRange(10, 30) .weight(20) @@ -1180,7 +1179,7 @@ public enum OreMixes { .secondary(MaterialsFluorides.FLUORITE) .inBetween(MaterialsOres.LAFOSSAITE) .sporadic(MaterialsOres.FLORENCITE)), - + GTPP10(new OreMixBuilder().name("ore.mix.gtpp10") .heightRange(20, 50) .weight(20) @@ -1191,7 +1190,7 @@ public enum OreMixes { .secondary(MaterialsOres.YTTROCERITE) .inBetween(MaterialsOres.LANTHANITE_LA) .sporadic(MaterialsOres.RADIOBARITE)), - + GTPP11(new OreMixBuilder().name("ore.mix.gtpp11") .heightRange(30, 70) .weight(20) @@ -1202,7 +1201,7 @@ public enum OreMixes { .secondary(MaterialsOres.KASHINITE) .inBetween(MaterialsOres.ZIRCON) .sporadic(MaterialsOres.CRYOLITE)), - + GTPP12(new OreMixBuilder().name("ore.mix.gtpp12") .heightRange(40, 80) .weight(20) @@ -1213,7 +1212,7 @@ public enum OreMixes { .secondary(MaterialsOres.ALBURNITE) .inBetween(MaterialsOres.MIESSIITE) .sporadic(MaterialsOres.HIBONITE)), - + GTPP13(new OreMixBuilder().name("ore.mix.gtpp13") .heightRange(5, 15) .weight(5) @@ -1224,7 +1223,7 @@ public enum OreMixes { .secondary(MaterialsOres.RADIOBARITE) .inBetween(MaterialsOres.HONEAITE) .sporadic(MaterialsOres.FLORENCITE)), - + GTPP14(new OreMixBuilder().name("ore.mix.gtpp14") .heightRange(10, 20) .weight(8) @@ -1235,7 +1234,7 @@ public enum OreMixes { .secondary(MaterialsOres.PERROUDITE) .inBetween(MaterialsOres.IRARSITE) .sporadic(MaterialsOres.RADIOBARITE)), - + GTPP15(new OreMixBuilder().name("ore.mix.gtpp15") .heightRange(5, 25) .weight(5) @@ -1246,7 +1245,7 @@ public enum OreMixes { .secondary(MaterialsOres.LAFOSSAITE) .inBetween(MaterialsOres.GADOLINITE_CE) .sporadic(MaterialsOres.GADOLINITE_Y)), - + GTPP16(new OreMixBuilder().name("ore.mix.gtpp16") .heightRange(0, 25) .weight(4) @@ -1257,7 +1256,7 @@ public enum OreMixes { .secondary(MaterialsOres.LEPERSONNITE) .inBetween(MaterialsOres.LAUTARITE) .sporadic(MaterialsFluorides.FLUORITE)), - + GTPP17(new OreMixBuilder().name("ore.mix.gtpp17") .heightRange(10, 35) .weight(4) @@ -1268,7 +1267,7 @@ public enum OreMixes { .secondary(MaterialsOres.LAUTARITE) .inBetween(MaterialsOres.SAMARSKITE_YB) .sporadic(MaterialsOres.POLYCRASE)), - + GTPP18(new OreMixBuilder().name("ore.mix.gtpp18") .heightRange(15, 40) .weight(4) @@ -1279,7 +1278,7 @@ public enum OreMixes { .secondary(MaterialsOres.GADOLINITE_Y) .inBetween(MaterialsOres.AGARDITE_LA) .sporadic(MaterialsOres.AGARDITE_CD)), - + GTPP19(new OreMixBuilder().name("ore.mix.gtpp19") .heightRange(0, 20) .weight(4) @@ -1291,8 +1290,7 @@ public enum OreMixes { .inBetween(MaterialsElements.STANDALONE.RUNITE) .sporadic(MaterialsElements.STANDALONE.RUNITE)), - Thorianit(new OreMixBuilder() - .name("ore.mix.ross128.Thorianit") + Thorianit(new OreMixBuilder().name("ore.mix.ross128.Thorianit") .heightRange(30, 60) .weight(17) .density(1) @@ -1302,9 +1300,8 @@ public enum OreMixes { .secondary(Materials.Uraninite) .inBetween(Materials.Lepidolite) .sporadic(Materials.Spodumene)), - - RossCarbon(new OreMixBuilder() - .name("ore.mix.ross128.carbon") + + RossCarbon(new OreMixBuilder().name("ore.mix.ross128.carbon") .heightRange(5, 25) .weight(5) .density(4) @@ -1314,9 +1311,8 @@ public enum OreMixes { .secondary(Materials.Diamond) .inBetween(Materials.Coal) .sporadic(Materials.Graphite)), - - Bismuth(new OreMixBuilder() - .name("ore.mix.ross128.bismuth") + + Bismuth(new OreMixBuilder().name("ore.mix.ross128.bismuth") .heightRange(5, 80) .weight(30) .density(1) @@ -1326,9 +1322,8 @@ public enum OreMixes { .secondary(Materials.Stibnite) .inBetween(Materials.Bismuth) .sporadic(WerkstoffLoader.Bismutite)), - - TurmalinAlkali(new OreMixBuilder() - .name("ore.mix.ross128.TurmalinAlkali") + + TurmalinAlkali(new OreMixBuilder().name("ore.mix.ross128.TurmalinAlkali") .heightRange(5, 80) .weight(15) .density(4) @@ -1338,9 +1333,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.FluorBuergerit) .inBetween(WerkstoffLoader.ChromoAluminoPovondrait) .sporadic(WerkstoffLoader.VanadioOxyDravit)), - - Roquesit(new OreMixBuilder() - .name("ore.mix.ross128.Roquesit") + + Roquesit(new OreMixBuilder().name("ore.mix.ross128.Roquesit") .heightRange(30, 50) .weight(3) .density(1) @@ -1350,9 +1344,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.Ferberite) .inBetween(WerkstoffLoader.Loellingit) .sporadic(WerkstoffLoader.Roquesit)), - - RossTungstate(new OreMixBuilder() - .name("ore.mix.ross128.Tungstate") + + RossTungstate(new OreMixBuilder().name("ore.mix.ross128.Tungstate") .heightRange(5, 40) .weight(10) .density(4) @@ -1362,9 +1355,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.Huebnerit) .inBetween(WerkstoffLoader.Loellingit) .sporadic(Materials.Scheelite)), - - CopperSulfits(new OreMixBuilder() - .name("ore.mix.ross128.CopperSulfits") + + CopperSulfits(new OreMixBuilder().name("ore.mix.ross128.CopperSulfits") .heightRange(40, 70) .weight(80) .density(3) @@ -1374,9 +1366,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.Bornite) .inBetween(WerkstoffLoader.Wittichenit) .sporadic(Materials.Tetrahedrite)), - - Forsterit(new OreMixBuilder() - .name("ore.mix.ross128.Forsterit") + + Forsterit(new OreMixBuilder().name("ore.mix.ross128.Forsterit") .heightRange(20, 90) .weight(50) .density(2) @@ -1386,9 +1377,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.Fayalit) .inBetween(WerkstoffLoader.DescloiziteCUVO4) .sporadic(WerkstoffLoader.DescloiziteZNVO4)), - - Hedenbergit(new OreMixBuilder() - .name("ore.mix.ross128.Hedenbergit") + + Hedenbergit(new OreMixBuilder().name("ore.mix.ross128.Hedenbergit") .heightRange(20, 90) .weight(50) .density(2) @@ -1398,9 +1388,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.Fayalit) .inBetween(WerkstoffLoader.DescloiziteCUVO4) .sporadic(WerkstoffLoader.DescloiziteZNVO4)), - - RedZircon(new OreMixBuilder() - .name("ore.mix.ross128.RedZircon") + + RedZircon(new OreMixBuilder().name("ore.mix.ross128.RedZircon") .heightRange(10, 80) .weight(40) .density(3) @@ -1410,9 +1399,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.FuchsitAL) .inBetween(WerkstoffLoader.RedZircon) .sporadic(WerkstoffLoader.FuchsitCR)), - - Tiberium(new OreMixBuilder() - .name("ore.mix.ross128ba.tib") + + Tiberium(new OreMixBuilder().name("ore.mix.ross128ba.tib") .heightRange(30, 60) .weight(6) .density(1) @@ -1422,9 +1410,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.Tiberium) .inBetween(Materials.NaquadahEnriched) .sporadic(Materials.NaquadahEnriched)), - - Ross128baTungstate(new OreMixBuilder() - .name("ore.mix.ross128ba.Tungstate") + + Ross128baTungstate(new OreMixBuilder().name("ore.mix.ross128ba.Tungstate") .heightRange(5, 40) .weight(60) .density(4) @@ -1434,9 +1421,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.Huebnerit) .inBetween(WerkstoffLoader.Loellingit) .sporadic(Materials.Scheelite)), - - Bart(new OreMixBuilder() - .name("ore.mix.ross128ba.bart") + + Bart(new OreMixBuilder().name("ore.mix.ross128ba.bart") .heightRange(30, 60) .weight(1) .density(1) @@ -1446,9 +1432,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.BArTiMaEuSNeK) .inBetween(WerkstoffLoader.BArTiMaEuSNeK) .sporadic(WerkstoffLoader.BArTiMaEuSNeK)), - - Ross128baTurmalinAlkali(new OreMixBuilder() - .name("ore.mix.ross128ba.TurmalinAlkali") + + Ross128baTurmalinAlkali(new OreMixBuilder().name("ore.mix.ross128ba.TurmalinAlkali") .heightRange(5, 80) .weight(60) .density(4) @@ -1458,9 +1443,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.FluorBuergerit) .inBetween(WerkstoffLoader.ChromoAluminoPovondrait) .sporadic(WerkstoffLoader.VanadioOxyDravit)), - - Ross128baAmethyst(new OreMixBuilder() - .name("ore.mix.ross128ba.Amethyst") + + Ross128baAmethyst(new OreMixBuilder().name("ore.mix.ross128ba.Amethyst") .heightRange(5, 80) .weight(35) .density(2) @@ -1470,9 +1454,8 @@ public enum OreMixes { .secondary(Materials.Olivine) .inBetween(WerkstoffLoader.Prasiolite) .sporadic(WerkstoffLoader.Hedenbergit)), - - Ross128baCopperSulfits(new OreMixBuilder() - .name("ore.mix.ross128ba.CopperSulfits") + + Ross128baCopperSulfits(new OreMixBuilder().name("ore.mix.ross128ba.CopperSulfits") .heightRange(40, 70) .weight(80) .density(3) @@ -1482,9 +1465,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.Bornite) .inBetween(WerkstoffLoader.Wittichenit) .sporadic(Materials.Tetrahedrite)), - - Ross128baRedZircon(new OreMixBuilder() - .name("ore.mix.ross128ba.RedZircon") + + Ross128baRedZircon(new OreMixBuilder().name("ore.mix.ross128ba.RedZircon") .heightRange(10, 80) .weight(40) .density(3) @@ -1494,9 +1476,8 @@ public enum OreMixes { .secondary(WerkstoffLoader.FuchsitAL) .inBetween(WerkstoffLoader.RedZircon) .sporadic(WerkstoffLoader.FuchsitCR)), - - Fluorspar(new OreMixBuilder() - .name("ore.mix.ross128ba.Fluorspar") + + Fluorspar(new OreMixBuilder().name("ore.mix.ross128ba.Fluorspar") .heightRange(10, 80) .weight(35) .density(4) @@ -1505,8 +1486,7 @@ public enum OreMixes { .primary(Materials.Galena) .secondary(Materials.Sphalerite) .inBetween(WerkstoffLoader.Fluorspar) - .sporadic(Materials.Barite)), - ; + .sporadic(Materials.Barite)); // spotless : on diff --git a/src/main/java/gregtech/api/enums/SmallOres.java b/src/main/java/gregtech/api/enums/SmallOres.java index 24bf608e45e..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,10 +34,6 @@ import static galacticgreg.api.enums.DimensionDef.Triton; import static galacticgreg.api.enums.DimensionDef.VegaB; import static galacticgreg.api.enums.DimensionDef.Venus; -import static galacticgreg.api.enums.DimensionDef.DimNames.OW; -import static galacticgreg.api.enums.DimensionDef.DimNames.NETHER; -import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; -import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; import gregtech.common.SmallOreBuilder; import gregtech.common.WorldgenGTOreSmallPieces; @@ -529,8 +529,7 @@ public enum SmallOres { .heightRange(5, 115) .amount(4) .ore(Materials.CertusQuartzCharged) - .enableInDim(Horus)), - ; + .enableInDim(Horus)); // spotless : on public final SmallOreBuilder smallOreBuilder; diff --git a/src/main/java/gregtech/api/enums/StoneType.java b/src/main/java/gregtech/api/enums/StoneType.java index a43a30d6040..16fcfecd881 100644 --- a/src/main/java/gregtech/api/enums/StoneType.java +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -11,6 +11,15 @@ import java.util.List; import java.util.Objects; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +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 cpw.mods.fml.common.registry.GameRegistry; @@ -25,14 +34,6 @@ import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; import it.unimi.dsi.fastutil.objects.ObjectIntPair; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; public enum StoneType implements IStoneType { @@ -124,11 +125,20 @@ public enum StoneType implements IStoneType { // spotless:on public static final ImmutableList STONE_TYPES = ImmutableList.copyOf(values()); - public static final ImmutableList VISUAL_STONE_TYPES = ImmutableList.copyOf(Arrays.stream(values()).filter(s -> s.builder.enabled && !s.isExtraneous()).toArray(StoneType[]::new)); + public static final ImmutableList VISUAL_STONE_TYPES = ImmutableList.copyOf( + Arrays.stream(values()) + .filter(s -> s.builder.enabled && !s.isExtraneous()) + .toArray(StoneType[]::new)); public static final ImmutableList STONE_ONLY = ImmutableList.of(StoneType.Stone); - public static final ImmutableList STONES = ImmutableList.copyOf(StoneType.STONE_TYPES.stream().filter(s -> s.getCategory() == StoneCategory.Stone).toArray(StoneType[]::new)); - public static final ImmutableList ICES = ImmutableList.copyOf(StoneType.STONE_TYPES.stream().filter(s -> s.getCategory() == StoneCategory.Ice).toArray(StoneType[]::new)); + public static final ImmutableList STONES = ImmutableList.copyOf( + StoneType.STONE_TYPES.stream() + .filter(s -> s.getCategory() == StoneCategory.Stone) + .toArray(StoneType[]::new)); + public static final ImmutableList ICES = ImmutableList.copyOf( + StoneType.STONE_TYPES.stream() + .filter(s -> s.getCategory() == StoneCategory.Ice) + .toArray(StoneType[]::new)); private final StoneBuilder builder; @@ -169,6 +179,7 @@ public ITexture getTexture(int side) { case Marble -> BlockIcons.MARBLE_STONE; case Basalt -> BlockIcons.BASALT_STONE; default -> new IIconContainer() { + @Override public IIcon getIcon() { return StoneType.this.getIcon(side); @@ -186,7 +197,10 @@ public ResourceLocation getTextureFile() { }; }; - return TextureFactory.builder().addIcon(container).stdOrient().build(); + return TextureFactory.builder() + .addIcon(container) + .stdOrient() + .build(); } @Override @@ -195,7 +209,7 @@ public IIcon getIcon(int side) { return Blocks.stone.getIcon(side, 0); } - return switch(this) { + 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); @@ -266,6 +280,7 @@ public static StoneType findStoneType(Block block, int meta) { } private static class BlockMeta { + public Block block; public int meta; @@ -276,6 +291,7 @@ public BlockMeta(Block block, int meta) { } private static class StoneBuilder { + public boolean enabled = true; public BlockMeta cobble, mainStone; public List otherStones; @@ -380,7 +396,9 @@ public StoneBuilder addOtherStone(Mods owner, String blockName, int meta) { public StoneBuilder setCoremodDust(String name) { if (NewHorizonsCoreMod.isModLoaded()) { Item dust = GameRegistry.findItem(NewHorizonsCoreMod.ID, "item." + name + "StoneDust"); - pureDust = impureDust = new ItemStack(Objects.requireNonNull(dust, "Could not find " + "item." + name + "StoneDust"), 1); + pureDust = impureDust = new ItemStack( + Objects.requireNonNull(dust, "Could not find " + "item." + name + "StoneDust"), + 1); } return this; diff --git a/src/main/java/gregtech/api/interfaces/IBlockOre.java b/src/main/java/gregtech/api/interfaces/IBlockOre.java deleted file mode 100644 index 3b0ed75cfab..00000000000 --- a/src/main/java/gregtech/api/interfaces/IBlockOre.java +++ /dev/null @@ -1,16 +0,0 @@ -package gregtech.api.interfaces; - -import java.util.List; - -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -public interface IBlockOre { - - /** Works like the vanilla getDrops, except it doesn't check to make sure a player is breaking the block. */ - public List getDropsForMachine(World world, int x, int y, int z, boolean silktouch, int fortune); - - public boolean isSmall(World world, int x, int y, int z); - public boolean isNatural(World world, int x, int y, int z); - public String getOreUnlocalizedName(World world, int x, int y, int z); -} diff --git a/src/main/java/gregtech/api/interfaces/IBlockWithTextures.java b/src/main/java/gregtech/api/interfaces/IBlockWithTextures.java index 4ac1ad04670..057dbf17158 100644 --- a/src/main/java/gregtech/api/interfaces/IBlockWithTextures.java +++ b/src/main/java/gregtech/api/interfaces/IBlockWithTextures.java @@ -3,7 +3,7 @@ import javax.annotation.Nullable; public interface IBlockWithTextures { - + /** * @return Texture[forge direction ordinal][layer] */ diff --git a/src/main/java/gregtech/api/interfaces/IDimension.java b/src/main/java/gregtech/api/interfaces/IDimension.java deleted file mode 100644 index 0e0857778af..00000000000 --- a/src/main/java/gregtech/api/interfaces/IDimension.java +++ /dev/null @@ -1,10 +0,0 @@ -package gregtech.api.interfaces; - -import net.minecraft.world.World; - -public interface IDimension { - - public String getWorldName(); - - public boolean matches(World world); -} diff --git a/src/main/java/gregtech/api/interfaces/IMaterial.java b/src/main/java/gregtech/api/interfaces/IMaterial.java index b3c1a79993d..18948f4dee7 100644 --- a/src/main/java/gregtech/api/interfaces/IMaterial.java +++ b/src/main/java/gregtech/api/interfaces/IMaterial.java @@ -7,7 +7,7 @@ import gtPlusPlus.core.material.Material; public interface IMaterial { - + public String getLocalizedName(); public int getId(); @@ -24,11 +24,12 @@ public static IMaterial findMaterial(String name) { Werkstoff bw = Werkstoff.werkstoffVarNameHashMap.get(name); if (bw != null) return bw; - + IMaterial gtpp = Material.mMaterialsByName.get(name); if (gtpp != null) return gtpp; - return Materials.getMaterialsMap().get(name); + 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 index 498df5d1d01..390409de84f 100644 --- a/src/main/java/gregtech/api/interfaces/IStoneCategory.java +++ b/src/main/java/gregtech/api/interfaces/IStoneCategory.java @@ -1,5 +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 index b7bfcc18f6d..0416999fb5e 100644 --- a/src/main/java/gregtech/api/interfaces/IStoneType.java +++ b/src/main/java/gregtech/api/interfaces/IStoneType.java @@ -1,29 +1,36 @@ package gregtech.api.interfaces; -import gregtech.api.enums.OrePrefixes; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; +import gregtech.api.enums.OrePrefixes; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; + public interface IStoneType { - + /** Checks if this stone type contains this specific block. */ public boolean contains(Block block, int meta); public OrePrefixes getPrefix(); + public IStoneCategory getCategory(); public ItemStack getDust(boolean pure, int amount); public ObjectIntPair getCobblestone(); + public ObjectIntPair getStone(); public ITexture getTexture(int side); + public IIcon getIcon(int side); public boolean isRich(); + public boolean isDimensionSpecific(); + public boolean isExtraneous(); + public boolean isEnabled(); } diff --git a/src/main/java/gregtech/api/objects/MolecularRandom.java b/src/main/java/gregtech/api/objects/MolecularRandom.java index d0d6aaacc61..325040054d7 100644 --- a/src/main/java/gregtech/api/objects/MolecularRandom.java +++ b/src/main/java/gregtech/api/objects/MolecularRandom.java @@ -8,155 +8,154 @@ */ public class MolecularRandom extends Random { - private long seed; - private double nextNextGaussian; - private boolean haveNextNextGaussian; - - public MolecularRandom(long var1) { - this.haveNextNextGaussian = false; - this.seed = initialScramble(var1); - } - - private static long initialScramble(long var0) { - return (var0 ^ 25214903917L) & 281474976710655L; - } - - public void setSeed(long var1) { - this.seed = initialScramble(var1); - this.haveNextNextGaussian = false; - } - - protected int next(int var1) { - seed = seed * 25214903917L + 11L & 281474976710655L; - - return (int)(seed >>> 48 - var1); - } - - public void nextBytes(byte[] var1) { - int var2 = 0; - int var3 = var1.length; - - while(var2 < var3) { - int var4 = this.nextInt(); - - for(int var5 = Math.min(var3 - var2, 4); var5-- > 0; var4 >>= 8) { - var1[var2++] = (byte)var4; - } - } - - } - - final long internalNextLong(long var1, long var3) { - long var5 = this.nextLong(); - if (var1 < var3) { - long var7 = var3 - var1; - long var9 = var7 - 1L; - if ((var7 & var9) == 0L) { - var5 = (var5 & var9) + var1; - } else if (var7 > 0L) { - for(long var11 = var5 >>> 1; var11 + var9 - (var5 = var11 % var7) < 0L; var11 = this.nextLong() >>> 1) { - } + private long seed; + private double nextNextGaussian; + private boolean haveNextNextGaussian; + + public MolecularRandom(long var1) { + this.haveNextNextGaussian = false; + this.seed = initialScramble(var1); + } + + private static long initialScramble(long var0) { + return (var0 ^ 25214903917L) & 281474976710655L; + } + + public void setSeed(long var1) { + this.seed = initialScramble(var1); + this.haveNextNextGaussian = false; + } + + protected int next(int var1) { + seed = seed * 25214903917L + 11L & 281474976710655L; + + return (int) (seed >>> 48 - var1); + } + + public void nextBytes(byte[] var1) { + int var2 = 0; + int var3 = var1.length; - var5 += var1; - } else { - while(var5 < var1 || var5 >= var3) { - var5 = this.nextLong(); + while (var2 < var3) { + int var4 = this.nextInt(); + + for (int var5 = Math.min(var3 - var2, 4); var5-- > 0; var4 >>= 8) { + var1[var2++] = (byte) var4; } - } - } - - return var5; - } - - final int internalNextInt(int var1, int var2) { - if (var1 >= var2) { - return this.nextInt(); - } else { - int var3 = var2 - var1; - if (var3 > 0) { - return this.nextInt(var3) + var1; - } else { - int var4; - do { - do { - var4 = this.nextInt(); - } while(var4 < var1); - } while(var4 >= var2); - - return var4; - } - } - } - - final double internalNextDouble(double var1, double var3) { - double var5 = this.nextDouble(); - if (var1 < var3) { - var5 = var5 * (var3 - var1) + var1; - if (var5 >= var3) { - var5 = Double.longBitsToDouble(Double.doubleToLongBits(var3) - 1L); - } - } - - return var5; - } - - public int nextInt() { - return this.next(32); - } - - public int nextInt(int var1) { - if (var1 <= 0) { - throw new IllegalArgumentException("bound must be positive"); - } else { - int var2 = this.next(31); - int var3 = var1 - 1; - if ((var1 & var3) == 0) { - var2 = (int)((long)var1 * (long)var2 >> 31); - } else { - for(int var4 = var2; var4 - (var2 = var4 % var1) + var3 < 0; var4 = this.next(31)) { + } + + } + + final long internalNextLong(long var1, long var3) { + long var5 = this.nextLong(); + if (var1 < var3) { + long var7 = var3 - var1; + long var9 = var7 - 1L; + if ((var7 & var9) == 0L) { + var5 = (var5 & var9) + var1; + } else if (var7 > 0L) { + for (long var11 = var5 >>> 1; var11 + var9 - (var5 = var11 % var7) + < 0L; var11 = this.nextLong() >>> 1) {} + + var5 += var1; + } else { + while (var5 < var1 || var5 >= var3) { + var5 = this.nextLong(); + } + } + } + + return var5; + } + + final int internalNextInt(int var1, int var2) { + if (var1 >= var2) { + return this.nextInt(); + } else { + int var3 = var2 - var1; + if (var3 > 0) { + return this.nextInt(var3) + var1; + } else { + int var4; + do { + do { + var4 = this.nextInt(); + } while (var4 < var1); + } while (var4 >= var2); + + return var4; } - } - - return var2; - } - } - - public long nextLong() { - return ((long)this.next(32) << 32) + (long)this.next(32); - } - - public boolean nextBoolean() { - return this.next(1) != 0; - } - - public float nextFloat() { - return (float)this.next(24) / 1.6777216E7F; - } - - public double nextDouble() { - return (double)(((long)this.next(26) << 27) + (long)this.next(27)) * 1.1102230246251565E-16; - } - - public double nextGaussian() { - if (this.haveNextNextGaussian) { - this.haveNextNextGaussian = false; - return this.nextNextGaussian; - } else { - double var1; - double var3; - double var5; - do { + } + } + + final double internalNextDouble(double var1, double var3) { + double var5 = this.nextDouble(); + if (var1 < var3) { + var5 = var5 * (var3 - var1) + var1; + if (var5 >= var3) { + var5 = Double.longBitsToDouble(Double.doubleToLongBits(var3) - 1L); + } + } + + return var5; + } + + public int nextInt() { + return this.next(32); + } + + public int nextInt(int var1) { + if (var1 <= 0) { + throw new IllegalArgumentException("bound must be positive"); + } else { + int var2 = this.next(31); + int var3 = var1 - 1; + if ((var1 & var3) == 0) { + var2 = (int) ((long) var1 * (long) var2 >> 31); + } else { + for (int var4 = var2; var4 - (var2 = var4 % var1) + var3 < 0; var4 = this.next(31)) {} + } + + return var2; + } + } + + public long nextLong() { + return ((long) this.next(32) << 32) + (long) this.next(32); + } + + public boolean nextBoolean() { + return this.next(1) != 0; + } + + public float nextFloat() { + return (float) this.next(24) / 1.6777216E7F; + } + + public double nextDouble() { + return (double) (((long) this.next(26) << 27) + (long) this.next(27)) * 1.1102230246251565E-16; + } + + public double nextGaussian() { + if (this.haveNextNextGaussian) { + this.haveNextNextGaussian = false; + return this.nextNextGaussian; + } else { + double var1; + double var3; + double var5; do { - var1 = 2.0 * this.nextDouble() - 1.0; - var3 = 2.0 * this.nextDouble() - 1.0; - var5 = var1 * var1 + var3 * var3; - } while(var5 >= 1.0); - } while(var5 == 0.0); - - double var7 = StrictMath.sqrt(-2.0 * StrictMath.log(var5) / var5); - this.nextNextGaussian = var3 * var7; - this.haveNextNextGaussian = true; - return var1 * var7; - } - } + do { + var1 = 2.0 * this.nextDouble() - 1.0; + var3 = 2.0 * this.nextDouble() - 1.0; + var5 = var1 * var1 + var3 * var3; + } while (var5 >= 1.0); + } while (var5 == 0.0); + + double var7 = StrictMath.sqrt(-2.0 * StrictMath.log(var5) / var5); + this.nextNextGaussian = var3 * var7; + this.haveNextNextGaussian = true; + return var1 * var7; + } + } } diff --git a/src/main/java/gregtech/api/task/CoopTask.java b/src/main/java/gregtech/api/task/CoopTask.java index 9df01160da5..104130ef355 100644 --- a/src/main/java/gregtech/api/task/CoopTask.java +++ b/src/main/java/gregtech/api/task/CoopTask.java @@ -2,6 +2,6 @@ @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 index 49831561902..db462b3206c 100644 --- a/src/main/java/gregtech/api/task/CooperativeScheduler.java +++ b/src/main/java/gregtech/api/task/CooperativeScheduler.java @@ -21,10 +21,12 @@ /** * 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 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 enum CooperativeScheduler { + INSTANCE; private final LinkedHashMap> tasks = new LinkedHashMap<>(); @@ -33,7 +35,9 @@ public enum CooperativeScheduler { private long start, end; private CooperativeScheduler() { - FMLCommonHandler.instance().bus().register(this); + FMLCommonHandler.instance() + .bus() + .register(this); } @SubscribeEvent @@ -46,11 +50,12 @@ public void tick(TickEvent.ServerTickEvent event) { end = 0; // we intentionally don't return to the previous ran task here - Iterator> iter = tasks.values().iterator(); - + Iterator> iter = tasks.values() + .iterator(); + while (iter.hasNext()) { CoopFuture future = iter.next(); - + long start2 = 0; if (Gregtech.general.schedulerProfileLevel >= 2) { @@ -71,7 +76,13 @@ public void tick(TickEvent.ServerTickEvent event) { 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"); + GTMod.GT_FML_LOGGER.info( + "Task " + future.name + + " " + + future.task + + " took " + + GTUtility.formatNumbers((end - start2) / 1e3) + + " microseconds"); } if ((end - start) > Gregtech.general.schedulerDuration) { @@ -80,7 +91,8 @@ public void tick(TickEvent.ServerTickEvent event) { } if (Gregtech.general.schedulerProfileLevel >= 1) { - GTMod.GT_FML_LOGGER.info("Task scheduler took " + GTUtility.formatNumbers((System.nanoTime() - start) / 1e3) + " microseconds"); + GTMod.GT_FML_LOGGER.info( + "Task scheduler took " + GTUtility.formatNumbers((System.nanoTime() - start) / 1e3) + " microseconds"); } for (CoopFuture future : newTasks) { @@ -98,7 +110,8 @@ public void tick(TickEvent.ServerTickEvent event) { public CoopFuture schedule(CoopTask task) { CoopFuture future = new CoopFuture<>(); - future.name = UUID.randomUUID().toString(); + future.name = UUID.randomUUID() + .toString(); future.task = task; newTasks.add(future); @@ -171,7 +184,8 @@ public void run() { @Override public boolean shouldYield() { - return (end = System.nanoTime()) - start > (Gregtech.general.schedulerDuration / Math.min(tasks.size(), Gregtech.general.maxTaskCount)); + return (end = System.nanoTime()) - start + > (Gregtech.general.schedulerDuration / Math.min(tasks.size(), Gregtech.general.maxTaskCount)); } @Override diff --git a/src/main/java/gregtech/api/task/ICoopTaskContext.java b/src/main/java/gregtech/api/task/ICoopTaskContext.java index 0e8f18c9faa..c65a65465a0 100644 --- a/src/main/java/gregtech/api/task/ICoopTaskContext.java +++ b/src/main/java/gregtech/api/task/ICoopTaskContext.java @@ -1,7 +1,7 @@ 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 4817b3f8043..249e7a759fa 100644 --- a/src/main/java/gregtech/api/util/GTBaseCrop.java +++ b/src/main/java/gregtech/api/util/GTBaseCrop.java @@ -239,7 +239,8 @@ public boolean isBlockBelow(ICropTile aCrop) { return false; } for (int i = 1; i < this.getrootslength(aCrop); i++) { - Block tBlock = aCrop.getWorld().getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); + Block tBlock = aCrop.getWorld() + .getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); int tMetaID = aCrop.getWorld() .getBlockMetadata(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 4e1022e8944..8080694a1f0 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -166,10 +166,8 @@ 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 gtPlusPlus.core.block.base.BlockBaseOre; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; import ic2.api.recipe.RecipeInputOreDict; @@ -4360,7 +4358,8 @@ public static boolean isOre(ItemStack aStack) { return sOreTable.get(tItem); } for (int id : OreDictionary.getOreIDs(aStack)) { - if (OreDictionary.getOreName(id).startsWith("ore")) { + if (OreDictionary.getOreName(id) + .startsWith("ore")) { sOreTable.put(tItem, true); return true; } @@ -4580,7 +4579,7 @@ public static int signum(int x) { public static long signum(long x) { return x < 0 ? -1 : x > 0 ? 1 : 0; } - + /** * Hash an item stack for the purpose of storing hash across launches */ diff --git a/src/main/java/gregtech/api/world/GTWorldgen.java b/src/main/java/gregtech/api/world/GTWorldgen.java index df60150e609..07c76e0e3a5 100644 --- a/src/main/java/gregtech/api/world/GTWorldgen.java +++ b/src/main/java/gregtech/api/world/GTWorldgen.java @@ -106,7 +106,9 @@ public boolean isGenerationAllowed(World aWorld, String[] blackListedProviders, if (tAllowed == null) { if (blackListedProviders != null) { for (String dimClass : blackListedProviders) { - if (dimClass.equals(aWorld.provider.getClass().getName())) { + if (dimClass.equals( + aWorld.provider.getClass() + .getName())) { return false; } } diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index 762813dd92b..a138b3f97e0 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -25,8 +25,8 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent; import cpw.mods.fml.common.registry.GameRegistry; -import galacticgreg.api.ModDimensionDef; import galacticgreg.api.Enums.DimensionType; +import galacticgreg.api.ModDimensionDef; import galacticgreg.api.enums.DimensionDef; import galacticgreg.api.enums.DimensionDef.DimNames; import gregtech.GTMod; @@ -77,7 +77,8 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide ModDimensionDef def = DimensionDef.getDefForWorld(aWorld); - if (def.getDimensionName().equals(DimNames.THE_END)) { + if (def.getDimensionName() + .equals(DimNames.THE_END)) { if (aX * aX + aZ * aZ > END_ASTEROID_DISTANCE * END_ASTEROID_DISTANCE) { def = DimensionDef.EndAsteroids.modDimensionDef; } @@ -86,7 +87,7 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide if (def == null || def.getDimensionType() != DimensionType.Planet) { return; } - + pendingTasks.add( new WorldGenContainer( new XSTR(Math.abs(aRandom.nextInt()) + 1), @@ -128,7 +129,7 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide + pendingTasks.size() + " i: " + i); - + task.run(); } this.mIsGenerating = false; @@ -371,11 +372,11 @@ public void generateVein(int oreseedX, int oreseedZ) { // 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 - * ); } } - */ + * 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; i++) { WorldgenGTOreLayer oreLayer = WorldgenQuery.veins() @@ -383,7 +384,7 @@ public void generateVein(int oreseedX, int oreseedZ) { .find(oreveinRNG); 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 @@ -569,11 +570,11 @@ public void run() { if (debugWorldGen || profileWorldGen) { GTMod.GT_FML_LOGGER.info( " Oregen took " + (oregenTime - stonegenTime) / 1e3 - + "us Stonegen took " - + (stonegenTime - startTime) / 1e3 - + "us Worldgen took " - + duration / 1e3 - + "us"); + + "us Stonegen took " + + (stonegenTime - startTime) / 1e3 + + "us Worldgen took " + + duration / 1e3 + + "us"); } } } diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 34afa1769e9..33a63e5d19c 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -9,10 +9,11 @@ import java.util.Random; import java.util.Set; -import com.google.common.collect.ImmutableList; - import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; + +import com.google.common.collect.ImmutableList; + import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneCategory; @@ -163,7 +164,8 @@ public boolean generatesBigOre() { } @Override - public int executeWorldgenChunkified(World world, Random rng, String biome, int dimId, int chunkX, int chunkY, int seedX, int seedZ, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + public int executeWorldgenChunkified(World world, Random rng, String biome, int dimId, int chunkX, int chunkY, + int seedX, int seedZ, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { if (mWorldGenName.equals("NoOresInVein")) { if (debugOrevein) GTLog.out.println(" NoOresInVein"); // Return a special empty orevein @@ -235,10 +237,13 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int + " cY=" + 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(chunkX / 16 - seedX / 16, 2) + Math.pow(chunkY / 16 - seedZ / 16, 2)))); + int localDensity = Math.max( + 1, + this.mDensity + / ((int) Math.sqrt(2 + Math.pow(chunkX / 16 - seedX / 16, 2) + Math.pow(chunkY / 16 - seedZ / 16, 2)))); LayerGenerator generator = new LayerGenerator(); @@ -260,7 +265,7 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int // 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. - + generator.generateLayer(true, false, false); // layer -1 if ((placeCount[1] + placeCount[3]) == 0) { @@ -279,7 +284,10 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int // Place small ores for the vein if (oreveinPlacerOres) { - int smallOresToGenerate = (limitEastX - limitWestX) * (limitSouthZ - limitNorthZ) * 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 i = 0; i < smallOresToGenerate; i++) { @@ -339,6 +347,7 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int } private class LayerGenerator { + World world; Random rng; int limitWestX, limitEastX, limitSouthZ, limitNorthZ; @@ -351,7 +360,8 @@ private void generateLayer(boolean secondary, boolean between, boolean primary) int placeX = Math.max(1, Math.max(Math.abs(veinWestX - tX), Math.abs(veinEastX - tX)) / localDensity); for (int tZ = limitNorthZ; tZ < limitSouthZ; tZ++) { - int placeZ = Math.max(1, Math.max(Math.abs(veinSouthZ - tZ), Math.abs(veinNorthZ - tZ)) / localDensity); + int placeZ = Math + .max(1, Math.max(Math.abs(veinSouthZ - tZ), Math.abs(veinNorthZ - tZ)) / localDensity); if (primary) { if ((rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mPrimary != null) { @@ -379,8 +389,9 @@ private void generateLayer(boolean secondary, boolean between, boolean primary) continue; } } - - if (rng.nextInt(7) == 0 && (rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mSporadic != null) { // Sporadics are reduce by 1/7 to compensate + + if (rng.nextInt(7) == 0 && (rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) + && mSporadic != null) { // Sporadics are reduce by 1/7 to compensate if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mSporadic, false)) { placeCount[3]++; } diff --git a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java index b029146ab4f..e3cf0053c47 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java +++ b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java @@ -7,10 +7,11 @@ import java.util.Random; import java.util.Set; -import com.google.common.collect.ImmutableList; - import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; + +import com.google.common.collect.ImmutableList; + import gregtech.api.GregTechAPI; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneCategory; @@ -117,8 +118,8 @@ public boolean generatesBigOre() { } @Override - public boolean executeWorldgen(World world, Random random, String biome, int dimId, int chunkX, - int chunkZ, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + public boolean executeWorldgen(World world, Random random, String biome, int dimId, 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 } diff --git a/src/main/java/gregtech/common/WorldgenStone.java b/src/main/java/gregtech/common/WorldgenStone.java index 7a69253af8f..0211350eb53 100644 --- a/src/main/java/gregtech/common/WorldgenStone.java +++ b/src/main/java/gregtech/common/WorldgenStone.java @@ -213,31 +213,31 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int 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); + + 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 diff --git a/src/main/java/gregtech/common/blocks/BlockFrameBox.java b/src/main/java/gregtech/common/blocks/BlockFrameBox.java index 06c13ec596e..2b1494e67ee 100644 --- a/src/main/java/gregtech/common/blocks/BlockFrameBox.java +++ b/src/main/java/gregtech/common/blocks/BlockFrameBox.java @@ -73,11 +73,9 @@ public BlockFrameBox() { GTLanguageManager .addStringLocalization(getUnlocalizedName() + "." + meta + DOT_TOOLTIP, material.getToolTip()); - ITexture[] texture = { - TextureFactory.of( - material.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex], - Dyes.getModulation(-1, material.mRGBa)) - }; + 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 }; } diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java index 24a4dd21856..2081f454aa8 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java @@ -5,6 +5,22 @@ import java.util.Collections; import java.util.List; +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; @@ -26,24 +42,9 @@ import gregtech.common.ores.OreInfo; import gregtech.common.render.GTRendererBlock; import gregtech.nei.NEIGTConfig; -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; public class BlockOresAbstract extends GTGenericBlock implements IBlockWithTextures { - + public final List stoneTypes; public BlockOresAbstract(int series, StoneType[] stoneTypes) { @@ -72,11 +73,16 @@ public BlockOresAbstract(int series, StoneType[] stoneTypes) { 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) + ".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()); + GTLanguageManager.addStringLocalization( + mUnlocalizedName + "." + (matId + GTOreAdapter.SMALL_ORE_META_OFFSET) + ".tooltip", + mat.getToolTip()); } OreInfo info = new OreInfo<>(); @@ -93,14 +99,10 @@ public BlockOresAbstract(int series, StoneType[] stoneTypes) { info.stoneType = stoneType; if (stoneType.getPrefix().mIsUnificatable) { - GTOreDictUnificator.set( - stoneType.getPrefix(), - info.material, - GTOreAdapter.INSTANCE.getStack(info, 1)); + GTOreDictUnificator + .set(stoneType.getPrefix(), info.material, GTOreAdapter.INSTANCE.getStack(info, 1)); } else { - GTOreDictUnificator.registerOre( - stoneType.getPrefix(), - GTOreAdapter.INSTANCE.getStack(info, 1)); + GTOreDictUnificator.registerOre(stoneType.getPrefix(), GTOreAdapter.INSTANCE.getStack(info, 1)); } } } @@ -112,7 +114,8 @@ public String getUnlocalizedName() { } /** - * The first stack with meta = 0 is always hidden in {@link NEIGTConfig} to prevent extraneous ores from showing up in nei. + * 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) { @@ -137,15 +140,15 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { 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)); } } @@ -167,15 +170,15 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { 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)); } } @@ -218,23 +221,18 @@ public ITexture[][] getTextures(int metadata) { if (mat != null) { ITexture iTexture = TextureFactory.builder() - .addIcon(mat.mIconSet.mTextures[small ? OrePrefixes.oreSmall.mTextureIndex : OrePrefixes.ore.mTextureIndex]) + .addIcon( + mat.mIconSet.mTextures[small ? OrePrefixes.oreSmall.mTextureIndex : OrePrefixes.ore.mTextureIndex]) .setRGBA(mat.mRGBa) .stdOrient() .build(); - textures = new ITexture[] { - stoneType.getTexture(0), - iTexture - }; + 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() - }; + 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 }; @@ -306,22 +304,25 @@ public String getHarvestTool(int aMeta) { @Override public int damageDropped(int meta) { - try(OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, meta)) { + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, meta)) { if (info == null) return 0; - return GTOreAdapter.INSTANCE.getBlock(info.setNatural(false)).rightInt(); + return GTOreAdapter.INSTANCE.getBlock(info.setNatural(false)) + .rightInt(); } } @Override public int getHarvestLevel(int meta) { - try(OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, 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; - + + int harvestLevel = GTMod.gregtechproxy.mChangeHarvestLevels + ? GTMod.gregtechproxy.mHarvestLevel[info.material.mMetaItemSubID] + : info.material.mToolQuality; + return GTUtility.clamp(harvestLevel + smallOreBonus, 0, GTMod.gregtechproxy.mMaxHarvestLevel); } } @@ -342,15 +343,22 @@ public float getExplosionResistance(Entity entity, World world, int x, int y, in } @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX, float subY, float subZ) { + 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);) { + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(world, x, y, z);) { info.setNatural(!info.isNatural); - world.setBlockMetadataWithNotify(x, y, z, GTOreAdapter.INSTANCE.getBlock(info).rightInt(), 3); + world.setBlockMetadataWithNotify( + x, + y, + z, + GTOreAdapter.INSTANCE.getBlock(info) + .rightInt(), + 3); GTUtility.sendChatToPlayer(player, "Set ore natural flag to " + info.isNatural); } - + return true; } else { return false; diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java b/src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java index de42e163735..6d1e8c9a58e 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java @@ -1,8 +1,5 @@ package gregtech.common.blocks; -import java.util.HashSet; -import java.util.Set; - import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; @@ -17,7 +14,8 @@ public abstract class BlockOresAbstractOld extends GTGenericBlock implements ITileEntityProvider { - protected BlockOresAbstractOld(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta, Material aMaterial) { + protected BlockOresAbstractOld(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta, + Material aMaterial) { super(ItemOresOld.class, aUnlocalizedName, aMaterial); this.isBlockContainer = true; } diff --git a/src/main/java/gregtech/common/blocks/BlockOresOld.java b/src/main/java/gregtech/common/blocks/BlockOresOld.java index 649b76f89a8..0b7549f02e9 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresOld.java +++ b/src/main/java/gregtech/common/blocks/BlockOresOld.java @@ -1,20 +1,10 @@ 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 net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; -import net.minecraft.init.Blocks; -import net.minecraft.util.IIcon; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - public class BlockOresOld extends BlockOresAbstractOld { private static final String UNLOCALIZED_NAME = "gt.blockores"; diff --git a/src/main/java/gregtech/common/blocks/ItemOres.java b/src/main/java/gregtech/common/blocks/ItemOres.java index 05bd47bd145..36ff2e2c647 100644 --- a/src/main/java/gregtech/common/blocks/ItemOres.java +++ b/src/main/java/gregtech/common/blocks/ItemOres.java @@ -33,7 +33,8 @@ public String getUnlocalizedName(ItemStack stack) { int matId = blockOre.getMaterialIndex(metadata); boolean small = blockOre.isSmallOre(metadata); - return this.field_150939_a.getUnlocalizedName() + "." + (matId + (small ? BlockOresAbstract.SMALL_ORE_META_OFFSET : 0)); + return this.field_150939_a.getUnlocalizedName() + "." + + (matId + (small ? BlockOresAbstract.SMALL_ORE_META_OFFSET : 0)); } @Override diff --git a/src/main/java/gregtech/common/blocks/TileEntityOres.java b/src/main/java/gregtech/common/blocks/TileEntityOres.java index 21c4e724bfd..ef9b127bf0a 100644 --- a/src/main/java/gregtech/common/blocks/TileEntityOres.java +++ b/src/main/java/gregtech/common/blocks/TileEntityOres.java @@ -3,12 +3,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import gregtech.api.GregTechAPI; -import gregtech.api.enums.Materials; -import gregtech.api.enums.StoneType; -import gregtech.common.ores.GTOreAdapter; -import gregtech.common.ores.OreInfo; - public class TileEntityOres extends TileEntity { public short mMetaData = 0; @@ -30,26 +24,6 @@ public void writeToNBT(NBTTagCompound aNBT) { @Override public boolean canUpdate() { - return true; - } - - private boolean recursed = false; - - @Override - public void updateEntity() { - if (!recursed) { - recursed = true; - - try(OreInfo info = OreInfo.getNewInfo()) { - info.stoneType = StoneType.STONE_TYPES.get(mMetaData % 16000 / 1000); - info.material = GregTechAPI.sGeneratedMaterials[mMetaData % 1000]; - info.isSmall = mMetaData >= 16000; - info.isNatural = mNatural; - - var p = GTOreAdapter.INSTANCE.getBlock(info); - - worldObj.setBlock(xCoord, yCoord, zCoord, p.left(), p.rightInt(), 3); - } - } + return false; } } diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java index 1f5280a6aa6..a04b9034e7b 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java @@ -43,7 +43,8 @@ private static Materials getOreMaterial(Block block, int 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; + if (!association.mPrefix.toString() + .startsWith("ore")) return null; return association.mMaterial.mMaterial; } @@ -66,8 +67,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (mat != null) { GTUtility.sendChatToPlayer( aPlayer, - GTUtility.trans("100", "This is ") + mat.getLocalizedName() - + GTUtility.trans("101", " Ore.")); + 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; } @@ -77,13 +77,13 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (oreMat != null) { GTUtility.sendChatToPlayer( aPlayer, - GTUtility.trans("100", "This is ") + oreMat.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.getMaterial() == Material.rock || aBlock.getMaterial() == Material.ground || OreManager.isOre(aBlock, aMeta)) { + 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); @@ -101,20 +101,17 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer break; } if (tBlock instanceof BlockLiquid || tBlock instanceof IFluidBlock) { - GTUtility - .sendChatToPlayer(aPlayer, GTUtility.trans("103", "There is a Liquid behind this Rock.")); + 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.")); + 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.")); + if (i < 4) GTUtility + .sendChatToPlayer(aPlayer, GTUtility.trans("105", "Material is changing behind this Rock.")); break; } } @@ -142,8 +139,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (oreMat != null) { GTUtility.sendChatToPlayer( aPlayer, - GTUtility.trans("106", "Found traces of ") - + oreMat.mDefaultLocalName + GTUtility.trans("106", "Found traces of ") + oreMat.mDefaultLocalName + GTUtility.trans("101", " Ore.")); return true; } diff --git a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java index 0e40af39d26..e1d8f57fcdc 100644 --- a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java +++ b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java @@ -8,6 +8,7 @@ import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.FakePlayer; + import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GTLog; import gregtech.api.util.GTModHandler; diff --git a/src/main/java/gregtech/common/ores/BWOreAdapter.java b/src/main/java/gregtech/common/ores/BWOreAdapter.java index 5855fe98f85..46a7d168fb7 100644 --- a/src/main/java/gregtech/common/ores/BWOreAdapter.java +++ b/src/main/java/gregtech/common/ores/BWOreAdapter.java @@ -6,6 +6,9 @@ import java.util.Random; import java.util.concurrent.ThreadLocalRandom; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + import com.gtnewhorizons.postea.api.TileEntityReplacementManager; import com.gtnewhorizons.postea.utility.BlockInfo; @@ -22,43 +25,28 @@ import gregtech.api.util.GTUtility.ItemId; import gregtech.common.GTProxy.OreDropSystem; import it.unimi.dsi.fastutil.objects.ObjectIntPair; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; public enum BWOreAdapter implements IOreAdapter { + INSTANCE; 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); + 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); + GameRegistry + .registerBlock(smallNatural, BWItemMetaGeneratedOre.class, "bw.blockores.natural." + smallSuffix); } public BWMetaGeneratedOres get(boolean small, boolean natural) { @@ -74,7 +62,7 @@ public BWMetaGeneratedOres get(boolean small, boolean natural) { } else { return this.big; } - } + } } } @@ -86,16 +74,16 @@ public void init() { 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); @@ -171,13 +159,13 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort return getSmallOreDrops(ThreadLocalRandom.current(), info, fortune); } else { OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; - + if (silktouch) oreDropSystem = OreDropSystem.Block; - + return getBigOreDrops(ThreadLocalRandom.current(), oreDropSystem, info, fortune); } } - + @Override public List getPotentialDrops(OreInfo info2) { if (!supports(info2)) return new ArrayList<>(); @@ -213,7 +201,9 @@ public ArrayList getSmallOreDrops(Random random, OreInfo i ArrayList drops = new ArrayList<>(); if (!possibleDrops.isEmpty()) { - int dropCount = Math.max(1, bridge.mOreMultiplier + (fortune > 0 ? random.nextInt(1 + fortune * bridge.mOreMultiplier) : 0) / 2); + 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())))); @@ -227,9 +217,10 @@ public ArrayList getSmallOreDrops(Random random, OreInfo i return drops; } - public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, int fortune) { + public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + int fortune) { ArrayList drops = new ArrayList<>(); - + // For Sake of god of balance! switch (oreDropMode) { diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index cd9aa2d1b14..851169d724c 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -7,6 +7,10 @@ import java.util.Random; import java.util.concurrent.ThreadLocalRandom; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + import com.gtnewhorizons.postea.api.TileEntityReplacementManager; import com.gtnewhorizons.postea.utility.BlockInfo; @@ -23,11 +27,9 @@ import gregtech.common.GTProxy.OreDropSystem; import gregtech.common.blocks.BlockOresAbstract; import it.unimi.dsi.fastutil.objects.ObjectIntPair; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; public enum GTOreAdapter implements IOreAdapter { + INSTANCE; private final Map oreBlocksByStoneType = new EnumMap<>(StoneType.class); @@ -37,6 +39,7 @@ public enum GTOreAdapter implements IOreAdapter { public BlockOresAbstract[] ores; public void init() { + // spotless:off ores1 = new BlockOresAbstract(2, new StoneType[] { StoneType.Stone, StoneType.Netherrack, @@ -103,6 +106,7 @@ public void init() { StoneType.Marble, StoneType.Basalt, }; + // spotless:on TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world) -> { int meta = tag.getInteger("m"); @@ -118,7 +122,7 @@ public void init() { return new BlockInfo(Blocks.air, 0); } else { var p = INSTANCE.getBlock(info); - + return new BlockInfo(p.left(), p.rightInt()); } } @@ -139,7 +143,8 @@ 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; + IStoneType stoneType = info.stoneType == null ? gtMat.getValidStones() + .get(0) : info.stoneType; if (!(stoneType instanceof StoneType stoneType2)) return false; if (!oreBlocksByStoneType.containsKey(stoneType2)) return false; @@ -157,7 +162,8 @@ public boolean supports(OreInfo info) { public OreInfo getOreInfo(Block block, int meta) { if (!(block instanceof BlockOresAbstract 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"); + 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; @@ -188,7 +194,7 @@ public ObjectIntPair getBlock(OreInfo info) { 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; @@ -226,13 +232,13 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort return getSmallOreDrops(ThreadLocalRandom.current(), info, fortune); } else { OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; - + if (silktouch) oreDropSystem = OreDropSystem.Block; - + return getBigOreDrops(ThreadLocalRandom.current(), oreDropSystem, info, fortune); } } - + @Override public List getPotentialDrops(OreInfo info2) { if (!supports(info2)) return new ArrayList<>(); @@ -266,7 +272,10 @@ public ArrayList getSmallOreDrops(Random random, OreInfo i 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); + 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())))); @@ -280,9 +289,10 @@ public ArrayList getSmallOreDrops(Random random, OreInfo i return drops; } - public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, int fortune) { + public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + int fortune) { ArrayList drops = new ArrayList<>(); - + // For Sake of god of balance! switch (oreDropMode) { diff --git a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java index 4677e212ef5..218a0885c97 100644 --- a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java @@ -5,17 +5,18 @@ import java.util.Random; import java.util.concurrent.ThreadLocalRandom; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + import gregtech.GTMod; import gregtech.api.enums.StoneType; import gregtech.common.GTProxy.OreDropSystem; import gtPlusPlus.core.block.base.BlockBaseOre; import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.minecraft.ItemUtils; import it.unimi.dsi.fastutil.objects.ObjectIntPair; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; public enum GTPPOreAdapter implements IOreAdapter { + INSTANCE; @Override @@ -37,7 +38,7 @@ 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; @@ -50,7 +51,7 @@ public ObjectIntPair 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; @@ -84,7 +85,8 @@ public List getPotentialDrops(OreInfo info2) { return getBigOreDrops(ThreadLocalRandom.current(), GTMod.gregtechproxy.oreDropSystem, info, 0); } - public List getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, int fortune) { + public List getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + int fortune) { ArrayList drops = new ArrayList<>(); switch (oreDropMode) { @@ -100,16 +102,10 @@ public List getBigOreDrops(Random random, OreDropSystem oreDropMode, if (fortune > 3) fortune = 3; long amount = (long) random.nextInt(fortune) + aMinAmount; for (int i = 0; i < amount; i++) { - drops.add( - ItemUtils.getItemStackOfAmountFromOreDictNoBroken( - "oreRaw" + info.material.getLocalizedName(), - 1)); + drops.add(info.material.getRawOre(1)); } } else { - drops.add( - ItemUtils.getItemStackOfAmountFromOreDictNoBroken( - "oreRaw" + info.material.getLocalizedName(), - 1)); + drops.add(info.material.getRawOre(1)); } } // Unified ore, Per Dimension ore, Regular ore diff --git a/src/main/java/gregtech/common/ores/IOreAdapter.java b/src/main/java/gregtech/common/ores/IOreAdapter.java index 120de9aa88a..ad1e07586cc 100644 --- a/src/main/java/gregtech/common/ores/IOreAdapter.java +++ b/src/main/java/gregtech/common/ores/IOreAdapter.java @@ -2,24 +2,28 @@ import java.util.List; -import gregtech.api.enums.StoneType; -import gregtech.api.interfaces.IMaterial; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; 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 gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IMaterial; +import it.unimi.dsi.fastutil.objects.ObjectIntPair; + public interface IOreAdapter { public boolean supports(Block block, int meta); + public boolean supports(OreInfo info); public OreInfo getOreInfo(Block block, int meta); + public default OreInfo getOreInfo(World world, int x, int y, int z) { return getOreInfo(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); } + public default OreInfo getOreInfo(ItemStack stack) { if (!(stack.getItem() instanceof ItemBlock itemBlock)) return null; @@ -27,7 +31,7 @@ public default OreInfo getOreInfo(ItemStack stack) { } public ObjectIntPair getBlock(OreInfo info); - + public default ItemStack getStack(OreInfo info, int amount) { ObjectIntPair p = getBlock(info); @@ -36,7 +40,7 @@ public default ItemStack getStack(OreInfo info, int amount) { } if (info.stoneType != StoneType.Stone) { - try(OreInfo info2 = info.clone()) { + try (OreInfo info2 = info.clone()) { info2.stoneType = StoneType.Stone; p = getBlock(info2); @@ -51,5 +55,6 @@ public default ItemStack getStack(OreInfo info, int amount) { } public List getOreDrops(OreInfo info, boolean silktouch, int fortune); + 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 index a90a9341494..7564ecce28a 100644 --- a/src/main/java/gregtech/common/ores/OreInfo.java +++ b/src/main/java/gregtech/common/ores/OreInfo.java @@ -6,7 +6,7 @@ import gregtech.api.interfaces.IStoneType; public class OreInfo implements AutoCloseable { - + public TMat material; public IStoneType stoneType; public boolean isSmall; @@ -16,13 +16,13 @@ public class OreInfo implements AutoCloseable { @SuppressWarnings("unchecked") public static OreInfo getNewInfo() { - synchronized(ORE_INFO_POOL) { + synchronized (ORE_INFO_POOL) { return (OreInfo) ORE_INFO_POOL.getInstance(); } } public static void releaseInfo(OreInfo info) { - synchronized(ORE_INFO_POOL) { + synchronized (ORE_INFO_POOL) { ORE_INFO_POOL.releaseInstance(info.reset()); } } @@ -86,33 +86,30 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; + 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 (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; + 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 + "]"; + 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 index 1db36d104b3..143a1f4dffe 100644 --- a/src/main/java/gregtech/common/ores/OreManager.java +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -6,12 +6,6 @@ import javax.annotation.Nullable; -import com.google.common.collect.ImmutableList; - -import gregtech.api.enums.StoneType; -import gregtech.api.interfaces.IMaterial; -import gregtech.api.interfaces.IStoneType; -import it.unimi.dsi.fastutil.Pair; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -19,14 +13,19 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import com.google.common.collect.ImmutableList; + +import gregtech.api.enums.StoneType; +import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IStoneType; +import it.unimi.dsi.fastutil.Pair; + public class OreManager { - - private OreManager() { } - public static final ImmutableList> ORE_ADAPTERS = ImmutableList.of( - GTOreAdapter.INSTANCE, - GTPPOreAdapter.INSTANCE, - BWOreAdapter.INSTANCE); + private OreManager() {} + + public static final ImmutableList> ORE_ADAPTERS = ImmutableList + .of(GTOreAdapter.INSTANCE, GTPPOreAdapter.INSTANCE, BWOreAdapter.INSTANCE); public static IStoneType getStoneType(Block block, int meta) { IStoneType stoneType = StoneType.findStoneType(block, meta); @@ -69,7 +68,8 @@ public static IOreAdapter getAdapter(OreInfo info) { return null; } - public static boolean setOreForWorldGen(World world, int x, int y, int z, IStoneType defaultStone, IMaterial material, boolean small) { + public static boolean setOreForWorldGen(World world, int x, int y, int z, IStoneType defaultStone, + IMaterial material, boolean small) { if (y < 0 || y >= world.getActualHeight()) return false; IStoneType existingStone = getStoneType(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); @@ -82,18 +82,18 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone } } - try(OreInfo info = OreInfo.getNewInfo();) { + try (OreInfo info = OreInfo.getNewInfo();) { info.material = material; info.stoneType = existingStone; info.isSmall = small; info.isNatural = true; - + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { var block = oreAdapter.getBlock(info); - + if (block != null) { world.setBlock(x, y, z, block.left(), block.rightInt(), 2); - + return true; } } @@ -102,21 +102,22 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone } } - public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneType stoneType, IMaterial material, boolean small) { + public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneType stoneType, IMaterial material, + boolean small) { if (y < 0 || y >= world.getActualHeight()) return false; - try(OreInfo info = OreInfo.getNewInfo();) { + try (OreInfo info = OreInfo.getNewInfo();) { info.material = material; info.stoneType = stoneType; info.isSmall = small; info.isNatural = true; - + for (IOreAdapter oreAdapter : ORE_ADAPTERS) { var block = oreAdapter.getBlock(info); - + if (block != null) { world.setBlock(x, y, z, block.left(), block.rightInt(), 2); - + return true; } } @@ -136,7 +137,7 @@ public static boolean setExistingOreStoneType(World world, int x, int y, int z, info.stoneType = newStoneType; var block = oreAdapter.getBlock(info); - + if (block == null) return false; world.setBlock(x, y, z, block.left(), block.rightInt(), 2); @@ -144,7 +145,8 @@ public static boolean setExistingOreStoneType(World world, int x, int y, int z, return true; } - public static List mineBlock(World world, int x, int y, int z, int fortune, boolean simulate, boolean replaceWithCobblestone) { + public static List mineBlock(World world, int x, int y, int z, int fortune, boolean simulate, + boolean replaceWithCobblestone) { Block ore = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); @@ -156,7 +158,8 @@ public static List mineBlock(World world, int x, int y, int z, int fo if (p != null) { try (OreInfo info = p.right()) { - oreBlockDrops = p.left().getOreDrops(info, false, fortune); + oreBlockDrops = p.left() + .getOreDrops(info, false, fortune); var cobble = info.stoneType.getCobblestone(); @@ -168,7 +171,7 @@ public static List mineBlock(World world, int x, int y, int z, int fo oreBlockDrops = new ArrayList<>(Arrays.asList(new ItemStack(ore, 1, meta))); } else { // Regular ore - oreBlockDrops = ore.getDrops(world, x, y, z, meta, fortune); + oreBlockDrops = ore.getDrops(world, x, y, z, meta, fortune); } replacement = Blocks.cobblestone; @@ -204,7 +207,7 @@ public static ItemStack getStack(OreInfo info, int amount) { if (stack != null) return stack; } - + return null; } @@ -224,7 +227,7 @@ public static List getDrops(Block block, int meta, boolean silktouch, } } } - + return null; } @@ -234,7 +237,7 @@ public static List getPotentialDrops(OreInfo 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 index 3d7ddaa8a2a..9e9b5fc3f9d 100644 --- a/src/main/java/gregtech/common/ores/SmallOreDrops.java +++ b/src/main/java/gregtech/common/ores/SmallOreDrops.java @@ -2,14 +2,16 @@ import java.util.ArrayList; +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; -import net.minecraft.item.ItemStack; public enum SmallOreDrops { + gemExquisite(OrePrefixes.gemExquisite, OrePrefixes.gem, 1), gemFlawless(OrePrefixes.gemFlawless, OrePrefixes.gem, 2), gem(OrePrefixes.gem, null, 12), @@ -46,4 +48,4 @@ public static ArrayList getDropList(Materials material) { return drops; } -} \ No newline at end of file +} 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 788bbac4d9c..13ff6e86dc8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java @@ -11,14 +11,12 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Objects; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -225,7 +223,8 @@ private boolean tryProcessOreList() { } private boolean processOreList(boolean simulate) { - List oreBlockPositions = simulate ? copyOreBlockPositions(this.oreBlockPositions) : this.oreBlockPositions; + List oreBlockPositions = simulate ? copyOreBlockPositions(this.oreBlockPositions) + : this.oreBlockPositions; ChunkPosition oreBlockPos = null; Block oreBlock = null; @@ -258,7 +257,8 @@ private boolean processOreList(boolean simulate) { int y = oreBlockPos.chunkPosY; int z = oreBlockPos.chunkPosZ; - List oreBlockDrops = OreManager.mineBlock(world, x, y, z, mTier + 3, simulate, replaceWithCobblestone); + List oreBlockDrops = OreManager + .mineBlock(world, x, y, z, mTier + 3, simulate, replaceWithCobblestone); ItemStack[] toOutput = getOutputByDrops(oreBlockDrops); if (simulate && !canOutputAll(toOutput)) { @@ -570,7 +570,7 @@ 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 (GTUtility.isMinable(block, blockMeta)) oreBlockPositions.add(blockPos); } diff --git a/src/main/java/gregtech/common/tools/ToolChainsawLV.java b/src/main/java/gregtech/common/tools/ToolChainsawLV.java index 3ce73a6f29c..6ed7918acc1 100644 --- a/src/main/java/gregtech/common/tools/ToolChainsawLV.java +++ b/src/main/java/gregtech/common/tools/ToolChainsawLV.java @@ -137,8 +137,8 @@ public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPla } @Override - public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, - int aX, int aY, int aZ) { + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, + int aY, int aZ) { if (aBlock.isWood(aPlayer.worldObj, aX, aY, aZ) && OrePrefixes.log.contains(new ItemStack(aBlock, 1, aMetaData))) { float rAmount = 1.0F; diff --git a/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java b/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java index 4a55ab4916f..62f2995aa68 100644 --- a/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java +++ b/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java @@ -7,19 +7,32 @@ import gregtech.api.interfaces.IStoneType; public interface IWorldgenLayer { - + public int getMinY(); + public int getMaxY(); + public int getWeight(); + public float getSize(); + public float getDensity(); + public boolean canGenerateIn(String dimName); + public boolean canGenerateIn(IStoneType stoneType); + public boolean canGenerateIn(IStoneCategory stoneType); + public boolean isStoneSpecific(); + public boolean generatesBigOre(); + public boolean contains(IMaterial ore); + public ImmutableList getOres(); + public IMaterial getOre(float k); + public String getName(); } diff --git a/src/main/java/gregtech/common/worldgen/WorldgenQuery.java b/src/main/java/gregtech/common/worldgen/WorldgenQuery.java index e6a2579b1bb..bc656137df6 100644 --- a/src/main/java/gregtech/common/worldgen/WorldgenQuery.java +++ b/src/main/java/gregtech/common/worldgen/WorldgenQuery.java @@ -6,16 +6,17 @@ import java.util.Random; import java.util.Set; +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; -import net.minecraft.world.World; public class WorldgenQuery { - + public List list; public int minY = -1, maxY = -1; public boolean checkWeight = true; diff --git a/src/main/java/gregtech/nei/NEIGTConfig.java b/src/main/java/gregtech/nei/NEIGTConfig.java index c9e03c8e345..827ca3ea68f 100644 --- a/src/main/java/gregtech/nei/NEIGTConfig.java +++ b/src/main/java/gregtech/nei/NEIGTConfig.java @@ -4,6 +4,8 @@ import java.util.Comparator; import java.util.Map; +import net.minecraft.item.ItemStack; + import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ListMultimap; @@ -38,7 +40,6 @@ import gregtech.nei.dumper.MetaTileEntityDumper; import gregtech.nei.dumper.RecipeLockingSupportDumper; import gregtech.nei.dumper.VoidProtectionSupportDumper; -import net.minecraft.item.ItemStack; public class NEIGTConfig implements IConfigureNEI { diff --git a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java index 9d4decfdeac..1efdf536c3d 100644 --- a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java +++ b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java @@ -15,6 +15,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; + import cpw.mods.fml.common.registry.GameRegistry; import gregtech.GTMod; import gregtech.api.enums.OrePrefixes; @@ -93,11 +94,9 @@ public int getRenderType() { 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 - }; + 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 }; } 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 e6d32941d38..5cd5e6ec352 100644 --- a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java @@ -5,8 +5,6 @@ import java.util.Map; import java.util.Set; -import gregtech.api.interfaces.IMaterial; -import gregtech.common.WorldgenGTOreLayer; import net.minecraft.block.Block; import net.minecraft.client.resources.I18n; import net.minecraft.entity.Entity; @@ -16,6 +14,8 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; +import gregtech.api.interfaces.IMaterial; +import gregtech.common.WorldgenGTOreLayer; import gtPlusPlus.core.block.base.BlockBaseOre; import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.material.Material; @@ -48,7 +48,7 @@ public ItemBlockOre(final Block block) { private static void initVeinInfo() { for (WorldgenGTOreLayer oreLayer : WorldgenGTOreLayer.sList) { IMaterial[] mats = { oreLayer.mPrimary, oreLayer.mSecondary, oreLayer.mBetween, oreLayer.mSporadic }; - + for (IMaterial mat : mats) { if (mat instanceof Material gtppMat) { mMapOreBlockItemToDimName.put(gtppMat, oreLayer.mAllowedDimensions); 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 71b8cc68306..5bf55491050 100644 --- a/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java @@ -252,7 +252,8 @@ public enum ComponentTypes { // crushed + centrifuged, purified } - ComponentTypes(final String LocalName, final OrePrefixes orePrefix, 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; diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index fabc029c554..e7f4e34d614 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -10,8 +10,6 @@ import java.util.Map; import java.util.Set; -import com.google.common.collect.ImmutableList; - import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.Item; @@ -19,6 +17,8 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import com.google.common.collect.ImmutableList; + import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.StoneType; @@ -1169,9 +1169,8 @@ public final ItemStack getCable16(final int stacksize) { */ public final ItemStack getOre(final int stacksize) { if (ore == null) { - ore = ItemUtils.getItemStackOfAmountFromOreDictNoBroken( - "ore" + Utils.sanitizeString(this.getUnlocalizedName()), - 1); + ore = ItemUtils + .getItemStackOfAmountFromOreDictNoBroken("ore" + Utils.sanitizeString(this.getUnlocalizedName()), 1); } return GTUtility.copyAmount(stacksize, ore); diff --git a/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java b/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java index ec85ace1ebf..fe17f0200cb 100644 --- a/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java +++ b/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java @@ -3,7 +3,6 @@ import java.util.List; import java.util.Random; -import gregtech.api.objects.MolecularRandom; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; import net.minecraft.entity.EnumCreatureType; @@ -32,6 +31,7 @@ import net.minecraftforge.event.terraingen.PopulateChunkEvent; import net.minecraftforge.event.terraingen.TerrainGen; +import gregtech.api.objects.MolecularRandom; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.everglades.dimension.DimensionEverglades; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java b/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java index 9e8b85a2ffe..ab194fcd36b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/HandlerGT.java @@ -1,8 +1,5 @@ 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; diff --git a/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java b/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java index d5856adc99e..c3341c512b0 100644 --- a/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java +++ b/src/main/java/gtneioreplugin/plugin/NEIPluginConfig.java @@ -14,9 +14,7 @@ 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.enums.StoneType; -import gregtech.api.util.GTOreDictUnificator; import gregtech.common.ores.OreInfo; import gregtech.common.ores.OreManager; import gtneioreplugin.GTNEIOrePlugin; @@ -65,7 +63,7 @@ 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<>(); - + OreInfo info = OreInfo.getNewInfo(); info.stoneType = StoneType.Stone; diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java index 6687ac83565..3ada88beccd 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -1,6 +1,7 @@ package gtneioreplugin.plugin.gregtech5; import net.minecraft.client.resources.I18n; + import codechicken.lib.gui.GuiDraw; import gregtech.api.enums.Materials; import gregtech.api.interfaces.IMaterial; diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java index e2c4937ea41..20a8de9b403 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java @@ -166,10 +166,7 @@ public CachedOreSmallRecipe(String oreGenName, List stackList, List dropStackList) { this.oreGenName = oreGenName; this.positionedStackOreSmall = new PositionedStack(stackList, 2, 0); - this.positionedStackMaterialDust = new PositionedStack( - materialDustStackList, - 43, - 66); + this.positionedStackMaterialDust = new PositionedStack(materialDustStackList, 43, 66); List positionedDropStackList = new ArrayList<>(); int i = 1; for (ItemStack stackDrop : dropStackList) { @@ -185,7 +182,7 @@ private void setDimensionDisplayItems() { int count = 0; int itemsPerLine = 9; int itemSize = 18; - + OreSmallWrapper wrapper = GT5OreSmallHelper.SMALL_ORES_BY_NAME.get(this.oreGenName); for (String abbrDimName : wrapper.enabledDims) { diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index fd14e7997dd..ae11c2ecf5a 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -6,11 +6,11 @@ import java.util.Comparator; import java.util.List; -import com.google.common.collect.ImmutableList; - 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.interfaces.IMaterial; @@ -23,6 +23,7 @@ public class PluginGT5VeinStat extends PluginGT5Base { + // spotless:off public static final ImmutableList PREFIX_WHITELIST = ImmutableList.copyOf(new OrePrefixes[] { OrePrefixes.dust, OrePrefixes.dustPure, @@ -46,6 +47,7 @@ public class PluginGT5VeinStat extends PluginGT5Base { OrePrefixes.gemExquisite, OrePrefixes.gem, }); + // spotless:on @Override public void loadCraftingRecipes(String outputId, Object... results) { @@ -106,7 +108,8 @@ public void loadUsageRecipes(ItemStack stack) { } for (OreLayerWrapper oreVein : getAllVeins()) { - if (Arrays.asList(getDimNameArrayFromVeinName(oreVein.veinName)).contains(dimension)) { + if (Arrays.asList(getDimNameArrayFromVeinName(oreVein.veinName)) + .contains(dimension)) { addVeinWithLayers(oreVein); } } @@ -184,8 +187,13 @@ public String getRecipeName() { private String[] getDimNameArrayFromVeinName(String veinName) { OreLayerWrapper oreLayer = GT5OreLayerHelper.mapOreLayerWrapper.get(veinName); - String[] dims = GT5OreLayerHelper.bufferedDims.get(oreLayer).toArray(new String[0]); - Arrays.sort(dims, Comparator.comparingInt(s -> Arrays.asList(DimensionHelper.DimNameDisplayed).indexOf(s))); + String[] dims = GT5OreLayerHelper.bufferedDims.get(oreLayer) + .toArray(new String[0]); + Arrays.sort( + dims, + Comparator.comparingInt( + s -> Arrays.asList(DimensionHelper.DimNameDisplayed) + .indexOf(s))); return dims; } diff --git a/src/main/java/gtneioreplugin/util/DimensionHelper.java b/src/main/java/gtneioreplugin/util/DimensionHelper.java index 7e61f9b198d..9f665ac5df9 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -1,10 +1,5 @@ package gtneioreplugin.util; -import static galacticgreg.api.enums.DimensionDef.DimNames.OW; -import static galacticgreg.api.enums.DimensionDef.DimNames.NETHER; -import static galacticgreg.api.enums.DimensionDef.DimNames.TWILIGHT_FOREST; -import static galacticgreg.api.enums.DimensionDef.DimNames.THE_END; -import static galacticgreg.api.enums.DimensionDef.DimNames.EVERGLADES; import static galacticgreg.api.enums.DimensionDef.DimNames.ANUBIS; import static galacticgreg.api.enums.DimensionDef.DimNames.ASTEROIDS; import static galacticgreg.api.enums.DimensionDef.DimNames.BARNARDC; @@ -18,6 +13,7 @@ import static galacticgreg.api.enums.DimensionDef.DimNames.ENCELADUS; import static galacticgreg.api.enums.DimensionDef.DimNames.ENDASTEROIDS; 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; @@ -31,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; @@ -39,8 +37,10 @@ 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; diff --git a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java index fe0c895dfc1..843332c8e6a 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -8,6 +8,7 @@ import java.util.Set; import net.minecraft.item.ItemStack; + import gregtech.api.enums.OreMixes; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneType; @@ -25,7 +26,7 @@ public static void init() { 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)); } @@ -99,13 +100,14 @@ public ItemStack getLayerOre(int veinLayer, IStoneType stoneType) { info.material = ores[veinLayer]; info.stoneType = stoneType; - return Objects.requireNonNull(OreManager.getStack(info, 1), "getLayerOre: " + veinLayer + ", " + stoneType + ", " + Arrays.toString(ores)); + return Objects.requireNonNull( + OreManager.getStack(info, 1), + "getLayerOre: " + veinLayer + ", " + stoneType + ", " + Arrays.toString(ores)); } } public boolean containsOre(IMaterial material) { - return ores[OreVeinLayer.VEIN_PRIMARY] == material - || ores[OreVeinLayer.VEIN_SECONDARY] == material + return ores[OreVeinLayer.VEIN_PRIMARY] == material || ores[OreVeinLayer.VEIN_SECONDARY] == material || ores[OreVeinLayer.VEIN_BETWEEN] == material || ores[OreVeinLayer.VEIN_SPORADIC] == material; } diff --git a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java index bfbef5eeff2..4a4a4b59e76 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java @@ -7,11 +7,11 @@ import java.util.Map; import java.util.Set; +import net.minecraft.item.ItemStack; + import com.google.common.collect.Multimap; import com.google.common.collect.MultimapBuilder; -import net.minecraft.item.ItemStack; - import gregtech.api.GregTechAPI; import gregtech.api.enums.SmallOres; import gregtech.api.enums.StoneType; @@ -39,7 +39,9 @@ public static void init() { smallOreDefMap.put(ore.smallOreBuilder.smallOreName, ore.smallOreBuilder); } - Multimap oreSpawning = MultimapBuilder.hashKeys().arrayListValues().build(); + Multimap oreSpawning = MultimapBuilder.hashKeys() + .arrayListValues() + .build(); OreInfo info = OreInfo.getNewInfo(); @@ -54,7 +56,8 @@ public static void init() { SMALL_ORES_BY_MAT.put(smallOreWorldGen.mMaterial, wrapper); if (ORE_MAT_TO_DROPS.containsKey(smallOreWorldGen.mMaterial)) { - throw new IllegalStateException("Duplicate small ore world gen for material " + smallOreWorldGen.mMaterial); + throw new IllegalStateException( + "Duplicate small ore world gen for material " + smallOreWorldGen.mMaterial); } for (String abbrDimName : wrapper.enabledDims) { @@ -87,7 +90,8 @@ public static void init() { SMALL_ORES_BY_DIM.get(e.getKey()).smallOres.add(e.getValue()); } - SMALL_ORES_BY_DIM.values().forEach(SmallOreDimensionWrapper::calculateWeights); + SMALL_ORES_BY_DIM.values() + .forEach(SmallOreDimensionWrapper::calculateWeights); } public static class OreSmallWrapper { @@ -113,7 +117,7 @@ public OreSmallWrapper(SmallOreBuilder ore) { this.allowedDimWithOrigNames = ore.dimsEnabled; this.enabledDims = new HashSet<>(); - + for (String dimName : ore.dimsEnabled) { if (!ore.dimsEnabled.contains(dimName)) { continue; @@ -126,7 +130,7 @@ public OreSmallWrapper(SmallOreBuilder ore) { public List getOreVariants() { List oreVariants = new ArrayList<>(); - try(OreInfo info = OreInfo.getNewInfo()) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = material; info.isSmall = true; @@ -157,8 +161,7 @@ private void calculateWeights() { totalWeight += oreVein.amountPerChunk; } for (OreSmallWrapper oreVein : smallOres) { - oreVeinProbabilities - .put(oreVein, ((double) oreVein.amountPerChunk) / ((double) totalWeight)); + 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 45b158886c6..ba2f9e1812f 100644 --- a/src/main/java/gtneioreplugin/util/Oremix.java +++ b/src/main/java/gtneioreplugin/util/Oremix.java @@ -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.contains(DimensionHelper.DimNameDisplayed[i])); + 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 ea0ae7a0bdd..8e8efa0e026 100644 --- a/src/main/java/gtneioreplugin/util/SmallOre.java +++ b/src/main/java/gtneioreplugin/util/SmallOre.java @@ -2,7 +2,6 @@ import static gtneioreplugin.util.DimensionHelper.DimNameDisplayed; -import java.util.Map; import java.util.Set; @SuppressWarnings("unused") 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 8fa8983cc27..0012ecfbd61 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java @@ -399,12 +399,14 @@ private static boolean setBlock(ItemStack stack, int x, int y, int z, World worl if (p != null) { try (OreInfo info = p.right()) { info.isNatural = true; - - var oreBlock = p.left().getBlock(info); - + + var oreBlock = p.left() + .getBlock(info); + world.setBlock(x, y, z, oreBlock.left(), oreBlock.rightInt(), 3); - if (world.getBlock(x, y, z) == oreBlock.left() && world.getBlockMetadata(x, y, z) == oreBlock.rightInt()) return true; + if (world.getBlock(x, y, z) == oreBlock.left() + && world.getBlockMetadata(x, y, z) == oreBlock.rightInt()) return true; } } diff --git a/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java b/src/main/java/tectech/recipe/EyeOfHarmonyRecipe.java index ffdf2020ccf..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) -> { - if (veinInfo.mPrimaryVeinMaterial instanceof Materials gtMat) processHelper(outputMap, gtMat, mainMultiplier, probability); - if (veinInfo.mSecondaryMaterial instanceof Materials gtMat) processHelper(outputMap, gtMat, 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. - 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); + 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.oreVeinProbabilities.forEach((veinInfo, probability) -> { - if (veinInfo.material instanceof Materials gtMat) processHelper(outputMap, gtMat, mainMultiplier, probability); - }); + smallOreDimWrapper.oreVeinProbabilities.forEach( + (veinInfo, probability) -> { + if (veinInfo.material instanceof Materials gtMat) + processHelper(outputMap, gtMat, mainMultiplier, probability); + }); } ArrayList> outputList = new ArrayList<>(); From ab7aaf681d4d2b8e54088f4c1429b05c50b7fdad Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Tue, 17 Dec 2024 14:15:01 -0500 Subject: [PATCH 19/47] misc cleanup from checking the code --- .../java/gregtech/common/GTWorldgenerator.java | 15 +++------------ .../java/gregtech/common/WorldgenGTOreLayer.java | 2 +- .../common/misc/DrillingLogicDelegate.java | 2 ++ .../multi/processing/MTEIndustrialWashPlant.java | 1 - .../gtneioreplugin/util/GT5OreSmallHelper.java | 1 - 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index a138b3f97e0..93e0b392fcb 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -28,7 +28,6 @@ import galacticgreg.api.Enums.DimensionType; import galacticgreg.api.ModDimensionDef; import galacticgreg.api.enums.DimensionDef; -import galacticgreg.api.enums.DimensionDef.DimNames; import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.GTValues; @@ -42,7 +41,6 @@ public class GTWorldgenerator implements IWorldGenerator { private static final int MAX_VEIN_SIZE = 2; // in chunks - private static final int END_ASTEROID_DISTANCE = 16; // in chunks public static List pendingTasks = Collections.synchronizedList(new LinkedList<>()); @@ -77,13 +75,6 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide ModDimensionDef def = DimensionDef.getDefForWorld(aWorld); - if (def.getDimensionName() - .equals(DimNames.THE_END)) { - if (aX * aX + aZ * aZ > END_ASTEROID_DISTANCE * END_ASTEROID_DISTANCE) { - def = DimensionDef.EndAsteroids.modDimensionDef; - } - } - if (def == null || def.getDimensionType() != DimensionType.Planet) { return; } @@ -337,7 +328,7 @@ public void generateVein(int oreseedX, int oreseedZ) { WorldgenGTOreLayer tWorldGen = validOreveins.get(oreveinSeed); // Reset RNG to only be based on oreseed X/Z and type of vein - oreveinRNG.setSeed(oreveinSeed ^ tWorldGen.mPrimary.hashCode()); + oreveinRNG.setSeed(oreveinSeed ^ tWorldGen.mPrimary.getId()); int placementResult = tWorldGen.executeWorldgenChunkified( this.mWorld, @@ -440,7 +431,7 @@ public void generateVein(int oreseedX, int oreseedZ) { if (debugOrevein) GTLog.out.println( " Added far oreveinSeed=" + oreveinSeed + " " - + (oreLayer).mWorldGenName + + oreLayer.mWorldGenName + " tries at oremix=" + i + " placementAttempts=" @@ -454,7 +445,7 @@ public void generateVein(int oreseedX, int oreseedZ) { if (debugOrevein) GTLog.out.println( " No overlap and air block in test spot=" + oreveinSeed + " " - + (oreLayer).mWorldGenName + + oreLayer.mWorldGenName + " tries at oremix=" + i + " placementAttempts=" diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 33a63e5d19c..249d7d6ed89 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -391,7 +391,7 @@ private void generateLayer(boolean secondary, boolean between, boolean primary) } if (rng.nextInt(7) == 0 && (rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) - && mSporadic != null) { // Sporadics are reduce by 1/7 to compensate + && mSporadic != null) { // Sporadics are reduced by 1/7 to compensate if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mSporadic, false)) { placeCount[3]++; } diff --git a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java index e1d8f57fcdc..13e6def449b 100644 --- a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java +++ b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java @@ -161,6 +161,7 @@ public void mineBlock(IGregTechTileEntity te, Block block, int x, int y, int z) return; } + // see if we can store all of the outputs List drops = OreManager.mineBlock(te.getWorld(), x, y, z, owner.getMachineTier(), true, true); for (ItemStack drop : drops) { @@ -173,6 +174,7 @@ public void mineBlock(IGregTechTileEntity te, Block block, int x, int y, int z) owner.pushOutputs(drop, drop.stackSize, false, false); } + // actually mine it OreManager.mineBlock(te.getWorld(), x, y, z, owner.getMachineTier(), false, true); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java index 9087eb5ed72..2533249734a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java @@ -303,7 +303,6 @@ public boolean checkForWater() { for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { for (int h = 0; h < 2; ++h) { Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - int tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == Blocks.water) { if (this.getStoredFluids() != null) { for (FluidStack stored : this.getStoredFluids()) { diff --git a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java index 4a4a4b59e76..0720e019ce5 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java @@ -46,7 +46,6 @@ public static void init() { OreInfo info = OreInfo.getNewInfo(); for (GTWorldgen worldGen : GregTechAPI.sWorldgenList) { - if (!worldGen.mWorldGenName.startsWith("ore.small.")) continue; if (!(worldGen instanceof WorldgenGTOreSmallPieces smallOreWorldGen)) continue; IMaterial material = smallOreWorldGen.mMaterial; From 4ff1fe72f6d3e7343fd3702d9dce9c80bdf66d2b Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Wed, 18 Dec 2024 20:49:14 -0500 Subject: [PATCH 20/47] optimize stonegen --- src/main/java/gregtech/common/WorldgenStone.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/common/WorldgenStone.java b/src/main/java/gregtech/common/WorldgenStone.java index 0211350eb53..600834d4828 100644 --- a/src/main/java/gregtech/common/WorldgenStone.java +++ b/src/main/java/gregtech/common/WorldgenStone.java @@ -263,15 +263,9 @@ 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) - Block tTargetedBlock = aWorld.getBlock(iX, iY, iZ); - - if (OreManager.setExistingOreStoneType(aWorld, iX, iY, iZ, stoneType)) { - continue; - } - if (!this.mAllowToGenerateinVoid && aWorld.isAirBlock(iX, iY, iZ)) continue; - if (tTargetedBlock == null) continue; + Block tTargetedBlock = aWorld.getBlock(iX, iY, iZ); // spotless:off if ( tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.stone) || @@ -282,8 +276,13 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int 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; + } } } } From 0aa0d7ee8a0619cdcc7537267e7cad433ea8d1c5 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 03:42:30 -0500 Subject: [PATCH 21/47] bw ore oredict + fix macerator recipes --- .../loaders/StaticRecipeChangeLoaders.java | 2 +- .../EventHandler/ServerEventHandler.java | 2 +- .../system/material/BWMetaGeneratedOres.java | 22 ++++++--- .../bartworks/system/material/Werkstoff.java | 8 ++-- .../system/material/WerkstoffLoader.java | 11 ++--- .../gregtech/common/ores/BWOreAdapter.java | 47 ++++++++++++------- 6 files changed, 57 insertions(+), 35 deletions(-) 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/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/BWMetaGeneratedOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java index 588540e7e55..ff2d4958fc3 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -32,7 +32,6 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; - import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IBlockWithTextures; @@ -40,6 +39,7 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GTLanguageManager; import gregtech.api.util.GTModHandler; +import gregtech.api.util.GTOreDictUnificator; import gregtech.common.ores.BWOreAdapter; import gregtech.common.ores.OreInfo; import gregtech.common.render.GTRendererBlock; @@ -68,18 +68,26 @@ public BWMetaGeneratedOres(String blockName, StoneType stoneType, boolean small, OrePrefixes.ore.mLocalizedMaterialPre + "%material" + OrePrefixes.ore.mLocalizedMaterialPost); } - Werkstoff.werkstoffHashSet.forEach(this::doRegistrationStuff); - this.stoneType = stoneType; this.isSmall = small; this.isNatural = natural; } + public void registerOredict() { + Werkstoff.werkstoffHashSet.forEach(this::doRegistrationStuff); + } + protected void doRegistrationStuff(Werkstoff w) { - if (w != null) { - if (!w.hasItemType(OrePrefixes.ore) || (w.getGenerationFeatures().blacklist & 0b1000) != 0) return; - GTModHandler.addValuableOre(this, w.getmID(), 1); - } + if (w == null) return; + if (!w.hasItemType(OrePrefixes.ore)) return; + if ((w.getGenerationFeatures().blacklist & 0b1000) != 0) return; + + GTModHandler.addValuableOre(this, w.getmID(), 1); + + ItemStack self = new ItemStack(this, 1, w.getmID()); + OrePrefixes prefix = isSmall ? OrePrefixes.oreSmall : OrePrefixes.ore; + + GTOreDictUnificator.registerOre(prefix + w.getVarName(), self); } @Override diff --git a/src/main/java/bartworks/system/material/Werkstoff.java b/src/main/java/bartworks/system/material/Werkstoff.java index a111b56690e..41b7beb6f80 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -89,7 +89,7 @@ public class Werkstoff implements IColorModulationContainer, ISubTagContainer, I .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<>(); @@ -398,12 +398,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 HashSet getAdditionalOredict() { + return this.additionalOredict; } public void setTCAspects(Pair... pAspectsArr) { diff --git a/src/main/java/bartworks/system/material/WerkstoffLoader.java b/src/main/java/bartworks/system/material/WerkstoffLoader.java index 41c454f5731..043def2006a 100644 --- a/src/main/java/bartworks/system/material/WerkstoffLoader.java +++ b/src/main/java/bartworks/system/material/WerkstoffLoader.java @@ -2060,11 +2060,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))); } @@ -2074,11 +2072,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))) @@ -2086,5 +2084,6 @@ private static void runAdditionalOreDict() { } GTOreDictUnificator.registerOre("craftingIndustrialDiamond", WerkstoffLoader.CubicZirconia.get(gemExquisite)); + BWOreAdapter.INSTANCE.registerOredict(); } } diff --git a/src/main/java/gregtech/common/ores/BWOreAdapter.java b/src/main/java/gregtech/common/ores/BWOreAdapter.java index 46a7d168fb7..eb4637af6f2 100644 --- a/src/main/java/gregtech/common/ores/BWOreAdapter.java +++ b/src/main/java/gregtech/common/ores/BWOreAdapter.java @@ -49,6 +49,13 @@ public Ores(StoneType stoneType, String bigSuffix, String smallSuffix) { .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) { @@ -90,6 +97,10 @@ public void init() { }); } + public void registerOredict() { + ores.values().forEach(Ores::registerOredict); + } + @Override public boolean supports(Block block, int meta) { return block instanceof BWMetaGeneratedOres; @@ -244,28 +255,32 @@ public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropM } } case UnifiedBlock -> { - OreInfo info2 = info.clone(); - - for (int i = 0; i < (info.stoneType.isRich() ? 2 : 1); i++) { - info.stoneType = StoneType.Stone; - drops.add(getStack(info, 1)); + 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)); + } } - - info2.release(); } case PerDimBlock -> { - OreInfo info2 = info.clone(); - - if (!info.stoneType.isDimensionSpecific()) { - info2.stoneType = StoneType.Stone; + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + if (!info2.stoneType.isDimensionSpecific()) { + info2.stoneType = StoneType.Stone; + } + + drops.add(getStack(info2, 1)); } - - drops.add(getStack(info, 1)); - - info2.release(); } case Block -> { - drops.add(getStack(info, 1)); + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + drops.add(getStack(info2, 1)); + } } } From a7e3d28a31b0d2f1bdd0a1720442ca31f3ac8d59 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 03:46:48 -0500 Subject: [PATCH 22/47] misc asteroid & stone fixes --- .../java/galacticgreg/SpaceDimRegisterer.java | 13 +- .../galacticgreg/WorldGeneratorSpace.java | 135 +++++++------- .../java/galacticgreg/api/BlockMetaComb.java | 4 +- .../galacticgreg/api/ModDimensionDef.java | 8 + .../galacticgreg/api/enums/DimensionDef.java | 32 +++- .../properties/AsteroidPropertyBuilder.java | 59 +++--- .../api/enums/properties/Asteroids.java | 47 ++--- .../galacticgreg/command/WorldgenCommand.java | 6 +- .../dynconfig/DynamicDimensionConfig.java | 18 +- src/main/java/gregtech/GTMod.java | 2 + src/main/java/gregtech/api/enums/Mods.java | 7 +- .../java/gregtech/api/enums/StoneType.java | 170 +++++++++++------- .../gregtech/api/interfaces/IStoneType.java | 4 +- .../gregtech/common/GTWorldgenerator.java | 4 +- .../gregtech/common/WorldgenGTOreLayer.java | 15 +- .../gregtech/common/ores/GTOreAdapter.java | 36 ++-- .../java/gregtech/common/ores/OreManager.java | 10 +- 17 files changed, 312 insertions(+), 258 deletions(-) diff --git a/src/main/java/galacticgreg/SpaceDimRegisterer.java b/src/main/java/galacticgreg/SpaceDimRegisterer.java index b21c1315445..be9e002d3d4 100644 --- a/src/main/java/galacticgreg/SpaceDimRegisterer.java +++ b/src/main/java/galacticgreg/SpaceDimRegisterer.java @@ -1,13 +1,14 @@ package galacticgreg; import net.minecraft.init.Blocks; - +import cpw.mods.fml.common.registry.GameRegistry; import galacticgreg.api.Enums; 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; /** @@ -33,15 +34,15 @@ 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(StoneType.Netherrack); - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(StoneType.RedGranite); - DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); 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); diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 5e29cb409b7..4bb27d200f4 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -23,7 +23,6 @@ import galacticgreg.api.ModDimensionDef; import galacticgreg.api.SpecialBlockComb; import galacticgreg.api.enums.DimensionDef; -import galacticgreg.api.enums.DimensionDef.DimNames; import galacticgreg.dynconfig.DynamicDimensionConfig; import galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; import gregtech.GTMod; @@ -41,22 +40,13 @@ public WorldGeneratorSpace() { GameRegistry.registerWorldGenerator(this, Integer.MAX_VALUE); } - private static final int END_ASTEROID_DISTANCE = 16; - @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { GalacticGreg.Logger.trace("Triggered generate: [Dimension %s]", world.provider.getDimensionName()); - ModDimensionDef tDimDef = DimensionDef.getDefForWorld(world); - - if (tDimDef.getDimensionName() - .equals(DimNames.THE_END)) { - if (chunkX * chunkX + chunkZ * chunkZ > END_ASTEROID_DISTANCE * END_ASTEROID_DISTANCE) { - tDimDef = DimensionDef.EndAsteroids.modDimensionDef; - } - } + ModDimensionDef tDimDef = DimensionDef.getDefForWorld(world, chunkX, chunkZ); if (tDimDef == null) { GalacticGreg.Logger.trace( @@ -89,7 +79,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP long post = System.nanoTime(); if (profileWorldGen) - GTMod.GT_FML_LOGGER.info("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3); + GTMod.GT_FML_LOGGER.info(String.format("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3)); Chunk tChunk = world.getChunkFromBlockCoords(chunkX, chunkZ); if (tChunk != null) { @@ -101,17 +91,17 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP public static class AsteroidGenerator { public List positive, negative; - public int seedChunkX, seedChunkZ, cX, cY, cZ, radius; + public int seedChunkX, seedChunkZ, cX, cY, cZ, radius, size; public long seed; public StoneType stoneType; public transient IWorldgenLayer ore; public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedChunkZ) { - ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world); + ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world, seedChunkX, seedChunkZ); AsteroidConfig asteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); - if (!asteroidConfig.Enabled) return null; + if (asteroidConfig == null || !asteroidConfig.Enabled) return null; if (!generatesAsteroid( world.getSeed(), @@ -122,10 +112,9 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh XSTR rng = getRandom(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId); - AsteroidBlockComb asteroidStone = dimensionDef.getRandomAsteroidMaterial(rng); + AsteroidBlockComb asteroidStone = dimensionDef.getRandomAsteroidMaterial(rng.clone()); if (asteroidStone == null) return null; - int minY, maxY; IWorldgenLayer oreLayer; if (rng.nextInt(5) == 0) { @@ -135,9 +124,6 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh asteroidStone.getStone() .getCategory()) .find(rng.clone()); - - minY = oreLayer == null ? 50 : oreLayer.getMinY(); - maxY = oreLayer == null ? 200 : oreLayer.getMaxY(); } else { oreLayer = WorldgenQuery.veins() .inDimension(dimensionDef) @@ -145,13 +131,13 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh asteroidStone.getStone() .getCategory()) .find(rng.clone()); - - minY = oreLayer == null ? 50 : oreLayer.getMinY(); - maxY = oreLayer == null ? 200 : oreLayer.getMaxY(); } if (oreLayer == null) return null; + int minY = oreLayer.getMinY(); + int maxY = oreLayer.getMaxY(); + GalacticGreg.Logger.debug( "Asteroid will be built with: Stone: [%s] Ore: [%s]", asteroidStone.getStone(), @@ -164,27 +150,31 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh List positive = new ArrayList<>(); List negative = new ArrayList<>(); - int radius = (asteroidConfig.MinSize + rng.nextInt(asteroidConfig.MinSize - asteroidConfig.MaxSize + 1)); + int radius = asteroidConfig.MinSize + rng.nextInt(asteroidConfig.MinSize - asteroidConfig.MaxSize + 1); positive.add(new Ellipsoid(0, 0, 0, radius)); - 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))); + 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))); + } } - k = rng.nextInt(2); - 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))); + 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))); + } } AsteroidGenerator gen = new AsteroidGenerator(); @@ -198,7 +188,8 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh gen.cX = tX; gen.cY = tY; gen.cZ = tZ; - gen.radius = radius * 2; + gen.radius = radius; + gen.size = radius * 2; gen.seed = rng.nextLong(); @@ -209,26 +200,26 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh } public boolean affectsChunk(int chunkX, int chunkZ) { - int minX = (cX - radius) >> 4; - int maxX = (cX + radius + 1) >> 4; + int minX = (cX - size) >> 4; + int maxX = (cX + size + 1) >> 4; - int minZ = (cZ - radius) >> 4; - int maxZ = (cZ + radius + 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 - radius - 1); - int maxX = Math.min((chunkX + 1) * 16, cX + radius + 1); + 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 - radius - 1); - int maxY = Math.min(255, cY + radius + 1); + int minY = Math.max(0, cY - size - 1); + int maxY = Math.min(255, cY + size + 1); - int minZ = Math.max(chunkZ * 16, cZ - radius - 1); - int maxZ = Math.min((chunkZ + 1) * 16, cZ + radius + 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); + ModDimensionDef def = DimensionDef.getDefForWorld(world, seedChunkX, seedChunkZ); AsteroidConfig dimAsteroidConfig = DynamicDimensionConfig.getAsteroidConfig(def); for (int y = minY; y < maxY; y++) { @@ -269,6 +260,7 @@ public void generateChunk(World world, int chunkX, int chunkZ) { if (ore.generatesBigOre()) { if (!placedAnything) { placedAnything = generateOreBlock( + dimAsteroidConfig, rng2, world, x, @@ -276,8 +268,8 @@ public void generateChunk(World world, int chunkX, int chunkZ) { z, stoneType, ore, - false, - radius / 4 < 15 ? rng2.nextFloat() : dist); + radius < 5 ? rng2.nextFloat() : dist, + dist); } } @@ -298,7 +290,8 @@ public void generateChunk(World world, int chunkX, int chunkZ) { // try to place small ores if (!placedAnything) { - placedAnything = generateOreBlock( + placedAnything = generateSmallOreBlock( + dimAsteroidConfig, rng2, world, x, @@ -306,7 +299,6 @@ public void generateChunk(World world, int chunkX, int chunkZ) { z, stoneType, ore, - true, rng2.nextFloat()); } @@ -329,12 +321,18 @@ public void generateChunk(World world, int chunkX, int chunkZ) { 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 || radius < 6) return; + if (asteroidConfig.LootChestChance == 0 || size < 6) return; GalacticGreg.Logger.trace("Random loot chest enabled, flipping the coin"); @@ -447,7 +445,7 @@ private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Rando }; if (validLocation) { - world.setBlock(x, y, z, bmc.getBlock(), bmc.getMeta(), 2); + world.setBlock(x, y, z, bmc.getBlock(), bmc.getMeta(), 3); return true; } } @@ -457,13 +455,26 @@ private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Rando return false; } - private static boolean generateOreBlock(Random rng, World pWorld, int pX, int pY, int pZ, IStoneType stoneType, - IWorldgenLayer oreLayer, boolean small, float control) { - if (rng.nextFloat() <= oreLayer.getDensity()) { + 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) { + IMaterial mat = oreLayer.getOre(control); + + if (mat != null) { + return OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, false); + } + } + + return false; + } + + 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) { IMaterial mat = oreLayer.getOre(control); if (mat != null) { - return OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, small); + return OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, true); } } diff --git a/src/main/java/galacticgreg/api/BlockMetaComb.java b/src/main/java/galacticgreg/api/BlockMetaComb.java index 47a1ced4f32..772ebbe5a67 100644 --- a/src/main/java/galacticgreg/api/BlockMetaComb.java +++ b/src/main/java/galacticgreg/api/BlockMetaComb.java @@ -1,5 +1,7 @@ package galacticgreg.api; +import java.util.Objects; + import net.minecraft.block.Block; /** @@ -27,7 +29,7 @@ public BlockMetaComb(Block pBlock) { */ public BlockMetaComb(Block pBlock, int pMeta) { mMeta = pMeta; - mBlock = pBlock; + mBlock = Objects.requireNonNull(pBlock); } /** diff --git a/src/main/java/galacticgreg/api/ModDimensionDef.java b/src/main/java/galacticgreg/api/ModDimensionDef.java index 5ad376e304a..e44e2685cdb 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -39,6 +39,8 @@ public class ModDimensionDef { private final Random random = new Random(System.currentTimeMillis()); + public boolean hasEoHRecipe = true; + /** * Define a new dimension * @@ -376,4 +378,10 @@ public void finalizeReplaceableBlocks(String pParentModName) { rpb.updateBlockName(pParentModName); } } + + public ModDimensionDef disableEoHRecipe() { + hasEoHRecipe = false; + + return this; + } } diff --git a/src/main/java/galacticgreg/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index 767d08a7dcd..a9ba966a35f 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -40,7 +40,8 @@ public enum DimensionDef { DimNames.EVERGLADES, ChunkProviderModded.class, DimensionType.Planet) - .setOreVeinChance(66)), + .setOreVeinChance(66) + .disableEoHRecipe()), Moon(new ModDimensionDef( @@ -60,11 +61,13 @@ public enum DimensionDef { Ross128b(new ModDimensionDef( DimNames.ROSS128B, "bwcrossmod.galacticraft.planets.ross128b.ChunkProviderRoss128b", - Enums.DimensionType.Planet)), + Enums.DimensionType.Planet) + .disableEoHRecipe()), Ross128ba(new ModDimensionDef( DimNames.ROSS128BA, "bwcrossmod.galacticraft.planets.ross128ba.ChunkProviderRoss128ba", - Enums.DimensionType.Planet)), + Enums.DimensionType.Planet) + .disableEoHRecipe()), Pluto(new ModDimensionDef( DimNames.PLUTO, "galaxyspace.SolarSystem.planets.pluto.dimension.ChunkProviderPluto", @@ -218,7 +221,13 @@ public enum DimensionDef { MehenBelt(new ModDimensionDef( DimNames.MEHENBELT, "de.katzenpapst.amunra.world.mehen.MehenChunkProvider", - Enums.DimensionType.Asteroid)); + Enums.DimensionType.Asteroid)), + + DeepDark(new ModDimensionDef( + DimNames.DEEPDARK, + "", + Enums.DimensionType.Planet)), + ; // spotless:on public final ModDimensionDef modDimensionDef; @@ -227,7 +236,7 @@ public enum DimensionDef { this.modDimensionDef = modDimDef; } - private static final Map DEF_BY_WORLD_NAME = new HashMap<>(); + public static final Map DEF_BY_WORLD_NAME = new HashMap<>(); static { for (DimensionDef def : values()) { @@ -235,8 +244,17 @@ public enum DimensionDef { } } - public static ModDimensionDef getDefForWorld(World world) { - return DEF_BY_WORLD_NAME.get(world.provider.getDimensionName()); + public static ModDimensionDef getDefForWorld(World world, int chunkX, int chunkZ) { + ModDimensionDef def = DEF_BY_WORLD_NAME.get(world.provider.getDimensionName()); + + if (def.getDimensionName() + .equals(DimNames.THE_END)) { + if (chunkX * chunkX + chunkZ * chunkZ > 16 * 16) { + def = DimensionDef.EndAsteroids.modDimensionDef; + } + } + + return def; } public static class DimNames { diff --git a/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java b/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java index b6c9f9be4e3..c3cef9baa0e 100644 --- a/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java +++ b/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java @@ -6,43 +6,10 @@ public class AsteroidPropertyBuilder { 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 obeyHeightLimits; - public boolean oresOnlyInsideAsteroids; - public int primaryToRareOreOffset; - public int smallOreChance; - - public OreSpawnPropertyBuilder baseOreChance(int baseOreChance) { - this.baseOreChance = baseOreChance; - return this; - } - - public OreSpawnPropertyBuilder doesObeyingHeightLimits(boolean obeyHeightLimits) { - this.obeyHeightLimits = obeyHeightLimits; - 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 static class LootPropertyBuilder { @@ -74,7 +41,6 @@ public LootPropertyBuilder isLootItemCountRandomized(boolean randomizeLootItemCo } public AsteroidPropertyBuilder() { - oreSpawn = new OreSpawnPropertyBuilder(); loot = new LootPropertyBuilder(); } @@ -99,8 +65,23 @@ 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; } diff --git a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java index e060b27b5d6..18850f86c60 100644 --- a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java +++ b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java @@ -5,65 +5,50 @@ public enum Asteroids { - // spotless : off + // 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(10) + 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(10) + 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) .loot( new AsteroidPropertyBuilder.LootPropertyBuilder().lootChestChance(1) .lootChestItemCount(10) .lootChestTable(3) .isLootItemCountRandomized(true))), - Asteroids(ModContainers.GalacticraftMars, DimensionDef.Asteroids, new AsteroidPropertyBuilder().probability(10) + 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/command/WorldgenCommand.java b/src/main/java/galacticgreg/command/WorldgenCommand.java index 5b61fc9f3a7..c2a29610426 100644 --- a/src/main/java/galacticgreg/command/WorldgenCommand.java +++ b/src/main/java/galacticgreg/command/WorldgenCommand.java @@ -5,6 +5,7 @@ import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; @@ -45,7 +46,7 @@ public void processCommand(ICommandSender pCommandSender, String[] pArgs) { int chunkX = pCommandSender.getPlayerCoordinates().posX >> 4; int chunkZ = pCommandSender.getPlayerCoordinates().posZ >> 4; - ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world); + ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world, chunkX, chunkZ); AsteroidConfig asteroidConfig = DynamicDimensionConfig.getAsteroidConfig(dimensionDef); switch (pArgs[0]) { @@ -102,9 +103,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/dynconfig/DynamicDimensionConfig.java b/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java index a11c124d406..df82d16d766 100644 --- a/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java +++ b/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java @@ -20,12 +20,12 @@ public static class AsteroidConfig { public int MinSize; public int MaxSize; public int Probability; + public int PositiveEllipsoids; + public int NegativeEllipsoids; + 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; @@ -85,14 +85,12 @@ public static boolean InitDynamicConfig() { 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.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.obeyHeightLimits; - 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/gregtech/GTMod.java b/src/main/java/gregtech/GTMod.java index a52a9c2013c..b731c4efea2 100644 --- a/src/main/java/gregtech/GTMod.java +++ b/src/main/java/gregtech/GTMod.java @@ -58,6 +58,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; @@ -443,6 +444,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/enums/Mods.java b/src/main/java/gregtech/api/enums/Mods.java index 366ee45eb0b..822e2c27e55 100644 --- a/src/main/java/gregtech/api/enums/Mods.java +++ b/src/main/java/gregtech/api/enums/Mods.java @@ -110,7 +110,12 @@ 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), diff --git a/src/main/java/gregtech/api/enums/StoneType.java b/src/main/java/gregtech/api/enums/StoneType.java index 16fcfecd881..02571ae86af 100644 --- a/src/main/java/gregtech/api/enums/StoneType.java +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -8,8 +8,10 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.function.Supplier; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.TextureMap; @@ -23,6 +25,7 @@ import com.google.common.collect.ImmutableList; import cpw.mods.fml.common.registry.GameRegistry; +import galacticgreg.api.enums.DimensionDef.DimNames; import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.Textures.BlockIcons; @@ -33,42 +36,43 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; +import gregtech.api.util.Lazy; import it.unimi.dsi.fastutil.objects.ObjectIntPair; public enum StoneType implements IStoneType { // spotless:off Stone(new StoneBuilder() - .setCobble(Blocks.cobblestone, 0) - .setMainStone(Blocks.stone, 0) + .setCobble(() -> Blocks.cobblestone, 0) + .setMainStone(() -> Blocks.stone, 0) .setDust(Materials.Stone)), Netherrack(new StoneBuilder() .setPrefix(OrePrefixes.oreNetherrack) - .setStoneNoCobble(Blocks.netherrack, 0) + .setStoneNoCobble(() -> Blocks.netherrack, 0) .setDust(Materials.Netherrack)), Endstone(new StoneBuilder() .setPrefix(OrePrefixes.oreEndstone) - .setStoneNoCobble(Blocks.end_stone, 0) + .setStoneNoCobble(() -> Blocks.end_stone, 0) .setDust(Materials.Endstone)), BlackGranite(new StoneBuilder() .setPrefix(OrePrefixes.oreBlackgranite) - .setCobble(GregTechAPI.sBlockGranites, 1) - .setMainStone(GregTechAPI.sBlockGranites, 0) + .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) + .setCobble(() -> GregTechAPI.sBlockGranites, 9) + .setMainStone(() -> GregTechAPI.sBlockGranites, 8) .setDust(Materials.GraniteRed)), Marble(new StoneBuilder() .setPrefix(OrePrefixes.oreMarble) - .setCobble(GregTechAPI.sBlockGranites, 1) - .setMainStone(GregTechAPI.sBlockGranites, 0) + .setCobble(() -> GregTechAPI.sBlockStones, 1) + .setMainStone(() -> GregTechAPI.sBlockStones, 0) .setDust(Materials.Marble)), Basalt(new StoneBuilder() .setPrefix(OrePrefixes.oreBasalt) - .setCobble(GregTechAPI.sBlockGranites, 9) - .setMainStone(GregTechAPI.sBlockGranites, 8) + .setCobble(() -> GregTechAPI.sBlockStones, 9) + .setMainStone(() -> GregTechAPI.sBlockStones, 8) .setDust(Materials.Basalt)), Moon(new StoneBuilder() .setStoneNoCobble(GalacticraftCore, "tile.moonBlock", 4) @@ -85,7 +89,7 @@ public enum StoneType implements IStoneType { Deimos(StoneBuilder.galaxySpace("Deimos", 1)), Ceres(StoneBuilder.galaxySpace("Ceres", 1)), Io(StoneBuilder.galaxySpace("Io", 2)), - Europa(StoneBuilder.galaxySpace("Europa", 1)), + Europa(StoneBuilder.galaxySpace("Europa", "grunt", 1)), Ganymede(StoneBuilder.galaxySpace("Ganymede", 1)), Callisto(StoneBuilder.galaxySpace("Callisto", 1)), Enceladus(StoneBuilder.galaxySpace("Enceladus", 1, 3)), @@ -109,15 +113,16 @@ public enum StoneType implements IStoneType { .setStoneNoCobble(GalaxySpace, "barnardaFsubgrunt", 0) .setCoremodDust("BarnardaF")), Horus(new StoneBuilder() - .setStoneNoCobble(Blocks.obsidian, 0) + .setStoneNoCobble(() -> Blocks.obsidian, 0) .addOtherStone(GalacticraftAmunRa, "tile.baseFalling", 0) + .addAllowedDimensions(DimNames.HORUS) .setDust(Materials.Obsidian)), Anubis(new StoneBuilder() .setCobble(GalacticraftAmunRa, "tile.baseBlockRock", 0) .setMainStone(GalacticraftAmunRa, "tile.baseBlockRock", 1) .setDust(Materials.Basalt)), PackedIce(new StoneBuilder() - .setStoneNoCobble(Blocks.packed_ice, 0) + .setStoneNoCobble(() -> Blocks.packed_ice, 0) .setDust(Materials.Ice) .setCategory(StoneCategory.Ice)), @@ -146,9 +151,25 @@ 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(Lazy::get); + + ItemStack pure = builder.pureDust.get(); + if (builder.impureDust.get() == null) { + builder.impureDust.set(pure.copy()); + } + } + } + @Override public ItemStack getDust(boolean pure, int amount) { - return GTUtility.copyAmount(amount, pure ? builder.pureDust : builder.impureDust); + return GTUtility.copyAmount(amount, pure ? builder.pureDust.get() : builder.impureDust.get()); } @Override @@ -163,12 +184,12 @@ public IStoneCategory getCategory() { @Override public ObjectIntPair getCobblestone() { - return ObjectIntPair.of(builder.cobble.block, builder.cobble.meta); + return builder.cobble.get().toPair(); } @Override public ObjectIntPair getStone() { - return ObjectIntPair.of(builder.mainStone.block, builder.mainStone.meta); + return builder.mainStone.get().toPair(); } @Override @@ -217,7 +238,11 @@ public IIcon getIcon(int side) { case RedGranite -> BlockIcons.GRANITE_RED_STONE.getIcon(); case Marble -> BlockIcons.MARBLE_STONE.getIcon(); case Basalt -> BlockIcons.BASALT_STONE.getIcon(); - default -> builder.mainStone.block.getIcon(side, builder.mainStone.meta); + default -> { + BlockMeta main = builder.mainStone.get(); + + yield main.block.getIcon(side, main.meta); + } }; } @@ -254,17 +279,26 @@ public boolean isEnabled() { @Override public boolean contains(Block block, int meta) { - if (block == builder.mainStone.block && meta == builder.mainStone.meta) return true; + BlockMeta main = builder.mainStone.get(); + + if (block == main.block && meta == main.meta) return true; if (builder.otherStones != null) { - for (BlockMeta other : builder.otherStones) { - if (block == other.block && meta == other.meta) return true; + for (Lazy other : builder.otherStones) { + BlockMeta other2 = other.get(); + + if (block == other2.block && meta == other2.meta) return true; } } return false; } + @Override + public boolean canGenerateInWorld(World world) { + return builder.allowedDimensions == null || builder.allowedDimensions.contains(world.provider.getDimensionName()); + } + public static StoneType findStoneType(World world, int x, int y, int z) { return findStoneType(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); } @@ -284,21 +318,34 @@ private static class BlockMeta { public Block block; public int meta; + public BlockMeta(Mods mod, String blockName, int meta) { + this.block = GameRegistry.findBlock(mod.ID, blockName); + this.meta = meta; + + Objects.requireNonNull(block, "Could not find block " + mod.ID + ":" + blockName); + } + public BlockMeta(Block block, int meta) { this.block = block; this.meta = meta; } + + public ObjectIntPair toPair() { + return ObjectIntPair.of(block, meta); + } } private static class StoneBuilder { public boolean enabled = true; - public BlockMeta cobble, mainStone; - public List otherStones; + public Lazy cobble = new Lazy<>(() -> new BlockMeta(Blocks.air, 0)); + public Lazy mainStone = new Lazy<>(() -> new BlockMeta(Blocks.air, 0)); + public List> otherStones; public OrePrefixes oreBlockPrefix = OrePrefixes.ore; - public ItemStack pureDust = GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1); - public ItemStack impureDust = GTOreDictUnificator.get(OrePrefixes.dustImpure, Materials.Stone, 1); + public Lazy pureDust = new Lazy<>(() -> GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1)); + public Lazy impureDust = new Lazy<>(() -> 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); @@ -310,16 +357,16 @@ public static StoneBuilder galaxySpace(String name, String suffix, int mainStone .setCoremodDust(name); for (int extra : extraStones) { - builder.addOtherStone(GalaxySpace, name.toLowerCase() + "blocks", extra); + builder.addOtherStone(GalaxySpace, name.toLowerCase() + suffix, extra); } return builder; } - public StoneBuilder setCobble(Block block, int meta) { + public StoneBuilder setCobble(Supplier block, int meta) { Objects.requireNonNull(block); - cobble = new BlockMeta(block, meta); + cobble = new Lazy<>(() -> new BlockMeta(block.get(), meta)); return this; } @@ -327,12 +374,8 @@ public StoneBuilder setCobble(Block block, int meta) { public StoneBuilder setCobble(Mods owner, String blockName, int meta) { enabled &= owner.isModLoaded(); - Block block = GameRegistry.findBlock(owner.ID, blockName); - - if (block != null) { - cobble = new BlockMeta(block, meta); - } else { - cobble = null; + if (enabled) { + cobble = new Lazy<>(() -> new BlockMeta(owner, blockName, meta)); } return this; @@ -341,21 +384,15 @@ public StoneBuilder setCobble(Mods owner, String blockName, int meta) { public StoneBuilder setStoneNoCobble(Mods owner, String blockName, int meta) { enabled &= owner.isModLoaded(); - Block block = GameRegistry.findBlock(owner.ID, blockName); - - if (block != null) { - cobble = mainStone = new BlockMeta(block, meta); - } else { - cobble = mainStone = null; + if (enabled) { + cobble = mainStone = new Lazy<>(() -> new BlockMeta(owner, blockName, meta)); } return this; } - public StoneBuilder setStoneNoCobble(Block block, int meta) { - Objects.requireNonNull(block); - - cobble = mainStone = new BlockMeta(block, meta); + public StoneBuilder setStoneNoCobble(Supplier block, int meta) { + cobble = mainStone = new Lazy<>(() -> new BlockMeta(block.get(), meta)); return this; } @@ -363,31 +400,23 @@ public StoneBuilder setStoneNoCobble(Block block, int meta) { public StoneBuilder setMainStone(Mods owner, String blockName, int meta) { enabled &= owner.isModLoaded(); - Block block = GameRegistry.findBlock(owner.ID, blockName); - - if (block != null) { - mainStone = new BlockMeta(block, meta); - } else { - mainStone = null; + if (enabled) { + mainStone = new Lazy<>(() -> new BlockMeta(owner, blockName, meta)); } return this; } - public StoneBuilder setMainStone(Block block, int meta) { - Objects.requireNonNull(block); - - mainStone = new BlockMeta(block, meta); + public StoneBuilder setMainStone(Supplier block, int meta) { + mainStone = new Lazy<>(() -> new BlockMeta(block.get(), meta)); return this; } public StoneBuilder addOtherStone(Mods owner, String blockName, int meta) { - Block block = GameRegistry.findBlock(owner.ID, blockName); - - if (block != null) { + if (owner.isModLoaded()) { if (otherStones == null) otherStones = new ArrayList<>(); - otherStones.add(new BlockMeta(block, meta)); + otherStones.add(new Lazy<>(() -> new BlockMeta(owner, blockName, meta))); } return this; @@ -395,20 +424,19 @@ public StoneBuilder addOtherStone(Mods owner, String blockName, int meta) { public StoneBuilder setCoremodDust(String name) { if (NewHorizonsCoreMod.isModLoaded()) { - Item dust = GameRegistry.findItem(NewHorizonsCoreMod.ID, "item." + name + "StoneDust"); - pureDust = impureDust = new ItemStack( - Objects.requireNonNull(dust, "Could not find " + "item." + name + "StoneDust"), - 1); + pureDust = impureDust = new Lazy<>(() -> { + Item dust = GameRegistry.findItem(NewHorizonsCoreMod.ID, "item." + name + "StoneDust"); + Objects.requireNonNull(dust, "Could not find " + "item." + name + "StoneDust"); + return new ItemStack(dust, 1); + }); } return this; } public StoneBuilder setDust(Materials mat) { - pureDust = mat.getDust(1); - impureDust = GTOreDictUnificator.get(OrePrefixes.dustImpure, mat, 1); - - if (impureDust == null) impureDust = pureDust; + pureDust = new Lazy<>(() -> mat.getDust(1)); + impureDust = new Lazy<>(() -> GTOreDictUnificator.get(OrePrefixes.dustImpure, mat, 1)); return this; } @@ -424,5 +452,13 @@ public StoneBuilder setCategory(StoneCategory 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/interfaces/IStoneType.java b/src/main/java/gregtech/api/interfaces/IStoneType.java index 0416999fb5e..dbd6dffcde7 100644 --- a/src/main/java/gregtech/api/interfaces/IStoneType.java +++ b/src/main/java/gregtech/api/interfaces/IStoneType.java @@ -3,7 +3,7 @@ import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; - +import net.minecraft.world.World; import gregtech.api.enums.OrePrefixes; import it.unimi.dsi.fastutil.objects.ObjectIntPair; @@ -33,4 +33,6 @@ public interface IStoneType { public boolean isExtraneous(); public boolean isEnabled(); + + public boolean canGenerateInWorld(World world); } diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index 93e0b392fcb..46709faa98d 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -73,7 +73,7 @@ public GTWorldgenerator() { public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - ModDimensionDef def = DimensionDef.getDefForWorld(aWorld); + ModDimensionDef def = DimensionDef.getDefForWorld(aWorld, aX >> 4, aZ >> 4); if (def == null || def.getDimensionType() != DimensionType.Planet) { return; @@ -354,7 +354,7 @@ public void generateVein(int oreseedX, int oreseedZ) { return; } - ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(mWorld); + ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(mWorld, oreseedX, oreseedZ); if (oreveinPercentageRoll < dimensionDef.getOreVeinChance()) { int placementAttempts = 0; diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 249d7d6ed89..407ee31a627 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -19,7 +19,6 @@ import gregtech.api.interfaces.IStoneCategory; import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTLog; -import gregtech.api.util.GTUtility; import gregtech.api.world.GTWorldgen; import gregtech.common.ores.OreManager; import gregtech.common.worldgen.IWorldgenLayer; @@ -96,7 +95,7 @@ public float getSize() { @Override public float getDensity() { - return GTUtility.clamp(mDensity / 64.0f, 0f, 1f); + return 1f / (float) mDensity; } @Override @@ -357,14 +356,14 @@ private class LayerGenerator { private void generateLayer(boolean secondary, boolean between, boolean primary) { for (int tX = limitWestX; tX < limitEastX; tX++) { - int placeX = Math.max(1, Math.max(Math.abs(veinWestX - tX), Math.abs(veinEastX - tX)) / localDensity); + int chanceX = Math.max(1, Math.max(Math.abs(veinWestX - tX), Math.abs(veinEastX - tX)) / localDensity); for (int tZ = limitNorthZ; tZ < limitSouthZ; tZ++) { - int placeZ = Math + int chanceZ = Math .max(1, Math.max(Math.abs(veinSouthZ - tZ), Math.abs(veinNorthZ - tZ)) / localDensity); if (primary) { - if ((rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mPrimary != null) { + if ((rng.nextInt(chanceZ) == 0 || rng.nextInt(chanceX) == 0) && mPrimary != null) { if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mPrimary, false)) { placeCount[0]++; } @@ -373,7 +372,7 @@ private void generateLayer(boolean secondary, boolean between, boolean primary) } if (between) { - if ((rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mBetween != null) { + if ((rng.nextInt(chanceZ) == 0 || rng.nextInt(chanceX) == 0) && mBetween != null) { if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mBetween, false)) { placeCount[2]++; } @@ -382,7 +381,7 @@ private void generateLayer(boolean secondary, boolean between, boolean primary) } if (secondary) { - if ((rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) && mSecondary != null) { + if ((rng.nextInt(chanceZ) == 0 || rng.nextInt(chanceX) == 0) && mSecondary != null) { if (OreManager.setOreForWorldGen(world, tX, level, tZ, null, mSecondary, false)) { placeCount[1]++; } @@ -390,7 +389,7 @@ private void generateLayer(boolean secondary, boolean between, boolean primary) } } - if (rng.nextInt(7) == 0 && (rng.nextInt(placeZ) == 0 || rng.nextInt(placeX) == 0) + 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]++; diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index 851169d724c..e8ba1f3cb4e 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -316,28 +316,32 @@ public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropM } } case UnifiedBlock -> { - OreInfo info2 = info.clone(); - - for (int i = 0; i < (info.stoneType.isRich() ? 2 : 1); i++) { - info.stoneType = StoneType.Stone; - drops.add(getStack(info, 1)); + 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)); + } } - - info2.release(); } case PerDimBlock -> { - OreInfo info2 = info.clone(); - - if (!info.stoneType.isDimensionSpecific()) { - info2.stoneType = StoneType.Stone; + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + if (!info2.stoneType.isDimensionSpecific()) { + info2.stoneType = StoneType.Stone; + } + + drops.add(getStack(info2, 1)); } - - drops.add(getStack(info, 1)); - - info2.release(); } case Block -> { - drops.add(getStack(info, 1)); + try (OreInfo info2 = info.clone()) { + info2.isNatural = false; + + drops.add(getStack(info2, 1)); + } } } diff --git a/src/main/java/gregtech/common/ores/OreManager.java b/src/main/java/gregtech/common/ores/OreManager.java index 143a1f4dffe..d1a0952590b 100644 --- a/src/main/java/gregtech/common/ores/OreManager.java +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -74,6 +74,8 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone IStoneType existingStone = getStoneType(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; @@ -92,7 +94,7 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone var block = oreAdapter.getBlock(info); if (block != null) { - world.setBlock(x, y, z, block.left(), block.rightInt(), 2); + world.setBlock(x, y, z, block.left(), block.rightInt(), 3); return true; } @@ -145,7 +147,7 @@ public static boolean setExistingOreStoneType(World world, int x, int y, int z, return true; } - public static List mineBlock(World world, int x, int y, int z, int fortune, boolean simulate, + public static List mineBlock(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); @@ -159,7 +161,7 @@ public static List mineBlock(World world, int x, int y, int z, int fo if (p != null) { try (OreInfo info = p.right()) { oreBlockDrops = p.left() - .getOreDrops(info, false, fortune); + .getOreDrops(info, silktouch, fortune); var cobble = info.stoneType.getCobblestone(); @@ -167,7 +169,7 @@ public static List mineBlock(World world, int x, int y, int z, int fo replacementMeta = cobble.rightInt(); } } else { - if (ore.canSilkHarvest(world, null, x, y, z, meta)) { + if (silktouch && ore.canSilkHarvest(world, null, x, y, z, meta)) { oreBlockDrops = new ArrayList<>(Arrays.asList(new ItemStack(ore, 1, meta))); } else { // Regular ore From 48549edae6ea136cbbd91d2ebd05c9dc3f5b5fc7 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 03:46:58 -0500 Subject: [PATCH 23/47] missed a byte cast --- src/main/java/gregtech/api/metatileentity/BaseTileEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index 5c0cc59f2c9..37f2871d761 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -406,7 +406,7 @@ public Block getBlock(ChunkCoordinates aCoords) { @Override public final int getMetaID(int x, int y, int z) { if (ignoreUnloadedChunks && crossedChunkBorder(x, z) && !worldObj.blockExists(x, y, z)) return 0; - return (byte) worldObj.getBlockMetadata(x, y, z); + return worldObj.getBlockMetadata(x, y, z); } @Override From 4d55ceaacdece3fb6c2f5de2a4258a485348461a Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 03:47:13 -0500 Subject: [PATCH 24/47] prevent crashes from coop tasks --- src/main/java/gregtech/api/task/CooperativeScheduler.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/task/CooperativeScheduler.java b/src/main/java/gregtech/api/task/CooperativeScheduler.java index db462b3206c..454322c163e 100644 --- a/src/main/java/gregtech/api/task/CooperativeScheduler.java +++ b/src/main/java/gregtech/api/task/CooperativeScheduler.java @@ -67,7 +67,12 @@ public void tick(TickEvent.ServerTickEvent event) { continue; } - future.run(); + 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(); From f9a4d55f99012fd31bc6424c13e29facdd086a17 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 03:48:11 -0500 Subject: [PATCH 25/47] remove bw & gt++ worlds from eoh --- .../plugin/gregtech5/PluginGT5VeinStat.java | 13 +++-- .../java/gtneioreplugin/util/CSVMaker.java | 4 +- .../gtneioreplugin/util/DimensionHelper.java | 7 +-- .../util/GT5OreLayerHelper.java | 50 ++++++++----------- .../recipe/EyeOfHarmonyRecipeStorage.java | 9 +++- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index ae11c2ecf5a..c79dfd89cc8 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -14,6 +14,7 @@ import codechicken.nei.PositionedStack; import gregtech.api.enums.OrePrefixes; import gregtech.api.interfaces.IMaterial; +import gregtech.api.util.GTUtility; import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.item.ItemDimensionDisplay; import gtneioreplugin.util.DimensionHelper; @@ -126,7 +127,7 @@ private void addVeinWithLayers(OreLayerWrapper oreVein) { } private Collection getAllVeins() { - return GT5OreLayerHelper.mapOreLayerWrapper.values(); + return GT5OreLayerHelper.ORE_VEINS_BY_NAME.values(); } @Override @@ -144,7 +145,7 @@ 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.ORE_VEINS_BY_NAME.get(crecipe.veinName); } private static void drawVeinName(OreLayerWrapper oreLayer) { @@ -186,14 +187,12 @@ public String getRecipeName() { } private String[] getDimNameArrayFromVeinName(String veinName) { - OreLayerWrapper oreLayer = GT5OreLayerHelper.mapOreLayerWrapper.get(veinName); - String[] dims = GT5OreLayerHelper.bufferedDims.get(oreLayer) - .toArray(new String[0]); + OreLayerWrapper oreLayer = GT5OreLayerHelper.ORE_VEINS_BY_NAME.get(veinName); + String[] dims = oreLayer.abbrDimNames.toArray(new String[0]); Arrays.sort( dims, Comparator.comparingInt( - s -> Arrays.asList(DimensionHelper.DimNameDisplayed) - .indexOf(s))); + s -> GTUtility.indexOf(DimensionHelper.DimNameDisplayed, s))); return dims; } diff --git a/src/main/java/gtneioreplugin/util/CSVMaker.java b/src/main/java/gtneioreplugin/util/CSVMaker.java index 78e3fd9c68f..7184a95fb4d 100644 --- a/src/main/java/gtneioreplugin/util/CSVMaker.java +++ b/src/main/java/gtneioreplugin/util/CSVMaker.java @@ -66,14 +66,14 @@ public void run() { public void runVeins() { try { - Iterator> it = GT5OreLayerHelper.mapOreLayerWrapper.entrySet() + Iterator> it = GT5OreLayerHelper.ORE_VEINS_BY_NAME.entrySet() .iterator(); List OreVeins = new ArrayList<>(); while (it.hasNext()) { Oremix oremix = new Oremix(); Map.Entry pair = it.next(); - Set Dims = GT5OreLayerHelper.bufferedDims.get(pair.getValue()); + Set Dims = pair.getValue().abbrDimNames; OreLayerWrapper oreLayer = pair.getValue(); oremix.setOreMixName(oreLayer.veinName); oremix.setPrimary(oreLayer.ores[0].getInternalName()); diff --git a/src/main/java/gtneioreplugin/util/DimensionHelper.java b/src/main/java/gtneioreplugin/util/DimensionHelper.java index 9f665ac5df9..01f6a364944 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -277,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) { + 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" -> ENDASTEROIDS; // EndAsteroid + case "Eg" -> EVERGLADES; // T1 case "Mo" -> MOON; // GalacticraftCore_Moon // T2 @@ -333,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 843332c8e6a..e61c07e1142 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import net.minecraft.item.ItemStack; @@ -18,38 +19,25 @@ public class GT5OreLayerHelper { - public static final HashMap mapOreLayerWrapper = new HashMap<>(); - public static final HashMap> bufferedDims = new HashMap<>(); - public static final HashMap dimToOreWrapper = new HashMap<>(); + /** {vein ore mix name: wrapper} */ + public static final HashMap ORE_VEINS_BY_NAME = new HashMap<>(); + /** {abbr dim name: wrapper} */ + public static final HashMap ORE_VEINS_BY_DIM = new HashMap<>(); public static void init() { 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)); - } - - // --- Handling of dimToOreWrapper --- + OreLayerWrapper wrapper = new OreLayerWrapper(mix.oreMixBuilder); + ORE_VEINS_BY_NAME.put(mix.oreMixBuilder.oreMixName, wrapper); - // Get dims as "Ow,Ne,Ma" etc. - bufferedDims.forEach((veinInfo, dims) -> { - - for (String dim : dims) { - NormalOreDimensionWrapper dimensionOres = dimToOreWrapper - .getOrDefault(dim, new NormalOreDimensionWrapper()); - dimensionOres.internalDimOreList.add(veinInfo); - dimToOreWrapper.put(dim, dimensionOres); + for (String dim : wrapper.abbrDimNames) { + NormalOreDimensionWrapper dimensionOres = ORE_VEINS_BY_DIM.getOrDefault(dim, new NormalOreDimensionWrapper()); + dimensionOres.oreVeins.add(wrapper); + ORE_VEINS_BY_DIM.put(dim, dimensionOres); } + } - // Calculate probabilities for each dim. - for (String dim : dimToOreWrapper.keySet()) { - dimToOreWrapper.get(dim) - .calculateWeights(); - } - }); - // --- End of handling for dimToOreWrapper --- + // Calculate probabilities for each dim. + ORE_VEINS_BY_DIM.values().forEach(NormalOreDimensionWrapper::calculateWeights); } public static class OreLayerWrapper { @@ -57,7 +45,10 @@ public static class OreLayerWrapper { public final String veinName, worldGenHeightRange, localizedName; public final IMaterial[] ores = new IMaterial[4]; public final short randomWeight, size, density; + /** {full dim name} */ public final Set allowedDimWithOrigNames; + /** {abbr dim name} */ + public final Set abbrDimNames; public final IMaterial mPrimaryVeinMaterial; public final IMaterial mSecondaryMaterial; @@ -83,6 +74,7 @@ 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 veinLayer) { @@ -115,16 +107,16 @@ public boolean containsOre(IMaterial material) { public static class NormalOreDimensionWrapper { - public final ArrayList internalDimOreList = new ArrayList<>(); + 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 : internalDimOreList) { + for (OreLayerWrapper oreVein : oreVeins) { totalWeight += oreVein.randomWeight; } - for (OreLayerWrapper oreVein : internalDimOreList) { + for (OreLayerWrapper oreVein : oreVeins) { oreVeinToProbabilityInDimension.put(oreVein, ((double) oreVein.randomWeight) / ((double) totalWeight)); } } diff --git a/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java b/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java index f90356d706a..9bf2756a771 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; @@ -53,14 +55,19 @@ public class EyeOfHarmonyRecipeStorage { BlockDimensionDisplay blockDimensionDisplay = (BlockDimensionDisplay) ModBlocks.blocks .get(dimAbbreviation); + ModDimensionDef dimensionDef = DimensionDef.DEF_BY_WORLD_NAME.get(DimensionHelper.getFullName(dimAbbreviation)); + + if (dimensionDef != null && !dimensionDef.hasEoHRecipe) continue; + if (dimAbbreviation.equals("DD")) { specialDeepDarkRecipe(this, blockDimensionDisplay); } else { - GT5OreLayerHelper.NormalOreDimensionWrapper normalOre = GT5OreLayerHelper.dimToOreWrapper + GT5OreLayerHelper.NormalOreDimensionWrapper normalOre = GT5OreLayerHelper.ORE_VEINS_BY_DIM .getOrDefault(dimAbbreviation, null); GT5OreSmallHelper.SmallOreDimensionWrapper smallOre = GT5OreSmallHelper.SMALL_ORES_BY_DIM .getOrDefault(dimAbbreviation, null); + if (normalOre == null && smallOre == null) { // No ores are generated in this dimension. Fail silently. continue; From 327d9d10931e469b9c5d388c8ecb6133c29510cf Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 03:48:26 -0500 Subject: [PATCH 26/47] forgot a util for the stone fixes --- src/main/java/gregtech/api/util/Lazy.java | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/gregtech/api/util/Lazy.java 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; + } +} From 93fec99f076b2cac28741e79b3515ca1ebc21750 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 03:49:56 -0500 Subject: [PATCH 27/47] optimize drilling plants --- src/main/java/gregtech/api/util/LRUCache.java | 31 +++++ .../common/misc/DrillingLogicDelegate.java | 4 +- .../multi/MTEOreDrillingPlantBase.java | 123 ++++++++++-------- 3 files changed, 100 insertions(+), 58 deletions(-) create mode 100644 src/main/java/gregtech/api/util/LRUCache.java 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..1c02a41e6fa --- /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/common/misc/DrillingLogicDelegate.java b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java index 13e6def449b..2462b243803 100644 --- a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java +++ b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java @@ -162,7 +162,7 @@ public void mineBlock(IGregTechTileEntity te, Block block, int x, int y, int z) } // see if we can store all of the outputs - List drops = OreManager.mineBlock(te.getWorld(), x, y, z, owner.getMachineTier(), true, true); + List drops = OreManager.mineBlock(te.getWorld(), x, y, z, false, owner.getMachineTier(), true, true); for (ItemStack drop : drops) { if (!owner.pushOutputs(drop, drop.stackSize, true, false)) { @@ -175,7 +175,7 @@ public void mineBlock(IGregTechTileEntity te, Block block, int x, int y, int z) } // actually mine it - OreManager.mineBlock(te.getWorld(), x, y, z, owner.getMachineTier(), false, true); + OreManager.mineBlock(te.getWorld(), x, y, z, false, owner.getMachineTier(), false, true); } /** 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 13ff6e86dc8..8ea6f56d629 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java @@ -10,10 +10,7 @@ import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; import java.util.List; -import java.util.Objects; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -23,7 +20,6 @@ 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; @@ -31,6 +27,7 @@ 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; @@ -46,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; @@ -57,13 +55,18 @@ import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; +import gregtech.api.util.LRUCache; import gregtech.api.util.MultiblockTooltipBuilder; +import gregtech.api.util.GTUtility.ItemId; 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; @@ -223,61 +226,55 @@ private boolean tryProcessOreList() { } private boolean processOreList(boolean simulate) { - List oreBlockPositions = simulate ? copyOreBlockPositions(this.oreBlockPositions) - : this.oreBlockPositions; + World world = getBaseMetaTileEntity().getWorld(); - ChunkPosition oreBlockPos = null; - Block oreBlock = null; - int oreBlockMetadata = 0; + LongIterator iter = oreBlockPositions.iterator(); - World world = getBaseMetaTileEntity().getWorld(); + while (iter.hasNext()) { + long pos = iter.nextLong(); - while ((oreBlock == null || !GTUtility.isMinable(oreBlock, oreBlockMetadata)) && !oreBlockPositions.isEmpty()) { - oreBlockPos = oreBlockPositions.remove(0); - int x = oreBlockPos.chunkPosX; - int y = oreBlockPos.chunkPosY; - int z = oreBlockPos.chunkPosZ; - if (GTUtility.eraseBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), x, y, z, true)) { - oreBlock = world.getBlock(x, y, z); - oreBlockMetadata = world.getBlockMetadata(x, y, z); - } - } + int x = CoordinatePacker.unpackX(pos); + int y = CoordinatePacker.unpackY(pos); + int z = CoordinatePacker.unpackZ(pos); - if (oreBlock == null) return false; - Objects.requireNonNull(oreBlockPos); + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); - if (!tryConsumeDrillingFluid(simulate)) { - oreBlockPositions.add(0, oreBlockPos); - setRuntimeFailureReason(CheckRecipeResultRegistry.NO_DRILLING_FLUID); - return false; - } + if (!GTUtility.isMinable(block, meta)) { + // always remove non-ore blocks, even if we're simulating + iter.remove(); + continue; + } - if (GTUtility.isMinable(oreBlock, oreBlockMetadata) || OreManager.isOre(oreBlock, oreBlockMetadata)) { - int x = oreBlockPos.chunkPosX; - int y = oreBlockPos.chunkPosY; - int z = 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(world, x, y, z, mTier + 3, simulate, replaceWithCobblestone); + .mineBlock(world, x, y, z, true, mTier + 3, simulate, replaceWithCobblestone); ItemStack[] toOutput = getOutputByDrops(oreBlockDrops); + if (simulate && !canOutputAll(toOutput)) { setRuntimeFailureReason(CheckRecipeResultRegistry.ITEM_OUTPUT_FULL); return false; } - mOutputItems = toOutput; - } + if (!simulate) iter.remove(); - return true; - } + mOutputItems = toOutput; - 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 @@ -491,29 +488,41 @@ private int calculateMaxProgressTime(int tier) { ((workState == STATE_DOWNWARD || workState == STATE_AT_BOTTOM) ? getBaseProgressTime() : 80) / (1 << 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]); } @@ -526,7 +535,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) { @@ -569,10 +579,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 (GTUtility.isMinable(block, blockMeta)) oreBlockPositions.add(blockPos); + long pos = CoordinatePacker.pack(x, y, z); + + if (!oreBlockPositions.contains(pos)) { + if (GTUtility.isMinable(block, blockMeta)) oreBlockPositions.add(pos); } } From 0b0780a7da46aefbf63185d3670350396d8f948a Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 03:52:26 -0500 Subject: [PATCH 28/47] spotless --- .../system/material/BWMetaGeneratedOres.java | 1 + .../java/galacticgreg/SpaceDimRegisterer.java | 7 +++++-- .../java/galacticgreg/WorldGeneratorSpace.java | 12 ++++++------ .../api/enums/properties/Asteroids.java | 4 ++-- .../galacticgreg/command/WorldgenCommand.java | 1 - src/main/java/gregtech/api/enums/Mods.java | 1 + src/main/java/gregtech/api/enums/StoneType.java | 15 ++++++++++----- .../java/gregtech/api/interfaces/IStoneType.java | 1 + .../gregtech/api/task/CooperativeScheduler.java | 4 +++- src/main/java/gregtech/api/util/LRUCache.java | 4 ++-- .../java/gregtech/common/ores/BWOreAdapter.java | 11 ++++++----- .../java/gregtech/common/ores/GTOreAdapter.java | 8 ++++---- .../java/gregtech/common/ores/OreManager.java | 4 ++-- .../machines/multi/MTEOreDrillingPlantBase.java | 5 +++-- .../plugin/gregtech5/PluginGT5VeinStat.java | 5 +---- .../gtneioreplugin/util/GT5OreLayerHelper.java | 10 +++++++--- .../tectech/recipe/EyeOfHarmonyRecipeStorage.java | 3 ++- 17 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java index ff2d4958fc3..c907e26be98 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -32,6 +32,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; + import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IBlockWithTextures; diff --git a/src/main/java/galacticgreg/SpaceDimRegisterer.java b/src/main/java/galacticgreg/SpaceDimRegisterer.java index be9e002d3d4..52c2a14aace 100644 --- a/src/main/java/galacticgreg/SpaceDimRegisterer.java +++ b/src/main/java/galacticgreg/SpaceDimRegisterer.java @@ -1,6 +1,7 @@ package galacticgreg; import net.minecraft.init.Blocks; + import cpw.mods.fml.common.registry.GameRegistry; import galacticgreg.api.Enums; import galacticgreg.api.ModContainer; @@ -40,8 +41,10 @@ private static ModContainer setupVanilla() { // These Blocks will randomly be generated DimensionDef.EndAsteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.glowstone)); if (Mods.HardcoreEnderExpansion.isModLoaded()) { - DimensionDef.EndAsteroids.modDimensionDef - .addSpecialAsteroidBlock(new SpecialBlockComb(GameRegistry.findBlock(Mods.HardcoreEnderExpansion.ID, "ender_goo"), Enums.AllowedBlockPosition.AsteroidCore)); + DimensionDef.EndAsteroids.modDimensionDef.addSpecialAsteroidBlock( + new SpecialBlockComb( + GameRegistry.findBlock(Mods.HardcoreEnderExpansion.ID, "ender_goo"), + Enums.AllowedBlockPosition.AsteroidCore)); } ModContainers.Vanilla.modContainer.addDimensionDef(DimensionDef.EndAsteroids.modDimensionDef); diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 4bb27d200f4..fff2f425ed2 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -78,8 +78,8 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP long post = System.nanoTime(); - if (profileWorldGen) - GTMod.GT_FML_LOGGER.info(String.format("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3)); + if (profileWorldGen) GTMod.GT_FML_LOGGER + .info(String.format("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3)); Chunk tChunk = world.getChunkFromBlockCoords(chunkX, chunkZ); if (tChunk != null) { @@ -455,8 +455,8 @@ private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Rando return false; } - private static boolean generateOreBlock(AsteroidConfig asteroidConfig, Random rng, World pWorld, int pX, int pY, int pZ, IStoneType stoneType, - IWorldgenLayer oreLayer, float control, float dist) { + 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) { IMaterial mat = oreLayer.getOre(control); @@ -468,8 +468,8 @@ private static boolean generateOreBlock(AsteroidConfig asteroidConfig, Random rn return false; } - private static boolean generateSmallOreBlock(AsteroidConfig asteroidConfig, Random rng, World pWorld, int pX, int pY, int pZ, IStoneType stoneType, - IWorldgenLayer oreLayer, float control) { + 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) { IMaterial mat = oreLayer.getOre(control); diff --git a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java index 18850f86c60..87e00f34c65 100644 --- a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java +++ b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java @@ -5,7 +5,7 @@ public enum Asteroids { - // spotless: off + // spotless:off EndAsteroids(ModContainers.Vanilla, DimensionDef.EndAsteroids, new AsteroidPropertyBuilder().probability(10) .sizeRange(5, 15) .specialBlockChance(5) @@ -48,7 +48,7 @@ public enum Asteroids { .lootChestTable(3) .isLootItemCountRandomized(true))), ; - // spotless: on + // spotless:on public ModContainers modContainers; public DimensionDef dimensionDef; diff --git a/src/main/java/galacticgreg/command/WorldgenCommand.java b/src/main/java/galacticgreg/command/WorldgenCommand.java index c2a29610426..59a29fbd58a 100644 --- a/src/main/java/galacticgreg/command/WorldgenCommand.java +++ b/src/main/java/galacticgreg/command/WorldgenCommand.java @@ -5,7 +5,6 @@ import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.Blocks; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; diff --git a/src/main/java/gregtech/api/enums/Mods.java b/src/main/java/gregtech/api/enums/Mods.java index 822e2c27e55..6bdfdbd270a 100644 --- a/src/main/java/gregtech/api/enums/Mods.java +++ b/src/main/java/gregtech/api/enums/Mods.java @@ -111,6 +111,7 @@ public enum Mods { Mantle(Names.MANTLE), MineAndBladeBattleGear2(Names.MINE_AND_BLADE_BATTLE_GEAR2), Minecraft(Names.MINECRAFT) { + @Override public boolean isModLoaded() { return true; diff --git a/src/main/java/gregtech/api/enums/StoneType.java b/src/main/java/gregtech/api/enums/StoneType.java index 02571ae86af..af3d6c9c31b 100644 --- a/src/main/java/gregtech/api/enums/StoneType.java +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -184,12 +184,14 @@ public IStoneCategory getCategory() { @Override public ObjectIntPair getCobblestone() { - return builder.cobble.get().toPair(); + return builder.cobble.get() + .toPair(); } @Override public ObjectIntPair getStone() { - return builder.mainStone.get().toPair(); + return builder.mainStone.get() + .toPair(); } @Override @@ -296,7 +298,8 @@ public boolean contains(Block block, int meta) { @Override public boolean canGenerateInWorld(World world) { - return builder.allowedDimensions == null || builder.allowedDimensions.contains(world.provider.getDimensionName()); + return builder.allowedDimensions == null + || builder.allowedDimensions.contains(world.provider.getDimensionName()); } public static StoneType findStoneType(World world, int x, int y, int z) { @@ -342,8 +345,10 @@ private static class StoneBuilder { public Lazy mainStone = new Lazy<>(() -> new BlockMeta(Blocks.air, 0)); public List> otherStones; public OrePrefixes oreBlockPrefix = OrePrefixes.ore; - public Lazy pureDust = new Lazy<>(() -> GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1)); - public Lazy impureDust = new Lazy<>(() -> GTOreDictUnificator.get(OrePrefixes.dustImpure, Materials.Stone, 1)); + public Lazy pureDust = new Lazy<>( + () -> GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1)); + public Lazy impureDust = new Lazy<>( + () -> GTOreDictUnificator.get(OrePrefixes.dustImpure, Materials.Stone, 1)); public StoneCategory category = StoneCategory.Stone; public HashSet allowedDimensions = null; diff --git a/src/main/java/gregtech/api/interfaces/IStoneType.java b/src/main/java/gregtech/api/interfaces/IStoneType.java index dbd6dffcde7..93e5fedbc49 100644 --- a/src/main/java/gregtech/api/interfaces/IStoneType.java +++ b/src/main/java/gregtech/api/interfaces/IStoneType.java @@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; + import gregtech.api.enums.OrePrefixes; import it.unimi.dsi.fastutil.objects.ObjectIntPair; diff --git a/src/main/java/gregtech/api/task/CooperativeScheduler.java b/src/main/java/gregtech/api/task/CooperativeScheduler.java index 454322c163e..9fd1bddfa79 100644 --- a/src/main/java/gregtech/api/task/CooperativeScheduler.java +++ b/src/main/java/gregtech/api/task/CooperativeScheduler.java @@ -70,7 +70,9 @@ public void tick(TickEvent.ServerTickEvent event) { 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); + GTMod.GT_FML_LOGGER.error( + "Caught error while running task; it will be cancelled (" + future.name + " " + future.task + ")", + t); future.cancel(true); } diff --git a/src/main/java/gregtech/api/util/LRUCache.java b/src/main/java/gregtech/api/util/LRUCache.java index 1c02a41e6fa..1922340bc2f 100644 --- a/src/main/java/gregtech/api/util/LRUCache.java +++ b/src/main/java/gregtech/api/util/LRUCache.java @@ -6,7 +6,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; public class LRUCache { - + public Object2ObjectLinkedOpenHashMap> map = new Object2ObjectLinkedOpenHashMap<>(); public int capacity; public Function lookup; @@ -23,7 +23,7 @@ public V get(K key) { v = Optional.ofNullable(lookup.apply(key)); map.putAndMoveToFirst(key, v); - while(map.size() > capacity) map.removeLast(); + while (map.size() > capacity) map.removeLast(); } return v.orElse(null); diff --git a/src/main/java/gregtech/common/ores/BWOreAdapter.java b/src/main/java/gregtech/common/ores/BWOreAdapter.java index eb4637af6f2..f2c1bc4b38b 100644 --- a/src/main/java/gregtech/common/ores/BWOreAdapter.java +++ b/src/main/java/gregtech/common/ores/BWOreAdapter.java @@ -98,7 +98,8 @@ public void init() { } public void registerOredict() { - ores.values().forEach(Ores::registerOredict); + ores.values() + .forEach(Ores::registerOredict); } @Override @@ -257,7 +258,7 @@ public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropM 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)); @@ -267,18 +268,18 @@ public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropM 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)); } } diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index e8ba1f3cb4e..11c5eb72fbb 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -318,7 +318,7 @@ public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropM 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)); @@ -328,18 +328,18 @@ public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropM 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)); } } diff --git a/src/main/java/gregtech/common/ores/OreManager.java b/src/main/java/gregtech/common/ores/OreManager.java index d1a0952590b..cf18b99fb1d 100644 --- a/src/main/java/gregtech/common/ores/OreManager.java +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -147,8 +147,8 @@ public static boolean setExistingOreStoneType(World world, int x, int y, int z, return true; } - public static List mineBlock(World world, int x, int y, int z, boolean silktouch, int fortune, boolean simulate, - boolean replaceWithCobblestone) { + public static List mineBlock(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); 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 8ea6f56d629..dad62cf8bc8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java @@ -55,9 +55,9 @@ 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.api.util.GTUtility.ItemId; import gregtech.common.ores.OreManager; import gregtech.crossmod.visualprospecting.VisualProspectingDatabase; import it.unimi.dsi.fastutil.longs.LongArrayList; @@ -247,7 +247,8 @@ private boolean processOreList(boolean simulate) { } 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 + // 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; } diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index c79dfd89cc8..ff0c6f49807 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -189,10 +189,7 @@ public String getRecipeName() { private String[] getDimNameArrayFromVeinName(String veinName) { OreLayerWrapper oreLayer = GT5OreLayerHelper.ORE_VEINS_BY_NAME.get(veinName); String[] dims = oreLayer.abbrDimNames.toArray(new String[0]); - Arrays.sort( - dims, - Comparator.comparingInt( - s -> GTUtility.indexOf(DimensionHelper.DimNameDisplayed, s))); + Arrays.sort(dims, Comparator.comparingInt(s -> GTUtility.indexOf(DimensionHelper.DimNameDisplayed, s))); return dims; } diff --git a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java index e61c07e1142..e13e7ad14f2 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -30,14 +30,16 @@ public static void init() { ORE_VEINS_BY_NAME.put(mix.oreMixBuilder.oreMixName, wrapper); for (String dim : wrapper.abbrDimNames) { - NormalOreDimensionWrapper dimensionOres = ORE_VEINS_BY_DIM.getOrDefault(dim, new NormalOreDimensionWrapper()); + NormalOreDimensionWrapper dimensionOres = ORE_VEINS_BY_DIM + .getOrDefault(dim, new NormalOreDimensionWrapper()); dimensionOres.oreVeins.add(wrapper); ORE_VEINS_BY_DIM.put(dim, dimensionOres); } } // Calculate probabilities for each dim. - ORE_VEINS_BY_DIM.values().forEach(NormalOreDimensionWrapper::calculateWeights); + ORE_VEINS_BY_DIM.values() + .forEach(NormalOreDimensionWrapper::calculateWeights); } public static class OreLayerWrapper { @@ -74,7 +76,9 @@ public OreLayerWrapper(OreMixBuilder mix) { this.randomWeight = (short) mix.weight; this.allowedDimWithOrigNames = mix.dimsEnabled; - this.abbrDimNames = mix.dimsEnabled.stream().map(DimensionHelper::getDimAbbreviatedName).collect(Collectors.toSet()); + this.abbrDimNames = mix.dimsEnabled.stream() + .map(DimensionHelper::getDimAbbreviatedName) + .collect(Collectors.toSet()); } public List getVeinLayerOre(int veinLayer) { diff --git a/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java b/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java index 9bf2756a771..0ba9ef2a2c1 100644 --- a/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java +++ b/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java @@ -55,7 +55,8 @@ public class EyeOfHarmonyRecipeStorage { BlockDimensionDisplay blockDimensionDisplay = (BlockDimensionDisplay) ModBlocks.blocks .get(dimAbbreviation); - ModDimensionDef dimensionDef = DimensionDef.DEF_BY_WORLD_NAME.get(DimensionHelper.getFullName(dimAbbreviation)); + ModDimensionDef dimensionDef = DimensionDef.DEF_BY_WORLD_NAME + .get(DimensionHelper.getFullName(dimAbbreviation)); if (dimensionDef != null && !dimensionDef.hasEoHRecipe) continue; From d7f16d2d2e303be132ac8ce501f8e083c80b9f2a Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 15:53:25 -0500 Subject: [PATCH 29/47] gt ore item transformer --- src/main/java/gregtech/common/ores/GTOreAdapter.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index 11c5eb72fbb..8a632dea88c 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -9,8 +9,10 @@ import net.minecraft.block.Block; import net.minecraft.init.Blocks; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import com.gtnewhorizons.postea.api.ItemStackReplacementManager; import com.gtnewhorizons.postea.api.TileEntityReplacementManager; import com.gtnewhorizons.postea.utility.BlockInfo; @@ -127,6 +129,12 @@ public void init() { } } }); + + ItemStackReplacementManager.addItemReplacement("gregtech:gt.blockores", (tag) -> { + int itemId = Item.getIdFromItem(Item.getItemFromBlock(ores1)); + tag.setInteger("id", itemId); + return tag; + }); } public void registerOre(StoneType stoneType, BlockOresAbstract oreBlock) { From 23b8207bdf4c7b9d0765d6764a12b18f15d8872a Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 15:54:47 -0500 Subject: [PATCH 30/47] kuiper belt fixes --- src/main/java/galacticgreg/SpaceDimRegisterer.java | 5 ++++- src/main/java/galacticgreg/WorldGeneratorSpace.java | 5 +---- src/main/java/galacticgreg/api/enums/DimensionDef.java | 4 +++- .../api/enums/properties/AsteroidPropertyBuilder.java | 7 +++++++ .../galacticgreg/api/enums/properties/Asteroids.java | 1 + .../galacticgreg/dynconfig/DynamicDimensionConfig.java | 4 ++++ src/main/java/gregtech/api/enums/OreMixes.java | 10 +++++----- src/main/java/gtneioreplugin/util/DimensionHelper.java | 2 +- 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/java/galacticgreg/SpaceDimRegisterer.java b/src/main/java/galacticgreg/SpaceDimRegisterer.java index 52c2a14aace..e280624f549 100644 --- a/src/main/java/galacticgreg/SpaceDimRegisterer.java +++ b/src/main/java/galacticgreg/SpaceDimRegisterer.java @@ -124,6 +124,9 @@ private static ModContainer setupGalaxySpace() { DimensionDef.KuiperBelt.modDimensionDef.setDimensionType(Enums.DimensionType.Asteroid); 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); @@ -142,7 +145,7 @@ private static ModContainer setupAmunRa() { DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(StoneType.BlackGranite); DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(StoneType.Horus); - DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(StoneType.Asteroid); + DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(StoneType.Asteroid); ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.MehenBelt.modDimensionDef); return ModContainers.AmunRa.modContainer; diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index fff2f425ed2..5d37e249223 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -135,16 +135,13 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh if (oreLayer == null) return null; - int minY = oreLayer.getMinY(); - int maxY = oreLayer.getMaxY(); - 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 = minY + rng.nextInt(maxY - minY); + int tY = asteroidConfig.AsteroidMinY + rng.nextInt(asteroidConfig.AsteroidMaxY - asteroidConfig.AsteroidMinY); int tZ = seedChunkZ * 16 + rng.nextInt(16); List positive = new ArrayList<>(); diff --git a/src/main/java/galacticgreg/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index a9ba966a35f..d3ed812a9d5 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -247,6 +247,8 @@ public enum DimensionDef { 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) { @@ -295,7 +297,7 @@ 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"; diff --git a/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java b/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java index c3cef9baa0e..4af6ed0f4ef 100644 --- a/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java +++ b/src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java @@ -10,6 +10,7 @@ public class AsteroidPropertyBuilder { public int smallOreChance = 10; public LootPropertyBuilder loot; public int positiveEllipsoids = 2, negativeEllipsoids = 2; + public int asteroidMinY = 50, asteroidMaxY = 100; public static class LootPropertyBuilder { @@ -85,6 +86,12 @@ public AsteroidPropertyBuilder negativeEllipsoids(int negativeEllipsoids) { return this; } + public AsteroidPropertyBuilder asteroidYBounds(int minY, int maxY) { + this.asteroidMinY = minY; + this.asteroidMaxY = maxY; + return this; + } + public AsteroidPropertyBuilder loot(LootPropertyBuilder lootPropertyBuilder) { this.loot = lootPropertyBuilder; 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 87e00f34c65..bd816537379 100644 --- a/src/main/java/galacticgreg/api/enums/properties/Asteroids.java +++ b/src/main/java/galacticgreg/api/enums/properties/Asteroids.java @@ -32,6 +32,7 @@ public enum Asteroids { .specialBlockChance(5) .oreDensityMultiplier(0.75f) .smallOreChance(10) + .asteroidYBounds(50, 200) .loot( new AsteroidPropertyBuilder.LootPropertyBuilder().lootChestChance(1) .lootChestItemCount(10) diff --git a/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java b/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java index df82d16d766..6ca5868bd17 100644 --- a/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java +++ b/src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java @@ -22,6 +22,8 @@ public static class AsteroidConfig { public int Probability; public int PositiveEllipsoids; public int NegativeEllipsoids; + public int AsteroidMinY; + public int AsteroidMaxY; public float OreDensityMultiplier; public int OreChance; public int SmallOreChance; @@ -87,6 +89,8 @@ public static boolean InitDynamicConfig() { 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; diff --git a/src/main/java/gregtech/api/enums/OreMixes.java b/src/main/java/gregtech/api/enums/OreMixes.java index 0acebd6fda5..2e703af3d21 100644 --- a/src/main/java/gregtech/api/enums/OreMixes.java +++ b/src/main/java/gregtech/api/enums/OreMixes.java @@ -1013,7 +1013,7 @@ public enum OreMixes { NitrogenIce(new OreMixBuilder().name("ore.mix.nitrogenice") .heightRange(30, 180) .weight(80) - .density(16) + .density(2) .size(16) .enableInDim(ASTEROIDS, KUIPERBELT) .primary(Materials.Nitrogen) @@ -1025,7 +1025,7 @@ public enum OreMixes { HydrocarbonIce(new OreMixBuilder().name("ore.mix.hydrocarbonice") .heightRange(30, 180) .weight(40) - .density(16) + .density(2) .size(12) .enableInDim(ASTEROIDS, KUIPERBELT) .primary(Materials.Methane) @@ -1037,7 +1037,7 @@ public enum OreMixes { CarbonIce(new OreMixBuilder().name("ore.mix.carbonice") .heightRange(30, 180) .weight(40) - .density(16) + .density(2) .size(12) .enableInDim(ASTEROIDS, KUIPERBELT) .primary(Materials.CarbonDioxide) @@ -1049,7 +1049,7 @@ public enum OreMixes { HHOIce(new OreMixBuilder().name("ore.mix.hhoice") .heightRange(30, 180) .weight(80) - .density(24) + .density(2) .size(16) .enableInDim(ASTEROIDS, KUIPERBELT) .primary(Materials.Oxygen) @@ -1061,7 +1061,7 @@ public enum OreMixes { SulfurIce(new OreMixBuilder().name("ore.mix.sulfurice") .heightRange(30, 180) .weight(20) - .density(16) + .density(2) .size(8) .enableInDim(ASTEROIDS, KUIPERBELT) .primary(Materials.SulfurDioxide) diff --git a/src/main/java/gtneioreplugin/util/DimensionHelper.java b/src/main/java/gtneioreplugin/util/DimensionHelper.java index 01f6a364944..19f4da39e67 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -167,7 +167,7 @@ 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 "Underdark" -> "T10: " + s; From d2926924e34c9c64362e54f52332c9c8fd6503c9 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 15:55:03 -0500 Subject: [PATCH 31/47] truncate long lines in the plugin --- .../plugin/gregtech5/PluginGT5Base.java | 14 +++++++++++--- .../plugin/gregtech5/PluginGT5VeinStat.java | 10 +++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java index 3ada88beccd..4ee9107b1c2 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -11,7 +11,7 @@ public abstract class PluginGT5Base extends PluginBase { - protected static String getGTOreLocalizedName(IMaterial ore, boolean small) { + protected String getGTOreLocalizedName(IMaterial ore, boolean small) { if (ore == Materials.DraconiumAwakened) return "Aw. Draconium Ore"; try (OreInfo info = OreInfo.getNewInfo()) { @@ -22,8 +22,16 @@ protected static String getGTOreLocalizedName(IMaterial ore, boolean small) { } } - static void drawLine(String lineKey, String value, int x, int y) { - GuiDraw.drawString(I18n.format(lineKey) + ": " + value, x, y, 0x404040, false); + 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/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index ff0c6f49807..dae82b46051 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -148,22 +148,22 @@ private OreLayerWrapper getOreLayer(int recipe) { return GT5OreLayerHelper.ORE_VEINS_BY_NAME.get(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.ores[veinLayer], false), @@ -171,7 +171,7 @@ private static void drawVeinLayerNameLine(OreLayerWrapper oreLayer, int veinLaye 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); } From 93956a7966a5cd497751fdf556962692ee957fab Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 15:55:25 -0500 Subject: [PATCH 32/47] clean up gt ore localization --- src/main/java/gregtech/api/enums/OrePrefixes.java | 13 +++++++++++++ .../gregtech/common/blocks/BlockOresAbstract.java | 12 +----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index 745f7083e96..08141ae979f 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -1479,6 +1479,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/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java index 2081f454aa8..591bd8a82dc 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java @@ -266,17 +266,7 @@ public boolean addDestroyEffects(World world, int x, int y, int z, int meta, Eff } public String getLocalizedNameFormat(Materials material) { - String base; - - if (material.contains(SubTag.ICE_ORE)) { - base = "%material Ice"; - } else { - base = switch (material.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; - }; - } + String base = OrePrefixes.ore.getDefaultLocalNameForItem(material); if (GTLanguageManager.i18nPlaceholder) { return base; From feeb1aaddb959a567af0a41f8ada9d92034729bc Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 15:55:38 -0500 Subject: [PATCH 33/47] bw fixes --- .../system/material/BWMetaGeneratedOres.java | 12 +++---- .../system/material/WerkstoffLoader.java | 31 ++++++++++++++----- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java index c907e26be98..3f8d0f62d3e 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -47,6 +47,7 @@ public class BWMetaGeneratedOres extends Block implements IBlockWithTextures { + public final String blockName; public final String blockTypeLocalizedName; public final StoneType stoneType; public final boolean isSmall, isNatural; @@ -61,14 +62,15 @@ public BWMetaGeneratedOres(String blockName, StoneType stoneType, boolean small, if (small) { this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( - "bw.blocktype." + OrePrefixes.oreSmall, + blockName, OrePrefixes.oreSmall.mLocalizedMaterialPre + "%material" + OrePrefixes.oreSmall.mLocalizedMaterialPost); } else { this.blockTypeLocalizedName = GTLanguageManager.addStringLocalization( - "bw.blocktype." + OrePrefixes.ore, + blockName, OrePrefixes.ore.mLocalizedMaterialPre + "%material" + OrePrefixes.ore.mLocalizedMaterialPost); } + this.blockName = blockName; this.stoneType = stoneType; this.isSmall = small; this.isNatural = natural; @@ -113,11 +115,7 @@ public int damageDropped(int meta) { @Override public String getUnlocalizedName() { - if (isSmall) { - return "bw.blockores.02"; - } else { - return "bw.blockores.01"; - } + return blockName; } @Override diff --git a/src/main/java/bartworks/system/material/WerkstoffLoader.java b/src/main/java/bartworks/system/material/WerkstoffLoader.java index 043def2006a..77bdaff31ef 100644 --- a/src/main/java/bartworks/system/material/WerkstoffLoader.java +++ b/src/main/java/bartworks/system/material/WerkstoffLoader.java @@ -133,6 +133,7 @@ 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; @@ -1634,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, BWOresNatural; - public static Block BWSmallOres, BWSmallOresNatural; public static Block BWBlocks; public static Block BWBlockCasings; public static Block BWBlockCasingsAdvanced; @@ -1663,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(); } From 26d5f15e29c496907f3eda198430892efc11d036 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 15:56:03 -0500 Subject: [PATCH 34/47] spotless --- src/main/java/bartworks/system/material/WerkstoffLoader.java | 4 ++-- src/main/java/galacticgreg/WorldGeneratorSpace.java | 3 ++- .../java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/bartworks/system/material/WerkstoffLoader.java b/src/main/java/bartworks/system/material/WerkstoffLoader.java index 77bdaff31ef..40dfe433c3d 100644 --- a/src/main/java/bartworks/system/material/WerkstoffLoader.java +++ b/src/main/java/bartworks/system/material/WerkstoffLoader.java @@ -1671,7 +1671,7 @@ public static ItemStack getCorrespondingItemStackUnsafe(OrePrefixes orePrefixes, return BWOreAdapter.INSTANCE.getStack(info, amount); } } - + if (orePrefixes == block) { return new ItemStack(WerkstoffLoader.BWBlocks, amount, werkstoff.getmID()); } @@ -1681,7 +1681,7 @@ public static ItemStack getCorrespondingItemStackUnsafe(OrePrefixes orePrefixes, if (orePrefixes == OrePrefixes.blockCasingAdvanced) { return new ItemStack(WerkstoffLoader.BWBlockCasingsAdvanced, amount, werkstoff.getmID()); } - + if (WerkstoffLoader.items.get(orePrefixes) == null) { return null; } diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 5d37e249223..2ade9add6b3 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -141,7 +141,8 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh oreLayer.getName()); int tX = seedChunkX * 16 + rng.nextInt(16); - int tY = asteroidConfig.AsteroidMinY + rng.nextInt(asteroidConfig.AsteroidMaxY - asteroidConfig.AsteroidMinY); + int tY = asteroidConfig.AsteroidMinY + + rng.nextInt(asteroidConfig.AsteroidMaxY - asteroidConfig.AsteroidMinY); int tZ = seedChunkZ * 16 + rng.nextInt(16); List positive = new ArrayList<>(); diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java index 4ee9107b1c2..705bcbd0827 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -26,7 +26,7 @@ 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); } From 753ad14911980d5affe8f5511924c1aecddafec6 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 16:13:56 -0500 Subject: [PATCH 35/47] swap everglades rng to XSTR --- .../gregtech/api/objects/MolecularRandom.java | 161 ------------------ .../everglades/chunk/ChunkProviderModded.java | 4 +- 2 files changed, 2 insertions(+), 163 deletions(-) delete mode 100644 src/main/java/gregtech/api/objects/MolecularRandom.java diff --git a/src/main/java/gregtech/api/objects/MolecularRandom.java b/src/main/java/gregtech/api/objects/MolecularRandom.java deleted file mode 100644 index 325040054d7..00000000000 --- a/src/main/java/gregtech/api/objects/MolecularRandom.java +++ /dev/null @@ -1,161 +0,0 @@ -package gregtech.api.objects; - -import java.util.Random; - -/** - * A standard {@link Random}, but without the atomics and synchronization. - * Useful in cases where you need to swap out a random instance without changing its results. - */ -public class MolecularRandom extends Random { - - private long seed; - private double nextNextGaussian; - private boolean haveNextNextGaussian; - - public MolecularRandom(long var1) { - this.haveNextNextGaussian = false; - this.seed = initialScramble(var1); - } - - private static long initialScramble(long var0) { - return (var0 ^ 25214903917L) & 281474976710655L; - } - - public void setSeed(long var1) { - this.seed = initialScramble(var1); - this.haveNextNextGaussian = false; - } - - protected int next(int var1) { - seed = seed * 25214903917L + 11L & 281474976710655L; - - return (int) (seed >>> 48 - var1); - } - - public void nextBytes(byte[] var1) { - int var2 = 0; - int var3 = var1.length; - - while (var2 < var3) { - int var4 = this.nextInt(); - - for (int var5 = Math.min(var3 - var2, 4); var5-- > 0; var4 >>= 8) { - var1[var2++] = (byte) var4; - } - } - - } - - final long internalNextLong(long var1, long var3) { - long var5 = this.nextLong(); - if (var1 < var3) { - long var7 = var3 - var1; - long var9 = var7 - 1L; - if ((var7 & var9) == 0L) { - var5 = (var5 & var9) + var1; - } else if (var7 > 0L) { - for (long var11 = var5 >>> 1; var11 + var9 - (var5 = var11 % var7) - < 0L; var11 = this.nextLong() >>> 1) {} - - var5 += var1; - } else { - while (var5 < var1 || var5 >= var3) { - var5 = this.nextLong(); - } - } - } - - return var5; - } - - final int internalNextInt(int var1, int var2) { - if (var1 >= var2) { - return this.nextInt(); - } else { - int var3 = var2 - var1; - if (var3 > 0) { - return this.nextInt(var3) + var1; - } else { - int var4; - do { - do { - var4 = this.nextInt(); - } while (var4 < var1); - } while (var4 >= var2); - - return var4; - } - } - } - - final double internalNextDouble(double var1, double var3) { - double var5 = this.nextDouble(); - if (var1 < var3) { - var5 = var5 * (var3 - var1) + var1; - if (var5 >= var3) { - var5 = Double.longBitsToDouble(Double.doubleToLongBits(var3) - 1L); - } - } - - return var5; - } - - public int nextInt() { - return this.next(32); - } - - public int nextInt(int var1) { - if (var1 <= 0) { - throw new IllegalArgumentException("bound must be positive"); - } else { - int var2 = this.next(31); - int var3 = var1 - 1; - if ((var1 & var3) == 0) { - var2 = (int) ((long) var1 * (long) var2 >> 31); - } else { - for (int var4 = var2; var4 - (var2 = var4 % var1) + var3 < 0; var4 = this.next(31)) {} - } - - return var2; - } - } - - public long nextLong() { - return ((long) this.next(32) << 32) + (long) this.next(32); - } - - public boolean nextBoolean() { - return this.next(1) != 0; - } - - public float nextFloat() { - return (float) this.next(24) / 1.6777216E7F; - } - - public double nextDouble() { - return (double) (((long) this.next(26) << 27) + (long) this.next(27)) * 1.1102230246251565E-16; - } - - public double nextGaussian() { - if (this.haveNextNextGaussian) { - this.haveNextNextGaussian = false; - return this.nextNextGaussian; - } else { - double var1; - double var3; - double var5; - do { - do { - var1 = 2.0 * this.nextDouble() - 1.0; - var3 = 2.0 * this.nextDouble() - 1.0; - var5 = var1 * var1 + var3 * var3; - } while (var5 >= 1.0); - } while (var5 == 0.0); - - double var7 = StrictMath.sqrt(-2.0 * StrictMath.log(var5) / var5); - this.nextNextGaussian = var3 * var7; - this.haveNextNextGaussian = true; - return var1 * var7; - } - } -} diff --git a/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java b/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java index fe17f0200cb..d1d9740de4f 100644 --- a/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java +++ b/src/main/java/gtPlusPlus/everglades/chunk/ChunkProviderModded.java @@ -31,7 +31,7 @@ import net.minecraftforge.event.terraingen.PopulateChunkEvent; import net.minecraftforge.event.terraingen.TerrainGen; -import gregtech.api.objects.MolecularRandom; +import gregtech.api.objects.XSTR; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.everglades.dimension.DimensionEverglades; @@ -108,7 +108,7 @@ public ChunkProviderModded(World par1World, long par2) { this.worldObj = par1World; this.field_147435_p = par1World.getWorldInfo() .getTerrainType(); - this.rand = new MolecularRandom(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); From f662b15a2f548a30196419cb787e06ac0b7795a9 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 21:41:09 -0500 Subject: [PATCH 36/47] clean up & mini ore vein fix --- .../api/task/CooperativeScheduler.java | 1 + .../gregtech/common/GTWorldgenerator.java | 60 ++++--------------- 2 files changed, 13 insertions(+), 48 deletions(-) diff --git a/src/main/java/gregtech/api/task/CooperativeScheduler.java b/src/main/java/gregtech/api/task/CooperativeScheduler.java index 9fd1bddfa79..9d14cc7c7ed 100644 --- a/src/main/java/gregtech/api/task/CooperativeScheduler.java +++ b/src/main/java/gregtech/api/task/CooperativeScheduler.java @@ -80,6 +80,7 @@ public void tick(TickEvent.ServerTickEvent event) { iter.remove(); } + // poll the time if the task hasn't if (end == 0) end = System.nanoTime(); if (Gregtech.general.schedulerProfileLevel >= 2) { diff --git a/src/main/java/gregtech/common/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index 46709faa98d..3957748ff8e 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -218,35 +218,6 @@ 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 List seedList = new LinkedList<>(); - // 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) { @@ -359,7 +330,7 @@ public void generateVein(int oreseedX, int oreseedZ) { if (oreveinPercentageRoll < dimensionDef.getOreVeinChance()) { int placementAttempts = 0; boolean oreveinFound = false; - int i; + int i = 0; // Used for outputting orevein weights and bins /* @@ -369,7 +340,8 @@ public void generateVein(int oreseedX, int oreseedZ) { * ); } } */ - for (i = 0; i < oreveinAttempts && placementAttempts < oreveinMaxPlacementAttempts; i++) { + for (i = 0; i < oreveinAttempts && placementAttempts < oreveinMaxPlacementAttempts + && !oreveinFound; i++) { WorldgenGTOreLayer oreLayer = WorldgenQuery.veins() .inDimension(dimensionName) .find(oreveinRNG); @@ -526,29 +498,22 @@ public void run() { long stonegenTime = System.nanoTime(); - int wXbox = this.mX - MAX_VEIN_SIZE; - int eXbox = this.mX + MAX_VEIN_SIZE + 1; // Need to add 1 since it is compared using a < - int nZbox = this.mZ - MAX_VEIN_SIZE; - int sZbox = this.mZ + MAX_VEIN_SIZE + 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); - generateVein(seedList.get(0).mX, seedList.get(0).mZ); - } - long oregenTime = System.nanoTime(); if (tChunk != null) { @@ -556,7 +521,6 @@ public void run() { } long endTime = System.nanoTime(); - long duration = (endTime - startTime); if (debugWorldGen || profileWorldGen) { GTMod.GT_FML_LOGGER.info( @@ -564,7 +528,7 @@ public void run() { + "us Stonegen took " + (stonegenTime - startTime) / 1e3 + "us Worldgen took " - + duration / 1e3 + + (endTime - startTime) / 1e3 + "us"); } } From 4971d6d536531a508b094a3b4c6967a6339528a9 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Sun, 22 Dec 2024 21:41:26 -0500 Subject: [PATCH 37/47] int hashcode utils --- src/main/java/gregtech/api/util/GTUtility.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 8080694a1f0..2739f285350 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -3934,6 +3934,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; From ecb239bef6afb1f800b3a731d299bd7e9f1b5723 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Mon, 23 Dec 2024 15:01:47 -0500 Subject: [PATCH 38/47] disabled void mining in asteroid dims --- .../galacticgreg/MTEVoidMinerBase.java | 78 ++++++++++++++++--- .../galacticgreg/VoidMinerUtility.java | 26 +++---- .../galacticgreg/api/ModDimensionDef.java | 7 ++ .../galacticgreg/api/enums/DimensionDef.java | 13 ++-- .../gtneioreplugin/util/DimensionHelper.java | 6 +- .../resources/assets/gregtech/lang/en_US.lang | 1 + 6 files changed, 96 insertions(+), 35 deletions(-) diff --git a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java index 249446aa854..6e47a53cc84 100644 --- a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java +++ b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.stream.Collectors; +import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -32,9 +33,16 @@ 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; @@ -43,9 +51,12 @@ 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; @@ -105,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(); @@ -158,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); @@ -230,15 +264,35 @@ private void handleFluidConsumption() { if (storedNobleGas == null || !this.consumeNobleGas(storedNobleGas)) this.multiplier = this.TIER_MULTIPLIER; } + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + calculateDropMap(); + } + /** * Computes first the ores related to the dim the VM is in, then the ores added manually, then it computes the * totalWeight for normalisation */ private void calculateDropMap() { - String dimName = this.getBaseMetaTileEntity() - .getWorld().provider.getDimensionName(); - this.dropMap = VoidMinerUtility.dropMapsByDimName.getOrDefault(dimName, new VoidMinerUtility.DropMap()); - this.extraDropMap = VoidMinerUtility.extraDropsByDimName.getOrDefault(dimName, new VoidMinerUtility.DropMap()); + 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(); } @@ -252,13 +306,15 @@ private void handleOutputs() { .filter(GTUtility::isOre) .collect(Collectors.toList()); - final ItemStack output = this.nextOre(); - output.stackSize = multiplier; + if (canVoidMine) { + final ItemStack output = this.nextOre(); + output.stackSize = multiplier; - boolean matchesFilter = contains(inputOres, output); + boolean matchesFilter = contains(inputOres, output); - if (inputOres.isEmpty() || (this.mBlacklist ? !matchesFilter : matchesFilter)) { - this.addOutput(output); + if (inputOres.isEmpty() || (this.mBlacklist ? !matchesFilter : matchesFilter)) { + this.addOutput(output); + } } this.updateSlots(); diff --git a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java index 38a3467c711..e48b4ea47a4 100644 --- a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java +++ b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java @@ -16,6 +16,8 @@ import bartworks.common.configs.Configuration; import bartworks.system.material.WerkstoffLoader; import cpw.mods.fml.common.registry.GameRegistry; +import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.enums.DimensionDef; import galacticgreg.api.enums.DimensionDef.DimNames; import gregtech.GTMod; import gregtech.api.enums.Materials; @@ -133,17 +135,13 @@ public Map getInternalMap() { * Computes the ores of the dims */ public static void generateDropMaps() { - outer: for (WorldgenGTOreLayer layer : WorldgenGTOreLayer.sList) { + for (WorldgenGTOreLayer layer : WorldgenGTOreLayer.sList) { if (!layer.mEnabled) continue; for (String dim : layer.mAllowedDimensions) { - if (dim.equals(DimNames.ENDASTEROIDS)) { - if (layer.mAllowedDimensions.contains(DimNames.THE_END)) { - continue outer; - } else { - dim = DimNames.THE_END; - } - } + ModDimensionDef dimensionDef = DimensionDef.DEF_BY_WORLD_NAME.get(dim); + + if (dimensionDef != null && !dimensionDef.canBeVoidMined) continue; DropMap map = dropMapsByDimName.computeIfAbsent(dim, ignored -> new DropMap()); @@ -154,17 +152,13 @@ public static void generateDropMaps() { } } - outer: for (WorldgenGTOreSmallPieces layer : WorldgenGTOreSmallPieces.sList) { + for (WorldgenGTOreSmallPieces layer : WorldgenGTOreSmallPieces.sList) { if (!layer.mEnabled) continue; for (String dim : layer.mAllowedDimensions) { - if (dim.equals(DimNames.ENDASTEROIDS)) { - if (layer.mAllowedDimensions.contains(DimNames.THE_END)) { - continue outer; - } else { - dim = DimNames.THE_END; - } - } + ModDimensionDef dimensionDef = DimensionDef.DEF_BY_WORLD_NAME.get(dim); + + if (dimensionDef != null && !dimensionDef.canBeVoidMined) continue; DropMap map = dropMapsByDimName.computeIfAbsent(dim, ignored -> new DropMap()); diff --git a/src/main/java/galacticgreg/api/ModDimensionDef.java b/src/main/java/galacticgreg/api/ModDimensionDef.java index e44e2685cdb..1c73077fe4a 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -40,6 +40,7 @@ public class ModDimensionDef { private final Random random = new Random(System.currentTimeMillis()); public boolean hasEoHRecipe = true; + public boolean canBeVoidMined = true; /** * Define a new dimension @@ -384,4 +385,10 @@ public ModDimensionDef disableEoHRecipe() { return this; } + + public ModDimensionDef disableVoidMining() { + canBeVoidMined = false; + + return this; + } } diff --git a/src/main/java/galacticgreg/api/enums/DimensionDef.java b/src/main/java/galacticgreg/api/enums/DimensionDef.java index d3ed812a9d5..95950cf1511 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -29,7 +29,7 @@ public enum DimensionDef { ChunkProviderEnd.class, DimensionType.Planet)), EndAsteroids(new ModDimensionDef( - DimNames.ENDASTEROIDS, + DimNames.ENDASTEROID, ChunkProviderEnd.class, Enums.DimensionType.Asteroid)), TwilightForest(new ModDimensionDef( @@ -57,7 +57,8 @@ public enum DimensionDef { Asteroids(new ModDimensionDef( DimNames.ASTEROIDS, "micdoodle8.mods.galacticraft.planets.asteroids.world.gen.ChunkProviderAsteroids", - Enums.DimensionType.Asteroid)), + Enums.DimensionType.Asteroid) + .disableVoidMining()), Ross128b(new ModDimensionDef( DimNames.ROSS128B, "bwcrossmod.galacticraft.planets.ross128b.ChunkProviderRoss128b", @@ -191,7 +192,8 @@ public enum DimensionDef { KuiperBelt(new ModDimensionDef( DimNames.KUIPERBELT, "galaxyspace.SolarSystem.planets.kuiperbelt.dimension.ChunkProviderKuiper", - Enums.DimensionType.Asteroid)), + Enums.DimensionType.Asteroid) + .disableVoidMining()), Neper(new ModDimensionDef( DimNames.NEPER, @@ -221,7 +223,8 @@ public enum DimensionDef { MehenBelt(new ModDimensionDef( DimNames.MEHENBELT, "de.katzenpapst.amunra.world.mehen.MehenChunkProvider", - Enums.DimensionType.Asteroid)), + Enums.DimensionType.Asteroid) + .disableVoidMining()), DeepDark(new ModDimensionDef( DimNames.DEEPDARK, @@ -264,7 +267,7 @@ public static class DimNames { public static final String OW = "Overworld"; public static final String NETHER = "Nether"; public static final String THE_END = "The End"; - public static final String ENDASTEROIDS = "EndAsteroids"; + public static final String ENDASTEROID = "EndAsteroid"; public static final String TWILIGHT_FOREST = "Twilight Forest"; public static final String EVERGLADES = "dimensionDarkWorld"; diff --git a/src/main/java/gtneioreplugin/util/DimensionHelper.java b/src/main/java/gtneioreplugin/util/DimensionHelper.java index 19f4da39e67..fa99dad3823 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -11,7 +11,7 @@ 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; @@ -221,7 +221,7 @@ public static String getDimAbbreviatedName(String dimName) { case NETHER -> abbreviatedName = "Ne"; // Nether case TWILIGHT_FOREST -> abbreviatedName = "TF"; // Twilight case THE_END -> abbreviatedName = "ED"; // The End because En = Encalus - case ENDASTEROIDS -> abbreviatedName = "EA"; // EndAsteroid + case ENDASTEROID -> abbreviatedName = "EA"; // EndAsteroid case EVERGLADES -> abbreviatedName = "Eg"; // T1 case MOON -> abbreviatedName = "Mo"; // GalacticraftCore_Moon @@ -284,7 +284,7 @@ public static String getFullName(String abbrDimName) { case "Ne" -> NETHER; // Nether case "TF" -> TWILIGHT_FOREST; // Twilight case "ED" -> THE_END; // The End because En = Encalus - case "EA" -> ENDASTEROIDS; // EndAsteroid + case "EA" -> ENDASTEROID; // EndAsteroid case "Eg" -> EVERGLADES; // T1 case "Mo" -> MOON; // GalacticraftCore_Moon diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index 01e8c4c2c96..029fad0fd58 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -578,6 +578,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. From a730939c320b8e030522f347eb85bf1b466a8812 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Mon, 23 Dec 2024 15:32:09 -0500 Subject: [PATCH 39/47] improve asteroid profiling --- .../galacticgreg/WorldGeneratorSpace.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 2ade9add6b3..20ed6a38dd0 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -58,9 +58,9 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP } if (tDimDef.getDimensionType() == Enums.DimensionType.Asteroid) { - boolean modified = false; + long pre = profileWorldGen ? System.nanoTime() : 0; - long pre = System.nanoTime(); + int seeds = 0; for (int offsetZ = -2; offsetZ <= 2; offsetZ++) { for (int offsetX = -2; offsetX <= 2; offsetX++) { @@ -72,18 +72,25 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP gen.generateChunk(world, chunkX, chunkZ); - modified = true; + seeds++; } } - long post = System.nanoTime(); + long post = profileWorldGen ? System.nanoTime() : 0; - if (profileWorldGen) GTMod.GT_FML_LOGGER - .info(String.format("Generated %d %d in %,.3f us", chunkX, chunkZ, (post - pre) / 1e3)); + 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 = world.getChunkFromBlockCoords(chunkX, chunkZ); if (tChunk != null) { - tChunk.isModified = modified; + tChunk.isModified = seeds > 0; } } } From 9584c496cb2935c59ef42e8598c7f91e726476dc Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Mon, 23 Dec 2024 15:41:14 -0500 Subject: [PATCH 40/47] Remove metadata casts to byte These are incompatible with NEID and can cause problems with blocks whose metadata can go over 127. --- src/main/java/bartworks/API/GlassTier.java | 4 +-- .../system/material/BWMetaGeneratedItems.java | 2 +- .../DetravToolElectricProspectorBase.java | 9 +++--- .../api/interfaces/IBlockContainer.java | 2 +- .../api/interfaces/IRedstoneCircuitBlock.java | 2 +- .../gregtech/api/interfaces/IToolStats.java | 8 ++--- .../tileentity/IHasWorldObjectAndCoords.java | 8 ++--- .../gregtech/api/items/MetaGeneratedTool.java | 8 ++--- .../api/metatileentity/BaseTileEntity.java | 10 +++--- .../java/gregtech/api/util/GTBlockMap.java | 32 +++++++++---------- .../java/gregtech/api/util/GTBlockSet.java | 6 ++-- .../api/util/GTToolHarvestHelper.java | 2 +- .../java/gregtech/api/util/GTUtility.java | 4 +-- src/main/java/gregtech/common/GTProxy.java | 6 ++-- .../common/items/MetaGeneratedItem01.java | 6 ++-- .../items/behaviors/BehaviourCrowbar.java | 2 +- .../items/behaviors/BehaviourScrewdriver.java | 2 +- .../items/behaviors/BehaviourSoftHammer.java | 2 +- .../render/GTCopiedBlockTextureRender.java | 7 ++-- .../render/GTCopiedCTMBlockTexture.java | 7 ++-- .../common/render/GTTextureBuilder.java | 4 +-- .../MTELongDistancePipelineBase.java | 2 +- .../machines/multi/MTEOilCracker.java | 2 +- .../java/gregtech/common/tools/GTTool.java | 4 +-- .../common/tools/ToolBranchCutter.java | 4 +-- .../common/tools/ToolButcheryKnife.java | 2 +- .../gregtech/common/tools/ToolBuzzSaw.java | 2 +- .../gregtech/common/tools/ToolChainsawLV.java | 6 ++-- .../gregtech/common/tools/ToolCrowbar.java | 2 +- .../gregtech/common/tools/ToolDrillLV.java | 2 +- .../java/gregtech/common/tools/ToolFile.java | 2 +- .../gregtech/common/tools/ToolHardHammer.java | 4 +-- .../gregtech/common/tools/ToolJackHammer.java | 4 +-- .../java/gregtech/common/tools/ToolKnife.java | 2 +- .../gregtech/common/tools/ToolMortar.java | 2 +- .../gregtech/common/tools/ToolPlunger.java | 2 +- .../gregtech/common/tools/ToolRollingPin.java | 2 +- .../java/gregtech/common/tools/ToolSaw.java | 4 +-- .../java/gregtech/common/tools/ToolScoop.java | 2 +- .../common/tools/ToolScrewdriver.java | 2 +- .../gregtech/common/tools/ToolSoftHammer.java | 2 +- .../common/tools/ToolSolderingIron.java | 2 +- .../gregtech/common/tools/ToolTurbine.java | 2 +- .../gregtech/common/tools/ToolWireCutter.java | 2 +- .../gregtech/common/tools/ToolWrench.java | 6 ++-- .../tools/pocket/ToolPocketMultitool.java | 2 +- .../api/interfaces/ILazyCoverable.java | 8 ++--- .../tileentities/base/TileEntityBase.java | 10 +++--- .../api/interfaces/internal/IToolStats.java | 4 +-- .../xmod/gregtech/api/items/GTMetaTool.java | 4 +-- .../blocks/GregtechMetaCasingBlocks4.java | 4 +-- .../GregtechMetaSpecialMultiCasings.java | 4 +-- .../GregtechMetaSpecialMultiCasings2.java | 6 ++-- .../turbine/LargeTurbineTextureHandler.java | 2 +- .../processing/MTEIndustrialWashPlant.java | 1 - .../production/MTEIndustrialFishingPond.java | 4 +-- .../production/algae/MTEAlgaePondBase.java | 4 +-- ...aTileEntity_PowerSubStationController.java | 2 +- .../redstone/MTERedstoneCircuitBlock.java | 2 +- .../common/tools/ToolAngleGrinder.java | 4 +-- 60 files changed, 131 insertions(+), 129 deletions(-) diff --git a/src/main/java/bartworks/API/GlassTier.java b/src/main/java/bartworks/API/GlassTier.java index 64612549c9a..897deddddbe 100644 --- a/src/main/java/bartworks/API/GlassTier.java +++ b/src/main/java/bartworks/API/GlassTier.java @@ -34,7 +34,7 @@ public static void addCustomGlass(String modname, String unlocalisedBlockName, i public static void addCustomGlass(@NotNull Block block, int meta, int tier) { Objects.requireNonNull(block, "Glass block cannot be null"); - GlassTier.glasses.put(new BlockMetaPair(block, (byte) meta), tier); + GlassTier.glasses.put(new BlockMetaPair(block, meta), tier); } public static HashMap getGlassMap() { @@ -42,7 +42,7 @@ public static HashMap getGlassMap() { } public static int getGlassTier(Block block, int meta) { - return glasses.getOrDefault(new BlockMetaPair(block, (byte) meta), 0); + return glasses.getOrDefault(new BlockMetaPair(block, meta), 0); } public static class BlockMetaPair { diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedItems.java b/src/main/java/bartworks/system/material/BWMetaGeneratedItems.java index cd8e360da6a..ae47f0d658c 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedItems.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedItems.java @@ -92,7 +92,7 @@ public boolean onEntityItemUpdate(EntityItem aItemEntity) { int tY = MathHelper.floor_double(aItemEntity.posY); int tZ = MathHelper.floor_double(aItemEntity.posZ); Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ); - byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ); + int tMetaData = aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ); if (tBlock == Blocks.cauldron && tMetaData > 0) { if (this.orePrefixes == OrePrefixes.dustImpure || this.orePrefixes == OrePrefixes.dustPure) { aItemEntity.setEntityItemStack( diff --git a/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java b/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java index 66d38c39ea9..59619ca090c 100644 --- a/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java +++ b/src/main/java/detrav/items/tools/DetravToolElectricProspectorBase.java @@ -138,14 +138,14 @@ public boolean isMiningTool() { return false; } - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } @Override public int convertBlockDrops(List list, ItemStack itemStack, EntityPlayer entityPlayer, Block block, - int i, int i1, int i2, byte b, int i3, boolean b1, BlockEvent.HarvestDropsEvent harvestDropsEvent) { + int i, int i1, int i2, int b, int i3, boolean b1, BlockEvent.HarvestDropsEvent harvestDropsEvent) { return 0; } @@ -193,8 +193,9 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase + EnumChatFormatting.WHITE); } - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, - int aX, int aY, int aZ) { + @Override + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, + int aY, int aZ) { return aDefault; } } diff --git a/src/main/java/gregtech/api/interfaces/IBlockContainer.java b/src/main/java/gregtech/api/interfaces/IBlockContainer.java index 5a80655a5ce..463d23b7425 100644 --- a/src/main/java/gregtech/api/interfaces/IBlockContainer.java +++ b/src/main/java/gregtech/api/interfaces/IBlockContainer.java @@ -6,5 +6,5 @@ public interface IBlockContainer { Block getBlock(); - byte getMeta(); + int getMeta(); } diff --git a/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java b/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java index a0a362c4e51..328da78bf44 100644 --- a/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java +++ b/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java @@ -50,7 +50,7 @@ public interface IRedstoneCircuitBlock { /** * returns whatever Meta-Value is adjacent to the Redstone Circuit Block */ - byte getMetaIDAtSide(ForgeDirection side); + int getMetaIDAtSide(ForgeDirection side); /** * returns whatever TileEntity is adjacent to the Redstone Circuit Block diff --git a/src/main/java/gregtech/api/interfaces/IToolStats.java b/src/main/java/gregtech/api/interfaces/IToolStats.java index 64fc81196c8..052dccfc521 100644 --- a/src/main/java/gregtech/api/interfaces/IToolStats.java +++ b/src/main/java/gregtech/api/interfaces/IToolStats.java @@ -47,7 +47,7 @@ public interface IToolStats { * @param tile TileEntity of the block if exist * @param event the event, cancel it to prevent the block from being broken */ - default void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, byte metadata, + default void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, int metadata, @Nullable TileEntity tile, @Nonnull BlockEvent.BreakEvent event) {} /** @@ -164,7 +164,7 @@ default boolean isScrewdriver() { * @return If this is a minable Block. Tool Quality checks (like Diamond Tier or something) are separate from this * check. */ - boolean isMinableBlock(Block aBlock, byte aMetaData); + boolean isMinableBlock(Block aBlock, int aMetaData); /** * This lets you modify the Drop List, when this type of Tool has been used. @@ -172,7 +172,7 @@ default boolean isScrewdriver() { * @return the Amount of modified Items, used to determine the extra durability cost */ int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, int aY, - int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); + int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); /** * @return Returns a broken Version of the Item. @@ -193,7 +193,7 @@ int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPl short[] getRGBa(boolean aIsToolHead, ItemStack aStack); - float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, + float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, int aY, int aZ); default String getToolTypeName() { diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java b/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java index b62c3e92cf9..429cfe39536 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java @@ -79,13 +79,13 @@ default ChunkCoordinates getCoords() { Block getBlockAtSideAndDistance(ForgeDirection side, int aDistance); - byte getMetaID(int aX, int aY, int aZ); + int getMetaID(int aX, int aY, int aZ); - byte getMetaIDOffset(int aX, int aY, int aZ); + int getMetaIDOffset(int aX, int aY, int aZ); - byte getMetaIDAtSide(ForgeDirection side); + int getMetaIDAtSide(ForgeDirection side); - byte getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance); + int getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance); byte getLightLevel(int aX, int aY, int aZ); diff --git a/src/main/java/gregtech/api/items/MetaGeneratedTool.java b/src/main/java/gregtech/api/items/MetaGeneratedTool.java index 4c9cdf39ae8..87698c7dbb6 100644 --- a/src/main/java/gregtech/api/items/MetaGeneratedTool.java +++ b/src/main/java/gregtech/api/items/MetaGeneratedTool.java @@ -255,7 +255,7 @@ public final ItemStack getToolWithStats(int aToolID, int aAmount, Materials aPri */ @Mod.EventHandler public void onHarvestBlockEvent(ArrayList aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, - int aX, int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aX, int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { IToolStats tStats = getToolStats(aStack); if (isItemStackUsable(aStack) && getDigSpeed(aStack, aBlock, aMetaData) > 0.0F) doDamage( aStack, @@ -266,7 +266,7 @@ public void onHarvestBlockEvent(ArrayList aDrops, ItemStack aStack, E @Mod.EventHandler public float onBlockBreakSpeedEvent(float aDefault, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, PlayerEvent.BreakSpeed aEvent) { + int aY, int aZ, int aMetaData, PlayerEvent.BreakSpeed aEvent) { IToolStats tStats = getToolStats(aStack); return tStats == null ? aDefault : tStats.getMiningSpeed(aBlock, aMetaData, aDefault, aPlayer, aPlayer.worldObj, aX, aY, aZ); @@ -695,14 +695,14 @@ public float getDigSpeed(ItemStack aStack, Block aBlock, int aMetaData) { if (!isItemStackUsable(aStack)) return 0.0F; IToolStats tStats = getToolStats(aStack); if (tStats == null || Math.max(0, getHarvestLevel(aStack, "")) < aBlock.getHarvestLevel(aMetaData)) return 0.0F; - return tStats.isMinableBlock(aBlock, (byte) aMetaData) + return tStats.isMinableBlock(aBlock, aMetaData) ? Math.max(Float.MIN_NORMAL, tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed) : 0.0F; } @Override public final boolean canHarvestBlock(Block aBlock, ItemStack aStack) { - return getDigSpeed(aStack, aBlock, (byte) 0) > 0.0F; + return getDigSpeed(aStack, aBlock, 0) > 0.0F; } @Override diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index f2b5278e49d..37f2871d761 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -221,17 +221,17 @@ public final Block getBlockAtSideAndDistance(ForgeDirection side, int distance) } @Override - public final byte getMetaIDOffset(int x, int y, int z) { + public final int getMetaIDOffset(int x, int y, int z) { return getMetaID(xCoord + x, yCoord + y, zCoord + z); } @Override - public final byte getMetaIDAtSide(ForgeDirection side) { + public final int getMetaIDAtSide(ForgeDirection side) { return getMetaIDAtSideAndDistance(side, 1); } @Override - public final byte getMetaIDAtSideAndDistance(ForgeDirection side, int distance) { + public final int getMetaIDAtSideAndDistance(ForgeDirection side, int distance) { return getMetaID(getOffsetX(side, distance), getOffsetY(side, distance), getOffsetZ(side, distance)); } @@ -404,9 +404,9 @@ public Block getBlock(ChunkCoordinates aCoords) { } @Override - public final byte getMetaID(int x, int y, int z) { + public final int getMetaID(int x, int y, int z) { if (ignoreUnloadedChunks && crossedChunkBorder(x, z) && !worldObj.blockExists(x, y, z)) return 0; - return (byte) worldObj.getBlockMetadata(x, y, z); + return worldObj.getBlockMetadata(x, y, z); } @Override diff --git a/src/main/java/gregtech/api/util/GTBlockMap.java b/src/main/java/gregtech/api/util/GTBlockMap.java index a5ac98d4271..a0a2e755ea4 100644 --- a/src/main/java/gregtech/api/util/GTBlockMap.java +++ b/src/main/java/gregtech/api/util/GTBlockMap.java @@ -5,17 +5,17 @@ import net.minecraft.block.Block; -import gnu.trove.map.TByteObjectMap; -import gnu.trove.map.hash.TByteObjectHashMap; +import gnu.trove.map.TIntObjectMap; +import gnu.trove.map.hash.TIntObjectHashMap; public class GTBlockMap { - public static final byte WILDCARD = -1; - private final ConcurrentHashMap> backing = new ConcurrentHashMap<>(); + public static final int WILDCARD = -1; + private final ConcurrentHashMap> backing = new ConcurrentHashMap<>(); private int size = 0; - private TByteObjectMap getSubmap(Block block) { - return backing.computeIfAbsent(block, b -> new TByteObjectHashMap<>()); + private TIntObjectMap getSubmap(Block block) { + return backing.computeIfAbsent(block, b -> new TIntObjectHashMap<>()); } /** @@ -25,7 +25,7 @@ private TByteObjectMap getSubmap(Block block) { * @param meta meta * @return old mapping, or null if that doesn't exist */ - public V put(Block block, byte meta, V value) { + public V put(Block block, int meta, V value) { V v = getSubmap(block).put(meta, value); if (v == null) size++; return v; @@ -38,7 +38,7 @@ public V put(Block block, byte meta, V value) { * @param meta meta * @return old mapping, or null if that doesn't exist */ - public V putIfAbsent(Block block, byte meta, V value) { + public V putIfAbsent(Block block, int meta, V value) { V v = getSubmap(block).putIfAbsent(meta, value); if (v == null) size++; return v; @@ -51,8 +51,8 @@ public V putIfAbsent(Block block, byte meta, V value) { * @param meta meta * @return old mapping, or null if that doesn't exist */ - public V computeIfAbsent(Block block, byte meta, BiFunction function) { - TByteObjectMap submap = getSubmap(block); + public V computeIfAbsent(Block block, int meta, BiFunction function) { + TIntObjectMap submap = getSubmap(block); V v = submap.get(meta); if (v == null) { v = function.apply(block, meta); @@ -69,8 +69,8 @@ public V computeIfAbsent(Block block, byte meta, BiFunction func * @param meta meta * @return current mapping OR wildcard of that mapping exists */ - public boolean containsKey(Block block, byte meta) { - TByteObjectMap submap = backing.get(block); + public boolean containsKey(Block block, int meta) { + TIntObjectMap submap = backing.get(block); if (submap == null) return false; return submap.containsKey(meta) || submap.containsKey(WILDCARD); } @@ -82,8 +82,8 @@ public boolean containsKey(Block block, byte meta) { * @param meta meta * @return current mapping OR wildcard of that block. null if neither exists */ - public V get(Block block, byte meta) { - TByteObjectMap submap = backing.get(block); + public V get(Block block, int meta) { + TIntObjectMap submap = backing.get(block); if (submap == null) return null; V v = submap.get(meta); if (v != null) return v; @@ -97,8 +97,8 @@ public V get(Block block, byte meta) { * @param meta meta * @return old value, or null if none */ - public V remove(Block block, byte meta) { - TByteObjectMap submap = backing.get(block); + public V remove(Block block, int meta) { + TIntObjectMap submap = backing.get(block); if (submap == null) return null; V v = submap.remove(meta); if (v != null) { diff --git a/src/main/java/gregtech/api/util/GTBlockSet.java b/src/main/java/gregtech/api/util/GTBlockSet.java index 6c91193832f..36086030b7d 100644 --- a/src/main/java/gregtech/api/util/GTBlockSet.java +++ b/src/main/java/gregtech/api/util/GTBlockSet.java @@ -6,15 +6,15 @@ public class GTBlockSet { private final GTBlockMap backing = new GTBlockMap<>(); - public boolean add(Block block, byte meta) { + public boolean add(Block block, int meta) { return backing.put(block, meta, this) != this; } - public boolean contains(Block block, byte meta) { + public boolean contains(Block block, int meta) { return backing.get(block, meta) == this; } - public boolean remove(Block block, byte meta) { + public boolean remove(Block block, int meta) { return backing.remove(block, meta) == this; } diff --git a/src/main/java/gregtech/api/util/GTToolHarvestHelper.java b/src/main/java/gregtech/api/util/GTToolHarvestHelper.java index 8dd5d6b93c4..5a09aaf6538 100644 --- a/src/main/java/gregtech/api/util/GTToolHarvestHelper.java +++ b/src/main/java/gregtech/api/util/GTToolHarvestHelper.java @@ -12,7 +12,7 @@ public class GTToolHarvestHelper { - public static boolean isAppropriateTool(Block aBlock, byte aMetaData, String... tTools) { + public static boolean isAppropriateTool(Block aBlock, int aMetaData, String... tTools) { if (aBlock == null || tTools == null) { return false; diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index da805f995db..901c7ae54d1 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -2525,7 +2525,7 @@ public static int getTextureId(byte page, byte startIndex, byte blockMeta) { * * @return casing texture 0 to 16383 */ - public static int getTextureId(Block blockFromBlock, byte metaFromBlock) { + public static int getTextureId(Block blockFromBlock, int metaFromBlock) { for (int page = 0; page < Textures.BlockIcons.casingTexturePages.length; page++) { ITexture[] casingTexturePage = Textures.BlockIcons.casingTexturePages[page]; if (casingTexturePage != null) { @@ -2533,7 +2533,7 @@ public static int getTextureId(Block blockFromBlock, byte metaFromBlock) { ITexture iTexture = casingTexturePage[index]; if (iTexture instanceof IBlockContainer) { Block block = ((IBlockContainer) iTexture).getBlock(); - byte meta = ((IBlockContainer) iTexture).getMeta(); + int meta = ((IBlockContainer) iTexture).getMeta(); if (meta == metaFromBlock && blockFromBlock == block) { return (page << 7) + index; } diff --git a/src/main/java/gregtech/common/GTProxy.java b/src/main/java/gregtech/common/GTProxy.java index 2bedabd299c..c85c27aaf19 100644 --- a/src/main/java/gregtech/common/GTProxy.java +++ b/src/main/java/gregtech/common/GTProxy.java @@ -1555,7 +1555,7 @@ public void onBlockBreakingEvent(BlockEvent.BreakEvent event) { if (stats == null) return; TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z); - stats.onBreakBlock(player, event.x, event.y, event.z, event.block, (byte) event.blockMetadata, tile, event); + stats.onBreakBlock(player, event.x, event.y, event.z, event.block, event.blockMetadata, tile, event); } @SubscribeEvent @@ -1574,7 +1574,7 @@ public void onBlockHarvestingEvent(BlockEvent.HarvestDropsEvent aEvent) { aEvent.x, aEvent.y, aEvent.z, - (byte) aEvent.blockMetadata, + aEvent.blockMetadata, aEvent.fortuneLevel, aEvent.isSilkTouching, aEvent); @@ -2694,7 +2694,7 @@ public void onBlockBreakSpeedEvent(PlayerEvent.BreakSpeed aEvent) { aEvent.x, aEvent.y, aEvent.z, - (byte) aEvent.metadata, + aEvent.metadata, aEvent); } } diff --git a/src/main/java/gregtech/common/items/MetaGeneratedItem01.java b/src/main/java/gregtech/common/items/MetaGeneratedItem01.java index 0b96caea028..59bc08da17f 100644 --- a/src/main/java/gregtech/common/items/MetaGeneratedItem01.java +++ b/src/main/java/gregtech/common/items/MetaGeneratedItem01.java @@ -3459,7 +3459,7 @@ public boolean onEntityItemUpdate(EntityItem aItemEntity) { OrePrefixes aPrefix = this.mGeneratedPrefixList[(aDamage / 1000)]; if ((aPrefix == OrePrefixes.dustImpure) || (aPrefix == OrePrefixes.dustPure)) { Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ); - byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ); + int tMetaData = aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ); if ((tBlock == Blocks.cauldron) && (tMetaData > 0)) { aMaterial = cauldronRemap.getOrDefault(aMaterial, aMaterial); @@ -3472,7 +3472,7 @@ public boolean onEntityItemUpdate(EntityItem aItemEntity) { } } else if (aPrefix == OrePrefixes.crushed) { Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ); - byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ); + int tMetaData = aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ); if ((tBlock == Blocks.cauldron) && (tMetaData > 0)) { aItemEntity.setEntityItemStack( GTOreDictUnificator @@ -3482,7 +3482,7 @@ public boolean onEntityItemUpdate(EntityItem aItemEntity) { } } else if (aPrefix == OrePrefixes.dust && aMaterial == Materials.Wheat) { Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ); - byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ); + int tMetaData = aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ); if ((tBlock == Blocks.cauldron) && (tMetaData > 0)) { aItemEntity.setEntityItemStack(ItemList.Food_Dough.get(aItemEntity.getEntityItem().stackSize)); aItemEntity.worldObj.setBlockMetadataWithNotify(tX, tY, tZ, tMetaData - 1, 3); diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java b/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java index 76c215bfd00..da9b3f336a3 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java @@ -37,7 +37,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (aBlock == null) { return false; } - byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); + int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); if (aBlock == Blocks.rail) { if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) { aWorld.isRemote = true; diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourScrewdriver.java b/src/main/java/gregtech/common/items/behaviors/BehaviourScrewdriver.java index 599398349f8..029f94fc5c8 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourScrewdriver.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourScrewdriver.java @@ -32,7 +32,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (aBlock == null) { return false; } - byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); + int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); if ((aBlock == Blocks.unpowered_repeater) || (aBlock == Blocks.powered_repeater)) { if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) { aWorld.setBlockMetadataWithNotify(aX, aY, aZ, aMeta / 4 * 4 + (aMeta % 4 + 1) % 4, 3); diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourSoftHammer.java b/src/main/java/gregtech/common/items/behaviors/BehaviourSoftHammer.java index 83e458276db..72c930ac60f 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourSoftHammer.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourSoftHammer.java @@ -35,7 +35,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer if (aBlock == null) { return false; } - byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); + int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); if (aBlock == Blocks.lit_redstone_lamp) { if ((aPlayer.capabilities.isCreativeMode) || (((MetaGeneratedTool) aItem).doDamage(aStack, this.mCosts))) { aWorld.isRemote = true; diff --git a/src/main/java/gregtech/common/render/GTCopiedBlockTextureRender.java b/src/main/java/gregtech/common/render/GTCopiedBlockTextureRender.java index 3ce88236635..3966654df46 100644 --- a/src/main/java/gregtech/common/render/GTCopiedBlockTextureRender.java +++ b/src/main/java/gregtech/common/render/GTCopiedBlockTextureRender.java @@ -12,14 +12,15 @@ public class GTCopiedBlockTextureRender extends GTTextureBase implements ITexture, IBlockContainer { private final Block mBlock; - private final byte mSide, mMeta; + private final byte mSide; + private final int mMeta; protected GTCopiedBlockTextureRender(Block aBlock, int ordinalSide, int aMeta, short[] aRGBa, boolean allowAlpha) { if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GTCopiedBlockTextureRender"); mBlock = aBlock; mSide = (byte) ordinalSide; - mMeta = (byte) aMeta; + mMeta = aMeta; } @Override @@ -107,7 +108,7 @@ public Block getBlock() { } @Override - public byte getMeta() { + public int getMeta() { return mMeta; } } diff --git a/src/main/java/gregtech/common/render/GTCopiedCTMBlockTexture.java b/src/main/java/gregtech/common/render/GTCopiedCTMBlockTexture.java index a33ead9ec54..1bfe6b55e8d 100644 --- a/src/main/java/gregtech/common/render/GTCopiedCTMBlockTexture.java +++ b/src/main/java/gregtech/common/render/GTCopiedCTMBlockTexture.java @@ -13,14 +13,15 @@ class GTCopiedCTMBlockTexture extends GTTextureBase implements ITexture, IBlockContainer { private final Block mBlock; - private final byte mSide, mMeta; + private final byte mSide; + private final int mMeta; GTCopiedCTMBlockTexture(Block aBlock, int ordinalSide, int aMeta, short[] aRGBa, boolean allowAlpha) { if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GTCopiedCTMBlockTexture"); mBlock = aBlock; mSide = (byte) ordinalSide; - mMeta = (byte) aMeta; + mMeta = aMeta; } @Override @@ -112,7 +113,7 @@ public Block getBlock() { } @Override - public byte getMeta() { + public int getMeta() { return mMeta; } } diff --git a/src/main/java/gregtech/common/render/GTTextureBuilder.java b/src/main/java/gregtech/common/render/GTTextureBuilder.java index aad734b8288..0346c579a46 100644 --- a/src/main/java/gregtech/common/render/GTTextureBuilder.java +++ b/src/main/java/gregtech/common/render/GTTextureBuilder.java @@ -134,10 +134,10 @@ public ITexture build() { } private boolean isCTMBlock(Block fromBlock, int fromMeta) { - return GTMod.gregtechproxy.mCTMBlockCache.computeIfAbsent(fromBlock, (byte) fromMeta, GTTextureBuilder::apply); + return GTMod.gregtechproxy.mCTMBlockCache.computeIfAbsent(fromBlock, fromMeta, GTTextureBuilder::apply); } - private static Boolean apply(Block b, Byte m) { + private static Boolean apply(Block b, int m) { Class clazz = b.getClass(); while (clazz != Block.class) { final String className = clazz.getName(); diff --git a/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java index 259988c16aa..e3f270e8a28 100644 --- a/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/long_distance/MTELongDistancePipelineBase.java @@ -215,7 +215,7 @@ protected void scanPipes() { Block aBlock = gtTile.getBlockAtSide(gtTile.getBackFacing()); if (aBlock instanceof BlockLongDistancePipe) { - byte aMetaData = gtTile.getMetaIDAtSide(gtTile.getBackFacing()); + int aMetaData = gtTile.getMetaIDAtSide(gtTile.getBackFacing()); if (aMetaData != getPipeMeta()) return; HashSet tVisited = new HashSet<>(Collections.singletonList(getCoords())), diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java index 32651313a31..885d9e90fe0 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOilCracker.java @@ -304,7 +304,7 @@ private void replaceDeprecatedCoils(IGregTechTileEntity aBaseMetaTileEntity) { for (int yPos = tY - 1; yPos <= tY + 1; yPos++) for (int zPos = tZ - 1; zPos <= tZ + 1; zPos += (xDir != 0 ? 2 : 1)) { if ((yPos == tY) && (xPos == tX || zPos == tZ)) continue; - final byte tUsedMeta = aBaseMetaTileEntity.getMetaID(xPos, yPos, zPos); + final int tUsedMeta = aBaseMetaTileEntity.getMetaID(xPos, yPos, zPos); if (tUsedMeta < 12) continue; if (tUsedMeta > 14) continue; if (aBaseMetaTileEntity.getBlock(xPos, yPos, zPos) != GregTechAPI.sBlockCasings1) continue; diff --git a/src/main/java/gregtech/common/tools/GTTool.java b/src/main/java/gregtech/common/tools/GTTool.java index 436ec767a99..78fc28883f9 100644 --- a/src/main/java/gregtech/common/tools/GTTool.java +++ b/src/main/java/gregtech/common/tools/GTTool.java @@ -142,7 +142,7 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { return 0; } @@ -184,7 +184,7 @@ public float getMagicDamageAgainstEntity(float aOriginalDamage, Entity aEntity, } @Override - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, int aY, int aZ) { return aDefault; } diff --git a/src/main/java/gregtech/common/tools/ToolBranchCutter.java b/src/main/java/gregtech/common/tools/ToolBranchCutter.java index c9ad255a457..54a17c9f9c2 100644 --- a/src/main/java/gregtech/common/tools/ToolBranchCutter.java +++ b/src/main/java/gregtech/common/tools/ToolBranchCutter.java @@ -45,7 +45,7 @@ public boolean isGrafter() { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { if (aBlock.getMaterial() == Material.leaves) { aEvent.dropChance = Math.min( 1.0F, @@ -72,7 +72,7 @@ public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPla } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "grafter") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.leaves); } diff --git a/src/main/java/gregtech/common/tools/ToolButcheryKnife.java b/src/main/java/gregtech/common/tools/ToolButcheryKnife.java index 43323b84047..926a1440aaa 100644 --- a/src/main/java/gregtech/common/tools/ToolButcheryKnife.java +++ b/src/main/java/gregtech/common/tools/ToolButcheryKnife.java @@ -98,7 +98,7 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } } diff --git a/src/main/java/gregtech/common/tools/ToolBuzzSaw.java b/src/main/java/gregtech/common/tools/ToolBuzzSaw.java index 7e62ab7bb42..e47b1c00742 100644 --- a/src/main/java/gregtech/common/tools/ToolBuzzSaw.java +++ b/src/main/java/gregtech/common/tools/ToolBuzzSaw.java @@ -50,7 +50,7 @@ public String getMiningSound() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } diff --git a/src/main/java/gregtech/common/tools/ToolChainsawLV.java b/src/main/java/gregtech/common/tools/ToolChainsawLV.java index ad47ae2cdc0..6ed7918acc1 100644 --- a/src/main/java/gregtech/common/tools/ToolChainsawLV.java +++ b/src/main/java/gregtech/common/tools/ToolChainsawLV.java @@ -106,7 +106,7 @@ public void onToolCrafted(ItemStack aStack, EntityPlayer aPlayer) { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rAmount = 0; if ((aBlock.getMaterial() == Material.leaves) && ((aBlock instanceof IShearable))) { aPlayer.worldObj.setBlock(aX, aY, aZ, aBlock, aMetaData, 0); @@ -137,8 +137,8 @@ public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPla } @Override - public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, - int aX, int aY, int aZ) { + public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, + int aY, int aZ) { if (aBlock.isWood(aPlayer.worldObj, aX, aY, aZ) && OrePrefixes.log.contains(new ItemStack(aBlock, 1, aMetaData))) { float rAmount = 1.0F; diff --git a/src/main/java/gregtech/common/tools/ToolCrowbar.java b/src/main/java/gregtech/common/tools/ToolCrowbar.java index db72d65a6dc..516c0138161 100644 --- a/src/main/java/gregtech/common/tools/ToolCrowbar.java +++ b/src/main/java/gregtech/common/tools/ToolCrowbar.java @@ -90,7 +90,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { if (aBlock.getMaterial() == Material.circuits) { return true; } diff --git a/src/main/java/gregtech/common/tools/ToolDrillLV.java b/src/main/java/gregtech/common/tools/ToolDrillLV.java index 1c6dfd7de3c..db8d46addd0 100644 --- a/src/main/java/gregtech/common/tools/ToolDrillLV.java +++ b/src/main/java/gregtech/common/tools/ToolDrillLV.java @@ -90,7 +90,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "pickaxe", "shovel") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, diff --git a/src/main/java/gregtech/common/tools/ToolFile.java b/src/main/java/gregtech/common/tools/ToolFile.java index 8e64dafdd21..6118f1597ea 100644 --- a/src/main/java/gregtech/common/tools/ToolFile.java +++ b/src/main/java/gregtech/common/tools/ToolFile.java @@ -85,7 +85,7 @@ public boolean isMiningTool() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "file"); } diff --git a/src/main/java/gregtech/common/tools/ToolHardHammer.java b/src/main/java/gregtech/common/tools/ToolHardHammer.java index a5b0a38ee56..323a1637c3e 100644 --- a/src/main/java/gregtech/common/tools/ToolHardHammer.java +++ b/src/main/java/gregtech/common/tools/ToolHardHammer.java @@ -120,7 +120,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "hammer", "pickaxe") || GTToolHarvestHelper .isAppropriateMaterial(aBlock, Material.rock, Material.glass, Material.ice, Material.packedIce) @@ -129,7 +129,7 @@ public boolean isMinableBlock(Block aBlock, byte aMetaData) { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rConversions = 0; GTRecipe tRecipe = RecipeMaps.hammerRecipes.findRecipeQuery() .items(new ItemStack(aBlock, 1, aMetaData)) diff --git a/src/main/java/gregtech/common/tools/ToolJackHammer.java b/src/main/java/gregtech/common/tools/ToolJackHammer.java index bc0a7ddcc0b..24c4815d00d 100644 --- a/src/main/java/gregtech/common/tools/ToolJackHammer.java +++ b/src/main/java/gregtech/common/tools/ToolJackHammer.java @@ -63,7 +63,7 @@ public float getMaxDurabilityMultiplier() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "pickaxe") // || GTToolHarvestHelper.isAppropriateMaterial( aBlock, // @@ -76,7 +76,7 @@ public boolean isMinableBlock(Block aBlock, byte aMetaData) { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { int rConversions = 0; GTRecipe tRecipe = RecipeMaps.hammerRecipes.findRecipeQuery() .items(new ItemStack(aBlock, 1, aMetaData)) diff --git a/src/main/java/gregtech/common/tools/ToolKnife.java b/src/main/java/gregtech/common/tools/ToolKnife.java index c5b8273d254..3005c746207 100644 --- a/src/main/java/gregtech/common/tools/ToolKnife.java +++ b/src/main/java/gregtech/common/tools/ToolKnife.java @@ -72,7 +72,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "sword") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, diff --git a/src/main/java/gregtech/common/tools/ToolMortar.java b/src/main/java/gregtech/common/tools/ToolMortar.java index e67e5924de6..c7223807ccc 100644 --- a/src/main/java/gregtech/common/tools/ToolMortar.java +++ b/src/main/java/gregtech/common/tools/ToolMortar.java @@ -85,7 +85,7 @@ public boolean isMiningTool() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } diff --git a/src/main/java/gregtech/common/tools/ToolPlunger.java b/src/main/java/gregtech/common/tools/ToolPlunger.java index 5cb9bcff482..422825833fe 100644 --- a/src/main/java/gregtech/common/tools/ToolPlunger.java +++ b/src/main/java/gregtech/common/tools/ToolPlunger.java @@ -45,7 +45,7 @@ public String getMiningSound() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "plunger"); } diff --git a/src/main/java/gregtech/common/tools/ToolRollingPin.java b/src/main/java/gregtech/common/tools/ToolRollingPin.java index 1af17f3072b..4e7cb251600 100644 --- a/src/main/java/gregtech/common/tools/ToolRollingPin.java +++ b/src/main/java/gregtech/common/tools/ToolRollingPin.java @@ -40,7 +40,7 @@ public float getBaseDamage() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } diff --git a/src/main/java/gregtech/common/tools/ToolSaw.java b/src/main/java/gregtech/common/tools/ToolSaw.java index ca1ec81b137..78942744cf1 100644 --- a/src/main/java/gregtech/common/tools/ToolSaw.java +++ b/src/main/java/gregtech/common/tools/ToolSaw.java @@ -79,7 +79,7 @@ public String getMiningSound() { @Override public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, - int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { + int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { if ((aBlock.getMaterial() == Material.leaves) && ((aBlock instanceof IShearable))) { aPlayer.worldObj.setBlock(aX, aY, aZ, aBlock, aMetaData, 0); if (((IShearable) aBlock).isShearable(aStack, aPlayer.worldObj, aX, aY, aZ)) { @@ -101,7 +101,7 @@ public int convertBlockDrops(List aDrops, ItemStack aStack, EntityPla } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "axe", "saw") || GTToolHarvestHelper.isAppropriateMaterial( aBlock, diff --git a/src/main/java/gregtech/common/tools/ToolScoop.java b/src/main/java/gregtech/common/tools/ToolScoop.java index 6f740da95eb..1ab4c0f9fcf 100644 --- a/src/main/java/gregtech/common/tools/ToolScoop.java +++ b/src/main/java/gregtech/common/tools/ToolScoop.java @@ -87,7 +87,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "scoop") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, sBeeHiveMaterial); } diff --git a/src/main/java/gregtech/common/tools/ToolScrewdriver.java b/src/main/java/gregtech/common/tools/ToolScrewdriver.java index b73f1371aab..6c772842d5a 100644 --- a/src/main/java/gregtech/common/tools/ToolScrewdriver.java +++ b/src/main/java/gregtech/common/tools/ToolScrewdriver.java @@ -117,7 +117,7 @@ public boolean isScrewdriver() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "screwdriver") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.circuits); } diff --git a/src/main/java/gregtech/common/tools/ToolSoftHammer.java b/src/main/java/gregtech/common/tools/ToolSoftHammer.java index 0cd3aa2eac6..9e812b59f1e 100644 --- a/src/main/java/gregtech/common/tools/ToolSoftHammer.java +++ b/src/main/java/gregtech/common/tools/ToolSoftHammer.java @@ -97,7 +97,7 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "softhammer"); } diff --git a/src/main/java/gregtech/common/tools/ToolSolderingIron.java b/src/main/java/gregtech/common/tools/ToolSolderingIron.java index 9ae4fade4c7..b00e97bee63 100644 --- a/src/main/java/gregtech/common/tools/ToolSolderingIron.java +++ b/src/main/java/gregtech/common/tools/ToolSolderingIron.java @@ -112,7 +112,7 @@ public boolean isMiningTool() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "soldering_iron") || GTToolHarvestHelper.isAppropriateMaterial(aBlock, Material.circuits); } diff --git a/src/main/java/gregtech/common/tools/ToolTurbine.java b/src/main/java/gregtech/common/tools/ToolTurbine.java index ace22b06bac..ceb2eb6df20 100644 --- a/src/main/java/gregtech/common/tools/ToolTurbine.java +++ b/src/main/java/gregtech/common/tools/ToolTurbine.java @@ -16,7 +16,7 @@ public abstract class ToolTurbine extends GTTool { public abstract float getBaseDamage(); @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } diff --git a/src/main/java/gregtech/common/tools/ToolWireCutter.java b/src/main/java/gregtech/common/tools/ToolWireCutter.java index 6009504d804..edbf21c3b93 100644 --- a/src/main/java/gregtech/common/tools/ToolWireCutter.java +++ b/src/main/java/gregtech/common/tools/ToolWireCutter.java @@ -81,7 +81,7 @@ public boolean isCrowbar() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(aBlock, aMetaData, "cutter"); } diff --git a/src/main/java/gregtech/common/tools/ToolWrench.java b/src/main/java/gregtech/common/tools/ToolWrench.java index 3d2adf48962..cbab13b401e 100644 --- a/src/main/java/gregtech/common/tools/ToolWrench.java +++ b/src/main/java/gregtech/common/tools/ToolWrench.java @@ -126,7 +126,7 @@ public boolean isWrench() { } @Override - public boolean isMinableBlock(Block block, byte aMetaData) { + public boolean isMinableBlock(Block block, int aMetaData) { return GTToolHarvestHelper.isAppropriateTool(block, aMetaData, "wrench") || GTToolHarvestHelper.isAppropriateMaterial(block, Material.piston) || block instanceof AEBaseTileBlock @@ -194,7 +194,7 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase private boolean LastEventFromThis = false; @Override - public void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, byte metadata, + public void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, int metadata, TileEntity tile, @Nonnull BlockEvent.BreakEvent event) { if (tile instanceof IWrenchable wrenchable) { if (!wrenchable.wrenchCanRemove(player)) { @@ -246,7 +246,7 @@ public void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Non @Override public int convertBlockDrops(List drops, ItemStack Stack, EntityPlayer player, Block block, int x, int y, - int z, byte metaData, int fortune, boolean silkTouch, BlockEvent.HarvestDropsEvent event) { + int z, int metaData, int fortune, boolean silkTouch, BlockEvent.HarvestDropsEvent event) { ItemStack drop = null; int modified = 0; if (wrenchableDrop != null) { diff --git a/src/main/java/gregtech/common/tools/pocket/ToolPocketMultitool.java b/src/main/java/gregtech/common/tools/pocket/ToolPocketMultitool.java index e55671d486f..e4cc20be246 100644 --- a/src/main/java/gregtech/common/tools/pocket/ToolPocketMultitool.java +++ b/src/main/java/gregtech/common/tools/pocket/ToolPocketMultitool.java @@ -44,7 +44,7 @@ public float getBaseDamage() { } @Override - public boolean isMinableBlock(Block aBlock, byte aMetaData) { + public boolean isMinableBlock(Block aBlock, int aMetaData) { return false; } } diff --git a/src/main/java/gtPlusPlus/api/interfaces/ILazyCoverable.java b/src/main/java/gtPlusPlus/api/interfaces/ILazyCoverable.java index d2a1e34f99d..d8b04fc2463 100644 --- a/src/main/java/gtPlusPlus/api/interfaces/ILazyCoverable.java +++ b/src/main/java/gtPlusPlus/api/interfaces/ILazyCoverable.java @@ -110,22 +110,22 @@ default IGregTechTileEntity getIGregTechTileEntityAtSideAndDistance(ForgeDirecti } @Override - default byte getMetaID(int arg0, int arg1, int arg2) { + default int getMetaID(int arg0, int arg1, int arg2) { return 0; } @Override - default byte getMetaIDOffset(int arg0, int arg1, int arg2) { + default int getMetaIDOffset(int arg0, int arg1, int arg2) { return 0; } @Override - default byte getMetaIDAtSide(ForgeDirection side) { + default int getMetaIDAtSide(ForgeDirection side) { return 0; } @Override - default byte getMetaIDAtSideAndDistance(ForgeDirection side, int arg1) { + default int getMetaIDAtSideAndDistance(ForgeDirection side, int arg1) { return 0; } diff --git a/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java b/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java index 811fb0cab13..6641a249272 100644 --- a/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java +++ b/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java @@ -567,17 +567,17 @@ public final Block getBlockAtSideAndDistance(ForgeDirection side, int aDistance) } @Override - public final byte getMetaIDOffset(int aX, int aY, int aZ) { + public final int getMetaIDOffset(int aX, int aY, int aZ) { return this.getMetaID(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ); } @Override - public final byte getMetaIDAtSide(ForgeDirection side) { + public final int getMetaIDAtSide(ForgeDirection side) { return this.getMetaIDAtSideAndDistance(side, 1); } @Override - public final byte getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance) { + public final int getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance) { return this.getMetaID( this.getOffsetX(side, aDistance), this.getOffsetY(side, aDistance), @@ -750,10 +750,10 @@ public final Block getBlock(int aX, int aY, int aZ) { } @Override - public final byte getMetaID(int aX, int aY, int aZ) { + public final int getMetaID(int aX, int aY, int aZ) { return this.ignoreUnloadedChunks && this.crossedChunkBorder(aX, aZ) && !this.worldObj.blockExists(aX, aY, aZ) ? 0 - : (byte) this.worldObj.getBlockMetadata(aX, aY, aZ); + : this.worldObj.getBlockMetadata(aX, aY, aZ); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IToolStats.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IToolStats.java index 1a61814f559..5e37c0cb649 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IToolStats.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IToolStats.java @@ -156,7 +156,7 @@ public interface IToolStats extends gregtech.api.interfaces.IToolStats { * check. */ @Override - boolean isMinableBlock(Block aBlock, byte aMetaData); + boolean isMinableBlock(Block aBlock, int aMetaData); /** * This lets you modify the Drop List, when this type of Tool has been used. @@ -165,7 +165,7 @@ public interface IToolStats extends gregtech.api.interfaces.IToolStats { */ @Override int convertBlockDrops(List aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, int aY, - int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); + int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); /** * @return Returns a broken Version of the Item. diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java index f47ef56e9a9..f1efe117a59 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/GTMetaTool.java @@ -78,7 +78,7 @@ public GTMetaTool(final String aUnlocalized) { */ @Override public void onHarvestBlockEvent(final ArrayList aDrops, final ItemStack aStack, - final EntityPlayer aPlayer, final Block aBlock, final int aX, final int aY, final int aZ, final byte aMetaData, + final EntityPlayer aPlayer, final Block aBlock, final int aX, final int aY, final int aZ, final int aMetaData, final int aFortune, final boolean aSilkTouch, final BlockEvent.HarvestDropsEvent aEvent) { final gregtech.api.interfaces.IToolStats tStats = this.getToolStats(aStack); if (this.isItemStackUsable(aStack) && (this.getDigSpeed(aStack, aBlock, aMetaData) > 0.0F)) { @@ -441,7 +441,7 @@ public float getDigSpeed(final ItemStack aStack, final Block aBlock, final int a if ((tStats == null) || (Math.max(0, this.getHarvestLevel(aStack, "")) < aBlock.getHarvestLevel(aMetaData))) { return 0.0F; } - return tStats.isMinableBlock(aBlock, (byte) aMetaData) + return tStats.isMinableBlock(aBlock, aMetaData) ? Math.max(Float.MIN_NORMAL, tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed) : 0.0F; } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks4.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks4.java index d68653e73af..63b0357d1b2 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks4.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks4.java @@ -45,10 +45,10 @@ public GregtechMetaCasingBlocks4() { @Override public IIcon getIcon(final int ordinalSide, final int aMeta) { - return getStaticIcon((byte) ordinalSide, (byte) aMeta); + return getStaticIcon((byte) ordinalSide, aMeta); } - public static IIcon getStaticIcon(final byte aSide, final byte aMeta) { + public static IIcon getStaticIcon(final byte aSide, final int aMeta) { // Texture ID's. case 0 == ID[57] if ((aMeta >= 0) && (aMeta < 16)) { switch (aMeta) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings.java index 38d9146e65d..a6ec678456b 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings.java @@ -86,10 +86,10 @@ public IIcon getIcon(final IBlockAccess aWorld, final int xCoord, final int yCoo @Override public IIcon getIcon(final int ordinalSide, final int aMeta) { - return getStaticIcon((byte) ordinalSide, (byte) aMeta); + return getStaticIcon((byte) ordinalSide, aMeta); } - public static IIcon getStaticIcon(final int ordinalSide, final byte aMeta) { + public static IIcon getStaticIcon(final int ordinalSide, final int aMeta) { return switch (aMeta) { case 0 -> TexturesGtBlock.Casing_Redox_1.getIcon(); case 1 -> Textures.BlockIcons.MACHINE_CASING_TURBINE_STEEL.getIcon(); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings2.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings2.java index 4f348112895..39ac2184410 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings2.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings2.java @@ -75,15 +75,15 @@ public GregtechMetaSpecialMultiCasings2() { @SideOnly(Side.CLIENT) public IIcon getIcon(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, final int ordinalSide) { - return getStaticIcon((byte) ordinalSide, (byte) aWorld.getBlockMetadata(xCoord, yCoord, zCoord)); + return getStaticIcon((byte) ordinalSide, aWorld.getBlockMetadata(xCoord, yCoord, zCoord)); } @Override public IIcon getIcon(final int ordinalSide, final int aMeta) { - return getStaticIcon((byte) ordinalSide, (byte) aMeta); + return getStaticIcon((byte) ordinalSide, aMeta); } - public static IIcon getStaticIcon(final byte aSide, final byte aMeta) { + public static IIcon getStaticIcon(final byte aSide, final int aMeta) { return switch (aMeta) { case 0 -> TexturesGtBlock.Casing_Resonance_1.getIcon(); case 1 -> TexturesGtBlock.Casing_Resonance_2.getIcon(); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/turbine/LargeTurbineTextureHandler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/turbine/LargeTurbineTextureHandler.java index cf300f9f3d6..080ea972d6f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/turbine/LargeTurbineTextureHandler.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/turbine/LargeTurbineTextureHandler.java @@ -133,7 +133,7 @@ public static IIcon handleCasingsGT(final IBlockAccess aWorld, final int xCoord, final ForgeDirection side, final GregtechMetaSpecialMultiCasings i) { final int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord); - return GregtechMetaSpecialMultiCasings.getStaticIcon(side.ordinal(), (byte) tMeta); + return GregtechMetaSpecialMultiCasings.getStaticIcon(side.ordinal(), tMeta); } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java index 0f9fa3497e7..2533249734a 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialWashPlant.java @@ -303,7 +303,6 @@ public boolean checkForWater() { for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { for (int h = 0; h < 2; ++h) { Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == Blocks.water) { if (this.getStoredFluids() != null) { for (FluidStack stored : this.getStoredFluids()) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java index d98e53e2da4..93f2e92bd95 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTEIndustrialFishingPond.java @@ -316,7 +316,7 @@ private boolean checkForWater() { for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { for (int h = 0; h < 2; h++) { Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + int tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); if (isNotStaticWater(tBlock, tMeta)) { if (this.getStoredFluids() != null) { for (FluidStack stored : this.getStoredFluids()) { @@ -350,7 +350,7 @@ private boolean checkForWater() { return tAmount >= 60; } - private boolean isNotStaticWater(Block block, byte meta) { + private boolean isNotStaticWater(Block block, int meta) { return block == Blocks.air || block == Blocks.flowing_water || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java index 779148199e4..e6a70c320ba 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/MTEAlgaePondBase.java @@ -262,7 +262,7 @@ public boolean checkForWater() { for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { for (int h = 0; h < 2; h++) { Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + int tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); if (isNotStaticWater(tBlock, tMeta)) { if (this.getStoredFluids() != null) { for (FluidStack stored : this.getStoredFluids()) { @@ -301,7 +301,7 @@ public boolean checkForWater() { } } - private boolean isNotStaticWater(Block block, byte meta) { + private boolean isNotStaticWater(Block block, int meta) { return block == Blocks.air || block == Blocks.flowing_water || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 492cb11081e..d84ec31cf24 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -166,7 +166,7 @@ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlaye private void checkMachineProblem(String msg, int xOff, int yOff, int zOff) { final IGregTechTileEntity te = this.getBaseMetaTileEntity(); final Block tBlock = te.getBlockOffset(xOff, yOff, zOff); - final byte tMeta = te.getMetaIDOffset(xOff, yOff, zOff); + final int tMeta = te.getMetaIDOffset(xOff, yOff, zOff); String name = tBlock.getLocalizedName(); String problem = msg + ": (" + xOff + ", " + yOff + ", " + zOff + ") " + name + ":" + tMeta; checkMachineProblem(problem); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java index fceebe62d37..4e0510bf333 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/redstone/MTERedstoneCircuitBlock.java @@ -380,7 +380,7 @@ public Block getBlockAtSide(ForgeDirection side) { } @Override - public byte getMetaIDAtSide(ForgeDirection side) { + public int getMetaIDAtSide(ForgeDirection side) { return getBaseMetaTileEntity().getMetaIDAtSide(side); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/ToolAngleGrinder.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/ToolAngleGrinder.java index f65b3162f8a..65d2fa09152 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/ToolAngleGrinder.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/ToolAngleGrinder.java @@ -115,14 +115,14 @@ public boolean isWeapon() { } @Override - public boolean isMinableBlock(final Block aBlock, final byte aMetaData) { + public boolean isMinableBlock(final Block aBlock, final int aMetaData) { final String tTool = aBlock.getHarvestTool(aMetaData); return (tTool != null) && (tTool.equals("sword") || tTool.equals("file")); } @Override public int convertBlockDrops(final List aDrops, final ItemStack aStack, final EntityPlayer aPlayer, - final Block aBlock, final int aX, final int aY, final int aZ, final byte aMetaData, final int aFortune, + final Block aBlock, final int aX, final int aY, final int aZ, final int aMetaData, final int aFortune, final boolean aSilkTouch, final BlockEvent.HarvestDropsEvent aEvent) { return 0; } From 51df8eae13d8c51cb44354187b091eb16b71fc2b Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Fri, 27 Dec 2024 12:51:38 -0500 Subject: [PATCH 41/47] optimize scanner --- .../items/behaviours/BehaviourDetravToolElectricProspector.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java index 60e8b04a3a7..60243b4eff1 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -117,8 +117,6 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW Block block = c.getBlock(x, y, z); int meta = c.getBlockMetadata(x, y, z); - if (OreManager.getStoneType(block, meta) != null) continue; - var p = OreManager.getOreInfo(block, meta); if (p != null) { From dc79490badc0529698f8e4d6e92341f8c9dcaf86 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Mon, 6 Jan 2025 23:14:42 -0500 Subject: [PATCH 42/47] vp changes --- src/main/java/bartworks/system/material/Werkstoff.java | 5 +++++ src/main/java/gregtech/api/enums/Materials.java | 5 +++++ src/main/java/gregtech/api/interfaces/IMaterial.java | 3 +++ src/main/java/gtPlusPlus/core/material/Material.java | 1 + 4 files changed, 14 insertions(+) diff --git a/src/main/java/bartworks/system/material/Werkstoff.java b/src/main/java/bartworks/system/material/Werkstoff.java index 41b7beb6f80..a45bb671c80 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -578,6 +578,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/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index 2835de566f9..24df5780d1c 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -3068,6 +3068,11 @@ public short[] getRGBA() { return mRGBa; } + @Override + public TextureSet getTextureSet() { + return mIconSet; + } + @Override public String toString() { return this.mName; diff --git a/src/main/java/gregtech/api/interfaces/IMaterial.java b/src/main/java/gregtech/api/interfaces/IMaterial.java index 18948f4dee7..c5576b62123 100644 --- a/src/main/java/gregtech/api/interfaces/IMaterial.java +++ b/src/main/java/gregtech/api/interfaces/IMaterial.java @@ -4,6 +4,7 @@ import bartworks.system.material.Werkstoff; import gregtech.api.enums.Materials; +import gregtech.api.enums.TextureSet; import gtPlusPlus.core.material.Material; public interface IMaterial { @@ -16,6 +17,8 @@ public interface IMaterial { public short[] getRGBA(); + public TextureSet getTextureSet(); + public boolean isValidForStone(IStoneType stoneType); public ImmutableList getValidStones(); diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index e7f4e34d614..e7a22197c7f 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -733,6 +733,7 @@ private static void checkForCellAndGenerate(Material material) { } } + @Override public final TextureSet getTextureSet() { synchronized (this) { return textureSet; From 46fc9b0516615f1559608f2d5ba2ac03af024073 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Tue, 7 Jan 2025 00:55:21 -0500 Subject: [PATCH 43/47] reduce hot-path allocations --- .../detrav/commands/DetravScannerCommand.java | 8 +- ...BehaviourDetravToolElectricProspector.java | 21 +--- .../BehaviourDetravToolProspector.java | 11 +- .../java/gregtech/common/ores/OreInfo.java | 3 + .../java/gregtech/common/ores/OreManager.java | 116 +++++++++++------- .../multiblock/eigbuckets/EIGIC2Bucket.java | 8 +- 6 files changed, 95 insertions(+), 72 deletions(-) diff --git a/src/main/java/detrav/commands/DetravScannerCommand.java b/src/main/java/detrav/commands/DetravScannerCommand.java index b74385c8e2d..319f3697ad4 100644 --- a/src/main/java/detrav/commands/DetravScannerCommand.java +++ b/src/main/java/detrav/commands/DetravScannerCommand.java @@ -98,12 +98,8 @@ private void process(ICommandSender sender, int aX, int aZ, String fName) { Block b = c.getBlock(x, y, z); int meta = c.getBlockMetadata(x, y, z); - var p = OreManager.getOreInfo(b, meta); - - if (p == null) continue; - - try (OreInfo info = p.right()) { - if (info.isSmall) continue; + try (OreInfo info = OreManager.getOreInfo(b, meta)) { + if (info == null || info.isSmall) continue; String matName = info.material.getLocalizedName(); diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java index 60243b4eff1..be9b4a61227 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -117,21 +117,12 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW Block block = c.getBlock(x, y, z); int meta = c.getBlockMetadata(x, y, z); - var p = OreManager.getOreInfo(block, meta); - - if (p != null) { - try (OreInfo info = p.right()) { - if (!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; - } + 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; } } } diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java index 3f12a10f5c8..e82a0e87323 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java @@ -299,17 +299,18 @@ protected void processOreProspecting(DetravMetaGeneratedTool01 aItem, ItemStack Block tBlock = chunk.getBlock(cx, cy, cz); short tMetaID = (short) chunk.getBlockMetadata(cx, cy, cz); - var p = OreManager.getOreInfo(tBlock, tMetaID); - - if (p != null) { - try (OreInfo info = p.right()) { + 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 (data == DetravMetaGeneratedTool01.MODE_ALL_ORES) { + } + + if (data == DetravMetaGeneratedTool01.MODE_ALL_ORES) { itemData = GTOreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); if (itemData != null && itemData.mPrefix.toString() .startsWith("ore")) { diff --git a/src/main/java/gregtech/common/ores/OreInfo.java b/src/main/java/gregtech/common/ores/OreInfo.java index 7564ecce28a..af696eb7497 100644 --- a/src/main/java/gregtech/common/ores/OreInfo.java +++ b/src/main/java/gregtech/common/ores/OreInfo.java @@ -7,6 +7,7 @@ public class OreInfo implements AutoCloseable { + public IOreAdapter cachedAdapter; public TMat material; public IStoneType stoneType; public boolean isSmall; @@ -37,6 +38,7 @@ public void release() { } public OreInfo reset() { + cachedAdapter = null; material = null; stoneType = null; isSmall = false; @@ -46,6 +48,7 @@ public OreInfo reset() { public OreInfo clone() { OreInfo dup = getNewInfo(); + dup.cachedAdapter = this.cachedAdapter; dup.material = this.material; dup.stoneType = this.stoneType; dup.isSmall = this.isSmall; diff --git a/src/main/java/gregtech/common/ores/OreManager.java b/src/main/java/gregtech/common/ores/OreManager.java index cf18b99fb1d..0c8b8b9fb33 100644 --- a/src/main/java/gregtech/common/ores/OreManager.java +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -18,7 +18,6 @@ import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneType; -import it.unimi.dsi.fastutil.Pair; public class OreManager { @@ -36,7 +35,11 @@ public static IStoneType getStoneType(Block block, int meta) { } public static boolean isOre(Block block, int meta) { - for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + 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; } @@ -45,23 +48,37 @@ public static boolean isOre(Block block, int meta) { return false; } - public static Pair, OreInfo> getOreInfo(Block block, int meta) { - for (IOreAdapter oreAdapter : ORE_ADAPTERS) { - OreInfo info = oreAdapter.getOreInfo(block, meta); - if (info != null) return Pair.of(oreAdapter, info); + @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 Pair, OreInfo> getOreInfo(ItemStack stack) { + 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) { - for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + 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; } @@ -90,7 +107,11 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone info.isSmall = small; info.isNatural = true; - for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + var block = oreAdapter.getBlock(info); if (block != null) { @@ -114,7 +135,11 @@ public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneT info.isSmall = small; info.isNatural = true; - for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + int size = ORE_ADAPTERS.size(); + + for (int i = 0; i < size; i++) { + IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); + var block = oreAdapter.getBlock(info); if (block != null) { @@ -129,22 +154,22 @@ public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneT } public static boolean setExistingOreStoneType(World world, int x, int y, int z, IStoneType newStoneType) { - var p = getOreInfo(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); - - if (p == null) return false; + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); - IOreAdapter oreAdapter = p.left(); - OreInfo info = p.right(); + try (OreInfo info = getOreInfo(block, meta)) { + if (info == null) return false; - info.stoneType = newStoneType; + info.stoneType = newStoneType; - var block = oreAdapter.getBlock(info); + var newBlock = getAdapter(info).getBlock(info); - if (block == null) return false; + if (newBlock == null) return false; - world.setBlock(x, y, z, block.left(), block.rightInt(), 2); + world.setBlock(x, y, z, newBlock.left(), newBlock.rightInt(), 2); - return true; + return true; + } } public static List mineBlock(World world, int x, int y, int z, boolean silktouch, int fortune, @@ -152,32 +177,29 @@ public static List mineBlock(World world, int x, int y, int z, boolea Block ore = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); - var p = getOreInfo(ore, meta); - List oreBlockDrops; Block replacement; int replacementMeta; - if (p != null) { - try (OreInfo info = p.right()) { - oreBlockDrops = p.left() - .getOreDrops(info, silktouch, fortune); + try (OreInfo info = getOreInfo(ore, meta)) { + if (info != null) { + oreBlockDrops = info.cachedAdapter.getOreDrops(info, silktouch, fortune); var cobble = info.stoneType.getCobblestone(); replacement = cobble.left(); replacementMeta = cobble.rightInt(); - } - } else { - if (silktouch && ore.canSilkHarvest(world, null, x, y, z, meta)) { - oreBlockDrops = new ArrayList<>(Arrays.asList(new ItemStack(ore, 1, meta))); } else { - // Regular ore - oreBlockDrops = ore.getDrops(world, x, y, z, meta, fortune); - } + if (silktouch && ore.canSilkHarvest(world, null, x, y, z, meta)) { + oreBlockDrops = new ArrayList<>(Arrays.asList(new ItemStack(ore, 1, meta))); + } else { + // Regular ore + oreBlockDrops = ore.getDrops(world, x, y, z, meta, fortune); + } - replacement = Blocks.cobblestone; - replacementMeta = 0; + replacement = Blocks.cobblestone; + replacementMeta = 0; + } } if (!simulate) { @@ -198,13 +220,17 @@ public static IMaterial getMaterial(ItemStack stack) { } public static IMaterial getMaterial(Block block, int meta) { - var p = getOreInfo(block, meta); - - return p == null ? null : p.right().material; + try (OreInfo info = getOreInfo(block, meta)) { + return info == null ? null : info.material; + } } public static ItemStack getStack(OreInfo info, int amount) { - for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + 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; @@ -222,7 +248,11 @@ public static String getLocalizedName(OreInfo info) { } public static List getDrops(Block block, int meta, boolean silktouch, int fortune) { - for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + 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) { return oreAdapter.getOreDrops(info, silktouch, fortune); @@ -234,7 +264,11 @@ public static List getDrops(Block block, int meta, boolean silktouch, } public static List getPotentialDrops(OreInfo info) { - for (IOreAdapter oreAdapter : ORE_ADAPTERS) { + 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); } 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 0012ecfbd61..1c8d8f7c322 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/eigbuckets/EIGIC2Bucket.java @@ -394,13 +394,11 @@ private static boolean setBlock(ItemStack stack, int x, int y, int z, World worl if (b == Blocks.air || !(item instanceof ItemBlock)) return false; short tDamage = (short) item.getDamage(stack); - var p = OreManager.getOreInfo(b, tDamage); - - if (p != null) { - try (OreInfo info = p.right()) { + try (OreInfo info = OreManager.getOreInfo(b, tDamage)) { + if (info != null) { info.isNatural = true; - var oreBlock = p.left() + var oreBlock = OreManager.getAdapter(info) .getBlock(info); world.setBlock(x, y, z, oreBlock.left(), oreBlock.rightInt(), 3); From 5c16d04021e3c883b8edab45cff173cb121df1d0 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Fri, 10 Jan 2025 15:12:46 -0500 Subject: [PATCH 44/47] clean up & fixes - Misc minor clean up - Removed several unused or useless methods and parameters - Encapsulated several fields behind getters - Made several public fields private where possible - Used generic interface for collections where possible - Used new (Immutable)BlockMeta types and removed old gcgreg classes that the new types replace - Removed replaceable block system in gcgreg to prevent duplication of responsibility, since that's handled by the new stone type system now - Fixed mehen belt asteroid gen (dim name was wrong) - Changed asteroid gen to use murmurhash to prevent ore banding (old bespoke hash algorithm was terrible) - Couldn't use google hash lib because those objects can't be reset - this code is in a hot-path, so allocations need to be as low as possible - Added custom pair type for detectPrefix - Added ice and clay stones for Seth to increase oregen (not needed due to void miners, but it looks nicer now) - Added @Nullable/@Nonnull for several methods - Added oregen event for visual prospecting, to remove its mixin (along with a new GT event bus) - Added lots of comments to critical methods - Changed singleton enums to proper final class instance singletons - Changed ore hardness/explosion resistance to reflect backing stone hardness - Changed GT++ ores to use the adapter drop logic (I forgot to change this before) - Removed old ambiguous BaseOreComponent constructor --- .../material/BWItemMetaGeneratedOre.java | 6 +- .../system/material/BWMetaGeneratedOres.java | 4 +- .../bartworks/system/material/Werkstoff.java | 16 +- .../galacticgreg/MTEVoidMinerBase.java | 2 +- .../galacticgreg/VoidMinerUtility.java | 14 +- .../detrav/commands/DetravScannerCommand.java | 5 +- ...BehaviourDetravToolElectricProspector.java | 20 +- .../BehaviourDetravToolProspector.java | 2 +- .../galacticgreg/WorldGeneratorSpace.java | 68 +++---- .../galacticgreg/api/AsteroidBlockComb.java | 82 -------- .../java/galacticgreg/api/BlockMetaComb.java | 52 ----- .../galacticgreg/api/ModDimensionDef.java | 154 +++----------- .../galacticgreg/api/SpecialBlockComb.java | 32 +-- .../api/StructureInformation.java | 8 +- .../DimensionBlockMetaDefinitionList.java | 57 ------ .../galacticgreg/api/enums/DimensionDef.java | 116 ++++------- .../galacticgreg/auxiliary/ConfigManager.java | 1 - .../galacticgreg/auxiliary/GTOreGroup.java | 21 -- .../auxiliary/GalacticGregConfig.java | 10 +- .../command/ProfilingCommand.java | 4 +- .../registry/GalacticGregRegistry.java | 58 +----- .../schematics/SpaceSchematic.java | 2 +- .../schematics/SpaceSchematicWrapper.java | 6 +- .../java/gregtech/api/enums/Materials.java | 5 +- src/main/java/gregtech/api/enums/Mods.java | 14 +- .../java/gregtech/api/enums/OrePrefixes.java | 55 ++++- .../java/gregtech/api/enums/StoneType.java | 167 ++++++++-------- .../java/gregtech/api/events/GTEventBus.java | 14 ++ .../gregtech/api/interfaces/IMaterial.java | 21 +- .../gregtech/api/interfaces/IStoneType.java | 21 +- .../java/gregtech/api/objects/MurmurHash.java | 188 ++++++++++++++++++ .../api/task/CooperativeScheduler.java | 4 +- .../java/gregtech/api/util/GTUtility.java | 2 +- .../java/gregtech/api/world/GTWorldgen.java | 17 +- .../gregtech/common/GTWorldgenerator.java | 29 ++- .../gregtech/common/WorldgenGTOreLayer.java | 79 +++----- .../common/WorldgenGTOreSmallPieces.java | 42 ++-- .../java/gregtech/common/WorldgenStone.java | 7 +- .../common/blocks/BlockOresAbstract.java | 39 ++-- .../common/misc/DrillingLogicDelegate.java | 8 +- .../gregtech/common/ores/BWOreAdapter.java | 33 +-- .../gregtech/common/ores/GTOreAdapter.java | 60 +++--- .../gregtech/common/ores/GTPPOreAdapter.java | 20 +- .../gregtech/common/ores/IOreAdapter.java | 60 +++++- .../java/gregtech/common/ores/OreInfo.java | 20 -- .../java/gregtech/common/ores/OreManager.java | 80 +++----- .../gregtech/common/ores/SmallOreDrops.java | 9 +- .../common/render/GTRendererBlock.java | 54 ++--- .../basic/MTEAdvSeismicProspector.java | 2 +- .../tileentities/machines/basic/MTEMiner.java | 4 +- .../multi/MTEOreDrillingPlantBase.java | 17 +- .../common/worldgen/IWorldgenLayer.java | 45 +++-- .../common/worldgen/VeinGenerateEvent.java | 38 ++++ .../common/worldgen/WorldgenQuery.java | 3 + src/main/java/gregtech/nei/NEIGTConfig.java | 7 +- .../core/block/base/BlockBaseOre.java | 75 ++----- .../item/base/itemblock/ItemBlockOre.java | 2 +- .../core/item/base/ore/BaseOreComponent.java | 24 +-- .../gtPlusPlus/core/material/Material.java | 15 +- .../gregtech5/PluginGT5SmallOreStat.java | 9 +- .../plugin/gregtech5/PluginGT5VeinStat.java | 20 +- .../plugin/item/ItemDimensionDisplay.java | 1 + .../java/gtneioreplugin/util/CSVMaker.java | 3 +- .../gtneioreplugin/util/DimensionHelper.java | 2 +- .../util/GT5OreLayerHelper.java | 39 +++- .../util/GT5OreSmallHelper.java | 31 ++- .../multiblock/eigbuckets/EIGIC2Bucket.java | 9 +- .../recipe/EyeOfHarmonyRecipeStorage.java | 13 +- .../assets/gtneioreplugin/lang/en_US.lang | 2 +- 69 files changed, 1018 insertions(+), 1131 deletions(-) delete mode 100644 src/main/java/galacticgreg/api/AsteroidBlockComb.java delete mode 100644 src/main/java/galacticgreg/api/BlockMetaComb.java delete mode 100644 src/main/java/galacticgreg/api/enums/DimensionBlockMetaDefinitionList.java delete mode 100644 src/main/java/galacticgreg/auxiliary/GTOreGroup.java create mode 100644 src/main/java/gregtech/api/events/GTEventBus.java create mode 100644 src/main/java/gregtech/api/objects/MurmurHash.java create mode 100644 src/main/java/gregtech/common/worldgen/VeinGenerateEvent.java diff --git a/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java b/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java index 3ef9cd7b00c..77eb6c45348 100644 --- a/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java +++ b/src/main/java/bartworks/system/material/BWItemMetaGeneratedOre.java @@ -28,9 +28,13 @@ public int getMetadata(int meta) { return meta; } + private OrePrefixes getOrePrefix() { + return blockOre.isSmall ? OrePrefixes.oreSmall : OrePrefixes.ore; + } + @Override public String getUnlocalizedName(ItemStack stack) { - return blockOre.isSmall ? "bw.blocktype." + OrePrefixes.oreSmall : "bw.blocktype." + OrePrefixes.ore; + return "bw.blocktype." + getOrePrefix().name(); } @Override diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java index 3f8d0f62d3e..fc606e82675 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nullable; @@ -138,7 +139,8 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad boolean doSilktouch = harvester != null && EnchantmentHelper.getSilkTouchModifier(harvester); try (OreInfo info = BWOreAdapter.INSTANCE.getOreInfo(this, metadata)) { - return (ArrayList) BWOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); + return BWOreAdapter.INSTANCE + .getOreDrops(ThreadLocalRandom.current(), info, doSilktouch, doFortune ? fortune : 0); } } diff --git a/src/main/java/bartworks/system/material/Werkstoff.java b/src/main/java/bartworks/system/material/Werkstoff.java index a45bb671c80..cbb52071bb8 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -30,12 +30,11 @@ 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; -import com.google.common.collect.ImmutableList; - import bartworks.MainMod; import bartworks.system.oredict.OreDictHandler; import bartworks.util.BWColorUtil; @@ -61,12 +60,14 @@ 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, IMaterial { 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<>(); @@ -402,7 +403,7 @@ public Werkstoff addAdditionalOreDict(String s) { return this; } - public HashSet getAdditionalOredict() { + public Set getAdditionalOredict() { return this.additionalOredict; } @@ -543,12 +544,7 @@ public int getId() { } @Override - public boolean isValidForStone(IStoneType stoneType) { - return stoneType == StoneType.Stone; - } - - @Override - public ImmutableList getValidStones() { + public List getValidStones() { return StoneType.STONE_ONLY; } diff --git a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java index 6e47a53cc84..c1ea72baa6b 100644 --- a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java +++ b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java @@ -285,7 +285,7 @@ private void calculateDropMap() { getBaseMetaTileEntity().getXCoord() >> 4, getBaseMetaTileEntity().getZCoord() >> 4); - if (dimensionDef == null || !dimensionDef.canBeVoidMined) return; + if (dimensionDef == null || !dimensionDef.canBeVoidMined()) return; this.canVoidMine = true; diff --git a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java index e48b4ea47a4..83ed74b66f6 100644 --- a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java +++ b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java @@ -138,10 +138,10 @@ public static void generateDropMaps() { for (WorldgenGTOreLayer layer : WorldgenGTOreLayer.sList) { if (!layer.mEnabled) continue; - for (String dim : layer.mAllowedDimensions) { - ModDimensionDef dimensionDef = DimensionDef.DEF_BY_WORLD_NAME.get(dim); + for (String dim : layer.getAllowedDimensions()) { + ModDimensionDef dimensionDef = DimensionDef.getDefByName(dim); - if (dimensionDef != null && !dimensionDef.canBeVoidMined) continue; + if (dimensionDef != null && !dimensionDef.canBeVoidMined()) continue; DropMap map = dropMapsByDimName.computeIfAbsent(dim, ignored -> new DropMap()); @@ -155,14 +155,14 @@ public static void generateDropMaps() { for (WorldgenGTOreSmallPieces layer : WorldgenGTOreSmallPieces.sList) { if (!layer.mEnabled) continue; - for (String dim : layer.mAllowedDimensions) { - ModDimensionDef dimensionDef = DimensionDef.DEF_BY_WORLD_NAME.get(dim); + for (String dim : layer.getAllowedDimensions()) { + ModDimensionDef dimensionDef = DimensionDef.getDefByName(dim); - if (dimensionDef != null && !dimensionDef.canBeVoidMined) continue; + if (dimensionDef != null && !dimensionDef.canBeVoidMined()) continue; DropMap map = dropMapsByDimName.computeIfAbsent(dim, ignored -> new DropMap()); - map.addDrop(layer.mMaterial, layer.mAmount); + map.addDrop(layer.getMaterial(), layer.mAmount); } } } diff --git a/src/main/java/detrav/commands/DetravScannerCommand.java b/src/main/java/detrav/commands/DetravScannerCommand.java index 319f3697ad4..6b9cbe15208 100644 --- a/src/main/java/detrav/commands/DetravScannerCommand.java +++ b/src/main/java/detrav/commands/DetravScannerCommand.java @@ -1,7 +1,6 @@ package detrav.commands; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.function.BiFunction; @@ -13,6 +12,8 @@ import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.chunk.Chunk; +import com.google.common.collect.ImmutableList; + import gregtech.common.ores.OreInfo; import gregtech.common.ores.OreManager; @@ -21,7 +22,7 @@ */ public class DetravScannerCommand implements ICommand { - private final List aliases = new ArrayList<>(Arrays.asList("DetravScanner", "dscan")); + private final List aliases = ImmutableList.of("DetravScanner", "dscan"); @Override public String getCommandName() { diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java index be9b4a61227..301f9580156 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolElectricProspector.java @@ -76,15 +76,15 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW final List chunks = new ArrayList<>(); aPlayer.addChatMessage(new ChatComponentText("Scanning...")); - int size; + final int radius = aItem.getHarvestLevel(aStack, ""); - { - int size2 = aItem.getHarvestLevel(aStack, "") + 1; - for (int i = -size2; i <= size2; i++) - for (int j = -size2; j <= size2; j++) if (i != -size2 && i != size2 && j != -size2 && j != size2) + 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)); - - size = size2 - 1; + } + } } final DetravMetaGeneratedTool01 tool = (DetravMetaGeneratedTool01) aItem; @@ -95,7 +95,7 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW cZ, (int) aPlayer.posX, (int) aPlayer.posZ, - size, + radius, data); Future task = CooperativeScheduler.INSTANCE.schedule(ctx -> { @@ -154,7 +154,7 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW aWorld.provider.dimensionId, (int) aPlayer.posX, (int) aPlayer.posZ, - size * 16), + radius * 16), new ArrayList<>()); } else if (data == MODE_FLUIDS) { VisualProspecting_API.LogicalServer.sendProspectionResultsToClient( @@ -164,7 +164,7 @@ public ItemStack onItemRightClick(MetaBaseItem aItem, ItemStack aStack, World aW aWorld, (int) aPlayer.posX, (int) aPlayer.posZ, - size * 16)); + radius * 16)); } } }); diff --git a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java index e82a0e87323..86e8788385b 100644 --- a/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java +++ b/src/main/java/detrav/items/behaviours/BehaviourDetravToolProspector.java @@ -88,7 +88,7 @@ public boolean onItemUse(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPla } if (block.getMaterial() == Material.rock || block.getMaterial() == Material.ground - || GTUtility.isMinable(block, meta)) { + || GTUtility.isOre(block, meta)) { prospectChunks(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, aRandom, chance); return true; diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 20ed6a38dd0..8f81730db39 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -14,10 +14,10 @@ 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.registry.GameRegistry; -import galacticgreg.api.AsteroidBlockComb; -import galacticgreg.api.BlockMetaComb; import galacticgreg.api.Enums; import galacticgreg.api.Enums.TargetBlockPosition; import galacticgreg.api.ModDimensionDef; @@ -26,9 +26,9 @@ import galacticgreg.dynconfig.DynamicDimensionConfig; import galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; import gregtech.GTMod; -import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; 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; @@ -97,12 +97,11 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkP public static class AsteroidGenerator { - public List positive, negative; - public int seedChunkX, seedChunkZ, cX, cY, cZ, radius, size; - public long seed; + private List positive, negative; + private int seedChunkX, seedChunkZ, cX, cY, cZ, radius, size; - public StoneType stoneType; - public transient IWorldgenLayer ore; + private IStoneType stoneType; + private transient IWorldgenLayer ore; public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedChunkZ) { ModDimensionDef dimensionDef = DimensionDef.getDefForWorld(world, seedChunkX, seedChunkZ); @@ -119,7 +118,7 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh XSTR rng = getRandom(world.getSeed(), seedChunkX, seedChunkZ, world.provider.dimensionId); - AsteroidBlockComb asteroidStone = dimensionDef.getRandomAsteroidMaterial(rng.clone()); + IStoneType asteroidStone = dimensionDef.getRandomAsteroidMaterial(rng.clone()); if (asteroidStone == null) return null; IWorldgenLayer oreLayer; @@ -127,16 +126,12 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh if (rng.nextInt(5) == 0) { oreLayer = WorldgenQuery.small() .inDimension(dimensionDef) - .inStone( - asteroidStone.getStone() - .getCategory()) + .inStone(asteroidStone.getCategory()) .find(rng.clone()); } else { oreLayer = WorldgenQuery.veins() .inDimension(dimensionDef) - .inStone( - asteroidStone.getStone() - .getCategory()) + .inStone(asteroidStone.getCategory()) .find(rng.clone()); } @@ -196,9 +191,7 @@ public static AsteroidGenerator forChunk(World world, int seedChunkX, int seedCh gen.radius = radius; gen.size = radius * 2; - gen.seed = rng.nextLong(); - - gen.stoneType = asteroidStone.getStone(); + gen.stoneType = asteroidStone; gen.ore = oreLayer; return gen; @@ -227,6 +220,8 @@ public void generateChunk(World world, int chunkX, int chunkZ) { 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++) { @@ -235,15 +230,15 @@ public void generateChunk(World world, int chunkX, int chunkZ) { continue; } - long seed = world.getSeed(); - seed = seed * 12289 + chunkX; - seed = seed * 12289 + chunkZ; - seed = seed * 12289 + world.provider.dimensionId; - seed = seed * 12289 + x; - seed = seed * 12289 + y; - seed = seed * 12289 + z; + hasher.reset(); + + hasher.feed(world.getSeed()); + hasher.feed(world.provider.dimensionId); + hasher.feed(x); + hasher.feed(y); + hasher.feed(z); - XSTR rng2 = new XSTR(seed); + 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) { @@ -314,9 +309,9 @@ public void generateChunk(World world, int chunkX, int chunkZ) { y, z, stoneType.getStone() - .left(), + .getBlock(), stoneType.getStone() - .rightInt(), + .getBlockMeta(), 2); } } @@ -382,10 +377,10 @@ private void generateLootChest(World world, AsteroidConfig asteroidConfig) { .getItems(DynamicDimensionConfig.getLootChestTable(asteroidConfig), rng); // Get chest-block to spawn - BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; + ImmutableBlockMeta tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; // Place down the chest - world.setBlock(cX, cY, cZ, tTargetChestType.getBlock(), tTargetChestType.getMeta(), 2); + 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); @@ -413,7 +408,7 @@ private void generateLootChest(World world, AsteroidConfig asteroidConfig) { /** A random number which gets added to the XSTR because I felt like it */ private static final long OFFSET = 588283; - public static XSTR getRandom(long worldSeed, int chunkX, int chunkZ, int dimId) { + private static XSTR getRandom(long worldSeed, int chunkX, int chunkZ, int dimId) { return new XSTR(chunkX * 341873128712L + chunkZ * 132897987541L + dimId + OFFSET + worldSeed); } @@ -423,15 +418,6 @@ public static boolean generatesAsteroid(long worldSeed, int chunkX, int chunkZ, /** * Generate Special Blocks in asteroids if enabled - * - * @param dimensionDef - * @param rng - * @param world - * @param asteroidConfig - * @param x - * @param y - * @param z - * @return */ private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Random rng, World world, AsteroidConfig asteroidConfig, int x, int y, int z, TargetBlockPosition blockPosition) { @@ -450,7 +436,7 @@ private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Rando }; if (validLocation) { - world.setBlock(x, y, z, bmc.getBlock(), bmc.getMeta(), 3); + world.setBlock(x, y, z, bmc.getBlock(), bmc.getBlockMeta(), 3); return true; } } diff --git a/src/main/java/galacticgreg/api/AsteroidBlockComb.java b/src/main/java/galacticgreg/api/AsteroidBlockComb.java deleted file mode 100644 index 34040a00681..00000000000 --- a/src/main/java/galacticgreg/api/AsteroidBlockComb.java +++ /dev/null @@ -1,82 +0,0 @@ -package galacticgreg.api; - -import net.minecraft.block.Block; - -import gregtech.api.enums.StoneType; - -/** - * 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 StoneType stoneType; - - /** - * 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(StoneType stoneType, Block pBlock) { - super(pBlock, 0); - this.stoneType = stoneType; - } - - /** - * 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(StoneType stoneType, Block pBlock, int pMeta) { - super(pBlock, pMeta); - this.stoneType = stoneType; - } - - /** - * Create a simple definition which uses the GregTech-OreType values for both asteroidStone and ores - * - * @param pOreType The GregTech oreType - */ - public AsteroidBlockComb(StoneType stoneType) { - super( - stoneType.getStone() - .left(), - stoneType.getStone() - .rightInt()); - this.stoneType = stoneType; - } - - /** - * Internal function - * - * @return The GT Material for the oregen - */ - public StoneType getStone() { - return stoneType; - } - - @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.getStone() == this.getStone())) 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 772ebbe5a67..00000000000 --- a/src/main/java/galacticgreg/api/BlockMetaComb.java +++ /dev/null @@ -1,52 +0,0 @@ -package galacticgreg.api; - -import java.util.Objects; - -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 = Objects.requireNonNull(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/ModDimensionDef.java b/src/main/java/galacticgreg/api/ModDimensionDef.java index 1c73077fe4a..9b63221b65c 100644 --- a/src/main/java/galacticgreg/api/ModDimensionDef.java +++ b/src/main/java/galacticgreg/api/ModDimensionDef.java @@ -4,11 +4,13 @@ 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.enums.StoneType; +import gregtech.api.interfaces.IStoneType; +import gregtech.api.objects.XSTR; import gregtech.common.config.Gregtech; // import galacticgreg.GalacticGreg; @@ -23,7 +25,6 @@ public class ModDimensionDef { /** "modname_dimname" */ private String internalDimIdentifier; private final String chunkProviderName; - private final ArrayList replaceableBlocks; private DimensionType dimensionType; private final List spaceObjectGenerators; @@ -34,64 +35,37 @@ public class ModDimensionDef { // ------ // Asteroid stuff - private final List validAsteroidMaterials; + private final List validAsteroidMaterials; private final List specialBlocksForAsteroids; - private final Random random = new Random(System.currentTimeMillis()); + private final XSTR random = new XSTR(); - public boolean hasEoHRecipe = true; - public boolean canBeVoidMined = true; + private boolean hasEoHRecipe = true; + private boolean canBeVoidMined = true; /** - * 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 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 ModDimensionDef(String pDimensionName, Class pChunkProvider, DimensionType pDimType) { - this(pDimensionName, pChunkProvider.getName(), 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, - DimensionType pDimType, List pBlockDefinitions) { - this(pDimensionName, pChunkProvider.getName(), pDimType, pBlockDefinitions); + this(pDimensionName, pChunkProvider.getName(), pDimType); } /** - * 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 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 ModDimensionDef(String pDimensionName, String pChunkProviderName, 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, DimensionType pDimType, - List pBlockDefinitions) { internalDimIdentifier = STR_NOTDEFINED; dimensionName = pDimensionName; chunkProviderName = pChunkProviderName; dimensionType = pDimType; - replaceableBlocks = new ArrayList<>(); - if (pBlockDefinitions != null) replaceableBlocks.addAll(pBlockDefinitions); - validAsteroidMaterials = new ArrayList<>(); specialBlocksForAsteroids = new ArrayList<>(); spaceObjectGenerators = new ArrayList<>(); @@ -112,15 +86,6 @@ public int getOreVeinChance() { return oreVeinChance; } - /** - * Internal function - * - * @return A list of possible asteroid-mixes that shall be generated - */ - public List getValidAsteroidMaterials() { - return validAsteroidMaterials; - } - // ================================================= /** * Register new generator for objects in space. You can register as many as you want. If you don't register @@ -225,22 +190,6 @@ public String getChunkProviderName() { return chunkProviderName; } - /** - * 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 (replaceableBlocks.contains(pBlockDef)) { - return false; - } else { - replaceableBlocks.add(pBlockDef); - return true; - } - } - /** * Internal function * @@ -250,15 +199,6 @@ public String getDimensionName() { return dimensionName; } - /** - * Internal function - * - * @return A list of all defined Blocks that can be replaced while generating ores - */ - public ArrayList getReplaceableBlocks() { - return replaceableBlocks; - } - /** * Internal function *

@@ -274,35 +214,6 @@ protected void setParentModName(String pModName) { } - /** - * 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 : replaceableBlocks) { - 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 *

@@ -310,7 +221,7 @@ public Enums.ReplaceState getReplaceStateForBlock(Block pBlock, int pMeta) { * * @return */ - public AsteroidBlockComb getRandomAsteroidMaterial(Random rng) { + public IStoneType getRandomAsteroidMaterial(Random rng) { if (validAsteroidMaterials.isEmpty()) return null; if (validAsteroidMaterials.size() == 1) { @@ -337,21 +248,12 @@ public SpecialBlockComb getRandomSpecialAsteroidBlock(Random rng) { } } - /** - * Define the material the asteroid shall be made of. Limited to GT-Based Ores and their stones - * - * @param pMaterial - */ - public void addAsteroidMaterial(StoneType stoneType) { - addAsteroidMaterial(new AsteroidBlockComb(stoneType)); - } - /** * Define the material the asteroid shall be made of, more advanced option to specify your own blocks * * @param pBlockComb */ - public void addAsteroidMaterial(AsteroidBlockComb pBlockComb) { + public void addAsteroidMaterial(IStoneType pBlockComb) { if (!validAsteroidMaterials.contains(pBlockComb)) { validAsteroidMaterials.add(pBlockComb); } @@ -370,25 +272,23 @@ public void addSpecialAsteroidBlock(SpecialBlockComb 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 : replaceableBlocks) { - rpb.updateBlockName(pParentModName); - } - } - 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 95950cf1511..fa860cc87b4 100644 --- a/src/main/java/galacticgreg/api/enums/DimensionDef.java +++ b/src/main/java/galacticgreg/api/enums/DimensionDef.java @@ -8,7 +8,6 @@ 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; @@ -31,7 +30,7 @@ public enum DimensionDef { EndAsteroids(new ModDimensionDef( DimNames.ENDASTEROID, ChunkProviderEnd.class, - Enums.DimensionType.Asteroid)), + DimensionType.Asteroid)), TwilightForest(new ModDimensionDef( DimNames.TWILIGHT_FOREST, "twilightforest.world.ChunkProviderTwilightForest", @@ -47,189 +46,158 @@ public enum DimensionDef { 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", - Enums.DimensionType.Planet) + DimensionType.Planet) .disableEoHRecipe()), Ross128ba(new ModDimensionDef( DimNames.ROSS128BA, "bwcrossmod.galacticraft.planets.ross128ba.ChunkProviderRoss128ba", - Enums.DimensionType.Planet) + 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, "", - Enums.DimensionType.Planet)), + DimensionType.Planet)), ; // spotless:on @@ -239,7 +207,7 @@ public enum DimensionDef { this.modDimensionDef = modDimDef; } - public static final Map DEF_BY_WORLD_NAME = new HashMap<>(); + private static final Map DEF_BY_WORLD_NAME = new HashMap<>(); static { for (DimensionDef def : values()) { @@ -247,6 +215,10 @@ public enum DimensionDef { } } + 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()); @@ -306,7 +278,7 @@ public static class DimNames { 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"; } 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 d19480fdd82..00000000000 --- a/src/main/java/galacticgreg/auxiliary/GTOreGroup.java +++ /dev/null @@ -1,21 +0,0 @@ -package galacticgreg.auxiliary; - -import gregtech.api.interfaces.IMaterial; - -/** - * Just a simple container to wrap 4 GT Ore-Meta ids into one var - */ -public class GTOreGroup { - - public IMaterial Primary; - public IMaterial Secondary; - public IMaterial SporadicBetween; - public IMaterial SporadicAround; - - public GTOreGroup(IMaterial pPrimary, IMaterial pSecondary, IMaterial pSporadicBetween, IMaterial pSporadicAround) { - Primary = pPrimary; - Secondary = pSecondary; - SporadicBetween = pSporadicBetween; - SporadicAround = pSporadicAround; - } -} 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/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/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index 24df5780d1c..847f3d8a7d0 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -24,8 +24,6 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; -import com.google.common.collect.ImmutableList; - import gregtech.GTMod; import gregtech.api.GregTechAPI; import gregtech.api.enums.TCAspects.TC_AspectStack; @@ -3088,7 +3086,6 @@ public int getId() { return mMetaItemSubID; } - @Override public boolean isValidForStone(IStoneType stoneType) { if (contains(SubTag.ICE_ORE)) { return stoneType.getCategory() == StoneCategory.Ice; @@ -3098,7 +3095,7 @@ public boolean isValidForStone(IStoneType stoneType) { } @Override - public ImmutableList getValidStones() { + public List getValidStones() { if (contains(SubTag.ICE_ORE)) { return StoneType.ICES; } else { diff --git a/src/main/java/gregtech/api/enums/Mods.java b/src/main/java/gregtech/api/enums/Mods.java index 6bdfdbd270a..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), @@ -388,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/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index 08141ae979f..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; @@ -1204,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() @@ -1218,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); @@ -1230,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); diff --git a/src/main/java/gregtech/api/enums/StoneType.java b/src/main/java/gregtech/api/enums/StoneType.java index af3d6c9c31b..722f5c87fb0 100644 --- a/src/main/java/gregtech/api/enums/StoneType.java +++ b/src/main/java/gregtech/api/enums/StoneType.java @@ -1,5 +1,6 @@ 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; @@ -11,20 +12,23 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; -import java.util.function.Supplier; + +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.Item; 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 cpw.mods.fml.common.registry.GameRegistry; import galacticgreg.api.enums.DimensionDef.DimNames; import gregtech.GTMod; import gregtech.api.GregTechAPI; @@ -35,9 +39,6 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.render.TextureFactory; import gregtech.api.util.GTOreDictUnificator; -import gregtech.api.util.GTUtility; -import gregtech.api.util.Lazy; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; public enum StoneType implements IStoneType { @@ -114,10 +115,10 @@ public enum StoneType implements IStoneType { .setCoremodDust("BarnardaF")), Horus(new StoneBuilder() .setStoneNoCobble(() -> Blocks.obsidian, 0) - .addOtherStone(GalacticraftAmunRa, "tile.baseFalling", 0) + .addOtherStone(GalacticraftAmunRa, "tile.baseFalling", 1) .addAllowedDimensions(DimNames.HORUS) .setDust(Materials.Obsidian)), - Anubis(new StoneBuilder() + AnubisAndMaahes(new StoneBuilder() .setCobble(GalacticraftAmunRa, "tile.baseBlockRock", 0) .setMainStone(GalacticraftAmunRa, "tile.baseBlockRock", 1) .setDust(Materials.Basalt)), @@ -125,22 +126,34 @@ public enum StoneType implements IStoneType { .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 ImmutableList STONE_TYPES = ImmutableList.copyOf(values()); - public static final ImmutableList VISUAL_STONE_TYPES = ImmutableList.copyOf( + 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 ImmutableList STONE_ONLY = ImmutableList.of(StoneType.Stone); - public static final ImmutableList STONES = ImmutableList.copyOf( + 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 ImmutableList ICES = ImmutableList.copyOf( + public static final List ICES = ImmutableList.copyOf( StoneType.STONE_TYPES.stream() .filter(s -> s.getCategory() == StoneCategory.Ice) .toArray(StoneType[]::new)); @@ -158,18 +171,23 @@ public static void init() { builder.cobble.get(); builder.mainStone.get(); - if (builder.otherStones != null) builder.otherStones.forEach(Lazy::get); + if (builder.otherStones != null) builder.otherStones.forEach(LazyBlock::get); + + builder.pureDust.get(); - ItemStack pure = builder.pureDust.get(); - if (builder.impureDust.get() == null) { - builder.impureDust.set(pure.copy()); + if (builder.impureDust == null || builder.impureDust.get() == null) { + builder.impureDust = builder.pureDust; } } } @Override public ItemStack getDust(boolean pure, int amount) { - return GTUtility.copyAmount(amount, pure ? builder.pureDust.get() : builder.impureDust.get()); + if (pure) { + return builder.pureDust.toStack(amount); + } else { + return builder.impureDust.toStack(amount); + } } @Override @@ -183,15 +201,13 @@ public IStoneCategory getCategory() { } @Override - public ObjectIntPair getCobblestone() { - return builder.cobble.get() - .toPair(); + public ImmutableBlockMeta getCobblestone() { + return builder.cobble; } @Override - public ObjectIntPair getStone() { - return builder.mainStone.get() - .toPair(); + public ImmutableBlockMeta getStone() { + return builder.mainStone; } @Override @@ -240,11 +256,8 @@ public IIcon getIcon(int side) { case RedGranite -> BlockIcons.GRANITE_RED_STONE.getIcon(); case Marble -> BlockIcons.MARBLE_STONE.getIcon(); case Basalt -> BlockIcons.BASALT_STONE.getIcon(); - default -> { - BlockMeta main = builder.mainStone.get(); - - yield main.block.getIcon(side, main.meta); - } + default -> builder.mainStone.getBlock() + .getIcon(side, builder.mainStone.getBlockMeta()); }; } @@ -271,7 +284,12 @@ public boolean isDimensionSpecific() { @Override public boolean isExtraneous() { - return this.ordinal() > Endstone.ordinal() && this != PackedIce; + if (this == Stone) return false; + if (this == Netherrack) return false; + if (this == Endstone) return false; + if (this == PackedIce) return false; + + return true; } @Override @@ -281,15 +299,11 @@ public boolean isEnabled() { @Override public boolean contains(Block block, int meta) { - BlockMeta main = builder.mainStone.get(); - - if (block == main.block && meta == main.meta) return true; + if (builder.mainStone.matches(block, meta)) return true; if (builder.otherStones != null) { - for (Lazy other : builder.otherStones) { - BlockMeta other2 = other.get(); - - if (block == other2.block && meta == other2.meta) return true; + for (ImmutableBlockMeta other : builder.otherStones) { + if (other.matches(block, meta)) return true; } } @@ -302,10 +316,12 @@ public boolean canGenerateInWorld(World world) { || 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)) { @@ -316,39 +332,25 @@ public static StoneType findStoneType(Block block, int meta) { return null; } - private static class BlockMeta { - - public Block block; - public int meta; - - public BlockMeta(Mods mod, String blockName, int meta) { - this.block = GameRegistry.findBlock(mod.ID, blockName); - this.meta = meta; - - Objects.requireNonNull(block, "Could not find block " + mod.ID + ":" + blockName); - } + private static class StoneBuilder { - public BlockMeta(Block block, int meta) { - this.block = block; - this.meta = meta; - } + private static final LazyBlock AIR = new LazyBlock(Mods.Minecraft, "air"); - public ObjectIntPair toPair() { - return ObjectIntPair.of(block, meta); - } - } + public boolean enabled = true; - private static class StoneBuilder { + public LazyBlock cobble = AIR; + public LazyBlock mainStone = AIR; + public List otherStones; - public boolean enabled = true; - public Lazy cobble = new Lazy<>(() -> new BlockMeta(Blocks.air, 0)); - public Lazy mainStone = new Lazy<>(() -> new BlockMeta(Blocks.air, 0)); - public List> otherStones; public OrePrefixes oreBlockPrefix = OrePrefixes.ore; - public Lazy pureDust = new Lazy<>( + + public LazyItem pureDust = new LazyItem( + Mods.GregTech, () -> GTOreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1)); - public Lazy impureDust = new Lazy<>( + public LazyItem impureDust = new LazyItem( + Mods.GregTech, () -> GTOreDictUnificator.get(OrePrefixes.dustImpure, Materials.Stone, 1)); + public StoneCategory category = StoneCategory.Stone; public HashSet allowedDimensions = null; @@ -368,10 +370,10 @@ public static StoneBuilder galaxySpace(String name, String suffix, int mainStone return builder; } - public StoneBuilder setCobble(Supplier block, int meta) { + public StoneBuilder setCobble(BlockSupplier block, int meta) { Objects.requireNonNull(block); - cobble = new Lazy<>(() -> new BlockMeta(block.get(), meta)); + cobble = new LazyBlock(Mods.Minecraft, block, meta); return this; } @@ -380,7 +382,7 @@ public StoneBuilder setCobble(Mods owner, String blockName, int meta) { enabled &= owner.isModLoaded(); if (enabled) { - cobble = new Lazy<>(() -> new BlockMeta(owner, blockName, meta)); + cobble = new LazyBlock(owner, blockName, meta); } return this; @@ -390,14 +392,14 @@ public StoneBuilder setStoneNoCobble(Mods owner, String blockName, int meta) { enabled &= owner.isModLoaded(); if (enabled) { - cobble = mainStone = new Lazy<>(() -> new BlockMeta(owner, blockName, meta)); + cobble = mainStone = new LazyBlock(owner, blockName, meta); } return this; } - public StoneBuilder setStoneNoCobble(Supplier block, int meta) { - cobble = mainStone = new Lazy<>(() -> new BlockMeta(block.get(), meta)); + public StoneBuilder setStoneNoCobble(BlockSupplier block, int meta) { + cobble = mainStone = new LazyBlock(Mods.Minecraft, block, meta); return this; } @@ -406,14 +408,14 @@ public StoneBuilder setMainStone(Mods owner, String blockName, int meta) { enabled &= owner.isModLoaded(); if (enabled) { - mainStone = new Lazy<>(() -> new BlockMeta(owner, blockName, meta)); + mainStone = new LazyBlock(owner, blockName, meta); } return this; } - public StoneBuilder setMainStone(Supplier block, int meta) { - mainStone = new Lazy<>(() -> new BlockMeta(block.get(), meta)); + public StoneBuilder setMainStone(BlockSupplier block, int meta) { + mainStone = new LazyBlock(Mods.Minecraft, block, meta); return this; } @@ -421,7 +423,16 @@ public StoneBuilder setMainStone(Supplier block, int meta) { public StoneBuilder addOtherStone(Mods owner, String blockName, int meta) { if (owner.isModLoaded()) { if (otherStones == null) otherStones = new ArrayList<>(); - otherStones.add(new Lazy<>(() -> new BlockMeta(owner, blockName, meta))); + 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; @@ -429,19 +440,15 @@ public StoneBuilder addOtherStone(Mods owner, String blockName, int meta) { public StoneBuilder setCoremodDust(String name) { if (NewHorizonsCoreMod.isModLoaded()) { - pureDust = impureDust = new Lazy<>(() -> { - Item dust = GameRegistry.findItem(NewHorizonsCoreMod.ID, "item." + name + "StoneDust"); - Objects.requireNonNull(dust, "Could not find " + "item." + name + "StoneDust"); - return new ItemStack(dust, 1); - }); + pureDust = impureDust = new LazyItem(NewHorizonsCoreMod, "item." + name + "StoneDust"); } return this; } public StoneBuilder setDust(Materials mat) { - pureDust = new Lazy<>(() -> mat.getDust(1)); - impureDust = new Lazy<>(() -> GTOreDictUnificator.get(OrePrefixes.dustImpure, mat, 1)); + pureDust = new LazyItem(Mods.GregTech, () -> mat.getDust(1)); + impureDust = new LazyItem(Mods.GregTech, () -> GTOreDictUnificator.get(OrePrefixes.dustImpure, mat, 1)); return this; } 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/IMaterial.java b/src/main/java/gregtech/api/interfaces/IMaterial.java index c5576b62123..1d2f6fa3a90 100644 --- a/src/main/java/gregtech/api/interfaces/IMaterial.java +++ b/src/main/java/gregtech/api/interfaces/IMaterial.java @@ -1,27 +1,30 @@ package gregtech.api.interfaces; -import com.google.common.collect.ImmutableList; +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 IMaterial { - public String getLocalizedName(); + String getLocalizedName(); - public int getId(); + int getId(); - public String getInternalName(); + String getInternalName(); - public short[] getRGBA(); + short[] getRGBA(); - public TextureSet getTextureSet(); + TextureSet getTextureSet(); - public boolean isValidForStone(IStoneType stoneType); - - public ImmutableList getValidStones(); + List getValidStones(); public static IMaterial findMaterial(String name) { Werkstoff bw = Werkstoff.werkstoffVarNameHashMap.get(name); diff --git a/src/main/java/gregtech/api/interfaces/IStoneType.java b/src/main/java/gregtech/api/interfaces/IStoneType.java index 93e5fedbc49..af43f2c73bd 100644 --- a/src/main/java/gregtech/api/interfaces/IStoneType.java +++ b/src/main/java/gregtech/api/interfaces/IStoneType.java @@ -5,35 +5,50 @@ import net.minecraft.util.IIcon; import net.minecraft.world.World; +import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; + import gregtech.api.enums.OrePrefixes; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; +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); - public ObjectIntPair getCobblestone(); + /** Gets the cobblestone block for this stone. */ + public ImmutableBlockMeta getCobblestone(); - public ObjectIntPair getStone(); + /** 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/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/CooperativeScheduler.java b/src/main/java/gregtech/api/task/CooperativeScheduler.java index 9d14cc7c7ed..1de35285898 100644 --- a/src/main/java/gregtech/api/task/CooperativeScheduler.java +++ b/src/main/java/gregtech/api/task/CooperativeScheduler.java @@ -25,9 +25,9 @@ * considering newer tasks. * This is to prevent it from becoming clogged if something's generating bad tasks. */ -public enum CooperativeScheduler { +public final class CooperativeScheduler { - INSTANCE; + public static final CooperativeScheduler INSTANCE = new CooperativeScheduler(); private final LinkedHashMap> tasks = new LinkedHashMap<>(); private final List> newTasks = new ArrayList<>(); diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 339d06be1ab..61f62a07953 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -4356,7 +4356,7 @@ public static boolean isPartOfOrePrefix(ItemStack aStack, OrePrefixes aPrefix) { && GTOreDictUnificator.getAssociation(aStack).mPrefix.equals(aPrefix); } - public static boolean isMinable(Block block, int meta) { + public static boolean isOre(Block block, int meta) { if (OreManager.isOre(block, meta)) return true; return isOre(new ItemStack(block, 1, meta)); 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/GTWorldgenerator.java b/src/main/java/gregtech/common/GTWorldgenerator.java index 3957748ff8e..5069b3281c4 100644 --- a/src/main/java/gregtech/common/GTWorldgenerator.java +++ b/src/main/java/gregtech/common/GTWorldgenerator.java @@ -42,7 +42,7 @@ public class GTWorldgenerator implements IWorldGenerator { private static final int MAX_VEIN_SIZE = 2; // in chunks - public static List pendingTasks = Collections.synchronizedList(new LinkedList<>()); + 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. @@ -79,34 +79,33 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide return; } - pendingTasks.add( + PENDING_TASKS.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 + + " DimName" + + aWorld.provider.getDimensionName() + " chunk x:" + aX + " z:" + aZ + " SIZE: " - + pendingTasks.size()); + + PENDING_TASKS.size()); // hack to prevent cascading worldgen lag if (!this.mIsGenerating) { this.mIsGenerating = true; // Run a maximum of 5 chunks at a time through worldgen. Extra chunks get done later. - for (int i = 0; i < Math.min(pendingTasks.size(), 5); i++) { - WorldGenContainer task = pendingTasks.remove(0); + 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() @@ -117,7 +116,7 @@ public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvide + " z:" + task.mZ + " SIZE: " - + pendingTasks.size() + + PENDING_TASKS.size() + " i: " + i); @@ -210,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; @@ -219,12 +217,11 @@ public static class WorldGenContainer implements Runnable { // static int test=0; // 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; @@ -305,7 +302,6 @@ public void generateVein(int oreseedX, int oreseedZ) { this.mWorld, oreveinRNG, this.mBiome, - this.mDimensionType, this.mX * 16, this.mZ * 16, oreseedX * 16, @@ -346,6 +342,9 @@ public void generateVein(int oreseedX, int oreseedZ) { .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 { @@ -358,7 +357,6 @@ public void generateVein(int oreseedX, int oreseedZ) { this.mWorld, new XSTR(oreveinSeed ^ (oreLayer.mPrimary.getId())), this.mBiome, - this.mDimensionType, this.mX * 16, this.mZ * 16, oreseedX * 16, @@ -486,7 +484,6 @@ public void run() { this.mWorld, this.mRandom, this.mBiome, - this.mDimensionType, this.mX * 16, this.mZ * 16, this.mChunkGenerator, diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 407ee31a627..64afbb4af85 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -12,21 +12,19 @@ import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; -import com.google.common.collect.ImmutableList; - import gregtech.api.enums.StoneType; +import gregtech.api.events.GTEventBus; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneCategory; -import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; import gregtech.common.ores.OreManager; import gregtech.common.worldgen.IWorldgenLayer; +import gregtech.common.worldgen.VeinGenerateEvent; 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; @@ -38,14 +36,8 @@ public class WorldgenGTOreLayer extends GTWorldgen implements IWorldgenLayer { public final IMaterial mSporadic; public final String mRestrictBiome; /** {full dim name} */ - public final Set mAllowedDimensions; - public final Set mAllowedStone; - 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; + private final Set mAllowedDimensions; + private final Set mAllowedStone; public final String aTextWorldgen = "worldgen."; public WorldgenGTOreLayer(OreMixBuilder mix) { @@ -67,10 +59,6 @@ public WorldgenGTOreLayer(OreMixBuilder mix) { this.mSporadic = mix.sporadic; this.mAllowedStone = mix.stoneCategories == null ? null : new HashSet<>(mix.stoneCategories); this.mRestrictBiome = "None"; - - if (this.mEnabled) { - sWeight += this.mWeight; - } } @Override @@ -88,11 +76,6 @@ public int getWeight() { return mWeight; } - @Override - public float getSize() { - return mSize / 2; - } - @Override public float getDensity() { return 1f / (float) mDensity; @@ -103,11 +86,6 @@ public boolean canGenerateIn(String dimName) { return mAllowedDimensions.contains(dimName); } - @Override - public boolean canGenerateIn(IStoneType stoneType) { - return mAllowedStone != null && mAllowedStone.contains(stoneType.getCategory()); - } - @Override public boolean canGenerateIn(IStoneCategory stoneType) { return mAllowedStone != null && mAllowedStone.contains(stoneType); @@ -123,18 +101,6 @@ public boolean contains(IMaterial material) { return mPrimary == material || mBetween == material || mSecondary == material || mSporadic == material; } - @Override - public ImmutableList getOres() { - ImmutableList.Builder ores = ImmutableList.builder(); - - if (mPrimary != null) ores.add(mPrimary); - if (mBetween != null) ores.add(mBetween); - if (mSecondary != null) ores.add(mSecondary); - if (mSporadic != null) ores.add(mSporadic); - - return ores.build(); - } - @Override public IMaterial getOre(float k) { if (k < 1.0 / 7.0) { @@ -162,9 +128,20 @@ public boolean generatesBigOre() { return true; } + public Set getAllowedDimensions() { + return mAllowedDimensions; + } + @Override - public int executeWorldgenChunkified(World world, Random rng, String biome, int dimId, int chunkX, int chunkY, - int seedX, int seedZ, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + 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 @@ -193,7 +170,7 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int 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, chunkY + 9) != null) { + 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 { @@ -206,12 +183,12 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int int veinNorthZ = seedZ - rng.nextInt(mSize); int veinSouthZ = seedZ + 16 + rng.nextInt(mSize); - int limitNorthZ = Math.max(veinNorthZ, chunkY + 2); // Bias placement by 2 blocks to prevent worldgen cascade. - int limitSouthZ = Math.min(veinSouthZ, chunkY + 2 + 16); + 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, chunkY + 9) != null) { + 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 { @@ -228,7 +205,7 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int + " mX=" + chunkX / 16 + " mZ=" - + chunkY / 16 + + chunkZ / 16 + " oreseedX=" + seedX / 16 + " oreseedZ=" @@ -242,7 +219,7 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int int localDensity = Math.max( 1, this.mDensity - / ((int) Math.sqrt(2 + Math.pow(chunkX / 16 - seedX / 16, 2) + Math.pow(chunkY / 16 - seedZ / 16, 2)))); + / ((int) Math.sqrt(2 + Math.pow(chunkX / 16 - seedX / 16, 2) + Math.pow(chunkZ / 16 - seedZ / 16, 2)))); LayerGenerator generator = new LayerGenerator(); @@ -291,28 +268,28 @@ public int executeWorldgenChunkified(World world, Random rng, String biome, int for (int i = 0; i < smallOresToGenerate; i++) { int tX = rng.nextInt(16) + chunkX + 2; - int tZ = rng.nextInt(16) + chunkY + 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) + chunkY + 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) + chunkY + 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) + chunkY + 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); diff --git a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java index e3cf0053c47..d8cd79b9dc2 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java +++ b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java @@ -4,18 +4,16 @@ 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.chunk.IChunkProvider; -import com.google.common.collect.ImmutableList; - import gregtech.api.GregTechAPI; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneCategory; -import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; import gregtech.api.world.GTWorldgen; @@ -24,14 +22,15 @@ 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 IMaterial mMaterial; + private final IMaterial mMaterial; + public final String mBiome; - public final Set mAllowedDimensions; - public final Set mAllowedStone; - public static ArrayList sList = new ArrayList<>(); + private final Set mAllowedDimensions; + private final Set mAllowedStone; public WorldgenGTOreSmallPieces(SmallOreBuilder ore) { super(ore.smallOreName, GregTechAPI.sWorldgenList, ore.enabledByDefault); @@ -62,11 +61,6 @@ public int getWeight() { return mAmount; } - @Override - public float getSize() { - return mAmount / 2; - } - @Override public float getDensity() { return GTUtility.clamp(mAmount / 64.0f, 0f, 1f); @@ -77,11 +71,6 @@ public boolean canGenerateIn(String dimName) { return mAllowedDimensions.contains(dimName); } - @Override - public boolean canGenerateIn(IStoneType stoneType) { - return mAllowedStone != null && mAllowedStone.contains(stoneType.getCategory()); - } - @Override public boolean canGenerateIn(IStoneCategory stoneType) { return mAllowedStone != null && mAllowedStone.contains(stoneType); @@ -97,11 +86,6 @@ public boolean contains(IMaterial material) { return material == mMaterial; } - @Override - public ImmutableList getOres() { - return mMaterial == null ? ImmutableList.of() : ImmutableList.of(mMaterial); - } - @Override public IMaterial getOre(float k) { return mMaterial; @@ -117,8 +101,16 @@ public boolean generatesBigOre() { return false; } + public Set getAllowedDimensions() { + return mAllowedDimensions; + } + + public IMaterial getMaterial() { + return mMaterial; + } + @Override - public boolean executeWorldgen(World world, Random random, String biome, int dimId, int chunkX, int chunkZ, + 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 @@ -148,8 +140,8 @@ public boolean executeWorldgen(World world, Random random, String biome, int dim if (debugSmallOres) { GTLog.out.println( "Small Ore:" + this.mWorldGenName - + " @ dim=" - + dimId + + " @ DimName=" + + world.provider.getDimensionName() + " mX=" + chunkX / 16 + " mZ=" diff --git a/src/main/java/gregtech/common/WorldgenStone.java b/src/main/java/gregtech/common/WorldgenStone.java index 600834d4828..844e9bf1646 100644 --- a/src/main/java/gregtech/common/WorldgenStone.java +++ b/src/main/java/gregtech/common/WorldgenStone.java @@ -13,6 +13,7 @@ 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; @@ -77,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<>(); @@ -128,7 +129,7 @@ public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int } } - IStoneType stoneType = OreManager.getStoneType(mBlock, mBlockMeta); + IStoneType stoneType = StoneType.findStoneType(mBlock, mBlockMeta); boolean result = !stones.isEmpty(); // Now process each oreseed vs this requested chunk diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java index 591bd8a82dc..3cec2c5a371 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstract.java @@ -4,6 +4,7 @@ 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; @@ -185,16 +186,6 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { } } - public boolean isExtraneous() { - for (StoneType stoneType : stoneTypes) { - if (stoneType == null || stoneType.isExtraneous()) continue; - - return false; - } - - return true; - } - @Override public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { EntityPlayer harvester = this.harvesters.get(); @@ -205,7 +196,8 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, metadata)) { if (info == null) return new ArrayList<>(); - return (ArrayList) GTOreAdapter.INSTANCE.getOreDrops(info, doSilktouch, doFortune ? fortune : 0); + return GTOreAdapter.INSTANCE + .getOreDrops(ThreadLocalRandom.current(), info, doSilktouch, doFortune ? fortune : 0); } } @@ -297,8 +289,10 @@ public int damageDropped(int meta) { try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(this, meta)) { if (info == null) return 0; - return GTOreAdapter.INSTANCE.getBlock(info.setNatural(false)) - .rightInt(); + info.isNatural = false; + + return GTOreAdapter.INSTANCE.getBlock(info) + .getBlockMeta(); } } @@ -319,17 +313,20 @@ public int getHarvestLevel(int meta) { @Override public float getBlockHardness(World world, int x, int y, int z) { - int meta = world.getBlockMetadata(x, y, z); - - return 1.0F + getHarvestLevel(meta); + 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) { - int meta = world.getBlockMetadata(x, y, z); - - return 1.0F + getHarvestLevel(meta); + try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(world, x, y, z)) { + return info.stoneType.getStone() + .getBlock() + .getExplosionResistance(entity); + } } @Override @@ -337,14 +334,14 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p float subY, float subZ) { if (!world.isRemote && player.capabilities.isCreativeMode && player.getHeldItem() == null) { try (OreInfo info = GTOreAdapter.INSTANCE.getOreInfo(world, x, y, z);) { - info.setNatural(!info.isNatural); + info.isNatural = !info.isNatural; world.setBlockMetadataWithNotify( x, y, z, GTOreAdapter.INSTANCE.getBlock(info) - .rightInt(), + .getBlockMeta(), 3); GTUtility.sendChatToPlayer(player, "Set ore natural flag to " + info.isNatural); } diff --git a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java index 2462b243803..e351d577da6 100644 --- a/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java +++ b/src/main/java/gregtech/common/misc/DrillingLogicDelegate.java @@ -10,6 +10,7 @@ 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; @@ -161,8 +162,11 @@ public void mineBlock(IGregTechTileEntity te, Block block, int x, int y, int z) return; } + XSTR rng = new XSTR(); + // see if we can store all of the outputs - List drops = OreManager.mineBlock(te.getWorld(), x, y, z, false, owner.getMachineTier(), true, true); + List drops = OreManager + .mineBlock(rng, te.getWorld(), x, y, z, false, owner.getMachineTier(), true, true); for (ItemStack drop : drops) { if (!owner.pushOutputs(drop, drop.stackSize, true, false)) { @@ -175,7 +179,7 @@ public void mineBlock(IGregTechTileEntity te, Block block, int x, int y, int z) } // actually mine it - OreManager.mineBlock(te.getWorld(), x, y, z, false, owner.getMachineTier(), false, true); + OreManager.mineBlock(rng, te.getWorld(), x, y, z, false, owner.getMachineTier(), false, true); } /** diff --git a/src/main/java/gregtech/common/ores/BWOreAdapter.java b/src/main/java/gregtech/common/ores/BWOreAdapter.java index f2c1bc4b38b..c880d0a6fa0 100644 --- a/src/main/java/gregtech/common/ores/BWOreAdapter.java +++ b/src/main/java/gregtech/common/ores/BWOreAdapter.java @@ -9,6 +9,8 @@ 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; @@ -24,11 +26,12 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.GTUtility.ItemId; import gregtech.common.GTProxy.OreDropSystem; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; -public enum BWOreAdapter implements IOreAdapter { +public final class BWOreAdapter implements IOreAdapter { - INSTANCE; + public static BWOreAdapter INSTANCE = new BWOreAdapter(); + + private BWOreAdapter() {} private final EnumMap ores = new EnumMap<>(StoneType.class); @@ -130,7 +133,7 @@ public OreInfo getOreInfo(Block block, int meta) { OreInfo info = OreInfo.getNewInfo(); info.stoneType = oreBlock.stoneType; - info.material = Werkstoff.werkstoffHashMap.get((Short) (short) meta); + info.material = Werkstoff.werkstoffHashMap.get((short) meta); info.isSmall = oreBlock.isSmall; info.isNatural = oreBlock.isNatural; @@ -138,7 +141,7 @@ public OreInfo getOreInfo(Block block, int meta) { } @Override - public ObjectIntPair getBlock(OreInfo info) { + public ImmutableBlockMeta getBlock(OreInfo info) { IStoneType stone = info.stoneType; if (stone == null) stone = StoneType.Stone; @@ -150,11 +153,11 @@ public ObjectIntPair getBlock(OreInfo info) { Ores ores = this.ores.get(stoneType); if (ores == null) return null; - return ObjectIntPair.of(ores.get(info.isSmall, info.isNatural), w.getmID()); + return new BlockMeta(ores.get(info.isSmall, info.isNatural), w.getmID()); } @Override - public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { + public ArrayList getOreDrops(Random random, OreInfo info2, boolean silktouch, int fortune) { if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") @@ -162,19 +165,19 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort IStoneType stone = info.stoneType; if (stone == null) stone = StoneType.Stone; - if (!(stone instanceof StoneType stoneType)) return null; - if (!this.ores.containsKey(stoneType)) return null; + 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(ThreadLocalRandom.current(), info, fortune); + return getSmallOreDrops(random, info, fortune); } else { OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; if (silktouch) oreDropSystem = OreDropSystem.Block; - return getBigOreDrops(ThreadLocalRandom.current(), oreDropSystem, info, fortune); + return getBigOreDrops(random, oreDropSystem, info, fortune); } } @@ -186,7 +189,7 @@ public List getPotentialDrops(OreInfo info2) { OreInfo info = (OreInfo) info2; if (info.isSmall) { - List drops = new ArrayList<>(); + ArrayList drops = new ArrayList<>(); for (ItemStack stack : SmallOreDrops.getDropList(info.material.getBridgeMaterial())) { ItemId id = ItemId.create(stack); @@ -194,7 +197,7 @@ public List getPotentialDrops(OreInfo info2) { if (!drops.contains(id)) drops.add(id); } - List drops2 = new ArrayList<>(); + ArrayList drops2 = new ArrayList<>(); for (ItemId id : drops) { drops2.add(id.getItemStack()); @@ -206,7 +209,7 @@ public List getPotentialDrops(OreInfo info2) { } } - public ArrayList getSmallOreDrops(Random random, OreInfo info, int fortune) { + private ArrayList getSmallOreDrops(Random random, OreInfo info, int fortune) { Materials bridge = info.material.getBridgeMaterial(); ArrayList possibleDrops = SmallOreDrops.getDropList(bridge); @@ -229,7 +232,7 @@ public ArrayList getSmallOreDrops(Random random, OreInfo i return drops; } - public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + private ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, int fortune) { ArrayList drops = new ArrayList<>(); diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index 8a632dea88c..c69fe9f11c6 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -12,10 +12,13 @@ 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; @@ -28,21 +31,20 @@ import gregtech.api.util.GTUtility.ItemId; import gregtech.common.GTProxy.OreDropSystem; import gregtech.common.blocks.BlockOresAbstract; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; -public enum GTOreAdapter implements IOreAdapter { +public final class GTOreAdapter implements IOreAdapter { - INSTANCE; + public static GTOreAdapter INSTANCE = new GTOreAdapter(); - private final Map oreBlocksByStoneType = new EnumMap<>(StoneType.class); + private GTOreAdapter() {} - public BlockOresAbstract ores1, ores2, ores3, ores4, ores5, ores6; + private final Map oreBlocksByStoneType = new EnumMap<>(StoneType.class); - public BlockOresAbstract[] ores; + private BlockOresAbstract[] ores; public void init() { // spotless:off - ores1 = new BlockOresAbstract(2, new StoneType[] { + BlockOresAbstract ores1 = new BlockOresAbstract(2, new StoneType[] { StoneType.Stone, StoneType.Netherrack, StoneType.Endstone, @@ -52,7 +54,7 @@ public void init() { StoneType.Basalt, StoneType.Moon, }); - ores2 = new BlockOresAbstract(3, new StoneType[] { + BlockOresAbstract ores2 = new BlockOresAbstract(3, new StoneType[] { StoneType.Mars, StoneType.Asteroid, StoneType.Phobos, @@ -62,7 +64,7 @@ public void init() { StoneType.Europa, StoneType.Ganymede, }); - ores3 = new BlockOresAbstract(4, new StoneType[] { + BlockOresAbstract ores3 = new BlockOresAbstract(4, new StoneType[] { StoneType.Callisto, StoneType.Enceladus, StoneType.Titan, @@ -72,7 +74,7 @@ public void init() { StoneType.Triton, StoneType.Pluto, }); - ores4 = new BlockOresAbstract(5, new StoneType[] { + BlockOresAbstract ores4 = new BlockOresAbstract(5, new StoneType[] { StoneType.Callisto, StoneType.Enceladus, StoneType.Titan, @@ -82,7 +84,7 @@ public void init() { StoneType.Triton, StoneType.Pluto, }); - ores5 = new BlockOresAbstract(6, new StoneType[] { + BlockOresAbstract ores5 = new BlockOresAbstract(6, new StoneType[] { StoneType.Haumea, StoneType.MakeMake, StoneType.AlphaCentauri, @@ -92,9 +94,11 @@ public void init() { StoneType.BarnardaF, StoneType.Horus, }); - ores6 = new BlockOresAbstract(7, new StoneType[] { - StoneType.Anubis, + BlockOresAbstract ores6 = new BlockOresAbstract(7, new StoneType[] { + StoneType.AnubisAndMaahes, StoneType.PackedIce, + StoneType.SethIce, + StoneType.SethClay, }); ores = new BlockOresAbstract[] { ores1, ores2, ores3, ores4, ores5, ores6 }; @@ -123,9 +127,9 @@ public void init() { if (!INSTANCE.supports(info)) { return new BlockInfo(Blocks.air, 0); } else { - var p = INSTANCE.getBlock(info); + ImmutableBlockMeta bm = INSTANCE.getBlock(info); - return new BlockInfo(p.left(), p.rightInt()); + return new BlockInfo(bm.getBlock(), bm.getBlockMeta()); } } }); @@ -141,6 +145,12 @@ public void registerOre(StoneType stoneType, BlockOresAbstract oreBlock) { oreBlocksByStoneType.put(stoneType, oreBlock); } + public void hideOres() { + for (BlockOresAbstract ore : ores) { + API.hideItem(new ItemStack(ore, 1, 0)); + } + } + @Override public boolean supports(Block block, int meta) { return GTUtility.contains(ores, block); @@ -157,7 +167,7 @@ public boolean supports(OreInfo info) { if (!(stoneType instanceof StoneType stoneType2)) return false; if (!oreBlocksByStoneType.containsKey(stoneType2)) return false; if (!stoneType2.isEnabled()) return false; - if (!info.material.isValidForStone(stoneType2)) return false; + if (!gtMat.isValidForStone(stoneType2)) return false; if (stoneType2.getCategory() == StoneCategory.Ice && info.isSmall) return false; return true; @@ -197,7 +207,7 @@ public OreInfo getOreInfo(Block block, int meta) { } @Override - public ObjectIntPair getBlock(OreInfo info) { + public ImmutableBlockMeta getBlock(OreInfo info) { if (info.stoneType == null) info.stoneType = StoneType.Stone; if (!(info.material instanceof Materials gtMat)) return null; @@ -218,11 +228,11 @@ public ObjectIntPair getBlock(OreInfo info) { if (info.isSmall) meta += SMALL_ORE_META_OFFSET; if (info.isNatural) meta += NATURAL_ORE_META_OFFSET; - return ObjectIntPair.of(oreBlock, meta); + return new BlockMeta(oreBlock, meta); } @Override - public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { + public ArrayList getOreDrops(Random random, OreInfo info2, boolean silktouch, int fortune) { if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") @@ -237,13 +247,13 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort if (!info.isNatural) fortune = 0; if (info.isSmall) { - return getSmallOreDrops(ThreadLocalRandom.current(), info, fortune); + return getSmallOreDrops(random, info, fortune); } else { OreDropSystem oreDropSystem = GTMod.gregtechproxy.oreDropSystem; if (silktouch) oreDropSystem = OreDropSystem.Block; - return getBigOreDrops(ThreadLocalRandom.current(), oreDropSystem, info, fortune); + return getBigOreDrops(random, oreDropSystem, info, fortune); } } @@ -255,7 +265,7 @@ public List getPotentialDrops(OreInfo info2) { OreInfo info = (OreInfo) info2; if (info.isSmall) { - List drops = new ArrayList<>(); + ArrayList drops = new ArrayList<>(); for (ItemStack stack : SmallOreDrops.getDropList(info.material)) { ItemId id = ItemId.create(stack); @@ -263,7 +273,7 @@ public List getPotentialDrops(OreInfo info2) { if (!drops.contains(id)) drops.add(id); } - List drops2 = new ArrayList<>(); + ArrayList drops2 = new ArrayList<>(); for (ItemId id : drops) { drops2.add(id.getItemStack()); @@ -275,7 +285,7 @@ public List getPotentialDrops(OreInfo info2) { } } - public ArrayList getSmallOreDrops(Random random, OreInfo info, int fortune) { + private ArrayList getSmallOreDrops(Random random, OreInfo info, int fortune) { ArrayList possibleDrops = SmallOreDrops.getDropList(info.material); ArrayList drops = new ArrayList<>(); @@ -297,7 +307,7 @@ public ArrayList getSmallOreDrops(Random random, OreInfo i return drops; } - public ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + private ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, int fortune) { ArrayList drops = new ArrayList<>(); diff --git a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java index 218a0885c97..385fc222f82 100644 --- a/src/main/java/gregtech/common/ores/GTPPOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTPPOreAdapter.java @@ -8,16 +8,20 @@ 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; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; -public enum GTPPOreAdapter implements IOreAdapter { +public final class GTPPOreAdapter implements IOreAdapter { + + public static GTPPOreAdapter INSTANCE = new GTPPOreAdapter(); - INSTANCE; + private GTPPOreAdapter() {} @Override public boolean supports(Block block, int meta) { @@ -47,7 +51,7 @@ public OreInfo getOreInfo(Block block, int meta) { } @Override - public ObjectIntPair getBlock(OreInfo info) { + public ImmutableBlockMeta getBlock(OreInfo info) { if (!supports(info)) return null; if (!(info.material instanceof Material gtppMat)) return null; @@ -56,11 +60,11 @@ public ObjectIntPair getBlock(OreInfo info) { if (ore == null) return null; - return ObjectIntPair.of(ore, 0); + return new BlockMeta(ore, 0); } @Override - public List getOreDrops(OreInfo info2, boolean silktouch, int fortune) { + public ArrayList getOreDrops(Random random, OreInfo info2, boolean silktouch, int fortune) { if (!supports(info2)) return new ArrayList<>(); @SuppressWarnings("unchecked") @@ -72,7 +76,7 @@ public List getOreDrops(OreInfo info2, boolean silktouch, int fort if (silktouch) oreDropSystem = OreDropSystem.Block; - return getBigOreDrops(ThreadLocalRandom.current(), oreDropSystem, info, fortune); + return getBigOreDrops(random, oreDropSystem, info, fortune); } @Override @@ -85,7 +89,7 @@ public List getPotentialDrops(OreInfo info2) { return getBigOreDrops(ThreadLocalRandom.current(), GTMod.gregtechproxy.oreDropSystem, info, 0); } - public List getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, + private ArrayList getBigOreDrops(Random random, OreDropSystem oreDropMode, OreInfo info, int fortune) { ArrayList drops = new ArrayList<>(); diff --git a/src/main/java/gregtech/common/ores/IOreAdapter.java b/src/main/java/gregtech/common/ores/IOreAdapter.java index ad1e07586cc..f53d7116a05 100644 --- a/src/main/java/gregtech/common/ores/IOreAdapter.java +++ b/src/main/java/gregtech/common/ores/IOreAdapter.java @@ -1,6 +1,8 @@ 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; @@ -8,45 +10,78 @@ 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.IMaterial; -import it.unimi.dsi.fastutil.objects.ObjectIntPair; 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)); } - public ObjectIntPair getBlock(OreInfo info); + /** + * 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) { - ObjectIntPair p = getBlock(info); + ImmutableBlockMeta bm = getBlock(info); - if (p != null) { - return new ItemStack(p.left(), amount, p.rightInt()); + 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; - p = getBlock(info2); + bm = getBlock(info2); - if (p != null) { - return new ItemStack(p.left(), amount, p.rightInt()); + if (bm != null) { + return new ItemStack(bm.getBlock(), amount, bm.getBlockMeta()); } } } @@ -54,7 +89,14 @@ public default ItemStack getStack(OreInfo info, int amount) { return null; } - public List getOreDrops(OreInfo info, boolean silktouch, int fortune); + /** + * 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 index af696eb7497..00377c0ac6a 100644 --- a/src/main/java/gregtech/common/ores/OreInfo.java +++ b/src/main/java/gregtech/common/ores/OreInfo.java @@ -56,26 +56,6 @@ public OreInfo clone() { return dup; } - public OreInfo setMaterial(TMat material) { - this.material = material; - return this; - } - - public OreInfo setStoneType(IStoneType stoneType) { - this.stoneType = stoneType; - return this; - } - - public OreInfo setSmall(boolean isSmall) { - this.isSmall = isSmall; - return this; - } - - public OreInfo setNatural(boolean isNatural) { - this.isNatural = isNatural; - return this; - } - @Override public int hashCode() { final int prime = 31; diff --git a/src/main/java/gregtech/common/ores/OreManager.java b/src/main/java/gregtech/common/ores/OreManager.java index 0c8b8b9fb33..9c23482f104 100644 --- a/src/main/java/gregtech/common/ores/OreManager.java +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -1,8 +1,7 @@ package gregtech.common.ores; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.Random; import javax.annotation.Nullable; @@ -14,26 +13,20 @@ 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.IMaterial; import gregtech.api.interfaces.IStoneType; -public class OreManager { +public final class OreManager { private OreManager() {} - public static final ImmutableList> ORE_ADAPTERS = ImmutableList + private static final List> ORE_ADAPTERS = ImmutableList .of(GTOreAdapter.INSTANCE, GTPPOreAdapter.INSTANCE, BWOreAdapter.INSTANCE); - public static IStoneType getStoneType(Block block, int meta) { - IStoneType stoneType = StoneType.findStoneType(block, meta); - - if (stoneType != null) return stoneType; - - return null; - } - public static boolean isOre(Block block, int meta) { int size = ORE_ADAPTERS.size(); @@ -89,7 +82,7 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone IMaterial material, boolean small) { if (y < 0 || y >= world.getActualHeight()) return false; - IStoneType existingStone = getStoneType(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + IStoneType existingStone = StoneType.findStoneType(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); if (existingStone != null && !existingStone.canGenerateInWorld(world)) return false; @@ -101,7 +94,7 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone } } - try (OreInfo info = OreInfo.getNewInfo();) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = material; info.stoneType = existingStone; info.isSmall = small; @@ -112,10 +105,10 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone for (int i = 0; i < size; i++) { IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); - var block = oreAdapter.getBlock(info); + ImmutableBlockMeta oreBlock = oreAdapter.getBlock(info); - if (block != null) { - world.setBlock(x, y, z, block.left(), block.rightInt(), 3); + if (oreBlock != null) { + world.setBlock(x, y, z, oreBlock.getBlock(), oreBlock.getBlockMeta(), 3); return true; } @@ -129,7 +122,7 @@ public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneT boolean small) { if (y < 0 || y >= world.getActualHeight()) return false; - try (OreInfo info = OreInfo.getNewInfo();) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = material; info.stoneType = stoneType; info.isSmall = small; @@ -140,10 +133,10 @@ public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneT for (int i = 0; i < size; i++) { IOreAdapter oreAdapter = ORE_ADAPTERS.get(i); - var block = oreAdapter.getBlock(info); + ImmutableBlockMeta oreBlock = oreAdapter.getBlock(info); - if (block != null) { - world.setBlock(x, y, z, block.left(), block.rightInt(), 2); + if (oreBlock != null) { + world.setBlock(x, y, z, oreBlock.getBlock(), oreBlock.getBlockMeta(), 2); return true; } @@ -162,49 +155,44 @@ public static boolean setExistingOreStoneType(World world, int x, int y, int z, info.stoneType = newStoneType; - var newBlock = getAdapter(info).getBlock(info); + ImmutableBlockMeta oreBlock = getAdapter(info).getBlock(info); - if (newBlock == null) return false; + if (oreBlock == null) return false; - world.setBlock(x, y, z, newBlock.left(), newBlock.rightInt(), 2); + world.setBlock(x, y, z, oreBlock.getBlock(), oreBlock.getBlockMeta(), 2); return true; } } - public static List mineBlock(World world, int x, int y, int z, boolean silktouch, int fortune, - boolean simulate, boolean replaceWithCobblestone) { + 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; - Block replacement; - int replacementMeta; + ImmutableBlockMeta replacement; try (OreInfo info = getOreInfo(ore, meta)) { if (info != null) { - oreBlockDrops = info.cachedAdapter.getOreDrops(info, silktouch, fortune); + oreBlockDrops = info.cachedAdapter.getOreDrops(random, info, silktouch, fortune); - var cobble = info.stoneType.getCobblestone(); - - replacement = cobble.left(); - replacementMeta = cobble.rightInt(); + replacement = info.stoneType.getCobblestone(); } else { if (silktouch && ore.canSilkHarvest(world, null, x, y, z, meta)) { - oreBlockDrops = new ArrayList<>(Arrays.asList(new ItemStack(ore, 1, meta))); + oreBlockDrops = ImmutableList.of(new ItemStack(ore, 1, meta)); } else { // Regular ore - oreBlockDrops = ore.getDrops(world, x, y, z, meta, fortune); + oreBlockDrops = ImmutableList.copyOf(ore.getDrops(world, x, y, z, meta, fortune)); } - replacement = Blocks.cobblestone; - replacementMeta = 0; + replacement = new BlockMeta(Blocks.cobblestone, 0); } } if (!simulate) { if (replaceWithCobblestone) { - world.setBlock(x, y, z, replacement, replacementMeta, 3); + world.setBlock(x, y, z, replacement.getBlock(), replacement.getBlockMeta(), 3); } else { world.setBlockToAir(x, y, z); } @@ -247,22 +235,6 @@ public static String getLocalizedName(OreInfo info) { return stack.getDisplayName(); } - public static List getDrops(Block block, int meta, boolean silktouch, int fortune) { - 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) { - return oreAdapter.getOreDrops(info, silktouch, fortune); - } - } - } - - return null; - } - public static List getPotentialDrops(OreInfo info) { int size = ORE_ADAPTERS.size(); diff --git a/src/main/java/gregtech/common/ores/SmallOreDrops.java b/src/main/java/gregtech/common/ores/SmallOreDrops.java index 9e9b5fc3f9d..64918af0a12 100644 --- a/src/main/java/gregtech/common/ores/SmallOreDrops.java +++ b/src/main/java/gregtech/common/ores/SmallOreDrops.java @@ -1,6 +1,7 @@ package gregtech.common.ores; import java.util.ArrayList; +import java.util.List; import net.minecraft.item.ItemStack; @@ -20,11 +21,11 @@ public enum SmallOreDrops { gemChipped(OrePrefixes.gemChipped, OrePrefixes.dustImpure, 5), dustImpure(OrePrefixes.dustImpure, null, 10); - public static final ImmutableList DROPS = ImmutableList.copyOf(values()); + public static final List DROPS = ImmutableList.copyOf(values()); - public final OrePrefixes primary; - public final OrePrefixes fallback; - public final int weight; + private final OrePrefixes primary; + private final OrePrefixes fallback; + private final int weight; private SmallOreDrops(OrePrefixes primary, OrePrefixes fallback, int weight) { this.primary = primary; diff --git a/src/main/java/gregtech/common/render/GTRendererBlock.java b/src/main/java/gregtech/common/render/GTRendererBlock.java index a9b00532756..febe89b873f 100644 --- a/src/main/java/gregtech/common/render/GTRendererBlock.java +++ b/src/main/java/gregtech/common/render/GTRendererBlock.java @@ -53,6 +53,7 @@ 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; @@ -542,6 +543,12 @@ public static void addDestroyEffects(EffectRenderer effectRenderer, Block block, } } + 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) { aRenderer.enableAO = false; @@ -549,9 +556,10 @@ 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); - // spotless:off - 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); + + 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) { @@ -565,7 +573,6 @@ public void renderInventoryBlock(Block aBlock, int aMeta, int aModelID, RenderBl renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, texture[ForgeDirection.EAST.ordinal()], true); } } - // spotless:on aBlock.setBlockBounds(blockMin, blockMin, blockMin, blockMax, blockMax, blockMax); aRenderer.setRenderBoundsFromBlock(aBlock); @@ -574,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 } 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 b79becaf1e7..fc0d91e4f6e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/MTEAdvSeismicProspector.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/MTEAdvSeismicProspector.java @@ -280,7 +280,7 @@ private String checkForOre(int x, int y, int z) { ItemData association = GTOreDictUnificator.getAssociation(is); if ((association != null) && (association.mPrefix.toString() .startsWith("ore"))) return association.mMaterial.mMaterial.mDefaultLocalName; - else if (GTUtility.isMinable(tBlock, tMetaID)) return tBlock.getLocalizedName(); + else if (GTUtility.isOre(tBlock, tMetaID)) return tBlock.getLocalizedName(); } return null; } 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 4df3c45191a..64f9107f777 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/MTEMiner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/MTEMiner.java @@ -248,7 +248,7 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { x = aBaseMetaTileEntity.getXCoord() + oreBlockPos.chunkPosX; y = aBaseMetaTileEntity.getYCoord() + oreBlockPos.chunkPosY; z = aBaseMetaTileEntity.getZCoord() + oreBlockPos.chunkPosZ; - isOre = GTUtility.isMinable( + isOre = GTUtility.isOre( oreBlock, aBaseMetaTileEntity.getWorld() .getBlockMetadata(x, y, z)); @@ -273,7 +273,7 @@ private void fillOreList(IGregTechTileEntity aBaseMetaTileEntity) { Block block = aBaseMetaTileEntity.getBlockOffset(x, pipe.getTipDepth(), z); int blockMeta = aBaseMetaTileEntity.getMetaIDOffset(x, pipe.getTipDepth(), z); - if (GTUtility.isMinable(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 669f800e12d..35c63c84b09 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEOreDrillingPlantBase.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -239,7 +240,7 @@ private boolean processOreList(boolean simulate) { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); - if (!GTUtility.isMinable(block, meta)) { + if (!GTUtility.isOre(block, meta)) { // always remove non-ore blocks, even if we're simulating iter.remove(); continue; @@ -257,8 +258,16 @@ private boolean processOreList(boolean simulate) { return false; } - List oreBlockDrops = OreManager - .mineBlock(world, x, y, z, true, mTier + 3, simulate, replaceWithCobblestone); + List oreBlockDrops = OreManager.mineBlock( + ThreadLocalRandom.current(), + world, + x, + y, + z, + true, + mTier + 3, + simulate, + replaceWithCobblestone); ItemStack[] toOutput = getOutputByDrops(oreBlockDrops); @@ -585,7 +594,7 @@ private void tryAddOreBlockToMineList(int x, int y, int z) { long pos = CoordinatePacker.pack(x, y, z); if (!oreBlockPositions.contains(pos)) { - if (GTUtility.isMinable(block, blockMeta)) oreBlockPositions.add(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 index 62f2995aa68..3d01e6717b9 100644 --- a/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java +++ b/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java @@ -1,38 +1,43 @@ package gregtech.common.worldgen; -import com.google.common.collect.ImmutableList; - import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneCategory; -import gregtech.api.interfaces.IStoneType; +/** A worldgen layer that generates ore. */ public interface IWorldgenLayer { - public int getMinY(); - - public int getMaxY(); - - public int getWeight(); - - public float getSize(); + int getMinY(); - public float getDensity(); + int getMaxY(); - public boolean canGenerateIn(String dimName); + /** Gets the RNG weight. */ + int getWeight(); - public boolean canGenerateIn(IStoneType stoneType); + /** Gets the density. 1 = 100%, 0.5 = 50%, 0 = 0% */ + float getDensity(); - public boolean canGenerateIn(IStoneCategory stoneType); + /** Checks if this layer can generate in the given dimension. */ + boolean canGenerateIn(String dimName); - public boolean isStoneSpecific(); + /** Checks if this layer can generate in the given stone category. */ + boolean canGenerateIn(IStoneCategory stoneType); - public boolean generatesBigOre(); + /** Whether this layer can only generate in specific stone types. */ + boolean isStoneSpecific(); - public boolean contains(IMaterial ore); + /** If this layer generates big ore. Ignores small ore. */ + boolean generatesBigOre(); - public ImmutableList getOres(); + /** Checks if this layer contains this material */ + boolean contains(IMaterial ore); - public IMaterial getOre(float k); + /** + * Selects an ore for worldgen. + * + * @param k The weight, 0-1. + * @return The ore. + */ + IMaterial getOre(float k); - public String getName(); + 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 index bc656137df6..aa8bbcbc056 100644 --- a/src/main/java/gregtech/common/worldgen/WorldgenQuery.java +++ b/src/main/java/gregtech/common/worldgen/WorldgenQuery.java @@ -6,6 +6,8 @@ import java.util.Random; import java.util.Set; +import javax.annotation.Nullable; + import net.minecraft.world.World; import galacticgreg.api.ModDimensionDef; @@ -94,6 +96,7 @@ public WorldgenQuery inStone(IStoneCategory stoneCategories) { return this; } + @Nullable public TLayer find(Random random) { if (checkWeight) { return findWithWeight(random); diff --git a/src/main/java/gregtech/nei/NEIGTConfig.java b/src/main/java/gregtech/nei/NEIGTConfig.java index 827ca3ea68f..664d34e4afc 100644 --- a/src/main/java/gregtech/nei/NEIGTConfig.java +++ b/src/main/java/gregtech/nei/NEIGTConfig.java @@ -4,8 +4,6 @@ import java.util.Comparator; import java.util.Map; -import net.minecraft.item.ItemStack; - import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ListMultimap; @@ -28,7 +26,6 @@ import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.RecipeMaps; import gregtech.api.util.GTModHandler; -import gregtech.common.blocks.BlockOresAbstract; import gregtech.common.items.MetaGeneratedItem01; import gregtech.common.items.MetaGeneratedItem02; import gregtech.common.items.MetaGeneratedItem03; @@ -127,9 +124,7 @@ private void registerDumpers() { } private void hideItems() { - for (BlockOresAbstract ore : GTOreAdapter.INSTANCE.ores) { - API.hideItem(new ItemStack(ore, 1, 0)); - } + GTOreAdapter.INSTANCE.hideOres(); } @SubscribeEvent diff --git a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java index 1efdf536c3d..da8f9bf84a9 100644 --- a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java +++ b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java @@ -1,7 +1,7 @@ package gtPlusPlus.core.block.base; import java.util.ArrayList; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nullable; @@ -17,13 +17,14 @@ import net.minecraftforge.common.util.FakePlayer; import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.GTMod; 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.GTOreDictUnificator; +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; @@ -33,8 +34,6 @@ 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( @@ -105,67 +104,17 @@ public ITexture[][] getTextures(int metadata) { 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/item/base/itemblock/ItemBlockOre.java b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java index 5cd5e6ec352..ef156df1847 100644 --- a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java @@ -51,7 +51,7 @@ private static void initVeinInfo() { for (IMaterial mat : mats) { if (mat instanceof Material gtppMat) { - mMapOreBlockItemToDimName.put(gtppMat, oreLayer.mAllowedDimensions); + mMapOreBlockItemToDimName.put(gtppMat, oreLayer.getAllowedDimensions()); } } } 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 5bf55491050..2363b33195b 100644 --- a/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java @@ -227,14 +227,14 @@ 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), + 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", "Milled ", " Ore", true); + MILLED("milled", OrePrefixes.milled, "Milled ", " Ore", true); private final String COMPONENT_NAME; private final String PREFIX; @@ -242,16 +242,6 @@ public enum ComponentTypes { private final boolean HAS_OVERLAY; private final String orePrefix; - ComponentTypes(final String LocalName, final String prefix, final String DisplayName, final boolean overlay) { - this.COMPONENT_NAME = LocalName; - this.orePrefix = LocalName; - this.PREFIX = prefix; - this.DISPLAY_NAME = DisplayName; - this.HAS_OVERLAY = overlay; - // dust + Dirty, Impure, Pure, Refined - // crushed + centrifuged, purified - } - ComponentTypes(final String LocalName, final OrePrefixes orePrefix, final String prefix, final String DisplayName, final boolean overlay) { this.COMPONENT_NAME = LocalName; diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index e7a22197c7f..9adb63def34 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; @@ -17,8 +18,6 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; -import com.google.common.collect.ImmutableList; - import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.StoneType; @@ -96,6 +95,9 @@ public class Material implements IMaterial { 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); } @@ -871,12 +873,7 @@ public int getId() { } @Override - public boolean isValidForStone(IStoneType stoneType) { - return stoneType == StoneType.Stone; - } - - @Override - public ImmutableList getValidStones() { + public List getValidStones() { return StoneType.STONE_ONLY; } @@ -1228,8 +1225,6 @@ public final ItemStack getMilled(final int stacksize) { return getComponentByPrefix(OrePrefixes.milled, stacksize); } - ItemStack rawOre; - public final ItemStack getRawOre(final int stacksize) { if (rawOre == null) { rawOre = getComponentByPrefix(OrePrefixes.rawOre, 1); diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java index 20a8de9b403..ca83852c78d 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java @@ -8,6 +8,7 @@ import codechicken.nei.PositionedStack; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.OrePrefixes.ParsedOreDictName; import gregtech.api.enums.StoneType; import gregtech.api.interfaces.IMaterial; import gregtech.common.ores.IOreAdapter; @@ -75,10 +76,10 @@ public void loadCraftingRecipes(ItemStack stack) { boolean isMatItem = false; - for (var p : OrePrefixes.detectPrefix(stack)) { - if (!PluginGT5VeinStat.PREFIX_WHITELIST.contains(p.left())) continue; + for (ParsedOreDictName oredict : OrePrefixes.detectPrefix(stack)) { + if (!PluginGT5VeinStat.PREFIX_WHITELIST.contains(oredict.prefix)) continue; - mat = IMaterial.findMaterial(p.right()); + mat = IMaterial.findMaterial(oredict.material); if (mat != null) { isMatItem |= loadSmallOre(mat); @@ -95,7 +96,7 @@ public void loadUsageRecipes(ItemStack stack) { String abbr = ItemDimensionDisplay.getDimension(stack); if (abbr == null) return; - SmallOreDimensionWrapper wrapper = GT5OreSmallHelper.SMALL_ORES_BY_DIM.get(abbr); + SmallOreDimensionWrapper wrapper = GT5OreSmallHelper.getSmallOrebyDim(abbr); if (wrapper == null) return; for (OreSmallWrapper oreVein : wrapper.smallOres) { diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index dae82b46051..2f645b193ed 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -13,6 +13,7 @@ import codechicken.nei.PositionedStack; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.OrePrefixes.ParsedOreDictName; import gregtech.api.interfaces.IMaterial; import gregtech.api.util.GTUtility; import gregtech.common.ores.OreManager; @@ -25,7 +26,7 @@ public class PluginGT5VeinStat extends PluginGT5Base { // spotless:off - public static final ImmutableList PREFIX_WHITELIST = ImmutableList.copyOf(new OrePrefixes[] { + public static final List PREFIX_WHITELIST = ImmutableList.of( OrePrefixes.dust, OrePrefixes.dustPure, OrePrefixes.dustImpure, @@ -46,8 +47,8 @@ public class PluginGT5VeinStat extends PluginGT5Base { OrePrefixes.gemFlawed, OrePrefixes.gemFlawless, OrePrefixes.gemExquisite, - OrePrefixes.gem, - }); + OrePrefixes.gem + ); // spotless:on @Override @@ -73,10 +74,10 @@ public void loadCraftingRecipes(ItemStack stack) { boolean isMatItem = false; - for (var p : OrePrefixes.detectPrefix(stack)) { - if (!PREFIX_WHITELIST.contains(p.left())) continue; + for (ParsedOreDictName oredict : OrePrefixes.detectPrefix(stack)) { + if (!PREFIX_WHITELIST.contains(oredict.prefix)) continue; - mat = IMaterial.findMaterial(p.right()); + mat = IMaterial.findMaterial(oredict.material); if (mat != null) { isMatItem |= loadMatchingVeins(mat); @@ -127,7 +128,8 @@ private void addVeinWithLayers(OreLayerWrapper oreVein) { } private Collection getAllVeins() { - return GT5OreLayerHelper.ORE_VEINS_BY_NAME.values(); + return GT5OreLayerHelper.getOreVeinsByName() + .values(); } @Override @@ -145,7 +147,7 @@ public void drawExtras(int recipe) { private OreLayerWrapper getOreLayer(int recipe) { CachedVeinStatRecipe crecipe = (CachedVeinStatRecipe) this.arecipes.get(recipe); - return GT5OreLayerHelper.ORE_VEINS_BY_NAME.get(crecipe.veinName); + return GT5OreLayerHelper.getVeinByName(crecipe.veinName); } private void drawVeinName(OreLayerWrapper oreLayer) { @@ -187,7 +189,7 @@ public String getRecipeName() { } private String[] getDimNameArrayFromVeinName(String veinName) { - OreLayerWrapper oreLayer = GT5OreLayerHelper.ORE_VEINS_BY_NAME.get(veinName); + 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; 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/util/CSVMaker.java b/src/main/java/gtneioreplugin/util/CSVMaker.java index 7184a95fb4d..d215d74d5dd 100644 --- a/src/main/java/gtneioreplugin/util/CSVMaker.java +++ b/src/main/java/gtneioreplugin/util/CSVMaker.java @@ -66,7 +66,8 @@ public void run() { public void runVeins() { try { - Iterator> it = GT5OreLayerHelper.ORE_VEINS_BY_NAME.entrySet() + Iterator> it = GT5OreLayerHelper.getOreVeinsByName() + .entrySet() .iterator(); List OreVeins = new ArrayList<>(); while (it.hasNext()) { diff --git a/src/main/java/gtneioreplugin/util/DimensionHelper.java b/src/main/java/gtneioreplugin/util/DimensionHelper.java index fa99dad3823..c46e48d21c1 100644 --- a/src/main/java/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/gtneioreplugin/util/DimensionHelper.java @@ -169,7 +169,7 @@ private static List computeString(String line) { case "Proteus", "Triton" -> "T6: " + 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; }; diff --git a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java index e13e7ad14f2..5528592b626 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -4,12 +4,15 @@ import java.util.Arrays; 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 com.google.common.collect.ImmutableMap; + import gregtech.api.enums.OreMixes; import gregtech.api.interfaces.IMaterial; import gregtech.api.interfaces.IStoneType; @@ -20,26 +23,48 @@ public class GT5OreLayerHelper { /** {vein ore mix name: wrapper} */ - public static final HashMap ORE_VEINS_BY_NAME = new HashMap<>(); + private static Map ORE_VEINS_BY_NAME; + /** {abbr dim name: wrapper} */ - public static final HashMap ORE_VEINS_BY_DIM = new HashMap<>(); + private static Map ORE_VEINS_BY_DIM; public static void init() { + HashMap byName = new HashMap<>(); + HashMap byDim = new HashMap<>(); + for (OreMixes mix : OreMixes.values()) { OreLayerWrapper wrapper = new OreLayerWrapper(mix.oreMixBuilder); - ORE_VEINS_BY_NAME.put(mix.oreMixBuilder.oreMixName, wrapper); + byName.put(mix.oreMixBuilder.oreMixName, wrapper); for (String dim : wrapper.abbrDimNames) { - NormalOreDimensionWrapper dimensionOres = ORE_VEINS_BY_DIM - .getOrDefault(dim, new NormalOreDimensionWrapper()); + NormalOreDimensionWrapper dimensionOres = byDim.getOrDefault(dim, new NormalOreDimensionWrapper()); dimensionOres.oreVeins.add(wrapper); - ORE_VEINS_BY_DIM.put(dim, dimensionOres); + byDim.put(dim, dimensionOres); } } // Calculate probabilities for each dim. - ORE_VEINS_BY_DIM.values() + byDim.values() .forEach(NormalOreDimensionWrapper::calculateWeights); + + ORE_VEINS_BY_NAME = ImmutableMap.copyOf(byName); + ORE_VEINS_BY_DIM = ImmutableMap.copyOf(byDim); + } + + public static OreLayerWrapper getVeinByName(String name) { + return ORE_VEINS_BY_NAME.get(name); + } + + public static NormalOreDimensionWrapper getVeinByDim(String abbrName) { + return ORE_VEINS_BY_DIM.get(abbrName); + } + + public static Map getOreVeinsByName() { + return ORE_VEINS_BY_NAME; + } + + public static Map getOreVeinsByDim() { + return ORE_VEINS_BY_DIM; } public static class OreLayerWrapper { diff --git a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java index 0720e019ce5..5e6b132937b 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java @@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Multimap; import com.google.common.collect.MultimapBuilder; @@ -30,7 +31,7 @@ public class GT5OreSmallHelper { public static final HashMap ORE_DROP_TO_MAT = new HashMap<>(); public static final HashMap> ORE_MAT_TO_DROPS = new HashMap<>(); /** {abbr dim name: wrapper} */ - public static final HashMap SMALL_ORES_BY_DIM = new HashMap<>(); + private static Map SMALL_ORES_BY_DIM; public static void init() { Map smallOreDefMap = new HashMap<>(); @@ -48,15 +49,15 @@ public static void init() { for (GTWorldgen worldGen : GregTechAPI.sWorldgenList) { if (!(worldGen instanceof WorldgenGTOreSmallPieces smallOreWorldGen)) continue; - IMaterial material = smallOreWorldGen.mMaterial; + IMaterial material = smallOreWorldGen.getMaterial(); OreSmallWrapper wrapper = new OreSmallWrapper(smallOreDefMap.get(smallOreWorldGen.mWorldGenName)); SMALL_ORES_BY_NAME.put(worldGen.mWorldGenName, wrapper); - SMALL_ORES_BY_MAT.put(smallOreWorldGen.mMaterial, wrapper); + SMALL_ORES_BY_MAT.put(smallOreWorldGen.getMaterial(), wrapper); - if (ORE_MAT_TO_DROPS.containsKey(smallOreWorldGen.mMaterial)) { + if (ORE_MAT_TO_DROPS.containsKey(smallOreWorldGen.getMaterial())) { throw new IllegalStateException( - "Duplicate small ore world gen for material " + smallOreWorldGen.mMaterial); + "Duplicate small ore world gen for material " + smallOreWorldGen.getMaterial()); } for (String abbrDimName : wrapper.enabledDims) { @@ -81,21 +82,32 @@ public static void init() { info.release(); + HashMap byDim = new HashMap<>(); + for (String abbrDimName : oreSpawning.keySet()) { - SMALL_ORES_BY_DIM.put(abbrDimName, new SmallOreDimensionWrapper()); + byDim.put(abbrDimName, new SmallOreDimensionWrapper()); } for (var e : oreSpawning.entries()) { - SMALL_ORES_BY_DIM.get(e.getKey()).smallOres.add(e.getValue()); + byDim.get(e.getKey()).smallOres.add(e.getValue()); } - SMALL_ORES_BY_DIM.values() + byDim.values() .forEach(SmallOreDimensionWrapper::calculateWeights); + + SMALL_ORES_BY_DIM = ImmutableMap.copyOf(byDim); + } + + public static Map getSmallOresByDim() { + return SMALL_ORES_BY_DIM; + } + + public static SmallOreDimensionWrapper getSmallOrebyDim(String abbrName) { + return SMALL_ORES_BY_DIM.get(abbrName); } public static class OreSmallWrapper { - public final SmallOreBuilder builder; public final String oreGenName; public final IMaterial material; public final String worldGenHeightRange; @@ -107,7 +119,6 @@ public static class OreSmallWrapper { public final Set enabledDims; public OreSmallWrapper(SmallOreBuilder ore) { - this.builder = ore; this.oreGenName = ore.smallOreName; this.material = ore.ore; this.worldGenHeightRange = ore.minY + "-" + ore.maxY; 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 1c8d8f7c322..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,6 +16,8 @@ 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.ores.OreInfo; @@ -398,13 +400,12 @@ private static boolean setBlock(ItemStack stack, int x, int y, int z, World worl if (info != null) { info.isNatural = true; - var oreBlock = OreManager.getAdapter(info) + ImmutableBlockMeta oreBlock = OreManager.getAdapter(info) .getBlock(info); - world.setBlock(x, y, z, oreBlock.left(), oreBlock.rightInt(), 3); + world.setBlock(x, y, z, oreBlock.getBlock(), oreBlock.getBlockMeta(), 3); - if (world.getBlock(x, y, z) == oreBlock.left() - && world.getBlockMetadata(x, y, z) == oreBlock.rightInt()) return true; + if (oreBlock.matches(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z))) return true; } } diff --git a/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java b/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java index 0ba9ef2a2c1..e4df8d3c90b 100644 --- a/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java +++ b/src/main/java/tectech/recipe/EyeOfHarmonyRecipeStorage.java @@ -27,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; @@ -55,19 +57,16 @@ public class EyeOfHarmonyRecipeStorage { BlockDimensionDisplay blockDimensionDisplay = (BlockDimensionDisplay) ModBlocks.blocks .get(dimAbbreviation); - ModDimensionDef dimensionDef = DimensionDef.DEF_BY_WORLD_NAME - .get(DimensionHelper.getFullName(dimAbbreviation)); + ModDimensionDef dimensionDef = DimensionDef.getDefByName(DimensionHelper.getFullName(dimAbbreviation)); - if (dimensionDef != null && !dimensionDef.hasEoHRecipe) continue; + if (dimensionDef != null && !dimensionDef.hasEoHRecipe()) continue; if (dimAbbreviation.equals("DD")) { specialDeepDarkRecipe(this, blockDimensionDisplay); } else { - GT5OreLayerHelper.NormalOreDimensionWrapper normalOre = GT5OreLayerHelper.ORE_VEINS_BY_DIM - .getOrDefault(dimAbbreviation, null); - GT5OreSmallHelper.SmallOreDimensionWrapper smallOre = GT5OreSmallHelper.SMALL_ORES_BY_DIM - .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. diff --git a/src/main/resources/assets/gtneioreplugin/lang/en_US.lang b/src/main/resources/assets/gtneioreplugin/lang/en_US.lang index 2c511ab337b..936ebbc60ca 100644 --- a/src/main/resources/assets/gtneioreplugin/lang/en_US.lang +++ b/src/main/resources/assets/gtneioreplugin/lang/en_US.lang @@ -77,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 From ce65ac07e333ea60c07c53b6a0743586969d1c5d Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Fri, 10 Jan 2025 15:35:51 -0500 Subject: [PATCH 45/47] rename new classes --- .../bartworks/system/material/Werkstoff.java | 4 +-- .../gtenhancement/PlatinumSludgeOverHaul.java | 4 +-- .../galacticgreg/VoidMinerUtility.java | 8 ++--- .../java/detrav/net/ProspectingPacket.java | 4 +-- .../galacticgreg/WorldGeneratorSpace.java | 6 ++-- .../java/gregtech/api/enums/Materials.java | 4 +-- .../{IMaterial.java => IOreMaterial.java} | 6 ++-- .../java/gregtech/common/OreMixBuilder.java | 12 ++++---- .../java/gregtech/common/SmallOreBuilder.java | 6 ++-- .../gregtech/common/WorldgenGTOreLayer.java | 14 ++++----- .../common/WorldgenGTOreSmallPieces.java | 10 +++---- ...tOld.java => BlockOresAbstractLegacy.java} | 9 ++++-- ...BlockOresOld.java => BlockOresLegacy.java} | 7 +++-- ...BlockOresAbstract.java => GTBlockOre.java} | 6 ++-- .../blocks/{ItemOres.java => GTItemOre.java} | 10 +++---- .../common/blocks/ItemOresLegacy.java | 16 ++++++++++ .../gregtech/common/blocks/ItemOresOld.java | 13 -------- .../items/behaviors/BehaviourProspecting.java | 4 +-- .../gregtech/common/ores/GTOreAdapter.java | 30 +++++++++---------- .../gregtech/common/ores/IOreAdapter.java | 4 +-- .../java/gregtech/common/ores/OreInfo.java | 6 ++-- .../java/gregtech/common/ores/OreManager.java | 16 +++++----- .../common/worldgen/IWorldgenLayer.java | 6 ++-- .../loaders/preload/LoaderGTBlockFluid.java | 4 +-- .../item/base/itemblock/ItemBlockOre.java | 6 ++-- .../gtPlusPlus/core/material/Material.java | 4 +-- .../plugin/gregtech5/PluginGT5Base.java | 6 ++-- .../gregtech5/PluginGT5SmallOreStat.java | 10 +++---- .../plugin/gregtech5/PluginGT5VeinStat.java | 8 ++--- .../util/GT5OreLayerHelper.java | 16 +++++----- .../util/GT5OreSmallHelper.java | 16 +++++----- 31 files changed, 142 insertions(+), 133 deletions(-) rename src/main/java/gregtech/api/interfaces/{IMaterial.java => IOreMaterial.java} (84%) rename src/main/java/gregtech/common/blocks/{BlockOresAbstractOld.java => BlockOresAbstractLegacy.java} (75%) rename src/main/java/gregtech/common/blocks/{BlockOresOld.java => BlockOresLegacy.java} (80%) rename src/main/java/gregtech/common/blocks/{BlockOresAbstract.java => GTBlockOre.java} (98%) rename src/main/java/gregtech/common/blocks/{ItemOres.java => GTItemOre.java} (85%) create mode 100644 src/main/java/gregtech/common/blocks/ItemOresLegacy.java delete mode 100644 src/main/java/gregtech/common/blocks/ItemOresOld.java diff --git a/src/main/java/bartworks/system/material/Werkstoff.java b/src/main/java/bartworks/system/material/Werkstoff.java index cbb52071bb8..2db51bb07c4 100644 --- a/src/main/java/bartworks/system/material/Werkstoff.java +++ b/src/main/java/bartworks/system/material/Werkstoff.java @@ -55,7 +55,7 @@ import gregtech.api.enums.TCAspects; import gregtech.api.enums.TextureSet; import gregtech.api.interfaces.IColorModulationContainer; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneType; import gregtech.api.interfaces.ISubTagContainer; import gregtech.api.util.GTLanguageManager; @@ -64,7 +64,7 @@ import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; import thaumcraft.api.aspects.Aspect; -public class Werkstoff implements IColorModulationContainer, ISubTagContainer, IMaterial { +public class Werkstoff implements IColorModulationContainer, ISubTagContainer, IOreMaterial { public static final LinkedHashSet werkstoffHashSet = new LinkedHashSet<>(); public static final Short2ObjectMap werkstoffHashMap = new Short2ObjectLinkedOpenHashMap<>(); 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/bwcrossmod/galacticgreg/VoidMinerUtility.java b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java index 83ed74b66f6..50039924075 100644 --- a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java +++ b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java @@ -21,7 +21,7 @@ import galacticgreg.api.enums.DimensionDef.DimNames; import gregtech.GTMod; import gregtech.api.enums.Materials; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.util.GTUtility; import gregtech.common.WorldgenGTOreLayer; import gregtech.common.WorldgenGTOreSmallPieces; @@ -55,8 +55,8 @@ public DropMap() { * @param weight the non normalised weight * @param isBWOres true for BW ores, false for GT ores */ - public void addDrop(IMaterial material, float weight) { - try (OreInfo info = OreInfo.getNewInfo()) { + public void addDrop(IOreMaterial material, float weight) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = material; ItemStack stack = OreManager.getStack(info, 1); @@ -181,7 +181,7 @@ public static void addBlockToDimensionList(String dimName, Block block, int meta * @param material the material with an ore version * @param weight the non normalised version of the given weight */ - public static void addMaterialToDimensionList(String dimName, IMaterial material, float 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/detrav/net/ProspectingPacket.java b/src/main/java/detrav/net/ProspectingPacket.java index e8803b26585..d7a96b6d8bf 100644 --- a/src/main/java/detrav/net/ProspectingPacket.java +++ b/src/main/java/detrav/net/ProspectingPacket.java @@ -19,7 +19,7 @@ import detrav.gui.DetravScannerGUI; import detrav.gui.textures.DetravMapTexture; import detrav.utils.FluidColors; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.common.ores.OreManager; import it.unimi.dsi.fastutil.longs.Long2ShortOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap; @@ -151,7 +151,7 @@ public void addBlock(int x, int y, int z, Block block, int meta) { } else { objectId = nextId++; - IMaterial mat = OreManager.getMaterial(block, meta); + IOreMaterial mat = OreManager.getMaterial(block, meta); short[] rgba = mat == null ? new short[] { 125, 125, 125, 255 } : mat.getRGBA(); diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java index 8f81730db39..32053caf8a1 100644 --- a/src/main/java/galacticgreg/WorldGeneratorSpace.java +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -26,7 +26,7 @@ import galacticgreg.dynconfig.DynamicDimensionConfig; import galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; import gregtech.GTMod; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneType; import gregtech.api.objects.MurmurHash; import gregtech.api.objects.XSTR; @@ -449,7 +449,7 @@ private static boolean generateSpecialBlocks(ModDimensionDef dimensionDef, Rando 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) { - IMaterial mat = oreLayer.getOre(control); + IOreMaterial mat = oreLayer.getOre(control); if (mat != null) { return OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, false); @@ -462,7 +462,7 @@ private static boolean generateOreBlock(AsteroidConfig asteroidConfig, Random rn 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) { - IMaterial mat = oreLayer.getOre(control); + IOreMaterial mat = oreLayer.getOre(control); if (mat != null) { return OreManager.setOreForWorldGen(pWorld, pX, pY, pZ, stoneType, mat, true); diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index 847f3d8a7d0..e171243313e 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -29,8 +29,8 @@ import gregtech.api.enums.TCAspects.TC_AspectStack; import gregtech.api.fluid.GTFluidFactory; import gregtech.api.interfaces.IColorModulationContainer; -import gregtech.api.interfaces.IMaterial; 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; @@ -49,7 +49,7 @@ import gregtech.loaders.materials.MaterialsInit1; @SuppressWarnings("unused") // API Legitimately has unused Members and Methods -public class Materials implements IColorModulationContainer, ISubTagContainer, IMaterial { +public class Materials implements IColorModulationContainer, ISubTagContainer, IOreMaterial { public static final List mMaterialHandlers = new ArrayList<>(); private static final Map MATERIALS_MAP = new LinkedHashMap<>(); diff --git a/src/main/java/gregtech/api/interfaces/IMaterial.java b/src/main/java/gregtech/api/interfaces/IOreMaterial.java similarity index 84% rename from src/main/java/gregtech/api/interfaces/IMaterial.java rename to src/main/java/gregtech/api/interfaces/IOreMaterial.java index 1d2f6fa3a90..2966e0ae8c9 100644 --- a/src/main/java/gregtech/api/interfaces/IMaterial.java +++ b/src/main/java/gregtech/api/interfaces/IOreMaterial.java @@ -12,7 +12,7 @@ * 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 IMaterial { +public interface IOreMaterial { String getLocalizedName(); @@ -26,12 +26,12 @@ public interface IMaterial { List getValidStones(); - public static IMaterial findMaterial(String name) { + public static IOreMaterial findMaterial(String name) { Werkstoff bw = Werkstoff.werkstoffVarNameHashMap.get(name); if (bw != null) return bw; - IMaterial gtpp = Material.mMaterialsByName.get(name); + IOreMaterial gtpp = Material.mMaterialsByName.get(name); if (gtpp != null) return gtpp; diff --git a/src/main/java/gregtech/common/OreMixBuilder.java b/src/main/java/gregtech/common/OreMixBuilder.java index cf4f7801ac0..896c0cbb08b 100644 --- a/src/main/java/gregtech/common/OreMixBuilder.java +++ b/src/main/java/gregtech/common/OreMixBuilder.java @@ -7,7 +7,7 @@ import galacticgreg.api.enums.DimensionDef; import gregtech.api.enums.Materials; import gregtech.api.enums.StoneCategory; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneCategory; public class OreMixBuilder { @@ -17,7 +17,7 @@ public class OreMixBuilder { /** {full dim name} */ public Set dimsEnabled = new HashSet<>(); public int minY, maxY, weight, density, size; - public IMaterial 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; @@ -67,7 +67,7 @@ public OreMixBuilder size(int size) { return this; } - public OreMixBuilder primary(IMaterial primary) { + public OreMixBuilder primary(IOreMaterial primary) { this.primary = primary; if (representative == null || localizedName == null) { representative = primary; @@ -76,17 +76,17 @@ public OreMixBuilder primary(IMaterial primary) { return this; } - public OreMixBuilder secondary(IMaterial secondary) { + public OreMixBuilder secondary(IOreMaterial secondary) { this.secondary = secondary; return this; } - public OreMixBuilder inBetween(IMaterial between) { + public OreMixBuilder inBetween(IOreMaterial between) { this.between = between; return this; } - public OreMixBuilder sporadic(IMaterial sporadic) { + public OreMixBuilder sporadic(IOreMaterial sporadic) { this.sporadic = sporadic; return this; } diff --git a/src/main/java/gregtech/common/SmallOreBuilder.java b/src/main/java/gregtech/common/SmallOreBuilder.java index 635b0383761..d990044e6f9 100644 --- a/src/main/java/gregtech/common/SmallOreBuilder.java +++ b/src/main/java/gregtech/common/SmallOreBuilder.java @@ -5,7 +5,7 @@ import java.util.Set; import galacticgreg.api.enums.DimensionDef; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneCategory; public class SmallOreBuilder { @@ -15,7 +15,7 @@ public class SmallOreBuilder { /** {full dimension name} */ public Set dimsEnabled = new HashSet<>(); public int minY, maxY, amount; - public IMaterial ore; + public IOreMaterial ore; public Set stoneCategories; public boolean defaultStoneCategories = true; @@ -54,7 +54,7 @@ public SmallOreBuilder amount(int amount) { return this; } - public SmallOreBuilder ore(IMaterial ore) { + public SmallOreBuilder ore(IOreMaterial ore) { this.ore = ore; return this; } diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 64afbb4af85..37872587afa 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -14,7 +14,7 @@ import gregtech.api.enums.StoneType; import gregtech.api.events.GTEventBus; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneCategory; import gregtech.api.util.GTLog; import gregtech.api.world.GTWorldgen; @@ -30,10 +30,10 @@ public class WorldgenGTOreLayer extends GTWorldgen implements IWorldgenLayer { public final short mWeight; public final short mDensity; public final short mSize; - public final IMaterial mPrimary; - public final IMaterial mSecondary; - public final IMaterial mBetween; - public final IMaterial mSporadic; + public final IOreMaterial mPrimary; + public final IOreMaterial mSecondary; + public final IOreMaterial mBetween; + public final IOreMaterial mSporadic; public final String mRestrictBiome; /** {full dim name} */ private final Set mAllowedDimensions; @@ -97,12 +97,12 @@ public boolean isStoneSpecific() { } @Override - public boolean contains(IMaterial material) { + public boolean contains(IOreMaterial material) { return mPrimary == material || mBetween == material || mSecondary == material || mSporadic == material; } @Override - public IMaterial getOre(float k) { + public IOreMaterial getOre(float k) { if (k < 1.0 / 7.0) { return mSporadic; } diff --git a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java index d8cd79b9dc2..5f06929db62 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java +++ b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java @@ -12,7 +12,7 @@ import net.minecraft.world.chunk.IChunkProvider; import gregtech.api.GregTechAPI; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneCategory; import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; @@ -26,7 +26,7 @@ public class WorldgenGTOreSmallPieces extends GTWorldgen implements IWorldgenLay public final short mMinY; public final short mMaxY; public final short mAmount; - private final IMaterial mMaterial; + private final IOreMaterial mMaterial; public final String mBiome; private final Set mAllowedDimensions; @@ -82,12 +82,12 @@ public boolean isStoneSpecific() { } @Override - public boolean contains(IMaterial material) { + public boolean contains(IOreMaterial material) { return material == mMaterial; } @Override - public IMaterial getOre(float k) { + public IOreMaterial getOre(float k) { return mMaterial; } @@ -105,7 +105,7 @@ public Set getAllowedDimensions() { return mAllowedDimensions; } - public IMaterial getMaterial() { + public IOreMaterial getMaterial() { return mMaterial; } diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java b/src/main/java/gregtech/common/blocks/BlockOresAbstractLegacy.java similarity index 75% rename from src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java rename to src/main/java/gregtech/common/blocks/BlockOresAbstractLegacy.java index 6d1e8c9a58e..975d3f00353 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstractOld.java +++ b/src/main/java/gregtech/common/blocks/BlockOresAbstractLegacy.java @@ -12,11 +12,14 @@ import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.items.GTGenericBlock; -public abstract class BlockOresAbstractOld extends GTGenericBlock implements ITileEntityProvider { +/** + * 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 BlockOresAbstractOld(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta, + protected BlockOresAbstractLegacy(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta, Material aMaterial) { - super(ItemOresOld.class, aUnlocalizedName, aMaterial); + super(ItemOresLegacy.class, aUnlocalizedName, aMaterial); this.isBlockContainer = true; } diff --git a/src/main/java/gregtech/common/blocks/BlockOresOld.java b/src/main/java/gregtech/common/blocks/BlockOresLegacy.java similarity index 80% rename from src/main/java/gregtech/common/blocks/BlockOresOld.java rename to src/main/java/gregtech/common/blocks/BlockOresLegacy.java index 0b7549f02e9..42389e583f0 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresOld.java +++ b/src/main/java/gregtech/common/blocks/BlockOresLegacy.java @@ -5,11 +5,14 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public class BlockOresOld extends BlockOresAbstractOld { +/** + * 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 BlockOresOld() { + public BlockOresLegacy() { super(UNLOCALIZED_NAME, 7, false, Material.rock); } diff --git a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java b/src/main/java/gregtech/common/blocks/GTBlockOre.java similarity index 98% rename from src/main/java/gregtech/common/blocks/BlockOresAbstract.java rename to src/main/java/gregtech/common/blocks/GTBlockOre.java index 3cec2c5a371..21e530f6b45 100644 --- a/src/main/java/gregtech/common/blocks/BlockOresAbstract.java +++ b/src/main/java/gregtech/common/blocks/GTBlockOre.java @@ -44,12 +44,12 @@ import gregtech.common.render.GTRendererBlock; import gregtech.nei.NEIGTConfig; -public class BlockOresAbstract extends GTGenericBlock implements IBlockWithTextures { +public class GTBlockOre extends GTGenericBlock implements IBlockWithTextures { public final List stoneTypes; - public BlockOresAbstract(int series, StoneType[] stoneTypes) { - super(ItemOres.class, "gt.blockores" + series, Material.rock); + public GTBlockOre(int series, StoneType[] stoneTypes) { + super(GTItemOre.class, "gt.blockores" + series, Material.rock); setStepSound(soundTypeStone); setCreativeTab(GregTechAPI.TAB_GREGTECH_ORES); diff --git a/src/main/java/gregtech/common/blocks/ItemOres.java b/src/main/java/gregtech/common/blocks/GTItemOre.java similarity index 85% rename from src/main/java/gregtech/common/blocks/ItemOres.java rename to src/main/java/gregtech/common/blocks/GTItemOre.java index 36ff2e2c647..f3161ded4f6 100644 --- a/src/main/java/gregtech/common/blocks/ItemOres.java +++ b/src/main/java/gregtech/common/blocks/GTItemOre.java @@ -13,17 +13,17 @@ import gregtech.api.GregTechAPI; import gregtech.api.enums.Materials; -public class ItemOres extends ItemBlock { +public class GTItemOre extends ItemBlock { - public final BlockOresAbstract blockOre; + public final GTBlockOre blockOre; - public ItemOres(Block block) { + public GTItemOre(Block block) { super(block); setMaxDamage(0); setHasSubtypes(true); setCreativeTab(GregTechAPI.TAB_GREGTECH_MATERIALS); - blockOre = (BlockOresAbstract) block; + blockOre = (GTBlockOre) block; } @Override @@ -34,7 +34,7 @@ public String getUnlocalizedName(ItemStack stack) { boolean small = blockOre.isSmallOre(metadata); return this.field_150939_a.getUnlocalizedName() + "." - + (matId + (small ? BlockOresAbstract.SMALL_ORE_META_OFFSET : 0)); + + (matId + (small ? GTBlockOre.SMALL_ORE_META_OFFSET : 0)); } @Override 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/ItemOresOld.java b/src/main/java/gregtech/common/blocks/ItemOresOld.java deleted file mode 100644 index 79893c17d26..00000000000 --- a/src/main/java/gregtech/common/blocks/ItemOresOld.java +++ /dev/null @@ -1,13 +0,0 @@ -package gregtech.common.blocks; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemBlock; - -public class ItemOresOld extends ItemBlock { - - public ItemOresOld(Block block) { - super(block); - setMaxDamage(0); - setHasSubtypes(true); - } -} diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java index a04b9034e7b..1466dca3abb 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourProspecting.java @@ -15,7 +15,7 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.SoundResource; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.items.MetaBaseItem; import gregtech.api.items.MetaGeneratedTool; import gregtech.api.objects.ItemData; @@ -63,7 +63,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer int aMeta = aWorld.getBlockMetadata(aX, aY, aZ); - IMaterial mat = OreManager.getMaterial(aBlock, aMeta); + IOreMaterial mat = OreManager.getMaterial(aBlock, aMeta); if (mat != null) { GTUtility.sendChatToPlayer( aPlayer, diff --git a/src/main/java/gregtech/common/ores/GTOreAdapter.java b/src/main/java/gregtech/common/ores/GTOreAdapter.java index c69fe9f11c6..684c1367fd0 100644 --- a/src/main/java/gregtech/common/ores/GTOreAdapter.java +++ b/src/main/java/gregtech/common/ores/GTOreAdapter.java @@ -30,7 +30,7 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.GTUtility.ItemId; import gregtech.common.GTProxy.OreDropSystem; -import gregtech.common.blocks.BlockOresAbstract; +import gregtech.common.blocks.GTBlockOre; public final class GTOreAdapter implements IOreAdapter { @@ -38,13 +38,13 @@ public final class GTOreAdapter implements IOreAdapter { private GTOreAdapter() {} - private final Map oreBlocksByStoneType = new EnumMap<>(StoneType.class); + private final Map oreBlocksByStoneType = new EnumMap<>(StoneType.class); - private BlockOresAbstract[] ores; + private GTBlockOre[] ores; public void init() { // spotless:off - BlockOresAbstract ores1 = new BlockOresAbstract(2, new StoneType[] { + GTBlockOre ores1 = new GTBlockOre(2, new StoneType[] { StoneType.Stone, StoneType.Netherrack, StoneType.Endstone, @@ -54,7 +54,7 @@ public void init() { StoneType.Basalt, StoneType.Moon, }); - BlockOresAbstract ores2 = new BlockOresAbstract(3, new StoneType[] { + GTBlockOre ores2 = new GTBlockOre(3, new StoneType[] { StoneType.Mars, StoneType.Asteroid, StoneType.Phobos, @@ -64,7 +64,7 @@ public void init() { StoneType.Europa, StoneType.Ganymede, }); - BlockOresAbstract ores3 = new BlockOresAbstract(4, new StoneType[] { + GTBlockOre ores3 = new GTBlockOre(4, new StoneType[] { StoneType.Callisto, StoneType.Enceladus, StoneType.Titan, @@ -74,7 +74,7 @@ public void init() { StoneType.Triton, StoneType.Pluto, }); - BlockOresAbstract ores4 = new BlockOresAbstract(5, new StoneType[] { + GTBlockOre ores4 = new GTBlockOre(5, new StoneType[] { StoneType.Callisto, StoneType.Enceladus, StoneType.Titan, @@ -84,7 +84,7 @@ public void init() { StoneType.Triton, StoneType.Pluto, }); - BlockOresAbstract ores5 = new BlockOresAbstract(6, new StoneType[] { + GTBlockOre ores5 = new GTBlockOre(6, new StoneType[] { StoneType.Haumea, StoneType.MakeMake, StoneType.AlphaCentauri, @@ -94,14 +94,14 @@ public void init() { StoneType.BarnardaF, StoneType.Horus, }); - BlockOresAbstract ores6 = new BlockOresAbstract(7, new StoneType[] { + GTBlockOre ores6 = new GTBlockOre(7, new StoneType[] { StoneType.AnubisAndMaahes, StoneType.PackedIce, StoneType.SethIce, StoneType.SethClay, }); - ores = new BlockOresAbstract[] { ores1, ores2, ores3, ores4, ores5, ores6 }; + ores = new GTBlockOre[] { ores1, ores2, ores3, ores4, ores5, ores6 }; StoneType[] legacyStones = { StoneType.Stone, @@ -141,12 +141,12 @@ public void init() { }); } - public void registerOre(StoneType stoneType, BlockOresAbstract oreBlock) { + public void registerOre(StoneType stoneType, GTBlockOre oreBlock) { oreBlocksByStoneType.put(stoneType, oreBlock); } public void hideOres() { - for (BlockOresAbstract ore : ores) { + for (GTBlockOre ore : ores) { API.hideItem(new ItemStack(ore, 1, 0)); } } @@ -178,7 +178,7 @@ public boolean supports(OreInfo info) { @Override public OreInfo getOreInfo(Block block, int meta) { - if (!(block instanceof BlockOresAbstract oreBlock)) return null; + 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"); @@ -217,7 +217,7 @@ public ImmutableBlockMeta getBlock(OreInfo info) { if (!stoneType.isEnabled()) return null; if (stoneType.getCategory() == StoneCategory.Ice && info.isSmall) return null; - BlockOresAbstract oreBlock = oreBlocksByStoneType.get(stoneType); + GTBlockOre oreBlock = oreBlocksByStoneType.get(stoneType); if (oreBlock == null) return null; int stoneIndex = oreBlock.stoneTypes.indexOf(stoneType); @@ -240,7 +240,7 @@ public ArrayList getOreDrops(Random random, OreInfo info2, boolean if (info.stoneType == null) info.stoneType = StoneType.Stone; - BlockOresAbstract oreBlock = oreBlocksByStoneType.get(info.stoneType); + GTBlockOre oreBlock = oreBlocksByStoneType.get(info.stoneType); if (oreBlock == null) return new ArrayList<>(); diff --git a/src/main/java/gregtech/common/ores/IOreAdapter.java b/src/main/java/gregtech/common/ores/IOreAdapter.java index f53d7116a05..2a60482749b 100644 --- a/src/main/java/gregtech/common/ores/IOreAdapter.java +++ b/src/main/java/gregtech/common/ores/IOreAdapter.java @@ -13,9 +13,9 @@ import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; import gregtech.api.enums.StoneType; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; -public interface IOreAdapter { +public interface IOreAdapter { /** * A fast check to see if this adapter can support this block/meta combination. diff --git a/src/main/java/gregtech/common/ores/OreInfo.java b/src/main/java/gregtech/common/ores/OreInfo.java index 00377c0ac6a..7eab5e0dc3a 100644 --- a/src/main/java/gregtech/common/ores/OreInfo.java +++ b/src/main/java/gregtech/common/ores/OreInfo.java @@ -2,10 +2,10 @@ import com.gtnewhorizon.gtnhlib.util.ObjectPooler; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneType; -public class OreInfo implements AutoCloseable { +public class OreInfo implements AutoCloseable { public IOreAdapter cachedAdapter; public TMat material; @@ -16,7 +16,7 @@ public class OreInfo implements AutoCloseable { static final ObjectPooler> ORE_INFO_POOL = new ObjectPooler<>(OreInfo::new); @SuppressWarnings("unchecked") - public static OreInfo getNewInfo() { + public static OreInfo getNewInfo() { synchronized (ORE_INFO_POOL) { return (OreInfo) ORE_INFO_POOL.getInstance(); } diff --git a/src/main/java/gregtech/common/ores/OreManager.java b/src/main/java/gregtech/common/ores/OreManager.java index 9c23482f104..3ffdf6c9b11 100644 --- a/src/main/java/gregtech/common/ores/OreManager.java +++ b/src/main/java/gregtech/common/ores/OreManager.java @@ -17,7 +17,7 @@ import com.gtnewhorizon.gtnhlib.util.data.ImmutableBlockMeta; import gregtech.api.enums.StoneType; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneType; public final class OreManager { @@ -79,7 +79,7 @@ public static IOreAdapter getAdapter(OreInfo info) { } public static boolean setOreForWorldGen(World world, int x, int y, int z, IStoneType defaultStone, - IMaterial material, boolean small) { + 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)); @@ -94,7 +94,7 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone } } - try (OreInfo info = OreInfo.getNewInfo()) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = material; info.stoneType = existingStone; info.isSmall = small; @@ -118,11 +118,11 @@ public static boolean setOreForWorldGen(World world, int x, int y, int z, IStone } } - public static boolean setOre(World world, int x, int y, int z, @Nullable IStoneType stoneType, IMaterial material, - boolean small) { + 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()) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = material; info.stoneType = stoneType; info.isSmall = small; @@ -201,13 +201,13 @@ public static List mineBlock(Random random, World world, int x, int y return oreBlockDrops; } - public static IMaterial getMaterial(ItemStack stack) { + 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 IMaterial getMaterial(Block block, int meta) { + public static IOreMaterial getMaterial(Block block, int meta) { try (OreInfo info = getOreInfo(block, meta)) { return info == null ? null : info.material; } diff --git a/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java b/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java index 3d01e6717b9..8a8efec4d92 100644 --- a/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java +++ b/src/main/java/gregtech/common/worldgen/IWorldgenLayer.java @@ -1,6 +1,6 @@ package gregtech.common.worldgen; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneCategory; /** A worldgen layer that generates ore. */ @@ -29,7 +29,7 @@ public interface IWorldgenLayer { boolean generatesBigOre(); /** Checks if this layer contains this material */ - boolean contains(IMaterial ore); + boolean contains(IOreMaterial ore); /** * Selects an ore for worldgen. @@ -37,7 +37,7 @@ public interface IWorldgenLayer { * @param k The weight, 0-1. * @return The ore. */ - IMaterial getOre(float k); + IOreMaterial getOre(float k); String getName(); } diff --git a/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java b/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java index fef4a3a373a..aac87c6eea6 100644 --- a/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java +++ b/src/main/java/gregtech/loaders/preload/LoaderGTBlockFluid.java @@ -73,7 +73,7 @@ import gregtech.common.blocks.BlockLaser; import gregtech.common.blocks.BlockMachines; import gregtech.common.blocks.BlockMetal; -import gregtech.common.blocks.BlockOresOld; +import gregtech.common.blocks.BlockOresLegacy; import gregtech.common.blocks.BlockReinforced; import gregtech.common.blocks.BlockStones; import gregtech.common.blocks.BlockTintedIndustrialGlass; @@ -549,7 +549,7 @@ public void run() { GregTechAPI.sBlockLongDistancePipes = new BlockLongDistancePipe(); GregTechAPI.sBlockConcretes = new BlockConcretes(); GregTechAPI.sBlockStones = new BlockStones(); - GregTechAPI.sBlockOres1 = new BlockOresOld(); + GregTechAPI.sBlockOres1 = new BlockOresLegacy(); GregTechAPI.sBlockFrames = new BlockFrameBox(); GregTechAPI.sDroneRender = new BlockDrone(); GregTechAPI.sBlockGlass1 = new BlockGlass1(); 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 ef156df1847..0e6a08ec77e 100644 --- a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java @@ -14,7 +14,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.common.WorldgenGTOreLayer; import gtPlusPlus.core.block.base.BlockBaseOre; import gtPlusPlus.core.lib.GTPPCore; @@ -47,9 +47,9 @@ public ItemBlockOre(final Block block) { private static void initVeinInfo() { for (WorldgenGTOreLayer oreLayer : WorldgenGTOreLayer.sList) { - IMaterial[] mats = { oreLayer.mPrimary, oreLayer.mSecondary, oreLayer.mBetween, oreLayer.mSporadic }; + IOreMaterial[] mats = { oreLayer.mPrimary, oreLayer.mSecondary, oreLayer.mBetween, oreLayer.mSporadic }; - for (IMaterial mat : mats) { + for (IOreMaterial mat : mats) { if (mat instanceof Material gtppMat) { mMapOreBlockItemToDimName.put(gtppMat, oreLayer.getAllowedDimensions()); } diff --git a/src/main/java/gtPlusPlus/core/material/Material.java b/src/main/java/gtPlusPlus/core/material/Material.java index 9adb63def34..f0d16f74a30 100644 --- a/src/main/java/gtPlusPlus/core/material/Material.java +++ b/src/main/java/gtPlusPlus/core/material/Material.java @@ -22,7 +22,7 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.StoneType; import gregtech.api.enums.TextureSet; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneType; import gregtech.api.util.GTLanguageManager; import gregtech.api.util.GTUtility; @@ -38,7 +38,7 @@ import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; -public class Material implements IMaterial { +public class Material implements IOreMaterial { public static final Set mMaterialMap = new HashSet<>(); public static HashMap mMaterialCache = new HashMap<>(); diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java index 705bcbd0827..b1b17520f7d 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -4,17 +4,17 @@ import codechicken.lib.gui.GuiDraw; import gregtech.api.enums.Materials; -import gregtech.api.interfaces.IMaterial; +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 { - protected String getGTOreLocalizedName(IMaterial ore, boolean small) { + protected String getGTOreLocalizedName(IOreMaterial ore, boolean small) { if (ore == Materials.DraconiumAwakened) return "Aw. Draconium Ore"; - try (OreInfo info = OreInfo.getNewInfo()) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = ore; info.isSmall = small; diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java index ca83852c78d..3e452c5ef2d 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java @@ -10,7 +10,7 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.OrePrefixes.ParsedOreDictName; import gregtech.api.enums.StoneType; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.common.ores.IOreAdapter; import gregtech.common.ores.OreInfo; import gregtech.common.ores.OreManager; @@ -63,7 +63,7 @@ public void loadCraftingRecipes(String outputId, Object... results) { @Override public void loadCraftingRecipes(ItemStack stack) { - IMaterial mat = OreManager.getMaterial(stack); + IOreMaterial mat = OreManager.getMaterial(stack); if (mat == null) { mat = GT5OreSmallHelper.ORE_DROP_TO_MAT.get(stack.getUnlocalizedName()); @@ -79,7 +79,7 @@ public void loadCraftingRecipes(ItemStack stack) { for (ParsedOreDictName oredict : OrePrefixes.detectPrefix(stack)) { if (!PluginGT5VeinStat.PREFIX_WHITELIST.contains(oredict.prefix)) continue; - mat = IMaterial.findMaterial(oredict.material); + mat = IOreMaterial.findMaterial(oredict.material); if (mat != null) { isMatItem |= loadSmallOre(mat); @@ -104,7 +104,7 @@ public void loadUsageRecipes(ItemStack stack) { } } - private boolean loadSmallOre(IMaterial material) { + private boolean loadSmallOre(IOreMaterial material) { OreSmallWrapper smallOre = GT5OreSmallHelper.SMALL_ORES_BY_MAT.get(material); if (smallOre != null) { @@ -121,7 +121,7 @@ private void addSmallOre(OreSmallWrapper smallOre) { List ores = smallOre.getOreVariants(); List dusts = new ArrayList<>(); - try (OreInfo info = OreInfo.getNewInfo()) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = smallOre.material; info.isSmall = true; diff --git a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index 2f645b193ed..a920fbd2062 100644 --- a/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -14,7 +14,7 @@ import codechicken.nei.PositionedStack; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.OrePrefixes.ParsedOreDictName; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.util.GTUtility; import gregtech.common.ores.OreManager; import gtneioreplugin.plugin.item.ItemDimensionDisplay; @@ -64,7 +64,7 @@ public void loadCraftingRecipes(String outputId, Object... results) { @Override public void loadCraftingRecipes(ItemStack stack) { - IMaterial mat = OreManager.getMaterial(stack); + IOreMaterial mat = OreManager.getMaterial(stack); if (mat != null) { loadMatchingVeins(mat); @@ -77,7 +77,7 @@ public void loadCraftingRecipes(ItemStack stack) { for (ParsedOreDictName oredict : OrePrefixes.detectPrefix(stack)) { if (!PREFIX_WHITELIST.contains(oredict.prefix)) continue; - mat = IMaterial.findMaterial(oredict.material); + mat = IOreMaterial.findMaterial(oredict.material); if (mat != null) { isMatItem |= loadMatchingVeins(mat); @@ -89,7 +89,7 @@ public void loadCraftingRecipes(ItemStack stack) { super.loadCraftingRecipes(stack); } - private boolean loadMatchingVeins(IMaterial ore) { + private boolean loadMatchingVeins(IOreMaterial ore) { boolean foundAny = false; for (OreLayerWrapper oreVein : getAllVeins()) { diff --git a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java index 5528592b626..fcdcd2ab051 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreLayerHelper.java @@ -14,7 +14,7 @@ import com.google.common.collect.ImmutableMap; import gregtech.api.enums.OreMixes; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.interfaces.IStoneType; import gregtech.common.OreMixBuilder; import gregtech.common.ores.OreInfo; @@ -70,17 +70,17 @@ public static Map getOreVeinsByDim() { public static class OreLayerWrapper { public final String veinName, worldGenHeightRange, localizedName; - public final IMaterial[] ores = new IMaterial[4]; + public final IOreMaterial[] ores = new IOreMaterial[4]; public final short randomWeight, size, density; /** {full dim name} */ public final Set allowedDimWithOrigNames; /** {abbr dim name} */ public final Set abbrDimNames; - public final IMaterial mPrimaryVeinMaterial; - public final IMaterial mSecondaryMaterial; - public final IMaterial mBetweenMaterial; - public final IMaterial 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; @@ -117,7 +117,7 @@ public List getVeinLayerOre(int veinLayer) { } public ItemStack getLayerOre(int veinLayer, IStoneType stoneType) { - try (OreInfo info = OreInfo.getNewInfo()) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = ores[veinLayer]; info.stoneType = stoneType; @@ -127,7 +127,7 @@ public ItemStack getLayerOre(int veinLayer, IStoneType stoneType) { } } - public boolean containsOre(IMaterial material) { + 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; diff --git a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java index 5e6b132937b..f3af50d77d0 100644 --- a/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java +++ b/src/main/java/gtneioreplugin/util/GT5OreSmallHelper.java @@ -16,7 +16,7 @@ import gregtech.api.GregTechAPI; import gregtech.api.enums.SmallOres; import gregtech.api.enums.StoneType; -import gregtech.api.interfaces.IMaterial; +import gregtech.api.interfaces.IOreMaterial; import gregtech.api.world.GTWorldgen; import gregtech.common.SmallOreBuilder; import gregtech.common.WorldgenGTOreSmallPieces; @@ -27,9 +27,9 @@ public class GT5OreSmallHelper { 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<>(); + 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; @@ -44,12 +44,12 @@ public static void init() { .arrayListValues() .build(); - OreInfo info = OreInfo.getNewInfo(); + OreInfo info = OreInfo.getNewInfo(); for (GTWorldgen worldGen : GregTechAPI.sWorldgenList) { if (!(worldGen instanceof WorldgenGTOreSmallPieces smallOreWorldGen)) continue; - IMaterial material = smallOreWorldGen.getMaterial(); + IOreMaterial material = smallOreWorldGen.getMaterial(); OreSmallWrapper wrapper = new OreSmallWrapper(smallOreDefMap.get(smallOreWorldGen.mWorldGenName)); SMALL_ORES_BY_NAME.put(worldGen.mWorldGenName, wrapper); @@ -109,7 +109,7 @@ public static SmallOreDimensionWrapper getSmallOrebyDim(String abbrName) { public static class OreSmallWrapper { public final String oreGenName; - public final IMaterial material; + public final IOreMaterial material; public final String worldGenHeightRange; public final short amountPerChunk; @@ -140,7 +140,7 @@ public OreSmallWrapper(SmallOreBuilder ore) { public List getOreVariants() { List oreVariants = new ArrayList<>(); - try (OreInfo info = OreInfo.getNewInfo()) { + try (OreInfo info = OreInfo.getNewInfo()) { info.material = material; info.isSmall = true; From 800ed4b96e5e61e6b8ae2dd72c361ef4d984c8e0 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Fri, 10 Jan 2025 15:51:22 -0500 Subject: [PATCH 46/47] OreInfo header comment --- .../java/gregtech/common/ores/OreInfo.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/ores/OreInfo.java b/src/main/java/gregtech/common/ores/OreInfo.java index 7eab5e0dc3a..0f6b5399409 100644 --- a/src/main/java/gregtech/common/ores/OreInfo.java +++ b/src/main/java/gregtech/common/ores/OreInfo.java @@ -5,12 +5,45 @@ 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 { - public IOreAdapter cachedAdapter; + /** + * 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); From 88fc4c0c524b65eb20cb0f87cca5628d3dafa153 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Fri, 10 Jan 2025 15:57:47 -0500 Subject: [PATCH 47/47] spotless --- src/main/java/bartworks/system/material/BWMetaGeneratedOres.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java index d603588182b..2e940b12456 100644 --- a/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java +++ b/src/main/java/bartworks/system/material/BWMetaGeneratedOres.java @@ -40,7 +40,6 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.render.TextureFactory; import gregtech.api.util.GTLanguageManager; -import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.common.ores.BWOreAdapter; import gregtech.common.ores.OreInfo;