Skip to content
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 @@ -162,7 +162,7 @@ public interface EntityEquipment {
*
* <p>
* This returns a copy if this equipment instance is from a non-player.
* For stacks from players, this returns a live mirror (or null). You can check if this
* For items from players, this returns a live mirror. You can check if this
* will return a mirror with
* <pre>{@code
* EntityEquipment equipment = entity.getEquipment();
Expand All @@ -175,8 +175,7 @@ public interface EntityEquipment {
*
* @return The helmet being worn
*/
@org.bukkit.UndefinedNullability("not null for entities, nullable for players") // Paper
ItemStack getHelmet();
@NotNull ItemStack getHelmet();

/**
* Sets the helmet worn by the entity
Expand All @@ -198,7 +197,7 @@ public interface EntityEquipment {
*
* <p>
* This returns a copy if this equipment instance is from a non-player.
* For stacks from players, this returns a live mirror (or null). You can check if this
* For items from players, this returns a live mirror. You can check if this
* will return a mirror with
* <pre>{@code
* EntityEquipment equipment = entity.getEquipment();
Expand All @@ -211,8 +210,7 @@ public interface EntityEquipment {
*
* @return The chest plate being worn
*/
@org.bukkit.UndefinedNullability("not null for entities, nullable for players") // Paper
ItemStack getChestplate();
@NotNull ItemStack getChestplate();

/**
* Sets the chest plate worn by the entity
Expand All @@ -234,7 +232,7 @@ public interface EntityEquipment {
*
* <p>
* This returns a copy if this equipment instance is from a non-player.
* For stacks from players, this returns a live mirror (or null). You can check if this
* For items from players, this returns a live mirror. You can check if this
* will return a mirror with
* <pre>{@code
* EntityEquipment equipment = entity.getEquipment();
Expand All @@ -247,8 +245,7 @@ public interface EntityEquipment {
*
* @return The leggings being worn
*/
@org.bukkit.UndefinedNullability("not null for entities, nullable for players") // Paper
ItemStack getLeggings();
@NotNull ItemStack getLeggings();

/**
* Sets the leggings worn by the entity
Expand All @@ -270,7 +267,7 @@ public interface EntityEquipment {
*
* <p>
* This returns a copy if this equipment instance is from a non-player.
* For stacks from players, this returns a live mirror (or null). You can check if this
* For items from players, this returns a live mirror. You can check if this
* will return a mirror with
* <pre>{@code
* EntityEquipment equipment = entity.getEquipment();
Expand All @@ -283,8 +280,7 @@ public interface EntityEquipment {
*
* @return The boots being worn
*/
@org.bukkit.UndefinedNullability("not null for entities, nullable for players") // Paper
ItemStack getBoots();
@NotNull ItemStack getBoots();

/**
* Sets the boots worn by the entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,28 @@ public interface PlayerInventory extends Inventory {
*
* @return The ItemStack in the helmet slot
*/
@Nullable
public ItemStack getHelmet();
public @NotNull ItemStack getHelmet();

/**
* Return the ItemStack from the chestplate slot
*
* @return The ItemStack in the chestplate slot
*/
@Nullable
public ItemStack getChestplate();
public @NotNull ItemStack getChestplate();

/**
* Return the ItemStack from the leg slot
*
* @return The ItemStack in the leg slot
*/
@Nullable
public ItemStack getLeggings();
public @NotNull ItemStack getLeggings();

/**
* Return the ItemStack from the boots slot
*
* @return The ItemStack in the boots slot
*/
@Nullable
public ItemStack getBoots();
public @NotNull ItemStack getBoots();

/**
* Stores the ItemStack at the given index of the inventory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,10 @@ public Inventory getInventory(final int rawSlot) {
}
Preconditions.checkArgument(rawSlot >= 0, "Negative, non outside slot %s", rawSlot);
Preconditions.checkArgument(rawSlot < this.countSlots(), "Slot %s greater than inventory slot count", rawSlot);
return this.mapValidSlotToInventory(rawSlot);
}

// Paper start - Fix crafter slot ID conversions
if (this.getType() == InventoryType.CRAFTER) {
// Raw slot ID for crafter inventory views is 45 for result slot and 0-8 for crafting grid slots.
// Crafter inventory size is 10. Only check 0-8 and 45.
if (rawSlot < (this.getTopInventory().getSize() - 1) || rawSlot == 45) {
return this.getTopInventory();
} else {
return this.getBottomInventory();
}
}
// Paper end - Fix crafter slot ID conversions

public Inventory mapValidSlotToInventory(final int rawSlot) {
if (rawSlot < this.getTopInventory().getSize()) {
return this.getTopInventory();
} else {
Expand All @@ -74,43 +65,6 @@ public Inventory getInventory(final int rawSlot) {

@Override
public int convertSlot(final int rawSlot) {
// Paper start - Fix crafter slot ID conversions
// Crafter inventory size is 10, but the view uses non-contiguous raw slot IDs 0-8 (grid) and 45 (result).
// The numInTop check and slot number shift lower in this method assume contiguous slot IDs.
if (this.getType() == InventoryType.CRAFTER) {
/*
* Raw Slots:
*
* 0 1 2
* 3 4 5 45
* 6 7 8
* 9 10 11 12 13 14 15 16 17
* 18 19 20 21 22 23 24 25 26
* 27 28 29 30 31 32 33 34 35
* 36 37 38 39 40 41 42 43 44
*/

/*
* Converted Slots:
*
* 0 1 2
* 3 4 5 9
* 6 7 8
* 9 10 11 12 13 14 15 16 17
* 18 19 20 21 22 23 24 25 26
* 27 28 29 30 31 32 33 34 35
* 0 1 2 3 4 5 6 7 8
*/
if (rawSlot == 45) {
return 9; // Result
} else if (rawSlot >= 36) {
return rawSlot - 36; // Quickbar
} else {
return rawSlot; // Crafting grid or player inventory
}
}
// Paper end - Fix crafter slot ID conversions

int numInTop = this.getTopInventory().getSize();
// Index from the top inventory as having slots from [0,size]
if (rawSlot < numInTop) {
Expand Down Expand Up @@ -178,18 +132,7 @@ public int convertSlot(final int rawSlot) {
@Override
public InventoryType.SlotType getSlotType(final int slot) {
InventoryType.SlotType type = InventoryType.SlotType.CONTAINER;
// Paper start - Fix crafter slot ID conversions
if (this.getType() == InventoryType.CRAFTER) {
// Crafter inventory size is 10, but the view uses non-contiguous raw slot IDs 0-8 (grid) and 45 (result).
if (slot < 0) {
type = InventoryType.SlotType.OUTSIDE;
} else if (slot == 45) {
type = InventoryType.SlotType.RESULT;
} else if (slot > 35) {
type = InventoryType.SlotType.QUICKBAR;
}
} else if (slot >= 0 && slot < this.getTopInventory().getSize()) {
// Paper end - Fix crafter slot ID conversions
if (slot >= 0 && slot < this.getTopInventory().getSize()) {
switch (this.getType()) {
case BLAST_FURNACE:
case FURNACE:
Expand Down Expand Up @@ -261,6 +204,12 @@ public InventoryType.SlotType getSlotType(final int slot) {
} else if (slot > 35) {
type = InventoryType.SlotType.QUICKBAR;
}
} else if (this.getType() == InventoryType.CRAFTER) {
if (slot == 45) {
type = InventoryType.SlotType.RESULT;
} else if (slot > 35) {
type = InventoryType.SlotType.QUICKBAR;
}
} else if (slot >= (this.countSlots() - (9 + 4 + 1))) { // Quickbar, Armor, Offhand
type = InventoryType.SlotType.QUICKBAR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.CrafterInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.view.CrafterView;

public class CraftCrafterView extends CraftInventoryView<CrafterMenu, CrafterInventory> implements CrafterView {
Expand All @@ -23,6 +24,53 @@ public boolean isPowered() {
return this.container.isPowered();
}

@Override
public int convertSlot(final int rawSlot) {
// Crafter inventory size is 10, but the view uses non-contiguous raw slot IDs 0-8 (grid) and 45 (result).
// The numInTop check and slot number shift lower in this method assume contiguous slot IDs.
/*
* Raw Slots:
*
* 0 1 2
* 3 4 5 45
* 6 7 8
* 9 10 11 12 13 14 15 16 17
* 18 19 20 21 22 23 24 25 26
* 27 28 29 30 31 32 33 34 35
* 36 37 38 39 40 41 42 43 44
*/

/*
* Converted Slots:
*
* 0 1 2
* 3 4 5 9
* 6 7 8
* 9 10 11 12 13 14 15 16 17
* 18 19 20 21 22 23 24 25 26
* 27 28 29 30 31 32 33 34 35
* 0 1 2 3 4 5 6 7 8
*/
if (rawSlot == 45) {
return 9; // Result
} else if (rawSlot >= 36) {
return rawSlot - 36; // Quickbar
} else {
return rawSlot; // Crafting grid or player inventory
}
}

@Override
public Inventory mapValidSlotToInventory(final int rawSlot) {
// Raw slot ID for crafter inventory views is 45 for result slot and 0-8 for crafting grid slots.
// Crafter inventory size is 10. Only check 0-8 and 45.
if (rawSlot < (this.getTopInventory().getSize() - 1) || rawSlot == 45) {
return this.getTopInventory();
} else {
return this.getBottomInventory();
}
}

@Override
public void setSlotDisabled(final int slot, final boolean disabled) {
Preconditions.checkArgument(slot >= 0 && slot < 9, "Invalid slot index %s for Crafter", slot);
Expand Down
Loading