Jump to content

[1.10.2] Custom Lead Entity Won't Render (unsolved)


Recommended Posts

Posted

I am having trouble seeing my custom entity. I register the renders and entity, the entity spawns in the world (/testfor @e and place sound effect indicates that) but it is completely invisible. Most of the code was copied from default since there are not a lot of custom lead entity examples out there...

 

Teh code:

Entities.java

package net.creativerealmsmc.conquest.init;

import net.creativerealmsmc.conquest.Main;
import net.creativerealmsmc.conquest.entity.EntityRopeKnot;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderLeashKnot;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;

public class Entities {
//	https://github.com/micdoodle8/Galacticraft/tree/master/src/main/java/micdoodle8/mods/galacticraft/core/entities
//https://github.com/micdoodle8/Galacticraft/blob/edab080014e1ad2603d0555a6449567c41f7560a/src/main/java/micdoodle8/mods/galacticraft/core/util/GCCoreUtil.java
public static void init() {
	registerEntity(EntityRopeKnot.class, "Rope", ;

}

//	/RenderingRegistry.registerEntityRenderingHandler(EntityEvolvedSkeleton.class, (RenderManager manager) -> new RenderEvolvedSkeleton(manager));
public static void register() {
	//registerBlock(sample);

	/* EntityList.idToClassMapping.put(nextEggID, var0); EntityList.classToIDMapping.put(var0, nextEggID); EntityList.entityEggs.put(nextEggID, new EntityList.EntityEggInfo(nextEggID, back, fore)); */
}

public static void registerRenders() {/*
	RenderingRegistry.registerEntityRenderingHandler(EntityRopeKnot.class, new IRenderFactory() {
		@Override
		public Render createRenderFor(RenderManager manager) {
			return new RenderLeashKnot(manager);
		}
	});*/
	RenderingRegistry.registerEntityRenderingHandler(EntityRopeKnot.class, new RenderLeashKnot(Minecraft.getMinecraft().getRenderManager()));
}

public static void registerEntity(Class entityClass, String name, int id) {
	//EntityRegistry.registerGlobalEntityID(entityClass, name, EntityRegistry.findGlobalUniqueEntityId());
	EntityRegistry.registerModEntity(entityClass, name, id, Main.instance, 64, 3, false);
	//
	//EntityRegistry.registerModEntity(var0, var1, nextInternalID(), GalacticraftCore.instance, trackingDistance, updateFreq, sendVel);
}
}

CommonProxy.java

package net.creativerealmsmc.conquest.proxy;

import net.creativerealmsmc.conquest.init.Blocks;
import net.creativerealmsmc.conquest.init.Entities;
import net.creativerealmsmc.conquest.init.Items;
import net.creativerealmsmc.conquest.init.MetaBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public abstract class CommonProxy
{
public void preInit(FMLPreInitializationEvent e)
{
	Entities.init();
	MetaBlocks.init();
	MetaBlocks.register();
}

public void init(FMLInitializationEvent e)
{
	Blocks.init();
	Blocks.register();
	Items.init();
	Items.register();
}

public void postInit(FMLPostInitializationEvent e)
{

}

abstract public boolean playerIsInCreativeMode(EntityPlayer player);
abstract public boolean isDedicatedServer();
}

ClientProxy.java

package net.creativerealmsmc.conquest.proxy;

import net.creativerealmsmc.conquest.Main;
import net.creativerealmsmc.conquest.init.Blocks;
import net.creativerealmsmc.conquest.init.Entities;
import net.creativerealmsmc.conquest.init.Items;
import net.creativerealmsmc.conquest.init.MetaBlocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public class ClientProxy extends CommonProxy
{
@Override
public void preInit(FMLPreInitializationEvent e)
{
	super.preInit(e);
	Entities.registerRenders();
	MetaBlocks.registerRenders();
	OBJLoader.INSTANCE.addDomain(Main.MODID);
}

@Override
public void init(FMLInitializationEvent e)
{
	super.init(e);
	MetaBlocks.registerRendersNoMeta();
	Items.registerRenders();
}

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

@Override
public boolean playerIsInCreativeMode(EntityPlayer player)
{
	if (player instanceof EntityPlayerMP)
    {
		EntityPlayerMP entityPlayerMP = (EntityPlayerMP)player;
		return entityPlayerMP.interactionManager.isCreative();
    }
	else if (player instanceof EntityPlayerSP)
    {
		return Minecraft.getMinecraft().playerController.isInCreativeMode();
    }
    return false;
}

@Override
public boolean isDedicatedServer()
{
	return false;
}
}

EntityRopeKnot.java

package net.creativerealmsmc.conquest.entity;

import java.util.UUID;

import javax.annotation.Nullable;

import com.google.common.base.Predicate;
import net.minecraft.block.BlockFence;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityHanging;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.server.SPacketEntityAttach;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityRopeKnot extends Entity {

public EntityRopeKnot(World worldIn) {
	super(worldIn);
	this.setSize(0.5F, 0.5F);

}

public EntityRopeKnot(World worldIn, BlockPos hangingPositionIn) {
	this(worldIn);
	this.hangingPosition = hangingPositionIn;

	this.setPosition((double) hangingPositionIn.getX() + 0.5D, (double) hangingPositionIn.getY() + 0.5D, (double) hangingPositionIn.getZ() + 0.5D);
	/* float f = 0.125F; float f1 = 0.1875F; float f2 = 0.25F; */
	this.setEntityBoundingBox(new AxisAlignedBB(this.posX - 0.1875D, this.posY - 0.25D + 0.125D, this.posZ - 0.1875D, this.posX + 0.1875D, this.posY + 0.25D + 0.125D, this.posZ + 0.1875D));
}

private boolean isLeashed;
private Entity leashedToEntity;
private NBTTagCompound leashNBTTag;

//TODO: implemented Entity methods
/** Get whether this Entity's AI is disabled */
/*public boolean isAIDisabled() {
	return true;
}*/

@Override
protected void entityInit() {}

//TODO: Entity Leash

/** Sets the x,y,z of the entity from the given parameters. Also seems to set up a bounding box. */
public void setPosition(double x, double y, double z) {
	x = (double) MathHelper.floor_double(x) + 0.5D;
	y = (double) MathHelper.floor_double(y) + 0.5D;
	z = (double) MathHelper.floor_double(z) + 0.5D;
	//super:
	this.hangingPosition = new BlockPos(x, y, z);
	this.updateBoundingBox();
	this.isAirBorne = true;
}

/** Updates the entity bounding box based on current facing */
protected void updateBoundingBox() {
	this.posX = (double) this.hangingPosition.getX() + 0.5D;
	this.posY = (double) this.hangingPosition.getY() + 0.5D;
	this.posZ = (double) this.hangingPosition.getZ() + 0.5D;
}

/** Updates facing and bounding box based on it */
public void updateFacingWithBoundingBox(EnumFacing facingDirectionIn) {}

public int getWidthPixels() {
	return 9;
}

public int getHeightPixels() {
	return 9;
}

public float getEyeHeight() {
	return -0.0625F;
}

/** Checks if the entity is in range to render. */
@SideOnly(Side.CLIENT)
public boolean isInRangeToRenderDist(double distance) {
	return distance < 1024.0D;
}

/** Called when this entity is broken. Entity parameter may be null. */
public void onBroken(@Nullable Entity brokenEntity) {
	this.playSound(SoundEvents.ENTITY_LEASHKNOT_BREAK, 1.0F, 1.0F);
}

/** Either write this entity to the NBT tag given and return true, or return false without doing anything. If this returns false the entity is not saved on disk. Ridden entities return false here as they are saved with their rider. */
public boolean writeToNBTOptional(NBTTagCompound compound) {
	return false;
}

public boolean processInitialInteractLeash(EntityPlayer player, @Nullable ItemStack stack, EnumHand hand) //custom, changed name
{
	if (this.worldObj.isRemote) {
		return true;
	} else {
		boolean flag = false;

		if (stack != null && stack.getItem() == Items.LEAD) {
			for (EntityLiving entityliving : this.worldObj.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(this.posX - 7.0D, this.posY - 7.0D, this.posZ - 7.0D, this.posX + 7.0D, this.posY + 7.0D, this.posZ + 7.0D))) {
				if (entityliving.getLeashed() && entityliving.getLeashedToEntity() == player) {
					entityliving.setLeashedToEntity(this, true);
					flag = true;
				}
			}
		}

		if (!flag) {
			this.setDead();

			if (player.capabilities.isCreativeMode) {
				for (EntityLiving entityliving1 : this.worldObj.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(this.posX - 7.0D, this.posY - 7.0D, this.posZ - 7.0D, this.posX + 7.0D, this.posY + 7.0D, this.posZ + 7.0D))) {
					if (entityliving1.getLeashed() && entityliving1.getLeashedToEntity() == this) {
						entityliving1.clearLeashed(true, false);
					}
				}
			}
		}

		return true;
	}
}

