1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #2270 from LinoxGH/master

Fixes #2265 <Tested>
This commit is contained in:
TheBusyBiscuit 2020-08-31 19:56:05 +02:00 committed by GitHub
commit 3d22e42bef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 22 deletions

View File

@ -92,6 +92,7 @@
* Fixed #2257
* Fixed #2260
* Fixed #2263
* Fixed #2265
* Fixed #2269
* Fixed #2266

View File

@ -127,31 +127,40 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
if (!menu.fits(bucket.get(), getOutputSlots())) {
return;
}
Block nextFluid = findNextFluid(fluid);
if (nextFluid == null) return;
removeCharge(b.getLocation(), ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(bucket.get().clone(), getOutputSlots());
consumeFluid(fluid);
nextFluid.setType(Material.AIR);
return;
}
}
}
}
private void consumeFluid(Block fluid) {
if (fluid.isLiquid()) {
if (fluid.getType() == Material.WATER || fluid.getType() == Material.BUBBLE_COLUMN) {
// With water we can be sure to find an infinite source whenever we go
// further than 2 blocks, so we can just remove the water here and save
// outselves all of that computing...
fluid.setType(Material.AIR);
private Block findNextFluid(Block fluid) {
if (fluid.getType() == Material.WATER || fluid.getType() == Material.BUBBLE_COLUMN) {
// With water we can be sure to find an infinite source whenever we go
// further than 2 blocks, so we can just remove the water here and save
// ourselves all of that computing...
if (isSource(fluid)) {
return fluid;
}
else {
List<Block> list = Vein.find(fluid, RANGE, block -> isLiquid(block) && block.getType() == fluid.getType());
list.get(list.size() - 1).setType(Material.AIR);
} else if (fluid.getType() == Material.LAVA) {
List<Block> list = Vein.find(fluid, RANGE, block -> block.getType() == fluid.getType());
for (int i = list.size() - 1; i >= 0; i--) {
Block block = list.get(i);
if (isSource(block)) {
return block;
}
}
}
return null;
}
private Optional<ItemStack> getFilledBucket(Block fluid) {
@ -166,21 +175,17 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
}
}
private boolean isLiquid(Block block) {
private boolean isSource(Block block) {
if (block.isLiquid()) {
BlockData data = block.getBlockData();
if (data instanceof Levelled) {
// Check if this is a full block.
return ((Levelled) data).getLevel() == 0;
}
else {
return false;
Levelled levelled = (Levelled) data;
return levelled.getLevel() == 0;
}
}
else {
return false;
}
return false;
}
@Override
@ -198,5 +203,4 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
}
};
}
}