Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello, how I can update the current light level?...This is my code:

 

 

 

   
    @SubscribeEvent
    public void NearUraniumEvent(PlayerEvent event) {
        
        int blockX = event.entityPlayer.getPosition().getX();
        int blockY = event.entityPlayer.getPosition().down().getY();
        int blockZ = event.entityPlayer.getPosition().getZ();
        
        BlockPos pos = new BlockPos(blockX, blockY, blockZ);
        
        Block block = event.entityPlayer.worldObj.getBlockState(pos).getBlock();
        
        if(block == NukeMod.uranium_grass) {
            
            System.out.println("Uranium_grass down!");
                        
            event.entityPlayer.worldObj.getBlockState(pos).getBlock().setLightLevel(1.0F);
            
        }else {
            
            event.entityPlayer.worldObj.getBlockState(pos).getBlock().setLightLevel(0.0F);
            
        }
        
        int light = event.entityPlayer.worldObj.getBlockState(pos).getBlock().getLightValue();
        
        System.out.println("Light: " + light);
        
    }   

 

 

The light value changes correctly (There is the print in console...), but I don't know hoe to refresh the block :( Help me please.

 

that you cannot, is one thing.

 

first, let me explain what you tried to do. (later we'll see what you may have wanted to do.)

getBlock() returns a Block - but not an individual instance (as seen by player). object that you have there represents all blocks in the world of the same type (including variations, for example wooden log orientation and before 1.13 wood types). now if you change its hardness, resistance, light level (if you manage to), inside the game that would affect ALL blocks of the same type, anywhere in the world. in other words, not what you want. i hope.

 

 

but what is it that you want to do? different blockstates of the same block can have different light intensities.

if that is what you want, just do SetBlockState() to change your block to the correct/new state. for the last parameter put 3 (or was it 11? can't remember. let's go with 3), one of those two flags (inside "3") tells the game to update what the players see).

  • Author

OK, so I will use setBlockState, but it requiers an IBlockState, that must have the Block state ( setBlockState(pos, IBlockState, 3); ) ...how can I set Light Level by using this?

Edited by progamergalil

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.