Jump to content

Recommended Posts

Posted

I have a light bulb block which has a tile entity. The light bulb will work like any other lamp until its lifetime value, which decreases every tick, reaches 25% of its max value, at which point it will start flashing. When the value reaches 0 it will stop glowing completely.

 

My question is how I can track this value effectively, and if I'm using the randomTick method properly.

This is how I track the value in my tile entity (bare in mind that a lot of unrelated values are cropped right now)

EnergyLevel is an enum that represents a percentage of the energy stored within the tile entity.

Posted

There is already a vanilla effect that flickers when its timer is about to run out. Take a gander at its code.

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.

Posted

I know that this forum can be vague about things so that the OP can figure parts of what the response meant himself and learn more from it, but could you atleast tell me which block/effect you meant? I was thinking about redstone torch/repeater, but they don't have a lifetime mechanic.

Posted

Night Vision

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.

Posted

Night vision works very differently from how I want the block to work though. Night vision visually brightens the players vision periodically without actually making the world brighter. I want my block to randomly become completely dark or get its normal brightness back. Besides, the only night vision related files I can find in IDEA are three fields (two constants from PotionTypes, the other a constant from MobEffects) and a method which is unrelated to what I'm looking for.

 

After trying out the way of doing this I posted earlier I have some problems. The lifetime value in the tile entity decreases more than once per tick, although I don't know how much exactly (log excerpt from the machine posting it once every time update is called, 400 is max). The lamp doesn't blink at all (It's not that I've been unlucky, I've added a print that states when it's triggered, and it's getting triggered correctly). Also when I come back into a world after exiting minecraft with such a lamp already in the world I'm entering I crash with this error. 

Posted

I know that the world isn't actually changed, I was point out that it already had code for taking a "only X time remains" value and converting that into a fluctuation 0-1 value. You're not interested in what that value does you're interested in how that value is calculated.

 

Anyway, if your light is changing to "not bright" but the actual lighting isn't updated. Well...

 

Too bad, because there isn't a fix for that. Trust me, I've already tried having a block that either emits light, or it doesn't. Getting Minecraft to recognize the fact that the block no longer emits light requires changing the block to a different block. Not just changing state, it has to be an entirely different block.

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.

Posted

The night vision effect might work except it is from the perspective of the player, and so I don't think it would be easy to handle cases of multiple lamp blocks each timing out at different times.

 

Instead I think you have to change the light value of individual lamp blocks. However, you can't just change the light value for your lamp block since that would change it for all lamps in the world at the same time.

 

I think what you need to do is use a tile entity system where one is attached to a block with full light value and other with no light value (or low light value depending on the flicker effect you want). You would need two blocks with tile entities really, and each one would have to replace the other while passing information about the timer between them at the time of creation. You would need two timer fields in the light block TE, one for the constant light countdown and another for the flickering. In the non-light block TE you could just have the flickering timer. The light block TE would count down with constant light until it hits zero then would tick the flicker counter for a couple ticks (how ever long a flicker should be), then replace itself with the non-light block TE and pass the flicker counter to it, and the non-light block TE would count down a couple ticks and replace itself with a light block TE.

 

Actually, since the passing of the information back and forth might be a bit tricky, it might be actually easier to create a number of blocks with TE each meant for next step of the flicker. So the main TE will replace itself with TE "flicker 0", which counts down and replaces itself with TE "flicker 1", etc. for as long as you want the flicker to last. You can make the count downs a bit random too for nicer flicker effect.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
7 minutes ago, jabelar said:

The night vision effect might work except it is from the perspective of the player, and so I don't think it would be easy to handle cases of multiple lamp blocks each timing out at different times.

 

Instead I think you have to change the light value of individual lamp blocks. However, you can't just change the light value for your lamp block since that would change it for all lamps in the world at the same time.

You literally both have no idea what you're talking about and didn't understand why I used night vision as a place to go look at a thing.

Quote

However, you can't just change the light value for your lamp block since that would change it for all lamps in the world at the same time.

There is a state-sensitive version of getLightValue(), and you can specify different states by using getActualState() which allows you to get data from a TileEntity. However, my previous post just pointed out why this still won't work though.

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.

Posted (edited)

Actually, you might be able to get away with just three tile entity blocks. One for the constant light, one for flicker off and one for flicker on. If you have randomness for the flicker off, you can give it a random chance of the flicker ending as well so each lamp will flicker a random number of times and eventually not replace itself and it will just remain as the off block.

 

So, idea is:

1. place the constant on TE, it counts down until it should start to flicker.

2. it replaces itself with the flicker off TE, that creates a random counter and possibly ends the flickering. If flicker should continue and it counts down, it goes to next step. 

3. It replaces itself with the flicker on TE, that creates a random counter, and when it counts down goes back to step 2.

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted (edited)
5 minutes ago, Draco18s said:

You literally both have no idea what you're talking about and didn't understand why I used night vision as a place to go look at a thing.

There is a state-sensitive version of getLightValue(), and you can specify different states by using getActualState() which allows you to get data from a TileEntity. However, my previous post just pointed out why this still won't work though.

Okay, true I'm not familiar with what you're talking about but I've created pretty complicated dynamic lighting mods, for example see my moving light sources mod and my proposed method will work for what he's doing. http://jabelarminecraftmods.blogspot.com/p/jabelars-moving-light-source-mod.html

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.