Search in sources :

Example 46 with ActionResult

use of net.minecraft.util.ActionResult in project Cavern2 by kegare.

the class ItemMirageBook method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    DimensionType type = EnumType.byItemStack(stack).getDimension();
    if (type == null) {
        return new ActionResult<>(EnumActionResult.PASS, stack);
    }
    if (world.provider.getDimensionType() == type) {
        if (!world.isRemote) {
            PlayerData.get(player).setLastTeleportTime(type, world.getTotalWorldTime());
            transferTo(null, player);
        }
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }
    if (world.isRemote) {
        if (CavernAPI.dimension.isInMirageWorlds(player)) {
            player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".fail"), true);
        } else {
            player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".portal"), true);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, stack);
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 47 with ActionResult

use of net.minecraft.util.ActionResult 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 48 with ActionResult

use of net.minecraft.util.ActionResult in project Binnie by ForestryMC.

the class ItemHoneyCrystal method onItemRightClick.

@Override
@Optional.Method(modid = "ic2")
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote && stack.getCount() == 1) {
        if (ElectricItem.manager.getCharge(stack) > 0.0D) {
            boolean transferred = false;
            for (int i = 0; i < 9; ++i) {
                ItemStack target = player.inventory.mainInventory.get(i);
                if (target != null && target != stack && ElectricItem.manager.discharge(target, Double.POSITIVE_INFINITY, Integer.MAX_VALUE, true, true, true) <= 0.0D) {
                    double transfer = ElectricItem.manager.discharge(stack, 2.0D * TRANSFER_LIMIT, Integer.MAX_VALUE, true, true, true);
                    if (transfer > 0.0D) {
                        transfer = ElectricItem.manager.charge(target, transfer, TIER, true, false);
                        if (transfer > 0.0D) {
                            ElectricItem.manager.discharge(stack, transfer, Integer.MAX_VALUE, true, true, false);
                            transferred = true;
                        }
                    }
                }
            }
            if (transferred && !world.isRemote) {
                player.openContainer.detectAndSendChanges();
            }
        }
        return new ActionResult(EnumActionResult.SUCCESS, stack);
    } else {
        return new ActionResult(EnumActionResult.PASS, stack);
    }
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 49 with ActionResult

use of net.minecraft.util.ActionResult in project Binnie by ForestryMC.

the class ItemArboristDatabase method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    openGuiOnRightClick(itemStack, world, player);
    return new ActionResult<>(EnumActionResult.PASS, itemStack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 50 with ActionResult

use of net.minecraft.util.ActionResult in project Binnie by ForestryMC.

the class ItemMothDatabase method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    openGuiOnRightClick(itemStack, world, player);
    return new ActionResult<>(EnumActionResult.PASS, itemStack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ActionResult (net.minecraft.util.ActionResult)148 EnumActionResult (net.minecraft.util.EnumActionResult)147 ItemStack (net.minecraft.item.ItemStack)124 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)39 BlockPos (net.minecraft.util.math.BlockPos)31 RayTraceResult (net.minecraft.util.math.RayTraceResult)25 Nonnull (javax.annotation.Nonnull)15 Vec3d (net.minecraft.util.math.Vec3d)14 IBlockState (net.minecraft.block.state.IBlockState)12 TextComponentString (net.minecraft.util.text.TextComponentString)12 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 Entity (net.minecraft.entity.Entity)7 Block (net.minecraft.block.Block)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 TileEntity (net.minecraft.tileentity.TileEntity)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)3 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)3 FluidStack (net.minecraftforge.fluids.FluidStack)3