Migrate the Carpet codebase to Mojang Mappings

This commit is contained in:
altrisi committed 2022-01-24 20:33:16 +01:00
1 parent a1a2488bc3
commit 06af9ce8b1
346 files changed
+8353 -8492

No files matched your search

@@ -1,13 +1,12 @@
package carpet.patches;
import net.minecraft.util.profiler.ProfileResult;
import net.minecraft.util.profiler.ProfilerTiming;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import net.minecraft.util.profiling.ProfileResults;
import net.minecraft.util.profiling.ResultField;
public class CopyProfilerResult implements ProfileResult {
public class CopyProfilerResult implements ProfileResults {
int startI, endI;
long startL, endL;
public CopyProfilerResult(int startI, long startL, int endI, long endL)
@@ -18,37 +17,37 @@ public class CopyProfilerResult implements ProfileResult {
this.endL = endL;
}
@Override
public List<ProfilerTiming> getTimings(String parentPath) {
public List<ResultField> getTimes(String parentPath) {
return Collections.emptyList();
}
@Override
public boolean save(Path path) {
public boolean saveResults(Path path) {
return false;
}
@Override
public long getStartTime() {
public long getStartTimeNano() {
return startL;
}
@Override
public int getStartTick() {
public int getStartTimeTicks() {
return startI;
}
@Override
public long getEndTime() {
public long getEndTimeNano() {
return endL;
}
@Override
public int getEndTick() {
public int getEndTimeTicks() {
return endI;
}
@Override
public String getRootTimings() {
public String getProfilerResults() {
return "";
}
}
@@ -2,48 +2,48 @@ package carpet.patches;
import carpet.CarpetSettings;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.entity.SkullBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket;
import net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.HungerManager;
import net.minecraft.network.NetworkSide;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTask;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.UserCache;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;
import net.minecraft.server.TickTask;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.GameProfileCache;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import carpet.fakes.ServerPlayerEntityInterface;
import carpet.utils.Messenger;
import java.util.concurrent.atomic.AtomicReference;
@SuppressWarnings("EntityConstructor")
public class EntityPlayerMPFake extends ServerPlayerEntity
public class EntityPlayerMPFake extends ServerPlayer
{
public Runnable fixStartingPosition = () -> {};
public boolean isAShadow;
public static EntityPlayerMPFake createFake(String username, MinecraftServer server, double d0, double d1, double d2, double yaw, double pitch, RegistryKey<World> dimensionId, GameMode gamemode, boolean flying)
public static EntityPlayerMPFake createFake(String username, MinecraftServer server, double d0, double d1, double d2, double yaw, double pitch, ResourceKey<Level> dimensionId, GameType gamemode, boolean flying)
{
//prolly half of that crap is not necessary, but it works
ServerWorld worldIn = server.getWorld(dimensionId);
UserCache.setUseRemote(false);
ServerLevel worldIn = server.getLevel(dimensionId);
GameProfileCache.setUsesAuthentication(false);
GameProfile gameprofile;
try {
gameprofile = server.getUserCache().findByName(username).orElse(null); //findByName .orElse(null)
gameprofile = server.getProfileCache().get(username).orElse(null); //findByName .orElse(null)
}
finally {
UserCache.setUseRemote(server.isDedicated() && server.isOnlineMode());
GameProfileCache.setUsesAuthentication(server.isDedicatedServer() && server.usesAuthentication());
}
if (gameprofile == null)
{
@@ -51,65 +51,65 @@ public class EntityPlayerMPFake extends ServerPlayerEntity
{
return null;
} else {
gameprofile = new GameProfile(PlayerEntity.getOfflinePlayerUuid(username), username);
gameprofile = new GameProfile(Player.createPlayerUUID(username), username);
}
}
if (gameprofile.getProperties().containsKey("textures"))
{
AtomicReference<GameProfile> result = new AtomicReference<>();
SkullBlockEntity.loadProperties(gameprofile, result::set);
SkullBlockEntity.updateGameprofile(gameprofile, result::set);
gameprofile = result.get();
}
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false);
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(d0, d1, d2, (float) yaw, (float) pitch);
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance);
instance.teleport(worldIn, d0, d1, d2, (float)yaw, (float)pitch);
instance.fixStartingPosition = () -> instance.moveTo(d0, d1, d2, (float) yaw, (float) pitch);
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance);
instance.teleportTo(worldIn, d0, d1, d2, (float)yaw, (float)pitch);
instance.setHealth(20.0F);
instance.unsetRemoved();
instance.stepHeight = 0.6F;
instance.interactionManager.changeGameMode(gamemode);
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), dimensionId);//instance.dimension);
server.getPlayerManager().sendToDimension(new EntityPositionS2CPacket(instance), dimensionId);//instance.dimension);
instance.maxUpStep = 0.6F;
instance.gameMode.changeGameModeForPlayer(gamemode);
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(instance, (byte) (instance.yHeadRot * 256 / 360)), dimensionId);//instance.dimension);
server.getPlayerList().broadcastAll(new ClientboundTeleportEntityPacket(instance), dimensionId);//instance.dimension);
//instance.world.getChunkManager(). updatePosition(instance);
instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes)
instance.getAbilities().flying = flying;
return instance;
}
public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlayerEntity player)
public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlayer player)
{
player.getServer().getPlayerManager().remove(player);
player.networkHandler.disconnect(new TranslatableText("multiplayer.disconnect.duplicate_login"));
ServerWorld worldIn = player.getWorld();//.getWorld(player.dimension);
player.getServer().getPlayerList().remove(player);
player.connection.disconnect(new TranslatableComponent("multiplayer.disconnect.duplicate_login"));
ServerLevel worldIn = player.getLevel();//.getWorld(player.dimension);
GameProfile gameprofile = player.getGameProfile();
EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, true);
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), playerShadow);
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow);
playerShadow.setHealth(player.getHealth());
playerShadow.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
playerShadow.interactionManager.changeGameMode(player.interactionManager.getGameMode());
playerShadow.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
playerShadow.gameMode.changeGameModeForPlayer(player.gameMode.getGameModeForPlayer());
((ServerPlayerEntityInterface) playerShadow).getActionPack().copyFrom(((ServerPlayerEntityInterface) player).getActionPack());
playerShadow.stepHeight = 0.6F;
playerShadow.dataTracker.set(PLAYER_MODEL_PARTS, player.getDataTracker().get(PLAYER_MODEL_PARTS));
playerShadow.maxUpStep = 0.6F;
playerShadow.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, player.getEntityData().get(DATA_PLAYER_MODE_CUSTOMISATION));
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(playerShadow, (byte) (player.headYaw * 256 / 360)), playerShadow.world.getRegistryKey());
server.getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, playerShadow));
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(playerShadow, (byte) (player.yHeadRot * 256 / 360)), playerShadow.level.dimension());
server.getPlayerList().broadcastAll(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, playerShadow));
//player.world.getChunkManager().updatePosition(playerShadow);
playerShadow.getAbilities().flying = player.getAbilities().flying;
return playerShadow;
}
private EntityPlayerMPFake(MinecraftServer server, ServerWorld worldIn, GameProfile profile, boolean shadow)
private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, boolean shadow)
{
super(server, worldIn, profile);
isAShadow = shadow;
}
@Override
protected void onEquipStack(ItemStack stack)
protected void equipEventAndSound(ItemStack stack)
{
if (!isUsingItem()) super.onEquipStack(stack);
if (!isUsingItem()) super.equipEventAndSound(stack);
}
@Override
@@ -118,27 +118,27 @@ public class EntityPlayerMPFake extends ServerPlayerEntity
kill(Messenger.s("Killed"));
}
public void kill(Text reason)
public void kill(Component reason)
{
shakeOff();
this.server.send(new ServerTask(this.server.getTicks(), () -> {
this.networkHandler.onDisconnected(reason);
this.server.tell(new TickTask(this.server.getTickCount(), () -> {
this.connection.onDisconnect(reason);
}));
}
@Override
public void tick()
{
if (this.getServer().getTicks() % 10 == 0)
if (this.getServer().getTickCount() % 10 == 0)
{
this.networkHandler.syncWithPlayerPosition();
this.getWorld().getChunkManager().updatePosition(this);
onTeleportationDone(); //<- causes hard crash but would need to be done to enable portals // not as of 1.17
this.connection.resetPosition();
this.getLevel().getChunkSource().move(this);
hasChangedDimension(); //<- causes hard crash but would need to be done to enable portals // not as of 1.17
}
try
{
super.tick();
this.playerTick();
this.doTick();
}
catch (NullPointerException ignored)
{
@@ -151,25 +151,25 @@ public class EntityPlayerMPFake extends ServerPlayerEntity
private void shakeOff()
{
if (getVehicle() instanceof PlayerEntity) stopRiding();
for (Entity passenger : getPassengersDeep())
if (getVehicle() instanceof Player) stopRiding();
for (Entity passenger : getIndirectPassengers())
{
if (passenger instanceof PlayerEntity) passenger.stopRiding();
if (passenger instanceof Player) passenger.stopRiding();
}
}
@Override
public void onDeath(DamageSource cause)
public void die(DamageSource cause)
{
shakeOff();
super.onDeath(cause);
super.die(cause);
setHealth(20);
this.hungerManager = new HungerManager();
kill(this.getDamageTracker().getDeathMessage());
this.foodData = new FoodData();
kill(this.getCombatTracker().getDeathMessage());
}
@Override
public String getIp()
public String getIpAddress()
{
return "127.0.0.1";
}
@@ -2,12 +2,12 @@ package carpet.patches;
import carpet.fakes.ClientConnectionInterface;
import io.netty.channel.embedded.EmbeddedChannel;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.NetworkSide;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.PacketFlow;
public class FakeClientConnection extends ClientConnection
public class FakeClientConnection extends Connection
{
public FakeClientConnection(NetworkSide p)
public FakeClientConnection(PacketFlow p)
{
super(p);
// compat with adventure-platform-fabric. This does NOT trigger other vanilla handlers for establishing a channel
@@ -16,7 +16,7 @@ public class FakeClientConnection extends ClientConnection
}
@Override
public void disableAutoRead()
public void setReadOnly()
{
}
@@ -1,28 +1,28 @@
package carpet.patches;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.Packet;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler
public class NetHandlerPlayServerFake extends ServerGamePacketListenerImpl
{
public NetHandlerPlayServerFake(MinecraftServer server, ClientConnection cc, EntityPlayerMPFake playerIn)
public NetHandlerPlayServerFake(MinecraftServer server, Connection cc, EntityPlayerMPFake playerIn)
{
super(server, cc, playerIn);
}
@Override
public void sendPacket(final Packet<?> packetIn)
public void send(final Packet<?> packetIn)
{
}
@Override
public void disconnect(Text message)
public void disconnect(Component message)
{
if (message instanceof TranslatableText text && (text.getKey().equals("multiplayer.disconnect.idling") || text.getKey().equals("multiplayer.disconnect.duplicate_login")))
if (message instanceof TranslatableComponent text && (text.getKey().equals("multiplayer.disconnect.idling") || text.getKey().equals("multiplayer.disconnect.duplicate_login")))
{
((EntityPlayerMPFake) player).kill(message);
}