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

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.

  • Author

Try returning true instead of false within your if statements - that signals Minecraft that something happened.

That works, thanks!

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.