Skip to content

Commit

Permalink
Fixed metadata issues, added new config options to emulate world bord…
Browse files Browse the repository at this point in the history
…er, cleaned protocol code.
  • Loading branch information
FlorianMichael committed Oct 8, 2023
1 parent 7689769 commit 2d3e495
Show file tree
Hide file tree
Showing 27 changed files with 546 additions and 630 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ public int getMaxBookPageSize() {
return getInt("max-book-page-length", 5000);
}

@Override
@Override
public boolean isEmulateWorldBorder() {
return getBoolean("emulate-world-border", true);
}

@Override
public String getWorldBorderParticle() {
return getString("world-border-particle", "fireworksSpark");
}

@Override
public URL getDefaultConfigURL() {
return getClass().getClassLoader().getResource("assets/viarewind/config.yml");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@ enum CooldownIndicator {
* @return the max amount of characters
*/
int getMaxBookPageSize();

/**
* Whether to emulate the 1.8+ world border for 1.7.x clients
*
* @return true if enabled
*/
boolean isEmulateWorldBorder();

/**
* The particle to show the world border for the 1.8+ world border for 1.7.x clients
*
* @return the particle name (see https://wiki.vg/index.php?title=Protocol&oldid=7368#Particle_2)
*/
String getWorldBorderParticle();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8;

import com.viaversion.viarewind.ViaRewind;
import com.viaversion.viarewind.api.rewriter.ReplacementItemRewriter;
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ClientboundPackets1_7_2_5;
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ServerboundPackets1_7_2_5;
Expand All @@ -28,7 +29,6 @@
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.rewriter.ReplacementItemRewriter1_7_6_10;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.*;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.task.WorldBorderUpdateTask;
import com.viaversion.viarewind.utils.Ticker;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
Expand Down Expand Up @@ -118,13 +118,13 @@ public void transform(Direction direction, State state, PacketWrapper packetWrap

@Override
public void init(UserConnection userConnection) {
userConnection.put(new Windows(userConnection));
userConnection.put(new EntityTracker(userConnection, this));
userConnection.put(new WindowTracker(userConnection));
userConnection.put(new EntityTracker(userConnection));
userConnection.put(new PlayerPositionTracker(userConnection));
userConnection.put(new GameProfileStorage(userConnection));
userConnection.put(new Scoreboard(userConnection));
userConnection.put(new CompressionStatusTracker(userConnection));
userConnection.put(new WorldBorder(userConnection));
userConnection.put(new WorldBorderEmulator(userConnection));
userConnection.put(new PlayerAbilitiesTracker(userConnection));
userConnection.put(new ClientWorld(userConnection));
}
Expand All @@ -133,7 +133,9 @@ public void init(UserConnection userConnection) {
public void register(ViaProviders providers) {
providers.register(CompressionHandlerProvider.class, new TrackingCompressionHandlerProvider());

Via.getManager().getScheduler().scheduleRepeating(new WorldBorderUpdateTask(), 0L, 50L, TimeUnit.MILLISECONDS);
if (ViaRewind.getConfig().isEmulateWorldBorder()) {
Via.getManager().getScheduler().scheduleRepeating(new WorldBorderUpdateTask(), 0L, 50L, TimeUnit.MILLISECONDS);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.model;

public class FurnaceData {

public short fuelLeft = 0;
public short maxFuel = 0;
public short progress = 0;
public short maxProgress = 200;
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public enum MetaIndex1_7_6_10To1_8 {
ENDER_CRYSTAL_HEALTH(Entity1_10Types.EntityType.ENDER_CRYSTAL, 8, MetaType1_7_6_10.Int, 9, MetaType1_8.Int),
;

private static final HashMap<Pair<Entity1_10Types.EntityType, Integer>, MetaIndex1_7_6_10To1_8> metadataRewrites = new HashMap<>();
private final static HashMap<Pair<Entity1_10Types.EntityType, Integer>, MetaIndex1_7_6_10To1_8> metadataRewrites = new HashMap<>();

static {
for (MetaIndex1_7_6_10To1_8 index : MetaIndex1_7_6_10To1_8.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public enum ParticleIndex1_7_6_10 {

public final String name;
public final int extra;
private static final HashMap<String, ParticleIndex1_7_6_10> particleMap = new HashMap<>();
private final static HashMap<String, ParticleIndex1_7_6_10> particleMap = new HashMap<>();

ParticleIndex1_7_6_10(String name) {
this(name, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@

package com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.packets;

import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ClientboundPackets1_7_2_5;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.EntityTracker;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.GameProfileStorage;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.types.Types1_7_6_10;
import com.viaversion.viarewind.api.minecraft.EntityModel;
import com.viaversion.viarewind.utils.PacketUtil;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_8;
Expand Down Expand Up @@ -222,7 +217,7 @@ public void register() {
handler(wrapper -> {
int entityId = wrapper.get(Type.INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
Entity1_10Types.EntityType type = tracker.getClientEntityTypes().get(entityId);
Entity1_10Types.EntityType type = tracker.getEntityMap().get(entityId);
if (type == Entity1_10Types.EntityType.MINECART_ABSTRACT) { // TODO | Realign all entities?
int y = wrapper.get(Type.INT, 2);
y += 12;
Expand Down Expand Up @@ -298,13 +293,13 @@ public void register() {
final List<Metadata> metadataList = wrapper.get(Types1_7_6_10.METADATA_LIST, 0);

final EntityTracker tracker = wrapper.user().get(EntityTracker.class);
if (tracker.getClientEntityTypes().containsKey(entityId)) {
if (tracker.getEntityMap().containsKey(entityId)) {
final EntityModel<?> replacement = tracker.getEntityReplacement(entityId);
if (replacement != null) {
wrapper.cancel();
replacement.updateMetadata(metadataList);
} else {
protocol.getMetadataRewriter().transform(tracker.getClientEntityTypes().get(entityId), metadataList);
protocol.getMetadataRewriter().transform(tracker.getEntityMap().get(entityId), metadataList);
if (metadataList.isEmpty()) {
wrapper.cancel();
}
Expand Down
Loading

0 comments on commit 2d3e495

Please sign in to comment.