Jump to content

Recommended Posts

Posted

I can't make my item display its texture. This is my code:

 

Main mod class:

@Mod(modid = TheMod.MODID, name = TheMod.NAME, version = TheMod.VERSION)
public class TheMod
{
public static final String MODID = "mymod";
public static final String VERSION = "1.9-Alpha-1.0";
public static final String NAME = "My Mod";

@SidedProxy(clientSide = ClientProxy.NAME, serverSide = CommonProxy.NAME)
public static CommonProxy proxy;

@Instance
public static TheMod instance;
public static Logger logger;

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	logger = event.getModLog();
	proxy.preInit(event);
}

@EventHandler
public void init(FMLInitializationEvent event)
{
	proxy.init(event);
}

@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
	proxy.postInit(event);
}
}

 

CommomProxy class:

public class CommonProxy
{
public static final String NAME = "mod.mymod.CommonProxy";

public void preInit(FMLPreInitializationEvent event)
{

}

public void init(FMLInitializationEvent event)
{
	Items.init(event);
}

public void postInit(FMLPostInitializationEvent event)
{

}
}

 

ClientProxy class:

public class ClientProxy extends CommonProxy
{
public static final String NAME = "mod.mymod.ClientProxy";

@Override
public void preInit(FMLPreInitializationEvent event)
{
	super.preInit(event);
}

@Override
public void init(FMLInitializationEvent event)
{
	super.init(event);
}

@Override
public void postInit(FMLPostInitializationEvent event)
{
	super.postInit(event);
}
}

 

ItemBase class:

public class ItemBase extends Item
{
public final String name;

public ItemBase(String name)
{
	setRegistryName(name);
	this.name = name;
	setUnlocalizedName(getRegistryName().toString());
}

public ItemBase init(FMLInitializationEvent event)
{
	GameRegistry.register(this);
	if(event.getSide() != Side.SERVER)
	{
		registerModel();
	}
	return this;
}

private void registerModel()
{
	ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(TheMod.MODID + ":" + name, "inventory"));
}

@Override
public ItemBase setCreativeTab(CreativeTabs tab)
{
	super.setCreativeTab(tab);
	return this;
}
}

 

Items class:

public final class Items
{
private Items()
{

}

public static Item firstItem;

public static void preInit(FMLPreInitializationEvent event)
{

}

public static void init(FMLInitializationEvent event)
{
	firstItem = new ItemBase("first_item").init(event);
}

public static void postInit(FMLPostInitializationEvent event)
{

}
}

 

What I understand should happen is:

TheMod 

gets a chance to handle the 3 initialization events it is subscribed to.

 

1:

TheMod 

handles the pre initialization event, where the

logger

field is initialized.

2:

TheMod

handles the initialization event by invoking the sided proxy

init

method.

3: the sided proxy's

init

invokes

Items.init

method

4:

Items.init

instantiates a new

ItemBase

4.1: The constructor of

ItemBase

registers the non-prefixed name passed to it.

4.2: The constructor of

ItemBase

stores the non-prexifed name passed to it as the instance field

name

4.3: The constructor of

ItemBase

invokes

setUnlocalized

name, passing as argument the result of

getRegistryName

(which will return the name prefixed by the mod id).

5:

Items.init

invokes

ItemBase#init

on the newly created

ItemBase

instance.

5.1:

ItemBase#init

registers

this

by invoking

GameRegistry#register

5.2:

ItemBase#init

uses its event argument's

getSide

method to decide if

registerModel

should be invoked.

5.3:

registerModel

is responsible for the item having a texture. This method's body was copy pasted from somewhere else. I'm not sure what it's being done here.

 

Where is my mistake and why? Thanks.

Posted

All of this is bad:

 

	public ItemBase init(FMLInitializationEvent event)
{
	GameRegistry.register(this);
	if(event.getSide() != Side.SERVER)
	{
		registerModel();
	}
	return this;
}

private void registerModel()
{
	ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(TheMod.MODID + ":" + name, "inventory"));
}

 

  On 5/30/2016 at 2:28 PM, Draco18s said:

Don't register your renderers there.  You must do it in your client proxy or you will crash the dedicated server.

  Quote
Because you have a common class (
BlocClearInventory

) that contains sided code (

registerRenders

references

Minecraft.getMinecraft()

).

 

As soon as the server reads your block class from the disk, it needs to make sure that the class is valid code.  This includes loading every class referenced by your class.  This means that it will then attempt to load the

Minecraft

class, which won't exist.

 

This is not a question of "where is it called from."  This is a question of "does the code exist."  Your class contains CLIENT SIDE ONLY code.  The mere existence of that code crashes the dedicated server, even if you never call the function from anywhere ever.

 

