Mightydanp Posted October 1, 2015 Posted October 1, 2015 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 Quote
deerangle Posted October 1, 2015 Posted October 1, 2015 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"); } } Quote
deerangle Posted October 1, 2015 Posted October 1, 2015 and you have to do the tessellating, using the texture afterwards. this.bindTexture(texture); Tessellator tess = new Tessellator.getInstance(); //tessellating stuffs tess.addVertexWithUV(0, 0, 0, 0, 0); //etc. Quote
Mightydanp Posted October 1, 2015 Author Posted October 1, 2015 im not using a tileneitity special renerer i am using a basic furnace code to try to get the blocks to switch from one block to the other based on what time of day it is Quote
Draco18s Posted October 1, 2015 Posted October 1, 2015 Or you could use the getIcon(World, x, y, z) methods and ask the world what time it is... Quote 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.
Mightydanp Posted October 2, 2015 Author Posted October 2, 2015 I have tried that in a form it did not work because it would always we turn false Quote
Draco18s Posted October 2, 2015 Posted October 2, 2015 it would always return false What. Quote 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.
Mightydanp Posted October 2, 2015 Author Posted October 2, 2015 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; } Quote
Draco18s Posted October 2, 2015 Posted October 2, 2015 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. Quote 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.
Mightydanp Posted October 2, 2015 Author Posted October 2, 2015 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 Quote
Mightydanp Posted October 2, 2015 Author Posted October 2, 2015 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)]; } Quote
Draco18s Posted October 2, 2015 Posted October 2, 2015 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. Quote 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.
Mightydanp Posted October 2, 2015 Author Posted October 2, 2015 Alright so your saying i cant use it in the way that im using it to fins out the time of say ? ( i just woke up) Quote
Mightydanp Posted October 2, 2015 Author Posted October 2, 2015 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)]; } Quote
Draco18s Posted October 3, 2015 Posted October 3, 2015 i have tried something like this And what happened? Quote 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.
Draco18s Posted October 3, 2015 Posted October 3, 2015 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; } Quote 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.
Mightydanp Posted October 3, 2015 Author Posted October 3, 2015 Wait if it says if worldhellworld doesnt it only work in the nether ? Quote
Draco18s Posted October 3, 2015 Posted October 3, 2015 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 Quote 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.
Recommended Posts
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.