3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Re-enable crafter inventory

Dieser Commit ist enthalten in:
Camotoy 2024-06-14 19:36:10 -04:00
Ursprung 7e87af718b
Commit be83fe7220
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
5 geänderte Dateien mit 43 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -38,7 +38,7 @@ import org.jetbrains.annotations.Range;
*/ */
@Getter @Getter
public class Container extends Inventory { public class Container extends Inventory {
private final PlayerInventory playerInventory; protected final PlayerInventory playerInventory;
private final int containerSize; private final int containerSize;
/** /**

Datei anzeigen

@ -25,13 +25,19 @@
package org.geysermc.geyser.inventory; 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 org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.jetbrains.annotations.Range;
@Getter @Getter
public class CrafterContainer extends Container { public class CrafterContainer extends Container {
private GeyserItemStack resultItem = GeyserItemStack.EMPTY;
@Setter @Setter
private boolean triggered = false; private boolean triggered = false;
@ -46,8 +52,36 @@ public class CrafterContainer extends Container {
super(title, id, size, containerType, playerInventory); 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) { 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); GeyserImpl.getInstance().getLogger().warning("Crafter slot out of bounds: " + slot);
return; return;
} }
@ -58,4 +92,8 @@ public class CrafterContainer extends Container {
disabledSlotsMask = (short) (disabledSlotsMask | (1 << slot)); disabledSlotsMask = (short) (disabledSlotsMask | (1 << slot));
} }
} }
private static boolean isCraftingGrid(int slot) {
return slot >= 0 && slot <= 8;
}
} }

Datei anzeigen

@ -86,7 +86,7 @@ public abstract class InventoryTranslator {
put(ContainerType.BEACON, new BeaconInventoryTranslator()); put(ContainerType.BEACON, new BeaconInventoryTranslator());
put(ContainerType.BREWING_STAND, new BrewingInventoryTranslator()); put(ContainerType.BREWING_STAND, new BrewingInventoryTranslator());
put(ContainerType.CARTOGRAPHY, new CartographyInventoryTranslator()); 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.CRAFTING, new CraftingInventoryTranslator());
put(ContainerType.ENCHANTMENT, new EnchantingInventoryTranslator()); put(ContainerType.ENCHANTMENT, new EnchantingInventoryTranslator());
put(ContainerType.HOPPER, new HopperInventoryTranslator()); put(ContainerType.HOPPER, new HopperInventoryTranslator());

Datei anzeigen

@ -25,8 +25,6 @@
package org.geysermc.geyser.translator.protocol.java.inventory; 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.GeyserLogger;
import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.inventory.Inventory; 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.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.InventoryUtils; import org.geysermc.geyser.util.InventoryUtils;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetContentPacket;
@Translator(packet = ClientboundContainerSetContentPacket.class) @Translator(packet = ClientboundContainerSetContentPacket.class)
public class JavaContainerSetContentTranslator extends PacketTranslator<ClientboundContainerSetContentPacket> { public class JavaContainerSetContentTranslator extends PacketTranslator<ClientboundContainerSetContentPacket> {

@ -1 +1 @@
Subproject commit 5f892d04d2212a13fad3f517b3f516d6526833f2 Subproject commit 2ac0c1415cb9063c405dbd7e14f2d426a0ba1180