Class SceneViewport
java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.viewport.SceneViewport
- All Implemented Interfaces:
AutoCloseable
A small 3D scene drawn to a texture of its own: blocks, whole structures, entities and items' icons, seen from a camera that
circles them. Because it is a texture, what it shows is always kept inside the rectangle it is drawn in, wherever
that is: a GUI (
SceneViewportWidget), or a face in
the world (use texture() with any textured render type).
SceneViewport view = SceneViewport.create(MyMod.id("altar_view"), 256, 256);
view.block(BlockPos.ZERO, Blocks.BEACON.defaultBlockState()).camera(35, 28).spin(16);
// every frame it is on screen:
view.use();
It is drawn only when it has to be: when its scene or camera has changed, or, while it spins or holds entities
(which move), a set number of times a second (refreshRate). A viewport nobody has used
for a couple of seconds is not drawn at all. Everything in it is lit as the world lights it: a block's top brightest, each side its own shade,
whichever way the scene is turned. The texture is upside down, as every texture drawn to is: show it with its V flipped (the widget
does). Client code only; make and change viewports on the render thread.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA block of the scene.static final recordAn entity of the scene: never in a world, only drawn.static final recordAn item of the scene, drawn as its icon is in an inventory:sizeacross, its middle at a place, flat to the camera when the camera looks straight on (camera(0, 0)). -
Method Summary
Modifier and TypeMethodDescriptionblock(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) blocks()A structure, or any build: every block of it.net.minecraft.world.phys.AABBbounds()The box the scene fills: what the camera circles and fits in view.camera(float yaw, float pitch) Where the camera stands about the scene, in degrees:yawround it,pitchabove it (0 level, 90 overhead).clear()voidclose()Frees the texture.static SceneViewportcreate(net.minecraft.resources.Identifier texture, int width, int height) entities()entity(net.minecraft.world.entity.Entity entity, double x, double y, double z, float yaw) An entity standing with its feet at a place.frame(double span, double x, double y, double z) Fixes what the picture shows, in place of fitting the scene to it:spanof the scene's own units across the picture's width, with a point of the scene at its middle.net.minecraft.world.phys.Vec3doubleintheight()booleanisClosed()booleanisReady()Whether the viewport has been drawn at least once, so that its texture exists: it is, from the frame after it is first used.item(net.minecraft.world.item.ItemStack stack, double x, double y, double z, float size) An item's icon.items()longlastUsed()floatpitch()voidrefresh()Has the viewport drawn again though nothing of its own changed: a block's model, or an entity, did.intrefreshRate(int timesPerSecond) How many times a second a viewport that moves (it spins, or has entities) is drawn again.floatspin()spin(float degreesPerSecond) Turns the camera round the scene by itself, this many degrees a second; 0 to stop.booleanWhether the scene or camera has changed since it was last drawn; asking clears it.net.minecraft.resources.Identifiertexture()voiduse()Says the viewport is being shown this frame.intwidth()floatyaw()floatzoom()zoom(float zoom) How large the scene is drawn: 1 fits all of it in view from any side.
-
Method Details
-
create
public static SceneViewport create(net.minecraft.resources.Identifier texture, int width, int height) - Parameters:
texture- the id its texture is registered under, for drawing itwidth- the texture's size in pixels: what it is drawn at is up to whoever draws it- Throws:
IllegalArgumentException- if a viewport already has that id
-
texture
public net.minecraft.resources.Identifier texture() -
width
public int width() -
height
public int height() -
clear
-
block
public SceneViewport block(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) -
blocks
public SceneViewport blocks(Map<net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState> all) A structure, or any build: every block of it. -
entity
public SceneViewport entity(net.minecraft.world.entity.Entity entity, double x, double y, double z, float yaw) An entity standing with its feet at a place. It is drawn as it is each time the viewport is: animate it by ticking it. -
item
public SceneViewport item(net.minecraft.world.item.ItemStack stack, double x, double y, double z, float size) An item's icon. A scene of icons is a picture of them: look straight on withcamera(0, 0)and no spin, and it is drawn once. They are lit as the game lights icons in its screens. -
items
-
frame
Fixes what the picture shows, in place of fitting the scene to it:spanof the scene's own units across the picture's width, with a point of the scene at its middle. For laying a scene out to match something drawn about it (a grid's frames, say). A span of 0 goes back to fitting. -
frameSpan
@Internal public double frameSpan() -
frameCentre
@Internal public net.minecraft.world.phys.Vec3 frameCentre() -
blocks
-
entities
-
bounds
public net.minecraft.world.phys.AABB bounds()The box the scene fills: what the camera circles and fits in view. -
camera
Where the camera stands about the scene, in degrees:yawround it,pitchabove it (0 level, 90 overhead). -
zoom
How large the scene is drawn: 1 fits all of it in view from any side. -
spin
Turns the camera round the scene by itself, this many degrees a second; 0 to stop. -
refreshRate
How many times a second a viewport that moves (it spins, or has entities) is drawn again. 60 by default, which turns smoothly; lower it for a large scene that need not. -
yaw
public float yaw() -
pitch
public float pitch() -
zoom
public float zoom() -
spin
public float spin() -
refreshRate
public int refreshRate() -
use
public void use()Says the viewport is being shown this frame. Without it for a couple of seconds, the viewport stops being drawn. -
isReady
public boolean isReady()Whether the viewport has been drawn at least once, so that its texture exists: it is, from the frame after it is first used. -
refresh
public void refresh()Has the viewport drawn again though nothing of its own changed: a block's model, or an entity, did. -
close
public void close()Frees the texture. The viewport draws nothing after this.- Specified by:
closein interfaceAutoCloseable
-
isClosed
public boolean isClosed() -
lastUsed
@Internal public long lastUsed() -
takeDirty
@Internal public boolean takeDirty()Whether the scene or camera has changed since it was last drawn; asking clears it.
-