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

    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
  • Topics

×
×
  • Create New...

Important Information

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