Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-09-08 20:43:04 +02:00
Remove locator map from creative menu; show some map colors
Java allows any map color but Bedrock only allows a few, so we take what we can get. Fixes #2617
Dieser Commit ist enthalten in:
Ursprung
b7de1b668f
Commit
877301a500
@ -166,6 +166,9 @@ public class ItemRegistryPopulator {
|
||||
if (identifier.equals("minecraft:debug_stick")) {
|
||||
// Just shows an empty texture; either way it doesn't exist in the creative menu on Java
|
||||
continue;
|
||||
} else if (identifier.equals("minecraft:empty_map") && damage == 2) {
|
||||
// Bedrock-only as its own item
|
||||
continue;
|
||||
}
|
||||
StartGamePacket.ItemEntry entry = entries.get(identifier);
|
||||
int id = -1;
|
||||
|
@ -41,17 +41,6 @@ import java.util.stream.Collectors;
|
||||
@ItemRemapper
|
||||
public class CompassTranslator extends ItemTranslator {
|
||||
|
||||
private final List<ItemMapping> appliedItems;
|
||||
|
||||
public CompassTranslator() {
|
||||
appliedItems = Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
|
||||
.getItems()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(entry -> entry.getJavaIdentifier().endsWith("compass"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
||||
if (isLodestoneCompass(itemStack.getNbt())) {
|
||||
@ -89,6 +78,11 @@ public class CompassTranslator extends ItemTranslator {
|
||||
|
||||
@Override
|
||||
public List<ItemMapping> getAppliedItems() {
|
||||
return appliedItems;
|
||||
return Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
|
||||
.getItems()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(entry -> entry.getJavaIdentifier().endsWith("compass"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 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.geyser.translator.inventory.item;
|
||||
|
||||
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.Tag;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||
import org.geysermc.geyser.network.MinecraftProtocol;
|
||||
import org.geysermc.geyser.registry.Registries;
|
||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||
import org.geysermc.geyser.registry.type.ItemMappings;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ItemRemapper
|
||||
public class FilledMapTranslator extends ItemTranslator {
|
||||
|
||||
@Override
|
||||
protected ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
||||
ItemData.Builder builder = super.translateToBedrock(itemStack, mapping, mappings);
|
||||
CompoundTag nbt = itemStack.getNbt();
|
||||
if (nbt != null && nbt.get("display") instanceof CompoundTag display) {
|
||||
// Note: damage 5 treasure map, 6 ???
|
||||
Tag mapColor = display.get("MapColor");
|
||||
if (mapColor != null && mapColor.getValue() instanceof Number color) {
|
||||
// Java Edition allows any color; Bedrock only allows some. So let's take what colors we can get
|
||||
switch (color.intValue()) {
|
||||
case 3830373 -> builder.damage(3); // Ocean Monument
|
||||
case 5393476 -> builder.damage(4); // Woodland explorer
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemMapping> getAppliedItems() {
|
||||
return Collections.singletonList(
|
||||
Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
|
||||
.getMapping("minecraft:filled_map")
|
||||
);
|
||||
}
|
||||
}
|
@ -303,13 +303,16 @@ public abstract class ItemTranslator {
|
||||
return new ItemStack(mapping.getJavaId(), itemData.getCount(), this.translateToJavaNBT("", itemData.getTag()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for initialization only and only called once.
|
||||
*/
|
||||
public abstract List<ItemMapping> getAppliedItems();
|
||||
|
||||
protected ItemMapping getItemMapping(int javaId, CompoundTag nbt, ItemMappings mappings) {
|
||||
return mappings.getMapping(javaId);
|
||||
}
|
||||
|
||||
public NbtMap translateNbtToBedrock(CompoundTag tag) {
|
||||
protected NbtMap translateNbtToBedrock(CompoundTag tag) {
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
|
||||
for (String str : tag.getValue().keySet()) {
|
||||
@ -388,7 +391,7 @@ public abstract class ItemTranslator {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CompoundTag translateToJavaNBT(String name, NbtMap tag) {
|
||||
private CompoundTag translateToJavaNBT(String name, NbtMap tag) {
|
||||
CompoundTag javaTag = new CompoundTag(name);
|
||||
Map<String, Tag> javaValue = javaTag.getValue();
|
||||
if (tag != null && !tag.isEmpty()) {
|
||||
|
@ -42,17 +42,6 @@ import java.util.stream.Collectors;
|
||||
@ItemRemapper
|
||||
public class PotionTranslator extends ItemTranslator {
|
||||
|
||||
private final List<ItemMapping> appliedItems;
|
||||
|
||||
public PotionTranslator() {
|
||||
appliedItems = Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
|
||||
.getItems()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(entry -> entry.getJavaIdentifier().endsWith("potion"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
||||
if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, mapping, mappings);
|
||||
@ -84,6 +73,11 @@ public class PotionTranslator extends ItemTranslator {
|
||||
|
||||
@Override
|
||||
public List<ItemMapping> getAppliedItems() {
|
||||
return appliedItems;
|
||||
return Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
|
||||
.getItems()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(entry -> entry.getJavaIdentifier().endsWith("potion"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -41,23 +41,10 @@ import java.util.stream.Collectors;
|
||||
|
||||
@ItemRemapper
|
||||
public class TippedArrowTranslator extends ItemTranslator {
|
||||
|
||||
private final List<ItemMapping> appliedItems;
|
||||
|
||||
private static final int TIPPED_ARROW_JAVA_ID = Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
|
||||
.getMapping("minecraft:tipped_arrow")
|
||||
.getJavaId();
|
||||
|
||||
public TippedArrowTranslator() {
|
||||
appliedItems = Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
|
||||
.getItems()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(entry -> entry.getJavaIdentifier().contains("arrow")
|
||||
&& !entry.getJavaIdentifier().contains("spectral"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
||||
if (!mapping.getJavaIdentifier().equals("minecraft:tipped_arrow") || itemStack.getNbt() == null) {
|
||||
@ -93,6 +80,12 @@ public class TippedArrowTranslator extends ItemTranslator {
|
||||
|
||||
@Override
|
||||
public List<ItemMapping> getAppliedItems() {
|
||||
return appliedItems;
|
||||
return Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
|
||||
.getItems()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(entry -> entry.getJavaIdentifier().contains("arrow")
|
||||
&& !entry.getJavaIdentifier().contains("spectral"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren