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());
}
}
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;
}
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());
}
}
Aggregations