Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

TileEntity networks


Sync Views
 Share

Recommended Posts

I was thinking about working on something that would require some fairly complex interactions between linked tileentities (so I guess kind of like LogisiticPipes, rather than normal Buildcraft pipes with the way it needs to know about everything to route stuff).

 

Ideally Id like this to work by forming a network which has references to all the relevant TileEntity instances, and runs its logic once per tick.

 

However not sure about some conceptual issues:

[*]If I have a separate Network object, how do I handle loading and saving of this object?

 

Its not part of any one TileEntity, they might not even be loaded and saved at the same time. Likewise it isn't really owned by any specific block, so cant be a TileEntity itself, and there needs to be a way for any loaded TileEntity in the network to find this object.

 

[*]How do I handle if the Network spans multiple chunks? My current idea is to make it so in the networks update method, it checks all the chunks for connected devices and only updates if there all loaded (it needs to get the TileEntity for each of those x/y/z's anyway since unloading/reloading a chunk changes the TileEntity object references unless there is also some way around that).

 

[*]When to recreate the network graph. Finding all connected devices provided all relevant chunks are loaded is easy, but when to update it. My best idea right now is to make every thing that might be part of the network, including blocks that are just acting as wires/connections be a TileEntity that just references the network (however 1. is solved). However won't such a large number of TileEntity instances that do nothing degrade performance? I know people complain about build craft pipes, logistic pipes, alternatives, paintings, item frames, etc. and blame them when the server lags, and I can think of many ways the simple presence of a number of TileEntity instances in the chunk might hurt performance, but I have no idea if this is truly a noticeable amount.

 

Link to comment
Share on other sites

I had a go at this in my mod, which is currently still in development. It uses a separate Network object like you described, which is shared between all connected TileEntities. When a TileEntity gets destroyed or unloaded it removes itself from the network. And when a TileEntity is loaded, it adds itself to any nearby network, or if none are found it creates a new one. This works, because Minecraft works synchronously, that means no 2 TileEntities can load at the exact same time. Even if they were to be placed in the exact same tick, they would be created one after another.

It includes a simple event system which lets you sent events through the network, all TileEntities in the network will then be notified and can act accordingly.

It's still work in progress, for example when a TileEntity get's removed that has two or more neighbors which are part of the network, the entire network has to be rebuilt.

You can find the source on github: https://github.com/diesieben07/CameraCraft3/tree/master/src/main/java/de/take_weiland/mods/cameracraft/networking

The most important part is in the NetworkUtil class. An example of an actual TileEntity that is part of the Network is the CardReader: https://github.com/diesieben07/CameraCraft3/blob/master/src/main/java/de/take_weiland/mods/cameracraft/tileentity/TileCardReader.java

 

Hope this gives you a starting point.

Link to comment
Share on other sites

Not looked through all the code, but looks like you did what I suggested and made the cable blocks a tile entity. Then on an entities first update it will attempt to create, join or merge networks (so things like the card reader are also like a cable, it cant connect to two separate unrelated networks).

 

Also as far as I can tell you never save the Network but just create it on demand (for both client and server?)? That was something I wanted to do so that the network can maintain state, although thinking about it I guess the devices etc. could store the relevant state for themselves in any situation I can think of. So if part of the network gets unloaded everything carries on but that bit doesn't send/get events?

 

 

Link to comment
Share on other sites

Also as far as I can tell you never save the Network but just create it on demand (for both client and server?)?

Yes. It never gets saved and only created on demand. So far the network is only present on the server, as the client doesn't need it.
That was something I wanted to do so that the network can maintain state, although thinking about it I guess the devices etc. could store the relevant state for themselves in any situation I can think of. So if part of the network gets unloaded everything carries on but that bit doesn't send/get events?

Also yes. That was my though process as well. Because the network doesn't really belong anywhere in the world, when should it be loaded, when unloaded? You can't bind it to chunks, because networks might cross chunk borders. It just all gets haywire. So every TE saves it's state on its own and recreates the network when needed.
Link to comment
Share on other sites

Think I got a basic network working. Had some issues with a multiple block machine. I didn't want to allow machines to allow through traffic, or confusing connected to multiple unique networks at once (for now at least, perhaps later I'll let machines have multiple terminals) so the machine would often just connect to itself and reject the cable connection lol. Think I solved that with a "TileEntity INetworkProxy.getReal()" method and more complex getAdjacentNetworks.

 

Didn't see any such things in your code, suspect when I test more tomorrow its going to give me lots of problems if the machine itself crosses a chunk boundary and is only partly loaded since I guess the proxy code (including for ISidedInventory) can fail giving me an object that claims to implement an interface but cant actually do anything with it...

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Whenever I try to start my server I get this crash: [14:05:21] [main/FATAL]: Failed to start the minecraft server com.google.gson.JsonParseException: Error loading registry data: Not a valid resource location: #minecraft:infiniburn_end Non [a-z0-9_.-] character in namespace of location: #minecraft:infiniburn_end         at net.minecraft.core.RegistryAccess.m_175498_(RegistryAccess.java:156) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]         at net.minecraft.core.RegistryAccess.m_175503_(RegistryAccess.java:155) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at net.minecraft.core.RegistryAccess.m_175500_(RegistryAccess.java:146) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at net.minecraft.resources.RegistryReadOps.m_195841_(RegistryReadOps.java:37) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at net.minecraft.resources.RegistryReadOps.m_179866_(RegistryReadOps.java:31) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at net.minecraft.server.Main.main(Main.java:161) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:46) ~[fmlloader-1.18.1-39.0.75.jar%2361!/:?]         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) ~[bootstraplauncher-1.0.0.jar:?]         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]         at org.jmt.mcmt.modlauncher.FastUtilTransformerService.argumentValues(FastUtilTransformerService.java:200) ~[jmt_mcmt-1.18.1-0.24.2-118-packaged.jar%2375!/:?]         at cpw.mods.modlauncher.TransformationServicesHandler.lambda$offerArgumentResultsToServices$5(TransformationServicesHandler.java:80) ~[modlauncher-9.1.0.jar%235!/:?]         at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[?:?]         at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[?:?]         at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779) ~[?:?]         at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?]         at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?]         at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?]         at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?]         at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]         at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[?:?]         at cpw.mods.modlauncher.TransformationServicesHandler.offerArgumentResultsToServices(TransformationServicesHandler.java:80) ~[modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.ArgumentHandler.processArguments(ArgumentHandler.java:71) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.TransformationServicesHandler.processArguments(TransformationServicesHandler.java:68) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:50) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.Launcher.run(Launcher.java:87) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] container@pterodactyl~ Server marked as offline... [Game2 Daemon]: ---------- Detected server process in a crashed state! ---------- [Game2 Daemon]: Exit code: 1 [Game2 Daemon]: Out of memory: false [Game2 Daemon]: Aborting automatic restart, last crash occurred less than 120 seconds ago.
    • why, you have Event instance so call the getters we all have the code of the Event the Event exist to perform an action at a specific 'time'/'action' in the game what are you talking about
    • I am sorry, but I have zero idea what you are trying to say.
    • Thanks for the tip, I managed to get the data I wanted in the return parameters of the listened event. Here is part of the code @SubscribeEvent public static void Demo02(LivingHurtEvent event) { System.out.println("sadawedawdawdawdadwa" + '\n' + event.getAmount()); }  
    • update Forge to the latest version and do not put your server on OneDrive
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.