Skip to content

Commit

Permalink
Added fast search to the option menu and fixed the restart trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Guichaguri committed Feb 10, 2017
1 parent 2d475be commit 946121a
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 18 deletions.
1 change: 1 addition & 0 deletions mappings.srg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CL: IInventory net/minecraft/inventory/IInventory
CL: ModelBox net/minecraft/client/model/ModelBox
CL: EntityRenderer net/minecraft/client/renderer/EntityRenderer
CL: GuiContainerCreative net/minecraft/client/gui/inventory/GuiContainerCreative
CL: RenderPlayer net/minecraft/client/renderer/entity/RenderPlayer

MD: startGame net/minecraft/client/Minecraft/init ()V
MD: freeMemory net/minecraft/client/Minecraft/freeMemory ()V
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/guichaguri/betterfps/BetterFpsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public class BetterFpsConfig {

public boolean fog = true;

public boolean beaconBeam = true;

public boolean fastHopper = true;

public boolean fastBeacon = true;

public boolean beaconBeam = true;
public boolean fastSearch = true;

public enum AlgorithmType {
@SerializedName("vanilla") VANILLA,
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/guichaguri/betterfps/gui/data/OptionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import guichaguri.betterfps.BetterFpsConfig.AlgorithmType;
import guichaguri.betterfps.BetterFpsHelper;
import guichaguri.betterfps.gui.GuiConfigOption;
import guichaguri.betterfps.transformers.Conditions;
import guichaguri.betterfps.tweaker.Mappings;
import java.util.List;
import net.minecraft.client.resources.I18n;

Expand Down Expand Up @@ -36,7 +38,7 @@ public static void addButtons(List<GuiConfigOption> buttons) {
algorithm.add(AlgorithmType.TAYLORS, "betterfps.options.algorithm.taylors");
algorithm.add(AlgorithmType.JAVA, "betterfps.options.algorithm.java");
algorithm.add(AlgorithmType.RANDOM, "betterfps.options.algorithm.random");
algorithm.setRestart(true);
algorithm.setRestart(Conditions.isPatched(Mappings.C_MathHelper));
algorithm.setWide(true);
algorithm.setDefaults(AlgorithmType.VANILLA, AlgorithmType.RIVENS_HALF, config.algorithm);
algorithm.setDescription(
Expand All @@ -60,44 +62,53 @@ public static void addButtons(List<GuiConfigOption> buttons) {
// Pre-allocate memory
GuiConfigOption<Boolean> allocMemory = new GuiConfigOption<Boolean>(2, "betterfps.options.allocmemory.title");
allocMemory.set(boolMap, enabledNames);
allocMemory.setRestart(true);
allocMemory.setRestart(Conditions.isPatched(Mappings.C_Minecraft));
allocMemory.setDefaults(true, false, config.preallocateMemory);
allocMemory.setDescription(I18n.format("betterfps.options.allocmemory.desc"));
buttons.add(allocMemory);

// Fog
GuiConfigOption<Boolean> fog = new GuiConfigOption<Boolean>(3, "betterfps.options.fog.title");
fog.set(boolMap, fancyFast);
fog.setRestart(true);
fog.setRestart(Conditions.isPatched(Mappings.C_EntityRenderer));
fog.setDefaults(true, true, config.fog);
fog.setDescription(I18n.format("betterfps.options.fog.desc"));
buttons.add(fog);

// Beacon Beam
GuiConfigOption<Boolean> beam = new GuiConfigOption<Boolean>(4, "betterfps.options.beaconbeam.title");
beam.set(boolMap, fancyFast);
beam.setRestart(true);
beam.setRestart(Conditions.isPatched(Mappings.C_TileEntityBeaconRenderer));
beam.setDefaults(true, true, config.beaconBeam);
beam.setDescription(I18n.format("betterfps.options.beaconbeam.desc"));
buttons.add(beam);

// Hopper Improvement
GuiConfigOption<Boolean> hopper = new GuiConfigOption<Boolean>(5, "betterfps.options.hopper.title");
hopper.set(boolMap, enabledNames);
hopper.setRestart(true);
hopper.setRestart(Conditions.isPatched(Mappings.C_TileEntityHopper));
hopper.setDefaults(false, true, config.fastHopper);
hopper.setDescription(I18n.format("betterfps.options.hopper.desc"));
hopper.setRestart(true);
buttons.add(hopper);

// Hopper Improvement
// Beacon Improvement
GuiConfigOption<Boolean> beacon;
beacon = new GuiConfigOption<Boolean>(6, "betterfps.options.beacon.title");
beacon.set(boolMap, enabledNames);
beacon.setRestart(true);
beacon.setRestart(Conditions.isPatched(Mappings.C_TileEntityBeacon));
beacon.setDefaults(false, true, config.fastBeacon);
beacon.setDescription(I18n.format("betterfps.options.beacon.desc"));
buttons.add(beacon);

// Creative Search Improvement
GuiConfigOption<Boolean> search;
search = new GuiConfigOption<Boolean>(7, "betterfps.options.creativesearch.title");
search.set(boolMap, enabledNames);
search.setRestart(Conditions.isPatched(Mappings.C_GuiContainerCreative));
search.setDefaults(false, true, config.fastSearch);
search.setDescription(I18n.format("betterfps.options.creativesearch.desc"));
buttons.add(search);
}

public static boolean store(List<GuiConfigOption> buttons) {
Expand All @@ -110,6 +121,7 @@ public static boolean store(List<GuiConfigOption> buttons) {
config.beaconBeam = getButtonValue(buttons, 4);
config.fastHopper = getButtonValue(buttons, 5);
config.fastBeacon = getButtonValue(buttons, 6);
config.fastSearch = getButtonValue(buttons, 7);

for(GuiConfigOption button : buttons) {
if(button.shouldRestart()) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void patch(Patch patch) {

for(JumpInsnNode node : ifNullNodes) {
AbstractInsnNode previous = node.getPrevious();
System.out.println(previous);

if(previous instanceof VarInsnNode) {
if(((VarInsnNode)previous).var == inv.index) {
ifNull = node;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package guichaguri.betterfps.patches.misc;

import guichaguri.betterfps.transformers.Conditions;
import guichaguri.betterfps.transformers.annotations.Condition;
import guichaguri.betterfps.transformers.annotations.Copy;
import guichaguri.betterfps.transformers.annotations.Copy.Mode;
import java.util.Iterator;
Expand All @@ -17,32 +19,42 @@
/**
* @author Guilherme Chaguri
*/
@Condition(Conditions.FAST_SEARCH)
public abstract class FastCreativeSearch extends GuiContainerCreative {
@Copy
private String oldSearchText;
@Copy
private NonNullList<ItemStack> itemBuffer;


public FastCreativeSearch(EntityPlayer player) {
super(player);
}

@Copy(Mode.PREPEND)
@Override
public void initGui() {
// When the Gui is initialized, let's create our buffer list

if(itemBuffer == null) itemBuffer = NonNullList.create();
}

@Copy(Mode.PREPEND)
@Override
public void setCurrentCreativeTab(CreativeTabs tab) {
// When the tab changes, clear the search history so when the search field is shown again, it will rebuild the results

oldSearchText = null;
}

@Copy(Mode.REPLACE)
@Override
public void updateCreativeSearch() {
// The search algorithm is still the same
// But the amount of work it has to do has been reduced
// Before this improvement, the search would have to rebuild its results everytime the text changed
// Now, the search only rebuilds completely when necessary
// It will also significantly reduce the amount of rebuilding work when adding/removing characters

String search = this.searchField.getText().toLowerCase(Locale.ROOT);
boolean rebuildCache = false;
GuiContainerCreative.ContainerCreative container = (GuiContainerCreative.ContainerCreative)this.inventorySlots;
Expand Down Expand Up @@ -76,13 +88,15 @@ public void updateCreativeSearch() {

Iterator<ItemStack> iterator = container.itemList.iterator();
boolean lookupBuffer = !itemBuffer.isEmpty();
EntityPlayer player = mc.player;
boolean advancedTooltips = mc.gameSettings.advancedItemTooltips;

while(iterator.hasNext()) {
ItemStack itemstack = iterator.next();

if(lookupBuffer && itemBuffer.contains(itemstack)) continue;

for(String s : itemstack.getTooltip(this.mc.player, this.mc.gameSettings.advancedItemTooltips)) {
for(String s : itemstack.getTooltip(player, advancedTooltips)) {
if(!TextFormatting.getTextWithoutFormattingCodes(s).toLowerCase(Locale.ROOT).contains(search)) {
iterator.remove();
break;
Expand All @@ -103,7 +117,7 @@ private void updateAdditionalItems(GuiContainerCreative.ContainerCreative contai
}

/**
* Forge has a method with the exact same name and descriptor which works with custom search tabs.
* Forge has a method with the exact same name and descriptor as this one which works with custom search tabs.
* To prevent conflicts, this is set to copy instead of replacing, so Forge should overwrite this method
*/
@Copy(Mode.COPY)
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/guichaguri/betterfps/transformers/Conditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import guichaguri.betterfps.BetterFpsConfig;
import guichaguri.betterfps.BetterFpsHelper;
import guichaguri.betterfps.transformers.annotations.Condition;
import guichaguri.betterfps.tweaker.Mappings;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.tree.AnnotationNode;

Expand All @@ -11,8 +13,11 @@
*/
public class Conditions {

protected static final List<Mappings> patched = new ArrayList<Mappings>();

public static final String FAST_HOPPER = "fastHopper";
public static final String FAST_BEACON = "fastBeacon";
public static final String FAST_SEARCH = "fastSearch";
public static final String FAST_BEAM_RENDER = "fastBeaconBeamRender";
public static final String FOG_DISABLED = "fogDisabled";

Expand All @@ -26,6 +31,8 @@ public static boolean shouldPatch(String condition) {
return config.fastHopper;
} else if(condition.equals(FAST_BEACON)) {
return config.fastBeacon;
} else if(condition.equals(FAST_SEARCH)) {
return config.fastSearch;
} else if(condition.equals(FAST_BEAM_RENDER)) {
return !config.beaconBeam;
} else if(condition.equals(FOG_DISABLED)) {
Expand All @@ -47,4 +54,8 @@ public static boolean shouldPatch(List<AnnotationNode> annotations) {
return true;
}

public static boolean isPatched(Mappings name) {
return patched.contains(name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ private byte[] patchMath(byte[] bytes) throws Exception {
}
}

Conditions.patched.add(Mappings.C_MathHelper);

return ASMUtils.writeClass(classNode, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class PatcherTransformer implements IClassTransformer {
patches.put(Mappings.C_EntityPlayerSP, "guichaguri/betterfps/patches/misc/ClientPlayerPatch");

patches.put(Mappings.C_GuiContainerCreative, "guichaguri/betterfps/patches/misc/FastCreativeSearch");
//patches.put(Mappings.C_RenderPlayer, "guichaguri/betterfps/patches/misc/PlayerModelPatch");
}

@Override
Expand Down Expand Up @@ -61,6 +62,7 @@ public byte[] transform(String name, String transformedName, byte[] bytes) {
private ClassNode findPatch(String name) {
for(Mappings m : patches.keySet()) {
if(m.is(name)) {
Conditions.patched.add(m);
return loadPatch(patches.get(m));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/guichaguri/betterfps/tweaker/Mappings.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public enum Mappings {
C_EntityRenderer(Type.CLASS, "EntityRenderer"),
C_IInventory(Type.CLASS, "IInventory"),
C_GuiContainerCreative(Type.CLASS, "GuiContainerCreative"),
C_RenderPlayer(Type.CLASS, "RenderPlayer"),

M_startGame(Type.METHOD, "startGame"), // Minecraft
M_sin(Type.METHOD, "sin"), // MathHelper
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/assets/betterfps/lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ betterfps.options.allocmemory.desc=Ob beim Start 10MB Arbeitsspeicher vorbelegt
betterfps.options.fog.title=Nebel
betterfps.options.fog.desc=Ob der Nebel dargestellt wird

betterfps.options.beaconbeam.title=Strahl des Leuchtfeuers
betterfps.options.beaconbeam.desc=Ob die transparente Schicht vom Strahl des Leuchtfeuers dargestellt wird

betterfps.options.hopper.title=Schnelle Trichter
betterfps.options.hopper.desc=Ob Optimierungen für Trichter aktiv sind

betterfps.options.beacon.title=Schnelle Leuchtfeuer
betterfps.options.beacon.desc=Ob Optimierungen für Leuchtfeuer aktiv sind

betterfps.options.beaconbeam.title=Strahl des Leuchtfeuers
betterfps.options.beaconbeam.desc=Ob die transparente Schicht vom Strahl des Leuchtfeuers dargestellt wird
betterfps.options.creativesearch.title=Fast Creative Search
betterfps.options.creativesearch.desc=Whether the search improvements will be enabled
7 changes: 5 additions & 2 deletions src/main/resources/assets/betterfps/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ betterfps.options.allocmemory.desc=Whether it will preallocate 10MB on startup
betterfps.options.fog.title=Fog
betterfps.options.fog.desc=Whether fog will be rendered

betterfps.options.beaconbeam.title=Beacon Beam
betterfps.options.beaconbeam.desc=Whether the transparent layer of the beacon beam will be rendered

betterfps.options.hopper.title=Fast Hopper
betterfps.options.hopper.desc=Whether hopper improvements will be enabled

betterfps.options.beacon.title=Fast Beacon
betterfps.options.beacon.desc=Whether beacon improvements will be enabled

betterfps.options.beaconbeam.title=Beacon Beam
betterfps.options.beaconbeam.desc=Whether the transparent layer of the beacon beam will be rendered
betterfps.options.creativesearch.title=Fast Creative Search
betterfps.options.creativesearch.desc=Whether the search improvements will be enabled
7 changes: 5 additions & 2 deletions src/main/resources/assets/betterfps/lang/pt_br.lang
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ betterfps.options.allocmemory.desc=Se 10MB de memória vai ser alocada na inicia
betterfps.options.fog.title=Névoa
betterfps.options.fog.desc=Se a névoa vai ser renderizada

betterfps.options.beaconbeam.title=Raio do Sinalizador
betterfps.options.beaconbeam.desc=Se o a camada transparente do raio vai ser renderizada

betterfps.options.hopper.title=Funil Rápido
betterfps.options.hopper.desc=Se as melhorias do funil vão ser ativadas

betterfps.options.beacon.title=Sinalizador Rápido
betterfps.options.beacon.desc=Se as melhorias do sinalizador vão ser ativadas

betterfps.options.beaconbeam.title=Raio do Sinalizador
betterfps.options.beaconbeam.desc=Se o a camada transparente do raio vai ser renderizada
betterfps.options.creativesearch.title=Busca do Criativo Rápida
betterfps.options.creativesearch.desc=Se as melhorias na busca do criativo vão ser ativadas

0 comments on commit 946121a

Please sign in to comment.