net.minecraft.util.hit.BlockHitResult Java Examples

The following examples show how to use net.minecraft.util.hit.BlockHitResult. 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: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 7 votes vote down vote up
@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);
}
 
Example #2
Source File: SpeedNukerHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@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));
}
 
Example #3
Source File: FlowerPotBlockMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example #4
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 6 votes vote down vote up
@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);
}
 
Example #5
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 6 votes vote down vote up
@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);
}
 
Example #6
Source File: HallowedLogBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@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;
}
 
Example #7
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 #8
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 #9
Source File: HallowedTreasureChestBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@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;
}
 
Example #10
Source File: NukerLegitHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@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));
}
 
Example #11
Source File: ColoredPumpkinBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@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);
}
 
Example #12
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(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;
}
 
Example #13
Source File: ClientPlayerInteractionManagerMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rightClickBlock(BlockPos pos, Direction side, Vec3d hitVec)
{
	interactBlock(client.player, client.world, Hand.MAIN_HAND,
		new BlockHitResult(hitVec, side, pos, false));
	interactItem(client.player, client.world, Hand.MAIN_HAND);
}
 
Example #14
Source File: CavernousVineBlockPoisonous.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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;
}
 
Example #15
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ActionResult statisOnUse(org.sandboxpowered.sandbox.api.state.BlockState blockState_1, org.sandboxpowered.sandbox.api.world.World world_1, Position blockPos_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1, Block block) {
    InteractionResult result = block.onBlockUsed(
            world_1,
            blockPos_1,
            blockState_1,
            playerEntity_1,
            hand_1 == Hand.MAIN_HAND ? org.sandboxpowered.sandbox.api.entity.player.Hand.MAIN_HAND : org.sandboxpowered.sandbox.api.entity.player.Hand.OFF_HAND,
            WrappingUtil.convert(blockHitResult_1.getSide()),
            (Vec3f) (Object) new Vector3f(blockHitResult_1.getPos())
    );
    return WrappingUtil.convert(result);
}
 
Example #16
Source File: BlockRotator.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static boolean flipBlockWithCactus(BlockState state, World world, PlayerEntity player, Hand hand, BlockHitResult hit)
{
    if (!player.abilities.allowModifyWorld || !CarpetSettings.flippinCactus || !player_holds_cactus_mainhand(player))
    {
        return false;
    }
    CarpetSettings.impendingFillSkipUpdates = true;
    boolean retval = flip_block(state, world, player, hand, hit);
    CarpetSettings.impendingFillSkipUpdates = false;
    return retval;
}
 
Example #17
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 #18
Source File: Tracer.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static BlockHitResult rayTraceBlocks(Entity source, float partialTicks, double reach, boolean fluids)
{
    Vec3d pos = source.getCameraPosVec(partialTicks);
    Vec3d rotation = source.getRotationVec(partialTicks);
    Vec3d reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
    return source.world.rayTrace(new RayTraceContext(pos, reachEnd, RayTraceContext.ShapeType.OUTLINE, fluids ? RayTraceContext.FluidHandling.ANY : RayTraceContext.FluidHandling.NONE, source));
}
 
Example #19
Source File: BlockValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static PlacementContext from(World world, BlockPos pos, String direction, boolean sneakPlace, ItemStack itemStack)
{
    SpecificDirection dir = SpecificDirection.DIRECTION_MAP.get(direction);
    if (dir == null)
        throw new InternalExpressionException("unknown block placement direction: "+direction);
    BlockHitResult hitres =  new BlockHitResult(new Vec3d(pos).add(dir.hitOffset), dir.facing, pos, false);
    return new PlacementContext(world, dir.facing, sneakPlace, itemStack, hitres);
}
 
Example #20
Source File: CauldronBlock_stackableSBoxesMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onUse", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/item/ItemStack;hasTag()Z",
        shift = At.Shift.BEFORE
))
private void setSboxCount(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult arg5, CallbackInfoReturnable<Boolean> cir,
                          ItemStack itemStack, int i, Item item, Block block, ItemStack itemStack5)
{
    if (CarpetSettings.stackableShulkerBoxes)
        itemStack5.setCount(itemStack.getCount());
}
 
Example #21
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerInteractBlock", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;interactBlock(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;"
))
private void onBlockInteracted(PlayerInteractBlockC2SPacket playerInteractBlockC2SPacket_1, CallbackInfo ci)
{
    if (PLAYER_RIGHT_CLICKS_BLOCK.isNeeded())
    {
        Hand hand = playerInteractBlockC2SPacket_1.getHand();
        BlockHitResult hitRes = playerInteractBlockC2SPacket_1.getHitY();
        PLAYER_RIGHT_CLICKS_BLOCK.onBlockHit(player, hand, hitRes);
    }
}
 
Example #22
Source File: ServerPlayerInteractionManager_cactusMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "interactBlock", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;"
))
private ActionResult activateWithOptionalCactus(BlockState blockState, World world_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1)
{
    boolean flipped = BlockRotator.flipBlockWithCactus(blockState, world_1, playerEntity_1, hand_1, blockHitResult_1);
    if (flipped)
        return ActionResult.SUCCESS;

    return blockState.onUse(world_1, playerEntity_1, hand_1, blockHitResult_1);
}
 
Example #23
Source File: ServerPlayerInteractionManager_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "interactBlock", at = @At(
        value = "RETURN",
        ordinal = 2
))
private void onBlockActivated(PlayerEntity playerArg, World world, ItemStack stack, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable<ActionResult> cir)
{
    PLAYER_INTERACTS_WITH_BLOCK.onBlockHit(player, hand, blockHitResult);
}
 
Example #24
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 #25
Source File: WireBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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);
}
 
Example #26
Source File: UnlitWallTorchBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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);
}
 
Example #27
Source File: UnlitTorchBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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);
}
 
Example #28
Source File: MoonBerryBushBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example #29
Source File: BasicSolarPanelPartBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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);
}
 
Example #30
Source File: TinyPumpkinBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@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;
}