Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-08 17:20:20 +01: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;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
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 {
|
||||||
|
|
||||||
@ -44,4 +45,17 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
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