net.minecraft.util.hit.HitResult Java Examples

The following examples show how to use net.minecraft.util.hit.HitResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThrowHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRightClick(RightClickEvent event)
{
	if(IMC.getItemUseCooldown() > 0)
		return;
	
	if(!MC.options.keyUse.isPressed())
		return;
	
	for(int i = 0; i < amount.getValueI(); i++)
	{
		if(MC.crosshairTarget.getType() == HitResult.Type.BLOCK)
		{
			BlockHitResult hitResult = (BlockHitResult)MC.crosshairTarget;
			IMC.getInteractionManager().rightClickBlock(
				hitResult.getBlockPos(), hitResult.getSide(),
				hitResult.getPos());
		}
		
		IMC.getInteractionManager().rightClickItem();
	}
}
 
Example #2
Source File: ProjectileEntityMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onHit(Lnet/minecraft/util/hit/HitResult;)V", at = @At("RETURN"))
private void remove(HitResult hitResult_1, CallbackInfo ci)
{
    if (LoggerRegistry.__projectiles &&
            (hitResult_1.getType() == HitResult.Type.ENTITY || hitResult_1.getType() == HitResult.Type.BLOCK)
            && logHelper != null)
    {
        logHelper.onFinish();
        logHelper = null;
    }
}
 
Example #3
Source File: AutoBuildHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRightClick(RightClickEvent event)
{
	if(status != Status.IDLE)
		return;
	
	HitResult hitResult = MC.crosshairTarget;
	if(hitResult == null || hitResult.getPos() == null
		|| hitResult.getType() != HitResult.Type.BLOCK
		|| !(hitResult instanceof BlockHitResult))
		return;
	
	BlockHitResult blockHitResult = (BlockHitResult)hitResult;
	BlockPos hitResultPos = blockHitResult.getBlockPos();
	if(!BlockUtils.canBeClicked(hitResultPos))
		return;
	
	BlockPos startPos = hitResultPos.offset(blockHitResult.getSide());
	Direction direction = MC.player.getHorizontalFacing();
	remainingBlocks = template.getPositions(startPos, direction);
	
	if(instaBuild.isChecked() && template.size() <= 64)
		buildInstantly();
	else
		status = Status.BUILDING;
}
 
Example #4
Source File: Tracer.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static HitResult rayTrace(Entity source, float partialTicks, double reach, boolean fluids)
{
    BlockHitResult blockHit = rayTraceBlocks(source, partialTicks, reach, fluids);
    double maxSqDist = reach * reach;
    if (blockHit != null)
    {
        maxSqDist = blockHit.getPos().squaredDistanceTo(source.getCameraPosVec(partialTicks));
    }
    EntityHitResult entityHit = rayTraceEntities(source, partialTicks, reach, maxSqDist);
    return entityHit == null ? blockHit : entityHit;
}
 
Example #5
Source File: AutoEatHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private boolean isClickable(HitResult hitResult)
{
	if(hitResult == null)
		return false;
	
	if(hitResult instanceof EntityHitResult)
	{
		Entity entity = ((EntityHitResult)hitResult).getEntity();
		return entity instanceof VillagerEntity
			|| entity instanceof TameableEntity;
	}
	
	if(hitResult instanceof BlockHitResult)
	{
		BlockPos pos = ((BlockHitResult)hitResult).getBlockPos();
		if(pos == null)
			return false;
		
		Block block = MC.world.getBlockState(pos).getBlock();
		return block instanceof BlockWithEntity
			|| block instanceof CraftingTableBlock;
	}
	
	return false;
}
 
Example #6
Source File: AutoSoupHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private boolean isClickable(HitResult hitResult)
{
	if(hitResult == null)
		return false;
	
	if(hitResult instanceof EntityHitResult)
	{
		Entity entity = ((EntityHitResult)MC.crosshairTarget).getEntity();
		return entity instanceof VillagerEntity
			|| entity instanceof TameableEntity;
	}
	
	if(hitResult instanceof BlockHitResult)
	{
		BlockPos pos = ((BlockHitResult)MC.crosshairTarget).getBlockPos();
		if(pos == null)
			return false;
		
		Block block = MC.world.getBlockState(pos).getBlock();
		return block instanceof BlockWithEntity
			|| block instanceof CraftingTableBlock;
	}
	
	return false;
}
 
Example #7
Source File: AutoSwordHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate()
{
	if(MC.crosshairTarget != null
		&& MC.crosshairTarget.getType() == HitResult.Type.ENTITY)
	{
		Entity entity = ((EntityHitResult)MC.crosshairTarget).getEntity();
		
		if(entity instanceof LivingEntity
			&& ((LivingEntity)entity).getHealth() > 0)
			setSlot();
	}
	
	// update timer
	if(timer > 0)
	{
		timer--;
		return;
	}
	
	resetSlot();
}
 
