From 5c4e60ee72293214c70548d5fff9f4d19f9ebbec Mon Sep 17 00:00:00 2001 From: Dragon2488 Date: Sun, 18 Dec 2016 02:28:34 +0700 Subject: [PATCH] Fixed Crash with generation of GT ores. --- build.properties | 2 +- .../common/blocks/GT_Block_GeneratedOres.java | 45 ++++++++++++++++--- .../common/blocks/GT_Item_GeneratedOres.java | 2 +- .../gregtech/common/render/RenderBlocks.java | 11 ++--- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/build.properties b/build.properties index 0a4c6c2f..13faa37c 100644 --- a/build.properties +++ b/build.properties @@ -1,7 +1,7 @@ minecraft.version=1.10.2 forge.version=12.18.1.2079 -gt.version=5.10.21 +gt.version=5.10.21.1 forestry.version=5.2.7.220 ic2.version=2.6.99-ex110 diff --git a/src/main/java/gregtech/common/blocks/GT_Block_GeneratedOres.java b/src/main/java/gregtech/common/blocks/GT_Block_GeneratedOres.java index cef32f1d..c2f49bf2 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_GeneratedOres.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_GeneratedOres.java @@ -10,6 +10,7 @@ import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; import gregtech.common.render.RenderGeneratedOres; import net.minecraft.block.Block; +import net.minecraft.block.BlockObsidian; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -128,6 +129,38 @@ public class GT_Block_GeneratedOres extends GT_Generic_Block { sNextId++; } + public Materials getMaterialSafe(IBlockState state) { + int index = state.getValue(METADATA) / MATERIALS_META_OFFSET; + if(mMaterials.length > index) { + return mMaterials[index]; + } + return Materials.Air; + } + + public StoneTypes getStoneTypeSafe(IBlockState state) { + int index = state.getValue(METADATA) % MATERIALS_META_OFFSET; + if(StoneTypes.mTypes.length > index) { + return StoneTypes.mTypes[index]; + } + return StoneTypes.STONE; + } + + public Materials getMaterialSafe(ItemStack state) { + int index = state.getMetadata() / MATERIALS_META_OFFSET; + if(mMaterials.length > index) { + return mMaterials[index]; + } + return Materials.Air; + } + + public StoneTypes getStoneTypeSafe(ItemStack state) { + int index = state.getMetadata() % MATERIALS_META_OFFSET; + if(StoneTypes.mTypes.length > index) { + return StoneTypes.mTypes[index]; + } + return StoneTypes.STONE; + } + @Override public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { for(int i = 0; i < mMaterials.length; i++) { @@ -144,17 +177,17 @@ public class GT_Block_GeneratedOres extends GT_Generic_Block { @Override public int getHarvestLevel(IBlockState state) { - return this.mMaterials[state.getValue(METADATA) / 5].mToolQuality; + return Math.max(0, getMaterialSafe(state).mToolQuality - 1); } @Override public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) { - return 1.0F + getHarvestLevel(blockState); + return 1.0F * Math.max(1, getHarvestLevel(blockState)); } @Override public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) { - return 1.0F + getHarvestLevel(world.getBlockState(pos)); + return 1.0F * Math.max(1, getHarvestLevel(world.getBlockState(pos))); } @Override @@ -165,7 +198,7 @@ public class GT_Block_GeneratedOres extends GT_Generic_Block { @Override @SideOnly(Side.CLIENT) public TextureAtlasSprite getParticleSprite(World worldObj, BlockPos aPos, EnumFacing side) { - return StoneTypes.mTypes[worldObj.getBlockState(aPos).getValue(METADATA) % MATERIALS_META_OFFSET].mIconContainer.getIcon(); + return getStoneTypeSafe(worldObj.getBlockState(aPos)).mIconContainer.getIcon(); } @Override @@ -176,8 +209,8 @@ public class GT_Block_GeneratedOres extends GT_Generic_Block { rList.add(new ItemStack(this, 1, aMetaData)); return rList; } - Materials aMaterial = mMaterials[aMetaData / MATERIALS_META_OFFSET]; - Materials aBaseMaterial = StoneTypes.mTypes[aMetaData % MATERIALS_META_OFFSET].stoneMaterial; + Materials aMaterial = getMaterialSafe(state); + Materials aBaseMaterial = getStoneTypeSafe(state).stoneMaterial; if (aMaterial != null) { Random tRandom = new Random(pos.hashCode()); ArrayList tSelector = new ArrayList<>(); diff --git a/src/main/java/gregtech/common/blocks/GT_Item_GeneratedOres.java b/src/main/java/gregtech/common/blocks/GT_Item_GeneratedOres.java index df7f4ee3..17e6e554 100644 --- a/src/main/java/gregtech/common/blocks/GT_Item_GeneratedOres.java +++ b/src/main/java/gregtech/common/blocks/GT_Item_GeneratedOres.java @@ -19,7 +19,7 @@ public class GT_Item_GeneratedOres extends ItemBlock { @Override public int getMetadata(int damage) { - return damage; + return Math.max(0, Math.min(16, damage)); //checks to prevent outofbounds } } diff --git a/src/main/java/gregtech/common/render/RenderBlocks.java b/src/main/java/gregtech/common/render/RenderBlocks.java index c80d8d41..de64cd3b 100644 --- a/src/main/java/gregtech/common/render/RenderBlocks.java +++ b/src/main/java/gregtech/common/render/RenderBlocks.java @@ -125,14 +125,12 @@ public class RenderBlocks implements ICCBlockRenderer { double z = pos.getZ(); GT_Block_GeneratedOres aOres = (GT_Block_GeneratedOres) state.getBlock(); - int meta = state.getValue(GT_Generic_Block.METADATA); - Materials mats = aOres.mMaterials[meta / GT_Block_GeneratedOres.MATERIALS_META_OFFSET]; + Materials mats = aOres.getMaterialSafe(state); boolean small = aOres.mSmall; - int lightmap; int color = ITexture.color(mats.mRGBa, false); - TextureAtlasSprite sprite1 = StoneTypes.mTypes[meta % GT_Block_GeneratedOres.MATERIALS_META_OFFSET].mIconContainer.getIcon(); + TextureAtlasSprite sprite1 = aOres.getStoneTypeSafe(state).mIconContainer.getIcon(); TextureAtlasSprite sprite2 = mats.mIconSet.mTextures[small ? TextureSet.INDEX_oreSmall : TextureSet.INDEX_ore].getIcon(); if(state.shouldSideBeRendered(world, pos, EnumFacing.UP)) { @@ -232,12 +230,11 @@ public class RenderBlocks implements ICCBlockRenderer { VertexBuffer buf = tes.getBuffer(); GT_Block_GeneratedOres aOres = (GT_Block_GeneratedOres) ((ItemBlock) stack.getItem()).block; - int meta = stack.getItem().getMetadata(stack); - Materials mats = aOres.mMaterials[meta / GT_Block_GeneratedOres.MATERIALS_META_OFFSET]; + Materials mats = aOres.getMaterialSafe(stack); boolean small = aOres.mSmall; int color = ITexture.color(mats.mRGBa, false); - TextureAtlasSprite sprite1 = StoneTypes.mTypes[meta % GT_Block_GeneratedOres.MATERIALS_META_OFFSET].mIconContainer.getIcon(); + TextureAtlasSprite sprite1 = aOres.getStoneTypeSafe(stack).mIconContainer.getIcon(); TextureAtlasSprite sprite2 = mats.mIconSet.mTextures[small ? TextureSet.INDEX_oreSmall : TextureSet.INDEX_ore].getIcon(); buf.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);