mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-13 10:20:46 +01:00
Anvil renaming works; other things
This commit is contained in:
parent
4b461e5e0a
commit
956d264c3e
5 changed files with 77 additions and 5 deletions
|
@ -25,6 +25,9 @@
|
||||||
|
|
||||||
package org.geysermc.connector.inventory;
|
package org.geysermc.connector.inventory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to determine if rename packets should be sent.
|
||||||
|
*/
|
||||||
public class AnvilContainer extends Container {
|
public class AnvilContainer extends Container {
|
||||||
public AnvilContainer(String title, int id, int size, PlayerInventory playerInventory) {
|
public AnvilContainer(String title, int id, int size, PlayerInventory playerInventory) {
|
||||||
super(title, id, size, playerInventory);
|
super(title, id, size, playerInventory);
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.inventory;
|
||||||
|
|
||||||
|
public class CartographyContainer extends Container {
|
||||||
|
public CartographyContainer(String title, int id, int size, PlayerInventory playerInventory) {
|
||||||
|
super(title, id, size, playerInventory);
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,7 +25,10 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.bedrock;
|
package org.geysermc.connector.network.translators.bedrock;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.FilterTextPacket;
|
import com.nukkitx.protocol.bedrock.packet.FilterTextPacket;
|
||||||
|
import org.geysermc.connector.inventory.AnvilContainer;
|
||||||
|
import org.geysermc.connector.inventory.CartographyContainer;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
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;
|
||||||
|
@ -39,7 +42,18 @@ public class BedrockFilterTextTranslator extends PacketTranslator<FilterTextPack
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(FilterTextPacket packet, GeyserSession session) {
|
public void translate(FilterTextPacket packet, GeyserSession session) {
|
||||||
|
if (session.getOpenInventory() instanceof CartographyContainer) {
|
||||||
|
// We don't want to be able to rename in the cartography table
|
||||||
|
return;
|
||||||
|
}
|
||||||
packet.setFromServer(true);
|
packet.setFromServer(true);
|
||||||
session.sendUpstreamPacket(packet);
|
session.sendUpstreamPacket(packet);
|
||||||
|
|
||||||
|
if (session.getOpenInventory() instanceof AnvilContainer) {
|
||||||
|
// Java Edition sends a packet every time an item is renamed even slightly in GUI. Fortunately, this works out for us now
|
||||||
|
ClientRenameItemPacket renameItemPacket = new ClientRenameItemPacket(packet.getText());
|
||||||
|
System.out.println(renameItemPacket);
|
||||||
|
session.sendDownstreamPacket(renameItemPacket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.geysermc.connector.inventory.CartographyContainer;
|
||||||
import org.geysermc.connector.inventory.GeyserItemStack;
|
import org.geysermc.connector.inventory.GeyserItemStack;
|
||||||
import org.geysermc.connector.inventory.Inventory;
|
import org.geysermc.connector.inventory.Inventory;
|
||||||
import org.geysermc.connector.inventory.PlayerInventory;
|
import org.geysermc.connector.inventory.PlayerInventory;
|
||||||
|
@ -483,8 +484,25 @@ public abstract class InventoryTranslator {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// These three are called for the grindstone
|
// The following three tend to be called for UI inventories
|
||||||
case CONSUME: {
|
case CONSUME: {
|
||||||
|
if (inventory instanceof CartographyContainer) {
|
||||||
|
// TODO add this for more inventories? Only seems to glitch out the cartography table, though.
|
||||||
|
ConsumeStackRequestActionData consumeData = (ConsumeStackRequestActionData) action;
|
||||||
|
int sourceSlot = bedrockSlotToJava(consumeData.getSource());
|
||||||
|
if (sourceSlot == 0 && inventory.getItem(1).isEmpty()) {
|
||||||
|
// Java doesn't allow an item to be renamed; this is why CARTOGRAPHY_ADDITIONAL could remain empty for Bedrock
|
||||||
|
// We check this during slot 0 since setting the inventory slots here messes up shouldRejectItemPlace
|
||||||
|
return rejectRequest(request, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
GeyserItemStack item = inventory.getItem(sourceSlot);
|
||||||
|
item.setAmount(item.getAmount() - consumeData.getCount());
|
||||||
|
if (item.isEmpty()) {
|
||||||
|
inventory.setItem(sourceSlot, GeyserItemStack.EMPTY);
|
||||||
|
}
|
||||||
|
affectedSlots.add(sourceSlot);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CRAFT_NON_IMPLEMENTED_DEPRECATED: {
|
case CRAFT_NON_IMPLEMENTED_DEPRECATED: {
|
||||||
|
|
|
@ -25,11 +25,14 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.inventory.translators;
|
package org.geysermc.connector.network.translators.inventory.translators;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData;
|
import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData;
|
||||||
|
import org.geysermc.connector.inventory.CartographyContainer;
|
||||||
import org.geysermc.connector.inventory.GeyserItemStack;
|
import org.geysermc.connector.inventory.GeyserItemStack;
|
||||||
import org.geysermc.connector.inventory.Inventory;
|
import org.geysermc.connector.inventory.Inventory;
|
||||||
|
import org.geysermc.connector.inventory.PlayerInventory;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
|
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
|
||||||
import org.geysermc.connector.network.translators.inventory.updater.UIInventoryUpdater;
|
import org.geysermc.connector.network.translators.inventory.updater.UIInventoryUpdater;
|
||||||
|
@ -45,13 +48,10 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
|
||||||
// Bedrock Edition can use paper in slot 0
|
// Bedrock Edition can use paper in slot 0
|
||||||
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
|
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
|
||||||
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:paper");
|
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:paper");
|
||||||
}if (javaDestinationSlot == 1) {
|
} else if (javaDestinationSlot == 1) {
|
||||||
// Bedrock Edition can use a compass to create locator maps in the ADDITIONAL slot
|
// Bedrock Edition can use a compass to create locator maps in the ADDITIONAL slot
|
||||||
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
|
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
|
||||||
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:compass");
|
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:compass");
|
||||||
} else if (javaSourceSlot == 2) {
|
|
||||||
// Java doesn't allow an item to be renamed; this is why CARTOGRAPHY_ADDITIONAL could remain empty for Bedrock
|
|
||||||
return inventory.getItem(1).isEmpty();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -95,4 +95,9 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
|
||||||
}
|
}
|
||||||
return super.javaSlotToBedrock(slot);
|
return super.javaSlotToBedrock(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
|
||||||
|
return new CartographyContainer(name, windowId, this.size, playerInventory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue