Search in sources :

Example 6 with SPacketEffect

use of net.minecraft.network.play.server.SPacketEffect in project Wurst-MC-1.12 by Wurst-Imperium.

the class PlayerFinderMod method onReceivedPacket.

@Override
public void onReceivedPacket(PacketInputEvent event) {
    if (WMinecraft.getPlayer() == null)
        return;
    Packet packet = event.getPacket();
    // get packet position
    BlockPos newPos = null;
    if (packet instanceof SPacketEffect) {
        SPacketEffect effect = (SPacketEffect) packet;
        newPos = effect.getSoundPos();
    } else if (packet instanceof SPacketSoundEffect) {
        SPacketSoundEffect sound = (SPacketSoundEffect) packet;
        newPos = new BlockPos(sound.getX(), sound.getY(), sound.getZ());
    } else if (packet instanceof SPacketSpawnGlobalEntity) {
        SPacketSpawnGlobalEntity lightning = (SPacketSpawnGlobalEntity) packet;
        newPos = new BlockPos(lightning.getX() / 32D, lightning.getY() / 32D, lightning.getZ() / 32D);
    }
    if (newPos == null)
        return;
    // check distance to player
    BlockPos playerPos = new BlockPos(WMinecraft.getPlayer());
    if (Math.abs(playerPos.getX() - newPos.getX()) > 250 || Math.abs(playerPos.getZ() - newPos.getZ()) > 250)
        pos = newPos;
}
Also used : SPacketEffect(net.minecraft.network.play.server.SPacketEffect) SPacketSoundEffect(net.minecraft.network.play.server.SPacketSoundEffect) Packet(net.minecraft.network.Packet) BlockPos(net.minecraft.util.math.BlockPos) SPacketSpawnGlobalEntity(net.minecraft.network.play.server.SPacketSpawnGlobalEntity)

Example 7 with SPacketEffect

use of net.minecraft.network.play.server.SPacketEffect in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class VSNetwork method sendToAllNearExcept.

public static void sendToAllNearExcept(@Nullable EntityPlayer except, double x, double y, double z, double radius, int dimension, Packet<?> packetIn) {
    BlockPos pos = new BlockPos(x, y, z);
    World worldIn;
    if (except == null) {
        worldIn = DimensionManager.getWorld(dimension);
    } else {
        worldIn = except.world;
    }
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(worldIn, pos);
    Vector3d packetPosition = new Vector3d(x, y, z);
    if (physicsObject.isPresent()) {
        physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(packetPosition, TransformType.SUBSPACE_TO_GLOBAL);
        // Special treatment for certain packets.
        if (packetIn instanceof SPacketSoundEffect) {
            SPacketSoundEffect soundEffect = (SPacketSoundEffect) packetIn;
            packetIn = new SPacketSoundEffect(soundEffect.sound, soundEffect.category, packetPosition.x, packetPosition.y, packetPosition.z, soundEffect.soundVolume, soundEffect.soundPitch);
        }
        if (packetIn instanceof SPacketEffect) {
            SPacketEffect effect = (SPacketEffect) packetIn;
            BlockPos blockpos = new BlockPos(packetPosition.x, packetPosition.y, packetPosition.z);
            packetIn = new SPacketEffect(effect.soundType, blockpos, effect.soundData, effect.serverWide);
        }
    }
    List<EntityPlayer> playerEntityList = ((WorldServer) worldIn).playerEntities;
    // Original method here.
    for (int i = 0; i < playerEntityList.size(); ++i) {
        EntityPlayerMP entityplayermp = (EntityPlayerMP) playerEntityList.get(i);
        if (entityplayermp != except && entityplayermp.dimension == dimension) {
            double d0 = x - entityplayermp.posX;
            double d1 = y - entityplayermp.posY;
            double d2 = z - entityplayermp.posZ;
            double d3 = packetPosition.x - entityplayermp.posX;
            double d4 = packetPosition.y - entityplayermp.posY;
            double d5 = packetPosition.z - entityplayermp.posZ;
            // Cover both cases; if player is in ship space or if player is in world space.
            if ((d0 * d0 + d1 * d1 + d2 * d2 < radius * radius) || (d3 * d3 + d4 * d4 + d5 * d5 < radius * radius)) {
                entityplayermp.connection.sendPacket(packetIn);
            }
        }
    }
}
Also used : SPacketSoundEffect(net.minecraft.network.play.server.SPacketSoundEffect) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SPacketEffect(net.minecraft.network.play.server.SPacketEffect) Vector3d(org.joml.Vector3d) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 8 with SPacketEffect

use of net.minecraft.network.play.server.SPacketEffect in project SpongeForge by SpongePowered.

the class EntityPlayerMPMixin_Forge method changeDimension.

/**
 * @author Zidane - June 2019 - 1.12.2
 * @reason Re-route dimension changes to common hook
 */
@Nullable
@Overwrite(remap = false)
public net.minecraft.entity.Entity changeDimension(final int toDimensionId, final ITeleporter teleporter) {
    if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension((EntityPlayerMP) (Object) this, toDimensionId)) {
        return (EntityPlayerMP) (Object) this;
    }
    this.invulnerableDimensionChange = true;
    if (this.dimension == 0 && toDimensionId == -1) {
        this.enteredNetherPosition = new Vec3d(this.posX, this.posY, this.posZ);
    } else if (this.dimension != -1 && toDimensionId != 0) {
        this.enteredNetherPosition = null;
    }
    if (this.dimension == 1 && toDimensionId == 1 && teleporter.isVanilla()) {
        this.world.removeEntity((EntityPlayerMP) (Object) this);
        if (!this.queuedEndExit) {
            this.queuedEndExit = true;
            this.connection.sendPacket(new SPacketChangeGameState(4, this.seenCredits ? 0.0F : 1.0F));
            this.seenCredits = true;
        }
        return (EntityPlayerMP) (Object) this;
    } else {
        // this.server.getPlayerList().transferPlayerToDimension(this, dimensionIn, teleporter);
        if (EntityUtil.transferPlayerToWorld((EntityPlayerMP) (Object) this, null, this.server.getWorld(toDimensionId), (ForgeITeleporterBridge) teleporter) != null) {
            // Sponge end
            this.connection.sendPacket(new SPacketEffect(1032, BlockPos.ORIGIN, 0, false));
            this.lastExperience = -1;
            this.lastHealth = -1.0F;
            this.lastFoodLevel = -1;
        } else {
            this.invulnerableDimensionChange = false;
        }
        return (EntityPlayerMP) (Object) this;
    }
}
Also used : SPacketEffect(net.minecraft.network.play.server.SPacketEffect) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketChangeGameState(net.minecraft.network.play.server.SPacketChangeGameState) ForgeITeleporterBridge(org.spongepowered.common.bridge.world.ForgeITeleporterBridge) Vec3d(net.minecraft.util.math.Vec3d) Overwrite(org.spongepowered.asm.mixin.Overwrite) Nullable(javax.annotation.Nullable)

Aggregations

SPacketEffect (net.minecraft.network.play.server.SPacketEffect)8 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 BlockPos (net.minecraft.util.math.BlockPos)5 WorldServer (net.minecraft.world.WorldServer)4 Nullable (javax.annotation.Nullable)3 SPacketChangeGameState (net.minecraft.network.play.server.SPacketChangeGameState)3 SPacketSoundEffect (net.minecraft.network.play.server.SPacketSoundEffect)3 Vec3d (net.minecraft.util.math.Vec3d)2 World (net.minecraft.world.World)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 Vector (ValkyrienWarfareBase.API.Vector)1 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)1 IColony (com.minecolonies.api.colony.IColony)1 Colony (com.minecolonies.coremod.colony.Colony)1 BuildingTownHall (com.minecolonies.coremod.colony.buildings.BuildingTownHall)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Packet (net.minecraft.network.Packet)1 SPacketSpawnGlobalEntity (net.minecraft.network.play.server.SPacketSpawnGlobalEntity)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 TextComponentString (net.minecraft.util.text.TextComponentString)1