Search in sources :

Example 1 with Tickable

use of net.minecraft.util.Tickable in project roadrunner by MaxNeedsSnacks.

the class WorldMixin method postBlockEntityTick.

// Add any pending block entities to the world.
@Inject(method = "tickBlockEntities", at = @At("RETURN"))
private void postBlockEntityTick(CallbackInfo ci) {
    Profiler profiler = this.profiler.get();
    profiler.push("pendingBlockEntities$lithium");
    this.blockEntities$lithium.checkOffThreadModifications(false);
    this.pendingBlockEntities$lithium.checkOffThreadModifications(false);
    // The overhead of this is essentially non-zero and doesn't matter in this code.
    for (BlockEntity entity : this.pendingBlockEntities) {
        if (entity.isRemoved()) {
            continue;
        }
        // Try-add directly to avoid the double map lookup, helps speed things along
        if (this.blockEntities$lithium.addIfAbsent(entity)) {
            // vanilla has an extra updateListeners(...) call on the client here, but the one below should be enough
            if (entity instanceof Tickable) {
                this.tickingBlockEntities.add(entity);
            }
            BlockPos pos = entity.getPos();
            World thisWorld = (World) (Object) this;
            if (entity.getWorld() != thisWorld) {
                entity.setLocation(thisWorld, pos);
            }
            entity.onLoad();
            // Avoid the double chunk lookup (isLoaded followed by getChunk) by simply inlining getChunk call
            // pass this.isClient instead of false, so the updateListeners call is always executed on the client (like vanilla)
            Chunk chunk = this.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.FULL, this.isClient);
            if (chunk != null) {
                BlockState state = chunk.getBlockState(pos);
                chunk.setBlockEntity(pos, entity);
                this.updateListeners(pos, state, state, 3);
            }
        }
    }
    this.pendingBlockEntities.clear();
    profiler.pop();
}
Also used : BlockState(net.minecraft.block.BlockState) Profiler(net.minecraft.util.profiler.Profiler) Tickable(net.minecraft.util.Tickable) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Chunk(net.minecraft.world.chunk.Chunk) BlockEntity(net.minecraft.block.entity.BlockEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with Tickable

use of net.minecraft.util.Tickable in project isometric-renders by gliscowo.

the class IsometricRenderPresets method setupBlockEntityRender.

public static void setupBlockEntityRender(IsometricRenderScreen screen, @NotNull BlockEntity entity) {
    final MinecraftClient client = MinecraftClient.getInstance();
    final Identifier blockId = Registry.BLOCK.getId(entity.getCachedState().getBlock());
    screen.setup((matrices, vertexConsumerProvider, tickDelta) -> {
        matrices.push();
        matrices.translate(-0.5, 0, -0.5);
        client.getBlockRenderManager().renderBlockAsEntity(entity.getCachedState(), matrices, vertexConsumerProvider, 15728880, OverlayTexture.DEFAULT_UV);
        if (BlockEntityRenderDispatcher.INSTANCE.get(entity) != null) {
            BlockEntityRenderDispatcher.INSTANCE.get(entity).render(entity, tickDelta, matrices, vertexConsumerProvider, 15728880, OverlayTexture.DEFAULT_UV);
        }
        double xOffset = client.player.getX() % 1d;
        double zOffset = client.player.getZ() % 1d;
        if (xOffset < 0)
            xOffset += 1;
        if (zOffset < 0)
            zOffset += 1;
        matrices.translate(xOffset, 1.65 + client.player.getY() % 1d, zOffset);
        client.particleManager.renderParticles(matrices, (VertexConsumerProvider.Immediate) vertexConsumerProvider, client.gameRenderer.getLightmapTextureManager(), getParticleCamera(), tickDelta);
        matrices.pop();
    }, blockId.getNamespace() + "/blocks/" + blockId.getPath());
    screen.setTickCallback(() -> {
        if (entity instanceof Tickable) {
            ((Tickable) entity).tick();
        }
        if (client.world.random.nextDouble() < 0.150) {
            entity.getCachedState().getBlock().randomDisplayTick(entity.getCachedState(), client.world, client.player.getBlockPos(), client.world.random);
        }
    });
}
Also used : Identifier(net.minecraft.util.Identifier) Tickable(net.minecraft.util.Tickable) MinecraftClient(net.minecraft.client.MinecraftClient) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Aggregations

Tickable (net.minecraft.util.Tickable)2 BlockState (net.minecraft.block.BlockState)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 VertexConsumerProvider (net.minecraft.client.render.VertexConsumerProvider)1 Identifier (net.minecraft.util.Identifier)1 BlockPos (net.minecraft.util.math.BlockPos)1 Profiler (net.minecraft.util.profiler.Profiler)1 World (net.minecraft.world.World)1 Chunk (net.minecraft.world.chunk.Chunk)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1