Search in sources :

Example 1 with LiquidBlock

use of net.minecraft.world.level.block.LiquidBlock in project Tropicraft by Tropicraft.

the class TropicraftSpawnEgg method use.

public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
    ItemStack heldItem = player.getItemInHand(hand);
    if (world.isClientSide) {
        return InteractionResultHolder.pass(heldItem);
    } else {
        HitResult rayTraceResult = getPlayerPOVHitResult(world, player, ClipContext.Fluid.SOURCE_ONLY);
        if (rayTraceResult.getType() != HitResult.Type.BLOCK) {
            return InteractionResultHolder.pass(heldItem);
        } else {
            BlockHitResult traceResult = (BlockHitResult) rayTraceResult;
            BlockPos tracePos = traceResult.getBlockPos();
            if (!(world.getBlockState(tracePos).getBlock() instanceof LiquidBlock)) {
                return InteractionResultHolder.pass(heldItem);
            } else if (world.mayInteract(player, tracePos) && player.mayUseItemAt(tracePos, traceResult.getDirection(), heldItem)) {
                EntityType<?> type = typeIn.get();
                if (type.spawn((ServerLevel) world, heldItem, player, tracePos, MobSpawnType.SPAWN_EGG, false, false) == null) {
                    return InteractionResultHolder.pass(heldItem);
                } else {
                    if (!player.getAbilities().instabuild) {
                        heldItem.shrink(1);
                    }
                    player.awardStat(Stats.ITEM_USED.get(this));
                    return InteractionResultHolder.success(heldItem);
                }
            } else {
                return InteractionResultHolder.fail(heldItem);
            }
        }
    }
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) EntityType(net.minecraft.world.entity.EntityType) BlockPos(net.minecraft.core.BlockPos) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 2 with LiquidBlock

use of net.minecraft.world.level.block.LiquidBlock in project SpongeCommon by SpongePowered.

the class BlockTickContext method source.

@Override
public BlockTickContext source(final Object owner) {
    super.source(owner);
    if (owner instanceof LocatableBlock) {
        final LocatableBlock locatableBlock = (LocatableBlock) owner;
        final Block block = ((BlockState) locatableBlock.blockState()).getBlock();
        this.tickingBlock = (BlockBridge) block;
        this.providesModifier = !(block instanceof LiquidBlock);
        this.world = locatableBlock.world();
        if (block instanceof TrackableBridge) {
            final TrackableBridge trackable = (TrackableBridge) block;
            this.setBlockEvents(trackable.bridge$allowsBlockEventCreation()).setBulkBlockCaptures(trackable.bridge$allowsBlockBulkCaptures()).setEntitySpawnEvents(trackable.bridge$allowsEntityEventCreation()).setBulkEntityCaptures(trackable.bridge$allowsEntityBulkCaptures());
        }
    }
    return this;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Block(net.minecraft.world.level.block.Block) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) LocatableBlock(org.spongepowered.api.world.LocatableBlock) TrackableBridge(org.spongepowered.common.bridge.TrackableBridge) LiquidBlock(net.minecraft.world.level.block.LiquidBlock)

Example 3 with LiquidBlock

use of net.minecraft.world.level.block.LiquidBlock in project SpongeCommon by SpongePowered.

the class FluidTickContext method source.

@Override
public FluidTickContext source(final Object owner) {
    super.source(owner);
    if (owner instanceof LocatableBlock) {
        final LocatableBlock locatableBlock = (LocatableBlock) owner;
        final Block block = ((BlockState) locatableBlock.blockState()).getBlock();
        this.providesModifier = !(block instanceof LiquidBlock);
        this.world = locatableBlock.world();
        if (block instanceof TrackableBridge) {
            final TrackableBridge trackable = (TrackableBridge) block;
            this.setBlockEvents(trackable.bridge$allowsBlockEventCreation()).setBulkBlockCaptures(trackable.bridge$allowsBlockBulkCaptures()).setEntitySpawnEvents(trackable.bridge$allowsEntityEventCreation()).setBulkEntityCaptures(trackable.bridge$allowsEntityBulkCaptures());
        }
    }
    return this;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Block(net.minecraft.world.level.block.Block) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) LocatableBlock(org.spongepowered.api.world.LocatableBlock) TrackableBridge(org.spongepowered.common.bridge.TrackableBridge) LiquidBlock(net.minecraft.world.level.block.LiquidBlock)

Aggregations

LiquidBlock (net.minecraft.world.level.block.LiquidBlock)3 Block (net.minecraft.world.level.block.Block)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 LocatableBlock (org.spongepowered.api.world.LocatableBlock)2 TrackableBridge (org.spongepowered.common.bridge.TrackableBridge)2 BlockPos (net.minecraft.core.BlockPos)1 EntityType (net.minecraft.world.entity.EntityType)1 ItemStack (net.minecraft.world.item.ItemStack)1 BlockHitResult (net.minecraft.world.phys.BlockHitResult)1 HitResult (net.minecraft.world.phys.HitResult)1