/** checks to make sure painting can be placed there */
public boolean onValidSurface() {
	return this.worldObj.getBlockState(this.hangingPosition).getBlock() instanceof BlockFence;
}

public static EntityRopeKnot createKnot(World worldIn, BlockPos fence) {
	EntityRopeKnot entityleashknot = new EntityRopeKnot(worldIn, fence);
	entityleashknot.forceSpawn = true;
	worldIn.spawnEntityInWorld(entityleashknot);
	entityleashknot.playPlaceSound();
	return entityleashknot;
}

public static EntityRopeKnot getKnotForPosition(World worldIn, BlockPos pos) {
	int i = pos.getX();
	int j = pos.getY();
	int k = pos.getZ();

	for (EntityRopeKnot entityleashknot : worldIn.getEntitiesWithinAABB(EntityRopeKnot.class, new AxisAlignedBB((double) i - 1.0D, (double) j - 1.0D, (double) k - 1.0D, (double) i + 1.0D, (double) j + 1.0D, (double) k + 1.0D))) {
		if (entityleashknot.getHangingPosition().equals(pos)) {
			return entityleashknot;
		}
	}

	return null;
}

public void playPlaceSound() {
	this.playSound(SoundEvents.ENTITY_LEASHKNOT_PLACE, 1.0F, 1.0F);
}

