Skip to content

Commit 9a8e788

Browse files
committed
Update AutoBuild
1 parent 757f4c9 commit 9a8e788

4 files changed

Lines changed: 404 additions & 6 deletions

File tree

src/main/java/net/wurstclient/commands/AutoBuildCmd.java

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
import net.wurstclient.command.CmdSyntaxError;
1515
import net.wurstclient.command.Command;
1616
import net.wurstclient.hacks.AutoBuildHack;
17+
import net.wurstclient.util.AutoBuildTemplate;
18+
import net.wurstclient.util.AutoBuildTextTemplateFactory;
1719
import net.wurstclient.util.ChatUtils;
1820

1921
public final class AutoBuildCmd extends Command
2022
{
2123
public AutoBuildCmd()
2224
{
2325
super("autobuild",
24-
"Selects an AutoBuild template by file name and enables AutoBuild.",
25-
".autobuild <template>");
26+
"Selects an AutoBuild template by file name or generates block text and enables AutoBuild.",
27+
".autobuild <template>", ".autobuild \"<text>\" <height>");
2628
setCategory(Category.BLOCKS);
2729
}
2830

@@ -33,6 +35,23 @@ public void call(String[] args) throws CmdException
3335
throw new CmdSyntaxError();
3436

3537
AutoBuildHack autoBuildHack = WURST.getHax().autoBuildHack;
38+
TextRequest textRequest = parseTextRequest(args);
39+
if(textRequest != null)
40+
{
41+
AutoBuildTemplate generatedTemplate = AutoBuildTextTemplateFactory
42+
.create(textRequest.text(), textRequest.height());
43+
autoBuildHack.selectGeneratedTemplate(generatedTemplate);
44+
45+
if(!autoBuildHack.isEnabled())
46+
autoBuildHack.setEnabled(true);
47+
48+
ChatUtils.message("AutoBuild ready with text \""
49+
+ textRequest.text().toUpperCase() + "\" at "
50+
+ textRequest.height()
51+
+ " blocks tall. Right-click to start building.");
52+
return;
53+
}
54+
3655
String templateName = String.join(" ", args);
3756
if(!autoBuildHack.selectTemplateByName(templateName))
3857
{
@@ -49,4 +68,49 @@ public void call(String[] args) throws CmdException
4968
ChatUtils.message("AutoBuild ready with template \"" + templateName
5069
+ "\". Right-click to start building.");
5170
}
71+
72+
private TextRequest parseTextRequest(String[] args) throws CmdSyntaxError
73+
{
74+
if(args.length < 2 || !args[0].startsWith("\""))
75+
return null;
76+
77+
StringBuilder text = new StringBuilder(args[0]);
78+
int closingIndex = args[0].endsWith("\"") ? 0 : -1;
79+
for(int i = 1; i < args.length && closingIndex < 0; i++)
80+
{
81+
text.append(" ").append(args[i]);
82+
if(args[i].endsWith("\""))
83+
closingIndex = i;
84+
}
85+
86+
if(closingIndex < 0)
87+
throw new CmdSyntaxError("Missing closing quote.");
88+
89+
if(closingIndex + 1 >= args.length)
90+
throw new CmdSyntaxError("Missing text height.");
91+
92+
if(closingIndex + 2 != args.length)
93+
throw new CmdSyntaxError("Syntax: .autobuild \"<text>\" <height>");
94+
95+
String heightArg = args[closingIndex + 1];
96+
int height;
97+
try
98+
{
99+
height = Integer.parseInt(heightArg);
100+
101+
}catch(NumberFormatException e)
102+
{
103+
throw new CmdSyntaxError("Height must be a whole number.");
104+
}
105+
106+
String literal = text.toString();
107+
if(literal.length() < 2 || !literal.endsWith("\""))
108+
throw new CmdSyntaxError("Missing closing quote.");
109+
110+
return new TextRequest(literal.substring(1, literal.length() - 1),
111+
height);
112+
}
113+
114+
private record TextRequest(String text, int height)
115+
{}
52116
}

src/main/java/net/wurstclient/hacks/AutoBuildHack.java

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ public final class AutoBuildHack extends Hack implements UpdateListener,
111111
"Disable when finished",
112112
"Automatically disables AutoBuild when all blocks are placed.", true);
113113

114+
private final CheckboxSetting enableCreativeFlight = new CheckboxSetting(
115+
"Enable CreativeFlight",
116+
"Enables CreativeFlight and starts flying when AutoBuild begins.\n\n"
117+
+ "If CreativeFlight was off before the build, it will be turned"
118+
+ " off again when the build ends.",
119+
false);
120+
114121
private final CheckboxSetting swapFlightWithAirWalk =
115122
new CheckboxSetting("Swap flight with AirWalk",
116123
"If Flight is enabled, swaps to AirWalk while building and swaps"
@@ -129,6 +136,7 @@ public final class AutoBuildHack extends Hack implements UpdateListener,
129136

130137
private static final long STUCK_TIMEOUT_MS = 1250L;
131138
private boolean swappedFlightForAirWalk;
139+
private boolean enabledCreativeFlightForBuild;
132140

133141
public AutoBuildHack()
134142
{
@@ -145,6 +153,7 @@ public AutoBuildHack()
145153
addSetting(previewTemplate);
146154
addSetting(confirmTicks);
147155
addSetting(disableOnFinish);
156+
addSetting(enableCreativeFlight);
148157
addSetting(swapFlightWithAirWalk);
149158
}
150159

@@ -203,6 +212,7 @@ protected void onDisable()
203212

204213
// Swap back from AirWalk to Flight if we swapped earlier
205214
swapBackFlightIfNeeded();
215+
stopCreativeFlightIfNeeded();
206216

207217
if(template == null)
208218
status = Status.NO_TEMPLATE;
@@ -294,6 +304,8 @@ public void onRightClick(RightClickEvent event)
294304

295305
status = Status.BUILDING;
296306

307+
startCreativeFlightIfEnabled();
308+
297309
// If Flight is enabled, swap to AirWalk while building
298310
swapFlightToAirWalkIfEnabled();
299311
}
@@ -311,7 +323,7 @@ public void onUpdate()
311323
break;
312324

