Search in sources :

Example 1 with SoundEvent

use of net.minecraft.util.SoundEvent in project MinecraftForge by MinecraftForge.

the class FluidUtil method tryPlaceFluid.

/**
     * Tries to place a fluid in the world in block form and drains the container.
     * Makes a fluid emptying sound when successful.
     * Honors the amount of fluid contained by the used container.
     * Checks if water-like fluids should vaporize like in the nether.
     *
     * Modeled after {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
     *
     * @param player    Player who places the fluid. May be null for blocks like dispensers.
     * @param world     World to place the fluid in
     * @param pos       The position in the world to place the fluid block
     * @param container The fluid container holding the fluidStack to place
     * @param resource  The fluidStack to place
     * @return the container's ItemStack with the remaining amount of fluid if the placement was successful, null otherwise
     */
@Nonnull
public static FluidActionResult tryPlaceFluid(@Nullable EntityPlayer player, World world, BlockPos pos, @Nonnull ItemStack container, FluidStack resource) {
    if (world == null || resource == null || pos == null) {
        return FluidActionResult.FAILURE;
    }
    Fluid fluid = resource.getFluid();
    if (fluid == null || !fluid.canBePlacedInWorld()) {
        return FluidActionResult.FAILURE;
    }
    // check that we can place the fluid at the destination
    IBlockState destBlockState = world.getBlockState(pos);
    Material destMaterial = destBlockState.getMaterial();
    boolean isDestNonSolid = !destMaterial.isSolid();
    boolean isDestReplaceable = destBlockState.getBlock().isReplaceable(world, pos);
    if (!world.isAirBlock(pos) && !isDestNonSolid && !isDestReplaceable) {
        // Non-air, solid, unreplacable block. We can't put fluid here.
        return FluidActionResult.FAILURE;
    }
    if (world.provider.doesWaterVaporize() && fluid.doesVaporize(resource)) {
        fluid.vaporize(player, world, pos, resource);
        return tryEmptyContainer(container, new VoidFluidHandler(), Integer.MAX_VALUE, player, true);
    } else {
        if (!world.isRemote && (isDestNonSolid || isDestReplaceable) && !destMaterial.isLiquid()) {
            world.destroyBlock(pos, true);
        }
        // Defer the placement to the fluid block
        // Instead of actually "filling", the fluid handler method replaces the block
        Block block = fluid.getBlock();
        IFluidHandler handler;
        if (block instanceof IFluidBlock) {
            handler = new FluidBlockWrapper((IFluidBlock) block, world, pos);
        } else if (block instanceof BlockLiquid) {
            handler = new BlockLiquidWrapper((BlockLiquid) block, world, pos);
        } else {
            handler = new BlockWrapper(block, world, pos);
        }
        FluidActionResult result = tryEmptyContainer(container, handler, Integer.MAX_VALUE, player, true);
        if (result.isSuccess()) {
            SoundEvent soundevent = fluid.getEmptySound(resource);
            world.playSound(player, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
        }
        return result;
    }
}
Also used : VoidFluidHandler(net.minecraftforge.fluids.capability.templates.VoidFluidHandler) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) BlockWrapper(net.minecraftforge.fluids.capability.wrappers.BlockWrapper) IBlockState(net.minecraft.block.state.IBlockState) Material(net.minecraft.block.material.Material) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) SoundEvent(net.minecraft.util.SoundEvent) BlockLiquid(net.minecraft.block.BlockLiquid) BlockLiquidWrapper(net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper) Block(net.minecraft.block.Block) Nonnull(javax.annotation.Nonnull)

Example 2 with SoundEvent

use of net.minecraft.util.SoundEvent in project MinecraftForge by MinecraftForge.

the class FluidUtil method tryFillContainer.

/**
     * Fill a container from the given fluidSource.
     *
     * @param container   The container to be filled. Will not be modified.
     *                    Separate handling must be done to reduce the stack size, stow containers, etc, on success.
     *                    See {@link  #tryFillContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, EntityPlayer)}.
     * @param fluidSource The fluid handler to be drained.
     * @param maxAmount   The largest amount of fluid that should be transferred.
     * @param player      The player to make the filling noise. Pass null for no noise.
     * @param doFill      true if the container should actually be filled, false if it should be simulated.
     * @return a {@link FluidActionResult} holding the filled container if successful.
     */
