Jump to content

[1.12.2] Recalculate comparator output of a block every tick without a tile entity


Aarilight

Recommended Posts

I want to make a block that updates its comparator output every tick, preferably without having to create a tile entity for it (because it can be used as a building block and for beacon bases as well... making a tile entity for all of them and updating all of them every tick sounds like an issue). Is this possible?

(I've already Overridden hasComparatorInputOverride and getComparatorInputOverride)

Edited by Aarilight
Link to comment
Share on other sites

I saw another thread (from a long time ago, tho) which recommended I use setTickRandomly(false);, set the tickRate to 1, and use onUpdate, but I couldn't figure out what onUpdate was referring to. Is this what I should be doing to update the comparator? If so, what is onUpdate referring to? It doesn't seem to be updateTick, as that seems to only be called by random ticks, which I'm disabling.

Link to comment
Share on other sites

onNeighborChange only seems to be called when I destroy a comparator, not place it, and it doesn't work if the comparator is placed two blocks away. Is there another event I could use to detect this? I could switch to the comparator blockstate when hasComparatorInputOverride or getComparatorInputOverride are first called, I think that would be fine, but would detecting the comparator being destroyed only be possible via looping through all the valid comparator locations?

Link to comment
Share on other sites

Why don't you want to use a tile entity? This is exactly what they are meant for. There really isn't a more efficient way, because you'll end up basically making your own tile entity system. You can't get around the performance impact of having multiple blocks checking multiple locations around themselves every tick. 

 

When people say that tile entities cause performance problems they don't mean that tile entities themselves are a problem, it is just that whenever you want lots of blocks doing complex logic every tick it costs performance.

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I'm not really worried about a few blocks, but I like the look of the block and want to keep it as a viable building block. Having a tile entity in each of them just sounds really inefficient when it doesn't have to be that way. The comparator functionality is just a fun quirk I wanted to add to the block, not the sole purpose of it.

Link to comment
Share on other sites

2 hours ago, Aarilight said:

I'm not really worried about a few blocks, but I like the look of the block and want to keep it as a viable building block. Having a tile entity in each of them just sounds really inefficient when it doesn't have to be that way. The comparator functionality is just a fun quirk I wanted to add to the block, not the sole purpose of it.

Our point is that a tile entity is NOT inefficient, it is actually super efficient. If you want a block to do something every tick, then you need to scan the world every tick to find all the blocks, then fire their update() code. To find all the blocks you'll want to avoid cycling through all the blocks in the world so you'll create a collection to keep track of all the locations where you placed a block. Once you've done that you've basically created the tile entity! Basically you can't do what you want to do any more simply or efficiently than using a tile entity.

 

Also, why are you mentioning that you "like the look of the block and want to keep it as a viable building block"? Having a tile entity doesn't prevent that. A tile entity is really just a way to tag blocks (that can also act like regular blocks) as also having tickable code. That's it.

 

I think you think tile entities are complicated because some people do complicated logic with the tickable code. For example, you can run a container to make a furnace, or you can create an animated model. But even if you just want a simple variable to record the player that placed the block, you should use a tile entity. 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

But instead of having each of my blocks in a list of tile entities, which are updated every tick, I can instead elect to not have them be in the list unless they actually need to be. It may not be necessary optimization but it's not hard so I don't see the point of not doing it. And it's implemented, so....

Also, aren't tile entities saved to disk, whether or not you save any data in them? Doesn't this technically reduce file size as well?

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I had a similar issue to what you do above. Given this is an old post, you've probably sorted this now In my case, I had Java (JDK) 22 installed. After uninstalling that and installing 17.0.11 (having both installed gives the same error), then running the startserver.bat worked for me. I managed to get to the EULA section and then start my server correctly- I hope it helps anyone else who may have this issue!
    • Make a test with another Launcher like MultiMC, AT Launcher or Technic Launcher
    • I opened up Minecraft today for the first time in a month and whenever I try and play forge I get an error 1 message. I restarted my computer, tried reinstalling both Minecraft and Forge and have updated all of my drivers. Nothing seems to work so I'm stumped. I have absolutely no mods installed ATM so I have no idea what could be causing the problem. I hope yall are able to help.   DebugLog:   [19May2024 20:33:51.600] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, dmoy18, --version, 1.20.1-forge-47.2.0, --gameDir, C:\Users\dmoyf\AppData\Roaming\.minecraft, --assetsDir, C:\Users\dmoyf\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, c083972cd92d4dd2894beb25b82ebe82, --accessToken, ????????, --clientId, MDljMzIwMjYtOTJiNS00YWUxLTk1M2EtN2ExMGExZWM0MDAw, --xuid, 2535417310772497, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\dmoyf\AppData\Roaming\.minecraft\quickPlay\java\1716168829421.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.0, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [19May2024 20:33:51.604] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 11 arch amd64 version 10.0 [19May2024 20:33:51.634] [main/DEBUG] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Found launch services [fmlclientdev,forgeclient,minecraft,forgegametestserverdev,fmlserveruserdev,fmlclient,fmldatauserdev,forgeserverdev,forgeserveruserdev,forgeclientdev,forgeclientuserdev,forgeserver,forgedatadev,fmlserver,fmlclientuserdev,fmlserverdev,forgedatauserdev,testharness,forgegametestserveruserdev] [19May2024 20:33:51.653] [main/DEBUG] [cpw.mods.modlauncher.NameMappingServiceHandler/MODLAUNCHER]: Found naming services : [srgtomcp] [19May2024 20:33:51.668] [main/DEBUG] [cpw.mods.modlauncher.LaunchPluginHandler/MODLAUNCHER]: Found launch plugins: [mixin,eventbus,slf4jfixer,object_holder_definalize,runtime_enum_extender,capability_token_subclass,accesstransformer,runtimedistcleaner] [19May2024 20:33:51.681] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Discovering transformation services [19May2024 20:33:51.688] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path GAMEDIR is C:\Users\dmoyf\AppData\Roaming\.minecraft [19May2024 20:33:51.689] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path MODSDIR is C:\Users\dmoyf\AppData\Roaming\.minecraft\mods [19May2024 20:33:51.689] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path CONFIGDIR is C:\Users\dmoyf\AppData\Roaming\.minecraft\config [19May2024 20:33:51.689] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path FMLCONFIG is C:\Users\dmoyf\AppData\Roaming\.minecraft\config\fml.toml
  • Topics

×
×
  • Create New...

Important Information

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