Jump to content

[1.10] Entity Texture Not Rendering


averysumner

Recommended Posts

My Slimeball Entity's texture isn't loading, heres the code:

EntitySlimeball.class:

package com.averysumner.randomstuff;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class EntitySlimeball extends EntityThrowable
{
    public EntitySlimeball(World worldIn)
    {
        super(worldIn);
    }

    public EntitySlimeball(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    }

    public EntitySlimeball(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }

    public static void func_189662_a(DataFixer p_189662_0_)
    {
        EntityThrowable.func_189661_a(p_189662_0_, "Slimeball");
    }

    /**
     * Called when this EntityThrowable hits a block or entity.
     */
    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            int i = 0;

            if (result.entityHit instanceof EntityBlaze)
            {
                i = 3;
            }

            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
        }

        for (int j = 0; j < 8; ++j)
        {
            this.worldObj.spawnParticle(EnumParticleTypes.SLIME, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
        }

        if (!this.worldObj.isRemote)
        {
            this.setDead();
        }
    }
}

ModEntities(Rendering and Entity register):

package com.averysumner.randomstuff;

import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.Biomes;
import net.minecraft.init.Items;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;

public class ModEntities {

public static int id = 0;
public static int index;

public static Entity brownbear;
public static Entity slimeball;

public static void registerEntities()
{
	registerModEntity(EntityBrownBear.class, "brownbear", 0x228717, 0xE2F048);
	registerModProjectile(EntitySlimeball.class, "slimeball");

}

public static void registerRenders() {
	RenderingRegistry.registerEntityRenderingHandler(EntitySlimeball.class, new ProjectileRenderFactory());
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void registerModEntity(Class entityClass, String name, int primaryColor, int secondaryColor)
{
        EntityRegistry.registerModEntity(entityClass, name, ++id, RandomStuff.instance, 80, 3, false);
        EntityRegistry.registerEgg(entityClass, primaryColor, secondaryColor);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.FOREST);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.BIRCH_FOREST);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.BIRCH_FOREST_HILLS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.EXTREME_HILLS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.EXTREME_HILLS_EDGE);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.EXTREME_HILLS_WITH_TREES);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.FOREST_HILLS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_BIRCH_FOREST);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_BIRCH_FOREST_HILLS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_EXTREME_HILLS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_FOREST);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_PLAINS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_REDWOOD_TAIGA);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_REDWOOD_TAIGA_HILLS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.MUTATED_FOREST);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.PLAINS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.REDWOOD_TAIGA);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.REDWOOD_TAIGA_HILLS);
        EntityRegistry.addSpawn(entityClass, 6, 1, 5, EnumCreatureType.CREATURE, Biomes.ROOFED_FOREST);
        System.out.println("Registering Entity " + name + " with ID " + id);
}

@SuppressWarnings({ "rawtypes", "unchecked"})
public static void registerModProjectile(Class entityClass, String name){
	EntityRegistry.registerModEntity(entityClass, name, id, RandomStuff.instance, 64, 10, true);
        System.out.println("Registering Projectile " + name + " with ID " + id);
}
}

RenderProjectile:

package com.averysumner.randomstuff;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderProjectile extends Render {

    private final RenderItem ri;

    public RenderProjectile(RenderManager rm) {
        super(rm);
        this.ri = Minecraft.getMinecraft().getRenderItem();
    }

    @Override
    protected ResourceLocation getEntityTexture(Entity entity) {
        return new ResourceLocation("minecraft:items/slimeball");
    }

    @Override
    public void doRender(Entity entity, double x, double y, double z, float f, float partialTicks) {
        GlStateManager.pushMatrix();
        GlStateManager.translate((float) x, (float) y, (float) z);
        GlStateManager.enableRescaleNormal();
        GlStateManager.scale(0.5F, 0.5F, 0.5F);//TODO: Possibly change scale
        GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
        this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        this.ri.renderItem(new ItemStack(Items.SLIME_BALL), ItemCameraTransforms.TransformType.GROUND);
        GlStateManager.disableRescaleNormal();
        GlStateManager.popMatrix();
        super.doRender(entity, x, y, z, f, partialTicks);
    }

ProjectileRenderFactory:

package com.averysumner.randomstuff;

import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ProjectileRenderFactory implements IRenderFactory<EntitySlimeball> {
    @Override
    public Render<? super EntitySlimeball> createRenderFor(RenderManager manager) {
        return new RenderProjectile(manager);
    }
}

ThrowableSlimeball (What spawns the entity):

package com.averysumner.randomstuff;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ThrowableSlimeball extends Item {

@SubscribeEvent
public void playerRightClickSlime(PlayerInteractEvent.RightClickItem e){
	if (e.getEntityPlayer().getHeldItemMainhand().getItem() == Items.SLIME_BALL) {
        ItemStack playerHeld = e.getEntityPlayer().getHeldItemMainhand();
        
		System.out.println("Slime right clicked!");
		if (!e.getEntityPlayer().capabilities.isCreativeMode)
        {
            --e.getEntityPlayer().getHeldItemMainhand().stackSize;
        }
        
		if (e.getEntityPlayer().getHeldItemMainhand().stackSize == 0) {
			playerHeld = null;
			ForgeEventFactory.onPlayerDestroyItem(e.getEntityPlayer(), e.getEntityPlayer().getHeldItemMainhand(), e.getEntityPlayer().getActiveHand());
		}

		e.getWorld().playSound((EntityPlayer)null, e.getEntityPlayer().posX, e.getEntityPlayer().posY, e.getEntityPlayer().posZ, SoundEvents.ENTITY_SLIME_SQUISH, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!e.getWorld().isRemote)
        {
            EntitySlimeball entityslimeball = new EntitySlimeball(e.getWorld(), e.getEntityPlayer());
            entityslimeball.setHeadingFromThrower(e.getEntityPlayer(), e.getEntityPlayer().rotationPitch, e.getEntityPlayer().rotationYaw, 0.0F, 1.5F, 1.0F);
            e.getWorld().spawnEntityInWorld(entityslimeball);
        }
        e.setCanceled(true);
	}

}
}

There are 10 types of people in this world. Those who know binary and those who don't.

Link to comment
Share on other sites

It is called in PreInit:

package com.averysumner.randomstuff;

import net.minecraft.util.datafix.DataFixer;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
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);
        ModItems.init();
        ModEntities.registerEntities();
        ModEntities.registerRenders();
    }

    @Override
    public void init(FMLInitializationEvent e) {
    	super.init(e);
    }

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

There are 10 types of people in this world. Those who know binary and those who don't.

Link to comment
Share on other sites

What do you mean by 'not loading'?

If it is simply not rendered, then it is obviously problem with your rendering.

Or do you mean you got the MISSING_TEXTURE? Then it gets interesting.

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

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

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.