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

 

  On 11/23/2016 at 1:36 AM, Lambda said:

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • it was flywheel, it's solved now and i am reporting it but i am going to figure what create addon was the cause or if was create itself  
    • I deleted delightful and all farmers delight addon (just in case) and still i have the error :'(, i need to check mod by mod?
    • I'm developing a Forge mod for Minecraft 1.16.5 to run on CatServer (version 1.16.5-1d8d6313, Forge 36.2.39). My mod needs to get the player's UUID from a ServerPlayerEntity object within a Forge ServerChatEvent handler. When I use serverPlayerEntity.getUUID(), my mod compiles fine, but I get a java.lang.NoSuchMethodError: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; at runtime. I cannot use serverPlayerEntity.getUniqueID() as it causes a compile error (cannot find symbol). Is there a known issue with this on CatServer, or a recommended way for a Forge mod to reliably get a player's UUID from ServerPlayerEntity in this environment? My goal is to pass this UUID to the LuckPerms API (which is running as a Bukkit plugin and successfully connected via ServicesManager). erorr ChatMod: FMLServerStartedEvent received. Attempting to initialize LuckPerms connection... [22:45:20] [Server thread/INFO]: ⚙️ Початок ініціалізації LuckPerms API через Bukkit Services Manager... [22:45:20] [Server thread/INFO]: ✅ Bukkit ServicesManager успішно отримано. [22:45:20] [Server thread/INFO]: ✅ Реєстрацію сервісу LuckPerms знайдено. [22:45:20] [Server thread/INFO]: ✅ API LuckPerms успішно отримано від Bukkit plugin! [22:45:20] [Server thread/INFO]: Використовується реалізація: me.lucko.luckperms.common.api.LuckPermsApiProvider [22:45:20] [Server thread/INFO]: ✅ LuckPerms API схоже що успішно ініціалізовано через Bukkit Services Manager. [22:45:24] [User Authenticator #1/INFO]: UUID of player Hiklee is 92cd7721-2652-3867-896b-2ceba5b99306 [22:45:25] [Server thread/INFO]: Using new advancement loading for net.minecraft.advancements.PlayerAdvancements@24cb7a68 [22:45:26] [Server thread/INFO]: Hiklee[/127.0.0.1:41122] logged in with entity id 210 at (92.23203876864889, 95.6183020148442, 68.24087802017877) [22:45:28] [Async Chat Thread - #0/INFO]: ✅ Скасовано стандартне відправлення чату! [22:45:28] [Async Chat Thread - #0/ERROR]: Exception caught during firing event: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; Index: 1 Listeners: 0: NORMAL 1: ASM: class com.example.chatmod.ChatEventHandler onPlayerChat(Lnet/minecraftforge/event/ServerChatEvent;)V java.lang.NoSuchMethodError: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; at com.example.chatmod.ChatPacketHandler.getPlayerPrefix(ChatPacketHandler.java:46) at com.example.chatmod.ChatEventHandler.onPlayerChat(ChatEventHandler.java:32) at net.minecraftforge.eventbus.ASMEventHandler_1_ChatEventHandler_onPlayerChat_ServerChatEvent.invoke(.dynamic) at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:303) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) at net.minecraftforge.common.ForgeHooks.onServerChatEvent(ForgeHooks.java:493) at net.minecraft.network.play.ServerPlayNetHandler.chat(ServerPlayNetHandler.java:1717) at net.minecraft.network.play.ServerPlayNetHandler.func_244548_c(ServerPlayNetHandler.java:1666) at net.minecraft.network.play.ServerPlayNetHandler.func_147354_a(ServerPlayNetHandler.java:1605) at net.minecraft.network.play.client.CChatMessagePacket.lambda$handle$0(CChatMessagePacket.java:34) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:750
    • Thank you so much for your help, I'll try it as soon as I can. I have a genuine question because I'm not familiar with the matter: Can a recipe error cause something as serious as the AMD error?
    • When i try to launch my modpack, the instance crashes and this is sent to the logs: Time: 2025-05-27 23:07:18 Description: Rendering overlay Below is the full log: https://mclo.gs/jP5G2EH
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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