Jump to content

Recommended Posts

Posted

Hello,

 

So I'm having an issue with my itemblock not registering a texture.

The console does not output any missing resourcelocation so I'm guessing its somewhere in my code, but I had no luck in finding it.

 

Here is my ItemUtil class:

package com.lambda.plentifulmisc.util;

/**
* Created by Blake on 11/22/2016.
*/

import com.lambda.plentifulmisc.PlentifulMisc;
import com.lambda.plentifulmisc.blocks.base.ItemBlockBase;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameRegistry;

import java.util.*;


public final class ItemUtil{

    public static Item getItemFromName(String name){
        ResourceLocation resLoc = new ResourceLocation(name);
        if(Item.REGISTRY.containsKey(resLoc)){
            return Item.REGISTRY.getObject(resLoc);
        }
        return null;
    }

    public static void registerBlock(Block block, ItemBlockBase itemBlock, String name, boolean addTab){
        block.setUnlocalizedName(ModUtil.MOD_ID+"."+name);

        block.setRegistryName(ModUtil.MOD_ID, name);
        GameRegistry.register(block);

        itemBlock.setRegistryName(block.getRegistryName());
        GameRegistry.register(itemBlock);

        block.setCreativeTab(addTab ? PlentifulMisc.instance.CREATIVE_TAB : null);

    }

    public static void registerItem(Item item, String name, boolean addTab){
        item.setUnlocalizedName(ModUtil.MOD_ID+"."+name);

        item.setRegistryName(ModUtil.MOD_ID, name);
        GameRegistry.register(item);

        item.setCreativeTab(addTab ? PlentifulMisc.instance.CREATIVE_TAB : null);

    }


}

 

Here is my BlockBase:

package com.lambda.plentifulmisc.blocks.base;

import com.lambda.plentifulmisc.PlentifulMisc;
import com.lambda.plentifulmisc.util.ItemUtil;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;


/**
* Created by Blake on 11/22/2016.
*/
public class BlockBase extends Block{

    private final String name;

    public BlockBase(Material material, String name){
        super(material);
        this.name = name;

        this.register();
    }

    private void register(){
        ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());

        this.registerRendering();
    }

    protected String getBaseName(){
        return this.name;
    }

    protected ItemBlockBase getItemBlock(){
        return new ItemBlockBase(this);
    }

    public boolean shouldAddCreative(){
        return true;
    }

    protected void registerRendering(){
        PlentifulMisc.proxy.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
    }
}

 

Here is my Block Class

 

package com.lambda.plentifulmisc.blocks;

import com.lambda.plentifulmisc.blocks.base.BlockBase;
import com.lambda.plentifulmisc.blocks.base.ItemBlockBase;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;

/**
* Created by Blake on 11/22/2016.
*/
public class BlockCeleistrum extends BlockBase{

    BlockCeleistrum(String name) {
        super(Material.ROCK, name);
        this.setHarvestLevel("pickaxe", 0);
        this.setHardness(2.5F);
        this.setResistance(10.0F);
        this.setSoundType(SoundType.STONE);
    }

}

 

Lastly, my BlockInit:

package com.lambda.plentifulmisc.blocks;

import com.lambda.plentifulmisc.util.ModUtil;
import net.minecraft.block.Block;

/**
* Created by Blake on 11/22/2016.
*/
public class InitBlocks {

    public static Block blockCeleistrum;

    public static void init() {
        ModUtil.LOGGER.info("Initializing Blocks...");
        blockCeleistrum = new BlockCeleistrum("block_celestrium");
    }
}

 

Thanks!

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

Client Proxy:

package com.lambda.plentifulmisc.proxy;

import com.lambda.plentifulmisc.util.ModUtil;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import java.util.*;



/**
* Created by Blake on 11/22/2016.
*/
public class ClientProxy implements IProxy
{
    private static final Map<ItemStack, ModelResourceLocation> MODEL_LOCATIONS_FOR_REGISTERING = new HashMap<ItemStack, ModelResourceLocation>();


