Jump to content

Multi-block doesn't break proerly


KeeganDeathman

Recommended Posts

I setup my multi-block so when its assembled, the textures conenct, and when its not, not yet, or its broken, they result to a separate texture.

I have it setup so it checks every time onEntityUpdate is ran on the central tile entity, it will report to the blocks that connect (the 'walls') whether or not the multiblock is complete.

In addition to it knowing when the other blocks are broken, the block class of the tile entity will set the 'multiblock' Boolean of the walls(which are stored in an array passed to it from the tile entity every update) to false.

However, if another complete multiblock exists in the world, it doesn't break right. I deciphered it to this.

The Boolean isnt changed on break, until all of the 'central TEs' are removed from the world(I haven't tried breaking one of the other blocks in all other multi-blocks), and only the sides of the blocks that decipher their correct textures based off their location relative to the tile-entities position revert.

Also, sometimes the 'back' of the multi-block doesnt revert, when the aforementioned bug condition is met. Until I break one of the affected blocks and replace it, to look pretty, and see if those blocks still thought the structure was complete(they didnt).

 

onEntityUpdate()

 

 

public void updateEntity()
{
	if ((worldObj.getBlock(xCoord+1, yCoord, zCoord) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord, zCoord) != null)
	&&(worldObj.getBlock(xCoord+1, yCoord+1, zCoord) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord+1, zCoord) != null)
	&&(worldObj.getBlock(xCoord+1, yCoord-1, zCoord) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord+1, zCoord) != null)
	&&(worldObj.getBlock(xCoord, yCoord+1, zCoord) != null)
	&&(worldObj.getBlock(xCoord, yCoord-1, zCoord) != null)
	&&(worldObj.getBlock(xCoord+1, yCoord, zCoord+1) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord, zCoord+1) != null)
	&&(worldObj.getBlock(xCoord+1, yCoord+1, zCoord+1) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord+1, zCoord+1) != null)
	&&(worldObj.getBlock(xCoord+1, yCoord-1, zCoord+1) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord+1, zCoord+1) != null)
	&&(worldObj.getBlock(xCoord, yCoord+1, zCoord+1) != null)
	&&(worldObj.getBlock(xCoord, yCoord-1, zCoord+1) != null)
	&&(worldObj.getBlock(xCoord+1, yCoord, zCoord+2) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord, zCoord+2) != null)
	&&(worldObj.getBlock(xCoord+1, yCoord+1, zCoord+2) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord+1, zCoord+2) != null)
	&&(worldObj.getBlock(xCoord+1, yCoord-1, zCoord+2) != null)
	&&(worldObj.getBlock(xCoord-1, yCoord+1, zCoord+2) != null)
	&&(worldObj.getBlock(xCoord, yCoord+1, zCoord+2) != null)
	&&(worldObj.getBlock(xCoord, yCoord-1, zCoord+2) != null)
	&&(worldObj.getBlock(xCoord, yCoord, zCoord+2) != null)) {
		if ((worldObj.getBlock(xCoord + 1, yCoord, zCoord) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord, zCoord) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord + 1, yCoord + 1, zCoord) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord + 1, zCoord) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord + 1, yCoord - 1, zCoord) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord + 1, zCoord) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord, yCoord + 1, zCoord) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord, yCoord - 1, zCoord) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord + 1, yCoord, zCoord + 1) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord, zCoord + 1) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord + 1, yCoord + 1, zCoord + 1) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord + 1, zCoord + 1) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord + 1, yCoord - 1, zCoord + 1) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord + 1, zCoord + 1) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord, yCoord + 1, zCoord + 1) == LabStuffMain.blockGasChamberPort)
				&& (worldObj.getBlock(xCoord, yCoord - 1, zCoord + 1) == LabStuffMain.blockGasChamberPort)
				&& (worldObj.getBlock(xCoord + 1, yCoord, zCoord + 2) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord, zCoord + 2) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord + 1, yCoord + 1, zCoord + 2) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord + 1, zCoord + 2) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord + 1, yCoord - 1, zCoord + 2) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord - 1, yCoord + 1, zCoord + 2) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord, yCoord + 1, zCoord + 2) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord, yCoord - 1, zCoord + 2) == LabStuffMain.blockGasChamberWall)
				&& (worldObj.getBlock(xCoord, yCoord, zCoord + 2) == LabStuffMain.blockGasChamberWall)) 
		{
			multiblocks[0][0][0] = worldObj.getBlock(xCoord+1, yCoord+1, zCoord+2);
			multiblocks[0][0][1] = worldObj.getBlock(xCoord, yCoord+1, zCoord+2);
			multiblocks[0][0][2] = worldObj.getBlock(xCoord-1, yCoord+1, zCoord+2);
			multiblocks[0][1][0] = worldObj.getBlock(xCoord+1, yCoord+1, zCoord+1);
			multiblocks[0][1][1] = worldObj.getBlock(xCoord, yCoord+1, zCoord+1);
			multiblocks[0][1][2] = worldObj.getBlock(xCoord-1, yCoord+1, zCoord+1);
			multiblocks[0][2][0] = worldObj.getBlock(xCoord+1, yCoord+1, zCoord);
			multiblocks[0][2][0] = worldObj.getBlock(xCoord, yCoord+1, zCoord);
			multiblocks[0][2][0] = worldObj.getBlock(xCoord-1, yCoord+1, zCoord);
			multiblocks[1][0][0] = worldObj.getBlock(xCoord+1, yCoord, zCoord+2);
			multiblocks[1][0][1] = worldObj.getBlock(xCoord, yCoord, zCoord+2);
			multiblocks[1][0][2] = worldObj.getBlock(xCoord-1, yCoord, zCoord+2);
			multiblocks[1][1][0] = worldObj.getBlock(xCoord+1, yCoord, zCoord+1);
			multiblocks[1][1][1] = worldObj.getBlock(xCoord, yCoord, zCoord+1);
			multiblocks[1][1][2] = worldObj.getBlock(xCoord-1, yCoord, zCoord+1);
			multiblocks[1][2][0] = worldObj.getBlock(xCoord+1, yCoord, zCoord);
			multiblocks[1][2][0] = worldObj.getBlock(xCoord, yCoord, zCoord);
			multiblocks[1][2][0] = worldObj.getBlock(xCoord-1, yCoord, zCoord);
			multiblocks[2][0][0] = worldObj.getBlock(xCoord+1, yCoord-1, zCoord+2);
			multiblocks[2][0][1] = worldObj.getBlock(xCoord, yCoord-1, zCoord+2);
			multiblocks[2][0][2] = worldObj.getBlock(xCoord-1, yCoord-1, zCoord+2);
			multiblocks[2][1][0] = worldObj.getBlock(xCoord+1, yCoord-1, zCoord+1);
			multiblocks[2][1][1] = worldObj.getBlock(xCoord, yCoord-1, zCoord+1);
			multiblocks[2][1][2] = worldObj.getBlock(xCoord-1, yCoord-1, zCoord+1);
			multiblocks[2][2][0] = worldObj.getBlock(xCoord+1, yCoord-1, zCoord);
			multiblocks[2][2][0] = worldObj.getBlock(xCoord, yCoord-1, zCoord);
			multiblocks[2][2][0] = worldObj.getBlock(xCoord-1, yCoord-1, zCoord);
			for(int i = 0; i < 3; i++)
			{
				for(int j = 0; j < 3; j++)
				{
					for(int k = 0; k < 3; k++)
					{
						if(multiblocks[i][j][k] != null && multiblocks[i][j][k] == LabStuffMain.blockGasChamberWall)
						{
							System.out.println("Lets a go!");
							((BlockGasChamberWall)multiblocks[i][j][k]).setMultiBlockState(true);;
						}
					}
				}
			}
		}
		else 
		{
			if(multiblocks[0][0][0] != null)
			{
				for(int i = 0; i < 3; i++)
				{
					for(int j = 0; j < 3; j++)
					{
						for(int k = 0; k < 3; k++)
						{
							if(multiblocks[i][j][k] != null && multiblocks[i][j][k] == LabStuffMain.blockGasChamberWall)
							{
								((BlockGasChamberWall)multiblocks[i][j][k]).setMultiBlockState(false);
							}
						}
					}
				}
			}
		}
	}

	if(worldObj.getBlock(xCoord, yCoord, zCoord) == LabStuffMain.blockElectronGrabber)
	{
		((BlockElectronGrabber) worldObj.getBlock(xCoord, yCoord, zCoord)).multiblocks = multiblocks;
	}

}

 

 

 

