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

I would like to preemptively say I'm sorry I am newish to forge modding, I seem to have come to a stump and can not find the answer in the forums. But My problem is that when one block gets updated with redstone all blocks of the same Id seem to get updated as well, while I Only want a single one(the one seeing redstone) to be updated.

 

The Block Code is As Follows:

 

public static boolean laserState = false;

public void onNeighborBlockChange(World world, int x, int y, int z, int l)
    {
	 if(BlockGlassBase.BaseHasGlass)
	 {
        if (world.isBlockIndirectlyGettingPowered(x, y, z))
        {
        	this.laserState = true;
        	this.setLightValue(0.8f);
        	
        }
        else
        {
        	this.laserState = false;
        	this.setLightValue(0.0f);
        }
	 }
    }

 

The TileEntity Code is As Follows:

 

@Override
    public void updateEntity()
{
	if(BlockGlassLaser.laserState)
	{

        if(!worldObj.isRemote){
        	LaserParticleEffects.spawnParticle("test", this.xCoord+0.5f, this.yCoord-0.1f, this.zCoord+0.5f, 1.5D, -0.1D, 1.5D);
        }
	}
        super.updateEntity();
    }

 

I tried many different things to get this to work from having a incrementing int in the block constructor for an associated id per block but every block was only 1 suggesting all were made at the same time when I logged in(???) I also tried having the laserState variable in the TileEntity Class and from the block class running a function that was located in the TileEntity Class that set its state but to no avail it also updated all blocks as well. :( I'm probably noobing it up but please help!

Maybe you can use metadata or both the on state and the off state?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Mmmm, static. <3

(I love scope.  This is the fourth thread in the last two days that has had the same problem.)

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.

In minecraft there is only one Block instance for each type. So you have to change metadata for your goal. Use world.setBlockMetadataWithNotify.

  • Author

It seems I must make a separate Block Id For This, I was thinking something like this would be promising:

 

if(world.isBlockIndirectlyGettingPowered(i, j, k))
                                {
                                                if(blockID == CLASS.laserStateOff.blockID)
                                                {
                                                        world.setBlockMetadataWithNotify(i, j, k, CLASS.laserStateOn.blockID);
                                }
                                else
                                {
                                                world.setBlockMetadataWithNotify(i, j, k, CLASS.laserStateOff.blockID);
                                }
}

 

My other question though with this is whether I might need to use world.setBlockMetadataWithNotify(i, j, k, CLASS.laserStateOff.blockID); for the original constructors as well or if just having it as above should be fine?

  • Author

Well I was able to finally solve this but was unable to get it working via metadata(probably due to my lack of knowledge on custom TileEntity Blocks and metadata) My method of solving this was to merely create a second Block that had the particle render in its own tileentity.

ex:

public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        if (world.isBlockIndirectlyGettingPowered(i, j, k))
        {
        	world.setBlock(i,j,k,Blocks.blockGlassLaserOn.blockID);
        }
    }

 

and then on the other block I merely reversed it.

public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        if (!world.isBlockIndirectlyGettingPowered(i, j, k))
        {
        	world.setBlock(i,j,k,Blocks.blockGlassLaser.blockID);
        }
    }

 

though I did not want to do this as it creates issues with if the player left it in the on state and were to restart the client/server it would crash cause it calls the particle render too fast and sees a nullpointer :( So If anyone knows of a way to fix this? or maybe set a block in the world with an id=blockGlassLaserOn.blockID To the default off state when the server/client is first loaded so it will not crash. I think atm though I can fix it by setting a bool in the load event to false and set it to true when the default block gets power although this is unfortunate as the player will have to turn it off and back on again in the case they left it in the on position when they quit the client/server :/

 

world.setBlockMetadataWithNotify(i, j, k, CLASS.laserStateOn.blockID);

That method set the block metadata, according to the last parameter given. Do you know the metadata range is [0,15] ?

  • Author

ah ok, that might have been what was happening. I will retry that then.

  • Author

Well I was finally able to get back to coding and yep, merely setting the metadata values below 15 worked :) TY! In the tileentity I now just check for this.getMetadata. which works great! and for the crashing issue I just use this.metaData = 0; inside the tileentity constructor and that resets it to 0 when the game is freshly loaded.

Example:

 

Block Class

public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
	 System.out.println("neighbor Event ran");
        if (world.isBlockIndirectlyGettingPowered(i, j, k))
        {
        	world.setBlockMetadataWithNotify(i, j, k, 2,3);
        }
        else
        {
        	world.setBlockMetadataWithNotify(i, j, k, 0,3);
        }
    }

TileEntityClass

public TileEntityGlassLaser()
{
	this.blockMetadata = 0;
}
@Override
    public void updateEntity()
{
	if(this.getBlockMetadata() == 2)
	{
        if(!worldObj.isRemote){
        	LaserParticleEffects.spawnParticle("test", this.xCoord+0.5f, this.yCoord-0.1f, this.zCoord+0.5f, 1.5D, -0.1D, 1.5D);
        }
	}
        super.updateEntity();
    }

 

TY Everyone!

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.