From 74a5bc8ac5f043709d9ebc4e28f9f4d2331a5216 Mon Sep 17 00:00:00 2001 From: balugaq <129668183+balugaq@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:17:58 +0800 Subject: [PATCH 1/2] Update NetworkBlueprintDecoder.java --- .../advanced/NetworkBlueprintDecoder.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/com/ytdd9527/networksexpansion/implementation/machines/networks/advanced/NetworkBlueprintDecoder.java b/src/main/java/com/ytdd9527/networksexpansion/implementation/machines/networks/advanced/NetworkBlueprintDecoder.java index 0c9fc9ed..e2f8df3a 100644 --- a/src/main/java/com/ytdd9527/networksexpansion/implementation/machines/networks/advanced/NetworkBlueprintDecoder.java +++ b/src/main/java/com/ytdd9527/networksexpansion/implementation/machines/networks/advanced/NetworkBlueprintDecoder.java @@ -2,6 +2,7 @@ import com.balugaq.netex.api.helpers.Icon; import com.balugaq.netex.utils.BlockMenuUtil; +import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils; import com.ytdd9527.networksexpansion.core.items.unusable.AbstractBlueprint; import com.ytdd9527.networksexpansion.implementation.ExpansionItems; import io.github.sefiraat.networks.Networks; @@ -15,6 +16,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; @@ -24,10 +26,12 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import javax.annotation.Nonnull; +import java.util.List; import java.util.Map; public class NetworkBlueprintDecoder extends NetworkObject { @@ -56,6 +60,30 @@ public static int getDecodeSlot() { return DECODE_SLOT; } + @Override + public void preRegister() { + addItemHandler(new BlockBreakHandler(false, false) { + @Override + public void onPlayerBreak(@Nonnull BlockBreakEvent blockBreakEvent, @Nonnull ItemStack itemStack, @Nonnull List list) { + BlockMenu blockMenu = StorageCacheUtils.getMenu(blockBreakEvent.getBlock().getLocation()); + if (blockMenu == null) { + return; + } + + for (int slot : getOutputSlots()) { + ItemStack item = blockMenu.getItemInSlot(slot); + if (item != null && item.getType()!= Material.AIR) { + blockMenu.getLocation().getWorld().dropItemNaturally(blockMenu.getLocation(), item); + } + } + + ItemStack input = blockMenu.getItemInSlot(getInputSlot()); + if (input != null && input.getType()!= Material.AIR) { + blockMenu.getLocation().getWorld().dropItemNaturally(blockMenu.getLocation(), input); + } + } + }); + } @Override public void postRegister() { new BlockMenuPreset(this.getId(), this.getItemName()) { From 8881ea62df93885030d6f0ed3adee5c7d550a421 Mon Sep 17 00:00:00 2001 From: balugaq <129668183+balugaq@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:18:31 +0800 Subject: [PATCH 2/2] spotless --- .../machines/networks/advanced/NetworkBlueprintDecoder.java | 5 +++-- .../networksexpansion/utils/itemstacks/ItemStackUtil.java | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ytdd9527/networksexpansion/implementation/machines/networks/advanced/NetworkBlueprintDecoder.java b/src/main/java/com/ytdd9527/networksexpansion/implementation/machines/networks/advanced/NetworkBlueprintDecoder.java index e2f8df3a..c1c42045 100644 --- a/src/main/java/com/ytdd9527/networksexpansion/implementation/machines/networks/advanced/NetworkBlueprintDecoder.java +++ b/src/main/java/com/ytdd9527/networksexpansion/implementation/machines/networks/advanced/NetworkBlueprintDecoder.java @@ -72,18 +72,19 @@ public void onPlayerBreak(@Nonnull BlockBreakEvent blockBreakEvent, @Nonnull Ite for (int slot : getOutputSlots()) { ItemStack item = blockMenu.getItemInSlot(slot); - if (item != null && item.getType()!= Material.AIR) { + if (item != null && item.getType() != Material.AIR) { blockMenu.getLocation().getWorld().dropItemNaturally(blockMenu.getLocation(), item); } } ItemStack input = blockMenu.getItemInSlot(getInputSlot()); - if (input != null && input.getType()!= Material.AIR) { + if (input != null && input.getType() != Material.AIR) { blockMenu.getLocation().getWorld().dropItemNaturally(blockMenu.getLocation(), input); } } }); } + @Override public void postRegister() { new BlockMenuPreset(this.getId(), this.getItemName()) { diff --git a/src/main/java/com/ytdd9527/networksexpansion/utils/itemstacks/ItemStackUtil.java b/src/main/java/com/ytdd9527/networksexpansion/utils/itemstacks/ItemStackUtil.java index a151ffe1..c60b795e 100644 --- a/src/main/java/com/ytdd9527/networksexpansion/utils/itemstacks/ItemStackUtil.java +++ b/src/main/java/com/ytdd9527/networksexpansion/utils/itemstacks/ItemStackUtil.java @@ -4,7 +4,6 @@ import com.balugaq.netex.api.data.ItemWrapper; import com.balugaq.netex.utils.NetworksVersionedEnchantment; import io.github.sefiraat.networks.utils.StackUtils; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.nms.ItemNameAdapter; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;