Skip to content

Commit f538b5b

Browse files
committed
- SmithDisplay
1 parent 16b254b commit f538b5b

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

common/src/main/java/smartin/miapi/client/gui/crafting/CraftingScreen.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import smartin.miapi.client.gui.TransformableWidget;
2121
import smartin.miapi.client.gui.crafting.crafter.ModuleCrafter;
2222
import smartin.miapi.client.gui.crafting.slotdisplay.SlotDisplay;
23+
import smartin.miapi.client.gui.crafting.slotdisplay.SmithDisplay;
2324
import smartin.miapi.client.gui.crafting.statdisplay.StatDisplay;
2425
import smartin.miapi.item.ModularItemStackConverter;
2526
import smartin.miapi.modules.ItemModule;
@@ -38,6 +39,7 @@ public class CraftingScreen extends ParentHandledScreen<CraftingScreenHandler> i
3839
private ModuleCrafter moduleCrafter;
3940
private StatDisplay statDisplay;
4041
private SlotDisplay slotDisplay;
42+
private SmithDisplay smithDisplay;
4143
private SlotProperty.ModuleSlot baseSlot;
4244
@Nullable
4345
public SlotProperty.ModuleSlot slot;
@@ -66,6 +68,7 @@ public void selectSlot(SlotProperty.ModuleSlot slot) {
6668
public void previewStack(ItemStack itemStack) {
6769
slotDisplay.setItem(itemStack);
6870
statDisplay.setCompareTo(itemStack);
71+
smithDisplay.setPreview(itemStack);
6972
}
7073

7174
public void selectEditOption(EditOption editOption) {
@@ -87,6 +90,7 @@ public void init() {
8790
}, (item) -> {
8891
slotDisplay.setItem(item);
8992
statDisplay.setCompareTo(item);
93+
smithDisplay.setPreview(item);
9094
}, handler.inventory,
9195
handler::addSlotByClient, handler::removeSlotByClient);
9296
moduleCrafter.setPacketIdentifier(handler.packetID);
@@ -97,6 +101,8 @@ public void init() {
97101
});
98102
slotDisplay.setItem(getItem());
99103
this.addChild(slotDisplay);
104+
smithDisplay = new SmithDisplay(centerX + 140, centerY + 117, 55, 70);
105+
this.addChild(smithDisplay);
100106
statDisplay = new StatDisplay(centerX + 213, centerY + 30, 160, 95);
101107
this.addChild(statDisplay);
102108

@@ -147,6 +153,9 @@ private void updateItem(ItemStack stack) {
147153
slotDisplay.select(current);
148154
slotDisplay.setItem(converted);
149155
}
156+
if(smithDisplay != null){
157+
smithDisplay.setPreview(converted);
158+
}
150159
if (moduleCrafter != null) {
151160
moduleCrafter.setBaseSlot(current);
152161
moduleCrafter.setItem(converted);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package smartin.miapi.client.gui.crafting.slotdisplay;
2+
3+
import net.minecraft.client.MinecraftClient;
4+
import net.minecraft.client.gui.DrawContext;
5+
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
6+
import net.minecraft.entity.EquipmentSlot;
7+
import net.minecraft.entity.LivingEntity;
8+
import net.minecraft.entity.decoration.ArmorStandEntity;
9+
import net.minecraft.item.ArmorItem;
10+
import net.minecraft.item.Item;
11+
import net.minecraft.item.ItemStack;
12+
import net.minecraft.text.Text;
13+
import org.jetbrains.annotations.Nullable;
14+
import org.joml.Quaternionf;
15+
import smartin.miapi.client.gui.InteractAbleWidget;
16+
17+
public class SmithDisplay extends InteractAbleWidget {
18+
public static final Quaternionf ARMOR_STAND_ROTATION = new Quaternionf().rotationXYZ(0.43633232f, 0.0f, (float) Math.PI);
19+
@Nullable
20+
private ArmorStandEntity armorStand;
21+
22+
public SmithDisplay(int x, int y, int width, int height) {
23+
super(x, y, width, height, Text.empty());
24+
this.armorStand = new ArmorStandEntity(MinecraftClient.getInstance().world, 0.0, 0.0, 0.0);
25+
this.armorStand.setHideBasePlate(true);
26+
this.armorStand.setShowArms(true);
27+
this.armorStand.bodyYaw = 210.0f;
28+
this.armorStand.setPitch(25.0f);
29+
this.armorStand.headYaw = this.armorStand.getYaw();
30+
this.armorStand.prevHeadYaw = this.armorStand.getYaw();
31+
this.equipArmorStand(ItemStack.EMPTY);
32+
}
33+
34+
public void setPreview(ItemStack itemStack) {
35+
equipArmorStand(itemStack);
36+
}
37+
38+
private void equipArmorStand(ItemStack stack) {
39+
if (this.armorStand == null) {
40+
return;
41+
}
42+
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
43+
this.armorStand.equipStack(equipmentSlot, ItemStack.EMPTY);
44+
}
45+
if (!stack.isEmpty()) {
46+
ItemStack itemStack = stack.copy();
47+
Item item = stack.getItem();
48+
if (item instanceof ArmorItem) {
49+
ArmorItem armorItem = (ArmorItem) item;
50+
this.armorStand.equipStack(armorItem.getSlotType(), itemStack);
51+
} else {
52+
this.armorStand.equipStack(EquipmentSlot.OFFHAND, itemStack);
53+
}
54+
}
55+
}
56+
57+
@Override
58+
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
59+
//context.enableScissor(getX(),getY(),getX()+getWidth(),getY()+getHeight());
60+
InventoryScreen.drawEntity(context, this.getX() + getWidth() / 2 + 10, this.getY() + this.height - 10, 30, ARMOR_STAND_ROTATION, null, (LivingEntity) this.armorStand);
61+
//context.disableScissor();
62+
super.render(context, mouseX, mouseY, delta);
63+
}
64+
}

common/src/main/java/smartin/miapi/client/gui/crafting/statdisplay/MiningLevelStatDisplay.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public int getWidthDesired() {
108108

109109
@Override
110110
public InteractAbleWidget getHoverWidget() {
111-
return hoverDescription;
111+
return null ;
112112
}
113113

114114
@Override
@@ -174,6 +174,16 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
174174
textWidget.render(drawContext, mouseX, mouseY, delta);
175175
}
176176

177+
@Override
178+
public void renderHover(DrawContext drawContext, int mouseX, int mouseY, float delta) {
179+
if (isMouseOver(mouseX, mouseY)) {
180+
Text text1 = this.hover.resolve(compareTo);
181+
if(!text1.getString().isEmpty()){
182+
drawContext.drawTooltip(MinecraftClient.getInstance().textRenderer, this.hover.resolve(compareTo), mouseX, mouseY);
183+
}
184+
}
185+
}
186+
177187
public static Builder builder(String type) {
178188
return new Builder(type);
179189
}

common/src/main/java/smartin/miapi/client/gui/crafting/statdisplay/SingleStatDisplayDouble.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,17 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
148148
textWidget.render(drawContext, mouseX, mouseY, delta);
149149
}
150150

151+
@Override
152+
public void renderHover(DrawContext drawContext, int mouseX, int mouseY, float delta) {
153+
if (isMouseOver(mouseX, mouseY)) {
154+
Text text1 = this.hover.resolve(compareTo);
155+
if(!text1.getString().isEmpty()){
156+
drawContext.drawTooltip(MinecraftClient.getInstance().textRenderer, this.hover.resolve(compareTo), mouseX, mouseY);
157+
}
158+
}
159+
}
160+
151161
public InteractAbleWidget getHoverWidget() {
152-
return hoverDescription;
162+
return null;
153163
}
154164
}

0 commit comments

Comments
 (0)