Skip to content

Instantly share code, notes, and snippets.

View zskamljic's full-sized avatar

Žan Skamljič zskamljic

  • Equaleyes d.o.o.
View GitHub Profile
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;
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?
@zskamljic
zskamljic / EventHandler.java
Last active December 27, 2022 19:09
Guess ghost rendering
@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();
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);
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
placeable.placeRelativeWithLayer(x = indent.toInt(), y = yPosition) {
alpha = interpolatedValue.toFloat()
}
// ... 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
@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 }) {
@Composable
fun CurvedScroll(
itemCount: Int,
item: @Composable (Int) -> Unit
) {
Layout(
modifier = Modifier,
content = { repeat(itemCount) { item(it) } }
) { measurables, constraints ->
val placeables = measurables.map { measurable ->
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