Jump to content

Registering textures (such as compass & clock)


AlexDGr8r

Recommended Posts

I'm having trouble getting my custom animated textures to work properly. Please know that this is similar to how the compass work. In fact, the code mirrors off of the TextureCompass class. In MC 1.5, everything worked fine. I've hooked into the Pre-TextureStitchEvent to set the texture entry for the custom animation, but now that appears to not register it. The texture itself animates, but only from reading the png file. In other words, the compass just keeps turning, but it's not calling my updateAnimation() method. My debug code shows me it set's the texture entry, but it still doesn't call the TextureDetector class updateAnimation() method.

 

Here's some code for you all:

 

Hook for registering the texture entry:

package net.minecraft.src.meteor;

import net.meteor.common.MeteorsMod;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class HandlerTextures {

@ForgeSubscribe
public void registerTextures(TextureStitchEvent.Pre event) {
	TextureMap map = event.map;
	if (map.textureType == 1) {		// Items
		map.setTextureEntry("meteors:MeteorDetectorProximity", new TextureDetector("meteors:MeteorDetectorProximity", 0));
		map.setTextureEntry("meteors:MeteorDetectorTime", new TextureDetector("meteors:MeteorDetectorTime", 1));
		map.setTextureEntry("meteors:MeteorDetectorCrash", new TextureDetector("meteors:MeteorDetectorCrash", 2));
		MeteorsMod.log.info("Textures set for detector!");
	}
}

}

 

And here's my TextureDetector class:

package net.minecraft.src.meteor;

import net.meteor.common.ClientHandler;
import net.meteor.common.MeteorsMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;

public class TextureDetector extends TextureAtlasSprite {

public double currentAngle;
public double angleDelta;
public int detectorType;		// 0 = Proximity, 1 = Time, 2 = Crash

public TextureDetector(String s, int type) {
	super(s);
	this.detectorType = type;
}

@Override
public void updateAnimation()
{
	Minecraft minecraft = Minecraft.getMinecraft();

	if (minecraft.theWorld != null && minecraft.thePlayer != null)
	{
		this.updateCompass(minecraft.theWorld, minecraft.thePlayer.posX, minecraft.thePlayer.posZ, (double)minecraft.thePlayer.rotationYaw, false, false);
	}
	else
	{
		this.updateCompass((World)null, 0.0D, 0.0D, 0.0D, true, false);
	}
}

public void updateCompass(World par1World, double par2, double par4, double par6, boolean par8, boolean par9)
{
	if (this.field_110976_a.isEmpty()) return;
	MeteorsMod.log.info("Updating Detector in compass method!");
	double d3 = 0.0D;

	if (par1World != null && !par8)
	{
		ChunkCoordinates chunkcoordinates;
		if (this.detectorType == 0) {
			chunkcoordinates = ClientHandler.nearestTimeLocation;
		} else if (this.detectorType == 1) {
			chunkcoordinates = ClientHandler.getClosestIncomingMeteor(par2, par4);
		} else {
			chunkcoordinates = ClientHandler.lastCrashLocation;
		}
		if (chunkcoordinates != null) {
			double d4 = (double)chunkcoordinates.posX - par2;
			double d5 = (double)chunkcoordinates.posZ - par4;
			par6 %= 360.0D;
			d3 = -((par6 - 90.0D) * Math.PI / 180.0D - Math.atan2(d5, d4));
			MeteorsMod.log.info("Chunk coords are NOT null");
		} else {
			d3 = Math.random() * Math.PI * 2.0D;
			MeteorsMod.log.info("Chunk coords are null");
		}

		if (!par1World.provider.isSurfaceWorld())
		{
			d3 = Math.random() * Math.PI * 2.0D;
		}
	}

	if (par9)
	{
		this.currentAngle = d3;
	}
	else
	{
		double d6;

		for (d6 = d3 - this.currentAngle; d6 < -Math.PI; d6 += (Math.PI * 2D))
		{
			;
		}

		while (d6 >= Math.PI)
		{
			d6 -= (Math.PI * 2D);
		}

		if (d6 < -1.0D)
		{
			d6 = -1.0D;
		}

		if (d6 > 1.0D)
		{
			d6 = 1.0D;
		}

		this.angleDelta += d6 * 0.1D;
		this.angleDelta *= 0.8D;
		this.currentAngle += this.angleDelta;
	}

	int i;

	for (i = (int)((this.currentAngle / (Math.PI * 2D) + 1.0D) * (double)this.field_110976_a.size()) % this.field_110976_a.size(); i < 0; i = (i + this.field_110976_a.size()) % this.field_110976_a.size())
	{
		;
	}

	if (i != this.field_110973_g)
	{
		this.field_110973_g = i;
		//this.textureSheet.copyFrom(this.originX, this.originY, (Texture)this.field_110976_a.get(this.frameCounter), this.rotated);
		TextureUtil.func_110998_a((int[])this.field_110976_a.get(this.field_110973_g), this.field_130223_c, this.field_130224_d, this.field_110975_c, this.field_110974_d, false, false);
	}
}

}

 

Item variables declaration:

itemMeteorProximityDetector = new ItemMeteorsMod(IDs[33]).setUnlocalizedName("MeteorDetectorProximity").func_111206_d("meteors:MeteorDetectorProximity").setCreativeTab(meteorTab);
itemMeteorTimeDetector 		= new ItemMeteorsMod(IDs[34]).setUnlocalizedName("MeteorDetectorTime").func_111206_d("meteors:MeteorDetectorTime").setCreativeTab(meteorTab);
itemMeteorCrashDetector 	= new ItemMeteorsMod(IDs[35]).setUnlocalizedName("MeteorDetectorCrash").func_111206_d("meteors:MeteorDetectorCrash").setCreativeTab(meteorTab);

 

And yes, I register the TextureStitchEvent in my client proxy during my mod's Pre-initialization.

 

Any help on this would be great.

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.