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();
}
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);
}
});
}
Aggregations