Jump to content

changing texture based on tileentity time of day


Mightydanp

Recommended Posts

Alright i am changing my block status on what time of day it is. i am using metadata for this code i have based this off of the furnace and how it returns its active texture

 

I do have one question. since i am using metadata on the blocks do i have to get and save the the metadata of the block for it to use later because some of the ids are 506, 506:1 .... 509, 509:1 an i think if i did it like this without the world.setBlockMetadataWithNotify(int, int, int, int, int); instead i wouldnt be able to change it to the block it needs to be it would just switch from 506:2 to : 509 to 506 and that would mess up the meaning of the block

 

 

http://pastebin.com/Y6kwxpBc

 

http://pastebin.com/zpdmACmL

Link to comment
Share on other sites

set the metadata how you need it and test it in a tileentity special render


private ResourceLocation texture;

@Override
public void renderTileEntityAt(TileEntity tile, double posX, double posY, double posZ, float partialTick, int damage) {
	YourTileEntity tileEntity = (YourTileEntity)tile;

	if(tileEntity.getBlockMetadata() == 0)
	{
		texture = new ResourceLocation(YourMod.MODID, "textures/blocks/yourTextureFile0.png");
	}

	if(tileEntity.getBlockMetadata() == 1)
	{
		texture = new ResourceLocation(YourMod.MODID, "textures/blocks/yourTextureFile1.png");
	}

}

Link to comment
Share on other sites

Or you could use the getIcon(World, x, y, z) methods and ask the world what time it is...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

it would always return  false

 

What.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

This does not work it always returns false @SideOnly(Side.CLIENT)

        @Override

    public IIcon getIcon(int side, int meta)

    {

                if(!Minecraft.getMinecraft().theWorld.isRemote){

                        if(Minecraft.getMinecraft().theWorld.isDaytime() == true){

                        return  unActive;

                }else if (Minecraft.getMinecraft().theWorld.isDaytime() == false){

                        return magic;

                }

                }

                return unActive;

    }

Link to comment
Share on other sites

Idiot.*

 

1) Use the method that has a world passed to it. You should never use Minecraft.getMinecraft(). It happens to be safe here do to the SideOnly annotation, but it is still a bad idea.

public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)

2) "it returns false" makes no sense for a method that returns IIcon. You meant that isDaytime is returning false. You never once mentioned using this method.

3) world.getTotalWorldTime()

 

I would have to look, but isDaytime might not be useful client side. I so know that total world time will work though, as it (or at least the variable that method returns) is used by getMoonPhase, which is a client side method.

 

*sorry, I'm a bit grumpier than usual. I can't sleep and it's 5am. You posted half intelligible gibberish, played the pronoun game, and forced me to ask for clarification rather than posing what you meant (with code!) the first time.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

in this public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side){}

 

IBlockAccess does not have access to  getTotalWorldTime

 

all that is in the IBlockAccess is

getBlock

getTileEntity

getLightBrightnessForSkyBlocks

getBlockMetadata

isBlockProvidingPowerTo

isAirBlock

getBiomeGenForCoords

getHeight

extendedLevelsInChunkCache

isSideSolid

 

Link to comment
Share on other sites

i have tried something like this

@SideOnly(Side.CLIENT)

@Override

public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side){

if(world instanceof World){

if(((World) world).getWorldTime() >= 0 && ((World) world).getWorldTime() <= 2400){

return iconArray[world.getBlockMetadata(x, y, z)];

}

}

return iconUnactive[world.getBlockMetadata(x, y, z)];

    }

Link to comment
Share on other sites

getWorldTime() returns the total amount of time since the world's creation.  There's a comment buried deep on the

long

that is returned which says that it is clamped 0-23999, but that's wrong.  If you do a project-wide search for where that value is set and modified, you will find no such modulation.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

i have tried something like this

@SideOnly(Side.CLIENT)

@Override

public IIcon getIcon(IBlockAccess iBlockAcess, int x, int y, int z, int side){

if(iBlockAcess instanceof World){

long worldTime = ((World) iBlockAcess).getWorldTime() % 24000;

if(worldTime <= 1200){

return iconArray[iBlockAcess.getBlockMetadata(x, y, z)];

}

}

return iconUnactive[iBlockAcess.getBlockMetadata(x, y, z)];

    }

Link to comment
Share on other sites

i have tried something like this

 

And what happened?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ah, I have inadvertently mislead you.

The object passed to that getIcon method, the IBlockAccess is not a World at all, but a ChunkCache.

 

While a ChunkCache object has a World property, it is private.  Instead, you will need to do something a little more clever.  You will need to make a TextureAtlas class.  There's a second reason too.  The icon won't update just because it went from "night" to "day."  You'd also have to tell the game to re-render the blocks.  Fortunately a TextureAtlas can solve both of these problems.

 

Here is a TextureAtlas I use.  It does something very similar, but with a different time scale.  It is up to you to rewrite this class for your needs.  It's a simple class, really.

 

package com.draco18s.wildlife.client;

import com.draco18s.wildlife.WildlifeEventHandler;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureUtil;

@SideOnly(Side.CLIENT)
public class TextureCalendar extends TextureAtlasSprite {

    public TextureCalendar(String par1Str) {
        super(par1Str);
    }

    public void updateAnimation() {
        if (!this.framesTextureData.isEmpty()) {
            Minecraft minecraft = Minecraft.getMinecraft();
            
            int i = frameCounter;
            if (minecraft.theWorld != null && minecraft.thePlayer != null) {
            	i = (int) ((minecraft.theWorld.getWorldTime() % WildlifeEventHandler.yearLength)/(WildlifeEventHandler.yearLength/4));
            	i*=2;
            	if(minecraft.theWorld.provider.isHellWorld) {
                	//Hell does not have day or night, you will want to do something else here.
                	//Look at the TextureClock class in vanilla
            		i++;
            	}
            }
            if (i != this.frameCounter) {
                this.frameCounter = i;
                TextureUtil.uploadTextureMipmap((int[][])this.framesTextureData.get(this.frameCounter), this.width, this.height, this.originX, this.originY, false, false);
            }
        }
    }
}

 

You will also need to register an event handler:

 

public class ClientEventHandler {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void registerTextures(TextureStitchEvent.Pre event) {
	if(event.map.getTextureType() == 1 ) {
		//change these to point to your own variables and texture strings.  The two strings should be identical.
		event.map.setTextureEntry("wildlife:season_calendar", ClientProxy.calendar = new TextureCalendar("wildlife:season_calendar"));
	}
}
}

 

Finally, your getIcon and registerIcon methods:

	@SideOnly(Side.CLIENT)
@Override
    public void registerIcons(IIconRegister iconReg) {
	itemIcon = ClientProxy.calendar;
    }

@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1) {
	return ClientProxy.calendar;
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Draco, you don't need the stitch event. registerIcons method in Blocks / Items class is equivalent to an event handler on that event.

 

Noted.  I wrote that code months ago and whatever reference I had did it that way and I never tried using the registerIcons method for it.

 

Wait if it says if worldhellworld doesnt it only work in the nether ?

 

Sigh.  That check handles a portion of the code.  In my case it makes it select an odd numbered item out of a list, rather than an even one.

Learn 2 Java

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.