Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 248fef3

Browse files
committed
feat: 1.19.3 update
1 parent 1f7b4be commit 248fef3

21 files changed

+97
-60
lines changed

common/src/main/java/com/github/franckyi/guapi/api/RenderHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static void drawTexture(PoseStack matrices, ResourceLocation id, int x, i
6767
}
6868

6969
public static void drawSprite(PoseStack matrices, TextureAtlasSprite sprite, int x, int y, int imageWidth, int imageHeight) {
70-
RenderSystem.setShaderTexture(0, sprite.atlas().location());
70+
RenderSystem.setShaderTexture(0, sprite.atlasLocation());
7171
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
7272
GuiComponent.blit(matrices, x, y, 0, imageWidth, imageHeight, sprite);
7373
}

common/src/main/java/com/github/franckyi/guapi/api/node/ItemView.java

+10
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ default boolean isDrawDecorations() {
2424
default void setDrawDecorations(boolean value) {
2525
drawDecorationsProperty().setValue(value);
2626
}
27+
28+
default boolean isDrawTooltip() {
29+
return drawTooltipProperty().getValue();
30+
}
31+
32+
BooleanProperty drawTooltipProperty();
33+
34+
default void setDrawTooltip(boolean value) {
35+
drawTooltipProperty().setValue(value);
36+
}
2737
}

common/src/main/java/com/github/franckyi/guapi/base/node/AbstractItemView.java

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public abstract class AbstractItemView extends AbstractControl implements ItemView {
99
private final ObjectProperty<ItemStack> itemProperty = ObjectProperty.create();
1010
private final BooleanProperty drawDecorationsProperty = BooleanProperty.create(false);
11+
private final BooleanProperty drawTooltipProperty = BooleanProperty.create(true);
1112

1213
protected AbstractItemView() {
1314
}
@@ -25,4 +26,9 @@ public ObjectProperty<ItemStack> itemProperty() {
2526
public BooleanProperty drawDecorationsProperty() {
2627
return drawDecorationsProperty;
2728
}
29+
30+
@Override
31+
public BooleanProperty drawTooltipProperty() {
32+
return drawTooltipProperty;
33+
}
2834
}

common/src/main/java/com/github/franckyi/guapi/base/theme/vanilla/VanillaItemViewSkin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void render(ItemView node, PoseStack matrices, int mouseX, int mouseY, fl
2828

2929
@Override
3030
public void postRender(ItemView node, PoseStack matrices, int mouseX, int mouseY, float delta) {
31-
if (node.isHovered() && node.getItem() != null) {
31+
if (node.isHovered() && node.getItem() != null && node.isDrawTooltip()) {
3232
RenderHelper.drawTooltip(matrices, node.getItem(), mouseX, mouseY);
3333
}
3434
super.postRender(node, matrices, mouseX, mouseY, delta);

common/src/main/java/com/github/franckyi/guapi/base/theme/vanilla/delegate/VanillaButtonSkinDelegate.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import com.github.franckyi.guapi.api.node.Button;
44

5+
import java.util.function.Supplier;
6+
57
public class VanillaButtonSkinDelegate<N extends Button> extends net.minecraft.client.gui.components.Button implements VanillaWidgetSkinDelegate {
68
protected final N node;
79

810
public VanillaButtonSkinDelegate(N node) {
911
super(node.getX(), node.getY(), node.getWidth(), node.getHeight(), node.getLabel(), button -> {
10-
});
12+
}, Supplier::get);
1113
this.node = node;
1214
initLabeledWidget(node);
1315
}

common/src/main/java/com/github/franckyi/guapi/base/theme/vanilla/delegate/VanillaCheckBoxSkinDelegate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float delt
4141
RenderSystem.enableBlend();
4242
RenderSystem.defaultBlendFunc();
4343
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
44-
blit(poseStack, x, y, isHoveredOrFocused() ? 16 : 0, selected() ? 16 : 0, 16, 16, 32, 32);
44+
blit(poseStack, getX(), getY(), isHoveredOrFocused() ? 16 : 0, selected() ? 16 : 0, 16, 16, 32, 32);
4545
renderBg(poseStack, mc, mouseX, mouseY);
46-
drawString(poseStack, mc.font, getMessage(), x + 20, y + (height - mc.font.lineHeight - 1) / 2, 14737632 | Mth.ceil(alpha * 255.0F) << 24);
46+
drawString(poseStack, mc.font, getMessage(), getX() + 20, getY() + (height - mc.font.lineHeight - 1) / 2, 14737632 | Mth.ceil(alpha * 255.0F) << 24);
4747
}
4848
}

common/src/main/java/com/github/franckyi/guapi/base/theme/vanilla/delegate/VanillaSliderSkinDelegate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
4747
}
4848

4949
private void updateNodeFromMouse(double mouseX) {
50-
updateNode((mouseX - (x + 4)) / (width - 8));
50+
updateNode((mouseX - (getX() + 4)) / (width - 8));
5151
}
5252

5353
private void updateNode(double newRawValue) {

common/src/main/java/com/github/franckyi/guapi/base/theme/vanilla/delegate/VanillaTextAreaSkinDelegate.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class VanillaTextAreaSkinDelegate<N extends TextArea> extends MultiLineEd
1313
private final MultilineTextFieldMixin textFieldMixin;
1414

1515
public VanillaTextAreaSkinDelegate(N node) {
16-
super(Minecraft.getInstance().font, node.getX(), node.getY(), node.getWidth(), node.getHeight(), node.getPlaceholder(), node.getLabel());
16+
super(Minecraft.getInstance().font, node.getX(), node.getY(), node.getWidth() - 8, node.getHeight(), node.getPlaceholder(), node.getLabel());
1717
this.node = node;
1818
self = (MultiLineEditBoxMixin) this;
1919
textFieldMixin = (MultilineTextFieldMixin) self.getTextField();
@@ -22,11 +22,11 @@ public VanillaTextAreaSkinDelegate(N node) {
2222
setValue(node.getText());
2323
setFocused(node.isFocused());
2424
setValueListener(node::setText);
25-
node.xProperty().addListener(newVal -> x = newVal);
26-
node.yProperty().addListener(newVal -> y = newVal);
25+
node.xProperty().addListener(this::setX);
26+
node.yProperty().addListener(this::setY);
2727
node.widthProperty().addListener(newVal -> {
28-
setWidth(newVal);
29-
textFieldMixin.setWidth(newVal);
28+
setWidth(newVal - 8);
29+
textFieldMixin.setWidth(newVal - 8);
3030
textFieldMixin.invokeReflowDisplayLines();
3131
});
3232
node.heightProperty().addListener(newVal -> height = newVal);

common/src/main/java/com/github/franckyi/guapi/base/theme/vanilla/delegate/VanillaTextFieldSkinDelegate.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public VanillaTextFieldSkinDelegate(N node) {
2828
setValue(node.getText());
2929
setFocused(node.isFocused());
3030
setResponder(node::setText);
31-
node.xProperty().addListener(newVal -> x = newVal + 1);
32-
node.yProperty().addListener(newVal -> y = newVal + 1);
31+
node.xProperty().addListener(newVal -> setX(newVal + 1));
32+
node.yProperty().addListener(newVal -> setY(newVal + 1));
3333
node.widthProperty().addListener(newVal -> setWidth(newVal - 2));
3434
node.heightProperty().addListener(newVal -> height = newVal - 2);
3535
node.disabledProperty().addListener(newVal -> active = !newVal);
@@ -137,7 +137,7 @@ protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY
137137
int displayPos = self.getDisplayPos();
138138
Font font = Minecraft.getInstance().font;
139139
FormattedText string = font.substrByWidth(renderText(getValue().substring(displayPos), displayPos), getInnerWidth());
140-
setHighlightPos(font.substrByWidth(string, Mth.floor(mouseX) - x - 4).getString().length() + displayPos);
140+
setHighlightPos(font.substrByWidth(string, Mth.floor(mouseX) - getX() - 4).getString().length() + displayPos);
141141
}
142142

143143
@Override
@@ -146,13 +146,13 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
146146
if (!isVisible()) {
147147
return false;
148148
} else {
149-
boolean flag = mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + height;
149+
boolean flag = mouseX >= getX() && mouseX < getX() + width && mouseY >= getY() && mouseY < getY() + height;
150150
if (self.canLoseFocus() && button == 0) {
151151
setFocus(flag);
152152
}
153153

154154
if (isFocused() && flag && button == 0) {
155-
int i = Mth.floor(mouseX) - x;
155+
int i = Mth.floor(mouseX) - getX();
156156
if (self.isBordered()) {
157157
i -= 4;
158158
}
@@ -172,8 +172,8 @@ public void renderButton(@NotNull PoseStack matrices, int mouseX, int mouseY, fl
172172
if (isVisible()) {
173173
if (self.isBordered()) {
174174
int i = isFocused() ? -1 : -6250336;
175-
fill(matrices, x - 1, y - 1, x + width + 1, y + height + 1, i);
176-
fill(matrices, x, y, x + width, y + height, -16777216);
175+
fill(matrices, getX() - 1, getY() - 1, getX() + width + 1, getY() + height + 1, i);
176+
fill(matrices, getX(), getY(), getX() + width, getY() + height, -16777216);
177177
}
178178

179179
int i2 = self.isEditable() ? self.getTextColor() : self.getTextColorUneditable();
@@ -185,8 +185,8 @@ public void renderButton(@NotNull PoseStack matrices, int mouseX, int mouseY, fl
185185
: font.plainSubstrByWidth(getValue().substring(self.getDisplayPos()), this.getInnerWidth());
186186
boolean flag = j >= 0 && j <= s.length();
187187
boolean flag1 = isFocused() && self.getFrame() / 6 % 2 == 0 && flag;
188-
int l = self.isBordered() ? x + 4 : x;
189-
int i1 = self.isBordered() ? y + (height - 8) / 2 : y;
188+
int l = self.isBordered() ? getX() + 4 : getX();
189+
int i1 = self.isBordered() ? getY() + (height - 8) / 2 : getY();
190190
int j1 = l;
191191
if (k > s.length()) {
192192
k = s.length();
@@ -237,7 +237,7 @@ public void renderButton(@NotNull PoseStack matrices, int mouseX, int mouseY, fl
237237
int previousTextWidth = font.width(previousText);
238238
Component highlightedText = renderText(getValue().substring(start, end), start);
239239
int highlightedTextWidth = font.width(highlightedText);
240-
int x0 = x + 4;
240+
int x0 = getX() + 4;
241241
self.invokeRenderHighlight(x0 + previousTextWidth, i1 - 1, x0 + previousTextWidth + highlightedTextWidth, i1 + 1 + 9);
242242
}
243243

common/src/main/java/com/github/franckyi/guapi/base/theme/vanilla/delegate/VanillaTexturedButtonSkinDelegate.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import net.minecraft.network.chat.Component;
77
import org.jetbrains.annotations.NotNull;
88

9+
import java.util.function.Supplier;
10+
911
public class VanillaTexturedButtonSkinDelegate<N extends TexturedButton> extends Button implements VanillaWidgetSkinDelegate {
1012
protected final N node;
1113

1214
public VanillaTexturedButtonSkinDelegate(N node) {
1315
super(node.getX(), node.getY(), node.getWidth(), node.getHeight(), node.getTooltip().isEmpty() ? Component.empty() : node.getTooltip().get(0), button -> {
14-
});
16+
}, Supplier::get);
1517
this.node = node;
1618
initNodeWidget(node);
1719
}

common/src/main/java/com/github/franckyi/guapi/base/theme/vanilla/delegate/VanillaWidgetSkinDelegate.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import com.github.franckyi.guapi.api.node.Node;
88
import com.github.franckyi.ibeeditor.mixin.AbstractWidgetMixin;
99
import net.minecraft.client.gui.components.AbstractWidget;
10-
import net.minecraft.client.gui.components.Widget;
1110
import net.minecraft.client.gui.components.events.GuiEventListener;
1211

13-
public interface VanillaWidgetSkinDelegate extends Renderable, EventTarget, GuiEventListener, Widget {
12+
public interface VanillaWidgetSkinDelegate extends Renderable, EventTarget, GuiEventListener {
1413
@Override
1514
default void mouseClicked(MouseButtonEvent event) {
1615
mouseClicked(event.getMouseX(), event.getMouseY(), event.getButton());
@@ -55,8 +54,8 @@ default void initNodeWidget(Node node) {
5554
AbstractWidget widget = (AbstractWidget) this;
5655
widget.active = !node.isDisabled();
5756
widget.visible = node.isVisible();
58-
node.xProperty().addListener(newVal -> widget.x = newVal);
59-
node.yProperty().addListener(newVal -> widget.y = newVal);
57+
node.xProperty().addListener(widget::setX);
58+
node.yProperty().addListener(widget::setY);
6059
node.widthProperty().addListener(widget::setWidth);
6160
node.heightProperty().addListener(((AbstractWidgetMixin) widget)::setHeight);
6261
node.disabledProperty().addListener(newVal -> widget.active = !newVal);

common/src/main/java/com/github/franckyi/ibeeditor/client/ClientCache.java

+23-18
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
import com.github.franckyi.ibeeditor.client.screen.model.selection.element.*;
55
import com.github.franckyi.ibeeditor.common.ColoredItemHelper;
66
import net.minecraft.client.Minecraft;
7+
import net.minecraft.core.HolderLookup;
78
import net.minecraft.core.Registry;
9+
import net.minecraft.core.registries.BuiltInRegistries;
10+
import net.minecraft.core.registries.Registries;
11+
import net.minecraft.resources.ResourceKey;
812
import net.minecraft.world.item.Item;
913
import net.minecraft.world.item.ItemStack;
1014
import net.minecraft.world.item.Items;
1115
import net.minecraft.world.item.enchantment.Enchantment;
1216
import net.minecraft.world.item.enchantment.EnchantmentCategory;
1317

1418
import java.util.ArrayList;
19+
import java.util.Comparator;
1520
import java.util.List;
1621

1722
public final class ClientCache {
@@ -29,23 +34,23 @@ public final class ClientCache {
2934
private static List<SpriteListSelectionElementModel> effectSelectionItems;
3035

3136
public static List<String> getItemSuggestions() {
32-
return itemSuggestions == null ? itemSuggestions = buildSuggestions(Registry.ITEM) : itemSuggestions;
37+
return itemSuggestions == null ? itemSuggestions = buildSuggestions(BuiltInRegistries.ITEM) : itemSuggestions;
3338
}
3439

3540
public static List<ItemListSelectionElementModel> getItemSelectionItems() {
3641
return itemSelectionItems == null ? itemSelectionItems = buildItemSelectionItems() : itemSelectionItems;
3742
}
3843

3944
public static List<String> getBlockSuggestions() {
40-
return blockSuggestions == null ? blockSuggestions = buildSuggestions(Registry.BLOCK) : blockSuggestions;
45+
return blockSuggestions == null ? blockSuggestions = buildSuggestions(BuiltInRegistries.BLOCK) : blockSuggestions;
4146
}
4247

4348
public static List<ItemListSelectionElementModel> getBlockSelectionItems() {
4449
return blockSelectionItems == null ? blockSelectionItems = buildBlockSelectionItems() : blockSelectionItems;
4550
}
4651

4752
public static List<String> getEnchantmentSuggestions() {
48-
return enchantmentSuggestions == null ? enchantmentSuggestions = buildSuggestions(Registry.ENCHANTMENT) : enchantmentSuggestions;
53+
return enchantmentSuggestions == null ? enchantmentSuggestions = buildSuggestions(BuiltInRegistries.ENCHANTMENT) : enchantmentSuggestions;
4954
}
5055

5156
public static List<SortedEnchantmentListSelectionElementModel> getSortedEnchantmentSelectionItems(ItemStack target) {
@@ -84,23 +89,23 @@ public static List<SortedEnchantmentListSelectionElementModel> getSortedEnchantm
8489
}
8590

8691
public static List<String> getAttributeSuggestions() {
87-
return attributeSuggestions == null ? attributeSuggestions = buildSuggestions(Registry.ATTRIBUTE) : attributeSuggestions;
92+
return attributeSuggestions == null ? attributeSuggestions = buildSuggestions(BuiltInRegistries.ATTRIBUTE) : attributeSuggestions;
8893
}
8994

9095
public static List<ListSelectionElementModel> getAttributeSelectionItems() {
9196
return attributeSelectionItems == null ? attributeSelectionItems = buildAttributeSelectionItems() : attributeSelectionItems;
9297
}
9398

9499
public static List<String> getPotionSuggestions() {
95-
return potionSuggestions == null ? potionSuggestions = buildSuggestions(Registry.POTION) : potionSuggestions;
100+
return potionSuggestions == null ? potionSuggestions = buildSuggestions(BuiltInRegistries.POTION) : potionSuggestions;
96101
}
97102

98103
public static List<ItemListSelectionElementModel> getPotionSelectionItems() {
99104
return potionSelectionItems == null ? potionSelectionItems = buildPotionSelectionItems() : potionSelectionItems;
100105
}
101106

102107
public static List<String> getEffectSuggestions() {
103-
return effectSuggestions == null ? effectSuggestions = buildSuggestions(Registry.MOB_EFFECT) : effectSuggestions;
108+
return effectSuggestions == null ? effectSuggestions = buildSuggestions(BuiltInRegistries.MOB_EFFECT) : effectSuggestions;
104109
}
105110

106111
public static List<SpriteListSelectionElementModel> getEffectSelectionItems() {
@@ -122,21 +127,21 @@ private static List<String> buildSuggestions(Registry<?> registry) {
122127
}
123128

124129
private static List<ItemListSelectionElementModel> buildItemSelectionItems() {
125-
return Registry.ITEM.entrySet().stream()
130+
return BuiltInRegistries.ITEM.entrySet().stream()
126131
.map(e -> new ItemListSelectionElementModel(e.getValue().getDescriptionId(), e.getKey().location(), new ItemStack(e.getValue())))
127-
.toList();
132+
.sorted().toList();
128133
}
129134

130135
private static List<ItemListSelectionElementModel> buildBlockSelectionItems() {
131-
return Registry.BLOCK.entrySet().stream()
136+
return BuiltInRegistries.BLOCK.entrySet().stream()
132137
.map(e -> new ItemListSelectionElementModel(e.getValue().getDescriptionId(), e.getKey().location(), new ItemStack(e.getValue())))
133-
.toList();
138+
.sorted().toList();
134139
}
135140

136141
private static List<EnchantmentListSelectionElementModel> buildEnchantmentSelectionItems() {
137-
return Registry.ENCHANTMENT.entrySet().stream()
142+
return BuiltInRegistries.ENCHANTMENT.entrySet().stream()
138143
.map(e -> new EnchantmentListSelectionElementModel(e.getValue().getDescriptionId(), e.getKey().location(), e.getValue(), new ItemStack(getEnchantmentTypeItem(e.getValue()))))
139-
.toList();
144+
.sorted().toList();
140145
}
141146

142147
private static Item getEnchantmentTypeItem(Enchantment e) {
@@ -171,21 +176,21 @@ private static Item getEnchantmentTypeItem(Enchantment e) {
171176
}
172177

173178
private static List<ListSelectionElementModel> buildAttributeSelectionItems() {
174-
return Registry.ATTRIBUTE.entrySet().stream()
179+
return BuiltInRegistries.ATTRIBUTE.entrySet().stream()
175180
.map(e -> new ListSelectionElementModel(e.getValue().getDescriptionId(), e.getKey().location()))
176-
.toList();
181+
.sorted().toList();
177182
}
178183

179184
private static List<ItemListSelectionElementModel> buildPotionSelectionItems() {
180-
return Registry.POTION.entrySet().stream()
185+
return BuiltInRegistries.POTION.entrySet().stream()
181186
.map(e -> new ItemListSelectionElementModel(e.getValue().getName(Items.POTION.getDescriptionId() + ".effect."), e.getKey().location(), ColoredItemHelper.createColoredPotionItem(e.getKey().location(), Color.NONE)))
182-
.toList();
187+
.sorted().toList();
183188
}
184189

185190
private static List<SpriteListSelectionElementModel> buildEffectSelectionItems() {
186-
return Registry.MOB_EFFECT.entrySet().stream()
191+
return BuiltInRegistries.MOB_EFFECT.entrySet().stream()
187192
.map(e -> new SpriteListSelectionElementModel(e.getValue().getDescriptionId(), e.getKey().location(), () -> Minecraft.getInstance().getMobEffectTextures().get(e.getValue())))
188-
.toList();
193+
.sorted().toList();
189194
}
190195

191196
}

common/src/main/java/com/github/franckyi/ibeeditor/client/context/BlockEditorContext.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.github.franckyi.ibeeditor.common.ModTexts;
44
import net.minecraft.core.BlockPos;
55
import net.minecraft.core.Registry;
6+
import net.minecraft.core.registries.BuiltInRegistries;
67
import net.minecraft.nbt.CompoundTag;
78
import net.minecraft.network.chat.Component;
89
import net.minecraft.network.chat.MutableComponent;
@@ -47,7 +48,7 @@ public String getCommandName() {
4748
@Override
4849
protected String getCommand() {
4950
String blockStateStr = getBlockState().toString();
50-
return String.format("/setblock ~ ~ ~ %s%s%s replace", Registry.BLOCK.getKey(getBlockState().getBlock()),
51+
return String.format("/setblock ~ ~ ~ %s%s%s replace", BuiltInRegistries.BLOCK.getKey(getBlockState().getBlock()),
5152
getBlockState().getProperties().isEmpty() ? "" : blockStateStr.substring(blockStateStr.indexOf("[")), getTag());
5253
}
5354
}

common/src/main/java/com/github/franckyi/ibeeditor/client/logic/ClientEditorRequestLogic.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import net.minecraft.world.Container;
1818
import net.minecraft.world.entity.player.Inventory;
1919
import net.minecraft.world.item.CreativeModeTab;
20+
import net.minecraft.world.item.CreativeModeTabs;
2021
import net.minecraft.world.phys.BlockHitResult;
2122
import net.minecraft.world.phys.EntityHitResult;
2223
import net.minecraft.world.phys.HitResult;
@@ -90,7 +91,7 @@ public static boolean requestInventoryItemEditor(EditorType editorType, Abstract
9091
if (screen instanceof CreativeModeInventoryScreen c) {
9192
creativeInventoryScreen = true;
9293
// "survival inventory" creative tab slot indexes are different, need a hacky fix to get the actual inventory slot id
93-
if (c.getSelectedTab() == CreativeModeTab.TAB_INVENTORY.getId()) {
94+
if (c.isInventoryOpen()) {
9495
slotIndex = ClientUtil.convertCreativeInventorySlot(slotIndex);
9596
}
9697
}

0 commit comments

Comments
 (0)