Jump to content

[1.8] [UNSOLVED] 3D Smart Item Model is Textured with the Sprite Atlas?


Recommended Posts

Posted

Firstly, for anyone wondering, forge version: 1.8-11.14.3.1521

 

 

l4jwFVn.png

 

 

oycVwER.png

 

 

XXJZRw9.png

 

 

PO6QeI8.png

 

 

 

package com.scors.bioalchemy.render;

import java.util.ArrayList;
import java.util.List;

import com.scors.bioalchemy.BioAlchemy;
import com.scors.bioalchemy.render.ModelMapper.CannonPart;

import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.model.IFlexibleBakedModel;
import net.minecraftforge.client.model.ISmartItemModel;

public class ArmCannonSmartModel implements ISmartItemModel {

private IBakedModel base;
private IFlexibleBakedModel chase;

public static ModelResourceLocation mrl = new ModelResourceLocation(BioAlchemy.modid+":armcannon", "inventory");

public ArmCannonSmartModel(IBakedModel base)
{
	this.base = base;
}

@Override
public IBakedModel handleItemState(ItemStack stack) {
	if(stack != null)
	{
		NBTTagCompound tag = stack.getTagCompound();
		if(tag == null){
			chase = ModelMapper.getBaked(CannonPart.CHASE, "defaultchase");
		}
	}
	return this;
}

@Override
public List getFaceQuads(EnumFacing p_177551_1_) {
	// TODO Auto-generated method stub
	return base.getFaceQuads(p_177551_1_);
}

@Override
public List getGeneralQuads() {
	// TODO Auto-generated method stub
	return chase.getGeneralQuads();
}

@Override
public boolean isAmbientOcclusion() {
	// TODO Auto-generated method stub
	return base.isAmbientOcclusion();
}

@Override
public boolean isGui3d() {
	// TODO Auto-generated method stub
	return base.isGui3d();
}

@Override
public boolean isBuiltInRenderer() {
	// TODO Auto-generated method stub
	return false;
}

@Override
public TextureAtlasSprite getTexture() {
	// TODO Auto-generated method stub
	return base.getTexture();
}

@Override
public ItemCameraTransforms getItemCameraTransforms() {
	// TODO Auto-generated method stub
	return base.getItemCameraTransforms();
}

}

 

 

Images and title says it all.  For some reason, my Smart Item Model class is no longer rendering the proper textures, and I believe it is related to the forge update to version 1519.  Attached is the class code, and the only real change is getGeneralQuads() can be changed from chase to base and it'll render the base properly.  (Both have identical JSon's so I know it's not the JSON itself.)

In the images, the left is the chase and the right is the smart item.

 

If anyone has any idea what I can do to fix/work-around this it would be greatly appreciated!  Thank you!

Posted

All of those

// TODO Auto-generated method stub

might be the problem.

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 think you should show relevant code with this line:

ModelMapper.getBaked(CannonPart.CHASE, "defaultchase")

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

All of those

// TODO Auto-generated method stub

might be the problem.

Those are generated by Eclipse when bringing in methods from an interface/super/etc.  They're considered comments by java's code.

 

I think you should show relevant code with this line:

ModelMapper.getBaked(CannonPart.CHASE, "defaultchase")

 

This just grabs the recorded baked model of the part, this case being the chase.  It's returning a model, I know that much, but here's the ModelMapper and Event manager classes.

 

ModelMapper:

 

package com.scors.bioalchemy.render;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;

import com.scors.bioframe.elements.extended.ElementExtendedFrame;

import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.util.Vec3;
import net.minecraftforge.client.model.IFlexibleBakedModel;

public class ModelMapper {

public enum CannonPart { 
	CHASE("chases/"),
	REINFORCE("reinforces/"),
	CHAMBER("chambers/"),
	EXTRA("extras/");

