3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

Properly translate ominous items

Dieser Commit ist enthalten in:
Camotoy 2024-06-14 15:44:00 -04:00
Ursprung 28e4661fcf
Commit a9ba1ad603
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
10 geänderte Dateien mit 111 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -1368,7 +1368,7 @@ public final class Items {
public static final Item TRIAL_KEY = register(new Item("trial_key", builder()));
public static final Item OMINOUS_TRIAL_KEY = register(new Item("ominous_trial_key", builder()));
public static final Item VAULT = register(new BlockItem(builder(), Blocks.VAULT));
public static final Item OMINOUS_BOTTLE = register(new Item("ominous_bottle", builder()));
public static final Item OMINOUS_BOTTLE = register(new OminousBottleItem("ominous_bottle", builder()));
public static final Item BREEZE_ROD = register(new Item("breeze_rod", builder()));
public static final int AIR_ID = AIR.javaId();

Datei anzeigen

@ -51,4 +51,9 @@ public class ArrowItem extends Item {
}
return itemStack;
}
@Override
public boolean ignoreDamage() {
return true;
}
}

Datei anzeigen

@ -90,4 +90,9 @@ public class FireworkStarItem extends Item {
components.put(DataComponentType.FIREWORK_EXPLOSION, newExplosion);
}
}
@Override
public boolean ignoreDamage() {
return true;
}
}

Datei anzeigen

@ -62,4 +62,9 @@ public class GoatHornItem extends Item {
return itemStack;
}
@Override
public boolean ignoreDamage() {
return true;
}
}

Datei anzeigen

@ -226,6 +226,14 @@ public class Item {
}
}
/**
* Override if the Bedrock equivalent of an item uses damage for extra data, and should not be tracked
* when translating an item.
*/
public boolean ignoreDamage() {
return false;
}
/* Translation methods end */
public GeyserItemStack newItemStack(int count, DataComponents components) {

Datei anzeigen

@ -0,0 +1,72 @@
/*
* Copyright (c) 2024 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.item.type;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.registry.type.ItemMappings;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
public class OminousBottleItem extends Item {
public OminousBottleItem(String javaIdentifier, Builder builder) {
super(javaIdentifier, builder);
}
@Override
public ItemData.Builder translateToBedrock(int count, @Nullable DataComponents components, ItemMapping mapping, ItemMappings mappings) {
var builder = super.translateToBedrock(count, components, mapping, mappings);
if (components == null) {
// Level 1 ominous bottle is null components - Java 1.21.
return builder;
}
Integer amplifier = components.get(DataComponentType.OMINOUS_BOTTLE_AMPLIFIER);
if (amplifier != null) {
builder.damage(amplifier);
}
return builder;
}
@Override
public @NonNull GeyserItemStack translateToJava(@NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) {
// This item can be pulled from the creative inventory with amplifiers.
GeyserItemStack itemStack = super.translateToJava(itemData, mapping, mappings);
int damage = itemData.getDamage();
if (damage == 0) {
return itemStack;
}
itemStack.getOrCreateComponents().put(DataComponentType.OMINOUS_BOTTLE_AMPLIFIER, damage);
return itemStack;
}
@Override
public boolean ignoreDamage() {
return true;
}
}

Datei anzeigen

@ -76,4 +76,9 @@ public class PotionItem extends Item {
}
return itemStack;
}
@Override
public boolean ignoreDamage() {
return true;
}
}

Datei anzeigen

@ -50,6 +50,12 @@ public class Conversion685_671 {
if (NEW_MUSIC_DISCS.contains(item)) {
return mapping.withBedrockIdentifier("minecraft:music_disc_otherside");
}
if (item == Items.OMINOUS_TRIAL_KEY) {
return mapping.withBedrockIdentifier("minecraft:trial_key");
}
if (item == Items.OMINOUS_BOTTLE) {
return mapping.withBedrockIdentifier("minecraft:glass_bottle");
}
if (!NEW_BLOCKS.contains(identifer)) {
return mapping;

Datei anzeigen

@ -25,7 +25,6 @@
package org.geysermc.geyser.registry.type;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import lombok.Builder;
@ -41,7 +40,7 @@ import org.geysermc.geyser.api.block.custom.CustomBlockData;
import org.geysermc.geyser.inventory.item.StoredItemMappings;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.item.type.PotionItem;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import java.util.List;
import java.util.Map;
@ -148,10 +147,8 @@ public class ItemMappings implements DefinitionRegistry<ItemDefinition> {
}
} else {
if (!(mapping.getBedrockData() == data.getDamage() ||
// Make exceptions for potions, tipped arrows, firework stars, goat horns, and suspicious stews, whose damage values can vary
(mapping.getJavaItem() instanceof PotionItem || mapping.getJavaItem() == Items.ARROW
|| mapping.getJavaItem() == Items.FIREWORK_STAR || mapping.getJavaItem() == Items.GOAT_HORN
|| mapping.getJavaItem() == Items.SUSPICIOUS_STEW))) {
// Make exceptions for items whose damage values can vary
(mapping.getJavaItem().ignoreDamage() || mapping.getJavaItem() == Items.SUSPICIOUS_STEW))) {
continue;
}
}

@ -1 +1 @@
Subproject commit 396ea5ff50d8c976fde4e7423e682d21aa0ee350
Subproject commit 5f892d04d2212a13fad3f517b3f516d6526833f2