Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-09-17 00:33:47 +02:00
Fix fishing rod durability (fixes #1964)
Dieser Commit ist enthalten in:
Ursprung
3a2cff7864
Commit
65c52f9ff0
@ -56,6 +56,7 @@ import org.geysermc.connector.network.translators.inventory.translators.furnace.
|
|||||||
import org.geysermc.connector.network.translators.inventory.translators.furnace.FurnaceInventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.translators.furnace.FurnaceInventoryTranslator;
|
||||||
import org.geysermc.connector.network.translators.inventory.translators.furnace.SmokerInventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.translators.furnace.SmokerInventoryTranslator;
|
||||||
import org.geysermc.connector.utils.InventoryUtils;
|
import org.geysermc.connector.utils.InventoryUtils;
|
||||||
|
import org.geysermc.connector.utils.ItemUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -865,7 +866,7 @@ public abstract class InventoryTranslator {
|
|||||||
if (itemStack.getNbt() != null) {
|
if (itemStack.getNbt() != null) {
|
||||||
Tag damage = itemStack.getNbt().get("Damage");
|
Tag damage = itemStack.getNbt().get("Damage");
|
||||||
if (damage instanceof IntTag) {
|
if (damage instanceof IntTag) {
|
||||||
durability = ((IntTag) damage).getValue();
|
durability = ItemUtils.getCorrectBedrockDurability(itemStack.getJavaId(), ((IntTag) damage).getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +98,10 @@ public class ItemRegistry {
|
|||||||
* Crossbow item entry, used in PillagerEntity.java
|
* Crossbow item entry, used in PillagerEntity.java
|
||||||
*/
|
*/
|
||||||
public static ItemEntry CROSSBOW;
|
public static ItemEntry CROSSBOW;
|
||||||
|
/**
|
||||||
|
* Fishing rod item entry, used in ItemUtils.java
|
||||||
|
*/
|
||||||
|
public static ItemEntry FISHING_ROD;
|
||||||
/**
|
/**
|
||||||
* Empty item bucket, used in BedrockInventoryTransactionTranslator.java
|
* Empty item bucket, used in BedrockInventoryTransactionTranslator.java
|
||||||
*/
|
*/
|
||||||
@ -438,6 +442,9 @@ public class ItemRegistry {
|
|||||||
case "minecraft:egg":
|
case "minecraft:egg":
|
||||||
EGG = itemEntry;
|
EGG = itemEntry;
|
||||||
break;
|
break;
|
||||||
|
case "minecraft:fishing_rod":
|
||||||
|
FISHING_ROD = itemEntry;
|
||||||
|
break;
|
||||||
case "minecraft:shield":
|
case "minecraft:shield":
|
||||||
SHIELD = itemEntry;
|
SHIELD = itemEntry;
|
||||||
break;
|
break;
|
||||||
|
@ -226,14 +226,14 @@ public abstract class ItemTranslator {
|
|||||||
public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
|
public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
|
||||||
if (itemData == null) return null;
|
if (itemData == null) return null;
|
||||||
if (itemData.getTag() == null) {
|
if (itemData.getTag() == null) {
|
||||||
return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new com.github.steveice10.opennbt.tag.builtin.CompoundTag(""));
|
return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new CompoundTag(""));
|
||||||
}
|
}
|
||||||
return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT("", itemData.getTag()));
|
return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT("", itemData.getTag()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract List<ItemEntry> getAppliedItems();
|
public abstract List<ItemEntry> getAppliedItems();
|
||||||
|
|
||||||
public NbtMap translateNbtToBedrock(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) {
|
public NbtMap translateNbtToBedrock(CompoundTag tag) {
|
||||||
NbtMapBuilder builder = NbtMap.builder();
|
NbtMapBuilder builder = NbtMap.builder();
|
||||||
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
|
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
|
||||||
for (String str : tag.getValue().keySet()) {
|
for (String str : tag.getValue().keySet()) {
|
||||||
@ -248,7 +248,7 @@ public abstract class ItemTranslator {
|
|||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object translateToBedrockNBT(com.github.steveice10.opennbt.tag.builtin.Tag tag) {
|
private Object translateToBedrockNBT(Tag tag) {
|
||||||
if (tag instanceof ByteArrayTag) {
|
if (tag instanceof ByteArrayTag) {
|
||||||
return ((ByteArrayTag) tag).getValue();
|
return ((ByteArrayTag) tag).getValue();
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,13 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.item.translators.nbt;
|
package org.geysermc.connector.network.translators.item.translators.nbt;
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.ItemRemapper;
|
import org.geysermc.connector.network.translators.ItemRemapper;
|
||||||
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
||||||
import org.geysermc.connector.network.translators.item.ItemEntry;
|
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||||
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
|
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
|
||||||
|
import org.geysermc.connector.utils.ItemUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -43,6 +41,16 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
|
Tag damage = itemTag.get("Damage");
|
||||||
|
if (damage instanceof IntTag) {
|
||||||
|
int originalDurability = ((IntTag) damage).getValue();
|
||||||
|
int durability = ItemUtils.getCorrectBedrockDurability(itemEntry.getJavaId(), originalDurability);
|
||||||
|
if (durability != originalDurability) {
|
||||||
|
// Fix damage tag inconsistencies
|
||||||
|
itemTag.put(new IntTag("Damage", durability));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CompoundTag displayTag = itemTag.get("display");
|
CompoundTag displayTag = itemTag.get("display");
|
||||||
if (displayTag == null) {
|
if (displayTag == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,47 +1,61 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* @author GeyserMC
|
* @author GeyserMC
|
||||||
* @link https://github.com/GeyserMC/Geyser
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geysermc.connector.utils;
|
package org.geysermc.connector.utils;
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||||
|
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||||
public class ItemUtils {
|
|
||||||
|
public class ItemUtils {
|
||||||
public static int getEnchantmentLevel(CompoundTag itemNBTData, String enchantmentId) {
|
|
||||||
ListTag enchantments = (itemNBTData == null ? null : itemNBTData.get("Enchantments"));
|
public static int getEnchantmentLevel(CompoundTag itemNBTData, String enchantmentId) {
|
||||||
if (enchantments != null) {
|
ListTag enchantments = (itemNBTData == null ? null : itemNBTData.get("Enchantments"));
|
||||||
int enchantmentLevel = 0;
|
if (enchantments != null) {
|
||||||
for (Tag tag : enchantments) {
|
int enchantmentLevel = 0;
|
||||||
CompoundTag enchantment = (CompoundTag) tag;
|
for (Tag tag : enchantments) {
|
||||||
StringTag enchantId = enchantment.get("id");
|
CompoundTag enchantment = (CompoundTag) tag;
|
||||||
if (enchantId.getValue().equals(enchantmentId)) {
|
StringTag enchantId = enchantment.get("id");
|
||||||
enchantmentLevel = (int) ((ShortTag) enchantment.get("lvl")).getValue();
|
if (enchantId.getValue().equals(enchantmentId)) {
|
||||||
}
|
enchantmentLevel = (int) ((ShortTag) enchantment.get("lvl")).getValue();
|
||||||
}
|
}
|
||||||
return enchantmentLevel;
|
}
|
||||||
}
|
return enchantmentLevel;
|
||||||
return 0;
|
}
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the correct Bedrock durability for this item.
|
||||||
|
*/
|
||||||
|
public static int getCorrectBedrockDurability(int javaId, int original) {
|
||||||
|
if (javaId == ItemRegistry.FISHING_ROD.getJavaId()) {
|
||||||
|
// Java durability: 64
|
||||||
|
// Bedrock durability : 384
|
||||||
|
// 384 / 64 = 6
|
||||||
|
return original * 6;
|
||||||
|
}
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren