Skip to content

Commit c90b3b8

Browse files
committed
✨ Updated to Minecraft 1.21.9
1 parent c1cf356 commit c90b3b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+548
-505
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
plugins {
2+
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7"
23
id 'fabric-loom' version '1.11-SNAPSHOT' apply false
3-
id 'net.neoforged.moddev' version '2.0.103' apply false
4+
id 'net.neoforged.gradle.userdev' version '7.0.192' apply false
5+
id 'net.neoforged.moddev' version '2.0.111' apply false
46
}

common/src/main/java/com/mrcrayfish/controllable/client/InputHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import net.minecraft.client.gui.screens.recipebook.RecipeBookTabButton;
6161
import net.minecraft.client.gui.screens.recipebook.RecipeButton;
6262
import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener;
63+
import net.minecraft.client.input.MouseButtonInfo;
6364
import net.minecraft.client.multiplayer.ServerData;
6465
import net.minecraft.client.player.ClientInput;
6566
import net.minecraft.client.player.LocalPlayer;
@@ -371,7 +372,7 @@ public static void toggleCraftBook(Context context)
371372
// Since no reference to craft book button, instead search for it and invoke press.
372373
ClientServices.CLIENT.getScreenRenderables(screen).stream().filter(widget -> {
373374
return widget instanceof ImageButton btn && RecipeBookComponent.RECIPE_BUTTON_SPRITES.equals(ClientServices.CLIENT.getImageButtonResource(btn));
374-
}).findFirst().ifPresent(btn -> ((Button) btn).onPress());
375+
}).findFirst().ifPresent(btn -> ((Button) btn).onPress(new MouseButtonInfo(0, 0)));
375376
boolean visible = optional.get().isVisible();
376377
Minecraft.getInstance()
377378
.getSoundManager()

common/src/main/java/com/mrcrayfish/controllable/client/binding/ButtonBindings.java

Lines changed: 65 additions & 67 deletions
Large diffs are not rendered by default.

common/src/main/java/com/mrcrayfish/controllable/client/gui/RadialItemList.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import net.minecraft.client.gui.narration.NarratableEntry;
1818
import net.minecraft.client.gui.narration.NarratedElementType;
1919
import net.minecraft.client.gui.narration.NarrationElementOutput;
20+
import net.minecraft.client.input.MouseButtonEvent;
2021
import net.minecraft.network.chat.Component;
2122
import net.minecraft.util.Mth;
2223

@@ -79,12 +80,32 @@ protected int scrollBarX()
7980
protected void updateWidgetNarration(NarrationElementOutput output) {}
8081

8182
@Override
82-
protected void renderSelection(GuiGraphics graphics, int rowTop, int rowWidth, int rowHeight, int outlineColour, int backgroundColour)
83+
protected void renderListItems(GuiGraphics graphics, int mouseX, int mouseY, float partialTick)
8384
{
84-
int left = this.getRowLeft();
85-
int right = this.getRowRight();
86-
graphics.fill(left, rowTop - 2, right, rowTop + rowHeight + 2, outlineColour);
87-
graphics.fill(left + 1, rowTop - 1, right - 1, rowTop + rowHeight + 1, backgroundColour);
85+
List<RadialItemList.ButtonBindingEntry> entries = this.children();
86+
for(int i = 0; i < entries.size(); i++)
87+
{
88+
var entry = entries.get(i);
89+
if(entry.getY() + entry.getHeight() >= this.getY() && entry.getY() <= this.getBottom())
90+
{
91+
if(i % 2 != 0)
92+
{
93+
graphics.fill(entry.getX(), entry.getY(), entry.getX() + entry.getWidth(), entry.getY() + entry.getHeight(), 0x55000000);
94+
}
95+
this.renderItem(graphics, mouseX, mouseY, partialTick, entry);
96+
}
97+
}
98+
}
99+
100+
@Override
101+
protected void renderSelection(GuiGraphics graphics, ButtonBindingEntry entry, int outlineColour)
102+
{
103+
int left = entry.getX();
104+
int right = entry.getX() + entry.getWidth();
105+
int top = entry.getY();
106+
int bottom = entry.getY() + entry.getHeight();
107+
graphics.fill(left, top, right, bottom, outlineColour);
108+
graphics.fill(left + 1, top + 1, right - 1, bottom -1, 0xFF111111);
88109
}
89110

90111
public class ButtonBindingEntry extends ContainerObjectSelectionList.Entry<ButtonBindingEntry>
@@ -162,32 +183,28 @@ public List<? extends GuiEventListener> children()
162183
}
163184

164185
@Override
165-
public void render(GuiGraphics graphics, int slotIndex, int top, int left, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean hovered, float partialTicks)
186+
public void renderContent(GuiGraphics graphics, int mouseX, int mouseY, boolean hovered, float partialTick)
166187
{
167-
if(slotIndex % 2 != 0)
168-
{
169-
graphics.fill(left, top - 2, left + rowWidth, top + rowHeight + 2, 0x55000000);
170-
}
171188
Font font = RadialItemList.this.minecraft.font;
172-
graphics.drawString(font, this.label, left + 5, top + 5, 0xFFFFFFFF);
173-
graphics.drawString(font, this.description, left + 5, top + 18, 0xFFFFFFFF);
189+
graphics.drawString(font, this.label, this.getX() + 5, this.getY() + 7, 0xFFFFFFFF);
190+
graphics.drawString(font, this.description, this.getX() + 5, this.getY() + 20, 0xFFFFFFFF);
174191
for(int i = 0; i < this.buttons.length; i++)
175192
{
176193
int offset = (this.buttons.length - i) * 22;
177-
int buttonLeft = left + rowWidth - 6 - offset;
194+
int buttonLeft = this.getX() + this.getWidth() - 6 - offset;
178195
this.buttons[i].visible = RadialItemList.this.getSelected() == this;
179196
this.buttons[i].setX(buttonLeft);
180-
this.buttons[i].setY(top + 6);
181-
this.buttons[i].render(graphics, mouseX, mouseY, partialTicks);
197+
this.buttons[i].setY(this.getY() + 8);
198+
this.buttons[i].render(graphics, mouseX, mouseY, partialTick);
182199
}
183200
}
184201

185202
@Override
186-
public boolean mouseClicked(double mouseX, double mouseY, int button)
203+
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick)
187204
{
188205
RadialItemList.this.setSelected(this);
189206
RadialItemList.this.selectedBinding = this.data.getBinding();
190-
return super.mouseClicked(mouseX, mouseY, button);
207+
return super.mouseClicked(event, doubleClick);
191208
}
192209

193210
@Override

common/src/main/java/com/mrcrayfish/controllable/client/gui/components/ButtonBindingList.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import net.minecraft.client.gui.narration.NarratableEntry;
2626
import net.minecraft.client.gui.narration.NarratedElementType;
2727
import net.minecraft.client.gui.narration.NarrationElementOutput;
28+
import net.minecraft.client.input.MouseButtonEvent;
2829
import net.minecraft.network.chat.CommonComponents;
2930
import net.minecraft.network.chat.Component;
3031
import org.lwjgl.glfw.GLFW;
@@ -48,14 +49,14 @@ public ButtonBindingList(SettingsScreen settingsScreen, Minecraft mc, int itemHe
4849
{
4950
super(mc, itemHeight);
5051
this.settingsScreen = settingsScreen;
51-
this.categories.put("key.categories.controllable_custom", new ArrayList<>());
52-
this.categories.put("key.categories.movement", new ArrayList<>());
53-
this.categories.put("key.categories.gameplay", new ArrayList<>());
54-
this.categories.put("key.categories.inventory", new ArrayList<>());
55-
this.categories.put("key.categories.creative", new ArrayList<>());
56-
this.categories.put("key.categories.multiplayer", new ArrayList<>());
57-
this.categories.put("key.categories.ui", new ArrayList<>());
58-
this.categories.put("key.categories.misc", new ArrayList<>());
52+
this.categories.put("key.category.controllable.custom", new ArrayList<>());
53+
this.categories.put("key.category.minecraft.movement", new ArrayList<>());
54+
this.categories.put("key.category.minecraft.gameplay", new ArrayList<>());
55+
this.categories.put("key.category.minecraft.inventory", new ArrayList<>());
56+
this.categories.put("key.category.minecraft.creative", new ArrayList<>());
57+
this.categories.put("key.category.minecraft.multiplayer", new ArrayList<>());
58+
this.categories.put("key.category.controllable.ui", new ArrayList<>());
59+
this.categories.put("key.category.minecraft.misc", new ArrayList<>());
5960
this.repopulateBindings(false);
6061
}
6162

@@ -175,18 +176,18 @@ public List<? extends GuiEventListener> children()
175176

176177
@Override
177178
@SuppressWarnings("ConstantConditions")
178-
public void render(GuiGraphics graphics, int index, int top, int left, int width, int itemHeight, int mouseX, int mouseY, boolean selected, float partialTick)
179+
public void renderContent(GuiGraphics graphics, int mouseX, int mouseY, boolean hovered, float partialTick)
179180
{
180181
this.updateTooltip(graphics, mouseX, mouseY);
181182
this.setLabelColor(this.binding.isConflictingContext() ? ChatFormatting.RED.getColor() : ChatFormatting.WHITE.getColor());
182-
super.render(graphics, index, top, left, width, itemHeight, mouseX, mouseY, selected, partialTick);
183+
super.renderContent(graphics, mouseX, mouseY, hovered, partialTick);
183184
this.bindingButton.setTooltip(ClientHelper.createListTooltip(this.getBindingTooltip(this.binding)));
184185
this.bindingButton.setTooltipDelay(Duration.ofMillis(400));
185-
this.bindingButton.setX(left + width - 65);
186-
this.bindingButton.setY(top);
186+
this.bindingButton.setX(this.getX() + this.getWidth() - 65);
187+
this.bindingButton.setY(this.getY() + 2);
187188
this.bindingButton.render(graphics, mouseX, mouseY, partialTick);
188-
this.resetButton.setX(left + width - 24);
189-
this.resetButton.setY(top);
189+
this.resetButton.setX(this.getX() + width - 24);
190+
this.resetButton.setY(this.getY() + 2);
190191
this.resetButton.active = !this.binding.isDefault();
191192
this.resetButton.render(graphics, mouseX, mouseY, partialTick);
192193
}
@@ -206,14 +207,14 @@ private void updateTooltip(GuiGraphics graphics, double mouseX, double mouseY)
206207
}
207208