removedByPlayer(block destroyed of 'electron grabber)

 

 

@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z)
{
	super.removedByPlayer(world, player, x, y, z);
	if (multiblocks[0][0][0] != null) 
	{
		for (int i = 0; i < 3; i++) 
		{
			for (int j = 0; j < 3; j++) 
			{
				for (int k = 0; k < 3; k++) 
				{
					if (multiblocks[i][j][k] != null && multiblocks[i][j][k] == LabStuffMain.blockGasChamberWall) 
					{
						((BlockGasChamberWall) multiblocks[i][j][k]).setMultiBlockState(false);
					}
				}
			}
		}
	}
	return true;
}

 

 

 

getIcon method of the walls

 

 

@Override
public IIcon getIcon(IBlockAccess access, int x, int y, int z, int side)
    {
	if (isMultiBlock()) 
	{
		if (side == 1 || side == 0) {
			if (access.getBlock(x + 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
				return icons[2][2];
			}
			if (access.getBlock(x, y, z + 1) == LabStuffMain.blockGasChamberPort) {
				return icons[2][1];
			}
			if (access.getBlock(x - 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
				return icons[2][0];
			}
			if (access.getBlock(x + 1, y, z) == LabStuffMain.blockGasChamberPort) {
				return icons[1][2];
			}
			if (access.getBlock(x - 1, y, z) == LabStuffMain.blockGasChamberPort) {
				return icons[1][0];
			}
			if (access.getBlock(x - 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][0];
			}
			if (access.getBlock(x, y, z - 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][1];
			}
			if (access.getBlock(x + 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][2];
			}

			return this.blank;
		}
		if (access.getBlock(x, y - 1, z) == LabStuffMain.blockGasChamberWall
				|| access.getBlock(x, y - 1, z) == LabStuffMain.blockGasChamberPort
				|| access.getBlock(x, y - 1, z) == LabStuffMain.blockElectronCannon
				|| access.getBlock(x, y - 1, z) == LabStuffMain.blockElectronGrabber) {
			if (side == 2 || side == 3) {
				if (access.getBlock(x + 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][2];
				}
				if (access.getBlock(x, y, z + 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][1];
				}
				if (access.getBlock(x - 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][0];
				}
				if (access.getBlock(x + 1, y, z) == LabStuffMain.blockGasChamberPort) {
					return icons[2][2];
				}
				if (access.getBlock(x - 1, y, z) == LabStuffMain.blockGasChamberPort) {
					return icons[2][0];
				}
				if (access.getBlock(x - 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][0];
				}
				if (access.getBlock(x, y, z - 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][1];
				}
				if (access.getBlock(x + 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][2];
				}
			}
			if (side == 4 || side == 5) {
				if (access.getBlock(x + 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][2];
				}
				if (access.getBlock(x - 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][2];
				}
				if (access.getBlock(x + 1, y, z) == LabStuffMain.blockGasChamberPort) {
					return icons[2][1];
				}
				if (access.getBlock(x - 1, y, z) == LabStuffMain.blockGasChamberPort) {
					return icons[2][1];
				}
				if (access.getBlock(x - 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][0];
				}
				if (access.getBlock(x + 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
					return icons[2][0];
				}
			}
			if (side == 2 || side == 3) {
				if ((access.getBlock(x + 1, y, z) == LabStuffMain.blockElectronCannon
						|| access.getBlock(x + 1, y, z) == LabStuffMain.blockElectronGrabber || access
						.getBlock(x + 1, y, z) == LabStuffMain.blockGasChamberWall)
						&& access.getBlock(x, y + 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y - 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x - 1, y, z) != LabStuffMain.blockGasChamberWall) {
					return icons[1][2];
				}
				if ((access.getBlock(x - 1, y, z) == LabStuffMain.blockElectronCannon
						|| access.getBlock(x - 1, y, z) == LabStuffMain.blockElectronGrabber || access
						.getBlock(x - 1, y, z) == LabStuffMain.blockGasChamberWall)
						&& access.getBlock(x, y + 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y - 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x + 1, y, z) != LabStuffMain.blockGasChamberWall) {
					return icons[1][0];
				}
				if (access.getBlock(x - 1, y, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y + 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x + 1, y, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y - 1, z) == LabStuffMain.blockGasChamberWall) {
					return icons[1][1];
				}
			}
			if (side == 4 || side == 5) {
				if ((access.getBlock(x, y, z + 1) == LabStuffMain.blockElectronCannon
						|| access.getBlock(x + 1, y, z) == LabStuffMain.blockElectronGrabber || access
						.getBlock(x, y, z + 1) == LabStuffMain.blockGasChamberWall)
						&& access.getBlock(x, y + 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y - 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y, z - 1) != LabStuffMain.blockGasChamberWall) {
					return icons[1][2];
				}
				if ((access.getBlock(x, y, z - 1) == LabStuffMain.blockElectronCannon
						|| access.getBlock(x - 1, y, z) == LabStuffMain.blockElectronGrabber || access
						.getBlock(x, y, z - 1) == LabStuffMain.blockGasChamberWall)
						&& access.getBlock(x, y + 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y - 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y, z + 1) != LabStuffMain.blockGasChamberWall) {
					return icons[1][0];
				}
				if (access.getBlock(x, y, z - 1) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y + 1, z) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y, z + 1) == LabStuffMain.blockGasChamberWall
						&& access.getBlock(x, y - 1, z) == LabStuffMain.blockGasChamberWall) {
					return icons[1][1];
				}
			}
			return this.blank;
		}
		if (side == 2 || side == 3) {
			if (access.getBlock(x + 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][2];
			}
			if (access.getBlock(x, y, z + 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][1];
			}
			if (access.getBlock(x - 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][0];
			}
			if (access.getBlock(x + 1, y, z) == LabStuffMain.blockGasChamberPort) {
				return icons[0][2];
			}
			if (access.getBlock(x - 1, y, z) == LabStuffMain.blockGasChamberPort) {
				return icons[0][0];
			}
			if (access.getBlock(x - 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][0];
			}
			if (access.getBlock(x, y, z - 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][1];
			}
			if (access.getBlock(x + 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][2];
			}
		}
		if (side == 4 || side == 5) {
			if (access.getBlock(x + 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][2];
			}
			if (access.getBlock(x - 1, y, z + 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][2];
			}
			if (access.getBlock(x + 1, y, z) == LabStuffMain.blockGasChamberPort) {
				return icons[0][1];
			}
			if (access.getBlock(x - 1, y, z) == LabStuffMain.blockGasChamberPort) {
				return icons[0][1];
			}
			if (access.getBlock(x - 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][0];
			}
			if (access.getBlock(x + 1, y, z - 1) == LabStuffMain.blockGasChamberPort) {
				return icons[0][0];
			}
		}
	}
	return this.blank;
    }

 

 

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to comment
Share on other sites

First. Arrrgh, my eyes. There was that pic somewhere with Mickey Mouse tearing his eyes.

Please dedupe code. I'd advise some kind of enumVolume func which returns iterable over some specified volume. I did the thing for myself (though in Scala): https://github.com/target-san/Gateway/blob/master/src/targetsan/mcmods/gateway/Mod.scala (see Utils.enumVolume function).

 

Second, you didn't show isMultiBlock.

 

Third, you need to notify neighbor blocks when one of them is changed/destroyed. So, when any part of multiblock pieces is destroyed, you need to notify _all_ other pieces and enforce their update.

Link to comment
Share on other sites

Okay, yes I see. I was derping last night, and guess I thought the onEntityUpdate() function would handle it all.

But now that I think of it, the entity doesn't update unless there's a block update in BUD range.

Heres the isMultiBlock() function. Nothing special. this was written when I thought the TE would handle it all.

public boolean isMultiBlock()
{
       return this.multiblock();
}

 

Now that I think of it, that should also check to predetermine itself if the multiblock is complete and not rely on the te.

Now hopefully, one block determining the state of the multiblock, well update blocks near it, and those will do the same, and chain reaction.

If not, add a forceupdate call to isMultiblock

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to comment
Share on other sites

I think I found the problem with the textures not reverting until all 'electron grabbers' are removed from the world.

During a test to see if I could send the array from the tile entities to the blocks, and have them decide their icons based on their position in the array(3 for loops, one for each sub-array or whatever, and an if (if(multiblocks[j][k] == this)), however, the tops and bottoms, the only sides implemented in the new method, all defaulted to the icon of multiblock 0,0,0, even wall blocks not part of a multiblock,and therefore shouldnt have a multiblock array, default to 0,0,0s top texture.

My conclusion, for whatever reason, my electron grabber is affecting all wall blocks in the world. Even though it should only affect those in the array. I have not yet tested to see if it is in fact, just a coding bug, and all blocks believe they are 0,0,0 by default, whether or not they have a multiblock, by removing the grabbers, and seeing if their texture resets.

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to comment
Share on other sites

Is the grabber assigning all walls to the array? No, I use world.getBlock, its very strict.

Is the default [00][00][00]? maybe, but that wouldn't explain the original problem. onBlockremoved should set the boolean on all walls. And it does, is just delayed until all grabbers are gone! Maybe, yes! a secondary testing system, to see if there is a tile entity at the coords provided by the tile entity, this would be in the isMultiBlock, and would be half the return value. multiblock boolean would be set to false, if the tile entity doesnt show up! tertiary defense, the return method is return (multiblock && isTileEntityPresent)! Ill add it as soon as I can!

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

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.



×
×
  • Create New...

Important Information

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