Skip to content

Commit ad56062

Browse files
committed
Merge branch 'param-ghosts'
# Conflicts: # gradle.properties # src/main/java/dev/dfonline/codeclient/mixin/MMouse.java
2 parents 89b5c2f + e92ae02 commit ad56062

38 files changed

Lines changed: 986 additions & 159 deletions

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.20.4+build.3
88
loader_version=0.15.3
99

1010
# Mod Properties
11-
mod_version=1.6.5
11+
mod_version=1.6.6
1212
maven_group=dev.dfonline
1313
archives_base_name=CodeClient
1414

src/main/java/dev/dfonline/codeclient/CodeClient.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
import dev.dfonline.codeclient.action.impl.DevForBuild;
77
import dev.dfonline.codeclient.config.Config;
88
import dev.dfonline.codeclient.config.KeyBinds;
9-
import dev.dfonline.codeclient.dev.BuildPhaser;
9+
import dev.dfonline.codeclient.dev.*;
1010
import dev.dfonline.codeclient.dev.Debug.Debug;
11-
import dev.dfonline.codeclient.dev.LastPos;
12-
import dev.dfonline.codeclient.dev.NoClip;
13-
import dev.dfonline.codeclient.dev.RecentChestInsert;
1411
import dev.dfonline.codeclient.dev.overlay.ChestPeeker;
1512
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
1613
import dev.dfonline.codeclient.location.*;
@@ -26,6 +23,7 @@
2623
import net.minecraft.client.MinecraftClient;
2724
import net.minecraft.client.gui.screen.ChatScreen;
2825
import net.minecraft.client.gui.screen.GameMenuScreen;
26+
import net.minecraft.client.gui.screen.ingame.HandledScreen;
2927
import net.minecraft.client.render.RenderLayer;
3028
import net.minecraft.client.render.VertexConsumerProvider;
3129
import net.minecraft.client.util.math.MatrixStack;
@@ -124,6 +122,11 @@ public static void onTick() {
124122
ChestPeeker.tick();
125123
RecentChestInsert.tick();
126124
KeyBinds.tick();
125+
SlotGhostManager.tick();
126+
127+
if(!(location instanceof Dev) || !(MC.currentScreen instanceof HandledScreen<?>)) {
128+
InsertOverlay.reset();
129+
}
127130

128131
if (location instanceof Dev dev) {
129132
if (MC.player == null) return;
@@ -177,6 +180,8 @@ public static void clean() {
177180
BuildPhaser.disableClipping();
178181
Commands.confirm = null;
179182
Debug.clean();
183+
SlotGhostManager.reset();
184+
InsertOverlay.reset();
180185
}
181186

182187
/**

src/main/java/dev/dfonline/codeclient/Utility.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,15 @@ public static String compileTemplate(String data) throws IOException {
245245
/**
246246
* @deprecated This uses literals, use translations when you can.
247247
*/
248+
@Deprecated
248249
public static void sendMessage(String message, ChatType type) {
249250
sendMessage(Text.literal(message), type);
250251
}
251252

252253
/**
253254
* @deprecated This uses literals, use translations when you can.
254255
*/
256+
@Deprecated
255257
public static void sendMessage(String message) {
256258
sendMessage(Text.literal(message), ChatType.INFO);
257259
}

src/main/java/dev/dfonline/codeclient/config/Config.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import dev.isxander.yacl3.api.controller.*;
1010
import dev.isxander.yacl3.gui.controllers.cycling.EnumController;
1111
import dev.isxander.yacl3.impl.controller.IntegerFieldControllerBuilderImpl;
12+
import net.fabricmc.loader.api.FabricLoader;
1213
import net.minecraft.text.ClickEvent;
1314
import net.minecraft.text.HoverEvent;
1415
import net.minecraft.text.Style;
@@ -65,6 +66,8 @@ public class Config {
6566
public boolean PickAction = true;
6667
public boolean DevForBuild = false;
6768
public boolean ChatEditsVars = true;
69+
public boolean InsertOverlay = true;
70+
public boolean ParameterGhosts = FabricLoader.getInstance().isDevelopmentEnvironment();
6871

6972
public Config() {
7073
}
@@ -134,6 +137,8 @@ private void save() {
134137
object.addProperty("PickAction", PickAction);
135138
object.addProperty("DevForBuild", DevForBuild);
136139
object.addProperty("ChatEditsVars",ChatEditsVars);
140+
object.addProperty("InsertOverlay",InsertOverlay);
141+
object.addProperty("ParameterGhosts",ParameterGhosts);
137142
FileManager.writeConfig(object.toString());
138143
} catch (Exception e) {
139144
CodeClient.LOGGER.info("Couldn't save config: " + e);
@@ -411,6 +416,19 @@ public YetAnotherConfigLib getLibConfig() {
411416
)
412417
.controller(TickBoxControllerBuilder::create)
413418
.build())
419+
.option(Option.createBuilder(boolean.class)
420+
.name(Text.translatable("codeclient.config.insert_overlay"))
421+
.description(OptionDescription.of(
422+
Text.translatable("codeclient.config.insert_overlay.description")
423+
))
424+
.binding(
425+
true,
426+
() -> InsertOverlay,
427+
opt -> InsertOverlay = opt
428+
)
429+
.controller(TickBoxControllerBuilder::create)
430+
.build()
431+
)
414432
.option(Option.createBuilder(CustomChestMenuType.class)
415433
.name(Text.literal("Custom Code Chest Menu"))
416434
.description(OptionDescription.createBuilder()
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
package dev.dfonline.codeclient.dev;
2+
3+
import dev.dfonline.codeclient.CodeClient;
4+
import dev.dfonline.codeclient.config.Config;
5+
import dev.dfonline.codeclient.dev.menu.customchest.CustomChestField;
6+
import dev.dfonline.codeclient.dev.menu.customchest.CustomChestMenu;
7+
import dev.dfonline.codeclient.hypercube.item.*;
8+
import dev.dfonline.codeclient.hypercube.item.Number;
9+
import net.minecraft.client.gui.DrawContext;
10+
import net.minecraft.client.gui.screen.ingame.HandledScreen;
11+
import net.minecraft.item.ItemStack;
12+
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
13+
import net.minecraft.screen.slot.Slot;
14+
import net.minecraft.screen.slot.SlotActionType;
15+
import net.minecraft.text.Text;
16+
import net.minecraft.util.Identifier;
17+
import org.lwjgl.glfw.GLFW;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
public class InsertOverlay {
23+
private static AddWidget selectedSlot = null;
24+
public static boolean isCodeChest = false;
25+
private static int screenX = 0;
26+
private static int screenY = 0;
27+
28+
public static void reset() {
29+
selectedSlot = null;
30+
isCodeChest = false;
31+
screenX = 0;
32+
screenY = 0;
33+
}
34+
35+
private static boolean overlayOpen() {
36+
return Config.getConfig().InsertOverlay && isCodeChest && selectedSlot != null;
37+
}
38+
39+
public static void render(DrawContext context, int mouseX, int mouseY, HandledScreen<?> handledScreen, int x, int y) {
40+
screenX = x;
41+
screenY = y;
42+
if (overlayOpen())
43+
selectedSlot.render(context, mouseX, mouseY, handledScreen);
44+
}
45+
46+
public static boolean mouseClicked(double mouseX, double mouseY, int button, HandledScreen<?> screen) {
47+
if (overlayOpen()) {
48+
boolean stayOpen = selectedSlot.mouseClicked(mouseX, mouseY, button, screen);
49+
if (!stayOpen) {
50+
selectedSlot.close();
51+
}
52+
return true;
53+
}
54+
return false;
55+
}
56+
57+
public static boolean keyPressed(int keyCode, int scanCode, int modifiers) {
58+
if (overlayOpen()) {
59+
return selectedSlot.keyPressed(keyCode, scanCode, modifiers);
60+
}
61+
return false;
62+
}
63+
64+
public static boolean keyReleased(int keyCode, int scanCode, int modifiers) {
65+
if (overlayOpen()) return selectedSlot.keyReleased(keyCode, scanCode, modifiers);
66+
return false;
67+
}
68+
69+
public static boolean charTyped(char chr, int modifiers) {
70+
if (overlayOpen()) return selectedSlot.charTyped(chr, modifiers);
71+
return false;
72+
}
73+
74+
public static boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
75+
if(overlayOpen()) return selectedSlot.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
76+
return false;
77+
}
78+
79+
public static void clickSlot(Slot slot, SlotActionType actionType) {
80+
if (Config.getConfig().InsertOverlay && isCodeChest && actionType == SlotActionType.PICKUP && !slot.hasStack() && CodeClient.MC.player.currentScreenHandler.getCursorStack().isEmpty())
81+
selectedSlot = new AddWidget(slot, () -> selectedSlot = null);
82+
else if (selectedSlot != null) selectedSlot.close();
83+
}
84+
85+
private static class AddWidget {
86+
private int x;
87+
private int y;
88+
private int width;
89+
private int height = 26;
90+
private List<Option> options;
91+
private Slot slot;
92+
private CustomChestField<?> field;
93+
private VarItem varItem = null;
94+
private final Runnable close;
95+
96+
public AddWidget(Slot slot, Runnable close) {
97+
this.slot = slot;
98+
this.close = close;
99+
this.x = slot.x + 16;
100+
this.y = slot.y - 5;
101+
var opt = new ArrayList<Option>();
102+
103+
int i = 0;
104+
for (var type : new VarItem[]{
105+
new dev.dfonline.codeclient.hypercube.item.Text(),
106+
new Component(),
107+
new Number(),
108+
new Location(),
109+
new Vector(),
110+
new Sound(),
111+
// new Particle(),
112+
new Potion(),
113+
}) {
114+
opt.add(new Option(type, x + 5 + i++ * 18, y + 5));
115+
}
116+
width = i * 18 + 8;
117+
height = 2 * 18 + 8;
118+
i = 0;
119+
for (var type : new VarItem[]{
120+
new Variable(),
121+
// new GameValue(),
122+
// new Parameter(),
123+
}) {
124+
opt.add(new Option(type, x + 5 + i++ * 18, y + 18 + 5));
125+
}
126+
127+
options = opt;
128+
}
129+
130+
private void setSlot(ItemStack stack) {
131+
var mc = CodeClient.MC;
132+
var currentScreen = mc.currentScreen;
133+
var manager = mc.interactionManager;
134+
if (manager == null || mc.getNetworkHandler() == null) return;
135+
if (currentScreen instanceof HandledScreen<?> screen) {
136+
var player = mc.player;
137+
var sync = screen.getScreenHandler().syncId;
138+
manager.clickSlot(sync, slot.id, 0, SlotActionType.SWAP, player);
139+
mc.getNetworkHandler().sendPacket(new CreativeInventoryActionC2SPacket(36, stack));
140+
manager.clickSlot(sync, slot.id, 0, SlotActionType.SWAP, player);
141+
manager.clickSlot(sync, 54, 0, SlotActionType.QUICK_CRAFT, player);
142+
slot.setStack(stack);
143+
}
144+
}
145+
146+
public void close() {
147+
if (field != null && varItem != null) {
148+
setSlot(varItem.toStack());
149+
}
150+
this.close.run();
151+
}
152+
153+
public void render(DrawContext context, int mouseX, int mouseY, HandledScreen<?> handledScreen) {
154+
context.getMatrices().push();
155+
context.getMatrices().translate(0.0F, 0.0F, 900.0F);
156+
context.drawGuiTexture(new Identifier("recipe_book/overlay_recipe"), x, y, width, height);
157+
if (field != null) {
158+
field.render(context, mouseX, mouseY, 0);
159+
} else {
160+
for (var option : options) {
161+
context.drawItem(option.type.getIcon(), option.x, option.y);
162+
}
163+
}
164+
context.getMatrices().pop();
165+
// new Identifier("recipe_book/crafting_overlay_highlighted")
166+
// new Identifier("recipe_book/crafting_overlay")
167+
// RecipeAlternativesWidget.CRAFTING_OVERLAY_HIGHLIGHTED_TEXTURE : RecipeAlternativesWidget.CRAFTING_OVERLAY_TEXTURE
168+
}
169+
170+
public boolean mouseClicked(double mouseX, double mouseY, int button, HandledScreen<?> screen) {
171+
int x = screenX;
172+
int y = screenY;
173+
if (mouseX > this.x + x && mouseY > this.y + y && mouseX < this.x + x + width && mouseY < this.y + y + height) {
174+
if (field != null) {
175+
boolean b = field.mouseClicked(mouseX - x, mouseY - y, button);
176+
setSlot(varItem.toStack());
177+
return b;
178+
}
179+
for (var option : options) {
180+
if (mouseX > option.x + x && mouseY > option.y + y && mouseX < option.x + x + 16 && mouseY < option.y + y + 21) {
181+
varItem = option.type;
182+
var stack = varItem.toStack();
183+
setSlot(stack);
184+
if (screen instanceof CustomChestMenu customChestMenu) {
185+
close();
186+
customChestMenu.update();
187+
return true;
188+
}
189+
this.width = 150;
190+
this.height = 26;
191+
field = new CustomChestField<>(CodeClient.MC.textRenderer, this.x + 5, this.y + 5, this.width - 10, this.height - 10, Text.literal(""), varItem);
192+
return true;
193+
}
194+
}
195+
}
196+
return false;
197+
}
198+
199+
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
200+
if (field != null) {
201+
if(keyCode != GLFW.GLFW_KEY_ENTER) field.keyPressed(keyCode, scanCode, modifiers);
202+
return true;
203+
}
204+
return false;
205+
}
206+
207+
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
208+
if (field != null) field.keyReleased(keyCode, scanCode, modifiers);
209+
if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_ESCAPE) {
210+
close();
211+
return true;
212+
}
213+
return false;
214+
}
215+
216+
public boolean charTyped(char chr, int modifiers) {
217+
if (field != null) return field.charTyped(chr, modifiers);
218+
return false;
219+
}
220+
221+
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
222+
if (field != null) return field.mouseScrolled(mouseX - screenX, mouseY - screenY, horizontalAmount, verticalAmount);
223+
return false;
224+
}
225+
226+
227+
private record Option(VarItem type, int x, int y) {
228+
}
229+
}
230+
}

src/main/java/dev/dfonline/codeclient/dev/InteractionManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private static void breakCodeBlock(BlockPos pos) {
131131

132132
public static boolean onClickSlot(Slot slot, int button, SlotActionType actionType, int syncId, int revision) {
133133
if (CodeClient.location instanceof Dev) {
134+
InsertOverlay.clickSlot(slot, actionType);
134135
if (!slot.hasStack()) return false;
135136
ItemStack item = slot.getStack();
136137
if (!item.hasNbt()) return false;
@@ -239,7 +240,8 @@ public static BlockPos getPlacePos(BlockHitResult hitResult) {
239240
}
240241

241242
public static BlockHitResult onBlockInteract(BlockHitResult hitResult) {
242-
if (CodeClient.location instanceof Dev plot) {
243+
SlotGhostManager.onClickChest(hitResult);
244+
if (CodeClient.location instanceof Dev plot && plot.isInCodeSpace(hitResult.getBlockPos().getX(), hitResult.getPos().getZ())) {
243245
plot.getLineStartCache();
244246
ChestPeeker.invalidate();
245247
BlockPos pos = hitResult.getBlockPos();

0 commit comments

Comments
 (0)