diff --git a/src/main/java/net/raphimc/vialegacy/api/remapper/AbstractChunkTracker.java b/src/main/java/net/raphimc/vialegacy/api/remapper/AbstractChunkTracker.java index 5aa9b16..a6956d2 100644 --- a/src/main/java/net/raphimc/vialegacy/api/remapper/AbstractChunkTracker.java +++ b/src/main/java/net/raphimc/vialegacy/api/remapper/AbstractChunkTracker.java @@ -17,8 +17,7 @@ */ package net.raphimc.vialegacy.api.remapper; -import com.viaversion.viaversion.api.connection.StoredObject; -import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.*; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap; @@ -32,16 +31,14 @@ import java.util.HashMap; import java.util.Map; -public abstract class AbstractChunkTracker extends StoredObject { +public abstract class AbstractChunkTracker implements StorableObject { private final Map chunks = new HashMap<>(); private final IntSet toTrack = new IntOpenHashSet(); private final boolean trackAll; private final Int2IntMap replacements = new Int2IntOpenHashMap(); - public AbstractChunkTracker(final UserConnection user, final int... toTrack) { - super(user); - + public AbstractChunkTracker(final int... toTrack) { for (final int trackedBlock : toTrack) { this.toTrack.add(trackedBlock); } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_6_1to1_5_2/metadata/MetadataRewriter.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_6_1to1_5_2/metadata/MetadataRewriter.java index 20868b5..af8e05e 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_6_1to1_5_2/metadata/MetadataRewriter.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_6_1to1_5_2/metadata/MetadataRewriter.java @@ -27,7 +27,7 @@ public class MetadataRewriter { - public static void transform(EntityTypes1_10.EntityType type, List list) { + public static void transform(final EntityTypes1_10.EntityType type, final List list) { for (Metadata entry : new ArrayList<>(list)) { final MetaIndex1_6_1to1_5_2 metaIndex = MetaIndex1_6_1to1_5_2.searchIndex(type, entry.id()); try { diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/storage/ChunkTracker.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/storage/ChunkTracker.java index 90f0d2d..2648ce8 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/storage/ChunkTracker.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/storage/ChunkTracker.java @@ -30,6 +30,7 @@ public class ChunkTracker extends AbstractChunkTracker { private static final Map SOLID_BLOCKS = new HashMap<>(); + private final boolean b173; static { SOLID_BLOCKS.put(0, false); @@ -206,7 +207,8 @@ public class ChunkTracker extends AbstractChunkTracker { } public ChunkTracker(final UserConnection user) { - super(user, 0); + super(0); + this.b173 = user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3); this.registerReplacement(new IdAndData(BlockList1_6.signWall.blockID, 0), new IdAndData(BlockList1_6.signWall.blockID, 3)); for (int i = 0; i < 16; i++) { @@ -239,7 +241,7 @@ public ChunkTracker(final UserConnection user) { @Override protected void remapBlock(final IdAndData block, final int x, final int y, final int z) { - if (block.id == BlockList1_6.chest.blockID && this.getUser().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) { + if (this.b173 && block.id == BlockList1_6.chest.blockID) { byte blockData = 3; int rot1 = this.getBlockNotNull(x, y, z - 1).id; int rot2 = this.getBlockNotNull(x, y, z + 1).id; @@ -307,7 +309,7 @@ protected void remapBlock(final IdAndData block, final int x, final int y, final @Override protected void postRemap(DataPalette palette) { - if (this.getUser().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) { + if (this.b173) { palette.replaceId(BlockList1_6.chest.blockID << 4, 0); palette.replaceId(BlockList1_6.chest.blockID << 4 | 1, 0); } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java index b8c910b..7a8fd02 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java @@ -248,7 +248,7 @@ public void register() { wrapper.write(Type.SHORT, (short) currentItem.identifier()); final List metadata = wrapper.read(Types1_7_6.METADATA_LIST); // metadata - metadataRewriter.transform(EntityTypes1_10.EntityType.PLAYER, metadata); + metadataRewriter.transform(wrapper.user(), EntityTypes1_10.EntityType.PLAYER, metadata); wrapper.write(Types1_8.METADATA_LIST, metadata); tablistStorage.sendTempEntry(tempTabEntry); @@ -352,7 +352,7 @@ public void register() { tracker.updateEntityLocation(entityID, x, y, z, false); tracker.updateEntityMetadata(entityID, metadataList); - metadataRewriter.transform(entityType, metadataList); + metadataRewriter.transform(wrapper.user(), entityType, metadataList); }); } }); @@ -558,7 +558,7 @@ public void register() { final int entityID = wrapper.get(Type.VAR_INT, 0); if (tracker.getTrackedEntities().containsKey(entityID)) { tracker.updateEntityMetadata(entityID, metadataList); - metadataRewriter.transform(tracker.getTrackedEntities().get(entityID), metadataList); + metadataRewriter.transform(wrapper.user(), tracker.getTrackedEntities().get(entityID), metadataList); if (metadataList.isEmpty()) wrapper.cancel(); } else { wrapper.cancel(); @@ -1488,7 +1488,7 @@ public void init(UserConnection userConnection) { userConnection.put(new EntityTracker(userConnection)); userConnection.put(new MapStorage()); userConnection.put(new DimensionTracker()); - userConnection.put(new ChunkTracker(userConnection)); + userConnection.put(new ChunkTracker()); } @Override diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/metadata/MetadataRewriter.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/metadata/MetadataRewriter.java index e1ac462..314f70d 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/metadata/MetadataRewriter.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/metadata/MetadataRewriter.java @@ -17,11 +17,14 @@ */ package net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.metadata; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import net.raphimc.vialegacy.ViaLegacy; +import net.raphimc.vialegacy.api.model.IdAndData; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.Protocol1_8to1_7_6_10; +import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.storage.ChunkTracker; import java.util.ArrayList; import java.util.List; @@ -35,7 +38,7 @@ public MetadataRewriter(final Protocol1_8to1_7_6_10 protocol) { this.protocol = protocol; } - public void transform(EntityTypes1_10.EntityType type, List list) { + public void transform(final UserConnection user, final EntityTypes1_10.EntityType type, final List list) { for (Metadata entry : new ArrayList<>(list)) { final MetaIndex1_8to1_7_6 metaIndex = MetaIndex1_8to1_7_6.searchIndex(type, entry.id()); try { @@ -67,7 +70,9 @@ public void transform(EntityTypes1_10.EntityType type, List list) { } } final byte data = blockDataMeta != null ? (Byte) blockDataMeta.getValue() : 0; - entry.setValue((short) (id | (data << 12))); + final IdAndData block = new IdAndData(id, data); + user.get(ChunkTracker.class).remapBlockParticle(block); + entry.setValue((short) (block.id | (block.data << 12))); continue; } else if (metaIndex == MetaIndex1_8to1_7_6.HUMAN_SKIN_FLAGS) { byte flags = (byte) value; diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/model/HologramPartEntity.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/model/HologramPartEntity.java index e3b2c4e..2e6d74b 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/model/HologramPartEntity.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/model/HologramPartEntity.java @@ -306,7 +306,7 @@ private List get1_8Metadata() { for (final Map.Entry entry : this.metadata.entrySet()) { metadataList.add(new Metadata(entry.getKey().getOldIndex(), entry.getKey().getOldType(), entry.getValue())); } - Via.getManager().getProtocolManager().getProtocol(Protocol1_8to1_7_6_10.class).getMetadataRewriter().transform(this.entityType, metadataList); + Via.getManager().getProtocolManager().getProtocol(Protocol1_8to1_7_6_10.class).getMetadataRewriter().transform(this.user, this.entityType, metadataList); return metadataList; } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/storage/ChunkTracker.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/storage/ChunkTracker.java index 3db7d1e..4a2393c 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/storage/ChunkTracker.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/storage/ChunkTracker.java @@ -17,7 +17,6 @@ */ package net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.storage; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; import net.raphimc.vialegacy.api.data.BlockList1_6; import net.raphimc.vialegacy.api.model.IdAndData; @@ -25,8 +24,8 @@ public class ChunkTracker extends AbstractChunkTracker { - public ChunkTracker(final UserConnection user) { - super(user, BlockList1_6.obsidian.blockID, BlockList1_6.portal.blockID); + public ChunkTracker() { + super(BlockList1_6.obsidian.blockID, BlockList1_6.portal.blockID); for (int i = 9; i < 16; i++) { // double plant this.registerReplacement(new IdAndData(175, i), new IdAndData(175, 0)); @@ -57,7 +56,7 @@ protected void remapBlock(IdAndData block, int x, int y, int z) { protected void postRemap(DataPalette palette) { palette.replaceId(BlockList1_6.portal.blockID << 4, 0); } - + private void registerInvalidDirectionReplacements(final int blockId, final IdAndData replacement) { for (int i = 0; i < 2; i++) { this.registerReplacement(new IdAndData(blockId, i), replacement);