//TODO: Entity Hanging

private static final Predicate<Entity> IS_HANGING_ENTITY = new Predicate<Entity>() {
	public boolean apply(@Nullable Entity p_apply_1_) {
		return p_apply_1_ instanceof EntityHanging;
	}
};
private int tickCounter1;
protected BlockPos hangingPosition;
/** The direction the entity is facing */
@Nullable
public EnumFacing facingDirection;

private double func_190202_a(int p_190202_1_) {
	return p_190202_1_ % 32 == 0 ? 0.5D : 0.0D;
}

/** Returns true if other Entities should be prevented from moving through this Entity. */
public boolean canBeCollidedWith() {
	return true;
}

/** Called when a player attacks an entity. If this returns true the attack will not happen. */
public boolean hitByEntity(Entity entityIn) {
	return entityIn instanceof EntityPlayer ? this.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityIn), 0.0F) : false;
}

/** Gets the horizontal facing direction of this Entity. */
public EnumFacing getHorizontalFacing() {
	return this.facingDirection;
}

/** Called when the entity is attacked. */
public boolean attackEntityFrom(DamageSource source, float amount) {
	if (this.isEntityInvulnerable(source)) {
		return false;
	} else {
		if (!this.isDead && !this.worldObj.isRemote) {
			this.setDead();
			this.setBeenAttacked();
			this.onBroken(source.getEntity());
		}

		return true;
	}
}

/** Tries to move the entity towards the specified location. */
public void moveEntity(double x, double y, double z) {
	if (!this.worldObj.isRemote && !this.isDead && x * x + y * y + z * z > 0.0D) {
		this.setDead();
		this.onBroken((Entity) null);
	}
}

