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

Forward & Update svr's changes

This commit is contained in:
JustAHuman-xD 2023-07-04 15:10:40 -05:00
parent 75a781d3d6
commit 103bd8bbd4
4 changed files with 89 additions and 74 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,21 @@ public class ElectricGoldPan extends AContainer implements RecipeDisplayItem {
}
/**
* This returns whether the {@link ElectricGoldPan} will stop proccessing inputs
* 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 +77,24 @@ 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);
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();
} else if (netherGoldPan.isValidInput(item)) {
output = netherGoldPan.getRandomOutput();
}
if (output != null && output.getType() != Material.AIR && menu.fits(output, getOutputSlots())) {
MachineRecipe recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { item }, new ItemStack[] { output });
menu.consumeItem(slot);
return recipe;
}
}
@ -121,7 +112,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,19 +62,25 @@ public class AutomatedPanningMachine extends MultiBlockMachine {
@Override
public void onInteract(Player p, Block b) {
ItemStack input = p.getInventory().getItemInMainHand();
if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.GRAVEL), true, false) || SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SOUL_SAND), true, false)) {
Material material = input.getType();
ItemStack output;
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);
}
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);
@ -92,8 +98,5 @@ public class AutomatedPanningMachine extends MultiBlockMachine {
});
queue.execute(Slimefun.instance());
} else {
Slimefun.getLocalization().sendMessage(p, "machines.wrong-item", true);
}
}
}

View File

@ -1,7 +1,9 @@
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;
@ -38,15 +40,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,12 +63,12 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
}
/**
* This method returns the target {@link Material} for this {@link GoldPan}.
* This method returns the target {@link Material Materials} for this {@link GoldPan}.
*
* @return The {@link Material} this {@link GoldPan} can be used on
* @return The {@link Set} of {@link Material Materials} this {@link GoldPan} can be used on
*/
public @Nonnull Material getInputMaterial() {
return Material.GRAVEL;
public @Nonnull Set<Material> getInputMaterials() {
return Collections.unmodifiableSet(inputMaterials);
}
protected @Nonnull Set<GoldPanDrop> getGoldPanDrops() {
@ -86,7 +90,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 +131,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 +164,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 inputMaterial : getInputMaterials()) {
recipes.add(new ItemStack(inputMaterial));
recipes.add(drop.getOutput());
}
}
@ -172,4 +180,13 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
return recipes;
}
public boolean isValidInput(ItemStack input) {
Material inputMaterial = input.getType();
return isValidInputMaterial(inputMaterial) && SlimefunUtils.isItemSimilar(input, new ItemStack(inputMaterial), true, false);
}
public boolean isValidInputMaterial(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,18 +20,21 @@ 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() {
return Material.SOUL_SAND;
public @Nonnull Set<Material> getInputMaterials() {
return inputMaterials;
}
@Override