Jump to content

Recommended Posts

Posted

Hi,

 

I attempted to do a seemingly simple task; randomise mob textures. Here is what I tried to do:

package fl.renders;

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.util.ResourceLocation;
import fl.main.Reference;
import fl.models.ModelGreedling;

public class RenderGreedling extends RenderLiving
{
private Random rand = new Random();
private static ResourceLocation greedlingTexture;
private static final ResourceLocation greedlingOriginal = new ResourceLocation(Reference.MOD_ID, "textures/entities/greedling/greedling_original.png");
private static final ResourceLocation greedlingEndling = new ResourceLocation(Reference.MOD_ID, "textures/entities/greedling/greedling_endling.png");
private static final ResourceLocation greedlingSpecial = new ResourceLocation(Reference.MOD_ID, "textures/entities/greedling/greedling_special.png");

public RenderGreedling(ModelBase modelBase, float par2)
{
	super(new ModelGreedling(), 0.3F);
}

@Override
protected ResourceLocation getEntityTexture(Entity ent){
	switch(rand.nextInt(3))
	{
	case 0:
		greedlingTexture = greedlingOriginal;
		break;
	case 1:
		greedlingTexture = greedlingEndling;
		break;
	case 2:
		greedlingTexture = greedlingSpecial;
		break;
	}
	return greedlingTexture;
}
}

 

However, getEntityTexture is constantly being called which makes it choose a new textures each time. I'm not sure how to get around it, advice?

Posted
  On 1/30/2014 at 12:07 AM, diesieben07 said:

Create the random texture id once, when the entity gets created (keyword: Constructor).

Okay, I setup a onEntityConstructingEvent, heres my code:

package fl.main;

import java.util.Random;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
import fl.entities.EntityGreedling;

public class ForgeEvents
{
private Random rand = new Random();
public  ResourceLocation greedlingTexture;
private ResourceLocation greedlingOriginal = new ResourceLocation(Reference.MOD_ID, "textures/entities/greedling/greedling_original.png");
private ResourceLocation greedlingEndling = new ResourceLocation(Reference.MOD_ID, "textures/entities/greedling/greedling_endling.png");
private ResourceLocation greedlingSpecial = new ResourceLocation(Reference.MOD_ID, "textures/entities/greedling/greedling_special.png");

@ForgeSubscribe
public void greedlingConstruction(EntityConstructing event){
	if(event.entity instanceof EntityGreedling)
	{
		switch(rand.nextInt(3))
		{
		case 0:
			greedlingTexture = greedlingOriginal;
		break;
		case 1:
			greedlingTexture = greedlingEndling;
		break;
		case 2:
			greedlingTexture = greedlingSpecial;
		break;
		}
	}
}
}

 

Render Class

package fl.renders;

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.util.ResourceLocation;
import fl.main.ForgeEvents;
import fl.main.Reference;
import fl.models.ModelGreedling;

public class RenderGreedling extends RenderLiving
{

public RenderGreedling(ModelBase modelBase, float par2)
{
	super(new ModelGreedling(), 0.3F);
}

@Override
protected ResourceLocation getEntityTexture(Entity ent){
	ForgeEvents fe = new ForgeEvents();
	return fe.greedlingTexture;
}
}

I had to create an object to the class so I could access greedlingTexture, the alternative would be making it static which would lead to all mobs being the same texture :/ I must be missing something

 

 

However, I hit an NPE for the texture registration.

Error:

