类net.minecraft.util.hit.BlockHitResult源码实例Demo

下面列出了怎么用net.minecraft.util.hit.BlockHitResult的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) {
    if(!CarpetExtraSettings.dispensersToggleThings) {
        return super.dispenseSilently(source, stack);
    }

    World world = source.getWorld();
    Direction direction = (Direction) source.getBlockState().get(DispenserBlock.FACING);
    BlockPos pos = source.getBlockPos().offset(direction);
    BlockState state = world.getBlockState(pos);  
    if(toggleable.contains(state.getBlock())) {
        ActionResult result = state.onUse(
            world, 
            null,
            Hand.MAIN_HAND,
            new BlockHitResult(
                new Vec3d(new Vec3i(pos.getX(), pos.getY(), pos.getZ())), 
                direction, 
                pos,
                false
            )
        );
        if(result.isAccepted()) return stack; // success or consume
    }
    return super.dispenseSilently(source, stack);
}
 
源代码2 项目: the-hallow   文件: HallowedLogBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
	ItemStack stack = player.getStackInHand(hand);
	if (stack.isEmpty() || !(stack.getItem() instanceof MiningToolItem)) {
		return ActionResult.PASS;
	}
	
	MiningToolItem tool = (MiningToolItem) stack.getItem();
	if (stripped != null && (tool.isEffectiveOn(state) || tool.getMiningSpeed(stack, state) > 1.0F)) {
		world.playSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
		if (!world.isClient) {
			BlockState target = stripped.getDefaultState().with(LogBlock.AXIS, state.get(LogBlock.AXIS));
			world.setBlockState(pos, target);
			stack.damage(1, player, consumedPlayer -> consumedPlayer.sendToolBreakStatus(hand));
		}
		return ActionResult.SUCCESS;
	}
	return ActionResult.PASS;
}
 
源代码3 项目: the-hallow   文件: HallowedTreasureChestBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos pos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	if (hand == Hand.MAIN_HAND) {
		float x = pos.getX() + .49f;
		float y = pos.getY();
		float z = pos.getZ() + .51f;
		
		HallowedTreasureChestEntity entity = new HallowedTreasureChestEntity(world, x, y, z, true, blockState.get(FACING).asRotation());
		entity.updatePosition(x, y, z);
		world.spawnEntity(entity);
		
		return ActionResult.SUCCESS;
	}
	
	return ActionResult.PASS;
}
 
源代码4 项目: the-hallow   文件: ColoredPumpkinBlock.java
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	ItemStack stack = playerEntity.getStackInHand(hand);

	if (stack.getItem() == Items.SHEARS) {
		if (!world.isClient) {
			Direction side = blockHitResult.getSide();
			Direction facingTowardPlayer = side.getAxis() == Direction.Axis.Y ? playerEntity.getHorizontalFacing().getOpposite() : side;

			world.playSound(null, blockPos, SoundEvents.BLOCK_PUMPKIN_CARVE, SoundCategory.BLOCKS, 1.0F, 1.0F);
			world.setBlockState(blockPos, HallowedBlocks.CARVED_PUMPKIN_COLORS.get(this.color).getDefaultState().with(CarvedPumpkinBlock.FACING, facingTowardPlayer), 11);
			ItemEntity itemEntity = new ItemEntity(world, blockPos.getX() + 0.5D + facingTowardPlayer.getOffsetX() * 0.65D, blockPos.getY() + 0.1D, blockPos.getZ() + 0.5D + facingTowardPlayer.getOffsetZ() * 0.65D, new ItemStack(Items.PUMPKIN_SEEDS, 4));

			itemEntity.setVelocity(0.05D * (double) facingTowardPlayer.getOffsetX() + world.random.nextDouble() * 0.02D, 0.05D, 0.05D * (double) facingTowardPlayer.getOffsetZ() + world.random.nextDouble() * 0.02D);
			world.spawnEntity(itemEntity);
			stack.damage(1, playerEntity, (playerEntityVar) -> {
				playerEntityVar.sendToolBreakStatus(hand);
			});
		}

		return ActionResult.SUCCESS;
	}

	return super.onUse(blockState, world, blockPos, playerEntity, hand, blockHitResult);
}
 
源代码5 项目: Wurst7   文件: ThrowHack.java
@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();
	}
}
 
源代码6 项目: Wurst7   文件: NukerLegitHack.java
@Override
public void onLeftClick(LeftClickEvent event)
{
	// check hitResult
	if(MC.crosshairTarget == null
		|| !(MC.crosshairTarget instanceof BlockHitResult))
		return;
	
	// check pos
	BlockPos pos = ((BlockHitResult)MC.crosshairTarget).getBlockPos();
	if(pos == null
		|| BlockUtils.getState(pos).getMaterial() == Material.AIR)
		return;
	
	// check mode
	if(mode.getSelected() != Mode.ID)
		return;
	
	// set id
	WURST.getHax().nukerHack.setId(BlockUtils.getName(pos));
}
 
源代码7 项目: Wurst7   文件: AutoBuildHack.java
@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;
}
 
源代码8 项目: Wurst7   文件: SpeedNukerHack.java
@Override
public void onLeftClick(LeftClickEvent event)
{
	// check hitResult
	if(MC.crosshairTarget == null
		|| !(MC.crosshairTarget instanceof BlockHitResult))
		return;
	
	// check pos
	BlockPos pos = ((BlockHitResult)MC.crosshairTarget).getBlockPos();
	if(pos == null
		|| BlockUtils.getState(pos).getMaterial() == Material.AIR)
		return;
	
	// check mode
	if(mode.getSelected() != Mode.ID)
		return;
	
	// set id
	WURST.getHax().nukerHack.setId(BlockUtils.getName(pos));
}
 
源代码9 项目: Wurst7   文件: AutoEatHack.java
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;
}
 
源代码10 项目: Wurst7   文件: AutoSoupHack.java
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;
}
 
源代码11 项目: carpet-extra   文件: FlowerPotBlockMixin.java
@Inject(method = "onUse", at = @At("HEAD"))
private void onActivate(BlockState blockState_1, World world_1, BlockPos blockPos_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1, CallbackInfoReturnable<Boolean> cir)
{
    if (CarpetExtraSettings.flowerPotChunkLoading && world_1.getServer() != null && !world_1.isClient)
    {
        ItemStack stack = playerEntity_1.getStackInHand(hand_1);
        Item item = stack.getItem();
        Block block = item instanceof BlockItem ? (Block) CONTENT_TO_POTTED.getOrDefault(((BlockItem) item).getBlock(), Blocks.AIR) : Blocks.AIR;
        boolean boolean_1 = block == Blocks.AIR;
        boolean boolean_2 = this.content == Blocks.AIR;
        ServerWorld serverWorld = world_1.getServer().getWorld(world_1.getDimension().getType());

        if (boolean_1 != boolean_2 && (block == Blocks.POTTED_WITHER_ROSE || this.content == Blocks.WITHER_ROSE))
        {
            // System.out.println("Chunk load status = " + boolean_2);
            serverWorld.setChunkForced(blockPos_1.getX() >> 4, blockPos_1.getZ() >> 4, boolean_2);
        }
    }
}
 
源代码12 项目: bleachhack-1.14   文件: Scaffold.java
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;
}
 
源代码13 项目: bleachhack-1.14   文件: Scaffold.java
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;
}
 
源代码14 项目: bleachhack-1.14   文件: Scaffold.java
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(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.RELEASE_SHIFT_KEY));
			}
			lastPlaced.put(block, 5);
			return true;
		}
	}
	
	return false;
}
 
源代码15 项目: fabric-carpet   文件: CarpetEventServer.java
@Override
public void onBlockHit(ServerPlayerEntity player, Hand enumhand, BlockHitResult hitRes)//ItemStack itemstack, Hand enumhand, BlockPos blockpos, Direction enumfacing, Vec3d vec3d)
{
    handler.call( () ->
    {
        ItemStack itemstack = player.getStackInHand(enumhand);
        BlockPos blockpos = hitRes.getBlockPos();
        Direction enumfacing = hitRes.getSide();
        Vec3d vec3d = hitRes.getPos().subtract(blockpos.getX(), blockpos.getY(), blockpos.getZ());
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> ListValue.fromItemStack(itemstack)),
                ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")),
                ((c, t) -> new BlockValue(null, player.getServerWorld(), blockpos)),
                ((c, t) -> new StringValue(enumfacing.getName())),
                ((c, t) -> ListValue.of(
                        new NumericValue(vec3d.x),
                        new NumericValue(vec3d.y),
                        new NumericValue(vec3d.z)
                ))
        );
    }, player::getCommandSource);
}
 
