Jump to content

Flower that glows at night, not in the day


microjunk

Recommended Posts

So as the title states I have a flower that I wish to make glow at night and not during the day. I have made several attempts at this all ending in not working correctly. The code I have now will make it glow at night if placed at night, but continues to glow during the day. If placed during the day, it will not glow at night....

 

Here is the code I have now.

public class BlockTwilightRose extends BlockFlower
{

	public BlockTwilightRose(int i, int j) 
        {
                super(i, j);
                this.setCreativeTab(Trees.tabTreeDeco);
                this.setTickRandomly(true);
        }

        public int getTextureSize()
        {
        	return 128;
        }
        
        public String getTextureFile()
        {
         return "/microjunk/trees/common/aart/HD_flowers.png";
        }
        
        /*public int tickRate()
        {
            return 10;
        }*/
        public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
        {
        	if (!par1World.isRemote)
            {
                long var6 = par1World.getWorldTime();
        		if(par1World.getBlockLightValue_do(par2, par3, par4,true)<10.0F || (par1World.canBlockSeeTheSky(par2, par3, par4) && var6 > 12000))
        		{
        			//var1.setBlockWithNotify(var2, var3, var4, blockID);
        			this.setLightValue(1F);
        		}
        		else
        		{
        			//var1.setBlockWithNotify(var2, var3, var4, blockID);
        			this.setLightValue(0F);
        		}
            }
            return par9;
        }        
        @Override
        public void updateTick(World var1, int var2, int var3, int var4, Random var5)
        {
        	this.onBlockPlaced(var1, var2, var3, var4,0,0F,0F,0F,0);
        }
        
        //public void randomDisplayTick(World var1, int var2, int var3, int var4, Random var5)
        //{
        //    this.updateTick(var1, var2, var3, var4, var5);
        //}
        
        /**
         * Returns the quantity of items to drop on block destruction.
         */
        public int quantityDropped(Random par1Random)
        {
            return 1;
        }

        /**
         * Returns the ID of the items to drop on destruction.
         */
        public int idDropped(int par1, Random par2Random, int par3)
        {
            return Trees.twilightRose.blockID;
        }
        
        
}

 

Any help at all is appreciated, thanks

Link to comment
Share on other sites

Unfortunately setLightValue is a class-wide...thing.

 

If you open up BlockRedstoneLamp you'll see that it actually uses two block IDs to be lit or unlit:

 

Block.java

public static final Block redstoneLampIdle = (new BlockRedstoneLight(123, false))
public static final Block redstoneLampActive = (new BlockRedstoneLight(124, true))

 

BlockRedstoneLight.java

public BlockRedstoneLight(int par1, boolean par2)
    {
        super(par1, 211, Material.redstoneLight);
        this.powered = par2;

        if (par2)
        {
            this.setLightValue(1.0F);
            ++this.blockIndexInTexture;
        }
    }

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

Unfortunately setLightValue is a class-wide...thing.

 

If you open up BlockRedstoneLamp you'll see that it actually uses two block IDs to be lit or unlit:

 

Block.java

public static final Block redstoneLampIdle = (new BlockRedstoneLight(123, false))
public static final Block redstoneLampActive = (new BlockRedstoneLight(124, true))

 

BlockRedstoneLight.java

public BlockRedstoneLight(int par1, boolean par2)
    {
        super(par1, 211, Material.redstoneLight);
        this.powered = par2;

        if (par2)
        {
            this.setLightValue(1.0F);
            ++this.blockIndexInTexture;
        }
    }

 

Actually there's a forge-hook for this purpose! It's called << int getLightValue(IBlockAccess world, int x, int y, int z) >>

You can read the javadoc what it does and what you have to return.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Yes, I have seen the getLightValue, I wasnt sure how to set it up, because when I tried it just kept showing errors, and suggesting to make this change or that change. So I abandoned hope using that. I even read the javadoc for it and its kind of vague to me. I was hoping to use a update tick but everything I tried doing that has not worked correctly or failed completely. Thats why I asked here. Could you possibly show me an example using getLightValue? Or know a github repo source whos mod uses it that I can look at to see what I was missing or doing wrong? Forge docs just dont have enough examples of how to set things up....

Link to comment
Share on other sites

Actually there's a forge-hook for this purpose! It's called << int getLightValue(IBlockAccess world, int x, int y, int z) >>

You can read the javadoc what it does and what you have to return.

 

Oh fancy.

 

Still if that method isn't working for you, the redstone lamp way works :P

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

Try harnessing ticks in some way. You'll likely have to set up some code to keep it synced, but a static variable (since they'll all be turning on at the same time) could be checked repeatedly for the correct value, and trigger the change in either light value or block.

 

It would be pretty cool if you could figure out how to dynamically change the light value, as that would allow you to make it pulse softly in the dark, or slowly fade "on" at twilight, instead of turning on abruptly like a light switch.

 

I like this idea, and I'm half tempted to code it and post it here.

Link to comment
Share on other sites

I like this idea, and I'm half tempted to code it and post it here.

 

I am too, actually. :P

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 be pretty cool if you could figure out how to dynamically change the light value, as that would allow you to make it pulse softly in the dark, or slowly fade "on" at twilight, instead of turning on abruptly like a light switch.

 

I like this idea, and I'm half tempted to code it and post it here.

 

I wish someone would help, I have been trying for almost 3 weeks and this is best I got

Link to comment
Share on other sites

  You will either have to:

1) rely on random ticks to update the block to a lit one, not precise

 

2) use a tile entity to keep track of time,  heavier on processing

 

3) keep track of all loaded block coords and update via a scheduled tick handler.

 

Or you could try using a scheduled tick handler to manipulate a boolean that sets the light value on Day/night rotations, however sleep will ruin the tick handler so you'll need to make a check for that...

I think its my java of the variables.

Link to comment
Share on other sites

I tried to keep this within one block ID, but  there's no way (that I know of) to do it that simply. There doesn't seem to be any way to force the lighting engine to recognize an updated lightValue, which is a pity. Minecraft's lighting engine generally seems rather buggy and featureless, tbh.

 

Anyways, I'll play with this more tomorrow and see what I can do, but no matter what the result is going to consume more ID's (and system resources) than I'd like.

Link to comment
Share on other sites

That's a shame.  Oh well.

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

So no night flower then huh. Well at least I got more interest here than I did in the MinecraftForums... It seems there people just dont have enough concern to actually contribute to the development of mods as they do here....

 

I would really like to see this though, it would be a great addition to my More Than Just Trees mod.

Link to comment
Share on other sites

IBlockAccess is an interface.  It supplied a handful of methods that might be relevant for that function call.  It's like World-lite.

 

In any case, I found that IBlockAccess was insufficient for the desired effect.  Here's what I ended up with:

 

public class GlowFlower extends Block {
//If you want a flower as per flower, extend BlockFlower.  I wanted mine to be placable under water, so I couldn't.
protected static World theWorld;

public GlowFlower(int par1, int par2, Material par3Material) {
	super(par1, par2, par3Material);
	setBlockName("Glow Moss");
	setStepSound(soundGrassFootstep);
        	setTickRandomly(true);
        	float var4 = 0.2F;
        	setBlockBounds(0.5F - var4, 0.0F, 0.5F - var4, 0.5F + var4, var4 * 3.0F, 0.5F + var4);
        	setCreativeTab(CreativeTabs.tabDecorations);
}

public GlowFlower(int par1, Material par2) {
	super(par1, par2);
	setBlockName("Glow Moss");
	setStepSound(soundGrassFootstep);
        	float var4 = 0.2F;
        	setBlockBounds(0.5F - var4, 0.0F, 0.5F - var4, 0.5F + var4, var4 * 3.0F, 0.5F + var4);
        	setCreativeTab(CreativeTabs.tabDecorations);
}

public void onBlockAdded(World world, int x, int y, int z) {
	if(theWorld == null)
		theWorld = world;
	world.scheduleBlockUpdate(x, y, z, blockID, 600);
}

public void updateTick(World world, int x, int y, int z, Random par5Random) {
	if(theWorld == null)
		theWorld = world;  //make sure theWorld is not null
	getLightValue(null, x, y, z); //force recheck of light level, probably not needed
	world.scheduleBlockUpdate(x, y, z, blockID, 600);  //schedule another update
}

@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
	if(theWorld != null) {
		int a = theWorld.calculateSkylightSubtracted(0); //force calculation of current lighting levels
		if(a > 
			return 8;
		else
			return 0;
	}
	else
		return 8; //light level when the world is loaded (loading from save does not call onAdded, onPlaced, etc.)
}

public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
        return null;
    }

