-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
447 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.lucaslah.weatherchanger; | ||
|
||
public class Config { | ||
private String mode; | ||
|
||
public Config() {} | ||
|
||
public Config(String mode) { | ||
this.mode = mode; | ||
} | ||
|
||
public String getMode() { | ||
return mode; | ||
} | ||
|
||
public void setMode(String mode) { | ||
this.mode = mode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package me.lucaslah.weatherchanger.keybind; | ||
|
||
import me.lucaslah.weatherchanger.WeatherChanger; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.option.KeyBinding; | ||
import net.minecraft.client.util.InputUtil.Type; | ||
import net.minecraft.util.Identifier; | ||
|
||
public abstract class Key { | ||
public KeyBinding keybind; | ||
public WeatherChanger mod = WeatherChanger.getInstance(); | ||
public MinecraftClient mc = MinecraftClient.getInstance(); | ||
|
||
public Key(@NotNull String name) { | ||
keybind = KeyBindingHelper.registerKeyBinding(new KeyBinding(this.getDisplayName(), this.getKeyType(), this.getKey(), this.getCategory())); | ||
} | ||
|
||
public abstract void onPress(@NotNull MinecraftClient client); | ||
public abstract Identifier getId(); | ||
|
||
public abstract KeyBinding getKeyBinding(); | ||
|
||
public abstract boolean isEnabled(); | ||
public abstract String getDisplayName(); | ||
public abstract Type getKeyType(); | ||
public abstract String getCategory(); | ||
public abstract int getKey(); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/me/lucaslah/weatherchanger/keybind/KeybindManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package me.lucaslah.weatherchanger.keybind; | ||
|
||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class KeybindManager { | ||
private final HashMap<Identifier, Key> entries = new HashMap<>(); | ||
|
||
private static KeybindManager INSTANCE; | ||
|
||
public KeybindManager() { | ||
INSTANCE = this; | ||
|
||
ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
for (Key key : getEntries()) { | ||
if (key.isEnabled() && key.getKeyBinding().wasPressed()) { | ||
key.onPress(client); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public KeybindManager add(Key entry) { | ||
entries.put(entry.getId(), entry); | ||
return this; | ||
} | ||
|
||
public Key get(Identifier identifier) { | ||
return entries.get(identifier); | ||
} | ||
|
||
public List<Key> getEntries() { | ||
if (entries.size() > 0) { | ||
return new ArrayList<>(entries.values()); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
public static KeybindManager getInstance() { | ||
return INSTANCE; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/me/lucaslah/weatherchanger/keybindings/ToggleClearKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package me.lucaslah.weatherchanger.keybindings; | ||
|
||
import me.lucaslah.weatherchanger.keybind.Key; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.option.KeyBinding; | ||
import net.minecraft.client.util.InputUtil; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ToggleClearKey extends Key { | ||
public ToggleClearKey() { | ||
super("ToggleClearKey"); | ||
} | ||
|
||
@Override | ||
public void onPress(@NotNull MinecraftClient client) { | ||
mod.setClear(); | ||
assert mc.player != null; | ||
mc.player.sendMessage(Text.of("Set client weather to: Clear"), true); | ||
} | ||
|
||
@Override | ||
public Identifier getId() { | ||
return new Identifier("weatherchangerkeys", "toggleclearkey"); | ||
} | ||
|
||
@Override | ||
public KeyBinding getKeyBinding() { | ||
return this.keybind; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Toggle Weather Clear"; | ||
} | ||
|
||
@Override | ||
public InputUtil.Type getKeyType() { | ||
return InputUtil.Type.KEYSYM; | ||
} | ||
|
||
@Override | ||
public String getCategory() { | ||
return "Weather Changer"; | ||
} | ||
|
||
@Override | ||
public int getKey() { | ||
return -1; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/me/lucaslah/weatherchanger/keybindings/ToggleOffKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package me.lucaslah.weatherchanger.keybindings; | ||
|
||
import me.lucaslah.weatherchanger.keybind.Key; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.option.KeyBinding; | ||
import net.minecraft.client.util.InputUtil; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ToggleOffKey extends Key { | ||
public ToggleOffKey() { | ||
super("ToggleOffKey"); | ||
} | ||
|
||
@Override | ||
public void onPress(@NotNull MinecraftClient client) { | ||
mod.setOff(); | ||
assert mc.player != null; | ||
mc.player.sendMessage(Text.of("Set client weather to: Off"), true); | ||
} | ||
|
||
@Override | ||
public Identifier getId() { | ||
return new Identifier("weatherchangerkeys", "toggleoffkey"); | ||
} | ||
|
||
@Override | ||
public KeyBinding getKeyBinding() { | ||
return this.keybind; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Toggle Weather Off"; | ||
} | ||
|
||
@Override | ||
public InputUtil.Type getKeyType() { | ||
return InputUtil.Type.KEYSYM; | ||
} | ||
|
||
@Override | ||
public String getCategory() { | ||
return "Weather Changer"; | ||
} | ||
|
||
@Override | ||
public int getKey() { | ||
return -1; | ||
} | ||
} |
Oops, something went wrong.