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

Merge pull request #4 from ViaVersion/dev

Dev
Dieser Commit ist enthalten in:
ForceUpdate1 2019-05-15 13:24:07 +02:00 committet von GitHub
Commit c9eee58a80
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
60 geänderte Dateien mit 9157 neuen und 516 gelöschten Zeilen

Datei anzeigen

@ -15,7 +15,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>2.4.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -44,6 +44,34 @@
<configuration> <configuration>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>false</minimizeJar> <minimizeJar>false</minimizeJar>
<relocations>
<relocation>
<pattern>com.github.steveice10.opennbt</pattern>
<shadedPattern>us.myles.viaversion.libs.opennbt</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>us.myles.viaversion.libs.gson</shadedPattern>
</relocation>
<relocation>
<pattern>javassist</pattern>
<shadedPattern>us.myles.viaversion.libs.javassist</shadedPattern>
</relocation>
<relocation>
<pattern>org.yaml.snakeyaml</pattern>
<shadedPattern>us.myles.viaversion.libs.snakeyaml</shadedPattern>
</relocation>
<relocation>
<pattern>net.md_5.bungee</pattern>
<shadedPattern>us.myles.viaversion.libs.bungeecordchat</shadedPattern>
<includes>
<include>net.md_5.bungee.api.chat.**</include>
<include>net.md_5.bungee.api.ChatColor</include>
<include>net.md_5.bungee.api.ChatMessageType</include>
<include>net.md_5.bungee.chat.**</include>
</includes>
</relocation>
</relocations>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
@ -81,5 +109,11 @@
<artifactId>viabackwards-sponge</artifactId> <artifactId>viabackwards-sponge</artifactId>
<version>${project.parent.version}</version> <version>${project.parent.version}</version>
</dependency> </dependency>
<dependency>
<groupId>nl.matsv</groupId>
<artifactId>viabackwards-velocity</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

Datei anzeigen

@ -15,7 +15,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>2.4.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -15,7 +15,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>2.4.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -15,7 +15,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>2.4.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -12,18 +12,18 @@ package nl.matsv.viabackwards.api;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1; import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
import nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2; import nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1; import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1;
import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2; import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.update.Version;
import java.lang.reflect.Field;
import java.util.Collections; import java.util.Collections;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -54,21 +54,22 @@ public interface ViaBackwardsPlatform {
*/ */
Logger getLogger(); Logger getLogger();
// TODO remove or better implement later
default boolean isOutdated() { default boolean isOutdated() {
String minimumVVVersion = "2.0.0";
boolean upToDate = false; boolean upToDate = false;
try { try {
Class<?> clazz = Class.forName("us.myles.ViaVersion.api.protocol.ProtocolVersion"); Class<?> vvVersionInfo = Class.forName("us.myles.ViaVersion.sponge.VersionInfo");
Field v1_13 = clazz.getField("v1_13"); String vvVersion = (String) vvVersionInfo.getField("VERSION").get(null);
upToDate = (v1_13 != null); upToDate = (vvVersion != null
} catch (ClassNotFoundException | NoSuchFieldException ignored) { && new Version(vvVersion).compareTo(new Version(minimumVVVersion + "--")) >= 0);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) {
} }
if (!upToDate) { if (!upToDate) {
getLogger().severe("================================"); getLogger().severe("================================");
getLogger().severe("YOUR VIAVERSION IS OUTDATED"); getLogger().severe("YOUR VIAVERSION IS OUTDATED");
getLogger().severe("PLEASE USE THE LATEST VERSION"); getLogger().severe("PLEASE USE VIAVERSION " + minimumVVVersion + " OR NEWER");
getLogger().severe("LINK: https://viaversion.com"); getLogger().severe("LINK: https://viaversion.com");
getLogger().severe("VIABACKWARDS WILL NOW DISABLE"); getLogger().severe("VIABACKWARDS WILL NOW DISABLE");
getLogger().severe("================================"); getLogger().severe("================================");

Datei anzeigen

@ -0,0 +1,311 @@
package nl.matsv.viabackwards.api.entities.types;
import lombok.AllArgsConstructor;
import lombok.Getter;
import nl.matsv.viabackwards.ViaBackwards;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class EntityType1_13 {
public static EntityType getTypeFromId(int typeID, boolean isObject) {
Optional<EntityType> type;
if (isObject)
type = ObjectType.getPCEntity(typeID);
else
type = EntityType.findById(typeID);
if (!type.isPresent()) {
ViaBackwards.getPlatform().getLogger().severe("[EntityType1_13] Could not find type id " + typeID + " isObject=" + isObject);
return EntityType.ENTITY; // Fall back to the basic ENTITY
}
return type.get();
}
@AllArgsConstructor
@Getter
public enum EntityType implements AbstractEntityType {
ENTITY(-1), // abm
AREA_EFFECT_CLOUD(0, ENTITY), // abk
ENDER_CRYSTAL(16, ENTITY), // aho
EVOCATION_FANGS(20, ENTITY), // ala
XP_ORB(22, ENTITY), // abs
EYE_OF_ENDER_SIGNAL(23, ENTITY), // alb
FALLING_BLOCK(24, ENTITY), // aix
FIREWORKS_ROCKET(25, ENTITY), // alc
ITEM(32, ENTITY), // aiy
LLAMA_SPIT(37, ENTITY), // ale
TNT(55, ENTITY), // aiz
SHULKER_BULLET(60, ENTITY), // alh
FISHING_BOBBER(93, ENTITY), // ais
LIVINGENTITY(-1, ENTITY), // abv
ARMOR_STAND(1, LIVINGENTITY), // ail
PLAYER(92, LIVINGENTITY), // aks
ABSTRACT_INSENTIENT(-1, LIVINGENTITY), // abw
ENDER_DRAGON(17, ABSTRACT_INSENTIENT), // ahp
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT), // acd
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE), // abj
VILLAGER(79, ABSTRACT_AGEABLE), // akn
// Animals
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE), // agd
CHICKEN(7, ABSTRACT_ANIMAL), // age
COW(9, ABSTRACT_ANIMAL), // agg
MOOSHROOM(47, COW), // agi
PIG(51, ABSTRACT_ANIMAL), // agl
POLAR_BEAR(54, ABSTRACT_ANIMAL), // agm
RABBIT(56, ABSTRACT_ANIMAL), // ago
SHEEP(58, ABSTRACT_ANIMAL), // agq
TURTLE(73, ABSTRACT_ANIMAL), // agv
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL), // acg
OCELOT(48, ABSTRACT_TAMEABLE_ANIMAL), // agj
WOLF(86, ABSTRACT_TAMEABLE_ANIMAL), // agy
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL), // agr
PARROT(50, ABSTRACT_PARROT), // agk
// Horses
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL), // aha
CHESTED_HORSE(-1, ABSTRACT_HORSE), // agz
DONKEY(11, CHESTED_HORSE), // ahb
MULE(46, CHESTED_HORSE), // ahf
LLAMA(36, CHESTED_HORSE), // ahe
HORSE(29, ABSTRACT_HORSE), // ahc
SKELETON_HORSE(63, ABSTRACT_HORSE), // ahg
ZOMBIE_HORSE(88, ABSTRACT_HORSE), // ahi
// Golem
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE), // agc
SNOWMAN(66, ABSTRACT_GOLEM), // ags
VILLAGER_GOLEM(80, ABSTRACT_GOLEM), // agw
SHULKER(59, ABSTRACT_GOLEM), // ajx
// Fish
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE), // agb
COD_MOB(8, ABSTRACT_FISHES), // agf
PUFFER_FISH(52, ABSTRACT_FISHES), // agn
SALMON_MOB(57, ABSTRACT_FISHES), // agp
TROPICAL_FISH(72, ABSTRACT_FISHES), // agu
// Monsters
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE), // ajs
BLAZE(4, ABSTRACT_MONSTER), // ajd
CREEPER(10, ABSTRACT_MONSTER), // ajf
ENDERMITE(19, ABSTRACT_MONSTER), // ajj
ENDERMAN(18, ABSTRACT_MONSTER), // aji
GIANT(27, ABSTRACT_MONSTER), // ajn
SILVERFISH(61, ABSTRACT_MONSTER), // ajy
VEX(78, ABSTRACT_MONSTER), // ake
WITCH(82, ABSTRACT_MONSTER), // akg
WITHER(83, ABSTRACT_MONSTER), // aij
// Illagers
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER), // ajb
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE), // akb
EVOCATION_ILLAGER(21, ABSTRACT_EVO_ILLU_ILLAGER), // ajl
ILLUSION_ILLAGER(31, ABSTRACT_EVO_ILLU_ILLAGER), // ajq
VINDICATION_ILLAGER(81, ABSTRACT_ILLAGER_BASE), // akf
// Skeletons
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER), // ajc
SKELETON(62, ABSTRACT_SKELETON), // ajz
STRAY(71, ABSTRACT_SKELETON), // akd
WITHER_SKELETON(84, ABSTRACT_SKELETON), // akh
// Guardians
GUARDIAN(28, ABSTRACT_MONSTER), // ajo
ELDER_GUARDIAN(15, GUARDIAN), // ajh
// Spiders
SPIDER(69, ABSTRACT_MONSTER), // akc
CAVE_SPIDER(6, SPIDER), // aje
// Zombies - META CHECKED
ZOMBIE(87, ABSTRACT_MONSTER), // aki
DROWNED(14, ZOMBIE), // ajg
HUSK(30, ZOMBIE), // ajp
ZOMBIE_PIGMAN(53, ZOMBIE), // aju
ZOMBIE_VILLAGER(89, ZOMBIE), // akj
// Flying entities
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT), // abt
GHAST(26, ABSTRACT_FLYING), // ajm
PHANTOM(90, ABSTRACT_FLYING), // ajt
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT), // afy
BAT(3, ABSTRACT_AMBIENT), // afz
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT), // agx
SQUID(70, ABSTRACT_WATERMOB), // agt
DOLPHIN(12, ABSTRACT_WATERMOB), // ajq
// Slimes
SLIME(64, ABSTRACT_INSENTIENT), // aka
MAGMA_CUBE(38, SLIME), // ajr
// Hangable objects
ABSTRACT_HANGING(-1, ENTITY), // aim
LEASH_KNOT(35, ABSTRACT_HANGING), // aio
ITEM_FRAME(33, ABSTRACT_HANGING), // ain
PAINTING(49, ABSTRACT_HANGING), // aiq
ABSTRACT_LIGHTNING(-1, ENTITY), // aiu
LIGHTNING_BOLT(91, ABSTRACT_LIGHTNING), // aiv
// Arrows
ABSTRACT_ARROW(-1, ENTITY), // akw
ARROW(2, ABSTRACT_ARROW), // aky
SPECTRAL_ARROW(68, ABSTRACT_ARROW), // alk
TRIDENT(94, ABSTRACT_ARROW), // alq
// Fireballs
ABSTRACT_FIREBALL(-1, ENTITY), // akx
DRAGON_FIREBALL(13, ABSTRACT_FIREBALL), // akz
FIREBALL(34, ABSTRACT_FIREBALL), // ald
SMALL_FIREBALL(65, ABSTRACT_FIREBALL), // ali
WITHER_SKULL(85, ABSTRACT_FIREBALL), // alr
// Projectiles
PROJECTILE_ABSTRACT(-1, ENTITY), // all
SNOWBALL(67, PROJECTILE_ABSTRACT), // alj
ENDER_PEARL(75, PROJECTILE_ABSTRACT), // aln
EGG(74, PROJECTILE_ABSTRACT), // alm
POTION(77, PROJECTILE_ABSTRACT), // alp
XP_BOTTLE(76, PROJECTILE_ABSTRACT), // alo
// Vehicles
MINECART_ABSTRACT(-1, ENTITY), // alt
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT), // alu
CHEST_MINECART(40, CHESTED_MINECART_ABSTRACT), // alx
HOPPER_MINECART(43, CHESTED_MINECART_ABSTRACT), // ama
MINECART(39, MINECART_ABSTRACT), // alw
FURNACE_MINECART(42, MINECART_ABSTRACT), // alz
COMMANDBLOCK_MINECART(41, MINECART_ABSTRACT), // aly
TNT_MINECART(45, MINECART_ABSTRACT), // amc
SPAWNER_MINECART(44, MINECART_ABSTRACT), // amb
BOAT(5, ENTITY); // alv
private final int id;
private final EntityType parent;
EntityType(int id) {
this.id = id;
this.parent = null;
}
public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called
return Optional.empty();
for (EntityType ent : EntityType.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.empty();
}
public boolean is(AbstractEntityType... types) {
for (AbstractEntityType type : types)
if (is(type))
return true;
return false;
}
public boolean is(AbstractEntityType type) {
return this == type;
}
public boolean isOrHasParent(AbstractEntityType type) {
EntityType parent = this;
do {
if (parent == type)
return true;
parent = parent.getParent();
} while (parent != null);
return false;
}
@Override
public List<AbstractEntityType> getParents() {
List<AbstractEntityType> types = new ArrayList<>();
EntityType parent = this;
do {
types.add(parent);
parent = parent.getParent();
} while (parent != null);
return types;
}
}
@AllArgsConstructor
@Getter
public enum ObjectType implements AbstractObjectType {
BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.ITEM),
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
MINECART(10, EntityType.MINECART_ABSTRACT),
TNT_PRIMED(50, EntityType.TNT),
ENDER_CRYSTAL(51, EntityType.ENDER_CRYSTAL),
TIPPED_ARROW(60, EntityType.ARROW),
SNOWBALL(61, EntityType.SNOWBALL),
EGG(62, EntityType.EGG),
FIREBALL(63, EntityType.FIREBALL),
SMALL_FIREBALL(64, EntityType.SMALL_FIREBALL),
ENDER_PEARL(65, EntityType.ENDER_PEARL),
WITHER_SKULL(66, EntityType.WITHER_SKULL),
SHULKER_BULLET(67, EntityType.SHULKER_BULLET),
LIAMA_SPIT(68, EntityType.LLAMA_SPIT),
FALLING_BLOCK(70, EntityType.FALLING_BLOCK),
ITEM_FRAME(71, EntityType.ITEM_FRAME),
ENDER_SIGNAL(72, EntityType.EYE_OF_ENDER_SIGNAL),
POTION(73, EntityType.POTION),
THROWN_EXP_BOTTLE(75, EntityType.XP_BOTTLE),
FIREWORK(76, EntityType.FIREWORKS_ROCKET),
LEASH(77, EntityType.LEASH_KNOT),
ARMOR_STAND(78, EntityType.ARMOR_STAND),
EVOCATION_FANGS(79, EntityType.EVOCATION_FANGS),
FISHIHNG_HOOK(90, EntityType.FISHING_BOBBER),
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
private final int id;
private final EntityType type;
public static Optional<ObjectType> findById(int id) {
if (id == -1)
return Optional.empty();
for (ObjectType ent : ObjectType.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.empty();
}
public static Optional<EntityType> getPCEntity(int id) {
Optional<ObjectType> output = findById(id);
return output.map(ObjectType::getType);
}
}
}