208209
@Override
209-
public boolean mouseClicked(double mouseX, double mouseY, int button)
210+
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick)
210211
{
211212
Controller controller = Controllable.getController();
212213
if(!this.resetButton.isHovered() && controller != null && controller.isBeingUsed())
213214
{
214-
this.bindingButton.mouseClicked(this.bindingButton.getX(), this.bindingButton.getY(), button);
215+
this.bindingButton.mouseClicked(new MouseButtonEvent(this.bindingButton.getX(), this.bindingButton.getY(), event.buttonInfo()), doubleClick);
215216
}
216-
return super.mouseClicked(mouseX, mouseY, button);
217+
return super.mouseClicked(event, doubleClick);
217218
}
218219

219220
@Override
@@ -247,11 +248,11 @@ public OneWidgetItem(AbstractWidget widget)
247248
}
248249

249250
@Override
250-
public void render(GuiGraphics graphics, int x, int top, int left, int width, int height, int mouseX, int mouseY, boolean selected, float partialTick)
251+
public void renderContent(GuiGraphics graphics, int mouseX, int mouseY, boolean hovered, float partialTick)
251252
{
252-
this.widget.setWidth(width - 10);
253-
this.widget.setX(left + 5);
254-
this.widget.setY(top);
253+
this.widget.setWidth(this.getWidth() - 10);
254+
this.widget.setX(this.getX() + 5);
255+
this.widget.setY(this.getY() + 2);
255256
this.widget.render(graphics, mouseX, mouseY, partialTick);
256257
}
257258

@@ -275,15 +276,15 @@ public TwoWidgetItem(AbstractWidget leftWidget, AbstractWidget rightWidget)
275276
}
276277

277278
@Override
278-
public void render(GuiGraphics graphics, int x, int top, int left, int width, int height, int mouseX, int mouseY, boolean selected, float partialTick)
279+
public void renderContent(GuiGraphics graphics, int mouseX, int mouseY, boolean hovered, float partialTick)
279280
{
280-
this.leftWidget.setWidth(width / 2 - 10);
281-
this.leftWidget.setX(left + 5);
282-
this.leftWidget.setY(top);
281+
this.leftWidget.setWidth(this.getWidth() / 2 - 10);
282+
this.leftWidget.setX(this.getX() + 5);
283+
this.leftWidget.setY(this.getY() + 2);
283284
this.leftWidget.render(graphics, mouseX, mouseY, partialTick);
284-
this.rightWidget.setWidth(width / 2 - 10);
285-
this.rightWidget.setX(left + width / 2 + 5);
286-
this.rightWidget.setY(top);
285+
this.rightWidget.setWidth(this.getWidth() / 2 - 10);
286+
this.rightWidget.setX(this.getX() + this.getWidth() / 2 + 5);
287+
this.rightWidget.setY(this.getY() + 2);
287288
this.rightWidget.render(graphics, mouseX, mouseY, partialTick);
288289
}
289290

