Jump to content

[1.7.10] how to emit light from a held item


Recommended Posts

ok so I created a method to add a potion effect to a player(like night vision) but I decided I wanted it to make the item emit light. so I had the players brightness increase when he holds the item making it look like the item glows. problem is it doesn't work. how should I fix it.

 

 

 

    public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
	super.onUpdate(stack, world, entity, par4, par5);
	{
	    EntityPlayer  player = (EntityPlayer) entity;
	    ItemStack equipped = player.getCurrentEquippedItem();
	    if(equipped == stack){
	    	  player.getBrightness(3.0f);
	    	  player.getBrightnessForRender(15728880);
	    }
	}
    }

Im serious don't look at it!!

Link to comment
Share on other sites

It works a litle bit more complicated than that. What you tried to set was the player model brightness. It does nothing with the players view. If you dont want to make things overcomplicated, I would stick with the nightvision potion. Otherwise you have to dig a lot deeper.

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Link to comment
Share on other sites

Hi

I've seen modders do this before, so it's possible (anything is possible in your code if you keep at it). Some people achieve this under one exception, its a hacky solution. What they do is they spawn in a block with a light source somewhere around the player and remove it. Either that or they spawn in a block with a transparent texture that has a light value to emit light around the player. I know that there is better solutions out there, so keep looking unless you fancy using the invisible light source block method.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

If you are actually trying to cast light from player (like a torch does), then there are only 2 ways to do it (not counting stupid try-hards).

 

Either write core mod that will change lighting system - lookup atomicstryker's DynamicLights.

 

Or update block light around source every tick. This is btw the stupidest idea anyone could come up with - it will cause massive lag. Good solution only for hype-PC and super-servers.

 

If you want to know exacly how to write it - GOOGLE or better - use this forum's search engine. There was a thread about month ago (maybe more).

 

Unless you wanted different thing?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Don't edit base files, that's never really good. Look into the torch class and see what it does. Try to implement that into your mod. If you still can't figure it out, look at some other mods such as Dynamic Lights (I believe this is the correct name), as they do exactly what you want. Even if the mod source is not in a repository or released somewhere, IDEA Intellij has a built-in decompiler.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

  • 2 weeks later...

Hey, sorry for dredging up a topic that is two weeks old. However, now that I had day off I had time to try to figure out how to make a handheld torch. It was actually really easy and doesn't seem to lag.

 

Here is a vid of it working:

 

What do you think?

 

The technique I used was to place an invisible torch at the head level of the player. It is a block, so I had to do things to ensure you could still interact with other blocks (that is why I do a bit of digging at the end of the video), and also needed to handle case when you're going through doors (since there is a point where the torch would interfere with the top block of the door) and other 2-block high situations like running through grass.

 

Overall though I was pleased with the result and it really wasn't hard to do. I'll write up a tutorial soon.

 

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

Link to comment
Share on other sites

Not really a new trick.

There are some problems with it, too, if you're not careful. But they're minor and as long as you are aware of them, you can tweak the invisible block (and item) to account for it.

 

Eg. What happens if the player drops the item? Dies? Is underwater? Had sand fall on him?

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

Not really a new trick.

There are some problems with it, too, if you're not careful. But they're minor and as long as you are aware of them, you can tweak the invisible block (and item) to account for it.

 

Eg. What happens if the player drops the item? Dies? Is underwater? Had sand fall on him?

 

Yeah, there is a lot of scenarios to check.

 

But the logic is really clean so the scenarios you mention aren't relevant. What I'm doing is detecting when the player holds a regular torch and then placing invisible light emitting blocks accordingly. But I only place it if there is air in the location. So if you're under water it works (meaning that the light goes out) and then comes on again when you resurface (for realism I suppose I could make an "extinquished torch" as well, but I'm just proving the concept). Since the block doesn't have any collision box sand and such seems to work normally.

 

Also, because it is just working when holding a normal torch if you drop it, it is just dropping a regular torch. The blocks will "kill" themselves over time so if the player dies or something it shouldn't cause issue.

 

I'm not saying that the approach is new, however, it was much easier to implement than I expected and not laggy at all (most people including myself thought it would be). Also it doesn't mess with G11 or anything so is really a beginner level mod. Other mods with similar effect like Dynamic Lighting has a lot of compatibility issues. In terms of mod compatibility I suspect that only another mod that places invisible blocks in same place would have conflict.

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

Link to comment
Share on other sites

Other mods with similar effect like Dynamic Lighting has a lot of compatibility issues. In terms of mod compatibility I suspect that only another mod that places invisible blocks in same place would have conflict.

 

Invisible blocks are just blocks.

But if you want to test it, go find my Unique Artifacts mod.

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

Other mods with similar effect like Dynamic Lighting has a lot of compatibility issues. In terms of mod compatibility I suspect that only another mod that places invisible blocks in same place would have conflict.

 

Invisible blocks are just blocks.

But if you want to test it, go find my Unique Artifacts mod.

 

Yes, but I can't think of any mods that create visible blocks on the player's head. Does yours do that? I'll check it out.

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

Link to comment
Share on other sites

Yes, it absolutely does, which is why I suggested it .

 

Edit: fixed url tag;  tablets are annoying

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

uUrl=https://github.com/Draco18s/Artifacts/blob/master/main/java/com/draco18s/artifacts/components/ComponentLight.java]Yes, it absolutely does, which is why I suggested it [/url].

 

Okay, cool. You had so much information about all sorts of artifacts it wasn't clear to me which one might be a problem. I'll check it out.

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

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.



×
×
  • Create New...

Important Information

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