Datei anzeigen

@ -17,7 +17,7 @@ import lombok.ToString;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.blockitem.BlockItemSettings; import nl.matsv.viabackwards.api.entities.blockitem.BlockItemSettings;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import nl.matsv.viabackwards.utils.Block; import nl.matsv.viabackwards.utils.Block;
import nl.matsv.viabackwards.utils.ItemUtil; import nl.matsv.viabackwards.utils.ItemUtil;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -138,10 +138,18 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
if (!(tag.contains("x") && tag.contains("y") && tag.contains("z"))) if (!(tag.contains("x") && tag.contains("y") && tag.contains("z")))
continue; continue;
Pos pos = new Pos( Pos pos = new Pos(
(int) tag.get("x").getValue() % 16, (int) tag.get("x").getValue() & 0xF,
(int) tag.get("y").getValue(), (int) tag.get("y").getValue(),
(int) tag.get("z").getValue() % 16); (int) tag.get("z").getValue() & 0xF);
tags.put(pos, tag); tags.put(pos, tag);
// Handle given Block Entities
ChunkSection section = chunk.getSections()[pos.getY() >> 4];
if (section == null) continue;
int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ());
int btype = block >> 4;
if (!hasBlockEntityHandler(btype)) continue;
replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
} }
for (int i = 0; i < chunk.getSections().length; i++) { for (int i = 0; i < chunk.getSections().length; i++) {
@ -149,32 +157,45 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
if (section == null) if (section == null)
continue; continue;
boolean hasBlockEntityHandler = false;
// Map blocks
for (int j = 0; j < section.getPaletteSize(); j++) {
int block = section.getPaletteEntry(j);
int btype = block >> 4;
int meta = block & 0xF;
if (containsBlock(btype)) {
Block b = handleBlock(btype, meta);
section.setPaletteEntry(j, (b.getId() << 4) | (b.getData() & 0xF));
}
hasBlockEntityHandler = hasBlockEntityHandler || hasBlockEntityHandler(btype);
}
if (!hasBlockEntityHandler) continue;
// We need to handle a Block Entity :(
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
int block = section.getBlock(x, y, z); int block = section.getFlatBlock(x, y, z);
int btype = block >> 4; int btype = block >> 4;
int meta = block & 15; int meta = block & 15;
if (containsBlock(btype)) { if (!hasBlockEntityHandler(btype)) continue;
Block b = handleBlock(btype, meta); // Type / data
section.setBlock(x, y, z, b.getId(), b.getData());
}
// Entity Tags
if (hasBlockEntityHandler(btype)) {
Pos pos = new Pos(x, (y + (i << 4)), z); Pos pos = new Pos(x, (y + (i << 4)), z);
CompoundTag tag = null;
if (tags.containsKey(pos)) { // Already handled above
tag = tags.get(pos); if (tags.containsKey(pos)) continue;
} else {
tag = new CompoundTag(""); CompoundTag tag = new CompoundTag("");
tag.put(new IntTag("x", x + (chunk.getX() << 4))); tag.put(new IntTag("x", x + (chunk.getX() << 4)));
tag.put(new IntTag("y", y + (i << 4))); tag.put(new IntTag("y", y + (i << 4)));
tag.put(new IntTag("z", z + (chunk.getZ() << 4))); tag.put(new IntTag("z", z + (chunk.getZ() << 4)));
chunk.getBlockEntities().add(tag);
}
replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag); replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
} chunk.getBlockEntities().add(tag);
} }
} }
} }

Datei anzeigen

@ -60,6 +60,10 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
getEntityTracker(connection).trackEntityType(entityId, type); getEntityTracker(connection).trackEntityType(entityId, type);
} }
protected boolean hasData(AbstractEntityType type) {
return entityTypes.containsKey(type);
}
protected Optional<EntityData> getEntityData(AbstractEntityType type) { protected Optional<EntityData> getEntityData(AbstractEntityType type) {
if (!entityTypes.containsKey(type)) if (!entityTypes.containsKey(type))
return Optional.empty(); return Optional.empty();
@ -144,9 +148,10 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
EntityData entData = opEd.get(); EntityData entData = opEd.get();
if (entData.getMobName() != null && if (entData.getMobName() != null &&
(data.getValue() == null || ((String) data.getValue()).isEmpty()) && (data.getValue() == null || ((String) data.getValue()).isEmpty()) &&
data.getMetaType().getTypeID() == getDisplayNameMetaType().getTypeID()) data.getMetaType().getTypeID() == getDisplayNameMetaType().getTypeID()) {
data.setValue(entData.getMobName()); data.setValue(entData.getMobName());
} }
}
} }

Datei anzeigen

@ -18,17 +18,18 @@ import nl.matsv.viabackwards.protocol.protocol1_10to1_11.EntityTypeNames;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import nl.matsv.viabackwards.utils.Block; import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
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.remapper.PacketHandler; 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;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
@ -226,7 +227,7 @@ public class BlockItemPackets1_11 extends BlockItemRewriter<Protocol1_10To1_11>
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.10 Chunk type since nothing changed. Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.10 Chunk type since nothing changed.
Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type); Chunk chunk = wrapper.passthrough(type);
handleChunk(chunk); handleChunk(chunk);
@ -269,18 +270,13 @@ public class BlockItemPackets1_11 extends BlockItemRewriter<Protocol1_10To1_11>
public void registerMap() { public void registerMap() {
map(Type.INT); // 0 - Chunk X map(Type.INT); // 0 - Chunk X
map(Type.INT); // 1 - Chunk Z map(Type.INT); // 1 - Chunk Z
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int count = wrapper.passthrough(Type.VAR_INT); // Array length for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
record.setBlockId(handleBlockID(record.getBlockId()));
for (int i = 0; i < count; i++) {
wrapper.passthrough(Type.UNSIGNED_BYTE); // Horizontal position
wrapper.passthrough(Type.UNSIGNED_BYTE); // Y coords
int id = wrapper.read(Type.VAR_INT); // Block ID
wrapper.write(Type.VAR_INT, handleBlockID(id));
} }
} }
}); });

Datei anzeigen

@ -17,7 +17,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer; 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.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
public class PlayerPackets1_11 { public class PlayerPackets1_11 {
private static final ValueTransformer<Short, Float> toNewFloat = new ValueTransformer<Short, Float>(Type.FLOAT) { private static final ValueTransformer<Short, Float> toNewFloat = new ValueTransformer<Short, Float>(Type.FLOAT) {
@ -45,10 +45,13 @@ public class PlayerPackets1_11 {
if (action == 2) { if (action == 2) {
// Convert to the old actionbar way // Convert to the old actionbar way
PacketWrapper actionbar = new PacketWrapper(0x0F, null, wrapper.user()); // Chat Message packet PacketWrapper actionbar = new PacketWrapper(0x0F, null, wrapper.user()); // Chat Message packet
actionbar.write(Type.STRING, wrapper.read(Type.STRING)); String msg = wrapper.read(Type.STRING);
msg = ChatRewriter.jsonTextToLegacy(msg);
msg = "{\"text\":\"" + msg + "\"}";
actionbar.write(Type.STRING, msg);
actionbar.write(Type.BYTE, (byte) 2); // Above hotbar actionbar.write(Type.BYTE, (byte) 2); // Above hotbar
actionbar.send(Protocol1_11To1_10.class); actionbar.send(Protocol1_10To1_11.class);
wrapper.cancel(); // Cancel the title packet wrapper.cancel(); // Cancel the title packet
return; return;

Datei anzeigen

@ -8,19 +8,19 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12;
import lombok.Getter; import lombok.Getter;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.ShoulderTracker; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets.*; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets.*;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
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;
@Getter @Getter
public class Protocol1_11_1To1_12 extends BackwardsProtocol { public class Protocol1_11_1To1_12 extends BackwardsProtocol {
// TODO store all rewriters and make them easy accessible? // TODO checkAndStore all rewriters and make them easy accessible?
private EntityPackets1_12 entityPackets; private EntityPackets1_12 entityPackets;
private BlockItemPackets1_12 blockItemPackets; private BlockItemPackets1_12 blockItemPackets;

Datei anzeigen

@ -8,7 +8,7 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;

Datei anzeigen

@ -8,7 +8,7 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;

Datei anzeigen

@ -1,4 +1,4 @@
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

Datei anzeigen

@ -8,7 +8,7 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
import lombok.Data; import lombok.Data;
import nl.matsv.viabackwards.api.entities.storage.EntityStorage; import nl.matsv.viabackwards.api.entities.storage.EntityStorage;

Datei anzeigen

@ -8,7 +8,7 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -20,7 +20,7 @@ import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
@Getter @Getter
@Setter @Setter
@ -37,7 +37,7 @@ public class ShoulderTracker extends StoredObject {
public void update() { public void update() {
PacketWrapper wrapper = new PacketWrapper(0x0F, null, getUser()); PacketWrapper wrapper = new PacketWrapper(0x0F, null, getUser());
wrapper.write(Type.STRING, Protocol1_9TO1_8.fixJson(generateString())); wrapper.write(Type.STRING, Protocol1_9To1_8.fixJson(generateString()));
wrapper.write(Type.BYTE, (byte) 2); wrapper.write(Type.BYTE, (byte) 2);
try { try {

Datei anzeigen

@ -8,24 +8,26 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter; import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.MapColorMapping; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.MapColorMapping;
import nl.matsv.viabackwards.utils.Block; import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
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.remapper.PacketHandler; 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;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.DoubleTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
import java.util.Collections; import java.util.Collections;
@ -171,6 +173,24 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
if (wrapper.get(Type.VAR_INT, 0) == 1) { // Shift click
// https://github.com/ViaVersion/ViaVersion/pull/754
// Previously clients grab the item from the clicked slot *before* it has
// been moved however now they grab the slot item *after* it has been moved
// and send that in the packet.
wrapper.set(Type.ITEM, 0, null); // Set null item (probably will work)
// Apologize (may happen in some cases, maybe if inventory is full?)
PacketWrapper confirm = wrapper.create(0x6);
confirm.write(Type.BYTE, wrapper.get(Type.UNSIGNED_BYTE, 0).byteValue());
confirm.write(Type.SHORT, wrapper.get(Type.SHORT, 1));
confirm.write(Type.BOOLEAN, false); // Success - not used
wrapper.sendToServer(Protocol1_11_1To1_12.class, true, true);
wrapper.cancel();
confirm.sendToServer(Protocol1_11_1To1_12.class, true, true);
return;
}
Item item = wrapper.get(Type.ITEM, 0); Item item = wrapper.get(Type.ITEM, 0);
handleItemToServer(item); handleItemToServer(item);
} }
@ -209,7 +229,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.9.4 Chunk type since nothing changed. Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.9.4 Chunk type since nothing changed.
Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type); Chunk chunk = wrapper.passthrough(type);
handleChunk(chunk); handleChunk(chunk);
} }
@ -242,18 +262,13 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
public void registerMap() { public void registerMap() {
map(Type.INT); // 0 - Chunk X map(Type.INT); // 0 - Chunk X
map(Type.INT); // 1 - Chunk Z map(Type.INT); // 1 - Chunk Z
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int count = wrapper.passthrough(Type.VAR_INT); // Array length for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
record.setBlockId(handleBlockID(record.getBlockId()));
for (int i = 0; i < count; i++) {
wrapper.passthrough(Type.UNSIGNED_BYTE); // Horizontal position
wrapper.passthrough(Type.UNSIGNED_BYTE); // Y coords
int id = wrapper.read(Type.VAR_INT); // Block ID
wrapper.write(Type.VAR_INT, handleBlockID(id));
} }
} }
}); });

Datei anzeigen

@ -8,10 +8,10 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import nl.matsv.viabackwards.api.rewriters.Rewriter; import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -87,7 +87,7 @@ public class ChangedPacketIds1_12 extends Rewriter<Protocol1_11_1To1_12> {
p.registerOutgoing(State.PLAY, 0x4D, 0x4A); // Entity Properties p.registerOutgoing(State.PLAY, 0x4D, 0x4A); // Entity Properties
p.registerOutgoing(State.PLAY, 0x4E, 0x4B); // Entity Effect p.registerOutgoing(State.PLAY, 0x4E, 0x4B); // Entity Effect
p.registerIncoming(State.PLAY, 0x01, -1); // Prepare Crafting Grid // New incoming packet 0x01 - Prepare Crafting Grid
p.registerIncoming(State.PLAY, 0x02, 0x01); // Tab-Complete (Serverbound) p.registerIncoming(State.PLAY, 0x02, 0x01); // Tab-Complete (Serverbound)
p.registerIncoming(State.PLAY, 0x03, 0x02); // Chat Message (Serverbound) p.registerIncoming(State.PLAY, 0x03, 0x02); // Chat Message (Serverbound)
// 0x04->0x03 Client Status handled in BlockItemPackets1_12.java // 0x04->0x03 Client Status handled in BlockItemPackets1_12.java
@ -109,9 +109,9 @@ public class ChangedPacketIds1_12 extends Rewriter<Protocol1_11_1To1_12> {
p.registerIncoming(State.PLAY, 0x14, 0x13); // Player Digging p.registerIncoming(State.PLAY, 0x14, 0x13); // Player Digging
p.registerIncoming(State.PLAY, 0x15, 0x14); // Entity Action p.registerIncoming(State.PLAY, 0x15, 0x14); // Entity Action
p.registerIncoming(State.PLAY, 0x16, 0x15); // Steer Vehicle p.registerIncoming(State.PLAY, 0x16, 0x15); // Steer Vehicle
p.registerIncoming(State.PLAY, 0x17, -1); // Crafting Book Data // New incoming packet 0x17 - Crafting Book Data
p.registerIncoming(State.PLAY, 0x18, 0x16); // Resource Pack Status p.registerIncoming(State.PLAY, 0x18, 0x16); // Resource Pack Status
p.registerIncoming(State.PLAY, 0x19, -1); // Advancement Tab // New incoming packet 0x19 - Advancement Tab
p.registerIncoming(State.PLAY, 0x1A, 0x17); // Held Item Change (Serverbound) p.registerIncoming(State.PLAY, 0x1A, 0x17); // Held Item Change (Serverbound)
// 0x1B -> 0x18 Creative Inventory Action handled in BlockItemPackets.java // 0x1B -> 0x18 Creative Inventory Action handled in BlockItemPackets.java
p.registerIncoming(State.PLAY, 0x1C, 0x19); // Update Sign p.registerIncoming(State.PLAY, 0x1C, 0x19); // Update Sign

Datei anzeigen

@ -8,12 +8,12 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.Rewriter; import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.AdvancementTranslations; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTranslations;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;

Datei anzeigen

@ -8,7 +8,7 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityData;
@ -17,9 +17,9 @@ import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
import nl.matsv.viabackwards.api.entities.types.EntityType1_12; import nl.matsv.viabackwards.api.entities.types.EntityType1_12;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.ParrotStorage; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.ShoulderTracker; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
import nl.matsv.viabackwards.utils.Block; import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;

Datei anzeigen

@ -8,10 +8,10 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;

Datei anzeigen

@ -10,75 +10,64 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13; package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13;
import lombok.Getter;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.SoundMapping;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.EntityPackets1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerPacket1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.SoundPackets1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.remapper.PacketHandler; 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.packets.State; import us.myles.ViaVersion.packets.State;
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;
@Getter
public class Protocol1_12_2To1_13 extends BackwardsProtocol { public class Protocol1_12_2To1_13 extends BackwardsProtocol {
private BlockItemPackets1_13 blockItemPackets;
static {
BackwardsMappings.init();
PaintingMapping.init();
SoundMapping.init();
}
@Override @Override
protected void registerPackets() { protected void registerPackets() {
new BlockItemPackets1_13().register(this); (blockItemPackets = new BlockItemPackets1_13()).register(this);
new EntityPackets1_13().register(this);
new PlayerPacket1_13().register(this);
new SoundPackets1_13().register(this);
// Thanks to https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14150 // Thanks to https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14150
out(State.PLAY, 0x00, 0x00, cancel());
out(State.PLAY, 0x04, 0x04, cancel());// Spawn Painting TODO MODIFIED
out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED
out(State.PLAY, 0x09, 0x09, cancel()); // Update Block Entity TODO MODIFIED
out(State.PLAY, 0x0B, 0x0B, cancel()); // Block Change TODO MODIFIED
out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound) out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound)
out(State.PLAY, 0x0F, 0x10, cancel()); // Multi Block Change TODO MODIFIED
out(State.PLAY, 0x10, 0x0E, cancel()); // Tab-Complete (clientbound) TODO MODIFIED
out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW
out(State.PLAY, 0x12, 0x11, cancel()); // Confirm Transaction (clientbound) out(State.PLAY, 0x12, 0x11); // Confirm Transaction (clientbound)
out(State.PLAY, 0x13, 0x12, cancel()); // Close Window (clientbound) out(State.PLAY, 0x13, 0x12); // Close Window (clientbound)
out(State.PLAY, 0x14, 0x13, cancel()); // Open Window out(State.PLAY, 0x14, 0x13); // Open Window
out(State.PLAY, 0x15, 0x14, cancel()); // Window Items out(State.PLAY, 0x16, 0x15); // Window Property
out(State.PLAY, 0x16, 0x15, cancel()); // Window Property
out(State.PLAY, 0x17, 0x16, cancel()); // Set Slot
out(State.PLAY, 0x18, 0x17); // Set Cooldown out(State.PLAY, 0x18, 0x17); // Set Cooldown
out(State.PLAY, 0x19, 0x18); // Plugin Message (clientbound) TODO MODIFIED
out(State.PLAY, 0x1A, 0x19, cancel()); // Named Sound Effect TODO MODIFIED
out(State.PLAY, 0x1B, 0x1A); // Disconnect (play) out(State.PLAY, 0x1B, 0x1A); // Disconnect (play)
out(State.PLAY, 0x1C, 0x1B); // Entity Status out(State.PLAY, 0x1C, 0x1B); // Entity Status
out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response TODO NEW out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response (client won't send a request, so the server should not answer)
out(State.PLAY, 0x1E, 0x1C); // Explosion out(State.PLAY, 0x1E, 0x1C); // Explosion
out(State.PLAY, 0x1F, 0x1D); // Unload Chunk out(State.PLAY, 0x1F, 0x1D); // Unload Chunk
out(State.PLAY, 0x20, 0x1E); // Change Game State out(State.PLAY, 0x20, 0x1E); // Change Game State
out(State.PLAY, 0x21, 0x1F); // Keep Alive (clientbound) out(State.PLAY, 0x21, 0x1F); // Keep Alive (clientbound)
// Chunk Data -> moved to BlockItemPackets
out(State.PLAY, 0x23, 0x21, cancel()); // Effect TODO MODIFIED
out(State.PLAY, 0x24, 0x22, cancel()); // Spawn Particle TODO MODIFIED out(State.PLAY, 0x24, 0x22, cancel()); // Spawn Particle TODO MODIFIED
out(State.PLAY, 0x25, 0x23, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
}
});
}
}); // Join Game
out(State.PLAY, 0x26, 0x24, cancel()); // Map TODO MODIFIED
out(State.PLAY, 0x27, 0x25); // Entity out(State.PLAY, 0x27, 0x25); // Entity
out(State.PLAY, 0x28, 0x26); // Entity Relative Move out(State.PLAY, 0x28, 0x26); // Entity Relative Move
out(State.PLAY, 0x29, 0x27); // Entity Look And Relative Move out(State.PLAY, 0x29, 0x27); // Entity Look And Relative Move
@ -88,55 +77,39 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
out(State.PLAY, 0x2D, 0x2B, cancel()); // Craft Recipe Response TODO MODIFIED out(State.PLAY, 0x2D, 0x2B, cancel()); // Craft Recipe Response TODO MODIFIED
out(State.PLAY, 0x2E, 0x2C); // Player Abilities (clientbound) out(State.PLAY, 0x2E, 0x2C); // Player Abilities (clientbound)
out(State.PLAY, 0x2F, 0x2D); // Combat Event out(State.PLAY, 0x2F, 0x2D); // Combat Event
out(State.PLAY, 0x30, 0x2E); // Player List Item
out(State.PLAY, 0x31, -1, cancel()); // Face Player TODO NEW out(State.PLAY, 0x31, -1, cancel()); // Face Player TODO NEW
out(State.PLAY, 0x32, 0x2F); // Player Position And Look (clientbound) out(State.PLAY, 0x32, 0x2F); // Player Position And Look (clientbound)
out(State.PLAY, 0x33, 0x30); // Use Bed out(State.PLAY, 0x33, 0x30); // Use Bed
out(State.PLAY, 0x34, 0x31, cancel()); // Unlock Recipes TODO MODIFIED out(State.PLAY, 0x34, 0x31, cancel()); // Unlock Recipes TODO MODIFIED
out(State.PLAY, 0x35, 0x32); // Destroy Entities
out(State.PLAY, 0x36, 0x33); // Remove Entity Effect out(State.PLAY, 0x36, 0x33); // Remove Entity Effect
out(State.PLAY, 0x37, 0x34); // Resource Pack Send out(State.PLAY, 0x37, 0x34); // Resource Pack Send
out(State.PLAY, 0x38, 0x35); // Respawn
out(State.PLAY, 0x39, 0x36); // Entity Head Look out(State.PLAY, 0x39, 0x36); // Entity Head Look
out(State.PLAY, 0x3A, 0x37); // Select Advancement Tab out(State.PLAY, 0x3A, 0x37); // Select Advancement Tab
out(State.PLAY, 0x3B, 0x38); // World Border out(State.PLAY, 0x3B, 0x38); // World Border
out(State.PLAY, 0x3C, 0x39); // Camera out(State.PLAY, 0x3C, 0x39); // Camera
out(State.PLAY, 0x3D, 0x3A, cancel()); // Held Item Change (clientbound) out(State.PLAY, 0x3D, 0x3A); // Held Item Change (clientbound)
out(State.PLAY, 0x3E, 0x3B); // Display Scoreboard out(State.PLAY, 0x3E, 0x3B); // Display Scoreboard
out(State.PLAY, 0x3F, 0x3C, cancel()); // Entity Metadata
out(State.PLAY, 0x40, 0x3D); // Attach Entity out(State.PLAY, 0x40, 0x3D); // Attach Entity
out(State.PLAY, 0x41, 0x3E); // Entity Velocity out(State.PLAY, 0x41, 0x3E); // Entity Velocity
out(State.PLAY, 0x42, 0x3F, cancel()); // Entity Equipment
out(State.PLAY, 0x43, 0x40); // Set Experience out(State.PLAY, 0x43, 0x40); // Set Experience
out(State.PLAY, 0x44, 0x41); // Update Health out(State.PLAY, 0x44, 0x41); // Update Health
out(State.PLAY, 0x45, 0x42, cancel()); // Scoreboard Objective TODO MODIFIED
out(State.PLAY, 0x46, 0x43); // Set Passengers out(State.PLAY, 0x46, 0x43); // Set Passengers
out(State.PLAY, 0x47, 0x44, cancel()); // Teams TODO MODIFIED
out(State.PLAY, 0x48, 0x45); // Update Score out(State.PLAY, 0x48, 0x45); // Update Score
out(State.PLAY, 0x49, 0x46); // Spawn Position out(State.PLAY, 0x49, 0x46); // Spawn Position
out(State.PLAY, 0x4A, 0x47); // Time Update out(State.PLAY, 0x4A, 0x47); // Time Update
out(State.PLAY, 0x4B, 0x48); // Title out(State.PLAY, 0x4B, 0x48); // Title
out(State.PLAY, 0x4C, -1, cancel()); // Stop Sound TODO NEW
out(State.PLAY, 0x4D, 0x49); // Sound Effect
out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer
out(State.PLAY, 0x4F, 0x4B, cancel()); // Collect Item out(State.PLAY, 0x4F, 0x4B); // Collect Item
out(State.PLAY, 0x50, 0x4C); // Entity Teleport out(State.PLAY, 0x50, 0x4C); // Entity Teleport
out(State.PLAY, 0x51, 0x4D, cancel()); // Advancements out(State.PLAY, 0x51, 0x4D, cancel()); // Advancements
out(State.PLAY, 0x52, 0x4E); // Entity Properties out(State.PLAY, 0x52, 0x4E); // Entity Properties
out(State.PLAY, 0x53, 0x4F); // Entity Effect out(State.PLAY, 0x53, 0x4F); // Entity Effect
out(State.PLAY, 0x54, -1, cancel()); // Declare Recipes TODO NEW out(State.PLAY, 0x54, -1, cancel()); // Declare Recipes TODO NEW
out(State.PLAY, 0x55, -1, cancel()); // Tags TODO NEW out(State.PLAY, 0x55, -1, cancel()); // Tags (the client won't need this)
in(State.PLAY, 0x01, -1, cancel()); // Query Block NBT TODO NEW
in(State.PLAY, 0x05, 0x01); // Tab-Complete (serverbound) TODO MODIFIED
in(State.PLAY, 0x06, 0x05); // Confirm Transaction (serverbound) in(State.PLAY, 0x06, 0x05); // Confirm Transaction (serverbound)
in(State.PLAY, 0x07, 0x06); // Enchant Item in(State.PLAY, 0x07, 0x06); // Enchant Item
in(State.PLAY, 0x08, 0x07); // Click Window
in(State.PLAY, 0x09, 0x08); // Close Window (serverbound) in(State.PLAY, 0x09, 0x08); // Close Window (serverbound)
in(State.PLAY, 0x0A, 0x09, cancel()); // Plugin message (serverbound) TODO MODIFIED
in(State.PLAY, 0x0B, -1, cancel()); // Edit Book TODO NEW
in(State.PLAY, 0x0C, -1, cancel()); // Query Entity NBT TODO NEW
in(State.PLAY, 0x0D, 0x0A); // Use Entity in(State.PLAY, 0x0D, 0x0A); // Use Entity
in(State.PLAY, 0x0E, 0x0B); // Keep Alive (serverbound) in(State.PLAY, 0x0E, 0x0B); // Keep Alive (serverbound)
in(State.PLAY, 0x0F, 0x0C); // Player in(State.PLAY, 0x0F, 0x0C); // Player
@ -145,23 +118,17 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
in(State.PLAY, 0x12, 0x0F); // Player Look in(State.PLAY, 0x12, 0x0F); // Player Look
in(State.PLAY, 0x13, 0x10); // Vehicle Move (serverbound) in(State.PLAY, 0x13, 0x10); // Vehicle Move (serverbound)
in(State.PLAY, 0x14, 0x11); // Steer Boat in(State.PLAY, 0x14, 0x11); // Steer Boat
in(State.PLAY, 0x15, -1, cancel()); // Pick Item TODO NEW
in(State.PLAY, 0x16, 0x12, cancel()); // Craft Recipe Request TODO MODIFIED in(State.PLAY, 0x16, 0x12, cancel()); // Craft Recipe Request TODO MODIFIED
in(State.PLAY, 0x17, 0x13); // Player Abilities (serverbound) in(State.PLAY, 0x17, 0x13); // Player Abilities (serverbound)
in(State.PLAY, 0x18, 0x14); // Player Digging in(State.PLAY, 0x18, 0x14); // Player Digging
in(State.PLAY, 0x19, 0x15); // Entity Action in(State.PLAY, 0x19, 0x15); // Entity Action
in(State.PLAY, 0x1A, 0x16); // Steer Vehicle in(State.PLAY, 0x1A, 0x16); // Steer Vehicle
in(State.PLAY, 0x1B, 0x17); // Recipe Book Data in(State.PLAY, 0x1B, 0x17, cancel()); // Recipe Book Data TODO MODIFIED
in(State.PLAY, 0x1C, -1, cancel()); // Name Item TODO NEW
in(State.PLAY, 0x1D, 0x18); // Resource Pack Status in(State.PLAY, 0x1D, 0x18); // Resource Pack Status
in(State.PLAY, 0x1E, 0x19); // Advancement Tab in(State.PLAY, 0x1E, 0x19); // Advancement Tab
in(State.PLAY, 0x1F, -1); // Select Trade in(State.PLAY, 0x1F, -1); // Select Trade
in(State.PLAY, 0x20, -1); // Set Beacon Effect in(State.PLAY, 0x20, -1); // Set Beacon Effect
in(State.PLAY, 0x21, 0x1A); // Held Item Change (serverbound) in(State.PLAY, 0x21, 0x1A); // Held Item Change (serverbound)
in(State.PLAY, 0x22, -1, cancel()); // Update Command Block TODO NEW
in(State.PLAY, 0x23, -1, cancel()); // Update Command Block Minecart TODO NEW
in(State.PLAY, 0x24, 0x1B); // Creative Inventory Action
in(State.PLAY, 0x25, -1, cancel()); // Update Structure Block TODO NEW
in(State.PLAY, 0x26, 0x1C); // Update Sign in(State.PLAY, 0x26, 0x1C); // Update Sign
in(State.PLAY, 0x27, 0x1D); // Animation (serverbound) in(State.PLAY, 0x27, 0x1D); // Animation (serverbound)
in(State.PLAY, 0x28, 0x1E); // Spectate in(State.PLAY, 0x28, 0x1E); // Spectate
@ -176,6 +143,24 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
if (!user.has(ClientWorld.class)) if (!user.has(ClientWorld.class))
user.put(new ClientWorld(user)); user.put(new ClientWorld(user));
// Register EntityTracker if it doesn't exist yet.
if (!user.has(EntityTracker.class))
user.put(new EntityTracker(user));
// Init protocol in EntityTracker
user.get(EntityTracker.class).initProtocol(this);
// Register Block Storage
if (!user.has(BackwardsBlockStorage.class))
user.put(new BackwardsBlockStorage(user));
// Register Block Storage
if (!user.has(TabCompleteStorage.class))
user.put(new TabCompleteStorage(user));
}
@Override
protected void register(ViaProviders providers) {
providers.register(BackwardsBlockEntityProvider.class, new BackwardsBlockEntityProvider());
} }
public PacketRemapper cancel() { public PacketRemapper cancel() {
@ -192,8 +177,4 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
}; };
} }
static {
BackwardsMappings.init();
}
} }

Datei anzeigen

@ -0,0 +1,55 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
public class BannerHandler implements BackwardsBlockEntityHandler {
private final int WALL_BANNER_START = 7110; // 4 each
private final int WALL_BANNER_STOP = 7173;
private final int BANNER_START = 6854; // 16 each
private final int BANNER_STOP = 7109;
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
// Normal banners
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
int color = (blockId - BANNER_START) >> 4;
tag.put(new IntTag("Base", (15 - color)));
}
// Wall banners
else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) {
int color = (blockId - WALL_BANNER_START) >> 2;
tag.put(new IntTag("Base", (15 - color)));
} else {
ViaBackwards.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
}
// Invert colors
if (tag.contains("Patterns") && tag.get("Patterns") instanceof ListTag) {
for (Tag pattern : (ListTag) tag.get("Patterns")) {
if (pattern instanceof CompoundTag) {
IntTag c = ((CompoundTag) pattern).get("Color");
c.setValue(15 - c.getValue()); // Invert color id
}
}
}
return tag;
}
}

Datei anzeigen

@ -0,0 +1,29 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
int offset = blockId - 748;
int color = offset >> 4;
tag.put(new IntTag("color", color));
return tag;
}
}

Datei anzeigen

@ -0,0 +1,78 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
private static final Map<Integer, Pair<String, Byte>> flowers = new ConcurrentHashMap<>();
static {
register(5265, "minecraft:air", (byte) 0);
register(5266, "minecraft:sapling", (byte) 0);
register(5267, "minecraft:sapling", (byte) 1);
register(5268, "minecraft:sapling", (byte) 2);
register(5269, "minecraft:sapling", (byte) 3);
register(5270, "minecraft:sapling", (byte) 4);
register(5271, "minecraft:sapling", (byte) 5);
register(5272, "minecraft:tallgrass", (byte) 2);
register(5273, "minecraft:yellow_flower", (byte) 0);
register(5274, "minecraft:red_flower", (byte) 0);
register(5275, "minecraft:red_flower", (byte) 1);
register(5276, "minecraft:red_flower", (byte) 2);
register(5277, "minecraft:red_flower", (byte) 3);
register(5278, "minecraft:red_flower", (byte) 4);
register(5279, "minecraft:red_flower", (byte) 5);
register(5280, "minecraft:red_flower", (byte) 6);
register(5281, "minecraft:red_flower", (byte) 7);
register(5282, "minecraft:red_flower", (byte) 8);
register(5283, "minecraft:red_mushroom", (byte) 0);
register(5284, "minecraft:brown_mushroom", (byte) 0);
register(5285, "minecraft:deadbush", (byte) 0);
register(5286, "minecraft:cactus", (byte) 0);
}
private static void register(int id, String identifier, byte data) {
flowers.put(id, new Pair<>(identifier, data));
}
public static boolean isFlowah(int id) {
return flowers.containsKey(id);
}
public Pair<String, Byte> getOrDefault(int blockId) {
if (flowers.containsKey(blockId))
return flowers.get(blockId);
return flowers.get(5265);
}
// TODO THIS IS NEVER CALLED BECAUSE ITS NO LONGER A BLOCK ENTITY :(
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
Pair<String, Byte> item = getOrDefault(blockId);
tag.put(new StringTag("Item", item.getKey()));
tag.put(new IntTag("Data", item.getValue()));
return tag;
}
}

Datei anzeigen

@ -0,0 +1,39 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.viaversion.libs.opennbt.tag.builtin.ByteTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
public class SkullHandler implements BackwardsBlockEntityHandler {
private final int SKULL_START = 5447;
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
int pos = (blockId - SKULL_START) % 20;
byte type = (byte) Math.floor((blockId - SKULL_START) / 20);
// Set type
tag.put(new ByteTag("SkullType", type));
// Remove wall skulls
if (pos < 4) {
return tag;
}
// Add rotation for normal skulls
tag.put(new ByteTag("Rot", (byte) ((pos - 4) & 255)));
return tag;
}
}

Datei anzeigen

@ -0,0 +1,32 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityNameRewrites;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
if (tag.contains("SpawnData") && tag.get("SpawnData") instanceof CompoundTag) {
CompoundTag data = tag.get("SpawnData");
if (data.contains("id") && data.get("id") instanceof StringTag) {
StringTag s = data.get("id");
s.setValue(EntityNameRewrites.rewrite(s.getValue()));
}
}
return tag;
}
}

Datei anzeigen

@ -10,36 +10,60 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data; package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import nl.matsv.viabackwards.ViaBackwards;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonObject;
import us.myles.viaversion.libs.gson.JsonPrimitive;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import static us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.loadData;
public class BackwardsMappings { public class BackwardsMappings {
public static BlockMappings blockMappings; public static BlockMappings blockMappings;
public static void init() { public static void init() {
us.myles.viaversion.libs.gson.JsonObject mapping1_12 = loadData("mapping-1.12.json"); us.myles.viaversion.libs.gson.JsonObject mapping1_12 = MappingData.loadData("mapping-1.12.json");
us.myles.viaversion.libs.gson.JsonObject mapping1_13 = loadData("mapping-1.13.json"); us.myles.viaversion.libs.gson.JsonObject mapping1_13 = MappingData.loadData("mapping-1.13.json");
us.myles.viaversion.libs.gson.JsonObject mapping1_12_2to1_13 = loadData("mapping-1.12.2to1.13.json");
Via.getPlatform().getLogger().info("Loading block mapping..."); ViaBackwards.getPlatform().getLogger().info("Loading block mapping...");
blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks")); blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks"), mapping1_12_2to1_13.getAsJsonObject("blockstates"));
} }
private static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { private static void mapIdentifiers(short[] output, JsonObject newIdentifiers, JsonObject oldIdentifiers, JsonObject mapping) {
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { for (Map.Entry<String, JsonElement> entry : newIdentifiers.entrySet()) {
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString()); String key = entry.getValue().getAsString();
Map.Entry<String, JsonElement> value = findValue(oldIdentifiers, key);
if (value == null) {
JsonPrimitive replacement = mapping.getAsJsonPrimitive(key);
if (replacement == null && key.contains("[")) {
replacement = mapping.getAsJsonPrimitive(key.substring(0, key.indexOf('[')));
}
if (replacement != null) {
if (replacement.getAsString().startsWith("id:")) {
String id = replacement.getAsString().replace("id:", "");
value = findValue(oldIdentifiers, oldIdentifiers.getAsJsonPrimitive(id).getAsString());
} else {
value = findValue(oldIdentifiers, replacement.getAsString());
}
}
if (value == null) { if (value == null) {
if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); if (replacement != null) {
ViaBackwards.getPlatform().getLogger().warning("No key for " + entry.getValue() + "/" + replacement.getAsString() + " :( ");
} else {
ViaBackwards.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());
} }
} }
@ -55,16 +79,26 @@ public class BackwardsMappings {
return null; return null;
} }
public static JsonObject loadData(String name) {
try (InputStreamReader reader = new InputStreamReader(BackwardsMappings.class.getClassLoader().getResourceAsStream("assets/viabackwards/data/" + name))) {
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
public interface BlockMappings { public interface BlockMappings {
int getNewBlock(int old); int getNewBlock(int old);
} }
private static class BlockMappingsShortArray implements BlockMappings { private static class BlockMappingsShortArray implements BlockMappings {
private short[] oldToNew = new short[4084 * 6]; private short[] oldToNew = new short[8582];
private BlockMappingsShortArray(JsonObject oldMapping, JsonObject newMapping) { private BlockMappingsShortArray(JsonObject newIdentifiers, JsonObject oldIdentifiers, JsonObject mapping) {
Arrays.fill(oldToNew, (short) -1); Arrays.fill(oldToNew, (short) -1);
mapIdentifiers(oldToNew, oldMapping, newMapping); mapIdentifiers(oldToNew, newIdentifiers, oldIdentifiers, mapping);
} }
@Override @Override

Datei anzeigen

@ -0,0 +1,53 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class EntityNameRewrites {
private static Map<String, String> entityNames = new ConcurrentHashMap<>();
static {
/*
CHANGED NAMES IN 1.13
*/
reg("commandblock_minecart", "command_block_minecart");
reg("ender_crystal", "end_crystal");
reg("evocation_fangs", "evoker_fangs");
reg("evocation_illager", "evoker");
reg("eye_of_ender_signal", "eye_of_ender");
reg("fireworks_rocket", "firework_rocket");
reg("illusion_illager", "illusioner");
reg("snowman", "snow_golem");
reg("villager_golem", "iron_golem");
reg("vindication_illager", "vindicator");
reg("xp_bottle", "experience_bottle");
reg("xp_orb", "experience_orb");
}
private static void reg(String past, String future) {
entityNames.put("minecraft:" + future, "minecraft:" + past);
}
public static String rewrite(String entName) {
String entityName = entityNames.get(entName);
if (entityName != null) {
return entityName;
}
entityName = entityNames.get("minecraft:" + entName);
if (entityName != null) {
return entityName;
} else
return entName;
}
}

Datei anzeigen

@ -0,0 +1,27 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class EntityTypeMapping {
private static Map<Integer, Integer> entityTypes = new HashMap<>();
static {
try {
Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes");
field.setAccessible(true);
Map<Integer, Integer> entityTypes = (Map<Integer, Integer>) field.get(null);
entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12));
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
}
public static Optional<Integer> getOldId(int type1_13) {
return Optional.ofNullable(entityTypes.get(type1_13));
}
}

Datei anzeigen

@ -0,0 +1,26 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
public class NamedSoundMapping {
private static Map<String, String> sounds = new HashMap<>();
static {
try {
Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew");
field.setAccessible(true);
Map<String, String> sounds = (Map<String, String>) field.get(null);
sounds.forEach((sound1_12, sound1_13) -> NamedSoundMapping.sounds.put(sound1_13, sound1_12));
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
}
public static String getOldId(String sound1_13) {
return sounds.get(sound1_13);
}
}

Datei anzeigen

@ -0,0 +1,45 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import java.util.HashMap;
import java.util.Map;
public class PaintingMapping {
private static Map<Integer, String> paintings = new HashMap<>();
public static void init() {
add("Kebab");
add("Aztec");
add("Alban");
add("Aztec2");
add("Bomb");
add("Plant");
add("Wasteland");
add("Pool");
add("Courbet");
add("Sea");
add("Sunset");
add("Creebet");
add("Wanderer");
add("Graham");
add("Match");
add("Bust");
add("Stage");
add("Void");
add("SkullAndRoses");
add("Wither");
add("Fighters");
add("Pointer");
add("Pigscene");
add("BurningSkull");
add("Skeleton");
add("DonkeyKong");
}
private static void add(String motive) {
paintings.put(paintings.size(), motive);
}
public static String getStringId(int id) {
return paintings.getOrDefault(id, "kebab");
}
}

Datei anzeigen

@ -0,0 +1,44 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import us.myles.viaversion.libs.gson.JsonArray;
import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject;
import java.util.Arrays;
import static us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.loadData;
public class SoundMapping {
private static short[] sounds = new short[662];
public static void init() {
JsonObject mapping1_12 = loadData("mapping-1.12.json");
JsonObject mapping1_13 = loadData("mapping-1.13.json");
Arrays.fill(sounds, (short) -1);
mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"));
}
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) continue; //There will be missing sounds, since we are goind backwards
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;
}
public static int getOldSound(int newSound) {
return newSound < 0 || newSound >= sounds.length ? -1 : sounds[newSound];
}
}

Datei anzeigen

@ -0,0 +1,496 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
import nl.matsv.viabackwards.api.entities.types.EntityType1_12;
import nl.matsv.viabackwards.api.entities.types.EntityType1_13;
import nl.matsv.viabackwards.api.entities.types.EntityType1_13.EntityType;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMapping;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
import us.myles.ViaVersion.api.PacketWrapper;
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_12;
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.api.type.types.version.Types1_12;
import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.Optional;
public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
@Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
//Spawn Object
protocol.out(State.PLAY, 0x00, 0x00, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.UUID);
map(Type.BYTE);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.BYTE);
map(Type.BYTE);
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
byte type = wrapper.get(Type.BYTE, 0);
EntityType entityType = EntityType1_13.getTypeFromId(type, true);
if (entityType == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type);
return;
}
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
entityType
);
}
});
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Optional<EntityType1_13.ObjectType> type = EntityType1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0));
if (type.isPresent() && type.get() == EntityType1_13.ObjectType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0);
int combined = BlockItemPackets1_13.toOldId(blockState);
combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12);
wrapper.set(Type.INT, 0, combined);
} else if (type.isPresent() && type.get() == EntityType1_13.ObjectType.ITEM_FRAME) {
int data = wrapper.get(Type.INT, 0);
switch (data) {
case 3:
data = 0;
break;
case 4:
data = 1;
break;
case 5:
data = 3;
break;
}
wrapper.set(Type.INT, 0, data);
}
}
});
}
});
//Spawn Experience Orb
protocol.out(State.PLAY, 0x01, 0x01, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
EntityType.XP_ORB
);
}
});
}
});
//Spawn Global Entity
protocol.out(State.PLAY, 0x02, 0x02, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.BYTE);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
EntityType.LIGHTNING_BOLT
);
}
});
}
});
//Spawn Mob
protocol.out(State.PLAY, 0x03, 0x03, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.UUID);
map(Type.VAR_INT);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.BYTE);
map(Type.BYTE);
map(Type.BYTE);
map(Type.SHORT);
map(Type.SHORT);
map(Type.SHORT);
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 1);
EntityType entityType = EntityType1_13.getTypeFromId(type, false);
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
entityType
);
Optional<Integer> oldId = EntityTypeMapping.getOldId(type);
if (!oldId.isPresent()) {
if (!hasData(entityType))
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType);
} else {
wrapper.set(Type.VAR_INT, 1, oldId.get());
}
}
});
// Handle entity type & metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
AbstractEntityType type = getEntityType(wrapper.user(), entityId);
MetaStorage storage = new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0));
handleMeta(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
storage
);
Optional<EntityData> optEntDat = getEntityData(type);
if (optEntDat.isPresent()) {
EntityData data = optEntDat.get();
Optional<Integer> replacementId = EntityTypeMapping.getOldId(data.getReplacementId());
wrapper.set(Type.VAR_INT, 1, replacementId.orElse(EntityType1_12.EntityType.ZOMBIE.getId()));
if (data.hasBaseMeta())
data.getDefaultMeta().handle(storage);
}
// Rewrite Metadata
wrapper.set(
Types1_12.METADATA_LIST,
0,
storage.getMetaDataList()
);
}
});
}
});
// Spawn Player
protocol.out(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.UUID);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.BYTE);
map(Type.BYTE);
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
EntityType.PLAYER
);
}
});
// Rewrite Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(
Types1_12.METADATA_LIST,
0,
handleMeta(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0))
).getMetaDataList()
);
}
});
}
});
//Spawn Painting
protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.UUID);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
EntityType.PAINTING
);
}
});
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int motive = wrapper.read(Type.VAR_INT);
String title = PaintingMapping.getStringId(motive);
wrapper.write(Type.STRING, title);
}
});
}
});
// Join game
protocol.out(State.PLAY, 0x25, 0x23, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.INT, 0),
EntityType1_12.EntityType.PLAYER
);
}
});
// Save dimension
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
}
});
}
});
// Respawn Packet (save dimension id)
protocol.registerOutgoing(State.PLAY, 0x38, 0x35, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
// Destroy Entities Packet
protocol.registerOutgoing(State.PLAY, 0x35, 0x32, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
getEntityTracker(wrapper.user()).removeEntity(entity);
}
});
}
});
// Entity Metadata packet
protocol.registerOutgoing(State.PLAY, 0x3F, 0x3C, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(
Types1_12.METADATA_LIST,
0,
handleMeta(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0))
).getMetaDataList()
);
}
});
}
});
}
@Override
protected void registerRewrites() {
// Rewrite new Entity 'drowned'
regEntType(EntityType.DROWNED, EntityType.ZOMBIE_VILLAGER).mobName("Drowned");
// Fishy
regEntType(EntityType.COD_MOB, EntityType.SQUID).mobName("Cod");
regEntType(EntityType.SALMON_MOB, EntityType.SQUID).mobName("Salmon");
regEntType(EntityType.PUFFER_FISH, EntityType.SQUID).mobName("Puffer Fish");
regEntType(EntityType.TROPICAL_FISH, EntityType.SQUID).mobName("Tropical Fish");
// Phantom
regEntType(EntityType.PHANTOM, EntityType.PARROT).mobName("Phantom").spawnMetadata(storage -> {
// The phantom is grey/blue so let's do yellow/blue
storage.add(new Metadata(15, MetaType1_12.VarInt, 3));
});
// Dolphin
regEntType(EntityType.DOLPHIN, EntityType.SQUID).mobName("Dolphin");
// Turtle
regEntType(EntityType.TURTLE, EntityType.OCELOT).mobName("Turtle");
// Rewrite Meta types
registerMetaHandler().handle(e -> {
Metadata meta = e.getData();
int typeId = meta.getMetaType().getTypeID();
// Rewrite optional chat to chat
if (typeId == 5) {
meta.setMetaType(MetaType1_12.String);
if (meta.getValue() == null) {
meta.setValue("");
}
}
// Rewrite items
else if (typeId == 6) {
meta.setMetaType(MetaType1_12.Slot);
Item item = (Item) meta.getValue();
meta.setValue(getProtocol().getBlockItemPackets().handleItemToClient(item));
}
// Discontinue particles
else if (typeId == 15) {
meta.setMetaType(MetaType1_12.Discontinued);
}
// Rewrite to 1.12 ids
else if (typeId > 5) {
meta.setMetaType(MetaType1_12.byId(
typeId - 1
));
}
return meta;
});
// Rewrite Custom Name from Chat to String
registerMetaHandler().filter(EntityType.ENTITY, true, 2).handle(e -> {
Metadata meta = e.getData();
meta.setValue(
ChatRewriter.jsonTextToLegacy(
(String) meta.getValue()
)
);
return meta;
});
// Handle zombie metadata
registerMetaHandler().filter(EntityType.ZOMBIE, true, 15).removed();
registerMetaHandler().filter(EntityType.ZOMBIE, true).handle(e -> {
Metadata meta = e.getData();
if (meta.getId() > 15) {
meta.setId(meta.getId() - 1);
}
return meta;
});
// Handle turtle metadata (Remove them all for now)
registerMetaHandler().filter(EntityType.TURTLE, 13).removed(); // Home pos
registerMetaHandler().filter(EntityType.TURTLE, 14).removed(); // Has egg
registerMetaHandler().filter(EntityType.TURTLE, 15).removed(); // Laying egg
registerMetaHandler().filter(EntityType.TURTLE, 16).removed(); // Travel pos
registerMetaHandler().filter(EntityType.TURTLE, 17).removed(); // Going home
registerMetaHandler().filter(EntityType.TURTLE, 18).removed(); // Traveling
// Remove additional fish meta
registerMetaHandler().filter(EntityType.ABSTRACT_FISHES, true, 12).removed();
registerMetaHandler().filter(EntityType.ABSTRACT_FISHES, true, 13).removed();
// Remove phantom size
registerMetaHandler().filter(EntityType.PHANTOM, 12).removed();
// Remove boat splash timer
registerMetaHandler().filter(EntityType.BOAT, 12).removed();
// Remove Trident special loyalty level
registerMetaHandler().filter(EntityType.TRIDENT, 7).removed();
// Handle new wolf colors
registerMetaHandler().filter(EntityType.WOLF, 17).handle(e -> {
Metadata meta = e.getData();
meta.setValue(15 - (int) meta.getValue());
return meta;
});
// Rewrite AreaEffectCloud
registerMetaHandler().filter(EntityType.AREA_EFFECT_CLOUD, 9).handle(e -> {
Metadata meta = e.getData();
Particle particle = (Particle) meta.getValue();
// TODO Rewrite particle ids
e.getStorage().add(new Metadata(9, MetaType1_12.VarInt, 0));
e.getStorage().add(new Metadata(10, MetaType1_12.VarInt, 0));
e.getStorage().add(new Metadata(11, MetaType1_12.VarInt, 0));
throw new RemovedValueException();
});
// TODO REWRITE BLOCKS IN MINECART
}
}

Datei anzeigen

