diff --git a/gradle.properties b/gradle.properties index ff28f6af..6732a72c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ fabric_version=0.83.0+1.20.1 maven_group = eu.pb4 -mod_version = 0.5.1 +mod_version = 0.5.2 minecraft_version_supported = ">=1.20-" diff --git a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java index 012ee9cf..b072116a 100644 --- a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java +++ b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java @@ -52,7 +52,7 @@ public static void init(MinecraftServer server) { CommonImpl.saveConfig("auto-host", config); - EarlyPlayNetworkHandler.register(ResourcePackNetworkHandler::new); + EarlyPlayNetworkHandler.register(ResourcePackNetworkHandler::create); provider.serverStarted(server); } diff --git a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/ResourcePackNetworkHandler.java b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/ResourcePackNetworkHandler.java index 3d77373c..3e604104 100644 --- a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/ResourcePackNetworkHandler.java +++ b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/ResourcePackNetworkHandler.java @@ -47,6 +47,13 @@ public ResourcePackNetworkHandler(Context context) { } } + public static ResourcePackNetworkHandler create(Context context) { + if (PolymerCommonUtils.isBedrockPlayer(context.player())) { + return null; + } + return new ResourcePackNetworkHandler(context); + } + @Override public void onTick() { if (this.delayed && AutoHost.provider.isReady()) { diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/other/IdListMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/other/IdListMixin.java index d77fa6df..b23c52f3 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/other/IdListMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/other/IdListMixin.java @@ -119,6 +119,7 @@ public abstract class IdListMixin implements PolymerIdList { } } } + this.polymer$vanillaBitCount = MathHelper.ceilLog2(this.list.size() - this.polymer$states.size()); } } @@ -157,7 +158,7 @@ public abstract class IdListMixin implements PolymerIdList { this.polymer$locked = false; this.polymer$lazyList.forEach(this::add); this.polymer$lazyList.clear(); - this.polymer$vanillaBitCount = MathHelper.ceilLog2(this.size() - this.polymer$states.size()); + this.polymer$vanillaBitCount = MathHelper.ceilLog2(this.list.size() - this.polymer$states.size()); } } diff --git a/polymer-networking/src/main/java/eu/pb4/polymer/networking/api/EarlyPlayNetworkHandler.java b/polymer-networking/src/main/java/eu/pb4/polymer/networking/api/EarlyPlayNetworkHandler.java index 7eaef079..15e2a235 100644 --- a/polymer-networking/src/main/java/eu/pb4/polymer/networking/api/EarlyPlayNetworkHandler.java +++ b/polymer-networking/src/main/java/eu/pb4/polymer/networking/api/EarlyPlayNetworkHandler.java @@ -40,7 +40,7 @@ public static void register(Function construct private final EarlyConnectionMagic.ContextImpl context; private final Identifier identifier; - private volatile long lastRespose = 0; + private volatile long lastResponse = 0; private volatile int keepAliveSent = 0; private volatile int keepAliveReceived = 0; @@ -76,9 +76,9 @@ public boolean handleCustomPayload(CustomPayloadC2SPacket packet) { @Override public final void tick() { - if (this.lastRespose++ == 1200) { + if (this.lastResponse++ == 1200) { this.disconnect(Text.translatable("multiplayer.disconnect.slow_login")); - } else if (this.lastRespose == 20) { + } else if (this.lastResponse == 20) { this.sendKeepAlive(); } @@ -98,7 +98,7 @@ protected boolean isForcingRespawnPacket() { @Override public final void onKeepAlive(KeepAliveC2SPacket packet) { - this.lastRespose = -20; + this.lastResponse = -20; this.keepAliveReceived++; if (this.canContinue) { this.handleKeepAlive(packet.getId()); @@ -443,7 +443,10 @@ public boolean isConnectionOpen() { } @ApiStatus.NonExtendable - public interface Context {} + public interface Context { + MinecraftServer server(); + ServerPlayerEntity player(); + } @Override public final @Nullable ServerPlayerEntity getPlayerForPacketTweaker() { diff --git a/polymer-networking/src/main/java/eu/pb4/polymer/networking/impl/EarlyConnectionMagic.java b/polymer-networking/src/main/java/eu/pb4/polymer/networking/impl/EarlyConnectionMagic.java index 908f37b0..51d9db47 100644 --- a/polymer-networking/src/main/java/eu/pb4/polymer/networking/impl/EarlyConnectionMagic.java +++ b/polymer-networking/src/main/java/eu/pb4/polymer/networking/impl/EarlyConnectionMagic.java @@ -6,6 +6,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -19,28 +20,28 @@ public class EarlyConnectionMagic { public static void handle(ServerPlayerEntity player, MinecraftServer server, ClientConnection connection, Consumer finish) { var iterator = new ArrayList<>(CONSTRUCTORS).iterator(); - if (iterator.hasNext()) { - var context = new ContextImpl(server, player, connection, new ArrayList<>(), (c) -> { - - if (iterator.hasNext()) { - iterator.next().apply(c); - } else { - finish.accept(c); + var context = new ContextImpl(server, player, connection, new ArrayList<>(), (c) -> { + while (iterator.hasNext()) { + var handler = iterator.next().apply(c); + if (handler != null) { + return; } - }); + } + + finish.accept(c); + }); - ((TempPlayerLoginAttachments) player).polymerNet$setLatePackets(context.storedPackets); + ((TempPlayerLoginAttachments) player).polymerNet$setLatePackets(context.storedPackets); - iterator.next().apply(context); - } + context.continueRunning.accept(context); } - public static void register(Function constructor) { + public static void register(Function constructor) { CONSTRUCTORS.add(constructor); } static { - EarlyConnectionMagic.register(PolymerHandshakeHandlerImplLogin::new); + EarlyConnectionMagic.register(PolymerHandshakeHandlerImplLogin::create); } public record ContextImpl( diff --git a/polymer-networking/src/main/java/eu/pb4/polymer/networking/impl/PolymerHandshakeHandlerImplLogin.java b/polymer-networking/src/main/java/eu/pb4/polymer/networking/impl/PolymerHandshakeHandlerImplLogin.java index 7e997533..a4f7cb8b 100644 --- a/polymer-networking/src/main/java/eu/pb4/polymer/networking/impl/PolymerHandshakeHandlerImplLogin.java +++ b/polymer-networking/src/main/java/eu/pb4/polymer/networking/impl/PolymerHandshakeHandlerImplLogin.java @@ -1,6 +1,6 @@ package eu.pb4.polymer.networking.impl; -import com.ibm.icu.impl.ICUResourceBundle; +import eu.pb4.polymer.common.api.PolymerCommonUtils; import eu.pb4.polymer.common.impl.CommonResourcePackInfoHolder; import eu.pb4.polymer.networking.api.EarlyPlayNetworkHandler; import eu.pb4.polymer.networking.api.PolymerHandshakeHandler; @@ -10,18 +10,16 @@ import net.minecraft.nbt.NbtElement; import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; import net.minecraft.network.packet.c2s.play.PlayPongC2SPacket; -import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.util.Identifier; -import net.minecraft.world.GameMode; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; -import java.util.Optional; @ApiStatus.Internal -public class PolymerHandshakeHandlerImplLogin extends EarlyPlayNetworkHandler implements PolymerHandshakeHandler { +public final class PolymerHandshakeHandlerImplLogin extends EarlyPlayNetworkHandler implements PolymerHandshakeHandler { public static long MAGIC_INIT_VALUE = 0xbb706c6d72627374L; public static int CONTINUE_LOGIN_ID = 1; @@ -30,7 +28,7 @@ public class PolymerHandshakeHandlerImplLogin extends EarlyPlayNetworkHandler im private final Object2LongMap lastUpdate = new Object2LongOpenHashMap<>(); private final Map metadata = new HashMap<>(); - public PolymerHandshakeHandlerImplLogin(Context context) { + private PolymerHandshakeHandlerImplLogin(Context context) { super(new Identifier("polymer", "early_handshake"), context); ((TempPlayerLoginAttachments) this.getPlayer()).polymerNet$setHandshakeHandler(this); if (NetImpl.SEND_GAME_JOIN_PACKET) { @@ -41,6 +39,14 @@ public PolymerHandshakeHandlerImplLogin(Context context) { //PolymerSyncUtils.PREPARE_HANDSHAKE.invoke((c) -> c.accept(this)); } + @Nullable + public static EarlyPlayNetworkHandler create(Context context) { + if (PolymerCommonUtils.isBedrockPlayer(context.player())) { + return null; + } + return new PolymerHandshakeHandlerImplLogin(context); + } + public void set(String polymerVersion, Object2IntMap protocolVersions) { this.polymerVersion = polymerVersion; this.protocolVersions = protocolVersions; diff --git a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/VirtualEntityUtils.java b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/VirtualEntityUtils.java index 666ad719..f7e0b476 100644 --- a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/VirtualEntityUtils.java +++ b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/VirtualEntityUtils.java @@ -95,9 +95,13 @@ public static Packet createSimpleMovePacket(int id, Ve } public static EntityPassengersSetS2CPacket createRidePacket(int id, IntList list) { + return createRidePacket(id, list.toIntArray()); + } + + public static EntityPassengersSetS2CPacket createRidePacket(int id, int[] list) { var packet = VirtualEntityImplUtils.createUnsafe(EntityPassengersSetS2CPacket.class); ((EntityPassengersSetS2CPacketAccessor) packet).setId(id); - ((EntityPassengersSetS2CPacketAccessor) packet).setPassengerIds(list.toIntArray()); + ((EntityPassengersSetS2CPacketAccessor) packet).setPassengerIds(list); return packet; } diff --git a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/elements/GenericEntityElement.java b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/elements/GenericEntityElement.java index 29eec381..2d667338 100644 --- a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/elements/GenericEntityElement.java +++ b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/elements/GenericEntityElement.java @@ -85,7 +85,10 @@ public final int getEntityId() { public void setOffset(Vec3d offset) { super.setOffset(offset); if (this.getHolder() != null) { - this.getHolder().sendPacket(VirtualEntityUtils.createMovePacket(this.id, this.getHolder().getPos().add(this.getOffset()), this.getHolder().getPos().add(offset), false, 0f, 0f)); + var x = VirtualEntityUtils.createMovePacket(this.id, this.getHolder().getPos().add(this.getOffset()), this.getHolder().getPos().add(offset), false, 0f, 0f); + if (x != null) { + this.getHolder().sendPacket(x); + } } } @@ -113,7 +116,10 @@ protected void sendChangedTrackerEntries(ServerPlayerEntity player, Consumer