313325
case IDLE:
314-
if(!template.isSelected(templateSetting))
326+
if(!template.isGenerated() && !template.isSelected(templateSetting))
315327
loadSelectedTemplate();
316328
updatePreview();
317329
break;
@@ -386,6 +398,7 @@ private void buildNormally()
386398

387399
// Swap back from AirWalk to Flight when building finishes
388400
swapBackFlightIfNeeded();
401+
stopCreativeFlightIfNeeded();
389402

390403
if(disableOnFinish.isChecked())
391404
setEnabled(false);
@@ -549,6 +562,18 @@ public boolean selectTemplateByName(String templateName)
549562
return false;
550563
}
551564

565+
public void selectGeneratedTemplate(AutoBuildTemplate generatedTemplate)
566+
{
567+
template = generatedTemplate;
568+
remainingBlocks.clear();
569+
previewBlocks.clear();
570+
placedConfirmations.clear();
571+
previewStartPos = null;
572+
previewDirection = null;
573+
lastProgressMs = System.currentTimeMillis();
574+
status = Status.IDLE;
575+
}
576+
552577
private void updatePreview()
553578
{
554579
if(!previewTemplate.isChecked() || template == null)
@@ -596,8 +621,8 @@ private void renderBlocks(PoseStack matrixStack,
596621
return;
597622

598623
List<BlockPos> blocksToDraw = blocks.keySet().stream()
599-
.filter(pos -> BlockUtils.getState(pos).canBeReplaced()).limit(1024)
600-
.toList();
624+
.filter(pos -> BlockUtils.getState(pos).canBeReplaced())
625+
.limit(16384).toList();
601626

602627
int black = 0x80000000;
603628
List<AABB> outlineBoxes =
@@ -678,6 +703,9 @@ private void swapFlightToAirWalkIfEnabled()
678703
if(!swapFlightWithAirWalk.isChecked())
679704
return;
680705

706+
if(enableCreativeFlight.isChecked())
707+
return;
708+
681709
if(!WURST.getHax().flightHack.isEnabled())
682710
return;
683711

@@ -698,4 +726,28 @@ private void swapBackFlightIfNeeded()
698726

699727
WURST.getHax().flightHack.setEnabled(true);
700728
}
729+
730+
private void startCreativeFlightIfEnabled()
731+
{
732+
if(!enableCreativeFlight.isChecked() || MC.player == null)
733+
return;
734+
735+
CreativeFlightHack creativeFlight = WURST.getHax().creativeFlightHack;
736+
enabledCreativeFlightForBuild = !creativeFlight.isEnabled();
737+
if(enabledCreativeFlightForBuild)
738+
creativeFlight.setEnabled(true);
739+
740+
MC.player.getAbilities().mayfly = true;
741+
MC.player.getAbilities().flying = true;
742+
}
743+
744+
private void stopCreativeFlightIfNeeded()
745+
{
746+
if(!enabledCreativeFlightForBuild)
747+
return;
748+
749+
enabledCreativeFlightForBuild = false;
750+
if(WURST.getHax().creativeFlightHack.isEnabled())
751+
WURST.getHax().creativeFlightHack.setEnabled(false);
752+
}
701753
}

src/main/java/net/wurstclient/util/AutoBuildTemplate.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ private AutoBuildTemplate(Path path, LinkedHashSet<BlockData> blocks)
3434
this.blocks = blocks;
3535
}
3636

37+
private AutoBuildTemplate(String name, LinkedHashSet<BlockData> blocks)
38+
{
39+
path = null;
40+
this.name = name;
41+
this.blocks = blocks;
42+
}
43+
3744
public static AutoBuildTemplate load(Path path)
3845
throws IOException, JsonException
3946
{
@@ -56,6 +63,16 @@ public static AutoBuildTemplate load(Path path)
5663
return new AutoBuildTemplate(path, loadedBlocks);
5764
}
5865

66+
public static AutoBuildTemplate createGenerated(String name,
67+
LinkedHashSet<int[]> blocks)
68+
{
69+
LinkedHashSet<BlockData> generatedBlocks = new LinkedHashSet<>();
70+
for(int[] pos : blocks)
71+
generatedBlocks.add(new BlockData(pos.clone(), ""));
72+
73+
return new AutoBuildTemplate(name, generatedBlocks);
74+
}
75+
5976
private static void loadV2(WsonArray jsonBlocks,
6077
LinkedHashSet<BlockData> loadedBlocks) throws JsonException
6178
{
@@ -126,7 +143,12 @@ public int size()
126143

127144
public boolean isSelected(FileSetting setting)
128145
{
129-
return path.equals(setting.getSelectedFile());
146+
return path != null && path.equals(setting.getSelectedFile());
147+
}
148+
149+
public boolean isGenerated()
150+
{
151+
return path == null;
130152
}
131153

132154
public String getName()

0 commit comments

Comments
 (0)