Jump to content

Recommended Posts

Posted

I put a print inside of my entity's update method to check if they are in the world and it is being called.

 

Render:

package enlistment.render.entity;

import org.lwjgl.opengl.GL11;

import enlistment.Enlistment;
import enlistment.entity.EntityTroop;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.client.renderer.entity.layers.LayerArrow;
import net.minecraft.client.renderer.entity.layers.LayerBipedArmor;
import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;

public class RenderTroop extends RendererLivingEntity {
public static final ResourceLocation TROOP_TEXTURE = new ResourceLocation(Enlistment.ID + ":textures/entity/troop.png");

public RenderTroop() {
	super(Minecraft.getMinecraft().getRenderManager(), new ModelBiped(1F), 1F);

	this.addLayer(new LayerBipedArmor(this));
	this.addLayer(new LayerHeldItem(this));
	this.addLayer(new LayerArrow(this));
}

@Override
protected void preRenderCallback(EntityLivingBase entity, float f) {
	if(entity instanceof EntityTroop) {
		EntityTroop troop = (EntityTroop) entity;

		GL11.glScalef(1F, 1F, 1F);
	}
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return TROOP_TEXTURE;
	/*
	if(entity instanceof EntityTroop) {
		EntityTroop troop = (EntityTroop) entity;

		switch(troop.getTier()) {
		case (69):
			return null;
		default:
			return TROOP_TEXTURE;
		}
	}

	return null;

	*/
}
}

 

Entity:

package enlistment.entity;

import java.util.UUID;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.ai.EntityAIWatchClosest2;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

public class EntityTroop extends EntityCreature {
protected FoodStatsTroop foodStats = new FoodStatsTroop();
protected int tier;
protected boolean hired = false;
protected int morale;
protected int relationWithPlayer;
protected boolean stationary = false;

public EntityTroop(World world) {
	super(world);

	this.setSize(0.6F, 1.95F);
	this.setCanPickUpLoot(false);

	applyEntityAI();
}

public EntityTroop(World world, boolean hired) {
	this(world);

	this.hired = hired;
}

@Override
protected void entityInit() {
	super.entityInit();

	this.dataWatcher.addObject(17, "");
}

protected void applyEntityAI() {
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(5, new EntityAITroopFollow(this, 1.0D, 10.0F, 2.0F));
	this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3F, 1F));
	this.tasks.addTask(9, new EntityAIWander(this, 0D));
	this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8F));
	this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityMob.class, 1D, true));
	this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1D, false));
	this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityMob.class, true));
}

protected void applyEntityAttributes() {
	super.applyEntityAttributes();

	this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(16D);
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10D);
	this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(35D);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.1D);
	this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1D);

	this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(1D);
}

@Override
public void onLivingUpdate() {
	super.onLivingUpdate();

	if(getFoodStats().needFood() && this.ticksExisted % 10 == 0) {
		getFoodStats().setFoodLevel(this.foodStats.getFoodLevel() + 1);
	}
}

@Override
public void onUpdate() {
	super.onUpdate();

	if(!this.worldObj.isRemote) {
		System.out.println("Hi! I'm here at X: " + this.posX + ", Z: " + this.posZ);

		getFoodStats().onUpdate(this);
	}
}

@Override
public void readEntityFromNBT(NBTTagCompound comp) {
	super.readEntityFromNBT(comp);

	foodStats.readNBT(comp);

	NBTTagCompound nbt = comp.getCompoundTag("Enlistment_NBT");

	setTier(nbt.getInteger("Tier"));
	setHired(nbt.getBoolean("Hired"));
	setMorale(nbt.getInteger("Morale"));
	setRelationWithPlayer(nbt.getInteger("Relation_with_Player"));
	setOwnerID(nbt.getString("Owner_ID"));
	setStationary(nbt.getBoolean("Stationary"));
}

@Override
public void writeEntityToNBT(NBTTagCompound comp) {
	super.writeEntityToNBT(comp);

	foodStats.writeNBT(comp);

	NBTTagCompound nbt = comp.getCompoundTag("Enlistment_NBT");

	nbt.setInteger("Tier", tier);
	nbt.setBoolean("Hired", hired);
	nbt.setInteger("Morale", morale);
	nbt.setInteger("Relation_with_Player", relationWithPlayer);
	nbt.setString("Owner_ID", getOwnerID());
	nbt.setBoolean("Stationary", isStationary());

	comp.setTag("Enlistment_NBT", nbt);
}