    @Override
    public void preInit(FMLPreInitializationEvent event) {
        ModUtil.LOGGER.info("PreInitializing ClientProxy...");

        for(Map.Entry<ItemStack, ModelResourceLocation> entry : MODEL_LOCATIONS_FOR_REGISTERING.entrySet()){
            ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(), entry.getValue());
        }
    }

    @Override
    public void init(FMLInitializationEvent event) {

    }

    @Override
    public void postInit(FMLPostInitializationEvent event) {

    }

    @Override
    public void addRenderRegister(ItemStack stack, ResourceLocation location, String variant) {
        MODEL_LOCATIONS_FOR_REGISTERING.put(stack, new ModelResourceLocation(location, variant));
    }
}

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

Hi

 

So I'm having an issue with my itemblock not registering a texture.

The console does not output any missing resourcelocation so I'm guessing its somewhere in my code, but I had no luck in finding it.

when you say "not registering" I guess you mean that you get a purple-and-black chequered cube when you're holding the block, and when it's in the inventory?

Does your itemblock look correct when it's placed in the world?

 

My first comment is- I think your registration code is making your life difficult with the method calls and assembling the name strings from pieces - hard to spot things being missed or called out of order or names being wrong.

 

I'd suggest you put the registration code directly into preInit and Init and use literal strings for the names, etc, and once that is working, move it back out /change it back one piece at a time till you figure out the problem.

 

eg in your mod preInit:

  {
    // each instance of your block should have two names:
    // 1) a registry name that is used to uniquely identify this block.  Should be unique within your mod.  use lower case.
    // 2) an 'unlocalised name' that is used to retrieve the text name of your block in the player's language.  For example-
    //    the unlocalised name might be "water", which is printed on the user's screen as "Wasser" in German or
    //    "aqua" in Italian.
    //
    //    Multiple blocks can have the same unlocalised name - for example
    //  +----RegistryName----+---UnlocalisedName----+
    //  |  flowing_water     +       water          |
    //  |  stationary_water  +       water          |
    //  +--------------------+----------------------+
    //
    blockSimple = (BlockSimple)(new BlockSimple().setUnlocalizedName("mbe01_block_simple_unlocalised_name"));
    blockSimple.setRegistryName("mbe01_block_simple_registry_name");
    GameRegistry.register(blockSimple);

    // We also need to create and register an ItemBlock for this block otherwise it won't appear in the inventory
    itemBlockSimple = new ItemBlock(blockSimple);
    itemBlockSimple.setRegistryName(blockSimple.getRegistryName());
    GameRegistry.register(itemBlockSimple);
  }

and then in your client preinit, which must be called after common preinit,

    ModelResourceLocation itemModelResourceLocation = new ModelResourceLocation("minecraftbyexample:mbe01_block_simple", "inventory");
    final int DEFAULT_ITEM_SUBTYPE = 0;
    ModelLoader.setCustomModelResourceLocation(StartupCommon.itemBlockSimple, DEFAULT_ITEM_SUBTYPE, itemModelResourceLocation);

 

-TGG

Posted

Okay, tried something a bit more basic, removed the hashmap( I dont really know why I did that in the first place  :P ), now:

- Block & Item(not ItemBlock) textures are registering

- ItemBlock still 'unregistered' (default texture)

 

Here is the updated code:

 

ItemUtil

package com.lambda.plentifulmisc.util;

/**
* Created by Blake on 11/22/2016.
*/

import com.lambda.plentifulmisc.PlentifulMisc;
import com.lambda.plentifulmisc.blocks.base.ItemBlockBase;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;


public final class ItemUtil{

    public static void registerBlock(Block block, ItemBlockBase itemBlock, String name, boolean addTab){
        block.setUnlocalizedName(ModUtil.MOD_ID+"."+name);

        block.setRegistryName(ModUtil.MOD_ID, name);
        GameRegistry.register(block);

        itemBlock.setRegistryName(block.getRegistryName());
        GameRegistry.register(itemBlock);

        block.setCreativeTab(addTab ? PlentifulMisc.instance.CREATIVE_TAB : null);

    }

