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 minecraft.version=1.10.2
forge.version=12.18.1.2079 forge.version=12.18.1.2079
gt.version=5.10.21 gt.version=5.10.21.1
forestry.version=5.2.7.220 forestry.version=5.2.7.220
ic2.version=2.6.99-ex110 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.api.util.GT_Utility;
import gregtech.common.render.RenderGeneratedOres; import gregtech.common.render.RenderGeneratedOres;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockObsidian;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -128,6 +129,38 @@ public class GT_Block_GeneratedOres extends GT_Generic_Block {
sNextId++; 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 @Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
for(int i = 0; i < mMaterials.length; i++) { for(int i = 0; i < mMaterials.length; i++) {
@ -144,17 +177,17 @@ public class GT_Block_GeneratedOres extends GT_Generic_Block {
@Override @Override
public int getHarvestLevel(IBlockState state) { public int getHarvestLevel(IBlockState state) {
return this.mMaterials[state.getValue(METADATA) / 5].mToolQuality; return Math.max(0, getMaterialSafe(state).mToolQuality - 1);
} }
@Override @Override
public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) { public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) {
return 1.0F + getHarvestLevel(blockState); return 1.0F * Math.max(1, getHarvestLevel(blockState));
} }
@Override @Override
public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) { 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 @Override
@ -165,7 +198,7 @@ public class GT_Block_GeneratedOres extends GT_Generic_Block {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public TextureAtlasSprite getParticleSprite(World worldObj, BlockPos aPos, EnumFacing side) { 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 @Override
@ -176,8 +209,8 @@ public class GT_Block_GeneratedOres extends GT_Generic_Block {
rList.add(new ItemStack(this, 1, aMetaData)); rList.add(new ItemStack(this, 1, aMetaData));
return rList; return rList;
} }
Materials aMaterial = mMaterials[aMetaData / MATERIALS_META_OFFSET]; Materials aMaterial = getMaterialSafe(state);
Materials aBaseMaterial = StoneTypes.mTypes[aMetaData % MATERIALS_META_OFFSET].stoneMaterial; Materials aBaseMaterial = getStoneTypeSafe(state).stoneMaterial;
if (aMaterial != null) { if (aMaterial != null) {
Random tRandom = new Random(pos.hashCode()); Random tRandom = new Random(pos.hashCode());
ArrayList<ItemStack> tSelector = new ArrayList<>(); ArrayList<ItemStack> tSelector = new ArrayList<>();

View file

@ -19,7 +19,7 @@ public class GT_Item_GeneratedOres extends ItemBlock {
@Override @Override
public int getMetadata(int damage) { 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(); double z = pos.getZ();
GT_Block_GeneratedOres aOres = (GT_Block_GeneratedOres) state.getBlock(); GT_Block_GeneratedOres aOres = (GT_Block_GeneratedOres) state.getBlock();
int meta = state.getValue(GT_Generic_Block.METADATA); Materials mats = aOres.getMaterialSafe(state);
Materials mats = aOres.mMaterials[meta / GT_Block_GeneratedOres.MATERIALS_META_OFFSET];
boolean small = aOres.mSmall; boolean small = aOres.mSmall;
int lightmap; int lightmap;
int color = ITexture.color(mats.mRGBa, false); 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(); TextureAtlasSprite sprite2 = mats.mIconSet.mTextures[small ? TextureSet.INDEX_oreSmall : TextureSet.INDEX_ore].getIcon();
if(state.shouldSideBeRendered(world, pos, EnumFacing.UP)) { if(state.shouldSideBeRendered(world, pos, EnumFacing.UP)) {
@ -232,12 +230,11 @@ public class RenderBlocks implements ICCBlockRenderer {
VertexBuffer buf = tes.getBuffer(); VertexBuffer buf = tes.getBuffer();
GT_Block_GeneratedOres aOres = (GT_Block_GeneratedOres) ((ItemBlock) stack.getItem()).block; GT_Block_GeneratedOres aOres = (GT_Block_GeneratedOres) ((ItemBlock) stack.getItem()).block;
int meta = stack.getItem().getMetadata(stack); Materials mats = aOres.getMaterialSafe(stack);
Materials mats = aOres.mMaterials[meta / GT_Block_GeneratedOres.MATERIALS_META_OFFSET];
boolean small = aOres.mSmall; boolean small = aOres.mSmall;
int color = ITexture.color(mats.mRGBa, false); 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(); TextureAtlasSprite sprite2 = mats.mIconSet.mTextures[small ? TextureSet.INDEX_oreSmall : TextureSet.INDEX_ore].getIcon();
buf.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM); buf.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);