Jump to content

[1.8 SOLVED]Creating a Custom Throwable Entity, Texture Not Showing


riderj

Recommended Posts

 

 

The Solution

 

 

The reason why I was not able to render my own throwable "enderpearl" with a custom texture was because I had not written any OpenGL code to apply the texture to the entity. I was able to work around this by using the RenderSnowball class when registering my renderers.

 

RenderingRegistry.registerEntityRenderingHandler(EntityItemTest.class,new RenderSnowball(Minecraft.getMinecraft().getRenderManager(),item,Harvester.game.getRenderItem()));

 

I needed a RenderItem for the third parameter so I instanced a variable to Minecraft, called it game, and then that allowed me to get the RenderItem I needed. After registering the snowball as the render handler I was able to just allow the RenderSnowball  to handle my test_item and its texture. I ended up creating a HarversterEntity class to handle entities and rendering.

 

 

 

 

The old Post

 

I'm trying to create a custom throwable entity and I'm using the EnderPearl code to have a base functionality. When using this code as an extension of my ItemTest I get a null texture for the entity being thrown, but it in fact is being thrown because I get teleported to the location it landed. I've looked through all of the code that the EnderPearl class uses, and cannot find a single thing regarding textures. I have registered the entity into the GlobalEntityID and it successfully loads into the database, and I can access it, so no issue there. I have also created a RenderEntityItemTest class and EntityItemTest class. I'm rendering the entity using RenderingRegistry, and still have a null texture. Here is my code:

 

 

I had managed to spawn an entity, but it's having issues rendering the texture. When it gets spawned it's a white box with no texture. I'm not familiar with how things get rendered. I had looked through it, and all I get out of it is that when the entity spawns it tries to render a texture, but can't. All code is updated.

 

HarvestItems.java

package riderj.harvester.init.items;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import riderj.harvester.References;
import riderj.harvester.entity.item.EntityItemTest;
import riderj.harvester.items.ItemTest;

public class HarvesterItems {

public static ItemTest test_item;

public static void init(){
	test_item = (ItemTest) new ItemTest().setUnlocalizedName("test_item");

	test_item.setCreativeTab(CreativeTabs.tabMisc);
}

public static void register(){
	GameRegistry.registerItem(test_item, test_item.getUnlocalizedName().substring(5));
	EntityRegistry.registerGlobalEntityID(EntityItemTest.class, "test_item", EntityRegistry.findGlobalUniqueEntityId());
	EntityRegistry.registerModEntity(EntityItemTest.class, "test_item", 1, References.MODID, 128, 1, true);
	RenderingRegistry.registerEntityRenderingHandler(EntityItemTest.class, new RenderEntityItemTest(Minecraft.getMinecraft().getRenderManager())); //Without this, it spawns a white block
}

public static void registerRenders(){
	registerRender(test_item);
}

public static void registerRender(Item item){
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.MODID+":"+item.getUnlocalizedName().substring(5),"inventory"));

}
}

 

ItemTest.java

package riderj.harvester.items;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityEgg;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;
import riderj.harvester.entity.item.EntityItemTest;

public class ItemTest extends Item {
 private static final String __OBFID = "CL_00000027";

    public ItemTest()
    {
        this.maxStackSize = 16;
        this.setCreativeTab(CreativeTabs.tabMisc);
    }

