use of me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu in project FluffyMachines by NCBPFluffyBear.
the class AutoCrafter method constructMenu.
private void constructMenu(String displayName) {
new BlockMenuPreset(getId(), displayName) {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(@Nonnull BlockMenu menu, @Nonnull Block b) {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "enabled") == null || BlockStorage.getLocationInfo(b.getLocation(), "enabled").equals(String.valueOf(false))) {
menu.replaceExistingItem(6, new CustomItemStack(Material.GUNPOWDER, "&7Enabled: &4\u2718", "", "&e> Click to enable this Machine"));
menu.addMenuClickHandler(6, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "enabled", String.valueOf(true));
newInstance(menu, b);
return false;
});
} else {
menu.replaceExistingItem(6, new CustomItemStack(Material.REDSTONE, "&7Enabled: &2\u2714", "", "&e> Click to disable this Machine"));
menu.addMenuClickHandler(6, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "enabled", String.valueOf(false));
newInstance(menu, b);
return false;
});
}
}
@Override
public boolean canOpen(@Nonnull Block b, @Nonnull Player p) {
return p.hasPermission("slimefun.inventory.bypass") || Slimefun.getProtectionManager().hasPermission(p, b.getLocation(), Interaction.INTERACT_BLOCK);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
@Override
public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportFlow flow, ItemStack item) {
return getCustomItemTransport(menu, flow, item);
}
};
}
use of me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu in project Slimefun4 by Slimefun.
the class CargoUtils method withdraw.
@Nullable
static ItemStack withdraw(AbstractItemNetwork network, Map<Location, Inventory> inventories, Block node, Block target, ItemStack template) {
DirtyChestMenu menu = getChestMenu(target);
if (menu == null) {
if (hasInventory(target)) {
Inventory inventory = inventories.get(target.getLocation());
if (inventory != null) {
return withdrawFromVanillaInventory(network, node, template, inventory);
}
BlockState state = PaperLib.getBlockState(target, false).getState();
if (state instanceof InventoryHolder) {
inventory = ((InventoryHolder) state).getInventory();
inventories.put(target.getLocation(), inventory);
return withdrawFromVanillaInventory(network, node, template, inventory);
}
}
return null;
}
ItemStackWrapper wrapperTemplate = ItemStackWrapper.wrap(template);
for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) {
ItemStack is = menu.getItemInSlot(slot);
ItemStackWrapper wrapperItemInSlot = ItemStackWrapper.wrap(is);
if (SlimefunUtils.isItemSimilar(wrapperItemInSlot, wrapperTemplate, true) && matchesFilter(network, node, wrapperItemInSlot)) {
if (is.getAmount() > template.getAmount()) {
is.setAmount(is.getAmount() - template.getAmount());
menu.replaceExistingItem(slot, is);
return template;
} else {
menu.replaceExistingItem(slot, null);
return is;
}
}
}
return null;
}
use of me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu in project Slimefun4 by Slimefun.
the class CargoUtils method insert.
@Nullable
static ItemStack insert(AbstractItemNetwork network, Map<Location, Inventory> inventories, Block node, Block target, boolean smartFill, ItemStack stack, ItemStackWrapper wrapper) {
Debug.log(TestCase.CARGO_INPUT_TESTING, "CargoUtils#insert");
if (!matchesFilter(network, node, stack)) {
return stack;
}
DirtyChestMenu menu = getChestMenu(target);
if (menu == null) {
if (hasInventory(target)) {
Inventory inventory = inventories.get(target.getLocation());
if (inventory != null) {
return insertIntoVanillaInventory(stack, wrapper, smartFill, inventory);
}
BlockState state = PaperLib.getBlockState(target, false).getState();
if (state instanceof InventoryHolder) {
inventory = ((InventoryHolder) state).getInventory();
inventories.put(target.getLocation(), inventory);
return insertIntoVanillaInventory(stack, wrapper, smartFill, inventory);
}
}
return stack;
}
for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.INSERT, wrapper)) {
ItemStack itemInSlot = menu.getItemInSlot(slot);
if (itemInSlot == null) {
menu.replaceExistingItem(slot, stack);
return null;
}
int maxStackSize = itemInSlot.getType().getMaxStackSize();
int currentAmount = itemInSlot.getAmount();
if (!smartFill && currentAmount == maxStackSize) {
// Skip full stacks - Performance optimization for non-smartfill nodes
continue;
}
if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false)) {
if (currentAmount < maxStackSize) {
int amount = currentAmount + stack.getAmount();
itemInSlot.setAmount(Math.min(amount, maxStackSize));
if (amount > maxStackSize) {
stack.setAmount(amount - maxStackSize);
} else {
stack = null;
}
menu.replaceExistingItem(slot, itemInSlot);
return stack;
} else if (smartFill) {
return stack;
}
}
}
return stack;
}
Aggregations