1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2021-02-27 10:19:19 +01:00
parent ed847826c7
commit 84ad08be37
4 changed files with 82 additions and 6 deletions

View File

@ -45,6 +45,7 @@
* Fixed #2818
* Fixed a duplication glitch with the Woodcutter Android
* Fixed #2839
* Fixed #2849
## Release Candidate 20 (30 Jan 2021)

View File

@ -6,6 +6,7 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
@ -26,6 +27,7 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.OutputChest;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
@ -50,6 +52,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
protected final List<ItemStack> displayRecipes;
protected final MultiBlock multiblock;
@ParametersAreNonnullByDefault
public MultiBlockMachine(Category category, SlimefunItemStack item, ItemStack[] recipe, ItemStack[] machineRecipes, BlockFace trigger) {
super(category, item, RecipeType.MULTIBLOCK, recipe);
this.recipes = new ArrayList<>();
@ -60,6 +63,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
registerDefaultRecipes(displayRecipes);
}
@ParametersAreNonnullByDefault
public MultiBlockMachine(Category category, SlimefunItemStack item, ItemStack[] recipe, BlockFace trigger) {
this(category, item, recipe, new ItemStack[0], trigger);
}
@ -142,17 +146,25 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
* The {@link Block} of our {@link Dispenser}
* @param dispInv
* The {@link Inventory} of our {@link Dispenser}
*
* @return The target {@link Inventory}
*/
@Nullable
@ParametersAreNonnullByDefault
protected Inventory findOutputInventory(ItemStack adding, Block dispBlock, Inventory dispInv) {
return findOutputInventory(adding, dispBlock, dispInv, dispInv);
}
@Nullable
@ParametersAreNonnullByDefault
protected Inventory findOutputInventory(ItemStack product, Block dispBlock, Inventory dispInv, Inventory placeCheckerInv) {
Inventory outputInv = findOutputChest(dispBlock, product);
// This if-clause will trigger if no suitable output chest was found. It's functionally the same as the old fit
// check for the dispenser, only refactored.
/*
* This if-clause will trigger if no suitable output chest was found.
* It's functionally the same as the old fit check for the dispenser,
* only refactored.
*/
if (outputInv == null && InvUtils.fits(placeCheckerInv, product)) {
return dispInv;
} else {
@ -166,9 +178,9 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
Block potentialOutput = b.getRelative(face);
if (potentialOutput.getType() == Material.CHEST) {
String id = BlockStorage.checkID(potentialOutput);
SlimefunItem slimefunItem = BlockStorage.check(potentialOutput);
if (id != null && id.equals("OUTPUT_CHEST")) {
if (slimefunItem instanceof OutputChest) {
// Found the output chest! Now, let's check if we can fit the product in it.
BlockState state = PaperLib.getBlockState(potentialOutput, false).getState();
@ -187,7 +199,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
}
@Nonnull
private static Material[] convertItemStacksToMaterial(ItemStack[] items) {
private static Material[] convertItemStacksToMaterial(@Nonnull ItemStack[] items) {
List<Material> materials = new ArrayList<>();
for (ItemStack item : items) {

View File

@ -0,0 +1,62 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.blocks;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/**
* The {@link OutputChest} can be used to capture the output items from a {@link MultiBlockMachine}.
*
* @author TheBusyBiscuit
*
* @see MultiBlockMachine
*
*/
public class OutputChest extends SimpleSlimefunItem<BlockBreakHandler> {
@ParametersAreNonnullByDefault
public OutputChest(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
}
@Override
public BlockBreakHandler getItemHandler() {
/*
* Explosions don't need explicit handling here.
* The default of "destroy the chest and drop the contents" is
* fine for our purposes already.
*/
return new BlockBreakHandler(false, true) {
@Override
public void onPlayerBreak(BlockBreakEvent e, ItemStack item, List<ItemStack> drops) {
// Fixes #2849 - Manually drop inventory contents
Block b = e.getBlock();
BlockState state = PaperLib.getBlockState(b, false).getState();
if (state instanceof InventoryHolder) {
for (ItemStack stack : ((InventoryHolder) state).getInventory()) {
if (stack != null && !stack.getType().isAir()) {
drops.add(stack);
}
}
}
}
};
}
}

View File

@ -52,6 +52,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.Crucible;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.EnhancedFurnace;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.HardenedGlass;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.HologramProjector;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.OutputChest;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RepairedSpawner;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.UnplaceableBlock;
@ -243,7 +244,7 @@ public final class SlimefunItemSetup {
new ItemStack[] {new ItemStack(Material.COOKIE), SlimefunItems.ELYTRA_SCALE, null, null, null, null, null, null, null})
.register(plugin);
new SlimefunItem(categories.basicMachines, SlimefunItems.OUTPUT_CHEST, RecipeType.ENHANCED_CRAFTING_TABLE,
new OutputChest(categories.basicMachines, SlimefunItems.OUTPUT_CHEST, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.LEAD_INGOT, new ItemStack(Material.HOPPER), SlimefunItems.LEAD_INGOT, SlimefunItems.LEAD_INGOT, new ItemStack(Material.CHEST), SlimefunItems.LEAD_INGOT, null, SlimefunItems.LEAD_INGOT, null})
.register(plugin);