forked from GeyserMC/Geyser
Brewing stand support; other attempts
This commit is contained in:
parent
33a86485dc
commit
aa4a1058e3
2 changed files with 151 additions and 4 deletions
|
@ -26,6 +26,7 @@
|
|||
package org.geysermc.connector.network.translators.inventory;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
|
||||
|
@ -67,9 +68,9 @@ public abstract class InventoryTranslator {
|
|||
put(WindowType.GENERIC_9X6, new DoubleChestInventoryTranslator(54));
|
||||
put(WindowType.CRAFTING, new CraftingInventoryTranslator());
|
||||
put(WindowType.SHULKER_BOX, new ShulkerInventoryTranslator());
|
||||
/*put(WindowType.BREWING_STAND, new BrewingInventoryTranslator());
|
||||
put(WindowType.ANVIL, new AnvilInventoryTranslator());
|
||||
put(WindowType.GRINDSTONE, new GrindstoneInventoryTranslator());*/
|
||||
put(WindowType.BREWING_STAND, new BrewingInventoryTranslator());
|
||||
//put(WindowType.ANVIL, new AnvilInventoryTranslator());
|
||||
//put(WindowType.GRINDSTONE, new GrindstoneInventoryTranslator());
|
||||
put(WindowType.MERCHANT, new MerchantInventoryTranslator());
|
||||
//put(WindowType.SMITHING, new SmithingInventoryTranslator());
|
||||
//put(WindowType.ENCHANTMENT, new EnchantmentInventoryTranslator()); //TODO
|
||||
|
@ -81,6 +82,11 @@ public abstract class InventoryTranslator {
|
|||
put(WindowType.GENERIC_3X3, new GenericBlockInventoryTranslator(9, "minecraft:dispenser[facing=north,triggered=false]", ContainerType.DISPENSER));
|
||||
put(WindowType.HOPPER, new GenericBlockInventoryTranslator(5, "minecraft:hopper[enabled=false,facing=down]", ContainerType.HOPPER));
|
||||
//put(WindowType.BEACON, new AbstractBlockInventoryTranslator(1, "minecraft:beacon", ContainerType.BEACON)); //TODO*/
|
||||
|
||||
//put(WindowType.CARTOGRAPHY
|
||||
//put(WindowType.STONECUTTER
|
||||
//put(WindowType.LOOM
|
||||
//put(WindowType.
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -129,8 +135,12 @@ public abstract class InventoryTranslator {
|
|||
case TAKE:
|
||||
case PLACE: {
|
||||
TransferStackRequestActionData transferAction = (TransferStackRequestActionData) action;
|
||||
if (!(checkNetId(session, inventory, transferAction.getSource()) && checkNetId(session, inventory, transferAction.getDestination())))
|
||||
if (!(checkNetId(session, inventory, transferAction.getSource()) && checkNetId(session, inventory, transferAction.getDestination()))) {
|
||||
session.getConnector().getLogger().error("DEBUG: About to reject request.");
|
||||
session.getConnector().getLogger().error("Source: " + transferAction.getSource().toString() + " Result: " + checkNetId(session, inventory, transferAction.getSource()));
|
||||
session.getConnector().getLogger().error("Destination: " + transferAction.getDestination().toString() + " Result: " + checkNetId(session, inventory, transferAction.getDestination()));
|
||||
return rejectRequest(request);
|
||||
}
|
||||
|
||||
if (isCursor(transferAction.getSource()) && isCursor(transferAction.getDestination())) { //???
|
||||
return rejectRequest(request);
|
||||
|
@ -273,6 +283,30 @@ public abstract class InventoryTranslator {
|
|||
CraftCreativeStackRequestActionData creativeAction = (CraftCreativeStackRequestActionData) action;
|
||||
System.out.println(creativeAction.getCreativeItemNetworkId());
|
||||
}
|
||||
case DESTROY: {
|
||||
//TODO: Yeah this doesn't work yet.
|
||||
|
||||
// Only called when a creative client wants to destroy an item... I think - Camotoy
|
||||
DestroyStackRequestActionData destroyAction = (DestroyStackRequestActionData) action;
|
||||
if (session.getGameMode() == GameMode.CREATIVE) {
|
||||
if (isCursor(destroyAction.getSource())) {
|
||||
session.getPlayerInventory().setCursor(GeyserItemStack.EMPTY);
|
||||
return acceptRequest(request, makeContainerEntries(session, inventory, Collections.emptySet()));
|
||||
} else {
|
||||
int javaSlot = bedrockSlotToJava(destroyAction.getSource());
|
||||
inventory.setItem(javaSlot, GeyserItemStack.EMPTY);
|
||||
ClientCreativeInventoryActionPacket creativeActionPacket = new ClientCreativeInventoryActionPacket(
|
||||
javaSlot,
|
||||
new ItemStack(0)
|
||||
);
|
||||
session.sendDownstreamPacket(creativeActionPacket);
|
||||
Set<Integer> affectedSlots = Collections.singleton(javaSlot);
|
||||
return acceptRequest(request, makeContainerEntries(session, inventory, affectedSlots));
|
||||
}
|
||||
} else {
|
||||
return rejectRequest(request);
|
||||
}
|
||||
}
|
||||
default:
|
||||
return rejectRequest(request);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* 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.translators;
|
||||
|
||||
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 com.nukkitx.protocol.bedrock.packet.ContainerSetDataPacket;
|
||||
import org.geysermc.connector.inventory.Inventory;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
|
||||
import org.geysermc.connector.network.translators.inventory.updater.ContainerInventoryUpdater;
|
||||
|
||||
public class BrewingInventoryTranslator extends AbstractBlockInventoryTranslator {
|
||||
public BrewingInventoryTranslator() {
|
||||
super(5, "minecraft:brewing_stand[has_bottle_0=false,has_bottle_1=false,has_bottle_2=false]", ContainerType.BREWING_STAND, ContainerInventoryUpdater.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(GeyserSession session, Inventory inventory) {
|
||||
super.openInventory(session, inventory);
|
||||
ContainerSetDataPacket dataPacket = new ContainerSetDataPacket();
|
||||
dataPacket.setWindowId((byte) inventory.getId());
|
||||
dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_FUEL_TOTAL);
|
||||
dataPacket.setValue(20);
|
||||
session.sendUpstreamPacket(dataPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProperty(GeyserSession session, Inventory inventory, int key, int value) {
|
||||
ContainerSetDataPacket dataPacket = new ContainerSetDataPacket();
|
||||
dataPacket.setWindowId((byte) inventory.getId());
|
||||
switch (key) {
|
||||
case 0:
|
||||
dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_BREW_TIME);
|
||||
break;
|
||||
case 1:
|
||||
dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_FUEL_AMOUNT);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
dataPacket.setValue(value);
|
||||
session.sendUpstreamPacket(dataPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
||||
System.out.println("Brewing stand: " + slotInfoData);
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.BREWING_INPUT) {
|
||||
// Ingredient
|
||||
// TODO: This hasn't worked and then suddenly, it did.
|
||||
return 3;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.BREWING_RESULT) {
|
||||
// Potions
|
||||
return slotInfoData.getSlot() - 1;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int javaSlotToBedrock(int slot) {
|
||||
switch (slot) {
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
return 2;
|
||||
case 2:
|
||||
return 3;
|
||||
case 3:
|
||||
return 0;
|
||||
}
|
||||
return super.javaSlotToBedrock(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
|
||||
if (slot == 0 || slot == 1 || slot == 2) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.BREWING_RESULT, javaSlotToBedrock(slot));
|
||||
}
|
||||
if (slot == 3) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.BREWING_INPUT, 0);
|
||||
}
|
||||
if (slot == 4) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.BREWING_FUEL, 4);
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(slot);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue