Skip to content

Walshy/mc 1.21 bundles #4299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import io.github.thebusybiscuit.slimefun4.implementation.listeners.BundlingListener;
import io.github.thebusybiscuit.slimefun4.storage.Storage;
import io.github.thebusybiscuit.slimefun4.storage.backend.legacy.LegacyStorage;

Expand Down Expand Up @@ -655,6 +656,7 @@ private void registerListeners() {
new PiglinListener(this);
new SmithingTableListener(this);
new JoinListener(this);
new BundlingListener(this);

// Item-specific Listeners
new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public boolean isItemAllowed(@Nonnull ItemStack item, @Nullable SlimefunItem ite
return false;
}

// Bundles aren't allowed either
if (SlimefunTag.BUNDLES.isTagged(item.getType())) {
return false;
}

return !(itemAsSlimefunItem instanceof SlimefunBackpack);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;

public class BundlingListener implements Listener {
public BundlingListener(@Nonnull Slimefun plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@EventHandler(ignoreCancelled = true)
public void onBundling(InventoryClickEvent event) {
ItemStack cursor = event.getCursor();
ItemStack slot = event.getCurrentItem();

if (slot == null || cursor.isEmpty()) {
return;
}

if (isBundle(cursor) && isBackpack(slot) || isBundle(slot) && isBackpack(cursor)) {
event.setCancelled(true);
}
}

@EventHandler(ignoreCancelled = true)
public void onCreativeBundle(InventoryClickEvent event) {
ItemStack cursor = event.getCursor();
ItemStack slot = event.getCurrentItem();

if (slot == null || cursor.isEmpty()) {
return;
}

if (isBundle(cursor) && isBackpack(slot) || isBundle(slot) && isBackpack(cursor)) {
event.setCancelled(true);
}
}

private boolean isBundle(ItemStack stack) {
return SlimefunTag.BUNDLES.isTagged(stack.getType());
}

private boolean isBackpack(ItemStack stack) {
if (stack.getType() != Material.PLAYER_HEAD) {
return false;
}

SlimefunItem backpack = SlimefunItem.getByItem(stack);
if (backpack == null) {
return false;
}

return backpack instanceof SlimefunBackpack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ public enum SlimefunTag implements Tag<Material> {
/**
* All tile entities.
*/
TILE_ENTITIES;
TILE_ENTITIES,

/**
* All bundles.
*/
BUNDLES;

/**
* Lookup table for tag names.
Expand Down
72 changes: 72 additions & 0 deletions src/main/resources/tags/bundles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"values": [
{
"id": "minecraft:bundle",
"required": false
},
{
"id": "minecraft:white_bundle",
"required": false
},
{
"id": "minecraft:orange_bundle",
"required": false
},
{
"id": "minecraft:magenta_bundle",
"required": false
},
{
"id": "minecraft:light_blue_bundle",
"required": false
},
{
"id": "minecraft:yellow_bundle",
"required": false
},
{
"id": "minecraft:lime_bundle",
"required": false
},
{
"id": "minecraft:pink_bundle",
"required": false
},
{
"id": "minecraft:gray_bundle",
"required": false
},
{
"id": "minecraft:light_gray_bundle",
"required": false
},
{
"id": "minecraft:cyan_bundle",
"required": false
},
{
"id": "minecraft:purple_bundle",
"required": false
},
{
"id": "minecraft:blue_bundle",
"required": false
},
{
"id": "minecraft:brown_bundle",
"required": false
},
{
"id": "minecraft:green_bundle",
"required": false
},
{
"id": "minecraft:red_bundle",
"required": false
},
{
"id": "minecraft:black_bundle",
"required": false
}
]
}