This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.zskamljic.tophium.rendering; | |
import net.minecraft.MethodsReturnNonnullByDefault; | |
import net.minecraft.client.renderer.block.model.BakedQuad; | |
import net.minecraft.client.renderer.block.model.ItemOverrides; | |
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | |
import net.minecraft.client.resources.model.BakedModel; | |
import net.minecraft.core.Direction; | |
import net.minecraft.util.RandomSource; | |
import net.minecraft.world.level.block.state.BlockState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var renderer = Minecraft.getInstance().getBlockRenderer(); | |
var buffer = event.getMultiBufferSource() | |
.getBuffer(RenderType.translucent()); | |
var model = renderer.getBlockModel(Blocks.STONE.defaultBlockState()); | |
renderer.getModelRenderer().tesselateBlock(player.getLevel(), model, Blocks.STONE.defaultBlockState(), | |
position, poseStack, buffer, false, player.getLevel().getRandom(), | |
state.getSeed(previewPosition), 0); // What is pPackedOverlay, the last parameter? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Mod.EventBusSubscriber | |
public static class EventHandler { | |
@SubscribeEvent | |
public static void renderBlockPreview(RenderHighlightEvent.Block event) { | |
var target = event.getTarget(); | |
var cameraPosition = event.getCamera().getPosition(); | |
var previewPosition = target.getBlockPos().relative(target.getDirection()); | |
var player = Minecraft.getInstance().player; | |
var itemStack = player.getMainHandItem(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = new ProjectCreateOrUpdate(); | |
request.setContactId(UUID.randomUUID()); | |
request.setName("Project from API"); | |
request.setDeadlineUtc(OffsetDateTime.now().plusDays(5)); | |
request.setEstimateAmount(15.); | |
var credentials = xeroAuthService.getCredentials(); | |
projectApi.createProject(credentials.token(), credentials.tenant(), request); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layout(constraints.maxWidth, size.height + contentHeight) { | |
val startOffset = size.height / 2 - placeables[0].height / 2 | |
var yPosition = startOffset | |
// Get the current ratio as float, otherwise it's either 0 or 1 | |
val scrollPercent = scrollState.value.toFloat() / scrollState.maxValue | |
// We need the element index now | |
placeables.forEachIndexed { index, placeable -> | |
// Get the ratio at which the item appears |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
placeable.placeRelativeWithLayer(x = indent.toInt(), y = yPosition) { | |
alpha = interpolatedValue.toFloat() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... other remembered values | |
// Required to call animateScrollTo | |
val scope = rememberCoroutineScope() | |
// A place to store item positions | |
val indices = remember { IntArray(itemCount) { 0 } } | |
val flingBehavior = object : FlingBehavior { | |
override suspend fun ScrollScope.performFling(initialVelocity: Float): Float { | |
// Get the current scroll position | |
val value = scrollState.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun CurvedScroll( | |
itemCount: Int, | |
item: @Composable (Int) -> Unit | |
) { | |
val scrollState = rememberScrollState() | |
// Added: to hold the size of the composable | |
var size by remember { mutableStateOf(IntSize.Zero) } | |
Box(modifier = Modifier.onSizeChanged { size = it }) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun CurvedScroll( | |
itemCount: Int, | |
item: @Composable (Int) -> Unit | |
) { | |
Layout( | |
modifier = Modifier, | |
content = { repeat(itemCount) { item(it) } } | |
) { measurables, constraints -> | |
val placeables = measurables.map { measurable -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.playground.ui.scroll | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.gestures.FlingBehavior | |
import androidx.compose.foundation.gestures.ScrollScope | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.fillMaxHeight | |
import androidx.compose.foundation.layout.height | |
import androidx.compose.foundation.layout.width | |
import androidx.compose.foundation.rememberScrollState |
NewerOlder