1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-28 19:19:15 +00:00

More proper player reloading

This commit is contained in:
Camotoy
2021-03-29 14:07:05 -04:00
parent 71395ed659
commit 01134d2f6c

View File

@@ -1,17 +1,30 @@
package org.geysermc.floodgate.pluginmessage;
import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.datafixers.util.Pair;
import lombok.RequiredArgsConstructor;
import net.minecraft.network.packet.s2c.play.EntitiesDestroyS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerSpawnS2CPacket;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.util.math.MathHelper;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.geysermc.floodgate.skin.SkinApplier;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@RequiredArgsConstructor
public final class FabricSkinApplier implements SkinApplier {
// See FabricCommandUtil
@@ -51,7 +64,45 @@ public final class FabricSkinApplier implements SkinApplier {
otherPlayer.networkHandler.sendPacket(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, bedrockPlayer));
if (loadedInWorld) {
otherPlayer.networkHandler.sendPacket(new PlayerSpawnS2CPacket(bedrockPlayer));
// Copied from EntityTrackerEntry
Packet<?> spawnPacket = bedrockPlayer.createSpawnPacket();
otherPlayer.networkHandler.sendPacket(spawnPacket);
if (!bedrockPlayer.getDataTracker().isEmpty()) {
otherPlayer.networkHandler.sendPacket(new EntityTrackerUpdateS2CPacket(bedrockPlayer.getEntityId(), bedrockPlayer.getDataTracker(), true));
}
Collection<EntityAttributeInstance> collection = bedrockPlayer.getAttributes().getAttributesToSend();
if (!collection.isEmpty()) {
otherPlayer.networkHandler.sendPacket(new EntityAttributesS2CPacket(bedrockPlayer.getEntityId(), collection));
}
otherPlayer.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(bedrockPlayer.getEntityId(), bedrockPlayer.getVelocity()));
List<Pair<EquipmentSlot, ItemStack>> equipmentList = Lists.newArrayList();
EquipmentSlot[] slots = EquipmentSlot.values();
for (EquipmentSlot equipmentSlot : slots) {
ItemStack itemStack = bedrockPlayer.getEquippedStack(equipmentSlot);
if (!itemStack.isEmpty()) {
equipmentList.add(Pair.of(equipmentSlot, itemStack.copy()));
}
}
if (!equipmentList.isEmpty()) {
otherPlayer.networkHandler.sendPacket(new EntityEquipmentUpdateS2CPacket(bedrockPlayer.getEntityId(), equipmentList));
}
for (StatusEffectInstance statusEffectInstance : bedrockPlayer.getStatusEffects()) {
otherPlayer.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(bedrockPlayer.getEntityId(), statusEffectInstance));
}
if (!bedrockPlayer.getPassengerList().isEmpty()) {
otherPlayer.networkHandler.sendPacket(new EntityPassengersSetS2CPacket(bedrockPlayer));
}
if (bedrockPlayer.hasVehicle()) {
otherPlayer.networkHandler.sendPacket(new EntityPassengersSetS2CPacket(bedrockPlayer.getVehicle()));
}
}
}
});