Example #8
Source File: CriticalsHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onLeftClick(LeftClickEvent event)
{
	if(MC.crosshairTarget == null
		|| MC.crosshairTarget.getType() != HitResult.Type.ENTITY
		|| !(((EntityHitResult)MC.crosshairTarget)
			.getEntity() instanceof LivingEntity))
		return;
	
	doCritical();
}
 
Example #9
Source File: HorseCam.java    From MineLittlePony with MIT License 4 votes vote down vote up
/**
 * Calculates a corresponding camera pitch for the current player at
 * the specified character height.
 *
 * @param toHeight      Target height.
 * @param originalPitch Original, unchanged pitch.
 *
 * @return The new pitch value, otherwise the original value passed in.
 */
public static float rescaleCameraPitch(double toHeight, float originalPitch) {
    /*     -90
     *     |
     *     ---------------0
     *     |
     *     90
     */
    /*  A                A - toHeight
     *  |\               B - fromHeight
     *  |?\              y - headPitch
     *  |  \             ? - result
     *  |   \            C - raytrace
     *  B-   \
     *  |y -  \
     *  |    - \         Tan(?) = horDist / toHeight
     *==|-------C===         ?  = arcTan(horDist / toHeight);
     *   horDist
     *
     *   horDist
     *  |-------C
     *  |      /.
     *  |     /.
     *  |    / .
     *  |   / .
     *  |  /  .
     *  |?/  .
     *  A/  .
     *  |   .
     *  |  .
     *  |  .
     *  | .
     *  B
     *  |
     *  |
     *==o===========
     */

    MinecraftClient client = MinecraftClient.getInstance();
    PlayerEntity player = client.player;
    client.gameRenderer.updateTargetedEntity(1);
    HitResult hit = client.crosshairTarget;

    // noop
    // Ignore misses, helps with bows, arrows, and projectiles
    if (hit == null || hit.getType() != HitResult.Type.BLOCK || player == null) {
        return originalPitch;
    }

    Vec3d hitPos = hit.getPos();
    Vec3d pos = player.getPos();

    double diffX = Math.abs(hitPos.x - pos.x);
    double diffZ = Math.abs(hitPos.z - pos.z);

    double horDist = Math.sqrt(diffX * diffX + diffZ * diffZ);

    double toEyePos = pos.y + toHeight;

    double verDist = Math.abs(hitPos.y - toEyePos);

    double theta = Math.atan(horDist / verDist);

    // convert to degress
    theta /= Math.PI / 180D;

    // convert to vertical pitch (-90 to 90).
    // Preserve up/down direction.
    double newPitch = Math.abs(90 - theta) * Math.signum(originalPitch);

    return (float)newPitch;
}
 
Example #10
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Override
boolean execute(ServerPlayerEntity player, Action action) {
    HitResult hit = getTarget(player);
    switch (hit.getType()) {
        case ENTITY: {
            EntityHitResult entityHit = (EntityHitResult) hit;
            player.attack(entityHit.getEntity());
            player.resetLastAttackedTicks();
            player.updateLastActionTime();
            player.swingHand(Hand.MAIN_HAND);
            return true;
        }
        case BLOCK: {
            EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
            if (ap.blockHitDelay > 0)
            {
                ap.blockHitDelay--;
                return false;
            }
            BlockHitResult blockHit = (BlockHitResult) hit;
            BlockPos pos = blockHit.getBlockPos();
            Direction side = blockHit.getSide();
            // rather should be canNotMine
            if (player.canMine(player.world, pos, player.interactionManager.getGameMode())) return false;
            if (ap.currentBlock != null && player.world.getBlockState(ap.currentBlock).isAir())
            {
                ap.currentBlock = null;
                return false;
            }
            BlockState state = player.world.getBlockState(pos);
            boolean blockBroken = false;
            if (player.interactionManager.getGameMode().isCreative())
            {
                player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight());
                ap.blockHitDelay = 5;
                blockBroken = true;
            }
            else  if (ap.currentBlock == null || !ap.currentBlock.equals(pos))
            {
                if (ap.currentBlock != null)
                {
                    player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.server.getWorldHeight());
                }
                player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight());
                boolean notAir = !state.isAir();
                if (notAir && ap.curBlockDamageMP == 0)
                {
                    state.onBlockBreakStart(player.world, pos, player);
                }
                if (notAir && state.calcBlockBreakingDelta(player, player.world, pos) >= 1)
                {
                    ap.currentBlock = null;
                    //instamine??
                    blockBroken = true;
                }
                else
                {
                    ap.currentBlock = pos;
                    ap.curBlockDamageMP = 0;
                }
            }
            else
            {
                ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.world, pos);
                if (ap.curBlockDamageMP >= 1)
                {
                    player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.server.getWorldHeight());
                    ap.currentBlock = null;
                    ap.blockHitDelay = 5;
                    blockBroken = true;
                }
                player.world.setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));

            }
            player.updateLastActionTime();
            player.swingHand(Hand.MAIN_HAND);
            return blockBroken;
        }
    }
    return false;
}
 
Example #11
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 4 votes vote down vote up
static HitResult getTarget(ServerPlayerEntity player)
{
    double reach = player.interactionManager.isCreative() ? 5 : 4.5f;
    return Tracer.rayTrace(player, 1, reach, false);
}
 
Example #12
Source File: MinecraftClientMixin.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Inject(at = {@At("HEAD")}, method = {"doItemPick()V"})
private void onDoItemPick(CallbackInfo ci)
{
	if(!WurstClient.INSTANCE.isEnabled())
		return;
	
	HitResult hitResult = WurstClient.MC.crosshairTarget;
	if(hitResult == null || hitResult.getType() != HitResult.Type.ENTITY)
		return;
	
	Entity entity = ((EntityHitResult)hitResult).getEntity();
	WurstClient.INSTANCE.getFriends().middleClick(entity);
}
 
Example #13
Source File: NukerHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onLeftClick(LeftClickEvent event)
{
	if(mode.getSelected() != Mode.ID)
		return;
	
	if(MC.crosshairTarget == null
		|| MC.crosshairTarget.getType() != HitResult.Type.BLOCK)
		return;
	
	BlockHitResult blockHitResult = (BlockHitResult)MC.crosshairTarget;
	BlockPos pos = new BlockPos(blockHitResult.getBlockPos());
	id = BlockUtils.getName(pos);
}
 
Example #14
Source File: OverlayHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onRender(float partialTicks)
{
	if(MC.crosshairTarget == null
		|| MC.crosshairTarget.getType() != HitResult.Type.BLOCK)
		return;
	
	BlockHitResult blockHitResult = (BlockHitResult)MC.crosshairTarget;
	BlockPos pos = new BlockPos(blockHitResult.getBlockPos());
	
	// check if hitting block
	if(!MC.interactionManager.isBreakingBlock())
		return;
	
	// GL settings
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glEnable(GL11.GL_LINE_SMOOTH);
	GL11.glLineWidth(2);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glEnable(GL11.GL_CULL_FACE);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glDisable(GL11.GL_LIGHTING);
	
	GL11.glPushMatrix();
	RenderUtils.applyRenderOffset();
	
	// set position
	GL11.glTranslated(pos.getX(), pos.getY(), pos.getZ());
	
	// get progress
	float progress =
		IMC.getInteractionManager().getCurrentBreakingProgress();
	
	// set size
	GL11.glTranslated(0.5, 0.5, 0.5);
	GL11.glScaled(progress, progress, progress);
	GL11.glTranslated(-0.5, -0.5, -0.5);
	
	// get color
	float red = progress * 2F;
	float green = 2 - red;
	
	// draw box
	GL11.glColor4f(red, green, 0, 0.25F);
	RenderUtils.drawSolidBox();
	GL11.glColor4f(red, green, 0, 0.5F);
	RenderUtils.drawOutlinedBox();
	
	GL11.glPopMatrix();
	
	// GL resets
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glDisable(GL11.GL_LINE_SMOOTH);
}
 
Example #15
Source File: AutoMineHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private void setCurrentBlockFromHitResult()
{
	if(MC.crosshairTarget == null || MC.crosshairTarget.getPos() == null
		|| MC.crosshairTarget.getType() != HitResult.Type.BLOCK
		|| !(MC.crosshairTarget instanceof BlockHitResult))
	{
		stopMiningAndResetProgress();
		return;
	}
	
	currentBlock = ((BlockHitResult)MC.crosshairTarget).getBlockPos();
}
 
