Improved fluid tanks. #111

Closed
albinaask wants to merge 0 commits from machine-fluid-tank-update-branch into dev/1.19.x
albinaask commented 2023-03-08 16:42:02 +00:00 (Migrated from github.com)

Description

Fluid tanks now behave more like they behaved in 1.12, They can be clicked on with buckets or other containers to transfer fluid, their item correspondence are now correctly fluid containing items with accessible fluid stacks. The item variant now renders fluid and displays tank content on the extended tooltip which you can access by holding shift.

NOTE: should be merged after the #110 yeta wrench updates since it needs some of the stuff from that commit.

Todo. I think it is ready to merge, and then this could be worked on after an alpha release.

  • Fix the break particles of the tanks, I tried but didn't get this to work.
  • Allow tanks to stack to 64. I worked on this for like 12h, but only went around in circles. It seems to be rather involved.

Checklist:

  • My code follows the style guidelines of this project (.editorconfig, most IDEs will use this for you)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
# Description Fluid tanks now behave more like they behaved in 1.12, They can be clicked on with buckets or other containers to transfer fluid, their item correspondence are now correctly fluid containing items with accessible fluid stacks. The item variant now renders fluid and displays tank content on the extended tooltip which you can access by holding shift. NOTE: should be merged after the #110 yeta wrench updates since it needs some of the stuff from that commit. # Todo. I think it is ready to merge, and then this could be worked on after an alpha release. - [x] Fix the break particles of the tanks, I tried but didn't get this to work. - [ ] Allow tanks to stack to 64. I worked on this for like 12h, but only went around in circles. It seems to be rather involved. # Checklist: - [x] My code follows the style guidelines of this project (.editorconfig, most IDEs will use this for you) - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation
justliliandev (Migrated from github.com) requested changes 2023-03-09 21:37:08 +00:00
justliliandev (Migrated from github.com) commented 2023-03-09 20:19:12 +00:00

don't use notnull annotation add the package.info file that contains the default

don't use notnull annotation add the package.info file that contains the default
justliliandev (Migrated from github.com) commented 2023-03-09 20:20:48 +00:00

don't put this on one line

don't put this on one line
justliliandev (Migrated from github.com) commented 2023-03-09 20:25:01 +00:00

use UseOnly annotation for this

