Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 16:40:14 +01:00
Initial crafting table support
Dieser Commit ist enthalten in:
Ursprung
f167ed2583
Commit
3b3e72d5c3
@ -32,7 +32,6 @@ import org.geysermc.connector.network.session.GeyserSession;
|
|||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||||
import org.geysermc.connector.utils.InventoryUtils;
|
|
||||||
|
|
||||||
@Translator(packet = ItemStackRequestPacket.class)
|
@Translator(packet = ItemStackRequestPacket.class)
|
||||||
public class BedrockItemStackRequestTranslator extends PacketTranslator<ItemStackRequestPacket> {
|
public class BedrockItemStackRequestTranslator extends PacketTranslator<ItemStackRequestPacket> {
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* @author GeyserMC
|
||||||
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geysermc.connector.network.translators.inventory;
|
||||||
|
|
||||||
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData;
|
||||||
|
import org.geysermc.connector.inventory.Inventory;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.network.translators.inventory.holder.BlockInventoryHolder;
|
||||||
|
import org.geysermc.connector.network.translators.inventory.holder.InventoryHolder;
|
||||||
|
import org.geysermc.connector.network.translators.inventory.updater.ContainerInventoryUpdater;
|
||||||
|
import org.geysermc.connector.network.translators.inventory.updater.InventoryUpdater;
|
||||||
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||||
|
|
||||||
|
public class CraftingInventoryTranslator extends BaseInventoryTranslator {
|
||||||
|
private final InventoryHolder holder;
|
||||||
|
private final InventoryUpdater updater;
|
||||||
|
|
||||||
|
CraftingInventoryTranslator() {
|
||||||
|
super(10);
|
||||||
|
int javaBlockState = BlockTranslator.getJavaBlockState("minecraft:crafting_table");
|
||||||
|
this.holder = new BlockInventoryHolder(BlockTranslator.getBedrockBlockId(javaBlockState), ContainerType.WORKBENCH);
|
||||||
|
this.updater = new ContainerInventoryUpdater();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
||||||
|
holder.prepareInventory(this, session, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openInventory(GeyserSession session, Inventory inventory) {
|
||||||
|
holder.openInventory(this, session, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeInventory(GeyserSession session, Inventory inventory) {
|
||||||
|
holder.closeInventory(this, session, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateInventory(GeyserSession session, Inventory inventory) {
|
||||||
|
updater.updateInventory(this, session, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSlot(GeyserSession session, Inventory inventory, int slot) {
|
||||||
|
updater.updateSlot(this, session, inventory, slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SlotType getSlotType(int javaSlot) {
|
||||||
|
if (javaSlot == 0)
|
||||||
|
return SlotType.OUTPUT;
|
||||||
|
return SlotType.NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int javaSlotToBedrock(int slot) {
|
||||||
|
if (slot < size) {
|
||||||
|
return slot == 0 ? 50 : slot + 31;
|
||||||
|
}
|
||||||
|
return super.javaSlotToBedrock(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
|
||||||
|
if (slot >= 1 && slot <= 9) {
|
||||||
|
return new BedrockContainerSlot(ContainerSlotType.CRAFTING_INPUT, slot + 31);
|
||||||
|
}
|
||||||
|
if (slot == 0) {
|
||||||
|
return new BedrockContainerSlot(ContainerSlotType.CRAFTING_OUTPUT, 0);
|
||||||
|
}
|
||||||
|
return super.javaSlotToBedrockContainer(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
||||||
|
if (slotInfoData.getContainer() == ContainerSlotType.CRAFTING_INPUT) {
|
||||||
|
// Java goes from 1 - 9, left to right then up to down
|
||||||
|
// Bedrock is the same, but it starts from 32.
|
||||||
|
return slotInfoData.getSlot() - 31;
|
||||||
|
}
|
||||||
|
if (slotInfoData.getContainer() == ContainerSlotType.CRAFTING_OUTPUT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return super.bedrockSlotToJava(slotInfoData);
|
||||||
|
}
|
||||||
|
}
|
@ -58,9 +58,9 @@ public abstract class InventoryTranslator {
|
|||||||
put(WindowType.GENERIC_9X4, new DoubleChestInventoryTranslator(36));
|
put(WindowType.GENERIC_9X4, new DoubleChestInventoryTranslator(36));
|
||||||
put(WindowType.GENERIC_9X5, new DoubleChestInventoryTranslator(45));
|
put(WindowType.GENERIC_9X5, new DoubleChestInventoryTranslator(45));
|
||||||
put(WindowType.GENERIC_9X6, new DoubleChestInventoryTranslator(54));
|
put(WindowType.GENERIC_9X6, new DoubleChestInventoryTranslator(54));
|
||||||
|
put(WindowType.CRAFTING, new CraftingInventoryTranslator());
|
||||||
/*put(WindowType.BREWING_STAND, new BrewingInventoryTranslator());
|
/*put(WindowType.BREWING_STAND, new BrewingInventoryTranslator());
|
||||||
put(WindowType.ANVIL, new AnvilInventoryTranslator());
|
put(WindowType.ANVIL, new AnvilInventoryTranslator());
|
||||||
put(WindowType.CRAFTING, new CraftingInventoryTranslator());
|
|
||||||
put(WindowType.GRINDSTONE, new GrindstoneInventoryTranslator());*/
|
put(WindowType.GRINDSTONE, new GrindstoneInventoryTranslator());*/
|
||||||
put(WindowType.MERCHANT, new MerchantInventoryTranslator());
|
put(WindowType.MERCHANT, new MerchantInventoryTranslator());
|
||||||
/*put(WindowType.SMITHING, new SmithingInventoryTranslator());
|
/*put(WindowType.SMITHING, new SmithingInventoryTranslator());
|
||||||
@ -295,7 +295,7 @@ public abstract class InventoryTranslator {
|
|||||||
}
|
}
|
||||||
craftState = CraftState.RECIPE_ID;
|
craftState = CraftState.RECIPE_ID;
|
||||||
recipeId = craftAction.getRecipeNetworkId();
|
recipeId = craftAction.getRecipeNetworkId();
|
||||||
System.out.println(session.getCraftingRecipes().get(recipeId).toString());
|
System.out.println(session.getCraftingRecipes().get(recipeId));
|
||||||
autoCraft = false;
|
autoCraft = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,9 @@ import org.geysermc.connector.network.session.GeyserSession;
|
|||||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the fake block we implement for each inventory.
|
||||||
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class BlockInventoryHolder extends InventoryHolder {
|
public class BlockInventoryHolder extends InventoryHolder {
|
||||||
private final int blockId;
|
private final int blockId;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren