Jump to content

Recommended Posts

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!

Posted

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.

Posted

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?

Posted

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 :/

 

Posted

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] ?

Posted

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

×   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



×
×
  • Create New...

Important Information

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