/** Adds to the current velocity of the entity. */
public void addVelocity(double x, double y, double z) {
	if (!this.worldObj.isRemote && !this.isDead && x * x + y * y + z * z > 0.0D) {
		this.setDead();
		this.onBroken((Entity) null);
	}
}

/** (abstract) Protected helper method to write subclass entity data to NBT. */
/* public void writeEntityToNBT(NBTTagCompound compound) { compound.setByte("Facing", (byte)this.facingDirection.getHorizontalIndex()); BlockPos blockpos = this.getHangingPosition(); compound.setInteger("TileX", blockpos.getX()); compound.setInteger("TileY", blockpos.getY()); compound.setInteger("TileZ", blockpos.getZ()); } */

/** (abstract) Protected helper method to read subclass entity data from NBT. */
/* public void readEntityFromNBT(NBTTagCompound compound) { this.hangingPosition = new BlockPos(compound.getInteger("TileX"), compound.getInteger("TileY"), compound.getInteger("TileZ")); this.updateFacingWithBoundingBox(EnumFacing.getHorizontal(compound.getByte("Facing"))); } */

/** Called when this entity is broken. Entity parameter may be null. */

/** Drops an item at the position of the entity. */
public EntityItem entityDropItem(ItemStack stack, float offsetY) {
	EntityItem entityitem = new EntityItem(this.worldObj, this.posX + (double) ((float) this.facingDirection.getFrontOffsetX() * 0.15F), this.posY + (double) offsetY, this.posZ + (double) ((float) this.facingDirection.getFrontOffsetZ() * 0.15F), stack);
	entityitem.setDefaultPickupDelay();
	this.worldObj.spawnEntityInWorld(entityitem);
	return entityitem;
}

protected boolean shouldSetPosAfterLoading() {
	return false;
}

public BlockPos getHangingPosition() {
	return this.hangingPosition;
}

/** Transforms the entity's current yaw with the given Rotation and returns it. This does not have a side-effect. */
@SuppressWarnings("incomplete-switch")
public float getRotatedYaw(Rotation transformRotation) {
	if (this.facingDirection != null && this.facingDirection.getAxis() != EnumFacing.Axis.Y) {
		switch (transformRotation) {
		case CLOCKWISE_180:
			this.facingDirection = this.facingDirection.getOpposite();
			break;
		case COUNTERCLOCKWISE_90:
			this.facingDirection = this.facingDirection.rotateYCCW();
			break;
		case CLOCKWISE_90:
			this.facingDirection = this.facingDirection.rotateY();
		}
	}

	float f = MathHelper.wrapDegrees(this.rotationYaw);

	switch (transformRotation) {
	case CLOCKWISE_180:
		return f + 180.0F;
	case COUNTERCLOCKWISE_90:
		return f + 90.0F;
	case CLOCKWISE_90:
		return f + 270.0F;
	default:
		return f;
	}
}

/** Transforms the entity's current yaw with the given Mirror and returns it. This does not have a side-effect. */
public float getMirroredYaw(Mirror transformMirror) {
	return this.getRotatedYaw(transformMirror.toRotation(this.facingDirection));
}

/** Called when a lightning bolt hits the entity. */
public void onStruckByLightning(EntityLightningBolt lightningBolt) {}

//TODO: LEASHES

/** Called to update the entity's position/logic. */
public void onUpdate() {
	this.prevPosX = this.posX;
	this.prevPosY = this.posY;
	this.prevPosZ = this.posZ;

	if (this.tickCounter1++ == 100 && !this.worldObj.isRemote) {
		this.tickCounter1 = 0;

		if (!this.isDead && !this.onValidSurface()) {
			this.setDead();
			this.onBroken((Entity) null);
		}
	}
	//endsuper hanging entity
	if (!this.worldObj.isRemote) {
		this.updateLeashedState();

	}
}

