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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
    • Hello there! I am trying to make custom dimensions for a modpack I am making in an older minecraft version, 1.16.5. I like that version and it has a few other mods that have not been updated that I would still like to use. Anyway, I am having a terrible time with getting my dimension to work and have tried using code from other peoples projects to at least figure out what I'm supposed to be doing but it has not been as helpful as I would have liked. If anyone could help that would be greatly appreciated! Here is my github with all the code as I am using it: https://github.com/BladeColdsteel/InvigoratedDimensionsMod I have also included the last log, https://pastebin.com/zX9vsDSq, I had when I tried to load up a world, let me know if there is anything else I should send though, thank you!
  • Topics

×
×
  • Create New...

Important Information

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