3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-08 22:02:50 +02:00
Dieser Commit ist enthalten in:
Myles 2018-08-12 20:29:30 +01:00
Commit 4f84200a47
16 geänderte Dateien mit 152 neuen und 76 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.api;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import lombok.Getter;
import lombok.Setter;
@ -331,7 +330,7 @@ public class PacketWrapper {
// Apply other protocols
apply(Direction.OUTGOING, user().get(ProtocolInfo.class).getState(), index, protocols);
// Send
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output);
return output;
@ -379,7 +378,7 @@ public class PacketWrapper {
public void send() throws Exception {
if (!isCancelled()) {
// Send
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output);
user().sendRawPacket(output);
}
@ -474,7 +473,7 @@ public class PacketWrapper {
*/
public void sendToServer() throws Exception {
if (!isCancelled()) {
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output);
user().getChannel().pipeline().context(Via.getManager().getInjector().getDecoderName()).fireChannelRead(output);

Datei anzeigen

@ -28,7 +28,7 @@ public class MetadataRewriter {
if (metadata.getId() == 2) {
metadata.setMetaType(MetaType1_13.OptChat);
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
metadata.setValue(Protocol1_9TO1_8.fixJson((String) metadata.getValue()));
metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue()));
} else {
metadata.setValue(null);
}

Datei anzeigen

@ -198,7 +198,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
registerOutgoing(State.PLAY, 0x12, 0x13);
registerOutgoing(State.PLAY, 0x13, 0x14);
// InventoryPackets 0x14 -> 0x15
registerOutgoing(State.PLAY, 0x15, 0x16);
// InventoryPackets 0x15 -> 0x16
// InventoryPackets 0x16 -> 0x17
registerOutgoing(State.PLAY, 0x17, 0x18);
// WorldPackets 0x18 -> 0x19

Datei anzeigen

@ -21,6 +21,7 @@ public class MappingData {
public static Map<String, Integer[]> itemTags = new HashMap<>();
public static Map<String, Integer[]> fluidTags = new HashMap<>();
public static BiMap<Short, String> oldEnchantmentsIds = HashBiMap.create();
public static EnchantmentMappings enchantmentMappings;
public static SoundMappings soundMappings;
public static BlockMappings blockMappings;
@ -38,6 +39,7 @@ public class MappingData {
loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));
Via.getPlatform().getLogger().info("Loading enchantments...");
loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
enchantmentMappings = new EnchantmentMappingByteArray(mapping1_12.getAsJsonObject("enchantments"), mapping1_13.getAsJsonObject("enchantments"));
Via.getPlatform().getLogger().info("Loading sound mapping...");
soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
}
@ -68,6 +70,40 @@ public class MappingData {
}
}
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) {
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
continue;
}
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
}
}
private static void mapIdentifiers(byte[] 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) {
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
continue;
}
output[Integer.parseInt(entry.getKey())] = Byte.parseByte(value.getKey());
}
}
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 void loadTags(Map<String, Integer[]> output, JsonObject newTags) {
for (Map.Entry<String, JsonElement> entry : newTags.entrySet()) {
JsonArray ids = entry.getValue().getAsJsonArray();
@ -79,24 +115,12 @@ public class MappingData {
}
}
public static void loadEnchantments(Map<Short, String> output, JsonObject enchantments) {
private static void loadEnchantments(Map<Short, String> output, JsonObject enchantments) {
for (Map.Entry<String, JsonElement> enchantment : enchantments.entrySet()) {
output.put(Short.parseShort(enchantment.getKey()), enchantment.getValue().getAsString());
}
}
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();
@ -121,29 +145,6 @@ public class MappingData {
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) {
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
continue;
}
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
}
}
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 {
private short[] oldToNew = new short[4084];
@ -175,4 +176,22 @@ public class MappingData {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
public interface EnchantmentMappings {
int getNewEnchantment(int old);
}
private static class EnchantmentMappingByteArray implements EnchantmentMappings {
private byte[] oldToNew = new byte[72];
private EnchantmentMappingByteArray(JsonObject m1_12, JsonObject m1_13) {
Arrays.fill(oldToNew, (byte) -1);
mapIdentifiers(oldToNew, m1_12, m1_13);
}
@Override
public int getNewEnchantment(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
}

Datei anzeigen

@ -67,6 +67,26 @@ public class InventoryPackets {
}
});
// Window property
protocol.registerOutgoing(State.PLAY, 0x15, 0x16, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // Window id
map(Type.SHORT); // Property
map(Type.SHORT); // Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
short property = wrapper.get(Type.SHORT, 0);
if (property >= 4 && property <= 6) { // Enchantment id
wrapper.set(Type.SHORT, 1, (short) MappingData.enchantmentMappings.getNewEnchantment(
wrapper.get(Type.SHORT, 1)
));
}
}
});
}
});
// Plugin message Packet -> Trading
protocol.registerOutgoing(State.PLAY, 0x18, 0x19, new PacketRemapper() {

Datei anzeigen

@ -152,7 +152,7 @@ public class WorldPackets {
if (blockId == 73) { // Note block
PacketWrapper blockChange = wrapper.create(0x0B); // block change
blockChange.write(Type.POSITION, new Position(pos.getX(), pos.getY(), pos.getZ())); // Clone because position is mutable
blockChange.write(Type.VAR_INT, 248 + (action * 24 * 2) + (param * 2));
blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2));
blockChange.send(Protocol1_13To1_12_2.class, true, true);
}
wrapper.set(Type.VAR_INT, 0, blockId);

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -83,7 +82,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
output.writeBoolean(chunk.isGroundUp());
Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer();
ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks;
import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.api.type.Type;
@ -351,12 +350,15 @@ public class ChunkSection1_9_3_4 implements ChunkSection {
private int countBytes(int value) throws Exception {
// Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer();
Type.VAR_INT.write(buf, value);
buf.readerIndex(0);
int bitCount = buf.readableBytes();
buf.release();
return bitCount;
if ((value & (~0 << 7)) == 0)
return 1;
if ((value & (~0 << 14)) == 0)
return 2;
if ((value & (~0 << 21)) == 0)
return 3;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
}
@Override

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -81,7 +80,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
output.writeBoolean(chunk.isGroundUp());
Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer();
ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks;
import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.api.type.Type;
@ -348,11 +347,14 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
private int countBytes(int value) throws Exception {
// Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer();
Type.VAR_INT.write(buf, value);
buf.readerIndex(0);
int bitCount = buf.readableBytes();
buf.release();
return bitCount;
if ((value & (~0 << 7)) == 0)
return 1;
if ((value & (~0 << 14)) == 0)
return 2;
if ((value & (~0 << 21)) == 0)
return 3;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
}
}

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -79,7 +78,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
output.writeBoolean(chunk.isGroundUp());
Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer();
ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks;
import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.api.type.Type;
@ -251,11 +250,14 @@ public class ChunkSection1_9to1_8 implements ChunkSection {
private int countBytes(int value) throws Exception {
// Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer();
Type.VAR_INT.write(buf, value);
buf.readerIndex(0);
int bitCount = buf.readableBytes();
buf.release();
return bitCount;
if ((value & (~0 << 7)) == 0)
return 1;
if ((value & (~0 << 14)) == 0)
return 2;
if ((value & (~0 << 21)) == 0)
return 3;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
}
}

Datei anzeigen

@ -4,7 +4,6 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.google.common.base.Optional;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Position;
@ -158,11 +157,12 @@ public class WorldPackets {
throw new IOException("transformMapChunkBulk returned the wrong object type");
PacketWrapper output = (PacketWrapper) obj;
ByteBuf buffer = Unpooled.buffer();
ByteBuf buffer = wrapper.user().getChannel().alloc().buffer();
output.setId(-1); // -1 for no writing of id
output.writeToBuffer(buffer);
PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user());
chunkPacket.send(Protocol1_9TO1_8.class, false, true);
buffer.release();
}
}
});

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.type.PartialType;
@ -154,7 +153,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00);
Type.VAR_INT.write(output, chunk.getPrimaryBitmask());
ByteBuf buf = Unpooled.buffer();
ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < SECTION_COUNT; i++) {
ChunkSection1_9to1_8 section = chunk.getSections()[i];
if (section == null) continue; // Section not set

Datei anzeigen

@ -154,7 +154,7 @@
"384": "minecraft:sandstone",
"385": "minecraft:chiseled_sandstone",
"386": "minecraft:cut_sandstone",
"400": "minecraft:note_block[instrument=harp,note=0,powered=true]",
"400": "minecraft:note_block[instrument=harp,note=0,powered=false]",
"416": "minecraft:red_bed[facing=south,occupied=false,part=foot]",
"417": "minecraft:red_bed[facing=west,occupied=false,part=foot]",
"418": "minecraft:red_bed[facing=north,occupied=false,part=foot]",

Datei anzeigen

@ -10705,5 +10705,41 @@
"ui.toast.out",
"weather.rain",
"weather.rain.above"
]
],
"enchantments": {
"0": "minecraft:protection",
"1": "minecraft:fire_protection",
"2": "minecraft:feather_falling",
"3": "minecraft:blast_protection",
"4": "minecraft:projectile_protection",
"5": "minecraft:respiration",
"6": "minecraft:aqua_affinity",
"7": "minecraft:thorns",
"8": "minecraft:depth_strider",
"9": "minecraft:frost_walker",
"10": "minecraft:binding_curse",
"11": "minecraft:sharpness",
"12": "minecraft:smite",
"13": "minecraft:bane_of_arthropods",
"14": "minecraft:knockback",
"15": "minecraft:fire_aspect",
"16": "minecraft:looting",
"17": "minecraft:sweeping",
"18": "minecraft:efficiency",
"19": "minecraft:silk_touch",
"20": "minecraft:unbreaking",
"21": "minecraft:fortune",
"22": "minecraft:power",
"23": "minecraft:punch",
"24": "minecraft:flame",
"25": "minecraft:infinity",
"26": "minecraft:luck_of_the_sea",
"27": "minecraft:lure",
"28": "minecraft:loyalty",
"29": "minecraft:impaling",
"30": "minecraft:riptide",
"31": "minecraft:channeling",
"32": "minecraft:mending",
"33": "minecraft:vanishing_curse"
}
}