mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 03:25:18 +00:00
[1.11.x] Refine fluid placement utilities (#3509)
This commit is contained in:
1 parent
160427b12c
commit
8eea766288
12 files changed
+615
-69
No files matched your search
@@ -64,7 +64,7 @@ public class BlockFluidFinite extends BlockFluidBase
|
||||
@Override
|
||||
public boolean canCollideCheck(@Nonnull IBlockState state, boolean fullHit)
|
||||
{
|
||||
return fullHit && state.getValue(LEVEL) == quantaPerBlock - 1;
|
||||
return fullHit;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -244,6 +244,41 @@ public class BlockFluidFinite extends BlockFluidBase
|
||||
}
|
||||
|
||||
/* IFluidBlock */
|
||||
@Override
|
||||
public int place(World world, BlockPos pos, @Nonnull FluidStack fluidStack, boolean doPlace)
|
||||
{
|
||||
IBlockState existing = world.getBlockState(pos);
|
||||
float quantaAmount = Fluid.BUCKET_VOLUME / quantaPerBlockFloat;
|
||||
// If the stack contains more available fluid than the full source block,
|
||||
// set a source block
|
||||
int closest = Fluid.BUCKET_VOLUME;
|
||||
int quanta = quantaPerBlock;
|
||||
if (fluidStack.amount < closest)
|
||||
{
|
||||
// Figure out maximum level to match stack amount
|
||||
closest = MathHelper.floor_float(quantaAmount * MathHelper.floor_float(fluidStack.amount / quantaAmount));
|
||||
quanta = MathHelper.floor_float(closest / quantaAmount);
|
||||
}
|
||||
if (existing.getBlock() == this)
|
||||
{
|
||||
int existingQuanta = existing.getValue(LEVEL) + 1;
|
||||
int missingQuanta = quantaPerBlock - existingQuanta;
|
||||
closest = Math.min(closest, MathHelper.floor_float(missingQuanta * quantaAmount));
|
||||
quanta = Math.min(quanta + existingQuanta, quantaPerBlock);
|
||||
}
|
||||
|
||||
// If too little (or too much, technically impossible) fluid is to be placed, abort
|
||||
if (quanta < 1 || quanta > 16)
|
||||
return 0;
|
||||
|
||||
if (doPlace)
|
||||
{
|
||||
world.setBlockState(pos, getDefaultState().withProperty(LEVEL, quanta - 1), 11);
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(World world, BlockPos pos, boolean doDrain)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user