Cadiboo Posted August 26, 2018 Share Posted August 26, 2018 I'm making a tech based mod involving a lot of energy and so far I've been using wires that have pretty abysmal performance. They each have an energy storage and they just transfer energy into all storages next to them every tick. This works ok when using under 10 wires, but it's useless for transferring energy over any range. I'm wondering how I would make an energy network for my wires. I've found this post which is someone trying to do the same thing, unfortunately there aren't any responses to the topic. I've also found their code here, but I would like to know the best way of making a network, rather than deducing a functional way from someone else's code. My current idea is to have an map of energy storages linked to a list of connected tile entities, stored in a worldSavedObject or something (I'll look into the saving part of it later). Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 26, 2018 Share Posted August 26, 2018 4 hours ago, Cadiboo said: My current idea is to have an map of energy storages linked to a list of connected tile entities, stored in a worldSavedObject or something (I'll look into the saving part of it later). Ultimately it depends on how you want the network to function, do you want simulated energy flow where power individually flows from point a to point b? Or would you rather it function like thermal energy flow? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Cadiboo Posted August 26, 2018 Author Share Posted August 26, 2018 (edited) 36 minutes ago, Animefan8888 said: Ultimately it depends on how you want the network to function, do you want simulated energy flow where power individually flows from point a to point b? Or would you rather it function like thermal energy flow? I want it to be a loss-less transfer, what do you mean by thermal energy flow? Edited August 26, 2018 by Cadiboo Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 26, 2018 Share Posted August 26, 2018 2 minutes ago, Cadiboo said: I want it to be a loss-less transfer, wha do you mean by thermal energy flow? I meant the thermal mods. If you want it to be lossless you can simply store one energy storage that represents a cable network on which its size scales on how many cables there are. And also stores positions of connected TEs. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
jabelar Posted August 26, 2018 Share Posted August 26, 2018 if you want lossless, then it just becomes a "pathfinding" type algorithm. As long as there is a path between the machine and a source, it can be considered connected/powered. What I would do then is implement a pathfinding algorithm (there are lots of papers and code samples out there as it is a common game programming thing) or possibly adapt the Minecraft current pathfinding. The thing is to create a version of the world map where your connector blocks are considerable "passable" and everything else is not. There is some discussion of the main algorithms including a 2-d sample in the wikipedia article: https://en.wikipedia.org/wiki/Pathfinding Now the problem though is that even the most efficient pathfinding algorithms will take an immense amount of processing time as the dimensions (i.e. distance) increase. If you think about it, in a 10 x 10 x 10 area of minecraft there are 1000 blocks and the number of ways that a path could be constructed through it is also very large. For instance you could create spirals, stairs up then down, paths that cross over each other and so forth. There is a reason why pathfinding in all games, including Minecraft is limited to a fairly short distance, and it is easy to demonstrate that it is possible to create fairly simple blocks structures (such as spiral staircase) that the Minecraft mobs can't navigate even though technically they should. Anyway, pathfinding is an appropriate method. An alternate method is a propagation method. Basically, each block with power checks to see if there are any neighbors that can be powered and then does. Note a very important point for this algoritm -- "powered" needs to represent having connection to power source, not just matter of containing power. Some implementations do this by using a block property that counts down the distance from the power source. So power source checks surrounding blocks and if it finds a connector then it gives the connector value of 10, then that connector looks around and if it finds any connector that has value less than 9 will set it to 9, and then each connector with value 9 look around for connector with value less than 8 and so on. Of course the initial value will determine the maximum distance and again performance will go down rapidly at longer distances. This is similar to how redstone works. Performance can be boosted a bit by not checking every block/path every tick. You can either do it randomly (bigger systems might update more slowly) or staggered (like every 5 ticks). Basically the user won't usually notice if the updating takes less than a half second or so and might be willing to wait a bit longer for big systems. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Pheenixm Posted August 26, 2018 Share Posted August 26, 2018 You could do this fairly easily with a DFS search algorithm. Don't need something as advanced as Dijkstra's for this Quote Link to comment Share on other sites More sharing options...
jabelar Posted August 26, 2018 Share Posted August 26, 2018 One other important point to help optimize. In most path-finding you want to find the "lowest cost" path -- usually meaning the shortest, or maybe the fastest. However, in your case you can just find any path. So you can "short-circuit" any path finding loops as soon as you find a path. That could actually help a fair bit for performance. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Cadiboo Posted August 27, 2018 Author Share Posted August 27, 2018 7 hours ago, jabelar said: One other important point to help optimize. In most path-finding you want to find the "lowest cost" path -- usually meaning the shortest, or maybe the fastest. However, in your case you can just find any path. So you can "short-circuit" any path finding loops as soon as you find a path. That could actually help a fair bit for performance. Would having a list of networks(energy storages) with a saved list of connected tile entity positions that are updated by the tile entitie in onblockplaced/destroyed work? Very simple & without pathfinding. Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 27, 2018 Share Posted August 27, 2018 55 minutes ago, Cadiboo said: Would having a list of networks(energy storages) with a saved list of connected tile entity positions that are updated by the tile entitie in onblockplaced/destroyed work? Very simple & without pathfinding. Yes, this is what I suggested. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
jabelar Posted August 27, 2018 Share Posted August 27, 2018 3 hours ago, Cadiboo said: Would having a list of networks(energy storages) with a saved list of connected tile entity positions that are updated by the tile entitie in onblockplaced/destroyed work? Very simple & without pathfinding. The problem is that there are things that can add/destroy blocks without an event to hook into. If player is making or modifying the network certainly that would be good time to trigger a recalculation of paths, but depending on how you make your network blocks they can possibly be destroyed by other things like creeper explosion. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Cadiboo Posted August 27, 2018 Author Share Posted August 27, 2018 3 minutes ago, jabelar said: The problem is that there are things that can add/destroy blocks without an event to hook into. If player is making or modifying the network certainly that would be good time to trigger a recalculation of paths, but depending on how you make your network blocks they can possibly be destroyed by other things like creeper explosion. Is there any event that is fired every time a block is destroyed? Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 27, 2018 Share Posted August 27, 2018 2 hours ago, Cadiboo said: Is there any event that is fired every time a block is destroyed? You don't need to use forge Events for this, there are methods in the Block class you can use. Such as breakBlock and onNeighborChanged. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Cadiboo Posted August 27, 2018 Author Share Posted August 27, 2018 19 minutes ago, Animefan8888 said: You don't need to use forge Events for this, there are methods in the Block class you can use. Such as breakBlock and onNeighborChanged. Thats what I though but jabelar said 2 hours ago, jabelar said: there are things that can add/destroy blocks without an event to hook into Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 27, 2018 Share Posted August 27, 2018 20 minutes ago, Cadiboo said: Thats what I though but jabelar said Block#onNeighborChanged is called whenever a TileEntity is removed or placed in the world to all adjacent blocks. You should just be able to override this in your cable(s) class. And Block#breakBlock is called every time a block is broken/replaced since it is the method that removes TEs. And you can use Block#onBlockAdded for when the cable is placed. You will need to use all three of them. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Cadiboo Posted August 27, 2018 Author Share Posted August 27, 2018 I've got everything working, except that my EnergyNetworkList is shared between the server & client. this isn't a problem when the sides are physically seperate... but I get concurrent modification exceptions & multiple versions of the same EnergyNetworks. How would I attach my networks (& lists) to specific worlds and have seperate instances for server & client? Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
jabelar Posted August 27, 2018 Share Posted August 27, 2018 What do you mean by "shared" between server and client? Logically, it would probably be best if the network is only maintained on server, but the concept of whether each block/machine is powered is communicated in the regular property way for blocks. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Cadiboo Posted August 27, 2018 Author Share Posted August 27, 2018 1 minute ago, jabelar said: What do you mean by "shared" between server and client? Logically, it would probably be best if the network is only maintained on server, but the concept of whether each block/machine is powered is communicated in the regular property way for blocks. Look at my code I stupidly made a single static instance and accessed it from both client and server threads 2 hours ago, Cadiboo said: How would I attach my networks (& lists) to specific worlds and have seperate instances for server & client? Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Cadiboo Posted August 27, 2018 Author Share Posted August 27, 2018 (edited) I’m probably going to try and change my lists from Map<BlockPos, EnergyStorage> to ArrayList<IEnergyUser>. But I tried this before and it appears you can’t have an ArrayList like <T extends TileEntity & IEnergyUser>. You can have class xyz<T extends TileEntity & IEnergyUser> But not an ArrayList with the same generic prameters? Edited August 27, 2018 by Cadiboo Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Cadiboo Posted August 27, 2018 Author Share Posted August 27, 2018 4 minutes ago, Cadiboo said: Look at my code Just realised I forgot to actually provide a link https://github.com/Cadiboo/WIPTechAlpha/tree/master/src/main/java/cadiboo/wiptech/capability/energy https://github.com/Cadiboo/WIPTechAlpha/blob/master/src/main/java/cadiboo/wiptech/block/BlockWire.java https://github.com/Cadiboo/WIPTechAlpha/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityWire.java Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Cadiboo Posted August 27, 2018 Author Share Posted August 27, 2018 8 minutes ago, jabelar said: What do you mean by "shared" between server and client? Logically, it would probably be best if the network is only maintained on server, but the concept of whether each block/machine is powered is communicated in the regular property way for blocks. The networks will be server side only in my actual mod, but for debugging I’d like to do some rendering to show(overlay) different networks to make sure that they are joining & separating properly Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Pheenixm Posted August 27, 2018 Share Posted August 27, 2018 (edited) You should stick with HashMap<Key,Value>. It allows for .contains() queries in O(1) time as opposed to ArrayList, which is O(n). At the very least, use HashSet<Key>, that also allows for O(1) time. If I were you, I'd look into A* search. You want the shortest distance, it's optimal. That all said, it sounds like what you need is something similar to the way I'm doing multiblocks. This may prove somewhat useful to you, particularly the checkNeighbors() method, which is called whenever a block is placed. It basically checks each neighbor to see if they are an instance of the network type, and if they are, it joins the network; otherwise, it forms a new network. Ought to have a lot of cross-over application with your aims. I'm gonna warn you right now, the code for this is still fairly buggy on edge-cases. When a network is split in half and the blocks on one half have to re-resolve the master node, that just gets ugly. You can make yours simpler by implementing a true master/slave architecture in your blocks, rather than the virtual master/slave architecture I decided to implement for the challenge of it. Edited August 27, 2018 by Pheenixm 1 Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 27, 2018 Share Posted August 27, 2018 @Cadiboo Networks should be server side only. Save and load them from the world using WorldSavedData or a World Capability. Use Packets to send the information from server to client. For debugging log messages to the log or use debug mode. Also instead of having each TileEntity send energy have a WorldTickEvent that handles all the energy sending and receiving. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Cadiboo Posted August 28, 2018 Author Share Posted August 28, 2018 29 minutes ago, Animefan8888 said: @Cadiboo Networks should be server side only. Save and load them from the world using WorldSavedData or a World Capability. Use Packets to send the information from server to client. For debugging log messages to the log or use debug mode. Also instead of having each TileEntity send energy have a WorldTickEvent that handles all the energy sending and receiving. What’s a world capability and how would I attach it/a worldSavedData (I don’t want the networks to be saved, just exist in game) to a world? And yes the network is going to be server side only, but I want to draw a box around each of my wires with a colour based on what network it is connected to so I can easily see if the networks are working Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Cadiboo Posted August 28, 2018 Author Share Posted August 28, 2018 24 minutes ago, Cadiboo said: What’s a world capability and how would I attach it/a worldSavedData (I don’t want the networks to be saved, just exist in game) to a world? And yes the network is going to be server side only, but I want to draw a box around each of my wires with a colour based on what network it is connected to so I can easily see if the networks are working Ok so, I’ve looked at this topic Is this still up to date? It looks like I just have to subscribe to the AttachCapabilities event and add a Map<EnergyNetwork> to the world Object? or make my own capability something like EnergyNetworkList and attach that to the world Object. Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 28, 2018 Share Posted August 28, 2018 31 minutes ago, Cadiboo said: I don’t want the networks to be saved, just exist in game If you dont save them you will have to get them again when they are loaded which could lead to some performance issues when loading chunks. You have to make your own capability and attach it in AttachCapabilityEvent<World>. 33 minutes ago, Cadiboo said: but I want to draw a box around each of my wires with a colour based on what network it is connected to so I can easily see if the networks are working Then you have to sync the network with a packet. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Recommended Posts
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.