use UseOnly annotation for this
justliliandev (Migrated from github.com) commented 2023-03-09 20:26:04 +00:00
        if (player != null && level != null && player.isSecondaryUseActive()) {//aka break block
```suggestion if (player != null && level != null && player.isSecondaryUseActive()) {//aka break block ```
justliliandev (Migrated from github.com) commented 2023-03-09 20:26:25 +00:00

use pos from blockentity

use pos from blockentity
justliliandev (Migrated from github.com) commented 2023-03-09 20:26:38 +00:00

use statehelper from blockentity

use statehelper from blockentity
justliliandev (Migrated from github.com) commented 2023-03-09 20:27:28 +00:00

don't do blindcast, do instanceof check at the top if and remove comment

don't do blindcast, do instanceof check at the top if and remove comment
justliliandev (Migrated from github.com) commented 2023-03-09 20:32:24 +00:00

add a helper for this, there might be more callers (and maybe throw from the player like the SoulVial, so yeah, add that to the helper as well)

add a helper for this, there might be more callers (and maybe throw from the player like the SoulVial, so yeah, add that to the helper as well)
justliliandev (Migrated from github.com) commented 2023-03-09 20:33:33 +00:00
        } else {
```suggestion } else { ```
justliliandev (Migrated from github.com) commented 2023-03-09 20:40:21 +00:00

merge those lines

merge those lines
justliliandev (Migrated from github.com) commented 2023-03-09 20:44:47 +00:00
        Supplier<BlockEntityEntry<? extends MachineBlockEntity>> blockEntityEntry) {
```suggestion Supplier<BlockEntityEntry<? extends MachineBlockEntity>> blockEntityEntry) { ```
justliliandev (Migrated from github.com) commented 2023-03-09 20:48:11 +00:00

put text on new line

put text on new line
justliliandev (Migrated from github.com) commented 2023-03-09 20:48:31 +00:00

put text on new line

put text on new line
justliliandev (Migrated from github.com) commented 2023-03-09 20:51:03 +00:00

put text on new line

put text on new line
justliliandev (Migrated from github.com) commented 2023-03-09 21:00:18 +00:00

use pattern like this:

if (source.isEmpty)
    return 0;
if (!fluid.isEmpty() && !fluid.isFluidEqual(source))
    return 0;
use pattern like this: ``` if (source.isEmpty) return 0; if (!fluid.isEmpty() && !fluid.isFluidEqual(source)) return 0; ```
justliliandev (Migrated from github.com) commented 2023-03-09 21:00:45 +00:00
        if (fluid.isEmpty()) {
```suggestion if (fluid.isEmpty()) { ```
justliliandev (Migrated from github.com) commented 2023-03-09 21:01:02 +00:00
        return fill(new FluidStack(fluid.getFluid(),desiredAmount), action, force);
```suggestion return fill(new FluidStack(fluid.getFluid(),desiredAmount), action, force); ```
justliliandev (Migrated from github.com) commented 2023-03-09 21:01:16 +00:00
        return fill(source, action, false);
```suggestion return fill(source, action, false); ```
justliliandev (Migrated from github.com) commented 2023-03-09 21:04:05 +00:00

use pattern from above and please put a space between if and whitespace

use pattern from above and please put a space between if and whitespace
justliliandev (Migrated from github.com) commented 2023-03-09 21:05:02 +00:00

put return on new line and don't use else as it's the only other path as it return early

put return on new line and don't use else as it's the only other path as it return early
justliliandev (Migrated from github.com) commented 2023-03-09 21:05:23 +00:00

don't use else

don't use else
justliliandev (Migrated from github.com) commented 2023-03-09 21:11:46 +00:00

text on new line

text on new line
justliliandev (Migrated from github.com) commented 2023-03-09 21:12:05 +00:00
        if (!player.level.isClientSide() && player.hasItemInSlot(EquipmentSlot.MAINHAND) && hand == InteractionHand.MAIN_HAND) {
```suggestion if (!player.level.isClientSide() && player.hasItemInSlot(EquipmentSlot.MAINHAND) && hand == InteractionHand.MAIN_HAND) { ```
justliliandev (Migrated from github.com) commented 2023-03-09 21:12:53 +00:00

fix spaces for other conditions as well

fix spaces for other conditions as well
justliliandev (Migrated from github.com) commented 2023-03-09 21:15:42 +00:00

you can't fix stackable fluid containers, like just don't. dupe bugs everywhere because there is no common way to do this

you can't fix stackable fluid containers, like just don't. dupe bugs everywhere because there is no common way to do this
justliliandev (Migrated from github.com) commented 2023-03-09 21:16:35 +00:00

not necessarily, just do the ifPresent thing and log warning

not necessarily, just do the ifPresent thing and log warning
justliliandev (Migrated from github.com) commented 2023-03-09 21:22:14 +00:00

nullable on line above

nullable on line above
justliliandev (Migrated from github.com) commented 2023-03-09 21:27:41 +00:00

maybe use multiple Optional.map chains or fix the early returns like above

maybe use multiple Optional.map chains or fix the early returns like above
justliliandev (Migrated from github.com) commented 2023-03-09 21:27:57 +00:00
        }
        
        protected void setFluid(FluidStack fluid) {
```suggestion } protected void setFluid(FluidStack fluid) { ```
justliliandev (Migrated from github.com) commented 2023-03-09 21:29:17 +00:00

use ItemStack#getOrCreateTag

use ItemStack#getOrCreateTag
justliliandev (Migrated from github.com) commented 2023-03-09 21:31:05 +00:00

follow java naming scheme beTag

follow java naming scheme beTag
justliliandev (Migrated from github.com) commented 2023-03-09 21:35:02 +00:00

why does this extend IForgeBlockEntity?

why does this extend IForgeBlockEntity?
justliliandev (Migrated from github.com) commented 2023-03-09 21:35:27 +00:00

put return on new line and remove else

put return on new line and remove else
justliliandev (Migrated from github.com) commented 2023-03-09 21:36:10 +00:00

don't use else here and call super

don't use else here and call super
albinaask (Migrated from github.com) reviewed 2023-03-16 15:42:36 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 15:42:35 +00:00

Sorry, but I'm not really sure I understand what you mean since my understanding of the annotation system isn't good enough. Do you mean that I should remove the "@NotNull"? The reason that I inserted it was that befor I had it Intellij threw a warning at me saying that "Not annotated method overrides method annotated with @NotNull". It seems to be done that same way in the class "XPVacuumBlockEntity" line 88 in the method "getCapability". What's the difference between the two cases so I understand for next time?

Sorry, but I'm not really sure I understand what you mean since my understanding of the annotation system isn't good enough. Do you mean that I should remove the "@NotNull"? The reason that I inserted it was that befor I had it Intellij threw a warning at me saying that "Not annotated method overrides method annotated with @NotNull". It seems to be done that same way in the class "XPVacuumBlockEntity" line 88 in the method "getCapability". What's the difference between the two cases so I understand for next time?
albinaask (Migrated from github.com) reviewed 2023-03-16 15:45:56 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 15:45:56 +00:00

I'll change it. But I'm wondering; since this is done in loads of other places in the code, even in the same class since before. What is the rule for when to do it and when not to?

I'll change it. But I'm wondering; since this is done in loads of other places in the code, even in the same class since before. What is the rule for when to do it and when not to?
albinaask (Migrated from github.com) reviewed 2023-03-16 15:48:18 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 15:48:17 +00:00

Of course, just me not being used to the code base

Of course, just me not being used to the code base
justliliandev (Migrated from github.com) reviewed 2023-03-16 16:10:52 +00:00
justliliandev (Migrated from github.com) commented 2023-03-16 16:10:51 +00:00

basically: this doesn't happen in the code base (maybe one or two if they were missed). Some IDEs collapse one liner methods, but there are no methods that have the return in one line.
Only exception if the method does nothing and returns nothing, only then void method() {} is allowed on one line

basically: this doesn't happen in the code base (maybe one or two if they were missed). Some IDEs collapse one liner methods, but there are no methods that have the return in one line. Only exception if the method does nothing and returns nothing, only then `void method() {}` is allowed on one line
albinaask (Migrated from github.com) reviewed 2023-03-16 16:20:44 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 16:20:44 +00:00

Those lines were accidentally pushed since they should be part of the vat. I have now moved them to that branch.

Those lines were accidentally pushed since they should be part of the vat. I have now moved them to that branch.
albinaask (Migrated from github.com) reviewed 2023-03-16 16:22:37 +00:00
albinaask (Migrated from github.com) reviewed 2023-03-16 16:27:25 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 16:27:25 +00:00

That pattern produces more branches that the branch predictor needs to navigate if the Java interpreter does not squash those into one. But it may be a price worth paying since it makes things clearer. I'll make the suggested change.

That pattern produces more branches that the branch predictor needs to navigate if the Java interpreter does not squash those into one. But it may be a price worth paying since it makes things clearer. I'll make the suggested change.
albinaask (Migrated from github.com) reviewed 2023-03-16 16:37:45 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 16:37:44 +00:00

What I meant was that the EnderIO fluidtanks in 1.12 were stackable, and the current implementation only supports fluidtanks that doesn't stack because of the code in [FluidTankEntity].internalDrain/fill. The same bug will be apparent for fluid cells from forestry for example. But I'll move this comment to those methods.

What I meant was that the EnderIO fluidtanks in 1.12 were stackable, and the current implementation only supports fluidtanks that doesn't stack because of the code in [FluidTankEntity].internalDrain/fill. The same bug will be apparent for fluid cells from forestry for example. But I'll move this comment to those methods.
albinaask (Migrated from github.com) reviewed 2023-03-16 16:46:40 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 16:46:40 +00:00

Or this was maybe what you meant? That we can't make them stack anymore?

Or this was maybe what you meant? That we can't make them stack anymore?
albinaask (Migrated from github.com) reviewed 2023-03-16 16:48:23 +00:00
albinaask (Migrated from github.com) reviewed 2023-03-16 16:51:33 +00:00
albinaask (Migrated from github.com) reviewed 2023-03-16 17:20:15 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 17:20:14 +00:00

Okay, so I don't understand how to do it, but chatGPT did apparently, so done now...

Okay, so I don't understand how to do it, but chatGPT did apparently, so done now...
albinaask (Migrated from github.com) reviewed 2023-03-16 17:20:50 +00:00
albinaask (Migrated from github.com) reviewed 2023-03-16 17:21:27 +00:00
albinaask (Migrated from github.com) reviewed 2023-03-16 17:21:36 +00:00
albinaask (Migrated from github.com) reviewed 2023-03-16 17:23:25 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 17:23:25 +00:00

I think I used a method in a block entity related class at some point during one of the many iterations while trying to get everything to work. Probably mostly legacy, but pretty useful for indicating that you only should be able to use the wrench in the configuration other than wrenching on block entities and that was the most suitable interface that BlockEntity was implementing. But I could absolutely change this! Would you rather it extending nothing?

I think I used a method in a block entity related class at some point during one of the many iterations while trying to get everything to work. Probably mostly legacy, but pretty useful for indicating that you only should be able to use the wrench in the configuration other than wrenching on block entities and that was the most suitable interface that BlockEntity was implementing. But I could absolutely change this! Would you rather it extending nothing?
albinaask (Migrated from github.com) reviewed 2023-03-16 17:25:20 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 17:25:19 +00:00

This is a valid point, yet something that really is regarding #110 since that should be merged first anyway. But I'll definitely change it!

This is a valid point, yet something that really is regarding #110 since that should be merged first anyway. But I'll definitely change it!
albinaask (Migrated from github.com) reviewed 2023-03-16 17:25:59 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 17:25:58 +00:00

Like above, but will fix also!

Like above, but will fix also!
albinaask (Migrated from github.com) reviewed 2023-03-16 17:28:34 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 17:28:33 +00:00

Sure, added it in a class called PlayerInteractionUtil in the core source folder since I didn't find any other good place for it. If you have another place in mind, let me know!

Sure, added it in a class called PlayerInteractionUtil in the core source folder since I didn't find any other good place for it. If you have another place in mind, let me know!
albinaask commented 2023-03-16 17:32:03 +00:00 (Migrated from github.com)

I've amended the commit. So now you should (hopefully) be able to see them.

I've amended the commit. So now you should (hopefully) be able to see them.
justliliandev (Migrated from github.com) reviewed 2023-03-16 18:40:27 +00:00
justliliandev (Migrated from github.com) commented 2023-03-16 18:40:26 +00:00

it is not wanted there either.
this file has the annotations for a whole package and that replaces the annotations on each field
https://github.com/SleepyTrousers/EnderIO-Rewrite/blob/dev/1.19.x/src/main/java/com/enderio/package-info.java

it is not wanted there either. this file has the annotations for a whole package and that replaces the annotations on each field <https://github.com/SleepyTrousers/EnderIO-Rewrite/blob/dev/1.19.x/src/main/java/com/enderio/package-info.java>
justliliandev (Migrated from github.com) reviewed 2023-03-16 18:54:21 +00:00
justliliandev (Migrated from github.com) commented 2023-03-16 18:54:21 +00:00

microoptimization like that are probably not worth it, if they make code less readable and I kinda doubt that fill is called often enough to be worth it

microoptimization like that are probably not worth it, if they make code less readable and I kinda doubt that fill is called often enough to be worth it
justliliandev (Migrated from github.com) reviewed 2023-03-16 18:59:11 +00:00
justliliandev (Migrated from github.com) commented 2023-03-16 18:59:11 +00:00

we technically can, but I've heard about a lot of weird interactions with stackable fluid containers over the years, it's probably not worth the bugs imo

we technically can, but I've heard about a lot of weird interactions with stackable fluid containers over the years, it's probably not worth the bugs imo
justliliandev (Migrated from github.com) reviewed 2023-03-16 19:00:01 +00:00
justliliandev (Migrated from github.com) commented 2023-03-16 19:00:01 +00:00

extend nothing and add javadoc

extend nothing and add javadoc
albinaask (Migrated from github.com) reviewed 2023-03-16 19:00:52 +00:00
albinaask (Migrated from github.com) commented 2023-03-16 19:00:52 +00:00

I see, it however was one of my very favourite features of EnderIO, I'll see if I can get it to work later on...

I see, it however was one of my very favourite features of EnderIO, I'll see if I can get it to work later on...
justliliandev (Migrated from github.com) approved these changes 2023-03-18 15:53:08 +00:00
justliliandev (Migrated from github.com) left a comment

Fix conflicts

Fix conflicts
ferriarnus (Migrated from github.com) reviewed 2023-03-25 12:59:44 +00:00
ferriarnus (Migrated from github.com) commented 2023-03-25 12:59:44 +00:00

So what exactly is this class for? It does something like a fluid bar, and some things for in world interactions and fluidutil? I seemed to have glossed over this when I first looked, but is this all needed like this?

So what exactly is this class for? It does something like a fluid bar, and some things for in world interactions and fluidutil? I seemed to have glossed over this when I first looked, but is this all needed like this?
albinaask (Migrated from github.com) reviewed 2023-03-26 17:11:37 +00:00
albinaask (Migrated from github.com) commented 2023-03-26 17:11:37 +00:00

The MachineFluidTank is a class that does similar things to the FluidTank class that Forge provides, it holds data about what type of fluid is contained and how much. It has a capacity and an API for transferring into and out of the tank. The Forge implementation is missing filters for controlling which fluids are allowed to enter and exit the tank. My implementation allows for flagging a tank as for example an input tank accepting only fluids that has the coolant property set for example. It would reject any attempt from external sources to pull coolant out or put lava into the tank. As for the enchantment infuser or whatever it's called you flag it as an input tank and set the predicate to only accept fluidXP and only do it when the machine has a recipe, also set the capacity to whatever amount the recipe requires. This will disallow any fluid from going into the tank until the machine has a valid recipe. Then it only accepts liqudXP and only the amount specified by the recipe. It won't allow liquidXP to be pulled out by pipes, however when you are done with your recipe and want to void the fluid that went into the recipe you just use tank.drain([tank.get_amount()], true) to force it to drain all internal content. The reason to why it is so long is that I had to rewrite like the entire class to enable the predicate and to remove the functionality of storing multiple fluids (like in the tinkers smeltery). If you want to I'll point you towards my unfinished implementation of the vat, but it is still missing all the recipe stuff.

The MachineFluidTank is a class that does similar things to the FluidTank class that Forge provides, it holds data about what type of fluid is contained and how much. It has a capacity and an API for transferring into and out of the tank. The Forge implementation is missing filters for controlling which fluids are allowed to enter and exit the tank. My implementation allows for flagging a tank as for example an input tank accepting only fluids that has the coolant property set for example. It would reject any attempt from external sources to pull coolant out or put lava into the tank. As for the enchantment infuser or whatever it's called you flag it as an input tank and set the predicate to only accept fluidXP and only do it when the machine has a recipe, also set the capacity to whatever amount the recipe requires. This will disallow any fluid from going into the tank until the machine has a valid recipe. Then it only accepts liqudXP and only the amount specified by the recipe. It won't allow liquidXP to be pulled out by pipes, however when you are done with your recipe and want to void the fluid that went into the recipe you just use tank.drain([tank.get_amount()], true) to force it to drain all internal content. The reason to why it is so long is that I had to rewrite like the entire class to enable the predicate and to remove the functionality of storing multiple fluids (like in the tinkers smeltery). If you want to I'll point you towards my unfinished implementation of the vat, but it is still missing all the recipe stuff.
albinaask commented 2023-03-26 17:26:18 +00:00 (Migrated from github.com)

I goofed it up bad somehow... submitting the exact same pr again. Sorry for the inconvenience...

I goofed it up bad somehow... submitting the exact same pr again. Sorry for the inconvenience...

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Team-EnderIO/EnderIO#111
No description provided.