mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Handle correct internal slot for swapping from inventory
This commit is contained in:
parent
6d577a3f4e
commit
f702fb45b4
10 changed files with 38 additions and 26 deletions
|
@ -26,10 +26,6 @@
|
|||
package org.geysermc.geyser.inventory;
|
||||
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class BedrockContainerSlot {
|
||||
ContainerSlotType container;
|
||||
int slot;
|
||||
public record BedrockContainerSlot(ContainerSlotType container, int slot) {
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import lombok.Getter;
|
|||
import lombok.NonNull;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
/**
|
||||
* Combination of {@link Inventory} and {@link PlayerInventory}
|
||||
|
@ -59,6 +60,11 @@ public class Container extends Inventory {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffsetForHotbar(@Range(from = 0, to = 8) int slot) {
|
||||
return playerInventory.getOffsetForHotbar(slot) - InventoryTranslator.PLAYER_INVENTORY_OFFSET + this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession session) {
|
||||
if (slot < this.size) {
|
||||
|
|
|
@ -36,11 +36,12 @@ import lombok.Setter;
|
|||
import lombok.ToString;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ToString
|
||||
public class Inventory {
|
||||
public abstract class Inventory {
|
||||
|
||||
@Getter
|
||||
protected final int id;
|
||||
|
@ -110,6 +111,8 @@ public class Inventory {
|
|||
return items[slot];
|
||||
}
|
||||
|
||||
public abstract int getOffsetForHotbar(@Range(from = 0, to = 8) int slot);
|
||||
|
||||
public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession session) {
|
||||
if (slot > this.size) {
|
||||
session.getGeyser().getLogger().debug("Tried to set an item out of bounds! " + this);
|
||||
|
|
|
@ -26,10 +26,12 @@
|
|||
package org.geysermc.geyser.inventory;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class PlayerInventory extends Inventory {
|
||||
/**
|
||||
|
@ -41,7 +43,7 @@ public class PlayerInventory extends Inventory {
|
|||
private int heldItemSlot;
|
||||
|
||||
@Getter
|
||||
@NonNull
|
||||
@Nonnull
|
||||
private GeyserItemStack cursor = GeyserItemStack.EMPTY;
|
||||
|
||||
public PlayerInventory() {
|
||||
|
@ -49,7 +51,12 @@ public class PlayerInventory extends Inventory {
|
|||
heldItemSlot = 0;
|
||||
}
|
||||
|
||||
public void setCursor(@NonNull GeyserItemStack newCursor, GeyserSession session) {
|
||||
@Override
|
||||
public int getOffsetForHotbar(@Range(from = 0, to = 8) int slot) {
|
||||
return slot + 36;
|
||||
}
|
||||
|
||||
public void setCursor(@Nonnull GeyserItemStack newCursor, GeyserSession session) {
|
||||
updateItemNetId(cursor, newCursor, session);
|
||||
cursor = newCursor;
|
||||
}
|
||||
|
@ -62,7 +69,7 @@ public class PlayerInventory extends Inventory {
|
|||
return items[36 + heldItemSlot];
|
||||
}
|
||||
|
||||
public void setItemInHand(@NonNull GeyserItemStack item) {
|
||||
public void setItemInHand(@Nonnull GeyserItemStack item) {
|
||||
if (36 + heldItemSlot > this.size) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Held item slot was larger than expected!");
|
||||
return;
|
||||
|
|
|
@ -234,31 +234,31 @@ public class ClickPlan {
|
|||
}
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_1:
|
||||
swap(action.slot, 36, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(0), clicked);
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_2:
|
||||
swap(action.slot, 37, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(1), clicked);
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_3:
|
||||
swap(action.slot, 38, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(2), clicked);
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_4:
|
||||
swap(action.slot, 39, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(3), clicked);
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_5:
|
||||
swap(action.slot, 40, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(4), clicked);
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_6:
|
||||
swap(action.slot, 41, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(5), clicked);
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_7:
|
||||
swap(action.slot, 42, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(6), clicked);
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_8:
|
||||
swap(action.slot, 43, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(7), clicked);
|
||||
break;
|
||||
case SWAP_TO_HOTBAR_9:
|
||||
swap(action.slot, 44, clicked);
|
||||
swap(action.slot, inventory.getOffsetForHotbar(8), clicked);
|
||||
break;
|
||||
case LEFT_SHIFT:
|
||||
//TODO
|
||||
|
|
|
@ -104,7 +104,7 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
protected boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
return action.getType() == StackRequestActionType.BEACON_PAYMENT;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
protected boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
return action.getType() == StackRequestActionType.CRAFT_RECIPE;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ public abstract class InventoryTranslator {
|
|||
* Should be overrided if this request matches a certain criteria and shouldn't be treated normally.
|
||||
* E.G. anvil renaming or enchanting
|
||||
*/
|
||||
public boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
protected boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -864,8 +864,8 @@ public abstract class InventoryTranslator {
|
|||
Map<ContainerSlotType, List<ItemStackResponsePacket.ItemEntry>> containerMap = new HashMap<>();
|
||||
for (int slot : affectedSlots) {
|
||||
BedrockContainerSlot bedrockSlot = javaSlotToBedrockContainer(slot);
|
||||
List<ItemStackResponsePacket.ItemEntry> list = containerMap.computeIfAbsent(bedrockSlot.getContainer(), k -> new ArrayList<>());
|
||||
list.add(makeItemEntry(session, bedrockSlot.getSlot(), inventory.getItem(slot)));
|
||||
List<ItemStackResponsePacket.ItemEntry> list = containerMap.computeIfAbsent(bedrockSlot.container(), k -> new ArrayList<>());
|
||||
list.add(makeItemEntry(session, bedrockSlot.slot(), inventory.getItem(slot)));
|
||||
}
|
||||
|
||||
List<ItemStackResponsePacket.ContainerEntry> containerEntries = new ArrayList<>();
|
||||
|
|
|
@ -117,7 +117,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
protected boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
// If the LOOM_MATERIAL slot is not empty, we are crafting a pattern that does not come from an item
|
||||
// Remove the CRAFT_NON_IMPLEMENTED_DEPRECATED when 1.17.30 is dropped
|
||||
return (action.getType() == StackRequestActionType.CRAFT_NON_IMPLEMENTED_DEPRECATED || action.getType() == StackRequestActionType.CRAFT_LOOM)
|
||||
|
|
|
@ -52,7 +52,7 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
protected boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
|
||||
// First is pre-1.18. TODO remove after 1.17.40 support is dropped and refactor stonecutter support to use CraftRecipeStackRequestActionData's recipe ID
|
||||
return action.getType() == StackRequestActionType.CRAFT_NON_IMPLEMENTED_DEPRECATED || action.getType() == StackRequestActionType.CRAFT_RECIPE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue