3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-09-08 05:42:51 +02:00

Handle soul speed enchant

Dieser Commit ist enthalten in:
KennyTV 2020-04-29 21:50:41 +02:00
Ursprung 6e9155ba80
Commit 8fbcd71e09
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
3 geänderte Dateien mit 90 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,13 @@
package nl.matsv.viabackwards.api.rewriters; package nl.matsv.viabackwards.api.rewriters;
import us.myles.viaversion.libs.opennbt.tag.builtin.*; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.viaversion.libs.opennbt.tag.builtin.ByteTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ShortTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -11,15 +18,45 @@ public class EnchantmentRewriter {
private final Map<String, String> enchantmentMappings = new HashMap<>(); private final Map<String, String> enchantmentMappings = new HashMap<>();
private final String nbtTagName; private final String nbtTagName;
private final boolean jsonFormat;
public EnchantmentRewriter(final String nbtTagName) { public EnchantmentRewriter(String nbtTagName, boolean jsonFormat) {
this.nbtTagName = nbtTagName; this.nbtTagName = nbtTagName;
this.jsonFormat = jsonFormat;
}
public EnchantmentRewriter(String nbtTagName) {
this(nbtTagName, true);
} }
public void registerEnchantment(String key, String replacementLore) { public void registerEnchantment(String key, String replacementLore) {
enchantmentMappings.put(key, replacementLore); enchantmentMappings.put(key, replacementLore);
} }
public void handleToClient(Item item) {
CompoundTag tag = item.getTag();
if (tag == null) return;
if (tag.get("Enchantments") instanceof ListTag) {
rewriteEnchantmentsToClient(tag, false);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
rewriteEnchantmentsToClient(tag, true);
}
}
public void handleToServer(Item item) {
CompoundTag tag = item.getTag();
if (tag == null) return;
if (tag.contains(nbtTagName + "|Enchantments")) {
rewriteEnchantmentsToServer(tag, false);
}
if (tag.contains(nbtTagName + "|StoredEnchantments")) {
rewriteEnchantmentsToServer(tag, true);
}
}
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) { public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "Enchantments"; String key = storedEnchant ? "StoredEnchantments" : "Enchantments";
ListTag enchantments = tag.get(key); ListTag enchantments = tag.get(key);
@ -31,7 +68,12 @@ public class EnchantmentRewriter {
if (enchantmentName != null) { if (enchantmentName != null) {
enchantments.remove(enchantmentEntry); enchantments.remove(enchantmentEntry);
Number level = (Number) ((CompoundTag) enchantmentEntry).get("lvl").getValue(); Number level = (Number) ((CompoundTag) enchantmentEntry).get("lvl").getValue();
lore.add(new StringTag("", enchantmentName + " " + getRomanNumber(level.intValue()))); String loreValue = enchantmentName + " " + getRomanNumber(level.intValue());
if (jsonFormat) {
loreValue = ChatRewriter.legacyTextToJson(loreValue);
}
lore.add(new StringTag("", loreValue));
remappedEnchantments.add(enchantmentEntry); remappedEnchantments.add(enchantmentEntry);
} }
} }

Datei anzeigen

@ -539,7 +539,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
enchantmentRewriter = new EnchantmentRewriter(nbtTagName); enchantmentRewriter = new EnchantmentRewriter(nbtTagName, false);
enchantmentRewriter.registerEnchantment("minecraft:multishot", "§7Multishot"); enchantmentRewriter.registerEnchantment("minecraft:multishot", "§7Multishot");
enchantmentRewriter.registerEnchantment("minecraft:quick_charge", "§7Quick Charge"); enchantmentRewriter.registerEnchantment("minecraft:quick_charge", "§7Quick Charge");
enchantmentRewriter.registerEnchantment("minecraft:piercing", "§7Piercing"); enchantmentRewriter.registerEnchantment("minecraft:piercing", "§7Piercing");
@ -550,8 +550,8 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
if (item == null) return null; if (item == null) return null;
super.handleItemToClient(item); super.handleItemToClient(item);
CompoundTag tag; CompoundTag tag = item.getTag();
if ((tag = item.getTag()) != null) { if (tag != null) {
// Display Name now uses JSON // Display Name now uses JSON
if (tag.get("display") instanceof CompoundTag) { if (tag.get("display") instanceof CompoundTag) {
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
@ -575,12 +575,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
} }
} }
if (tag.get("Enchantments") instanceof ListTag) { enchantmentRewriter.handleToClient(item);
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
}
} }
return item; return item;
} }
@ -590,8 +585,8 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
if (item == null) return null; if (item == null) return null;
super.handleItemToServer(item); super.handleItemToServer(item);
CompoundTag tag; CompoundTag tag = item.getTag();
if ((tag = item.getTag()) != null) { if (tag != null) {
// Display Lore now uses JSON // Display Lore now uses JSON
if (tag.get("display") instanceof CompoundTag) { if (tag.get("display") instanceof CompoundTag) {
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
@ -606,12 +601,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
} }
} }
if (tag.contains(nbtTagName + "|Enchantments")) { enchantmentRewriter.handleToServer(item);
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
}
if (tag.contains(nbtTagName + "|StoredEnchantments")) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
}
} }
return item; return item;
} }

Datei anzeigen

@ -1,6 +1,7 @@
package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets; package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings;
@ -28,6 +29,8 @@ import java.util.UUID;
public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_15_2To1_16> { public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_15_2To1_16> {
private EnchantmentRewriter enchantmentRewriter;
public BlockItemPackets1_16(Protocol1_15_2To1_16 protocol) { public BlockItemPackets1_16(Protocol1_15_2To1_16 protocol) {
super(protocol, BlockItemPackets1_16::getOldItemId, BlockItemPackets1_16::getNewItemId, id -> BackwardsMappings.itemMappings.getMappedItem(id)); super(protocol, BlockItemPackets1_16::getOldItemId, BlockItemPackets1_16::getNewItemId, id -> BackwardsMappings.itemMappings.getMappedItem(id));
} }
@ -196,6 +199,27 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
// Spawn particle // Spawn particle
blockRewriter.registerSpawnParticle(Type.DOUBLE, 0x24, 0x24, 3, 23, 32, blockRewriter.registerSpawnParticle(Type.DOUBLE, 0x24, 0x24, 3, 23, 32,
BlockItemPackets1_16::getNewParticleId, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM); BlockItemPackets1_16::getNewParticleId, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM);
// Window Property
protocol.registerOutgoing(State.PLAY, 0x16, 0x16, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // Window id
map(Type.SHORT); // Property
map(Type.SHORT); // Value
handler(wrapper -> {
short property = wrapper.get(Type.SHORT, 0);
if (property >= 4 && property <= 6) { // Enchantment id
short enchantmentId = wrapper.get(Type.SHORT, 1);
if (enchantmentId > 11) { // soul_speed
wrapper.set(Type.SHORT, 1, --enchantmentId);
} else if (enchantmentId == 11) {
wrapper.set(Type.SHORT, 1, (short) 9);
}
}
});
}
});
} }
public static int getNewParticleId(int id) { public static int getNewParticleId(int id) {
@ -223,14 +247,20 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
return id; return id;
} }
@Override
protected void registerRewrites() {
enchantmentRewriter = new EnchantmentRewriter(nbtTagName);
enchantmentRewriter.registerEnchantment("minecraft:soul_speed", "§7Soul Speed");
}
@Override @Override
public Item handleItemToClient(Item item) { public Item handleItemToClient(Item item) {
if (item == null) return null; if (item == null) return null;
super.handleItemToClient(item); super.handleItemToClient(item);
if (item.getIdentifier() == 771 && item.getTag() != null) { CompoundTag tag = item.getTag();
CompoundTag tag = item.getTag(); if (item.getIdentifier() == 771 && tag != null) {
Tag ownerTag = tag.get("SkullOwner"); Tag ownerTag = tag.get("SkullOwner");
if (ownerTag instanceof CompoundTag) { if (ownerTag instanceof CompoundTag) {
CompoundTag ownerCompundTag = (CompoundTag) ownerTag; CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
@ -241,6 +271,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
} }
} }
} }
enchantmentRewriter.handleToClient(item);
return item; return item;
} }
@ -251,8 +283,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
int identifier = item.getIdentifier(); int identifier = item.getIdentifier();
super.handleItemToServer(item); super.handleItemToServer(item);
if (identifier == 771 && item.getTag() != null) { CompoundTag tag = item.getTag();
CompoundTag tag = item.getTag(); if (identifier == 771 && tag != null) {
Tag ownerTag = tag.get("SkullOwner"); Tag ownerTag = tag.get("SkullOwner");
if (ownerTag instanceof CompoundTag) { if (ownerTag instanceof CompoundTag) {
CompoundTag ownerCompundTag = (CompoundTag) ownerTag; CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
@ -263,6 +295,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
} }
} }
} }
enchantmentRewriter.handleToServer(item);
return item; return item;
} }