Skip to content

Commit 267ed3e

Browse files
committed
Stable Beta 0.8.5.9
1 parent 894d186 commit 267ed3e

6 files changed

Lines changed: 239 additions & 111 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
# Server Mod Menu
1+
# Server Mod Menu - 0.8.5.9
22
### A direct fork of [ModMenu](https://github.com/TerraformersMC/ModMenu) made for downloading and getting details of server mods
33
![An image](https://cdn.modrinth.com/data/mdAdBC85/images/bab950bf491ccdb79a2b7b5001cf3ebc86f847cb.png)
44

5+
## Do you need to update?
6+
I recommand you download this update just because of the added measures to downloads that fail.
7+
58
## Running and using this mod
69
It's pretty easy, download the mod's jar file and run minecraft.
710
No extra nonsense or dependencies to install just like the original modmenu mod.
@@ -17,11 +20,9 @@ Since this mod needs to see the mods, i created a secondary server side mod name
1720
You can download the appropriate version of [SCMC](https://github.com/SkellyBuilds/scmc) for your server, make sure to read the documentation so that you don't make your members download unnecessary server side mods that aren't flagged as server side only.
1821

1922
## ChangeLog
20-
* Fixed the calculations for Showing [Number] servers
21-
* Added different (buggy) colors for optional & required mods for the mod list.
22-
* Optional mods are an thing now (As of SCMC version 0.9.2.7) and they are now natively supported to servermodmenu
23-
* Bug fixes
24-
* ***Added SRV support! Learn more [here](https://github.com/SkellyBuilds/scmc/wiki/Getting-started-using-SCMC#how-do-i-use-different-ports-properly)***
23+
You wouldn't be seeing much BIG changelogs other than bug fixes and added adjustments as the first release itself had everything
24+
* Adding measures to prevent downloading or setting the wrong variables when a download fails
25+
* A bit of GUI fixes.
2526

2627
## Stuff that hasn't been worked on
2728
* **Translations - Switching the language that isn't EN_US will pretty make the mod chaotic. I will plan on making a crowdin as well but for now. Sorry :(**

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.20.1+build.2
88
loader_version=0.16.0
99
fabric_version=0.92.2+1.20.1
1010
quilt_loader_version=0.17.7
11-
mod_version=0.8.3.9
11+
mod_version=0.8.5.9
1212
# Project Metadata
1313
project_name=Server Mod Menu
1414
project_url=https://modrinth.com/mod/servermodmenu

src/main/java/com/skellybuilds/servermodmenu/gui/ModsScreen.java

Lines changed: 101 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ public class ModsScreen extends Screen {
9090
private ServerList serverList;
9191
public AtomicInteger amountofvmods = new AtomicInteger();
9292

93-
94-
9593
public ModsScreen(Screen previousScreen) {
9694
super(Text.translatable("servermodmenu.title"));
9795
this.previousScreen = previousScreen;
@@ -123,8 +121,19 @@ private boolean NThreadsFinished(){
123121
}
124122

125123
public void switchToConfirm(){
126-
MinecraftClient.getInstance().setScreen(new ConfirmationScreen(this, this::resCB, this::backCB, Text.literal("Do you wish to close the game?")
127-
.formatted(Formatting.ITALIC).formatted(Formatting.GREEN)));
124+
this.client.execute(() -> {
125+
this.client.setScreen(new ConfirmationScreen(this, this::resCB, this::backCB, Text.literal("All of your mods have finished downloading! Do you wish to close the game?")
126+
.formatted(Formatting.ITALIC).formatted(Formatting.GREEN)));
127+
});
128+
129+
}
130+
131+
public void switchToConfirmCS(String CSText){
132+
this.client.execute(() -> {
133+
this.client.setScreen(new ConfirmationScreen(this, this::resCB, this::backCB, Text.literal(CSText)
134+
.formatted(Formatting.ITALIC).formatted(Formatting.GREEN)));
135+
});
136+
128137
}
129138

130139
@Override
@@ -165,8 +174,6 @@ public void calcServersSize(){
165174
@Override
166175
protected void init() {
167176

168-
169-
170177
serverList = new ServerList(client);
171178
serverList.loadFile();
172179

@@ -230,62 +237,90 @@ protected void init() {
230237

231238
// Downloads all from each server. Yep, may take time!
232239
ButtonWidget downloadAllSButton = new TexturedButtonWidget(paneWidth / 2 + searchBoxWidth / 2 - 20 / 2 + 41, 22, 20, 20, 0, 0, 20, DOWNLOSD_BUTTON_LOCATION, 32, 64, button -> {
240+
233241
final SoundManager[] tempmgr = new SoundManager[1];
234242
boolean change = false;
235-
243+
button.active = false;
236244
Thread finalT = new Thread(() -> {
237-
for (ModListEntry child : modList.children()) {
238-
245+
AtomicBoolean isERRORD = new AtomicBoolean(false);
246+
AtomicBoolean isSUCONCE = new AtomicBoolean(false);
247+
modList.children().forEach((child) -> {
239248
if(child.isFirst){
240249
EntryButton mButton = ModMenu.buttonEntries.get(child.serverName);
241-
if(!change) {
250+
mButton.active = false;
251+
}
252+
});
253+
254+
modList.children().forEach((child) -> {
255+
if(child.isFirst) {
256+
EntryButton mButton = ModMenu.buttonEntries.get(child.serverName);
257+
if (!change) {
242258
tempmgr[0] = mButton.SOUNDMANAGER;
243259
}
244-
Thread mWa = new Thread(() -> {
245-
mButton.visible = false;
246-
boolean e = child.downloadA(mButton);
247-
while(true){
248-
if(e){
249-
break;
250-
}
260+
child.downloadA(mButton);
261+
boolean isDT0 = false;
262+
boolean isDTFW = false;
263+
while (true) {
264+
if(MainNetwork.isDthreadDone(child.serverName)){
265+
isDT0 = true;
266+
}
267+
if(isDT0 && !isDTFW){
251268
try {
252-
Thread.sleep(750);
253-
} catch (InterruptedException ex) {
254-
LOGGER.error(ex.toString());
269+
Thread.sleep(2950);
270+
} catch (InterruptedException e) {
271+
LOGGER.error("Interrupted: {}", e.toString());
272+
}
273+
if(MainNetwork.isDthreadDone(child.serverName)){
274+
if(Objects.equals(MainNetwork.networkErrors.get(child.serverName), "ERR")){
275+
button.active = true;
276+
button.visible = true;
277+
mButton.active = true;
278+
mButton.visible = true;
279+
tempmgr[0].play(PositionedSoundInstance.master(SoundEvents.ENTITY_VILLAGER_NO, 1.0F));
280+
isERRORD.set(true);
281+
break;
282+
} else {
283+
isDTFW = true;
284+
isSUCONCE.set(true);
285+
}
286+
} else isDT0 = false;
287+
} else {
288+
if(!isDTFW) {
289+
try {
290+
Thread.sleep(750);
291+
} catch (InterruptedException e) {
292+
LOGGER.error("Interrupted: {}", e.toString());
293+
}
294+
} else {
295+
break;
255296
}
256297
}
257-
});
258-
mWa.start();
259-
260-
while(true){
261-
if(mWa.getState() != Thread.State.RUNNABLE){
262-
break;
263-
}
264-
try {
265-
Thread.sleep(850);
266-
} catch (InterruptedException e) {
267-
LOGGER.error(e.toString());
268-
}
298+
}
299+
if(!isERRORD.get() && !isSUCONCE.get()) {
300+
mButton.visible = false;
269301
}
270302
}
303+
});
304+
305+
// if no errors & downloaded a server sucessfully
306+
if(!isERRORD.get() && isSUCONCE.get()) {
307+
tempmgr[0].play(PositionedSoundInstance.master(SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, 1.0F));
308+
button.visible = false;
309+
switchToConfirm();
310+
} // a server downlaoded successfully but another one failed!
311+
else if(isERRORD.get() && isSUCONCE.get()) {
312+
tempmgr[0].play(PositionedSoundInstance.master(SoundEvents.ENTITY_PLAYER_BIG_FALL, 1.0F));
313+
//button.visible = false;
314+
switchToConfirmCS("A server's mod successfully were downloaded but another one failed!!! Do you wish to close the game?");
315+
} // All servers failed to download!!!
316+
else if(isERRORD.get() && !isSUCONCE.get()){
317+
tempmgr[0].play(PositionedSoundInstance.master(SoundEvents.ENTITY_PLAYER_DEATH, 1.0F));
271318
}
272319
});
273320

274321
finalT.start();
275322

276-
while(true) {
277-
if(finalT.getState() != Thread.State.RUNNABLE){
278-
ModMenu.isAllDFB = true;
279-
if(tempmgr[0] == null) break;
280-
tempmgr[0].play(PositionedSoundInstance.master(SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, 1.0F));
281-
break;
282-
}
283-
try {
284-
Thread.sleep(850);
285-
} catch (InterruptedException e) {
286-
LOGGER.error(e.toString());
287-
}
288-
}
323+
289324

290325
}){
291326
@Override
@@ -351,21 +386,29 @@ public void renderButton(DrawContext DrawContext, int mouseX, int mouseY, float
351386

352387
orgw.start();
353388

389+
AtomicBoolean isNE = new AtomicBoolean(false);
390+
354391
Thread bla = new Thread(() -> {
355392
while (true) {
356393
if (orgw.getState() != Thread.State.RUNNABLE) {
357-
ModMenu.idsDLD.add(selected.getSMod().id);
358-
selected.smod.isDownloaded = true;
394+
if(Objects.equals(MainNetwork.networkErrors.get(selected.serverName), "ERR")){
359395
button.active = true;
360-
if(!ModMenu.isAllDFB){
361-
List<Boolean> isAllt = new ArrayList<>();
362-
ModMenu.buttonEntries.forEach((name, mButton) -> {
363-
if(!mButton.visible)
364-
isAllt.add(true);
365-
});
366-
367-
if(isAllt.size() == ModMenu.buttonEntries.size())
368-
ModMenu.isAllDFB = true;
396+
button.visible = true;
397+
isNE.set(true);
398+
} else {
399+
ModMenu.idsDLD.add(selected.getSMod().id);
400+
selected.smod.isDownloaded = true;
401+
button.active = true;
402+
if (!ModMenu.isAllDFB) {
403+
List<Boolean> isAllt = new ArrayList<>();
404+
ModMenu.buttonEntries.forEach((name, mButton) -> {
405+
if (!mButton.visible)
406+
isAllt.add(true);
407+
});
408+
409+
if (isAllt.size() == ModMenu.buttonEntries.size())
410+
ModMenu.isAllDFB = true;
411+
}
369412
}
370413
break;
371414
}
@@ -377,7 +420,7 @@ public void renderButton(DrawContext DrawContext, int mouseX, int mouseY, float
377420

378421
do {
379422
if (bla.getState() != Thread.State.RUNNABLE) {
380-
switchToConfirm();
423+
if(!isNE.get()) switchToConfirm();
381424
break;
382425
}
383426
} while (true);
@@ -424,6 +467,7 @@ public void render(DrawContext DrawContext, int mouseX, int mouseY, float delta)
424467
}
425468

426469
visible = true;
470+
active = true;
427471

428472
super.render(DrawContext, mouseX, mouseY, delta);
429473
return;

src/main/java/com/skellybuilds/servermodmenu/gui/widget/ModListWidget.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class ModListWidget extends AlwaysSelectedEntryListWidget<ModListEntry> i
4242
private boolean scrolling;
4343
private final FabricIconHandler iconHandler = new FabricIconHandler();
4444
private boolean isInit = false;
45+
private double scrollAm;
46+
private int origT;
4547

4648
public ModListWidget(MinecraftClient client, int width, int height, int y1, int y2, int entryHeight, String searchTerm, ModListWidget list, ModsScreen parent) {
4749
super(client, width, height, y1, y2, entryHeight);
@@ -161,6 +163,10 @@ protected boolean removeEntry(ModListEntry entry) {
161163
return super.removeEntry(entry);
162164
}
163165

166+
protected void removeAllEntries(){
167+
children().forEach(super::removeEntry);
168+
}
169+
164170
@Override
165171
protected ModListEntry remove(int index) {
166172
if(getEntry(index).useSMOD()) addedMods.remove(getEntry(index).smod);
@@ -191,6 +197,8 @@ private void filter(String searchTerm, boolean refresh, boolean search) {
191197
this.clearEntries();
192198
SaddedMods.clear();
193199
addedMods.clear();
200+
this.removeAllEntries();
201+
194202
if (useSMod) {
195203

196204

@@ -224,15 +232,17 @@ private void filter(String searchTerm, boolean refresh, boolean search) {
224232
AtomicBoolean isHidden = new AtomicBoolean(false);
225233
boolean isF = true;
226234
for (SMod mod : matched) {
227-
if(isF){
235+
236+
237+
228238
ModMenuConfig.HIDDEN_SERVERS.getValue().forEach((name) -> {
229239
if(Objects.equals(name, serverName)){
230240
if(!ModMenuConfig.SHOWHIDDENSERVERS.getValue()){
231241
isHidden.set(true);
232242
}
233243
}
234244
});
235-
}
245+
236246

237247
if(matched.isEmpty()){
238248
if(isHidden.get() && ModMenuConfig.SHOWHIDDENSERVERS.getValue() || !isHidden.get()) {
@@ -245,23 +255,38 @@ private void filter(String searchTerm, boolean refresh, boolean search) {
245255

246256
if(isHidden.get() && ModMenuConfig.SHOWHIDDENSERVERS.getValue() || !isHidden.get()) {
247257
this.addEntry(new IndependentEntry(mod, this, serverName, isF, false, addMoreY.get()));
258+
259+
}
260+
261+
if(isHidden.get() && ModMenuConfig.SHOWHIDDENSERVERS.getValue() || !isHidden.get()){
262+
isF = false;
248263
}
249-
isF = false;
250264
}
251265

252266
addMoreY.set(true);
253267

268+
269+
254270
if(children().size() > 1) {
255271
setSelected(getEntry(0));
256272
} else {
257273
setSelected(null);
258274
}
259275

260-
if (getScrollAmount() > Math.max(0, this.getMaxPosition() - (this.bottom - this.top - 4))) {
261-
setScrollAmount(Math.max(0, this.getMaxPosition() - (this.bottom - this.top - 4)));
262-
}
276+
263277
});
264278

279+
// if(children().size() > 2){
280+
// if(addMoreY.get()){
281+
// int wa2 = children().stream().filter((ra) -> ra.isFirst).toList().size()-1;
282+
//
283+
// this.top = this.top - 6 * wa2;
284+
// }
285+
// }
286+
287+
if (getScrollAmount() > Math.max(0, this.getMaxPosition() - (this.bottom - this.top - 4))) {
288+
setScrollAmount(Math.max(0, this.getMaxPosition() - (this.bottom - this.top - 4)));
289+
}
265290
parent.calcServersSize();
266291

267292
isInit = true;
@@ -359,20 +384,19 @@ protected void renderList(DrawContext DrawContext, int mouseX, int mouseY, float
359384
ModListEntry entry = this.getEntry(index);
360385

361386

362-
int entryTop = entry.isFirst ? this.getRowTop(index) + 12 : this.getRowTop(index) + 15;
387+
int entryTop = this.getRowTop(index) + 12;
363388
//int entryBottom = entry.isFirst ? this.getRowTop(index) + this.itemHeight + 8 : this.getRowTop(index) + this.itemHeight ;
364389

365-
if(entry.moreY) entryTop = entryTop + 17;
390+
//if(entry.moreY) entryTop = entryTop + 17;
366391

367392

368393
int entryHeight = this.itemHeight - 4;
369394

370-
// if(entry.moreY){
371-
// this.bottom = this.bottom + 7;
372-
// }
373-
374395
int rowWidth = this.getRowWidth();
375396
int entryLeft;
397+
if(entry.moreY){
398+
// rowWidth = rowWidth + 8;
399+
}
376400
if (this.isSelectedEntry(index) && !entry.renderSvnNO) {
377401

378402
entryLeft = getRowLeft() - 2 + entry.getXOffset();

0 commit comments

Comments
 (0)