merge upstream

This commit is contained in:
creeper123123321 2018-07-29 08:30:58 -03:00
commit 446fd84035
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
12 changed files with 212 additions and 186 deletions

View File

@ -6,11 +6,11 @@ import us.myles.ViaVersion.api.entities.Entity1_13Types;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -5,6 +5,9 @@ import com.google.common.collect.HashBiMap;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import java.io.IOException; import java.io.IOException;
@ -27,64 +30,46 @@ public class MappingData {
JsonObject mapping1_12 = loadData("mapping-1.12.json"); JsonObject mapping1_12 = loadData("mapping-1.12.json");
JsonObject mapping1_13 = loadData("mapping-1.13.json"); JsonObject mapping1_13 = loadData("mapping-1.13.json");
// TODO: Remove how verbose this is Via.getPlatform().getLogger().info("Loading block mapping...");
System.out.println("Loading block mapping...");
blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
System.out.println("Loading item mapping..."); Via.getPlatform().getLogger().info("Loading item mapping...");
mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items")); mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
System.out.println("Loading new tags..."); Via.getPlatform().getLogger().info("Loading new tags...");
loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags")); loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags"));
loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags")); loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags"));
loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags")); loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));
System.out.println("Loading enchantments..."); Via.getPlatform().getLogger().info("Loading enchantments...");
loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments")); loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
System.out.println("Loading sound mapping..."); Via.getPlatform().getLogger().info("Loading sound mapping...");
soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds")); soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
} }
public static JsonObject loadData(String name) {
InputStream stream = MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name);
InputStreamReader reader = new InputStreamReader(stream);
try {
JsonObject jsonObject = GsonUtil.getGson().fromJson(reader, JsonObject.class);
return jsonObject;
} finally {
try {
reader.close();
} catch (IOException ignored) {
// Ignored
}
}
}
private static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { private static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) {
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString()); Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
if (value == null) { if (value == null) {
System.out.println("No key for " + entry.getValue() + " :( "); Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
continue; continue;
} }
output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey()));
} }
} }
private static Map.Entry<String, JsonElement> findValue(JsonObject object, String needle) {
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
String value = entry.getValue().getAsString();
if (value.equals(needle)) {
return entry;
}
}
return null;
}
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement v = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, v.getAsString());
if (index == null) {
System.out.println("No key for " + v + " :( ");
continue;
}
output[i] = index.shortValue();
}
}
private static Integer findIndex(JsonArray array, String value) {
for (int i = 0; i < array.size(); i++) {
JsonElement v = array.get(i);
if (v.getAsString().equals(value)) {
return i;
}
}
return null;
}
private static void loadTags(Map<String, Integer[]> output, JsonObject newTags) { private static void loadTags(Map<String, Integer[]> output, JsonObject newTags) {
for (Map.Entry<String, JsonElement> entry : newTags.entrySet()) { for (Map.Entry<String, JsonElement> entry : newTags.entrySet()) {
JsonArray ids = entry.getValue().getAsJsonArray(); JsonArray ids = entry.getValue().getAsJsonArray();
@ -102,34 +87,63 @@ public class MappingData {
} }
} }
public static JsonObject loadData(String name) { private static void mapIdentifiers(Map<Integer, Integer> output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
InputStream stream = MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name); for (int i = 0; i < oldIdentifiers.size(); i++) {
InputStreamReader reader = new InputStreamReader(stream); JsonElement v = oldIdentifiers.get(i);
try { Integer index = findIndex(newIdentifiers, v.getAsString());
JsonObject jsonObject = GsonUtil.getGson().fromJson(reader, JsonObject.class); if (index == null) {
return jsonObject; Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
} finally { continue;
try { }
reader.close(); output.put(i, index);
} catch (IOException ignored) { }
// Ignored }
private static Map.Entry<String, JsonElement> findValue(JsonObject object, String needle) {
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
String value = entry.getValue().getAsString();
if (value.equals(needle)) {
return entry;
} }
} }
return null;
}
private static Integer findIndex(JsonArray array, String value) {
for (int i = 0; i < array.size(); i++) {
JsonElement v = array.get(i);
if (v.getAsString().equals(value)) {
return i;
}
}
return null;
}
public interface BlockMappings {
int getNewBlock(int old);
} }
private static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { private static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) {
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString()); Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
if (value == null) { if (value == null) {
System.out.println("No key for " + entry.getValue() + " :( "); Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
continue; continue;
} }
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
} }
} }
public interface BlockMappings { private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
int getNewBlock(int old); for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement v = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, v.getAsString());
if (index == null) {
Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
continue;
}
output[i] = index.shortValue();
}
} }
private static class BlockMappingsShortArray implements BlockMappings { private static class BlockMappingsShortArray implements BlockMappings {

View File

@ -15,6 +15,7 @@ import java.util.Random;
public class ParticleRewriter { public class ParticleRewriter {
private static List<NewParticle> particles = new LinkedList<>(); private static List<NewParticle> particles = new LinkedList<>();
private static Random rand = new Random();
static { static {
add(34); // (0->34) explode -> minecraft:poof add(34); // (0->34) explode -> minecraft:poof
@ -102,10 +103,6 @@ public class ParticleRewriter {
particles.add(new NewParticle(newId, dataHandler)); particles.add(new NewParticle(newId, dataHandler));
} }
interface ParticleDataHandler {
Particle handler(Particle particle, Integer[] data);
}
// Randomized because the previous one was a lot of different colors at once! :) // Randomized because the previous one was a lot of different colors at once! :)
private static ParticleDataHandler reddustHandler() { private static ParticleDataHandler reddustHandler() {
return new ParticleDataHandler() { return new ParticleDataHandler() {
@ -120,6 +117,10 @@ public class ParticleRewriter {
}; };
} }
private static float randomFloat() {
return rand.nextFloat();
}
// Rewrite IconCrack items to new format :) // Rewrite IconCrack items to new format :)
private static ParticleDataHandler iconcrackHandler() { private static ParticleDataHandler iconcrackHandler() {
return new ParticleDataHandler() { return new ParticleDataHandler() {
@ -157,6 +158,9 @@ public class ParticleRewriter {
}; };
} }
interface ParticleDataHandler {
Particle handler(Particle particle, Integer[] data);
}
@Data @Data
@RequiredArgsConstructor @RequiredArgsConstructor
@ -171,11 +175,5 @@ public class ParticleRewriter {
} }
} }
private static Random rand = new Random();
private static float randomFloat() {
return rand.nextFloat();
}
} }

View File

@ -5,6 +5,7 @@ import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.io.BaseEncoding; import com.google.common.io.BaseEncoding;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -92,7 +93,7 @@ public class InventoryPackets {
flags |= 1; flags |= 1;
Optional<SoundSource> finalSource = SoundSource.findBySource(originalSource); Optional<SoundSource> finalSource = SoundSource.findBySource(originalSource);
if (!finalSource.isPresent()) { if (!finalSource.isPresent()) {
System.out.println("Could not handle unknown sound source " + originalSource + " falling back to default: master"); Via.getPlatform().getLogger().info("Could not handle unknown sound source " + originalSource + " falling back to default: master");
finalSource = Optional.of(SoundSource.MASTER); finalSource = Optional.of(SoundSource.MASTER);
} }
@ -133,10 +134,8 @@ public class InventoryPackets {
wrapper.passthrough(Type.INT); // Maximum number of trade uses wrapper.passthrough(Type.INT); // Maximum number of trade uses
} }
} else { } else {
String originalChannel = channel;
channel = getNewPluginChannelId(channel); channel = getNewPluginChannelId(channel);
if (channel == null) { if (channel == null) {
System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug
wrapper.cancel(); wrapper.cancel();
return; return;
} else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) { } else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) {
@ -144,10 +143,11 @@ public class InventoryPackets {
List<String> rewrittenChannels = new ArrayList<>(); List<String> rewrittenChannels = new ArrayList<>();
for (int i = 0; i < channels.length; i++) { for (int i = 0; i < channels.length; i++) {
String rewritten = getNewPluginChannelId(channels[i]); String rewritten = getNewPluginChannelId(channels[i]);
if (rewritten != null) if (rewritten != null) {
rewrittenChannels.add(rewritten); rewrittenChannels.add(rewritten);
else } else {
System.out.println("Ignoring plugin channel in REGISTER: " + channels[i]); Via.getPlatform().getLogger().warning("Ignoring plugin channel in REGISTER: " + channels[i]);
}
} }
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
} }
@ -213,10 +213,8 @@ public class InventoryPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.get(Type.STRING, 0); String channel = wrapper.get(Type.STRING, 0);
String originalChannel = channel;
channel = getOldPluginChannelId(channel); channel = getOldPluginChannelId(channel);
if (channel == null) { if (channel == null) {
System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug
wrapper.cancel(); wrapper.cancel();
return; return;
} else if (channel.equals("REGISTER") || channel.equals("UNREGISTER")) { } else if (channel.equals("REGISTER") || channel.equals("UNREGISTER")) {
@ -224,10 +222,11 @@ public class InventoryPackets {
List<String> rewrittenChannels = new ArrayList<>(); List<String> rewrittenChannels = new ArrayList<>();
for (int i = 0; i < channels.length; i++) { for (int i = 0; i < channels.length; i++) {
String rewritten = getOldPluginChannelId(channels[i]); String rewritten = getOldPluginChannelId(channels[i]);
if (rewritten != null) if (rewritten != null) {
rewrittenChannels.add(rewritten); rewrittenChannels.add(rewritten);
else } else {
System.out.println("Ignoring plugin channel in REGISTER: " + channels[i]); Via.getPlatform().getLogger().warning("Ignoring plugin channel in REGISTER: " + channels[i]);
}
} }
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
} }
@ -319,8 +318,8 @@ public class InventoryPackets {
CompoundTag enchantmentEntry = new CompoundTag(""); CompoundTag enchantmentEntry = new CompoundTag("");
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue();
String newId = MappingData.oldEnchantmentsIds.get(oldId); String newId = MappingData.oldEnchantmentsIds.get(oldId);
if (newId == null){ if (newId == null) {
newId = "viaversion:legacy/"+oldId; newId = "viaversion:legacy/" + oldId;
} }
enchantmentEntry.put(new StringTag("id", newId)); enchantmentEntry.put(new StringTag("id", newId));
enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue())); enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue()));
@ -339,7 +338,7 @@ public class InventoryPackets {
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue();
String newId = MappingData.oldEnchantmentsIds.get(oldId); String newId = MappingData.oldEnchantmentsIds.get(oldId);
if (newId == null) { if (newId == null) {
newId = "viaversion:legacy/"+oldId; newId = "viaversion:legacy/" + oldId;
} }
enchantmentEntry.put(new StringTag("id", enchantmentEntry.put(new StringTag("id",
newId newId
@ -389,7 +388,7 @@ public class InventoryPackets {
} else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) { } else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) {
rawId &= ~0xF; // Remove data rawId &= ~0xF; // Remove data
} else { } else {
System.out.println("FAILED TO GET 1.13 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T Via.getPlatform().getLogger().warning("Failed to get 1.13 item for " + item.getId());
rawId = 16; // Stone rawId = 16; // Stone
} }
} }
@ -398,7 +397,38 @@ public class InventoryPackets {
item.setData((short) 0); item.setData((short) 0);
} }
// TODO cleanup / smarter rewrite system public static String getNewPluginChannelId(String old) {
switch (old) {
case "MC|TrList":
return "minecraft:trader_list";
case "MC|Brand":
return "minecraft:brand";
case "MC|BOpen":
return "minecraft:book_open";
case "MC|DebugPath":
return "minecraft:debug/paths";
case "MC|DebugNeighborsUpdate":
return "minecraft:debug/neighbors_update";
case "REGISTER":
return "minecraft:register";
case "UNREGISTER":
return "minecraft:unregister";
case "BungeeCord":
return "bungeecord:main";
case "WDL|INIT":
return "wdl:init";
case "WDL|CONTROL":
return "wdl:init";
case "WDL|REQUEST":
return "wdl:request";
default:
return old.matches("[0-9a-z_-]+:[0-9a-z_/.-]+") // Identifier regex
? old
: "viaversion:legacy/" + BaseEncoding.base32().lowerCase().withPadChar('-').encode(
old.getBytes(StandardCharsets.UTF_8));
}
}
public static void toServer(Item item) { public static void toServer(Item item) {
if (item == null) return; if (item == null) return;
@ -439,7 +469,7 @@ public class InventoryPackets {
} }
if (rawId == null) { if (rawId == null) {
System.out.println("FAILED TO GET 1.12 ITEM FOR " + item.getId()); Via.getPlatform().getLogger().warning("Failed to get 1.12 item for " + item.getId());
rawId = 0x10000; // Stone rawId = 0x10000; // Stone
} }
@ -506,7 +536,7 @@ public class InventoryPackets {
CompoundTag enchEntry = new CompoundTag(""); CompoundTag enchEntry = new CompoundTag("");
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId); Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")){ if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18)); oldId = Short.valueOf(newId.substring(18));
} }
enchEntry.put( enchEntry.put(
@ -527,9 +557,10 @@ public class InventoryPackets {
ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class); ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class);
for (Tag enchantmentEntry : storedEnch) { for (Tag enchantmentEntry : storedEnch) {
if (enchantmentEntry instanceof CompoundTag) { if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag("");String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); CompoundTag enchEntry = new CompoundTag("");
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId); Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")){ if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18)); oldId = Short.valueOf(newId.substring(18));
} }
enchEntry.put( enchEntry.put(
@ -548,52 +579,6 @@ public class InventoryPackets {
} }
} }
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
}
public static String getNewPluginChannelId(String old) {
switch (old) {
case "MC|TrList":
return "minecraft:trader_list";
case "MC|Brand":
return "minecraft:brand";
case "MC|BOpen":
return "minecraft:book_open";
case "MC|DebugPath":
return "minecraft:debug/paths";
case "MC|DebugNeighborsUpdate":
return "minecraft:debug/neighbors_update";
case "REGISTER":
return "minecraft:register";
case "UNREGISTER":
return "minecraft:unregister";
case "BungeeCord":
return "bungeecord:main";
case "WDL|INIT":
return "wdl:init";
case "WDL|CONTROL":
return "wdl:init";
case "WDL|REQUEST":
return "wdl:request";
default:
return old.matches("[0-9a-z_-]+:[0-9a-z_/.-]+") // Identifier regex
? old
: "viaversion:legacy/" + BaseEncoding.base32().lowerCase().withPadChar('-').encode(
old.getBytes(StandardCharsets.UTF_8));
}
}
public static String getOldPluginChannelId(String newId) { public static String getOldPluginChannelId(String newId) {
switch (newId) { switch (newId) {
case "minecraft:register": case "minecraft:register":
@ -617,4 +602,18 @@ public class InventoryPackets {
: newId; : newId;
} }
} }
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
}
} }

View File

@ -14,10 +14,13 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
<<<<<<< HEAD
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
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;
=======
>>>>>>> fc264d0b0f90b4115a583cbe7a58da15389a4721
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
@ -25,6 +28,8 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityP
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.PaintingProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.PaintingProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
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 java.util.List; import java.util.List;
@ -47,9 +52,9 @@ public class WorldPackets {
Optional<Integer> id = provider.getIntByIdentifier(motive); Optional<Integer> id = provider.getIntByIdentifier(motive);
if (!id.isPresent()) if (!id.isPresent()) {
System.out.println("Could not find painting motive: " + motive + " falling back to default (0)"); Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)");
}
wrapper.write(Type.VAR_INT, id.or(0)); wrapper.write(Type.VAR_INT, id.or(0));
} }
}); });
@ -316,26 +321,23 @@ public class WorldPackets {
} }
//Handle reddust particle color //Handle reddust particle color
ifStatement:
if (particle.getId() == 11) { if (particle.getId() == 11) {
int count = wrapper.get(Type.INT, 1); int count = wrapper.get(Type.INT, 1);
float speed = wrapper.get(Type.FLOAT, 6); float speed = wrapper.get(Type.FLOAT, 6);
if (count != 0 || speed != 1) break ifStatement; // Only handle for count = 0 & speed = 1
if (count == 0 && speed == 1) {
wrapper.set(Type.INT, 1, 1);
wrapper.set(Type.FLOAT, 6, 0f);
wrapper.set(Type.INT, 1, 1); List<Particle.ParticleData> arguments = particle.getArguments();
wrapper.set(Type.FLOAT, 6, 0f); for (int i = 0; i < 3; i++) {
//RGB values are represented by the X/Y/Z offset
List<Particle.ParticleData> arguments = particle.getArguments(); arguments.get(i).setValue(wrapper.get(Type.FLOAT, i + 3));
for (int i = 0; i < 3; i++) { wrapper.set(Type.FLOAT, i + 3, 0f);
//RGB values are represented by the X/Y/Z offset }
arguments.get(i).setValue(wrapper.get(Type.FLOAT, i + 3));
wrapper.set(Type.FLOAT, i + 3, 0f);
} }
} }
// System.out.println("Old particle " + particleId + " " + Arrays.toString(data) + " new Particle" + particle);
wrapper.set(Type.INT, 0, particle.getId()); wrapper.set(Type.INT, 0, particle.getId());
for (Particle.ParticleData particleData : particle.getArguments()) for (Particle.ParticleData particleData : particle.getArguments())
wrapper.write(particleData.getType(), particleData.getValue()); wrapper.write(particleData.getType(), particleData.getValue());
@ -347,16 +349,19 @@ public class WorldPackets {
} }
public static int toNewId(int oldId) { public static int toNewId(int oldId) {
if (oldId < 0) {
oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air.
}
int newId = MappingData.blockMappings.getNewBlock(oldId); int newId = MappingData.blockMappings.getNewBlock(oldId);
if (newId != -1) { if (newId != -1) {
return newId; return newId;
} }
newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data
if (newId != -1) { if (newId != -1) {
System.out.println("Missing block " + oldId); Via.getPlatform().getLogger().warning("Missing block " + oldId);
return newId; return newId;
} }
System.out.println("Missing block completely " + oldId); Via.getPlatform().getLogger().warning("Missing block completely " + oldId);
// Default stone // Default stone
return 1; return 1;
} }