	public final String file;
	CannonPart(String file)
	{
		this.file = file;
	}
}

private static HashMap<String, ModelResourceLocation> chases = new HashMap<String, ModelResourceLocation>();
private static HashMap<String, IFlexibleBakedModel> chasesBaked = new HashMap<String, IFlexibleBakedModel>();
private static HashMap<String, Vec3> chaseOffsets = new HashMap<String, Vec3>();
private static HashMap<String, Float> chaseScales = new HashMap<String, Float>();
private static HashMap<String, ElementExtendedFrame> chaseNatives = new HashMap<String, ElementExtendedFrame>();

private static HashMap<String, ModelResourceLocation> reinforces = new HashMap<String, ModelResourceLocation>();
private static HashMap<String, IFlexibleBakedModel> reinforcesBaked = new HashMap<String, IFlexibleBakedModel>();
private static HashMap<String, Vec3[]> reinforceOffsets = new HashMap<String, Vec3[]>();
private static HashMap<String, Float> reinforceScales = new HashMap<String, Float>();
private static HashMap<String, ElementExtendedFrame> reinforceNatives = new HashMap<String, ElementExtendedFrame>();

private static HashMap<String, ModelResourceLocation> chambers = new HashMap<String, ModelResourceLocation>();
private static HashMap<String, IFlexibleBakedModel> chambersBaked = new HashMap<String, IFlexibleBakedModel>();
private static HashMap<String, Vec3> chamberOffsets = new HashMap<String, Vec3>();
private static HashMap<String, Float> chamberScales = new HashMap<String, Float>();
private static HashMap<String, ElementExtendedFrame> chamberNatives = new HashMap<String, ElementExtendedFrame>();

private static HashMap<String, ModelResourceLocation> extras = new HashMap<String, ModelResourceLocation>();
private static HashMap<String, IFlexibleBakedModel> extrasBaked = new HashMap<String, IFlexibleBakedModel>();
private static HashMap<String, Vec3> extraOffsets = new HashMap<String, Vec3>();
private static HashMap<String, Float> extraScales = new HashMap<String, Float>();
private static HashMap<String, ElementExtendedFrame> extraNatives = new HashMap<String, ElementExtendedFrame>();

public static void addUnbaked(CannonPart part, String name, ModelResourceLocation mrl)
{
	switch(part)
	{
	case CHASE:{
		if(chases.containsKey(name)){return;}
		chases.put(name, mrl);
		break;
	}
	case CHAMBER:{
		if(chambers.containsKey(name)){return;}
		chambers.put(name, mrl);
		break;
	}
	case REINFORCE:{
		if(reinforces.containsKey(name)){return;}
		reinforces.put(name, mrl);
		break;
	}
	case EXTRA:{
		if(extras.containsKey(name)){return;}
		extras.put(name, mrl);
		break;
	}
	default:
		break;
	}
}

public static ModelResourceLocation getUnbaked(CannonPart part, String name)
{
	switch(part)
	{
	case CHASE:{
		return chases.get(name);
	}
	case REINFORCE:{
		return reinforces.get(name);
	}
	case CHAMBER:{
		return chambers.get(name);
	}
	case EXTRA:{
		return extras.get(name);
	}
	default:
		return null;
	}
}

public static Set<String> getKeys(CannonPart part) {
	switch(part)
	{
	case CHAMBER:
		return chambers.keySet();
	case CHASE:
		return chases.keySet();
	case EXTRA:
		return extras.keySet();
	case REINFORCE:
		return reinforces.keySet();
	default:
		return null;
	}
}

public static void addBaked(CannonPart part, String name, IFlexibleBakedModel ifbm)
{
	switch(part)
	{
	case CHAMBER:{
		if(chambersBaked.containsKey(name)){return;}
		chambersBaked.put(name, ifbm);
		break;
	}
	case CHASE: {
		if(chasesBaked.containsKey(name)){return;}
		chasesBaked.put(name, ifbm);
		break;
	}
	case EXTRA:{
		if(extrasBaked.containsKey(name)){return;}
		extrasBaked.put(name, ifbm);
		break;
	}
	case REINFORCE:{
		if(reinforcesBaked.containsKey(name)){return;}
		reinforcesBaked.put(name, ifbm);
		break;
	}
	default:
		break;
	}
}

public static IFlexibleBakedModel getBaked(CannonPart part, String name) {
	switch(part)
	{
	case CHAMBER:
		return chambersBaked.get(name);
	case CHASE:
		return chasesBaked.get(name);
	case EXTRA:
		return extrasBaked.get(name);
	case REINFORCE:
		return reinforcesBaked.get(name);
	default:
		return null;
	}
}

public static void setOffset(CannonPart part, String name, Vec3 vec)
{
	switch(part)
	{
	case CHAMBER:{
		if(chamberOffsets.containsKey(name)){return;}
		chamberOffsets.put(name, vec);
		return;
	}
	case CHASE:{
		if(chaseOffsets.containsKey(name)){return;}
		chaseOffsets.put(name, vec);
	}
	case EXTRA:{
		if(extraOffsets.containsKey(name)){return;}
		extraOffsets.put(name, vec);
	}
	default:{
		return;
	}
	}
}

public static void addReinforceOffsets(String name, Vec3[] vecs)
{
	if(vecs.length < 3)
	{
		System.out.println("Too few vector entries for " + name + "  3 are required.");
		System.out.println("Vector offsets required: Chase, Chamber, Extra");
		return;
	}
	if(reinforceOffsets.containsKey(name)){return;}
	if(vecs.length > 3)
	{
		System.out.println("Detected more than 3 vector entires.  Using the first 3 entries");
	}

	Vec3[] vecos = {vecs[0], vecs[1], vecs[2]};
	reinforceOffsets.put(name, vecos);
}

public static Vec3 getOffset(CannonPart part, String name) {

	switch(part)
	{
	case CHAMBER:{
		if(!chamberOffsets.containsKey(name)){return new Vec3(0,0,0);}
		return chamberOffsets.get(name);
	}
	case CHASE:{
		if(!chaseOffsets.containsKey(name)){return new Vec3(0,0,0);}
		return chaseOffsets.get(name);
	}
	case EXTRA:{
		if(extraOffsets.containsKey(name)){return new Vec3(0,0,0);}
		return extraOffsets.get(name);
	}
	default:
		return new Vec3(0,0,0);

	}
}

public static Vec3[] getReinforceOffset(String name)
{
	if(!reinforceOffsets.containsKey(name))
	{
		Vec3[] vecos = {new Vec3(0,0,0), new Vec3(0,0,0), new Vec3(0,0,0)};
		return vecos;
	}
	return reinforceOffsets.get(name);
}

public static void setScale(CannonPart part, String name, float scale)
{
	switch(part){
	case CHAMBER:{
		if(chamberScales.containsKey(name)){return;}
		chamberScales.put(name, scale);
		break;
	}
	case CHASE:{
		if(chaseScales.containsKey(name)){return;}
		chaseScales.put(name, scale);
		break;
	}
	case EXTRA:{
		if(extraScales.containsKey(name)){return;}
		extraScales.put(name, scale);
		break;
	}
	case REINFORCE:{
		if(reinforceScales.containsKey(name)){return;}
		reinforceScales.put(name, scale);
		break;
	}
	default:
		break;

	}
}

public static float getScale(CannonPart part, String name)
{
	switch(part)
	{
	case CHAMBER:{
		if(!chamberScales.containsKey(name)){return 1.0F;}
		return chamberScales.get(name);
	}
	case CHASE:{
		if(!chaseScales.containsKey(name)){return 1.0F;}
		return chaseScales.get(name);
	}
	case EXTRA: {
		if(!extraScales.containsKey(name)){return 1.0F;}
		return extraScales.get(name);
	}
	case REINFORCE:{
		if(!reinforceScales.containsKey(name)){return 1.0F;}
		return reinforceScales.get(name);
	}
	default:
		return 1.0F;
	}
}
}

 

 

 

