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

Merge pull request #3893 from JustAHuman-xD/feature/soul-soil-recipe

Gold Pan Rework (Continuation of #3269)
This commit is contained in:
Sfiguz7 2023-07-14 15:42:35 +02:00 committed by GitHub
commit dc22e66589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 73 deletions

View File

@ -17,7 +17,6 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
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;
@ -28,10 +27,11 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
* It also serves as a {@link NetherGoldPan}.
*
* @author TheBusyBiscuit
*
* @author svr333
* @author JustAHuman
*
* @see GoldPan
* @see NetherGoldPan
*
*/
public class ElectricGoldPan extends AContainer implements RecipeDisplayItem {
@ -40,9 +40,6 @@ 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);
@ -50,21 +47,30 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem {
}
/**
* 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());
@ -80,30 +86,26 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem {
@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 (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 (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 (output != null && output.getType() != Material.AIR && menu.fits(output, getOutputSlots())) {
menu.consumeItem(slot);
return recipe;
}
}
@ -121,7 +123,7 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem {
}
@Override
public String getMachineIdentifier() {
public @Nonnull String getMachineIdentifier() {
return "ELECTRIC_GOLD_PAN";
}

View File

@ -27,7 +27,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
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
@ -35,9 +34,10 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
*
* @author TheBusyBiscuit
* @author Liruxo
* @author svr333
* @author JustAHuman
*
* @see GoldPan
*
*/
public class AutomatedPanningMachine extends MultiBlockMachine {
@ -62,38 +62,41 @@ public class AutomatedPanningMachine extends MultiBlockMachine {
@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();
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);
if (outputChest.isPresent()) {
outputChest.get().addItem(output.clone());
} else {
b.getWorld().dropItemNaturally(b.getLocation(), output.clone());
}
SoundEffect.AUTOMATED_PANNING_MACHINE_SUCCESS_SOUND.playAt(b);
} else {
SoundEffect.AUTOMATED_PANNING_MACHINE_FAIL_SOUND.playAt(b);
}
});
queue.execute(Slimefun.instance());
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;
}
if (p.getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(input, false);
}
TaskQueue queue = new TaskQueue();
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);
if (outputChest.isPresent()) {
outputChest.get().addItem(output.clone());
} else {
b.getWorld().dropItemNaturally(b.getLocation(), output.clone());
}
SoundEffect.AUTOMATED_PANNING_MACHINE_SUCCESS_SOUND.playAt(b);
} else {
SoundEffect.AUTOMATED_PANNING_MACHINE_FAIL_SOUND.playAt(b);
}
});
queue.execute(Slimefun.instance());
}
}

View File

@ -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;
@ -38,15 +41,17 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
* 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
@ -59,14 +64,28 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
}
/**
* 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<>();
@ -86,7 +105,7 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
/**
* <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}.
*/
@ -127,7 +146,7 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
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());
@ -160,11 +179,15 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
@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());
}
}
@ -172,4 +195,33 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
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);
}
}

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@ -19,20 +20,29 @@ import io.github.thebusybiscuit.slimefun4.implementation.settings.GoldPanDrop;
* 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<>();