Skip to content

Commit

Permalink
Merge pull request Slimefun#3893 from JustAHuman-xD/feature/soul-soil…
Browse files Browse the repository at this point in the history
…-recipe

Gold Pan Rework (Continuation of Slimefun#3269)
  • Loading branch information
Sfiguz7 authored Jul 14, 2023
2 parents f2fb911 + e5dd218 commit dc22e66
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GoldPan;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.NetherGoldPan;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;

import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
Expand All @@ -28,10 +27,11 @@
* It also serves as a {@link NetherGoldPan}.
*
* @author TheBusyBiscuit
*
* @author svr333
* @author JustAHuman
*
* @see GoldPan
* @see NetherGoldPan
*
*/
public class ElectricGoldPan extends AContainer implements RecipeDisplayItem {

Expand All @@ -40,31 +40,37 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem {
private final GoldPan goldPan = SlimefunItems.GOLD_PAN.getItem(GoldPan.class);
private final GoldPan netherGoldPan = SlimefunItems.NETHER_GOLD_PAN.getItem(GoldPan.class);

private final ItemStack gravel = new ItemStack(Material.GRAVEL);
private final ItemStack soulSand = new ItemStack(Material.SOUL_SAND);

@ParametersAreNonnullByDefault
public ElectricGoldPan(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
addItemSetting(overrideOutputLimit);
}

/**
* This returns whether the {@link ElectricGoldPan} will stop proccessing inputs
* @deprecated since RC-36
* Use {@link ElectricGoldPan#isOutputLimitOverridden()} instead.
*/
@Deprecated(since = "RC-36")
public boolean isOutputLimitOverriden() {
return isOutputLimitOverridden();
}

/**
* This returns whether the {@link ElectricGoldPan} will stop processing inputs
* if both output slots contain items or if that default behavior should be
* overriden and allow the {@link ElectricGoldPan} to continue processing inputs
* overridden and allow the {@link ElectricGoldPan} to continue processing inputs
* even if both output slots are occupied. Note this option will allow players
* to force specific outputs from the {@link ElectricGoldPan} but can be
* necessary when a server has disabled cargo networks.
*
* @return If output limits are overriden
* @return If output limits are overridden
*/
public boolean isOutputLimitOverriden() {
public boolean isOutputLimitOverridden() {
return overrideOutputLimit.getValue();
}

@Override
public List<ItemStack> getDisplayRecipes() {
public @Nonnull List<ItemStack> getDisplayRecipes() {
List<ItemStack> recipes = new ArrayList<>();

recipes.addAll(goldPan.getDisplayRecipes());
Expand All @@ -80,30 +86,26 @@ public ItemStack getProgressBar() {

@Override
protected MachineRecipe findNextRecipe(BlockMenu menu) {
if (!isOutputLimitOverriden() && !hasFreeSlot(menu)) {
if (!isOutputLimitOverridden() && !hasFreeSlot(menu)) {
return null;
}

for (int slot : getInputSlots()) {
ItemStack item = menu.getItemInSlot(slot);
MachineRecipe recipe = null;
ItemStack output = null;

if (goldPan.isValidInput(item)) {
output = goldPan.getRandomOutput();
recipe = new MachineRecipe(3 / getSpeed(), new ItemStack[] { item }, new ItemStack[] { output });
} else if (netherGoldPan.isValidInput(item)) {
output = netherGoldPan.getRandomOutput();
recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { item }, new ItemStack[] { output });
}

if (SlimefunUtils.isItemSimilar(item, gravel, true, false)) {
ItemStack output = goldPan.getRandomOutput();
MachineRecipe recipe = new MachineRecipe(3 / getSpeed(), new ItemStack[] { gravel }, new ItemStack[] { output });

if (output.getType() != Material.AIR && menu.fits(output, getOutputSlots())) {
menu.consumeItem(slot);
return recipe;
}
} else if (SlimefunUtils.isItemSimilar(item, soulSand, true, false)) {
ItemStack output = netherGoldPan.getRandomOutput();
MachineRecipe recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { soulSand }, new ItemStack[] { output });

if (output.getType() != Material.AIR && menu.fits(output, getOutputSlots())) {
menu.consumeItem(slot);
return recipe;
}

if (output != null && output.getType() != Material.AIR && menu.fits(output, getOutputSlots())) {
menu.consumeItem(slot);
return recipe;
}
}

Expand All @@ -121,7 +123,7 @@ private boolean hasFreeSlot(@Nonnull BlockMenu menu) {
}

@Override
public String getMachineIdentifier() {
public @Nonnull String getMachineIdentifier() {
return "ELECTRIC_GOLD_PAN";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.OutputChest;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GoldPan;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.NetherGoldPan;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;

/**
* The {@link AutomatedPanningMachine} is a {@link MultiBlockMachine} that
* functions as a semi-automatic version of the {@link GoldPan} and {@link NetherGoldPan}.
*
* @author TheBusyBiscuit
* @author Liruxo
* @author svr333
* @author JustAHuman
*
* @see GoldPan
*
*/
public class AutomatedPanningMachine extends MultiBlockMachine {

Expand All @@ -62,38 +62,41 @@ public AutomatedPanningMachine(ItemGroup itemGroup, SlimefunItemStack item) {
@Override
public void onInteract(Player p, Block b) {
ItemStack input = p.getInventory().getItemInMainHand();
Material material = input.getType();
ItemStack output;

if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.GRAVEL), true, false) || SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SOUL_SAND), true, false)) {
Material material = input.getType();

if (p.getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(input, false);
}

ItemStack output = material == Material.GRAVEL ? goldPan.getRandomOutput() : netherGoldPan.getRandomOutput();
TaskQueue queue = new TaskQueue();
if (goldPan.isValidInputMaterial(material)) {
output = goldPan.getRandomOutput();
} else if (netherGoldPan.isValidInputMaterial(material)) {
output = netherGoldPan.getRandomOutput();
} else {
Slimefun.getLocalization().sendMessage(p, "machines.wrong-item", true);
return;
}

queue.thenRepeatEvery(20, 5, () -> b.getWorld().playEffect(b.getRelative(BlockFace.DOWN).getLocation(), Effect.STEP_SOUND, material));
if (p.getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(input, false);
}

queue.thenRun(20, () -> {
if (output.getType() != Material.AIR) {
Optional<Inventory> outputChest = OutputChest.findOutputChestFor(b.getRelative(BlockFace.DOWN), output);
TaskQueue queue = new TaskQueue();

if (outputChest.isPresent()) {
outputChest.get().addItem(output.clone());
} else {
b.getWorld().dropItemNaturally(b.getLocation(), output.clone());
}
queue.thenRepeatEvery(20, 5, () -> b.getWorld().playEffect(b.getRelative(BlockFace.DOWN).getLocation(), Effect.STEP_SOUND, material));
queue.thenRun(20, () -> {
if (output.getType() != Material.AIR) {
Optional<Inventory> outputChest = OutputChest.findOutputChestFor(b.getRelative(BlockFace.DOWN), output);

SoundEffect.AUTOMATED_PANNING_MACHINE_SUCCESS_SOUND.playAt(b);
if (outputChest.isPresent()) {
outputChest.get().addItem(output.clone());
} else {
SoundEffect.AUTOMATED_PANNING_MACHINE_FAIL_SOUND.playAt(b);
b.getWorld().dropItemNaturally(b.getLocation(), output.clone());
}
});

queue.execute(Slimefun.instance());
} else {
Slimefun.getLocalization().sendMessage(p, "machines.wrong-item", true);
}
SoundEffect.AUTOMATED_PANNING_MACHINE_SUCCESS_SOUND.playAt(b);
} else {
SoundEffect.AUTOMATED_PANNING_MACHINE_FAIL_SOUND.playAt(b);
}
});

queue.execute(Slimefun.instance());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.Effect;
Expand Down Expand Up @@ -38,15 +41,17 @@
* resources from Gravel.
*
* @author TheBusyBiscuit
* @author svr333
* @author JustAHuman
*
* @see NetherGoldPan
* @see AutomatedPanningMachine
* @see ElectricGoldPan
*
*/
public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements RecipeDisplayItem {

private final RandomizedSet<ItemStack> randomizer = new RandomizedSet<>();
private final Set<Material> inputMaterials = new HashSet<>(Arrays.asList(Material.GRAVEL));
private final Set<GoldPanDrop> drops = new HashSet<>();

@ParametersAreNonnullByDefault
Expand All @@ -59,14 +64,28 @@ public GoldPan(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeTyp
}

/**
* This method returns the target {@link Material} for this {@link GoldPan}.
*
* @return The {@link Material} this {@link GoldPan} can be used on
* @deprecated since RC-36
* Use {@link GoldPan#getInputMaterials()} instead.
*/
public @Nonnull Material getInputMaterial() {
@Deprecated(since = "RC-36")
public Material getInputMaterial() {
return Material.GRAVEL;
}

/**
* This method returns the target {@link Material Materials} for this {@link GoldPan}.
*
* @return The {@link Set} of {@link Material Materials} this {@link GoldPan} can be used on.
*/
public @Nonnull Set<Material> getInputMaterials() {
return Collections.unmodifiableSet(inputMaterials);
}

/**
* This method returns the target {@link GoldPanDrop GoldPanDrops} for this {@link GoldPan}.
*
* @return The {@link Set} of {@link GoldPanDrop GoldPanDrops} this {@link GoldPan} can drop.
*/
protected @Nonnull Set<GoldPanDrop> getGoldPanDrops() {
Set<GoldPanDrop> settings = new HashSet<>();

Expand All @@ -86,7 +105,7 @@ public void postRegister() {

/**
* <strong>Do not call this method directly</strong>.
*
* <p>
* This method is for internal purposes only.
* It will update and re-calculate all weights in our {@link RandomizedSet}.
*/
Expand Down Expand Up @@ -127,7 +146,7 @@ public void updateRandomizer() {
Block b = block.get();

// Check the clicked block type and for protections
if (b.getType() == getInputMaterial() && Slimefun.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), Interaction.BREAK_BLOCK)) {
if (isValidInputMaterial(b.getType()) && Slimefun.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), Interaction.BREAK_BLOCK)) {
ItemStack output = getRandomOutput();

b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
Expand Down Expand Up @@ -160,16 +179,49 @@ public void updateRandomizer() {

@Override
public @Nonnull List<ItemStack> getDisplayRecipes() {
List<ItemStack> recipes = new LinkedList<>();
List<ItemStack> recipes = new ArrayList<>();

for (GoldPanDrop drop : drops) {
if (drop.getValue() > 0) {
recipes.add(new ItemStack(getInputMaterial()));
if (drop.getValue() <= 0) {
continue;
}

for (Material material : getInputMaterials()) {
recipes.add(new ItemStack(material));
recipes.add(drop.getOutput());
}
}

return recipes;
}

/**
* This returns whether the {@link GoldPan} accepts the {@link ItemStack} as an input
*
* @param itemStack
* The {@link ItemStack} to check
*
* @return If the {@link ItemStack} is valid
*/
public boolean isValidInput(@Nullable ItemStack itemStack) {
if (itemStack == null) {
return false;
}

Material material = itemStack.getType();
return isValidInputMaterial(material) && SlimefunUtils.isItemSimilar(itemStack, new ItemStack(material), true, false);
}

/**
* This returns whether the {@link GoldPan} accepts the {@link Material} as an input
*
* @param material
* The {@link Material} to check
*
* @return If the {@link Material} is valid
*/
public boolean isValidInputMaterial(@Nonnull Material material) {
return getInputMaterials().contains(material);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -19,20 +20,29 @@
* which can be used on Soul Sand.
*
* @author TheBusyBiscuit
*
* @author svr333
* @author JustAHuman
*/
public class NetherGoldPan extends GoldPan {

private final Set<Material> inputMaterials = new HashSet<>(Arrays.asList(Material.SOUL_SAND, Material.SOUL_SOIL));

@ParametersAreNonnullByDefault
public NetherGoldPan(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
}

@Override
public @Nonnull Material getInputMaterial() {
@Deprecated(since = "RC-36")
public Material getInputMaterial() {
return Material.SOUL_SAND;
}

@Override
public @Nonnull Set<Material> getInputMaterials() {
return inputMaterials;
}

@Override
protected @Nonnull Set<GoldPanDrop> getGoldPanDrops() {
Set<GoldPanDrop> settings = new HashSet<>();
Expand Down

0 comments on commit dc22e66

Please sign in to comment.