Fluid API proposal
haykam821 opened this issue · 4 comments
Fluids
Any still fluid would be allowed to be stored in a fluid container.
Fluid layers are a representation of a fluid and its amount. A fluid’s amount cannot be negative.
int getAmount()
Gets the amount of fluid this fluid layer holds.
Fluid getFluid()
Gets the fluid this fluid layer holds.
Providers
The FluidProvider
interface would allow management of fluid layers.
FluidLayer getLayer()
Should return the fluid layer in a provider.
boolean insert(Fluid fluid, int amount)
Inserts as much of an amount of fluid as possible into the provider. Should return the whether the fluid could be inserted.
Example:
if (!this.shouldAllowFluid(fluid)) return false;
if (this.getLayer().getAmount() + amount > this.getMaximumAmount()) return false;
this.getLayer().setAmount(this.layer.getAmount() + amount);
return true;
boolean remove(Fluid fluid, int amount)
Depletes an amount of fluid from a provider. If there was not enough fluid in the provider, should return false
.
it may be useful to have methods for (trying to) move fluid directly from one container to another.
why "fluid layer" as a name? how should blocks, items etc expose fluid providers (and how can they do so differently based on e.g. block face)? should a block that stores multiple fluids are once (such as input and output) provide multiple fluid providers, of should one fluid provider be able to provide multiple fluid layers?
why "fluid layer" as a name?
Fluid providers can have multiple layers of different fluids and amounts.
how should blocks, items etc expose fluid providers (and how can they do so differently based on e.g. block face)?
We would provide different interfaces for different types, such as BlockFluidProvider
which would provide extra context, such as Direction
for block states).
should a block that stores multiple fluids are once (such as input and output) provide multiple fluid providers, of should one fluid provider be able to provide multiple fluid layers?
With additional context, a single fluid provider should work. I don't think it would be feasible to have multiple fluid providers on the same object with differences such as the direction.
alright. I was just a little confused about "should return the fluid layer in a provider".
Superseded by #1356.