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

Merge pull request #1 from TheBusyBiscuit/master

update to sf
This commit is contained in:
dniym 2019-08-03 13:39:06 -04:00 committed by GitHub
commit 0c4c25f31f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 618 additions and 494 deletions

View File

@ -234,6 +234,8 @@ public class SlimefunItems {
public static ItemStack ANCIENT_PEDESTAL = new CustomItem(Material.DISPENSER, "&dAncient Pedestal", "", "&5Part of the Ancient Altar");
public static ItemStack ANCIENT_ALTAR = new CustomItem(Material.ENCHANTING_TABLE, "&dAncient Altar", "", "&5Multi-Block Altar for", "&5magical Crafting Processes");
public static ItemStack DUCT_TAPE = null;
public static ItemStack COPPER_WIRE = new CustomItem(Material.STRING, "&6Copper Wire", "", "&6Crucial component in electric modules");
public static ItemStack RAINBOW_WOOL = new CustomItem(Material.WHITE_WOOL, "&5Rainbow Wool", "", "&dCycles through all Colors of the Rainbow!");
public static ItemStack RAINBOW_GLASS = new CustomItem(Material.WHITE_STAINED_GLASS, "&5Rainbow Glass", "", "&dCycles through all Colors of the Rainbow!");
@ -376,7 +378,7 @@ public class SlimefunItems {
public static ItemStack DIGITAL_MINER = new CustomItem(Material.IRON_PICKAXE, "&bDigital Miner", "", "&a&oDigs out everything!");
public static ItemStack ADVANCED_DIGITAL_MINER = new CustomItem(Material.DIAMOND_PICKAXE, "&6Advanced Digital Miner", "", "&a&oDigs out everything!", "&a&oAutomatically crushes your Ores");
public static ItemStack AUTOMATED_PANNING_MACHINE = new CustomItem(Material.BOWL, "&aAutomated Panning Machine", "", "&a&oA MultiBlock Version of the Gold Pan");
public static ItemStack OUTPUT_CHEST = new CustomItem(Material.CHEST, "&4Output Chest", "", "&c&oA basic machine will try to put", "&c&oitems in this chest if it's placed", "&c&oadjacent to the dispenser.");
public static ItemStack HOLOGRAM_PROJECTOR = new CustomItem(Material.QUARTZ_SLAB, "&bHologram Projector", "", "&rProjects an Editable Hologram");
/* Enhanced Furnaces */

View File

@ -2,11 +2,17 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem;
import java.util.*;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.InvUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.MultiBlock;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Container;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class SlimefunMachine extends SlimefunItem {
@ -14,6 +20,14 @@ public class SlimefunMachine extends SlimefunItem {
private List<ItemStack[]> recipes;
private List<ItemStack> shownRecipes;
private Material trigger;
//Adjacent blockfaces for iterative output chest checks
private static final BlockFace[] outputFaces = {
BlockFace.UP,
BlockFace.NORTH,
BlockFace.EAST,
BlockFace.SOUTH,
BlockFace.WEST
};
public SlimefunMachine(Category category, ItemStack item, String id, ItemStack[] recipe, ItemStack[] machineRecipes, Material trigger) {
super(category, item, id, RecipeType.MULTIBLOCK, recipe);
@ -47,6 +61,10 @@ public class SlimefunMachine extends SlimefunItem {
return this.shownRecipes;
}
public static BlockFace[] getOutputFaces() {
return outputFaces;
}
public void addRecipe(ItemStack[] input, ItemStack output) {
this.recipes.add(input);
this.recipes.add(new ItemStack[] {output});
@ -80,5 +98,35 @@ public class SlimefunMachine extends SlimefunItem {
public Iterator<ItemStack[]> recipeIterator() {
return this.recipes.iterator();
}
// Overloaded method for finding a potential output chest. Fallbacks to the old system of putting the adding back into the dispenser.
// Optional last argument Inventory placeCheckerInv is for multiblock machines that create a dummy inventory to check if there's a space for the adding,
// i.e. Enhanced crafting table
public static Inventory findValidOutputInv(ItemStack adding, Block dispBlock, Inventory dispInv) {
return findValidOutputInv(adding, dispBlock, dispInv, dispInv);
}
public static Inventory findValidOutputInv(ItemStack product, Block dispBlock, Inventory dispInv, Inventory placeCheckerInv) {
Inventory outputInv = null;
for (BlockFace face : outputFaces) {
Block potentialOutput = dispBlock.getRelative(face);
String id = BlockStorage.checkID(potentialOutput);
if (id != null && id.equals("OUTPUT_CHEST")) {
// Found the output chest! Now, let's check if we can fit the product in it.
Inventory inv = ((Container) potentialOutput.getState()).getInventory();
if (InvUtils.fits(inv, product)) {
// It fits! Let's set the inventory to that now.
outputInv = inv;
break;
}
}
}
// 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)) outputInv = dispInv;
return outputInv;
}
}

View File

@ -1,200 +1,211 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.Setup.Messages;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class AdvancedCargoOutputNode extends SlimefunItem {
private static final int[] border = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 24, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
public AdvancedCargoOutputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, name, recipeType, recipe, recipeOutput);
new BlockMenuPreset(name, "&cOutput Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.WHITE_WOOL), "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.BLACK_WOOL), "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.STONE_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.GOLDEN_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (CargoNet.EXTRA_CHANNELS) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialHelper.WoolColours[channel]), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (CargoNet.EXTRA_CHANNELS) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean canOpen(Block b, Player p) {
boolean open = CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b) || p.hasPermission("slimefun.cargo.bypass");
if (!open) {
Messages.local.sendTranslation(p, "inventory.no-access", true);
}
return open;
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(name, new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot: getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
return true;
}
});
}
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
}
preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"),
(p, slot, item, action) -> false
);
}
public int[] getInputSlots() {
return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
}
}
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.Setup.Messages;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class AdvancedCargoOutputNode extends SlimefunItem {
private static final int[] border = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 24, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
public AdvancedCargoOutputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, name, recipeType, recipe, recipeOutput);
new BlockMenuPreset(name, "&cOutput Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.WHITE_WOOL), "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.BLACK_WOOL), "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
ItemStack is = new ItemStack(Material.STONE_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true");
newInstance(menu, b);
return false;
});
}
else {
ItemStack is = new ItemStack(Material.GOLDEN_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (CargoNet.EXTRA_CHANNELS) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialHelper.WoolColours[channel]), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (CargoNet.EXTRA_CHANNELS) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean canOpen(Block b, Player p) {
boolean open = CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b) || p.hasPermission("slimefun.cargo.bypass");
if (!open) {
Messages.local.sendTranslation(p, "inventory.no-access", true);
}
return open;
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(name, new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot: getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
return true;
}
});
}
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
}
preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"),
(p, slot, item, action) -> false
);
}
public int[] getInputSlots() {
return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
}
}

View File

@ -1,218 +1,228 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines;
import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.Setup.Messages;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class CargoInputNode extends SlimefunItem {
private static final int[] border = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
public CargoInputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, name, recipeType, recipe, recipeOutput);
new BlockMenuPreset(name, "&3Input Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.WHITE_WOOL), "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.BLACK_WOOL), "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.STONE_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.GOLDEN_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals("false")) {
menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&7Round-Robin Mode: &4\u2718", "", "&e> Click to enable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "round-robin", "true");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&7Round-Robin Mode: &2\u2714", "", "&e> Click to disable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "round-robin", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (CargoNet.EXTRA_CHANNELS) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialHelper.WoolColours[channel]), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (CargoNet.EXTRA_CHANNELS) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean canOpen(Block b, Player p) {
boolean open = CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b) || p.hasPermission("slimefun.cargo.bypass");
if (!open) {
Messages.local.sendTranslation(p, "inventory.no-access", true);
}
return open;
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(name, new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
BlockStorage.addBlockInfo(b, "round-robin", "false");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
return true;
}
});
}
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
}
preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"),
(p, slot, item, action) -> false
);
}
public int[] getInputSlots() {
return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
}
}
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines;
import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.Setup.Messages;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class CargoInputNode extends SlimefunItem {
private static final int[] border = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
public CargoInputNode(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, name, recipeType, recipe, recipeOutput);
new BlockMenuPreset(name, "&3Input Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(final BlockMenu menu, final Block b) {
try {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.WHITE_WOOL), "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(new ItemStack(Material.BLACK_WOOL), "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
ItemStack is = new ItemStack(Material.STONE_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true");
newInstance(menu, b);
return false;
});
}
else {
ItemStack is = new ItemStack(Material.GOLDEN_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals("false")) {
menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&7Round-Robin Mode: &4\u2718", "", "&e> Click to enable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "round-robin", "true");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(24, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&7Round-Robin Mode: &2\u2714", "", "&e> Click to disable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "round-robin", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(new ItemStack(Material.MAP), "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (CargoNet.EXTRA_CHANNELS) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0: (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunItems.CHEST_TERMINAL, "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialHelper.WoolColours[channel]), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42,
(p, slot, item, action) -> false
);
}
menu.replaceExistingItem(43, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ=="), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (CargoNet.EXTRA_CHANNELS) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean canOpen(Block b, Player p) {
boolean open = CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b) || p.hasPermission("slimefun.cargo.bypass");
if (!open) {
Messages.local.sendTranslation(p, "inventory.no-access", true);
}
return open;
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(name, new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
BlockStorage.addBlockInfo(b, "round-robin", "false");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
}
return true;
}
});
}
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
}
preset.addItem(2, new CustomItem(new ItemStack(Material.PAPER), "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"),
(p, slot, item, action) -> false
);
}
public int[] getInputSlots() {
return new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
}
}

View File

@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemStack;
public class ResearchSetup {
public static void setupResearches() {
Slimefun.registerResearch(new Research(0, "Walking Sticks", 1), SlimefunItems.GRANDMAS_WALKING_STICK, SlimefunItems.GRANDPAS_WALKING_STICK);
Slimefun.registerResearch(new Research(0, "Walking Sticks", 1), SlimefunItems.GRANDMAS_WALKING_STICK, SlimefunItems.GRANDPAS_WALKING_STICK);
Slimefun.registerResearch(new Research(1, "Portable Crafter", 1), SlimefunItems.PORTABLE_CRAFTER);
Slimefun.registerResearch(new Research(2, "Fortune Cookie", 1), SlimefunItems.FORTUNE_COOKIE);
Slimefun.registerResearch(new Research(4, "Portable Dustbin", 2), SlimefunItems.PORTABLE_DUSTBIN);
@ -235,5 +235,7 @@ public class ResearchSetup {
Slimefun.registerResearch(new Research(236, "Nether Star Reactor", 60), SlimefunItems.NETHERSTAR_REACTOR);
Slimefun.registerResearch(new Research(237, "Blistering Radioactivity", 38), SlimefunItems.BLISTERING_INGOT, SlimefunItems.BLISTERING_INGOT_2, SlimefunItems.BLISTERING_INGOT_3);
Slimefun.registerResearch(new Research(239, "Automatic Ignition Chamber", 12), SlimefunItems.IGNITION_CHAMBER);
Slimefun.registerResearch(new Research(240, "Basic machinery output chest", 20), SlimefunItems.OUTPUT_CHEST);
Slimefun.registerResearch(new Research(241, "Thinned-down Conductivity", 15), SlimefunItems.COPPER_WIRE);
}
}

View File

@ -14,6 +14,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
@ -21,6 +22,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Dispenser;
import org.bukkit.block.Hopper;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Levelled;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.ArmorStand;
@ -189,6 +191,10 @@ public class SlimefunSetup {
new ItemStack[] {new ItemStack(Material.COOKIE), new ItemStack(Material.PAPER), null, null, null, null, null, null, null})
.register(true);
new SlimefunItem(Categories.MACHINES_1, SlimefunItems.OUTPUT_CHEST, "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(true);
new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.ENHANCED_CRAFTING_TABLE, "ENHANCED_CRAFTING_TABLE",
new ItemStack[] {null, null, null, null, new ItemStack(Material.CRAFTING_TABLE), null, null, new ItemStack(Material.DISPENSER), null},
new ItemStack[0], Material.CRAFTING_TABLE)
@ -202,9 +208,13 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState();
final Inventory inv = disp.getInventory();
// Objects dispBlock and disp have been split up, in order to add the output chest functionallity, which is the only functionallity
// that is dependant on the dispenser's block methods.
// the Dispenser disp still remains the same though, and as such doesn't break any existing code which involves said object.
Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
for (int i = 0; i < inputs.size(); i++) {
@ -231,9 +241,11 @@ public class SlimefunSetup {
for (int j = 0; j < inv.getContents().length; j++) {
inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null);
}
if (InvUtils.fits(inv2, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv, inv2);
if (outputInv != null) {
SlimefunItem sfItem = SlimefunItem.getByItem(adding);
if (sfItem instanceof SlimefunBackpack) {
ItemStack backpack = null;
@ -300,7 +312,8 @@ public class SlimefunSetup {
}
p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1);
inv.addItem(adding);
outputInv.addItem(adding);
}
else Messages.local.sendTranslation(p, "machines.full-inventory", true);
}
@ -338,7 +351,7 @@ public class SlimefunSetup {
new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.GRIND_STONE, "GRIND_STONE",
new ItemStack[] {null, null, null, null, new ItemStack(Material.OAK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null},
new ItemStack[] {new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4), new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4), new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT), new ItemStack(Material.NETHER_WART), new CustomItem(SlimefunItems.MAGIC_LUMP_1, 2), new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2), new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL), new ItemStack(Material.WHEAT), SlimefunItems.WHEAT_FLOUR, new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK},
new ItemStack[] {new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4), new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4), new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT), new ItemStack(Material.NETHER_WART), new CustomItem(SlimefunItems.MAGIC_LUMP_1, 2), new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2), new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL), new ItemStack(Material.WHEAT), SlimefunItems.WHEAT_FLOUR, new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK, new ItemStack(Material.SANDSTONE), new ItemStack(Material.SAND, 4), new ItemStack(Material.RED_SANDSTONE), new ItemStack(Material.RED_SAND, 4)},
Material.OAK_FENCE)
.register(true, new MultiBlockInteractionHandler() {
@ -350,17 +363,19 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState();
Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
ItemStack output = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, output)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(output, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone();
removing.setAmount(1);
inv.removeItem(removing);
inv.addItem(output);
outputInv.addItem(output);
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1);
}
else Messages.local.sendTranslation(p, "machines.full-inventory", true);
@ -391,8 +406,9 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState();
final Inventory inv = disp.getInventory();
Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
for (int i = 0; i < inputs.size(); i++) {
@ -407,7 +423,8 @@ public class SlimefunSetup {
if (craft) {
final ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i)).clone();
if (Slimefun.hasUnlocked(p, adding, true)) {
if (InvUtils.fits(inv, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
for (ItemStack removing: inputs.get(i)) {
if (removing != null) inv.removeItem(removing);
}
@ -418,7 +435,7 @@ public class SlimefunSetup {
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ANVIL_USE, 1F, 2F);
} else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(adding);
outputInv.addItem(adding);
}
}, j*20L);
}
@ -451,17 +468,19 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState();
Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone();
removing.setAmount(convert.getAmount());
inv.removeItem(removing);
inv.addItem(adding);
outputInv.addItem(adding);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1);
}
else Messages.local.sendTranslation(p, "machines.full-inventory", true);
@ -492,13 +511,15 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState();
final Inventory inv = disp.getInventory();
Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
final ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone();
removing.setAmount(convert.getAmount());
inv.removeItem(removing);
@ -509,7 +530,7 @@ public class SlimefunSetup {
p.getWorld().playSound(p.getLocation(), j == 1 ? Sound.BLOCK_PISTON_CONTRACT : Sound.BLOCK_PISTON_EXTEND, 1F, j == 0 ? 1F : 2F);
} else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(adding);
outputInv.addItem(adding);
}
}, i*20L);
}
@ -709,7 +730,8 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState();
Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
@ -730,23 +752,27 @@ public class SlimefunSetup {
if (craft) {
ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i)).clone();
if (Slimefun.hasUnlocked(p, adding, true)) {
if (InvUtils.fits(inv, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
for (ItemStack removing: inputs.get(i)) {
if (removing != null) inv.removeItem(removing);
}
inv.addItem(adding);
outputInv.addItem(adding);
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1);
p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
Block raw_disp = b.getRelative(BlockFace.DOWN);
// Block raw_disp = b.getRelative(BlockFace.DOWN);
// raw_disp has been removed since the outputInv functionality already uses such an object which is declared above as dispBlock.
// The chamber methods have been updated to reflect this change.
// Maybe this code snippet should be turned into a loop?
Hopper chamber = null;
if (BlockStorage.check(raw_disp.getRelative(BlockFace.EAST).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) raw_disp.getRelative(BlockFace.EAST).getState();
} else if (BlockStorage.check(raw_disp.getRelative(BlockFace.WEST).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) raw_disp.getRelative(BlockFace.WEST).getState();
} else if (BlockStorage.check(raw_disp.getRelative(BlockFace.NORTH).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) raw_disp.getRelative(BlockFace.NORTH).getState();
} else if (BlockStorage.check(raw_disp.getRelative(BlockFace.SOUTH).getState().getBlock(), "IGNITION_CHAMBER")){
chamber = (Hopper) raw_disp.getRelative(BlockFace.SOUTH).getState();
if (BlockStorage.check(dispBlock.getRelative(BlockFace.EAST).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) dispBlock.getRelative(BlockFace.EAST).getState();
} else if (BlockStorage.check(dispBlock.getRelative(BlockFace.WEST).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) dispBlock.getRelative(BlockFace.WEST).getState();
} else if (BlockStorage.check(dispBlock.getRelative(BlockFace.NORTH).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) dispBlock.getRelative(BlockFace.NORTH).getState();
} else if (BlockStorage.check(dispBlock.getRelative(BlockFace.SOUTH).getState().getBlock(), "IGNITION_CHAMBER")){
chamber = (Hopper) dispBlock.getRelative(BlockFace.SOUTH).getState();
}
if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("SMELTERY", "chance.fireBreak"))) {
@ -810,13 +836,15 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getState();
Block dispBlock = b.getRelative(BlockFace.UP).getRelative(BlockFace.UP);
Dispenser disp = (Dispenser) dispBlock.getState();
final Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
final ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone();
removing.setAmount(convert.getAmount());
inv.removeItem(removing);
@ -831,7 +859,7 @@ public class SlimefunSetup {
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_TNT_PRIMED, 1F, 1F);
} else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(adding);
outputInv.addItem(adding);
}
}, i*20L);
}
@ -1130,13 +1158,14 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = null;
if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(1, 0, 0).getState();
else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(0, 0, 1).getState();
else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(-1, 0, 0).getState();
else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(0, 0, -1).getState();
Block dispBlock = null;
// Maybe this could be implemented by instead looping over a BlockFace<> array?
if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) dispBlock = b.getRelative(1, 0, 0);
else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) dispBlock = b.getRelative(0, 0, 1);
else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) dispBlock = b.getRelative(-1, 0, 0);
else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) dispBlock = b.getRelative(0, 0, -1);
Dispenser disp = (Dispenser) dispBlock.getState();
final Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
@ -1164,7 +1193,8 @@ public class SlimefunSetup {
for (int j = 0; j < inv.getContents().length; j++) {
inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null);
}
if (InvUtils.fits(inv2, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv, inv2);
if (outputInv != null) {
SlimefunItem sfItem = SlimefunItem.getByItem(adding);
if (sfItem instanceof SlimefunBackpack) {
@ -1238,7 +1268,7 @@ public class SlimefunSetup {
p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1F, 1F);
} else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(adding);
outputInv.addItem(adding);
}
}, j*20L);
}
@ -1352,7 +1382,8 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.UP).getState();
Block dispBlock = b.getRelative(BlockFace.UP);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) {
if (current != null) {
@ -1366,26 +1397,38 @@ public class SlimefunSetup {
else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.MAGNESIUM_DUST;
else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.LEAD_DUST;
else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.SILVER_DUST;
if (inv.firstEmpty() != -1 || (legacy_ore_washer && InvUtils.fits(inv, adding))) {
Inventory outputInv = null;
if (!legacy_ore_washer) {
// This is a fancy way of checking if there is empty space in the inv; by checking if an unobtainable item could fit in it.
// However, due to the way the method findValidOutputInv() functions, the dummyAdding will never actually be added to the real inventory,
// so it really doesn't matter what item the ItemStack is made by. SlimefunItems.DEBUG_FISH however, signals that it's
// not supposed to be given to the player.
ItemStack dummyAdding = SlimefunItems.DEBUG_FISH;
outputInv = SlimefunMachine.findValidOutputInv(dummyAdding, dispBlock, inv);
} else outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone();
removing.setAmount(1);
inv.removeItem(removing);
inv.addItem(adding);
outputInv.addItem(adding);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER);
if (InvUtils.fits(inv, SlimefunItems.STONE_CHUNK)) inv.addItem(SlimefunItems.STONE_CHUNK);
if (InvUtils.fits(outputInv, SlimefunItems.STONE_CHUNK)) outputInv.addItem(SlimefunItems.STONE_CHUNK);
}
else Messages.local.sendTranslation(p, "machines.full-inventory", true);
return true;
}
else if (SlimefunManager.isItemSimiliar(current, new ItemStack(Material.SAND, 4), false)) {
ItemStack adding = SlimefunItems.SALT;
if (InvUtils.fits(inv, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone();
removing.setAmount(4);
inv.removeItem(removing);
inv.addItem(adding);
outputInv.addItem(adding);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1);
}
@ -1394,11 +1437,12 @@ public class SlimefunSetup {
}
else if (SlimefunManager.isItemSimiliar(current, SlimefunItems.PULVERIZED_ORE, true)) {
ItemStack adding = SlimefunItems.PURE_ORE_CLUSTER;
if (InvUtils.fits(inv, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone();
removing.setAmount(1);
inv.removeItem(removing);
inv.addItem(adding);
outputInv.addItem(adding);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1);
}
@ -2535,17 +2579,19 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, SlimefunItems.JUICER, true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState();
Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) {
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone();
removing.setAmount(1);
inv.removeItem(removing);
inv.addItem(adding);
outputInv.addItem(adding);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.HAY_BLOCK);
}
@ -2679,13 +2725,18 @@ public class SlimefunSetup {
.register(true);
new SlimefunItem(Categories.TECH_MISC, SlimefunItems.ELECTRIC_MOTOR, "ELECTRIC_MOTOR", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, null, SlimefunItems.ELECTRO_MAGNET, null, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT})
new ItemStack[] {SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, null, SlimefunItems.ELECTRO_MAGNET, null, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE})
.register(true);
new SlimefunItem(Categories.TECH_MISC, SlimefunItems.HEATING_COIL, "HEATING_COIL", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT})
new ItemStack[] {SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE})
.register(true);
new SlimefunItem(Categories.TECH_MISC, SlimefunItems.COPPER_WIRE, "COPPER_WIRE", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {null, null, null, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, null, null, null}, new CustomItem(SlimefunItems.COPPER_WIRE, 8))
.register(true);
@SuppressWarnings("unchecked")
final String[] blockPlacerBlacklist = Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks") != null ? ((List<String>) Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks")).toArray(new String[((List<String>) Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks")).size()]) : new String[] {"STRUCTURE_BLOCK"};
@ -3611,30 +3662,30 @@ public class SlimefunSetup {
registerFuel(new MachineFuel(3, new ItemStack(Material.POTATO)));
registerFuel(new MachineFuel(3, new ItemStack(Material.SUGAR_CANE)));
registerFuel(new MachineFuel(3, new ItemStack(Material.NETHER_WART)));
registerFuel(new MachineFuel(2, new ItemStack(Material.DANDELION)));
registerFuel(new MachineFuel(2, new ItemStack(Material.POPPY)));
registerFuel(new MachineFuel(2, new ItemStack(Material.RED_MUSHROOM)));
registerFuel(new MachineFuel(2, new ItemStack(Material.BROWN_MUSHROOM)));
registerFuel(new MachineFuel(2, new ItemStack(Material.VINE)));
registerFuel(new MachineFuel(2, new ItemStack(Material.CACTUS)));
registerFuel(new MachineFuel(2, new ItemStack(Material.LILY_PAD)));
registerFuel(new MachineFuel(8, new ItemStack(Material.CHORUS_FRUIT)));
registerFuel(new MachineFuel(1, new ItemStack(Material.BAMBOO)));
registerFuel(new MachineFuel(1, new ItemStack(Material.KELP)));
registerFuel(new MachineFuel(2, new ItemStack(Material.DRIED_KELP)));
registerFuel(new MachineFuel(20, new ItemStack(Material.DRIED_KELP_BLOCK)));
registerFuel(new MachineFuel(1, new ItemStack(Material.SEAGRASS)));
registerFuel(new MachineFuel(2, new ItemStack(Material.SEA_PICKLE)));
// Leaves
registerFuel(new MachineFuel(1, new ItemStack(Material.OAK_LEAVES)));
registerFuel(new MachineFuel(1, new ItemStack(Material.BIRCH_LEAVES)));
registerFuel(new MachineFuel(1, new ItemStack(Material.SPRUCE_LEAVES)));
registerFuel(new MachineFuel(1, new ItemStack(Material.JUNGLE_LEAVES)));
registerFuel(new MachineFuel(1, new ItemStack(Material.ACACIA_LEAVES)));
registerFuel(new MachineFuel(1, new ItemStack(Material.DARK_OAK_LEAVES)));
for(Material m:Tag.LEAVES.getValues())
registerFuel(new MachineFuel(1, new ItemStack(m)));
// Saplings
registerFuel(new MachineFuel(1, new ItemStack(Material.OAK_SAPLING)));
registerFuel(new MachineFuel(1, new ItemStack(Material.BIRCH_SAPLING)));
registerFuel(new MachineFuel(1, new ItemStack(Material.SPRUCE_SAPLING)));
registerFuel(new MachineFuel(1, new ItemStack(Material.JUNGLE_SAPLING)));
registerFuel(new MachineFuel(1, new ItemStack(Material.ACACIA_SAPLING)));
registerFuel(new MachineFuel(1, new ItemStack(Material.DARK_OAK_SAPLING)));
for (Material m:Tag.SAPLINGS.getValues())
registerFuel(new MachineFuel(1, new ItemStack(m)));
// Small Flowers (formally just dandelions and poppies.
for(Material m:Tag.SMALL_FLOWERS.getValues())
registerFuel(new MachineFuel(1, new ItemStack(m)));
}
@Override