Search in sources :

Example 1 with BlockParticleEffectMessage

use of com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage in project minecolonies by Minecolonies.

the class CitizenItemHandler method hitBlockWithToolInHand.

/**
 * Swing entity arm, create sound and particle effects.
 * <p>
 * If breakBlock is true then it will break the block (different sound and particles), and damage the tool in the citizens hand.
 *
 * @param blockPos   Block position.
 * @param breakBlock if we want to break this block.
 */
@Override
public void hitBlockWithToolInHand(@Nullable final BlockPos blockPos, final boolean breakBlock) {
    if (blockPos == null) {
        return;
    }
    citizen.getLookControl().setLookAt(blockPos.getX(), blockPos.getY(), blockPos.getZ(), FACING_DELTA_YAW, citizen.getMaxHeadXRot());
    citizen.swing(citizen.getUsedItemHand());
    final BlockState blockState = CompatibilityUtils.getWorldFromCitizen(citizen).getBlockState(blockPos);
    final Block block = blockState.getBlock();
    if (breakBlock) {
        if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide) {
            Network.getNetwork().sendToPosition(new BlockParticleEffectMessage(blockPos, CompatibilityUtils.getWorldFromCitizen(citizen).getBlockState(blockPos), BlockParticleEffectMessage.BREAK_BLOCK), new PacketDistributor.TargetPoint(blockPos.getX(), blockPos.getY(), blockPos.getZ(), BLOCK_BREAK_SOUND_RANGE, citizen.level.dimension()));
        }
        CompatibilityUtils.getWorldFromCitizen(citizen).playSound(null, blockPos, block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getBreakSound(), SoundCategory.BLOCKS, block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getVolume(), block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getPitch());
        WorldUtil.removeBlock(CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, false);
        damageItemInHand(citizen.getUsedItemHand(), 1);
    } else {
        if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide) {
            final BlockPos vector = blockPos.subtract(citizen.blockPosition());
            final Direction facing = Direction.getNearest(vector.getX(), vector.getY(), vector.getZ()).getOpposite();
            Network.getNetwork().sendToPosition(new BlockParticleEffectMessage(blockPos, CompatibilityUtils.getWorldFromCitizen(citizen).getBlockState(blockPos), facing.ordinal()), new PacketDistributor.TargetPoint(blockPos.getX(), blockPos.getY(), blockPos.getZ(), BLOCK_BREAK_PARTICLE_RANGE, citizen.level.dimension()));
        }
        CompatibilityUtils.getWorldFromCitizen(citizen).playSound(null, blockPos, block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getBreakSound(), SoundCategory.BLOCKS, block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getVolume(), block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getPitch());
    }
}
Also used : BlockState(net.minecraft.block.BlockState) PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) BlockParticleEffectMessage(com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Example 2 with BlockParticleEffectMessage

use of com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage in project minecolonies by Minecolonies.

the class EntityAIWorkAlchemist method harvestMistleToe.

/**
 * Go to a random position with leaves and hit the leaves until getting a mistletoe.
 * @return next state to go to.
 */
private IAIState harvestMistleToe() {
    if (checkForToolOrWeapon(ToolType.SHEARS)) {
        return IDLE;
    }
    if (walkTo == null) {
        final List<BlockPos> leaveList = building.getAllLeavePositions();
        if (leaveList.isEmpty()) {
            return IDLE;
        }
        final BlockPos randomLeaf = leaveList.get(worker.getRandom().nextInt(leaveList.size()));
        if (WorldUtil.isBlockLoaded(world, randomLeaf)) {
            if (world.getBlockState(randomLeaf).getBlock() instanceof LeavesBlock) {
                walkTo = randomLeaf;
            } else {
                building.removeLeafPosition(randomLeaf);
            }
        }
        return HARVEST_MISTLETOE;
    }
    if (WorldUtil.isBlockLoaded(world, walkTo) && world.getBlockState(walkTo).getBlock() instanceof LeavesBlock) {
        if (walkToBlock(walkTo)) {
            return HARVEST_MISTLETOE;
        }
        final BlockState state = world.getBlockState(walkTo);
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), stack -> stack.getItem() instanceof ShearsItem);
        worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, slot);
        worker.swing(Hand.MAIN_HAND);
        world.playSound(null, walkTo, state.getSoundType(world, walkTo, worker).getBreakSound(), SoundCategory.BLOCKS, state.getSoundType(world, walkTo, worker).getVolume(), state.getSoundType(world, walkTo, worker).getPitch());
        Network.getNetwork().sendToTrackingEntity(new BlockParticleEffectMessage(walkTo, state, worker.getRandom().nextInt(7) - 1), worker);
        if (worker.getRandom().nextInt(120) < 1) {
            worker.decreaseSaturationForContinuousAction();
            InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(ModItems.mistletoe, 1));
            walkTo = null;
            worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
            return INVENTORY_FULL;
        }
    } else {
        walkTo = null;
        return IDLE;
    }
    return HARVEST_MISTLETOE;
}
Also used : BlockParticleEffectMessage(com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage) BlockPos(net.minecraft.util.math.BlockPos) ShearsItem(net.minecraft.item.ShearsItem) ItemStack(net.minecraft.item.ItemStack)