@Override
public boolean interact(EntityPlayer player) {
	if(getOwnerID().equals("")) {
		setOwnerID(player.getUniqueID().toString());

		return true;
	} else if(getOwnerID().equals(player.getUniqueID().toString())) {
		setStationary(!isStationary());

		return true;
	}

	return super.interact(player);
}

@Override
public boolean attackEntityFrom(DamageSource src, float par2) {
	if(this.isEntityInvulnerable(src)) {
		return false;
	} else {
		//retalliate

		return super.attackEntityFrom(src, par2);
	}
}

public boolean canEat() {
	return getFoodStats().needFood();
}

public boolean shouldHeal() {
	return this.getHealth() > 0.0F && this.getHealth() < this.getMaxHealth();
}

public void upgradeTier() {
	setTier(getTier() + 1);

	System.out.println("Troop #" + this.getEntityId() + " has ranked up!");

	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(1D + (2D * tier));
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10D + (7.5D * tier));
}

@Override
protected String getHurtSound() {
	return "game.player.hurt";
}

@Override
protected String getDeathSound() {
	return "game.player.die";
}

public String getOwnerID() {
	return this.dataWatcher.getWatchableObjectString(17);
}

public void setOwnerID(String ownerUuid) {
	this.dataWatcher.updateObject(17, ownerUuid);
}

public EntityPlayer getOwner() {
	try {
		UUID uuid = UUID.fromString(getOwnerID());

		return uuid == null ? null : this.worldObj.getPlayerEntityByUUID(uuid);
	} catch(IllegalArgumentException illegalargumentexception) {
		return null;
	}
}

public FoodStatsTroop getFoodStats() {
	return foodStats;
}

public void setFoodStats(FoodStatsTroop foodStats) {
	this.foodStats = foodStats;
}

public int getTier() {
	return tier;
}

public void setTier(int tier) {
	this.tier = tier;
}

public boolean isHired() {
	return hired;
}

public void setHired(boolean hired) {
	this.hired = hired;
}

public int getMorale() {
	return morale;
}

public void setMorale(int morale) {
	this.morale = morale;
}

public int getRelationWithPlayer() {
	return relationWithPlayer;
}

public void setRelationWithPlayer(int relationWithPlayer) {
	this.relationWithPlayer = relationWithPlayer;
}

public boolean isStationary() {
	return stationary;
}

public void setStationary(boolean stationary) {
	this.stationary = stationary;
}
}

 

Sorry if I sound vague, I am completely in the dark myself when it comes to rendering.

Kain

Posted

Yes

 

EntityHandler:

package enlistment.entity;

import enlistment.Enlistment;
import enlistment.render.entity.RenderTroop;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityHandler {
public static void init() {
	registerEntity(EntityTroop.class, "Troop");
}

@SideOnly(Side.CLIENT)
public static void initRenders() {
	RenderingRegistry.registerEntityRenderingHandler(EntityTroop.class, new RenderTroop());
}

private static void registerEntity(Class<? extends EntityLiving> clazz, String name) {
	EntityRegistry.registerGlobalEntityID(clazz, name, EntityRegistry.findGlobalUniqueEntityId());
	EntityRegistry.addSpawn(clazz, 100, 6, 8, EnumCreatureType.CREATURE, BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.desert, BiomeGenBase.desertHills, BiomeGenBase.forestHills);
	Enlistment.instance.entities.add(name, clazz);
}
}

Kain

Posted

initRenders()

isn't called anywhere in code you have posted.

 

Just because you wrote this method doesn't mean its magically called.

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

It's called in my ClientProxy, which in turn is called client-side from my mod class, which extends an abstract class that automatically calls the proxy.

 

ClientProxy:

package enlistment.network;

import enlistment.entity.EntityHandler;
import enlistment.gui.GuiTroopsOverlay;
import net.minecraftforge.common.MinecraftForge;

public class ClientProxy extends ServerProxy {
@Override
public void init() {
	super.init();

	MinecraftForge.EVENT_BUS.register(new GuiTroopsOverlay());

	EntityHandler.initRenders();
}
}

 

The overlay that is also registered is being rendered.

Kain

Posted

