Ver Fonte

Fix better springing crash

Jared há 6 anos atrás
pai
commit
adefb75be0

+ 2 - 0
build.gradle

@@ -23,6 +23,8 @@ sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = co
 
 minecraft {
     mappings channel: 'snapshot', version: '20190608-1.14.2'
+    accessTransformer = file('build/resources/main/META-INF/accesstransformer.cfg')
+
     runs {
         client {
             workingDirectory project.file('run')

+ 13 - 16
src/main/java/com/blamejared/controlling/client/gui/GuiNewControls.java

@@ -16,7 +16,6 @@ import java.util.function.Predicate;
 @OnlyIn(Dist.CLIENT)
 public class GuiNewControls extends ControlsScreen {
     
-    private GuiNewKeyBindingList keyBindingList;
     private Button buttonReset;
     private final Screen parentScreen;
     private final GameSettings options;
@@ -33,8 +32,6 @@ public class GuiNewControls extends ControlsScreen {
     private GuiCheckBox buttonKey;
     private GuiCheckBox buttonCat;
     
-    private Button buttonSort;
-    
     public GuiNewControls(Screen screen, GameSettings settings) {
         super(screen, settings);
         this.parentScreen = screen;
@@ -52,9 +49,9 @@ public class GuiNewControls extends ControlsScreen {
         }));
         this.addButton(AbstractOption.field_216719_z.func_216586_a(this.minecraft.gameSettings, this.width / 2 - 155 + 160, 18, 150));
         
-        this.keyBindingList = new GuiNewKeyBindingList(this, this.minecraft);
-        this.children.add(this.keyBindingList);
-        this.setFocused(this.keyBindingList);
+        this.field_146494_r = new GuiNewKeyBindingList(this, this.minecraft);
+        this.children.add(this.field_146494_r);
+        this.setFocused(this.field_146494_r);
         this.addButton(new Button(this.width / 2 - 155 + 160, this.height - 29, 150, 20, I18n.format("gui.done"), (p_213126_1_) -> GuiNewControls.this.minecraft.displayGuiScreen(GuiNewControls.this.parentScreen)));
         
         this.buttonReset = this.addButton(new Button(this.width / 2 - 155, this.height - 29, 150, 20, I18n.format("controls.resetAll"), (p_213126_1_) -> {
@@ -107,7 +104,7 @@ public class GuiNewControls extends ControlsScreen {
             }
         });
         sortOrder = SortOrder.NONE;
-        this.buttonSort = this.addButton(new Button(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24 - 24, 150 / 2, 20, I18n.format("options.sort") + ": " + sortOrder.getName(), (p_213126_1_) -> {
+        Button buttonSort = this.addButton(new Button(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24 - 24, 150 / 2, 20, I18n.format("options.sort") + ": " + sortOrder.getName(), (p_213126_1_) -> {
             sortOrder = sortOrder.cycle();
             p_213126_1_.setMessage(I18n.format("options.sort") + ": " + sortOrder.getName());
             filterKeys();
@@ -132,9 +129,9 @@ public class GuiNewControls extends ControlsScreen {
     
     public void filterKeys() {
         lastSearch = search.getText();
-        keyBindingList.children().clear();
+        field_146494_r.children().clear();
         if(lastSearch.isEmpty() && displayMode == DisplayMode.ALL && sortOrder == SortOrder.NONE) {
-            keyBindingList.children().addAll(keyBindingList.getAllEntries());
+            field_146494_r.children().addAll(((GuiNewKeyBindingList) field_146494_r).getAllEntries());
             return;
         }
         Predicate<GuiNewKeyBindingList.KeyEntry> filters = displayMode.getPredicate();
@@ -152,15 +149,15 @@ public class GuiNewControls extends ControlsScreen {
                 break;
         }
         
-        for(GuiNewKeyBindingList.Entry entry : keyBindingList.getAllEntries()) {
+        for(GuiNewKeyBindingList.Entry entry : ((GuiNewKeyBindingList) field_146494_r).getAllEntries()) {
             if(entry instanceof GuiNewKeyBindingList.KeyEntry) {
                 GuiNewKeyBindingList.KeyEntry keyEntry = (GuiNewKeyBindingList.KeyEntry) entry;
                 if(filters.test(keyEntry)) {
-                    keyBindingList.children().add(entry);
+                    field_146494_r.children().add(entry);
                 }
             }
         }
-        sortOrder.sort(keyBindingList.children());
+        sortOrder.sort(field_146494_r.children());
         
         
     }
@@ -170,7 +167,7 @@ public class GuiNewControls extends ControlsScreen {
      */
     public void render(int mouseX, int mouseY, float partialTicks) {
         this.renderBackground();
-        this.keyBindingList.render(mouseX, mouseY, partialTicks);
+        this.field_146494_r.render(mouseX, mouseY, partialTicks);
         this.drawCenteredString(this.font, this.title.getFormattedText(), this.width / 2, 8, 16777215);
         boolean flag = false;
         
@@ -198,9 +195,9 @@ public class GuiNewControls extends ControlsScreen {
             KeyBinding.resetKeyBindingArrayAndHash();
             valid = true;
             search.setFocused(false);
-        } else if(mb == 0 && this.keyBindingList.mouseClicked(mx, my, mb)) {
+        } else if(mb == 0 && this.field_146494_r.mouseClicked(mx, my, mb)) {
             this.setDragging(true);
-            this.setFocused(this.keyBindingList);
+            this.setFocused(this.field_146494_r);
             valid = true;
             search.setFocused(false);
         } else {
@@ -232,7 +229,7 @@ public class GuiNewControls extends ControlsScreen {
     }
     
     public boolean mouseReleased(double mx, double my, int mb) {
-        if(mb == 0 && this.keyBindingList.mouseReleased(mx, my, mb)) {
+        if(mb == 0 && this.field_146494_r.mouseReleased(mx, my, mb)) {
             this.setDragging(false);
             return true;
         } else if(search.isFocused()) {

+ 10 - 8
src/main/java/com/blamejared/controlling/client/gui/GuiNewKeyBindingList.java

@@ -15,7 +15,7 @@ import org.apache.commons.lang3.ArrayUtils;
 import java.util.*;
 
 @OnlyIn(Dist.CLIENT)
-public class GuiNewKeyBindingList extends AbstractOptionList<GuiNewKeyBindingList.Entry> {
+public class GuiNewKeyBindingList extends KeyBindingList {
     
     private final ControlsScreen controlsScreen;
     private final Minecraft mc;
@@ -23,7 +23,12 @@ public class GuiNewKeyBindingList extends AbstractOptionList<GuiNewKeyBindingLis
     public List<Entry> allEntries;
     
     public GuiNewKeyBindingList(ControlsScreen controls, Minecraft mcIn) {
-        super(mcIn, controls.width + 45, controls.height, 43, controls.height - 80, 20);
+        super(controls, mcIn);
+        this.width = controls.width + 45;
+        this.height = controls.height;
+        this.y0 = 43;
+        this.y1 = controls.height - 80;
+        this.x1 = controls.width + 45;
         this.controlsScreen = controls;
         this.mc = mcIn;
         allEntries = new ArrayList<>();
@@ -57,7 +62,7 @@ public class GuiNewKeyBindingList extends AbstractOptionList<GuiNewKeyBindingLis
     }
     
     public void add(Entry ent) {
-        this.addEntry(ent);
+        children().add(ent);
         allEntries.add(ent);
     }
     
@@ -70,7 +75,7 @@ public class GuiNewKeyBindingList extends AbstractOptionList<GuiNewKeyBindingLis
     }
     
     @OnlyIn(Dist.CLIENT)
-    public class CategoryEntry extends GuiNewKeyBindingList.Entry {
+    public class CategoryEntry extends KeyBindingList.Entry {
         
         private final String labelText;
         private final int labelWidth;
@@ -92,10 +97,7 @@ public class GuiNewKeyBindingList extends AbstractOptionList<GuiNewKeyBindingLis
     }
     
     @OnlyIn(Dist.CLIENT)
-    public abstract static class Entry extends AbstractOptionList.Entry<GuiNewKeyBindingList.Entry> {}
-    
-    @OnlyIn(Dist.CLIENT)
-    public class KeyEntry extends GuiNewKeyBindingList.Entry {
+    public class KeyEntry extends KeyBindingList.Entry {
         
         /**
          * The keybinding specified for this KeyEntry

+ 1 - 12
src/main/java/com/blamejared/controlling/events/ClientEventHandler.java

@@ -16,21 +16,10 @@ public class ClientEventHandler {
     
     @SubscribeEvent
     public void openGui(GuiOpenEvent event) {
-        World w;
         try {
             if(event.getGui() instanceof ControlsScreen && !(event.getGui() instanceof GuiNewControls)) {
                 ControlsScreen gui = (ControlsScreen) event.getGui();
-                Field parent = null;
-                for(Field field : gui.getClass().getDeclaredFields()) {
-                    if(field.getType() == Screen.class) {
-                        parent = field;
-                    }
-                }
-                if(parent == null) {
-                    return;
-                }
-                parent.setAccessible(true);
-                event.setGui(new GuiNewControls((Screen) parent.get(gui), Minecraft.getInstance().gameSettings));
+                event.setGui(new GuiNewControls(gui.field_146496_h, Minecraft.getInstance().gameSettings));
             }
         } catch(Exception e) {
             e.printStackTrace();

+ 2 - 0
src/main/resources/META-INF/accesstransformer.cfg

@@ -0,0 +1,2 @@
+public net.minecraft.client.gui.screen.ControlsScreen field_146494_r # keyBindingList
+public net.minecraft.client.gui.screen.ControlsScreen field_146496_h # parentScreen