common/src/main/java/com/mrcrayfish/controllable/client/gui/components/ControllerList.java

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
package com.mrcrayfish.controllable.client.gui.components;
22

3-
import com.mojang.blaze3d.systems.RenderSystem;
43
import com.mrcrayfish.controllable.Controllable;
54
import com.mrcrayfish.controllable.client.gui.Icons;
65
import com.mrcrayfish.controllable.client.input.Controller;
76
import com.mrcrayfish.controllable.client.input.AdaptiveControllerManager;
87
import com.mrcrayfish.controllable.client.input.MultiController;
9-
import com.mrcrayfish.controllable.client.util.ClientHelper;
108
import com.mrcrayfish.controllable.client.util.ScreenHelper;
119
import net.minecraft.ChatFormatting;
12-
import net.minecraft.Util;
1310
import net.minecraft.client.Minecraft;
1411
import net.minecraft.client.gui.Font;
1512
import net.minecraft.client.gui.GuiGraphics;
16-
import net.minecraft.client.gui.components.Tooltip;
1713
import net.minecraft.client.gui.screens.Screen;
18-
import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner;
14+
import net.minecraft.client.input.MouseButtonEvent;
1915
import net.minecraft.client.renderer.RenderPipelines;
20-
import net.minecraft.client.renderer.RenderType;
2116
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
2217
import net.minecraft.network.chat.ClickEvent;
2318
import net.minecraft.network.chat.Component;
24-
import net.minecraft.network.chat.FormattedText;
2519
import net.minecraft.network.chat.MutableComponent;
26-
import net.minecraft.network.chat.Style;
2720
import net.minecraft.resources.ResourceLocation;
2821
import net.minecraft.sounds.SoundEvents;
2922
import net.minecraft.util.FormattedCharSequence;
@@ -72,12 +65,6 @@ private void reloadControllers()
7265
this.updateSelected();
7366
}
7467

75-
@Override
76-
protected boolean isSelectedItem(int index)
77-
{
78-
return false;
79-
}
80-
8168
private void updateSelected()
8269
{
8370
Controller controller = Controllable.getController();
@@ -109,19 +96,19 @@ public void tick()
10996
}
11097

11198
@Override
112-
public boolean mouseClicked(double mouseX, double mouseY, int button)
99+
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick)
113100
{
114101
if(this.footerText != null)
115102
{
116103
Font font = this.minecraft.font;
117104
int footerWidth = font.width(this.footerText);
118105
int footerSubWidth = font.width(this.footerSubText);
119-
if(ScreenHelper.isMouseWithin(this.getX() + (this.width + footerWidth) / 2 - footerSubWidth, this.getBottom() + 4, footerSubWidth, 14, (int) mouseX, (int) mouseY))
106+
if(ScreenHelper.isMouseWithin(this.getX() + (this.width + footerWidth) / 2 - footerSubWidth, this.getBottom() + 4, footerSubWidth, 14, (int) event.x(), (int) event.y()))
120107
{
121108
Objects.requireNonNull(Minecraft.getInstance().screen).handleComponentClicked(this.footerSubText.getStyle());
122109
}
123110
}
124-
return super.mouseClicked(mouseX, mouseY, button);
111+
return super.mouseClicked(event, doubleClick);
125112
}
126113

