Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TechPizzaDev committed Aug 12, 2023
1 parent 00b84c0 commit 190d899
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.util.CharacterUtils;
import net.minecraft.world.World;

import java.util.ArrayList;

public class AC_GuiMessage extends Screen {

private AC_TileEntityMessage msg;
Expand All @@ -19,38 +21,37 @@ public AC_GuiMessage(World world, AC_TileEntityMessage msg) {
}

public void initVanillaScreen() {
String[] soundList = ((ExWorld) this.world).getSoundList();

int var1 = 3 * ((this.height - 60) / 20);
ArrayList<String> soundList = ((ExWorld) this.world).getSoundList();

int var2;
ButtonWidget var4;
for (var2 = 0; var2 + var1 * this.page - 1 < soundList.length && var2 < var1; ++var2) {
String var3 = "None";
if (var2 != 0 || this.page != 0) {
var3 = soundList[var2 + var1 * this.page - 1];
int soundsPerPage = 3 * ((this.height - 60) / 20);
for (int i = 0; i + soundsPerPage * this.page - 1 < soundList.size() && i < soundsPerPage; ++i) {
String name = "None";
if (i != 0 || this.page != 0) {
name = soundList.get(i + soundsPerPage * this.page - 1);
}

var4 = new ButtonWidget(var2, 4 + var2 % 3 * this.width / 3, 60 + var2 / 3 * 20, (this.width - 16) / 3, 18, var3);
this.buttons.add(var4);
int x = 4 + i % 3 * this.width / 3;
int y = 60 + i / 3 * 20;
int w = (this.width - 16) / 3;

var button = new ButtonWidget(i, x, y, w, 18, name);
this.buttons.add(button);
}

var2 = soundList.length / var1 + 1;

for (int var5 = 0; var5 < var2; ++var5) {
var4 = new ButtonWidget(100 + var5, 4 + var5 * 50, 40, 46, 18, String.format("Page %d", var5 + 1));
this.buttons.add(var4);
int pageCount = soundList.size() / soundsPerPage + 1;
for (int i = 0; i < pageCount; ++i) {
var button = new ButtonWidget(100 + i, 4 + i * 50, 40, 46, 18, String.format("Page %d", i + 1));
this.buttons.add(button);
}

}

@Override
protected void buttonClicked(ButtonWidget button) {
if (button.id == 0 && this.page == 0) {
this.msg.sound = "";
} else if (button.id < 100) {
int var2 = 3 * ((this.height - 60) / 20);
this.msg.sound = ((ExWorld) this.world).getSoundList()[button.id - 1 + var2 * this.page];
int soundId = 3 * ((this.height - 60) / 20);
this.msg.sound = ((ExWorld) this.world).getSoundList().get(button.id - 1 + soundId * this.page);
} else {
this.page = button.id - 100;
this.buttons.clear();
Expand Down Expand Up @@ -78,7 +79,7 @@ public void render(int mouseX, int mouseY, float deltaTime) {
if (!this.msg.sound.equals("")) {
this.drawTextWithShadow(this.textRenderer, String.format("Sound: %s", this.msg.sound), 4, 24, 14737632);
} else {
this.drawTextWithShadow(this.textRenderer, String.format("Sound: None"), 4, 24, 14737632);
this.drawTextWithShadow(this.textRenderer, "Sound: None", 4, 24, 14737632);
}

super.render(mouseX, mouseY, deltaTime);
Expand Down
62 changes: 32 additions & 30 deletions src/main/java/dev/adventurecraft/awakening/common/AC_GuiMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,68 @@
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.world.World;

import java.util.ArrayList;

public class AC_GuiMusic extends Screen {

private World world;
private AC_TileEntityMusic music;
private GuiSlider2 fadeOut;
private GuiSlider2 fadeIn;
private int page;

public AC_GuiMusic(World var1, AC_TileEntityMusic var2) {
this.world = var1;
this.music = var2;
public AC_GuiMusic(World world, AC_TileEntityMusic entity) {
this.world = world;
this.music = entity;
}

public void tick() {
}

public void initVanillaScreen() {
String[] musicList = ((ExWorld) this.world).getMusicList();

int var1 = 3 * ((this.height - 60) / 20);
ArrayList<String> musicList = ((ExWorld) this.world).getMusicList();

int var2;
ButtonWidget var4;
for (var2 = 0; var2 + var1 * this.page <= musicList.length && var2 < var1; ++var2) {
String var3 = "Stop Music";
if (var2 != 0 || this.page != 0) {
var3 = musicList[var2 - 1 + var1 * this.page];
int musicPerPage = 3 * ((this.height - 60) / 20);
for (int i = 0; i + musicPerPage * this.page <= musicList.size() && i < musicPerPage; ++i) {
String name = "Stop Music";
if (i != 0 || this.page != 0) {
name = musicList.get(i - 1 + musicPerPage * this.page);
}

var4 = new ButtonWidget(var2, 4 + var2 % 3 * this.width / 3, 60 + var2 / 3 * 20, (this.width - 16) / 3, 18, var3);
this.buttons.add(var4);
int x = 4 + i % 3 * this.width / 3;
int y = 60 + i / 3 * 20;
int w = (this.width - 16) / 3;

var button = new ButtonWidget(i, x, y, w, 18, name);
this.buttons.add(button);
}

this.fadeOut = new GuiSlider2(200, 4, 16, 10, String.format("Fade Out: %d", this.music.fadeOut), (float) this.music.fadeOut / 5000.0F);
this.fadeIn = new GuiSlider2(201, this.width / 2, 16, 10, String.format("Fade In: %d", this.music.fadeIn), (float) this.music.fadeIn / 5000.0F);
this.buttons.add(this.fadeOut);
this.buttons.add(this.fadeIn);
var2 = (musicList.length - 1) / var1 + 1;

for (int var5 = 0; var5 < var2; ++var5) {
var4 = new ButtonWidget(100 + var5, 4 + var5 * 50, 40, 46, 18, String.format("Page %d", var5 + 1));
this.buttons.add(var4);
int pageCount = (musicList.size() - 1) / musicPerPage + 1;
for (int i = 0; i < pageCount; ++i) {
var button = new ButtonWidget(100 + i, 4 + i * 50, 40, 46, 18, String.format("Page %d", i + 1));
this.buttons.add(button);
}

}

protected void buttonClicked(ButtonWidget var1) {
if (var1.id == 0 && this.page == 0) {
protected void buttonClicked(ButtonWidget button) {
if (button.id == 0 && this.page == 0) {
this.music.musicName = "";
} else if (var1.id < 100) {
} else if (button.id < 100) {
int var2 = 3 * ((this.height - 60) / 20);
this.music.musicName = ((ExWorld) this.world).getMusicList()[var1.id + var2 * this.page - 1];
} else if (var1.id < 200) {
this.page = var1.id - 100;
this.music.musicName = ((ExWorld) this.world).getMusicList().get(button.id + var2 * this.page - 1);
} else if (button.id < 200) {
this.page = button.id - 100;
this.buttons.clear();
this.initVanillaScreen();
}

}

public void render(int var1, int var2, float var3) {
public void render(int mouseX, int mouseY, float deltaTime) {
this.fill(0, 0, this.width, this.height, Integer.MIN_VALUE);
if (this.music.musicName.equals("")) {
this.drawTextWithShadow(this.textRenderer, "Music: Stop Music", 4, 4, 14737632);
Expand All @@ -77,12 +79,12 @@ public void render(int var1, int var2, float var3) {
this.fadeOut.text = String.format("Fade Out: %d", this.music.fadeOut);
this.music.fadeIn = (int) (this.fadeIn.sliderValue * 5000.0F + 0.5F);
this.fadeIn.text = String.format("Fade In: %d", this.music.fadeIn);
super.render(var1, var2, var3);
super.render(mouseX, mouseY, deltaTime);
this.world.getChunk(this.music.x, this.music.z).method_885();
}

public static void showUI(World var0, AC_TileEntityMusic var1) {
Minecraft.instance.openScreen(new AC_GuiMusic(var0, var1));
public static void showUI(World world, AC_TileEntityMusic entity) {
Minecraft.instance.openScreen(new AC_GuiMusic(world, entity));
}

public boolean isPauseScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ public void loadScripts(ProgressListener progressListener) {
return;
}

long lastNotifyTime = 0;

for (int i = 0; i < files.length; i++) {
File file = files[i];
String fileName = file.getName();
String name = fileName.toLowerCase();

if (name.endsWith(".js")) {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
try (var reader = new BufferedReader(new FileReader(file))) {
var script = ((ExWorld) this.world).getScript().compileReader(reader, fileName);
this.scripts.put(name, new AC_JScriptInfo(fileName, script));
} catch (IOException e) {
Expand All @@ -54,13 +52,8 @@ public void loadScripts(ProgressListener progressListener) {
}

if (progressListener != null) {
long currTime = System.currentTimeMillis();
if (currTime - lastNotifyTime > 25L) {
lastNotifyTime = currTime;

progressListener.notifyProgress(String.format("%4d / %4d", i + 1, files.length));
progressListener.progressStagePercentage((int) ((100.0 * (double) i / files.length)));
}
progressListener.notifyProgress(String.format("%4d / %4d", i + 1, files.length));
progressListener.progressStagePercentage((int) ((100.0 * (double) i / files.length)));
}
}

Expand Down
110 changes: 60 additions & 50 deletions src/main/java/dev/adventurecraft/awakening/common/GuiCreateNewMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.lwjgl.input.Keyboard;

public class GuiCreateNewMap extends Screen {

private Screen parent;
private TextboxWidget textboxMapName;
private TextboxWidget textboxSeed;
Expand All @@ -32,22 +33,24 @@ public class GuiCreateNewMap extends Screen {
GuiSlider2 sliderVolatilityWeight1;
GuiSlider2 sliderVolatilityWeight2;

public GuiCreateNewMap(Screen var1) {
this.parent = var1;
public GuiCreateNewMap(Screen parent) {
this.parent = parent;
}

@Override
public void tick() {
this.textboxMapName.tick();
this.textboxSeed.tick();
}

@Override
public void initVanillaScreen() {
TranslationStorage var1 = TranslationStorage.getInstance();
TranslationStorage ts = TranslationStorage.getInstance();
Keyboard.enableRepeatEvents(true);
this.buttons.clear();
this.buttons.add(new ButtonWidget(0, this.width / 2 - 205, 200, "Create Map"));
this.buttons.add(new ButtonWidget(1, this.width / 2 + 5, 200, var1.translate("gui.cancel")));
this.textboxMapName = new TextboxWidget(this, this.textRenderer, this.width / 2 - 100, 38, 200, 20, var1.translate("selectWorld.newWorld"));
this.buttons.add(new ButtonWidget(1, this.width / 2 + 5, 200, ts.translate("gui.cancel")));
this.textboxMapName = new TextboxWidget(this, this.textRenderer, this.width / 2 - 100, 38, 200, 20, ts.translate("selectWorld.newWorld"));
this.textboxMapName.selected = true;
this.textboxMapName.setMaxLength(32);
this.textboxSeed = new TextboxWidget(this, this.textRenderer, this.width / 2 - 100, 62, 200, 20, "");
Expand Down Expand Up @@ -101,59 +104,64 @@ private void updateSliders() {
this.sliderVolatilityWeight2.text = String.format("Volatility Weight 2: %.2f", wgp.volatilityWeight2);
}

@Override
public void onClose() {
Keyboard.enableRepeatEvents(false);
}

protected void buttonClicked(ButtonWidget var1) {
if (var1.active) {
if (var1.id == 1) {
this.client.openScreen(this.parent);
} else if (var1.id == 0) {
this.client.openScreen(null);
if (this.createClicked) {
return;
}
@Override
protected void buttonClicked(ButtonWidget button) {
if (!button.active) {
return;
}

this.createClicked = true;
long var2 = (new Random()).nextLong();
String var4 = this.textboxSeed.getText();
if (!MathHelper.isStringEmpty(var4)) {
try {
long var5 = Long.parseLong(var4);
if (var5 != 0L) {
var2 = var5;
}
} catch (NumberFormatException var7) {
var2 = var4.hashCode();
if (button.id == 1) {
this.client.openScreen(this.parent);
} else if (button.id == 0) {
this.client.openScreen(null);
if (this.createClicked) {
return;
}

this.createClicked = true;
long wSeed = (new Random()).nextLong();
String wSeedStr = this.textboxSeed.getText();
if (!MathHelper.isStringEmpty(wSeedStr)) {
try {
long parsedSeed = Long.parseLong(wSeedStr);
if (parsedSeed != 0L) {
wSeed = parsedSeed;
}
} catch (NumberFormatException var7) {
wSeed = wSeedStr.hashCode();
}

this.client.interactionManager = new SingleplayerInteractionManager(this.client);
AC_DebugMode.levelEditing = true;
String var8 = this.textboxMapName.getText().trim();
((ExMinecraft) this.client).saveMapUsed(var8, var8);
World var6 = ((ExMinecraft) this.client).getWorld(var8, var2, var8);
WorldGenProperties wgpS = this.worldGenProps;
WorldGenProperties wgpD = ((ExWorldProperties) var6.properties).getWorldGenProps();
wgpD.useImages = wgpS.useImages;
wgpD.mapSize = wgpS.mapSize;
wgpD.waterLevel = wgpS.waterLevel;
wgpD.fractureHorizontal = wgpS.fractureHorizontal;
wgpD.fractureVertical = wgpS.fractureVertical;
wgpD.maxAvgDepth = wgpS.maxAvgDepth;
wgpD.maxAvgHeight = wgpS.maxAvgHeight;
wgpD.volatility1 = wgpS.volatility1;
wgpD.volatility2 = wgpS.volatility2;
wgpD.volatilityWeight1 = wgpS.volatilityWeight1;
wgpD.volatilityWeight2 = wgpS.volatilityWeight2;
((ExWorld) var6).updateChunkProvider();
this.client.notifyStatus(var6, "Generating level");
this.client.openScreen(null);
}

this.client.interactionManager = new SingleplayerInteractionManager(this.client);
AC_DebugMode.levelEditing = true;
String wName = this.textboxMapName.getText().trim();
((ExMinecraft) this.client).saveMapUsed(wName, wName);
World world = ((ExMinecraft) this.client).getWorld(wName, wSeed, wName);
WorldGenProperties wgpS = this.worldGenProps;
WorldGenProperties wgpD = ((ExWorldProperties) world.properties).getWorldGenProps();
wgpD.useImages = wgpS.useImages;
wgpD.mapSize = wgpS.mapSize;
wgpD.waterLevel = wgpS.waterLevel;
wgpD.fractureHorizontal = wgpS.fractureHorizontal;
wgpD.fractureVertical = wgpS.fractureVertical;
wgpD.maxAvgDepth = wgpS.maxAvgDepth;
wgpD.maxAvgHeight = wgpS.maxAvgHeight;
wgpD.volatility1 = wgpS.volatility1;
wgpD.volatility2 = wgpS.volatility2;
wgpD.volatilityWeight1 = wgpS.volatilityWeight1;
wgpD.volatilityWeight2 = wgpS.volatilityWeight2;
((ExWorld) world).updateChunkProvider();
this.client.notifyStatus(world, "Generating level");
this.client.openScreen(null);
}
}

@Override
protected void keyPressed(char var1, int var2) {
this.textboxMapName.keyPressed(var1, var2);
this.textboxSeed.keyPressed(var1, var2);
Expand All @@ -164,14 +172,16 @@ protected void keyPressed(char var1, int var2) {
((ButtonWidget) this.buttons.get(0)).active = this.textboxMapName.getText().length() > 0;
}

@Override
protected void mouseClicked(int var1, int var2, int var3) {
super.mouseClicked(var1, var2, var3);
this.textboxMapName.mouseClicked(var1, var2, var3);
this.textboxSeed.mouseClicked(var1, var2, var3);
}

public void render(int var1, int var2, float var3) {
TranslationStorage var4 = TranslationStorage.getInstance();
@Override
public void render(int mouseX, int mouseY, float deltaTime) {
TranslationStorage ts = TranslationStorage.getInstance();
this.renderBackground();
this.drawTextWithShadowCentred(this.textRenderer, "Create Random Map", this.width / 2, 20, 16777215);
String var5 = "Map Name:";
Expand All @@ -181,6 +191,6 @@ public void render(int var1, int var2, float var3) {
this.textboxMapName.draw();
this.textboxSeed.draw();
this.updateSliders();
super.render(var1, var2, var3);
super.render(mouseX, mouseY, deltaTime);
}
}
Loading

0 comments on commit 190d899

Please sign in to comment.