mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-27 04:25:12 +01:00
merge upstream
This commit is contained in:
commit
446fd84035
@ -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.metadata.Metadata;
|
||||
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.ParticleRewriter;
|
||||
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_9to1_8.Protocol1_9TO1_8;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -5,6 +5,9 @@ import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
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 java.io.IOException;
|
||||
@ -27,64 +30,46 @@ public class MappingData {
|
||||
JsonObject mapping1_12 = loadData("mapping-1.12.json");
|
||||
JsonObject mapping1_13 = loadData("mapping-1.13.json");
|
||||
|
||||
// TODO: Remove how verbose this is
|
||||
System.out.println("Loading block mapping...");
|
||||
Via.getPlatform().getLogger().info("Loading block mapping...");
|
||||
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"));
|
||||
System.out.println("Loading new tags...");
|
||||
Via.getPlatform().getLogger().info("Loading new tags...");
|
||||
loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags"));
|
||||
loadTags(itemTags, mapping1_13.getAsJsonObject("item_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"));
|
||||
System.out.println("Loading sound mapping...");
|
||||
Via.getPlatform().getLogger().info("Loading sound mapping...");
|
||||
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) {
|
||||
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
|
||||
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
|
||||
if (value == null) {
|
||||
System.out.println("No key for " + entry.getValue() + " :( ");
|
||||
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
|
||||
continue;
|
||||
}
|
||||
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) {
|
||||
for (Map.Entry<String, JsonElement> entry : newTags.entrySet()) {
|
||||
JsonArray ids = entry.getValue().getAsJsonArray();
|
||||
@ -102,34 +87,63 @@ public class MappingData {
|
||||
}
|
||||
}
|
||||
|
||||
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, 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) {
|
||||
Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
|
||||
continue;
|
||||
}
|
||||
output.put(i, index);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
|
||||
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
|
||||
if (value == null) {
|
||||
System.out.println("No key for " + entry.getValue() + " :( ");
|
||||
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
|
||||
continue;
|
||||
}
|
||||
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
public interface BlockMappings {
|
||||
int getNewBlock(int old);
|
||||
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) {
|
||||
Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
|
||||
continue;
|
||||
}
|
||||
output[i] = index.shortValue();
|
||||
}
|
||||
}
|
||||
|
||||
private static class BlockMappingsShortArray implements BlockMappings {
|
||||
|
@ -15,6 +15,7 @@ import java.util.Random;
|
||||
|
||||
public class ParticleRewriter {
|
||||
private static List<NewParticle> particles = new LinkedList<>();
|
||||
private static Random rand = new Random();
|
||||
|
||||
static {
|
||||
add(34); // (0->34) explode -> minecraft:poof
|
||||
@ -102,10 +103,6 @@ public class ParticleRewriter {
|
||||
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! :)
|
||||
private static ParticleDataHandler reddustHandler() {
|
||||
return new ParticleDataHandler() {
|
||||
@ -120,6 +117,10 @@ public class ParticleRewriter {
|
||||
};
|
||||
}
|
||||
|
||||
private static float randomFloat() {
|
||||
return rand.nextFloat();
|
||||
}
|
||||
|
||||
// Rewrite IconCrack items to new format :)
|
||||
private static ParticleDataHandler iconcrackHandler() {
|
||||
return new ParticleDataHandler() {
|
||||
@ -157,6 +158,9 @@ public class ParticleRewriter {
|
||||
};
|
||||
}
|
||||
|
||||
interface ParticleDataHandler {
|
||||
Particle handler(Particle particle, Integer[] data);
|
||||
}
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@ -171,11 +175,5 @@ public class ParticleRewriter {
|
||||
}
|
||||
}
|
||||
|
||||
private static Random rand = new Random();
|
||||
|
||||
private static float randomFloat() {
|
||||
return rand.nextFloat();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
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.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
@ -92,7 +93,7 @@ public class InventoryPackets {
|
||||
flags |= 1;
|
||||
Optional<SoundSource> finalSource = SoundSource.findBySource(originalSource);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -133,10 +134,8 @@ public class InventoryPackets {
|
||||
wrapper.passthrough(Type.INT); // Maximum number of trade uses
|
||||
}
|
||||
} else {
|
||||
String originalChannel = channel;
|
||||
channel = getNewPluginChannelId(channel);
|
||||
if (channel == null) {
|
||||
System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug
|
||||
wrapper.cancel();
|
||||
return;
|
||||
} else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) {
|
||||
@ -144,10 +143,11 @@ public class InventoryPackets {
|
||||
List<String> rewrittenChannels = new ArrayList<>();
|
||||
for (int i = 0; i < channels.length; i++) {
|
||||
String rewritten = getNewPluginChannelId(channels[i]);
|
||||
if (rewritten != null)
|
||||
if (rewritten != null) {
|
||||
rewrittenChannels.add(rewritten);
|
||||
else
|
||||
System.out.println("Ignoring plugin channel in REGISTER: " + channels[i]);
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
@ -213,10 +213,8 @@ public class InventoryPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
String channel = wrapper.get(Type.STRING, 0);
|
||||
String originalChannel = channel;
|
||||
channel = getOldPluginChannelId(channel);
|
||||
if (channel == null) {
|
||||
System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug
|
||||
wrapper.cancel();
|
||||
return;
|
||||
} else if (channel.equals("REGISTER") || channel.equals("UNREGISTER")) {
|
||||
@ -224,10 +222,11 @@ public class InventoryPackets {
|
||||
List<String> rewrittenChannels = new ArrayList<>();
|
||||
for (int i = 0; i < channels.length; i++) {
|
||||
String rewritten = getOldPluginChannelId(channels[i]);
|
||||
if (rewritten != null)
|
||||
if (rewritten != null) {
|
||||
rewrittenChannels.add(rewritten);
|
||||
else
|
||||
System.out.println("Ignoring plugin channel in REGISTER: " + channels[i]);
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
@ -319,8 +318,8 @@ public class InventoryPackets {
|
||||
CompoundTag enchantmentEntry = new CompoundTag("");
|
||||
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue();
|
||||
String newId = MappingData.oldEnchantmentsIds.get(oldId);
|
||||
if (newId == null){
|
||||
newId = "viaversion:legacy/"+oldId;
|
||||
if (newId == null) {
|
||||
newId = "viaversion:legacy/" + oldId;
|
||||
}
|
||||
enchantmentEntry.put(new StringTag("id", newId));
|
||||
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();
|
||||
String newId = MappingData.oldEnchantmentsIds.get(oldId);
|
||||
if (newId == null) {
|
||||
newId = "viaversion:legacy/"+oldId;
|
||||
newId = "viaversion:legacy/" + oldId;
|
||||
}
|
||||
enchantmentEntry.put(new StringTag("id",
|
||||
newId
|
||||
@ -389,7 +388,7 @@ public class InventoryPackets {
|
||||
} else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) {
|
||||
rawId &= ~0xF; // Remove data
|
||||
} 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
|
||||
}
|
||||
}
|
||||
@ -398,7 +397,38 @@ public class InventoryPackets {
|
||||
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) {
|
||||
if (item == null) return;
|
||||
|
||||
@ -439,7 +469,7 @@ public class InventoryPackets {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -506,7 +536,7 @@ public class InventoryPackets {
|
||||
CompoundTag enchEntry = new CompoundTag("");
|
||||
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
|
||||
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));
|
||||
}
|
||||
enchEntry.put(
|
||||
@ -527,9 +557,10 @@ public class InventoryPackets {
|
||||
ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class);
|
||||
for (Tag enchantmentEntry : storedEnch) {
|
||||
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);
|
||||
if (oldId == null && newId.startsWith("viaversion:legacy/")){
|
||||
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
|
||||
oldId = Short.valueOf(newId.substring(18));
|
||||
}
|
||||
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) {
|
||||
switch (newId) {
|
||||
case "minecraft:register":
|
||||
@ -617,4 +602,18 @@ public class InventoryPackets {
|
||||
: 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
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,13 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
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.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_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.Particle;
|
||||
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.storage.BlockStorage;
|
||||
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;
|
||||
|
||||
@ -47,9 +52,9 @@ public class WorldPackets {
|
||||
|
||||
Optional<Integer> id = provider.getIntByIdentifier(motive);
|
||||
|
||||
if (!id.isPresent())
|
||||
System.out.println("Could not find painting motive: " + motive + " falling back to default (0)");
|
||||
|
||||
if (!id.isPresent()) {
|
||||
Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)");
|
||||
}
|
||||
wrapper.write(Type.VAR_INT, id.or(0));
|
||||
}
|
||||
});
|
||||
@ -316,12 +321,11 @@ public class WorldPackets {
|
||||
}
|
||||
|
||||
//Handle reddust particle color
|
||||
ifStatement:
|
||||
if (particle.getId() == 11) {
|
||||
int count = wrapper.get(Type.INT, 1);
|
||||
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);
|
||||
|
||||
@ -332,9 +336,7 @@ public class WorldPackets {
|
||||
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());
|
||||
for (Particle.ParticleData particleData : particle.getArguments())
|
||||
@ -347,16 +349,19 @@ public class WorldPackets {
|
||||
}
|
||||
|
||||
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);
|
||||
if (newId != -1) {
|
||||
return newId;
|
||||
}
|
||||
newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data
|
||||
if (newId != -1) {
|
||||
System.out.println("Missing block " + oldId);
|
||||
Via.getPlatform().getLogger().warning("Missing block " + oldId);
|
||||
return newId;
|
||||
}
|
||||
System.out.println("Missing block completely " + oldId);
|
||||
Via.getPlatform().getLogger().warning("Missing block completely " + oldId);
|
||||
// Default stone
|
||||
return 1;
|
||||
}
|
||||
|
@ -41,8 +41,9 @@ public class BlockEntityProvider implements Provider {
|
||||
String id = (String) tag.get("id").getValue();
|
||||
|
||||
if (!handlers.containsKey(id)) {
|
||||
if (Via.getManager().isDebug())
|
||||
System.out.println("Unhandled BlockEntity " + id + " full tag: " + tag);
|
||||
if (Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -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.ListTag;
|
||||
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.minecraft.Position;
|
||||
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")));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -30,13 +31,14 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||
|
||||
int color = (int) tag.get("Base").getValue();
|
||||
// Standing banner
|
||||
if (blockId >= BANNER_START && blockId <= BANNER_STOP)
|
||||
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
|
||||
blockId += ((15 - color) * 16);
|
||||
// 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);
|
||||
else
|
||||
System.out.println("Why does this block have the banner block entity? :(" + tag);
|
||||
} else {
|
||||
Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
|
||||
}
|
||||
|
||||
if (tag.get("Patterns") instanceof ListTag) {
|
||||
for (Tag pattern : (ListTag) tag.get("Patterns")) {
|
||||
|
@ -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.Tag;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
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")));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentiti
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
|
||||
|
||||
@ -60,7 +61,7 @@ public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler
|
||||
} else if (flowersNumberId.containsKey(pair)) {
|
||||
return flowersNumberId.get(pair);
|
||||
} 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;
|
||||
|
@ -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.Tag;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
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 {
|
||||
private final int SKULL_WALL_START = 5447;
|
||||
private final int SKULL_END = 5566;
|
||||
|
||||
@Override
|
||||
public int transform(UserConnection user, CompoundTag tag) {
|
||||
BlockStorage storage = user.get(BlockStorage.class);
|
||||
Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z")));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -28,12 +30,13 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||
id += (byte) tag.get("Rot").getValue();
|
||||
}
|
||||
} 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 id;
|
||||
}
|
||||
|
||||
private long getLong(Tag tag) {
|
||||
return ((Integer) tag.getValue()).longValue();
|
||||
}
|
||||
|
@ -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.Type;
|
||||
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.ChunkSection1_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -55,7 +55,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
||||
|
||||
byte[] biomeData = groundUp ? new byte[256] : null;
|
||||
if (groundUp) {
|
||||
for (int i = 0; i < 256; i++){
|
||||
for (int i = 0; i < 256; i++) {
|
||||
// todo use int in Chunk?
|
||||
biomeData[i] = 0;
|
||||
}
|
||||
@ -66,8 +66,9 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
||||
// Read all the remaining bytes (workaround for #681)
|
||||
if (input.readableBytes() > 0) {
|
||||
byte[] array = Type.REMAINING_BYTES.read(input);
|
||||
if (Via.getManager().isDebug())
|
||||
System.out.println("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
|
||||
if (Via.getManager().isDebug()) {
|
||||
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);
|
||||
|
@ -64,8 +64,9 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
||||
// Read all the remaining bytes (workaround for #681)
|
||||
if (input.readableBytes() > 0) {
|
||||
byte[] array = Type.REMAINING_BYTES.read(input);
|
||||
if (Via.getManager().isDebug())
|
||||
System.out.println("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
|
||||
if (Via.getManager().isDebug()) {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user