Skip to content

Commit

Permalink
extract removeFluid function
Browse files Browse the repository at this point in the history
  • Loading branch information
Intybyte committed Sep 8, 2024
1 parent d41ad3f commit dcb9802
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,7 @@ protected void tick(@Nonnull Block b) {
}

Block nextFluid = findNextFluid(fluid);

if (nextFluid != null) {
removeCharge(blockLocation, ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(bucket, getOutputSlots());
nextFluid.setType(Material.AIR);
}
removeFluid(menu, blockLocation, slot, bucket, nextFluid, null);

return;
} else if (SlimefunUtils.isItemSimilar(itemInSlot, emptyBottle, true, false)) {
Expand All @@ -159,22 +153,35 @@ protected void tick(@Nonnull Block b) {
}

Block nextFluid = findNextFluid(fluid);

if (nextFluid != null) {
removeCharge(blockLocation, ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(bottle, getOutputSlots());

if (ThreadLocalRandom.current().nextInt(100) < 30) {
nextFluid.setType(Material.AIR);
}
}
removeFluid(menu, blockLocation, slot, bottle, nextFluid, 30);

return;
}
}
}

/**
* @param menu Menu from which take the iem and push the new element
* @param blockLocation Location of the FluidPump
* @param slot Slot to consume the item from
* @param stack Item to push into the menu
* @param nextFluid Fluid to potentially remove
* @param chance Chance of the removal of the fluid, if null it is 100%
*/
private void removeFluid(BlockMenu menu, Location blockLocation, int slot, ItemStack stack, Block nextFluid, Integer chance) {
if (nextFluid == null) {
return;
}

removeCharge(blockLocation, ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(stack, getOutputSlots());

if (chance == null || ThreadLocalRandom.current().nextInt(100) < chance) {
nextFluid.setType(Material.AIR);
}
}

@Nullable
private Block findNextFluid(@Nonnull Block fluid) {
if (fluid.getType() == Material.WATER || fluid.getType() == Material.BUBBLE_COLUMN) {
Expand Down

0 comments on commit dcb9802

Please sign in to comment.