This is why the

registerRenders

code must be moved out of the block class and into the ClientProxy.

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 made the following changes:

 

CommonProxy class:

public void registerItemRenderer(Item item, int meta, String name)
{

}

 

 

ClientProxy class:

        @Override
public void registerItemRenderer(Item item, int meta, String name)
{
	ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(TheMod.MODID + ":" + name, "inventory"));
}

 

ItemBase class:

public ItemBase init()
{
	GameRegistry.register(this);
	TheMod.proxy.registerItemRenderer(this, 0, name);
	return this;
}

 

I think that covers your observation, but still no texture.

Posted
Item

s,

Block

s and every other

IForgeRegistryEntry

implementation should be registered in preInit, not init.

ModelLoader

methods only work in preInit.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 6/1/2016 at 5:21 PM, Choonster said:

Item

s,

Block

s and every other

IForgeRegistryEntry

implementation should be registered in preInit, not init.

ModelLoader

methods only work in preInit.

 

That fixed it, thanks!

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

    • Looks like an issue with biomeswevegone
    • In the server.properties, set max-tick-time to -1   if there are further issues, make a test without distanthorizons
    • Verified user can get a $300 off TℰℳU Coupon code using the code ((“{{ '[''com31844'']}}”)). This TℰℳU $100Off code is specifically for new and existing customers both and can be redeemed to receive a $100discount on your purchase. Our exclusive TℰℳU Coupon code offers a flat $100off your purchase, plus an additional 100% discount on top of that. You can slash prices by up to $100as a new TℰℳU customer using code ((“{{ '[''com31844'']}}”)). Existing users can enjoy $100off their next haul with this code. But that’s not all! With our TℰℳU Coupon codes for 2025, you can get up to 90% discount on select items and clearance sales. Whether you’re a new customer or an existing shopper, our TℰℳU codes provide extra discounts tailored just for you. Save up to 100% with these current TℰℳU Coupons ["^"{{ '[''com31844'']}} "^"] for April 2025. The latest TℰℳU coupon codes at here. New users at TℰℳU receive a $100discount on orders over $100Use the code ((“{{ '[''com31844'']}}”)) during checkout to get TℰℳU Coupon $100Off For New Users. You can save $100Off your first order with the coupon code available for a limited time only. TℰℳU 90% Off promo code ((“{{ '[''com31844'']}}”)) will save you $100on your order. To get a discount, click on the item to purchase and enter the coe. Yes, offers $100Off coupon code “{{ '[''com31844'']}}” for first time users. You can get a $100bonus plus $100Off any purchase at TℰℳU with the $100Coupon Bundle at TℰℳU if you sign up with the referral code ((“{{ '[''com31844'']}}”)) and make a first purchase of $100or more. Free TℰℳU codes $100off — ((“{{ '[''com31844'']}}”)) Get a $100discount on your TℰℳU order with the promo code "{{ '[''com31844'']}}". You can get a discount by clicking on the item to purchase and entering this TℰℳU Coupon code $100off ((“{{ '[''com31844'']}}”)). ŢℰNew User Coupon ((“{{ '[''com31844'']}})): Up To $100OFF For First-Time Users Our TℰℳU first-time user coupon codes are designed just for new customers, offering the biggest discounts and the best deals currently available on TℰℳU To maximize your savings, download the TℰℳU app and apply our TℰℳU new user coupon during checkout. TℰℳU Coupon Codes For Existing Users ((“{{ '[''com31844'']}}”)): $100Price Slash Have you been shopping on TℰℳU or a while? Our TℰℳU Coupon for existing customers is here to reward you for your continued support, offering incredible discounts on your favorite products. TℰℳU Coupon For $100Off ((“{{ '[''com31844'']}}”)): Get A Flat $100Discount On Order Value Get ready to save big with our incredible TℰℳU Coupon for $100off! Our amazing ŢℰM$100off coupon code will give you a flat $100discount on your order value, making your shopping experience even more rewarding. TℰℳU Coupon Code For $100Off ((“{{ '[''com31844'']}}”)): For Both New And Existing Customers Our incredible TℰℳU Coupon code for $100off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our $100off code for TℰℳU will give you an additional discount! TℰℳU Coupon Bundle ((“{{ '[''com31844'']}}”)): Flat $100Off + Up To $100Discount Get ready for an unbelievable deal with our TℰℳU Coupon bundle for 2025! Our TℰℳU Coupon bundles will give you a flat $100discount and an additional $100off on top of it. Free TℰℳU Coupons ((“{{ '[''com31844'']}}”)): Unlock Unlimited Savings! Get ready to unlock a world of savings with our free TℰℳU Coupons! We’ve got you covered with a wide range of TℰℳU Coupon code options that will help you maximize your shopping experience. 100% Off TℰℳU Coupons, Promo Codes + 25% Cash Back ((“{{ '[''com31844'']}}”)) Redeem TℰℳU Coupon Code ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FOR EXISTING CUSTOMERS ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FIRST ORDER ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF REDDIT ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FOR EXISTING CUSTOMERS REDDIT ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF CODE ((“{{ '[''com31844'']}}”)) TℰℳU 70 OFF COUPON 2025 ((“{{ '[''com31844'']}}”)) DOMINOS 70 RS OFF COUPON CODE ((“{{ '[''com31844'']}}”)) WHAT IS A COUPON RATE ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FOR EXISTING CUSTOMERS ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FIRST ORDER ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FREE SHIPPING ((“{{ '[''com31844'']}}”)) You can get an exclusive $100off discount on your TℰℳU purchase with the code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}].This code is specially designed for new customers and offers a significant price cut on your shopping. Make your first purchase on TℰℳU more rewarding by using this code to get $100off instantly.   TℰℳU Coupon Code For $100Off [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]: Get A Flat $100Discount On Order Value Get ready to save big with our incredible TℰℳU coupon for $100off! Our coupon code will give you a flat $100discount on your order value, making your shopping experience even more rewarding.   Exclusive TℰℳU Discount Code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]: Flat $300 OFF for New and Existing Customers Using our TℰℳU promo code you can get A$ 200 off your order and 100% off using our TℰℳU promo code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]. As a new TℰℳU customer, you can save up to $100using this promo code. For returning users, our TℰℳU promo code offers a $100price slash on your next shopping spree. This is our way of saying thank you for shopping with us! Get ready to save big with our incredible TℰℳU Coupon code for $300 off! Our amazing TℰℳU $300 off coupon code will give you a flat $300 discount on your order value, making your shopping experience even more rewarding.   TℰℳU Coupon Code For 40% Off ["{com31844}"] For Both New And Existing Customers   Our incredible TℰℳU Coupon code for 40% off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our 40% off code for TℰℳU will give you an additional discount!   TℰℳU Coupon Bundle ["{com31844}"]: Flat $300 Off + Up To 90% Discount   Get ready for an unbelievable deal with our TℰℳU Coupon bundle for 2025! Our TℰℳU Coupon bundles will give you a flat $300 discount and an additional 40% off on top of it.   Free TℰℳU Coupons ["{com31844}"]: Unlock Unlimited Savings!   Get ready to unlock a world of savings with our free TℰℳU Coupons! We’ve got you covered with a wide range of TℰℳU Coupon code options that will help you maximize your shopping experience.   50% Off TℰℳU Coupons, Promo Codes + 25% Cash Back ["{com31844}"]   Redeem TℰℳU Coupon Code ["{com31844}"]   TℰℳU Coupon $300 OFF ["{com31844}"]   TℰℳU Coupon $300 OFF ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS ["{com31844}"]   TℰℳU Coupon $300 OFF FIRST ORDER ["{com31844}"]   TℰℳU Coupon $300 OFF FIRST ORDER ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS FREE SHIPPING USA ["{com31844}"]   TℰℳU Coupon $300 OFF HOW DOES IT WORK ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS CANADA ["{com31844}"]   TℰℳU Coupon $300 OFF 2025 ["{com31844}"]   TℰℳU Coupon $300 OFF FOR NEW CUSTOMERS ["{com31844}"]   TℰℳU Coupon $300 OFF CANADA ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS FIRST ORDER ["{com31844}"]   TℰℳU 300 OFF COUPON BUNDLE ["{com31844}"]   This TℰℳU coupon $300 off is designed to provide substantial savings on your purchases, making shopping for your favorite items easier than ever. With our $300 off TℰℳU coupon, you'll be amazed at how much you can save on your next order. Here are the key benefits you can expect when using our coupon code {com31844} "OR" {com31844}: {com31844} "OR" {com31844}: Flat $300 off on your purchase {com31844} "OR" {com31844}: $300 coupon pack for multiple uses {com31844} "OR" {com31844}: $300 flat discount for new customers {com31844} "OR" {com31844}: Extra $300 promo code for existing customers {com31844} "OR" {com31844}: $300 coupon exclusively for USA/Canada users H2: TℰℳU Coupon Code $300 Off For New Users In 2024 New users can reap the highest benefits by using our coupon code on the TℰℳU app. This TℰℳU coupon $300 off is specifically designed to welcome new customers with incredible savings  
    • Now the serve runs for a bit, then crashes after 20 minutes of running, what's the issue here? apologies if I need to start a new post and didn't https://pastebin.com/uBpp5bCz  
  • 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.