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.

Redstone(and more stuff like repeaters and maybe more I havne't checked) send TONS of updates

Featured Replies

Posted

So I noticed on Block#neighborChanged that when redstone is activated/deactivated, between 2 to 9 updates are sent, using a repeater or even just dust, they're all sent from the same position and at the same tick. But why??
The RedstoneBlock only sends a single update when placed and destroyed, so why does activating and deactivating redstone signal sends so many?(and identical ones nontheless) and how can I make it so I ignore them all except one, because one is all I need

Buttons send 2 updates, one using a regular BlockPos, and one using an mutable version of that... which is odd aswell

Edited by 1Mangomaster1

  • Author

	@Override
	public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos changedPos, boolean _unknownBoolean) {
		if (world.isClientSide)
			return;
		
		boolean hasPower = powered(state);
		boolean neighborPowred = world.hasNeighborSignal(pos);
		if (hasPower != neighborPowred) {
			RedstoneTransmitterBlockEntity blockEntity = (RedstoneTransmitterBlockEntity)world.getBlockEntity(pos);
			if (!neighborPowred || !blockEntity.hasRedstoneControls()) {
				cyclePowerState(world, pos, state);
				return;
			}

			System.out.println("Update from " + changedPos);
			if (changedPos.equals(front(state, pos))) {
				cyclePowerState(world, pos, state);
			} else if (changedPos.equals(left(state, pos))) {				
				blockEntity.setChannel(blockEntity.getChannel() + 1);
			} else if (changedPos.equals(right(state, pos))) {
				blockEntity.setChannel(blockEntity.getChannel() - 1);
			} else if (changedPos.equals(back(state, pos))) {
				world.setBlock(pos, state.cycle(TRANSMISSION_KIND), UPDATE_ALL);
			}
		}
	}

the front(), left(), right() and back() get the relative direction of a block in relation to its FACING state, it works I've checked that many times
The idea of this method was to make each face of the block to behave differently when powered, it works, except when using some redstone stuff many updates are called and it presents a problem as cycles and additions and subtractions happen many times

  • Author

Anyways.... my way around it was to add to my BlockEntity a boolean for "hasSignal", unliked "powered", has signal becomes true for any direciton inputted, not only the front(or when the redstone controls are off), so I can check if there's signal rather than checking for "powered"

 

	public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos changedPos, boolean _unknownBoolean) {
		if (world.isClientSide)
			return;
		
		RedstoneTransmitterBlockEntity blockEntity = (RedstoneTransmitterBlockEntity)world.getBlockEntity(pos);
		
		boolean powered = blockEntity.hasSignal();
		boolean neighborPowred = world.hasNeighborSignal(pos);
		
		if (powered != neighborPowred) {
			blockEntity.setSignal(neighborPowred);
			
			if (!neighborPowred || !blockEntity.hasRedstoneControls()) {
				world.setBlock(pos, state.setValue(POWERED, neighborPowred), UPDATE_ALL);
				updateWirelessConnection(world, state, pos);
				return;
			}
			
			if (changedPos.equals(front(state, pos)))
				world.setBlock(pos, state.setValue(POWERED, neighborPowred), UPDATE_ALL);
			else if (changedPos.equals(left(state, pos)))
				blockEntity.setChannel(blockEntity.getChannel() + 1);
			else if (changedPos.equals(right(state, pos)))
				blockEntity.setChannel(blockEntity.getChannel() - 1);
			else if (changedPos.equals(back(state, pos)))
				world.setBlock(pos, state.cycle(TRANSMISSION_KIND), UPDATE_ALL);
			
			updateWirelessConnection(world, state, pos);
		}
	}

If anybody ever needs that--

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.