    public static void registerItem(Item item, String name, boolean addTab){
        item.setUnlocalizedName(ModUtil.MOD_ID+"."+name);

        item.setRegistryName(ModUtil.MOD_ID, name);
        GameRegistry.register(item);

        item.setCreativeTab(addTab ? PlentifulMisc.instance.CREATIVE_TAB : null);

    }


}

 

blockBase

package com.lambda.plentifulmisc.blocks.base;

import com.lambda.plentifulmisc.PlentifulMisc;
import com.lambda.plentifulmisc.util.ItemUtil;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.model.ModelLoader;


/**
* Created by Blake on 11/22/2016.
*/
public class BlockBase extends Block{

    private final String name;

    public BlockBase(Material material, String name){
        super(material);
        this.name = name;

        this.register();
    }

    private void register(){
        ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());

        this.registerRendering(this.getItemBlock(), 0);
    }

    protected String getBaseName(){
        return this.name;
    }

    protected ItemBlockBase getItemBlock(){
        return new ItemBlockBase(this);
    }

    public boolean shouldAddCreative(){
        return true;
    }

    protected void registerRendering(ItemBlock itemBlock, int metadata){
        PlentifulMisc.proxy.registerRendering(itemBlock, metadata, new ModelResourceLocation(this.getRegistryName(), "inventory"));
    }
}

 

Client Proxy:

 

package com.lambda.plentifulmisc.proxy;

import com.lambda.plentifulmisc.blocks.base.BlockBase;
import com.lambda.plentifulmisc.util.ModUtil;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import java.util.*;



/**
* Created by Blake on 11/22/2016.
*/
public class ClientProxy implements IProxy
{

    @Override
    public void preInit(FMLPreInitializationEvent event) {
        ModUtil.LOGGER.info("PreInitializing ClientProxy...");

    }

    @Override
    public void init(FMLInitializationEvent event) {

    }

    @Override
    public void postInit(FMLPostInitializationEvent event) {

    }

    @Override
    public void registerRendering(ItemBlock itemBlock, int metadata, ModelResourceLocation location){
        ModelLoader.setCustomModelResourceLocation(itemBlock, metadata, location);
    }

    @Override
    public void registerRenderingItem(Item item, int metadata, ModelResourceLocation location) {
        ModelLoader.setCustomModelResourceLocation(item, metadata, location);
    }
}

 

Block itself

package com.lambda.plentifulmisc.blocks;

import com.lambda.plentifulmisc.blocks.base.BlockBase;
import com.lambda.plentifulmisc.util.ItemUtil;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;

/**
* Created by Blake on 11/22/2016.
*/
public class BlockCeleistrum extends BlockBase{

    BlockCeleistrum(String name) {
        super(Material.ROCK, name);
        this.setHarvestLevel("pickaxe", 0);
        this.setHardness(2.5F);
        this.setResistance(10.0F);
        this.setSoundType(SoundType.STONE);
    }


}

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

Hi

 

I suggest you go simpler still, take the registering out of the Block constructor, and just register it line by line in the Mod class methods, as per previous post

 

In particular this makes me nervous- it might be fine, but looking at it I'm not so sure:

 

public BlockBase(Material material, String name){
        super(material);
        this.name = name;

        this.register();
    }

    private void register(){
        ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());  // this isn't constructed yet

        this.registerRendering(this.getItemBlock(), 0);
    }

Calling methods and passing this, before the class is fully constructed, is always risky.

And it also appears you might be trying to retrieve an ItemBlock before you have registered the block itself, which also could be bad news.

 

I didn't understand what you mean here

"- Block & Item(not ItemBlock) textures are registering

- ItemBlock still 'unregistered' (default texture)

"

 

The Item is the ItemBlock, or not?  Normally you have a Block, an ItemBlock, and that's it.

 

-TGG

 

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.