Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configs not saving on closing config gui #9

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/com/cleanroommc/bogosorter/BogoSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
Expand Down Expand Up @@ -94,6 +96,11 @@ public void onPlayerJoin(EntityJoinWorldEvent event) {
PlayerConfig.syncToServer();
}
}
@SubscribeEvent
public void onPlayerLogout(FMLNetworkEvent.ClientDisconnectionFromServerEvent ignored){
// save config file on logout
Serializer.saveConfig();
}

@SubscribeEvent
public void onServerTick(TickEvent.WorldTickEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public void onKeyInput(InputEvent.MouseInputEvent event) {
@SubscribeEvent(priority = EventPriority.LOW)
public void onGuiKeyInput(KeyboardInputEvent.Pre event) {
KeyBind.checkKeys(getTicks());
if (!(event.gui instanceof GuiContainer)) return;
if (!(event.gui instanceof GuiContainer))
return;
if (handleInput((GuiContainer) event.gui)) {
event.setCanceled(true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public ConfigGui(GuiScreen old) {
public boolean shouldAnimate() {
return super.shouldAnimate() && ConfigGui.this.old == null;
}

@Override
public void onClose() {
super.onClose();
Serializer.saveConfig();
PlayerConfig.syncToServer();
MinecraftForge.EVENT_BUS.post(new SortConfigChangeEvent());
}
}.size(300, 250).align(Alignment.Center);

PagedWidget.Controller controller = new PagedWidget.Controller();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package com.cleanroommc.bogosorter.common.dropoff;

import com.cleanroommc.bogosorter.BogoSorter;
import com.cleanroommc.bogosorter.ClientEventHandler;
import com.cleanroommc.bogosorter.common.sort.ButtonHandler;
import com.cleanroommc.bogosorter.common.sort.IGuiContainerAccessor;
import com.cleanroommc.modularui.screen.GuiScreenWrapper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraftforge.client.event.GuiScreenEvent;

public class DropOffButtonHandler {

public static int buttonX = 80;
public static int buttonX = 120;
public static int buttonY = 12;

@SubscribeEvent
Expand All @@ -27,7 +24,7 @@ public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
return;
}
try {
if (screen instanceof InventoryEffectRenderer inv) {
if (screen instanceof GuiInventory inv) {
event.buttonList.add(new InvButton(inv));
}
} catch (NullPointerException e) {
Expand All @@ -41,7 +38,7 @@ public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
GuiScreen screen = event.gui;

if (screen instanceof InventoryEffectRenderer) {
if (screen instanceof GuiInventory) {
for (GuiButton guiButton : ((IGuiContainerAccessor) event.gui).getButtons()) {
if (guiButton instanceof InvButton invButton) {
invButton.drawTooltip(event.mouseX, event.mouseY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.client.resources.I18n;

import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;

public class InvButton extends GuiButton {
Expand Down
Loading