3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-08 09:10:10 +01:00

Configurable block/item mappings (1.9-1.12), cleanup

Resolves #39
Dieser Commit ist enthalten in:
KennyTV 2020-02-01 11:58:02 +01:00
Ursprung 8df3815e82
Commit 01121dedf3
19 geänderte Dateien mit 213 neuen und 282 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,63 @@
package nl.matsv.viabackwards.api.data;
import net.md_5.bungee.api.ChatColor;
import nl.matsv.viabackwards.utils.Block;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
public class MappedLegacyBlockItem {
private final int id;
private final short data;
private final String name;
private Block block;
private BlockEntityHandler blockEntityHandler;
public MappedLegacyBlockItem(int id, short data, String name) {
this.id = id;
this.data = data;
this.name = name != null ? ChatColor.RESET + name : null;
}
public int getId() {
return id;
}
public short getData() {
return data;
}
public String getName() {
return name;
}
public boolean isBlock() {
return block != null;
}
// Mark this as a block item
public void setBlock() {
block = new Block(id, data);
}
public Block getBlock() {
return block;
}
public boolean hasBlockEntityHandler() {
return blockEntityHandler != null;
}
public BlockEntityHandler getBlockEntityHandler() {
return blockEntityHandler;
}
public void setBlockEntityHandler(BlockEntityHandler blockEntityHandler) {
this.blockEntityHandler = blockEntityHandler;
}
@FunctionalInterface
public interface BlockEntityHandler {
CompoundTag handleOrNewCompoundTag(int block, CompoundTag tag);
}
}

Datei anzeigen

@ -1,91 +0,0 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.api.entities.blockitem;
import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
public class BlockItemSettings {
private final int id;
private Item repItem;
private Block repBlock;
private BlockEntityHandler blockEntityHandler;
private ItemHandler itemHandler;
public BlockItemSettings(int id) {
this.id = id;
}
public BlockItemSettings repItem(Item item) {
this.repItem = item;
return this;
}
public BlockItemSettings repBlock(Block block) {
this.repBlock = block;
return this;
}
public BlockItemSettings blockEntityHandler(BlockEntityHandler handler) {
this.blockEntityHandler = handler;
return this;
}
public BlockItemSettings itemHandler(ItemHandler handler) {
this.itemHandler = handler;
return this;
}
public boolean hasRepItem() {
return repItem != null;
}
public boolean hasRepBlock() {
return repBlock != null;
}
public boolean hasEntityHandler() {
return blockEntityHandler != null;
}
public boolean hasItemTagHandler() {
return itemHandler != null;
}
public int getId() {
return id;
}
public Item getRepItem() {
return repItem;
}
public Block getRepBlock() {
return repBlock;
}
public BlockEntityHandler getBlockEntityHandler() {
return blockEntityHandler;
}
public ItemHandler getItemHandler() {
return itemHandler;
}
public interface BlockEntityHandler {
CompoundTag handleOrNewCompoundTag(int block, CompoundTag tag);
}
public interface ItemHandler {
Item handle(Item i);
}
}

Datei anzeigen

@ -12,99 +12,122 @@ package nl.matsv.viabackwards.api.rewriters;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.blockitem.BlockItemSettings; import nl.matsv.viabackwards.api.data.MappedLegacyBlockItem;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import nl.matsv.viabackwards.utils.Block; import nl.matsv.viabackwards.utils.Block;
import nl.matsv.viabackwards.utils.ItemUtil;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.rewriters.IdRewriteFunction; import us.myles.ViaVersion.api.rewriters.IdRewriteFunction;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject;
import us.myles.viaversion.libs.gson.JsonPrimitive;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag; import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> extends ItemRewriterBase<T> { public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> extends ItemRewriterBase<T> {
private final Map<Integer, BlockItemSettings> replacementData = new HashMap<>(); private static final Map<String, Map<Integer, MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>();
protected final Map<Integer, MappedLegacyBlockItem> replacementData;
static {
JsonObject jsonObject = VBMappingDataLoader.loadData("legacy-mappings.json");
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
Map<Integer, MappedLegacyBlockItem> mappings = new HashMap<>();
LEGACY_MAPPINGS.put(entry.getKey(), mappings);
for (Map.Entry<String, JsonElement> dataEntry : entry.getValue().getAsJsonObject().entrySet()) {
JsonObject object = dataEntry.getValue().getAsJsonObject();
int id = object.getAsJsonPrimitive("id").getAsInt();
JsonPrimitive jsonData = object.getAsJsonPrimitive("data");
short data = jsonData != null ? jsonData.getAsShort() : 0;
String name = object.getAsJsonPrimitive("name").getAsString();
if (dataEntry.getKey().contains("-")) {
// Range of ids
String[] split = dataEntry.getKey().split("-", 2);
int from = Integer.parseInt(split[0]);
int to = Integer.parseInt(split[1]);
// Special block color handling
if (name.contains("%color%")) {
for (int i = from; i <= to; i++) {
mappings.put(i, new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors.get(i - from))));
}
} else {
MappedLegacyBlockItem mappedBlockItem = new MappedLegacyBlockItem(id, data, name);
for (int i = from; i <= to; i++) {
mappings.put(i, mappedBlockItem);
}
}
} else {
mappings.put(Integer.parseInt(dataEntry.getKey()), new MappedLegacyBlockItem(id, data, name));
}
}
}
}
protected LegacyBlockItemRewriter(T protocol, IdRewriteFunction oldRewriter, IdRewriteFunction newRewriter) { protected LegacyBlockItemRewriter(T protocol, IdRewriteFunction oldRewriter, IdRewriteFunction newRewriter) {
super(protocol, oldRewriter, newRewriter, false); super(protocol, oldRewriter, newRewriter, false);
replacementData = LEGACY_MAPPINGS.get(protocol.getClass().getSimpleName().split("To")[1].replace("_", "."));
} }
protected LegacyBlockItemRewriter(T protocol) { protected LegacyBlockItemRewriter(T protocol) {
super(protocol, false); this(protocol, null, null);
} }
protected BlockItemSettings rewrite(int itemId) { protected void markAsBlock(int... ids) {
BlockItemSettings settings = new BlockItemSettings(itemId); for (int id : ids) {
replacementData.put(itemId, settings); replacementData.get(id).setBlock();
return settings; }
} }
@Override @Override
public Item handleItemToClient(Item item) { public Item handleItemToClient(Item item) {
if (item == null) return null; if (item == null) return null;
BlockItemSettings data = replacementData.get(item.getIdentifier()); MappedLegacyBlockItem data = replacementData.get(item.getIdentifier());
if (data == null) { if (data == null) {
// Just rewrite the id // Just rewrite the id
return super.handleItemToClient(item); return super.handleItemToClient(item);
} }
Item original = ItemUtil.copyItem(item);
if (data.hasRepItem()) {
// Also includes the already mapped id
ItemUtil.copyItem(item, data.getRepItem());
if (item.getTag() == null) { if (item.getTag() == null) {
item.setTag(new CompoundTag("")); item.setTag(new CompoundTag(""));
} }
// Backup data for toServer // Backup data for toServer
item.getTag().put(createViaNBT(original)); short originalData = item.getData();
item.getTag().put(createViaNBT(item));
// Keep original data (aside from the name) item.setIdentifier(data.getId());
if (original.getTag() != null) { // Keep original data if mapped data is set to -1
for (Tag ai : original.getTag()) { if (data.getData() != -1) {
item.getTag().put(ai); item.setData(data.getData());
} }
// Set display name
if (data.getName() != null) {
CompoundTag tag = item.getTag().get("display");
if (tag == null) {
item.getTag().put(tag = new CompoundTag("display"));
}
StringTag nameTag = tag.get("Name");
if (nameTag == null) {
tag.put(nameTag = new StringTag("Name", data.getName()));
} }
// Handle colors // Handle colors
CompoundTag tag = item.getTag().get("display");
if (tag != null) {
StringTag nameTag = tag.get("Name");
if (nameTag != null) {
String value = nameTag.getValue(); String value = nameTag.getValue();
if (value.contains("%vb_color%")) { if (value.contains("%vb_color%")) {
tag.put(new StringTag("Name", value.replace("%vb_color%", BlockColors.get(original.getData())))); tag.put(new StringTag("Name", value.replace("%vb_color%", BlockColors.get(originalData))));
} }
} }
}
item.setAmount(original.getAmount());
// Keep original data when -1
if (item.getData() == -1) {
item.setData(original.getData());
}
} else {
// Set the mapped id if no custom item is defined
super.handleItemToClient(item);
}
if (data.hasItemTagHandler()) {
if (!item.getTag().contains(nbtTagName)) {
item.getTag().put(createViaNBT(original));
}
data.getItemHandler().handle(item);
}
return item; return item;
} }
@ -119,10 +142,10 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
} }
public Block handleBlock(int blockId, int data) { public Block handleBlock(int blockId, int data) {
BlockItemSettings settings = replacementData.get(blockId); MappedLegacyBlockItem settings = replacementData.get(blockId);
if (settings == null || !settings.hasRepBlock()) return null; if (settings == null || !settings.isBlock()) return null;
Block block = settings.getRepBlock(); Block block = settings.getBlock();
// For some blocks, the data can still be useful (: // For some blocks, the data can still be useful (:
if (block.getData() == -1) { if (block.getData() == -1) {
return block.withData(data); return block.withData(data);
@ -148,8 +171,8 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ()); int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ());
int btype = block >> 4; int btype = block >> 4;
BlockItemSettings settings = replacementData.get(btype); MappedLegacyBlockItem settings = replacementData.get(btype);
if (settings != null && settings.hasEntityHandler()) { if (settings != null && settings.hasBlockEntityHandler()) {
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag); settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
} }
} }
@ -174,8 +197,8 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
// We already know that is has a handler // We already know that is has a handler
if (hasBlockEntityHandler) continue; if (hasBlockEntityHandler) continue;
BlockItemSettings settings = replacementData.get(btype); MappedLegacyBlockItem settings = replacementData.get(btype);
if (settings != null && settings.hasEntityHandler()) { if (settings != null && settings.hasBlockEntityHandler()) {
hasBlockEntityHandler = true; hasBlockEntityHandler = true;
} }
} }
@ -190,8 +213,8 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
int btype = block >> 4; int btype = block >> 4;
int meta = block & 15; int meta = block & 15;
BlockItemSettings settings = replacementData.get(btype); MappedLegacyBlockItem settings = replacementData.get(btype);
if (settings == null || !settings.hasEntityHandler()) continue; if (settings == null || !settings.hasBlockEntityHandler()) continue;
Pos pos = new Pos(x, (y + (i << 4)), z); Pos pos = new Pos(x, (y + (i << 4)), z);
@ -221,11 +244,13 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
private static final class Pos { private static final class Pos {
private final int x, y, z; private final int x;
private final short y;
private final int z;
private Pos(final int x, final int y, final int z) { private Pos(int x, int y, int z) {
this.x = x; this.x = x;
this.y = y; this.y = (short) y;
this.z = z; this.z = z;
} }

Datei anzeigen

@ -117,10 +117,10 @@ public class LegacyEnchantmentRewriter {
tag.remove(remappedEnchantments.getName()); tag.remove(remappedEnchantments.getName());
} }
public void setHideLevelForEnchants(Integer... enchants) { public void setHideLevelForEnchants(int... enchants) {
this.hideLevelForEnchants = new HashSet<>(); this.hideLevelForEnchants = new HashSet<>();
for (Integer enchant : enchants) { for (int enchant : enchants) {
hideLevelForEnchants.add(enchant.shortValue()); hideLevelForEnchants.add((short) enchant);
} }
} }
} }

Datei anzeigen

@ -35,7 +35,8 @@ public abstract class Rewriter<T extends BackwardsProtocol> {
/** /**
* Register rewrites. * Register rewrites.
*/ */
protected abstract void registerRewrites(); protected void registerRewrites() {
}
public T getProtocol() { public T getProtocol() {
return protocol; return protocol;

Datei anzeigen

@ -15,6 +15,7 @@ import com.google.common.collect.HashBiMap;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
/* /*
Copied from ViaVersion Copied from ViaVersion
@ -106,8 +107,9 @@ public class EntityTypeNames {
} }
public static void toClient(CompoundTag tag) { public static void toClient(CompoundTag tag) {
if (tag.get("id") instanceof StringTag) { Tag idTag = tag.get("id");
StringTag id = tag.get("id"); if (idTag instanceof StringTag) {
StringTag id = (StringTag) idTag;
if (NEW_TO_OLD_NAMES.containsKey(id.getValue())) { if (NEW_TO_OLD_NAMES.containsKey(id.getValue())) {
id.setValue(NEW_TO_OLD_NAMES.get(id.getValue())); id.setValue(NEW_TO_OLD_NAMES.get(id.getValue()));
} }
@ -115,12 +117,14 @@ public class EntityTypeNames {
} }
public static void toClientSpawner(CompoundTag tag) { public static void toClientSpawner(CompoundTag tag) {
if (tag != null && tag.contains("SpawnData")) { Tag spawnDataTag;
CompoundTag spawnData = tag.get("SpawnData"); if (tag != null && (spawnDataTag = tag.get("SpawnData")) != null) {
if (spawnData != null && spawnData.contains("id")) CompoundTag spawnData = (CompoundTag) spawnDataTag;
if (spawnData != null && spawnData.contains("id")) {
toClient(spawnData); toClient(spawnData);
} }
} }
}
public static void toClientItem(Item item) { public static void toClientItem(Item item) {
if (hasEntityTag(item)) { if (hasEntityTag(item)) {
@ -132,9 +136,10 @@ public class EntityTypeNames {
private static boolean hasEntityTag(Item item) { private static boolean hasEntityTag(Item item) {
if (item != null && item.getIdentifier() == 383) { // Monster Egg if (item != null && item.getIdentifier() == 383) { // Monster Egg
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag != null && tag.contains("EntityTag") && tag.get("EntityTag") instanceof CompoundTag) { if (tag != null) {
if (((CompoundTag) tag.get("EntityTag")).get("id") instanceof StringTag) { Tag entityTag = tag.get("EntityTag");
return true; if (entityTag instanceof CompoundTag) {
return ((CompoundTag) entityTag).get("id") instanceof StringTag;
} }
} }
} }

Datei anzeigen

@ -11,6 +11,7 @@
package nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets; package nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import nl.matsv.viabackwards.api.data.MappedLegacyBlockItem;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.LegacyBlockItemRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import nl.matsv.viabackwards.api.rewriters.LegacyEnchantmentRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
@ -18,8 +19,6 @@ import nl.matsv.viabackwards.protocol.protocol1_10to1_11.EntityTypeNames;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_11Types; import us.myles.ViaVersion.api.entities.Entity1_11Types;
@ -352,32 +351,12 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
// ShulkerBoxes to Dropper // Handle spawner block entity (map to itself with custom handler)
for (int i = 219; i < 235; i++) replacementData.computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null)).setBlockEntityHandler((b, tag) -> {
rewrite(i).repItem(new Item(158, (byte) 1, (short) 0, getNamedTag("1.11 " + BlockColors.get(i - 219) + " Shulker Box")))
.repBlock(new Block(158));
// Observer to Dispenser
rewrite(218).repItem(new Item(23, (byte) 1, (short) 0, getNamedTag("1.11 Observer"))).repBlock(new Block(23, -1));
// Handle spawner block entity
rewrite(52).blockEntityHandler((b, tag) -> {
EntityTypeNames.toClientSpawner(tag); EntityTypeNames.toClientSpawner(tag);
return tag; return tag;
}); });
// Rewrite spawn eggs
rewrite(383).itemHandler((i) -> {
EntityTypeNames.toClientItem(i);
return i;
});
// Totem of Undying to Dead Bush
rewrite(449).repItem(new Item(32, (byte) 1, (short) 0, getNamedTag("1.11 Totem of Undying")));
// Shulker shell to Popped Chorus Fruit
rewrite(450).repItem(new Item(433, (byte) 1, (short) 0, getNamedTag("1.11 Shulker Shell")));
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName); enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName);
enchantmentRewriter.registerEnchantment(71, "§cCurse of Vanishing"); enchantmentRewriter.registerEnchantment(71, "§cCurse of Vanishing");
enchantmentRewriter.registerEnchantment(10, "§cCurse of Binding"); enchantmentRewriter.registerEnchantment(10, "§cCurse of Binding");
@ -386,13 +365,16 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
} }
@Override @Override
public Item handleItemToClient(final Item item) { public Item handleItemToClient(Item item) {
if (item == null) return null; if (item == null) return null;
super.handleItemToClient(item); super.handleItemToClient(item);
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag == null) return item; if (tag == null) return item;
// Rewrite spawn eggs (id checks are done in the method itself)
EntityTypeNames.toClientItem(item);
if (tag.get("ench") instanceof ListTag) { if (tag.get("ench") instanceof ListTag) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false); enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
} }

Datei anzeigen

@ -12,9 +12,7 @@ package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import nl.matsv.viabackwards.api.rewriters.LegacyBlockItemRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.MapColorMapping; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.MapColorMapping;
import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -27,10 +25,6 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
import java.util.Collections;
public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1To1_12> { public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1To1_12> {
@ -263,37 +257,4 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
} }
}); });
} }
@Override
protected void registerRewrites() {
// Concrete -> Stained clay? (Also got a new name Terracota?)
rewrite(251).repItem(new Item(159, (byte) 1, (short) -1, getNamedTag("1.12 %vb_color% Concrete")))
.repBlock(new Block(159, -1));
// Concrete Powder -> Wool
rewrite(252)
.repItem(new Item(35, (byte) 1, (short) -1, getNamedTag("1.12 %vb_color% Concrete Powder")))
.repBlock(new Block(35, -1));
// Knowledge book -> book
rewrite(453)
.repItem(new Item(340, (byte) 1, (short) 0, getNamedTag("1.12 Knowledge Book")))
.itemHandler(i -> {
CompoundTag tag = i.getTag();
if (!tag.contains("ench"))
tag.put(new ListTag("ench", Collections.emptyList()));
return i;
});
// Glazed Terracotta -> Stained Clay
for (int i = 235; i < 251; i++) {
rewrite(i).repItem(new Item(159, (byte) 1, (short) (i - 235), getNamedTag("1.12 " + BlockColors.get(i - 235) + " Glazed Terracotta")))
.repBlock(new Block(159, (i - 235)));
}
// Handle beds
rewrite(355).repItem(new Item(355, (byte) 1, (short) 0, getNamedTag("1.12 %vb_color% Bed")));
}
} }

Datei anzeigen

@ -96,9 +96,4 @@ public class ChangedPacketIds1_12 extends Rewriter<Protocol1_11_1To1_12> {
protocol.registerIncoming(State.PLAY, 0x1F, 0x1C); // Player Block Placement protocol.registerIncoming(State.PLAY, 0x1F, 0x1C); // Player Block Placement
protocol.registerIncoming(State.PLAY, 0x20, 0x1D); // Use Item protocol.registerIncoming(State.PLAY, 0x20, 0x1D); // Use Item
} }
@Override
protected void registerRewrites() {
}
} }

Datei anzeigen

@ -103,10 +103,4 @@ public class ChatPackets1_12 extends Rewriter<Protocol1_11_1To1_12> {
} }
return result; return result;
} }
@Override
protected void registerRewrites() {
}
} }

Datei anzeigen

@ -95,8 +95,6 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<Protocol1_11To1_1
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
rewrite(452).repItem(new Item(265, (byte) 1, (short) 0, getNamedTag("1.11.2 Iron Nugget")));
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName); enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName);
enchantmentRewriter.registerEnchantment(22, "§7Sweeping Edge"); enchantmentRewriter.registerEnchantment(22, "§7Sweeping Edge");
} }

Datei anzeigen

@ -534,9 +534,4 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
} }
}); });
} }
@Override
protected void registerRewrites() {
}
} }

Datei anzeigen

@ -86,8 +86,4 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
} }
}); });
} }
@Override
protected void registerRewrites() {
}
} }

Datei anzeigen

@ -145,9 +145,4 @@ public class PlayerPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
} }
}); });
} }
@Override
protected void registerRewrites() {
}
} }

Datei anzeigen

@ -84,8 +84,4 @@ public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
} }
}); });
} }
@Override
protected void registerRewrites() {
}
} }

Datei anzeigen

@ -211,10 +211,6 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
}); });
} }
@Override
protected void registerRewrites() {
}
public static int getNewItemId(int id) { public static int getNewItemId(int id) {
Integer newId = MappingData.oldToNewItems.get(id); Integer newId = MappingData.oldToNewItems.get(id);
if (newId == null) { if (newId == null) {

Datei anzeigen

@ -12,7 +12,6 @@ package nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets;
import nl.matsv.viabackwards.api.rewriters.LegacyBlockItemRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -178,14 +177,4 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<Protocol1_9_4T
} }
}); });
} }
@Override
protected void registerRewrites() {
rewrite(255).repItem(new Item(166, (byte) 1, (short) 0, getNamedTag("1.10 Structure Block"))); // Structure block only item since the structure block is in 1.9
rewrite(217).repItem(new Item(287, (byte) 1, (short) 0, getNamedTag("1.10 Structure Void"))).repBlock(new Block(287)); // Structure void to string
rewrite(213).repItem(new Item(159, (byte) 1, (short) 1, getNamedTag("1.10 Magma Block"))).repBlock(new Block(159, 1)); // Magma block to orange clay
rewrite(214).repItem(new Item(159, (byte) 1, (short) 14, getNamedTag("1.10 Nether Wart Block"))).repBlock(new Block(159, 14)); // Nether wart block to red clay
rewrite(215).repItem(new Item(112, (byte) 1, (short) 0, getNamedTag("1.10 Red Nether Bricks"))).repBlock(new Block(112)); // Red nether brick to nether brick
rewrite(216).repItem(new Item(155, (byte) 1, (short) 0, getNamedTag("1.10 Bone Block"))).repBlock(new Block(155)); // Bone block to quartz
}
} }

Datei anzeigen

@ -12,14 +12,14 @@ package nl.matsv.viabackwards.utils;
public class Block { public class Block {
private final int id; private final int id;
private final int data; private final short data;
public Block(final int id, final int data) { public Block(int id, int data) {
this.id = id; this.id = id;
this.data = data; this.data = (short) data;
} }
public Block(final int id) { public Block(int id) {
this.id = id; this.id = id;
this.data = 0; this.data = 0;
} }
@ -32,7 +32,7 @@ public class Block {
return data; return data;
} }
public Block withData(final int data) { public Block withData(int data) {
return new Block(this.id, data); return new Block(this.id, data);
} }

Datei anzeigen

@ -1,7 +1,38 @@
{ {
"1.12": {
"251": {
"id": 159,
"data": -1,
"name": "1.12 %vb_color% Concrete"
},
"252": {
"id": 35,
"data": -1,
"name": "1.12 %vb_color% Concrete Powder"
},
"453": {
"id": 340,
"name": "1.12 Knowledge Book"
},
"355": {
"id": 355,
"name": "1.12 %vb_color% Bed"
},
"235-250": {
"id": 159,
"name": "1.12 %color% Glazed Terracotta"
}
},
"1.11.1": {
"452": {
"id": 265,
"name": "1.11.1 Iron Nugget"
}
},
"1.11": { "1.11": {
"218": { "218": {
"id": 23, "id": 23,
"data": -1,
"name": "1.11 Observer" "name": "1.11 Observer"
}, },
"449": { "449": {
@ -19,7 +50,7 @@
}, },
"1.10": { "1.10": {
"255": { "255": {
"id": 166, "id": 217,
"name": "1.10 Structure Block" "name": "1.10 Structure Block"
}, },
"217": { "217": {