Java Code Examples for net.minecraft.util.math.Direction#values()

The following examples show how to use net.minecraft.util.math.Direction#values() . 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: WireBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
@Deprecated
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
    super.onStateReplaced(state, world, pos, newState, moved);
    if (!world.isClient()) {
        WireNetwork myNet = ((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos);
        ((ServerWorldAccessor) world).getNetworkManager().removeWire(pos);
        myNet.removeWire(pos);
        WireNetwork network = ((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos);
        if (network == null) return;
        for (Direction d : Direction.values()) {
            if (world.getBlockState(pos.offset(d)).getBlock() instanceof WireConnectable) {
                WireConnectionType type = ((WireConnectable) world.getBlockState(pos.offset(d)).getBlock()).canWireConnect(world, d.getOpposite(), pos, pos.offset(d));
                if (type != WireConnectionType.WIRE && type != WireConnectionType.NONE) {
                    if (type == WireConnectionType.ENERGY_INPUT) {
                        network.removeConsumer(pos.offset(d));
                    } else {
                        network.removeProducer(pos.offset(d));
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: Scaffold.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public boolean placeBlockAuto(BlockPos block) {
	if (lastPlaced.containsKey(block) || !WorldUtils.NONSOLID_BLOCKS.contains(mc.world.getBlockState(block).getBlock())) {
		return false;
	}
	
	for (Direction d: Direction.values()) {
		if (!WorldUtils.NONSOLID_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
			if (WorldUtils.RIGHTCLICKABLE_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
				mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.PRESS_SHIFT_KEY));
			
			}
			mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, 
					new BlockHitResult(Vec3d.of(block), d.getOpposite(), block.offset(d), false));
			mc.player.swingHand(Hand.MAIN_HAND);
			if (WorldUtils.RIGHTCLICKABLE_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
				mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.RELEASE_SHIFT_KEY));
			}
			lastPlaced.put(block, 5);
			return true;
		}
	}
	
	return false;
}
 
Example 3
Source File: Scaffold.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public boolean placeBlockAuto(BlockPos block) {
	if (lastPlaced.containsKey(block) || !WorldUtils.NONSOLID_BLOCKS.contains(mc.world.getBlockState(block).getBlock())) {
		return false;
	}
	
	for (Direction d: Direction.values()) {
		if (!WorldUtils.NONSOLID_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
			if (WorldUtils.RIGHTCLICKABLE_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
				mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.START_SNEAKING));
			
			}
			mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, 
					new BlockHitResult(new Vec3d(block), d.getOpposite(), block.offset(d), false));
			mc.player.swingHand(Hand.MAIN_HAND);
			if (WorldUtils.RIGHTCLICKABLE_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
				mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.STOP_SNEAKING));
			}
			lastPlaced.put(block, 5);
			return true;
		}
	}
	
	return false;
}
 
Example 4
Source File: WireNetwork.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public void addWire(BlockPos pos) {
    addVertex(pos);
    ((ServerWorldAccessor) world).getNetworkManager().addWire(pos, this);
    for (Direction dir : Direction.values()) {
        if (adjacentVertices.containsKey(new BlockPos(pos.offset(dir)))) {
            addEdge(pos, new BlockPos(pos.offset(dir)));
        }
    }
}
 
Example 5
Source File: FluidPipeBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
    BlockState state = this.getDefaultState();
    for (Direction direction : Direction.values()) {
        Block block = context.getWorld().getBlockState(context.getBlockPos().offset(direction)).getBlock();
        if (block instanceof FluidPipeBlock)
            state = state.with(propFromDirection(direction), true);
    }
    return state;
}
 
Example 6
Source File: AluminumWireBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean moved) {
    super.onBlockAdded(state, world, pos, oldState, moved);
    if (!world.isClient) {
        WireNetwork network = ((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos);
        if (network == null) network = new WireNetwork(pos, ((ServerWorld) world));
        for (Direction d : Direction.values()) {
            if (state.get(getPropForDirection(d)) && world.getBlockState(pos.offset(d)).getBlock() instanceof WireConnectable) {
                WireConnectionType type = ((WireConnectable) world.getBlockState(pos.offset(d)).getBlock()).canWireConnect(world, d.getOpposite(), pos, pos.offset(d));
                if (type == WireConnectionType.WIRE) {
                    WireNetwork network1 = ((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos.offset(d));
                    if (network1 != network) {
                        if (network1 != null) {
                            network = network1.merge(network); // prefer other network rather than this one
                        } else {
                            network.addWire(pos.offset(d));
                        }
                        //this.updateNeighborStates(state, world, pos, 3);
                    }
                } else if (type != WireConnectionType.NONE) {
                    if (type == WireConnectionType.ENERGY_INPUT) {
                        network.addConsumer(pos.offset(d));
                    } else {
                        network.addProducer(pos.offset(d));
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: ObsidianBlock.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void scheduledTick(BlockState blockState_1, ServerWorld serverWorld_1, BlockPos blockPos_1, Random random_1)
{
    for (Direction dir : Direction.values())
    {
        FluidState neighbor = serverWorld_1.getFluidState(blockPos_1.offset(dir));
        if (neighbor.getFluid() != Fluids.LAVA || !neighbor.isStill())
            return;
    }
    if (random_1.nextInt(10) == 0)
    {
        serverWorld_1.setBlockState(blockPos_1, Blocks.LAVA.getDefaultState());
    }
}
 
Example 8
Source File: ConfigurableElectricMachineBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private static List<ModelElement> generateCube() {
    Map<Direction, ModelElementFace> faces = new HashMap<>();
    for (Direction direction : Direction.values()) {
        faces.put(direction, new ModelElementFace(null, -1, direction.getName(), new ModelElementTexture(null, 0)));
    }
    return Collections.singletonList(new ModelElement(new Vector3f(0, 0, 0), new Vector3f(16, 16, 16), faces, null, true));
}
 
Example 9
Source File: ConfigurableElectricMachineBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public void render(MatrixStack.Entry entry, VertexConsumer vertexConsumer, @Nullable BlockState blockState, BakedModel bakedModel, float red, float green, float blue, int[] light, int overlay) {
    Random random = new Random();
    Direction[] var13 = Direction.values();

    for (Direction direction : var13) {
        random.setSeed(42L);
        renderQuad(entry, vertexConsumer, red, green, blue, bakedModel.getQuads(blockState, direction, random), light[getId(direction)], overlay);
    }

    random.setSeed(42L);
    renderQuad(entry, vertexConsumer, red, green, blue, bakedModel.getQuads(blockState, null, random), light[getId(Direction.UP)], overlay);
}
 
Example 10
Source File: WireBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Deprecated
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean moved) {
    super.onBlockAdded(state, world, pos, oldState, moved);
    if (!world.isClient) {
        WireNetwork network = ((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos);
        if (network == null) network = new WireNetwork(pos, ((ServerWorld) world));
        for (Direction d : Direction.values()) {
            if (world.getBlockState(pos.offset(d)).getBlock() instanceof WireConnectable) {
                WireConnectionType type = ((WireConnectable) world.getBlockState(pos.offset(d)).getBlock()).canWireConnect(world, d.getOpposite(), pos, pos.offset(d));
                if (type == WireConnectionType.WIRE) {
                    WireNetwork network1 = ((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos.offset(d));
                    if (network1 != network) {
                        if (network1 != null) {
                            network = network1.merge(network); // prefer other network rather than this one
                        } else {
                            network.addWire(pos.offset(d));
                        }
                        state.method_30101(world, pos, 3);
                    }
                } else if (type != WireConnectionType.NONE) {
                    if (type == WireConnectionType.ENERGY_INPUT) {
                        network.addConsumer(pos.offset(d));
                    } else {
                        network.addProducer(pos.offset(d));
                    }
                }
            }
        }
    }
}
 
Example 11
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 12
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 13
Source File: TunnellerHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private void placeBlockSimple(BlockPos pos)
{
	Direction side = null;
	Direction[] sides = Direction.values();
	
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	Vec3d[] hitVecs = new Vec3d[sides.length];
	for(int i = 0; i < sides.length; i++)
		hitVecs[i] =
			posVec.add(Vec3d.of(sides[i].getVector()).multiply(0.5));
	
	for(int i = 0; i < sides.length; i++)
	{
		// check if neighbor can be right clicked
		BlockPos neighbor = pos.offset(sides[i]);
		if(!BlockUtils.canBeClicked(neighbor))
			continue;
		
		// check line of sight
		BlockState neighborState = BlockUtils.getState(neighbor);
		VoxelShape neighborShape =
			neighborState.getOutlineShape(MC.world, neighbor);
		if(MC.world.rayTraceBlock(eyesPos, hitVecs[i], neighbor,
			neighborShape, neighborState) != null)
			continue;
		
		side = sides[i];
		break;
	}
	
	if(side == null)
		for(int i = 0; i < sides.length; i++)
		{
			// check if neighbor can be right clicked
			if(!BlockUtils.canBeClicked(pos.offset(sides[i])))
				continue;
			
			// check if side is facing away from player
			if(distanceSqPosVec > eyesPos.squaredDistanceTo(hitVecs[i]))
				continue;
			
			side = sides[i];
			break;
		}
	
	if(side == null)
		return;
	
	Vec3d hitVec = hitVecs[side.ordinal()];
	
	// face block
	WURST.getRotationFaker().faceVectorPacket(hitVec);
	if(RotationUtils.getAngleToLastReportedLookVec(hitVec) > 1)
		return;
	
	// check timer
	if(IMC.getItemUseCooldown() > 0)
		return;
	
	// place block
	IMC.getInteractionManager().rightClickBlock(pos.offset(side),
		side.getOpposite(), hitVec);
	
	// swing arm
	MC.player.networkHandler
		.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
	
	// reset timer
	IMC.setItemUseCooldown(4);
}
 
Example 14
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 15
Source File: InstantBunkerHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private void placeBlockSimple(BlockPos pos)
{
	Direction side = null;
	Direction[] sides = Direction.values();
	
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	Vec3d[] hitVecs = new Vec3d[sides.length];
	for(int i = 0; i < sides.length; i++)
		hitVecs[i] =
			posVec.add(Vec3d.of(sides[i].getVector()).multiply(0.5));
	
	for(int i = 0; i < sides.length; i++)
	{
		// check if neighbor can be right clicked
		BlockPos neighbor = pos.offset(sides[i]);
		if(!BlockUtils.canBeClicked(neighbor))
			continue;
		
		// check line of sight
		BlockState neighborState = BlockUtils.getState(neighbor);
		VoxelShape neighborShape =
			neighborState.getOutlineShape(MC.world, neighbor);
		if(MC.world.rayTraceBlock(eyesPos, hitVecs[i], neighbor,
			neighborShape, neighborState) != null)
			continue;
		
		side = sides[i];
		break;
	}
	
	if(side == null)
		for(int i = 0; i < sides.length; i++)
		{
			// check if neighbor can be right clicked
			if(!BlockUtils.canBeClicked(pos.offset(sides[i])))
				continue;
			
			// check if side is facing away from player
			if(distanceSqPosVec > eyesPos.squaredDistanceTo(hitVecs[i]))
				continue;
			
			side = sides[i];
			break;
		}
	
	if(side == null)
		return;
	
	Vec3d hitVec = hitVecs[side.ordinal()];
	
	// face block
	// WURST.getRotationFaker().faceVectorPacket(hitVec);
	// if(RotationUtils.getAngleToLastReportedLookVec(hitVec) > 1)
	// return;
	
	// check timer
	// if(IMC.getItemUseCooldown() > 0)
	// return;
	
	// place block
	IMC.getInteractionManager().rightClickBlock(pos.offset(side),
		side.getOpposite(), hitVec);
	
	// swing arm
	MC.player.networkHandler
		.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
	
	// reset timer
	IMC.setItemUseCooldown(4);
}
 
Example 16
Source File: ChunkUpgrader.java    From multiconnect with MIT License 4 votes vote down vote up
public static void fix(WorldAccess world, BlockPos pos, int flags) {
    doFix(world, pos, flags);
    for (Direction dir : Direction.values())
        doFix(world, pos.offset(dir), flags);
}
 
Example 17
Source File: ConfigurableElectricMachineBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public BakedModel getModelForState(T entity, BlockState state) {
    StringBuilder builder = new StringBuilder();
    for (ConfigurableElectricMachineBlock.BlockFace face : ConfigurableElectricMachineBlock.BlockFace.values()) {
        builder.append(((ConfigurableElectricMachineBlock) state.getBlock()).getOption(state, face).asString());
    }
    if (!MODEL_CACHE.containsKey(builder.toString())) {
        Map<String, Either<SpriteIdentifier, String>> texMap = new HashMap<>();
        texMap.put("particle", Either.left(EMPTY));
        for (Direction direction : Direction.values()) {
            switch (((ConfigurableElectricMachineBlock) state.getBlock()).getOption(state, ConfigurableElectricMachineBlock.BlockFace.toFace(Direction.NORTH, direction))) { //north so that the model doesn't rotate
                case DEFAULT:
                    texMap.put(direction.getName(), Either.left(getDefaultSpriteId(entity, direction)));
                    break;
                case POWER_INPUT:
                    texMap.put(direction.getName(), Either.left(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_power_input"))));
                    break;
                case POWER_OUTPUT:
                    texMap.put(direction.getName(), Either.left(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_power_output"))));
                    break;
                case OXYGEN_INPUT:
                    texMap.put(direction.getName(), Either.left(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_oxygen_input"))));
                    break;
                case OXYGEN_OUTPUT:
                    texMap.put(direction.getName(), Either.left(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_oxygen_output"))));
                    break;
                case FLUID_INPUT:
                    texMap.put(direction.getName(), Either.left(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_fluid_input"))));
                    break;
                case FLUID_OUTPUT:
                    texMap.put(direction.getName(), Either.left(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_fluid_output"))));
                    break;
            }
        }

        BakedModel model = this.bakeModel(new JsonUnbakedModel(null, element, texMap, true,
                        JsonUnbakedModel.GuiLight.field_21859, ModelTransformation.NONE, new ArrayList<>()),
                spriteIdentifier -> MinecraftClient.getInstance().getSpriteAtlas(spriteIdentifier.getAtlasId()).apply(spriteIdentifier.getTextureId()),
                ModelRotation.X0_Y0, new Identifier(Constants.MOD_ID, builder.toString()), true);
        MODEL_CACHE.put(builder.toString(), model);

        return model;
    } else {
        return MODEL_CACHE.get(builder.toString());
    }
}
 
Example 18
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 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: ScaffoldWalkHack.java    From Wurst7 with GNU General Public License v3.0 1 votes vote down vote up
private boolean placeBlock(BlockPos pos)
{
	Vec3d eyesPos = new Vec3d(MC.player.getX(),
		MC.player.getY() + MC.player.getEyeHeight(MC.player.getPose()),
		MC.player.getZ());
	
	for(Direction side : Direction.values())
	{
		BlockPos neighbor = pos.offset(side);
		Direction side2 = side.getOpposite();
		
		// check if side is visible (facing away from player)
		if(eyesPos.squaredDistanceTo(Vec3d.ofCenter(pos)) >= eyesPos
			.squaredDistanceTo(Vec3d.ofCenter(neighbor)))
			continue;
		
		// check if neighbor can be right clicked
		if(!BlockUtils.canBeClicked(neighbor))
			continue;
		
		Vec3d hitVec = Vec3d.ofCenter(neighbor)
			.add(Vec3d.of(side2.getVector()).multiply(0.5));
		
		// check if hitVec is within range (4.25 blocks)
		if(eyesPos.squaredDistanceTo(hitVec) > 18.0625)
			continue;
		
		// place block
		Rotation rotation = RotationUtils.getNeededRotations(hitVec);
		PlayerMoveC2SPacket.LookOnly packet =
			new PlayerMoveC2SPacket.LookOnly(rotation.getYaw(),
				rotation.getPitch(), MC.player.isOnGround());
		MC.player.networkHandler.sendPacket(packet);
		IMC.getInteractionManager().rightClickBlock(neighbor, side2,
			hitVec);
		MC.player.swingHand(Hand.MAIN_HAND);
		IMC.setItemUseCooldown(4);
		
		return true;
	}
	
	return false;
}