Skip to content

Commit

Permalink
Fix machine upgrade slot preview renderer not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Rearth committed Dec 6, 2024
1 parent 5f1bd75 commit 2636d61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void remove() {
var relativePos = MultiblockMachineEntity.worldToRelativePos(handler.blockPos, addonBlockPos, facing);

holoPreviewContainer.child(
new BlockPreviewComponent(addonBlock, addonBlockEntity, relativePos, rotationSpeed, 20)
new BlockPreviewComponent(addonBlock, addonBlockEntity, relativePos, rotationSpeed)
.sizing(Sizing.fixed(20))
.positioning(Positioning.absolute(previewX, previewY))
);
Expand Down Expand Up @@ -206,7 +206,7 @@ public void remove() {
var dummyBlock = BlockContent.ADDON_INDICATOR_BLOCK.getDefaultState();

holoPreviewContainer.child(
new BlockPreviewComponent(dummyBlock, null, relativePos, rotationSpeed, 20)
new BlockPreviewComponent(dummyBlock, null, relativePos, rotationSpeed)
.sizing(Sizing.fixed(20))
.positioning(Positioning.absolute(previewX, previewY))
);
Expand All @@ -218,7 +218,7 @@ public void remove() {

// machine itself
holoPreviewContainer.child(
new BlockPreviewComponent(handler.machineBlock, handler.blockEntity, new Vec3i(0, 0, 0), rotationSpeed, 20)
new BlockPreviewComponent(handler.machineBlock, handler.blockEntity, new Vec3i(0, 0, 0), rotationSpeed)
.sizing(Sizing.fixed(20))
.positioning(Positioning.absolute(previewX, previewY))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,24 @@ public class BlockPreviewComponent extends BaseComponent {
private final @Nullable BlockEntity entity;
private final Vec3i offset;
private final float mouseRotationSpeed;
private final float blockSizing;

private float mouseRotation;

public BlockPreviewComponent(BlockState state, @Nullable BlockEntity entity, Vec3i offset, float blockSizing) {
this(state, entity, offset, 0, blockSizing);
}

public BlockPreviewComponent(BlockState state, @Nullable BlockEntity entity, Vec3i offset, float mouseRotationSpeed, float blockSizing) {
public BlockPreviewComponent(BlockState state, @Nullable BlockEntity entity, Vec3i offset, float mouseRotationSpeed) {
this.state = state;
this.entity = entity;
this.offset = offset;
this.mouseRotationSpeed = mouseRotationSpeed;
this.blockSizing = blockSizing;
}

@Override
public boolean shouldDrawTooltip(double mouseX, double mouseY) {
if (!super.shouldDrawTooltip(mouseX, mouseY)) return false;

var offsetX = mouseX - this.x;
var offsetY = mouseY - this.y;

System.out.println(offsetX + " " + offsetY + " | " + x + " " + offset.getX() + " " + blockSizing);
// no idea how to properly do this

return true;
}

@Override
public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {
context.getMatrices().push();

context.getMatrices().translate(x + this.blockSizing / 2f, y + this.blockSizing / 2f, 2000);
context.getMatrices().scale(40 * this.blockSizing / 64f, -40 * this.blockSizing / 64f, 40);
context.getMatrices().translate(x + this.width / 2f, y + this.height / 2f, 400);
context.getMatrices().scale(40 * this.width / 64f, -40 * this.height / 64f, 40);

context.getMatrices().multiply(RotationAxis.POSITIVE_X.rotationDegrees(35));
context.getMatrices().multiply(RotationAxis.POSITIVE_X.rotationDegrees(30));
context.getMatrices().multiply(RotationAxis.POSITIVE_Y.rotationDegrees(45 + 180 + mouseRotation));

mouseRotation += mouseRotationSpeed;
Expand Down

0 comments on commit 2636d61

Please sign in to comment.