Jump to content

[1.8] item rendering not working


sigurd4

Recommended Posts

this is very strange. i've been struggling for days now trying to figure this out on my own. there's been a lot of other posts with the excact same problem, and i've tried doing the same thing that solved it for those, but it wont work. i've quadruple-checked that the path is correct and i've tried making a new world. none of it works. previously in the log it said it couldnt find the json file, but i fixed it, and now it doesn't say anything special. despite that, the item looks like a untextured block, except double the size of a normal block (more or less), which i've noticed is a common issue. hwever, i've tried every single solution i've found and none of it has worked for me. main mod file code:

 

main mod class:

@Mod(modid = References.MODID, version = References.VERSION)
public class M
{
//TODO if we are ever going to add mobs, enable this and notify me! i have some nifty code for custom mob eggs that we can use! - sigurd4
/**Register entity with egg**/
/*public static void registerEntity(Class<? extends Entity> entityClass, String name, int entityID, int primaryColor, int secondaryColor)
{
	EntityRegistry.registerGlobalEntityID(entityClass, name, entityID);
	ItemMonsterPlacer2.EntityList2.registerEntity(entityClass, entityID, name, primaryColor, secondaryColor);
}*/

/**Register entity without egg**/
public static void registerEntityNoEgg(Class<? extends Entity> entityClass, String name, int entityID)
{
	EntityRegistry.registerModEntity(entityClass, name, entityID, instance, 64, 1, true);
}

@Instance(References.MODID)
public static M instance;

public static SimpleNetworkWrapper network;

/**tabs**/
public static TabGeneric tabCore = new TabGeneric("spectralGunsCore", M.component_barrel);
/**items**/
public static ItemComponent component_barrel;

public M()
{
	items();
	tabs();
}

private void items()
{
	component_barrel = (ItemComponent)new ItemComponent("barrel").setUnlocalizedName("barrel");
}

private void tabs()
{
	tabCore.icon = component_barrel;
}

@SidedProxy(clientSide = References.Client, serverSide = References.Server)
public static ProxyCommon proxy;

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

 

the reason there are so many comments is because im working with some other people, so i need to explain stuff for them.

 

modid in References is "spectralguns"

 

client proxy:

public class ProxyClient extends ProxyCommon
{
@Override
public void init()
{
	super.init();

	/**to be used for item rendering**/
	RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
	/**to be used for item rendering**/
	RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();

	MinecraftForge.EVENT_BUS.register(new HandlerClient());
	FMLCommonHandler.instance().bus().register(new HandlerClientFML());

	//TODO add keyhandler
	//HandlerKeys.init();
	//FMLCommonHandler.instance().bus().register(new HandlerKeys());
}
}

client fml event handler:

@SideOnly(Side.CLIENT)
public class HandlerClientFML extends HandlerCommonFML
{
//fml events for client only here!

@EventHandler
public void FMLInitializationEvent(FMLInitializationEvent event)
{
	Minecraft mc = Minecraft.getMinecraft();
	RenderItem ri = mc.getRenderItem();
	ItemModelMesher imm = ri.getItemModelMesher();
	for(int i = 0; i < ItemBase.itemsToBeRegistered.size(); ++i)
	{
		ItemBase item = ItemBase.itemsToBeRegistered.get(i);
		imm.register(item, 0, new ModelResourceLocation(References.MODID + ":" + item.id, "inventory"));
	}
}
}

ItemBase class:

public abstract class ItemBase extends Item
{
public static ArrayList<ItemBase> itemsToBeRegistered = new ArrayList<ItemBase>();

public final String id;
private CreativeTabs[] creativeTabs;

public static final String RIGHTCLICKED = "RightClicked";
/**
 * Base for all items
 */
public ItemBase(String id)
{
	super();
	this.setMaxStackSize(64);
	GameRegistry.registerItem(this, id);
	itemsToBeRegistered.add(this);
	this.id = id;
}

/**
 * Base for all items
 */
public ItemBase(String id, CreativeTabs[] tabs)
{
	this(id);
	this.setCreativeTabs(tabs);
}

/**
 * Gets a list of tabs that items belonging to this class can display on,
 * combined properly with getSubItems allows for a single item to span
 * many sub-items across many tabs.
 *
 * @return A list of all tabs that this item could possibly be on.
 */
@Override
public CreativeTabs[] getCreativeTabs()
{
	if(this.creativeTabs != null)
	{
		return  this.creativeTabs;
	}
	else
	{
		return super.getCreativeTabs();
	}
}

public void setCreativeTabs(CreativeTabs[] tabs)
{
	this.creativeTabs = tabs;
}
}

ItemComponent class:

public class ItemComponent extends ItemBase
{
/**
 * Crafting components
 */
public ItemComponent(String id)
{
	super("component_" + id);
	this.setCreativeTab(M.tabCore);
}

/**
 * Crafting components
 */
public ItemComponent(String id, CreativeTabs[] tabs)
{
	super("component_" + id, tabs);
}

