Jump to content

Model Block/Item Replacement Not Working At RunTime


jredfox

Recommended Posts

It shows a stone block and then when placing it crashes. It isn't showing the right texutre it's showing stone and sometimes crashes when I place the block

block.json:

{
    "parent": "block/cube_all",
    "textures": {
        "all": "blocks/default"
    }
}

CrashReport:
https://pastebin.com/fC6yidec

What I am trying to do:
make them have whatever texture location from the registry name. I returned the right texture atlis sprite from my model I think so I don't understand why this isn't working. It's got to be dynamic I don't want to be messing with 10,000 jsons everytime I want a single Item I am trying to make a model that works with everything. This eventually is going to have one model per default type, one for default blocks, one for stairs, one for slabs, one for pickaxe, one for item etc.. I just need help in how to accomplish this. I want a model with a dynamic texture that is default like it was in < 1.8 without this it requires 4,000+ jsons for a decent mod and all they do is change the texture location no actual custom model ridiculous 

	@SubscribeEvent(priority=EventPriority.HIGHEST)
	public void registerModels(ModelRegistryEvent event) 
	{
	   for(IBasicItem i : MainJava.items)
	   {
		   if(i.registerModel())
		   {
			   Item item = (Item)i;
			   ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(MainJava.MODID + ":" + "block", "inventory"));
		   }
	   }
	   for(IBasicBlock i : MainJava.blocks)
	   {
		   if(i.registerModel())
		   {
			   Block b = (Block)i;
			   ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(b), 0,  new ModelResourceLocation(MainJava.MODID + ":" + "block", "inventory"));
		   }
	   }
	}
@SubscribeEvent(priority=EventPriority.HIGH)
	public void modeltest(ModelBakeEvent event)
	{
		Set<ResourceLocation> locs = new HashSet<>();
		for(IBasicBlock b : MainJava.blocks)
		{
			Block block = (Block)b;
			locs.add(BlockApi.getBlockString(block));
		}
		for(IBasicItem i : MainJava.items)
		{
			Item item = (Item)i;
			locs.add(BlockApi.getItemString(item));
		}
		IRegistry<ModelResourceLocation, IBakedModel> reg = event.getModelRegistry();
		for(ModelResourceLocation strm : reg.getKeys())
		{
			ResourceLocation key = new ResourceLocation(strm.getResourceDomain() + ":" + strm.getResourcePath());
			if(locs.contains(key))
			{
				System.out.println("overring model:" + key);
				reg.putObject(strm, new BasicModel(reg.getObject(new ModelResourceLocation(new ResourceLocation(MainJava.MODID + ":" + "block").toString(),strm.getVariant())),key) );
			}
		}
	}

Here is the model itself:

package com.EvilNotch.lib.util.minecraft.content.client.models;

import java.util.List;

import com.EvilNotch.lib.Api.MCPMappings;
import com.EvilNotch.lib.Api.ReflectionUtil;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;

public class BasicModel implements IBakedModel{
	IBakedModel model = null;
	TextureAtlasSprite sprite = null;
	
	public BasicModel(IBakedModel m,ResourceLocation texture){
		this.model = m;
		this.setTexture(texture);
	}
	
	public void setTexture(ResourceLocation loc){
		sprite = new TextureAtlasSpriteFixed(loc);
	}

	@Override
	public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
		return this.model.getQuads(state,side,rand);
	}

	@Override
	public boolean isAmbientOcclusion() {
		return this.model.isAmbientOcclusion();
	}

	@Override
	public boolean isGui3d() {
		return this.model.isGui3d();
	}

	@Override
	public boolean isBuiltInRenderer() {
		return this.model.isBuiltInRenderer();
	}

	@Override
	public TextureAtlasSprite getParticleTexture() {
//		System.out.println(ReflectionUtil.getObject(model, TextureAtlasSprite.class,"iconName"));
		return this.sprite;
	}

	@Override
	public ItemOverrideList getOverrides() {
		return this.model.getOverrides();
	}

}

My Block model:
C:\Users\jredfox\Documents\MDK\EvilNotchLib\src\main\resources\assets\evilnotchlib\models\block\block.json
Block Image:
C:\Users\jredfox\Documents\MDK\EvilNotchLib\src\main\resources\assets\evilnotchlib\blocks\spider.png

Edited by jredfox
Link to comment
Share on other sites

1 hour ago, diesieben07 said:

You don't need "10,000 jsons" for every item.

You need one. Precisely one (example from vanilla's apple):


{
    "parent": "item/generated",
    "textures": {
        "layer0": "items/apple"
    }
}

 

If this is too much for you, write a program that generates these files.

Nope Need to learn eventually

Link to comment
Share on other sites

15 hours ago, diesieben07 said:

You don't need "10,000 jsons" for every item.

You need one. Precisely one (example from vanilla's apple):


{
    "parent": "item/generated",
    "textures": {
        "layer0": "items/apple"
    }
}

 

If this is too much for you, write a program that generates these files.

I noticed IBaked models for fluids had a texture atlis sprite why is their's working and mine isn't?

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.



×
×
  • Create New...

Important Information

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