Let's get more output, like the coords of the entity when it updates and prints status. Turn on bounding boxes too, so you can "see" it even if it's not rendered. What are your symptoms exactly?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Let's get more output, like the coords of the entity when it updates and prints status. Turn on bounding boxes too, so you can "see" it even if it's not rendered. What are your symptoms exactly?

 

I'm an idiot. The render isn't being called at all, even though it's registered.

 

Render:

package enlistment.render.entity;

import org.lwjgl.opengl.GL11;

import enlistment.Enlistment;
import enlistment.entity.EntityTroop;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.client.renderer.entity.layers.LayerArrow;
import net.minecraft.client.renderer.entity.layers.LayerBipedArmor;
import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;

public class RenderTroop extends RendererLivingEntity {
public static final ResourceLocation TROOP_TEXTURE = new ResourceLocation(Enlistment.ID + ":textures/entity/troop.png");

public RenderTroop() {
	super(Minecraft.getMinecraft().getRenderManager(), new ModelBiped(1F) {
		@Override
		public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) {
			super.render(entityIn, p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale);

			System.out.println("RENDERING TROOP MODEL AT X: " + entityIn.posX + ", Y: " + entityIn.posY + ", Z: " + entityIn.posZ);
		}
	}, 1F);

	this.addLayer(new LayerBipedArmor(this));
	this.addLayer(new LayerHeldItem(this));
	this.addLayer(new LayerArrow(this));
}

@Override
protected void preRenderCallback(EntityLivingBase entity, float f) {
	if(entity instanceof EntityTroop) {
		EntityTroop troop = (EntityTroop) entity;

		GL11.glScalef(1F, 1F, 1F);

		System.out.println("PRE-RENDERING TROOP AT X: " + troop.posX + ", Y: " + troop.posY + ", Z: " + troop.posZ);
	}
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return TROOP_TEXTURE;
	/*
	if(entity instanceof EntityTroop) {
		EntityTroop troop = (EntityTroop) entity;

		switch(troop.getTier()) {
		case (69):
			return null;
		default:
			return TROOP_TEXTURE;
		}
	}

	return null;

	*/
}
}

Kain

Posted

Why so you have a function inside your super call?

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

Why so you have a function inside your super call?

 

If you mean the ModelBiped function, I overrode it so I could put the print in to check if it was rendering. I also called the super so that it would render the model if it did, which it didn't.

Kain

Posted

mo, your RenderTroop constructor.

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

mo, your RenderTroop constructor.

 

Do you mean this?

Minecraft.getMinecraft().getRenderManager()

 

I didn't know which render manager to get, so I figured the Minecraft class had an instance of it.

 

 

Also if you mean this:

this.addLayer(new LayerBipedArmor(this));
	this.addLayer(new LayerHeldItem(this));
	this.addLayer(new LayerArrow(this));

 

I plan on making the entity equip armor and hold items.

Kain

Posted

No.

 

	public RenderTroop() {

		super(Minecraft.getMinecraft().getRenderManager(), new ModelBiped(1F) {

@Override

			

public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) {

				

super.render(entityIn, p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale);

				

System.out.println("RENDERING TROOP MODEL AT X: " + entityIn.posX + ", Y: " + entityIn.posY + ", Z: " + entityIn.posZ);

			

}

		}, 1F);

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

No.

 

	public RenderTroop() {

		super(Minecraft.getMinecraft().getRenderManager(), new ModelBiped(1F) {

@Override

			

public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) {

				

super.render(entityIn, p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale);

				

System.out.println("RENDERING TROOP MODEL AT X: " + entityIn.posX + ", Y: " + entityIn.posY + ", Z: " + entityIn.posZ);

			

}

		}, 1F);

 

That's an anonymous class that extends

ModelBiped

and overrides

render

. It's what TLHPoE was referring to in this post:

 

Why so you have a function inside your super call?

 

If you mean the ModelBiped function, I overrode it so I could put the print in to check if it was rendering. I also called the super so that it would render the model if it did, which it didn't.

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

Ah. Well. As long as it is being used correctly.

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

Upon further research I discovered some past problems with rendering entities in 1.8 that were fixed by registering the renderers after the pre-initialization stage. I moved my entity renderer registerings to the initialization stage, but nothing changed.

Kain

Posted

I have Mine and Blade: Battlegear 2 installed and it patched the ModelBiped class. I removed it to see if it caused anything, nope.

 

I'm going to try to make my own biped model to render.

Kain

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.