Jump to content

Entity Texture


Recommended Posts

hi :)

 

i'm trying to make a mob with multiple skins, like horse have.

but when i try then i can't seem to let it work proper-ly.

it just shifts between all the skins.

Any suggestions?

 

Source code

 

Render Entity class

 

package dk.MathiasVO053.RobinsamseCraft.entity;

 

import java.util.Random;

 

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.renderer.entity.RenderLiving;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.util.ResourceLocation;

import dk.MathiasVO053.RobinsamseCraft.Strings;

import dk.MathiasVO053.RobinsamseCraft.Model.modelButtMob;

 

public class RenderButtMobRed extends RenderLiving {

private static  ResourceLocation texture1 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_blue.png");

private static  ResourceLocation texture2 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_gray.png");

private static  ResourceLocation texture3 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_green.png");

private static  ResourceLocation texture4 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_lime.png");

private static  ResourceLocation texture5 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_orange.png");

private static  ResourceLocation texture6 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_pink.png");

private static  ResourceLocation texture7 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_purple.png");

private static  ResourceLocation texture8 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_red.png");

private ResourceLocation TE;

protected modelButtMob modelEntity;

 

 

 

public RenderButtMobRed(ModelBase par1ModelBase, float par2) {

super(par1ModelBase, par2);

modelEntity = ((modelButtMob) mainModel);

}

 

public void renderButt(entityButtMobRed entity, double x, double y, double z, float u, float v){

super.doRender(entity, x, y, z, u, v);

}

 

public void doRenderLiving(EntityLiving entityliving, double x, double y, double z, float u, float v){

renderButt((entityButtMobRed)entityliving, x, y, z, u, v);

}

 

public void doRender(Entity entity, double x, double y, double z, float u, float v){

renderButt((entityButtMobRed)entity, x, y, z, u, v);

}

 

 

int p1 = 9;

private boolean l = true;

private ResourceLocation p;

 

protected ResourceLocation getEntityTexture(Entity entity){

Random r;

r = new Random();

        int rand = r.nextInt(8);

switch (rand)

        {

            case 1:

            default:

                TE = texture1;

                break;

            case 2:

            TE = texture2;

            break;

            case 3:

            TE = texture3;

            break;

            case 4:

            TE = texture4;

            break;

            case 5:

            TE = texture5;

            break;

            case 6:

            TE = texture6;

            break;

            case 7:

            TE = texture7;

            break;

            case 8:

            TE = texture8;

        }

        return TE;

}

}

Link to comment
Share on other sites

You are randomly picking the texture each time the getTexture is called.  What did you think would happen?

 

 

Pick that random value in the initilization of the entity.  Then check for the value in your render method and pick the right texture.  That or just do all the texture stuff in the entity and just call the entity for the right texture.  I've done both.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

hmm.

i'm sorry but i don't think i understand.

i've tried it but can't seem to get that working either.

 

source code

 

public class RenderButtMobRed extends RenderLiving {

private static  ResourceLocation texture1 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_blue.png");

private static  ResourceLocation texture2 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_gray.png");

private static  ResourceLocation texture3 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_green.png");

private static  ResourceLocation texture4 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_lime.png");

private static  ResourceLocation texture5 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_orange.png");

private static  ResourceLocation texture6 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_pink.png");

private static  ResourceLocation texture7 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_purple.png");

private static  ResourceLocation texture8 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_red.png");

protected modelButtMob modelEntity;

private int randText;

 

private static int rendText(entityButtMobRed entity){

return entity.buttText();

}

public RenderButtMobRed(ModelBase par1ModelBase, float par2) {

super(par1ModelBase, par2);

modelEntity = ((modelButtMob) mainModel);

}

 

public void renderButt(entityButtMobRed entity, double x, double y, double z, float u, float v){

super.doRender(entity, x, y, z, u, v);

}

 

public void doRenderLiving(EntityLiving entityliving, double x, double y, double z, float u, float v){

renderButt((entityButtMobRed)entityliving, x, y, z, u, v);

}

 

public void doRender(Entity entity, double x, double y, double z, float u, float v){

renderButt((entityButtMobRed)entity, x, y, z, u, v);

}

 

protected ResourceLocation getEntityTexture(Entity entity){

        return this.rendText(entity)

}

}

 

 

 

 

 

 

 

 

 

public class entityButtMobRed extends EntityAnimal{

 

private static int TE;

 

public entityButtMobRed(World par1World) {

super(par1World);

this.setSize(0.5F, 0.4F);

this.tasks.addTask(0, new EntityAIWander(this, 0.5D));

this.tasks.addTask(1, new EntityAIPanic(this, 1.0D));

this.tasks.addTask(2, new EntityAITempt(this, 0.7D, Items.beef, false));

this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));

this.tasks.addTask(2, new EntityAIMate(this, 1.0D));

 

 

}

 

public boolean isAIEnabled(){

return true;

}

 

protected void applyEntityAttributes(){

super.applyEntityAttributes();

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(16.0F);

this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);

}

 

@Override

public EntityAgeable createChild(EntityAgeable age) {

return new entityButtMobRed(worldObj);

}

