3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Merge pull request #1782 from KennyTV/abstraction

20w21a
Dieser Commit ist enthalten in:
Myles 2020-05-20 16:18:26 +01:00 committet von GitHub
Commit 062d846c37
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
6 geänderte Dateien mit 96 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -1,21 +1,13 @@
package us.myles.ViaVersion.api.minecraft; package us.myles.ViaVersion.api.minecraft;
import java.util.HashMap;
import java.util.Map;
public enum Environment { public enum Environment {
NORMAL(0), NORMAL(0),
NETHER(-1), NETHER(-1),
END(1); END(1),
CUSTOM(Integer.MAX_VALUE);
private final int id; private final int id;
private static final Map<Integer, Environment> lookup = new HashMap<>();
static {
for (Environment env : values()) {
lookup.put(env.getId(), env);
}
}
Environment(int id) { Environment(int id) {
this.id = id; this.id = id;
@ -25,8 +17,28 @@ public enum Environment {
return id; return id;
} }
public static Environment getEnvironmentById(int id) { public static Environment getEnvironmentById(int id) {
return lookup.get(id); switch (id) {
default:
case -1:
return NETHER;
case 0:
return NORMAL;
case 1:
return END;
}
}
public static Environment getEnvironmentById(String id) {
switch (id) {
case "minecraft:the_nether":
return NETHER;
case "minecraft:overworld":
return NORMAL;
case "minecraft:the_end":
return END;
default:
return CUSTOM;
}
} }
} }

Datei anzeigen

@ -80,7 +80,7 @@ public class ProtocolVersion {
register(v1_15 = new ProtocolVersion(573, "1.15")); register(v1_15 = new ProtocolVersion(573, "1.15"));
register(v1_15_1 = new ProtocolVersion(575, "1.15.1")); register(v1_15_1 = new ProtocolVersion(575, "1.15.1"));
register(v1_15_2 = new ProtocolVersion(578, "1.15.2")); register(v1_15_2 = new ProtocolVersion(578, "1.15.2"));
register(v1_16 = new ProtocolVersion(717, "1.16")); register(v1_16 = new ProtocolVersion(718, "1.16"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN")); register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
} }

Datei anzeigen

@ -20,6 +20,7 @@ import java.util.UUID;
public class Protocol1_16To1_15_2 extends Protocol { public class Protocol1_16To1_15_2 extends Protocol {
public static final UUID ZERO_UUID = new UUID(0, 0);
private TagRewriter tagRewriter; private TagRewriter tagRewriter;
public Protocol1_16To1_15_2() { public Protocol1_16To1_15_2() {
@ -49,6 +50,16 @@ public class Protocol1_16To1_15_2 extends Protocol {
} }
}); });
// Chat Message
registerOutgoing(State.PLAY, 0x0F, 0x0F, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING);
map(Type.BYTE);
handler(wrapper -> wrapper.write(Type.UUID, ZERO_UUID)); // sender uuid
}
});
// Entity Sound Effect // Entity Sound Effect
registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() {
@Override @Override

Datei anzeigen

@ -1,9 +1,14 @@
package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets; package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.entities.Entity1_16Types; import us.myles.ViaVersion.api.entities.Entity1_16Types;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
@ -15,6 +20,39 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class EntityPackets { public class EntityPackets {
private static final ValueTransformer<Integer, String> DIMENSION_TRANSFORMER = new ValueTransformer<Integer, String>(Type.INT, Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, Integer input) throws Exception {
switch (input) {
case -1:
return "the_nether";
case 0:
return "overworld";
case 1:
return "the_end";
default:
Via.getPlatform().getLogger().warning("Invalid dimension id: " + input);
return "overworld";
}
}
};
private static final CompoundTag DIMENSIONS_TAG = new CompoundTag("");
static {
ListTag list = new ListTag("dimension", CompoundTag.class);
list.add(createDimensionEntry("minecraft:overworld"));
list.add(createDimensionEntry("minecraft:the_nether"));
list.add(createDimensionEntry("minecraft:the_end"));
DIMENSIONS_TAG.put(list);
}
private static CompoundTag createDimensionEntry(String dimension) {
CompoundTag tag = new CompoundTag("");
tag.put(new StringTag("key", dimension));
tag.put(new StringTag("element", dimension));
return tag;
}
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class); MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class);
@ -37,12 +75,12 @@ public class EntityPackets {
protocol.registerOutgoing(State.PLAY, 0x3B, 0x3B, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x3B, 0x3B, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.INT); map(DIMENSION_TRANSFORMER);
map(Type.LONG); map(Type.LONG);
map(Type.BYTE); map(Type.BYTE);
handler(wrapper -> { handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0); String dimensionId = wrapper.get(Type.STRING, 0);
clientWorld.setEnvironment(dimensionId); clientWorld.setEnvironment(dimensionId);
String levelType = wrapper.read(Type.STRING); String levelType = wrapper.read(Type.STRING);
@ -59,13 +97,19 @@ public class EntityPackets {
public void registerMap() { public void registerMap() {
map(Type.INT); // Entity ID map(Type.INT); // Entity ID
map(Type.UNSIGNED_BYTE); // Gamemode map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.INT); // Dimension map(Type.NOTHING, new ValueTransformer<Void, CompoundTag>(Type.NBT) { // whatever this is
@Override
public CompoundTag transform(PacketWrapper wrapper, Void input) throws Exception {
return DIMENSIONS_TAG;
}
});
map(DIMENSION_TRANSFORMER); // Dimension
map(Type.LONG); // Seed map(Type.LONG); // Seed
map(Type.UNSIGNED_BYTE); // Max players map(Type.UNSIGNED_BYTE); // Max players
handler(wrapper -> { handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1); String dimension = wrapper.get(Type.STRING, 0);
clientChunks.setEnvironment(dimensionId); clientChunks.setEnvironment(dimension);
wrapper.user().get(EntityTracker1_16.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.EntityType.PLAYER); wrapper.user().get(EntityTracker1_16.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.EntityType.PLAYER);

Datei anzeigen

@ -16,12 +16,10 @@ public class ClientWorld extends StoredObject {
} }
public void setEnvironment(int environmentId) { public void setEnvironment(int environmentId) {
this.environment = getEnvFromId(environmentId); this.environment = Environment.getEnvironmentById(environmentId);
} }
private Environment getEnvFromId(int id) { public void setEnvironment(String environmentId) {
Environment output = Environment.getEnvironmentById(id); this.environment = Environment.getEnvironmentById(environmentId);
if (output == null) return Environment.NETHER;
return output;
} }
} }

Datei anzeigen

@ -19047,6 +19047,7 @@
"entity.donkey.angry", "entity.donkey.angry",
"entity.donkey.chest", "entity.donkey.chest",
"entity.donkey.death", "entity.donkey.death",
"entity.donkey.eat",
"entity.donkey.hurt", "entity.donkey.hurt",
"entity.drowned.ambient", "entity.drowned.ambient",
"entity.drowned.ambient_water", "entity.drowned.ambient_water",
@ -19132,6 +19133,7 @@
"entity.fox.sleep", "entity.fox.sleep",
"entity.fox.sniff", "entity.fox.sniff",
"entity.fox.spit", "entity.fox.spit",
"entity.fox.teleport",
"block.roots.break", "block.roots.break",
"block.roots.step", "block.roots.step",
"block.roots.place", "block.roots.place",
@ -19304,8 +19306,10 @@
"entity.mooshroom.suspicious_milk", "entity.mooshroom.suspicious_milk",
"entity.mooshroom.shear", "entity.mooshroom.shear",
"entity.mule.ambient", "entity.mule.ambient",
"entity.mule.angry",
"entity.mule.chest", "entity.mule.chest",
"entity.mule.death", "entity.mule.death",
"entity.mule.eat",
"entity.mule.hurt", "entity.mule.hurt",
"music.creative", "music.creative",
"music.credits", "music.credits",
@ -19425,10 +19429,12 @@
"entity.parrot.imitate.evoker", "entity.parrot.imitate.evoker",
"entity.parrot.imitate.ghast", "entity.parrot.imitate.ghast",
"entity.parrot.imitate.guardian", "entity.parrot.imitate.guardian",
"entity.parrot.imitate.hoglin",
"entity.parrot.imitate.husk", "entity.parrot.imitate.husk",
"entity.parrot.imitate.illusioner", "entity.parrot.imitate.illusioner",
"entity.parrot.imitate.magma_cube", "entity.parrot.imitate.magma_cube",
"entity.parrot.imitate.phantom", "entity.parrot.imitate.phantom",
"entity.parrot.imitate.piglin",
"entity.parrot.imitate.pillager", "entity.parrot.imitate.pillager",
"entity.parrot.imitate.ravager", "entity.parrot.imitate.ravager",
"entity.parrot.imitate.shulker", "entity.parrot.imitate.shulker",
@ -19442,6 +19448,7 @@
"entity.parrot.imitate.witch", "entity.parrot.imitate.witch",
"entity.parrot.imitate.wither", "entity.parrot.imitate.wither",
"entity.parrot.imitate.wither_skeleton", "entity.parrot.imitate.wither_skeleton",
"entity.parrot.imitate.zoglin",
"entity.parrot.imitate.zombie", "entity.parrot.imitate.zombie",
"entity.parrot.imitate.zombie_villager", "entity.parrot.imitate.zombie_villager",
"entity.parrot.step", "entity.parrot.step",