Example 3 with BlockParticleEffectMessage

use of com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage in project minecolonies by ldtteam.

the class CitizenItemHandler method hitBlockWithToolInHand.

/**
 * Swing entity arm, create sound and particle effects.
 * <p>
 * If breakBlock is true then it will break the block (different sound and particles), and damage the tool in the citizens hand.
 *
 * @param blockPos   Block position.
 * @param breakBlock if we want to break this block.
 */
@Override
public void hitBlockWithToolInHand(@Nullable final BlockPos blockPos, final boolean breakBlock) {
    if (blockPos == null) {
        return;
    }
    citizen.getLookControl().setLookAt(blockPos.getX(), blockPos.getY(), blockPos.getZ(), FACING_DELTA_YAW, citizen.getMaxHeadXRot());
    citizen.swing(citizen.getUsedItemHand());
    final BlockState blockState = CompatibilityUtils.getWorldFromCitizen(citizen).getBlockState(blockPos);
    final Block block = blockState.getBlock();
    if (breakBlock) {
        if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide) {
            Network.getNetwork().sendToPosition(new BlockParticleEffectMessage(blockPos, CompatibilityUtils.getWorldFromCitizen(citizen).getBlockState(blockPos), BlockParticleEffectMessage.BREAK_BLOCK), new PacketDistributor.TargetPoint(blockPos.getX(), blockPos.getY(), blockPos.getZ(), BLOCK_BREAK_SOUND_RANGE, citizen.level.dimension()));
        }
        CompatibilityUtils.getWorldFromCitizen(citizen).playSound(null, blockPos, block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getBreakSound(), SoundCategory.BLOCKS, block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getVolume(), block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getPitch());
        WorldUtil.removeBlock(CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, false);
        damageItemInHand(citizen.getUsedItemHand(), 1);
    } else {
        if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide) {
            final BlockPos vector = blockPos.subtract(citizen.blockPosition());
            final Direction facing = Direction.getNearest(vector.getX(), vector.getY(), vector.getZ()).getOpposite();
            Network.getNetwork().sendToPosition(new BlockParticleEffectMessage(blockPos, CompatibilityUtils.getWorldFromCitizen(citizen).getBlockState(blockPos), facing.ordinal()), new PacketDistributor.TargetPoint(blockPos.getX(), blockPos.getY(), blockPos.getZ(), BLOCK_BREAK_PARTICLE_RANGE, citizen.level.dimension()));
        }
        CompatibilityUtils.getWorldFromCitizen(citizen).playSound(null, blockPos, block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getBreakSound(), SoundCategory.BLOCKS, block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getVolume(), block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getPitch());
    }
}
Also used : BlockState(net.minecraft.block.BlockState) PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) BlockParticleEffectMessage(com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Aggregations

BlockParticleEffectMessage (com.minecolonies.coremod.network.messages.client.BlockParticleEffectMessage)3 BlockPos (net.minecraft.util.math.BlockPos)3 Block (net.minecraft.block.Block)2 BlockState (net.minecraft.block.BlockState)2 Direction (net.minecraft.util.Direction)2 PacketDistributor (net.minecraftforge.fml.network.PacketDistributor)2 ItemStack (net.minecraft.item.ItemStack)1 ShearsItem (net.minecraft.item.ShearsItem)1