Skip to content

Commit

Permalink
Merge branch 'param-ghosts'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	src/main/java/dev/dfonline/codeclient/mixin/MMouse.java
  • Loading branch information
GeorgeRNG committed May 28, 2024
2 parents 89b5c2f + e92ae02 commit ad56062
Show file tree
Hide file tree
Showing 38 changed files with 986 additions and 159 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.20.4+build.3
loader_version=0.15.3

# Mod Properties
mod_version=1.6.5
mod_version=1.6.6
maven_group=dev.dfonline
archives_base_name=CodeClient

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/dev/dfonline/codeclient/CodeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
import dev.dfonline.codeclient.action.impl.DevForBuild;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.config.KeyBinds;
import dev.dfonline.codeclient.dev.BuildPhaser;
import dev.dfonline.codeclient.dev.*;
import dev.dfonline.codeclient.dev.Debug.Debug;
import dev.dfonline.codeclient.dev.LastPos;
import dev.dfonline.codeclient.dev.NoClip;
import dev.dfonline.codeclient.dev.RecentChestInsert;
import dev.dfonline.codeclient.dev.overlay.ChestPeeker;
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
import dev.dfonline.codeclient.location.*;
Expand All @@ -26,6 +23,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
Expand Down Expand Up @@ -124,6 +122,11 @@ public static void onTick() {
ChestPeeker.tick();
RecentChestInsert.tick();
KeyBinds.tick();
SlotGhostManager.tick();

if(!(location instanceof Dev) || !(MC.currentScreen instanceof HandledScreen<?>)) {
InsertOverlay.reset();
}

if (location instanceof Dev dev) {
if (MC.player == null) return;
Expand Down Expand Up @@ -177,6 +180,8 @@ public static void clean() {
BuildPhaser.disableClipping();
Commands.confirm = null;
Debug.clean();
SlotGhostManager.reset();
InsertOverlay.reset();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/dfonline/codeclient/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,15 @@ public static String compileTemplate(String data) throws IOException {
/**
* @deprecated This uses literals, use translations when you can.
*/
@Deprecated
public static void sendMessage(String message, ChatType type) {
sendMessage(Text.literal(message), type);
}

/**
* @deprecated This uses literals, use translations when you can.
*/
@Deprecated
public static void sendMessage(String message) {
sendMessage(Text.literal(message), ChatType.INFO);
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/dev/dfonline/codeclient/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.isxander.yacl3.api.controller.*;
import dev.isxander.yacl3.gui.controllers.cycling.EnumController;
import dev.isxander.yacl3.impl.controller.IntegerFieldControllerBuilderImpl;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Style;
Expand Down Expand Up @@ -65,6 +66,8 @@ public class Config {
public boolean PickAction = true;
public boolean DevForBuild = false;
public boolean ChatEditsVars = true;
public boolean InsertOverlay = true;
public boolean ParameterGhosts = FabricLoader.getInstance().isDevelopmentEnvironment();

public Config() {
}
Expand Down Expand Up @@ -134,6 +137,8 @@ private void save() {
object.addProperty("PickAction", PickAction);
object.addProperty("DevForBuild", DevForBuild);
object.addProperty("ChatEditsVars",ChatEditsVars);
object.addProperty("InsertOverlay",InsertOverlay);
object.addProperty("ParameterGhosts",ParameterGhosts);
FileManager.writeConfig(object.toString());
} catch (Exception e) {
CodeClient.LOGGER.info("Couldn't save config: " + e);
Expand Down Expand Up @@ -411,6 +416,19 @@ public YetAnotherConfigLib getLibConfig() {
)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.translatable("codeclient.config.insert_overlay"))
.description(OptionDescription.of(
Text.translatable("codeclient.config.insert_overlay.description")
))
.binding(
true,
() -> InsertOverlay,
opt -> InsertOverlay = opt
)
.controller(TickBoxControllerBuilder::create)
.build()
)
.option(Option.createBuilder(CustomChestMenuType.class)
.name(Text.literal("Custom Code Chest Menu"))
.description(OptionDescription.createBuilder()
Expand Down
230 changes: 230 additions & 0 deletions src/main/java/dev/dfonline/codeclient/dev/InsertOverlay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
package dev.dfonline.codeclient.dev;

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.dev.menu.customchest.CustomChestField;
import dev.dfonline.codeclient.dev.menu.customchest.CustomChestMenu;
import dev.dfonline.codeclient.hypercube.item.*;
import dev.dfonline.codeclient.hypercube.item.Number;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

import java.util.ArrayList;
import java.util.List;

public class InsertOverlay {
private static AddWidget selectedSlot = null;
public static boolean isCodeChest = false;
private static int screenX = 0;
private static int screenY = 0;

public static void reset() {
selectedSlot = null;
isCodeChest = false;
screenX = 0;
screenY = 0;
}

private static boolean overlayOpen() {
return Config.getConfig().InsertOverlay && isCodeChest && selectedSlot != null;
}

public static void render(DrawContext context, int mouseX, int mouseY, HandledScreen<?> handledScreen, int x, int y) {
screenX = x;
screenY = y;
if (overlayOpen())
selectedSlot.render(context, mouseX, mouseY, handledScreen);
}

public static boolean mouseClicked(double mouseX, double mouseY, int button, HandledScreen<?> screen) {
if (overlayOpen()) {
boolean stayOpen = selectedSlot.mouseClicked(mouseX, mouseY, button, screen);
if (!stayOpen) {
selectedSlot.close();
}
return true;
}
return false;
}

public static boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (overlayOpen()) {
return selectedSlot.keyPressed(keyCode, scanCode, modifiers);
}
return false;
}

public static boolean keyReleased(int keyCode, int scanCode, int modifiers) {
if (overlayOpen()) return selectedSlot.keyReleased(keyCode, scanCode, modifiers);
return false;
}

public static boolean charTyped(char chr, int modifiers) {
if (overlayOpen()) return selectedSlot.charTyped(chr, modifiers);
return false;
}

public static boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
if(overlayOpen()) return selectedSlot.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
return false;
}

public static void clickSlot(Slot slot, SlotActionType actionType) {
if (Config.getConfig().InsertOverlay && isCodeChest && actionType == SlotActionType.PICKUP && !slot.hasStack() && CodeClient.MC.player.currentScreenHandler.getCursorStack().isEmpty())
selectedSlot = new AddWidget(slot, () -> selectedSlot = null);
else if (selectedSlot != null) selectedSlot.close();
}

private static class AddWidget {
private int x;
private int y;
private int width;
private int height = 26;
private List<Option> options;
private Slot slot;
private CustomChestField<?> field;
private VarItem varItem = null;
private final Runnable close;

public AddWidget(Slot slot, Runnable close) {
this.slot = slot;
this.close = close;
this.x = slot.x + 16;
this.y = slot.y - 5;
var opt = new ArrayList<Option>();

int i = 0;
for (var type : new VarItem[]{
new dev.dfonline.codeclient.hypercube.item.Text(),
new Component(),
new Number(),
new Location(),
new Vector(),
new Sound(),
// new Particle(),
new Potion(),
}) {
opt.add(new Option(type, x + 5 + i++ * 18, y + 5));
}
width = i * 18 + 8;
height = 2 * 18 + 8;
i = 0;
for (var type : new VarItem[]{
new Variable(),
// new GameValue(),
// new Parameter(),
}) {
opt.add(new Option(type, x + 5 + i++ * 18, y + 18 + 5));
}

options = opt;
}

private void setSlot(ItemStack stack) {
var mc = CodeClient.MC;
var currentScreen = mc.currentScreen;
var manager = mc.interactionManager;
if (manager == null || mc.getNetworkHandler() == null) return;
if (currentScreen instanceof HandledScreen<?> screen) {
var player = mc.player;
var sync = screen.getScreenHandler().syncId;
manager.clickSlot(sync, slot.id, 0, SlotActionType.SWAP, player);
mc.getNetworkHandler().sendPacket(new CreativeInventoryActionC2SPacket(36, stack));
manager.clickSlot(sync, slot.id, 0, SlotActionType.SWAP, player);
manager.clickSlot(sync, 54, 0, SlotActionType.QUICK_CRAFT, player);
slot.setStack(stack);
}
}

public void close() {
if (field != null && varItem != null) {
setSlot(varItem.toStack());
}
this.close.run();
}

public void render(DrawContext context, int mouseX, int mouseY, HandledScreen<?> handledScreen) {
context.getMatrices().push();
context.getMatrices().translate(0.0F, 0.0F, 900.0F);
context.drawGuiTexture(new Identifier("recipe_book/overlay_recipe"), x, y, width, height);
if (field != null) {
field.render(context, mouseX, mouseY, 0);
} else {
for (var option : options) {
context.drawItem(option.type.getIcon(), option.x, option.y);
}
}
context.getMatrices().pop();
// new Identifier("recipe_book/crafting_overlay_highlighted")
// new Identifier("recipe_book/crafting_overlay")
// RecipeAlternativesWidget.CRAFTING_OVERLAY_HIGHLIGHTED_TEXTURE : RecipeAlternativesWidget.CRAFTING_OVERLAY_TEXTURE
}

public boolean mouseClicked(double mouseX, double mouseY, int button, HandledScreen<?> screen) {
int x = screenX;
int y = screenY;
if (mouseX > this.x + x && mouseY > this.y + y && mouseX < this.x + x + width && mouseY < this.y + y + height) {
if (field != null) {
boolean b = field.mouseClicked(mouseX - x, mouseY - y, button);
setSlot(varItem.toStack());
return b;
}
for (var option : options) {
if (mouseX > option.x + x && mouseY > option.y + y && mouseX < option.x + x + 16 && mouseY < option.y + y + 21) {
varItem = option.type;
var stack = varItem.toStack();
setSlot(stack);
if (screen instanceof CustomChestMenu customChestMenu) {
close();
customChestMenu.update();
return true;
}
this.width = 150;
this.height = 26;
field = new CustomChestField<>(CodeClient.MC.textRenderer, this.x + 5, this.y + 5, this.width - 10, this.height - 10, Text.literal(""), varItem);
return true;
}
}
}
return false;
}

public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (field != null) {
if(keyCode != GLFW.GLFW_KEY_ENTER) field.keyPressed(keyCode, scanCode, modifiers);
return true;
}
return false;
}

public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
if (field != null) field.keyReleased(keyCode, scanCode, modifiers);
if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_ESCAPE) {
close();
return true;
}
return false;
}

public boolean charTyped(char chr, int modifiers) {
if (field != null) return field.charTyped(chr, modifiers);
return false;
}

public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
if (field != null) return field.mouseScrolled(mouseX - screenX, mouseY - screenY, horizontalAmount, verticalAmount);
return false;
}


private record Option(VarItem type, int x, int y) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private static void breakCodeBlock(BlockPos pos) {

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

public static BlockHitResult onBlockInteract(BlockHitResult hitResult) {
if (CodeClient.location instanceof Dev plot) {
SlotGhostManager.onClickChest(hitResult);
if (CodeClient.location instanceof Dev plot && plot.isInCodeSpace(hitResult.getBlockPos().getX(), hitResult.getPos().getZ())) {
plot.getLineStartCache();
ChestPeeker.invalidate();
BlockPos pos = hitResult.getBlockPos();
Expand Down
Loading

0 comments on commit ad56062

Please sign in to comment.