@ -0,0 +1,404 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage;
import nl.matsv.viabackwards.utils.ChatUtil;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
@Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
// Login Plugin Request
protocol.out(State.LOGIN, 0x04, -1, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper packetWrapper) throws Exception {
packetWrapper.cancel();
packetWrapper.create(0x02, new ValueCreator() { // Plugin response
@Override
public void write(PacketWrapper newWrapper) throws Exception {
newWrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id
newWrapper.write(Type.BOOLEAN, false); // Success
}
}).sendToServer(Protocol1_12_2To1_13.class);
}
});
}
});
//Plugin Message
protocol.out(State.PLAY, 0x19, 0x18, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.read(Type.STRING);
if (channel.equals("minecraft:trader_list")) {
wrapper.write(Type.STRING, "MC|TrList");
wrapper.passthrough(Type.INT); //Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
//Input Item
Item input = wrapper.read(Type.FLAT_ITEM);
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(input));
//Output Item
Item output = wrapper.read(Type.FLAT_ITEM);
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(output));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
if (secondItem) {
//Second Item
Item second = wrapper.read(Type.FLAT_ITEM);
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(second));
}
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
wrapper.passthrough(Type.INT); //Number of tools uses
wrapper.passthrough(Type.INT); //Maximum number of trade uses
}
} else {
String oldChannel = InventoryPackets.getOldPluginChannelId(channel);
if (oldChannel == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find old channel for " + channel);
wrapper.cancel();
return;
}
wrapper.write(Type.STRING, oldChannel);
}
}
});
}
});
// Player List Item
protocol.out(State.PLAY, 0x30, 0x2E, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper packetWrapper) throws Exception {
TabCompleteStorage storage = packetWrapper.user().get(TabCompleteStorage.class);
int action = packetWrapper.passthrough(Type.VAR_INT);
int nPlayers = packetWrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < nPlayers; i++) {
UUID uuid = packetWrapper.passthrough(Type.UUID);
if (action == 0) { // Add
String name = packetWrapper.passthrough(Type.STRING);
storage.usernames.put(uuid, name);
int nProperties = packetWrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < nProperties; j++) {
packetWrapper.passthrough(Type.STRING);
packetWrapper.passthrough(Type.STRING);
if (packetWrapper.passthrough(Type.BOOLEAN)) {
packetWrapper.passthrough(Type.STRING);
}
}
packetWrapper.passthrough(Type.VAR_INT);
packetWrapper.passthrough(Type.VAR_INT);
if (packetWrapper.passthrough(Type.BOOLEAN)) {
packetWrapper.passthrough(Type.STRING);
}
} else if (action == 1) { // Update Game Mode
packetWrapper.passthrough(Type.VAR_INT);
} else if (action == 2) { // Update Ping
packetWrapper.passthrough(Type.VAR_INT);
} else if (action == 3) { // Update Display Name
if (packetWrapper.passthrough(Type.BOOLEAN)) {
packetWrapper.passthrough(Type.STRING);
}
} else if (action == 4) { // Remove Player
storage.usernames.remove(uuid);
}
}
}
});
}
});
//Scoreboard Objective
protocol.out(State.PLAY, 0x45, 0x42, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING);
map(Type.BYTE);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
byte mode = wrapper.get(Type.BYTE, 0);
if (mode == 0 || mode == 2) {
String value = wrapper.read(Type.STRING);
value = ChatRewriter.jsonTextToLegacy(value);
if (value.length() > 32) value = value.substring(0, 32);
wrapper.write(Type.STRING, value);
int type = wrapper.read(Type.VAR_INT);
wrapper.write(Type.STRING, type == 1 ? "hearts" : "integer");
}
}
});
}
});
//Teams
protocol.out(State.PLAY, 0x47, 0x44, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING);
map(Type.BYTE);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
byte action = wrapper.get(Type.BYTE, 0);
if (action == 0 || action == 2) {
String displayName = wrapper.read(Type.STRING);
displayName = ChatRewriter.jsonTextToLegacy(displayName);
displayName = ChatUtil.removeUnusedColor(displayName, 'f');
if (displayName.length() > 32) displayName = displayName.substring(0, 32);
wrapper.write(Type.STRING, displayName);
byte flags = wrapper.read(Type.BYTE);
String nameTagVisibility = wrapper.read(Type.STRING);
String collisionRule = wrapper.read(Type.STRING);
int colour = wrapper.read(Type.VAR_INT);
if (colour == 21) {
colour = -1;
}
//TODO team color/prefix handling changed from 1.12.2 to 1.13 and to 1.13.1 again afaik
String prefix = wrapper.read(Type.STRING);
String suffix = wrapper.read(Type.STRING);
prefix = prefix == null || prefix.equals("null") ? "" : ChatRewriter.jsonTextToLegacy(prefix);
prefix += "§" + (colour > -1 && colour <= 15 ? Integer.toHexString(colour) : "r");
prefix = ChatUtil.removeUnusedColor(prefix, 'f', true);
if (prefix.length() > 16) prefix = prefix.substring(0, 16);
if (prefix.endsWith("§")) prefix = prefix.substring(0, prefix.length() - 1);
suffix = suffix == null || suffix.equals("null") ? "" : ChatRewriter.jsonTextToLegacy(suffix);
suffix = ChatUtil.removeUnusedColor(suffix, 'f');
if (suffix.endsWith("§")) suffix = suffix.substring(0, suffix.length() - 1);
wrapper.write(Type.STRING, prefix);
wrapper.write(Type.STRING, suffix);
wrapper.write(Type.BYTE, flags);
wrapper.write(Type.STRING, nameTagVisibility);
wrapper.write(Type.STRING, collisionRule);
wrapper.write(Type.BYTE, (byte) colour);
}
if (action == 0 || action == 3 || action == 4) {
wrapper.passthrough(Type.STRING_ARRAY); //Entities
}
}
});
}
});
// Tab-Complete (clientbound) TODO MODIFIED
protocol.out(State.PLAY, 0x10, 0x0E, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class);
if (storage.lastRequest == null) {
wrapper.cancel();
return;
}
if (storage.lastId != wrapper.read(Type.VAR_INT)) wrapper.cancel();
int start = wrapper.read(Type.VAR_INT);
int length = wrapper.read(Type.VAR_INT);
int lastRequestPartIndex = storage.lastRequest.lastIndexOf(' ') + 1;
if (lastRequestPartIndex != start) wrapper.cancel(); // Client only replaces after space
if (length != storage.lastRequest.length() - lastRequestPartIndex) {
wrapper.cancel(); // We can't set the length in previous versions
}
int count = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < count; i++) {
String match = wrapper.read(Type.STRING);
wrapper.write(Type.STRING, (start == 0 && !storage.lastAssumeCommand ? "/" : "") + match);
// Ignore tooltip
if (wrapper.read(Type.BOOLEAN)) {
wrapper.read(Type.STRING);
}
}
}
});
}
});
// Tab-Complete (serverbound)
protocol.in(State.PLAY, 0x05, 0x01, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class);
int id = ThreadLocalRandom.current().nextInt();
wrapper.write(Type.VAR_INT, id);
String command = wrapper.read(Type.STRING);
boolean assumeCommand = wrapper.read(Type.BOOLEAN);
wrapper.read(Type.OPTIONAL_POSITION);
if (!assumeCommand) {
if (command.startsWith("/")) {
command = command.substring(1);
} else {
wrapper.cancel();
PacketWrapper response = wrapper.create(0xE);
List<String> usernames = new ArrayList<>();
for (String value : storage.usernames.values()) {
if (value.toLowerCase().startsWith(command.substring(command.lastIndexOf(' ') + 1).toLowerCase())) {
usernames.add(value);
}
}
response.write(Type.VAR_INT, usernames.size());
for (String value : usernames) {
response.write(Type.STRING, value);
}
response.send(protocol.getClass());
}
}
wrapper.write(Type.STRING, command);
storage.lastId = id;
storage.lastAssumeCommand = assumeCommand;
storage.lastRequest = command;
}
});
}
});
//Plugin Message
protocol.in(State.PLAY, 0x0A, 0x09, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.read(Type.STRING);
if (channel.equals("MC|BSign") || channel.equals("MC|BEdit")) {
wrapper.setId(0x0B);
Item book = wrapper.read(Type.ITEM);
wrapper.write(Type.FLAT_ITEM, getProtocol().getBlockItemPackets().handleItemToServer(book));
boolean signing = channel.equals("MC|BSign");
wrapper.write(Type.BOOLEAN, signing);
} else if (channel.equals("MC|ItemName")) {
wrapper.setId(0x1C);
} else if (channel.equals("MC|AdvCmd")) {
byte type = wrapper.read(Type.BYTE);
if (type == 0) {
//Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089
//The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either.
//Maybe older versions used this and we need to implement this? The issues is that we would have to save the command block types
wrapper.setId(0x22);
wrapper.cancel();
ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!");
} else if (type == 1) {
wrapper.setId(0x23);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Entity Id
wrapper.passthrough(Type.STRING); //Command
wrapper.passthrough(Type.BOOLEAN); //Track Output
} else {
wrapper.cancel();
}
} else if (channel.equals("MC|AutoCmd")) {
wrapper.setId(0x22);
Integer x = wrapper.read(Type.INT);
Integer y = wrapper.read(Type.INT);
Integer z = wrapper.read(Type.INT);
wrapper.write(Type.POSITION, new Position(x.longValue(), y.longValue(), z.longValue()));
wrapper.passthrough(Type.STRING); //Command
byte flags = 0;
if (wrapper.read(Type.BOOLEAN)) flags |= 0x01; //Track Output
String mode = wrapper.read(Type.STRING);
int modeId = mode.equals("SEQUENCE") ? 0 : mode.equals("AUTO") ? 1 : 2;
wrapper.write(Type.VAR_INT, modeId);
if (wrapper.read(Type.BOOLEAN)) flags |= 0x02; //Is conditional
if (wrapper.read(Type.BOOLEAN)) flags |= 0x04; //Automatic
} else if (channel.equals("MC|Struct")) {
wrapper.setId(0x25);
Integer x = wrapper.read(Type.INT);
Integer y = wrapper.read(Type.INT);
Integer z = wrapper.read(Type.INT);
wrapper.write(Type.POSITION, new Position(x.longValue(), y.longValue(), z.longValue()));
wrapper.write(Type.VAR_INT, wrapper.read(Type.BYTE) - 1);
String mode = wrapper.read(Type.STRING);
int modeId = mode.equals("SAVE") ? 0 : mode.equals("LOAD") ? 1 : mode.equals("CORNER") ? 2 : 3;
wrapper.write(Type.VAR_INT, modeId);
wrapper.passthrough(Type.STRING); //Name
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset X
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset Y
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset Z
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size X
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size Y
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size Z
String mirror = wrapper.read(Type.STRING);
int mirrorId = mode.equals("NONE") ? 0 : mode.equals("LEFT_RIGHT") ? 1 : 2;
String rotation = wrapper.read(Type.STRING);
int rotationId = mode.equals("NONE") ? 0 : mode.equals("CLOCKWISE_90") ? 1 : mode.equals("CLOCKWISE_180") ? 2 : 3;
wrapper.passthrough(Type.STRING); //Metadata
byte flags = 0;
if (wrapper.read(Type.BOOLEAN)) flags |= 0x01; //Ignore entities
if (wrapper.read(Type.BOOLEAN)) flags |= 0x02; //Show air
if (wrapper.read(Type.BOOLEAN)) flags |= 0x04; //Show bounding box
wrapper.passthrough(Type.FLOAT); //Integrity
wrapper.passthrough(Type.VAR_LONG); //Seed
wrapper.write(Type.BYTE, flags);
} else if (channel.equals("MC|Beacon")) {
wrapper.setId(0x20);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Primary Effect
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Secondary Effect
} else if (channel.equals("MC|TrSel")) {
wrapper.setId(0x1F);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Slot
} else if (channel.equals("MC|PickItem")) {
wrapper.setId(0x15);
} else {
String newChannel = InventoryPackets.getNewPluginChannelId(channel);
if (newChannel == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find new channel for " + channel);
wrapper.cancel();
return;
}
wrapper.write(Type.STRING, newChannel);
//TODO REGISTER and UNREGISTER (see ViaVersion)
wrapper.cancel();
}
}
});
}
});
}
@Override
protected void registerRewrites() {
}
}

Datei anzeigen

@ -0,0 +1,86 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMapping;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.SoundMapping;
import us.myles.ViaVersion.api.PacketWrapper;
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;
public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"};
@Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
//Named Sound Event
protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String newSound = wrapper.get(Type.STRING, 0);
String oldSound = NamedSoundMapping.getOldId(newSound);
if (oldSound != null) {
wrapper.set(Type.STRING, 0, oldSound);
}
}
});
}
});
//Stop Sound
protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "MC|StopSound");
byte flags = wrapper.read(Type.BYTE);
String source;
if ((flags & 0x01) != 0) {
source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)];
} else {
source = "";
}
String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : "";
wrapper.write(Type.STRING, source);
wrapper.write(Type.STRING, sound);
}
});
}
});
//Sound Effect
protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int newSound = wrapper.get(Type.VAR_INT, 0);
int oldSound = SoundMapping.getOldSound(newSound);
if (oldSound == -1) {
wrapper.cancel();
} else {
wrapper.set(Type.VAR_INT, 0, oldSound);
}
}
});
}
});
}
@Override
protected void registerRewrites() {
}
}

Datei anzeigen

@ -0,0 +1,97 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.*;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class BackwardsBlockEntityProvider implements Provider {
private final Map<String, BackwardsBlockEntityProvider.BackwardsBlockEntityHandler> handlers = new ConcurrentHashMap<>();
public BackwardsBlockEntityProvider() {
handlers.put("minecraft:flower_pot", new FlowerPotHandler()); // TODO requires special treatment, manually send
handlers.put("minecraft:bed", new BedHandler());
handlers.put("minecraft:banner", new BannerHandler());
handlers.put("minecraft:skull", new SkullHandler());
handlers.put("minecraft:mob_spawner", new SpawnerHandler());
}
/**
* Check if a block entity handler is present
*
* @param key Id of the NBT data ex: minecraft:bed
* @return true if present
*/
public boolean isHandled(String key) {
return handlers.containsKey(key);
}
/**
* Transform blocks to block entities!
*
* @param user The user
* @param position The position of the block entity
* @param tag The block entity tag
*/
public CompoundTag transform(UserConnection user, Position position, CompoundTag tag) throws Exception {
String id = (String) tag.get("id").getValue();
BackwardsBlockEntityHandler handler = handlers.get(id);
if (handler == null) {
if (Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag);
}
return tag;
}
BackwardsBlockStorage storage = user.get(BackwardsBlockStorage.class);
if (!storage.contains(position)) {
if (Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("Handled BlockEntity does not have a stored block :( " + id + " full tag: " + tag);
}
return tag;
}
return handler.transform(user, storage.get(position), tag);
}
/**
* Transform blocks to block entities!
*
* @param user The user
* @param position The position of the block entity
* @param id The block entity id
*/
public CompoundTag transform(UserConnection user, Position position, String id) throws Exception {
CompoundTag tag = new CompoundTag("");
tag.put(new StringTag("id", id));
tag.put(new IntTag("x", Math.toIntExact(position.getX())));
tag.put(new IntTag("y", Math.toIntExact(position.getY())));
tag.put(new IntTag("z", Math.toIntExact(position.getZ())));
return this.transform(user, position, tag);
}
public interface BackwardsBlockEntityHandler {
CompoundTag transform(UserConnection user, int blockId, CompoundTag tag);
}
}

