Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various changes to StructureTemplates, 1.20.5 branch. #13

Open
wants to merge 2 commits into
base: 1.20.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial
var entityBuffers = client.getBufferBuilders().getEntityVertexConsumers();

float scale = Math.min(this.width, this.height);
scale /= Math.max(structure.xSize, Math.max(structure.ySize, structure.zSize));
scale /= Math.max(this.structure.xSize(), Math.max(this.structure.ySize(), this.structure.zSize()));
scale /= 1.625f;

var matrices = context.getMatrices();
Expand All @@ -69,7 +69,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial

matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(this.displayAngle));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(this.rotation));
matrices.translate(this.structure.xSize / -2f, this.structure.ySize / -2f, this.structure.zSize / -2f);
matrices.translate(this.structure.xSize() / -2.0f, this.structure.ySize() / -2.0f, this.structure.zSize() / -2.0f);

RenderSystem.runAsFancy(() -> {
structure.forEachPredicate((blockPos, predicate) -> {
Expand All @@ -95,7 +95,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial
});

if (this.placeable) {
if (StructureOverlayRenderer.isShowingOverlay(this.structure.id)) {
if (StructureOverlayRenderer.isShowingOverlay(this.structure.id())) {
context.drawText(client.textRenderer, Text.translatable("text.lavender.structure_component.active_overlay_hint"), this.x + this.width - 5 - client.textRenderer.getWidth("⚓"), this.y + this.height - 9 - 5, 0, false);
this.tooltip(Text.translatable("text.lavender.structure_component.hide_hint"));
} else {
Expand All @@ -109,11 +109,11 @@ public boolean onMouseDown(double mouseX, double mouseY, int button) {
var result = super.onMouseDown(mouseX, mouseY, button);
if (!this.placeable || button != GLFW.GLFW_MOUSE_BUTTON_LEFT || !Screen.hasShiftDown()) return result;

if (StructureOverlayRenderer.isShowingOverlay(this.structure.id)) {
StructureOverlayRenderer.removeAllOverlays(this.structure.id);
if (StructureOverlayRenderer.isShowingOverlay(this.structure.id())) {
StructureOverlayRenderer.removeAllOverlays(this.structure.id());
} else {
StructureOverlayRenderer.addPendingOverlay(this.structure.id);
StructureOverlayRenderer.restrictVisibleLayer(this.structure.id, this.visibleLayer);
StructureOverlayRenderer.addPendingOverlay(this.structure.id());
StructureOverlayRenderer.restrictVisibleLayer(this.structure.id(), this.visibleLayer);

MinecraftClient.getInstance().setScreen(null);
}
Expand All @@ -138,7 +138,7 @@ public boolean canFocus(FocusSource source) {
}

public StructureComponent visibleLayer(int visibleLayer) {
StructureOverlayRenderer.restrictVisibleLayer(this.structure.id, visibleLayer);
StructureOverlayRenderer.restrictVisibleLayer(this.structure.id(), visibleLayer);

this.visibleLayer = visibleLayer;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ private static Vec3i getPendingOffset(StructureTemplate structure) {
return switch (PENDING_OVERLAY.rotation) {
case NONE -> new Vec3i(-structure.anchor().getX(), -structure.anchor().getY(), -structure.anchor().getZ());
case CLOCKWISE_90 -> new Vec3i(-structure.anchor().getZ(), -structure.anchor().getY(), -structure.anchor().getX());
case CLOCKWISE_180 -> new Vec3i(-structure.xSize + structure.anchor.getX() + 1, -structure.anchor().getY(), -structure.zSize + structure.anchor.getZ() + 1);
case COUNTERCLOCKWISE_90 -> new Vec3i(-structure.zSize + structure.anchor.getZ() + 1, -structure.anchor().getY(), -structure.xSize + structure.anchor.getX() + 1);
case CLOCKWISE_180 -> new Vec3i(-structure.xSize() + structure.anchor().getX() + 1, -structure.anchor().getY(), -structure.zSize() + structure.anchor().getZ() + 1);
case COUNTERCLOCKWISE_90 -> new Vec3i(-structure.zSize() + structure.anchor().getZ() + 1, -structure.anchor().getY(), -structure.xSize() + structure.anchor().getX() + 1);
};
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,23 @@ public StructureNode(StructureTemplate structure, int angle, boolean placeable)
protected void visitStart(MarkdownCompiler<?> compiler) {
var structureComponent = StructureFeature.this.bookComponentSource.builtinTemplate(
ParentComponent.class,
this.structure.ySize > 1 ? "structure-preview-with-layers" : "structure-preview",
Map.of("structure", this.structure.id.toString(), "angle", String.valueOf(this.angle))
this.structure.ySize() > 1 ? "structure-preview-with-layers" : "structure-preview",
Map.of("structure", this.structure.id().toString(), "angle", String.valueOf(this.angle))
);

var structurePreview = structureComponent.childById(StructureComponent.class, "structure").placeable(this.placeable);
var layerSlider = structureComponent.childById(SlimSliderComponent.class, "layer-slider");

if (layerSlider != null) {
layerSlider.max(0).min(this.structure.ySize).tooltipSupplier(layer -> {
layerSlider.max(0).min(this.structure.ySize()).tooltipSupplier(layer -> {
return layer > 0
? Text.translatable("text.lavender.structure_component.layer_tooltip", layer.intValue())
: Text.translatable("text.lavender.structure_component.all_layers_tooltip");
}).onChanged().subscribe(layer -> {
structurePreview.visibleLayer((int) layer - 1);
});

layerSlider.value(StructureOverlayRenderer.getLayerRestriction(this.structure.id) + 1);
layerSlider.value(StructureOverlayRenderer.getLayerRestriction(this.structure.id()) + 1);
}

((OwoUICompiler) compiler).visitComponent(structureComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public interface BlockStatePredicate {
* a full state match
*/
BlockStatePredicate NULL_PREDICATE = new BlockStatePredicate() {
private static final BlockState[] PREVIEW_STATES = {Blocks.AIR.getDefaultState()};

@Override
public BlockState preview() {
return Blocks.AIR.getDefaultState();
public BlockState[] previewBlockstates() {
return PREVIEW_STATES;
}

@Override
Expand All @@ -38,9 +40,11 @@ public boolean isOf(MatchCategory type) {
* match on any air block
*/
BlockStatePredicate AIR_PREDICATE = new BlockStatePredicate() {
private static final BlockState[] PREVIEW_STATES = {Blocks.AIR.getDefaultState()};

@Override
public BlockState preview() {
return Blocks.AIR.getDefaultState();
public BlockState[] previewBlockstates() {
return PREVIEW_STATES;
}

@Override
Expand Down Expand Up @@ -69,7 +73,15 @@ default boolean matches(BlockState state) {
* is called every frame the preview is rendered, returning a different sample
* depending on system time (e.g. to cycle to a block tag) is valid behavior
*/
BlockState preview();
default BlockState preview() {
BlockState[] states = this.previewBlockstates();
return states[(int) (System.currentTimeMillis() / 1000 % states.length)];
}

/**
* @return An array of all possible preview block states.
*/
BlockState[] previewBlockstates();

/**
* @return Whether this predicate falls into the given matching category, generally
Expand Down
Loading