    public Item setUnlocalizedName(String unlocalizedName)
    {
        return super.setUnlocalizedName("component." + unlocalizedName);
    }
}

component_barrel.json in spectralguns:models/item:

{
    "parent": "builtin/generated",
    "textures": {
        "layer0": "spectralguns:items/barrel"
    },
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 1.7, 1.7, 1.7 ]
        }
    }
}

texture is spectralguns:textures/items/barrel.png

 

i cant find out what i've done wrong! there are so many things in 1.8 that confuse me and this especially. :/

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

Link to comment
Share on other sites

ok i tried something different, but it's not working:

client fml event handler:

@SideOnly(Side.CLIENT)
public class HandlerClientFML extends HandlerCommonFML
{
//fml events for client only here!

@EventHandler
public void FMLInitializationEvent(FMLInitializationEvent event)
{
	Minecraft mc = Minecraft.getMinecraft();
	RenderItem ri = mc.getRenderItem();
	ItemModelMesher imm = ri.getItemModelMesher();
	for(int i = 0; i < ItemBase.itemsToBeRegistered.size(); ++i)
	{
		ItemBase item = ItemBase.itemsToBeRegistered.get(i);
		//String id = References.MODID + ":" + item.id;
		String id = References.MODID + ":" + item.getUnlocalizedName2();
		ModelBakery.addVariantName(item, new String[]{id});
		imm.register(item, 0, new ModelResourceLocation(id, "inventory"));
	}
}
}

getUnlocalizedName2() in ItemBase:

public String getUnlocalizedName2()
{
	String s = getUnlocalizedName();
	s = s.replaceFirst("item.", "");
	return s;
}

now i get the warning in the console saying it cant find the json file. you sure it doesn't use the item string id rather than the unlocalized name?

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

Link to comment
Share on other sites

