mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-18 21:20:24 -07:00
Add a method on InventoryView to get the MenuType (#12193)
Since there is a new (better) way to create views for players using MenuType, it would be nice to also be able to get it back from InventoryView after creating.
This commit is contained in:
parent
0e9b94d533
commit
835b955913
@ -512,6 +512,7 @@ public net.minecraft.world.flag.FeatureFlagRegistry names
|
||||
public net.minecraft.world.food.FoodData exhaustionLevel
|
||||
public net.minecraft.world.food.FoodData foodLevel
|
||||
public net.minecraft.world.food.FoodData saturationLevel
|
||||
public net.minecraft.world.inventory.AbstractContainerMenu menuType
|
||||
public net.minecraft.world.inventory.AbstractContainerMenu quickcraftSlots
|
||||
public net.minecraft.world.inventory.AbstractContainerMenu quickcraftStatus
|
||||
public net.minecraft.world.inventory.AbstractContainerMenu quickcraftType
|
||||
|
@ -2,6 +2,7 @@ package org.bukkit.inventory;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -321,4 +322,16 @@ public interface InventoryView {
|
||||
*/
|
||||
@Deprecated(since = "1.21.1") // Paper
|
||||
public void setTitle(@NotNull String title);
|
||||
|
||||
/**
|
||||
* Gets the menu type of the inventory view if applicable.
|
||||
* <p>
|
||||
* Some inventory types do not support a menu type. In such cases, this method
|
||||
* returns null. This typically applies to inventories belonging to entities
|
||||
* like players or animals (e.g., a horse).
|
||||
*
|
||||
* @return the menu type of the inventory view or null if not applicable
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@Nullable MenuType getMenuType();
|
||||
}
|
||||
|
@ -95,6 +95,11 @@ public class CraftContainer extends AbstractContainerMenu {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuType getMenuType() {
|
||||
return CraftMenuType.minecraftToBukkit(getNotchInventoryType(inventory));
|
||||
}
|
||||
|
||||
}, player, id);
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,12 @@ public class CraftInventoryView<T extends AbstractContainerMenu, I extends Inven
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.MenuType getMenuType() {
|
||||
MenuType<?> menuType = container.menuType;
|
||||
return menuType != null ? CraftMenuType.minecraftToBukkit(menuType) : null;
|
||||
}
|
||||
|
||||
public boolean isInTop(int rawSlot) {
|
||||
return rawSlot < this.viewing.getSize();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user