View File

@ -41,8 +41,9 @@ public class BlockEntityProvider implements Provider {
String id = (String) tag.get("id").getValue(); String id = (String) tag.get("id").getValue();
if (!handlers.containsKey(id)) { if (!handlers.containsKey(id)) {
if (Via.getManager().isDebug()) if (Via.getManager().isDebug()) {
System.out.println("Unhandled BlockEntity " + id + " full tag: " + tag); Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag);
}
return -1; return -1;
} }

View File

@ -4,6 +4,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
@ -22,7 +23,7 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z")));
if (!storage.contains(position)) { if (!storage.contains(position)) {
System.out.println("Received an banner color update packet, but there is no banner! O_o " + tag); Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag);
return -1; return -1;
} }
@ -30,13 +31,14 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
int color = (int) tag.get("Base").getValue(); int color = (int) tag.get("Base").getValue();
// Standing banner // Standing banner
if (blockId >= BANNER_START && blockId <= BANNER_STOP) if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
blockId += ((15 - color) * 16); blockId += ((15 - color) * 16);
// Wall banner // Wall banner
else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) } else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) {
blockId += ((15 - color) * 4); blockId += ((15 - color) * 4);
else } else {
System.out.println("Why does this block have the banner block entity? :(" + tag); Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
}
if (tag.get("Patterns") instanceof ListTag) { if (tag.get("Patterns") instanceof ListTag) {
for (Tag pattern : (ListTag) tag.get("Patterns")) { for (Tag pattern : (ListTag) tag.get("Patterns")) {

View File

@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentiti
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
@ -15,7 +16,7 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler {
Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z")));
if (!storage.contains(position)) { if (!storage.contains(position)) {
System.out.println("Received an bed color update packet, but there is no bed! O_o " + tag); Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag);
return -1; return -1;
} }

View File

@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentiti
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
@ -13,28 +14,28 @@ public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler
private static final Map<Pair<Byte, Byte>, Integer> flowersNumberId = new ConcurrentHashMap<>(); private static final Map<Pair<Byte, Byte>, Integer> flowersNumberId = new ConcurrentHashMap<>();
static { static {
register("minecraft:air", (byte) 0, (byte) 0, 5265); register("minecraft:air", (byte) 0, (byte) 0, 5265);
register("minecraft:sapling", (byte) 6, (byte) 0, 5266); register("minecraft:sapling", (byte) 6, (byte) 0, 5266);
register("minecraft:sapling", (byte) 6, (byte) 1, 5267); register("minecraft:sapling", (byte) 6, (byte) 1, 5267);
register("minecraft:sapling", (byte) 6, (byte) 2, 5268); register("minecraft:sapling", (byte) 6, (byte) 2, 5268);
register("minecraft:sapling", (byte) 6, (byte) 3, 5269); register("minecraft:sapling", (byte) 6, (byte) 3, 5269);
register("minecraft:sapling", (byte) 6, (byte) 4, 5270); register("minecraft:sapling", (byte) 6, (byte) 4, 5270);
register("minecraft:sapling", (byte) 6, (byte) 5, 5271); register("minecraft:sapling", (byte) 6, (byte) 5, 5271);
register("minecraft:tallgrass", (byte) 31, (byte) 2, 5272); register("minecraft:tallgrass", (byte) 31, (byte) 2, 5272);
register("minecraft:yellow_flower", (byte) 37, (byte) 0, 5273); register("minecraft:yellow_flower", (byte) 37, (byte) 0, 5273);
register("minecraft:red_flower", (byte) 38, (byte) 0, 5274); register("minecraft:red_flower", (byte) 38, (byte) 0, 5274);
register("minecraft:red_flower", (byte) 38, (byte) 1, 5275); register("minecraft:red_flower", (byte) 38, (byte) 1, 5275);
register("minecraft:red_flower", (byte) 38, (byte) 2, 5276); register("minecraft:red_flower", (byte) 38, (byte) 2, 5276);
register("minecraft:red_flower", (byte) 38, (byte) 3, 5277); register("minecraft:red_flower", (byte) 38, (byte) 3, 5277);
register("minecraft:red_flower", (byte) 38, (byte) 4, 5278); register("minecraft:red_flower", (byte) 38, (byte) 4, 5278);
register("minecraft:red_flower", (byte) 38, (byte) 5, 5279); register("minecraft:red_flower", (byte) 38, (byte) 5, 5279);
register("minecraft:red_flower", (byte) 38, (byte) 6, 5280); register("minecraft:red_flower", (byte) 38, (byte) 6, 5280);
register("minecraft:red_flower", (byte) 38, (byte) 7, 5281); register("minecraft:red_flower", (byte) 38, (byte) 7, 5281);
register("minecraft:red_flower", (byte) 38, (byte) 8, 5282); register("minecraft:red_flower", (byte) 38, (byte) 8, 5282);
register("minecraft:red_mushroom", (byte) 40, (byte) 0, 5283); register("minecraft:red_mushroom", (byte) 40, (byte) 0, 5283);
register("minecraft:brown_mushroom", (byte) 39, (byte) 0, 5284); register("minecraft:brown_mushroom", (byte) 39, (byte) 0, 5284);
register("minecraft:deadbush", (byte) 32, (byte) 0, 5285); register("minecraft:deadbush", (byte) 32, (byte) 0, 5285);
register("minecraft:cactus", (byte) 81, (byte) 0, 5286); register("minecraft:cactus", (byte) 81, (byte) 0, 5286);
} }
@ -60,7 +61,7 @@ public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler
} else if (flowersNumberId.containsKey(pair)) { } else if (flowersNumberId.containsKey(pair)) {
return flowersNumberId.get(pair); return flowersNumberId.get(pair);
} else { } else {
System.out.println("Could not find flowerpot content " + item + " for " + tag); Via.getPlatform().getLogger().warning("Could not find flowerpot content " + item + " for " + tag);
} }
return -1; return -1;

View File

@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentiti
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
@ -10,13 +11,14 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage;
public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
private final int SKULL_WALL_START = 5447; private final int SKULL_WALL_START = 5447;
private final int SKULL_END = 5566; private final int SKULL_END = 5566;
@Override @Override
public int transform(UserConnection user, CompoundTag tag) { public int transform(UserConnection user, CompoundTag tag) {
BlockStorage storage = user.get(BlockStorage.class); BlockStorage storage = user.get(BlockStorage.class);
Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z")));
if (!storage.contains(position)) { if (!storage.contains(position)) {
System.out.println("Received an head update packet, but there is no head! O_o " + tag); Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag);
return -1; return -1;
} }
@ -28,12 +30,13 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
id += (byte) tag.get("Rot").getValue(); id += (byte) tag.get("Rot").getValue();
} }
} else { } else {
System.out.println("Why does this block have the skull block entity? :(" + tag); Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);
return -1; return -1;
} }
return id; return id;
} }
private long getLong(Tag tag) { private long getLong(Tag tag) {
return ((Integer) tag.getValue()).longValue(); return ((Integer) tag.getValue()).longValue();
} }

View File

@ -9,9 +9,9 @@ import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.type.PartialType; import us.myles.ViaVersion.api.type.PartialType;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType; import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks.Chunk1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks.Chunk1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks.ChunkSection1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks.ChunkSection1_13;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -55,7 +55,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
byte[] biomeData = groundUp ? new byte[256] : null; byte[] biomeData = groundUp ? new byte[256] : null;
if (groundUp) { if (groundUp) {
for (int i = 0; i < 256; i++){ for (int i = 0; i < 256; i++) {
// todo use int in Chunk? // todo use int in Chunk?
biomeData[i] = 0; biomeData[i] = 0;
} }
@ -66,8 +66,9 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
// Read all the remaining bytes (workaround for #681) // Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) { if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input); byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) if (Via.getManager().isDebug()) {
System.out.println("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
} }
return new Chunk1_13(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData); return new Chunk1_13(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);

View File

@ -64,8 +64,9 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
// Read all the remaining bytes (workaround for #681) // Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) { if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input); byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) if (Via.getManager().isDebug()) {
System.out.println("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
} }
return new Chunk1_9_3_4(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData); return new Chunk1_9_3_4(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);