[14:57:43] [Client thread/WARN]: Unable to load item model: 'spectralguns:item/component_barrel' for item: 'spectralguns:component_barrel'
java.io.FileNotFoundException: spectralguns:models/item/component_barrel.json
at net.minecraft.client.resources.FallbackResourceManager.getResource(FallbackResourceManager.java:70) ~[FallbackResourceManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:67) ~[simpleReloadableResourceManager.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadModel(ModelBakery.java:260) ~[ModelBakery.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadItemModels(ModelBakery.java:307) [ModelBakery.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadVariantItemModels(ModelBakery.java:105) [ModelBakery.class:?]
at net.minecraft.client.resources.model.ModelBakery.setupModelRegistry(ModelBakery.java:88) [ModelBakery.class:?]
at net.minecraft.client.resources.model.ModelManager.onResourceManagerReload(ModelManager.java:29) [ModelManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.notifyReloadListeners(SimpleReloadableResourceManager.java:134) [simpleReloadableResourceManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.reloadResources(SimpleReloadableResourceManager.java:118) [simpleReloadableResourceManager.class:?]
at net.minecraft.client.Minecraft.refreshResources(Minecraft.java:727) [Minecraft.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:298) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:484) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:325) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]
at GradleStart.main(GradleStart.java:45) [start/:?]

it's the same name that i used previously. the strange thing is that it does not seem to be affected by the string i use in the json file registration in my event handler. it seems to use the item's string id instead. do i even need to register it like i have done; in the init event?

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

Link to comment
Share on other sites

This is the basic code that I was working with:

 

    	obliteratorAxe = new ItemAxeUpgrade(Item.ToolMaterial.EMERALD);
    	obliteratorAxe.setUnlocalizedName("obliteratorAxe");
    	GameRegistry.registerItem(obliteratorAxe, "obliteratorAxe");
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(obliteratorAxe, 0, new ModelResourceLocation("perstools:obliteratorAxe", "inventory"));

 

I'm going to keep looking over your code to see if I can locate the issue, but from what I understand, the unlocalized name as well as the ModelResourceLocation have to be the same (other than the modID in front of the ":". Sorry if I'm wrong, but that seems to have been my initial issue. My unlocalized name was different.

 

Just want to make sure,

your model json is located here? - src/main/resources/assets/spectralguns/models/item

And the name of the file is "component_barrel.json"

Also respecting all letter cases.

Link to comment
Share on other sites

yes exactly.

also, i notice that your unlocalizedName is the same as the item string id, so that makes sense.

another thing: i /* */ed out the whole model registering stuff and it seemed to still look after the model. isn't that strange? do i actually need to register the item like that? the string i put in the register code does not seem to affect anything. then i tried changing the unlocalizedName to match the id, yet i have the same problem (yes, i tried making a new world).

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

Link to comment
Share on other sites

I don't know what to tell you... I used the code that you put in your initial post, and I recreated it in my workspace. When I started the game, the image loaded up fine right away... Do you get the "java.io.FileNotFoundException: spectralguns:models/item/component_barrel.json" error with the code in your initial post?

 

Also, if you open up the file directory where your json is saved, is it located here?

 

"WhereverYouSavedYourModdingFolder"\fml\src\main\resources\assets\spectralguns\models\item

 

As a last ditch effort, maybe try to "Clean" your workspace? I don't know what tool you use, but with Eclipse, it can be found under "Project" - "Clean". This should clear out any temp files that could be causing issues...

 

Good Luck with this...

Link to comment
Share on other sites

I don't know what to tell you... I used the code that you put in your initial post, and I recreated it in my workspace. When I started the game, the image loaded up fine right away... Do you get the "java.io.FileNotFoundException: spectralguns:models/item/component_barrel.json" error with the code in your initial post?

no. i did when i changed the name of the json file. if i changed the string in the texture registration thing it didnt change anything.

 

Also, if you open up the file directory where your json is saved, is it located here?

 

"WhereverYouSavedYourModdingFolder"\fml\src\main\resources\assets\spectralguns\models\item

fml? ok i moved my src folder into a new folder that i named fml and made it like you described, then added \fml\src\main\resources and \fml\src\main\java to the build path. didn't do any difference.

 

As a last ditch effort, maybe try to "Clean" your workspace? I don't know what tool you use, but with Eclipse, it can be found under "Project" - "Clean". This should clear out any temp files that could be causing issues...

will try this. i'll come back once i've done it.

 

Good Luck with this...

thanks. this update has been a lot of trouble for me. hopefully it'll work after i clean my workspace.

 

Maybe try "refreshing" your eclipse workspace by pressing F5? For me, usually, any changes I do to the texture JSON files won't apply in eclipse (and in-game) until I refresh.

done that for a long time ago.

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I made a block entity in forge 1.20.1, I want to prevent hopper from taking input slot item, i tried to override the extractItem method, it prevented hopper from taking input slot item, but the player also unable to take/change the item in input slot unless the slot is empty. public class FluidSeparatorBlockEntity extends BlockEntity implements MenuProvider { private static final int INPUT_SLOT = 0; private final CustomItemHandler itemHandler = new CustomItemHandler(3){ @Override protected void onContentsChanged(int slot) { setChanged(); } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return slot == INPUT_SLOT; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == INPUT_SLOT) { return ItemStack.EMPTY; } return super.extractItem(slot, amount, simulate); } }; private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); protected final ContainerData data; private int progress = 0; private int maxProgress = 78; public FluidSeparatorBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.FLUID_SEPARATOR_BE.get(), pPos, pBlockState); this.data = new ContainerData() { @Override public int get(int pIndex) { return switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress; default -> 0; }; } @Override public void set(int pIndex, int pValue) { switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress = pValue; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress = pValue; } } @Override public int getCount() { return 3; } }; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ForgeCapabilities.ITEM_HANDLER) { return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } @Override public Component getDisplayName() { return Component.translatable("block.chemmaster.fluid_separator"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new FluidSeparatorMenu(pContainerId, pPlayerInventory, this, this.data); } @Override protected void saveAdditional(CompoundTag pTag) { pTag.put("inventory", itemHandler.serializeNBT()); pTag.putInt("fluid_separator.progress", progress); super.saveAdditional(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); itemHandler.deserializeNBT(pTag.getCompound("inventory")); progress = pTag.getInt("fluid_separator.progress"); } public void tick(Level pLevel, BlockPos pPos, BlockState pState) { ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { resetProgress(); return; } if(hasRecipe()) { increaseCraftingProgress(); setChanged(pLevel, pPos, pState); if(hasProgressFinished()) { craftItem(); resetProgress(); } } else { resetProgress(); } } private void resetProgress() { progress = 0; } private void craftItem() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isPresent()) { List<ItemStack> results = recipe.get().getOutputs(); ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { // If there are not enough items, do not proceed with crafting return; } // Extract the input item from the input slot this.itemHandler.internalExtractItem(INPUT_SLOT, 2, false); // Loop through each result item and find suitable output slots for (ItemStack result : results) { int outputSlot = findSuitableOutputSlot(result); if (outputSlot != -1) { this.itemHandler.setStackInSlot(outputSlot, new ItemStack(result.getItem(), this.itemHandler.getStackInSlot(outputSlot).getCount() + result.getCount())); } else { // Handle the case where no suitable output slot is found // This can be logging an error, throwing an exception, or any other handling logic System.err.println("No suitable output slot found for item: " + result); } } } } private int findSuitableOutputSlot(ItemStack result) { // Implement logic to find a suitable output slot for the given result // Return the slot index or -1 if no suitable slot is found for (int i = 0; i < this.itemHandler.getSlots(); i++) { // Ensure we do not place the output item in the input slot if (i == INPUT_SLOT) { continue; } ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return i; } } return -1; } private boolean hasRecipe() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isEmpty()) { return false; } List<ItemStack> results = recipe.get().getOutputs(); for (ItemStack result : results) { if (!canInsertAmountIntoOutputSlot(result) || !canInsertItemIntoOutputSlot(result.getItem())) { return false; } } return true; } private Optional<FluidSeparatingRecipe> getCurrentRecipe(){ SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(FluidSeparatingRecipe.Type.INSTANCE, inventory, level); } private boolean canInsertAmountIntoOutputSlot(ItemStack result) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return true; } } return false; } private boolean canInsertItemIntoOutputSlot(Item item) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || stackInSlot.getItem() == item) { return true; } } return false; } private boolean hasProgressFinished() { return progress >= maxProgress; } private void increaseCraftingProgress() { progress++; } }  
    • No dice. Unfortunately this fix didn't work, thank you though.
    • Maybe you need a rayon mod. https://www.curseforge.com/minecraft/mc-mods/rayon
    • Not sure what's going on the logs are making even less sense than usual to me. Any help would be much appreciated.   https://paste.ee/p/KBHyP#s=0
  • Topics

×
×
  • Create New...

Important Information

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