Commits

Ricky Brent committed ad3f541

Finally fixing all the problems with multiplayer overwriting config... probably.

  • Participants
  • Parent commits 83006b0
  • Branches 1.5.1

Comments (0)

Files changed (2)

File mod/ymt/air/ClientKeyBinder.java

+/**
+ * Copyright 2013 Yamato
+ *
+ * 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.
+ *
+ * Small class to handle the keybinding so it won't throw multiplayer 
+ * servers for a loop. There is perhaps a better way to handle this...
+ */
+package mod.ymt.air;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.lwjgl.input.Keyboard;
+import mod.ymt.air.AirCraftCore;
+import net.minecraft.src.KeyBinding;
+
+/**
+ * @author Yamato
+ *
+ */
+public class ClientKeyBinder  {
+    public KeyBinding[] keys;   
+    public boolean isClient = false;
+    
+    public void init() {
+        try {
+            Class.forName("net.minecraft.client.Minecraft");
+            isClient = true;
+        } catch(ClassNotFoundException e) {
+            isClient = false;
+        }     
+        
+        if (isClient) {
+            KeyBinding[] keys = { // MoveManager の並びと合わせる
+                new KeyBinding("key.HAC_Stop", Keyboard.KEY_NUMPAD5),
+                new KeyBinding("key.HAC_Forward", Keyboard.KEY_NUMPAD1),
+                new KeyBinding("key.HAC_Backward", Keyboard.KEY_NUMPAD3),
+                new KeyBinding("key.HAC_TurnRight", Keyboard.KEY_NUMPAD9),
+                new KeyBinding("key.HAC_TurnLeft", Keyboard.KEY_NUMPAD7),
+                new KeyBinding("key.HAC_Up", Keyboard.KEY_NUMPAD8),
+                new KeyBinding("key.HAC_Down", Keyboard.KEY_NUMPAD2),
+                new KeyBinding("key.HAC_Right", Keyboard.KEY_NUMPAD6),
+                new KeyBinding("key.HAC_Left", Keyboard.KEY_NUMPAD4),
+                new KeyBinding("key.HAC_Terminate", Keyboard.KEY_DIVIDE),
+            };
+            this.keys = keys;
+        }
+    }
+}

File mod_HariboteAirCraft.java

 import java.util.List;
 import java.util.Map;
 import mod.ymt.air.AirCraftCore;
+import mod.ymt.air.ClientKeyBinder;
 import mod.ymt.cmn.Utils;
-import org.lwjgl.input.Keyboard;
+
 
 /**
  * @author Yamato
  *
  */
 public class mod_HariboteAirCraft extends BaseMod {
-    public KeyBinding[] keys;
+    public ClientKeyBinder keybinder;
 
     @MLProp(min = 0)
     public static int IdPyxis = 209;
 
     @Override
     public void keyboardEvent(KeyBinding key) {
-      if (keys != null) {
-        for (int i = 0; i < keys.length; i++) {
-            if (key == keys[i]) {
-                AirCraftCore.getInstance().net.sendKeyToServer((byte) i);
-                break;
+        if (keybinder.isClient) {
+            for (int i = 0; i < keybinder.keys.length; i++) {
+                if (key == keybinder.keys[i]) {
+                    AirCraftCore.getInstance().net.sendKeyToServer((byte) i);
+                    break;
+                }
             }
         }
-      }
     }
-
+    
+    // For multiplayer:
+    public void mod_HariboteAirCraft() {
+        load();
+    }
+    
     @Override
     public void load() {
         try {
-            KeyBinding[] keys = { // MoveManager の並びと合わせる
-                new KeyBinding("key.HAC_Stop", Keyboard.KEY_NUMPAD5),
-                new KeyBinding("key.HAC_Forward", Keyboard.KEY_NUMPAD1),
-                new KeyBinding("key.HAC_Backward", Keyboard.KEY_NUMPAD3),
-                new KeyBinding("key.HAC_TurnRight", Keyboard.KEY_NUMPAD9),
-                new KeyBinding("key.HAC_TurnLeft", Keyboard.KEY_NUMPAD7),
-                new KeyBinding("key.HAC_Up", Keyboard.KEY_NUMPAD8),
-                new KeyBinding("key.HAC_Down", Keyboard.KEY_NUMPAD2),
-                new KeyBinding("key.HAC_Right", Keyboard.KEY_NUMPAD6),
-                new KeyBinding("key.HAC_Left", Keyboard.KEY_NUMPAD4),
-                new KeyBinding("key.HAC_Terminate", Keyboard.KEY_DIVIDE),
-            };
-            this.keys = keys;
-        }
-        catch (NoClassDefFoundError ex) {
-            //ex.printStackTrace();
-        }
-
-        try {
             AirCraftCore core = AirCraftCore.getInstance();
             core.setBaseMod(this);
             core.setBlockIdPyxis(IdPyxis);
             core.setFlyBlockPercent(blockFlyPercent);
 
             core.run();
+            
+            keybinder = new ClientKeyBinder(); 
+            keybinder.init();
+            if (keybinder.isClient) {
+                for (KeyBinding kb: keybinder.keys) {
+                    ModLoader.registerKey(this, kb, false);
+                }
+                ModLoader.addLocalization("key.HAC_Forward", "ja_JP", "はりぼて前進");
+                ModLoader.addLocalization("key.HAC_Backward", "ja_JP", "はりぼて後退");
+                ModLoader.addLocalization("key.HAC_TurnRight", "ja_JP", "はりぼて右旋回");
+                ModLoader.addLocalization("key.HAC_TurnLeft", "ja_JP", "はりぼて左旋回");
+                ModLoader.addLocalization("key.HAC_Up", "ja_JP", "はりぼて上昇");
+                ModLoader.addLocalization("key.HAC_Down", "ja_JP", "はりぼて下降");
+                ModLoader.addLocalization("key.HAC_Right", "ja_JP", "はりぼて右スライド");
+                ModLoader.addLocalization("key.HAC_Left", "ja_JP", "はりぼて左スライド");
+                ModLoader.addLocalization("key.HAC_Stop", "ja_JP", "はりぼて停止");
+                ModLoader.addLocalization("key.HAC_Terminate", "ja_JP", "はりぼて終了");
+            }
         }
         catch (NoClassDefFoundError ex) {
             ex.printStackTrace();
         }
     
-        if (keys != null) {
-            for (KeyBinding kb: keys) {
-                ModLoader.registerKey(this, kb, false);
-            }
-            ModLoader.addLocalization("key.HAC_Forward", "ja_JP", "はりぼて前進");
-            ModLoader.addLocalization("key.HAC_Backward", "ja_JP", "はりぼて後退");
-            ModLoader.addLocalization("key.HAC_TurnRight", "ja_JP", "はりぼて右旋回");
-            ModLoader.addLocalization("key.HAC_TurnLeft", "ja_JP", "はりぼて左旋回");
-            ModLoader.addLocalization("key.HAC_Up", "ja_JP", "はりぼて上昇");
-            ModLoader.addLocalization("key.HAC_Down", "ja_JP", "はりぼて下降");
-            ModLoader.addLocalization("key.HAC_Right", "ja_JP", "はりぼて右スライド");
-            ModLoader.addLocalization("key.HAC_Left", "ja_JP", "はりぼて左スライド");
-            ModLoader.addLocalization("key.HAC_Stop", "ja_JP", "はりぼて停止");
-            ModLoader.addLocalization("key.HAC_Terminate", "ja_JP", "はりぼて終了");
-        }
+
     }
 
     @Override