Datei anzeigen

@ -0,0 +1,81 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage;
import com.google.common.collect.Sets;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class BackwardsBlockStorage extends StoredObject {
// This BlockStorage is very exclusive (;
private static final Set<Integer> whitelist = Sets.newConcurrentHashSet();
static {
// Flower pots
for (int i = 5265; i <= 5286; i++)
whitelist.add(i);
// Add those beds
for (int i = 0; i < (16 * 16); i++)
whitelist.add(748 + i);
// Add the banners
for (int i = 6854; i <= 7173; i++)
whitelist.add(i);
// Spawner
whitelist.add(1647);
// Skulls
for (int i = 5447; i <= 5566; i++)
whitelist.add(i);
}
private Map<Position, Integer> blocks = new ConcurrentHashMap<>();
public BackwardsBlockStorage(UserConnection user) {
super(user);
}
public void checkAndStore(Position position, int block) {
if (!whitelist.contains(block)) {
// Remove if not whitelisted
if (blocks.containsKey(position))
blocks.remove(position);
return;
}
blocks.put(position, block);
}
public boolean isWelcome(int block) {
return whitelist.contains(block);
}
public boolean contains(Position position) {
return blocks.containsKey(position);
}
public int get(Position position) {
return blocks.get(position);
}
public int remove(Position position) {
return blocks.remove(position);
}
}

Datei anzeigen

@ -0,0 +1,19 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class TabCompleteStorage extends StoredObject {
public int lastId;
public String lastRequest;
public boolean lastAssumeCommand;
public Map<UUID, String> usernames = new HashMap<>();
public TabCompleteStorage(UserConnection user) {
super(user);
}
}

Datei anzeigen

@ -96,7 +96,7 @@ public class Protocol1_12To1_12_1 extends BackwardsProtocol {
registerIncoming(State.PLAY, 0xf, 0x10); registerIncoming(State.PLAY, 0xf, 0x10);
registerIncoming(State.PLAY, 0x10, 0x11); registerIncoming(State.PLAY, 0x10, 0x11);
registerIncoming(State.PLAY, 0x11, 0x12); registerIncoming(State.PLAY, 0x11, 0x12);
registerIncoming(State.PLAY, 0x12, -1); // No sent by client, sad :( // New incoming 0x12 - No sent by client, sad :(
} }
@Override @Override

Datei anzeigen

@ -1,6 +1,9 @@
package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2; package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.EntityPackets1_13_2;
import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.InventoryPackets1_13_2;
import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.WorldPackets1_13_2;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -8,17 +11,14 @@ 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;
import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.EntityPackets;
import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.InventoryPackets;
import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.WorldPackets;
public class Protocol1_13_1To1_13_2 extends BackwardsProtocol { public class Protocol1_13_1To1_13_2 extends BackwardsProtocol {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
InventoryPackets.register(this); InventoryPackets1_13_2.register(this);
WorldPackets.register(this); WorldPackets1_13_2.register(this);
EntityPackets.register(this); EntityPackets1_13_2.register(this);
//Edit Book //Edit Book
registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {

Datei anzeigen

@ -12,7 +12,7 @@ import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.api.type.types.version.Types1_13_2; import us.myles.ViaVersion.api.type.types.version.Types1_13_2;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class EntityPackets { public class EntityPackets1_13_2 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
@ -73,7 +73,6 @@ public class EntityPackets {
} }
}); });
// Metadata packet // Metadata packet
protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
@Override @Override

Datei anzeigen

@ -7,7 +7,7 @@ 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;
public class InventoryPackets { public class InventoryPackets1_13_2 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
@ -78,7 +78,7 @@ public class InventoryPackets {
} }
}); });
// // Declare Recipes // Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {

Datei anzeigen

@ -7,7 +7,7 @@ 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;
public class WorldPackets { public class WorldPackets1_13_2 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
//spawn particle //spawn particle
@ -24,6 +24,7 @@ public class WorldPackets {
map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count map(Type.INT); // 9 - Particle Count
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {

Datei anzeigen

@ -1,48 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_13Types;
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
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 java.util.ArrayList;
import java.util.List;
public class MetadataRewriter {
public static void handleMetadata(int entityId, Entity1_13Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
for (Metadata metadata : new ArrayList<>(metadatas)) {
try {
// 1.13 changed item to flat item (no data)
if (metadata.getMetaType() == MetaType1_13.Slot) {
InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_13.BlockID) {
// Convert to new block id
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data));
}
if (type == null) continue;
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
// New block format
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data));
}
if(type.is(EntityType.ITEM)){
}
} catch (Exception e) {
metadatas.remove(metadata);
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
e.printStackTrace();
}
}
}
}
}

Datei anzeigen

@ -1,9 +1,10 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1; package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets1_13_1;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets1_13_1;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -12,16 +13,15 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer; 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.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker;
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;
public class Protocol1_13To1_13_1 extends BackwardsProtocol { public class Protocol1_13To1_13_1 extends BackwardsProtocol {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
EntityPackets.register(this); new EntityPackets1_13_1().register(this);
InventoryPackets.register(this); InventoryPackets1_13_1.register(this);
WorldPackets.register(this); WorldPackets1_13_1.register(this);
//Tab complete //Tab complete
registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() { registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@ -47,6 +47,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
InventoryPackets1_13_1.toServer(wrapper.get(Type.FLAT_ITEM, 0));
wrapper.write(Type.VAR_INT, 0); wrapper.write(Type.VAR_INT, 0);
} }
}); });
@ -94,6 +95,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.FLOAT); wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.VAR_INT);
short flags = wrapper.read(Type.UNSIGNED_BYTE); short flags = wrapper.read(Type.UNSIGNED_BYTE);
if ((flags & 0x04) != 0) flags |= 0x02; if ((flags & 0x04) != 0) flags |= 0x02;
wrapper.write(Type.UNSIGNED_BYTE, flags); wrapper.write(Type.UNSIGNED_BYTE, flags);
@ -126,7 +128,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
wrapper.passthrough(Type.STRING); // Title wrapper.passthrough(Type.STRING); // Title
wrapper.passthrough(Type.STRING); // Description wrapper.passthrough(Type.STRING); // Description
Item icon = wrapper.passthrough(Type.FLAT_ITEM); Item icon = wrapper.passthrough(Type.FLAT_ITEM);
InventoryPackets.toClient(icon); InventoryPackets1_13_1.toClient(icon);
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) if ((flags & 1) != 0)
@ -167,7 +169,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);
Integer[] items = wrapper.passthrough(Type.VAR_INT_ARRAY); Integer[] items = wrapper.passthrough(Type.VAR_INT_ARRAY);
for (int j = 0; j < items.length; j++) { for (int j = 0; j < items.length; j++) {
items[j] = InventoryPackets.getOldItemId(items[j]); items[j] = InventoryPackets1_13_1.getOldItemId(items[j]);
} }
} }
} }
@ -180,8 +182,8 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
public static int getNewBlockStateId(int blockId) { public static int getNewBlockStateId(int blockId) {
if (blockId > 8590) { if (blockId > 8590) {
blockId -= 17; blockId -= 17;
} else if (blockId > 8573) { } else if (blockId > 8588) {
blockId = 0; //TODO replace new blocks blockId = 8573;
} else if (blockId > 8479) { } else if (blockId > 8479) {
blockId -= 16; blockId -= 16;
} else if (blockId > 8469 && blockId % 2 == 0) { } else if (blockId > 8469 && blockId % 2 == 0) {
@ -212,9 +214,15 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
} }
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection user) {
userConnection.put(new EntityTracker(userConnection)); // Register EntityTracker if it doesn't exist yet.
if (!userConnection.has(ClientWorld.class)) if (!user.has(EntityTracker.class))
userConnection.put(new ClientWorld(userConnection)); user.put(new EntityTracker(user));
// Init protocol in EntityTracker
user.get(EntityTracker.class).initProtocol(this);
if (!user.has(ClientWorld.class))
user.put(new ClientWorld(user));
} }
} }

Datei anzeigen

@ -1,152 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets;
import com.google.common.base.Optional;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.MetadataRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_13Types;
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
import us.myles.ViaVersion.api.protocol.Protocol;
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.api.type.types.version.Types1_13;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker;
public class EntityPackets {
public static void register(Protocol protocol) {
//spawn entity
protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.BYTE); // 2 - Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
byte type = wrapper.get(Type.BYTE, 0);
Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, true);
if (entType != null) {
if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) {
int data = wrapper.get(Type.INT, 0);
wrapper.set(Type.INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data));
}
}
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
}
});
}
});
// Spawn mob packet
protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1);
Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false);
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
}
});
}
});
// Spawn player packet
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
}
});
}
});
// Destroy entities
protocol.registerOutgoing(State.PLAY, 0x35, 0x35, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
wrapper.user().get(EntityTracker.class).removeEntity(entity);
}
});
}
});
// Metadata packet
protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
}
});
}
});
}
}

Datei anzeigen

@ -0,0 +1,360 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.entities.types.EntityType1_12;
import nl.matsv.viabackwards.api.entities.types.EntityType1_13;
import nl.matsv.viabackwards.api.entities.types.EntityType1_13.EntityType;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import us.myles.ViaVersion.api.PacketWrapper;
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.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class EntityPackets1_13_1 extends EntityRewriter<Protocol1_13To1_13_1> {
@Override
protected void registerPackets(Protocol1_13To1_13_1 protocol) {
// Spawn Object
protocol.out(State.PLAY, 0x00, 0x00, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.BYTE); // 2 - Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
byte type = wrapper.get(Type.BYTE, 0);
EntityType entType = EntityType1_13.getTypeFromId(type, true);
if (entType == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type);
return;
}
// Rewrite falling block
if (entType.is(EntityType.FALLING_BLOCK)) {
int data = wrapper.get(Type.INT, 0);
wrapper.set(Type.INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data));
}
// Track Entity
addTrackedEntity(
wrapper.user(),
entityId,
entType
);
}
});
}
});
// Spawn Experience Orb
protocol.out(State.PLAY, 0x01, 0x01, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
EntityType.XP_ORB
);
}
});
}
});
// Spawn Global Entity
protocol.out(State.PLAY, 0x02, 0x02, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.BYTE);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
EntityType.LIGHTNING_BOLT
);
}
});
}
});
// Spawn Mob
protocol.out(State.PLAY, 0x3, 0x3, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST); // 12 - Metadata
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 1);
EntityType entityType = EntityType1_13.getTypeFromId(type, false);
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
entityType
);
}
});
// Rewrite Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
MetaStorage storage = new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0));
handleMeta(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
storage
);
// Don't handle new ids / base meta since it's not used for this version
// Rewrite Metadata
wrapper.set(
Types1_13.METADATA_LIST,
0,
storage.getMetaDataList()
);
}
});
}
});
// Spawn player packet
protocol.out(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST); // 7 - Metadata
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
EntityType.PLAYER
);
}
});
// Rewrite Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(
Types1_13.METADATA_LIST,
0,
handleMeta(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0))
).getMetaDataList()
);
}
});
}
});
//Spawn Painting
protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.UUID);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
EntityType.PAINTING
);
}
});
}
});
// Join Game
protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.INT, 0),
EntityType1_12.EntityType.PLAYER
);
}
});
// Save dimension
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
}
});
}
});
// Respawn
protocol.out(State.PLAY, 0x38, 0x38, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID\
// Save dimension
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
// Destroy entities
protocol.out(State.PLAY, 0x35, 0x35, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
getEntityTracker(wrapper.user()).removeEntity(entity);
}
});
}
});
// Metadata packet
protocol.out(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(
Types1_13.METADATA_LIST,
0,
handleMeta(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0))
).getMetaDataList()
);
}
});
}
});
}
@Override
protected void registerRewrites() {
// Rewrite items & blocks
registerMetaHandler().handle(e -> {
Metadata meta = e.getData();
if (meta.getMetaType() == MetaType1_13.Slot) {
InventoryPackets1_13_1.toClient((Item) meta.getValue());
} else if (meta.getMetaType() == MetaType1_13.BlockID) {
// Convert to new block id
int data = (int) meta.getValue();
meta.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data));
}
return meta;
});
// Remove shooter UUID
registerMetaHandler().
filter(EntityType.ABSTRACT_ARROW, true, 7)
.removed();
// Move colors to old position
registerMetaHandler().filter(EntityType.SPECTRAL_ARROW, 8)
.handleIndexChange(7);
// Move loyalty level to old position
registerMetaHandler().filter(EntityType.TRIDENT, 8)
.handleIndexChange(7);
// Rewrite Minecart blocks
registerMetaHandler()
.filter(EntityType.MINECART_ABSTRACT, true, 9)
.handle(e -> {
Metadata meta = e.getData();
int data = (int) meta.getValue();
meta.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data));
return meta;
});
}
}

