Jump to content

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


Recommended Posts

Posted (edited)

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
Posted

	@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

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • My guess would be that you are not getting the chunk coordinates right, or getChunk dosnt work.
    • Hello, Recently I have been hosting an RLcraft server on Minecraft Forge Version 1.12.2 - 14.23.5.2860 I originally had lag issues and I chalked it up to playing on less than perfect hardware so I moved the server to better hardware(i9-9900k with 64GB of RAM for 1 player.) After lots of troubleshooting I discovered a couple of things. World saving was causing the MSPT to spike to over 2000Miliseconds and was happening every minute. This kind of makes sense as the world was pre-generated and is over 100GB. I learned that I could turn off world saving and just schedule that and that resolved that issue. After that issue was resolved I discovered another issue. It appears that when exploring chunks, any chunks explored stay loaded. They persist. I was originally thinking that this had to be a mod issue, but it didn't seem like anyone was talking about it. This isn't really a problem on packs with few worldgen mods or just few mods in general, but on beefier packs it becomes a problem. I went through forge changelogs and found this line. Build: 1.12.2-14.23.5.2841 - Thu Aug 29 01:58:50 GMT 2019 bs2609: Improve performance of persistent chunk checks (#5706) Is this a related item to what I am dealing with or just something else?   I went ahead and created a new dedicated server with Just Forge 14.23.5.2860, spark reforged, and it's core mods. I was able to replicate the issue and log it with spark. Hopefully you're able to see this spark profile. It basically shows that as I explored the chunk loading persisted(2000 chunks loaded over 10 minutes with one player)The view distance is set to 10 so that should be 200 chunks per player. If I don't move the loaded chunks are 200. I was however able to fix the persistent chunk issue if I save the world more frequently. My question is, is this intended function of the game or is this a bug? Everywhere I read seems to indicate Minecraft servers save every 5 minutes and not every minute. Can chunks not unload if the world does not autosave. Additionally. Autosave specifically appears to fix this issue. Manually running save-all does not resolve the issue.   I realize this is kind of a log one, sorry. Please let me know if you require further information. Thanks in advance for your time. https://spark.lucko.me/NvlMtC39Yt https://imgur.com/a/K0oyukx https://pastebin.com/z0qGu1Vh  
    • Thank you so much, I had originally tried to allocate 16 gb of ram but still had the same issue with the lag, 12 was perfect.
    • Something related to shaders - check the config file of this mod - maybe you can disable shaders there
  • Topics

×
×
  • Create New...

Important Information

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