Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 08:10:10 +01:00
Replace tag instanceof/unchecked casts with helper methods
Dieser Commit ist enthalten in:
Ursprung
e9c3889c82
Commit
9241213fb5
@ -27,7 +27,7 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class BackwardsProtocol<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>
|
||||
extends AbstractProtocol<CU, CM, SM, SU> {
|
||||
extends AbstractProtocol<CU, CM, SM, SU> {
|
||||
|
||||
protected BackwardsProtocol() {
|
||||
}
|
||||
|
@ -112,11 +112,11 @@ public class EntityData {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EntityData{" +
|
||||
"id=" + id +
|
||||
", mobName='" + key + '\'' +
|
||||
", replacementId=" + replacementId +
|
||||
", defaultMeta=" + defaultMeta +
|
||||
'}';
|
||||
"id=" + id +
|
||||
", mobName='" + key + '\'' +
|
||||
", replacementId=" + replacementId +
|
||||
", defaultMeta=" + defaultMeta +
|
||||
'}';
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
|
@ -43,7 +43,7 @@ public class EntityPositionHandler {
|
||||
|
||||
public void cacheEntityPosition(PacketWrapper wrapper, boolean create, boolean relative) throws Exception {
|
||||
cacheEntityPosition(wrapper,
|
||||
wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), create, relative);
|
||||
wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), create, relative);
|
||||
}
|
||||
|
||||
public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) throws Exception {
|
||||
|
@ -21,7 +21,6 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
@ -57,10 +56,10 @@ public class EnchantmentRewriter {
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return;
|
||||
|
||||
if (tag.get("Enchantments") instanceof ListTag) {
|
||||
if (tag.getListTag("Enchantments") != null) {
|
||||
rewriteEnchantmentsToClient(tag, false);
|
||||
}
|
||||
if (tag.get("StoredEnchantments") instanceof ListTag) {
|
||||
if (tag.getListTag("StoredEnchantments") != null) {
|
||||
rewriteEnchantmentsToClient(tag, true);
|
||||
}
|
||||
}
|
||||
@ -79,17 +78,16 @@ public class EnchantmentRewriter {
|
||||
|
||||
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
|
||||
String key = storedEnchant ? "StoredEnchantments" : "Enchantments";
|
||||
ListTag enchantments = tag.get(key);
|
||||
ListTag enchantments = tag.getListTag(key);
|
||||
List<Tag> loreToAdd = new ArrayList<>();
|
||||
boolean changed = false;
|
||||
|
||||
Iterator<Tag> iterator = enchantments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
CompoundTag enchantmentEntry = (CompoundTag) iterator.next();
|
||||
Tag idTag = enchantmentEntry.get("id");
|
||||
if (!(idTag instanceof StringTag)) continue;
|
||||
StringTag idTag = enchantmentEntry.getStringTag("id");
|
||||
|
||||
String enchantmentId = ((StringTag) idTag).getValue();
|
||||
String enchantmentId = idTag.getValue();
|
||||
String remappedName = enchantmentMappings.get(enchantmentId);
|
||||
if (remappedName != null) {
|
||||
if (!changed) {
|
||||
@ -100,7 +98,8 @@ public class EnchantmentRewriter {
|
||||
|
||||
iterator.remove();
|
||||
|
||||
int level = ((NumberTag) enchantmentEntry.get("lvl")).asInt();
|
||||
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
|
||||
int level = levelTag != null ? levelTag.asInt() : 1;
|
||||
String loreValue = remappedName + " " + getRomanNumber(level);
|
||||
if (jsonFormat) {
|
||||
loreValue = ComponentUtil.legacyToJsonString(loreValue);
|
||||
@ -112,19 +111,19 @@ public class EnchantmentRewriter {
|
||||
|
||||
if (!loreToAdd.isEmpty()) {
|
||||
// Add dummy enchant for the glow effect if there are no actual enchantments left
|
||||
if (!storedEnchant && enchantments.size() == 0) {
|
||||
if (!storedEnchant && enchantments.isEmpty()) {
|
||||
CompoundTag dummyEnchantment = new CompoundTag();
|
||||
dummyEnchantment.put("id", new StringTag());
|
||||
dummyEnchantment.put("lvl", new ShortTag((short) 0));
|
||||
dummyEnchantment.putString("id", "");
|
||||
dummyEnchantment.putShort("lvl", (short) 0);
|
||||
enchantments.add(dummyEnchantment);
|
||||
}
|
||||
|
||||
CompoundTag display = tag.get("display");
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
if (display == null) {
|
||||
tag.put("display", display = new CompoundTag());
|
||||
}
|
||||
|
||||
ListTag loreTag = display.get("Lore");
|
||||
ListTag loreTag = display.getListTag("Lore");
|
||||
if (loreTag == null) {
|
||||
display.put("Lore", loreTag = new ListTag(StringTag.class));
|
||||
} else {
|
||||
|
@ -177,12 +177,12 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
||||
}
|
||||
|
||||
public void registerMetaTypeHandler(
|
||||
@Nullable MetaType itemType,
|
||||
@Nullable MetaType blockStateType,
|
||||
@Nullable MetaType optionalBlockStateType,
|
||||
@Nullable MetaType particleType,
|
||||
@Nullable MetaType componentType,
|
||||
@Nullable MetaType optionalComponentType
|
||||
@Nullable MetaType itemType,
|
||||
@Nullable MetaType blockStateType,
|
||||
@Nullable MetaType optionalBlockStateType,
|
||||
@Nullable MetaType particleType,
|
||||
@Nullable MetaType componentType,
|
||||
@Nullable MetaType optionalComponentType
|
||||
) {
|
||||
filter().handler((event, meta) -> {
|
||||
MetaType type = meta.metaType();
|
||||
|
@ -34,7 +34,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
|
||||
|
||||
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
|
||||
super(protocol, itemType, itemArrayType, true);
|
||||
@ -46,25 +46,23 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
return null;
|
||||
}
|
||||
|
||||
CompoundTag display = item.tag() != null ? item.tag().get("display") : null;
|
||||
CompoundTag display = item.tag() != null ? item.tag().getCompoundTag("display") : null;
|
||||
if (protocol.getTranslatableRewriter() != null && display != null) {
|
||||
// Handle name and lore components
|
||||
Tag name = display.get("Name");
|
||||
if (name instanceof StringTag) {
|
||||
StringTag nameStringTag = (StringTag) name;
|
||||
String newValue = protocol.getTranslatableRewriter().processText(nameStringTag.getValue()).toString();
|
||||
StringTag name = display.getStringTag("Name");
|
||||
if (name != null) {
|
||||
String newValue = protocol.getTranslatableRewriter().processText(name.getValue()).toString();
|
||||
if (!newValue.equals(name.getValue())) {
|
||||
saveStringTag(display, nameStringTag, "Name");
|
||||
saveStringTag(display, name, "Name");
|
||||
}
|
||||
|
||||
nameStringTag.setValue(newValue);
|
||||
name.setValue(newValue);
|
||||
}
|
||||
|
||||
Tag lore = display.get("Lore");
|
||||
if (lore instanceof ListTag) {
|
||||
ListTag loreListTag = (ListTag) lore;
|
||||
ListTag lore = display.getListTag("Lore");
|
||||
if (lore != null) {
|
||||
boolean changed = false;
|
||||
for (Tag loreEntryTag : loreListTag) {
|
||||
for (Tag loreEntryTag : lore) {
|
||||
if (!(loreEntryTag instanceof StringTag)) {
|
||||
continue;
|
||||
}
|
||||
@ -74,7 +72,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
if (!changed && !newValue.equals(loreEntry.getValue())) {
|
||||
// Backup original lore before doing any modifications
|
||||
changed = true;
|
||||
saveListTag(display, loreListTag, "Lore");
|
||||
saveListTag(display, lore, "Lore");
|
||||
}
|
||||
|
||||
loreEntry.setValue(newValue);
|
||||
@ -93,12 +91,12 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
}
|
||||
|
||||
// Save original id, set remapped id
|
||||
item.tag().put(nbtTagName + "|id", new IntTag(item.identifier()));
|
||||
item.tag().putInt(nbtTagName + "|id", item.identifier());
|
||||
item.setIdentifier(data.getId());
|
||||
|
||||
// Add custom model data
|
||||
if (data.customModelData() != null && !item.tag().contains("CustomModelData")) {
|
||||
item.tag().put("CustomModelData", new IntTag(data.customModelData()));
|
||||
item.tag().putInt("CustomModelData", data.customModelData());
|
||||
}
|
||||
|
||||
// Set custom name - only done if there is no original one
|
||||
@ -118,9 +116,9 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
|
||||
super.handleItemToServer(item);
|
||||
if (item.tag() != null) {
|
||||
IntTag originalId = item.tag().remove(nbtTagName + "|id");
|
||||
if (originalId != null) {
|
||||
item.setIdentifier(originalId.asInt());
|
||||
Tag originalId = item.tag().remove(nbtTagName + "|id");
|
||||
if (originalId instanceof IntTag) {
|
||||
item.setIdentifier(((IntTag) originalId).asInt());
|
||||
}
|
||||
}
|
||||
return item;
|
||||
|
@ -30,7 +30,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
|
||||
|
||||
protected final String nbtTagName;
|
||||
protected final boolean jsonNameFormat;
|
||||
@ -58,7 +58,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
// Multiple places might try to backup data
|
||||
String backupName = nbtTagName + "|o" + name;
|
||||
if (!displayTag.contains(backupName)) {
|
||||
displayTag.put(backupName, new StringTag(original.getValue()));
|
||||
displayTag.putString(backupName, original.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
protected void restoreDisplayTag(Item item) {
|
||||
if (item.tag() == null) return;
|
||||
|
||||
CompoundTag display = item.tag().get("display");
|
||||
CompoundTag display = item.tag().getCompoundTag("display");
|
||||
if (display != null) {
|
||||
// Remove custom name / restore original name
|
||||
if (display.remove(nbtTagName + "|customName") != null) {
|
||||
@ -94,16 +94,16 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
}
|
||||
|
||||
protected void restoreStringTag(CompoundTag tag, String tagName) {
|
||||
StringTag original = tag.remove(nbtTagName + "|o" + tagName);
|
||||
if (original != null) {
|
||||
tag.put(tagName, new StringTag(original.getValue()));
|
||||
Tag original = tag.remove(nbtTagName + "|o" + tagName);
|
||||
if (original instanceof StringTag) {
|
||||
tag.putString(tagName, ((StringTag) original).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreListTag(CompoundTag tag, String tagName) {
|
||||
ListTag original = tag.remove(nbtTagName + "|o" + tagName);
|
||||
if (original != null) {
|
||||
tag.put(tagName, new ListTag(original.getValue()));
|
||||
Tag original = tag.remove(nbtTagName + "|o" + tagName);
|
||||
if (original instanceof ListTag) {
|
||||
tag.put(tagName, new ListTag(((ListTag) original).getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,17 +38,15 @@ import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
|
||||
|
||||
private static final Map<String, Int2ObjectMap<MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>();
|
||||
protected final Int2ObjectMap<MappedLegacyBlockItem> replacementData; // Raw id -> mapped data
|
||||
@ -134,21 +132,22 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
item.setTag(new CompoundTag());
|
||||
}
|
||||
|
||||
CompoundTag display = item.tag().get("display");
|
||||
CompoundTag display = item.tag().getCompoundTag("display");
|
||||
if (display == null) {
|
||||
item.tag().put("display", display = new CompoundTag());
|
||||
}
|
||||
|
||||
StringTag nameTag = display.get("Name");
|
||||
StringTag nameTag = display.getStringTag("Name");
|
||||
if (nameTag == null) {
|
||||
display.put("Name", nameTag = new StringTag(data.getName()));
|
||||
nameTag = new StringTag(data.getName());
|
||||
display.put("Name", nameTag);
|
||||
display.put(nbtTagName + "|customName", new ByteTag());
|
||||
}
|
||||
|
||||
// Handle colors
|
||||
String value = nameTag.getValue();
|
||||
if (value.contains("%vb_color%")) {
|
||||
display.put("Name", new StringTag(value.replace("%vb_color%", BlockColors.get(originalData))));
|
||||
display.putString("Name", value.replace("%vb_color%", BlockColors.get(originalData)));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
@ -190,17 +189,16 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
// Map Block Entities
|
||||
Map<Pos, CompoundTag> tags = new HashMap<>();
|
||||
for (CompoundTag tag : chunk.getBlockEntities()) {
|
||||
Tag xTag;
|
||||
Tag yTag;
|
||||
Tag zTag;
|
||||
if ((xTag = tag.get("x")) == null || (yTag = tag.get("y")) == null || (zTag = tag.get("z")) == null) {
|
||||
NumberTag xTag;
|
||||
NumberTag yTag;
|
||||
NumberTag zTag;
|
||||
if ((xTag = tag.getNumberTag("x")) == null
|
||||
|| (yTag = tag.getNumberTag("y")) == null
|
||||
|| (zTag = tag.getNumberTag("z")) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Pos pos = new Pos(
|
||||
((NumberTag) xTag).asInt() & 0xF,
|
||||
((NumberTag) yTag).asInt(),
|
||||
((NumberTag) zTag).asInt() & 0xF);
|
||||
Pos pos = new Pos(xTag.asInt() & 0xF, yTag.asInt(), zTag.asInt() & 0xF);
|
||||
tags.put(pos, tag);
|
||||
|
||||
// Handle given Block Entities
|
||||
@ -263,9 +261,9 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
if (tags.containsKey(pos)) continue;
|
||||
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("x", new IntTag(x + (chunk.getX() << 4)));
|
||||
tag.put("y", new IntTag(y + (i << 4)));
|
||||
tag.put("z", new IntTag(z + (chunk.getZ() << 4)));
|
||||
tag.putInt("x", x + (chunk.getX() << 4));
|
||||
tag.putInt("y", y + (i << 4));
|
||||
tag.putInt("z", z + (chunk.getZ() << 4));
|
||||
|
||||
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
|
||||
chunk.getBlockEntities().add(tag);
|
||||
@ -277,9 +275,10 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
protected CompoundTag getNamedTag(String text) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("display", new CompoundTag());
|
||||
CompoundTag displayTag = new CompoundTag();
|
||||
tag.put("display", displayTag);
|
||||
text = "§r" + text;
|
||||
((CompoundTag) tag.get("display")).put("Name", new StringTag(jsonNameFormat ? ComponentUtil.legacyToJsonString(text) : text));
|
||||
displayTag.putString("Name", jsonNameFormat ? ComponentUtil.legacyToJsonString(text) : text);
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import java.util.ArrayList;
|
||||
@ -48,18 +47,24 @@ public class LegacyEnchantmentRewriter {
|
||||
|
||||
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
|
||||
String key = storedEnchant ? "StoredEnchantments" : "ench";
|
||||
ListTag enchantments = tag.get(key);
|
||||
ListTag enchantments = tag.getListTag(key);
|
||||
ListTag remappedEnchantments = new ListTag(CompoundTag.class);
|
||||
List<Tag> lore = new ArrayList<>();
|
||||
for (Tag enchantmentEntry : enchantments.copy()) {
|
||||
Tag idTag = ((CompoundTag) enchantmentEntry).get("id");
|
||||
if (!(enchantmentEntry instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
|
||||
NumberTag idTag = entryTag.getNumberTag("id");
|
||||
if (idTag == null) continue;
|
||||
|
||||
short newId = ((NumberTag) idTag).asShort();
|
||||
short newId = idTag.asShort();
|
||||
String enchantmentName = enchantmentMappings.get(newId);
|
||||
if (enchantmentName != null) {
|
||||
enchantments.remove(enchantmentEntry);
|
||||
short level = ((NumberTag) ((CompoundTag) enchantmentEntry).get("lvl")).asShort();
|
||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
||||
short level = levelTag != null ? levelTag.asShort() : 1;
|
||||
if (hideLevelForEnchants != null && hideLevelForEnchants.contains(newId)) {
|
||||
lore.add(new StringTag(enchantmentName));
|
||||
} else {
|
||||
@ -69,33 +74,32 @@ public class LegacyEnchantmentRewriter {
|
||||
}
|
||||
}
|
||||
if (!lore.isEmpty()) {
|
||||
if (!storedEnchant && enchantments.size() == 0) {
|
||||
if (!storedEnchant && enchantments.isEmpty()) {
|
||||
CompoundTag dummyEnchantment = new CompoundTag();
|
||||
dummyEnchantment.put("id", new ShortTag((short) 0));
|
||||
dummyEnchantment.put("lvl", new ShortTag((short) 0));
|
||||
dummyEnchantment.putShort("id", (short) 0);
|
||||
dummyEnchantment.putShort("lvl", (short) 0);
|
||||
enchantments.add(dummyEnchantment);
|
||||
|
||||
tag.put(nbtTagName + "|dummyEnchant", new ByteTag());
|
||||
|
||||
IntTag hideFlags = tag.get("HideFlags");
|
||||
NumberTag hideFlags = tag.getNumberTag("HideFlags");
|
||||
if (hideFlags == null) {
|
||||
hideFlags = new IntTag();
|
||||
} else {
|
||||
tag.put(nbtTagName + "|oldHideFlags", new IntTag(hideFlags.asByte()));
|
||||
tag.putInt(nbtTagName + "|oldHideFlags", hideFlags.asByte());
|
||||
}
|
||||
|
||||
int flags = hideFlags.asByte() | 1;
|
||||
hideFlags.setValue(flags);
|
||||
tag.put("HideFlags", hideFlags);
|
||||
tag.putInt("HideFlags", flags);
|
||||
}
|
||||
|
||||
tag.put(nbtTagName + "|" + key, remappedEnchantments);
|
||||
|
||||
CompoundTag display = tag.get("display");
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
if (display == null) {
|
||||
tag.put("display", display = new CompoundTag());
|
||||
}
|
||||
ListTag loreTag = display.get("Lore");
|
||||
ListTag loreTag = display.getListTag("Lore");
|
||||
if (loreTag == null) {
|
||||
display.put("Lore", loreTag = new ListTag(StringTag.class));
|
||||
}
|
||||
@ -108,38 +112,45 @@ public class LegacyEnchantmentRewriter {
|
||||
public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) {
|
||||
String key = storedEnchant ? "StoredEnchantments" : "ench";
|
||||
ListTag remappedEnchantments = tag.remove(nbtTagName + "|" + key);
|
||||
ListTag enchantments = tag.get(key);
|
||||
ListTag enchantments = tag.getListTag(key);
|
||||
if (enchantments == null) {
|
||||
enchantments = new ListTag(CompoundTag.class);
|
||||
}
|
||||
|
||||
if (!storedEnchant && tag.remove(nbtTagName + "|dummyEnchant") != null) {
|
||||
for (Tag enchantment : enchantments.copy()) {
|
||||
short id = ((NumberTag) ((CompoundTag) enchantment).get("id")).asShort();
|
||||
short level = ((NumberTag) ((CompoundTag) enchantment).get("lvl")).asShort();
|
||||
if (!(enchantment instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CompoundTag entryTag = (CompoundTag) enchantment;
|
||||
NumberTag idTag = entryTag.getNumberTag("id");
|
||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
||||
short id = idTag != null ? idTag.asShort() : 0;
|
||||
short level = levelTag != null ? levelTag.asShort() : 0;
|
||||
if (id == 0 && level == 0) {
|
||||
enchantments.remove(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
IntTag hideFlags = tag.remove(nbtTagName + "|oldHideFlags");
|
||||
if (hideFlags != null) {
|
||||
tag.put("HideFlags", new IntTag(hideFlags.asByte()));
|
||||
Tag hideFlags = tag.remove(nbtTagName + "|oldHideFlags");
|
||||
if (hideFlags instanceof IntTag) {
|
||||
tag.putInt("HideFlags", ((IntTag) hideFlags).asByte());
|
||||
} else {
|
||||
tag.remove("HideFlags");
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag display = tag.get("display");
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
// A few null checks just to be safe, though they shouldn't actually be
|
||||
ListTag lore = display != null ? display.get("Lore") : null;
|
||||
ListTag lore = display != null ? display.getListTag("Lore") : null;
|
||||
for (Tag enchantment : remappedEnchantments.copy()) {
|
||||
enchantments.add(enchantment);
|
||||
if (lore != null && lore.size() != 0) {
|
||||
if (lore != null && !lore.isEmpty()) {
|
||||
lore.remove(lore.get(0));
|
||||
}
|
||||
}
|
||||
if (lore != null && lore.size() == 0) {
|
||||
if (lore != null && lore.isEmpty()) {
|
||||
display.remove("Lore");
|
||||
if (display.isEmpty()) {
|
||||
tag.remove("display");
|
||||
|
@ -33,15 +33,11 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_11to1_10.EntityIdRewriter;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
@ -181,12 +177,12 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
|
||||
// only patch it for signs for now
|
||||
for (CompoundTag tag : chunk.getBlockEntities()) {
|
||||
Tag idTag = tag.get("id");
|
||||
if (!(idTag instanceof StringTag)) continue;
|
||||
StringTag idTag = tag.getStringTag("id");
|
||||
if (idTag == null) continue;
|
||||
|
||||
String id = (String) idTag.getValue();
|
||||
String id = idTag.getValue();
|
||||
if (id.equals("minecraft:sign")) {
|
||||
((StringTag) idTag).setValue("Sign");
|
||||
idTag.setValue("Sign");
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -327,10 +323,10 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
// Rewrite spawn eggs (id checks are done in the method itself)
|
||||
EntityIdRewriter.toClientItem(item, true);
|
||||
|
||||
if (tag.get("ench") instanceof ListTag) {
|
||||
if (tag.getListTag("ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
|
||||
}
|
||||
if (tag.get("StoredEnchantments") instanceof ListTag) {
|
||||
if (tag.getListTag("StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
|
||||
}
|
||||
return item;
|
||||
@ -347,10 +343,10 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
// Rewrite spawn eggs (id checks are done in the method itself)
|
||||
EntityIdRewriter.toServerItem(item, true);
|
||||
|
||||
if (tag.contains(nbtTagName + "|ench")) {
|
||||
if (tag.getListTag(nbtTagName + "|ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
|
||||
}
|
||||
if (tag.contains(nbtTagName + "|StoredEnchantments")) {
|
||||
if (tag.getListTag(nbtTagName + "|StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
|
||||
}
|
||||
return item;
|
||||
|
@ -26,9 +26,9 @@ import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_1
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
|
@ -82,8 +82,8 @@ public class ShoulderTracker extends StoredObject {
|
||||
|
||||
for (String s : array) {
|
||||
builder.append(s.substring(0, 1).toUpperCase())
|
||||
.append(s.substring(1))
|
||||
.append(" ");
|
||||
.append(s.substring(1))
|
||||
.append(" ");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
|
@ -276,7 +276,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
// Restore the removed long array tags
|
||||
for (Map.Entry<String, Tag> entry : backupTag) {
|
||||
if (entry.getValue() instanceof CompoundTag) {
|
||||
CompoundTag nestedTag = compoundTag.get(entry.getKey());
|
||||
CompoundTag nestedTag = compoundTag.getCompoundTag(entry.getKey());
|
||||
handleNbtToServer(nestedTag, (CompoundTag) entry.getValue());
|
||||
} else {
|
||||
compoundTag.put(entry.getKey(), fromIntArrayTag((IntArrayTag) entry.getValue()));
|
||||
|
@ -24,11 +24,10 @@ import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStor
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
@ -271,8 +270,8 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
if (tag.isEmpty() && tracker.getLeftShoulder() != null) {
|
||||
tracker.setLeftShoulder(null);
|
||||
tracker.update();
|
||||
} else if (tag.contains("id") && event.entityId() == tracker.getEntityId()) {
|
||||
String id = (String) tag.get("id").getValue();
|
||||
} else if (tag.getStringTag("id") != null && event.entityId() == tracker.getEntityId()) {
|
||||
String id = tag.getStringTag("id").getValue();
|
||||
if (tracker.getLeftShoulder() == null || !tracker.getLeftShoulder().equals(id)) {
|
||||
tracker.setLeftShoulder(id);
|
||||
tracker.update();
|
||||
@ -290,8 +289,8 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
if (tag.isEmpty() && tracker.getRightShoulder() != null) {
|
||||
tracker.setRightShoulder(null);
|
||||
tracker.update();
|
||||
} else if (tag.contains("id") && event.entityId() == tracker.getEntityId()) {
|
||||
String id = (String) tag.get("id").getValue();
|
||||
} else if (tag.getStringTag("id") != null && event.entityId() == tracker.getEntityId()) {
|
||||
String id = tag.getStringTag("id").getValue();
|
||||
if (tracker.getRightShoulder() == null || !tracker.getRightShoulder().equals(id)) {
|
||||
tracker.setRightShoulder(id);
|
||||
tracker.update();
|
||||
|
@ -20,8 +20,8 @@ package com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
|
@ -25,7 +25,6 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
|
||||
@ -97,10 +96,10 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
if (tag.get("ench") instanceof ListTag) {
|
||||
if (tag.getListTag("ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
|
||||
}
|
||||
if (tag.get("StoredEnchantments") instanceof ListTag) {
|
||||
if (tag.getListTag("StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
|
||||
}
|
||||
return item;
|
||||
@ -114,10 +113,10 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
if (tag.contains(nbtTagName + "|ench")) {
|
||||
if (tag.getListTag(nbtTagName + "|ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
|
||||
}
|
||||
if (tag.contains(nbtTagName + "|StoredEnchantments")) {
|
||||
if (tag.getListTag(nbtTagName + "|StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
|
||||
}
|
||||
return item;
|
||||
|
@ -22,8 +22,8 @@ import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
|
||||
public class BannerHandler implements BackwardsBlockEntityHandler {
|
||||
@ -38,24 +38,25 @@ public class BannerHandler implements BackwardsBlockEntityHandler {
|
||||
// Normal banners
|
||||
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
|
||||
int color = (blockId - BANNER_START) >> 4;
|
||||
tag.put("Base", new IntTag((15 - color)));
|
||||
tag.putInt("Base", 15 - color);
|
||||
}
|
||||
// Wall banners
|
||||
else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) {
|
||||
int color = (blockId - WALL_BANNER_START) >> 2;
|
||||
tag.put("Base", new IntTag((15 - color)));
|
||||
tag.putInt("Base", 15 - color);
|
||||
} else {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
|
||||
}
|
||||
|
||||
// Invert colors
|
||||
Tag patternsTag = tag.get("Patterns");
|
||||
if (patternsTag instanceof ListTag) {
|
||||
for (Tag pattern : (ListTag) patternsTag) {
|
||||
ListTag patternsTag = tag.getListTag("Patterns");
|
||||
if (patternsTag != null) {
|
||||
for (Tag pattern : patternsTag) {
|
||||
if (!(pattern instanceof CompoundTag)) continue;
|
||||
|
||||
IntTag c = ((CompoundTag) pattern).get("Color");
|
||||
c.setValue(15 - c.asInt()); // Invert color id
|
||||
CompoundTag patternTag = (CompoundTag) pattern;
|
||||
NumberTag colorTag = patternTag.getNumberTag("Color");
|
||||
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
|
||||
public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
|
||||
|
||||
@ -30,7 +29,7 @@ public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEn
|
||||
int offset = blockId - 748;
|
||||
int color = offset >> 4;
|
||||
|
||||
tag.put("color", new IntTag(color));
|
||||
tag.putInt("color", color);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
@ -23,8 +23,6 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
|
||||
@ -75,8 +73,8 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
|
||||
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
|
||||
Pair<String, Byte> item = getOrDefault(blockId);
|
||||
|
||||
tag.put("Item", new StringTag(item.key()));
|
||||
tag.put("Data", new IntTag(item.value()));
|
||||
tag.putString("Item", item.key());
|
||||
tag.putInt("Data", item.value());
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
@ -22,21 +22,22 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.Backw
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
|
||||
|
||||
private final Map<String, Integer> pistonIds = new HashMap<>();
|
||||
private final Object2IntMap<String> pistonIds = new Object2IntOpenHashMap<>();
|
||||
|
||||
public PistonHandler() {
|
||||
pistonIds.defaultReturnValue(-1);
|
||||
if (Via.getConfig().isServersideBlockConnections()) {
|
||||
Map<String, Integer> keyToId = ConnectionData.getKeyToId();
|
||||
for (Map.Entry<String, Integer> entry : keyToId.entrySet()) {
|
||||
@ -77,29 +78,29 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
|
||||
|
||||
@Override
|
||||
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
|
||||
CompoundTag blockState = tag.get("blockState");
|
||||
CompoundTag blockState = tag.getCompoundTag("blockState");
|
||||
if (blockState == null) return tag;
|
||||
|
||||
String dataFromTag = getDataFromTag(blockState);
|
||||
if (dataFromTag == null) return tag;
|
||||
|
||||
Integer id = pistonIds.get(dataFromTag);
|
||||
if (id == null) {
|
||||
int id = pistonIds.getInt(dataFromTag);
|
||||
if (id == -1) {
|
||||
//TODO see why this could be null and if this is bad
|
||||
return tag;
|
||||
}
|
||||
|
||||
tag.put("blockId", new IntTag(id >> 4));
|
||||
tag.put("blockData", new IntTag(id & 15));
|
||||
tag.putInt("blockId", id >> 4);
|
||||
tag.putInt("blockData", id & 15);
|
||||
return tag;
|
||||
}
|
||||
|
||||
// The type hasn't actually been updated in the blockstorage, so we need to construct it
|
||||
private String getDataFromTag(CompoundTag tag) {
|
||||
StringTag name = tag.get("Name");
|
||||
StringTag name = tag.getStringTag("Name");
|
||||
if (name == null) return null;
|
||||
|
||||
CompoundTag properties = tag.get("Properties");
|
||||
CompoundTag properties = tag.getCompoundTag("Properties");
|
||||
if (properties == null) return name.getValue();
|
||||
|
||||
StringJoiner joiner = new StringJoiner(",", name.getValue() + "[", "]");
|
||||
|
@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h
|
||||
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
|
||||
public class SkullHandler implements BackwardsBlockEntityHandler {
|
||||
@ -33,7 +32,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler {
|
||||
byte type = (byte) Math.floor(diff / 20f);
|
||||
|
||||
// Set type
|
||||
tag.put("SkullType", new ByteTag(type));
|
||||
tag.putByte("SkullType", type);
|
||||
|
||||
// Remove wall skulls
|
||||
if (pos < 4) {
|
||||
@ -41,7 +40,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler {
|
||||
}
|
||||
|
||||
// Add rotation for normal skulls
|
||||
tag.put("Rot", new ByteTag((byte) ((pos - 4) & 255)));
|
||||
tag.putByte("Rot", (byte) ((pos - 4) & 255));
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
@ -23,19 +23,16 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.Backw
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
|
||||
public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
|
||||
|
||||
@Override
|
||||
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
|
||||
Tag dataTag = tag.get("SpawnData");
|
||||
if (dataTag instanceof CompoundTag) {
|
||||
CompoundTag data = (CompoundTag) dataTag;
|
||||
Tag idTag = data.get("id");
|
||||
if (idTag instanceof StringTag) {
|
||||
StringTag s = (StringTag) idTag;
|
||||
s.setValue(EntityNameRewrites.rewrite(s.getValue()));
|
||||
CompoundTag dataTag = tag.getCompoundTag("SpawnData");
|
||||
if (dataTag != null) {
|
||||
StringTag idTag = dataTag.getStringTag("id");
|
||||
if (idTag != null) {
|
||||
idTag.setValue(EntityNameRewrites.rewrite(idTag.getValue()));
|
||||
}
|
||||
}
|
||||
return tag;
|
||||
|
@ -19,7 +19,6 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data;
|
||||
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data;
|
||||
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -55,94 +55,94 @@ public class ParticleMapping {
|
||||
};
|
||||
|
||||
particles = new ParticleData[]{
|
||||
rewrite(16), // (0->16) minecraft:ambient_entity_effect -> mobSpellAmbient
|
||||
rewrite(20), // (1->20) minecraft:angry_villager -> angryVillager
|
||||
rewrite(35), // (2->35) minecraft:barrier -> barrier
|
||||
rewrite(37, blockHandler),
|
||||
// (3->37) minecraft:block -> blockcrack
|
||||
rewrite(4), // (4->4) minecraft:bubble -> bubble
|
||||
rewrite(29), // (5->29) minecraft:cloud -> cloud
|
||||
rewrite(9), // (6->9) minecraft:crit -> crit
|
||||
rewrite(44), // (7->44) minecraft:damage_indicator -> damageIndicator
|
||||
rewrite(42), // (8->42) minecraft:dragon_breath -> dragonbreath
|
||||
rewrite(19), // (9->19) minecraft:dripping_lava -> dripLava
|
||||
rewrite(18), // (10->18) minecraft:dripping_water -> dripWater
|
||||
rewrite(30, new ParticleHandler() {
|
||||
@Override
|
||||
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
||||
float r = wrapper.read(Type.FLOAT);
|
||||
float g = wrapper.read(Type.FLOAT);
|
||||
float b = wrapper.read(Type.FLOAT);
|
||||
float scale = wrapper.read(Type.FLOAT);
|
||||
rewrite(16), // (0->16) minecraft:ambient_entity_effect -> mobSpellAmbient
|
||||
rewrite(20), // (1->20) minecraft:angry_villager -> angryVillager
|
||||
rewrite(35), // (2->35) minecraft:barrier -> barrier
|
||||
rewrite(37, blockHandler),
|
||||
// (3->37) minecraft:block -> blockcrack
|
||||
rewrite(4), // (4->4) minecraft:bubble -> bubble
|
||||
rewrite(29), // (5->29) minecraft:cloud -> cloud
|
||||
rewrite(9), // (6->9) minecraft:crit -> crit
|
||||
rewrite(44), // (7->44) minecraft:damage_indicator -> damageIndicator
|
||||
rewrite(42), // (8->42) minecraft:dragon_breath -> dragonbreath
|
||||
rewrite(19), // (9->19) minecraft:dripping_lava -> dripLava
|
||||
rewrite(18), // (10->18) minecraft:dripping_water -> dripWater
|
||||
rewrite(30, new ParticleHandler() {
|
||||
@Override
|
||||
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
||||
float r = wrapper.read(Type.FLOAT);
|
||||
float g = wrapper.read(Type.FLOAT);
|
||||
float b = wrapper.read(Type.FLOAT);
|
||||
float scale = wrapper.read(Type.FLOAT);
|
||||
|
||||
wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3
|
||||
wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4
|
||||
wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5
|
||||
wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6
|
||||
wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle
|
||||
wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3
|
||||
wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4
|
||||
wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5
|
||||
wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6
|
||||
wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) {
|
||||
return null;
|
||||
}
|
||||
}), // (11->30) minecraft:dust -> reddust
|
||||
rewrite(13), // (12->13) minecraft:effect -> spell
|
||||
rewrite(41), // (13->41) minecraft:elder_guardian -> mobappearance
|
||||
rewrite(10), // (14->10) minecraft:enchanted_hit -> magicCrit
|
||||
rewrite(25), // (15->25) minecraft:enchant -> enchantmenttable
|
||||
rewrite(43), // (16->43) minecraft:end_rod -> endRod
|
||||
rewrite(15), // (17->15) minecraft:entity_effect -> mobSpell
|
||||
rewrite(2), // (18->2) minecraft:explosion_emitter -> hugeexplosion
|
||||
rewrite(1), // (19->1) minecraft:explosion -> largeexplode
|
||||
rewrite(46, blockHandler),
|
||||
// (20->46) minecraft:falling_dust -> fallingdust
|
||||
rewrite(3), // (21->3) minecraft:firework -> fireworksSpark
|
||||
rewrite(6), // (22->6) minecraft:fishing -> wake
|
||||
rewrite(26), // (23->26) minecraft:flame -> flame
|
||||
rewrite(21), // (24->21) minecraft:happy_villager -> happyVillager
|
||||
rewrite(34), // (25->34) minecraft:heart -> heart
|
||||
rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell
|
||||
rewrite(36, new ParticleHandler() {
|
||||
@Override
|
||||
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
||||
return rewrite(protocol, wrapper.read(Type.ITEM1_13));
|
||||
}
|
||||
@Override
|
||||
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) {
|
||||
return null;
|
||||
}
|
||||
}), // (11->30) minecraft:dust -> reddust
|
||||
rewrite(13), // (12->13) minecraft:effect -> spell
|
||||
rewrite(41), // (13->41) minecraft:elder_guardian -> mobappearance
|
||||
rewrite(10), // (14->10) minecraft:enchanted_hit -> magicCrit
|
||||
rewrite(25), // (15->25) minecraft:enchant -> enchantmenttable
|
||||
rewrite(43), // (16->43) minecraft:end_rod -> endRod
|
||||
rewrite(15), // (17->15) minecraft:entity_effect -> mobSpell
|
||||
rewrite(2), // (18->2) minecraft:explosion_emitter -> hugeexplosion
|
||||
rewrite(1), // (19->1) minecraft:explosion -> largeexplode
|
||||
rewrite(46, blockHandler),
|
||||
// (20->46) minecraft:falling_dust -> fallingdust
|
||||
rewrite(3), // (21->3) minecraft:firework -> fireworksSpark
|
||||
rewrite(6), // (22->6) minecraft:fishing -> wake
|
||||
rewrite(26), // (23->26) minecraft:flame -> flame
|
||||
rewrite(21), // (24->21) minecraft:happy_villager -> happyVillager
|
||||
rewrite(34), // (25->34) minecraft:heart -> heart
|
||||
rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell
|
||||
rewrite(36, new ParticleHandler() {
|
||||
@Override
|
||||
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
|
||||
return rewrite(protocol, wrapper.read(Type.ITEM1_13));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) {
|
||||
return rewrite(protocol, (Item) data.get(0).getValue());
|
||||
}
|
||||
@Override
|
||||
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) {
|
||||
return rewrite(protocol, (Item) data.get(0).getValue());
|
||||
}
|
||||
|
||||
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) {
|
||||
Item item = protocol.getItemRewriter().handleItemToClient(newItem);
|
||||
return new int[]{item.identifier(), item.data()};
|
||||
}
|
||||
}), // (27->36) minecraft:item -> iconcrack
|
||||
rewrite(33), // (28->33) minecraft:item_slime -> slime
|
||||
rewrite(31), // (29->31) minecraft:item_snowball -> snowballpoof
|
||||
rewrite(12), // (30->12) minecraft:large_smoke -> largesmoke
|
||||
rewrite(27), // (31->27) minecraft:lava -> lava
|
||||
rewrite(22), // (32->22) minecraft:mycelium -> townaura
|
||||
rewrite(23), // (33->23) minecraft:note -> note
|
||||
rewrite(0), // (34->0) minecraft:poof -> explode
|
||||
rewrite(24), // (35->24) minecraft:portal -> portal
|
||||
rewrite(39), // (36->39) minecraft:rain -> droplet
|
||||
rewrite(11), // (37->11) minecraft:smoke -> smoke
|
||||
rewrite(48), // (38->48) minecraft:spit -> spit
|
||||
rewrite(12), // (39->-1) minecraft:squid_ink -> squid_ink -> large_smoke
|
||||
rewrite(45), // (40->45) minecraft:sweep_attack -> sweepAttack
|
||||
rewrite(47), // (41->47) minecraft:totem_of_undying -> totem
|
||||
rewrite(7), // (42->7) minecraft:underwater -> suspended
|
||||
rewrite(5), // (43->5) minecraft:splash -> splash
|
||||
rewrite(17), // (44->17) minecraft:witch -> witchMagic
|
||||
rewrite(4), // (45->4) minecraft:bubble_pop -> bubble
|
||||
rewrite(4), // (46->4) minecraft:current_down -> bubble
|
||||
rewrite(4), // (47->4) minecraft:bubble_column_up -> bubble
|
||||
rewrite(18), // (48->-1) minecraft:nautilus -> nautilus -> dripWater
|
||||
rewrite(18), // (49->18) minecraft:dolphin -> dripWater
|
||||
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) {
|
||||
Item item = protocol.getItemRewriter().handleItemToClient(newItem);
|
||||
return new int[]{item.identifier(), item.data()};
|
||||
}
|
||||
}), // (27->36) minecraft:item -> iconcrack
|
||||
rewrite(33), // (28->33) minecraft:item_slime -> slime
|
||||
rewrite(31), // (29->31) minecraft:item_snowball -> snowballpoof
|
||||
rewrite(12), // (30->12) minecraft:large_smoke -> largesmoke
|
||||
rewrite(27), // (31->27) minecraft:lava -> lava
|
||||
rewrite(22), // (32->22) minecraft:mycelium -> townaura
|
||||
rewrite(23), // (33->23) minecraft:note -> note
|
||||
rewrite(0), // (34->0) minecraft:poof -> explode
|
||||
rewrite(24), // (35->24) minecraft:portal -> portal
|
||||
rewrite(39), // (36->39) minecraft:rain -> droplet
|
||||
rewrite(11), // (37->11) minecraft:smoke -> smoke
|
||||
rewrite(48), // (38->48) minecraft:spit -> spit
|
||||
rewrite(12), // (39->-1) minecraft:squid_ink -> squid_ink -> large_smoke
|
||||
rewrite(45), // (40->45) minecraft:sweep_attack -> sweepAttack
|
||||
rewrite(47), // (41->47) minecraft:totem_of_undying -> totem
|
||||
rewrite(7), // (42->7) minecraft:underwater -> suspended
|
||||
rewrite(5), // (43->5) minecraft:splash -> splash
|
||||
rewrite(17), // (44->17) minecraft:witch -> witchMagic
|
||||
rewrite(4), // (45->4) minecraft:bubble_pop -> bubble
|
||||
rewrite(4), // (46->4) minecraft:current_down -> bubble
|
||||
rewrite(4), // (47->4) minecraft:bubble_column_up -> bubble
|
||||
rewrite(18), // (48->-1) minecraft:nautilus -> nautilus -> dripWater
|
||||
rewrite(18), // (49->18) minecraft:dolphin -> dripWater
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
|
||||
@ -58,7 +57,6 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRew
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -78,16 +76,16 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
public static boolean isDamageable(int id) {
|
||||
return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel
|
||||
|| id == 261 // bow
|
||||
|| id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes
|
||||
|| id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe
|
||||
|| id >= 290 && id <= 294 // hoes
|
||||
|| id >= 298 && id <= 317 // armors
|
||||
|| id == 346 // fishing rod
|
||||
|| id == 359 // shears
|
||||
|| id == 398 // carrot on a stick
|
||||
|| id == 442 // shield
|
||||
|| id == 443; // elytra
|
||||
|| id == 261 // bow
|
||||
|| id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes
|
||||
|| id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe
|
||||
|| id >= 290 && id <= 294 // hoes
|
||||
|| id >= 298 && id <= 317 // armors
|
||||
|| id == 346 // fishing rod
|
||||
|| id == 359 // shears
|
||||
|| id == 398 // carrot on a stick
|
||||
|| id == 442 // shield
|
||||
|| id == 443; // elytra
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -171,11 +169,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
|
||||
wrapper.set(Type.NAMED_COMPOUND_TAG, 0,
|
||||
provider.transform(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.POSITION1_8, 0),
|
||||
wrapper.get(Type.NAMED_COMPOUND_TAG, 0)
|
||||
));
|
||||
provider.transform(
|
||||
wrapper.user(),
|
||||
wrapper.get(Type.POSITION1_8, 0),
|
||||
wrapper.get(Type.NAMED_COMPOUND_TAG, 0)
|
||||
));
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -189,7 +187,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
blockStorage.getBlocks().entrySet().removeIf(entry -> {
|
||||
Position position = entry.getKey();
|
||||
return position.x() >= chunkMinX && position.z() >= chunkMinZ
|
||||
&& position.x() <= chunkMaxX && position.z() <= chunkMaxZ;
|
||||
&& position.x() <= chunkMaxX && position.z() <= chunkMaxZ;
|
||||
});
|
||||
});
|
||||
|
||||
@ -235,9 +233,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
int chunkZ = wrapper.get(Type.INT, 1);
|
||||
int block = record.getBlockId();
|
||||
Position position = new Position(
|
||||
record.getSectionX() + (chunkX * 16),
|
||||
record.getY(),
|
||||
record.getSectionZ() + (chunkZ * 16));
|
||||
record.getSectionX() + (chunkX * 16),
|
||||
record.getY(),
|
||||
record.getSectionZ() + (chunkZ * 16));
|
||||
|
||||
// Store if needed
|
||||
storage.checkAndStore(position, block);
|
||||
@ -284,15 +282,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
|
||||
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
|
||||
for (CompoundTag tag : chunk.getBlockEntities()) {
|
||||
Tag idTag = tag.get("id");
|
||||
StringTag idTag = tag.getStringTag("id");
|
||||
if (idTag == null) continue;
|
||||
|
||||
String id = (String) idTag.getValue();
|
||||
String id = idTag.getValue();
|
||||
|
||||
// Ignore if we don't handle it
|
||||
if (!provider.isHandled(id)) continue;
|
||||
|
||||
int sectionIndex = ((NumberTag) tag.get("y")).asInt() >> 4;
|
||||
int sectionIndex = tag.getNumberTag("y").asInt() >> 4;
|
||||
if (sectionIndex < 0 || sectionIndex > 15) {
|
||||
// 1.17 chunks
|
||||
continue;
|
||||
@ -300,9 +298,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
ChunkSection section = chunk.getSections()[sectionIndex];
|
||||
|
||||
int x = ((NumberTag) tag.get("x")).asInt();
|
||||
int y = ((NumberTag) tag.get("y")).asInt();
|
||||
int z = ((NumberTag) tag.get("z")).asInt();
|
||||
int x = tag.getNumberTag("x").asInt();
|
||||
int y = tag.getNumberTag("y").asInt();
|
||||
int z = tag.getNumberTag("z").asInt();
|
||||
Position position = new Position(x, (short) y, z);
|
||||
|
||||
int block = section.palette(PaletteType.BLOCKS).idAt(x & 0xF, y & 0xF, z & 0xF);
|
||||
@ -328,9 +326,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
// Check if the block is a flower
|
||||
if (FlowerPotHandler.isFlowah(block)) {
|
||||
Position pos = new Position(
|
||||
(x + (chunk.getX() << 4)),
|
||||
(short) (y + (i << 4)),
|
||||
(z + (chunk.getZ() << 4))
|
||||
(x + (chunk.getX() << 4)),
|
||||
(short) (y + (i << 4)),
|
||||
(z + (chunk.getZ() << 4))
|
||||
);
|
||||
// Store block
|
||||
storage.checkAndStore(pos, block);
|
||||
@ -508,7 +506,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
// Use tag to get original ID and data
|
||||
Tag originalIdTag;
|
||||
if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) != null) {
|
||||
if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) instanceof NumberTag) {
|
||||
rawId = ((NumberTag) originalIdTag).asInt();
|
||||
gotRawIdFromTag = true;
|
||||
}
|
||||
@ -545,15 +543,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
if (tag != null) {
|
||||
if (isDamageable(item.identifier())) {
|
||||
Tag damageTag = tag.remove("Damage");
|
||||
if (!gotRawIdFromTag && damageTag instanceof IntTag) {
|
||||
item.setData((short) (int) damageTag.getValue());
|
||||
if (!gotRawIdFromTag && damageTag instanceof NumberTag) {
|
||||
item.setData(((NumberTag) damageTag).asShort());
|
||||
}
|
||||
}
|
||||
|
||||
if (item.identifier() == 358) { // map
|
||||
Tag mapTag = tag.remove("map");
|
||||
if (!gotRawIdFromTag && mapTag instanceof IntTag) {
|
||||
item.setData((short) (int) mapTag.getValue());
|
||||
if (!gotRawIdFromTag && mapTag instanceof NumberTag) {
|
||||
item.setData(((NumberTag) mapTag).asShort());
|
||||
}
|
||||
}
|
||||
|
||||
@ -561,11 +559,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
invertShieldAndBannerId(item, tag);
|
||||
|
||||
// Display Name now uses JSON
|
||||
CompoundTag display = tag.get("display");
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
if (display != null) {
|
||||
StringTag name = display.get("Name");
|
||||
StringTag name = display.getStringTag("Name");
|
||||
if (name != null) {
|
||||
display.put(extraNbtTag + "|Name", new StringTag(name.getValue()));
|
||||
display.putString(extraNbtTag + "|Name", name.getValue());
|
||||
name.setValue(protocol.jsonToLegacy(name.getValue()));
|
||||
}
|
||||
}
|
||||
@ -588,7 +586,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
if (!tag.contains("EntityTag")) {
|
||||
CompoundTag entityTag = new CompoundTag();
|
||||
entityTag.put("id", new StringTag(eggEntityId.get()));
|
||||
entityTag.putString("id", eggEntityId.get());
|
||||
tag.put("EntityTag", entityTag);
|
||||
}
|
||||
return 0x17f0000; // 383 << 16;
|
||||
@ -599,8 +597,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
private void rewriteCanPlaceToClient(CompoundTag tag, String tagName) {
|
||||
// The tag was manually created incorrectly so ignore rewriting it
|
||||
if (!(tag.get(tagName) instanceof ListTag)) return;
|
||||
ListTag blockTag = tag.get(tagName);
|
||||
ListTag blockTag = tag.getListTag(tagName);
|
||||
if (blockTag == null) return;
|
||||
|
||||
ListTag newCanPlaceOn = new ListTag(StringTag.class);
|
||||
@ -608,7 +605,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
for (Tag oldTag : blockTag) {
|
||||
Object value = oldTag.getValue();
|
||||
String[] newValues = value instanceof String ?
|
||||
BlockIdData.fallbackReverseMapping.get(Key.stripMinecraftNamespace((String) value)) : null;
|
||||
BlockIdData.fallbackReverseMapping.get(Key.stripMinecraftNamespace((String) value)) : null;
|
||||
if (newValues != null) {
|
||||
for (String newValue : newValues) {
|
||||
newCanPlaceOn.add(new StringTag(newValue));
|
||||
@ -623,7 +620,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
//TODO un-ugly all of this
|
||||
private void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnch) {
|
||||
String key = storedEnch ? "StoredEnchantments" : "Enchantments";
|
||||
ListTag enchantments = tag.get(key);
|
||||
ListTag enchantments = tag.getListTag(key);
|
||||
if (enchantments == null) return;
|
||||
|
||||
ListTag noMapped = new ListTag(CompoundTag.class);
|
||||
@ -631,14 +628,18 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
List<Tag> lore = new ArrayList<>();
|
||||
boolean hasValidEnchants = false;
|
||||
for (Tag enchantmentEntryTag : enchantments.copy()) {
|
||||
CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag;
|
||||
Tag idTag = enchantmentEntry.get("id");
|
||||
if (!(idTag instanceof StringTag)) {
|
||||
if (!(enchantmentEntryTag instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String newId = (String) idTag.getValue();
|
||||
NumberTag levelTag = enchantmentEntry.get("lvl");
|
||||
CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag;
|
||||
StringTag idTag = enchantmentEntry.getStringTag("id");
|
||||
if (idTag == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String newId = idTag.getValue();
|
||||
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
|
||||
if (levelTag == null) {
|
||||
continue;
|
||||
}
|
||||
@ -683,48 +684,47 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
|
||||
CompoundTag newEntry = new CompoundTag();
|
||||
newEntry.put("id", new ShortTag(oldId));
|
||||
newEntry.put("lvl", new ShortTag(level));
|
||||
newEntry.putShort("id", oldId);
|
||||
newEntry.putShort("lvl", level);
|
||||
newEnchantments.add(newEntry);
|
||||
}
|
||||
}
|
||||
|
||||
// Put here to hide empty enchantment from 1.14 rewrites
|
||||
if (!storedEnch && !hasValidEnchants) {
|
||||
IntTag hideFlags = tag.get("HideFlags");
|
||||
NumberTag hideFlags = tag.getNumberTag("HideFlags");
|
||||
if (hideFlags == null) {
|
||||
hideFlags = new IntTag();
|
||||
tag.put(extraNbtTag + "|DummyEnchant", new ByteTag());
|
||||
} else {
|
||||
tag.put(extraNbtTag + "|OldHideFlags", new IntTag(hideFlags.asByte()));
|
||||
tag.putInt(extraNbtTag + "|OldHideFlags", hideFlags.asByte());
|
||||
}
|
||||
|
||||
if (newEnchantments.size() == 0) {
|
||||
if (newEnchantments.isEmpty()) {
|
||||
CompoundTag enchEntry = new CompoundTag();
|
||||
enchEntry.put("id", new ShortTag((short) 0));
|
||||
enchEntry.put("lvl", new ShortTag((short) 0));
|
||||
enchEntry.putShort("id", (short) 0);
|
||||
enchEntry.putShort("lvl", (short) 0);
|
||||
newEnchantments.add(enchEntry);
|
||||
}
|
||||
|
||||
int value = hideFlags.asByte() | 1;
|
||||
hideFlags.setValue(value);
|
||||
tag.put("HideFlags", hideFlags);
|
||||
tag.putInt("HideFlags", value);
|
||||
}
|
||||
|
||||
if (noMapped.size() != 0) {
|
||||
tag.put(extraNbtTag + "|" + key, noMapped);
|
||||
|
||||
if (!lore.isEmpty()) {
|
||||
CompoundTag display = tag.get("display");
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
if (display == null) {
|
||||
tag.put("display", display = new CompoundTag());
|
||||
}
|
||||
|
||||
ListTag loreTag = display.get("Lore");
|
||||
ListTag loreTag = display.getListTag("Lore");
|
||||
if (loreTag == null) {
|
||||
display.put("Lore", loreTag = new ListTag(StringTag.class));
|
||||
tag.put(extraNbtTag + "|DummyLore", new ByteTag());
|
||||
} else if (loreTag.size() != 0) {
|
||||
} else if (!loreTag.isEmpty()) {
|
||||
ListTag oldLore = new ListTag(StringTag.class);
|
||||
for (Tag value : loreTag) {
|
||||
oldLore.add(value.copy());
|
||||
@ -755,11 +755,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
// NBT Additions
|
||||
if (isDamageable(item.identifier())) {
|
||||
if (tag == null) item.setTag(tag = new CompoundTag());
|
||||
tag.put("Damage", new IntTag(item.data()));
|
||||
tag.putInt("Damage", item.data());
|
||||
}
|
||||
if (item.identifier() == 358) { // map
|
||||
if (tag == null) item.setTag(tag = new CompoundTag());
|
||||
tag.put("map", new IntTag(item.data()));
|
||||
tag.putInt("map", item.data());
|
||||
}
|
||||
|
||||
// NBT Changes
|
||||
@ -768,13 +768,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
invertShieldAndBannerId(item, tag);
|
||||
|
||||
// Display Name now uses JSON
|
||||
Tag display = tag.get("display");
|
||||
if (display instanceof CompoundTag) {
|
||||
CompoundTag displayTag = (CompoundTag) display;
|
||||
StringTag name = displayTag.get("Name");
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
if (display != null) {
|
||||
StringTag name = display.getStringTag("Name");
|
||||
if (name != null) {
|
||||
StringTag via = displayTag.remove(extraNbtTag + "|Name");
|
||||
name.setValue(via != null ? via.getValue() : ComponentUtil.legacyToJsonString(name.getValue()));
|
||||
Tag via = display.remove(extraNbtTag + "|Name");
|
||||
name.setValue(via instanceof StringTag ? ((StringTag) via).getValue() : ComponentUtil.legacyToJsonString(name.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -787,9 +786,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
// Handle SpawnEggs
|
||||
if (item.identifier() == 383) {
|
||||
CompoundTag entityTag = tag.get("EntityTag");
|
||||
CompoundTag entityTag = tag.getCompoundTag("EntityTag");
|
||||
StringTag identifier;
|
||||
if (entityTag != null && (identifier = entityTag.get("id")) != null) {
|
||||
if (entityTag != null && (identifier = entityTag.getStringTag("id")) != null) {
|
||||
rawId = SpawnEggRewriter.getSpawnEggId(identifier.getValue());
|
||||
if (rawId == -1) {
|
||||
rawId = 25100288; // Bat fallback
|
||||
@ -823,8 +822,10 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
int newId = -1;
|
||||
if (protocol.getMappingData().getItemMappings().inverse().getNewId(rawId) == -1) {
|
||||
if (!isDamageable(item.identifier()) && item.identifier() != 358) { // Map
|
||||
if (tag == null) item.setTag(tag = new CompoundTag());
|
||||
tag.put(extraNbtTag, new IntTag(originalId)); // Data will be lost, saving original id
|
||||
if (tag == null) {
|
||||
item.setTag(tag = new CompoundTag());
|
||||
}
|
||||
tag.putInt(extraNbtTag, originalId); // Data will be lost, saving original id
|
||||
}
|
||||
|
||||
if (item.identifier() == 229) { // purple shulker box
|
||||
@ -851,11 +852,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
|
||||
private void rewriteCanPlaceToServer(CompoundTag tag, String tagName) {
|
||||
if (!(tag.get(tagName) instanceof ListTag)) return;
|
||||
if (tag.getListTag(tagName) == null) return;
|
||||
|
||||
ListTag blockTag = tag.remove(extraNbtTag + "|" + tagName);
|
||||
if (blockTag != null) {
|
||||
tag.put(tagName, blockTag.copy());
|
||||
} else if ((blockTag = tag.get(tagName)) != null) {
|
||||
} else if ((blockTag = tag.getListTag(tagName)) != null) {
|
||||
ListTag newCanPlaceOn = new ListTag(StringTag.class);
|
||||
for (Tag oldTag : blockTag) {
|
||||
Object value = oldTag.getValue();
|
||||
@ -882,15 +884,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
private void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnch) {
|
||||
String key = storedEnch ? "StoredEnchantments" : "Enchantments";
|
||||
ListTag enchantments = tag.get(storedEnch ? key : "ench");
|
||||
ListTag enchantments = tag.getListTag(storedEnch ? key : "ench");
|
||||
if (enchantments == null) return;
|
||||
|
||||
ListTag newEnchantments = new ListTag(CompoundTag.class);
|
||||
boolean dummyEnchant = false;
|
||||
if (!storedEnch) {
|
||||
IntTag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags");
|
||||
if (hideFlags != null) {
|
||||
tag.put("HideFlags", new IntTag(hideFlags.asByte()));
|
||||
Tag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags");
|
||||
if (hideFlags instanceof IntTag) {
|
||||
tag.putInt("HideFlags", ((NumberTag) hideFlags).asByte());
|
||||
dummyEnchant = true;
|
||||
} else if (tag.remove(extraNbtTag + "|DummyEnchant") != null) {
|
||||
tag.remove("HideFlags");
|
||||
@ -899,42 +901,50 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
|
||||
for (Tag enchEntry : enchantments) {
|
||||
CompoundTag enchantmentEntry = new CompoundTag();
|
||||
short oldId = ((NumberTag) ((CompoundTag) enchEntry).get("id")).asShort();
|
||||
short level = ((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort();
|
||||
if (dummyEnchant && oldId == 0 && level == 0) {
|
||||
continue; //Skip dummy enchatment
|
||||
if (!(enchEntry instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CompoundTag entryTag = (CompoundTag) enchEntry;
|
||||
NumberTag idTag = entryTag.getNumberTag("id");
|
||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
||||
CompoundTag enchantmentEntry = new CompoundTag();
|
||||
short oldId = idTag != null ? idTag.asShort() : 0;
|
||||
short level = levelTag != null ? levelTag.asShort() : 0;
|
||||
if (dummyEnchant && oldId == 0 && level == 0) {
|
||||
continue; // Skip dummy enchatment
|
||||
}
|
||||
|
||||
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
|
||||
if (newId == null) {
|
||||
newId = "viaversion:legacy/" + oldId;
|
||||
}
|
||||
enchantmentEntry.put("id", new StringTag(newId));
|
||||
enchantmentEntry.putString("id", newId);
|
||||
|
||||
enchantmentEntry.put("lvl", new ShortTag(level));
|
||||
enchantmentEntry.putShort("lvl", level);
|
||||
newEnchantments.add(enchantmentEntry);
|
||||
}
|
||||
|
||||
ListTag noMapped = tag.remove(extraNbtTag + "|Enchantments");
|
||||
if (noMapped != null) {
|
||||
for (Tag value : noMapped) {
|
||||
Tag noMapped = tag.remove(extraNbtTag + "|Enchantments");
|
||||
if (noMapped instanceof ListTag) {
|
||||
for (Tag value : ((ListTag) noMapped)) {
|
||||
newEnchantments.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag display = tag.get("display");
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
if (display == null) {
|
||||
tag.put("display", display = new CompoundTag());
|
||||
}
|
||||
|
||||
ListTag oldLore = tag.remove(extraNbtTag + "|OldLore");
|
||||
if (oldLore != null) {
|
||||
ListTag lore = display.get("Lore");
|
||||
Tag oldLore = tag.remove(extraNbtTag + "|OldLore");
|
||||
if (oldLore instanceof ListTag) {
|
||||
ListTag lore = display.getListTag("Lore");
|
||||
if (lore == null) {
|
||||
tag.put("Lore", lore = new ListTag());
|
||||
}
|
||||
|
||||
lore.setValue(oldLore.getValue());
|
||||
lore.setValue(((ListTag) oldLore).getValue());
|
||||
} else if (tag.remove(extraNbtTag + "|DummyLore") != null) {
|
||||
display.remove("Lore");
|
||||
if (display.isEmpty()) {
|
||||
@ -951,24 +961,22 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
private void invertShieldAndBannerId(Item item, CompoundTag tag) {
|
||||
if (item.identifier() != 442 && item.identifier() != 425) return;
|
||||
|
||||
Tag blockEntityTag = tag.get("BlockEntityTag");
|
||||
if (!(blockEntityTag instanceof CompoundTag)) return;
|
||||
CompoundTag blockEntityTag = tag.getCompoundTag("BlockEntityTag");
|
||||
if (blockEntityTag == null) return;
|
||||
|
||||
CompoundTag blockEntityCompoundTag = (CompoundTag) blockEntityTag;
|
||||
Tag base = blockEntityCompoundTag.get("Base");
|
||||
if (base instanceof IntTag) {
|
||||
IntTag baseTag = (IntTag) base;
|
||||
baseTag.setValue(15 - baseTag.asInt()); // invert color id
|
||||
NumberTag base = blockEntityTag.getNumberTag("Base");
|
||||
if (base != null) {
|
||||
blockEntityTag.putInt("Base", 15 - base.asInt()); // Invert color id
|
||||
}
|
||||
|
||||
Tag patterns = blockEntityCompoundTag.get("Patterns");
|
||||
if (patterns instanceof ListTag) {
|
||||
ListTag patternsTag = (ListTag) patterns;
|
||||
for (Tag pattern : patternsTag) {
|
||||
ListTag patterns = blockEntityTag.getListTag("Patterns");
|
||||
if (patterns != null) {
|
||||
for (Tag pattern : patterns) {
|
||||
if (!(pattern instanceof CompoundTag)) continue;
|
||||
|
||||
IntTag colorTag = ((CompoundTag) pattern).get("Color");
|
||||
colorTag.setValue(15 - colorTag.asInt()); // Invert color id
|
||||
CompoundTag patternTag = (CompoundTag) pattern;
|
||||
NumberTag colorTag = patternTag.getNumberTag("Color");
|
||||
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,8 +231,8 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
|
||||
//TODO properly cache and calculate head position?
|
||||
EntityPositionHandler.writeFacingDegrees(positionAndLook, positionStorage.getX(),
|
||||
anchor == 1 ? positionStorage.getY() + 1.62 : positionStorage.getY(),
|
||||
positionStorage.getZ(), x, y, z);
|
||||
anchor == 1 ? positionStorage.getY() + 1.62 : positionStorage.getY(),
|
||||
positionStorage.getZ(), x, y, z);
|
||||
|
||||
positionAndLook.write(Type.BYTE, (byte) 7); // bitfield, 0=absolute, 1=relative - x,y,z relative, yaw,pitch absolute
|
||||
positionAndLook.write(Type.VAR_INT, -1);
|
||||
|
@ -29,9 +29,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -65,12 +63,12 @@ public class BackwardsBlockEntityProvider implements Provider {
|
||||
* @param tag The block entity tag
|
||||
*/
|
||||
public CompoundTag transform(UserConnection user, Position position, CompoundTag tag) throws Exception {
|
||||
final Tag idTag = tag.get("id");
|
||||
if (!(idTag instanceof StringTag)) {
|
||||
final StringTag idTag = tag.getStringTag("id");
|
||||
if (idTag == null) {
|
||||
return tag;
|
||||
}
|
||||
|
||||
String id = (String) idTag.getValue();
|
||||
String id = idTag.getValue();
|
||||
BackwardsBlockEntityHandler handler = handlers.get(id);
|
||||
if (handler == null) {
|
||||
return tag;
|
||||
@ -94,14 +92,15 @@ public class BackwardsBlockEntityProvider implements Provider {
|
||||
*/
|
||||
public CompoundTag transform(UserConnection user, Position position, String id) throws Exception {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("id", new StringTag(id));
|
||||
tag.put("x", new IntTag(Math.toIntExact(position.x())));
|
||||
tag.put("y", new IntTag(Math.toIntExact(position.y())));
|
||||
tag.put("z", new IntTag(Math.toIntExact(position.z())));
|
||||
tag.putString("id", id);
|
||||
tag.putInt("x", Math.toIntExact(position.x()));
|
||||
tag.putInt("y", Math.toIntExact(position.y()));
|
||||
tag.putInt("z", Math.toIntExact(position.z()));
|
||||
|
||||
return this.transform(user, position, tag);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BackwardsBlockEntityHandler {
|
||||
CompoundTag transform(UserConnection user, int blockId, CompoundTag tag);
|
||||
}
|
||||
|
@ -472,8 +472,8 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
// Lore now uses JSON
|
||||
CompoundTag tag = item.tag();
|
||||
CompoundTag display;
|
||||
if (tag != null && (display = tag.get("display")) != null) {
|
||||
ListTag lore = display.get("Lore");
|
||||
if (tag != null && (display = tag.getCompoundTag("display")) != null) {
|
||||
ListTag lore = display.getListTag("Lore");
|
||||
if (lore != null) {
|
||||
saveListTag(display, lore, "Lore");
|
||||
|
||||
@ -500,9 +500,9 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
// Lore now uses JSON
|
||||
CompoundTag tag = item.tag();
|
||||
CompoundTag display;
|
||||
if (tag != null && (display = tag.get("display")) != null) {
|
||||
if (tag != null && (display = tag.getCompoundTag("display")) != null) {
|
||||
// Transform to json if no backup tag is found (else process that in the super method)
|
||||
ListTag lore = display.get("Lore");
|
||||
ListTag lore = display.getListTag("Lore");
|
||||
if (lore != null && !hasBackupTag(display, "Lore")) {
|
||||
for (Tag loreEntry : lore) {
|
||||
if (loreEntry instanceof StringTag) {
|
||||
|
@ -349,7 +349,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
});
|
||||
|
||||
registerMetaTypeHandler(Types1_13_2.META_TYPES.itemType, Types1_13_2.META_TYPES.blockStateType, null, null,
|
||||
Types1_13_2.META_TYPES.componentType, Types1_13_2.META_TYPES.optionalComponentType);
|
||||
Types1_13_2.META_TYPES.componentType, Types1_13_2.META_TYPES.optionalComponentType);
|
||||
|
||||
filter().type(EntityTypes1_14.PILLAGER).cancel(15);
|
||||
|
||||
|
@ -108,7 +108,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
if (ViaBackwards.getConfig().fix1_13FormattedInventoryTitle()) {
|
||||
if (title.isJsonObject() && title.getAsJsonObject().size() == 1
|
||||
&& title.getAsJsonObject().has("translate")) {
|
||||
&& title.getAsJsonObject().has("translate")) {
|
||||
// Hotfix simple translatable components from being converted to legacy text
|
||||
return;
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
@ -193,7 +193,7 @@ public class EntityPackets1_15 extends EntityRewriter<ClientboundPackets1_15, Pr
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, null, Types1_14.META_TYPES.particleType,
|
||||
Types1_14.META_TYPES.componentType, Types1_14.META_TYPES.optionalComponentType);
|
||||
Types1_14.META_TYPES.componentType, Types1_14.META_TYPES.optionalComponentType);
|
||||
|
||||
filter().type(EntityTypes1_15.LIVINGENTITY).removeIndex(12);
|
||||
|
||||
|
@ -19,8 +19,8 @@ package com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
|
@ -28,22 +28,22 @@ import com.viaversion.viaversion.util.ComponentUtil;
|
||||
public class TranslatableRewriter1_16 extends TranslatableRewriter<ClientboundPackets1_16> {
|
||||
|
||||
private static final ChatColor[] COLORS = {
|
||||
new ChatColor("black", 0x000000),
|
||||
new ChatColor("dark_blue", 0x0000aa),
|
||||
new ChatColor("dark_green", 0x00aa00),
|
||||
new ChatColor("dark_aqua", 0x00aaaa),
|
||||
new ChatColor("dark_red", 0xaa0000),
|
||||
new ChatColor("dark_purple", 0xaa00aa),
|
||||
new ChatColor("gold", 0xffaa00),
|
||||
new ChatColor("gray", 0xaaaaaa),
|
||||
new ChatColor("dark_gray", 0x555555),
|
||||
new ChatColor("blue", 0x5555ff),
|
||||
new ChatColor("green", 0x55ff55),
|
||||
new ChatColor("aqua", 0x55ffff),
|
||||
new ChatColor("red", 0xff5555),
|
||||
new ChatColor("light_purple", 0xff55ff),
|
||||
new ChatColor("yellow", 0xffff55),
|
||||
new ChatColor("white", 0xffffff)
|
||||
new ChatColor("black", 0x000000),
|
||||
new ChatColor("dark_blue", 0x0000aa),
|
||||
new ChatColor("dark_green", 0x00aa00),
|
||||
new ChatColor("dark_aqua", 0x00aaaa),
|
||||
new ChatColor("dark_red", 0xaa0000),
|
||||
new ChatColor("dark_purple", 0xaa00aa),
|
||||
new ChatColor("gold", 0xffaa00),
|
||||
new ChatColor("gray", 0xaaaaaa),
|
||||
new ChatColor("dark_gray", 0x555555),
|
||||
new ChatColor("blue", 0x5555ff),
|
||||
new ChatColor("green", 0x55ff55),
|
||||
new ChatColor("aqua", 0x55ffff),
|
||||
new ChatColor("red", 0xff5555),
|
||||
new ChatColor("light_purple", 0xff55ff),
|
||||
new ChatColor("yellow", 0xffff55),
|
||||
new ChatColor("white", 0xffffff)
|
||||
};
|
||||
|
||||
public TranslatableRewriter1_16(Protocol1_15_2To1_16 protocol) {
|
||||
@ -97,8 +97,8 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter<ClientboundPa
|
||||
int gDiff = color.g - g;
|
||||
int bDiff = color.b - b;
|
||||
int diff = ((2 + (rAverage >> 8)) * rDiff * rDiff)
|
||||
+ (4 * gDiff * gDiff)
|
||||
+ ((2 + ((255 - rAverage) >> 8)) * bDiff * bDiff);
|
||||
+ (4 * gDiff * gDiff)
|
||||
+ ((2 + ((255 - rAverage) >> 8)) * bDiff * bDiff);
|
||||
if (closest == null || diff < smallestDiff) {
|
||||
closest = color;
|
||||
smallestDiff = diff;
|
||||
|
@ -252,7 +252,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
|
||||
private void handleBlockEntity(CompoundTag tag) {
|
||||
StringTag idTag = tag.get("id");
|
||||
StringTag idTag = tag.getStringTag("id");
|
||||
if (idTag == null) return;
|
||||
|
||||
String id = idTag.getValue();
|
||||
@ -262,7 +262,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
// Target -> target_uuid
|
||||
UUID targetUuid = UUIDUtil.fromIntArray((int[]) targetUuidTag.getValue());
|
||||
tag.put("target_uuid", new StringTag(targetUuid.toString()));
|
||||
tag.putString("target_uuid", targetUuid.toString());
|
||||
} else if (id.equals("minecraft:skull")) {
|
||||
Tag skullOwnerTag = tag.remove("SkullOwner");
|
||||
if (!(skullOwnerTag instanceof CompoundTag)) return;
|
||||
@ -271,7 +271,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
Tag ownerUuidTag = skullOwnerCompoundTag.remove("Id");
|
||||
if (ownerUuidTag instanceof IntArrayTag) {
|
||||
UUID ownerUuid = UUIDUtil.fromIntArray((int[]) ownerUuidTag.getValue());
|
||||
skullOwnerCompoundTag.put("Id", new StringTag(ownerUuid.toString()));
|
||||
skullOwnerCompoundTag.putString("Id", ownerUuid.toString());
|
||||
}
|
||||
|
||||
// SkullOwner -> Owner
|
||||
@ -297,22 +297,21 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
if (item.identifier() == 771 && tag != null) {
|
||||
Tag ownerTag = tag.get("SkullOwner");
|
||||
if (ownerTag instanceof CompoundTag) {
|
||||
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
|
||||
Tag idTag = ownerCompundTag.get("Id");
|
||||
if (idTag instanceof IntArrayTag) {
|
||||
UUID ownerUuid = UUIDUtil.fromIntArray((int[]) idTag.getValue());
|
||||
ownerCompundTag.put("Id", new StringTag(ownerUuid.toString()));
|
||||
CompoundTag ownerTag = tag.getCompoundTag("SkullOwner");
|
||||
if (ownerTag != null) {
|
||||
IntArrayTag idTag = ownerTag.getIntArrayTag("Id");
|
||||
if (idTag != null) {
|
||||
UUID ownerUuid = UUIDUtil.fromIntArray(idTag.getValue());
|
||||
ownerTag.putString("Id", ownerUuid.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle hover event changes in written book pages
|
||||
if (item.identifier() == 759 && tag != null) {
|
||||
Tag pagesTag = tag.get("pages");
|
||||
if (pagesTag instanceof ListTag) {
|
||||
for (Tag page : ((ListTag) pagesTag)) {
|
||||
ListTag pagesTag = tag.getListTag("pages");
|
||||
if (pagesTag != null) {
|
||||
for (Tag page : pagesTag) {
|
||||
if (!(page instanceof StringTag)) {
|
||||
continue;
|
||||
}
|
||||
@ -338,13 +337,12 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
if (identifier == 771 && tag != null) {
|
||||
Tag ownerTag = tag.get("SkullOwner");
|
||||
if (ownerTag instanceof CompoundTag) {
|
||||
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
|
||||
Tag idTag = ownerCompundTag.get("Id");
|
||||
if (idTag instanceof StringTag) {
|
||||
UUID ownerUuid = UUID.fromString((String) idTag.getValue());
|
||||
ownerCompundTag.put("Id", new IntArrayTag(UUIDUtil.toIntArray(ownerUuid)));
|
||||
CompoundTag ownerTag = tag.getCompoundTag("SkullOwner");
|
||||
if (ownerTag != null) {
|
||||
StringTag idTag = ownerTag.getStringTag("Id");
|
||||
if (idTag != null) {
|
||||
UUID ownerUuid = UUID.fromString(idTag.getValue());
|
||||
ownerTag.put("Id", new IntArrayTag(UUIDUtil.toIntArray(ownerUuid)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,9 +118,9 @@ public class EntityPackets1_16 extends EntityRewriter<ClientboundPackets1_16, Pr
|
||||
|
||||
// Send a dummy respawn with a different dimension if the world name was different and the same dimension was used
|
||||
if (clientWorld.getEnvironment() != null && dimension == clientWorld.getEnvironment().id()
|
||||
&& (wrapper.user().isClientSide() || Via.getPlatform().isProxy()
|
||||
|| wrapper.user().getProtocolInfo().getProtocolVersion() <= ProtocolVersion.v1_12_2.getVersion() // Hotfix for https://github.com/ViaVersion/ViaBackwards/issues/381
|
||||
|| !nextWorldName.equals(worldNameTracker.getWorldName()))) {
|
||||
&& (wrapper.user().isClientSide() || Via.getPlatform().isProxy()
|
||||
|| wrapper.user().getProtocolInfo().getProtocolVersion() <= ProtocolVersion.v1_12_2.getVersion() // Hotfix for https://github.com/ViaVersion/ViaBackwards/issues/381
|
||||
|| !nextWorldName.equals(worldNameTracker.getWorldName()))) {
|
||||
PacketWrapper packet = wrapper.create(ClientboundPackets1_15.RESPAWN);
|
||||
packet.write(Type.INT, dimension == 0 ? -1 : 0);
|
||||
packet.write(Type.LONG, 0L);
|
||||
|
@ -32,7 +32,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
@ -140,29 +139,28 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr
|
||||
}
|
||||
|
||||
private void handleBlockEntity(CompoundTag tag) {
|
||||
StringTag idTag = tag.get("id");
|
||||
StringTag idTag = tag.getStringTag("id");
|
||||
if (idTag == null) return;
|
||||
if (idTag.getValue().equals("minecraft:skull")) {
|
||||
// Workaround an old client bug: MC-68487
|
||||
Tag skullOwnerTag = tag.get("SkullOwner");
|
||||
if (!(skullOwnerTag instanceof CompoundTag)) return;
|
||||
CompoundTag skullOwnerTag = tag.getCompoundTag("SkullOwner");
|
||||
if (skullOwnerTag == null) return;
|
||||
|
||||
CompoundTag skullOwnerCompoundTag = (CompoundTag) skullOwnerTag;
|
||||
if (!skullOwnerCompoundTag.contains("Id")) return;
|
||||
if (!skullOwnerTag.contains("Id")) return;
|
||||
|
||||
CompoundTag properties = skullOwnerCompoundTag.get("Properties");
|
||||
CompoundTag properties = skullOwnerTag.getCompoundTag("Properties");
|
||||
if (properties == null) return;
|
||||
|
||||
ListTag textures = properties.get("textures");
|
||||
ListTag textures = properties.getListTag("textures");
|
||||
if (textures == null) return;
|
||||
|
||||
CompoundTag first = textures.size() > 0 ? textures.get(0) : null;
|
||||
CompoundTag first = !textures.isEmpty() ? textures.get(0) : null;
|
||||
if (first == null) return;
|
||||
|
||||
// Make the client cache the skinprofile over this uuid
|
||||
int hashCode = first.get("Value").getValue().hashCode();
|
||||
int[] uuidIntArray = {hashCode, 0, 0, 0}; //TODO split texture in 4 for a lower collision chance
|
||||
skullOwnerCompoundTag.put("Id", new IntArrayTag(uuidIntArray));
|
||||
skullOwnerTag.put("Id", new IntArrayTag(uuidIntArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,13 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_16;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class EntityPackets1_16_2 extends EntityRewriter<ClientboundPackets1_16_2, Protocol1_16_1To1_16_2> {
|
||||
@ -114,13 +117,13 @@ public class EntityPackets1_16_2 extends EntityRewriter<ClientboundPackets1_16_2
|
||||
// This may technically break other custom dimension settings for 1.16/1.16.1 clients, so those cases are considered semi "unsupported" here
|
||||
StringTag effectsLocation = dimensionData.get("effects");
|
||||
return effectsLocation != null && oldDimensions.contains(effectsLocation.getValue()) ?
|
||||
effectsLocation.getValue() : "minecraft:overworld";
|
||||
effectsLocation.getValue() : "minecraft:overworld";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null,
|
||||
Types1_16.META_TYPES.particleType, Types1_16.META_TYPES.componentType, Types1_16.META_TYPES.optionalComponentType);
|
||||
Types1_16.META_TYPES.particleType, Types1_16.META_TYPES.componentType, Types1_16.META_TYPES.optionalComponentType);
|
||||
|
||||
mapTypes(EntityTypes1_16_2.values(), EntityTypes1_16.class);
|
||||
mapEntityTypeWithData(EntityTypes1_16_2.PIGLIN_BRUTE, EntityTypes1_16_2.PIGLIN).jsonName();
|
||||
|
@ -361,7 +361,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
|
||||
}
|
||||
|
||||
chunk.getBlockEntities().removeIf(compound -> {
|
||||
NumberTag tag = compound.get("y");
|
||||
NumberTag tag = compound.getNumberTag("y");
|
||||
return tag != null && (tag.asInt() < 0 || tag.asInt() > 255);
|
||||
});
|
||||
});
|
||||
|
@ -29,7 +29,11 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_16;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_17;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
|
||||
|
||||
@ -177,7 +181,7 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
|
||||
|
||||
// Particles have already been handled
|
||||
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null, null,
|
||||
Types1_16.META_TYPES.componentType, Types1_16.META_TYPES.optionalComponentType);
|
||||
Types1_16.META_TYPES.componentType, Types1_16.META_TYPES.optionalComponentType);
|
||||
|
||||
mapTypes(EntityTypes1_17.values(), EntityTypes1_16_2.class);
|
||||
filter().type(EntityTypes1_17.AXOLOTL).cancel(17);
|
||||
@ -205,9 +209,9 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
|
||||
}
|
||||
|
||||
private void reduceExtendedHeight(CompoundTag tag, boolean warn) {
|
||||
IntTag minY = tag.get("min_y");
|
||||
IntTag height = tag.get("height");
|
||||
IntTag logicalHeight = tag.get("logical_height");
|
||||
NumberTag minY = tag.getNumberTag("min_y");
|
||||
NumberTag height = tag.getNumberTag("height");
|
||||
NumberTag logicalHeight = tag.getNumberTag("logical_height");
|
||||
if (minY.asInt() != 0 || height.asInt() > 256 || logicalHeight.asInt() > 256) {
|
||||
if (warn && !warned) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Custom worlds heights are NOT SUPPORTED for 1.16 players and older and may lead to errors!");
|
||||
@ -215,8 +219,8 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
|
||||
warned = true;
|
||||
}
|
||||
|
||||
height.setValue(Math.min(256, height.asInt()));
|
||||
logicalHeight.setValue(Math.min(256, logicalHeight.asInt()));
|
||||
tag.putInt("height", Math.min(256, height.asInt()));
|
||||
tag.putInt("logical_height", Math.min(256, logicalHeight.asInt()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,6 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_17;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
|
||||
@ -152,13 +150,13 @@ public final class BlockItemPackets1_18 extends ItemRewriter<ClientboundPackets1
|
||||
final Position pos = wrapper.get(Type.POSITION1_14, 0);
|
||||
|
||||
// The protocol converters downstream rely on this field, let's add it back
|
||||
newTag.put("id", new StringTag(Key.namespaced(identifier)));
|
||||
newTag.putString("id", Key.namespaced(identifier));
|
||||
|
||||
// Weird glitches happen with the 1.17 client and below if these fields are missing
|
||||
// Some examples are block entity models becoming invisible (e.g.: signs, banners)
|
||||
newTag.put("x", new IntTag(pos.x()));
|
||||
newTag.put("y", new IntTag(pos.y()));
|
||||
newTag.put("z", new IntTag(pos.z()));
|
||||
newTag.putInt("x", pos.x());
|
||||
newTag.putInt("y", pos.y());
|
||||
newTag.putInt("z", pos.z());
|
||||
|
||||
handleSpawner(id, newTag);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) mappedId);
|
||||
@ -170,8 +168,8 @@ public final class BlockItemPackets1_18 extends ItemRewriter<ClientboundPackets1
|
||||
protocol.registerClientbound(ClientboundPackets1_18.CHUNK_DATA, wrapper -> {
|
||||
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
|
||||
final ChunkType1_18 chunkType = new ChunkType1_18(tracker.currentWorldSectionHeight(),
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
final Chunk oldChunk = wrapper.read(chunkType);
|
||||
final ChunkSection[] sections = oldChunk.getSections();
|
||||
final BitSet mask = new BitSet(oldChunk.getSections().length);
|
||||
@ -210,14 +208,14 @@ public final class BlockItemPackets1_18 extends ItemRewriter<ClientboundPackets1
|
||||
}
|
||||
|
||||
blockEntityTags.add(tag);
|
||||
tag.put("x", new IntTag((oldChunk.getX() << 4) + blockEntity.sectionX()));
|
||||
tag.put("y", new IntTag(blockEntity.y()));
|
||||
tag.put("z", new IntTag((oldChunk.getZ() << 4) + blockEntity.sectionZ()));
|
||||
tag.put("id", new StringTag(Key.namespaced(id)));
|
||||
tag.putInt("x", (oldChunk.getX() << 4) + blockEntity.sectionX());
|
||||
tag.putInt("y", blockEntity.y());
|
||||
tag.putInt("z", (oldChunk.getZ() << 4) + blockEntity.sectionZ());
|
||||
tag.putString("id", Key.namespaced(id));
|
||||
}
|
||||
|
||||
final Chunk chunk = new BaseChunk(oldChunk.getX(), oldChunk.getZ(), true, false, mask,
|
||||
oldChunk.getSections(), biomeData, oldChunk.getHeightMap(), blockEntityTags);
|
||||
oldChunk.getSections(), biomeData, oldChunk.getHeightMap(), blockEntityTags);
|
||||
wrapper.write(new ChunkType1_17(tracker.currentWorldSectionHeight()), chunk);
|
||||
|
||||
// Create and send light packet first
|
||||
@ -250,9 +248,9 @@ public final class BlockItemPackets1_18 extends ItemRewriter<ClientboundPackets1
|
||||
|
||||
private void handleSpawner(final int typeId, final CompoundTag tag) {
|
||||
if (typeId == 8) {
|
||||
final CompoundTag spawnData = tag.get("SpawnData");
|
||||
final CompoundTag spawnData = tag.getCompoundTag("SpawnData");
|
||||
final CompoundTag entity;
|
||||
if (spawnData != null && (entity = spawnData.get("entity")) != null) {
|
||||
if (spawnData != null && (entity = spawnData.getCompoundTag("entity")) != null) {
|
||||
tag.put("SpawnData", entity);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,10 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_17;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_18;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
|
||||
|
||||
public final class EntityPackets1_18 extends EntityRewriter<ClientboundPackets1_18, Protocol1_17_1To1_18> {
|
||||
@ -68,8 +71,8 @@ public final class EntityPackets1_18 extends EntityRewriter<ClientboundPackets1_
|
||||
}
|
||||
|
||||
// The client just needs something
|
||||
biomeCompound.put("depth", new FloatTag(0.125F));
|
||||
biomeCompound.put("scale", new FloatTag(0.05F));
|
||||
biomeCompound.putFloat("depth", 0.125F);
|
||||
biomeCompound.putFloat("scale", 0.05F);
|
||||
}
|
||||
|
||||
// Track amount of biomes sent
|
||||
@ -114,7 +117,7 @@ public final class EntityPackets1_18 extends EntityRewriter<ClientboundPackets1_
|
||||
|
||||
// Particles have already been handled
|
||||
registerMetaTypeHandler(Types1_17.META_TYPES.itemType, null, null, null,
|
||||
Types1_17.META_TYPES.componentType, Types1_17.META_TYPES.optionalComponentType);
|
||||
Types1_17.META_TYPES.componentType, Types1_17.META_TYPES.optionalComponentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,8 +105,8 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
|
||||
ListTag pagesTag;
|
||||
StringTag titleTag = null;
|
||||
// Sanity checks
|
||||
if (tag == null || (pagesTag = tag.get("pages")) == null
|
||||
|| (signing && (titleTag = tag.get("title")) == null)) {
|
||||
if (tag == null || (pagesTag = tag.getListTag("pages")) == null
|
||||
|| (signing && (titleTag = tag.getStringTag("title")) == null)) {
|
||||
wrapper.write(Type.VAR_INT, 0); // Pages length
|
||||
wrapper.write(Type.BOOLEAN, false); // Optional title
|
||||
return;
|
||||
@ -131,10 +131,6 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
|
||||
// Write optional title
|
||||
wrapper.write(Type.BOOLEAN, signing);
|
||||
if (signing) {
|
||||
if (titleTag == null) {
|
||||
titleTag = tag.get("title");
|
||||
}
|
||||
|
||||
// Limit title length
|
||||
String title = titleTag.getValue();
|
||||
if (title.length() > MAX_TITLE_LENGTH) {
|
||||
|
@ -56,7 +56,6 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -142,8 +142,8 @@ public final class BlockItemPackets1_19 extends ItemRewriter<ClientboundPackets1
|
||||
protocol.registerClientbound(ClientboundPackets1_19.CHUNK_DATA, wrapper -> {
|
||||
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
|
||||
final ChunkType1_18 chunkType = new ChunkType1_18(tracker.currentWorldSectionHeight(),
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
final Chunk chunk = wrapper.passthrough(chunkType);
|
||||
for (final ChunkSection section : chunk.getSections()) {
|
||||
final DataPalette blockPalette = section.palette(PaletteType.BLOCKS);
|
||||
|
@ -33,7 +33,11 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_18;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_19;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
|
||||
|
||||
@ -149,7 +153,7 @@ public final class EntityPackets1_19 extends EntityRewriter<ClientboundPackets1_
|
||||
final ListTag biomes = biomeRegistry.get("value");
|
||||
for (final Tag biome : biomes.getValue()) {
|
||||
final CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
|
||||
biomeCompound.put("category", new StringTag("none"));
|
||||
biomeCompound.putString("category", "none");
|
||||
}
|
||||
tracker(wrapper.user()).setBiomesSent(biomes.size());
|
||||
|
||||
@ -266,7 +270,7 @@ public final class EntityPackets1_19 extends EntityRewriter<ClientboundPackets1_
|
||||
});
|
||||
|
||||
registerMetaTypeHandler(Types1_18.META_TYPES.itemType, Types1_18.META_TYPES.blockStateType, null, null,
|
||||
Types1_18.META_TYPES.componentType, Types1_18.META_TYPES.optionalComponentType);
|
||||
Types1_18.META_TYPES.componentType, Types1_18.META_TYPES.optionalComponentType);
|
||||
|
||||
filter().type(EntityTypes1_19.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
final int data = (int) meta.getValue();
|
||||
|
@ -39,10 +39,9 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class EntityPackets1_19_3 extends EntityRewriter<ClientboundPackets1_19_3, Protocol1_19_1To1_19_3> {
|
||||
|
||||
@ -83,7 +82,7 @@ public final class EntityPackets1_19_3 extends EntityRewriter<ClientboundPackets
|
||||
final ChatTypeStorage1_19_3 chatTypeStorage = wrapper.user().get(ChatTypeStorage1_19_3.class);
|
||||
chatTypeStorage.clear();
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final ListTag chatTypes = ((CompoundTag) registry.get("minecraft:chat_type")).get("value");
|
||||
final ListTag chatTypes = registry.getCompoundTag("minecraft:chat_type").get("value");
|
||||
for (final Tag chatType : chatTypes) {
|
||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
||||
final NumberTag idTag = chatTypeCompound.get("id");
|
||||
@ -244,7 +243,7 @@ public final class EntityPackets1_19_3 extends EntityRewriter<ClientboundPackets
|
||||
}
|
||||
});
|
||||
registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, null, Types1_19.META_TYPES.particleType,
|
||||
Types1_19.META_TYPES.componentType, Types1_19.META_TYPES.optionalComponentType);
|
||||
Types1_19.META_TYPES.componentType, Types1_19.META_TYPES.optionalComponentType);
|
||||
|
||||
filter().index(6).handler((event, meta) -> {
|
||||
// Sitting pose added
|
||||
|
@ -28,7 +28,10 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_19_3;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_19_4;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
|
||||
|
||||
@ -69,7 +72,7 @@ public final class EntityPackets1_19_4 extends EntityRewriter<ClientboundPackets
|
||||
for (final Tag biomeTag : biomes) {
|
||||
final CompoundTag biomeData = ((CompoundTag) biomeTag).get("element");
|
||||
final NumberTag hasPrecipitation = biomeData.get("has_precipitation");
|
||||
biomeData.put("precipitation", new StringTag(hasPrecipitation.asByte() == 1 ? "rain" : "none"));
|
||||
biomeData.putString("precipitation", hasPrecipitation.asByte() == 1 ? "rain" : "none");
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -140,7 +143,7 @@ public final class EntityPackets1_19_4 extends EntityRewriter<ClientboundPackets
|
||||
meta.setMetaType(Types1_19_3.META_TYPES.byId(id));
|
||||
});
|
||||
registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, null, Types1_19_3.META_TYPES.particleType,
|
||||
Types1_19_3.META_TYPES.componentType, Types1_19_3.META_TYPES.optionalComponentType);
|
||||
Types1_19_3.META_TYPES.componentType, Types1_19_3.META_TYPES.optionalComponentType);
|
||||
|
||||
filter().type(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
|
@ -158,15 +158,15 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
super.handleItemToClient(item);
|
||||
|
||||
// Remove new trim tags
|
||||
final Tag trimTag;
|
||||
if (item.tag() != null && (trimTag = item.tag().get("Trim")) instanceof CompoundTag) {
|
||||
final Tag patternTag = ((CompoundTag) trimTag).get("pattern");
|
||||
if (patternTag instanceof StringTag) {
|
||||
final StringTag patternStringTag = (StringTag) patternTag;
|
||||
final String pattern = Key.stripMinecraftNamespace(patternStringTag.getValue());
|
||||
final CompoundTag trimTag;
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag != null && (trimTag = tag.getCompoundTag("Trim")) != null) {
|
||||
final StringTag patternTag = trimTag.getStringTag("pattern");
|
||||
if (patternTag != null) {
|
||||
final String pattern = Key.stripMinecraftNamespace(patternTag.getValue());
|
||||
if (NEW_TRIM_PATTERNS.contains(pattern)) {
|
||||
item.tag().remove("Trim");
|
||||
item.tag().put(nbtTagName + "|Trim", trimTag);
|
||||
tag.remove("Trim");
|
||||
tag.put(nbtTagName + "|Trim", trimTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -183,8 +183,9 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
|
||||
// Add back original trim tag
|
||||
final Tag trimTag;
|
||||
if (item.tag() != null && (trimTag = item.tag().remove(nbtTagName + "|Trim")) != null) {
|
||||
item.tag().put("Trim", trimTag);
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag != null && (trimTag = tag.remove(nbtTagName + "|Trim")) != null) {
|
||||
tag.put("Trim", trimTag);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
@ -196,19 +197,20 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
}
|
||||
|
||||
final CompoundTag tag = blockEntity.tag();
|
||||
final CompoundTag frontText = tag.remove("front_text");
|
||||
final Tag frontText = tag.remove("front_text");
|
||||
tag.remove("back_text");
|
||||
|
||||
if (frontText != null) {
|
||||
writeMessages(frontText, tag, false);
|
||||
writeMessages(frontText, tag, true);
|
||||
if (frontText instanceof CompoundTag) {
|
||||
final CompoundTag frontTextTag = (CompoundTag) frontText;
|
||||
writeMessages(frontTextTag, tag, false);
|
||||
writeMessages(frontTextTag, tag, true);
|
||||
|
||||
final Tag color = frontText.remove("color");
|
||||
final Tag color = frontTextTag.remove("color");
|
||||
if (color != null) {
|
||||
tag.put("Color", color);
|
||||
}
|
||||
|
||||
final Tag glowing = frontText.remove("has_glowing_text");
|
||||
final Tag glowing = frontTextTag.remove("has_glowing_text");
|
||||
if (glowing != null) {
|
||||
tag.put("GlowingText", glowing);
|
||||
}
|
||||
@ -216,7 +218,7 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
}
|
||||
|
||||
private void writeMessages(final CompoundTag frontText, final CompoundTag tag, final boolean filtered) {
|
||||
final ListTag messages = frontText.get(filtered ? "filtered_messages" : "messages");
|
||||
final ListTag messages = frontText.getListTag(filtered ? "filtered_messages" : "messages");
|
||||
if (messages == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -34,13 +34,12 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public final class EntityPackets1_20 extends EntityRewriter<ClientboundPackets1_19_4, Protocol1_19_4To1_20> {
|
||||
|
||||
private final Set<String> newTrimPatterns = Sets.newHashSet("host_armor_trim_smithing_template", "raiser_armor_trim_smithing_template",
|
||||
"silence_armor_trim_smithing_template", "shaper_armor_trim_smithing_template", "wayfinder_armor_trim_smithing_template");
|
||||
"silence_armor_trim_smithing_template", "shaper_armor_trim_smithing_template", "wayfinder_armor_trim_smithing_template");
|
||||
private static final Quaternion Y_FLIPPED_ROTATION = new Quaternion(0, 1, 0, 0);
|
||||
|
||||
public EntityPackets1_20(final Protocol1_19_4To1_20 protocol) {
|
||||
@ -81,16 +80,18 @@ public final class EntityPackets1_20 extends EntityRewriter<ClientboundPackets1_
|
||||
handler(wrapper -> {
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
|
||||
ListTag values;
|
||||
final ListTag values;
|
||||
// A 1.20 server can't send this element, and the 1.20 client still works, if the element is missing
|
||||
// on a 1.19.4 client there is an exception, so in case the 1.20 server doesn't send the element we put in an original 1.20 element
|
||||
if (registry.contains("minecraft:trim_pattern")) {
|
||||
values = ((CompoundTag) registry.get("minecraft:trim_pattern")).get("value");
|
||||
final CompoundTag trimPatternTag = registry.getCompoundTag("minecraft:trim_pattern");
|
||||
if (trimPatternTag != null) {
|
||||
values = trimPatternTag.getListTag("value");
|
||||
} else {
|
||||
final CompoundTag trimPatternRegistry = Protocol1_19_4To1_20.MAPPINGS.getTrimPatternRegistry().copy();
|
||||
registry.put("minecraft:trim_pattern", trimPatternRegistry);
|
||||
values = trimPatternRegistry.get("value");
|
||||
}
|
||||
|
||||
for (final Tag entry : values) {
|
||||
final CompoundTag element = ((CompoundTag) entry).get("element");
|
||||
final StringTag templateItem = element.get("template_item");
|
||||
@ -124,7 +125,7 @@ public final class EntityPackets1_20 extends EntityRewriter<ClientboundPackets1_
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> meta.setMetaType(Types1_19_4.META_TYPES.byId(meta.metaType().typeId())));
|
||||
registerMetaTypeHandler(Types1_19_4.META_TYPES.itemType, Types1_19_4.META_TYPES.blockStateType, Types1_19_4.META_TYPES.optionalBlockStateType,
|
||||
Types1_19_4.META_TYPES.particleType, Types1_19_4.META_TYPES.componentType, Types1_19_4.META_TYPES.optionalComponentType);
|
||||
Types1_19_4.META_TYPES.particleType, Types1_19_4.META_TYPES.componentType, Types1_19_4.META_TYPES.optionalComponentType);
|
||||
|
||||
filter().type(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
|
@ -103,7 +103,7 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPac
|
||||
chatTypeStorage.clear();
|
||||
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final ListTag chatTypes = ((CompoundTag) registry.get("minecraft:chat_type")).get("value");
|
||||
final ListTag chatTypes = registry.getCompoundTag("minecraft:chat_type").get("value");
|
||||
for (final Tag chatType : chatTypes) {
|
||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
||||
final NumberTag idTag = chatTypeCompound.get("id");
|
||||
@ -399,7 +399,7 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPac
|
||||
return null;
|
||||
}
|
||||
|
||||
chatType = chatType.<CompoundTag>get("element").get("chat");
|
||||
chatType = chatType.getCompoundTag("element").getCompoundTag("chat");
|
||||
if (chatType == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ package com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_19;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
|
||||
|
||||
|
@ -120,9 +120,9 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
|
||||
final byte[][] toBlow = new byte[blocks][3];
|
||||
for (int i = 0; i < blocks; i++) {
|
||||
toBlow[i] = new byte[]{
|
||||
wrapper.read(Type.BYTE), // Relative X
|
||||
wrapper.read(Type.BYTE), // Relative Y
|
||||
wrapper.read(Type.BYTE) // Relative Z
|
||||
wrapper.read(Type.BYTE), // Relative X
|
||||
wrapper.read(Type.BYTE), // Relative Y
|
||||
wrapper.read(Type.BYTE) // Relative Z
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -129,12 +129,12 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
|
||||
});
|
||||
|
||||
registerMetaTypeHandler(
|
||||
Types1_20_2.META_TYPES.itemType,
|
||||
Types1_20_2.META_TYPES.blockStateType,
|
||||
Types1_20_2.META_TYPES.optionalBlockStateType,
|
||||
Types1_20_2.META_TYPES.particleType,
|
||||
Types1_20_2.META_TYPES.componentType,
|
||||
Types1_20_2.META_TYPES.optionalComponentType
|
||||
Types1_20_2.META_TYPES.itemType,
|
||||
Types1_20_2.META_TYPES.blockStateType,
|
||||
Types1_20_2.META_TYPES.optionalBlockStateType,
|
||||
Types1_20_2.META_TYPES.particleType,
|
||||
Types1_20_2.META_TYPES.componentType,
|
||||
Types1_20_2.META_TYPES.optionalComponentType
|
||||
);
|
||||
|
||||
filter().type(EntityTypes1_20_3.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||
|
@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_20_2to1_20_3.storage;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.libs.fastutil.Pair;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SpawnPositionStorage implements StorableObject {
|
||||
|
@ -34,8 +34,8 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2;
|
||||
@ -108,13 +108,13 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
protocol.registerClientbound(ClientboundPackets1_20_2.CHUNK_DATA, wrapper -> {
|
||||
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
|
||||
final Type<Chunk> chunkType = new ChunkType1_20_2(tracker.currentWorldSectionHeight(),
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
final Chunk chunk = wrapper.read(chunkType);
|
||||
|
||||
final Type<Chunk> newChunkType = new ChunkType1_18(tracker.currentWorldSectionHeight(),
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
wrapper.write(newChunkType, chunk);
|
||||
|
||||
for (final ChunkSection section : chunk.getSections()) {
|
||||
@ -399,16 +399,16 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
return null;
|
||||
}
|
||||
|
||||
final StringTag primaryEffect = tag.remove("primary_effect");
|
||||
if (primaryEffect != null) {
|
||||
final String effectKey = Key.stripMinecraftNamespace(primaryEffect.getValue());
|
||||
tag.put("Primary", new IntTag(PotionEffects.keyToId(effectKey)));
|
||||
final Tag primaryEffect = tag.remove("primary_effect");
|
||||
if (primaryEffect instanceof StringTag) {
|
||||
final String effectKey = Key.stripMinecraftNamespace(((StringTag) primaryEffect).getValue());
|
||||
tag.putInt("Primary", PotionEffects.keyToId(effectKey));
|
||||
}
|
||||
|
||||
final StringTag secondaryEffect = tag.remove("secondary_effect");
|
||||
if (secondaryEffect != null) {
|
||||
final String effectKey = Key.stripMinecraftNamespace(secondaryEffect.getValue());
|
||||
tag.put("Secondary", new IntTag(PotionEffects.keyToId(effectKey)));
|
||||
final Tag secondaryEffect = tag.remove("secondary_effect");
|
||||
if (secondaryEffect instanceof StringTag) {
|
||||
final String effectKey = Key.stripMinecraftNamespace(((StringTag) secondaryEffect).getValue());
|
||||
tag.putInt("Secondary", PotionEffects.keyToId(effectKey));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||
@ -60,8 +59,8 @@ public class Protocol1_9_1_2To1_9_3_4 extends AbstractProtocol<ClientboundPacket
|
||||
wrapper.write(Type.POSITION1_8, position); // Position
|
||||
for (int i = 1; i < 5; i++) {
|
||||
// Should technically be written as COMPONENT, but left as String for simplification/to remove redundant wrapping for VR
|
||||
Tag textTag = tag.get("Text" + i);
|
||||
String line = textTag instanceof StringTag ? ((StringTag) textTag).getValue() : "";
|
||||
StringTag textTag = tag.getStringTag("Text" + i);
|
||||
String line = textTag != null ? textTag.getValue() : "";
|
||||
wrapper.write(Type.STRING, line); // Sign line
|
||||
}
|
||||
}
|
||||
|
@ -18,60 +18,56 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_9_1_2to1_9_3_4.chunks;
|
||||
|
||||
import com.viaversion.viabackwards.protocol.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockEntity {
|
||||
private static final Map<String, Integer> types = new HashMap<>();
|
||||
private static final Map<String, Integer> TYPES = new HashMap<>();
|
||||
|
||||
static {
|
||||
types.put("MobSpawner", 1);
|
||||
types.put("Control", 2);
|
||||
types.put("Beacon", 3);
|
||||
types.put("Skull", 4);
|
||||
types.put("FlowerPot", 5);
|
||||
types.put("Banner", 6);
|
||||
types.put("UNKNOWN", 7);
|
||||
types.put("EndGateway", 8);
|
||||
types.put("Sign", 9);
|
||||
TYPES.put("MobSpawner", 1);
|
||||
TYPES.put("Control", 2);
|
||||
TYPES.put("Beacon", 3);
|
||||
TYPES.put("Skull", 4);
|
||||
TYPES.put("FlowerPot", 5);
|
||||
TYPES.put("Banner", 6);
|
||||
TYPES.put("UNKNOWN", 7);
|
||||
TYPES.put("EndGateway", 8);
|
||||
TYPES.put("Sign", 9);
|
||||
}
|
||||
|
||||
public static void handle(List<CompoundTag> tags, UserConnection connection) {
|
||||
public static void handle(List<CompoundTag> tags, UserConnection connection) throws Exception {
|
||||
for (CompoundTag tag : tags) {
|
||||
try {
|
||||
if (!tag.contains("id"))
|
||||
throw new Exception("NBT tag not handled because the id key is missing");
|
||||
|
||||
String id = (String) tag.get("id").getValue();
|
||||
if (!types.containsKey(id))
|
||||
throw new Exception("Not handled id: " + id);
|
||||
|
||||
int newId = types.get(id);
|
||||
if (newId == -1)
|
||||
continue;
|
||||
|
||||
int x = ((NumberTag) tag.get("x")).asInt();
|
||||
int y = ((NumberTag) tag.get("y")).asInt();
|
||||
int z = ((NumberTag) tag.get("z")).asInt();
|
||||
|
||||
Position pos = new Position(x, (short) y, z);
|
||||
|
||||
updateBlockEntity(pos, (short) newId, tag, connection);
|
||||
} catch (Exception e) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("Block Entity: " + e.getMessage() + ": " + tag);
|
||||
}
|
||||
StringTag idTag = tag.getStringTag("id");
|
||||
if (idTag == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String id = idTag.getValue();
|
||||
if (!TYPES.containsKey(id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int newId = TYPES.get(id);
|
||||
if (newId == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int x = tag.getNumberTag("x").asInt();
|
||||
int y = tag.getNumberTag("y").asInt();
|
||||
int z = tag.getNumberTag("z").asInt();
|
||||
|
||||
Position pos = new Position(x, (short) y, z);
|
||||
|
||||
updateBlockEntity(pos, (short) newId, tag, connection);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,10 @@ import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren