1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00

Added FakeInv in ArmorForge

This commit is contained in:
CURVX 2020-10-14 21:34:57 +05:30
parent b778e2158b
commit 1437a8d555

View File

@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -23,6 +24,8 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import javax.annotation.Nonnull;
public class ArmorForge extends MultiBlockMachine { public class ArmorForge extends MultiBlockMachine {
public ArmorForge(Category category, SlimefunItemStack item) { public ArmorForge(Category category, SlimefunItemStack item) {
@ -31,8 +34,8 @@ public class ArmorForge extends MultiBlockMachine {
@Override @Override
public void onInteract(Player p, Block b) { public void onInteract(Player p, Block b) {
Block dispBlock = b.getRelative(BlockFace.DOWN); Block dispenser = b.getRelative(BlockFace.DOWN);
BlockState state = PaperLib.getBlockState(dispBlock, false).getState(); BlockState state = PaperLib.getBlockState(dispenser, false).getState();
if (state instanceof Dispenser) { if (state instanceof Dispenser) {
Dispenser disp = (Dispenser) state; Dispenser disp = (Dispenser) state;
@ -44,13 +47,7 @@ public class ArmorForge extends MultiBlockMachine {
ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone(); ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
if (Slimefun.hasUnlocked(p, output, true)) { if (Slimefun.hasUnlocked(p, output, true)) {
Inventory outputInv = findOutputInventory(output, dispBlock, inv); craft(p, output, inv, dispenser);
if (outputInv != null) {
craft(p, output, inv, outputInv);
} else {
SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
}
} }
return; return;
@ -71,7 +68,28 @@ public class ArmorForge extends MultiBlockMachine {
return true; return true;
} }
private void craft(Player p, ItemStack output, Inventory inv, Inventory outputInv) { private Inventory createVirtualInventory(Inventory inv) {
Inventory fakeInv = Bukkit.createInventory(null, 9, "Fake Inventory");
for (int j = 0; j < inv.getContents().length; j++) {
ItemStack stack = inv.getContents()[j];
if (stack != null) {
stack = stack.clone();
ItemUtils.consumeItem(stack, true);
}
fakeInv.setItem(j, stack);
}
return fakeInv;
}
private void craft(Player p, ItemStack output, Inventory inv, Block dispenser) {
Inventory fakeInv = createVirtualInventory(inv);
Inventory outputInv = findOutputInventory(output, dispenser, inv, fakeInv);
if (outputInv != null) {
for (int j = 0; j < 9; j++) { for (int j = 0; j < 9; j++) {
ItemStack item = inv.getContents()[j]; ItemStack item = inv.getContents()[j];
@ -92,6 +110,10 @@ public class ArmorForge extends MultiBlockMachine {
} }
}, j * 20L); }, j * 20L);
} }
} else {
SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
}
} }
} }