Search in sources :

Example 1 with SoundEvent

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

the class FluidUtil method tryPlaceFluid.

/**
 * Tries to place a fluid resource into the world as a block and drains the fluidSource.
 * Makes a fluid emptying or vaporization 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 BucketItem#emptyContents(Player, Level, BlockPos, BlockHitResult)}
 *
 * @param player      Player who places the fluid. May be null for blocks like dispensers.
 * @param world       Level to place the fluid in
 * @param hand
 * @param pos         The position in the world to place the fluid block
 * @param fluidSource The fluid source holding the fluidStack to place
 * @param resource    The fluidStack to place.
 * @return true if the placement was successful, false otherwise
 */
public static boolean tryPlaceFluid(@Nullable Player player, Level world, InteractionHand hand, BlockPos pos, IFluidHandler fluidSource, FluidStack resource) {
    if (world == null || pos == null) {
        return false;
    }
    Fluid fluid = resource.getFluid();
    if (fluid == Fluids.EMPTY || !fluid.getAttributes().canBePlacedInWorld(world, pos, resource)) {
        return false;
    }
    if (fluidSource.drain(resource, IFluidHandler.FluidAction.SIMULATE).isEmpty()) {
        return false;
    }
    BlockPlaceContext context = new BlockPlaceContext(world, player, hand, player == null ? ItemStack.EMPTY : player.getItemInHand(hand), new BlockHitResult(Vec3.ZERO, Direction.UP, pos, false));
    // check that we can place the fluid at the destination
    BlockState destBlockState = world.getBlockState(pos);
    Material destMaterial = destBlockState.getMaterial();
    boolean isDestNonSolid = !destMaterial.isSolid();
    boolean isDestReplaceable = destBlockState.canBeReplaced(context);
    boolean canDestContainFluid = destBlockState.getBlock() instanceof LiquidBlockContainer && ((LiquidBlockContainer) destBlockState.getBlock()).canPlaceLiquid(world, pos, destBlockState, fluid);
    if (!world.isEmptyBlock(pos) && !isDestNonSolid && !isDestReplaceable && !canDestContainFluid) {
        // Non-air, solid, unreplacable block. We can't put fluid here.
        return false;
    }
    if (world.dimensionType().ultraWarm() && fluid.getAttributes().doesVaporize(world, pos, resource)) {
        FluidStack result = fluidSource.drain(resource, IFluidHandler.FluidAction.EXECUTE);
        if (!result.isEmpty()) {
            result.getFluid().getAttributes().vaporize(player, world, pos, result);
            return true;
        }
    } else {
        // This fluid handler places the fluid block when filled
        IFluidHandler handler;
        if (canDestContainFluid) {
            handler = new BlockWrapper.LiquidContainerBlockWrapper((LiquidBlockContainer) destBlockState.getBlock(), world, pos);
        } else {
            handler = getFluidBlockHandler(fluid, world, pos);
        }
        FluidStack result = tryFluidTransfer(handler, fluidSource, resource, true);
        if (!result.isEmpty()) {
            SoundEvent soundevent = resource.getFluid().getAttributes().getEmptySound(resource);
            world.playSound(player, pos, soundevent, SoundSource.BLOCKS, 1.0F, 1.0F);
            return true;
        }
    }
    return false;
}
Also used : LiquidBlockContainer(net.minecraft.world.level.block.LiquidBlockContainer) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) BlockWrapper(net.minecraftforge.fluids.capability.wrappers.BlockWrapper) SoundEvent(net.minecraft.sounds.SoundEvent) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) Fluid(net.minecraft.world.level.material.Fluid) Material(net.minecraft.world.level.material.Material) BlockHitResult(net.minecraft.world.phys.BlockHitResult) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 2 with SoundEvent

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

the class ForgeMod method missingSoundMapping.

public void missingSoundMapping(RegistryEvent.MissingMappings<SoundEvent> event) {
    // Removed in 1.15, see https://minecraft.gamepedia.com/Parrot#History
    List<String> removedSounds = Arrays.asList("entity.parrot.imitate.panda", "entity.parrot.imitate.zombie_pigman", "entity.parrot.imitate.enderman", "entity.parrot.imitate.polar_bear", "entity.parrot.imitate.wolf");
    for (RegistryEvent.MissingMappings.Mapping<SoundEvent> mapping : event.getAllMappings()) {
        ResourceLocation regName = mapping.key;
        if (regName != null && regName.getNamespace().equals("minecraft")) {
            String path = regName.getPath();
            if (removedSounds.stream().anyMatch(s -> s.equals(path))) {
                LOGGER.info("Ignoring removed minecraft sound {}", regName);
                mapping.ignore();
            }
        }
    }
}
Also used : SoundEvent(net.minecraft.sounds.SoundEvent) ResourceLocation(net.minecraft.resources.ResourceLocation)

Aggregations

SoundEvent (net.minecraft.sounds.SoundEvent)2 ResourceLocation (net.minecraft.resources.ResourceLocation)1 BlockPlaceContext (net.minecraft.world.item.context.BlockPlaceContext)1 LiquidBlockContainer (net.minecraft.world.level.block.LiquidBlockContainer)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 Fluid (net.minecraft.world.level.material.Fluid)1 Material (net.minecraft.world.level.material.Material)1 BlockHitResult (net.minecraft.world.phys.BlockHitResult)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 BlockWrapper (net.minecraftforge.fluids.capability.wrappers.BlockWrapper)1 FluidBlockWrapper (net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper)1