Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-04 23:30:17 +01:00
Re-enable crafter inventory
Dieser Commit ist enthalten in:
Ursprung
7e87af718b
Commit
be83fe7220
@ -38,7 +38,7 @@ import org.jetbrains.annotations.Range;
|
||||
*/
|
||||
@Getter
|
||||
public class Container extends Inventory {
|
||||
private final PlayerInventory playerInventory;
|
||||
protected final PlayerInventory playerInventory;
|
||||
private final int containerSize;
|
||||
|
||||
/**
|
||||
|
@ -25,13 +25,19 @@
|
||||
|
||||
package org.geysermc.geyser.inventory;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.inventory.CrafterInventoryTranslator;
|
||||
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
@Getter
|
||||
public class CrafterContainer extends Container {
|
||||
private GeyserItemStack resultItem = GeyserItemStack.EMPTY;
|
||||
|
||||
@Setter
|
||||
private boolean triggered = false;
|
||||
@ -46,8 +52,36 @@ public class CrafterContainer extends Container {
|
||||
super(title, id, size, containerType, playerInventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeyserItemStack getItem(int slot) {
|
||||
if (slot == CrafterInventoryTranslator.JAVA_RESULT_SLOT) {
|
||||
return this.resultItem;
|
||||
} else if (isCraftingGrid(slot)) {
|
||||
return super.getItem(slot);
|
||||
} else {
|
||||
return playerInventory.getItem(slot - CrafterInventoryTranslator.GRID_SIZE + InventoryTranslator.PLAYER_INVENTORY_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffsetForHotbar(@Range(from = 0, to = 8) int slot) {
|
||||
return playerInventory.getOffsetForHotbar(slot) - InventoryTranslator.PLAYER_INVENTORY_OFFSET + CrafterInventoryTranslator.GRID_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession session) {
|
||||
if (slot == CrafterInventoryTranslator.JAVA_RESULT_SLOT) {
|
||||
// Result item probably won't be an item that needs to worry about net ID or lodestone compasses
|
||||
this.resultItem = newItem;
|
||||
} else if (isCraftingGrid(slot)) {
|
||||
super.setItem(slot, newItem, session);
|
||||
} else {
|
||||
playerInventory.setItem(slot - CrafterInventoryTranslator.GRID_SIZE + InventoryTranslator.PLAYER_INVENTORY_OFFSET, newItem, session);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSlot(int slot, boolean enabled) {
|
||||
if (slot < 0 || slot > 8) {
|
||||
if (!isCraftingGrid(slot)) {
|
||||
GeyserImpl.getInstance().getLogger().warning("Crafter slot out of bounds: " + slot);
|
||||
return;
|
||||
}
|
||||
@ -58,4 +92,8 @@ public class CrafterContainer extends Container {
|
||||
disabledSlotsMask = (short) (disabledSlotsMask | (1 << slot));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCraftingGrid(int slot) {
|
||||
return slot >= 0 && slot <= 8;
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public abstract class InventoryTranslator {
|
||||
put(ContainerType.BEACON, new BeaconInventoryTranslator());
|
||||
put(ContainerType.BREWING_STAND, new BrewingInventoryTranslator());
|
||||
put(ContainerType.CARTOGRAPHY, new CartographyInventoryTranslator());
|
||||
//put(ContainerType.CRAFTER_3x3, new CrafterInventoryTranslator()); todo Output slot is currently broken
|
||||
put(ContainerType.CRAFTER_3x3, new CrafterInventoryTranslator());
|
||||
put(ContainerType.CRAFTING, new CraftingInventoryTranslator());
|
||||
put(ContainerType.ENCHANTMENT, new EnchantingInventoryTranslator());
|
||||
put(ContainerType.HOPPER, new HopperInventoryTranslator());
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package org.geysermc.geyser.translator.protocol.java.inventory;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetContentPacket;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.GeyserLogger;
|
||||
import org.geysermc.geyser.inventory.GeyserItemStack;
|
||||
import org.geysermc.geyser.inventory.Inventory;
|
||||
@ -36,6 +34,7 @@ import org.geysermc.geyser.translator.inventory.PlayerInventoryTranslator;
|
||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||
import org.geysermc.geyser.translator.protocol.Translator;
|
||||
import org.geysermc.geyser.util.InventoryUtils;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetContentPacket;
|
||||
|
||||
@Translator(packet = ClientboundContainerSetContentPacket.class)
|
||||
public class JavaContainerSetContentTranslator extends PacketTranslator<ClientboundContainerSetContentPacket> {
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 5f892d04d2212a13fad3f517b3f516d6526833f2
|
||||
Subproject commit 2ac0c1415cb9063c405dbd7e14f2d426a0ba1180
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren