Skip to content

Commit dcb9802

Browse files
committed
extract removeFluid function
1 parent d41ad3f commit dcb9802

File tree

1 file changed

+24
-17
lines changed
  • src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines

1 file changed

+24
-17
lines changed

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,7 @@ protected void tick(@Nonnull Block b) {
142142
}
143143

144144
Block nextFluid = findNextFluid(fluid);
145-
146-
if (nextFluid != null) {
147-
removeCharge(blockLocation, ENERGY_CONSUMPTION);
148-
menu.consumeItem(slot);
149-
menu.pushItem(bucket, getOutputSlots());
150-
nextFluid.setType(Material.AIR);
151-
}
145+
removeFluid(menu, blockLocation, slot, bucket, nextFluid, null);
152146

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

161155
Block nextFluid = findNextFluid(fluid);
162-
163-
if (nextFluid != null) {
164-
removeCharge(blockLocation, ENERGY_CONSUMPTION);
165-
menu.consumeItem(slot);
166-
menu.pushItem(bottle, getOutputSlots());
167-
168-
if (ThreadLocalRandom.current().nextInt(100) < 30) {
169-
nextFluid.setType(Material.AIR);
170-
}
171-
}
156+
removeFluid(menu, blockLocation, slot, bottle, nextFluid, 30);
172157

173158
return;
174159
}
175160
}
176161
}
177162

163+
/**
164+
* @param menu Menu from which take the iem and push the new element
165+
* @param blockLocation Location of the FluidPump
166+
* @param slot Slot to consume the item from
167+
* @param stack Item to push into the menu
168+
* @param nextFluid Fluid to potentially remove
169+
* @param chance Chance of the removal of the fluid, if null it is 100%
170+
*/
171+
private void removeFluid(BlockMenu menu, Location blockLocation, int slot, ItemStack stack, Block nextFluid, Integer chance) {
172+
if (nextFluid == null) {
173+
return;
174+
}
175+
176+
removeCharge(blockLocation, ENERGY_CONSUMPTION);
177+
menu.consumeItem(slot);
178+
menu.pushItem(stack, getOutputSlots());
179+
180+
if (chance == null || ThreadLocalRandom.current().nextInt(100) < chance) {
181+
nextFluid.setType(Material.AIR);
182+
}
183+
}
184+
178185
@Nullable
179186
private Block findNextFluid(@Nonnull Block fluid) {
180187
if (fluid.getType() == Material.WATER || fluid.getType() == Material.BUBBLE_COLUMN) {

0 commit comments

Comments
 (0)