Example #16
Source File: TunnellerHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private boolean breakBlockSimple(BlockPos pos)
{
	Direction side = null;
	Direction[] sides = Direction.values();
	
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d relCenter = BlockUtils.getBoundingBox(pos)
		.offset(-pos.getX(), -pos.getY(), -pos.getZ()).getCenter();
	Vec3d center = Vec3d.of(pos).add(relCenter);
	
	Vec3d[] hitVecs = new Vec3d[sides.length];
	for(int i = 0; i < sides.length; i++)
	{
		Vec3i dirVec = sides[i].getVector();
		Vec3d relHitVec = new Vec3d(relCenter.x * dirVec.getX(),
			relCenter.y * dirVec.getY(), relCenter.z * dirVec.getZ());
		hitVecs[i] = center.add(relHitVec);
	}
	
	for(int i = 0; i < sides.length; i++)
	{
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVecs[i],
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		side = sides[i];
		break;
	}
	
	if(side == null)
	{
		double distanceSqToCenter = eyesPos.squaredDistanceTo(center);
		for(int i = 0; i < sides.length; i++)
		{
			// check if side is facing towards player
			if(eyesPos.squaredDistanceTo(hitVecs[i]) >= distanceSqToCenter)
				continue;
			
			side = sides[i];
			break;
		}
	}
	
	if(side == null)
		throw new RuntimeException(
			"How could none of the sides be facing towards the player?!");
	
	// face block
	WURST.getRotationFaker().faceVectorPacket(hitVecs[side.ordinal()]);
	
	// damage block
	if(!MC.interactionManager.updateBlockBreakingProgress(pos, side))
		return false;
	
	// swing arm
	MC.player.networkHandler
		.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
	
	return true;
}
 
Example #17
Source File: NukerLegitHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private boolean breakBlockExtraLegit(BlockPos pos)
{
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	for(Direction side : Direction.values())
	{
		Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5));
		double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec);
		
		// check if hitVec is within range (4.25 blocks)
		if(distanceSqHitVec > 18.0625)
			continue;
		
		// check if side is facing towards player
		if(distanceSqHitVec >= distanceSqPosVec)
			continue;
		
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVec,
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		// face block
		WURST.getRotationFaker().faceVectorClient(hitVec);
		
		if(currentBlock != null)
			WURST.getHax().autoToolHack.equipIfEnabled(currentBlock);
			
		// if attack key is down but nothing happens, release it for one
		// tick
		if(MC.options.keyAttack.isPressed()
			&& !MC.interactionManager.isBreakingBlock())
		{
			MC.options.keyAttack.setPressed(false);
			return true;
		}
		
		// damage block
		MC.options.keyAttack.setPressed(true);
		
		return true;
	}
	
	return false;
}
 
Example #18
Source File: BonemealAuraHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private boolean rightClickBlockLegit(BlockPos pos)
{
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	for(Direction side : Direction.values())
	{
		Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5));
		double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec);
		
		// check if hitVec is within range (4.25 blocks)
		if(distanceSqHitVec > 18.0625)
			continue;
		
		// check if side is facing towards player
		if(distanceSqHitVec >= distanceSqPosVec)
			continue;
		
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVec,
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		// face block
		WURST.getRotationFaker().faceVectorPacket(hitVec);
		
		// place block
		IMC.getInteractionManager().rightClickBlock(pos, side, hitVec);
		MC.player.swingHand(Hand.MAIN_HAND);
		IMC.setItemUseCooldown(4);
		
		return true;
	}
	
	return false;
}
 
Example #19
Source File: BuildRandomHack.java    From Wurst7 with GNU General Public License v3.0 3 votes vote down vote up
private boolean placeBlockLegit(BlockPos pos)
{
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	for(Direction side : Direction.values())
	{
		BlockPos neighbor = pos.offset(side);
		
		// check if neighbor can be right clicked
		if(!BlockUtils.canBeClicked(neighbor))
			continue;
		
		Vec3d dirVec = Vec3d.of(side.getVector());
		Vec3d hitVec = posVec.add(dirVec.multiply(0.5));
		
		// check if hitVec is within range (4.25 blocks)
		if(eyesPos.squaredDistanceTo(hitVec) > 18.0625)
			continue;
		
		// check if side is visible (facing away from player)
		if(distanceSqPosVec > eyesPos.squaredDistanceTo(posVec.add(dirVec)))
			continue;
		
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVec,
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		// face block
		Rotation rotation = RotationUtils.getNeededRotations(hitVec);
		PlayerMoveC2SPacket.LookOnly packet =
			new PlayerMoveC2SPacket.LookOnly(rotation.getYaw(),
				rotation.getPitch(), MC.player.isOnGround());
		MC.player.networkHandler.sendPacket(packet);
		
		// place block
		IMC.getInteractionManager().rightClickBlock(neighbor,
			side.getOpposite(), hitVec);
		MC.player.swingHand(Hand.MAIN_HAND);
		IMC.setItemUseCooldown(4);
		
		return true;
	}
	
	return false;
}
 