Event Manager:

 

package com.scors.bioalchemy.event;

import com.scors.bioalchemy.render.ArmCannonSmartModel;
import com.scors.bioalchemy.render.ModelMapper;
import com.scors.bioalchemy.render.ModelMapper.CannonPart;

import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.model.IFlexibleBakedModel;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class AlchEventManager {

@SubscribeEvent
public void onModelBakeEvent(ModelBakeEvent event)
{
	System.out.println("Model Bake event triggered");
	Object object = event.modelRegistry.getObject(ArmCannonSmartModel.mrl);
	if(object instanceof IBakedModel)
	{
		IBakedModel existingModel = (IBakedModel)object;
		ArmCannonSmartModel customModel = new ArmCannonSmartModel(existingModel);
		event.modelRegistry.putObject(ArmCannonSmartModel.mrl, customModel);
	}

	for(String str:ModelMapper.getKeys(CannonPart.CHASE))
	{
		ModelResourceLocation mrl = ModelMapper.getUnbaked(CannonPart.CHASE, str);
		Object obj = event.modelRegistry.getObject(mrl);
		if(obj instanceof IFlexibleBakedModel)
		{
			ModelMapper.addBaked(CannonPart.CHASE, str, (IFlexibleBakedModel)obj);
		}
	}

	for(String str:ModelMapper.getKeys(CannonPart.REINFORCE))
	{
		ModelResourceLocation mrl = ModelMapper.getUnbaked(CannonPart.REINFORCE, str);
		Object obj = event.modelRegistry.getObject(mrl);
		if(obj instanceof IFlexibleBakedModel)
		{
			ModelMapper.addBaked(CannonPart.REINFORCE, str, (IFlexibleBakedModel)obj);
		}
	}

	for(String str:ModelMapper.getKeys(CannonPart.CHAMBER))
	{
		ModelResourceLocation mrl = ModelMapper.getUnbaked(CannonPart.REINFORCE, str);
		Object obj = event.modelRegistry.getObject(mrl);
		if(obj instanceof IFlexibleBakedModel)
		{
			ModelMapper.addBaked(CannonPart.CHAMBER, str, (IFlexibleBakedModel)obj);
		}
	}

	for(String str:ModelMapper.getKeys(CannonPart.EXTRA))
	{
		ModelResourceLocation mrl = ModelMapper.getUnbaked(CannonPart.REINFORCE, str);
		Object obj = event.modelRegistry.getObject(mrl);
		if(obj instanceof IFlexibleBakedModel)
		{
			ModelMapper.addBaked(CannonPart.EXTRA, str, (IFlexibleBakedModel)obj);
		}
	}
}

}

 

