Fixed Crash with generation of GT ores.

This commit is contained in:
Dragon2488 2016-12-18 02:28:34 +07:00
parent db28da12e2
commit 5c4e60ee72
4 changed files with 45 additions and 15 deletions

View file

@ -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

View file

@ -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<ItemStack> 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<ItemStack> tSelector = new ArrayList<>();

View file

@ -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
}
}

View file

@ -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);