127114
@Override
@@ -141,7 +128,7 @@ private void renderLinkedItems(GuiGraphics graphics, int mouseX, int mouseY)
141128
int start = -1, end = -1;
142129
for(int i = 0; i < this.getItemCount(); i++)
143130
{
144-
ControllerEntry entry = this.getEntry(i);
131+
ControllerEntry entry = this.children().get(i);
145132
if(jids.contains(entry.getJid()))
146133
{
147134
matchedEntries.add(i);
@@ -154,7 +141,7 @@ private void renderLinkedItems(GuiGraphics graphics, int mouseX, int mouseY)
154141
}
155142
if(start != end)
156143
{
157-
int itemCenter = (this.itemHeight - 4) / 2;
144+
int itemCenter = (this.defaultEntryHeight) / 2 - 1;
158145
int rowLeft = this.getRowLeft();
159146
int lineTop = this.getRowTop(start) + itemCenter;
160147
int lineEnd = this.getRowTop(end) + itemCenter;
@@ -204,28 +191,28 @@ public Number getJid()
204191
}
205192

206193
@Override
207-
public void render(GuiGraphics graphics, int slotIndex, int top, int left, int listWidth, int slotHeight, int mouseX, int mouseY, boolean hovered, float partialTicks)
194+
public void renderContent(GuiGraphics graphics, int mouseX, int mouseY, boolean hovered, float partialTick)
208195
{
209-
State state = this.getState();
210-
if(state != State.NONE)
196+
SelectedState state = this.getSelectedState();
197+
if(state != SelectedState.NONE)
211198
{
212-
ScreenHelper.drawRoundedBox(graphics, left - 1, top - 1, listWidth + 2, slotHeight + 2, 0xFFFFFFFF);
213-
ScreenHelper.drawRoundedBox(graphics, left, top, listWidth, slotHeight, 0xFF000000);
214-
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, CHECKMARK, left + 2, top, 18, 18);
199+
ScreenHelper.drawRoundedBox(graphics, this.getX(), this.getY(), this.getWidth(), this.getHeight(), 0xFFFFFFFF);
200+
ScreenHelper.drawRoundedBox(graphics, this.getX() + 1, this.getY() + 1, this.getWidth() - 2, this.getHeight() - 2, 0xFF000000);
201+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, CHECKMARK, this.getX() + 2, this.getY() + 2, 18, 18);
215202
}
216203
else if(Controllable.getController() != null && hovered)
217204
{
218-
graphics.blit(RenderPipelines.GUI_TEXTURED, Icons.TEXTURE, left + 4, top + 4, 110, 0, 11, 11, 11, 11, Icons.TEXTURE_WIDTH, Icons.TEXTURE_HEIGHT);
205+
graphics.blit(RenderPipelines.GUI_TEXTURED, Icons.TEXTURE, this.getX() + 4, this.getY() + 6, 110, 0, 11, 11, 11, 11, Icons.TEXTURE_WIDTH, Icons.TEXTURE_HEIGHT);
219206
graphics.setTooltipForNextFrame(Component.translatable("controllable.gui.link").withStyle(ChatFormatting.AQUA), mouseX, mouseY);
220207
}
221208
Font font = Minecraft.getInstance().font;
222-
graphics.drawString(font, this.label, left + 22, top + (slotHeight - font.lineHeight) / 2 + 1, 0xFFFFFFFF);
209+
graphics.drawString(font, this.label, this.getX() + 22, this.getY() + (this.getHeight() - font.lineHeight) / 2 + 1, 0xFFFFFFFF);
223210
}
224211

225212
@Override
226-
public boolean mouseClicked(double mouseX, double mouseY, int button)
213+
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick)
227214
{
228-
if(button == GLFW.GLFW_MOUSE_BUTTON_1)
215+
if(event.button() == GLFW.GLFW_MOUSE_BUTTON_1)
229216
{
230217
this.connect();
231218
minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.WOODEN_BUTTON_CLICK_ON, 1.75F));
@@ -252,23 +239,23 @@ else if(!manager.removeActiveController(controller))
252239
manager.updateLastDevices();
253240
}
254241

255-
private State getState()
242+
private SelectedState getSelectedState()
256243
{
257244
Controller controller = Controllable.getController();
258245
if(controller != null)
259246
{
260247
if(controller.getJid().equals(this.jid))
261-
return State.SELECTED;
248+
return SelectedState.SELECTED;
262249

263250
if(controller instanceof MultiController m)
264251
{
265252
if(m.getControllers().stream().anyMatch(c -> c.getJid().equals(this.jid)))
266253
{
267-
return State.MULTI_SELECTED;
254+
return SelectedState.MULTI_SELECTED;
268255
}
269256
}
270257
}
271-
return State.NONE;
258+
return SelectedState.NONE;
272259
}
273260

274261
@Nullable
@@ -289,7 +276,7 @@ private Controller getController()
289276
return null;
290277
}
291278

292-
public enum State
279+
public enum SelectedState
293280
{
294281
NONE,
295282
SELECTED,

0 commit comments

Comments
 (0)