Skip to content

Commit

Permalink
Merge from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Dec 22, 2024
2 parents 5715c91 + 74e6bc1 commit e49747c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.androids;

import city.norain.slimefun4.api.menu.UniversalMenu;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;

Expand Down Expand Up @@ -71,15 +72,15 @@ public enum Instruction {
*/
TURN_LEFT(AndroidType.NONE, HeadTexture.SCRIPT_LEFT, (android, b, inv, face) -> {
int mod = -1;
ProgrammableAndroid.rotate(b, face, mod);
android.rotate(b, StorageCacheUtils.getUniversalBlock(inv.getUuid()), face, mod);
}),

/**
* This will make the {@link ProgrammableAndroid} rotate to the right side.
*/
TURN_RIGHT(AndroidType.NONE, HeadTexture.SCRIPT_RIGHT, (android, b, inv, face) -> {
int mod = 1;
ProgrammableAndroid.rotate(b, face, mod);
android.rotate(b, StorageCacheUtils.getUniversalBlock(inv.getUuid()), face, mod);
}),

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ private void executeInstruction(
}
}

protected static void rotate(Block b, BlockFace current, int mod) {
protected void rotate(Block b, SlimefunUniversalBlockData uniData, BlockFace current, int mod) {
int index = POSSIBLE_ROTATIONS.indexOf(current) + mod;

if (index == POSSIBLE_ROTATIONS.size()) {
Expand All @@ -819,7 +819,7 @@ protected static void rotate(Block b, BlockFace current, int mod) {
}
}));

StorageCacheUtils.setData(b.getLocation(), "rotation", rotation.name());
uniData.setData("rotation", rotation.name());
}

protected void depositItems(UniversalMenu menu, Block facedBlock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import java.util.*;
import javax.annotation.Nullable;

import org.bukkit.Material;
Expand All @@ -25,7 +23,10 @@
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;

/**
* This {@link Listener} is responsible for all events centered around a {@link SlimefunBackpack}.
Expand Down Expand Up @@ -62,12 +63,12 @@ public void onClose(InventoryCloseEvent e) {
}

private void saveBackpackInv(PlayerBackpack bp) {
var snapshot = invSnapshot.remove(bp.getUniqueId());
List<Pair<ItemStack, Integer>> snapshot = invSnapshot.remove(bp.getUniqueId());
if (snapshot == null) {
return;
}

var changed =
Set<Integer> changed =
InvStorageUtils.getChangedSlots(snapshot, bp.getInventory().getContents());
if (changed.isEmpty()) {
return;
Expand All @@ -87,6 +88,24 @@ public void onItemDrop(PlayerDropItemEvent e) {
}
}

@EventHandler
public void onPlayerSwap(PlayerSwapHandItemsEvent e) {
Player player = e.getPlayer();
if (!backpacks.containsKey(player.getUniqueId())) {
return;
}

ItemStack item = player.getInventory().getItemInOffHand();
if (item.getType().isAir()) {
return;
}

SlimefunItem backpack = SlimefunItem.getByItem(item);
if (backpack instanceof SlimefunBackpack) {
e.setCancelled(true);
}
}

@EventHandler(ignoreCancelled = true)
public void onClick(InventoryClickEvent e) {
ItemStack item = backpacks.get(e.getWhoClicked().getUniqueId());
Expand Down Expand Up @@ -145,13 +164,13 @@ public void openBackpack(Player p, ItemStack item, SlimefunBackpack backpack) {
}

private void openBackpack(Player p, ItemStack item, PlayerProfile profile, int size) {
var meta = item.getItemMeta();
ItemMeta meta = item.getItemMeta();
if (PlayerBackpack.getBackpackUUID(meta).isEmpty()
&& PlayerBackpack.getBackpackID(meta).isEmpty()) {
// Create backpack
Slimefun.getLocalization().sendMessage(p, "backpack.set-name", true);
Slimefun.getChatCatcher().scheduleCatcher(p.getUniqueId(), name -> {
var pInv = p.getInventory();
PlayerInventory pInv = p.getInventory();
if (!item.equals(pInv.getItemInMainHand()) && !item.equals(pInv.getItemInOffHand())) {
Slimefun.getLocalization().sendMessage(p, "backpack.not-original-item", true);
return;
Expand Down

0 comments on commit e49747c

Please sign in to comment.