Skip to content

Commit

Permalink
Small script loading cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TechPizzaDev committed Aug 21, 2023
1 parent 03d25b0 commit 20fc7e8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package dev.adventurecraft.awakening.common;

import dev.adventurecraft.awakening.extension.client.render.ExTextRenderer;
import dev.adventurecraft.awakening.extension.world.ExWorld;
import dev.adventurecraft.awakening.script.EntityDescriptions;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.Tessellator;
import net.minecraft.item.Item;

import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -239,7 +243,7 @@ protected void buttonClicked(ButtonWidget button) {
}

@Override
public void render(int mouseX, int mouseY, float deltaTime) {
public void render(int mouseX, int mouseY, float tickTime) {
this.fill(0, 0, this.width, this.height, Integer.MIN_VALUE);
this.drawTextWithShadow(this.textRenderer, String.format("Entity Spawn: %s", this.mobSpawner.entityID), 4, 4, 14737632);
this.drawTextWithShadow(this.textRenderer, String.format("Entities Alive: %d", this.mobSpawner.getNumAlive()), 4, 14, 14737632);
Expand All @@ -254,7 +258,7 @@ public void render(int mouseX, int mouseY, float deltaTime) {
this.spawnCountSlider.text = String.format("Spawn Count: %d", this.mobSpawner.spawnNumber);
this.mobSpawner.respawnDelay = (int) (this.respawnSlider.sliderValue * 12000.0F + 0.5F);
this.respawnSlider.text = String.format("Respawn Delay: %.1fs", (float) this.mobSpawner.respawnDelay / 20.0F);
super.render(mouseX, mouseY, deltaTime);
super.render(mouseX, mouseY, tickTime);
this.mobSpawner.world.getChunk(this.mobSpawner.x, this.mobSpawner.z).method_885();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.stream.Stream;

public class AC_JScriptHandler {

Expand All @@ -26,14 +29,33 @@ public AC_JScriptHandler(World var1, File var2) {
this.scripts = new HashMap<>();
}

public Stream<Path> getFiles() throws IOException {
//noinspection resource
return Files.walk(this.scriptDir.toPath(), 1).filter(Files::isRegularFile);
}

public String[] getFileNames() {
try {
return getFiles().map(path -> path.getFileName().toString()).toArray(String[]::new);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public void loadScripts(ProgressListener progressListener) {
this.scripts.clear();

if (progressListener != null)
progressListener.notifyIgnoreGameRunning("Loading scripts");

File[] files = this.scriptDir.listFiles();
if (files == null) {
File[] files;
try {
files = this.getFiles().map(Path::toFile).toArray(File[]::new);
} catch (IOException e) {
throw new RuntimeException(e);
}

if (files.length == 0) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1589,17 +1589,7 @@ public File getLevelDir() {

@Override
public String[] getScriptFiles() {
File scriptDir = new File(this.levelDir, "scripts");
File[] files = scriptDir.listFiles();
if (files == null) {
return null;
}

String[] scripts = new String[files.length];
for (int i = 0; i < scripts.length; i++) {
scripts[i] = files[i].getName();
}
return scripts;
return this.scriptHandler.getFileNames();
}

@Override
Expand Down

0 comments on commit 20fc7e8

Please sign in to comment.