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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have done this now but have got the error:   'food(net.minecraft.world.food.FoodProperties)' in 'net.minecraft.world.item.Item.Properties' cannot be applied to                '(net.minecraftforge.registries.RegistryObject<net.minecraft.world.item.Item>)' public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register( "lemon_juice", () -> new Item( new HoneyBottleItem.Properties().stacksTo(1).food( (new FoodProperties.Builder()) .nutrition(3) .saturationMod(0.25F) .effect(() -> new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 1500), 0.01f ) .build() ) )); The code above is from the ModFoods class, the one below from the ModItems class. public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register("lemon_juice", () -> new Item(new Item.Properties().food(ModFoods.LEMON_JUICE)));   I shall keep going between them to try and figure out the cause. I am sorry if this is too much for you to help with, though I thank you greatly for your patience and all the effort you have put in to help me.
    • I have been following these exact tutorials for quite a while, I must agree that they are amazing and easy to follow. I have registered the item in the ModFoods class, I tried to do it in ModItems (Where all the items should be registered) but got errors, I think I may need to revert this and figure it out from there. Once again, thank you for your help! 👍 Just looking back, I have noticed in your code you added ITEMS.register, which I am guessing means that they are being registered in ModFoods, I shall go through the process of trial and error to figure this out.
    • ♈+2349027025197ஜ Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join a brotherhood for protection and wealth here’s is your opportunity, but you should know there’s no ritual without repercussions but with the right guidance and support from this great temple your destiny is certain to be changed for the better and equally protected depending if you’re destined for greatness Call now for enquiry +2349027025197☎+2349027025197₩™ I want to join ILLUMINATI occult without human sacrificeGREATORLDRADO BROTHERHOOD OCCULT , Is The Club of the Riches and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In Greatorldrado BROTHERHOOD we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money Rewards once they join in order to upgrade their lifestyle.; interested viewers should contact us; on. +2349027025197 ۝ஐℰ+2349027025197 ₩Greatorldrado BROTHERHOOD OCCULT IS A SACRED FRATERNITY WITH A GRAND LODGE TEMPLE SITUATED IN G.R.A PHASE 1 PORT HARCOURT NIGERIA, OUR NUMBER ONE OBLIGATION IS TO MAKE EVERY INITIATE MEMBER HERE RICH AND FAMOUS IN OTHER RISE THE POWERS OF GUARDIANS OF AGE+. +2349027025197   SEARCHING ON HOW TO JOIN THE Greatorldrado BROTHERHOOD MONEY RITUAL OCCULT IS NOT THE PROBLEM BUT MAKE SURE YOU'VE THOUGHT ABOUT IT VERY WELL BEFORE REACHING US HERE BECAUSE NOT EVERYONE HAS THE HEART TO DO WHAT IT TAKES TO BECOME ONE OF US HERE, BUT IF YOU THINK YOU'RE SERIOUS MINDED AND READY TO RUN THE SPIRITUAL RACE OF LIFE IN OTHER TO ACQUIRE ALL YOU NEED HERE ON EARTH CONTACT SPIRITUAL GRANDMASTER NOW FOR INQUIRY +2349027025197   +2349027025197 Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join
    • Hi, I'm trying to use datagen to create json files in my own mod. This is my ModRecipeProvider class. public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder { public ModRecipeProvider(PackOutput pOutput) { super(pOutput); } @Override protected void buildRecipes(Consumer<FinishedRecipe> pWriter) { ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', ModItems.COMPRESSED_DIAMOND.get()) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get(),9) .requires(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .unlockedBy(getHasName(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()), has(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get())) .save(pWriter); ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', Blocks.DIAMOND_BLOCK) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); } } When I try to run the runData client, it shows an error:  Caused by: java.lang.IllegalStateException: Duplicate recipe compressed:compressed_diamond I know that it's caused by the fact that there are two recipes for the ModItems.COMPRESSED_DIAMOND. But I need both of these recipes, because I need a way to craft ModItems.COMPRESSED_DIAMOND_BLOCK and restore 9 diamond blocks from ModItems.COMPRESSED_DIAMOND. Is there a way to solve this?
  • Topics

×
×
  • Create New...

Important Information

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