Jump to content

Registering textures (such as compass & clock)


AlexDGr8r
 Share

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm researching the how to create biomes in json. There is a great tool for creating the jsons online. Using the vanilla `river` biome, I want to essentially create a custom disk feature that mixes 3 blocks instead of a single-block provider. Any ideas on where to start with that?
    • I figured out what was wrong ... you can spot it pretty quick most likely: { "type": "minecraft:smelting", "ingredient": { "item": "minecraft:gold_nugget_ore" }, "result": "minecraft:gold_nugget", "experience": 0.25, "cookingtime": 150 }   ... so, after changing `minecraft` to `foundations` for all the custom items and all the recipes work. Well that's what copy/paste will get you. One last question about recipes, though. What does the following json key/value do in the game? "group": "copper_ingot"  
    • # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # #      102.54.94.97     rhino.acme.com          # source server #       38.25.63.10     x.acme.com              # x client host # localhost name resolution is handled within DNS itself. #    127.0.0.1       localhost #    ::1             localhost ###0.0.0.0 apps.corel.com ###0.0.0.0 mc.corel.com 0.0.0.0 origin-mc.corel.com ###0.0.0.0 iws.corel.com
    • Is there a way to create a custom map marker for a custom structure/biome (same as a vanilla mansion)?
    • I’ve scrounged the Internet for solutions and found absolutely nothing that has worked for me I have posted my code in a GitHub Repository. I bet the culprit is somewhere in the Container or TileEntity classes (Furnace packages are in blocks/coke_furnace or blocks/foundry) PS I know I’m on 1.12.2 and that it’s not supported I don’t want to update my game or my code. Lol It’s my favorite version and the most widely modded. I don’t plan to release the mod, I’m just customizing my game to my will. I’ll send it to friends but that’s it.
  • Topics

×
×
  • Create New...

Important Information

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