Skip to content

Commit

Permalink
fix networked config sync
Browse files Browse the repository at this point in the history
fix #39
  • Loading branch information
Glease committed Jul 12, 2023
1 parent 7e7b26e commit 89f7a09
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
35 changes: 21 additions & 14 deletions src/main/java/net/glease/tc4tweak/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import net.glease.tc4tweak.asm.ASMCallhook;
import net.glease.tc4tweak.asm.LoadingPlugin;
import net.glease.tc4tweak.modules.researchBrowser.BrowserPaging;
Expand All @@ -31,7 +32,6 @@
import thaumcraft.common.config.ConfigItems;

public class ClientProxy extends CommonProxy {
static final FMLEventHandler instance = new FMLEventHandler();
static long lastScroll = 0;
static Field fieldPage = null;
static Field fieldLastPage = null;
Expand All @@ -41,6 +41,8 @@ public class ClientProxy extends CommonProxy {
private static final int mPrevX = 261, mPrevY = 189, mNextX = -17, mNextY = 189;
private static final int paneWidth = 256, paneHeight = 181;

private long updateCounter = 0;

public static void handleMouseInput(GuiResearchTable screen) {
if (fieldLastPage == null || fieldPage == null || methodPlayScroll == null) return;
final int dwheel = Mouse.getEventDWheel();
Expand Down Expand Up @@ -98,6 +100,11 @@ public static void handleMouseInput(GuiResearchRecipe screen) {
}
}

public ClientProxy() {
super();
MinecraftForge.EVENT_BUS.register(this);
}

@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e);
Expand All @@ -124,8 +131,6 @@ public void preInit(FMLPreInitializationEvent e) {
System.err.println("Cannot find thaumcraft fields. Research page scrolling will not properly function!");
err.printStackTrace();
}
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(instance);
final IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
if (resourceManager instanceof IReloadableResourceManager) {
//noinspection Convert2Lambda
Expand Down Expand Up @@ -161,7 +166,6 @@ public void postInit(FMLPostInitializationEvent e) {
} catch (ReflectiveOperationException ignored) {
// WG is probably not installed, ignoring
}
FMLCommonHandler.instance().bus().register(this);
}

@SubscribeEvent
Expand All @@ -183,17 +187,20 @@ else if (e.itemStack.getItem() == ConfigItems.itemWandCasting) {
}
}

public static class FMLEventHandler {
private long updateCounter = 0;

@SubscribeEvent
public void onTickEnd(TickEvent.ClientTickEvent e) {
if (e.phase == TickEvent.Phase.END) {
if (++updateCounter > ConfigurationHandler.INSTANCE.getUpdateInterval()) {
updateCounter = 0;
ASMCallhook.updatePostponed();
}
@SubscribeEvent
public void onTickEnd(TickEvent.ClientTickEvent e) {
if (e.phase == TickEvent.Phase.END) {
if (++updateCounter > ConfigurationHandler.INSTANCE.getUpdateInterval()) {
updateCounter = 0;
ASMCallhook.updatePostponed();
}
}
}

@SubscribeEvent
public void onServerConnected(FMLNetworkEvent.ClientConnectedToServerEvent e) {
if (!e.isLocal) {
NetworkedConfiguration.resetClient();
}
}
}
10 changes: 7 additions & 3 deletions src/main/java/net/glease/tc4tweak/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import thaumcraft.common.entities.projectile.EntityPrimalArrow;

public class CommonProxy {
public CommonProxy() {
FMLCommonHandler.instance().bus().register(this);
}

public void preInit(FMLPreInitializationEvent e) {
ConfigurationHandler.INSTANCE.init(e.getSuggestedConfigurationFile());

Expand All @@ -44,8 +48,7 @@ public void preInit(FMLPreInitializationEvent e) {

public void serverStarted(FMLServerStartedEvent e) {
FlushableCache.enableAll(true);
NetworkedConfiguration.reset();
FMLCommonHandler.instance().bus().register(this);
NetworkedConfiguration.resetServer();
}

public void init(FMLInitializationEvent e) {
Expand Down Expand Up @@ -93,7 +96,8 @@ private void addDummyCategories(int amount, String categoryPrefix) {

@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent e) {
if (e.player instanceof EntityPlayerMP && !TC4Tweak.INSTANCE.isAllowAll()) {
if (e.player instanceof EntityPlayerMP && !((EntityPlayerMP) e.player).playerNetServerHandler.netManager.isLocalChannel()) {
// no point sending config over to a local client
TC4Tweak.INSTANCE.CHANNEL.sendTo(new MessageSendConfiguration(), (EntityPlayerMP) e.player);
TC4Tweak.INSTANCE.CHANNEL.sendTo(new MessageSendConfigurationV2(), (EntityPlayerMP) e.player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public MessageSendConfigurationV2() {

@Override
public void fromBytes(ByteBuf buf) {
ByteBufUtils.writeTag(buf, tag);
tag = ByteBufUtils.readTag(buf);
}

@Override
public void toBytes(ByteBuf buf) {
tag = ByteBufUtils.readTag(buf);
ByteBufUtils.writeTag(buf, tag);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@

public class NetworkedConfiguration {
static boolean checkWorkbenchRecipes = true;
static boolean smallerJar = true;
static boolean smallerJar = false;

public static boolean isCheckWorkbenchRecipes() {
return checkWorkbenchRecipes;
}

public static void reset() {
public static void resetServer() {
checkWorkbenchRecipes = ConfigurationHandler.INSTANCE.isCheckWorkbenchRecipes();
smallerJar = ConfigurationHandler.INSTANCE.isSmallerJars();
}

public static void resetClient() {
checkWorkbenchRecipes = ConfigurationHandler.INSTANCE.isCheckWorkbenchRecipes();
smallerJar = false;
}

public static boolean isSmallerJar() {
return smallerJar;
}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.12
1.5.13

0 comments on commit 89f7a09

Please sign in to comment.