mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
added leftover changes, and bug fixes.
with possibility of bringing more bugs
This commit is contained in:
parent
e4a5e78cc6
commit
2233a0314d
@ -3,7 +3,7 @@ import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
|||||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
public final class BlockUtils {
|
final class BlockUtils {
|
||||||
|
|
||||||
private BlockUtils() {}
|
private BlockUtils() {}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||||
@ -72,18 +71,16 @@ final class CargoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int slot = minSlot; slot < maxSlot; slot++) {
|
for (int slot = minSlot; slot < maxSlot; slot++) {
|
||||||
ItemStack is = contents[slot];
|
ItemStack itemInSlot = contents[slot]; // Mapped into inventory
|
||||||
|
|
||||||
if (SlimefunUtils.isItemSimilar(is, template, true) && matchesFilter(node, is, -1)) {
|
if (SlimefunUtils.isItemSimilar(itemInSlot, template, true) && matchesFilter(node, itemInSlot, -1)) {
|
||||||
if (is.getAmount() > template.getAmount()) {
|
if (itemInSlot.getAmount() > template.getAmount()) {
|
||||||
is.setAmount(is.getAmount() - template.getAmount());
|
itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
|
||||||
inv.setItem(slot, is);
|
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
is.setAmount(is.getAmount() - template.getAmount());
|
itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
|
||||||
inv.setItem(slot, is);
|
return itemInSlot;
|
||||||
return is;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,11 +149,10 @@ final class CargoUtils {
|
|||||||
for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.INSERT, stack)) {
|
for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.INSERT, stack)) {
|
||||||
ItemStack itemInSlot = menu.getItemInSlot(slot);
|
ItemStack itemInSlot = menu.getItemInSlot(slot);
|
||||||
if (itemInSlot == null) {
|
if (itemInSlot == null) {
|
||||||
menu.replaceExistingItem(slot, stack.clone());
|
menu.replaceExistingItem(slot, stack);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemInSlot = itemInSlot.clone();
|
|
||||||
int inSlotMaxSize = itemInSlot.getType().getMaxStackSize();
|
int inSlotMaxSize = itemInSlot.getType().getMaxStackSize();
|
||||||
int inSlotAmount = itemInSlot.getAmount();
|
int inSlotAmount = itemInSlot.getAmount();
|
||||||
if (SlimefunUtils.isItemSimilar(itemInSlot, stack, true, false) && inSlotAmount < inSlotMaxSize) {
|
if (SlimefunUtils.isItemSimilar(itemInSlot, stack, true, false) && inSlotAmount < inSlotMaxSize) {
|
||||||
@ -211,26 +207,26 @@ final class CargoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int slot = minSlot; slot < maxSlot; slot++) {
|
for (int slot = minSlot; slot < maxSlot; slot++) {
|
||||||
ItemStack is = contents[slot];
|
ItemStack itemInSlot = contents[slot];
|
||||||
|
|
||||||
if (is == null) {
|
if (itemInSlot == null) {
|
||||||
inv.setItem(slot, stack.clone());
|
inv.setItem(slot, stack);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (SlimefunUtils.isItemSimilar(is, stack, true, false)
|
int maxStackSize = itemInSlot.getType().getMaxStackSize();
|
||||||
&& is.getAmount() < is.getType().getMaxStackSize()) {
|
if (SlimefunUtils.isItemSimilar(itemInSlot, stack, true, false) && itemInSlot.getAmount() < maxStackSize) {
|
||||||
int amount = is.getAmount() + stack.getAmount();
|
int amount = itemInSlot.getAmount() + stack.getAmount();
|
||||||
|
|
||||||
if (amount > is.getType().getMaxStackSize()) {
|
if (amount > maxStackSize) {
|
||||||
is.setAmount(is.getType().getMaxStackSize());
|
stack.setAmount(amount - maxStackSize);
|
||||||
stack.setAmount(amount - is.getType().getMaxStackSize());
|
}
|
||||||
} else {
|
else {
|
||||||
is.setAmount(amount);
|
|
||||||
stack = null;
|
stack = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
inv.setItem(slot, is);
|
itemInSlot.setAmount(Math.min(amount, maxStackSize));
|
||||||
|
inv.setItem(slot, itemInSlot);
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,6 +251,8 @@ final class CargoUtils {
|
|||||||
if (blockInfo.getString("id").equals("CARGO_NODE_OUTPUT")) return true;
|
if (blockInfo.getString("id").equals("CARGO_NODE_OUTPUT")) return true;
|
||||||
|
|
||||||
BlockMenu menu = BlockStorage.getInventory(block.getLocation());
|
BlockMenu menu = BlockStorage.getInventory(block.getLocation());
|
||||||
|
if (menu == null) return false;
|
||||||
|
|
||||||
boolean lore = "true".equals(blockInfo.getString("filter-lore"));
|
boolean lore = "true".equals(blockInfo.getString("filter-lore"));
|
||||||
|
|
||||||
if ("whitelist".equals(blockInfo.getString("filter-type"))) {
|
if ("whitelist".equals(blockInfo.getString("filter-type"))) {
|
||||||
@ -262,7 +260,9 @@ final class CargoUtils {
|
|||||||
|
|
||||||
for (int slot : SLOTS) {
|
for (int slot : SLOTS) {
|
||||||
ItemStack template = menu.getItemInSlot(slot);
|
ItemStack template = menu.getItemInSlot(slot);
|
||||||
if (template != null) items.add(new CustomItem(template, 1));
|
if (template != null) {
|
||||||
|
items.add(template);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
@ -289,7 +289,8 @@ final class CargoUtils {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (int slot : SLOTS) {
|
for (int slot : SLOTS) {
|
||||||
if (menu.getItemInSlot(slot) != null && SlimefunUtils.isItemSimilar(item, menu.getItemInSlot(slot), lore, false)) {
|
ItemStack itemInSlot = menu.getItemInSlot(slot);
|
||||||
|
if (itemInSlot != null && SlimefunUtils.isItemSimilar(item, itemInSlot, lore, false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user