3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

Add unusable inventory space message (#492)

* Add unusable inventory space message

* Remove unused imports

* Fixed barrier pickup (#1)

Co-authored-by: rtm516 <rtm516@users.noreply.github.com>
Dieser Commit ist enthalten in:
Luke 2020-05-06 22:05:03 +01:00 committet von GitHub
Ursprung 425df396cb
Commit 4c1dae6714
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 27 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -44,6 +44,8 @@ import org.geysermc.connector.utils.Toolbox;
import java.util.List; import java.util.List;
public class PlayerInventoryTranslator extends InventoryTranslator { public class PlayerInventoryTranslator extends InventoryTranslator {
private static final ItemData UNUSUABLE_CRAFTING_SPACE_BLOCK = InventoryUtils.createUnusableSpaceBlock(
"The creative crafting grid is\nunavailable in Java Edition");
public PlayerInventoryTranslator() { public PlayerInventoryTranslator() {
super(46); super(46);
@ -97,7 +99,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
slotPacket.setSlot(i + 27); slotPacket.setSlot(i + 27);
if (session.getGameMode() == GameMode.CREATIVE) { if (session.getGameMode() == GameMode.CREATIVE) {
slotPacket.setItem(Translators.getItemTranslator().translateToBedrock(session, new ItemStack(Toolbox.BARRIER_INDEX))); slotPacket.setItem(UNUSUABLE_CRAFTING_SPACE_BLOCK);
}else{ }else{
slotPacket.setItem(Translators.getItemTranslator().translateToBedrock(session, inventory.getItem(i))); slotPacket.setItem(Translators.getItemTranslator().translateToBedrock(session, inventory.getItem(i)));
} }

Datei anzeigen

@ -33,9 +33,13 @@ import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.Translators; import org.geysermc.connector.network.translators.Translators;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
import org.geysermc.connector.utils.InventoryUtils;
@AllArgsConstructor @AllArgsConstructor
public class ChestInventoryUpdater extends InventoryUpdater { public class ChestInventoryUpdater extends InventoryUpdater {
private static final ItemData UNUSUABLE_SPACE_BLOCK = InventoryUtils.createUnusableSpaceBlock(
"This slot does not exist in the inventory\non Java Edition, as there is less\nrows than possible in Bedrock");
private final int paddedSize; private final int paddedSize;
@Override @Override
@ -47,7 +51,7 @@ public class ChestInventoryUpdater extends InventoryUpdater {
if (i <= translator.size) { if (i <= translator.size) {
bedrockItems[i] = Translators.getItemTranslator().translateToBedrock(session, inventory.getItem(i)); bedrockItems[i] = Translators.getItemTranslator().translateToBedrock(session, inventory.getItem(i));
} else { } else {
bedrockItems[i] = ItemData.AIR; bedrockItems[i] = UNUSUABLE_SPACE_BLOCK;
} }
} }

Datei anzeigen

@ -27,9 +27,12 @@ package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.nbt.tag.StringTag;
import com.nukkitx.protocol.bedrock.data.ContainerId; import com.nukkitx.protocol.bedrock.data.ContainerId;
import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.data.ItemData;
import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
import org.geysermc.common.ChatColor;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
@ -37,6 +40,7 @@ import org.geysermc.connector.network.translators.Translators;
import org.geysermc.connector.network.translators.inventory.DoubleChestInventoryTranslator; import org.geysermc.connector.network.translators.inventory.DoubleChestInventoryTranslator;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -98,4 +102,19 @@ public class InventoryUtils {
return false; return false;
return item1.equals(item2, false, true, true); return item1.equals(item2, false, true, true);
} }
/**
* Returns a barrier block with custom name and lore to explain why
* part of the inventory is unusable.
*/
public static ItemData createUnusableSpaceBlock(String description) {
CompoundTagBuilder root = CompoundTagBuilder.builder();
CompoundTagBuilder display = CompoundTagBuilder.builder();
display.stringTag("Name", ChatColor.RESET + "Unusable inventory space");
display.listTag("Lore", StringTag.class, Collections.singletonList(new StringTag("", ChatColor.RESET + ChatColor.DARK_PURPLE + description)));
root.tag(display.build("display"));
return ItemData.of(Toolbox.ITEM_ENTRIES.get(Toolbox.BARRIER_INDEX).getBedrockId(), (short) 0, 1, root.buildRootTag());
}
} }