-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #885 from Gu-ZT/releases/1.20.1
优化Emi配方显示
- Loading branch information
Showing
4 changed files
with
74 additions
and
28 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
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
45 changes: 40 additions & 5 deletions
45
common/src/main/java/dev/dubhe/anvilcraft/integration/emi/ui/BlockWidget.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,21 +1,56 @@ | ||
package dev.dubhe.anvilcraft.integration.emi.ui; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import dev.dubhe.anvilcraft.integration.emi.stack.BlockStateEmiStack; | ||
import dev.dubhe.anvilcraft.util.BlockStateRender; | ||
import dev.emi.emi.EmiPort; | ||
import dev.emi.emi.api.widget.Bounds; | ||
import dev.emi.emi.api.widget.DrawableWidget.DrawableWidgetConsumer; | ||
import dev.emi.emi.api.widget.Widget; | ||
import dev.emi.emi.api.widget.WidgetHolder; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class BlockWidget implements DrawableWidgetConsumer { | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class BlockWidget extends Widget implements DrawableWidgetConsumer { | ||
private final BlockState blockState; | ||
private final int posY; | ||
private final int offsetX; | ||
private final int offsetY; | ||
|
||
public BlockWidget(BlockState blockStates, int posY) { | ||
this.blockState = blockStates; | ||
private BlockWidget(BlockState blockState, int posY, int offsetX, int offsetY) { | ||
this.blockState = blockState; | ||
this.posY = posY; | ||
this.offsetX = offsetX; | ||
this.offsetY = offsetY; | ||
} | ||
|
||
public static void of(@NotNull WidgetHolder widgets, BlockState blockState, int posY, int offsetX, int offsetY) { | ||
widgets.add(new BlockWidget(blockState, posY, offsetX, offsetY)); | ||
} | ||
|
||
@Override | ||
public Bounds getBounds() { | ||
return new Bounds(this.offsetX, this.offsetY, 25, 25); | ||
} | ||
|
||
@Override | ||
public List<ClientTooltipComponent> getTooltip(int mouseX, int mouseY) { | ||
if (this.blockState.isAir()) return List.of(); | ||
return BlockStateEmiStack.getTooltipLines(this.blockState) | ||
.stream().map(EmiPort::ordered).map(ClientTooltipComponent::create).collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public void render(GuiGraphics draw, int mouseX, int mouseY, float delta) { | ||
BlockStateRender.renderBlocks(blockState, posY, draw, 25); | ||
public void render(@NotNull GuiGraphics draw, int mouseX, int mouseY, float delta) { | ||
PoseStack pose = draw.pose(); | ||
pose.pushPose(); | ||
pose.translate(this.offsetX, 25.0, 0.0); | ||
BlockStateRender.renderBlock(this.blockState, this.posY, draw, 25); | ||
pose.popPose(); | ||
} | ||
} |
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