Search in sources :

Example 1 with SPacketCustomSound

use of net.minecraft.network.play.server.SPacketCustomSound in project MineCamera by PorPit.

the class ItemCamera method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    // System.out.println("1:"+playerIn.getActiveHand());
    playerIn.setActiveHand(hand);
    // System.out.println("2:"+playerIn.getActiveHand());
    if (playerIn.isSneaking()) {
        if (!worldIn.isRemote) {
            BlockPos pos = playerIn.getPosition();
            int id = GuiElementLoader.GUI_CAMERA;
            playerIn.openGui(MineCamera.instance, id, worldIn, pos.getX(), pos.getY(), pos.getZ());
        }
    } else {
        // ��Ʒ����
        if (!itemStackIn.hasTagCompound()) {
            itemStackIn.setTagCompound(new NBTTagCompound());
        }
        if (itemStackIn.getTagCompound().hasKey("filmOutCatch")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.isouting"));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        if (!itemStackIn.getTagCompound().hasKey("filmSlot")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.nofilm"));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        if (!itemStackIn.getTagCompound().hasKey("betterySlot")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.nobettery"));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        if (itemStackIn.getTagCompound().hasKey("filmOutSlot")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.hasfilmout"));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        ItemStack betteryStack = ItemStack.loadItemStackFromNBT(itemStackIn.getTagCompound().getCompoundTag("betterySlot"));
        if (betteryStack.getItemDamage() == betteryStack.getMaxDamage()) {
            itemStackIn.getTagCompound().removeTag("betterySlot");
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage(new TextComponentTranslation("chat.minecamera.betteryrunout"));
        } else {
            betteryStack.damageItem(1, playerIn);
            NBTTagCompound itemTag = new NBTTagCompound();
            betteryStack.writeToNBT(itemTag);
            itemStackIn.getTagCompound().setTag("betterySlot", itemTag);
        }
        ItemStack filmStack = ItemStack.loadItemStackFromNBT(itemStackIn.getTagCompound().getCompoundTag("filmSlot"));
        String createdpid = playerIn.getName() + "%_%" + System.currentTimeMillis();
        if (filmStack.hasTagCompound() && filmStack.getTagCompound().hasKey("pid")) {
            if (!worldIn.isRemote)
                playerIn.addChatComponentMessage((new TextComponentTranslation("chat.minecamera.filmcantwrite")));
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        } else {
            itemStackIn.getTagCompound().removeTag("filmSlot");
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setString("pid", createdpid);
            filmStack.setTagCompound(nbt);
            NBTTagCompound itemTag = new NBTTagCompound();
            filmStack.writeToNBT(itemTag);
            itemStackIn.getTagCompound().setTag("filmOutCatch", itemTag);
            if (!worldIn.isRemote) {
                MessageImageSyncSave message = new MessageImageSyncSave();
                message.imageName = createdpid;
                NetworkLoader.instance.sendTo(message, (EntityPlayerMP) playerIn);
            }
        }
        itemStackIn.getTagCompound().setInteger("burnTime", 0);
        // ��Ⱦ
        if (!worldIn.isRemote) {
            double particlePosX = playerIn.posX, particlePosY = playerIn.posY + 1.35, particlePosZ = playerIn.posZ;
            particlePosX = particlePosX + (-Math.sin(Math.toRadians(playerIn.rotationYaw + 15)) * 0.7) * Math.cos(Math.toRadians(playerIn.rotationPitch));
            particlePosY = particlePosY + (-Math.sin(Math.toRadians(playerIn.rotationPitch)) * 0.7);
            particlePosZ = particlePosZ + (Math.cos(Math.toRadians(playerIn.rotationYaw + 15)) * 0.7) * Math.cos(Math.toRadians(playerIn.rotationPitch));
            List<EntityPlayer> listentity = worldIn.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(playerIn.posX - 16, playerIn.posY - 16, playerIn.posZ - 16, playerIn.posX + 16, playerIn.posY + 16, playerIn.posZ + 16));
            if (listentity != null) {
                for (EntityPlayer i : listentity) {
                    EntityPlayerMP entityplayermp = (EntityPlayerMP) i;
                    entityplayermp.connection.sendPacket(new SPacketCustomSound("minecamera:minecamera.kacha", SoundCategory.PLAYERS, playerIn.posX, playerIn.posY, playerIn.posZ, 1.0F, 1.0F));
                    MessageSpawnParticle message = new MessageSpawnParticle();
                    message.delay = 200;
                    message.typeid = EnumParticleTypes.FIREWORKS_SPARK.getParticleID();
                    message.PosX = particlePosX;
                    message.PosY = particlePosY;
                    message.PosZ = particlePosZ;
                    message.SpeedX = 0;
                    message.SpeedY = 0;
                    message.SpeedZ = 0;
                    NetworkLoader.instance.sendTo(message, entityplayermp);
                /*
						 * entityplayermp.connection.sendPacket(new
						 * SPacketParticles(EnumParticleTypes.FIREWORKS_SPARK,
						 * EnumParticleTypes.FIREWORKS_SPARK.
						 * getShouldIgnoreRange(), (float) particlePosX, (float)
						 * particlePosY, (float) particlePosZ, 0F, 0F, 0F,
						 * 0.03F, 1));
						 */
                }
            }
        }
        if (!worldIn.isRemote)
            playerIn.addChatComponentMessage((new TextComponentTranslation("chat.minecamera.success")));
    }
    return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) MessageImageSyncSave(com.porpit.minecamera.network.MessageImageSyncSave) MessageSpawnParticle(com.porpit.minecamera.network.MessageSpawnParticle) SPacketCustomSound(net.minecraft.network.play.server.SPacketCustomSound) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 2 with SPacketCustomSound

use of net.minecraft.network.play.server.SPacketCustomSound in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method playSound.

@Override
public void playSound(SoundType sound, SoundCategory category, Vector3d position, double volume, double pitch, double minVolume) {
    SoundEvent event;
    try {
        // Check if the event is registered (ie has an integer ID)
        event = SoundEvents.getRegisteredSoundEvent(sound.getId());
    } catch (IllegalStateException e) {
        // Otherwise send it as a custom sound
        this.connection.sendPacket(new SPacketCustomSound(sound.getId(), (net.minecraft.util.SoundCategory) (Object) category, position.getX(), position.getY(), position.getZ(), (float) Math.max(minVolume, volume), (float) pitch));
        return;
    }
    this.connection.sendPacket(new SPacketSoundEffect(event, (net.minecraft.util.SoundCategory) (Object) category, position.getX(), position.getY(), position.getZ(), (float) Math.max(minVolume, volume), (float) pitch));
}
Also used : SPacketSoundEffect(net.minecraft.network.play.server.SPacketSoundEffect) SoundEvent(net.minecraft.util.SoundEvent) SPacketCustomSound(net.minecraft.network.play.server.SPacketCustomSound) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) IInteractionObject(net.minecraft.world.IInteractionObject)

Aggregations

SPacketCustomSound (net.minecraft.network.play.server.SPacketCustomSound)2 MessageImageSyncSave (com.porpit.minecamera.network.MessageImageSyncSave)1 MessageSpawnParticle (com.porpit.minecamera.network.MessageSpawnParticle)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SPacketSoundEffect (net.minecraft.network.play.server.SPacketSoundEffect)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 SoundEvent (net.minecraft.util.SoundEvent)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 IInteractionObject (net.minecraft.world.IInteractionObject)1 SoundCategory (org.spongepowered.api.effect.sound.SoundCategory)1