public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

public int getRenderType()
    {
        return 1;
    }

 

It DOES light up at night and turn off during the day, but it's updates are once a minute (I didn't feel like burdening the system with frequent updates).  And I had to make a class-level reference to the World in order to get the current sky light level.

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

Did you run it?

 

Note that this line:

 

int a = theWorld.calculateSkylightSubtracted(0); //force calculation of current lighting levels

 

Gets how much below 15 the current light level is (note the SUBTRACTED part).  Oddly I didn't find the "get current light level" function.  Either I missed seeing it, or it's part of a different class.

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

IBlockAccess is an interface.  It supplied a handful of methods that might be relevant for that function call.  It's like World-lite.

 

In any case, I found that IBlockAccess was insufficient for the desired effect.  Here's what I ended up with:

 

public class GlowFlower extends Block {
//If you want a flower as per flower, extend BlockFlower.  I wanted mine to be placable under water, so I couldn't.
protected static World theWorld;

public GlowFlower(int par1, int par2, Material par3Material) {
	super(par1, par2, par3Material);
	setBlockName("Glow Moss");
	setStepSound(soundGrassFootstep);
        	setTickRandomly(true);
        	float var4 = 0.2F;
        	setBlockBounds(0.5F - var4, 0.0F, 0.5F - var4, 0.5F + var4, var4 * 3.0F, 0.5F + var4);
        	setCreativeTab(CreativeTabs.tabDecorations);
}

public GlowFlower(int par1, Material par2) {
	super(par1, par2);
	setBlockName("Glow Moss");
	setStepSound(soundGrassFootstep);
        	float var4 = 0.2F;
        	setBlockBounds(0.5F - var4, 0.0F, 0.5F - var4, 0.5F + var4, var4 * 3.0F, 0.5F + var4);
        	setCreativeTab(CreativeTabs.tabDecorations);
}

public void onBlockAdded(World world, int x, int y, int z) {
	if(theWorld == null)
		theWorld = world;
	world.scheduleBlockUpdate(x, y, z, blockID, 600);
}

public void updateTick(World world, int x, int y, int z, Random par5Random) {
	if(theWorld == null)
		theWorld = world;  //make sure theWorld is not null
	getLightValue(null, x, y, z); //force recheck of light level, probably not needed
	world.scheduleBlockUpdate(x, y, z, blockID, 600);  //schedule another update
}

@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
	if(theWorld != null) {
		int a = theWorld.calculateSkylightSubtracted(0); //force calculation of current lighting levels
		if(a > 
			return 8;
		else
			return 0;
	}
	else
		return 8; //light level when the world is loaded (loading from save does not call onAdded, onPlaced, etc.)
}

public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
        return null;
    }

public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

public int getRenderType()
    {
        return 1;
    }

 

It DOES light up at night and turn off during the day, but it's updates are once a minute (I didn't feel like burdening the system with frequent updates).  And I had to make a class-level reference to the World in order to get the current sky light level.

 

Thanks, this works pretty good, was playing with it some to make the flower a bit brighter, and also to answer the other question by vogner I would really like it to light up at night, not in the dark necessarily. I dont plan to have it spawn in the caves or anything like that, and also I plant to have it as rare as I can get it....

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

    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
  • Topics

×
×
  • Create New...

Important Information

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