Merge branch 'master' into future

This commit is contained in:
gnembon committed 2022-01-19 21:46:37 +01:00
commit 0de2d74ef0
14 files changed
+84 -95

No files matched your search

@@ -1,18 +1,21 @@
package carpet.mixins;
import carpet.fakes.ClientConnectionInterface;
import carpet.logging.logHelpers.PacketCounter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.Packet;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientConnection.class)
public abstract class ClientConnectionMixin
public abstract class ClientConnectionMixin implements ClientConnectionInterface
{
// Add to the packet counter whenever a packet is received.
@Inject(method = "channelRead0", at = @At("HEAD"))
@@ -28,4 +31,8 @@ public abstract class ClientConnectionMixin
{
PacketCounter.totalOut++;
}
@Override
@Accessor //Compat with adventure-platform-fabric
public abstract void setChannel(Channel channel);
}
@@ -3,6 +3,7 @@ package carpet.mixins;
import carpet.fakes.EntityInterface;
import carpet.script.EntityEventsGroup;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -19,10 +20,14 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
@Shadow public abstract boolean isRemoved();
@Shadow private Vec3d pos, velocity;
private boolean permanentVehicle;
private final EntityEventsGroup events = new EntityEventsGroup((Entity) (Object)this);
private Vec3d pos1, motion;
@Override
public EntityEventsGroup getEventContainer()
{
@@ -79,4 +84,16 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
}
@Inject(method = "setPos", at = @At("HEAD"))
private void firstPos(CallbackInfo ci)
{
pos1 = this.pos;
motion = this.velocity;
}
@Inject(method = "setPos", at = @At("TAIL"))
private void secondPos(CallbackInfo ci)
{
events.onEvent(EntityEventsGroup.Event.ON_MOVE, motion, pos1, this.pos);
}
}
@@ -1,9 +1,7 @@
package carpet.mixins;
import com.mojang.authlib.GameProfile;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.ClientConnection;
import net.minecraft.text.TranslatableText;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayNetworkHandler;
@@ -15,14 +13,9 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import carpet.patches.NetHandlerPlayServerFake;
import carpet.patches.EntityPlayerMPFake;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@Mixin(PlayerManager.class)
public abstract class PlayerManager_fakePlayersMixin
{
@@ -42,38 +35,13 @@ public abstract class PlayerManager_fakePlayersMixin
@Redirect(method = "onPlayerConnect", at = @At(value = "NEW", target = "net/minecraft/server/network/ServerPlayNetworkHandler"))
private ServerPlayNetworkHandler replaceNetworkHandler(MinecraftServer server, ClientConnection clientConnection, ServerPlayerEntity playerIn)
{
boolean isServerPlayerEntity = playerIn instanceof EntityPlayerMPFake;
if (isServerPlayerEntity)
if (playerIn instanceof EntityPlayerMPFake fake)
{
return new NetHandlerPlayServerFake(this.server, clientConnection, playerIn);
return new NetHandlerPlayServerFake(this.server, clientConnection, fake);
}
else
{
return new ServerPlayNetworkHandler(this.server, clientConnection, playerIn);
}
}
@Redirect(method = "createPlayer", at = @At(value = "INVOKE", target = "Ljava/util/Iterator;hasNext()Z"))
private boolean cancelWhileLoop(Iterator iterator)
{
return false;
}
@Inject(method = "createPlayer", at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
target = "Ljava/util/Iterator;hasNext()Z"), locals = LocalCapture.CAPTURE_FAILHARD)
private void newWhileLoop(GameProfile gameProfile_1, CallbackInfoReturnable<ServerPlayerEntity> cir, UUID uUID_1,
List list_1, ServerPlayerEntity serverPlayerEntity, Iterator var5)
{
while (var5.hasNext())
{
ServerPlayerEntity serverPlayerEntity_3 = (ServerPlayerEntity) var5.next();
if(serverPlayerEntity_3 instanceof EntityPlayerMPFake)
{
((EntityPlayerMPFake)serverPlayerEntity_3).kill(new TranslatableText("multiplayer.disconnect.duplicate_login"));
continue;
}
serverPlayerEntity_3.networkHandler.disconnect(new TranslatableText("multiplayer.disconnect.duplicate_login"));
}
}
}
@@ -1,29 +0,0 @@
package carpet.mixins;
import carpet.patches.EntityPlayerMPFake;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.entity.projectile.thrown.ThrownItemEntity;
import net.minecraft.network.ClientConnection;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(EnderPearlEntity.class)
public abstract class ThrownEnderpearlEntity_fakePlayersMixin extends ThrownItemEntity
{
public ThrownEnderpearlEntity_fakePlayersMixin(EntityType<? extends ThrownItemEntity> entityType_1, World world_1)
{
super(entityType_1, world_1);
}
@Redirect(method = "onCollision", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/ClientConnection;isOpen()Z"
))
private boolean isConnectionGood(ClientConnection clientConnection)
{
return clientConnection.isOpen() || getOwner() instanceof EntityPlayerMPFake;
}
}