/** (abstract) Protected helper method to write subclass entity data to NBT. */
public void writeEntityToNBT(NBTTagCompound compound) {
	compound.setBoolean("Leashed", this.isLeashed);

	if (this.leashedToEntity != null) {
		NBTTagCompound nbttagcompound2 = new NBTTagCompound();

		if (this.leashedToEntity instanceof EntityLivingBase) {
			UUID uuid = this.leashedToEntity.getUniqueID();
			nbttagcompound2.setUniqueId("UUID", uuid);
		} else if (this.leashedToEntity instanceof EntityHanging) {
			BlockPos blockpos = ((EntityHanging) this.leashedToEntity).getHangingPosition();
			nbttagcompound2.setInteger("X", blockpos.getX());
			nbttagcompound2.setInteger("Y", blockpos.getY());
			nbttagcompound2.setInteger("Z", blockpos.getZ());
		}

		compound.setTag("Leash", nbttagcompound2);
	}

}

/** (abstract) Protected helper method to read subclass entity data from NBT. */
@Override
public void readEntityFromNBT(NBTTagCompound compound) {

	this.isLeashed = compound.getBoolean("Leashed");

	if (this.isLeashed && compound.hasKey("Leash", 10)) {
		this.leashNBTTag = compound.getCompoundTag("Leash");
	}

}

public final boolean processInitialInteract(EntityPlayer player, @Nullable ItemStack stack, EnumHand hand) {
	if (this.getLeashed() && this.getLeashedToEntity() == player) {
		this.clearLeashed(true, !player.capabilities.isCreativeMode);
		return true;
	} else if (stack != null && stack.getItem() == Items.LEAD && this.canBeLeashedTo(player)) {
		this.setLeashedToEntity(player, true);
		--stack.stackSize;
		return true;
	} else {
		return this.processInteract(player, hand, stack) ? true : super.processInitialInteract(player, stack, hand);
	}
}

protected boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack) {
	return processInitialInteractLeash(player, stack, hand);
}

/** Applies logic related to leashes, for example dragging the entity or breaking the leash. */
protected void updateLeashedState() {
	if (this.leashNBTTag != null) {
		this.recreateLeash();
	}

	if (this.isLeashed) {
		if (!this.isEntityAlive()) {
			this.clearLeashed(true, true);
		}

		if (this.leashedToEntity == null || this.leashedToEntity.isDead) {
			this.clearLeashed(true, true);
		}
	}
}

/** Removes the leash from this entity */
public void clearLeashed(boolean sendPacket, boolean dropLead) {
	if (this.isLeashed) {
		this.isLeashed = false;
		this.leashedToEntity = null;

		if (!this.worldObj.isRemote && dropLead) {
			this.dropItem(Items.LEAD, 1);
		}

		if (!this.worldObj.isRemote && sendPacket && this.worldObj instanceof WorldServer) {
			((WorldServer) this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new SPacketEntityAttach(this, (Entity) null));
		}
	}
}

public boolean canBeLeashedTo(EntityPlayer player) {
	return !this.getLeashed() && !(this instanceof IMob);
}

public boolean getLeashed() {
	return this.isLeashed;
}

public Entity getLeashedToEntity() {
	return this.leashedToEntity;
}

/** Sets the entity to be leashed to. */
public void setLeashedToEntity(Entity entityIn, boolean sendAttachNotification) {
	this.isLeashed = true;
	this.leashedToEntity = entityIn;

	if (!this.worldObj.isRemote && sendAttachNotification && this.worldObj instanceof WorldServer) {
		((WorldServer) this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new SPacketEntityAttach(this, this.leashedToEntity));
	}

	if (this.isRiding()) {
		this.dismountRidingEntity();
	}
}