2014-01-30 00:25:45 [iNFO] [sTDERR] Caused by: java.lang.NullPointerException
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:59)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.texture.SimpleTexture.loadTexture(SimpleTexture.java:31)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.texture.TextureManager.loadTexture(TextureManager.java:84)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	... 21 more
2014-01-30 00:25:45 [iNFO] [sTDERR] net.minecraft.util.ReportedException: Registering texture
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.texture.TextureManager.loadTexture(TextureManager.java:99)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.texture.TextureManager.bindTexture(TextureManager.java:41)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.Render.bindTexture(Render.java:53)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.Render.bindEntityTexture(Render.java:48)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.RendererLivingEntity.renderModel(RendererLivingEntity.java:296)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.RendererLivingEntity.doRenderLiving(RendererLivingEntity.java:156)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.RenderLiving.doRenderLiving(RenderLiving.java:28)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.RenderLiving.doRender(RenderLiving.java:142)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.RenderManager.renderEntityWithPosYaw(RenderManager.java:312)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:281)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:524)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1160)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1006)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:945)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:837)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.client.main.Main.main(Main.java:93)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at java.lang.reflect.Method.invoke(Unknown Source)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
2014-01-30 00:25:45 [iNFO] [sTDERR] 	at net.minecraft.launchwrapper.Launch.main(Launch.java:27)

 

 

Posted

Nevermind, I've managed to do it.

 

For anyone who wants to know:

 

Create an int in your entity, in the constructor of the entity, randomise the int using Javas random class.

Create a method to return the int.

In your render class, in the getEntityTexture method which returns a resourcelocation, you gotta get an object of your entity class, to do that, cast it to the entity param. Then, it simples, just use an else if and check the ints value. EG:

 

@Override
protected ResourceLocation getEntityTexture(Entity ent){
	EntityGreedling greedlingObj = (EntityGreedling)ent;
	int texture = greedlingObj.getTexture();
	if(texture == 0){
		return greedlingOriginal;
	}
	else if(texture == 1){
		return greedlingEndling;
	}
	else{
		return greedlingSpecial;
	}
}

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

    • Keep on using the original Launcher Run Vanilla 1.12.2 once and close the game Download Optifine and run optifine as installer (click on the optifine jar) Start the launcher and make sure the Optifine profile is selected - then test it again  
    • Hi everyone, I’m hoping to revisit an old version of Minecraft — specifically around Beta 1.7.3 — for nostalgia’s sake. I’ve heard you can do this through the official Minecraft Launcher, but I’m unsure how to do it safely without affecting my current installation or save files. Are there any compatibility issues I should watch out for when switching between versions? Would really appreciate any tips or advice from anyone who’s done this before! – Adam
    • hello! i was trying to recreate item-in-hand feature for my custom mob. i figured out that my mob needs a custom iteminhandlayer. i created it - but the main problem is.. well.. you can see all on screenshots any idea how i can fix that? is there any implemented method to render the item perfect to hand? public void render(@NotNull PoseStack pPoseStack, @NotNull MultiBufferSource pBufferSource, int pPackedLight, @NotNull TuneGolemRenderState pRenderState, float pYRot, float pXRot) { ItemStackRenderState item = pRenderState.heldItem; if (!item.isEmpty()) { pPoseStack.pushPose(); ModelPart leftArm = this.getParentModel().leftArm; pPoseStack.translate(0.35,0.5,-1.25); pPoseStack.mulPose(Axis.XP.rotationDegrees(180.0F)); pPoseStack.mulPose(Axis.YP.rotationDegrees(90.0F)); leftArm.translateAndRotate(pPoseStack); // pPoseStack.translate(0,0,0); leftArm.translateAndRotate(pPoseStack); if (TuneGolemRenderState.hornPlaying) { pPoseStack.translate(0, -0.5, 0.65); pPoseStack.scale(1.25F,1.25F,1.25F); } // Minecraft.getInstance().player.displayClientMessage(Component.literal(leftArm.xRot + " " + leftArm.yRot + " " + leftArm.zRot), true); item.render(pPoseStack, pBufferSource, pPackedLight, OverlayTexture.NO_OVERLAY); pPoseStack.popPose(); // -1.0F, -2.0F, -3.0F } }  
    • I checked for any driver updates, but no new updates were found
    • Maybe it refers to an issue with the system - check for CPU/GPU driver updates
  • Topics

×
×
  • Create New...

Important Information

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