    /**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
    {
        if (playerIn.capabilities.isCreativeMode)
        {
            return itemStackIn;
        }
        else
        {
            --itemStackIn.stackSize;
            worldIn.playSoundAtEntity(playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

            if (!worldIn.isRemote)
            {
                worldIn.spawnEntityInWorld(new EntityItemTest(worldIn, playerIn));
            }

            playerIn.triggerAchievement(StatList.objectUseStats[item.getIdFromItem(this)]);
            return itemStackIn;
        }
    }
}

 

EntityItemTest.java

package riderj.harvester.entity.item;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityEndermite;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityItemTest extends EntityThrowable
{
    

private static final String __OBFID = "CL_00001725";

    public EntityItemTest(World worldIn, EntityLivingBase p_i1783_2_)
    {
        super(worldIn, p_i1783_2_);
    }

    @SideOnly(Side.CLIENT)
    public EntityItemTest(World worldIn, double p_i1784_2_, double p_i1784_4_, double p_i1784_6_)
    {
        super(worldIn, p_i1784_2_, p_i1784_4_, p_i1784_6_);
    }

    /**
     * Called when this EntityThrowable hits a block or entity.
     */
    protected void onImpact(MovingObjectPosition p_70184_1_)
    {
        EntityLivingBase entitylivingbase = this.getThrower();

        if (p_70184_1_.entityHit != null)
        {
            p_70184_1_.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, entitylivingbase), 0.0F);
        }

        for (int i = 0; i < 32; ++i)
        {
            this.worldObj.spawnParticle(EnumParticleTypes.PORTAL, this.posX, this.posY + this.rand.nextDouble() * 2.0D, this.posZ, this.rand.nextGaussian(), 0.0D, this.rand.nextGaussian(), new int[0]);
        }

        if (!this.worldObj.isRemote)
        {
            if (entitylivingbase instanceof EntityPlayerMP)
            {
                EntityPlayerMP entityplayermp = (EntityPlayerMP)entitylivingbase;

                if (entityplayermp.playerNetServerHandler.getNetworkManager().isChannelOpen() && entityplayermp.worldObj == this.worldObj && !entityplayermp.isPlayerSleeping())
                {
                    net.minecraftforge.event.entity.living.EnderTeleportEvent event = new net.minecraftforge.event.entity.living.EnderTeleportEvent(entityplayermp, this.posX, this.posY, this.posZ, 5.0F);
                    if (!net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event))
                    { // Don't indent to lower patch size
                    if (this.rand.nextFloat() < 0.05F && this.worldObj.getGameRules().getGameRuleBooleanValue("doMobSpawning"))
                    {
                        EntityEndermite entityendermite = new EntityEndermite(this.worldObj);
                        entityendermite.setSpawnedByPlayer(true);
                        entityendermite.setLocationAndAngles(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, entitylivingbase.rotationYaw, entitylivingbase.rotationPitch);
                        this.worldObj.spawnEntityInWorld(entityendermite);
                    }

                    if (entitylivingbase.isRiding())
                    {
                        entitylivingbase.mountEntity((Entity)null);
                    }

                    entitylivingbase.setPositionAndUpdate(event.targetX, event.targetY, event.targetZ);
                    entitylivingbase.fallDistance = 0.0F;
                    entitylivingbase.attackEntityFrom(DamageSource.fall, event.attackDamage);
                    }
                }
            }

            this.setDead();
        }
    }

    /**
     * Called to update the entity's position/logic.
     */
    public void onUpdate()
    {
        EntityLivingBase entitylivingbase = this.getThrower();

        if (entitylivingbase != null && entitylivingbase instanceof EntityPlayer && !entitylivingbase.isEntityAlive())
        {
            this.setDead();
        }
        else
        {
            super.onUpdate();
        }
    }
}

 

RenderEntityItemTest.java

package riderj.harvester.init.items;

import net.minecraft.client.renderer.entity.RenderEntity;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;

public class RenderEntityItemTest extends RenderEntity {

public RenderEntityItemTest(RenderManager renderManager) {
	super(renderManager);
	// TODO Auto-generated constructor stub
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	// TODO Auto-generated method stub
	return new ResourceLocation("harvester:items/test_item");
}

}

 

 

 

 

Link to comment
Share on other sites

Still having issues with rendering the texture... I have no clue where it's messing up. I have looked everywhere multiple times, and have not found anything. I'm thinking that I'm rendering the entity wrong, but there is no documentation on what I need to do when creating a new entity.

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.

Announcements



×
×
  • Create New...

Important Information

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