Posted

You should register model names.

Only item name itself automatically registered as model name.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

All of those

// TODO Auto-generated method stub

might be the problem.

Those are generated by Eclipse when bringing in methods from an interface/super/etc.  They're considered comments by java's code.

 

I think he knows what a comment is... I guess his point is that you might want to implement them.

If my post helped you, please press that "Thank You"-button to show your appreciation.

 

Also if you don't know Java, I would suggest you read the official tutorials by Oracle to get an idea of how to do this. Thanks, and good modding!

 

Also if you haven't, set up a Git repo for your mod not only for convinience but also to make it easier to help you.

Posted

All of those

// TODO Auto-generated method stub

might be the problem.

Those are generated by Eclipse when bringing in methods from an interface/super/etc.  They're considered comments by java's code.

 

I think he knows what a comment is... I guess his point is that you might want to implement them.

 

I don't doubt he knows what a comment is, but I elaborated because I have no idea if he uses Eclipse or not.  :)

Also, they are implemented from the MinecraftByExample ( MBE15 )

 

You should register model names.

Only item name itself automatically registered as model name.

 

Model Names and such are registered via AlchItems...

I also threw in an addVariantName just to see if it would help, but it didn't...

 

package com.scors.bioalchemy.items;

import com.scors.bioalchemy.BioAlchemy;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class AlchItems {

public static ItemArmCannon itemArmCannon;
public static ItemCannonChase itemChase;
public static ItemCannonChamber itemChamber;
public static ItemCannonReinforce itemReinforce;
public static ItemCannonExtra itemExtra;

public static void initItems()
{
	System.out.println("Initing items");
	itemArmCannon = (ItemArmCannon)(new ItemArmCannon().setUnlocalizedName("armcannon"));
	itemChase = (ItemCannonChase)(new ItemCannonChase().setUnlocalizedName("itemchase"));
	itemChamber = (ItemCannonChamber)(new ItemCannonChamber().setUnlocalizedName("itemchamber"));
	itemReinforce = (ItemCannonReinforce)(new ItemCannonReinforce().setUnlocalizedName("itemreinforce"));
	itemExtra = (ItemCannonExtra)(new ItemCannonExtra().setUnlocalizedName("itemextra"));

	GameRegistry.registerItem(itemArmCannon, "armcannon");
	GameRegistry.registerItem(itemChase, "itemchase");
	GameRegistry.registerItem(itemChamber, "itemchamber");
	GameRegistry.registerItem(itemReinforce, "itemreinforce");
	GameRegistry.registerItem(itemExtra, "itemextra");
}

@SideOnly(Side.CLIENT)
public static void preInitItemRenders()
{
	ModelBakery.addVariantName(itemChase, BioAlchemy.modid+":chases/defaultchase");
	ModelBakery.addVariantName(itemChamber, BioAlchemy.modid+":chambers/defaultchamber");

	ModelBakery.addVariantName(itemArmCannon, BioAlchemy.modid+":armcannon", 
			BioAlchemy.modid +":chases/defaultchase");
}

@SideOnly(Side.CLIENT)
public static void initItemRenders()
{
	System.out.println("Initing Item Renders");
	registerRenderInv(itemArmCannon, "armcannon");
	registerRenderInv(itemChase, "chases/defaultchase");
}

public static void registerRenderInv(Item item, String name)
{
	registerRender(item, 0, name, "inventory");
}

public static void registerRender(Item item, int meta, String name, String location)
{
	ModelResourceLocation mrl = new ModelResourceLocation(BioAlchemy.modid+":"+name, location);
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, mrl);
}

}

The initItems() is called in the common proxy's preInit() field.

 

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.