源代码16 项目: fabric-carpet   文件: CarpetEventServer.java
@Override
public void onBlockHit(ServerPlayerEntity player, Hand enumhand, BlockHitResult hitRes)
{
    handler.call( () ->
    {
        BlockPos blockpos = hitRes.getBlockPos();
        Direction enumfacing = hitRes.getSide();
        Vec3d vec3d = hitRes.getPos().subtract(blockpos.getX(), blockpos.getY(), blockpos.getZ());
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")),
                ((c, t) -> new BlockValue(null, player.getServerWorld(), blockpos)),
                ((c, t) -> new StringValue(enumfacing.getName())),
                ((c, t) -> ListValue.of(
                        new NumericValue(vec3d.x),
                        new NumericValue(vec3d.y),
                        new NumericValue(vec3d.z)
                ))
        );
    }, player::getCommandSource);
}
 
源代码17 项目: Galacticraft-Rewoven   文件: WireBlock.java
@Override
@Deprecated
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (!world.isClient() && Galacticraft.configManager.get().isDebugLogEnabled()) {
        Galacticraft.logger.info(((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos));
    }
    return super.onUse(state, world, pos, player, hand, hit);
}
 
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
    if (playerEntity.getStackInHand(hand).getItem() instanceof ShearsItem) {
        world.setBlockState(blockPos, GalacticraftBlocks.CAVERNOUS_VINE.getDefaultState().with(VINES, blockState.get(VINES)));
        world.playSound(blockPos.getX(), blockPos.getY(), blockPos.getZ(), SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1f, 1f, true);
        return ActionResult.SUCCESS;
    }
    return ActionResult.SUCCESS;
}
 
源代码19 项目: Galacticraft-Rewoven   文件: UnlitWallTorchBlock.java
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (player.getStackInHand(hand).getItem() instanceof FlintAndSteelItem) {
        world.setBlockState(pos, Blocks.WALL_TORCH.getDefaultState().with(WallTorchBlock.FACING, state.get(WallTorchBlock.FACING)));
        ItemStack stack = player.getStackInHand(hand).copy();
        stack.damage(1, player, (playerEntity -> {
        }));
        player.setStackInHand(hand, stack);
    }

    return super.onUse(state, world, pos, player, hand, hit);
}
 
源代码20 项目: Galacticraft-Rewoven   文件: UnlitTorchBlock.java
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (player.getStackInHand(hand).getItem() instanceof FlintAndSteelItem) {
        world.setBlockState(pos, Blocks.TORCH.getDefaultState());
        ItemStack stack = player.getStackInHand(hand).copy();
        stack.damage(1, player, (playerEntity -> {
        }));
        player.setStackInHand(hand, stack);
    }
    return super.onUse(state, world, pos, player, hand, hit);
}
 
源代码21 项目: Galacticraft-Rewoven   文件: MoonBerryBushBlock.java
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
    int age = blockState.get(AGE);
    boolean mature = age == 3;

    if (mature) {
        int amount = 1 + world.random.nextInt(3);
        dropStack(world, blockPos, new ItemStack(GalacticraftItems.MOON_BERRIES, amount));
        world.playSound(null, blockPos, SoundEvents.ITEM_SWEET_BERRIES_PICK_FROM_BUSH, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
        world.setBlockState(blockPos, blockState.with(AGE, 1), 2);
        return ActionResult.SUCCESS;
    } else {
        return super.onUse(blockState, world, blockPos, playerEntity, hand, blockHitResult);
    }
}
 
@Override
public ActionResult onUse(BlockState blockState_1, World world_1, BlockPos blockPos_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1) {
    BlockEntity partEntity = world_1.getBlockEntity(blockPos_1);
    if (world_1.isAir(blockPos_1) || !(partEntity instanceof BasicSolarPanelPartBlockEntity)) {
        return ActionResult.SUCCESS;
    }

    if (world_1.isClient) return ActionResult.SUCCESS;

    BlockPos basePos = ((BasicSolarPanelPartBlockEntity) partEntity).basePos;

    BlockState base = world_1.getBlockState(basePos);
    Block baseBlock = base.getBlock();
    return ((BasicSolarPanelBlock) baseBlock).onUse(base, world_1, basePos, playerEntity_1, hand_1, blockHitResult_1);
}
 
源代码23 项目: the-hallow   文件: TinyPumpkinBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
	BlockEntity be = world.getBlockEntity(pos);
	if (be instanceof TinyPumpkinBlockEntity) {
		return ((TinyPumpkinBlockEntity) be).use(player, hand, hit);
	}
	return ActionResult.PASS;
}
 
