Skip to content

Commit

Permalink
Add option to skip search tree reloading on shutdown
Browse files Browse the repository at this point in the history
Closes #9
  • Loading branch information
LXGaming committed Dec 8, 2020
1 parent 0f76dfb commit f436baf
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ public class ForgeMixinCategory {
@Setting(value = "flush-network-on-tick", comment = "If 'true', reduces network usage by postponing flush.")
private boolean flushNetworkOnTick = false;

@Mapping(value = "forge.common.ForgeModContainerMixin")
@Mapping(value = "forge.fml.client.FMLClientHandlerMixin")
@Setting(value = "nuke-search-tree", comment = "If 'true', disables SearchTree reloading (Speeds up server connection process).")
private boolean nukeSearchTree = false;

@Mapping(value = "forge.fml.client.FMLClientHandlerMixin")
@Setting(value = "nuke-search-tree-shutdown", comment = "If 'true', disables SearchTree reloading on shutdown.")
private boolean nukeSearchTreeShutdown = false;

@Mapping(value = "forge.fml.common.network.simpleimpl.SimpleNetworkWrapperMixin")
@Setting(value = "packet-spam", comment = "If 'true', cancels packets sent by LootBags due to poorly written networking.")
private boolean packetSpam = false;
Expand All @@ -50,6 +54,10 @@ public boolean isNukeSearchTree() {
return nukeSearchTree;
}

public boolean isNukeSearchTreeShutdown() {
return nukeSearchTreeShutdown;
}

public boolean isPacketSpam() {
return packetSpam;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static void prepare() {
}

// Internal Mixins
MIXIN_MAPPINGS.put("core.client.MinecraftAccessor", true);
MIXIN_MAPPINGS.put("core.client.MinecraftMixin", true);
MIXIN_MAPPINGS.put("core.crash.CrashReportMixin", true);
MIXIN_MAPPINGS.put("core.server.DedicatedServerMixin", true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020 Alex Thomson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.lxgaming.sledgehammer.mixin.core.client;

import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(value = Minecraft.class)
public interface MinecraftAccessor {

@Accessor(value = "running")
boolean accessor$isRunning();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2020 Alex Thomson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.lxgaming.sledgehammer.mixin.forge.fml.client;

import io.github.lxgaming.sledgehammer.Sledgehammer;
import io.github.lxgaming.sledgehammer.configuration.Config;
import io.github.lxgaming.sledgehammer.configuration.category.MixinCategory;
import io.github.lxgaming.sledgehammer.configuration.category.mixin.ForgeMixinCategory;
import io.github.lxgaming.sledgehammer.mixin.core.client.MinecraftAccessor;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.client.FMLClientHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = FMLClientHandler.class, remap = false)
public abstract class FMLClientHandlerMixin {

/**
* Thanks covers1624
*/
@Inject(
method = "reloadSearchTrees",
at = @At(
value = "HEAD"
),
cancellable = true
)
private void onReloadSearchTrees(CallbackInfo callbackInfo) {
ForgeMixinCategory mixinCategory = Sledgehammer.getInstance().getConfig()
.map(Config::getMixinCategory)
.map(MixinCategory::getForgeMixinCategory)
.orElse(null);
if (mixinCategory == null) {
Sledgehammer.getInstance().getLogger().error("ForgeMixinCategory is unavailable");
return;
}

if (mixinCategory.isNukeSearchTree() || (mixinCategory.isNukeSearchTreeShutdown() && !((MinecraftAccessor) Minecraft.getMinecraft()).accessor$isRunning())) {
Sledgehammer.getInstance().getLogger().warn("Skipping reloadSearchTrees");
callbackInfo.cancel();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.sledgehammer.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"world.WorldMixin_ChunkUnload"
],
"client": [
"client.MinecraftAccessor",
"client.MinecraftMixin"
],
"server": [
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixins.sledgehammer.forge.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"world.storage.WorldInfoMixin"
],
"client": [
"common.ForgeModContainerMixin"
"fml.client.FMLClientHandlerMixin"
],
"server": [
],
Expand Down

0 comments on commit f436baf

Please sign in to comment.