mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-21 20:42:09 +00:00
Add fluid block autoplace with a pluggable fluid cost and source API
Water, lava and every Forge fluid block can now be placed by survival autoplace, paid for with fluid instead of with an item. * Fluid costs are registered per block state, water and lava are registered by default, and a registration can ask for fluid even when the block also has an item form. * A fluid is only placed once the rest of the structure is in place, so it cannot flow out of a half built multiblock, and only the fluid missing from a position is charged, so topping up a leak costs the difference instead of a whole bucket. * The fluid comes from the player: their fluid containers, plus whatever mods contribute through the new fluid container extractor and fluid source provider registries. * Existing structure definitions need no change, as ofBlock and the other block elements become fluid elements when the block has no item form.
This commit is contained in:
1 parent
d829ae466b
commit
98101c00aa
27 files changed
+2395
-83
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package com.gtnewhorizon.structurelib.fluid;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
|
||||
/**
|
||||
* A concrete request to put one fluid block at one position: which block and meta the structure wants there, what that
|
||||
* costs, and how strict the check for an already partially filled position is.
|
||||
* <p>
|
||||
* Structure elements create one of these, either from the {@link FluidPlacementRegistry} or from their own parameters,
|
||||
* and hand it to the autoplace helper.
|
||||
*
|
||||
* @param block the block the structure wants at that position
|
||||
* @param meta the block meta the structure wants at that position
|
||||
* @param cost the fluid that has to be paid for a position that holds nothing yet. Must hold a fluid and a positive
|
||||
* amount.
|
||||
* @param policy how much fluid an existing position has to hold to be accepted as is
|
||||
* @param placer how to actually place the block, or null to place it with a plain block set
|
||||
*/
|
||||
@Desugar
|
||||
public record FluidBlockRequirement(Block block, int meta, FluidStack cost, FluidFillPolicy policy,
|
||||
@Nullable FluidBlockPlacer placer) {
|
||||
|
||||
public FluidBlockRequirement {
|
||||
if (block == null) throw new IllegalArgumentException("block must not be null");
|
||||
if (cost == null || cost.getFluid() == null) throw new IllegalArgumentException("cost must hold a fluid");
|
||||
if (cost.amount <= 0) throw new IllegalArgumentException("cost must have a positive amount");
|
||||
if (policy == null) throw new IllegalArgumentException("policy must not be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a requirement from a registered placement.
|
||||
*
|
||||
* @param placement what the registry knows about this block state
|
||||
* @param block the block the structure wants
|
||||
* @param meta the block meta the structure wants
|
||||
* @param policy how strict the check for an already partially filled position is
|
||||
*/
|
||||
public static FluidBlockRequirement of(FluidBlockPlacement placement, Block block, int meta,
|
||||
FluidFillPolicy policy) {
|
||||
if (placement == null) throw new IllegalArgumentException("placement must not be null");
|
||||
return new FluidBlockRequirement(block, meta, placement.cost(), policy, placement.placer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a requirement that pays with given fluid, and that places the block directly.
|
||||
*/
|
||||
public static FluidBlockRequirement of(Block block, int meta, FluidStack cost, FluidFillPolicy policy) {
|
||||
return new FluidBlockRequirement(block, meta, cost, policy, null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user