private void recreateLeash() {
	if (this.isLeashed && this.leashNBTTag != null) {
		if (this.leashNBTTag.hasUniqueId("UUID")) {
			UUID uuid = this.leashNBTTag.getUniqueId("UUID");

			for (EntityLivingBase entitylivingbase : this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox().expandXyz(10.0D))) {
				if (entitylivingbase.getUniqueID().equals(uuid)) {
					this.leashedToEntity = entitylivingbase;
					break;
				}
			}
		} else if (this.leashNBTTag.hasKey("X", 99) && this.leashNBTTag.hasKey("Y", 99) && this.leashNBTTag.hasKey("Z", 99)) {
			BlockPos blockpos = new BlockPos(this.leashNBTTag.getInteger("X"), this.leashNBTTag.getInteger("Y"), this.leashNBTTag.getInteger("Z"));
			EntityRopeKnot entityleashknot = EntityRopeKnot.getKnotForPosition(this.worldObj, blockpos);

			if (entityleashknot == null) {
				entityleashknot = EntityRopeKnot.createKnot(this.worldObj, blockpos);
			}

			this.leashedToEntity = entityleashknot;
		} else {
			this.clearLeashed(false, true);
		}
	}

	this.leashNBTTag = null;
}

}

RenderRopeKnot.java

package net.creativerealmsmc.conquest.entity.render;

import net.creativerealmsmc.conquest.entity.EntityRopeKnot;
import net.creativerealmsmc.conquest.entity.model.ModelRopeKnot;
import net.minecraft.client.model.ModelLeashKnot;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;


@SideOnly(Side.CLIENT)
public class RenderRopeKnot extends Render<EntityRopeKnot>
{
    private static final ResourceLocation LEASH_KNOT_TEXTURES = new ResourceLocation("textures/entity/lead_knot.png");
    private final ModelRopeKnot leashKnotModel = new ModelRopeKnot();
    
    public RenderRopeKnot(RenderManager renderManagerIn)
    {
        super(renderManagerIn);
    }

    /**
     * Renders the desired {@code T} type Entity.
     */
    public void doRender(EntityRopeKnot entity, double x, double y, double z, float entityYaw, float partialTicks)
    {
        GlStateManager.pushMatrix();
        GlStateManager.disableCull();
        GlStateManager.translate((float)x, (float)y, (float)z);
        float f = 0.0625F;
        GlStateManager.enableRescaleNormal();
        GlStateManager.scale(-1.0F, -1.0F, 1.0F);
        GlStateManager.enableAlpha();
        this.bindEntityTexture(entity);

        if (this.renderOutlines)
        {
            GlStateManager.enableColorMaterial();
            GlStateManager.enableOutlineMode(this.getTeamColor(entity));
        }

        this.leashKnotModel.render(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);

        if (this.renderOutlines)
        {
            GlStateManager.disableOutlineMode();
            GlStateManager.disableColorMaterial();
        }

        GlStateManager.popMatrix();
        super.doRender(entity, x, y, z, entityYaw, partialTicks);
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityRopeKnot entity)
    {
        return LEASH_KNOT_TEXTURES;
    }
}


ModelRopeKnot.java

package net.creativerealmsmc.conquest.entity.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ModelRopeKnot extends ModelBase {

public ModelRenderer knotRenderer;

    public ModelRopeKnot()
    {
        this(0, 0, 32, 32);
    }

    public ModelRopeKnot(int p_i46365_1_, int p_i46365_2_, int p_i46365_3_, int p_i46365_4_)
    {
        this.textureWidth = p_i46365_3_;
        this.textureHeight = p_i46365_4_;
        this.knotRenderer = new ModelRenderer(this, p_i46365_1_, p_i46365_2_);
        this.knotRenderer.addBox(-3.0F, -6.0F, -3.0F, 6, 8, 6, 0.0F);
        this.knotRenderer.setRotationPoint(0.0F, 0.0F, 0.0F);
    }

    /**
     * Sets the models various rotation angles then renders the model.
     */
    public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale)
    {
        this.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entityIn);
        this.knotRenderer.render(scale);
    }

    /**
     * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms
     * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how
     * "far" arms and legs can swing at most.
     */
    public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn)
    {
        super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);
        this.knotRenderer.rotateAngleY = netHeadYaw * 0.017453292F;
        this.knotRenderer.rotateAngleX = headPitch * 0.017453292F;
    }

}

 

