Skip to content

Commit

Permalink
i forgot to commit yesterday (omw to lose my daily commit or something)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Dec 15, 2023
1 parent 76891e8 commit 9f0b78a
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/main/java/dev/dfonline/codeclient/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.io.FileUtils;
import oshi.util.FileUtil;

import java.io.IOException;
import java.nio.file.Files;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/dev/dfonline/codeclient/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.minecraft.sound.SoundCategory;
Expand Down Expand Up @@ -189,6 +190,14 @@ public static PlaceTemplates createPlacer(List<ItemStack> templates, Action.Call
return null;
}

public static void addLore(ItemStack stack, Text ...lore) {
var display = stack.getSubNbt("display");
var loreList = new NbtList();
for (Text line: lore) loreList.add(Utility.nbtify(Text.empty().append(line)));
display.put("Lore",loreList);
stack.setSubNbt("display",display);
}

public static void sendHandItem(ItemStack item) {
CodeClient.MC.getNetworkHandler().sendPacket(new CreativeInventoryActionC2SPacket(36 + CodeClient.MC.player.getInventory().selectedSlot, item));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package dev.dfonline.codeclient.dev.menu.customchest;

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.hypercube.Target;
import dev.dfonline.codeclient.hypercube.item.*;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.navigation.GuiNavigationPath;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.GameModeSelectionScreen;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.screen.narration.NarrationPart;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.*;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand All @@ -21,7 +25,7 @@ public class CustomChestField<ItemType extends VarItem> extends ClickableWidget
private final List<Drawable> widgets;
public ItemType item;

public CustomChestField(TextRenderer textRender, int x, int y, int width, int height, Text message, ItemType item) {
public CustomChestField(TextRenderer textRender, int x, int y, int width, int height, Text message, ItemType item, ScreenHandler handler) {
super(x, y, width, height, message);
this.item = item;
var widgets = new ArrayList<Drawable>();
Expand All @@ -33,12 +37,39 @@ public CustomChestField(TextRenderer textRender, int x, int y, int width, int he
scopeWidget.setValue(var.getScope());
widgets.add(scopeWidget);
}
if(item instanceof Parameter parameter) {
textboxWidth = textboxWidth - 18;

widgets.add(new FakeSlot(x+textboxWidth,y,Text.literal("Paramater Data"), handler));
}
var text = new TextFieldWidget(textRender,x,y,textboxWidth,height,Text.literal(""));
text.setMaxLength(10000);
text.setText(named.getName());
text.setFocused(false);
widgets.add(0,text);
}
if(item instanceof GameValue value) {
int targetWidth = 60;
int textboxWidth = width - targetWidth;

var text = new TextFieldWidget(textRender,x,y,textboxWidth,height,Text.literal(""));
text.setMaxLength(10000);
text.setText(value.getType());
widgets.add(text);

var scopeWidget = new CyclingButtonWidget.Builder<Target>(target -> Text.literal(target.name()).setStyle(Style.EMPTY.withColor(target.color))).values(
Target.Selection,
Target.Default,
Target.Killer,
Target.Damager,
Target.Victim,
Target.Shooter,
Target.Projectile,
Target.LastEntity
).omitKeyText().build(x+textboxWidth,y,targetWidth,height,Text.literal(""));
scopeWidget.setValue(value.getTarget());
widgets.add(scopeWidget);
}
if(item instanceof Vector vec) {
Double[] values = {vec.getX(), vec.getY(), vec.getZ()};
int textboxWidth = width / 3;
Expand All @@ -60,6 +91,34 @@ public CustomChestField(TextRenderer textRender, int x, int y, int width, int he
widgets.add(field);
}
}
if(item instanceof Potion pot) {
int durationWidth = 30;
int potencyWidth = 30;
int textboxWidth = width - durationWidth - potencyWidth;
var text = new TextFieldWidget(textRender,x,y,textboxWidth,height,Text.literal(""));
text.setText(pot.getPotion());
widgets.add(text);
var potency = new NumberFieldWidget(textRender,x+durationWidth,y,potencyWidth,height,Text.empty()).integer();
potency.setNumber(pot.getAmplifier());
widgets.add(potency);
var duration = new TextFieldWidget(textRender,x+durationWidth+potencyWidth,y,durationWidth,height,Text.empty());
duration.setText(String.valueOf(pot.getDuration()));
widgets.add(duration);
}
if(item instanceof Sound sound) {
int volumeWidth = 20;
int pitchWidth = 20;
int textboxWidth = width - volumeWidth - pitchWidth;
var text = new TextFieldWidget(textRender,x,y,textboxWidth,height,Text.literal(""));
text.setText(sound.getSound());
widgets.add(text);
var volume = new NumberFieldWidget(textRender,x+textboxWidth,y,volumeWidth,height,Text.empty());
volume.setNumber(sound.getVolume());
widgets.add(volume);
var pitch = new NumberFieldWidget(textRender,x+textboxWidth+volumeWidth,y,pitchWidth,height,Text.empty());
pitch.setNumber(sound.getPitch());
widgets.add(pitch);
}
this.widgets = widgets;
}

Expand All @@ -74,6 +133,14 @@ private void updateItem() {
}
}
}
if(item instanceof GameValue value) {
if(widgets.get(0) instanceof TextFieldWidget text) {
value.setType(text.getText());
}
if(widgets.get(1) instanceof CyclingButtonWidget<?> cycle) {
value.setTarget((Target) cycle.getValue());
}
}
if(item instanceof Vector vec) {
if (widgets.get(0) instanceof NumberFieldWidget num1
&& widgets.get(1) instanceof NumberFieldWidget num2
Expand All @@ -83,7 +150,7 @@ private void updateItem() {
}
if(item instanceof Location loc) {
if(
widgets.get(0) instanceof NumberFieldWidget num0
widgets.get(0) instanceof NumberFieldWidget num0
&& widgets.get(1) instanceof NumberFieldWidget num1
&& widgets.get(2) instanceof NumberFieldWidget num2
&& widgets.get(3) instanceof NumberFieldWidget num3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
context.getMatrices().translate(this.x, this.y, 0);
for (Widget widget : widgets.values()) {
if (widget instanceof Drawable drawable) {
drawable.render(context, mouseX, mouseY, delta);
drawable.render(context, mouseX - this.x, mouseY - this.y, delta);
}
}
List<Slot> subList = this.getScreenHandler().slots.subList((int) scroll, (int) scroll + Size.SLOTS);
Expand Down Expand Up @@ -132,7 +132,7 @@ private void update(int previousScroll) {
// widget.setMaxLength(10_000);
// widget.setText(named.getName());
// widget.setFocused(Objects.equals(i,focused));
var widget = new CustomChestField<>(textRenderer, x, y, Size.WIDGET_WIDTH, 18, Text.of(varItem.id), varItem);
var widget = new CustomChestField<>(textRenderer, x, y, Size.WIDGET_WIDTH, 18, Text.of(varItem.id), varItem, this.handler);
widgets.put(i,widget);
varItems.add(varItem);
continue;
Expand Down Expand Up @@ -161,15 +161,6 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
List<Slot> subList = this.getScreenHandler().slots.subList((int) scroll, Math.min((int) scroll + Size.SLOTS,27));
for (var entry : widgets.entrySet()) {
if (entry.getValue() instanceof ClickableWidget clickable) {
clickable.setFocused(clickable.isMouseOver(mouseX - this.x, mouseY - this.y));
if(clickable.mouseClicked(mouseX - this.x,mouseY - this.y,button)) {
updateItem(entry.getKey());
return true;
}
}
}
for (int i = 0; i < subList.size(); i++) {
var slot = subList.get(i);
final int x = 8;
Expand All @@ -194,6 +185,16 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
return true;
}
}
for (var entry : widgets.entrySet()) {
if (entry.getValue() instanceof ClickableWidget clickable) {
boolean mouseOver = clickable.isMouseOver(mouseX - this.x, mouseY - this.y);
clickable.setFocused(mouseOver);
if(mouseOver && clickable.mouseClicked(mouseX - this.x,mouseY - this.y,button)) {
updateItem(entry.getKey());
return true;
}
}
}
return super.mouseClicked(mouseX, mouseY, button);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dev.dfonline.codeclient.dev.menu.customchest;

import dev.dfonline.codeclient.CodeClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class FakeSlot extends ClickableWidget {
public static final Identifier TEXTURE = new Identifier("minecraft","textures/gui/sprites/container/slot.png");
private final ScreenHandler handler;
public boolean disabled = false;
@NotNull
public ItemStack item = ItemStack.EMPTY;

public FakeSlot(int x, int y, Text message, ScreenHandler handler) {
super(x, y, 18, 18, message);
this.handler = handler;
this.item = Items.STRING.getDefaultStack();
}

@Override
protected void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
context.drawTexture(TEXTURE,this.getX(),this.getY(),0,0,this.width,this.height,18,18);
context.drawItem(item,this.getX() + 1,this.getY() + 1);
if(this.isMouseOver(mouseX,mouseY)) {
HandledScreen.drawSlotHighlight(context,this.getX() + 1,this.getY() + 1,-1000);
}
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if(this.isMouseOver(mouseX,mouseY) && ((!this.item.isEmpty()) || (!this.handler.getCursorStack().isEmpty()))) {
var swap = this.item.copy();
this.item = this.handler.getCursorStack().copyWithCount(1);
this.handler.setCursorStack(swap);
return true;
}
return super.mouseClicked(mouseX, mouseY, button);
}

@Nullable
@Override
public Tooltip getTooltip() {
var data = Screen.getTooltipFromItem(CodeClient.MC, item);
var text = Text.empty();
boolean first = true;
for (var line: data) {
if(first) first = false;
else text.append(Text.literal("\n"));
text.append(line);
}
return Tooltip.of(text);
}

@Override
protected void appendClickableNarrations(NarrationMessageBuilder builder) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

public class NumberFieldWidget extends TextFieldWidget {
private double number = 0;
private static final @RegExp String regex = "(?<!^)-|[^\\d-.]";
private @RegExp String regex = "(?<!^)-|[^\\d-.]";

public NumberFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, Text text) {
super(textRenderer, x, y, width, height, text);
}
public NumberFieldWidget integer() {
this.regex = "(?<!^)-|[^\\d-]";
return this;
}

@Override
public void setText(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum Target {
Damager(Formatting.RED, true, true),
Shooter(Formatting.YELLOW, true, true),
Victim(Formatting.BLUE, true, true),
AllPlayers(Formatting.AQUA, true, true),
AllPlayers(Formatting.AQUA, true, false),
Projectile(Formatting.YELLOW, false, true),
LastEntity(Formatting.AQUA, false, true);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package dev.dfonline.codeclient.hypercube.item;

import com.google.gson.JsonObject;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.hypercube.Target;
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.io.IOException;
import java.util.Arrays;
import java.util.Optional;

public class GameValue extends VarItem {
private String type;
Expand All @@ -18,11 +28,19 @@ public String getType() {
return type;
}

// TODO: allow rejecting nonexistant values if actiondump is loaded
public void setType(String type) {
this.type = type;
this.data.addProperty("type",type);
}

// public void setData(String type, Target target) {
// this.type = type;
// this.target = target;
// this.data.add("type",type);
// this.data.add("scope");
// }

public Target getTarget() {
return target;
}
Expand All @@ -31,4 +49,19 @@ public void setTarget(Target target) {
this.target = target;
this.data.addProperty("target",target.name());
}

@Override
public ItemStack toStack() {
ItemStack stack = super.toStack();
try {
ActionDump db = ActionDump.getActionDump();
var value = Arrays.stream(db.gameValues).filter(gv -> gv.icon.getCleanName().equals(type)).findFirst();
if(value.isEmpty()) throw new Exception("");
stack.setCustomName(Text.literal(value.get().icon.name));
} catch (Exception e) {
stack.setCustomName(Text.literal(type).setStyle(Style.EMPTY));
}
Utility.addLore(stack,Text.literal("Target: ").formatted(Formatting.GRAY).append(Text.literal(target.name()).setStyle(Style.EMPTY.withColor(target.color))));
return stack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ public void setCoords(double x, double y, double z, double pitch, double yaw) {
public ItemStack toStack() {
ItemStack stack = super.toStack();
stack.setCustomName(Text.literal("Location").setStyle(Style.EMPTY.withItalic(false).withColor(Icon.Type.LOCATION.color)));
var display = stack.getSubNbt("display");
var lore = new NbtList();
lore.add(Utility.nbtify(Text.empty().append(Text.literal("X: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.x))));
lore.add(Utility.nbtify(Text.empty().append(Text.literal("Y: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.y))));
lore.add(Utility.nbtify(Text.empty().append(Text.literal("Z: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.z))));
lore.add(Utility.nbtify(Text.empty().append(Text.literal("p: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.z))));
lore.add(Utility.nbtify(Text.empty().append(Text.literal("y: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.z))));
display.put("Lore",lore);
stack.setSubNbt("display",display);
Utility.addLore(
stack,
Text.empty().append(Text.literal("X: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.x)),
Text.empty().append(Text.literal("Y: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.y)),
Text.empty().append(Text.literal("Z: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.z)),
Text.empty().append(Text.literal("p: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.z)),
Text.empty().append(Text.literal("y: ").formatted(Formatting.GRAY)).append("%.2f".formatted(this.z))
);
return stack;
}
}
Loading

0 comments on commit 9f0b78a

Please sign in to comment.