Example #20
Source File: AutoBuildHack.java    From Wurst7 with GNU General Public License v3.0 3 votes vote down vote up
private boolean tryToPlace(BlockPos pos, Vec3d eyesPos, double rangeSq)
{
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	for(Direction side : Direction.values())
	{
		BlockPos neighbor = pos.offset(side);
		
		// check if neighbor can be right clicked
		if(!BlockUtils.canBeClicked(neighbor)
			|| BlockUtils.getState(neighbor).getMaterial().isReplaceable())
			continue;
		
		Vec3d dirVec = Vec3d.of(side.getVector());
		Vec3d hitVec = posVec.add(dirVec.multiply(0.5));
		
		// check if hitVec is within range
		if(eyesPos.squaredDistanceTo(hitVec) > rangeSq)
			continue;
		
		// check if side is visible (facing away from player)
		if(distanceSqPosVec > eyesPos.squaredDistanceTo(posVec.add(dirVec)))
			continue;
		
		// check line of sight
		if(checkLOS.isChecked() && MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVec,
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		// face block
		Rotation rotation = RotationUtils.getNeededRotations(hitVec);
		PlayerMoveC2SPacket.LookOnly packet =
			new PlayerMoveC2SPacket.LookOnly(rotation.getYaw(),
				rotation.getPitch(), MC.player.isOnGround());
		MC.player.networkHandler.sendPacket(packet);
		
		// place block
		IMC.getInteractionManager().rightClickBlock(neighbor,
			side.getOpposite(), hitVec);
		MC.player.swingHand(Hand.MAIN_HAND);
		IMC.setItemUseCooldown(4);
		return true;
	}
	
	return false;
}
 
Example #21
Source File: IForgeBlockState.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called when a user uses the creative pick block button on this block.
 *
 * @param target The full target the player is looking at
 * @param world  The world the block is in
 * @param pos    The block's position
 * @param player The player picking the block
 * @return An {@link ItemStack} to add to the player's inventory, empty itemstack if nothing should be added.
 */
default ItemStack getPickBlock(HitResult target, BlockView world, BlockPos pos, PlayerEntity player) {
	return patchwork$getForgeBlock().getPickBlock(getBlockState(), target, world, pos, player);
}
 
Example #22
Source File: IForgeBlockState.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Spawn a digging particle effect in the world, this is a wrapper
 * around {@link ParticleManager.addBlockBreakParticles} to allow the block more
 * control over the particles.
 *
 * @param world   The current world
 * @param target  The target the player is looking at {x/y/z/side/sub}
 * @param manager A reference to the current particle manager.
 * @return True to prevent vanilla digging particles form spawning.
 */
@Environment(EnvType.CLIENT)
default boolean addHitEffects(World world, HitResult target, ParticleManager manager) {
	return patchwork$getForgeBlock().addHitEffects(getBlockState(), world, target, manager);
}
 
Example #23
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called when a user uses the creative pick block button on this block.
 *
 * @param state  The current state
 * @param target The full target the player is looking at
 * @param world  The world the block is in
 * @param pos    The block's position
 * @param player The player picking the block
 * @return An {@link ItemStack} to add to the player's inventory, empty itemstack if nothing should be added.
 */
default ItemStack getPickBlock(BlockState state, HitResult target, BlockView world, BlockPos pos, PlayerEntity player) {
	return this.getBlock().getPickStack(world, pos, state);
}
 
Example #24
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Spawn a digging particle effect in the world, this is a wrapper
 * around {@link ParticleManager.addBlockBreakParticles} to allow the block more
 * control over the particles.
 *
 * @param state   The current state
 * @param world   The current world
 * @param target  The target the player is looking at {x/y/z/side/sub}
 * @param manager A reference to the current particle manager.
 * @return True to prevent vanilla digging particles form spawning.
 */
@Environment(EnvType.CLIENT)
default boolean addHitEffects(BlockState state, World worldObj, HitResult target, ParticleManager manager) {
	return false;
}
 
Example #25
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit.
 *
 * @param state    The current state
 * @param world    The current world
 * @param pos      Block position in world
 * @param start    The start vector
 * @param end      The end vector
 * @param original The original result from {@link Block#collisionRayTrace(IBlockState, World, BlockPos, Vec3d, Vec3d)}
 * @return A result that suits your block
 */
@Nullable
default HitResult getRayTraceResult(BlockState state, World world, BlockPos pos, Vec3d start, Vec3d end, HitResult original) {
	return original;
}