Add inventory names

Some translation identifiers such as "container.blast_furnace" are not being translated yet
This commit is contained in:
AJ Ferguson 2019-11-01 01:07:13 -08:00
parent 24c27a03a9
commit 5797dc2c7e
6 changed files with 65 additions and 4 deletions

View file

@ -27,8 +27,10 @@ package org.geysermc.connector.network.translators.inventory;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.protocol.bedrock.data.ContainerType;
import com.nukkitx.protocol.bedrock.data.InventoryAction;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.inventory.Inventory;
@ -52,6 +54,16 @@ public class DispenserInventoryTranslator extends InventoryTranslator {
blockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
session.getUpstream().sendPacket(blockPacket);
inventory.setHolderPosition(position);
CompoundTag tag = CompoundTag.EMPTY.toBuilder()
.intTag("x", position.getX())
.intTag("y", position.getY())
.intTag("z", position.getZ())
.stringTag("CustomName", inventory.getTitle()).buildRootTag();
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag);
dataPacket.setBlockPosition(position);
session.getUpstream().sendPacket(dataPacket);
}
@Override

View file

@ -63,7 +63,8 @@ public class DoubleChestInventoryTranslator extends InventoryTranslator {
.intTag("y", position.getY())
.intTag("z", position.getZ())
.intTag("pairx", pairPosition.getX())
.intTag("pairz", pairPosition.getZ()).buildRootTag();
.intTag("pairz", pairPosition.getZ())
.stringTag("CustomName", inventory.getTitle()).buildRootTag();
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag);
dataPacket.setBlockPosition(position);
@ -82,7 +83,8 @@ public class DoubleChestInventoryTranslator extends InventoryTranslator {
.intTag("y", pairPosition.getY())
.intTag("z", pairPosition.getZ())
.intTag("pairx", position.getX())
.intTag("pairz", position.getZ()).buildRootTag();
.intTag("pairz", position.getZ())
.stringTag("CustomName", inventory.getTitle()).buildRootTag();
dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag);
dataPacket.setBlockPosition(pairPosition);

View file

@ -55,6 +55,16 @@ public class FurnaceInventoryTranslator extends InventoryTranslator {
blockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
session.getUpstream().sendPacket(blockPacket);
inventory.setHolderPosition(position);
CompoundTag tag = CompoundTag.EMPTY.toBuilder()
.intTag("x", position.getX())
.intTag("y", position.getY())
.intTag("z", position.getZ())
.stringTag("CustomName", inventory.getTitle()).buildRootTag();
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag);
dataPacket.setBlockPosition(position);
session.getUpstream().sendPacket(dataPacket);
}
@Override

View file

@ -27,8 +27,10 @@ package org.geysermc.connector.network.translators.inventory;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.protocol.bedrock.data.ContainerType;
import com.nukkitx.protocol.bedrock.data.InventoryAction;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.inventory.Inventory;
@ -52,6 +54,16 @@ public class HopperInventoryTranslator extends InventoryTranslator {
blockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
session.getUpstream().sendPacket(blockPacket);
inventory.setHolderPosition(position);
CompoundTag tag = CompoundTag.EMPTY.toBuilder()
.intTag("x", position.getX())
.intTag("y", position.getY())
.intTag("z", position.getZ())
.stringTag("CustomName", inventory.getTitle()).buildRootTag();
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag);
dataPacket.setBlockPosition(position);
session.getUpstream().sendPacket(dataPacket);
}
@Override

View file

@ -55,6 +55,16 @@ public class SingleChestInventoryTranslator extends InventoryTranslator {
blockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
session.getUpstream().sendPacket(blockPacket);
inventory.setHolderPosition(position);
CompoundTag tag = CompoundTag.EMPTY.toBuilder()
.intTag("x", position.getX())
.intTag("y", position.getY())
.intTag("z", position.getZ())
.stringTag("CustomName", inventory.getTitle()).buildRootTag();
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag);
dataPacket.setBlockPosition(position);
session.getUpstream().sendPacket(dataPacket);
}
@Override

View file

@ -25,9 +25,10 @@
package org.geysermc.connector.network.translators.java.window;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.nukkitx.protocol.bedrock.packet.ContainerClosePacket;
import org.geysermc.api.Geyser;
import org.geysermc.connector.inventory.Inventory;
@ -59,7 +60,21 @@ public class JavaOpenWindowTranslator extends PacketTranslator<ServerOpenWindowP
session.getDownstream().getSession().send(closeWindowPacket);
return;
}
Inventory newInventory = new Inventory(packet.getWindowId(), packet.getType(), newTranslator.size + 36);
String name = packet.getName();
try {
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(packet.getName()).getAsJsonObject();
if (jsonObject.has("text")) {
name = jsonObject.get("text").getAsString();
} else if (jsonObject.has("translate")) {
name = jsonObject.get("translate").getAsString();
}
} catch (Exception e) {
Geyser.getLogger().debug("JavaOpenWindowTranslator: " + e.toString());
}
Inventory newInventory = new Inventory(name, packet.getWindowId(), packet.getType(), newTranslator.size + 36);
session.getInventoryCache().cacheInventory(newInventory);
if (openInventory != null) {
InventoryTranslator openTranslator = TranslatorsInit.getInventoryTranslators().get(openInventory.getWindowType());