Jump to content

Recommended Posts

Posted

I'm trying to migrate from  1.10.2 to 1.12.2

I followed a tutorial and have simple blocks and items working,  when it comes to blocks with multiple states, no luck.   My block has getSubBlocks as

	  @SideOnly(Side.CLIENT)
	  public void getSubBlocks(CreativeTabs whichTab, NonNullList<ItemStack> items)
	  {
		  items.add(new ItemStack(this, 1, 0));
	      items.add(new ItemStack(this, 1, 4));
	      items.add(new ItemStack(this, 1, 8));
	      items.add(new ItemStack(this, 1, 12));
	      
	   }

 

My client proxy has

	   public void registerItemRenderer(Item item, int meta, String id) {
		   ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(),id));
	   }

 

 

 

and i get 4 blocks in the inventory, all with no textures and all with meta =  0.  I have tried searching the net, but all i can find pertains to simple blocks.  any help would be appreciated

Posted (edited)

Just because you said "this item with this meta exists" does not mean that your block actually has different states.

 

If you really, really wanted to, you could give yourself minecraft:grass with metadata 4. Its not any different than with metadata 0.

 

You need to...

 - override createBlockState

 - override getStateFromMeta

 - override getMetaFromState

 - call setDefaultState in the block's constructor

 - use a subclass of ItemBlock that overrides getMetadata (vanilla does provide some implementations, they may or may not work for your purposes)

 - register that ItemBlock subclass with your block's registry name instead of using new ItemBlock()

Edited by Draco18s

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.

Posted

I really stink at explaining.

 

here is  the base class

package com.steveT.yabm.objects.blocks;

import java.util.List;

import com.steveT.yabm.Main;
import com.steveT.yabm.init.YobBlockInit;
import com.steveT.yabm.init.YobItemInit;
import com.steveT.yabm.util.IHasModel;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemMultiTexture;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;

public class YobBlock extends Block implements IHasModel{


	public YobBlock(String name, Material material,CreativeTabs tab) {
		this(name, material,tab,true);

	}

	public YobBlock(String name, Material material,CreativeTabs tab, Boolean createItem) {
		super(material);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(tab);	
		
		YobBlockInit.BLOCKS.add(this);
		if(createItem)
			YobItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
	}

	@Override
	public void registerModels() {
		//System.out.println("--------------------------------------- YobBlock (blockbase)");
		Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}

	public String[] getSubTypes() {
		return null;
	}

	public void getSubBlocks(ItemMultiTexture item, CreativeTabs tudortab, List<ItemStack> list) {
		// TODO Auto-generated method stub
		
	}


}

 

child of YobBlock

package com.steveT.yabm.blocks;

import java.util.List;

import com.google.common.collect.Lists;
import com.steveT.yabm.objects.blocks.YobBlock;
import com.steveT.yabm.util.YbFacingHelper;
import com.steveT.yabm.util.YbStyleEnumHandler_4;
import com.steveT.yabm.util.YbUtility;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
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.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;



public abstract class YobBlockHFSCB extends YobBlock implements YbFacingHelper,YbUtility{

	public YobBlockHFSCB(String registryName, Material material, CreativeTabs tab) {
		super(registryName,material,tab);
	}
	
	public YobBlockHFSCB(String registryName, Material material, CreativeTabs tab, Boolean createItem) {
		super(registryName,material,tab,createItem);
	}

	public static final PropertyDirection FACING = BlockHorizontal.FACING;
	public static final PropertyEnum<YbStyleEnumHandler_4.EnumType> STYLE = PropertyEnum.<YbStyleEnumHandler_4.EnumType>create("style", YbStyleEnumHandler_4.EnumType.class);

	@Override
	protected BlockStateContainer createBlockState(){
    	return new BlockStateContainer(this, new IProperty[] {FACING,STYLE});
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta)
	{   IBlockState bs = this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta & 3)).withProperty(STYLE,YbStyleEnumHandler_4.EnumType.byMetadata((meta & 15) >> 2));
		return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta & 3)).withProperty(STYLE,YbStyleEnumHandler_4.EnumType.byMetadata((meta & 15) >> 2));
	}

	@Override
	public int getMetaFromState(IBlockState state)
	{
		int i = 0;
		i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
		i = i | (int)state.getValue(STYLE).getMeta() <<2;
		return i;
	}  
	
    
	/**
     * returns a list of blocks with the same ID, but different meta 
     */

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
    {
    	// item , amount, meta
        list.add(new ItemStack(itemIn,1,2));
        list.add(new ItemStack(itemIn, 1, 6));
        list.add(new ItemStack(itemIn, 1, 10));
        list.add(new ItemStack(itemIn, 1, 14));
    }
	
    /**
     * Adds 4 Styles to inventory with extension of s0 ...
     */

    public String[] getSubTypes(){
    	return new String[] {"s0", "s1", "s2", "s3"};
    }

    /**
     * when choosing block from the map, sets the correct meta 
     * to match inventory
     */

    @Override
    public int damageDropped(IBlockState state)
    {
    	// metadata: (s0)0-3, (s1)4-7,(s2)8-11,(s3) 12-15
     	int r = 2 ;
    
    	int meta = getMetaFromState(state);

    	switch(meta/4) {
    		case 1:
    			r = 6;
    			break;
    		case 2:
    			r = 10;
    			break;
    		case 3:
    			r = 14;
    	}
      	return r;
    }
    

    public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes,  Entity entityIn)
    {
    	for( AxisAlignedBB aabb: getCollisionBoxList(state)){
        	addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);	
    	}
    }

    /**
     * If you don't override is child class, collision box is a full block
     */
	protected List<AxisAlignedBB> getCollisionBoxList(IBlockState state) {
		List<AxisAlignedBB> list = Lists.<AxisAlignedBB>newArrayList();
		 list.add(new AxisAlignedBB	(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D));
		return list;
	}
	
 	@Override
    public RayTraceResult collisionRayTrace(IBlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end)
    {
        List<RayTraceResult> list = Lists.<RayTraceResult>newArrayList();

        if(blockState == null) {
        	System.out.println("Block State Error!");
        }
        
        for (AxisAlignedBB axisalignedbb : getCollisionBoxList(blockState))
        {
            list.add(this.rayTrace(pos, start, end, axisalignedbb));
        }

        RayTraceResult raytraceresult1 = null;
        double d1 = 0.0D;

        for (RayTraceResult raytraceresult : list)
        {
            if (raytraceresult != null)
            {
                double d0 = raytraceresult.hitVec.squareDistanceTo(end);

                if (d0 > d1)
                {
                    raytraceresult1 = raytraceresult;
                    d1 = d0;
                }
            }
        }
        return raytraceresult1;
    } 
}

 

here is the class i create int BlockInit()

package com.steveT.yabm.blocks;

import java.util.List;

import com.google.common.collect.Lists;
import com.steveT.yabm.Main;
import com.steveT.yabm.objects.blocks.YobBlock;
import com.steveT.yabm.util.YbConstants;
import com.steveT.yabm.util.YbStyleEnumHandler_4;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class YobBlockMultiBlockWF extends YobBlockHFSCB implements YbConstants{
	
	
	public final static AxisAlignedBB AABB = new AxisAlignedBB		( CU0, CU0,CU0		, CU16, CU16, CU16);
	
	public YobBlockMultiBlockWF(String registryNameBase, Material material, CreativeTabs tab, int numBlocks){
		super(registryNameBase+"0", material,tab);
		
		this.setDefaultState(this.blockState.getBaseState().withProperty(FACING,EnumFacing.NORTH).withProperty(STYLE,YbStyleEnumHandler_4.EnumType.S1 ));
		
		//yobBlockRegisterWFS(this);
		
		for(int i = 1 ; i <= numBlocks ; i++) {
			//new YobBlockMultiBlockWF(registryNameBase+i, material, tab);
		}
	}
	
	public YobBlockMultiBlockWF(String registryName, Material material, CreativeTabs tab){
		super(registryName,material,tab);
		//yobBlockRegisterWFS(this);
	}

	protected List<AxisAlignedBB> getCollisionBoxList(IBlockState state) {
		List<AxisAlignedBB> list = Lists.<AxisAlignedBB>newArrayList();
		list.add(AABB);
		return list;
	}
	
	@Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack){
    	YbStyleEnumHandler_4.EnumType bs = state.getValue(STYLE);
    	
    	EnumFacing playerFacing = getPlayerFacing(pos, placer);
    	
    	if(playerFacing == EnumFacing.DOWN || playerFacing == EnumFacing.UP){
    		world.setBlockToAir(pos);
            return;
    	}
    	
    	world.setBlockState(pos, state.withProperty(FACING, getFacingFromEntity(pos, placer)).withProperty(STYLE,bs), 2);
    }
    
	
	 @Override
	  @SideOnly(Side.CLIENT)
	  public void getSubBlocks(CreativeTabs whichTab, NonNullList<ItemStack> items)
	  {
		  items.add(new ItemStack(this, 1, 0));
	      items.add(new ItemStack(this, 1, 4));
	      items.add(new ItemStack(this, 1, 8));
	      items.add(new ItemStack(this, 1, 12));
	      
	   }
	
	 
		@Override
		public void registerModels() {

			Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
		}
}

 

I know the blocks/items  in the inventory are meta 0  because the block when placed is the blank texture state of the block.

 

thank you for helping

Posted
8 minutes ago, blinky000 said:

public abstract class YobBlockHFSCB extends YobBlock implements YbFacingHelper,YbUtility

Alphabet Soup much?

 

And as far as I can tell, you still haven't done this:

4 hours ago, Draco18s said:

 

 - register that ItemBlock subclass with your block's registry name instead of using new ItemBlock()

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.

Posted

HFSCB:  HasFacingStyleCollisionBox .

 

YobBlock creates the the itemBlock and sets the registryName  (in this case "yabm:yb_tudor_set_0")

YobItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));

 

Posted

wouldn't the the registerItemRenderer be differnt for multiple states?

 

clientProxy

ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(),id));

 

Posted
5 hours ago, Draco18s said:

 - use a subclass of ItemBlock that overrides getMetadata (vanilla does provide some implementations, they may or may not work for your purposes)

 - register that ItemBlock subclass with your block's registry name instead of using new ItemBlock()

You are not doing this.

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.

Posted

overiding the GetMetaData() still returns just one state.

 

the results i am hoping for  is ;  4 entries in in the inventory with the states from the sub_blocks (metas : 0 4, 8 ,12)

 

again  thank you for you help

Posted

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.

Posted
1 hour ago, blinky000 said:

ok, that worked half way.   In inventory i have the four blocks based on sub blocks,  and they work when placed, but i get no textures in the inventory

You still need to register their models with the ModelLoader

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.

Posted

so every state has to be registered with the ModleLoader.  when i place the blocks they have texture, dosn't that mean they have been registered?    since it's the inventory missing the textures wouldn't be i need to register the items.   for the blockstates i show?

Posted
1 minute ago, blinky000 said:

so every state has to be registered with the ModleLoader.  when i place the blocks they have texture, dosn't that mean they have been registered?    since it's the inventory missing the textures wouldn't be i need to register the items.   for the blockstates i show?

No, it does not. Because item models aren't block models. They are registered separately.

You want your item variants to have textures? Register your item variants to have textures.

 

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L100-L103

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.

Posted (edited)

Ah Ha !

So for the block with the multiple states  ,  besides registering the block, I also  registers the states i want in the inventory ;

 

            Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "facing=north,style=s0");
            Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 4, "facing=north,style=s1");
            Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 8, "facing=north,style=s2");
            Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 12, "facing=north,style=s3");

 

Actually much easier then ver. 1.10  once i got the kinks out :)

 

Thanks for all your help

Edited by blinky000
Posted
1 hour ago, blinky000 said:

Ah Ha !

So for the block with the multiple states  ,  besides registering the block, I also  registers the states i want in the inventory

Correct.

And this is why I have my registry code done up the way I have.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L64-L71

I search for all valid states of the block (note that this method is not good for things like leaves which have states that don't appear in the inventory) and register an item model for each.

  • Like 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.

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.

Announcements



×
×
  • Create New...

Important Information

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