public boolean isBreedingItem(ItemStack item) {

        return item != null && item.getItem() == Main.RainbowPowder;

    }

 

public static int buttText(){

Random r;

r = new Random();

        int rand = r.nextInt(8);

        switch(rand){

case 1:

        TE = 1;

        break;

    case 2:

    TE = 2;

    break;

    case 3:

    TE = 3;

    break;

    case 4:

    TE = 4;

    break;

    case 5:

    TE = 5;

    break;

    case 6:

    TE = 6;

    break;

    case 7:

    TE = 7;

    break;

    case 8:

    TE = 8;

}

return TE;

}

}

Link to comment
Share on other sites

hmm. now i've tried that but i get an error and idk how to fix it :(

 

source code

 

package dk.MathiasVO053.RobinsamseCraft.entity;

 

import java.util.Random;

 

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.renderer.entity.RenderLiving;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.util.ResourceLocation;

import dk.MathiasVO053.RobinsamseCraft.Strings;

import dk.MathiasVO053.RobinsamseCraft.Model.modelButtMob;

 

public class RenderButtMobRed extends RenderLiving {

private static  ResourceLocation texture1 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_blue.png");

private static  ResourceLocation texture2 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_gray.png");

private static  ResourceLocation texture3 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_green.png");

private static  ResourceLocation texture4 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_lime.png");

private static  ResourceLocation texture5 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_orange.png");

private static  ResourceLocation texture6 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_pink.png");

private static  ResourceLocation texture7 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_purple.png");

private static  ResourceLocation texture8 = new ResourceLocation(Strings.MODID + ":" + "textures/model/numse_red.png");

private ResourceLocation TE;

protected modelButtMob modelEntity;

 

 

 

public RenderButtMobRed(ModelBase par1ModelBase, float par2) {

super(par1ModelBase, par2);

modelEntity = ((modelButtMob) mainModel);

}

 

public void renderButt(entityButtMobRed entity, double x, double y, double z, float u, float v){

super.doRender(entity, x, y, z, u, v);

}

 

public void doRenderLiving(EntityLiving entityliving, double x, double y, double z, float u, float v){

renderButt((entityButtMobRed)entityliving, x, y, z, u, v);

}

 

public void doRender(Entity entity, double x, double y, double z, float u, float v){

renderButt((entityButtMobRed)entity, x, y, z, u, v);

}

 

private static void randT(entityButtMobRed entity){

entity.getButtText();

}

 

private boolean l = true;

private ResourceLocation p;

 

protected ResourceLocation getEntityTexture(Entity entity){   

switch(rand){

case 1:

TE = texture1;

break;

case 2:

TE = texture2;

break;

case 3:

TE = texture3;

break;

case 4:

TE = texture4;

break;

case 5:

TE = texture5;

break;

case 6:

TE = texture6;

break;

case 7:

TE = texture7;

break;

case 8:

TE = texture8;

break;

}

        return TE;

}

}

 

 

 

package dk.MathiasVO053.RobinsamseCraft.entity;

 

import java.util.Random;

 

import dk.MathiasVO053.RobinsamseCraft.Main;

import net.minecraft.entity.EntityAgeable;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.EntityAIFollowParent;

import net.minecraft.entity.ai.EntityAIMate;

import net.minecraft.entity.ai.EntityAIPanic;

import net.minecraft.entity.ai.EntityAITempt;

import net.minecraft.entity.ai.EntityAIWander;

import net.minecraft.entity.passive.EntityAnimal;

import net.minecraft.init.Items;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

 

public class entityButtMobRed extends EntityAnimal{

 

public entityButtMobRed(World world) {

super(world);

this.setSize(0.5F, 0.4F);

this.tasks.addTask(0, new EntityAIWander(this, 0.5D));

this.tasks.addTask(1, new EntityAIPanic(this, 1.0D));

this.tasks.addTask(2, new EntityAITempt(this, 0.7D, Items.beef, false));

this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));

this.tasks.addTask(2, new EntityAIMate(this, 1.0D));

}

 

public boolean isAIEnabled(){

return true;

}

 

public static Random getButtText(){

Random r;

r = new Random();

        int rand = r.nextInt(8);

        return r;

}

 

protected void applyEntityAttributes(){

super.applyEntityAttributes();

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(16.0F);

this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);

}

 

@Override

public EntityAgeable createChild(EntityAgeable age) {

return new entityButtMobRed(worldObj);

}

