-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
280 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
common/src/main/java/rearth/oritech/block/blocks/reactor/ReactorRodBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
package rearth.oritech.block.blocks.reactor; | ||
|
||
public class ReactorRodBlock extends BaseReactorBlock { | ||
public ReactorRodBlock(Settings settings) { | ||
|
||
private final int rodCount; | ||
private final int internalPulseCount; | ||
|
||
public ReactorRodBlock(Settings settings, int rodCount, int internalPulseCount) { | ||
super(settings); | ||
this.rodCount = rodCount; | ||
this.internalPulseCount = internalPulseCount; | ||
} | ||
|
||
public int getRodCount() { | ||
return rodCount; | ||
} | ||
|
||
public int getInternalPulseCount() { | ||
return internalPulseCount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
common/src/main/java/rearth/oritech/client/ui/ReactorScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package rearth.oritech.client.ui; | ||
|
||
import io.wispforest.owo.ui.base.BaseOwoHandledScreen; | ||
import io.wispforest.owo.ui.component.Components; | ||
import io.wispforest.owo.ui.container.Containers; | ||
import io.wispforest.owo.ui.container.FlowLayout; | ||
import io.wispforest.owo.ui.core.*; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ReactorScreen extends BaseOwoHandledScreen<FlowLayout, ReactorScreenHandler> { | ||
|
||
public ReactorScreen(ReactorScreenHandler handler, PlayerInventory inventory, Text title) { | ||
super(handler, inventory, title); | ||
} | ||
|
||
@Override | ||
protected @NotNull OwoUIAdapter<FlowLayout> createAdapter() { | ||
return OwoUIAdapter.create(this, Containers::verticalFlow); | ||
} | ||
|
||
@Override | ||
protected void build(FlowLayout rootComponent) { | ||
rootComponent | ||
.surface(Surface.VANILLA_TRANSLUCENT) | ||
.horizontalAlignment(HorizontalAlignment.CENTER) | ||
.verticalAlignment(VerticalAlignment.CENTER); | ||
|
||
var overlay = Containers.horizontalFlow(Sizing.fixed(240), Sizing.fixed(200)); | ||
|
||
if (handler.reactorEntity.uiData != null) { | ||
addReactorComponentPreview(overlay); | ||
} | ||
|
||
rootComponent.child(overlay.surface(Surface.PANEL)); | ||
|
||
addTitle(overlay); | ||
} | ||
|
||
private void addReactorComponentPreview(FlowLayout overlay) { | ||
|
||
var holoPreviewContainer = Containers.horizontalFlow(Sizing.fixed(180), Sizing.fixed(180)); | ||
holoPreviewContainer.surface(Surface.PANEL_INSET); | ||
holoPreviewContainer.margins(Insets.of(2)); | ||
|
||
var uiData = handler.reactorEntity.uiData; | ||
var rightMostPoint = uiData.min(); | ||
var leftMostPoint = uiData.previewMax(); | ||
var dist = rightMostPoint.getManhattanDistance(leftMostPoint); | ||
|
||
var availableDist = 170 / 20; | ||
var scaling = availableDist / (float) dist * 2; | ||
if (dist > 10) scaling *= 1.15f; | ||
|
||
System.out.println(dist + " | " + scaling); | ||
|
||
BlockPos.stream(uiData.min(), uiData.previewMax()).forEach(pos -> { | ||
var offset = pos.subtract(uiData.min()); | ||
var uiPos = new BlockPos(-offset.getX(), offset.getY(), -offset.getZ()); | ||
var preview = Components.block(handler.world.getBlockState(pos), handler.world.getBlockEntity(pos)) | ||
.sizing(Sizing.fixed(170)) | ||
.positioning(Positioning.absolute(5, 85)); | ||
if (uiPos.getY() == 1) { | ||
System.out.println("added tooltip!"); | ||
preview.tooltip(handler.world.getBlockState(pos).getBlock().getName()); | ||
} | ||
holoPreviewContainer.child(preview); | ||
|
||
}); | ||
|
||
overlay.child(holoPreviewContainer); | ||
|
||
} | ||
|
||
private void addTitle(FlowLayout overlay) { | ||
var blockTitle = handler.reactorEntity.getCachedState().getBlock().getName(); | ||
var label = Components.label(blockTitle); | ||
label.color(new Color(64 / 255f, 64 / 255f, 64 / 255f)); | ||
label.sizing(Sizing.fixed(176), Sizing.content(2)); | ||
label.horizontalTextAlignment(HorizontalAlignment.CENTER); | ||
label.zIndex(1); | ||
overlay.child(label.positioning(Positioning.relative(50, 2))); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
common/src/main/java/rearth/oritech/client/ui/ReactorScreenHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package rearth.oritech.client.ui; | ||
|
||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.world.World; | ||
import rearth.oritech.block.entity.reactor.ReactorControllerBlockEntity; | ||
import rearth.oritech.client.init.ModScreens; | ||
|
||
public class ReactorScreenHandler extends ScreenHandler { | ||
|
||
public final ReactorControllerBlockEntity reactorEntity; | ||
public final World world; | ||
|
||
// this calls the second version | ||
public ReactorScreenHandler(int syncId, PlayerInventory inventory, ModScreens.BasicData setupData) { | ||
this(syncId, inventory, inventory.player.getWorld().getBlockEntity(setupData.pos())); | ||
} | ||
|
||
// on server, also called from client constructor | ||
public ReactorScreenHandler(int syncId, PlayerInventory playerInventory, BlockEntity blockEntity) { | ||
super(ModScreens.REACTOR_SCREEN, syncId); | ||
|
||
reactorEntity = (ReactorControllerBlockEntity) blockEntity; | ||
world = blockEntity.getWorld(); | ||
} | ||
|
||
@Override | ||
public ItemStack quickMove(PlayerEntity player, int slot) { | ||
return ItemStack.EMPTY; | ||
} | ||
public boolean canUse(PlayerEntity player) { | ||
return true; | ||
} | ||
|
||
public static class HandlerFactory implements ExtendedScreenHandlerType.ExtendedFactory<ReactorScreenHandler, ModScreens.BasicData> { | ||
@Override | ||
public ReactorScreenHandler create(int syncId, PlayerInventory inventory, ModScreens.BasicData data) { | ||
return new ReactorScreenHandler(syncId, inventory, data); | ||
} | ||
} | ||
} |
Oops, something went wrong.