Datei anzeigen

@ -8,7 +8,7 @@ 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;
public class InventoryPackets { public class InventoryPackets1_13_1 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
@ -16,30 +16,12 @@ public class InventoryPackets {
Outgoing packets Outgoing packets
*/ */
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.FLAT_ITEM, 0);
toClient(stack);
}
});
}
});
// Window items packet // Window items packet
protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.FLAT_ITEM_ARRAY, Type.FLAT_ITEM_ARRAY); // 1 - Window Values map(Type.FLAT_ITEM_ARRAY); // 1 - Window Values
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
@ -52,13 +34,68 @@ public class InventoryPackets {
} }
}); });
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.FLAT_ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.FLAT_ITEM, 0);
toClient(stack);
}
});
}
});
//Plugin Message
protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.passthrough(Type.STRING);
if (channel.equals("minecraft:trader_list")) {
wrapper.passthrough(Type.INT); //Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
//Input Item
Item input = wrapper.passthrough(Type.FLAT_ITEM);
toClient(input);
//Output Item
Item output = wrapper.passthrough(Type.FLAT_ITEM);
toClient(input);
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
if (secondItem) {
//Second Item
Item second = wrapper.passthrough(Type.FLAT_ITEM);
toClient(input);
}
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
wrapper.passthrough(Type.INT); //Number of tools uses
wrapper.passthrough(Type.INT); //Maximum number of trade uses
}
}
}
});
}
});
// Entity Equipment Packet // Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID map(Type.VAR_INT); // 1 - Slot ID
map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 2 - Item map(Type.FLAT_ITEM); // 2 - Item
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
@ -84,7 +121,7 @@ public class InventoryPackets {
map(Type.BYTE); // 2 - Button map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode map(Type.VAR_INT); // 4 - Mode
map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item map(Type.FLAT_ITEM); // 5 - Clicked Item
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
@ -102,7 +139,7 @@ public class InventoryPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.SHORT); // 0 - Slot map(Type.SHORT); // 0 - Slot
map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item map(Type.FLAT_ITEM); // 1 - Clicked Item
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override

Datei anzeigen

@ -13,7 +13,7 @@ import us.myles.ViaVersion.packets.State;
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_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class WorldPackets { public class WorldPackets1_13_1 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
//Chunk //Chunk
@ -28,10 +28,10 @@ public class WorldPackets {
for (ChunkSection section : chunk.getSections()) { for (ChunkSection section : chunk.getSections()) {
if (section != null) { if (section != null) {
for (int i = 0; i < section.getPalette().size(); i++) { for (int i = 0; i < section.getPaletteSize(); i++) {
section.getPalette().set( section.setPaletteEntry(
i, i,
Protocol1_13To1_13_1.getNewBlockStateId(section.getPalette().get(i)) Protocol1_13To1_13_1.getNewBlockStateId(section.getPaletteEntry(i))
); );
} }
} }
@ -109,7 +109,7 @@ public class WorldPackets {
int id = wrapper.get(Type.INT, 0); int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1); int data = wrapper.get(Type.INT, 1);
if (id == 1010) { // Play record if (id == 1010) { // Play record
wrapper.set(Type.INT, 1, data = InventoryPackets.getNewItemId(data)); wrapper.set(Type.INT, 1, data = InventoryPackets1_13_1.getOldItemId(data));
} else if (id == 2001) { // Block break + block break sound } else if (id == 2001) { // Block break + block break sound
wrapper.set(Type.INT, 1, data = Protocol1_13To1_13_1.getNewBlockStateId(data)); wrapper.set(Type.INT, 1, data = Protocol1_13To1_13_1.getNewBlockStateId(data));
} }
@ -118,42 +118,6 @@ public class WorldPackets {
} }
}); });
//join game
protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Store the player
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
}
});
}
});
//respawn
protocol.registerOutgoing(State.PLAY, 0x38, 0x38, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
//spawn particle //spawn particle
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override @Override
@ -176,7 +140,7 @@ public class WorldPackets {
int data = wrapper.passthrough(Type.VAR_INT); int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data)); wrapper.set(Type.VAR_INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data));
} else if (id == 27) { } else if (id == 27) {
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); InventoryPackets1_13_1.toClient(wrapper.passthrough(Type.FLAT_ITEM));
} }
} }
}); });

Datei anzeigen

@ -14,13 +14,14 @@ import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import nl.matsv.viabackwards.utils.Block; import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
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.remapper.PacketHandler; 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;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
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;
@ -166,7 +167,7 @@ public class BlockItemPackets1_10 extends BlockItemRewriter<Protocol1_9_4To1_10>
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type); Chunk chunk = wrapper.passthrough(type);
handleChunk(chunk); handleChunk(chunk);
} }
@ -199,18 +200,13 @@ public class BlockItemPackets1_10 extends BlockItemRewriter<Protocol1_9_4To1_10>
public void registerMap() { public void registerMap() {
map(Type.INT); // 0 - Chunk X map(Type.INT); // 0 - Chunk X
map(Type.INT); // 1 - Chunk Z map(Type.INT); // 1 - Chunk Z
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int count = wrapper.passthrough(Type.VAR_INT); // Array length for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
record.setBlockId(handleBlockID(record.getBlockId()));
for (int i = 0; i < count; i++) {
wrapper.passthrough(Type.UNSIGNED_BYTE); // Horizontal position
wrapper.passthrough(Type.UNSIGNED_BYTE); // Y coords
int id = wrapper.read(Type.VAR_INT); // Block ID
wrapper.write(Type.VAR_INT, handleBlockID(id));
} }
} }
}); });
@ -234,7 +230,7 @@ public class BlockItemPackets1_10 extends BlockItemRewriter<Protocol1_9_4To1_10>
rewrite(255).repItem(new Item((short) 166, (byte) 1, (short) 0, getNamedTag("1.10 Structure Block"))); // Structure block only item since the structure block is in 1.9 rewrite(255).repItem(new Item((short) 166, (byte) 1, (short) 0, getNamedTag("1.10 Structure Block"))); // Structure block only item since the structure block is in 1.9
rewrite(217).repItem(new Item((short) 287, (byte) 1, (short) 0, getNamedTag("1.10 Structure Void"))).repBlock(new Block(287, 0)); // Structure void to string rewrite(217).repItem(new Item((short) 287, (byte) 1, (short) 0, getNamedTag("1.10 Structure Void"))).repBlock(new Block(287, 0)); // Structure void to string
rewrite(213).repItem(new Item((short) 159, (byte) 1, (short) 1, getNamedTag("1.10 Magma Block"))).repBlock(new Block(159, 1)); // Magma block to orange clay rewrite(213).repItem(new Item((short) 159, (byte) 1, (short) 1, getNamedTag("1.10 Magma Block"))).repBlock(new Block(159, 1)); // Magma block to orange clay
rewrite(214).repItem(new Item((short) 159, (byte) 1, (short) 14, getNamedTag("1.10 Nether Ward Block"))).repBlock(new Block(159, 14)); // Nether wart block to red clay rewrite(214).repItem(new Item((short) 159, (byte) 1, (short) 14, getNamedTag("1.10 Nether Ward Block"))).repBlock(new Block(159, 14)); // Nether ward block to red clay
rewrite(215).repItem(new Item((short) 112, (byte) 1, (short) 0, getNamedTag("1.10 Red Nether Bricks"))).repBlock(new Block(112, 0)); // Red nether brick to nether brick rewrite(215).repItem(new Item((short) 112, (byte) 1, (short) 0, getNamedTag("1.10 Red Nether Bricks"))).repBlock(new Block(112, 0)); // Red nether brick to nether brick
rewrite(216).repItem(new Item((short) 155, (byte) 1, (short) 0, getNamedTag("1.10 Bone Block"))).repBlock(new Block(155, 0)); // Bone block to quartz rewrite(216).repItem(new Item((short) 155, (byte) 1, (short) 0, getNamedTag("1.10 Bone Block"))).repBlock(new Block(155, 0)); // Bone block to quartz
} }

Datei anzeigen

@ -0,0 +1,32 @@
package nl.matsv.viabackwards.utils;
import java.util.regex.Pattern;
public class ChatUtil {
private static final Pattern UNUSED_COLOR_PATTERN = Pattern.compile("(?>(?>§[0-fk-or])*(§r|\\Z))|(?>(?>§[0-f])*(§[0-f]))");
private static final Pattern UNUSED_COLOR_PATTERN_PREFIX = Pattern.compile("(?>(?>§[0-fk-or])*(§r))|(?>(?>§[0-f])*(§[0-f]))");
public static String removeUnusedColor(String legacy, char defaultColor) {
return removeUnusedColor(legacy, defaultColor, false);
}
public static String removeUnusedColor(String legacy, char defaultColor, boolean isPrefix) {
if (legacy == null) return null;
Pattern pattern = isPrefix ? UNUSED_COLOR_PATTERN_PREFIX : UNUSED_COLOR_PATTERN;
legacy = pattern.matcher(legacy).replaceAll("$1$2");
StringBuilder builder = new StringBuilder();
char last = defaultColor;
for (int i = 0; i < legacy.length(); i++) {
char current = legacy.charAt(i);
if (current != '§' || i == legacy.length() - 1) {
builder.append(current);
continue;
}
current = legacy.charAt(++i);
if (current == last) continue;
builder.append('§').append(current);
last = current;
}
return builder.toString();
}
}

Datei-Diff unterdrückt, da er zu groß ist Diff laden

11
pom.xml
Datei anzeigen

@ -16,7 +16,7 @@
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<version>2.4.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<description>Allow newer clients to join older server versions.</description> <description>Allow newer clients to join older server versions.</description>
@ -28,6 +28,7 @@
<module>bukkit</module> <module>bukkit</module>
<module>bungee</module> <module>bungee</module>
<module>sponge</module> <module>sponge</module>
<module>velocity</module>
<module>all</module> <module>all</module>
</modules> </modules>
@ -55,17 +56,11 @@
<version>1.16.18</version> <version>1.16.18</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<!-- ViaVersion --> <!-- ViaVersion -->
<dependency> <dependency>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<artifactId>viaversion</artifactId> <artifactId>viaversion</artifactId>
<version>1.6.0</version> <version>2.0.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

Datei anzeigen

@ -15,7 +15,7 @@
<parent> <parent>
<artifactId>viabackwards-parent</artifactId> <artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId> <groupId>nl.matsv</groupId>
<version>2.4.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -11,14 +11,14 @@
package nl.matsv.viabackwards; package nl.matsv.viabackwards;
import com.google.inject.Inject; import com.google.inject.Inject;
import lombok.Getter;
import nl.matsv.viabackwards.api.ViaBackwardsPlatform; import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.sponge.VersionInfo; import nl.matsv.viabackwards.sponge.VersionInfo;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order; import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.plugin.Dependency; import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import us.myles.ViaVersion.sponge.util.LoggerWrapper; import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,26 +31,21 @@ import java.util.logging.Logger;
dependencies = {@Dependency(id = "viaversion")} dependencies = {@Dependency(id = "viaversion")}
) )
public class SpongePlugin implements ViaBackwardsPlatform { public class SpongePlugin implements ViaBackwardsPlatform {
@Getter
private Logger logger; private Logger logger;
@Inject @Inject
private PluginContainer container; private org.slf4j.Logger loggerSlf4j;
@Listener(order = Order.LATE) @Listener(order = Order.LATE)
public void onServerStart(GameAboutToStartServerEvent e) { public void onGameStart(GameInitializationEvent e) {
// Setup Logger // Setup Logger
this.logger = new LoggerWrapper(container.getLogger()); this.logger = new LoggerWrapper(loggerSlf4j);
// Init! // Init!
this.init(); this.init();
} }
@Override
public Logger getLogger() {
return logger;
}
// TODO check how to for sponge, site was offline
@Override @Override
public void disable() { public void disable() {
// Not possible
} }
} }

83
velocity/pom.xml Normale Datei
Datei anzeigen

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2016 Matsv
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>viabackwards-velocity</artifactId>
<build>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>src/main/resources/</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
<!-- Stolen from ViaVersion ;) -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>filter-src</id>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>velocity-maven-repo</id>
<name>Velocity maven repo</name>
<url>https://repo.velocitypowered.com/snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<!-- Common Module -->
<dependency>
<groupId>nl.matsv</groupId>
<artifactId>viabackwards-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!-- Velocity API -->
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,15 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.velocity;
public class VersionInfo {
public static final String VERSION = "${project.version}";
}

Datei anzeigen

@ -0,0 +1,51 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards;
import com.google.inject.Inject;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import lombok.Getter;
import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.velocity.VersionInfo;
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.util.logging.Logger;
@Plugin(id = "viabackwards",
name = "ViaBackwards",
version = VersionInfo.VERSION,
authors = {"Matsv"},
description = "Allow older Minecraft versions to connect to an newer server version.",
dependencies = {@Dependency(id = "viaversion")}
)
public class VelocityPlugin implements ViaBackwardsPlatform {
@Getter
private Logger logger;
@Inject
private org.slf4j.Logger loggerSlf4j;
@Subscribe(order = PostOrder.LATE)
public void onProxyStart(ProxyInitializeEvent e) {
// Setup Logger
this.logger = new LoggerWrapper(loggerSlf4j);
// Init!
this.init();
}
@Override
public void disable() {
// Not possible
}
}