public boolean isBreedingItem(ItemStack item) {

        return item != null && item.getItem() == Main.RainbowPowder;

    }

 

 

 

}

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Internal ExeptIon server bug Image LInk  l V https://lens.google.com/search?ep=gsbubb&hl=en-CA&re=df&p=AbrfA8p0hRZLHI5ozxFtMWh8xA21sqBQ71eivErBLG_oF8j-5G7yFOjJQP7DxnD3oOFBAYE4ajAvyOag8ykwGITxwfBg-8CpFUB0plaWJyrGKiw28bj9LohjoyyI07OsFTE5vJa1o3aKF80ocbEG8U_v5QhX_B5B3k370goGoohHkTodvClNPrBATvS6rYMKO43iTr_QbdYL_78wxQ%3D%3D#lns=W251bGwsbnVsbCxudWxsLG51bGwsbnVsbCxudWxsLG51bGwsIkVrY0tKR1E1T1RjeU5ETTVMV05pTVRVdE5HWXdNeTA1TmpWbUxXUXdOekZtWVdZeE9EWTJZaElmYTNoV05VWmFVREJJYTFGVWMwNXBYM3AxVm1GWlRWVTNSRnBoTFVob2F3PT0iLG51bGwsbnVsbCxudWxsLG51bGwsbnVsbCxudWxsLG51bGwsWyI4ZDdmNDE1Yi00ZWViLTQ2NzItOWQyOS05MTA2MWNmMzYyNjciXV0=
    • Ensure your system is running the latest version of Java. Sodium requires Java 17 or later for newer Minecraft versions (like 1.17+). 
    • Hi I wanted to my custom mob to hold any sword item, but didn’t rendered properly.   In entity class, make entity hold items as below: @Override public InteractionResult mobInteract(Player pPlayer, InteractionHand pHand) { //… ItemStack itemstack = pPlayer.getItemInHand(pHand); if (this.isTame()) { if ( (itemstack.is(Items.MELON_SLICE) || itemstack.is(Items.HONEY_BOTTLE)) && this.getHealth() < this.getMaxHealth() ) { //… } /* Handle holding sword */ else if (itemstack.getItem() instanceof SwordItem) { pPlayer.displayClientMessage(Component.literal("Clicked with item: " + itemstack.getDisplayName().getString()).withStyle(ChatFormatting.GOLD), true); //Return sword //pPlayer.getInventory().add(this.getItemInHand(InteractionHand.MAIN_HAND)); pPlayer.getInventory().add(this.getItemBySlot(EquipmentSlot.MAINHAND)); //The entity holds item //this.setItemInHand(InteractionHand.MAIN_HAND, itemstack); this.setItemSlot(EquipmentSlot.MAINHAND, itemstack.copy()); //Give copy of itemstack //If player is not in creative mode. From mobInteract() in wolf. if (!pPlayer.getAbilities().instabuild) { //Decrement sword count in hand pPlayer.getItemInHand(pHand).shrink(1); } return InteractionResult.SUCCESS; } else { //If player is sneaking pPlayer.displayClientMessage(getItemInHand(InteractionHand.MAIN_HAND).getDisplayName(), false); if (pPlayer.isShiftKeyDown()) { //Return sword //pPlayer.getInventory().add(this.getItemInHand(InteractionHand.MAIN_HAND)); pPlayer.getInventory().add(this.getItemBySlot(EquipmentSlot.MAINHAND)); //The entity holds nothing this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); return InteractionResult.SUCCESS; } else { //… } } else { return interactionresult; } }   And in render class, render the item as below: @Override public void render(RanaEntity pEntity, float pEntityYaw, float pPartialTicks, PoseStack pMatrixStack, MultiBufferSource pBuffer, int pPackedLight) { if(pEntity.isBaby()) { pMatrixStack.scale(0.5f, 0.5f, 0.5f); } model.setupAnim(pEntity, 0, 0, 0, pEntityYaw, 0); // //Get location and rotation of arm bone ModelPart rightArm = model.rightArm(); //Get right arm //Get location and rotation of item according to arm bone pMatrixStack.pushPose(); pMatrixStack.translate(rightArm.x, rightArm.y, rightArm.z); //Move to bone location pMatrixStack.mulPose(Axis.XP.rotationDegrees(rightArm.xRot)); //Rotate X pMatrixStack.mulPose(Axis.YP.rotationDegrees(rightArm.yRot)); //Rotate Y pMatrixStack.mulPose(Axis.ZP.rotationDegrees(rightArm.zRot)); //Rotate Z //Draw item //ItemStack itemStack = pEntity.getItemInHand(InteractionHand.MAIN_HAND); ItemStack itemStack = pEntity.getItemBySlot(EquipmentSlot.MAINHAND); if (!itemStack.isEmpty()) { //Offset pMatrixStack.translate(0.0, 0.0, 0.1); // Render the item //Minecraft.getInstance().getItemRenderer().renderStatic(itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, pPackedLight, OverlayTexture.NO_OVERLAY, pMatrixStack, pBuffer, pEntity.level(), pEntity.getId()); //itemRenderer.renderStatic(itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, pPackedLight, OverlayTexture.NO_OVERLAY, pMatrixStack, pBuffer, pEntity.level(), pEntity.getId()); itemInHandRenderer.renderItem(pEntity, itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, false, pMatrixStack, pBuffer, pEntity.getId()); } pMatrixStack.popPose(); super.render(pEntity, pEntityYaw, pPartialTicks, pMatrixStack, pBuffer, pPackedLight); }   I confirmed the entity can properly hold item(logically) but the item which the entity holds is not rendered at all.   Full code: https://github.com/sakiiiiika/ranamod   Thanks.
    • It is Immersive Melodies
  • Topics

×
×
  • Create New...

Important Information

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