I've spent so long on this I hope I can get help  :'(

 

Edit: I have narrowed my situation down to only seeing the entity at certain angles.

Posted

You're using the deprecated overload of

RenderingRegistry.registerEntityRenderingHandler

in preInit, before the

RenderManager

instance has been created. I'm surprised the game isn't crashing with a

NullPointerException

as soon as it tries to render the entity.

 

Use the non-deprecated overload of

RenderingRegistry.registerEntityRenderingHandler

(the

IRenderFactory

one) instead.

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

You're using the deprecated overload of

RenderingRegistry.registerEntityRenderingHandler

in preInit, before the

RenderManager

instance has been created. I'm surprised the game isn't crashing with a

NullPointerException

as soon as it tries to render the entity.

 

Use the non-deprecated overload of

RenderingRegistry.registerEntityRenderingHandler

(the

IRenderFactory

one) instead.

I've tried to do the factory method using the commented portion:

RenderingRegistry.registerEntityRenderingHandler(EntityRopeKnot.class, new IRenderFactory() {
		@Override
		public Render createRenderFor(RenderManager manager) {
			return new RenderLeashKnot(manager);
		}
	});

And moving the render register to init portion of the client proxy but there is still no change :|

 

On a side note, I don't suppose there is any harm in using a default rendering class RenderLeashKnot? I only made my own to see if that was somehow a problem.

Posted

Just to be clear, you've tried calling

RenderingRegistry#registerEntityRenderingHandler(Class<T>, IRenderFactory<? super T>)

with an

IRenderFactory

that produces a

RenderRopeKnot

instance in preInit? Is the method that calls this definitely being called?

 

RenderLeashKnot

can only be used for entities that extend

EntityLeashKnot

.

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

I made the class:

public class RenderFactoryRope implements IRenderFactory<EntityRopeKnot> {
@Override
public Render<? super EntityRopeKnot> createRenderFor(RenderManager manager) {
	return new RenderRopeKnot(manager);
}
}

And moved register renders into the preinit.

 

Maybe the problem is the entity and/or the render class? How do I make sure those work together?

Posted

Render

and

IRenderFactory

both have a generic type argument: the entity type that they support. If you try to return an incompatible

Render

instance from your

IRenderFactory

(e.g. an instance of

RenderZombie

for

EntityArrow

), you'll get a compilation error because the generic types don't match.

 

Is the method that calls

RenderingRegistry.registerEntityRenderingHandler

definitely being called? Is

RenderRopeKnot#doRender

being called? Are there any errors in the log?

 

Side note: You should always annotate override methods with

@Override

so you get a compilation error if they don't actually override a super method. You should also consider extending

EntityLeashKnot

and overriding any required methods instead of copy-pasting it.

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

The registerRender is definitely getting called, I didn't have time to see if doRender is getting called yet. I never get errors.

 

Also I didn't mention, before this wasn't working, the leash would render only at certain angles and with no outline. I can't get it to do that agin.

Posted

Well, funny enough I got it to work like it previously did:

03daea1a3f.jpg

72d85000db.jpg

 

As you can see, the entity is only visible at certain angles and has no hitbox when visible... now what would cause this?

Posted

EntityLeashKnot

extends

EntityHanging

, but your

EntityRopeKnot

doesn't. Do you replicate all of the logic from

EntityHanging

yourself?

 

There a few places where Minecraft checks if an entity is an instance of

EntityHanging

, so you may want to extend it (or extend

EntityLeashKnot

since your entity seems to be very similar).

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

Well before when I made it behave like this it was extending the leashKnot entity, but put it all into one class just to make sure I didn't need to change anything. I will also look to see if there are references to entityHanging I need to overwrite.

Posted

Well I made the entity extend EntityLeashKnot and it still does the same thing  >:(

 

I checked for references to EntityHanging and EntityLeashKnot too and can't find anything in the default code that would cause this whatsoever.

 

[move]JUST WORK PLEASE[/move] /cry

 

Edit: http://gamedev.stackexchange.com/questions/81921/tileentityspecialrenderer-only-renders-from-certain-angle This guy seems to have a similar problem but I don't know much of GL and I only used the default lead code.

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.