Jump to content

Model Bug with Ores


xTekBlue

Recommended Posts

Bug Demonstration

Spoiler

 

 

Code of Ore

package xtekblue.mod.objects.blocks;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import xtekblue.mod.Main;
import xtekblue.mod.init.BlockInit;
import xtekblue.mod.init.ItemInit;
import xtekblue.mod.objects.blocks.item.ItemBlockVariants;
import xtekblue.mod.util.IHasModel;
import xtekblue.mod.util.handlers.EnumHandler;
import xtekblue.mod.util.handlers.EnumHandler.EnumType;
import xtekblue.mod.util.interfaces.IMetaName;

public class OreBase extends Block implements IHasModel, IMetaName {

	public static final PropertyEnum<EnumHandler.EnumType> VARIANT = PropertyEnum.<EnumHandler.EnumType>create("variant", EnumHandler.EnumType.class);
	
	private String name, dimension;
	
	public OreBase(String name, String dimension) {
		
		super(Material.ROCK);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.xtrablocks);
		setHardness(3);
		setHarvestLevel("pickaxe", 2);
		setResistance(15);
		
		setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, EnumType.RUBY));
		
		this.name = name;
		this.dimension = dimension;
		
		BlockInit.BLOCKS.add(this);
		ItemInit.ITEMS.add(new ItemBlockVariants(this).setRegistryName(this.getRegistryName()));
		
	}
	
	@Override
	public void dropXpOnBlockBreak(World worldIn, BlockPos pos, int amount) {
		super.dropXpOnBlockBreak(worldIn, pos, 10);
	}
	
	@Override
	protected ItemStack getSilkTouchDrop(IBlockState state) {
		return super.getSilkTouchDrop(state);
	}
	
	@Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
		if(getMetaFromState(state) == 0) {
			return ItemInit.RUBY_GEM;
		}else if(getMetaFromState(state) == 1){
			return ItemInit.SAPPHIRE_GEM;
		}else {
			return ItemInit.RUBY_GEM;
		}

    }
	
	@Override
    public int quantityDropped(Random random) {
		return random.nextInt(1) + 1;
	}
	
	@Override
	public int damageDropped(IBlockState state) {
		return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		return this.getDefaultState().withProperty(VARIANT, EnumHandler.EnumType.byMetadata(meta));
	}
	
	/*@Override
	public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
		return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos)));
	}*/
	
	@Override
	public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
		for(EnumHandler.EnumType variant : EnumHandler.EnumType.values()) {
			items.add(new ItemStack(this, 1, variant.getMeta()));
		}
	}
	
	@Override
	protected BlockStateContainer createBlockState() {
		return new BlockStateContainer(this, new IProperty[] {VARIANT});
	}
	
	@Override
	public String getSpecialName(ItemStack stack) {
		return EnumHandler.EnumType.values()[stack.getItemDamage()].getName();
	}
	
	@Override
	public void registerModels() {

		for(int i = 0; i < EnumHandler.EnumType.values().length; i++) {
			Main.proxy.registerVariantRenderer(Item.getItemFromBlock(this), i, "ore_" + this.dimension + "_" + EnumHandler.EnumType.values()[i].getName(), "inventory");
		}
	}

}

 

Code of Gems

package xtekblue.mod.objects.items;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item.ToolMaterial;
import xtekblue.mod.Main;
import xtekblue.mod.init.ItemInit;
import xtekblue.mod.tabs.XtraItemsTab;
import xtekblue.mod.util.IHasModel;

public class ItemBase extends Item implements IHasModel {

	public ItemBase(String name) {
		
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.xtraitems);
		
		ItemInit.ITEMS.add(this);
	}

	@Override
	public void registerModels() {
		
		Main.proxy.registerItemRenderer(this, 0, "inventory");
	}

}

Sapphire Model JSON

{
    "parent": "item/generated",
    "textures": {
        "layer0": "xi:items/sapphire_gem"
    }
}

 

Additional things to say

  • I also do not believe the EXP is dropping either, unless the amount is too low. 

 

Link to comment
Share on other sites

2 hours ago, xTekBlue said:

	@Override
	public int damageDropped(IBlockState state) {
		return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
	}

 

You are returning different items in your getItemDropped method. When your drop a sapphire, you also drop that sapphire with damage 1.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.