源代码24 项目: the-hallow   文件: TinyPumpkinBlockEntity.java
public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit) {
	Direction facing = getCachedState().get(HorizontalFacingBlock.FACING);
	Direction hitSide = hit.getSide();
	if (hitSide != facing.rotateYClockwise() && hitSide != facing.rotateYCounterclockwise()) {
		return ActionResult.PASS;
	}
	
	if (!world.isClient) {
		ItemStack handStack = player.getStackInHand(hand);
		boolean isLeft = hitSide == facing.rotateYCounterclockwise();
		ItemStack heldItem = isLeft ? leftItem : rightItem;
		if (!heldItem.isEmpty()) {
			ItemScatterer.spawn(world, pos, DefaultedList.copyOf(ItemStack.EMPTY, heldItem));
			if (isLeft) {
				leftItem = ItemStack.EMPTY;
			} else {
				rightItem = ItemStack.EMPTY;
			}
			sync();
			markDirty();
		} else if (!handStack.isEmpty()) {
			if (isLeft) {
				leftItem = handStack.copy();
				leftItem.setCount(1);
			} else {
				rightItem = handStack.copy();
				rightItem.setCount(1);
			}
			handStack.decrement(1);
			sync();
			markDirty();
		}
	}
	
	return ActionResult.SUCCESS;
}
 
源代码25 项目: the-hallow   文件: PumpkinPieBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
	if (!world.isClient) {
		return this.tryEat(world, pos, state, player);
	}
	ItemStack stack = player.getStackInHand(hand);
	if(stack.isEmpty()) {
		return ActionResult.PASS;
	}
	return this.tryEat(world, pos, state, player);
}
 
源代码26 项目: the-hallow   文件: InfusionPillarBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	InfusionPillarBlockEntity pillarEntity = (InfusionPillarBlockEntity) world.getBlockEntity(blockPos);
	if (pillarEntity != null) {
		if (playerEntity.getStackInHand(hand).isEmpty()) {
			playerEntity.inventory.insertStack(pillarEntity.takeStack());
		} else {
			playerEntity.setStackInHand(hand, pillarEntity.putStack(playerEntity.getStackInHand(hand)));
		}
	}
	return ActionResult.SUCCESS;
}
 
源代码27 项目: the-hallow   文件: InfusionAltarBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	InfusionAltarBlockEntity altarEntity = (InfusionAltarBlockEntity) world.getBlockEntity(blockPos);
	if (playerEntity.isSneaking()) {
		if (altarEntity != null) {
			getLinkedPillars(altarEntity);
			getCombinedInventory(altarEntity);
			Optional<InfusionRecipe> recipe = world.getRecipeManager().getFirstMatch(InfusionRecipe.Type.INSTANCE, combinedInventory, world);
			if (recipe.isPresent()) {
				if (world.isClient()) {
					createParticles(altarEntity);
					createSound(altarEntity);
				}
				if (!altarEntity.storedStack.isEmpty()) {
					createDrop(altarEntity, recipe.get().getOutput());
					clearAllStacks(altarEntity);
				} else {
					altarEntity.storedStack = recipe.get().getOutput().copy();
					clearPillarStacks(altarEntity);
				}
			}
		}
	} else {
		if (altarEntity != null) {
			if (playerEntity.getStackInHand(hand).isEmpty()) {
				playerEntity.inventory.offerOrDrop(world, altarEntity.takeStack());
			} else {
				playerEntity.setStackInHand(hand, altarEntity.putStack(playerEntity.getStackInHand(hand)));
			}
		}
	}

	return ActionResult.SUCCESS;
}
 
源代码28 项目: Wurst7   文件: ExcavatorHack.java
private void handlePositionSelection()
{
	// continue with next step
	if(step.pos != null && InputUtil
		.isKeyPressed(MC.getWindow().getHandle(), GLFW.GLFW_KEY_ENTER))
	{
		step = Step.values()[step.ordinal() + 1];
		
		// delete posLookingAt
		if(!step.selectPos)
			posLookingAt = null;
		
		return;
	}
	
	if(MC.crosshairTarget != null
		&& MC.crosshairTarget instanceof BlockHitResult)
	{
		// set posLookingAt
		posLookingAt = ((BlockHitResult)MC.crosshairTarget).getBlockPos();
		
		// offset if sneaking
		if(MC.options.keySneak.isPressed())
			posLookingAt = posLookingAt
				.offset(((BlockHitResult)MC.crosshairTarget).getSide());
		
	}else
		posLookingAt = null;
	
	// set selected position
	if(posLookingAt != null && MC.options.keyUse.isPressed())
		step.pos = posLookingAt;
}
 
源代码29 项目: Wurst7   文件: AutoMineHack.java
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();
}
 
源代码30 项目: Wurst7   文件: NukerHack.java
@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);
}
 
 类所在包
 类方法
 同包方法