Jump to content

[Solved] [1.9] onBlockActivated running twice


tiffit

Recommended Posts

Before you say, "Oh, you OnBlockActivated runs twice! Once on the server and client!" That is NOT my problem. The client runs twice and the server runs twice.

 

OnBlockActivated:

	@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
	System.out.println("Is Remote: " + world.isRemote);
	LockedDoorTileEntity te = (LockedDoorTileEntity) world.getTileEntity(pos);
	DoorCorner corner = te.corner;
	if(playerIn.isSneaking() && playerIn.isCreative() && !world.isRemote){
		if(corner == DoorCorner.BottomLeftX){
			((LockedDoorTileEntity) world.getTileEntity(pos.add(1, 0, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(1, 1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos)).toggleKey();
		}
		if(corner == DoorCorner.BottomRightX){
			((LockedDoorTileEntity) world.getTileEntity(pos.add(-1, 0, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(-1, 1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos)).toggleKey();
		}
		if(corner == DoorCorner.TopLeftX){
			((LockedDoorTileEntity) world.getTileEntity(pos.add(1, 0, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, -1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(1, -1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos)).toggleKey();
		}
		if(corner == DoorCorner.TopRightX){
			((LockedDoorTileEntity) world.getTileEntity(pos.add(-1, 0, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, -1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(-1, -1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos)).toggleKey();
		}

		if(corner == DoorCorner.BottomLeftZ){
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 0, 1))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 1, 1))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos)).toggleKey();
		}
		if(corner == DoorCorner.BottomRightZ){
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 0, -1))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 1, -1))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos)).toggleKey();
		}
		if(corner == DoorCorner.TopLeftZ){
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 0, 1))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, -1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, -1, 1))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos)).toggleKey();
		}
		if(corner == DoorCorner.TopRightZ){
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, 0, -1))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, -1, 0))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos.add(0, -1, -1))).toggleKey();
			((LockedDoorTileEntity) world.getTileEntity(pos)).toggleKey();
		}
		LockedDoorTileEntity tehere = (LockedDoorTileEntity)world.getTileEntity(pos);
		String keyName = tehere.useSilverKey ? TextFormatting.DARK_GRAY + "silver " : TextFormatting.GOLD + "gold ";
		playerIn.addChatComponentMessage(new TextComponentString("This door now takes the " + keyName + TextFormatting.RESET + "key."));
		TaleCraft.network.sendToDimension(new DoorPacket(pos, tehere.useSilverKey), world.provider.getDimension());
		return false;
	}
	if(world.isRemote){
		if(heldItem != null && heldItem.getItem() instanceof KeyItem){
			if((heldItem.getItem() == TaleCraftItems.silverKey && te.useSilverKey) || (heldItem.getItem() == TaleCraftItems.goldKey && !te.useSilverKey))world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.block_chest_open, SoundCategory.BLOCKS, 100f, 1f, false);
		}
		return false;
	}
	if(heldItem != null && heldItem.getItem() instanceof KeyItem){
		if((heldItem.getItem() == TaleCraftItems.silverKey && te.useSilverKey) || (heldItem.getItem() == TaleCraftItems.goldKey && !te.useSilverKey)){
			world.setBlockToAir(pos);
			onBlockDestroyedByPlayer(world, pos, state);
			heldItem.stackSize--;
			return false;
		}
	}
	return true;
}

 

Console Output:

 

[17:11:50] [Client thread/INFO] [sTDOUT]: [tiffit.talecraft.blocks.world.LockedDoorBlock:onBlockActivated:42]: Is Remote: true

[17:11:50] [Client thread/INFO] [sTDOUT]: [tiffit.talecraft.blocks.world.LockedDoorBlock:onBlockActivated:42]: Is Remote: true

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.blocks.world.LockedDoorBlock:onBlockActivated:42]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.tileentity.LockedDoorTileEntity:toggleKey:32]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.tileentity.LockedDoorTileEntity:toggleKey:32]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.tileentity.LockedDoorTileEntity:toggleKey:32]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.tileentity.LockedDoorTileEntity:toggleKey:32]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.blocks.world.LockedDoorBlock:onBlockActivated:42]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.tileentity.LockedDoorTileEntity:toggleKey:32]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.tileentity.LockedDoorTileEntity:toggleKey:32]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.tileentity.LockedDoorTileEntity:toggleKey:32]: Is Remote: false

[17:11:50] [server thread/INFO] [sTDOUT]: [tiffit.talecraft.tileentity.LockedDoorTileEntity:toggleKey:32]: Is Remote: false

[17:11:50] [Client thread/INFO]: [CHAT] This door now takes the §6gold §rkey.

[17:11:50] [Client thread/INFO]: [CHAT] This door now takes the §8silver §rkey.

 

 

Can't seem to find the solution to this, but it is toggling and then immediately retoggling a boolean thus keeping it the same.

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



×
×
  • Create New...

Important Information

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