Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/fluid pump refactor #4236

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -72,7 +73,7 @@ private BlockBreakHandler onBreak() {
return new SimpleBlockBreakHandler() {

@Override
public void onBlockBreak(Block b) {
public void onBlockBreak(@Nonnull Block b) {
BlockMenu inv = BlockStorage.getInventory(b);

if (inv != null) {
Expand Down Expand Up @@ -111,7 +112,7 @@ public int[] getOutputSlots() {
}

@Override
public EnergyNetComponentType getEnergyComponentType() {
public @Nonnull EnergyNetComponentType getEnergyComponentType() {
return EnergyNetComponentType.CONSUMER;
}

Expand All @@ -122,52 +123,62 @@ public int getCapacity() {

protected void tick(@Nonnull Block b) {
Block fluid = b.getRelative(BlockFace.DOWN);
Location blockLocation = b.getLocation();

if (fluid.isLiquid() && getCharge(b.getLocation()) >= ENERGY_CONSUMPTION) {
BlockMenu menu = BlockStorage.getInventory(b);
if (!fluid.isLiquid() || getCharge(blockLocation) < ENERGY_CONSUMPTION) {
return;
}

BlockMenu menu = BlockStorage.getInventory(b);

for (int slot : getInputSlots()) {
ItemStack itemInSlot = menu.getItemInSlot(slot);
for (int slot : getInputSlots()) {
ItemStack itemInSlot = menu.getItemInSlot(slot);

if (SlimefunUtils.isItemSimilar(itemInSlot, emptyBucket, true, false)) {
ItemStack bucket = getFilledBucket(fluid);
if (SlimefunUtils.isItemSimilar(itemInSlot, emptyBucket, true, false)) {
ItemStack bucket = getFilledBucket(fluid);

if (!menu.fits(bucket, getOutputSlots())) {
return;
}
if (!menu.fits(bucket, getOutputSlots())) {
return;
}

Block nextFluid = findNextFluid(fluid);
Block nextFluid = findNextFluid(fluid);
removeFluid(menu, blockLocation, slot, bucket, nextFluid, null);

if (nextFluid != null) {
removeCharge(b.getLocation(), ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(bucket, getOutputSlots());
nextFluid.setType(Material.AIR);
}
return;
} else if (SlimefunUtils.isItemSimilar(itemInSlot, emptyBottle, true, false)) {
ItemStack bottle = getFilledBottle(fluid);

if (!menu.fits(bottle, getOutputSlots())) {
return;
} else if (SlimefunUtils.isItemSimilar(itemInSlot, emptyBottle, true, false)) {
ItemStack bottle = getFilledBottle(fluid);
}

if (!menu.fits(bottle, getOutputSlots())) {
return;
}
Block nextFluid = findNextFluid(fluid);
removeFluid(menu, blockLocation, slot, bottle, nextFluid, 30);

Block nextFluid = findNextFluid(fluid);
return;
}
}
}

if (nextFluid != null) {
removeCharge(b.getLocation(), ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(bottle, getOutputSlots());
/**
* @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;
}

if (ThreadLocalRandom.current().nextInt(100) < 30) {
nextFluid.setType(Material.AIR);
}
}
removeCharge(blockLocation, ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(stack, getOutputSlots());

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

Expand Down Expand Up @@ -244,7 +255,7 @@ private boolean isSource(@Nonnull Block block) {
}

@Override
public BlockTicker getItemHandler() {
public @Nonnull BlockTicker getItemHandler() {
return new BlockTicker() {

@Override
Expand Down
Loading