@Nonnull
public static FluidActionResult tryFillContainer(@Nonnull ItemStack container, IFluidHandler fluidSource, int maxAmount, @Nullable EntityPlayer player, boolean doFill) {
    // do not modify the input
    ItemStack containerCopy = container.copy();
    containerCopy.setCount(1);
    IFluidHandlerItem containerFluidHandler = getFluidHandler(containerCopy);
    if (containerFluidHandler != null) {
        FluidStack simulatedTransfer = tryFluidTransfer(containerFluidHandler, fluidSource, maxAmount, false);
        if (simulatedTransfer != null) {
            if (doFill) {
                tryFluidTransfer(containerFluidHandler, fluidSource, maxAmount, true);
                if (player != null) {
                    SoundEvent soundevent = simulatedTransfer.getFluid().getFillSound(simulatedTransfer);
                    player.playSound(soundevent, 1f, 1f);
                }
            } else {
                containerFluidHandler.fill(simulatedTransfer, true);
            }
            ItemStack resultContainer = containerFluidHandler.getContainer();
            return new FluidActionResult(resultContainer);
        }
    }
    return FluidActionResult.FAILURE;
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 3 with SoundEvent

use of net.minecraft.util.SoundEvent in project MinecraftForge by MinecraftForge.

the class FluidUtil method tryEmptyContainer.

/**
     * Takes a filled container and tries to empty it into the given tank.
     *
     * @param container        The filled container. Will not be modified.
     *                         Separate handling must be done to reduce the stack size, stow containers, etc, on success.
     *                         See {@link #tryEmptyContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, EntityPlayer)}.
     * @param fluidDestination The fluid handler to be filled by the container.
     * @param maxAmount        The largest amount of fluid that should be transferred.
     * @param player           Player for making the bucket drained sound. Pass null for no noise.
     * @param doDrain          true if the container should actually be drained, false if it should be simulated.
     * @return a {@link FluidActionResult} holding the empty container if the fluid handler was filled.
     *         NOTE If the container is consumable, the empty container will be null on success.
     */
@Nonnull
public static FluidActionResult tryEmptyContainer(@Nonnull ItemStack container, IFluidHandler fluidDestination, int maxAmount, @Nullable EntityPlayer player, boolean doDrain) {
    // do not modify the input
    ItemStack containerCopy = container.copy();
    containerCopy.setCount(1);
    IFluidHandlerItem containerFluidHandler = getFluidHandler(containerCopy);
    if (containerFluidHandler != null) {
        FluidStack simulatedTransfer = tryFluidTransfer(fluidDestination, containerFluidHandler, maxAmount, false);
        if (simulatedTransfer != null) {
            if (doDrain) {
                tryFluidTransfer(fluidDestination, containerFluidHandler, maxAmount, true);
                if (player != null) {
                    SoundEvent soundevent = simulatedTransfer.getFluid().getEmptySound(simulatedTransfer);
                    player.playSound(soundevent, 1f, 1f);
                }
            } else {
                containerFluidHandler.drain(simulatedTransfer, true);
            }
            ItemStack resultContainer = containerFluidHandler.getContainer();
            return new FluidActionResult(resultContainer);
        }
    }
    return FluidActionResult.FAILURE;
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 4 with SoundEvent

use of net.minecraft.util.SoundEvent in project ImmersiveEngineering by BluSunrize.

the class IESounds method registerSound.

private static SoundEvent registerSound(String name) {
    ResourceLocation location = new ResourceLocation(ImmersiveEngineering.MODID, name);
    SoundEvent event = new SoundEvent(location);
    registeredEvents.add(event.setRegistryName(location));
    return event;
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 5 with SoundEvent

use of net.minecraft.util.SoundEvent in project minecolonies by Minecolonies.

the class EntityAIOpenFenceGate method toggleDoor.

/**
     * Toggles the door(Opens or closes).
     *
     * @param open if open or close.
     */
private void toggleDoor(final boolean open) {
    final IBlockState iblockstate = this.theEntity.world.getBlockState(this.gatePosition);
    //If the block is a gate block and the fence gate state does not respond to the input open toggle it.
    if (iblockstate.getBlock() == this.gateBlock && (iblockstate.getValue(BlockFenceGate.OPEN)) != open) {
        this.theEntity.world.setBlockState(this.gatePosition, iblockstate.withProperty(BlockFenceGate.OPEN, open), 2);
        final SoundEvent openCloseSound = open ? SoundEvents.BLOCK_FENCE_GATE_OPEN : SoundEvents.BLOCK_FENCE_GATE_CLOSE;
        SoundUtils.playSoundAtCitizen(this.theEntity.world, this.gatePosition, openCloseSound);
    }
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) IBlockState(net.minecraft.block.state.IBlockState)

Aggregations

SoundEvent (net.minecraft.util.SoundEvent)17 ResourceLocation (net.minecraft.util.ResourceLocation)7 Nonnull (javax.annotation.Nonnull)3 ItemStack (net.minecraft.item.ItemStack)3 SoundType (net.minecraft.block.SoundType)2 IBlockState (net.minecraft.block.state.IBlockState)2 IFluidHandlerItem (net.minecraftforge.fluids.capability.IFluidHandlerItem)2 Block (net.minecraft.block.Block)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 Material (net.minecraft.block.material.Material)1 ISound (net.minecraft.client.audio.ISound)1 PositionedSound (net.minecraft.client.audio.PositionedSound)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 PlaySoundEvent (net.minecraftforge.client.event.sound.PlaySoundEvent)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 VoidFluidHandler (net.minecraftforge.fluids.capability.templates.VoidFluidHandler)1 BlockLiquidWrapper (net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper)1 BlockWrapper (net.minecraftforge.fluids.capability.wrappers.BlockWrapper)1 FluidBlockWrapper (net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper)1