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

Remove all items from the creative search tab to prevent lag/crash #241

Merged
merged 1 commit into from
Sep 14, 2023
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
2 changes: 2 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class LoadingConfig {
public boolean optimizeWorldUpdateLight;
public boolean preventPickupLoot;
public boolean removeSpawningMinecartSound;
public boolean removeCreativeSearchTab;

public boolean enableMacosCmdShortcuts;
public boolean fixFontRendererLinewrapRecursion;
Expand Down Expand Up @@ -297,6 +298,7 @@ public LoadingConfig(File file) {
preventPickupLoot = config.get(Category.TWEAKS.toString(), "preventPickupLoot", true, "Prevent monsters from picking up loot.").getBoolean();
enableMacosCmdShortcuts = config.get(Category.TWEAKS.toString(), "enableMacosCmdShortcuts", true, "Use CMD key on MacOS to COPY / INSERT / SELECT in text fields (Chat, NEI, Server IP etc.)").getBoolean();
removeSpawningMinecartSound = config.get(Category.TWEAKS.toString(), "removeSpawningMinecartSound", true, "Stop playing a sound when spawning a minecart in the world").getBoolean();
removeCreativeSearchTab = config.get(Category.FIXES.toString(), "removeCreativeSearchTab", true, "Disable the creative search tab since it can be very laggy in large modpacks").getBoolean();
removeUpdateChecks = config.get(Category.FIXES.toString(), "removeUpdateChecks", true, "Remove old/stale/outdated update checks.").getBoolean();
chunkSaveCMEDebug = config.get(Category.DEBUG.toString(), "chunkSaveCMEDebug", false, "Enable chunk save cme debugging code.").getBoolean();
renderDebug = config.get(Category.DEBUG.toString(), "renderDebug", true, "Enable GL state debug hooks. Will not do anything useful unless mode is changed to nonzero.").getBoolean();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ public enum Mixins {
.addMixinClasses("minecraft.MixinBlock_FixXray", "minecraft.MixinWorld_FixXray")
.setApplyIf(() -> Common.config.fixPerspectiveCamera).addTargetedMod(TargetedMod.VANILLA)
.setPhase(Phase.EARLY)),
DISABLE_CREATIVE_TAB_ALL_SEARCH(new Builder("Disable the creative tab with search bar").setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinGuiContainerCreative").setSide(Side.CLIENT)
.setApplyIf(() -> Common.config.removeCreativeSearchTab).addTargetedMod(TargetedMod.VANILLA)),

// Ic2 adjustments
IC2_UNPROTECTED_GET_BLOCK_FIX(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum TargetedMod {
HARVESTTHENETHER("harvestthenether", null, "harvestthenether"),
HUNGER_OVERHAUL("HungerOverhaul", null, "HungerOverhaul"),
IC2("IC2", "ic2.core.coremod.IC2core", "IC2"),
IMMERSIVE_ENGINENEERING("Immersive Engineering", null, "ImmersiveEngineering"),
JOURNEYMAP("JourneyMap", null, "journeymap"),
LOTR("The Lord of the rings mod", "lotr.common.coremod.LOTRLoadingPlugin", "lotr"),
LWJGL3IFY("lwjgl3ify", "me.eigenraven.lwjgl3ify.core.Lwjgl3ifyCoremod", "lwjgl3ify"),
Expand All @@ -33,7 +34,6 @@ public enum TargetedMod {
VANILLA("Minecraft", null),
WITCHERY("Witchery", null, "witchery"),
XAEROWORLDMAP("Xaero's World Map", null, "XaeroWorldMap"),
IMMERSIVE_ENGINENEERING("Immersive Engineering", null, "ImmersiveEngineering"),
ZTONES("ZTones", null, "Ztones");

/** The "name" in the @Mod annotation */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import java.util.List;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.inventory.Container;
import net.minecraft.util.EnumChatFormatting;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.gtnewhorizon.mixinextras.injector.ModifyExpressionValue;
import com.gtnewhorizon.mixinextras.injector.WrapWithCondition;

@Mixin(GuiContainerCreative.class)
public abstract class MixinGuiContainerCreative extends GuiContainer {

@Shadow
private static int selectedTabIndex;

public MixinGuiContainerCreative(Container p_i1072_1_) {
super(p_i1072_1_);
}

@Inject(
method = "drawScreen",
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glColor4f(FFFF)V", shift = At.Shift.BEFORE))
private void hodgepodge$drawMessageInfoInTab(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
if (selectedTabIndex == CreativeTabs.tabAllSearch.getTabIndex()) {
final String text = EnumChatFormatting.RED + "Use NEI to browse items!";
final int xOffset = mc.fontRenderer.getStringWidth(text) / 2;
mc.fontRenderer.drawStringWithShadow(
text,
this.guiLeft + this.xSize / 2 - xOffset,
this.guiTop + this.ySize / 2 - mc.fontRenderer.FONT_HEIGHT,
0xFFFFFF);
}
}

@ModifyExpressionValue(
method = "keyTyped",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/settings/GameSettings;isKeyDown(Lnet/minecraft/client/settings/KeyBinding;)Z"))
private boolean hodgepodge$disableChatKeybind(boolean original) {
return false;
}

@Inject(
method = "updateCreativeSearch",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/item/Item;itemRegistry:Lnet/minecraft/util/RegistryNamespaced;",
shift = At.Shift.BEFORE),
cancellable = true)
private void hodgepodge$disableCreativeSearch(CallbackInfo ci) {
ci.cancel();
}

@WrapWithCondition(
method = "setCurrentCreativeTab",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/creativetab/CreativeTabs;displayAllReleventItems(Ljava/util/List;)V"))
private boolean hodgepodge$removeAllItemsFromTab(CreativeTabs tab, @SuppressWarnings("rawtypes") List list) {
return tab != CreativeTabs.tabAllSearch;
}

}