Skip to content

Commit 07d5b1b

Browse files
committed
prevent peeker blowing up, implement all but textitems tostack
1 parent 22ba0e4 commit 07d5b1b

9 files changed

Lines changed: 195 additions & 11 deletions

File tree

src/main/java/dev/dfonline/codeclient/dev/menu/customchest/CustomChestField.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public CustomChestField(TextRenderer textRender, int x, int y, int width, int he
9898
var text = new TextFieldWidget(textRender,x,y,textboxWidth,height,Text.literal(""));
9999
text.setText(pot.getPotion());
100100
widgets.add(text);
101-
var potency = new NumberFieldWidget(textRender,x+durationWidth,y,potencyWidth,height,Text.empty()).integer();
102-
potency.setNumber(pot.getAmplifier());
101+
var potency = new NumberFieldWidget(textRender,x+textboxWidth,y,potencyWidth,height,Text.empty()).integer();
102+
potency.setNumber(pot.getAmplifier() + 1);
103103
widgets.add(potency);
104-
var duration = new TextFieldWidget(textRender,x+durationWidth+potencyWidth,y,durationWidth,height,Text.empty());
104+
var duration = new TextFieldWidget(textRender,x+textboxWidth+potencyWidth,y,durationWidth,height,Text.empty());
105105
duration.setText(String.valueOf(pot.getDuration()));
106106
widgets.add(duration);
107107
}
@@ -119,6 +119,14 @@ public CustomChestField(TextRenderer textRender, int x, int y, int width, int he
119119
pitch.setNumber(sound.getPitch());
120120
widgets.add(pitch);
121121
}
122+
if(item instanceof BlockTag tag) {
123+
int slotSize = 18;
124+
int textboxWidth = width - slotSize;
125+
widgets.add(new CyclingButtonWidget.Builder<>(Text::literal).values("A", "B", "C").build(x,y,textboxWidth,height,Text.empty()));
126+
var varItem = new FakeSlot(x + textboxWidth, y, Text.empty(), handler);
127+
if(tag.getVariable() != null) varItem.item = tag.getVariable().toStack();
128+
widgets.add(varItem);
129+
}
122130
this.widgets = widgets;
123131
}
124132

src/main/java/dev/dfonline/codeclient/dev/menu/customchest/FakeSlot.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.dfonline.codeclient.dev.menu.customchest;
22

33
import dev.dfonline.codeclient.CodeClient;
4+
import net.minecraft.client.font.TextRenderer;
45
import net.minecraft.client.gui.DrawContext;
56
import net.minecraft.client.gui.screen.Screen;
67
import net.minecraft.client.gui.screen.ingame.HandledScreen;
@@ -36,15 +37,18 @@ protected void renderButton(DrawContext context, int mouseX, int mouseY, float d
3637
context.drawItem(item,this.getX() + 1,this.getY() + 1);
3738
if(this.isMouseOver(mouseX,mouseY)) {
3839
HandledScreen.drawSlotHighlight(context,this.getX() + 1,this.getY() + 1,-1000);
40+
context.drawItemTooltip(CodeClient.MC.textRenderer,item,mouseX,mouseY);
3941
}
4042
}
4143

4244
@Override
4345
public boolean mouseClicked(double mouseX, double mouseY, int button) {
4446
if(this.isMouseOver(mouseX,mouseY) && ((!this.item.isEmpty()) || (!this.handler.getCursorStack().isEmpty()))) {
47+
this.handler.disableSyncing();
4548
var swap = this.item.copy();
4649
this.item = this.handler.getCursorStack().copyWithCount(1);
4750
this.handler.setCursorStack(swap);
51+
this.handler.enableSyncing();
4852
return true;
4953
}
5054
return super.mouseClicked(mouseX, mouseY, button);

src/main/java/dev/dfonline/codeclient/dev/menu/customchest/NumberFieldWidget.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
public class NumberFieldWidget extends TextFieldWidget {
99
private double number = 0;
1010
private @RegExp String regex = "(?<!^)-|[^\\d-.]";
11+
private boolean isInt = false;
1112

1213
public NumberFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, Text text) {
1314
super(textRenderer, x, y, width, height, text);
1415
}
1516
public NumberFieldWidget integer() {
1617
this.regex = "(?<!^)-|[^\\d-]";
18+
this.isInt = true;
1719
return this;
1820
}
1921

@@ -27,13 +29,14 @@ public void setText(String text) {
2729
}
2830

2931
public void setNumber(double number) {
30-
this.setText("%.2f".formatted(number));
32+
this.setText((isInt? "%.0f" : "%.2f").formatted(number));
3133
this.number = number;
3234
}
3335

3436
public double getNumber() {
3537
return number;
3638
}
39+
public int getInt() {return (int) number;}
3740

3841
@Override
3942
public void write(String text) {

src/main/java/dev/dfonline/codeclient/hypercube/item/BlockTag.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,81 @@
22

33
import com.google.gson.JsonObject;
44
import net.minecraft.item.Item;
5+
import net.minecraft.item.Items;
6+
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Nullable;
58

69
public class BlockTag extends VarItem {
10+
/**
11+
* Selected option.
12+
*/
13+
@NotNull
14+
private String option;
15+
/**
16+
* The name of the given tag.
17+
*/
18+
@NotNull
19+
private String tag;
20+
/**
21+
* The action it is on.
22+
*/
23+
@NotNull
24+
private String action;
25+
/**
26+
* ID, like `event` or `player_action`
27+
*/
28+
@NotNull
29+
private String block;
30+
/**
31+
* The active var tag.
32+
*/
33+
@Nullable
34+
private Variable variable;
35+
736
public BlockTag(Item material, JsonObject var) {
837
super(material, var);
38+
option = this.data.get("option").getAsString();
39+
tag = this.data.get("tag").getAsString();
40+
action = this.data.get("action").getAsString();
41+
block = this.data.get("block").getAsString();
42+
if(this.data.has("variable")) variable = new Variable(Items.MAGMA_CREAM,this.data.get("variable").getAsJsonObject());
43+
}
44+
45+
public @NotNull String getOption() {
46+
return this.option;
47+
}
48+
public void setOption(@NotNull String option) {
49+
this.option = option;
50+
this.data.addProperty("option",option);
51+
}
52+
public @NotNull String getTag() {
53+
return this.tag;
54+
}
55+
public void setTag(@NotNull String tag) {
56+
this.tag = tag;
57+
this.data.addProperty("tag",tag);
58+
}
59+
public @NotNull String getAction() {
60+
return this.action;
61+
}
62+
public void setAction(@NotNull String action) {
63+
this.action = action;
64+
this.data.addProperty("action",action);
65+
}
66+
public @NotNull String getBlock() {
67+
return this.block;
68+
}
69+
public void setBlock(@NotNull String block) {
70+
this.block = block;
71+
this.data.addProperty("block",block);
72+
}
73+
74+
public @Nullable Variable getVariable() {
75+
return variable;
76+
}
77+
78+
public void setVariable(@Nullable Variable variable) {
79+
this.variable = variable;
80+
this.data.add("variable",variable.getData());
981
}
1082
}

src/main/java/dev/dfonline/codeclient/hypercube/item/Potion.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package dev.dfonline.codeclient.hypercube.item;
22

33
import com.google.gson.JsonObject;
4+
import dev.dfonline.codeclient.Utility;
5+
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
6+
import dev.dfonline.codeclient.hypercube.actiondump.Icon;
47
import net.minecraft.item.Item;
8+
import net.minecraft.item.ItemStack;
9+
import net.minecraft.text.Style;
10+
import net.minecraft.text.Text;
11+
import net.minecraft.util.Formatting;
12+
13+
import java.util.Arrays;
514

615
public class Potion extends VarItem {
716
private String potion;
@@ -36,4 +45,36 @@ public void setAmplifier(int amplifier) {
3645
data.addProperty("amp",amplifier);
3746
this.amplifier = amplifier;
3847
}
48+
49+
@Override
50+
public ItemStack toStack() {
51+
ItemStack stack = super.toStack();
52+
stack.setCustomName(Text.literal("Potion Effect").setStyle(Style.EMPTY.withItalic(false).withColor(Icon.Type.POTION.color)));
53+
Text name;
54+
try {
55+
ActionDump db = ActionDump.getActionDump();
56+
var value = Arrays.stream(db.potions).filter(gv -> gv.icon.getCleanName().equals(potion)).findFirst();
57+
if(value.isEmpty()) throw new Exception("");
58+
name = Text.literal(value.get().icon.name);
59+
} catch (Exception e) {
60+
name = Text.literal(potion).setStyle(Style.EMPTY);
61+
}
62+
Utility.addLore(stack,
63+
name,
64+
Text.empty(),
65+
Text.empty().append(Text.literal("Amplifier: ").formatted(Formatting.GRAY)).append(Text.literal(String.valueOf(amplifier + 1))),
66+
Text.empty().append(Text.literal("Duration: ").formatted(Formatting.GRAY)).append(Text.literal(duration())));
67+
return stack;
68+
}
69+
70+
public String duration() {
71+
return durationToString(duration);
72+
}
73+
74+
public static String durationToString(int duration) {
75+
if(duration >= 1000000) return "Infinite";
76+
if(duration % 20 != 0) return "%d ticks".formatted(duration);
77+
int seconds = duration / 20;
78+
return "%d:%d".formatted(seconds / 60, seconds % 60);
79+
}
3980
}

src/main/java/dev/dfonline/codeclient/hypercube/item/Sound.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package dev.dfonline.codeclient.hypercube.item;
22

33
import com.google.gson.JsonObject;
4+
import dev.dfonline.codeclient.Utility;
5+
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
6+
import dev.dfonline.codeclient.hypercube.actiondump.Icon;
47
import net.minecraft.item.Item;
8+
import net.minecraft.item.ItemStack;
9+
import net.minecraft.text.Style;
10+
import net.minecraft.text.Text;
11+
import net.minecraft.util.Formatting;
12+
13+
import java.util.Arrays;
514

615
public class Sound extends VarItem {
716
private String sound;
@@ -41,4 +50,25 @@ public void setVolume(double volume) {
4150
this.volume = volume;
4251
this.data.addProperty("vol",volume);
4352
}
53+
54+
@Override
55+
public ItemStack toStack() {
56+
ItemStack stack = super.toStack();
57+
stack.setCustomName(Text.literal("Sound").setStyle(Style.EMPTY.withItalic(false).withColor(Icon.Type.SOUND.color)));
58+
Text name;
59+
try {
60+
ActionDump db = ActionDump.getActionDump();
61+
var value = Arrays.stream(db.sounds).filter(gv -> gv.icon.getCleanName().equals(sound)).findFirst();
62+
if(value.isEmpty()) throw new Exception("");
63+
name = Text.literal(value.get().icon.name);
64+
} catch (Exception e) {
65+
name = Text.literal(sound).setStyle(Style.EMPTY);
66+
}
67+
Utility.addLore(stack,
68+
name,
69+
Text.empty(),
70+
Text.empty().append(Text.literal("Pitch: ").formatted(Formatting.GRAY)).append("%.2f".formatted(pitch)),
71+
Text.empty().append(Text.literal("Volume: ").formatted(Formatting.GRAY)).append("%.2f".formatted(volume)));
72+
return stack;
73+
}
4474
}

src/main/java/dev/dfonline/codeclient/hypercube/item/VarItem.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ public ItemStack toStack() {
5050
public JsonObject getData() {
5151
return data;
5252
}
53+
54+
public JsonObject getVar() {
55+
// This is probably the best approach tbh instead of updating data constantly
56+
var var = new JsonObject();
57+
var.addProperty("id",id);
58+
var.add("data",data);
59+
return var;
60+
}
5361
}

src/main/java/dev/dfonline/codeclient/hypercube/item/Variable.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package dev.dfonline.codeclient.hypercube.item;
22

33
import com.google.gson.JsonObject;
4+
import dev.dfonline.codeclient.Utility;
45
import net.minecraft.item.Item;
6+
import net.minecraft.item.ItemStack;
7+
import net.minecraft.text.Style;
8+
import net.minecraft.text.Text;
59

610
public class Variable extends NamedItem {
711
private Scope scope;
@@ -19,4 +23,12 @@ public void setScope(Scope scope) {
1923
public Scope getScope() {
2024
return scope;
2125
}
26+
27+
@Override
28+
public ItemStack toStack() {
29+
var stack = super.toStack();
30+
stack.setCustomName(Text.literal(getName()).setStyle(Style.EMPTY.withItalic(false)));
31+
Utility.addLore(stack, Text.literal(scope.longName).setStyle(Style.EMPTY.withColor(scope.color)));
32+
return stack;
33+
}
2234
}

src/main/java/dev/dfonline/codeclient/mixin/render/hud/MInGameHud.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1616

1717
import java.util.List;
18+
import java.util.Objects;
1819

1920
@Mixin(InGameHud.class)
2021
public abstract class MInGameHud {
@@ -32,16 +33,21 @@ private void onRender(DrawContext context, float tickDelta, CallbackInfo ci) {
3233
if(!overlay.isEmpty()) {
3334
int index = 0;
3435
for (Text text : overlay) {
35-
context.drawTextWithShadow(textRenderer, text, 30, 30 + (index * 9), -1);
36+
context.drawTextWithShadow(textRenderer, Objects.requireNonNullElseGet(text, () -> Text.literal("NULL")), 30, 30 + (index * 9), -1);
3637
index++;
3738
}
3839
}
39-
List<Text> peeker = ChestPeeker.getOverlayText();
40-
if(peeker == null) peeker = SignPeeker.getOverlayText();
41-
if(peeker != null && !peeker.isEmpty()) {
42-
int x = (scaledWidth / 2) + Config.getConfig().ChestPeekerX;
43-
int yOrig = (scaledHeight / 2) + Config.getConfig().ChestPeekerY;
44-
context.drawTooltip(textRenderer,peeker,x,yOrig);
40+
int x = (scaledWidth / 2) + Config.getConfig().ChestPeekerX;
41+
int yOrig = (scaledHeight / 2) + Config.getConfig().ChestPeekerY;
42+
try {
43+
List<Text> peeker = ChestPeeker.getOverlayText();
44+
if(peeker == null) peeker = SignPeeker.getOverlayText();
45+
if(peeker != null && !peeker.isEmpty()) {
46+
context.drawTooltip(textRenderer,peeker,x,yOrig);
47+
48+
}
49+
} catch (Exception ignored) {
50+
context.drawTooltip(textRenderer,Text.literal("An error occurred"),x,yOrig);
4551

4652
}
4753
}

0 commit comments

Comments
 (0)