├── lib ├── luaj-jse-3.0.2.jar └── luaj-sources-3.0.2.jar ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src └── main │ ├── resources │ ├── assets │ │ └── scriptit │ │ │ ├── icon.png │ │ │ ├── themes │ │ │ └── light.json │ │ │ └── lang │ │ │ └── en_us.json │ ├── scriptit.mixins.json │ └── fabric.mod.json │ └── java │ └── com │ └── ddoerr │ └── scriptit │ ├── api │ ├── hud │ │ ├── HudAnchor.java │ │ ├── HudElementManager.java │ │ ├── HudElement.java │ │ ├── HudElementFactory.java │ │ ├── HudElementContainer.java │ │ ├── HudVerticalAnchor.java │ │ └── HudHorizontalAnchor.java │ ├── dependencies │ │ ├── Loadable.java │ │ └── Resolver.java │ ├── Identifiable.java │ ├── registry │ │ ├── ExtensionInitializer.java │ │ └── ScriptItRegistry.java │ ├── triggers │ │ ├── TriggerMessage.java │ │ ├── KeyBindingManager.java │ │ ├── Trigger.java │ │ └── TriggerFactory.java │ ├── exceptions │ │ ├── ConversionException.java │ │ └── DependencyException.java │ ├── scripts │ │ ├── ScriptContainerManager.java │ │ ├── RunningScript.java │ │ ├── StringScriptSource.java │ │ ├── Script.java │ │ ├── ScriptSource.java │ │ ├── ScriptManager.java │ │ ├── ScriptContainer.java │ │ ├── FileScriptSource.java │ │ └── ScriptBuilder.java │ ├── events │ │ ├── Event.java │ │ └── AbstractEvent.java │ ├── annotations │ │ ├── Callable.java │ │ ├── Getter.java │ │ └── Setter.java │ ├── util │ │ ├── geometry │ │ │ ├── Point.java │ │ │ └── Rectangle.java │ │ ├── Debouncer.java │ │ ├── DurationHelper.java │ │ ├── GenericEnumHelper.java │ │ └── KeyBindingHelper.java │ ├── languages │ │ ├── Language.java │ │ ├── ContainedValue.java │ │ └── ContainedResultFactory.java │ └── libraries │ │ └── Model.java │ ├── ducks │ └── TooltipRenderedDuck.java │ ├── models │ ├── settings │ │ ├── ToggleableSettingModel.java │ │ ├── SettingModel.java │ │ ├── AbstractNumberSettingModel.java │ │ ├── AbstractSettingModel.java │ │ ├── StringSettingModel.java │ │ ├── BooleanSettingModel.java │ │ ├── IntegerSettingModel.java │ │ ├── DoubleSettingModel.java │ │ └── EnumSettingModel.java │ ├── EntityModel.java │ ├── ScoreModel.java │ ├── PositionModel.java │ ├── ScriptBuilderModel.java │ ├── BlockModel.java │ ├── TeamModel.java │ ├── EnchantmentModel.java │ ├── ObjectiveModel.java │ ├── PlayerEntryModel.java │ ├── TargetModel.java │ ├── inventory │ │ ├── CreativeInventoryModel.java │ │ └── DefaultInventoryModel.java │ └── ItemModel.java │ ├── mixin │ ├── OptionKeyAccessor.java │ ├── StepAccessor.java │ ├── ActiveMouseButtonAccessor.java │ ├── FpsAccessor.java │ ├── SendPacketTextAccessor.java │ ├── PacketTextAccessor.java │ ├── MessagesAccessor.java │ ├── KeyBindingAccessor.java │ ├── CreativeInventoryAccessor.java │ ├── MixinMinecraftClient.java │ ├── ContainerAccessor.java │ ├── MixinSleepingChatScreen.java │ ├── MixinGameRenderer.java │ ├── MixinClientPlayerNetworkHandler.java │ └── MixinScreen.java │ ├── extension │ ├── libraries │ │ ├── clickables │ │ │ ├── ClickablesProvider.java │ │ │ ├── buttons │ │ │ │ ├── ButtonProvider.java │ │ │ │ ├── ButtonHelper.java │ │ │ │ ├── EnchantingButtonProvider.java │ │ │ │ └── DefaultButtonProvider.java │ │ │ ├── ClickablesHelper.java │ │ │ └── AbstractSpinneryClickablesProvider.java │ │ ├── SharedLibrary.java │ │ ├── JsonLibrary.java │ │ ├── ScriptsLibrary.java │ │ ├── GameLibrary.java │ │ ├── ScoreboardLibrary.java │ │ ├── GuiLibrary.java │ │ ├── ChatLibrary.java │ │ └── ServerLibrary.java │ ├── events │ │ ├── GameConnectEvent.java │ │ ├── SoundEvent.java │ │ ├── ChatOutgoingEvent.java │ │ └── ChatIncomingEvent.java │ ├── triggers │ │ ├── EventTriggerFactory.java │ │ ├── DurationTriggerFactory.java │ │ ├── KeyBindingTriggerFactory.java │ │ ├── KeyBindingTrigger.java │ │ ├── EventTrigger.java │ │ └── DurationTrigger.java │ ├── elements │ │ ├── ItemHudElementFactory.java │ │ ├── TextHudElementFactory.java │ │ └── ItemHudElement.java │ ├── text │ │ ├── TextContainedResultFactory.java │ │ └── TextContainedValue.java │ └── ScriptItExtension.java │ ├── config │ ├── ConfigContainer.java │ ├── ConfigHandler.java │ ├── ScriptContainerAdapter.java │ ├── TriggerAdapter.java │ ├── Config.java │ └── HudElementAdapter.java │ ├── elements │ ├── AbstractHudElement.java │ ├── HudElementManagerImpl.java │ └── HudElementContainerImpl.java │ ├── fields │ ├── Field.java │ ├── StringField.java │ ├── FieldAssembler.java │ ├── IntegerField.java │ ├── AbstractTextField.java │ ├── KeyBindingField.java │ ├── AbstractField.java │ ├── SelectionField.java │ └── ColorField.java │ ├── callbacks │ ├── GameJoinCallback.java │ ├── ConfigCallback.java │ ├── LateInitCallback.java │ ├── OutgoingChatMessageCallback.java │ └── IncomingChatMessageCallback.java │ ├── triggers │ ├── TriggerMessageImpl.java │ ├── AbstractTrigger.java │ └── KeyBindingManagerImpl.java │ ├── scripts │ ├── RunningScriptImpl.java │ ├── ScriptContainerManagerImpl.java │ ├── ScriptContainerImpl.java │ └── ScriptManagerImpl.java │ ├── languages │ └── LanguageManagerImpl.java │ ├── screens │ ├── AbstractHistoryScreen.java │ ├── ScreenHistory.java │ └── widgets │ │ ├── PanelWidget.java │ │ └── KeyBindingButtonWidget.java │ ├── extensions │ └── ExtensionLoader.java │ ├── ScriptItMod.java │ └── commands │ └── ScriptItCommand.java ├── settings.gradle ├── .gitignore ├── gradle.properties ├── .github └── workflows │ ├── gradle.yml │ └── gradlepublish.yml ├── readme.md ├── LICENSE └── gradlew.bat /lib/luaj-jse-3.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gorlem/ScriptIt/HEAD/lib/luaj-jse-3.0.2.jar -------------------------------------------------------------------------------- /lib/luaj-sources-3.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gorlem/ScriptIt/HEAD/lib/luaj-sources-3.0.2.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gorlem/ScriptIt/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/assets/scriptit/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gorlem/ScriptIt/HEAD/src/main/resources/assets/scriptit/icon.png -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/hud/HudAnchor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.hud; 2 | 3 | public interface HudAnchor { 4 | int getBaseValue(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/dependencies/Loadable.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.dependencies; 2 | 3 | public interface Loadable { 4 | void load(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/ducks/TooltipRenderedDuck.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.ducks; 2 | 3 | public interface TooltipRenderedDuck { 4 | boolean wasTooltipRendered(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/Identifiable.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api; 2 | 3 | import net.minecraft.util.Identifier; 4 | 5 | public interface Identifiable { 6 | Identifier getIdentifier(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/ToggleableSettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | public interface ToggleableSettingModel extends SettingModel { 4 | T toggle(); 5 | } 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | jcenter() 4 | maven { 5 | name = 'Fabric' 6 | url = 'https://maven.fabricmc.net/' 7 | } 8 | gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | 3 | .gradle/ 4 | build/ 5 | out/ 6 | classes/ 7 | 8 | # idea 9 | 10 | .idea/ 11 | *.iml 12 | *.ipr 13 | *.iws 14 | 15 | # vscode 16 | 17 | .settings/ 18 | .vscode/ 19 | bin/ 20 | .classpath 21 | .project 22 | 23 | # fabric 24 | 25 | run/ 26 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jul 22 21:19:04 CEST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip 7 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/registry/ExtensionInitializer.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.registry; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | 5 | public interface ExtensionInitializer { 6 | void onInitialize(ScriptItRegistry registry, Resolver resolver); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/triggers/TriggerMessage.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.triggers; 2 | 3 | import com.ddoerr.scriptit.api.libraries.Model; 4 | 5 | import java.time.Duration; 6 | 7 | public interface TriggerMessage { 8 | Model getTriggerModel(); 9 | Duration getTimeout(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/exceptions/ConversionException.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.exceptions; 2 | 3 | public class ConversionException extends Exception { 4 | public ConversionException() { 5 | } 6 | 7 | public ConversionException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/exceptions/DependencyException.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.exceptions; 2 | 3 | public class DependencyException extends Exception { 4 | public DependencyException() { 5 | } 6 | 7 | public DependencyException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/ScriptContainerManager.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | import java.util.List; 4 | 5 | public interface ScriptContainerManager { 6 | void add(ScriptContainer scriptContainer); 7 | List getAll(); 8 | void remove(ScriptContainer scriptContainer); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/OptionKeyAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.options.Option; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin({Option.class}) 8 | public interface OptionKeyAccessor { 9 | @Accessor 10 | String getKey(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/hud/HudElementManager.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.hud; 2 | 3 | import java.util.List; 4 | 5 | public interface HudElementManager { 6 | void add(HudElementContainer hudElement); 7 | 8 | List getAll(); 9 | 10 | void remove(HudElementContainer hudElement); 11 | 12 | void renderAll(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/RunningScript.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | import com.ddoerr.scriptit.api.languages.ContainedValue; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | 7 | public interface RunningScript { 8 | ScriptContainer getScriptContainer(); 9 | CompletableFuture getFuture(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/StepAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.options.DoubleOption; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin({DoubleOption.class}) 8 | public interface StepAccessor { 9 | @Accessor 10 | float getStep(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/ActiveMouseButtonAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.Mouse; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin({Mouse.class}) 8 | public interface ActiveMouseButtonAccessor { 9 | @Accessor 10 | int getActiveButton(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/events/Event.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.events; 2 | 3 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 4 | 5 | import java.util.function.Consumer; 6 | 7 | public interface Event { 8 | void registerListener(Consumer messageConsumer); 9 | void removeListener(Consumer messageConsumer); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/FpsAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin({MinecraftClient.class}) 8 | public interface FpsAccessor { 9 | @Accessor 10 | static int getCurrentFps() { return 0; } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/annotations/Callable.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.METHOD) 10 | public @interface Callable {} 11 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/clickables/ClickablesProvider.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries.clickables; 2 | 3 | import net.minecraft.client.gui.screen.Screen; 4 | 5 | public interface ClickablesProvider { 6 | int getAmount(Screen screen); 7 | boolean matches(Screen screen); 8 | void renderTooltip(Screen screen, int mouseX, int mouseY); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/StringScriptSource.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | public class StringScriptSource implements ScriptSource { 4 | String content; 5 | 6 | public StringScriptSource(String content) { 7 | this.content = content; 8 | } 9 | 10 | @Override 11 | public String getContent() { 12 | return content; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/clickables/buttons/ButtonProvider.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries.clickables.buttons; 2 | 3 | import com.ddoerr.scriptit.extension.libraries.clickables.ClickablesProvider; 4 | import net.minecraft.client.gui.screen.Screen; 5 | 6 | public interface ButtonProvider extends ClickablesProvider { 7 | void click(Screen screen, int index); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/annotations/Getter.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.METHOD, ElementType.FIELD}) 10 | public @interface Getter {} 11 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/annotations/Setter.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.METHOD, ElementType.FIELD}) 10 | public @interface Setter {} 11 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/Script.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | import com.ddoerr.scriptit.api.libraries.Model; 4 | import net.minecraft.util.Identifier; 5 | 6 | import java.util.Map; 7 | 8 | public interface Script { 9 | ScriptSource getScriptSource(); 10 | Map getLibraries(); 11 | String getName(); 12 | Identifier getLanguage(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/util/geometry/Point.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.util.geometry; 2 | 3 | public class Point { 4 | double x; 5 | double y; 6 | 7 | public Point(double x, double y) { 8 | this.x = x; 9 | this.y = y; 10 | } 11 | 12 | public double getX() { 13 | return x; 14 | } 15 | 16 | public double getY() { 17 | return y; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/SettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.Model; 5 | 6 | public interface SettingModel extends Model { 7 | String getName(); 8 | 9 | T getValue(); 10 | void setValue(T value); 11 | 12 | @Getter 13 | String getPossibleValues(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/ScriptSource.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | import java.io.File; 4 | 5 | public interface ScriptSource { 6 | static ScriptSource From(String content) { 7 | return new StringScriptSource(content); 8 | } 9 | 10 | static ScriptSource From(File file) { 11 | return new FileScriptSource(file); 12 | } 13 | 14 | String getContent(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/SendPacketTextAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin(ChatMessageC2SPacket.class) 8 | public interface SendPacketTextAccessor { 9 | @Accessor 10 | void setChatMessage(String chatMessage); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/PacketTextAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; 4 | import net.minecraft.text.Text; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.gen.Accessor; 7 | 8 | @Mixin(ChatMessageS2CPacket.class) 9 | public interface PacketTextAccessor { 10 | @Accessor 11 | void setMessage(Text message); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/MessagesAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.gui.hud.ChatHud; 4 | import net.minecraft.client.gui.hud.ChatHudLine; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.gen.Accessor; 7 | 8 | import java.util.List; 9 | 10 | @Mixin({ChatHud.class}) 11 | public interface MessagesAccessor { 12 | @Accessor 13 | List getMessages(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/KeyBindingAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.options.KeyBinding; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | import java.util.Map; 8 | 9 | @Mixin(KeyBinding.class) 10 | public interface KeyBindingAccessor { 11 | @Accessor 12 | static Map getKeysById() { 13 | return null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/config/ConfigContainer.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.config; 2 | 3 | import com.ddoerr.scriptit.api.hud.HudElementContainer; 4 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | 9 | public class ConfigContainer { 10 | public Collection elements = new ArrayList<>(); 11 | public Collection bindings = new ArrayList<>(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/languages/Language.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.languages; 2 | 3 | import com.ddoerr.scriptit.api.libraries.Model; 4 | import com.ddoerr.scriptit.api.scripts.Script; 5 | 6 | import java.util.Collection; 7 | import java.util.concurrent.CompletableFuture; 8 | 9 | public interface Language { 10 | Collection getExtensions(); 11 | void loadLibrary(String name, Model model); 12 | CompletableFuture runScript(Script script); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/triggers/KeyBindingManager.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.triggers; 2 | 3 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 4 | import net.minecraft.util.Tickable; 5 | 6 | import java.util.function.Consumer; 7 | 8 | public interface KeyBindingManager extends Tickable { 9 | void registerListener(String keyName, Consumer messageConsumer); 10 | 11 | void removeListener(String keyName, Consumer messageConsumer); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/triggers/Trigger.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.triggers; 2 | 3 | import com.ddoerr.scriptit.api.Identifiable; 4 | import com.ddoerr.scriptit.fields.Field; 5 | 6 | import java.util.Map; 7 | import java.util.function.Consumer; 8 | 9 | public interface Trigger extends Identifiable { 10 | void setCallback(Consumer callback); 11 | void check(); 12 | 13 | void start(); 14 | void stop(); 15 | 16 | Map> getFields(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/events/GameConnectEvent.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.events; 2 | 3 | import com.ddoerr.scriptit.api.events.AbstractEvent; 4 | import com.ddoerr.scriptit.callbacks.GameJoinCallback; 5 | 6 | public class GameConnectEvent extends AbstractEvent implements GameJoinCallback { 7 | public GameConnectEvent() { 8 | GameJoinCallback.EVENT.register(this); 9 | } 10 | 11 | @Override 12 | public void onGameJoin() { 13 | dispatch(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/elements/AbstractHudElement.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.elements; 2 | 3 | import com.ddoerr.scriptit.api.hud.HudElement; 4 | import com.ddoerr.scriptit.fields.Field; 5 | 6 | import java.util.LinkedHashMap; 7 | import java.util.Map; 8 | 9 | public abstract class AbstractHudElement implements HudElement { 10 | protected Map> fields = new LinkedHashMap<>(); 11 | 12 | @Override 13 | public Map> getFields() { 14 | return fields; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/Field.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import com.ddoerr.scriptit.screens.widgets.PanelWidget; 4 | import net.minecraft.text.Text; 5 | 6 | public interface Field { 7 | T getValue(); 8 | void setValue(T value); 9 | 10 | void deserialize(String value); 11 | String serialize(); 12 | 13 | void setTitle(Text title); 14 | void setDescription(Text description); 15 | 16 | void createWidget(PanelWidget panel); 17 | void applyTemporaryValue(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/StringField.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import spinnery.widget.WTextField; 4 | 5 | public class StringField extends AbstractTextField { 6 | @Override 7 | public void deserialize(String value) { 8 | this.value = value; 9 | } 10 | 11 | @Override 12 | public String serialize() { 13 | return value; 14 | } 15 | 16 | @Override 17 | protected String getTemporaryValue(WTextField widget) { 18 | return widget.getText(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to gradle. 2 | org.gradle.jvmargs=-Xmx1G 3 | 4 | # Fabric Properties 5 | # check these on https://fabricmc.net/use 6 | minecraft_version=1.15.2 7 | yarn_mappings=1.15.2+build.15 8 | loader_version=0.8.2+build.194 9 | 10 | # Mod Properties 11 | mod_version = 0.5.1 12 | maven_group = com.ddoerr 13 | archives_base_name = scriptit 14 | 15 | # Dependencies 16 | # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric 17 | fabric_version=0.5.1+build.294-1.15 18 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/callbacks/GameJoinCallback.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.callbacks; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | 6 | public interface GameJoinCallback { 7 | Event EVENT = EventFactory.createArrayBacked( 8 | GameJoinCallback.class, 9 | (listeners) -> () -> { 10 | for (GameJoinCallback event : listeners) { 11 | event.onGameJoin(); 12 | } 13 | } 14 | ); 15 | 16 | void onGameJoin(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/hud/HudElement.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.hud; 2 | 3 | import com.ddoerr.scriptit.api.Identifiable; 4 | import com.ddoerr.scriptit.api.scripts.Script; 5 | import com.ddoerr.scriptit.api.util.geometry.Point; 6 | import com.ddoerr.scriptit.api.util.geometry.Rectangle; 7 | import com.ddoerr.scriptit.fields.Field; 8 | 9 | import java.util.Map; 10 | 11 | public interface HudElement extends Identifiable { 12 | Rectangle render(Point origin, HudElementContainer hudElement); 13 | Script getDefaultScript(); 14 | 15 | Map> getFields(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/libraries/Model.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.libraries; 2 | 3 | import com.ddoerr.scriptit.api.languages.ContainedResultFactory; 4 | import com.ddoerr.scriptit.api.languages.ContainedValue; 5 | 6 | public interface Model { 7 | boolean hasGetter(String key); 8 | boolean hasSetter(String key); 9 | boolean hasFunction(String key); 10 | 11 | T runGetter(String key, ContainedResultFactory factory); 12 | void runSetter(String key, ContainedValue value); 13 | T runFunction(String key, ContainedValue[] values, ContainedResultFactory factory); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/callbacks/ConfigCallback.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.callbacks; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | 6 | public interface ConfigCallback { 7 | Event EVENT = EventFactory.createArrayBacked( 8 | ConfigCallback.class, 9 | (listeners) -> (Class source) -> { 10 | for (ConfigCallback event : listeners) { 11 | event.saveConfig(source); 12 | } 13 | } 14 | ); 15 | 16 | void saveConfig(Class source); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/ScriptManager.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | import com.ddoerr.scriptit.api.languages.ContainedValue; 4 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 5 | 6 | import java.util.List; 7 | import java.util.concurrent.CompletableFuture; 8 | 9 | public interface ScriptManager { 10 | CompletableFuture runScript(Script script); 11 | void runScriptContainer(ScriptContainer scriptContainer, TriggerMessage triggerMessage); 12 | List getRunningScripts(); 13 | int stopScripts(String name); 14 | int stopAllScripts(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/CreativeInventoryAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; 4 | import net.minecraft.container.Slot; 5 | import net.minecraft.item.ItemGroup; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | import org.spongepowered.asm.mixin.gen.Invoker; 9 | 10 | @Mixin({CreativeInventoryScreen.class}) 11 | public interface CreativeInventoryAccessor { 12 | @Accessor 13 | Slot getDeleteItemSlot(); 14 | 15 | @Invoker 16 | void invokeSetSelectedTab(ItemGroup group); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/clickables/buttons/ButtonHelper.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries.clickables.buttons; 2 | 3 | import com.ddoerr.scriptit.extension.libraries.clickables.ClickablesHelper; 4 | import net.minecraft.client.gui.screen.Screen; 5 | 6 | public class ButtonHelper extends ClickablesHelper { 7 | public ButtonHelper() { 8 | provider.add(new EnchantingButtonProvider()); 9 | provider.add(new DefaultButtonProvider()); 10 | } 11 | 12 | public void click(Screen screen, int index) { 13 | getProvider(screen).ifPresent(p -> p.click(screen, index)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/resources/assets/scriptit/themes/light.json: -------------------------------------------------------------------------------- 1 | { 2 | "Identifier": { 3 | "name": "light" 4 | }, 5 | "com.ddoerr.scriptit.widgets.KeyBindingButtonWidget": { 6 | "top_left_on": "0xff373737", 7 | "bottom_right_on": "0xffffffff", 8 | "background_on": "0xff686868", 9 | "top_left_off": "0xffffffff", 10 | "bottom_right_off": "0xff373737", 11 | "background_off": "0xff8b8b8b", 12 | "label": "0xffffff" 13 | }, 14 | "com.ddoerr.scriptit.widgets.ValuesDropdownWidget": { 15 | "shadow": "0xff555555", 16 | "background": "0xffc6c6c6", 17 | "highlight": "0xffffffff", 18 | "outline": "0xff000000", 19 | "label": "0xffffff" 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/callbacks/LateInitCallback.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.callbacks; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.client.MinecraftClient; 6 | 7 | public interface LateInitCallback { 8 | Event EVENT = EventFactory.createArrayBacked( 9 | LateInitCallback.class, 10 | listeners -> minecraft -> { 11 | for (LateInitCallback event : listeners) { 12 | event.onLateInitialize(minecraft); 13 | } 14 | } 15 | ); 16 | 17 | void onLateInitialize(MinecraftClient minecraft); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/hud/HudElementFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.hud; 2 | 3 | import com.ddoerr.scriptit.fields.Field; 4 | 5 | import java.util.Map; 6 | 7 | public interface HudElementFactory { 8 | HudElement createHudElement(); 9 | default HudElement createHudElement(Map data) { 10 | HudElement hudElement = createHudElement(); 11 | 12 | for (Map.Entry> entry : hudElement.getFields().entrySet()) { 13 | if (data.containsKey(entry.getKey())) { 14 | entry.getValue().deserialize(data.get(entry.getKey())); 15 | } 16 | } 17 | 18 | return hudElement; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/triggers/TriggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.triggers; 2 | 3 | import com.ddoerr.scriptit.fields.Field; 4 | import spinnery.widget.WTabHolder; 5 | 6 | import java.util.Map; 7 | 8 | public interface TriggerFactory { 9 | Trigger createTrigger(); 10 | 11 | default Trigger createTrigger(Map data) { 12 | Trigger trigger = createTrigger(); 13 | 14 | for (Map.Entry> entry : trigger.getFields().entrySet()) { 15 | if (data.containsKey(entry.getKey())) { 16 | entry.getValue().deserialize(data.get(entry.getKey())); 17 | } 18 | } 19 | 20 | return trigger; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/resources/scriptit.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "com.ddoerr.scriptit.mixin", 4 | "compatibilityLevel": "JAVA_8", 5 | "mixins": [ 6 | ], 7 | "client": [ 8 | "KeyBindingAccessor", 9 | "PacketTextAccessor", 10 | "SendPacketTextAccessor", 11 | "MixinClientPlayerNetworkHandler", 12 | "MixinScreen", 13 | "MixinSleepingChatScreen", 14 | "MessagesAccessor", 15 | "FpsAccessor", 16 | "ActiveMouseButtonAccessor", 17 | "ContainerAccessor", 18 | "CreativeInventoryAccessor", 19 | "MixinGameRenderer", 20 | "OptionKeyAccessor", 21 | "StepAccessor", 22 | "MixinMinecraftClient" 23 | ], 24 | "injectors": { 25 | "defaultRequire": 1 26 | } 27 | } -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Java CI with Gradle 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 1.8 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 1.8 23 | - name: Grant execute permission for gradlew 24 | run: chmod +x gradlew 25 | - name: Build with Gradle 26 | run: ./gradlew build 27 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/SharedLibrary.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.languages.ContainedValue; 5 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | public class SharedLibrary extends AnnotationBasedModel { 11 | private Map map = new HashMap<>(); 12 | 13 | @Callable 14 | public void set(String key, ContainedValue value) { 15 | map.put(key, value); 16 | } 17 | 18 | @Callable 19 | public ContainedValue get(String key) { 20 | return map.get(key); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/ScriptContainer.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | import com.ddoerr.scriptit.api.languages.ContainedValue; 4 | import com.ddoerr.scriptit.api.triggers.Trigger; 5 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 6 | 7 | import java.util.function.Consumer; 8 | 9 | public interface ScriptContainer { 10 | Trigger getTrigger(); 11 | void setTrigger(Trigger trigger); 12 | 13 | Script getScript(); 14 | void setScript(Script script); 15 | 16 | void setCallback(Consumer callback); 17 | 18 | ContainedValue getLastResult(); 19 | void setLastResult(ContainedValue value); 20 | 21 | boolean isDisabled(); 22 | void disable(); 23 | void enable(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/EntityModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.entity.Entity; 6 | 7 | public class EntityModel extends AnnotationBasedModel { 8 | public static EntityModel From(Entity entity) { 9 | EntityModel entityModel = new EntityModel(); 10 | entityModel.entity = entity; 11 | return entityModel; 12 | } 13 | 14 | private Entity entity; 15 | 16 | @Getter 17 | public String getName() { 18 | return entity.getName().asFormattedString(); 19 | } 20 | 21 | @Getter 22 | public String getUuid() { 23 | return entity.getUuidAsString(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/MixinMinecraftClient.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import com.ddoerr.scriptit.callbacks.LateInitCallback; 4 | import net.minecraft.client.MinecraftClient; 5 | import net.minecraft.client.RunArgs; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 10 | 11 | @Mixin({MinecraftClient.class}) 12 | public abstract class MixinMinecraftClient { 13 | @Inject(method = "*", at = @At("RETURN")) 14 | private void onConstructed(RunArgs runArgs, CallbackInfo info) { 15 | LateInitCallback.EVENT.invoker().onLateInitialize((MinecraftClient)(Object)this); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/ScoreModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.scoreboard.ScoreboardPlayerScore; 6 | 7 | public class ScoreModel extends AnnotationBasedModel { 8 | public static ScoreModel From(ScoreboardPlayerScore score) { 9 | ScoreModel scoreModel = new ScoreModel(); 10 | scoreModel.score = score; 11 | return scoreModel; 12 | } 13 | 14 | private ScoreboardPlayerScore score; 15 | 16 | @Getter 17 | public String getPlayer() { 18 | return score.getPlayerName(); 19 | } 20 | 21 | @Getter 22 | public int getScore() { 23 | return score.getScore(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/FileScriptSource.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.charset.Charset; 8 | 9 | public class FileScriptSource implements ScriptSource { 10 | File file; 11 | 12 | public FileScriptSource(File file) { 13 | this.file = file; 14 | } 15 | 16 | public String getFilePath() { 17 | return file.getPath(); 18 | } 19 | 20 | @Override 21 | public String getContent() { 22 | try { 23 | return FileUtils.readFileToString(file, Charset.defaultCharset()); 24 | } catch (IOException e) { 25 | e.printStackTrace(); 26 | return null; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/JsonLibrary.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import com.google.gson.Gson; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class JsonLibrary extends AnnotationBasedModel { 11 | private Gson gson = new Gson(); 12 | 13 | @Callable 14 | public String encode(Map map) { 15 | return gson.toJson(map); 16 | } 17 | 18 | @Callable 19 | public String encode(List list) { 20 | return gson.toJson(list); 21 | } 22 | 23 | @Callable 24 | public Object decode(String json) { 25 | return gson.fromJson(json, Object.class); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/ContainerAccessor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.gui.screen.ingame.ContainerScreen; 4 | import net.minecraft.container.Slot; 5 | import net.minecraft.container.SlotActionType; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.gen.Accessor; 8 | import org.spongepowered.asm.mixin.gen.Invoker; 9 | 10 | @Mixin({ContainerScreen.class}) 11 | public interface ContainerAccessor { 12 | @Invoker 13 | void invokeOnMouseClick(Slot slot, int invSlot, int button, SlotActionType slotActionType); 14 | 15 | @Invoker 16 | boolean invokeIsPointWithinBounds(int xPosition, int yPosition, int width, int height, double pointX, double pointY); 17 | 18 | @Accessor 19 | Slot getFocusedSlot(); 20 | } 21 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ScriptIt Readme 2 | =============== 3 | 4 | ScriptIt uses Lua as its scripting language. 5 | 6 | It ships with the `table`, `string`, `math` and `coroutine` libraries from Lua. 7 | 8 | Additionally a few different libraries were developed to interact with Minecraft. 9 | 10 | Scripts which are bound to keybindings are "threaded". That means that they pause their execution after 100 "instructions". And every tick the scripts gets resumed, until it is done. 11 | 12 | Event and hud element bindings on the other hand are executed "instantly". They run until they are done, and do not pause. Thath means that you should keep the logic in those scripts pretty short. 13 | 14 | The default key for opening the ScriptIt GUI is `K`. 15 | 16 | Documentation is available on the [github wiki](https://github.com/Gorlem/ScriptIt/wiki). -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/dependencies/Resolver.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.dependencies; 2 | 3 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 4 | 5 | import java.util.List; 6 | import java.util.function.Supplier; 7 | 8 | public interface Resolver { 9 | static Resolver getInstance() { 10 | return ResolverImpl.getInstance(); 11 | } 12 | 13 | void add(T dependency); 14 | void add(Class dependencyClass) throws DependencyException; 15 | 16 | T resolve(Class dependencyClass) throws DependencyException; 17 | List resolveAll(Class dependencyClass); 18 | 19 | T create(Class type, Object... parameters) throws DependencyException; 20 | 21 | Supplier supplier(Class derivedType, Object... parameters); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/FieldAssembler.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import com.ddoerr.scriptit.screens.widgets.PanelWidget; 4 | import spinnery.widget.WAbstractWidget; 5 | import spinnery.widget.api.Position; 6 | import spinnery.widget.api.Size; 7 | 8 | import java.util.Map; 9 | 10 | public class FieldAssembler { 11 | public void assembleFields(PanelWidget panel, Map> fields) { 12 | int y = 0; 13 | 14 | for (Map.Entry> entry : fields.entrySet()) { 15 | PanelWidget fieldPanel = panel.createChild(PanelWidget.class, Position.of(panel, 0, y), Size.of(panel.getWidth(), 0)); 16 | entry.getValue().createWidget(fieldPanel); 17 | y += fieldPanel.getHeight() + 5; 18 | } 19 | 20 | panel.setHeight(y); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/IntegerField.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import spinnery.widget.WTextField; 4 | 5 | public class IntegerField extends AbstractTextField { 6 | @Override 7 | public void deserialize(String value) { 8 | this.value = Integer.parseInt(value); 9 | } 10 | 11 | @Override 12 | public String serialize() { 13 | return value.toString(); 14 | } 15 | 16 | @Override 17 | protected Integer getTemporaryValue(WTextField widget) { 18 | String integerText = widget.getText().replaceAll("\\D+", ""); 19 | // TODO: Currently breaks spinnery 20 | // widget.setText(integerText); 21 | 22 | if (integerText.length() == 0) { 23 | return 0; 24 | } 25 | 26 | return Integer.parseInt(integerText); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/triggers/EventTriggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.triggers; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 5 | import com.ddoerr.scriptit.api.triggers.Trigger; 6 | import com.ddoerr.scriptit.api.triggers.TriggerFactory; 7 | 8 | public class EventTriggerFactory implements TriggerFactory { 9 | private Resolver resolver; 10 | 11 | public EventTriggerFactory(Resolver resolver) { 12 | this.resolver = resolver; 13 | } 14 | 15 | @Override 16 | public Trigger createTrigger() { 17 | try { 18 | return resolver.create(EventTrigger.class); 19 | } catch (DependencyException e) { 20 | e.printStackTrace(); 21 | return null; 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/elements/ItemHudElementFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.elements; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 5 | import com.ddoerr.scriptit.api.hud.HudElement; 6 | import com.ddoerr.scriptit.api.hud.HudElementFactory; 7 | 8 | public class ItemHudElementFactory implements HudElementFactory { 9 | private Resolver resolver; 10 | 11 | public ItemHudElementFactory(Resolver resolver) { 12 | this.resolver = resolver; 13 | } 14 | 15 | @Override 16 | public HudElement createHudElement() { 17 | try { 18 | return resolver.create(ItemHudElement.class); 19 | } catch (DependencyException e) { 20 | e.printStackTrace(); 21 | return null; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/elements/TextHudElementFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.elements; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 5 | import com.ddoerr.scriptit.api.hud.HudElement; 6 | import com.ddoerr.scriptit.api.hud.HudElementFactory; 7 | 8 | public class TextHudElementFactory implements HudElementFactory { 9 | private Resolver resolver; 10 | 11 | public TextHudElementFactory(Resolver resolver) { 12 | this.resolver = resolver; 13 | } 14 | 15 | @Override 16 | public HudElement createHudElement() { 17 | try { 18 | return resolver.create(TextHudElement.class); 19 | } catch (DependencyException e) { 20 | e.printStackTrace(); 21 | return null; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/triggers/DurationTriggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.triggers; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 5 | import com.ddoerr.scriptit.api.triggers.Trigger; 6 | import com.ddoerr.scriptit.api.triggers.TriggerFactory; 7 | 8 | public class DurationTriggerFactory implements TriggerFactory { 9 | private Resolver resolver; 10 | 11 | public DurationTriggerFactory(Resolver resolver) { 12 | this.resolver = resolver; 13 | } 14 | 15 | @Override 16 | public Trigger createTrigger() { 17 | try { 18 | return resolver.create(DurationTrigger.class); 19 | } catch (DependencyException e) { 20 | e.printStackTrace(); 21 | return null; 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/triggers/KeyBindingTriggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.triggers; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 5 | import com.ddoerr.scriptit.api.triggers.Trigger; 6 | import com.ddoerr.scriptit.api.triggers.TriggerFactory; 7 | 8 | public class KeyBindingTriggerFactory implements TriggerFactory { 9 | private Resolver resolver; 10 | 11 | public KeyBindingTriggerFactory(Resolver resolver) { 12 | this.resolver = resolver; 13 | } 14 | 15 | @Override 16 | public Trigger createTrigger() { 17 | try { 18 | return resolver.create(KeyBindingTrigger.class); 19 | } catch (DependencyException e) { 20 | e.printStackTrace(); 21 | return null; 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/AbstractNumberSettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | import java.util.function.Consumer; 4 | import java.util.function.Supplier; 5 | 6 | public abstract class AbstractNumberSettingModel extends AbstractSettingModel implements ToggleableSettingModel { 7 | protected T minimum; 8 | protected T maximum; 9 | protected T step; 10 | 11 | public AbstractNumberSettingModel(String name, Supplier getter, Consumer setter, T minimum, T maximum, T step) { 12 | super(name, getter, setter); 13 | this.minimum = minimum; 14 | this.maximum = maximum; 15 | this.step = step; 16 | } 17 | 18 | @Override 19 | public String getPossibleValues() { 20 | return minimum.toString() + " - " + maximum.toString() + "; step = " + step.toString(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/triggers/TriggerMessageImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.triggers; 2 | 3 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 4 | import com.ddoerr.scriptit.api.libraries.Model; 5 | 6 | import java.time.Duration; 7 | 8 | public class TriggerMessageImpl implements TriggerMessage { 9 | private Model model; 10 | private Duration duration; 11 | 12 | public TriggerMessageImpl() { 13 | } 14 | 15 | public TriggerMessageImpl(Model model) { 16 | this.model = model; 17 | } 18 | 19 | public TriggerMessageImpl(Model model, Duration duration) { 20 | this.model = model; 21 | this.duration = duration; 22 | } 23 | 24 | @Override 25 | public Model getTriggerModel() { 26 | return model; 27 | } 28 | 29 | @Override 30 | public Duration getTimeout() { 31 | return duration; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/util/Debouncer.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.util; 2 | 3 | import java.time.Duration; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.Future; 6 | import java.util.concurrent.ScheduledExecutorService; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | public class Debouncer { 10 | ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); 11 | Future future; 12 | Duration duration; 13 | Runnable runnable; 14 | 15 | public Debouncer(Duration duration, Runnable runnable) { 16 | this.duration = duration; 17 | this.runnable = runnable; 18 | } 19 | 20 | public void call() { 21 | if (future != null) { 22 | future.cancel(true); 23 | } 24 | 25 | future = scheduler.schedule(runnable, duration.toMillis(), TimeUnit.MILLISECONDS); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/clickables/ClickablesHelper.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries.clickables; 2 | 3 | import net.minecraft.client.gui.screen.Screen; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Optional; 8 | 9 | public abstract class ClickablesHelper { 10 | protected List provider = new ArrayList<>(); 11 | 12 | protected Optional getProvider(Screen screen) { 13 | return provider.stream().filter(p -> p.matches(screen)).findFirst(); 14 | } 15 | 16 | public int getAmount(Screen screen) { 17 | return getProvider(screen).map(p -> p.getAmount(screen)).orElse(0); 18 | } 19 | 20 | public void renderTooltip(Screen screen, int mouseX, int mouseY) { 21 | getProvider(screen).ifPresent(p -> p.renderTooltip(screen, mouseX, mouseY)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/hud/HudElementContainer.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.hud; 2 | 3 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 4 | import com.ddoerr.scriptit.api.util.geometry.Point; 5 | import net.minecraft.client.gui.Drawable; 6 | import net.minecraft.util.Tickable; 7 | 8 | public interface HudElementContainer extends Drawable, Tickable { 9 | int DEFAULT_PADDING = 2; 10 | 11 | void setAnchor(HudHorizontalAnchor horizontalAnchor, HudVerticalAnchor verticalAnchor); 12 | HudVerticalAnchor getVerticalAnchor(); 13 | HudHorizontalAnchor getHorizontalAnchor(); 14 | 15 | void setRealPosition(Point position); 16 | Point getRealPosition(); 17 | 18 | void setRelativePosition(Point position); 19 | Point getRelativePosition(); 20 | 21 | int getHeight(); 22 | int getWidth(); 23 | 24 | HudElement getHudElement(); 25 | ScriptContainer getScriptContainer(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "scriptit", 4 | "version": "${version}", 5 | 6 | "name": "ScriptIt", 7 | "description": "Script your Minecraft game with Lua!", 8 | "authors": [ 9 | "Gorlem / Dennis Dörr" 10 | ], 11 | "contact": { 12 | "homepage": "https://ddoerr.com/" 13 | }, 14 | 15 | "icon": "assets/scriptit/icon.png", 16 | 17 | "environment": "client", 18 | "entrypoints": { 19 | "client": [ 20 | "com.ddoerr.scriptit.ScriptItMod" 21 | ], 22 | "scriptit:extensions": [ 23 | "com.ddoerr.scriptit.extension.ScriptItExtension" 24 | ], 25 | "cotton-client-commands": [ 26 | "com.ddoerr.scriptit.commands.ScriptItCommand" 27 | ] 28 | }, 29 | 30 | "mixins": [ 31 | "scriptit.mixins.json" 32 | ], 33 | 34 | "depends": { 35 | "fabricloader": ">=0.4.0", 36 | "fabric": "*", 37 | "cotton-client-commands":"^1.0.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/scripts/RunningScriptImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.scripts; 2 | 3 | import com.ddoerr.scriptit.api.languages.ContainedValue; 4 | import com.ddoerr.scriptit.api.scripts.RunningScript; 5 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 6 | 7 | import java.util.concurrent.CompletableFuture; 8 | 9 | public class RunningScriptImpl implements RunningScript { 10 | ScriptContainer scriptContainer; 11 | CompletableFuture future; 12 | 13 | public RunningScriptImpl(ScriptContainer scriptContainer, CompletableFuture future) { 14 | this.scriptContainer = scriptContainer; 15 | this.future = future; 16 | } 17 | 18 | @Override 19 | public ScriptContainer getScriptContainer() { 20 | return scriptContainer; 21 | } 22 | 23 | @Override 24 | public CompletableFuture getFuture() { 25 | return future; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/languages/LanguageManagerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.languages; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Loadable; 4 | import com.ddoerr.scriptit.api.languages.Language; 5 | import com.ddoerr.scriptit.api.libraries.Model; 6 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 7 | import net.minecraft.util.Identifier; 8 | 9 | public class LanguageManagerImpl implements Loadable { 10 | private ScriptItRegistry registry; 11 | 12 | public LanguageManagerImpl(ScriptItRegistry registry) { 13 | this.registry = registry; 14 | } 15 | 16 | @Override 17 | public void load() { 18 | for (Language language : registry.languages) { 19 | for (Model library : registry.libraries) { 20 | Identifier identifier = registry.libraries.getId(library); 21 | language.loadLibrary(identifier.toString(), library); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/MixinSleepingChatScreen.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import net.minecraft.client.gui.screen.ChatScreen; 4 | import net.minecraft.client.gui.screen.SleepingChatScreen; 5 | import net.minecraft.client.network.ClientPlayerEntity; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Redirect; 9 | 10 | @Mixin(SleepingChatScreen.class) 11 | public abstract class MixinSleepingChatScreen extends ChatScreen { 12 | public MixinSleepingChatScreen(String originalChatText) { 13 | super(originalChatText); 14 | } 15 | 16 | @Redirect(method = "keyPressed", at = @At(value = "INVOKE", target = "net/minecraft/client/network/ClientPlayerEntity.sendChatMessage(Ljava/lang/String;)V")) 17 | public void proxySendChatMessage(ClientPlayerEntity entity, String message) { 18 | this.sendMessage(message); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/PositionModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.util.math.Vec3d; 6 | 7 | public class PositionModel extends AnnotationBasedModel { 8 | public static PositionModel From(Vec3d vector) { 9 | PositionModel positionModel = new PositionModel(); 10 | positionModel.vector = vector; 11 | return positionModel; 12 | } 13 | 14 | public static PositionModel From(double x, double y, double z) { 15 | return From(new Vec3d(x, y, z)); 16 | } 17 | 18 | private Vec3d vector; 19 | 20 | @Getter 21 | public double getX() { 22 | return vector.x; 23 | } 24 | 25 | @Getter 26 | public double getY() { 27 | return vector.y; 28 | } 29 | 30 | @Getter 31 | public double getZ() { 32 | return vector.z; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/ScriptBuilderModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import com.ddoerr.scriptit.api.scripts.ScriptBuilder; 6 | 7 | public class ScriptBuilderModel extends AnnotationBasedModel { 8 | private ScriptBuilder scriptBuilder = new ScriptBuilder(); 9 | 10 | @Callable 11 | public ScriptBuilderModel language(String language) { 12 | scriptBuilder.language(language); 13 | return this; 14 | } 15 | 16 | @Callable 17 | public ScriptBuilderModel script(String content) { 18 | scriptBuilder.fromString(content); 19 | return this; 20 | } 21 | 22 | @Callable 23 | public ScriptBuilderModel file(String path) { 24 | scriptBuilder.fromFile(path); 25 | return this; 26 | } 27 | 28 | @Callable 29 | public String run() { 30 | return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/hud/HudVerticalAnchor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.hud; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.client.util.Window; 5 | 6 | import java.util.function.Function; 7 | 8 | public enum HudVerticalAnchor implements HudAnchor { 9 | TOP((window) -> 0), 10 | MIDDLE((window) -> window.getScaledHeight() / 2), 11 | BOTTOM(Window::getScaledHeight); 12 | 13 | private Function baseValueFunction; 14 | private Window window; 15 | 16 | HudVerticalAnchor(Function baseValueFunction) { 17 | this.baseValueFunction = baseValueFunction; 18 | window = MinecraftClient.getInstance().getWindow(); 19 | } 20 | 21 | private Window getWindow() { 22 | if (window == null) 23 | window = MinecraftClient.getInstance().getWindow(); 24 | 25 | return window; 26 | } 27 | 28 | public int getBaseValue() { 29 | return baseValueFunction.apply(getWindow()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/hud/HudHorizontalAnchor.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.hud; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.client.util.Window; 5 | 6 | import java.util.function.Function; 7 | 8 | public enum HudHorizontalAnchor implements HudAnchor { 9 | LEFT((window) -> 0), 10 | CENTER((window) -> window.getScaledWidth() / 2), 11 | RIGHT(Window::getScaledWidth); 12 | 13 | private Function baseValueFunction; 14 | private Window window; 15 | 16 | HudHorizontalAnchor(Function baseValueFunction) { 17 | this.baseValueFunction = baseValueFunction; 18 | window = MinecraftClient.getInstance().getWindow(); 19 | } 20 | 21 | private Window getWindow() { 22 | if (window == null) 23 | window = MinecraftClient.getInstance().getWindow(); 24 | 25 | return window; 26 | } 27 | 28 | public int getBaseValue() { 29 | return baseValueFunction.apply(getWindow()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/events/AbstractEvent.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.events; 2 | 3 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 4 | import com.ddoerr.scriptit.triggers.TriggerMessageImpl; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.function.Consumer; 9 | 10 | public class AbstractEvent implements Event { 11 | protected List> listeners = new ArrayList<>(); 12 | 13 | @Override 14 | public void registerListener(Consumer messageConsumer) { 15 | listeners.add(messageConsumer); 16 | } 17 | 18 | @Override 19 | public void removeListener(Consumer messageConsumer) { 20 | listeners.remove(messageConsumer); 21 | } 22 | 23 | protected void dispatch() { 24 | dispatch(new TriggerMessageImpl()); 25 | } 26 | 27 | protected void dispatch(TriggerMessage message) { 28 | for (Consumer listener : listeners) { 29 | listener.accept(message); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/AbstractTextField.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import com.ddoerr.scriptit.screens.widgets.PanelWidget; 4 | import spinnery.widget.WTextField; 5 | import spinnery.widget.api.Position; 6 | import spinnery.widget.api.Size; 7 | 8 | public abstract class AbstractTextField extends AbstractField { 9 | @Override 10 | public void createWidget(PanelWidget panel) { 11 | super.createWidget(panel); 12 | 13 | panel.createChild(WTextField.class, Position.of(panel, 0, 10), Size.of(panel.getWidth(), 16)) 14 | .setText(serialize()) 15 | .setOnKeyPressed((widget, keyCode, character, keyModifier) -> { 16 | temporaryValue = getTemporaryValue((WTextField)widget); 17 | }) 18 | .setOnCharTyped((widget, character, keyCode) -> { 19 | temporaryValue = getTemporaryValue((WTextField)widget); 20 | }); 21 | 22 | panel.setHeight(26); 23 | } 24 | 25 | protected abstract T getTemporaryValue(WTextField widget); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/BlockModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.block.BlockState; 6 | import net.minecraft.state.property.Property; 7 | 8 | import java.util.Map; 9 | import java.util.stream.Collectors; 10 | 11 | public class BlockModel extends AnnotationBasedModel { 12 | public static BlockModel From(BlockState blockState) { 13 | BlockModel blockModel = new BlockModel(); 14 | blockModel.blockState = blockState; 15 | return blockModel; 16 | } 17 | 18 | private BlockState blockState; 19 | 20 | @Getter 21 | public ItemModel getItem() { 22 | return ItemModel.From(blockState.getBlock().asItem().getStackForRender()); 23 | } 24 | 25 | @Getter 26 | public Map getProperties() { 27 | return blockState.getProperties() 28 | .stream() 29 | .collect(Collectors.toMap(Property::getName, p -> blockState.get(p).toString())); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Dennis Dörr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/triggers/AbstractTrigger.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.triggers; 2 | 3 | import com.ddoerr.scriptit.api.triggers.Trigger; 4 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 5 | import com.ddoerr.scriptit.fields.Field; 6 | 7 | import java.util.LinkedHashMap; 8 | import java.util.Map; 9 | import java.util.function.Consumer; 10 | 11 | public abstract class AbstractTrigger implements Trigger { 12 | protected Consumer callback; 13 | protected Map> fields = new LinkedHashMap<>(); 14 | 15 | @Override 16 | public void setCallback(Consumer callback) { 17 | stop(); 18 | this.callback = callback; 19 | start(); 20 | } 21 | 22 | @Override 23 | public void check() { 24 | // Empty default 25 | } 26 | 27 | @Override 28 | public void start() { 29 | // Empty default 30 | } 31 | 32 | @Override 33 | public void stop() { 34 | // Empty default 35 | } 36 | 37 | @Override 38 | public Map> getFields() { 39 | return fields; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/callbacks/OutgoingChatMessageCallback.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.callbacks; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.util.ActionResult; 6 | import net.minecraft.util.TypedActionResult; 7 | 8 | public interface OutgoingChatMessageCallback { 9 | Event EVENT = EventFactory.createArrayBacked( 10 | OutgoingChatMessageCallback.class, 11 | (listeners) -> (message) -> { 12 | 13 | for (OutgoingChatMessageCallback event : listeners) { 14 | TypedActionResult result = event.onOutgoingChatMessage(message); 15 | 16 | if (result.getResult() != ActionResult.PASS) { 17 | return result; 18 | } 19 | 20 | message = result.getValue(); 21 | } 22 | 23 | return new TypedActionResult<>(ActionResult.PASS, message); 24 | } 25 | ); 26 | 27 | TypedActionResult onOutgoingChatMessage(String message); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/callbacks/IncomingChatMessageCallback.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.callbacks; 2 | 3 | import net.fabricmc.fabric.api.event.Event; 4 | import net.fabricmc.fabric.api.event.EventFactory; 5 | import net.minecraft.text.Text; 6 | import net.minecraft.util.ActionResult; 7 | import net.minecraft.util.TypedActionResult; 8 | 9 | public interface IncomingChatMessageCallback { 10 | Event EVENT = EventFactory.createArrayBacked( 11 | IncomingChatMessageCallback.class, 12 | (listeners) -> (text) -> { 13 | 14 | for (IncomingChatMessageCallback event : listeners) { 15 | TypedActionResult result = event.onIncomingChatMessage(text); 16 | 17 | if (result.getResult() != ActionResult.PASS) { 18 | return result; 19 | } 20 | 21 | text = result.getValue(); 22 | } 23 | 24 | return new TypedActionResult<>(ActionResult.PASS, text); 25 | } 26 | ); 27 | 28 | TypedActionResult onIncomingChatMessage(Text text); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/util/DurationHelper.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.util; 2 | 3 | import net.minecraft.util.Pair; 4 | 5 | import java.time.Duration; 6 | import java.time.temporal.ChronoUnit; 7 | import java.util.LinkedHashMap; 8 | import java.util.Map; 9 | 10 | public class DurationHelper { 11 | private static Map units = new LinkedHashMap<>(); 12 | static { 13 | units.put(ChronoUnit.HOURS, 60 * 60); 14 | units.put(ChronoUnit.MINUTES, 60); 15 | units.put(ChronoUnit.SECONDS, 1); 16 | } 17 | 18 | public static Pair getUnitAndAmount(Duration duration) { 19 | long seconds = duration.getSeconds(); 20 | long nanos = duration.getNano(); 21 | 22 | if (nanos == 0 && seconds != 0) { 23 | for (Map.Entry unit : units.entrySet()) { 24 | if (seconds % unit.getValue() == 0) { 25 | return new Pair<>(unit.getKey(), seconds / unit.getValue()); 26 | } 27 | } 28 | } 29 | 30 | return new Pair<>(ChronoUnit.MILLIS, duration.toMillis()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/KeyBindingField.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import com.ddoerr.scriptit.screens.widgets.KeyBindingButtonWidget; 4 | import com.ddoerr.scriptit.screens.widgets.PanelWidget; 5 | import net.minecraft.client.util.InputUtil; 6 | import spinnery.widget.api.Position; 7 | import spinnery.widget.api.Size; 8 | 9 | public class KeyBindingField extends AbstractField { 10 | @Override 11 | public void deserialize(String value) { 12 | this.value = InputUtil.fromName(value); 13 | } 14 | 15 | @Override 16 | public String serialize() { 17 | return value.getName(); 18 | } 19 | 20 | @Override 21 | public void createWidget(PanelWidget panel) { 22 | super.createWidget(panel); 23 | 24 | KeyBindingButtonWidget keyBindingButtonWidget = panel.createChild(KeyBindingButtonWidget.class, Position.of(panel, 0, 10), Size.of(panel.getWidth(), 20)); 25 | keyBindingButtonWidget.setOnChange(keyCode -> temporaryValue = keyCode); 26 | 27 | if (value != null) { 28 | keyBindingButtonWidget.setKeyCode(value); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/screens/AbstractHistoryScreen.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.screens; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 5 | import net.minecraft.client.gui.screen.Screen; 6 | import org.lwjgl.glfw.GLFW; 7 | import spinnery.client.BaseScreen; 8 | 9 | public class AbstractHistoryScreen extends BaseScreen { 10 | private ScreenHistory history; 11 | 12 | public AbstractHistoryScreen(ScreenHistory history) { 13 | this.history = history; 14 | } 15 | 16 | @Override 17 | public void onClose() { 18 | history.back(); 19 | } 20 | 21 | protected void openScreen(Class screenClass, Object... parameters) { 22 | history.open(screenClass, parameters); 23 | } 24 | 25 | @Override 26 | public boolean keyPressed(int keyCode, int character, int keyModifier) { 27 | if (keyCode == GLFW.GLFW_KEY_ESCAPE) { 28 | onClose(); 29 | return true; 30 | } else { 31 | super.keyPressed(keyCode, character, keyModifier); 32 | return false; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.github/workflows/gradlepublish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created 2 | # For more information see: https://github.com/actions/setup-java#publishing-using-gradle 3 | 4 | name: Gradle Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | build: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Set up JDK 1.8 18 | uses: actions/setup-java@v1 19 | with: 20 | java-version: 1.8 21 | server-id: github 22 | settings-path: ${{ github.workspace }} 23 | 24 | - name: Build with Gradle 25 | run: gradle build 26 | 27 | - name: Upload Release Asset 28 | uses: shogo82148/actions-upload-release-asset@v1 29 | with: 30 | github_token: ${{ secrets.GITHUB_TOKEN }} 31 | upload_url: ${{ github.event.release.upload_url }} 32 | asset_path: ./build/libs/scriptit-*.jar 33 | 34 | - name: Publish to GitHub Packages 35 | run: gradle publish 36 | env: 37 | USERNAME: ${{ github.actor }} 38 | PASSWORD: ${{ secrets.GITHUB_TOKEN }} 39 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/util/GenericEnumHelper.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.util; 2 | 3 | import org.apache.commons.lang3.ArrayUtils; 4 | 5 | import java.lang.reflect.InvocationTargetException; 6 | import java.lang.reflect.Method; 7 | 8 | public class GenericEnumHelper{ 9 | public static > T[] getValues(Class enumClass) { 10 | try { 11 | Method values = enumClass.getDeclaredMethod("values"); 12 | Object object = values.invoke(null); 13 | return (T[])object; 14 | } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { 15 | e.printStackTrace(); 16 | } 17 | return (T[])new Object[0]; 18 | } 19 | 20 | public static > T getValue(Class enumClass, int index) { 21 | return getValues(enumClass)[index]; 22 | } 23 | 24 | public static > T getNext(Class enumClass, T current) { 25 | T[] values = getValues(enumClass); 26 | int index = ArrayUtils.indexOf(values, current) + 1; 27 | int size = values.length; 28 | 29 | return values[index % size]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/ScriptsLibrary.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 6 | import com.ddoerr.scriptit.api.scripts.ScriptManager; 7 | 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | 11 | public class ScriptsLibrary extends AnnotationBasedModel { 12 | private ScriptManager scriptManager; 13 | 14 | public ScriptsLibrary(ScriptManager scriptManager) { 15 | this.scriptManager = scriptManager; 16 | } 17 | 18 | @Callable 19 | public int stop() { 20 | return scriptManager.stopAllScripts(); 21 | } 22 | 23 | @Callable 24 | public int stop(String name) { 25 | return scriptManager.stopScripts(name); 26 | } 27 | 28 | @Getter 29 | public List getRunningScripts() { 30 | return scriptManager.getRunningScripts().stream() 31 | .map(runningScript -> runningScript.getScriptContainer().getScript().getName()) 32 | .collect(Collectors.toList()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/GameLibrary.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import com.ddoerr.scriptit.mixin.FpsAccessor; 6 | import net.fabricmc.loader.api.FabricLoader; 7 | import net.minecraft.client.MinecraftClient; 8 | 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | public class GameLibrary extends AnnotationBasedModel { 13 | private MinecraftClient minecraft; 14 | 15 | public GameLibrary(MinecraftClient minecraft) { 16 | this.minecraft = minecraft; 17 | } 18 | 19 | @Getter 20 | public int getFps() { 21 | return FpsAccessor.getCurrentFps(); 22 | } 23 | 24 | @Getter 25 | public String getVersion() { 26 | return minecraft.getGame().getVersion().getName(); 27 | } 28 | 29 | @Getter 30 | public List getMods() { 31 | return FabricLoader.getInstance() 32 | .getAllMods() 33 | .stream() 34 | .map(m -> m.getMetadata().getId()) 35 | .collect(Collectors.toList()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/AbstractSettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 4 | import net.minecraft.client.MinecraftClient; 5 | 6 | import java.util.function.Consumer; 7 | import java.util.function.Supplier; 8 | 9 | public abstract class AbstractSettingModel extends AnnotationBasedModel implements SettingModel { 10 | private final String name; 11 | private final Supplier getter; 12 | private final Consumer setter; 13 | 14 | protected final MinecraftClient minecraft; 15 | 16 | public AbstractSettingModel(String name, Supplier getter, Consumer setter) { 17 | this.name = name; 18 | this.getter = getter; 19 | this.setter = setter; 20 | 21 | minecraft = MinecraftClient.getInstance(); 22 | } 23 | 24 | @Override 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | @Override 30 | public void setValue(T value) { 31 | setter.accept(value); 32 | minecraft.options.write(); 33 | } 34 | 35 | @Override 36 | public T getValue() { 37 | return getter.get(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extensions/ExtensionLoader.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extensions; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.dependencies.Loadable; 5 | import com.ddoerr.scriptit.api.dependencies.Resolver; 6 | import com.ddoerr.scriptit.api.registry.ExtensionInitializer; 7 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 8 | import net.fabricmc.loader.api.FabricLoader; 9 | import net.minecraft.util.Identifier; 10 | 11 | import java.util.List; 12 | 13 | public class ExtensionLoader implements Loadable { 14 | private ScriptItRegistry registry; 15 | private Resolver resolver; 16 | 17 | public ExtensionLoader(ScriptItRegistry registry, Resolver resolver) { 18 | this.registry = registry; 19 | this.resolver = resolver; 20 | } 21 | 22 | @Override 23 | public void load() { 24 | List entrypoints = FabricLoader.getInstance() 25 | .getEntrypoints(new Identifier(ScriptItMod.MOD_NAME, "extensions").toString(), ExtensionInitializer.class); 26 | 27 | for (ExtensionInitializer initializer : entrypoints) { 28 | initializer.onInitialize(registry, resolver); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/AbstractField.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import com.ddoerr.scriptit.screens.widgets.PanelWidget; 4 | import net.minecraft.text.Text; 5 | import spinnery.widget.WStaticText; 6 | import spinnery.widget.api.Position; 7 | 8 | public abstract class AbstractField implements Field { 9 | protected T value; 10 | protected T temporaryValue; 11 | 12 | protected Text title; 13 | protected Text description; 14 | 15 | @Override 16 | public T getValue() { 17 | return value; 18 | } 19 | 20 | @Override 21 | public void setValue(T value) { 22 | this.value = value; 23 | } 24 | 25 | @Override 26 | public void setTitle(Text title) { 27 | this.title = title; 28 | } 29 | 30 | @Override 31 | public void setDescription(Text description) { 32 | this.description = description; 33 | } 34 | 35 | @Override 36 | public void applyTemporaryValue() { 37 | value = temporaryValue; 38 | } 39 | 40 | @Override 41 | public void createWidget(PanelWidget panel) { 42 | temporaryValue = value; 43 | panel.createChild(WStaticText.class, Position.of(panel)) 44 | .setText(title); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/TeamModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.scoreboard.Team; 6 | import net.minecraft.util.Formatting; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class TeamModel extends AnnotationBasedModel { 12 | public static TeamModel From(Team team) { 13 | TeamModel teamModel = new TeamModel(); 14 | teamModel.team = team; 15 | return teamModel; 16 | } 17 | 18 | private Team team; 19 | 20 | @Getter 21 | public String getId() { 22 | return team.getName(); 23 | } 24 | 25 | @Getter 26 | public String getName() { 27 | return team.getDisplayName().asFormattedString(); 28 | } 29 | 30 | @Getter 31 | public String getPrefix() { 32 | return team.getPrefix().asFormattedString(); 33 | } 34 | 35 | @Getter 36 | public String getSuffix() { 37 | return team.getSuffix().asFormattedString(); 38 | } 39 | 40 | @Getter 41 | public Formatting getColor() { 42 | return team.getColor(); 43 | } 44 | 45 | @Getter 46 | public List getPlayers() { 47 | return new ArrayList<>(team.getPlayerList()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/EnchantmentModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.enchantment.Enchantment; 6 | 7 | import java.util.Map; 8 | 9 | public class EnchantmentModel extends AnnotationBasedModel { 10 | public static EnchantmentModel From(Map.Entry entry) { 11 | EnchantmentModel enchantmentModel = new EnchantmentModel(); 12 | enchantmentModel.enchantment = entry.getKey(); 13 | enchantmentModel.level = entry.getValue(); 14 | return enchantmentModel; 15 | } 16 | 17 | private Enchantment enchantment; 18 | @Getter 19 | public int level; 20 | 21 | @Getter 22 | public String getName() { 23 | return enchantment.getName(level).asFormattedString(); 24 | } 25 | 26 | @Getter 27 | public int getMinLevel() { 28 | return enchantment.getMinimumLevel(); 29 | } 30 | 31 | @Getter 32 | public int getMaxLevel() { 33 | return enchantment.getMaximumLevel(); 34 | } 35 | 36 | @Getter 37 | public boolean getIsCursed() { 38 | return enchantment.isCursed(); 39 | } 40 | 41 | @Getter 42 | public boolean getIsTreasure() { 43 | return enchantment.isTreasure(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/scripts/ScriptContainerManagerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.scripts; 2 | 3 | import com.ddoerr.scriptit.api.scripts.ScriptContainerManager; 4 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 5 | import com.ddoerr.scriptit.api.scripts.ScriptManager; 6 | import net.minecraft.util.Tickable; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class ScriptContainerManagerImpl implements Tickable, ScriptContainerManager { 12 | private List scripts = new ArrayList<>(); 13 | 14 | private ScriptManager scriptManager; 15 | 16 | public ScriptContainerManagerImpl(ScriptManager scriptManager) { 17 | this.scriptManager = scriptManager; 18 | } 19 | 20 | @Override 21 | public void add(ScriptContainer scriptContainer) { 22 | scripts.add(scriptContainer); 23 | scriptContainer.setCallback(message -> scriptManager.runScriptContainer(scriptContainer, message)); 24 | } 25 | 26 | @Override 27 | public List getAll() { 28 | return scripts; 29 | } 30 | 31 | @Override 32 | public void remove(ScriptContainer scriptContainer) { 33 | scripts.remove(scriptContainer); 34 | } 35 | 36 | @Override 37 | public void tick() { 38 | for (ScriptContainer script : scripts) { 39 | script.getTrigger().check(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/MixinGameRenderer.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import com.ddoerr.scriptit.extension.libraries.clickables.buttons.ButtonHelper; 4 | import com.ddoerr.scriptit.models.inventory.InventoryModel; 5 | import net.minecraft.client.MinecraftClient; 6 | import net.minecraft.client.render.GameRenderer; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | 13 | @Mixin({GameRenderer.class}) 14 | public abstract class MixinGameRenderer { 15 | private ButtonHelper buttonHelper = new ButtonHelper(); 16 | 17 | @Shadow 18 | private MinecraftClient client; 19 | 20 | @Inject(method = "render", at = @At("RETURN")) 21 | private void onRender(float tickDelta, long startTime, boolean tick, CallbackInfo info) { 22 | int mouseX = (int)(client.mouse.getX() * (double)client.getWindow().getScaledWidth() / (double)client.getWindow().getWidth()); 23 | int mouseY = (int)(client.mouse.getY() * (double)client.getWindow().getScaledHeight() / (double)client.getWindow().getHeight()); 24 | 25 | buttonHelper.renderTooltip(client.currentScreen, mouseX, mouseY); 26 | if (client.player != null) { 27 | InventoryModel.From(client.currentScreen, client.player.inventory).renderTooltip(mouseX, mouseY); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/ObjectiveModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.scoreboard.ScoreboardCriterion; 6 | import net.minecraft.scoreboard.ScoreboardObjective; 7 | 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | 11 | public class ObjectiveModel extends AnnotationBasedModel { 12 | public static ObjectiveModel From(ScoreboardObjective objective) { 13 | ObjectiveModel objectiveModel = new ObjectiveModel(); 14 | objectiveModel.objective = objective; 15 | return objectiveModel; 16 | } 17 | 18 | private ScoreboardObjective objective; 19 | 20 | @Getter 21 | public String getId(){ 22 | return objective.getName(); 23 | } 24 | 25 | @Getter 26 | public String getName() { 27 | return objective.getDisplayName().asFormattedString(); 28 | } 29 | 30 | @Getter 31 | public String getCriterion() { 32 | return objective.getCriterion().getName(); 33 | } 34 | 35 | @Getter 36 | public ScoreboardCriterion.RenderType getRenderType() { 37 | return objective.getRenderType(); 38 | } 39 | 40 | @Getter 41 | public List getScores() { 42 | return objective.getScoreboard().getAllPlayerScores(objective) 43 | .stream() 44 | .map(ScoreModel::From) 45 | .collect(Collectors.toList()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/ScoreboardLibrary.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import com.ddoerr.scriptit.models.ObjectiveModel; 6 | import com.ddoerr.scriptit.models.TeamModel; 7 | import net.minecraft.client.MinecraftClient; 8 | 9 | import java.util.Collections; 10 | import java.util.List; 11 | import java.util.Optional; 12 | import java.util.stream.Collectors; 13 | 14 | public class ScoreboardLibrary extends AnnotationBasedModel { 15 | MinecraftClient minecraft; 16 | 17 | public ScoreboardLibrary(MinecraftClient minecraft) { 18 | this.minecraft = minecraft; 19 | } 20 | 21 | @Getter 22 | public List getObjectives() { 23 | return Optional.ofNullable(minecraft.world) 24 | .map(w -> w.getScoreboard() 25 | .getObjectives() 26 | .stream() 27 | .map(ObjectiveModel::From) 28 | .collect(Collectors.toList())) 29 | .orElse(Collections.emptyList()); 30 | } 31 | 32 | @Getter 33 | public List getTeams() { 34 | return Optional.ofNullable(minecraft.world) 35 | .map(w -> w.getScoreboard() 36 | .getTeams() 37 | .stream() 38 | .map(TeamModel::From) 39 | .collect(Collectors.toList())) 40 | .orElse(Collections.emptyList()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/text/TextContainedResultFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.text; 2 | 3 | import com.ddoerr.scriptit.api.exceptions.ConversionException; 4 | import com.ddoerr.scriptit.api.languages.ContainedResultFactory; 5 | import com.ddoerr.scriptit.api.libraries.Model; 6 | 7 | import java.lang.reflect.Type; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public class TextContainedResultFactory implements ContainedResultFactory { 12 | @Override 13 | public Object nullValue() { 14 | return null; 15 | } 16 | 17 | @Override 18 | public Object fromString(String value) { 19 | return value; 20 | } 21 | 22 | @Override 23 | public Object fromBoolean(boolean value) { 24 | return value; 25 | } 26 | 27 | @Override 28 | public Object fromFloat(float value) { 29 | return value; 30 | } 31 | 32 | @Override 33 | public Object fromDouble(double value) { 34 | return value; 35 | } 36 | 37 | @Override 38 | public Object fromInteger(int value) { 39 | return value; 40 | } 41 | 42 | @Override 43 | public Object fromEnum(Enum value) { 44 | return value; 45 | } 46 | 47 | @Override 48 | public Object fromMap(Type keyType, Type valueType, Map value) throws ConversionException { 49 | return value; 50 | } 51 | 52 | @Override 53 | public Object fromList(Type entryType, List value) throws ConversionException { 54 | return value; 55 | } 56 | 57 | @Override 58 | public Object fromModel(Model value) { 59 | return value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/SelectionField.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import com.ddoerr.scriptit.screens.widgets.PanelWidget; 4 | import com.ddoerr.scriptit.screens.widgets.ValuesDropdownWidget; 5 | import spinnery.widget.api.Position; 6 | import spinnery.widget.api.Size; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class SelectionField extends AbstractField { 12 | private List values = new ArrayList<>(); 13 | private String prefix; 14 | 15 | @Override 16 | public void deserialize(String value) { 17 | this.value = value; 18 | } 19 | 20 | @Override 21 | public String serialize() { 22 | return value; 23 | } 24 | 25 | public void setValues(List values) { 26 | this.values = values; 27 | } 28 | 29 | public void setTranslationPrefix(String prefix) { 30 | this.prefix = prefix; 31 | } 32 | 33 | @Override 34 | public void createWidget(PanelWidget panel) { 35 | super.createWidget(panel); 36 | 37 | ValuesDropdownWidget dropdown = panel.createChild(ValuesDropdownWidget.class, Position.of(panel, 0, 10), Size.of(panel.getWidth(), 20)); 38 | 39 | if (prefix != null) { 40 | dropdown.setTranslationPrefix(prefix); 41 | } 42 | 43 | if (value == null) { 44 | dropdown.setLabel("Please select a value"); 45 | } else { 46 | dropdown.selectValue(value); 47 | } 48 | 49 | dropdown.addValues(values); 50 | dropdown.setOnChange(data -> temporaryValue = data); 51 | 52 | panel.setHeight(30); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/registry/ScriptItRegistry.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.registry; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.events.Event; 5 | import com.ddoerr.scriptit.api.hud.HudElement; 6 | import com.ddoerr.scriptit.api.hud.HudElementFactory; 7 | import com.ddoerr.scriptit.api.languages.Language; 8 | import com.ddoerr.scriptit.api.libraries.Model; 9 | import com.ddoerr.scriptit.api.triggers.Trigger; 10 | import com.ddoerr.scriptit.api.triggers.TriggerFactory; 11 | import net.minecraft.util.Identifier; 12 | import net.minecraft.util.registry.DefaultedRegistry; 13 | import net.minecraft.util.registry.Registry; 14 | import net.minecraft.util.registry.SimpleRegistry; 15 | 16 | import java.util.function.Supplier; 17 | 18 | public class ScriptItRegistry extends SimpleRegistry> { 19 | public final SimpleRegistry libraries = new SimpleRegistry<>(); 20 | public final DefaultedRegistry languages = new DefaultedRegistry<>(ScriptItMod.MOD_NAME + ":text"); 21 | public final SimpleRegistry events = new SimpleRegistry<>(); 22 | public final SimpleRegistry hudElements = new SimpleRegistry<>(); 23 | public final SimpleRegistry triggers = new SimpleRegistry<>(); 24 | 25 | public ScriptItRegistry() { 26 | add(new Identifier(ScriptItMod.MOD_NAME, "library"), libraries); 27 | add(new Identifier(ScriptItMod.MOD_NAME, "language"), languages); 28 | add(new Identifier(ScriptItMod.MOD_NAME, "event"), events); 29 | add(new Identifier(ScriptItMod.MOD_NAME, "hud_element"), hudElements); 30 | add(new Identifier(ScriptItMod.MOD_NAME, "trigger"), triggers); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/PlayerEntryModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.client.network.PlayerListEntry; 6 | import net.minecraft.scoreboard.Team; 7 | import net.minecraft.text.Text; 8 | import net.minecraft.world.GameMode; 9 | import org.apache.commons.lang3.StringUtils; 10 | 11 | import java.util.Optional; 12 | 13 | public class PlayerEntryModel extends AnnotationBasedModel { 14 | public static PlayerEntryModel From(PlayerListEntry playerListEntry) { 15 | PlayerEntryModel playerEntryModel = new PlayerEntryModel(); 16 | playerEntryModel.playerListEntry = playerListEntry; 17 | return playerEntryModel; 18 | } 19 | 20 | private PlayerListEntry playerListEntry; 21 | 22 | @Getter 23 | public String getUuid() { 24 | return playerListEntry.getProfile().getId().toString(); 25 | } 26 | 27 | @Getter 28 | public String getName() { 29 | return playerListEntry.getProfile().getName(); 30 | } 31 | 32 | @Getter 33 | public String getFormatted() { 34 | return Optional.ofNullable(playerListEntry.getDisplayName()) 35 | .map(Text::asFormattedString) 36 | .orElse(StringUtils.EMPTY); 37 | } 38 | 39 | @Getter 40 | public String getTeam() { 41 | return Optional.ofNullable(playerListEntry.getScoreboardTeam()) 42 | .map(Team::getName) 43 | .orElse(StringUtils.EMPTY); 44 | } 45 | 46 | @Getter 47 | public GameMode getGamemode() { 48 | return Optional.ofNullable(playerListEntry.getGameMode()) 49 | .orElse(GameMode.NOT_SET); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/GuiLibrary.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 6 | import com.ddoerr.scriptit.extension.libraries.clickables.buttons.ButtonHelper; 7 | import com.ddoerr.scriptit.models.inventory.InventoryModel; 8 | import com.google.common.collect.Lists; 9 | import net.minecraft.client.MinecraftClient; 10 | import org.apache.commons.lang3.StringUtils; 11 | 12 | import java.util.List; 13 | import java.util.Optional; 14 | 15 | public class GuiLibrary extends AnnotationBasedModel { 16 | private MinecraftClient minecraft; 17 | 18 | private ButtonHelper buttonHelper = new ButtonHelper(); 19 | 20 | public GuiLibrary(MinecraftClient minecraft) { 21 | this.minecraft = minecraft; 22 | } 23 | 24 | @Getter 25 | public String getScreenName() { 26 | return Optional.ofNullable(minecraft.currentScreen).map(s -> s.getClass().getSimpleName()).orElse(StringUtils.EMPTY); 27 | } 28 | 29 | @Getter 30 | public InventoryModel getInventory() { 31 | if (minecraft.player == null) { 32 | return null; 33 | } 34 | 35 | return InventoryModel.From(minecraft.currentScreen, minecraft.player.inventory); 36 | } 37 | 38 | @Getter 39 | public int getButtonCount() { 40 | return buttonHelper.getAmount(minecraft.currentScreen); 41 | } 42 | 43 | @Callable 44 | public void clickButton(List ids) { 45 | for (int id : ids) { 46 | buttonHelper.click(minecraft.currentScreen, id); 47 | } 48 | } 49 | 50 | @Callable 51 | public void clickButton(int id) { 52 | clickButton(Lists.newArrayList(id)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/TargetModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.block.BlockState; 6 | import net.minecraft.client.MinecraftClient; 7 | import net.minecraft.entity.Entity; 8 | import net.minecraft.util.hit.BlockHitResult; 9 | import net.minecraft.util.hit.EntityHitResult; 10 | import net.minecraft.util.hit.HitResult; 11 | import net.minecraft.util.math.BlockPos; 12 | 13 | public class TargetModel extends AnnotationBasedModel { 14 | public static TargetModel From(HitResult hitResult) { 15 | TargetModel targetModel = new TargetModel(); 16 | targetModel.hitResult = hitResult; 17 | return targetModel; 18 | } 19 | 20 | private HitResult hitResult; 21 | 22 | @Getter 23 | public HitResult.Type getType() { 24 | return hitResult.getType(); 25 | } 26 | 27 | @Getter 28 | public PositionModel getPosition() { 29 | return PositionModel.From(hitResult.getPos()); 30 | } 31 | 32 | @Getter 33 | public BlockModel getBlock() { 34 | if (hitResult.getType() == HitResult.Type.BLOCK && hitResult instanceof BlockHitResult) { 35 | BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos(); 36 | BlockState blockState = MinecraftClient.getInstance().world.getBlockState(blockPos); 37 | return BlockModel.From(blockState); 38 | } 39 | return null; 40 | } 41 | 42 | @Getter 43 | public EntityModel getEntity() { 44 | if (hitResult.getType() == HitResult.Type.ENTITY && hitResult instanceof EntityHitResult) { 45 | Entity entity = ((EntityHitResult) hitResult).getEntity(); 46 | return EntityModel.From(entity); 47 | } 48 | return null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/fields/ColorField.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.fields; 2 | 3 | import com.ddoerr.scriptit.api.util.Color; 4 | import com.ddoerr.scriptit.screens.widgets.PanelWidget; 5 | import spinnery.widget.WTextField; 6 | import spinnery.widget.api.Position; 7 | import spinnery.widget.api.Size; 8 | 9 | public class ColorField extends AbstractField { 10 | @Override 11 | public void deserialize(String value) { 12 | this.value = value; 13 | } 14 | 15 | @Override 16 | public String serialize() { 17 | return value; 18 | } 19 | 20 | @Override 21 | public void createWidget(PanelWidget panel) { 22 | super.createWidget(panel); 23 | 24 | PanelWidget colorPanel = panel.createChild(PanelWidget.class, Position.of(panel, 0, 10), Size.of(16, 16)); 25 | 26 | Color color = Color.runAndParse(value); 27 | colorPanel.setColor(spinnery.widget.api.Color.of(color.getValue())); 28 | 29 | 30 | panel.createChild(WTextField.class, Position.of(panel, 21, 10), Size.of(panel.getWidth() - 21, 16)) 31 | .setText(serialize()) 32 | .setOnKeyPressed((widget, keyCode, character, keyModifier) -> { 33 | String text = ((WTextField) widget).getText(); 34 | Color color1 = Color.runAndParse(text); 35 | colorPanel.setColor(spinnery.widget.api.Color.of(color1.getValue())); 36 | temporaryValue = text; 37 | }) 38 | .setOnCharTyped((widget, character, keyCode) -> { 39 | String text = ((WTextField) widget).getText(); 40 | Color color1 = Color.runAndParse(text); 41 | colorPanel.setColor(spinnery.widget.api.Color.of(color1.getValue())); 42 | temporaryValue = text; 43 | }); 44 | 45 | panel.setHeight(26); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/clickables/AbstractSpinneryClickablesProvider.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries.clickables; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import net.minecraft.client.gui.screen.Screen; 5 | import net.minecraft.client.resource.language.I18n; 6 | import net.minecraft.util.Identifier; 7 | import spinnery.client.BaseScreen; 8 | import spinnery.widget.WAbstractWidget; 9 | 10 | import java.util.List; 11 | import java.util.stream.Collectors; 12 | 13 | public abstract class AbstractSpinneryClickablesProvider implements ClickablesProvider { 14 | private Class type; 15 | private String translationKey; 16 | 17 | public AbstractSpinneryClickablesProvider(Class type) { 18 | this.type = type; 19 | translationKey = "tooltip.button"; 20 | } 21 | 22 | protected List getWidgets(BaseScreen screen) { 23 | return screen.getInterface().getAllWidgets() 24 | .stream() 25 | .filter(type::isInstance) 26 | .map(type::cast) 27 | .collect(Collectors.toList()); 28 | } 29 | 30 | @Override 31 | public int getAmount(Screen screen) { 32 | return getWidgets((BaseScreen)screen).size(); 33 | } 34 | 35 | @Override 36 | public boolean matches(Screen screen) { 37 | return screen instanceof BaseScreen; 38 | } 39 | 40 | @Override 41 | public void renderTooltip(Screen screen, int mouseX, int mouseY) { 42 | List widgets = getWidgets((BaseScreen)screen); 43 | 44 | for (int i = 0; i < widgets.size(); i++) { 45 | W widget = widgets.get(i); 46 | 47 | if (widget.isWithinBounds(mouseX, mouseY)) { 48 | screen.renderTooltip(I18n.translate(new Identifier(ScriptItMod.MOD_NAME, translationKey).toString(), i), mouseX, mouseY); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/screens/ScreenHistory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.screens; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 5 | import net.minecraft.client.MinecraftClient; 6 | import net.minecraft.client.gui.screen.Screen; 7 | 8 | import java.util.Stack; 9 | import java.util.function.Supplier; 10 | 11 | public class ScreenHistory { 12 | private Stack> screenStack = new Stack<>(); 13 | 14 | private MinecraftClient minecraft; 15 | private Resolver resolver; 16 | 17 | public ScreenHistory(MinecraftClient minecraft, Resolver resolver) { 18 | this.minecraft = minecraft; 19 | this.resolver = resolver; 20 | } 21 | 22 | private Supplier getScreenSupplier(Class screenClass, Object... parameters) { 23 | return () -> { 24 | try { 25 | return resolver.create(screenClass, parameters); 26 | } catch (DependencyException e) { 27 | e.printStackTrace(); 28 | } 29 | return null; 30 | }; 31 | } 32 | 33 | public void open(Class screenClass, Object... parameters) { 34 | Supplier screenSupplier = getScreenSupplier(screenClass, parameters); 35 | 36 | screenStack.push(screenSupplier); 37 | minecraft.openScreen(screenSupplier.get()); 38 | } 39 | 40 | public void push(Class screenClass, Object... parameters) { 41 | screenStack.push(getScreenSupplier(screenClass, parameters)); 42 | } 43 | 44 | public void back() { 45 | pop(); 46 | if (screenStack.isEmpty()) { 47 | minecraft.openScreen(null); 48 | } else { 49 | minecraft.openScreen(screenStack.peek().get()); 50 | } 51 | } 52 | 53 | public void pop() { 54 | screenStack.pop(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/events/SoundEvent.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.events; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.events.AbstractEvent; 5 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 6 | import com.ddoerr.scriptit.models.PositionModel; 7 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 8 | import com.ddoerr.scriptit.triggers.TriggerMessageImpl; 9 | import net.minecraft.client.MinecraftClient; 10 | import net.minecraft.client.sound.ListenerSoundInstance; 11 | import net.minecraft.client.sound.SoundInstance; 12 | import net.minecraft.client.sound.WeightedSoundSet; 13 | import net.minecraft.sound.SoundCategory; 14 | 15 | public class SoundEvent extends AbstractEvent implements ListenerSoundInstance { 16 | public SoundEvent() { 17 | MinecraftClient.getInstance().getSoundManager().registerListener(this); 18 | } 19 | 20 | @Override 21 | public void onSoundPlayed(SoundInstance sound, WeightedSoundSet soundSet) { 22 | SoundModel soundModel = new SoundModel(sound); 23 | TriggerMessage message = new TriggerMessageImpl(soundModel); 24 | dispatch(message); 25 | } 26 | 27 | public static class SoundModel extends AnnotationBasedModel { 28 | private SoundInstance soundInstance; 29 | 30 | public SoundModel(SoundInstance soundInstance) { 31 | this.soundInstance = soundInstance; 32 | } 33 | 34 | @Getter 35 | public String getIdentifier() { 36 | return soundInstance.getId().toString(); 37 | } 38 | 39 | @Getter 40 | public PositionModel getPosition() { 41 | return PositionModel.From(soundInstance.getX(), soundInstance.getY(), soundInstance.getZ()); 42 | } 43 | 44 | @Getter 45 | public SoundCategory getCategory() { 46 | return soundInstance.getCategory(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/clickables/buttons/EnchantingButtonProvider.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries.clickables.buttons; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.ducks.TooltipRenderedDuck; 5 | import com.ddoerr.scriptit.mixin.ContainerAccessor; 6 | import net.minecraft.client.MinecraftClient; 7 | import net.minecraft.client.gui.screen.Screen; 8 | import net.minecraft.client.gui.screen.ingame.EnchantingScreen; 9 | import net.minecraft.client.resource.language.I18n; 10 | import net.minecraft.container.EnchantingTableContainer; 11 | import net.minecraft.util.Identifier; 12 | 13 | public class EnchantingButtonProvider implements ButtonProvider { 14 | private MinecraftClient minecraft = MinecraftClient.getInstance(); 15 | 16 | @Override 17 | public int getAmount(Screen screen) { 18 | return 3; 19 | } 20 | 21 | @Override 22 | public void click(Screen screen, int index) { 23 | EnchantingTableContainer container = ((EnchantingScreen) screen).getContainer(); 24 | 25 | if (container.onButtonClick(minecraft.player, index)) { 26 | minecraft.interactionManager.clickButton(container.syncId, index); 27 | } 28 | } 29 | 30 | @Override 31 | public boolean matches(Screen screen) { 32 | return screen instanceof EnchantingScreen; 33 | } 34 | 35 | @Override 36 | public void renderTooltip(Screen screen, int mouseX, int mouseY) { 37 | for (int i = 0; i < 3; i++) { 38 | if (((ContainerAccessor)screen).invokeIsPointWithinBounds(60, 14 + 19 * i, 108, 17, mouseX, mouseY)) { 39 | if (((TooltipRenderedDuck) screen).wasTooltipRendered()) { 40 | mouseY -= 18; 41 | } 42 | 43 | screen.renderTooltip(I18n.translate(new Identifier(ScriptItMod.MOD_NAME, "tooltip.button").toString(), i), mouseX, mouseY); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/elements/HudElementManagerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.elements; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Loadable; 4 | import com.ddoerr.scriptit.api.hud.HudElementContainer; 5 | import com.ddoerr.scriptit.api.hud.HudElementManager; 6 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 7 | import com.ddoerr.scriptit.api.scripts.ScriptManager; 8 | import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; 9 | import net.minecraft.util.Tickable; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class HudElementManagerImpl implements Tickable, HudElementManager, Loadable { 15 | private List hudElements = new ArrayList<>(); 16 | 17 | private ScriptManager scriptManager; 18 | 19 | public HudElementManagerImpl(ScriptManager scriptManager) { 20 | this.scriptManager = scriptManager; 21 | } 22 | 23 | @Override 24 | public void add(HudElementContainer hudElement) { 25 | hudElements.add(hudElement); 26 | ScriptContainer scriptContainer = hudElement.getScriptContainer(); 27 | scriptContainer.setCallback(message -> scriptManager.runScriptContainer(scriptContainer, message)); 28 | } 29 | 30 | @Override 31 | public List getAll() { 32 | return hudElements; 33 | } 34 | 35 | @Override 36 | public void remove(HudElementContainer hudElement) { 37 | hudElements.remove(hudElement); 38 | } 39 | 40 | @Override 41 | public void renderAll() { 42 | for (HudElementContainer hudElement : getAll()) { 43 | hudElement.render(0, 0, 0); 44 | } 45 | } 46 | 47 | public void tick() { 48 | for (HudElementContainer hudElement : getAll()) { 49 | hudElement.tick(); 50 | } 51 | } 52 | 53 | @Override 54 | public void load() { 55 | HudRenderCallback.EVENT.register(delta -> renderAll()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/StringSettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.annotations.Setter; 6 | import com.google.common.base.Joiner; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.function.Consumer; 11 | import java.util.function.Supplier; 12 | 13 | public class StringSettingModel extends AbstractSettingModel implements ToggleableSettingModel { 14 | private List whitelist = new ArrayList<>(); 15 | private Joiner joiner = Joiner.on(", "); 16 | 17 | public StringSettingModel(String name, Supplier getter, Consumer setter) { 18 | super(name, getter, setter); 19 | } 20 | 21 | public StringSettingModel(String name, Supplier getter, Consumer setter, List whitelist) { 22 | super(name, getter, setter); 23 | this.whitelist = whitelist; 24 | } 25 | 26 | @Setter 27 | @Override 28 | public void setValue(String value) { 29 | if (!whitelist.isEmpty() && !whitelist.contains(value)) { 30 | return; 31 | } 32 | super.setValue(value); 33 | } 34 | 35 | @Getter 36 | @Override 37 | public String getValue() { 38 | return super.getValue(); 39 | } 40 | 41 | @Override 42 | public String getPossibleValues() { 43 | return joiner.join(whitelist); 44 | } 45 | 46 | @Callable 47 | @Override 48 | public String toggle() { 49 | if (whitelist.isEmpty()) { 50 | return null; 51 | } 52 | 53 | int index = whitelist.indexOf(getValue()); 54 | 55 | if (index == -1) { 56 | return null; 57 | } 58 | 59 | String next = whitelist.get((index + 1) % whitelist.size()); 60 | setValue(next); 61 | return next; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/util/geometry/Rectangle.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.util.geometry; 2 | 3 | public class Rectangle { 4 | int x; 5 | int y; 6 | int width; 7 | int height; 8 | 9 | public Rectangle(int x, int y, int width, int height) { 10 | this.x = x; 11 | this.y = y; 12 | this.width = width; 13 | this.height = height; 14 | } 15 | 16 | public static Rectangle center(int wholeWidth, int wholeHeight, int width, int height) { 17 | return new Rectangle((wholeWidth - width) / 2, (wholeHeight - height) / 2, width, height); 18 | } 19 | 20 | public static Rectangle centerHorizontal(int wholeWidth, int y, int width, int height) { 21 | return new Rectangle((wholeWidth - width) / 2, y, width, height); 22 | } 23 | 24 | public int getMinX() { 25 | return x; 26 | } 27 | 28 | public int getMaxX() { 29 | return x + width; 30 | } 31 | 32 | public int getMinY() { 33 | return y; 34 | } 35 | 36 | public int getMaxY() { 37 | return y + height; 38 | } 39 | 40 | public int getWidth() { 41 | return width; 42 | } 43 | 44 | public int getHeight() { 45 | return height; 46 | } 47 | 48 | public boolean contains(int x, int y) { 49 | return x >= getMinX() && x <= getMaxX() && y >= getMinY() && y <= getMaxY(); 50 | } 51 | 52 | public boolean contains(double x, double y) { 53 | return x >= getMinX() && x <= getMaxX() && y >= getMinY() && y <= getMaxY(); 54 | } 55 | 56 | public boolean contains(Rectangle rectangle) { 57 | return rectangle.getMinX() >= getMinX() && rectangle.getMaxX() <= getMaxX() && rectangle.getMinY() >= getMinY() && rectangle.getMaxY() <= getMaxY(); 58 | } 59 | 60 | public boolean overlaps(Rectangle rectangle) { 61 | return ( getMaxX() > rectangle.getMinX() && getMinX() < rectangle.getMaxX() ) && ( getMaxY() > rectangle.getMinY() && getMinY() < rectangle.getMaxY() ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/config/ConfigHandler.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.config; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Loadable; 4 | import com.ddoerr.scriptit.api.hud.HudElementManager; 5 | import com.ddoerr.scriptit.api.scripts.ScriptContainerManager; 6 | import com.ddoerr.scriptit.api.util.Debouncer; 7 | import com.ddoerr.scriptit.callbacks.ConfigCallback; 8 | import com.ddoerr.scriptit.api.hud.HudElementContainer; 9 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 10 | 11 | import java.time.Duration; 12 | 13 | public class ConfigHandler implements ConfigCallback, Loadable { 14 | private Config config; 15 | private Debouncer debouncer = new Debouncer(Duration.ofMillis(500), this::save); 16 | 17 | private ScriptContainerManager scriptContainerManager; 18 | private HudElementManager hudElementManager; 19 | 20 | public ConfigHandler(Config config, ScriptContainerManager scriptContainerManager, HudElementManager hudElementManager) { 21 | this.config = config; 22 | this.scriptContainerManager = scriptContainerManager; 23 | this.hudElementManager = hudElementManager; 24 | } 25 | 26 | public void save() { 27 | ConfigContainer configContainer = new ConfigContainer(); 28 | 29 | configContainer.bindings = scriptContainerManager.getAll(); 30 | configContainer.elements = hudElementManager.getAll(); 31 | 32 | config.write(configContainer); 33 | } 34 | 35 | public void load() { 36 | config.ensureConfigExists(); 37 | ConfigContainer configContainer = config.read(); 38 | 39 | for (ScriptContainer binding : configContainer.bindings) { 40 | scriptContainerManager.add(binding); 41 | } 42 | 43 | for (HudElementContainer element : configContainer.elements) { 44 | hudElementManager.add(element); 45 | } 46 | 47 | ConfigCallback.EVENT.register(this); 48 | } 49 | 50 | @Override 51 | public void saveConfig(Class source) { 52 | debouncer.call(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/events/ChatOutgoingEvent.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.events; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.events.AbstractEvent; 6 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 7 | import com.ddoerr.scriptit.callbacks.OutgoingChatMessageCallback; 8 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 9 | import com.ddoerr.scriptit.triggers.TriggerMessageImpl; 10 | import net.minecraft.util.TypedActionResult; 11 | 12 | import java.time.Duration; 13 | 14 | public class ChatOutgoingEvent extends AbstractEvent implements OutgoingChatMessageCallback { 15 | public ChatOutgoingEvent() { 16 | OutgoingChatMessageCallback.EVENT.register(this); 17 | } 18 | 19 | public TypedActionResult onOutgoingChatMessage(String text) { 20 | MessageModel messageModel = new MessageModel(text); 21 | TriggerMessage message = new TriggerMessageImpl(messageModel, Duration.ofMillis(10)); 22 | dispatch(message); 23 | return messageModel.getActionResult(); 24 | } 25 | 26 | public static class MessageModel extends AnnotationBasedModel { 27 | private TypedActionResult actionResult; 28 | private String message; 29 | 30 | public MessageModel(String message) { 31 | actionResult = TypedActionResult.pass(message); 32 | this.message = message; 33 | } 34 | 35 | @Getter 36 | public String getMessage() { 37 | return message; 38 | } 39 | 40 | @Callable 41 | public void modify(String message) { 42 | actionResult = TypedActionResult.success(message); 43 | } 44 | 45 | @Callable 46 | public void filter() { 47 | actionResult = TypedActionResult.fail(null); 48 | } 49 | 50 | public TypedActionResult getActionResult() { 51 | return actionResult; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/scripts/ScriptBuilder.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.scripts; 2 | 3 | import com.ddoerr.scriptit.api.libraries.Model; 4 | import net.minecraft.util.Identifier; 5 | 6 | import java.io.File; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | public class ScriptBuilder implements Script { 11 | private Identifier language; 12 | private ScriptSource scriptSource; 13 | private Map libraries = new HashMap<>(); 14 | private String name = "main"; 15 | 16 | public ScriptBuilder() { 17 | 18 | } 19 | 20 | public ScriptBuilder(Script script) { 21 | language = script.getLanguage(); 22 | scriptSource = script.getScriptSource(); 23 | libraries = new HashMap<>(script.getLibraries()); 24 | name = script.getName(); 25 | } 26 | 27 | public ScriptBuilder language(String language) { 28 | this.language = new Identifier(language); 29 | return this; 30 | } 31 | 32 | public ScriptBuilder fromString(String content) { 33 | this.scriptSource = ScriptSource.From(content); 34 | return this; 35 | } 36 | 37 | public ScriptBuilder fromFile(String path) { 38 | this.scriptSource = ScriptSource.From(new File(path)); 39 | return this; 40 | } 41 | 42 | public ScriptBuilder withLibrary(String name, Model model) { 43 | if (model != null) { 44 | libraries.put(name, model); 45 | } 46 | return this; 47 | } 48 | 49 | public ScriptBuilder name(String name) { 50 | this.name = name; 51 | return this; 52 | } 53 | 54 | @Override 55 | public ScriptSource getScriptSource() { 56 | return scriptSource; 57 | } 58 | 59 | @Override 60 | public Map getLibraries() { 61 | return libraries; 62 | } 63 | 64 | @Override 65 | public String getName() { 66 | return name; 67 | } 68 | 69 | @Override 70 | public Identifier getLanguage() { 71 | return language; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/MixinClientPlayerNetworkHandler.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import com.ddoerr.scriptit.callbacks.IncomingChatMessageCallback; 4 | import com.ddoerr.scriptit.callbacks.GameJoinCallback; 5 | import net.minecraft.client.network.ClientPlayNetworkHandler; 6 | import net.minecraft.network.listener.ClientPlayPacketListener; 7 | import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; 8 | import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; 9 | import net.minecraft.text.Text; 10 | import net.minecraft.util.ActionResult; 11 | import net.minecraft.util.TypedActionResult; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Inject; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 16 | 17 | @Mixin(ClientPlayNetworkHandler.class) 18 | public abstract class MixinClientPlayerNetworkHandler implements ClientPlayPacketListener { 19 | 20 | @Inject( 21 | method = "onChatMessage", 22 | cancellable = true, 23 | at = @At( 24 | value = "INVOKE", 25 | shift = At.Shift.AFTER, 26 | target = "net/minecraft/network/NetworkThreadUtils.forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V")) 27 | private void onChatMessageMixin(ChatMessageS2CPacket packet, CallbackInfo info) { 28 | TypedActionResult result = IncomingChatMessageCallback.EVENT.invoker().onIncomingChatMessage(packet.getMessage()); 29 | 30 | if (result.getResult() == ActionResult.FAIL) { 31 | info.cancel(); 32 | return; 33 | } 34 | 35 | ((PacketTextAccessor)packet).setMessage(result.getValue()); 36 | } 37 | 38 | @Inject(method = "onGameJoin", at = @At("RETURN")) 39 | private void onGameJoinMixin(GameJoinS2CPacket packet, CallbackInfo info) { 40 | GameJoinCallback.EVENT.invoker().onGameJoin(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/config/ScriptContainerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.config; 2 | 3 | import com.ddoerr.scriptit.api.scripts.Script; 4 | import com.ddoerr.scriptit.api.scripts.ScriptBuilder; 5 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 6 | import com.ddoerr.scriptit.scripts.ScriptContainerImpl; 7 | import com.ddoerr.scriptit.api.triggers.Trigger; 8 | import com.google.gson.*; 9 | 10 | import java.lang.reflect.Type; 11 | 12 | public class ScriptContainerAdapter implements JsonSerializer, JsonDeserializer { 13 | @Override 14 | public JsonElement serialize(ScriptContainer scriptContainer, Type typeOfSrc, JsonSerializationContext context) { 15 | JsonObject obj = new JsonObject(); 16 | Script script = scriptContainer.getScript(); 17 | obj.addProperty("name", script.getName()); 18 | obj.addProperty("language", script.getLanguage().toString()); 19 | obj.addProperty("content", script.getScriptSource().getContent()); 20 | obj.add("trigger", context.serialize(scriptContainer.getTrigger(), Trigger.class)); 21 | 22 | return obj; 23 | } 24 | 25 | @Override 26 | public ScriptContainer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { 27 | JsonObject jsonObject = json.getAsJsonObject(); 28 | 29 | String name = jsonObject.getAsJsonPrimitive("name").getAsString(); 30 | String content = jsonObject.getAsJsonPrimitive("content").getAsString(); 31 | Trigger trigger = context.deserialize(jsonObject.get("trigger"), Trigger.class); 32 | String language = jsonObject.getAsJsonPrimitive("language").getAsString(); 33 | 34 | Script script = new ScriptBuilder() 35 | .name(name) 36 | .language(language) 37 | .fromString(content); 38 | 39 | ScriptContainerImpl scriptContainer = new ScriptContainerImpl(); 40 | scriptContainer.setTrigger(trigger); 41 | scriptContainer.setScript(script); 42 | return scriptContainer; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/ChatLibrary.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.languages.ContainedValue; 6 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 7 | import com.ddoerr.scriptit.mixin.MessagesAccessor; 8 | import net.minecraft.client.MinecraftClient; 9 | import net.minecraft.text.BaseText; 10 | import net.minecraft.text.LiteralText; 11 | import net.minecraft.text.Text; 12 | 13 | import java.util.List; 14 | import java.util.stream.Collectors; 15 | 16 | public class ChatLibrary extends AnnotationBasedModel { 17 | private MinecraftClient minecraft; 18 | 19 | public ChatLibrary(MinecraftClient minecraft) { 20 | this.minecraft = minecraft; 21 | } 22 | 23 | @Callable 24 | public void send(String message) { 25 | if (minecraft.player != null) { 26 | minecraft.player.sendChatMessage(message); 27 | } 28 | } 29 | 30 | @Callable 31 | public void log(ContainedValue value) { 32 | String message = value.format(); 33 | Text text; 34 | try { 35 | text = BaseText.Serializer.fromJson(message); 36 | } 37 | catch (Exception e) { 38 | text = new LiteralText(message); 39 | } 40 | 41 | if (minecraft.player != null) { 42 | minecraft.player.addChatMessage(text, false); 43 | } 44 | } 45 | 46 | @Callable 47 | public void clear() { 48 | minecraft.inGameHud.getChatHud().clear(false); 49 | } 50 | 51 | @Getter 52 | public List getHistory() { 53 | return minecraft.inGameHud.getChatHud().getMessageHistory(); 54 | } 55 | 56 | @Getter 57 | public List getMessages() { 58 | return ((MessagesAccessor)minecraft.inGameHud.getChatHud()) 59 | .getMessages() 60 | .stream() 61 | .map(line -> line.getText().asFormattedString()) 62 | .collect(Collectors.toList()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/BooleanSettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.annotations.Setter; 6 | import com.ddoerr.scriptit.mixin.OptionKeyAccessor; 7 | import net.minecraft.client.MinecraftClient; 8 | import net.minecraft.client.options.BooleanOption; 9 | 10 | import java.util.function.Consumer; 11 | import java.util.function.Supplier; 12 | 13 | public class BooleanSettingModel extends AbstractSettingModel implements ToggleableSettingModel { 14 | public BooleanSettingModel(String name, Supplier getter, Consumer setter) { 15 | super(name, getter, setter); 16 | } 17 | 18 | public static BooleanSettingModel fromOption(BooleanOption option) { 19 | MinecraftClient minecraft = MinecraftClient.getInstance(); 20 | 21 | return new BooleanSettingModel( 22 | ((OptionKeyAccessor)option).getKey().substring(8), 23 | () -> option.get(minecraft.options), 24 | (value) -> option.set(minecraft.options, value.toString())); 25 | } 26 | 27 | public static BooleanSettingModel fromOption(BooleanOption option, String name) { 28 | MinecraftClient minecraft = MinecraftClient.getInstance(); 29 | 30 | return new BooleanSettingModel( 31 | name, 32 | () -> option.get(minecraft.options), 33 | (value) -> option.set(minecraft.options, value.toString())); 34 | } 35 | 36 | @Setter 37 | @Override 38 | public void setValue(Boolean value) { 39 | super.setValue(value); 40 | } 41 | 42 | @Getter 43 | @Override 44 | public Boolean getValue() { 45 | return super.getValue(); 46 | } 47 | 48 | @Override 49 | public String getPossibleValues() { 50 | return "true, false"; 51 | } 52 | 53 | 54 | @Callable 55 | @Override 56 | public Boolean toggle() { 57 | boolean value = getValue(); 58 | setValue(!value); 59 | return !value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/resources/assets/scriptit/lang/en_us.json: -------------------------------------------------------------------------------- 1 | { 2 | "key.scripitit.open": "Open ScriptIt Settings", 3 | 4 | "scriptit:generic.save": "Save", 5 | "scriptit:generic.cancel": "Cancel", 6 | 7 | "scriptit:scripts.edit": "Edit Script", 8 | "scriptit:scripts.remove": "Remove Script", 9 | "scriptit:scripts.add": "Add new Script", 10 | 11 | "scriptit:scripts.exception": "An error occurred while running script %s. Script will be disabled until it is saved again.", 12 | 13 | "scriptit:trigger.scriptit:keybinding": "Key Binding", 14 | "scriptit:trigger.scriptit:keybinding.icon": "tripwire_hook", 15 | 16 | "scriptit:trigger.scriptit:event": "Event", 17 | "scriptit:trigger.scriptit:event.icon": "firework_rocket", 18 | "scriptit:scripts.triggers.event.select": "Select an Event", 19 | 20 | "scriptit:trigger.scriptit:duration": "Duration", 21 | "scriptit:trigger.scriptit:duration.icon": "clock", 22 | "scriptit:scripts.triggers.duration.select": "Select a Time Unit", 23 | "scriptit:scripts.triggers.duration.values.millis": "Milliseconds", 24 | "scriptit:scripts.triggers.duration.values.seconds": "Seconds", 25 | "scriptit:scripts.triggers.duration.values.minutes": "Minutes", 26 | "scriptit:scripts.triggers.duration.values.hours": "Hours", 27 | 28 | "scriptit:elements.open": "Open Hud Designer", 29 | "scriptit:elements.add": "Add a Hud Element", 30 | "scriptit:elements.edit.script": "Edit Script", 31 | 32 | "scriptit:hud_element.scriptit:text": "Any Text", 33 | "scriptit:hud_element.scriptit:item": "Display any Item", 34 | 35 | "scriptit:keybinding.default": "§f%s", 36 | "scriptit:keybinding.conflict": "§c%s", 37 | "scriptit:keybinding.active": "§f> §e%s §f<", 38 | "scriptit:keybinding.unknown": "§4???", 39 | 40 | "scriptit:tooltip.button": "Button %s", 41 | "scriptit:tooltip.slot": "Slot %s", 42 | 43 | "scriptit:event.scriptit:chat/incoming": "Incoming Chat", 44 | "scriptit:event.scriptit:chat/outgoing": "Outgoing Chat", 45 | "scriptit:event.scriptit:game/connect": "Connect", 46 | "scriptit:event.scriptit:sound": "Sound", 47 | 48 | "scriptit:language.scriptit:text": "Simple text", 49 | "scriptit:language.scriptit:lua": "Lua" 50 | } -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/mixin/MixinScreen.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.mixin; 2 | 3 | import com.ddoerr.scriptit.callbacks.OutgoingChatMessageCallback; 4 | import com.ddoerr.scriptit.ducks.TooltipRenderedDuck; 5 | import net.minecraft.client.gui.screen.Screen; 6 | import net.minecraft.util.ActionResult; 7 | import net.minecraft.util.TypedActionResult; 8 | import org.spongepowered.asm.mixin.Mixin; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.ModifyVariable; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | import java.util.List; 15 | 16 | @Mixin(Screen.class) 17 | public abstract class MixinScreen implements TooltipRenderedDuck { 18 | public boolean tooltipRendered = false; 19 | 20 | @ModifyVariable(method = "sendMessage(Ljava/lang/String;Z)V", at = @At(value = "LOAD", ordinal = 1)) 21 | private String modifyMessage(String message) { 22 | TypedActionResult result = OutgoingChatMessageCallback.EVENT.invoker().onOutgoingChatMessage(message); 23 | 24 | if (result.getResult() == ActionResult.FAIL) { 25 | return null; 26 | } 27 | 28 | return result.getValue(); 29 | } 30 | 31 | @Inject(method = "sendMessage(Ljava/lang/String;Z)V", at = @At(value = "INVOKE", target = "net/minecraft/client/network/ClientPlayerEntity.sendChatMessage(Ljava/lang/String;)V"), cancellable = true) 32 | private void onSendMessage(String message, boolean boolean_1, CallbackInfo info) { 33 | if (message == null) { 34 | info.cancel(); 35 | } 36 | } 37 | 38 | @Inject(method = "renderTooltip(Ljava/util/List;II)V", at = @At("HEAD")) 39 | private void onRenderTooltip(List text, int x, int y, CallbackInfo info) { 40 | tooltipRendered = true; 41 | } 42 | 43 | @Inject(method = "render", at = @At("RETURN")) 44 | private void onRender(int mouseX, int mouseY, float delta, CallbackInfo info) { 45 | tooltipRendered = false; 46 | } 47 | 48 | @Override 49 | public boolean wasTooltipRendered() { 50 | return tooltipRendered; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/config/TriggerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.config; 2 | 3 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 4 | import com.ddoerr.scriptit.api.triggers.Trigger; 5 | import com.ddoerr.scriptit.api.triggers.TriggerFactory; 6 | import com.ddoerr.scriptit.fields.Field; 7 | import com.google.gson.*; 8 | import net.minecraft.util.Identifier; 9 | 10 | import java.lang.reflect.Type; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class TriggerAdapter implements JsonDeserializer, JsonSerializer { 15 | private ScriptItRegistry registry; 16 | 17 | public TriggerAdapter(ScriptItRegistry registry) { 18 | this.registry = registry; 19 | } 20 | 21 | @Override 22 | public Trigger deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { 23 | JsonObject jsonObject = json.getAsJsonObject(); 24 | 25 | String type = jsonObject.getAsJsonPrimitive("type").getAsString(); 26 | Identifier identifier = new Identifier(type); 27 | 28 | Map data = new HashMap<>(); 29 | for (Map.Entry entry : jsonObject.getAsJsonObject("data").entrySet()) { 30 | String value = entry.getValue().getAsString(); 31 | data.put(entry.getKey(), value); 32 | } 33 | 34 | TriggerFactory triggerFactory = registry.triggers.get(identifier); 35 | Trigger trigger = triggerFactory.createTrigger(data); 36 | return trigger; 37 | } 38 | 39 | @Override 40 | public JsonElement serialize(Trigger src, Type typeOfSrc, JsonSerializationContext context) { 41 | JsonObject obj = new JsonObject(); 42 | 43 | Map> fieldValues = src.getFields(); 44 | Map options = new HashMap<>(); 45 | 46 | for (Map.Entry> entry : fieldValues.entrySet()) { 47 | options.put(entry.getKey(), entry.getValue().serialize()); 48 | } 49 | 50 | obj.addProperty("type", src.getIdentifier().toString()); 51 | obj.add("data", context.serialize(options)); 52 | 53 | return obj; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/IntegerSettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.annotations.Setter; 6 | import com.ddoerr.scriptit.mixin.OptionKeyAccessor; 7 | import com.ddoerr.scriptit.mixin.StepAccessor; 8 | import net.minecraft.client.MinecraftClient; 9 | import net.minecraft.client.options.DoubleOption; 10 | import net.minecraft.util.math.MathHelper; 11 | 12 | import java.util.function.Consumer; 13 | import java.util.function.Supplier; 14 | 15 | public class IntegerSettingModel extends AbstractNumberSettingModel { 16 | public IntegerSettingModel(String name, Supplier getter, Consumer setter, int minimum, int maximum) { 17 | super(name, getter, setter, minimum, maximum, 1); 18 | } 19 | 20 | public IntegerSettingModel(String name, Supplier getter, Consumer setter, int minimum, int maximum, int step) { 21 | super(name, getter, setter, minimum, maximum, step); 22 | } 23 | 24 | public static IntegerSettingModel fromOption(DoubleOption option) { 25 | MinecraftClient minecraft = MinecraftClient.getInstance(); 26 | 27 | return new IntegerSettingModel( 28 | ((OptionKeyAccessor)option).getKey().substring(8), 29 | () -> (int)option.get(minecraft.options), 30 | (value) -> option.set(minecraft.options, (double)value), 31 | (int)option.getMin(), 32 | (int)option.getMax(), 33 | (int)((StepAccessor)option).getStep()); 34 | } 35 | 36 | @Setter 37 | @Override 38 | public void setValue(Integer value) { 39 | super.setValue(MathHelper.clamp(value, minimum, maximum)); 40 | } 41 | 42 | @Getter 43 | @Override 44 | public Integer getValue() { 45 | return super.getValue(); 46 | } 47 | 48 | @Callable 49 | @Override 50 | public Integer toggle() { 51 | int value = getValue(); 52 | int next = value + step; 53 | 54 | if (next > maximum) { 55 | next = minimum; 56 | } 57 | 58 | setValue(next); 59 | return next; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/triggers/KeyBindingTrigger.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.triggers; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.triggers.KeyBindingManager; 5 | import com.ddoerr.scriptit.api.triggers.Trigger; 6 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 7 | import com.ddoerr.scriptit.api.util.KeyBindingHelper; 8 | import com.ddoerr.scriptit.fields.Field; 9 | import com.ddoerr.scriptit.fields.KeyBindingField; 10 | import com.ddoerr.scriptit.fields.StringField; 11 | import com.ddoerr.scriptit.triggers.AbstractTrigger; 12 | import net.minecraft.client.util.InputUtil; 13 | import net.minecraft.text.LiteralText; 14 | import net.minecraft.util.Identifier; 15 | import org.apache.commons.lang3.StringUtils; 16 | 17 | import java.util.Collections; 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | import java.util.function.Consumer; 21 | 22 | public class KeyBindingTrigger extends AbstractTrigger { 23 | public static final Identifier IDENTIFIER = new Identifier(ScriptItMod.MOD_NAME, "keybinding"); 24 | public static final String KEY_FIELD = "key"; 25 | 26 | private KeyBindingManager keyBindingManager; 27 | 28 | private KeyBindingField keyField; 29 | 30 | public KeyBindingTrigger(KeyBindingManager keyBindingManager) { 31 | this.keyBindingManager = keyBindingManager; 32 | 33 | keyField = new KeyBindingField(); 34 | keyField.setTitle(new LiteralText("Key")); 35 | keyField.setDescription(new LiteralText("Key used to trigger")); 36 | fields.put(KEY_FIELD, keyField); 37 | } 38 | 39 | @Override 40 | public void start() { 41 | String keyName = keyField.serialize(); 42 | if (keyName != null) { 43 | keyBindingManager.registerListener(keyName, callback); 44 | } 45 | } 46 | 47 | @Override 48 | public void stop() { 49 | String keyName = keyField.serialize(); 50 | if (keyName != null) { 51 | keyBindingManager.removeListener(keyName, callback); 52 | } 53 | } 54 | 55 | @Override 56 | public Identifier getIdentifier() { 57 | return IDENTIFIER; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "on key " + KeyBindingHelper.getKeyCodeName(keyField.getValue()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/languages/ContainedValue.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.languages; 2 | 3 | import com.ddoerr.scriptit.api.exceptions.ConversionException; 4 | 5 | import java.lang.reflect.ParameterizedType; 6 | import java.lang.reflect.Type; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public interface ContainedValue { 11 | default Object to(Type type) throws ConversionException { 12 | if (String.class.equals(type)) { 13 | return toStr(); 14 | } else if (Boolean.class.equals(type) || boolean.class.equals(type)) { 15 | return toBoolean(); 16 | } else if (Float.class.equals(type) || float.class.equals(type)) { 17 | return toFloat(); 18 | } else if (Double.class.equals(type) || double.class.equals(type)) { 19 | return toDouble(); 20 | } else if (Integer.class.equals(type) || int.class.equals(type)) { 21 | return toInteger(); 22 | } else if (type instanceof Class && Enum.class.isAssignableFrom((Class)type)) { 23 | return toEnum((Class)type); 24 | } else if (type instanceof ParameterizedType && ((ParameterizedType)type).getRawType().equals(List.class)) { 25 | return toList(((ParameterizedType)type).getActualTypeArguments()[0]); 26 | } else if (type instanceof ParameterizedType && ((ParameterizedType)type).getRawType().equals(Map.class)) { 27 | Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments(); 28 | return toMap(typeArguments[0], typeArguments[1]); 29 | } else if (ContainedValue.class.equals(type)) { 30 | return this; 31 | } 32 | 33 | throw new ConversionException("Unknown type " + type.getTypeName()); 34 | } 35 | 36 | Type guessType(); 37 | 38 | String format(); 39 | 40 | String toStr() throws ConversionException; 41 | boolean toBoolean() throws ConversionException; 42 | float toFloat() throws ConversionException; 43 | double toDouble() throws ConversionException; 44 | int toInteger() throws ConversionException; 45 | > T toEnum(Class enumType) throws ConversionException; 46 | Map toMap(Type keyType, Type valueType) throws ConversionException; 47 | List toList(Type entryType) throws ConversionException; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/clickables/buttons/DefaultButtonProvider.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries.clickables.buttons; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.ducks.TooltipRenderedDuck; 5 | import net.minecraft.client.MinecraftClient; 6 | import net.minecraft.client.gui.screen.Screen; 7 | import net.minecraft.client.gui.widget.AbstractPressableButtonWidget; 8 | import net.minecraft.client.resource.language.I18n; 9 | import net.minecraft.util.Identifier; 10 | 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | public class DefaultButtonProvider implements ButtonProvider { 15 | @Override 16 | public int getAmount(Screen screen) { 17 | return getButtons(screen).size(); 18 | } 19 | 20 | @Override 21 | public void click(Screen screen, int index) { 22 | List buttons = getButtons(screen); 23 | 24 | if (index < 0 || index >= buttons.size()) { 25 | return; 26 | } 27 | 28 | MinecraftClient.getInstance().submit(() -> { 29 | buttons.get(index).onPress(); 30 | }); 31 | } 32 | 33 | @Override 34 | public boolean matches(Screen screen) { 35 | return screen != null; 36 | } 37 | 38 | @Override 39 | public void renderTooltip(Screen screen, int mouseX, int mouseY) { 40 | List buttons = getButtons(screen); 41 | 42 | for (int i = 0; i < buttons.size(); i++) { 43 | AbstractPressableButtonWidget button = buttons.get(i); 44 | if (button.visible && button.isHovered()) { 45 | 46 | if (((TooltipRenderedDuck) screen).wasTooltipRendered()) { 47 | mouseY -= 18; 48 | } 49 | 50 | screen.renderTooltip(I18n.translate(new Identifier(ScriptItMod.MOD_NAME, "tooltip.button").toString(), i), mouseX, mouseY); 51 | } 52 | } 53 | } 54 | 55 | private List getButtons(Screen screen) { 56 | return screen.children() 57 | .stream() 58 | .filter(AbstractPressableButtonWidget.class::isInstance) 59 | .map(AbstractPressableButtonWidget.class::cast) 60 | .collect(Collectors.toList()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/triggers/KeyBindingManagerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.triggers; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.triggers.KeyBindingManager; 5 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 6 | import com.ddoerr.scriptit.api.util.KeyBindingHelper; 7 | import net.minecraft.client.options.KeyBinding; 8 | import net.minecraft.client.util.InputUtil; 9 | import net.minecraft.util.Identifier; 10 | import net.minecraft.util.Pair; 11 | 12 | import java.util.*; 13 | import java.util.function.Consumer; 14 | 15 | public class KeyBindingManagerImpl implements KeyBindingManager { 16 | protected Map>>> listeners = new HashMap<>(); 17 | 18 | @Override 19 | public void registerListener(String keyName, Consumer messageConsumer) { 20 | Pair>> pair = listeners.get(keyName); 21 | 22 | if (pair == null) { 23 | Identifier identifier = new Identifier(ScriptItMod.MOD_NAME, UUID.randomUUID().toString()); 24 | InputUtil.KeyCode keyCode = InputUtil.fromName(keyName); 25 | 26 | KeyBinding keyBinding = KeyBindingHelper.create(identifier, keyCode); 27 | 28 | pair = new Pair<>(keyBinding, new ArrayList<>()); 29 | listeners.put(keyName, pair); 30 | } 31 | 32 | pair.getRight().add(messageConsumer); 33 | } 34 | 35 | @Override 36 | public void removeListener(String keyName, Consumer messageConsumer) { 37 | Pair>> pair = listeners.get(keyName); 38 | if (pair != null) { 39 | pair.getRight().remove(messageConsumer); 40 | 41 | if (pair.getRight().isEmpty()) { 42 | KeyBindingHelper.remove(pair.getLeft()); 43 | listeners.remove(keyName); 44 | } 45 | } 46 | } 47 | 48 | @Override 49 | public void tick() { 50 | for (Pair>> pair : listeners.values()) { 51 | if (pair.getLeft().wasPressed()) { 52 | for (Consumer consumer : pair.getRight()) { 53 | consumer.accept(new TriggerMessageImpl()); 54 | } 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/inventory/CreativeInventoryModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.inventory; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.ducks.TooltipRenderedDuck; 5 | import com.ddoerr.scriptit.models.ItemModel; 6 | import com.ddoerr.scriptit.mixin.ContainerAccessor; 7 | import com.ddoerr.scriptit.mixin.CreativeInventoryAccessor; 8 | import net.minecraft.client.gui.screen.Screen; 9 | import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; 10 | import net.minecraft.client.resource.language.I18n; 11 | import net.minecraft.container.Slot; 12 | import net.minecraft.entity.player.PlayerInventory; 13 | import net.minecraft.item.ItemGroup; 14 | import net.minecraft.util.Identifier; 15 | 16 | import java.util.List; 17 | 18 | public class CreativeInventoryModel extends ContainerInventoryModel { 19 | public CreativeInventoryModel(Screen screen, PlayerInventory inventory) { 20 | super(screen, inventory); 21 | } 22 | 23 | private void accessSurvivalInventory() { 24 | ((CreativeInventoryAccessor)screen).invokeSetSelectedTab(ItemGroup.INVENTORY); 25 | } 26 | 27 | @Override 28 | public void renderTooltip(int mouseX, int mouseY) { 29 | Slot focusedSlot = ((ContainerAccessor)screen).getFocusedSlot(); 30 | 31 | if (focusedSlot == null) { 32 | return; 33 | } 34 | 35 | int slotId = focusedSlot.id; 36 | if (((CreativeInventoryScreen)screen).getSelectedTab() == ItemGroup.INVENTORY.getIndex()) { 37 | slotId = ((CreativeInventoryScreen)screen).getContainer().slots.indexOf(focusedSlot); 38 | } 39 | 40 | if (((TooltipRenderedDuck) screen).wasTooltipRendered()) { 41 | mouseY -= 18; 42 | } 43 | 44 | screen.renderTooltip(I18n.translate(new Identifier(ScriptItMod.MOD_NAME, "tooltip.slot").toString(), slotId), mouseX, mouseY); 45 | } 46 | 47 | @Override 48 | public void click(int slot, ClickType clickType) { 49 | super.click(slot, clickType); 50 | } 51 | 52 | @Override 53 | public List getSlots() { 54 | return super.getSlots(); 55 | } 56 | 57 | @Override 58 | public ItemModel slot(int slot) { 59 | return super.slot(slot); 60 | } 61 | 62 | @Override 63 | public int getSlotCount() { 64 | return super.getSlotCount(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/screens/widgets/PanelWidget.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.screens.widgets; 2 | 3 | import spinnery.client.BaseRenderer; 4 | import spinnery.widget.WAbstractWidget; 5 | import spinnery.widget.api.Color; 6 | import spinnery.widget.api.WDelegatedEventListener; 7 | import spinnery.widget.api.WEventListener; 8 | import spinnery.widget.api.WModifiableCollection; 9 | 10 | import java.util.*; 11 | 12 | public class PanelWidget extends WAbstractWidget implements WModifiableCollection, WDelegatedEventListener { 13 | Set widgets = new HashSet<>(); 14 | Color color; 15 | 16 | public PanelWidget setColor(Color color) { 17 | this.color = color; 18 | return this; 19 | } 20 | 21 | @Override 22 | public void draw() { 23 | super.draw(); 24 | 25 | if (isHidden()) 26 | return; 27 | 28 | if (color != null && size != null) { 29 | BaseRenderer.drawRectangle(getX(), getY(), 0, getWidth(), getHeight(), color); 30 | } 31 | 32 | for (WAbstractWidget widget : getWidgets()) { 33 | widget.draw(); 34 | } 35 | } 36 | 37 | @Override 38 | public void add(WAbstractWidget... wWidgets) { 39 | widgets.addAll(Arrays.asList(wWidgets)); 40 | } 41 | 42 | @Override 43 | public void remove(WAbstractWidget... wWidgets) { 44 | widgets.removeAll(Arrays.asList(wWidgets)); 45 | } 46 | 47 | @Override 48 | public Set getWidgets() { 49 | return Collections.unmodifiableSet(widgets); 50 | } 51 | 52 | @Override 53 | public boolean contains(WAbstractWidget... wWidgets) { 54 | return widgets.containsAll(Arrays.asList(wWidgets)); 55 | } 56 | 57 | @Override 58 | public boolean updateFocus(int mouseX, int mouseY) { 59 | setFocus(isWithinBounds(mouseX, mouseY) && getWidgets().stream().noneMatch((WAbstractWidget::isFocused))); 60 | return isFocused(); 61 | } 62 | 63 | @Override 64 | public Collection getEventDelegates() { 65 | return widgets; 66 | } 67 | 68 | @Override 69 | public W setHidden(boolean isHidden) { 70 | for (WAbstractWidget widget : widgets) { 71 | widget.setHidden(isHidden); 72 | } 73 | 74 | return super.setHidden(isHidden); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/triggers/EventTrigger.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.triggers; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.events.Event; 5 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 6 | import com.ddoerr.scriptit.api.triggers.Trigger; 7 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 8 | import com.ddoerr.scriptit.fields.Field; 9 | import com.ddoerr.scriptit.fields.SelectionField; 10 | import com.ddoerr.scriptit.fields.StringField; 11 | import com.ddoerr.scriptit.triggers.AbstractTrigger; 12 | import net.minecraft.text.LiteralText; 13 | import net.minecraft.util.Identifier; 14 | 15 | import java.util.*; 16 | import java.util.function.Consumer; 17 | import java.util.stream.Collectors; 18 | 19 | public class EventTrigger extends AbstractTrigger { 20 | public static final Identifier IDENTIFIER = new Identifier(ScriptItMod.MOD_NAME, "event"); 21 | public static final String EVENT_FIELD = "event"; 22 | 23 | private ScriptItRegistry registry; 24 | 25 | private SelectionField eventField; 26 | 27 | public EventTrigger(ScriptItRegistry registry) { 28 | this.registry = registry; 29 | 30 | eventField = new SelectionField(); 31 | eventField.setTitle(new LiteralText("Event ID")); 32 | eventField.setDescription(new LiteralText("Event which should trigger this script")); 33 | eventField.setTranslationPrefix("event"); 34 | 35 | List eventIds = registry.events.getIds().stream() 36 | .map(Identifier::toString) 37 | .collect(Collectors.toList()); 38 | 39 | eventField.setValues(eventIds); 40 | fields.put(EVENT_FIELD, eventField); 41 | } 42 | 43 | @Override 44 | public void start() { 45 | Event event = registry.events.get(new Identifier(eventField.getValue())); 46 | if (event != null) { 47 | event.registerListener(callback); 48 | } 49 | } 50 | 51 | @Override 52 | public void stop() { 53 | Event event = registry.events.get(new Identifier(eventField.getValue())); 54 | if (event != null) { 55 | event.removeListener(callback); 56 | } 57 | } 58 | 59 | @Override 60 | public Identifier getIdentifier() { 61 | return IDENTIFIER; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "on event " + eventField.getValue(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/inventory/DefaultInventoryModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.inventory; 2 | 3 | import com.ddoerr.scriptit.models.ItemModel; 4 | import net.minecraft.client.MinecraftClient; 5 | import net.minecraft.client.gui.screen.Screen; 6 | import net.minecraft.entity.player.PlayerInventory; 7 | 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | import java.util.stream.IntStream; 11 | 12 | public class DefaultInventoryModel extends InventoryModel { 13 | PlayerInventory playerInventory; 14 | MinecraftClient minecraft; 15 | 16 | public DefaultInventoryModel(Screen screen, PlayerInventory playerInventory) { 17 | this.playerInventory = playerInventory; 18 | minecraft = MinecraftClient.getInstance(); 19 | } 20 | 21 | @Override 22 | public void renderTooltip(int mouseX, int mouseY) { 23 | 24 | } 25 | 26 | @Override 27 | public List getSlots() { 28 | return IntStream.range(0, PlayerInventory.getHotbarSize()) 29 | .mapToObj(i -> playerInventory.getInvStack(i)) 30 | .map(ItemModel::From) 31 | .collect(Collectors.toList()); 32 | } 33 | 34 | @Override 35 | public ItemModel slot(int slot) { 36 | return ItemModel.From(playerInventory.getInvStack(slot)); 37 | } 38 | 39 | @Override 40 | public int getSlotCount() { 41 | return PlayerInventory.getHotbarSize(); 42 | } 43 | 44 | @Override 45 | public ItemModel getActiveStack() { 46 | return ItemModel.From(playerInventory.getMainHandStack()); 47 | } 48 | 49 | @Override 50 | public void click(int slot, int button) { 51 | if (PlayerInventory.isValidHotbarIndex(slot)) { 52 | playerInventory.selectedSlot = slot; 53 | } 54 | } 55 | 56 | @Override 57 | public void drop(int button) { 58 | if (minecraft.player != null) { 59 | minecraft.player.dropSelectedItem(button == ClickType.WholeStack.button); 60 | } 61 | } 62 | 63 | @Override 64 | public void drop(int slot, int button) { 65 | click(slot); 66 | drop(button); 67 | } 68 | 69 | @Override 70 | public void move(int slot) { 71 | 72 | } 73 | 74 | @Override 75 | public void clone(int slot) { 76 | 77 | } 78 | 79 | @Override 80 | public void swap(int slot, int button) { 81 | 82 | } 83 | 84 | @Override 85 | public void distribute(List slots, int button) { 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/events/ChatIncomingEvent.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.events; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.events.AbstractEvent; 6 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 7 | import com.ddoerr.scriptit.callbacks.IncomingChatMessageCallback; 8 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 9 | import com.ddoerr.scriptit.triggers.TriggerMessageImpl; 10 | import net.minecraft.text.BaseText; 11 | import net.minecraft.text.LiteralText; 12 | import net.minecraft.text.Text; 13 | import net.minecraft.util.TypedActionResult; 14 | 15 | import java.time.Duration; 16 | 17 | public class ChatIncomingEvent extends AbstractEvent implements IncomingChatMessageCallback { 18 | public ChatIncomingEvent() { 19 | IncomingChatMessageCallback.EVENT.register(this); 20 | } 21 | 22 | public TypedActionResult onIncomingChatMessage(Text text) { 23 | MessageModel messageModel = new MessageModel(text); 24 | TriggerMessage message = new TriggerMessageImpl(messageModel, Duration.ofMillis(20)); 25 | dispatch(message); 26 | return messageModel.getActionResult(); 27 | } 28 | 29 | public static class MessageModel extends AnnotationBasedModel { 30 | private TypedActionResult actionResult; 31 | private Text text; 32 | 33 | public MessageModel(Text text) { 34 | actionResult = TypedActionResult.pass(text); 35 | this.text = text; 36 | } 37 | 38 | @Getter 39 | public String getJson() { 40 | return BaseText.Serializer.toJson(text); 41 | } 42 | 43 | @Getter 44 | public String getMessage() { 45 | return text.asFormattedString(); 46 | } 47 | 48 | @Callable 49 | public void modify(String message) { 50 | Text newText; 51 | try { 52 | newText = BaseText.Serializer.fromJson(message); 53 | } catch (Exception e) { 54 | newText = new LiteralText(message); 55 | } 56 | 57 | actionResult = TypedActionResult.success(newText); 58 | } 59 | 60 | @Callable 61 | public void filter() { 62 | actionResult = TypedActionResult.fail(null); 63 | } 64 | 65 | public TypedActionResult getActionResult() { 66 | return actionResult; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/text/TextContainedValue.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.text; 2 | 3 | import com.ddoerr.scriptit.api.exceptions.ConversionException; 4 | import com.ddoerr.scriptit.api.languages.ContainedValue; 5 | 6 | import java.lang.reflect.Type; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class TextContainedValue implements ContainedValue { 11 | private String value; 12 | 13 | public TextContainedValue(String value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public Type guessType() { 19 | return String.class; 20 | } 21 | 22 | @Override 23 | public String format() { 24 | return value; 25 | } 26 | 27 | @Override 28 | public String toStr() throws ConversionException { 29 | return value; 30 | } 31 | 32 | @Override 33 | public boolean toBoolean() throws ConversionException { 34 | return Boolean.parseBoolean(value); 35 | } 36 | 37 | @Override 38 | public float toFloat() throws ConversionException { 39 | try { 40 | return Float.parseFloat(value); 41 | } catch (Exception e) { 42 | throw new ConversionException("Cannot convert to Float"); 43 | } 44 | } 45 | 46 | @Override 47 | public double toDouble() throws ConversionException { 48 | try { 49 | return Double.parseDouble(value); 50 | } catch (Exception e) { 51 | throw new ConversionException("Cannot convert to Double"); 52 | } 53 | } 54 | 55 | @Override 56 | public int toInteger() throws ConversionException { 57 | try { 58 | return Integer.parseInt(value); 59 | } catch (Exception e) { 60 | throw new ConversionException("Cannot convert to Integer"); 61 | } 62 | } 63 | 64 | @Override 65 | public > T toEnum(Class enumType) throws ConversionException { 66 | try { 67 | return Enum.valueOf(enumType, value); 68 | } catch (Exception e) { 69 | throw new ConversionException("Cannot convert to Enum"); 70 | } 71 | } 72 | 73 | @Override 74 | public Map toMap(Type keyType, Type valueType) throws ConversionException { 75 | throw new ConversionException("Cannot convert to Map"); 76 | } 77 | 78 | @Override 79 | public List toList(Type entryType) throws ConversionException { 80 | throw new ConversionException("Cannot convert to List"); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/DoubleSettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.annotations.Getter; 5 | import com.ddoerr.scriptit.api.annotations.Setter; 6 | import com.ddoerr.scriptit.mixin.OptionKeyAccessor; 7 | import com.ddoerr.scriptit.mixin.StepAccessor; 8 | import net.minecraft.client.MinecraftClient; 9 | import net.minecraft.client.options.DoubleOption; 10 | import net.minecraft.util.math.MathHelper; 11 | 12 | import java.util.function.Consumer; 13 | import java.util.function.Supplier; 14 | 15 | public class DoubleSettingModel extends AbstractNumberSettingModel { 16 | public DoubleSettingModel(String name, Supplier getter, Consumer setter, double minimum, double maximum, double step) { 17 | super(name, getter, setter, minimum, maximum, step); 18 | } 19 | 20 | public static DoubleSettingModel fromOption(DoubleOption option) { 21 | MinecraftClient minecraft = MinecraftClient.getInstance(); 22 | 23 | return new DoubleSettingModel( 24 | ((OptionKeyAccessor)option).getKey().substring(8), 25 | () -> option.get(minecraft.options), 26 | (value) -> option.set(minecraft.options, value), 27 | option.getMin(), 28 | option.getMax(), 29 | ((StepAccessor)option).getStep()); 30 | } 31 | 32 | public static DoubleSettingModel fromOption(DoubleOption option, String name) { 33 | MinecraftClient minecraft = MinecraftClient.getInstance(); 34 | 35 | return new DoubleSettingModel( 36 | name, 37 | () -> option.get(minecraft.options), 38 | (value) -> option.set(minecraft.options, value), 39 | option.getMin(), 40 | option.getMax(), 41 | ((StepAccessor)option).getStep()); 42 | } 43 | 44 | @Setter 45 | @Override 46 | public void setValue(Double value) { 47 | super.setValue(MathHelper.clamp(value, minimum, maximum)); 48 | } 49 | 50 | @Getter 51 | @Override 52 | public Double getValue() { 53 | return super.getValue(); 54 | } 55 | 56 | @Callable 57 | @Override 58 | public Double toggle() { 59 | double value = getValue(); 60 | double next = value + step; 61 | 62 | if (next > maximum) { 63 | next = minimum; 64 | } 65 | 66 | setValue(next); 67 | return next; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/libraries/ServerLibrary.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.libraries; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import com.ddoerr.scriptit.models.PlayerEntryModel; 6 | import net.minecraft.client.MinecraftClient; 7 | import net.minecraft.client.network.ServerInfo; 8 | import org.apache.commons.lang3.StringUtils; 9 | 10 | import java.util.Collections; 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | public class ServerLibrary extends AnnotationBasedModel { 15 | MinecraftClient minecraft; 16 | 17 | public ServerLibrary(MinecraftClient minecraft) { 18 | this.minecraft = minecraft; 19 | } 20 | @Getter 21 | public String getName() { 22 | ServerInfo currentServerEntry = minecraft.getCurrentServerEntry(); 23 | if (currentServerEntry != null) { 24 | return currentServerEntry.name; 25 | } 26 | 27 | if (minecraft.isInSingleplayer() && minecraft.isIntegratedServerRunning() && minecraft.getServer() != null) { 28 | return minecraft.getServer().getLevelName(); 29 | } 30 | 31 | return StringUtils.EMPTY; 32 | } 33 | 34 | @Getter 35 | public String getAddress() { 36 | ServerInfo currentServerEntry = minecraft.getCurrentServerEntry(); 37 | if (currentServerEntry != null) { 38 | return currentServerEntry.address; 39 | } 40 | 41 | if (minecraft.isInSingleplayer() && minecraft.isIntegratedServerRunning()) { 42 | return "local"; 43 | } 44 | 45 | return StringUtils.EMPTY; 46 | } 47 | 48 | @Getter 49 | public String getLabel() { 50 | ServerInfo currentServerEntry = minecraft.getCurrentServerEntry(); 51 | if (currentServerEntry != null) { 52 | return currentServerEntry.label; 53 | } 54 | 55 | if (minecraft.isInSingleplayer() && minecraft.isIntegratedServerRunning() && minecraft.getServer() != null) { 56 | return minecraft.getServer().getServerMotd(); 57 | } 58 | 59 | return StringUtils.EMPTY; 60 | } 61 | 62 | @Getter 63 | public List getPlayers() { 64 | if (minecraft.getNetworkHandler() == null) { 65 | return Collections.emptyList(); 66 | } 67 | 68 | return minecraft.getNetworkHandler().getPlayerList().stream() 69 | .map(PlayerEntryModel::From) 70 | .collect(Collectors.toList()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/ItemModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Getter; 4 | import com.ddoerr.scriptit.api.libraries.AnnotationBasedModel; 5 | import net.minecraft.enchantment.EnchantmentHelper; 6 | import net.minecraft.item.ItemStack; 7 | import net.minecraft.util.Rarity; 8 | 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | public class ItemModel extends AnnotationBasedModel { 13 | public static ItemModel From(ItemStack item) { 14 | ItemModel itemModel = new ItemModel(); 15 | itemModel.itemStack = item; 16 | return itemModel; 17 | } 18 | 19 | private ItemStack itemStack; 20 | 21 | @Getter 22 | public int getAmount() { 23 | return itemStack.getCount(); 24 | } 25 | 26 | @Getter 27 | public int getMaxAmount() { 28 | return itemStack.getMaxCount(); 29 | } 30 | 31 | @Getter 32 | public int getCooldown() { 33 | return itemStack.getCooldown(); 34 | } 35 | 36 | @Getter 37 | public int getDamage() { 38 | return itemStack.getDamage(); 39 | } 40 | 41 | @Getter 42 | public int getMaxDamage() { 43 | return itemStack.getMaxDamage(); 44 | } 45 | 46 | @Getter 47 | public int getRepairCost() { 48 | return itemStack.getRepairCost(); 49 | } 50 | 51 | @Getter 52 | public int getMaxUsetime() { 53 | return itemStack.getMaxUseTime(); 54 | } 55 | 56 | @Getter 57 | public Rarity getRarity() { 58 | return itemStack.getRarity(); 59 | } 60 | 61 | @Getter 62 | public List getEnchantments() { 63 | return EnchantmentHelper.getEnchantments(itemStack) 64 | .entrySet() 65 | .stream() 66 | .map(EnchantmentModel::From) 67 | .collect(Collectors.toList()); 68 | } 69 | 70 | @Getter 71 | public String getName() { 72 | return itemStack.getName().asFormattedString(); 73 | } 74 | 75 | @Getter 76 | public String getId() { 77 | return itemStack.getItem().toString(); 78 | } 79 | 80 | @Getter 81 | public boolean getIsEnchantable() { 82 | return itemStack.isEnchantable(); 83 | } 84 | 85 | @Getter 86 | public boolean getIsFood() { 87 | return itemStack.isFood(); 88 | } 89 | 90 | @Getter 91 | public boolean getIsDamageable() { 92 | return itemStack.isDamageable(); 93 | } 94 | 95 | @Getter boolean getIsStackable() { 96 | return itemStack.isStackable(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/models/settings/EnumSettingModel.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.models.settings; 2 | 3 | import com.ddoerr.scriptit.api.annotations.Callable; 4 | import com.ddoerr.scriptit.api.exceptions.ConversionException; 5 | import com.ddoerr.scriptit.api.languages.ContainedResultFactory; 6 | import com.ddoerr.scriptit.api.languages.ContainedValue; 7 | import com.ddoerr.scriptit.api.util.GenericEnumHelper; 8 | import com.google.common.base.Joiner; 9 | 10 | import java.util.Arrays; 11 | import java.util.function.Consumer; 12 | import java.util.function.Supplier; 13 | import java.util.stream.Collectors; 14 | 15 | public class EnumSettingModel> extends AbstractSettingModel implements ToggleableSettingModel { 16 | private static final String VALUE_KEY = "value"; 17 | private Class enumClass; 18 | private Joiner joiner = Joiner.on(", "); 19 | 20 | public EnumSettingModel(String name, Class enumClass, Supplier getter, Consumer setter) { 21 | super(name, getter, setter); 22 | this.enumClass = enumClass; 23 | } 24 | 25 | @Override 26 | public boolean hasGetter(String key) { 27 | return super.hasGetter(key) || VALUE_KEY.equals(key); 28 | } 29 | 30 | @Override 31 | public boolean hasSetter(String key) { 32 | return super.hasSetter(key) || VALUE_KEY.equals(key); 33 | } 34 | 35 | @Override 36 | public T runGetter(String key, ContainedResultFactory factory) { 37 | if (VALUE_KEY.equals(key)) { 38 | return factory.fromEnum(getValue()); 39 | } else { 40 | return super.runGetter(key, factory); 41 | } 42 | } 43 | 44 | @Override 45 | public void runSetter(String key, ContainedValue value) { 46 | if (VALUE_KEY.equals(key)) { 47 | try { 48 | setValue(value.toEnum(enumClass)); 49 | } catch (ConversionException e) { 50 | e.printStackTrace(); 51 | } 52 | } else { 53 | super.runSetter(key, value); 54 | } 55 | } 56 | 57 | @Override 58 | public String getPossibleValues() { 59 | return joiner.join(Arrays.stream(GenericEnumHelper.getValues(enumClass)).map(Enum::name).collect(Collectors.toList())); 60 | } 61 | 62 | @Override 63 | public E getValue() { 64 | return super.getValue(); 65 | } 66 | 67 | @Override 68 | public void setValue(E value) { 69 | super.setValue(value); 70 | } 71 | 72 | @Callable 73 | @Override 74 | public E toggle() { 75 | E next = GenericEnumHelper.getNext(enumClass, getValue()); 76 | setValue(next); 77 | return next; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/config/Config.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.config; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.dependencies.Resolver; 5 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 6 | import com.ddoerr.scriptit.api.hud.HudElementContainer; 7 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 8 | import com.ddoerr.scriptit.api.triggers.Trigger; 9 | import com.google.gson.Gson; 10 | import com.google.gson.GsonBuilder; 11 | import net.fabricmc.loader.api.FabricLoader; 12 | 13 | import java.io.File; 14 | import java.io.FileReader; 15 | import java.io.FileWriter; 16 | import java.io.IOException; 17 | import java.nio.file.Path; 18 | 19 | public class Config { 20 | public static final String CONFIG_FILE = "config.json"; 21 | 22 | private Gson gson; 23 | 24 | public Config(Resolver resolver) { 25 | GsonBuilder gsonBuilder = new GsonBuilder(); 26 | 27 | try { 28 | gsonBuilder.registerTypeAdapter(ScriptContainer.class, resolver.create(ScriptContainerAdapter.class)); 29 | gsonBuilder.registerTypeAdapter(HudElementContainer.class, resolver.create(HudElementAdapter.class)); 30 | gsonBuilder.registerTypeAdapter(Trigger.class, resolver.create(TriggerAdapter.class)); 31 | } catch (DependencyException e) { 32 | e.printStackTrace(); 33 | } 34 | 35 | gsonBuilder.setPrettyPrinting(); 36 | gson = gsonBuilder.create(); 37 | } 38 | 39 | public void write(ConfigContainer configContainer) { 40 | File file = getConfigFilePath().toFile(); 41 | 42 | try { 43 | FileWriter writer = new FileWriter(file, false); 44 | gson.toJson(configContainer, writer); 45 | writer.flush(); 46 | writer.close(); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | public ConfigContainer read() { 53 | File file = getConfigFilePath().toFile(); 54 | ConfigContainer container = null; 55 | 56 | try { 57 | FileReader reader = new FileReader(file); 58 | container = gson.fromJson(reader, ConfigContainer.class); 59 | reader.close(); 60 | 61 | } catch (IOException e) { 62 | e.printStackTrace(); 63 | } 64 | 65 | return container; 66 | } 67 | 68 | private Path getConfigPath() { 69 | return FabricLoader.getInstance().getConfigDirectory().toPath().resolve(ScriptItMod.MOD_NAME); 70 | } 71 | 72 | private Path getConfigFilePath() { 73 | return getConfigPath().resolve(CONFIG_FILE); 74 | } 75 | 76 | public void ensureConfigExists() { 77 | getConfigPath().toFile().mkdirs(); 78 | 79 | if (!getConfigFilePath().toFile().exists()) { 80 | write(new ConfigContainer()); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/screens/widgets/KeyBindingButtonWidget.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.screens.widgets; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.util.KeyBindingHelper; 5 | import net.minecraft.client.util.InputUtil; 6 | import net.minecraft.text.Text; 7 | import net.minecraft.text.TranslatableText; 8 | import net.minecraft.util.Identifier; 9 | import spinnery.widget.WButton; 10 | import spinnery.widget.api.WFocusedMouseListener; 11 | 12 | import java.util.function.Consumer; 13 | 14 | @WFocusedMouseListener 15 | public class KeyBindingButtonWidget extends WButton { 16 | private InputUtil.KeyCode keyCode = InputUtil.UNKNOWN_KEYCODE; 17 | 18 | private Consumer onChange; 19 | 20 | public void setKeyCode(InputUtil.KeyCode keyCode) { 21 | this.keyCode = keyCode; 22 | setLabel(getFormattedKey(keyCode)); 23 | } 24 | 25 | public void setOnChange(Consumer onChange) { 26 | this.onChange = onChange; 27 | } 28 | 29 | @Override 30 | public void onMouseClicked(int mouseX, int mouseY, int mouseButton) { 31 | if (isLowered()) { 32 | keyCode = InputUtil.Type.MOUSE.createFromCode(mouseButton); 33 | setLowered(false); 34 | 35 | if (onChange != null) { 36 | onChange.accept(keyCode); 37 | } 38 | } else { 39 | super.onMouseClicked(mouseX, mouseY, mouseButton); 40 | } 41 | 42 | setLabel(getFormattedKey(keyCode)); 43 | } 44 | 45 | @Override 46 | public void tick() { 47 | // do not trigger `tick` from `WButton` 48 | } 49 | 50 | @Override 51 | public void onKeyPressed(int keyPressed, int character, int keyModifier) { 52 | super.onKeyPressed(keyPressed, character, keyModifier); 53 | 54 | if (isLowered()) { 55 | keyCode = InputUtil.getKeyCode(keyPressed, character); 56 | 57 | setLowered(false); 58 | setLabel(getFormattedKey(keyCode)); 59 | 60 | if (onChange != null) { 61 | onChange.accept(keyCode); 62 | } 63 | } 64 | } 65 | 66 | public Text getFormattedKey(InputUtil.KeyCode keyCode) { 67 | if (keyCode == null) { 68 | return new TranslatableText(new Identifier(ScriptItMod.MOD_NAME, "keybinding.unknown").toString()); 69 | } 70 | 71 | String translationKey; 72 | 73 | if (isLowered()) { 74 | translationKey = "keybinding.active"; 75 | } else if (KeyBindingHelper.hasConflict(keyCode)) { 76 | translationKey = "keybinding.conflict"; 77 | } else { 78 | translationKey = "keybinding.default"; 79 | } 80 | 81 | return new TranslatableText(new Identifier(ScriptItMod.MOD_NAME, translationKey).toString(), KeyBindingHelper.getKeyCodeName(keyCode)); 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/triggers/DurationTrigger.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.triggers; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.fields.Field; 5 | import com.ddoerr.scriptit.fields.IntegerField; 6 | import com.ddoerr.scriptit.fields.SelectionField; 7 | import com.ddoerr.scriptit.triggers.AbstractTrigger; 8 | import com.ddoerr.scriptit.triggers.TriggerMessageImpl; 9 | import net.minecraft.text.LiteralText; 10 | import net.minecraft.util.Identifier; 11 | 12 | import java.time.Duration; 13 | import java.time.Instant; 14 | import java.time.temporal.ChronoUnit; 15 | import java.util.LinkedHashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | import java.util.stream.Collectors; 19 | import java.util.stream.Stream; 20 | 21 | public class DurationTrigger extends AbstractTrigger { 22 | public static final Identifier IDENTIFIER = new Identifier(ScriptItMod.MOD_NAME, "duration"); 23 | public static final String TIME_FIELD = "time"; 24 | public static final String UNIT_FIELD = "unit"; 25 | 26 | private Duration duration = Duration.ZERO; 27 | private Instant lastActivation = Instant.now(); 28 | 29 | private IntegerField timeField; 30 | private SelectionField unitField; 31 | 32 | public DurationTrigger() { 33 | timeField = new IntegerField(); 34 | timeField.setTitle(new LiteralText("Time")); 35 | timeField.setDescription(new LiteralText("Amount of time")); 36 | timeField.setValue(0); 37 | fields.put(TIME_FIELD, timeField); 38 | 39 | unitField = new SelectionField(); 40 | unitField.setTitle(new LiteralText("Unit")); 41 | unitField.setDescription(new LiteralText("Time unit")); 42 | unitField.setValue(ChronoUnit.MILLIS.name()); 43 | unitField.setTranslationPrefix("scripts.triggers.duration.values"); 44 | 45 | List units = Stream.of(ChronoUnit.MILLIS, ChronoUnit.SECONDS, ChronoUnit.MINUTES, ChronoUnit.HOURS) 46 | .map(Enum::name).collect(Collectors.toList()); 47 | unitField.setValues(units); 48 | 49 | fields.put(UNIT_FIELD, unitField); 50 | } 51 | 52 | @Override 53 | public void start() { 54 | int time = timeField.getValue(); 55 | ChronoUnit unit = ChronoUnit.valueOf(unitField.getValue()); 56 | duration = Duration.of(time, unit); 57 | } 58 | 59 | @Override 60 | public void check() { 61 | Duration between = Duration.between(lastActivation, Instant.now()); 62 | 63 | if (duration.compareTo(between) < 0) { 64 | callback.accept(new TriggerMessageImpl()); 65 | lastActivation = Instant.now(); 66 | } 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "every " + timeField.getValue() + " " + unitField.getValue(); 72 | } 73 | 74 | @Override 75 | public Identifier getIdentifier() { 76 | return IDENTIFIER; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/scripts/ScriptContainerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.scripts; 2 | 3 | import com.ddoerr.scriptit.api.languages.ContainedValue; 4 | import com.ddoerr.scriptit.api.scripts.Script; 5 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 6 | import com.ddoerr.scriptit.api.triggers.Trigger; 7 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 8 | import net.minecraft.util.Formatting; 9 | import org.apache.commons.lang3.StringUtils; 10 | 11 | import java.util.function.Consumer; 12 | 13 | public class ScriptContainerImpl implements ScriptContainer { 14 | private Trigger trigger; 15 | private Script script; 16 | 17 | private Consumer callback = triggerMessage -> {}; 18 | 19 | private ContainedValue lastResult; 20 | private boolean isDisabled = false; 21 | 22 | @Override 23 | public Trigger getTrigger() { 24 | return trigger; 25 | } 26 | 27 | @Override 28 | public void setTrigger(Trigger trigger) { 29 | if (this.trigger != null) { 30 | this.trigger.stop(); 31 | } 32 | 33 | this.trigger = trigger; 34 | trigger.setCallback(callback); 35 | } 36 | 37 | @Override 38 | public ContainedValue getLastResult() { 39 | return lastResult; 40 | } 41 | 42 | @Override 43 | public void setLastResult(ContainedValue lastResult) { 44 | this.lastResult = lastResult; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | StringBuilder stringBuilder = new StringBuilder(); 50 | 51 | if (trigger != null) { 52 | stringBuilder 53 | .append("triggers ") 54 | .append(Formatting.YELLOW) 55 | .append(trigger.toString()); 56 | } else { 57 | stringBuilder.append("no activation trigger"); 58 | } 59 | 60 | stringBuilder 61 | .append(Formatting.RESET) 62 | .append("; ") 63 | .append(StringUtils.abbreviate(script.getScriptSource().getContent(), 50)); 64 | 65 | return stringBuilder.toString(); 66 | } 67 | 68 | @Override 69 | public boolean isDisabled() { 70 | return isDisabled; 71 | } 72 | 73 | @Override 74 | public void disable() { 75 | isDisabled = true; 76 | } 77 | 78 | @Override 79 | public void enable() { 80 | isDisabled = false; 81 | } 82 | 83 | @Override 84 | public Script getScript() { 85 | return script; 86 | } 87 | 88 | @Override 89 | public void setScript(Script script) { 90 | this.script = script; 91 | } 92 | 93 | @Override 94 | public void setCallback(Consumer callback) { 95 | this.callback = callback; 96 | if (trigger != null) { 97 | trigger.setCallback(callback); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/languages/ContainedResultFactory.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.languages; 2 | 3 | import com.ddoerr.scriptit.api.exceptions.ConversionException; 4 | import com.ddoerr.scriptit.api.libraries.Model; 5 | 6 | import java.lang.reflect.ParameterizedType; 7 | import java.lang.reflect.Type; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public interface ContainedResultFactory { 12 | default T from(Type type, Object value) throws ConversionException { 13 | if (value == null) { 14 | return nullValue(); 15 | } else if (String.class.equals(type)) { 16 | return fromString((String)value); 17 | } else if (Boolean.class.equals(type) || boolean.class.equals(type)) { 18 | return fromBoolean((boolean)value); 19 | } else if (Float.class.equals(type) || float.class.equals(type)) { 20 | return fromFloat((float)value); 21 | } else if (Double.class.equals(type) || double.class.equals(type)) { 22 | return fromDouble((double)value); 23 | } else if (Integer.class.equals(type) || int.class.equals(type)) { 24 | return fromInteger((int)value); 25 | } else if (type instanceof Class && Enum.class.isAssignableFrom((Class)type)) { 26 | return fromEnum((Enum)value); 27 | } else if (type instanceof ParameterizedType && ((ParameterizedType)type).getRawType().equals(List.class)) { 28 | return fromList(((ParameterizedType)type).getActualTypeArguments()[0], (List)value); 29 | } else if (type instanceof ParameterizedType && ((ParameterizedType)type).getRawType().equals(Map.class)) { 30 | Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments(); 31 | return fromMap(typeArguments[0], typeArguments[1], (Map)value); 32 | } else if (type instanceof Class && Model.class.isAssignableFrom((Class)type)) { 33 | return fromModel((Model)value); 34 | } else if (Void.TYPE.equals(type)) { 35 | return nullValue(); 36 | } else if (Object.class.equals(type)) { 37 | return from(value.getClass(), value); 38 | } else if (ContainedValue.class.equals(type)) { 39 | return fromContainedValue((ContainedValue)value); 40 | } 41 | 42 | throw new ConversionException("Unknown type " + type.getTypeName()); 43 | } 44 | 45 | T nullValue(); 46 | 47 | T fromString(String value); 48 | T fromBoolean(boolean value); 49 | T fromFloat(float value); 50 | T fromDouble(double value); 51 | T fromInteger(int value); 52 | T fromEnum(Enum value); 53 | T fromMap(Type keyType, Type valueType, Map value) throws ConversionException; 54 | T fromList(Type entryType, List value) throws ConversionException; 55 | T fromModel(Model value); 56 | default T fromContainedValue(ContainedValue containedValue) throws ConversionException { 57 | Type typeGuess = containedValue.guessType(); 58 | return from(typeGuess, containedValue.to(typeGuess)); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/api/util/KeyBindingHelper.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.api.util; 2 | 3 | import com.ddoerr.scriptit.mixin.KeyBindingAccessor; 4 | import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; 5 | import net.fabricmc.fabric.mixin.client.keybinding.KeyCodeAccessor; 6 | import net.minecraft.client.MinecraftClient; 7 | import net.minecraft.client.options.KeyBinding; 8 | import net.minecraft.client.resource.language.I18n; 9 | import net.minecraft.client.util.InputUtil; 10 | import net.minecraft.util.Identifier; 11 | 12 | import java.util.Map; 13 | 14 | public class KeyBindingHelper { 15 | public static boolean hasConflict(InputUtil.KeyCode keyCode) { 16 | MinecraftClient minecraft = MinecraftClient.getInstance(); 17 | 18 | for (KeyBinding keyBinding : minecraft.options.keysAll) { 19 | if (hasKeyBindingKeyCode(keyBinding, keyCode)) { 20 | return true; 21 | } 22 | } 23 | 24 | return false; 25 | } 26 | 27 | private static boolean hasKeyBindingKeyCode(KeyBinding keyBinding, InputUtil.KeyCode keyCode) { 28 | return ((KeyCodeAccessor)keyBinding).getKeyCode().getName().equals(keyCode.getName()); 29 | } 30 | 31 | public static KeyBinding create(Identifier identifier, InputUtil.KeyCode keyCode) { 32 | return FabricKeyBinding.Builder.create( 33 | identifier, 34 | keyCode.getCategory(), 35 | keyCode.getKeyCode(), 36 | "Scripts" 37 | ).build(); 38 | } 39 | public static KeyBinding create(Identifier identifier) { 40 | return create(identifier, InputUtil.UNKNOWN_KEYCODE); 41 | } 42 | 43 | public static KeyBinding create(String id, InputUtil.KeyCode keyCode) { 44 | return new KeyBinding( 45 | id, 46 | keyCode.getCategory(), 47 | keyCode.getKeyCode(), 48 | "Scripts" 49 | ); 50 | } 51 | 52 | public static void remove(KeyBinding keyBinding) { 53 | Map keyBindings = KeyBindingAccessor.getKeysById(); 54 | keyBindings.remove(keyBinding.getId()); 55 | KeyBinding.updateKeysByCode(); 56 | } 57 | 58 | 59 | // Copied from KeyBinding::getLocalizedName 60 | public static String getKeyCodeName(InputUtil.KeyCode keyCode) { 61 | String result = null; 62 | 63 | switch(keyCode.getCategory()) { 64 | case KEYSYM: 65 | result = InputUtil.getKeycodeName(keyCode.getKeyCode()); 66 | break; 67 | case SCANCODE: 68 | result = InputUtil.getScancodeName(keyCode.getKeyCode()); 69 | break; 70 | case MOUSE: 71 | String translated = I18n.translate(keyCode.getName()); 72 | result = translated.equals(keyCode.getName()) ? I18n.translate(InputUtil.Type.MOUSE.getName(), keyCode.getKeyCode() + 1) : translated; 73 | break; 74 | } 75 | 76 | return result == null ? I18n.translate(keyCode.getName()) : result; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/elements/ItemHudElement.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension.elements; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.hud.HudElement; 5 | import com.ddoerr.scriptit.api.hud.HudElementContainer; 6 | import com.ddoerr.scriptit.api.scripts.Script; 7 | import com.ddoerr.scriptit.api.scripts.ScriptBuilder; 8 | import com.ddoerr.scriptit.api.util.Color; 9 | import com.ddoerr.scriptit.api.util.geometry.Point; 10 | import com.ddoerr.scriptit.api.util.geometry.Rectangle; 11 | import com.ddoerr.scriptit.elements.AbstractHudElement; 12 | import com.ddoerr.scriptit.fields.ColorField; 13 | import com.ddoerr.scriptit.fields.Field; 14 | import com.ddoerr.scriptit.fields.StringField; 15 | import net.minecraft.client.MinecraftClient; 16 | import net.minecraft.client.render.DiffuseLighting; 17 | import net.minecraft.item.Item; 18 | import net.minecraft.text.LiteralText; 19 | import net.minecraft.util.Identifier; 20 | import net.minecraft.util.registry.Registry; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import static net.minecraft.client.gui.DrawableHelper.fill; 26 | 27 | public class ItemHudElement extends AbstractHudElement { 28 | public static final Identifier IDENTIFIER = new Identifier(ScriptItMod.MOD_NAME, "item"); 29 | public static final int ELEMENT_SIZE = 20; 30 | 31 | public static final String BACK_COLOR_FIELD = "back-color"; 32 | 33 | private ColorField backColorField; 34 | 35 | public ItemHudElement() { 36 | backColorField = new ColorField(); 37 | backColorField.setTitle(new LiteralText("Back Color")); 38 | backColorField.setDescription(new LiteralText("Color used as the background")); 39 | backColorField.setValue("BLACK 50%"); 40 | fields.put(BACK_COLOR_FIELD, backColorField); 41 | } 42 | 43 | @Override 44 | public Rectangle render(Point origin, HudElementContainer hudElement) { 45 | Rectangle rectangle = new Rectangle((int) origin.getX(), (int) origin.getY(), ELEMENT_SIZE, ELEMENT_SIZE); 46 | 47 | Color backColor = Color.runAndParse(backColorField.getValue()); 48 | if (backColor != null) { 49 | fill(rectangle.getMinX(), rectangle.getMinY(), rectangle.getMaxX(), rectangle.getMaxY(), backColor.getValue()); 50 | } 51 | 52 | try { 53 | String lastResult = hudElement.getScriptContainer().getLastResult().toStr(); 54 | Item item = Registry.ITEM.get(new Identifier(lastResult)); 55 | DiffuseLighting.enableGuiDepthLighting(); 56 | MinecraftClient.getInstance() 57 | .getItemRenderer() 58 | .renderGuiItemIcon(item.getStackForRender(), rectangle.getMinX() + HudElementContainer.DEFAULT_PADDING, rectangle.getMinY() + HudElementContainer.DEFAULT_PADDING); 59 | } 60 | catch (Exception ignored) { } 61 | 62 | return rectangle; 63 | } 64 | 65 | @Override 66 | public Identifier getIdentifier() { 67 | return IDENTIFIER; 68 | } 69 | 70 | @Override 71 | public Script getDefaultScript() { 72 | return new ScriptBuilder().fromString("grass_block"); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/extension/ScriptItExtension.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.extension; 2 | 3 | import com.ddoerr.scriptit.ScriptItMod; 4 | import com.ddoerr.scriptit.api.dependencies.Resolver; 5 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 6 | import com.ddoerr.scriptit.api.registry.ExtensionInitializer; 7 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 8 | import com.ddoerr.scriptit.extension.elements.ItemHudElement; 9 | import com.ddoerr.scriptit.extension.elements.ItemHudElementFactory; 10 | import com.ddoerr.scriptit.extension.elements.TextHudElement; 11 | import com.ddoerr.scriptit.extension.elements.TextHudElementFactory; 12 | import com.ddoerr.scriptit.extension.events.ChatIncomingEvent; 13 | import com.ddoerr.scriptit.extension.events.ChatOutgoingEvent; 14 | import com.ddoerr.scriptit.extension.events.GameConnectEvent; 15 | import com.ddoerr.scriptit.extension.events.SoundEvent; 16 | import com.ddoerr.scriptit.extension.libraries.*; 17 | import com.ddoerr.scriptit.extension.text.TextLanguage; 18 | import com.ddoerr.scriptit.extension.triggers.*; 19 | import net.minecraft.util.Identifier; 20 | import net.minecraft.util.registry.MutableRegistry; 21 | 22 | public class ScriptItExtension implements ExtensionInitializer { 23 | 24 | private Resolver resolver; 25 | 26 | @Override 27 | public void onInitialize(ScriptItRegistry registry, Resolver resolver) { 28 | this.resolver = resolver; 29 | add(registry.languages, "text", TextLanguage.class); 30 | 31 | add(registry.libraries, "scripts", ScriptsLibrary.class); 32 | add(registry.libraries, "json", JsonLibrary.class); 33 | 34 | add(registry.libraries, "chat", ChatLibrary.class); 35 | add(registry.libraries, "game", GameLibrary.class); 36 | add(registry.libraries, "gui", GuiLibrary.class); 37 | add(registry.libraries, "keyboard", KeyboardLibrary.class); 38 | add(registry.libraries, "options", OptionsLibrary.class); 39 | add(registry.libraries, "player", PlayerLibrary.class); 40 | add(registry.libraries, "scoreboard", ScoreboardLibrary.class); 41 | add(registry.libraries, "server", ServerLibrary.class); 42 | add(registry.libraries, "shared", SharedLibrary.class); 43 | 44 | add(registry.hudElements, TextHudElement.IDENTIFIER, TextHudElementFactory.class); 45 | add(registry.hudElements, ItemHudElement.IDENTIFIER, ItemHudElementFactory.class); 46 | 47 | add(registry.events, "game/connect", GameConnectEvent.class); 48 | add(registry.events, "chat/incoming", ChatIncomingEvent.class); 49 | add(registry.events, "chat/outgoing", ChatOutgoingEvent.class); 50 | add(registry.events, "sound", SoundEvent.class); 51 | 52 | add(registry.triggers, KeyBindingTrigger.IDENTIFIER, KeyBindingTriggerFactory.class); 53 | add(registry.triggers, EventTrigger.IDENTIFIER, EventTriggerFactory.class); 54 | add(registry.triggers, DurationTrigger.IDENTIFIER, DurationTriggerFactory.class); 55 | } 56 | 57 | private void add(MutableRegistry registry, String identifierPath, Class type) { 58 | add(registry, new Identifier(ScriptItMod.MOD_NAME, identifierPath), type); 59 | } 60 | 61 | private void add(MutableRegistry registry, Identifier identifier, Class type) { 62 | try { 63 | registry.add(identifier, resolver.create(type)); 64 | } catch (DependencyException e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/config/HudElementAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.config; 2 | 3 | import com.ddoerr.scriptit.api.hud.*; 4 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 5 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 6 | import com.ddoerr.scriptit.api.util.geometry.Point; 7 | import com.ddoerr.scriptit.elements.HudElementContainerImpl; 8 | import com.ddoerr.scriptit.fields.Field; 9 | import com.google.gson.*; 10 | import net.minecraft.util.Identifier; 11 | 12 | import java.lang.reflect.Type; 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | import java.util.stream.Collectors; 16 | 17 | public class HudElementAdapter implements JsonSerializer, JsonDeserializer { 18 | private ScriptItRegistry registry; 19 | 20 | public HudElementAdapter(ScriptItRegistry registry) { 21 | this.registry = registry; 22 | } 23 | 24 | @Override 25 | public JsonElement serialize(HudElementContainer src, Type typeOfSrc, JsonSerializationContext context) { 26 | JsonObject json = new JsonObject(); 27 | 28 | JsonObject anchor = new JsonObject(); 29 | anchor.add("horizontal", context.serialize(src.getHorizontalAnchor())); 30 | anchor.add("vertical", context.serialize(src.getVerticalAnchor())); 31 | 32 | Map> fieldValues = src.getHudElement().getFields(); 33 | Map data = new HashMap<>(); 34 | 35 | for (Map.Entry> entry : fieldValues.entrySet()) { 36 | data.put(entry.getKey(), entry.getValue().serialize()); 37 | } 38 | 39 | json.addProperty("type", src.getHudElement().getIdentifier().toString()); 40 | json.add("relative", context.serialize(src.getRelativePosition())); 41 | json.add("anchor", anchor); 42 | json.add("data", context.serialize(data)); 43 | json.add("script", context.serialize(src.getScriptContainer(), ScriptContainer.class)); 44 | 45 | return json; 46 | } 47 | 48 | @Override 49 | public HudElementContainer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { 50 | JsonObject jsonObject = json.getAsJsonObject(); 51 | 52 | String type = jsonObject.getAsJsonPrimitive("type").getAsString(); 53 | Point point = context.deserialize(jsonObject.get("relative"), Point.class); 54 | ScriptContainer scriptContainer = context.deserialize(jsonObject.get("script"), ScriptContainer.class); 55 | 56 | JsonObject anchor = jsonObject.getAsJsonObject("anchor"); 57 | HudHorizontalAnchor horizontalAnchor = context.deserialize(anchor.get("horizontal"), HudHorizontalAnchor.class); 58 | HudVerticalAnchor verticalAnchor = context.deserialize(anchor.get("vertical"), HudVerticalAnchor.class); 59 | 60 | Map data = new HashMap<>(); 61 | 62 | for (Map.Entry entry : jsonObject.getAsJsonObject("data").entrySet()) { 63 | String value = entry.getValue().getAsString(); 64 | data.put(entry.getKey(), value); 65 | } 66 | 67 | HudElementFactory hudElementFactory = registry.hudElements.get(new Identifier(type)); 68 | HudElement hudElement = hudElementFactory.createHudElement(data); 69 | HudElementContainer hudElementContainer = new HudElementContainerImpl(hudElement, 0, 0); 70 | hudElementContainer.setRelativePosition(point); 71 | 72 | hudElementContainer.getScriptContainer().setTrigger(scriptContainer.getTrigger()); 73 | hudElementContainer.getScriptContainer().setScript(scriptContainer.getScript()); 74 | hudElementContainer.setAnchor(horizontalAnchor, verticalAnchor); 75 | 76 | return hudElementContainer; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/scripts/ScriptManagerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.scripts; 2 | 3 | import com.ddoerr.scriptit.api.languages.ContainedValue; 4 | import com.ddoerr.scriptit.api.languages.Language; 5 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 6 | import com.ddoerr.scriptit.api.scripts.*; 7 | import com.ddoerr.scriptit.api.triggers.TriggerMessage; 8 | import net.minecraft.client.MinecraftClient; 9 | import net.minecraft.text.LiteralText; 10 | import net.minecraft.text.TranslatableText; 11 | 12 | import java.time.Duration; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.concurrent.CompletableFuture; 16 | import java.util.concurrent.ExecutionException; 17 | import java.util.concurrent.TimeUnit; 18 | import java.util.concurrent.TimeoutException; 19 | 20 | public class ScriptManagerImpl implements ScriptManager { 21 | private ScriptItRegistry registry; 22 | private MinecraftClient minecraft; 23 | 24 | private List runningScripts = new ArrayList<>(); 25 | 26 | public ScriptManagerImpl(ScriptItRegistry registry, MinecraftClient minecraft) { 27 | this.registry = registry; 28 | this.minecraft = minecraft; 29 | } 30 | 31 | @Override 32 | public CompletableFuture runScript(Script script) { 33 | Language language = registry.languages.get(script.getLanguage()); 34 | return language.runScript(script); 35 | } 36 | 37 | @Override 38 | public void runScriptContainer(ScriptContainer scriptContainer, TriggerMessage triggerMessage) { 39 | if (scriptContainer.isDisabled() || triggerMessage == null) { 40 | return; 41 | } 42 | 43 | ScriptBuilder scriptBuilder = new ScriptBuilder(scriptContainer.getScript()) 44 | .withLibrary("event", triggerMessage.getTriggerModel()); 45 | 46 | CompletableFuture future = runScript(scriptBuilder); 47 | 48 | RunningScriptImpl runningScript = new RunningScriptImpl(scriptContainer, future); 49 | runningScripts.add(runningScript); 50 | 51 | CompletableFuture handledFuture = future.exceptionally((throwable) -> { 52 | scriptContainer.disable(); 53 | throwable.printStackTrace(); 54 | 55 | minecraft.inGameHud.getChatHud().addMessage(new LiteralText(throwable.getMessage())); 56 | minecraft.inGameHud.getChatHud().addMessage(new TranslatableText("scriptit:scripts.exception", scriptContainer.getScript().getName())); 57 | 58 | return null; 59 | }).thenAccept(scriptContainer::setLastResult) 60 | .thenRun(() -> runningScripts.remove(runningScript)); 61 | 62 | if (triggerMessage.getTimeout() != null) { 63 | Duration timeout = triggerMessage.getTimeout(); 64 | try { 65 | handledFuture.get(timeout.toMillis(), TimeUnit.MILLISECONDS); 66 | } catch (InterruptedException | ExecutionException | TimeoutException e) { 67 | e.printStackTrace(); 68 | } 69 | } 70 | } 71 | 72 | @Override 73 | public List getRunningScripts() { 74 | return runningScripts; 75 | } 76 | 77 | @Override 78 | public int stopScripts(String name) { 79 | int count = 0; 80 | for (RunningScript runningScript : runningScripts) { 81 | if (runningScript.getScriptContainer().getScript().getName().equals(name)) { 82 | count++; 83 | runningScript.getFuture().cancel(true); 84 | } 85 | } 86 | return count; 87 | } 88 | 89 | @Override 90 | public int stopAllScripts() { 91 | int count = 0; 92 | for (RunningScript runningScript : runningScripts) { 93 | count++; 94 | runningScript.getFuture().cancel(true); 95 | } 96 | return count; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/ScriptItMod.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Loadable; 4 | import com.ddoerr.scriptit.api.dependencies.Resolver; 5 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 6 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 7 | import com.ddoerr.scriptit.api.scripts.ScriptManager; 8 | import com.ddoerr.scriptit.api.util.Color; 9 | import com.ddoerr.scriptit.callbacks.LateInitCallback; 10 | import com.ddoerr.scriptit.config.Config; 11 | import com.ddoerr.scriptit.config.ConfigHandler; 12 | import com.ddoerr.scriptit.elements.HudElementManagerImpl; 13 | import com.ddoerr.scriptit.extensions.ExtensionLoader; 14 | import com.ddoerr.scriptit.fields.FieldAssembler; 15 | import com.ddoerr.scriptit.languages.LanguageManagerImpl; 16 | import com.ddoerr.scriptit.screens.ScreenHistory; 17 | import com.ddoerr.scriptit.screens.ScriptOverviewScreen; 18 | import com.ddoerr.scriptit.scripts.ScriptContainerManagerImpl; 19 | import com.ddoerr.scriptit.scripts.ScriptManagerImpl; 20 | import com.ddoerr.scriptit.triggers.KeyBindingManagerImpl; 21 | import net.fabricmc.api.ClientModInitializer; 22 | import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; 23 | import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry; 24 | import net.fabricmc.fabric.api.event.client.ClientTickCallback; 25 | import net.minecraft.client.MinecraftClient; 26 | import net.minecraft.client.util.InputUtil; 27 | import net.minecraft.util.Identifier; 28 | import net.minecraft.util.Tickable; 29 | import org.lwjgl.glfw.GLFW; 30 | 31 | import java.util.Collection; 32 | 33 | public class ScriptItMod implements ClientModInitializer, LateInitCallback { 34 | public static final String MOD_NAME = "scriptit"; 35 | private Resolver resolver; 36 | 37 | @Override 38 | public void onInitializeClient() { 39 | LateInitCallback.EVENT.register(this); 40 | 41 | resolver = Resolver.getInstance(); 42 | 43 | try { 44 | resolver.add(resolver); 45 | resolver.add(MinecraftClient.getInstance()); 46 | 47 | resolver.add(FieldAssembler.class); 48 | resolver.add(ScreenHistory.class); 49 | resolver.add(KeyBindingManagerImpl.class); 50 | resolver.add(ScriptItRegistry.class); 51 | resolver.add(ExtensionLoader.class); 52 | resolver.add(ScriptManagerImpl.class); 53 | resolver.add(ScriptContainerManagerImpl.class); 54 | resolver.add(LanguageManagerImpl.class); 55 | resolver.add(HudElementManagerImpl.class); 56 | 57 | resolver.add(Config.class); 58 | resolver.add(ConfigHandler.class); 59 | } catch (DependencyException e) { 60 | e.printStackTrace(); 61 | } 62 | 63 | FabricKeyBinding openGuiKeyBinding = FabricKeyBinding.Builder.create( 64 | new Identifier(MOD_NAME, "open"), 65 | InputUtil.Type.KEYSYM, 66 | GLFW.GLFW_KEY_K, 67 | "ScriptIt" 68 | ).build(); 69 | KeyBindingRegistry.INSTANCE.addCategory("ScriptIt"); 70 | KeyBindingRegistry.INSTANCE.register(openGuiKeyBinding); 71 | 72 | try { 73 | Color.setScriptManager(resolver.resolve(ScriptManager.class)); 74 | 75 | Collection tickables = resolver.resolveAll(Tickable.class); 76 | ScreenHistory history = resolver.resolve(ScreenHistory.class); 77 | 78 | ClientTickCallback.EVENT.register(mc -> { 79 | if (openGuiKeyBinding.wasPressed()) { 80 | history.open(ScriptOverviewScreen.class); 81 | } 82 | 83 | if (mc.player != null) { 84 | for (Tickable tickable : tickables) { 85 | tickable.tick(); 86 | } 87 | } 88 | }); 89 | } catch (DependencyException e) { 90 | e.printStackTrace(); 91 | } 92 | } 93 | 94 | @Override 95 | public void onLateInitialize(MinecraftClient minecraft) { 96 | Collection loadables = resolver.resolveAll(Loadable.class); 97 | for (Loadable loadable : loadables) { 98 | loadable.load(); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/commands/ScriptItCommand.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.commands; 2 | 3 | import com.ddoerr.scriptit.api.dependencies.Resolver; 4 | import com.ddoerr.scriptit.api.exceptions.DependencyException; 5 | import com.ddoerr.scriptit.api.registry.ScriptItRegistry; 6 | import com.ddoerr.scriptit.api.scripts.Script; 7 | import com.ddoerr.scriptit.api.scripts.ScriptBuilder; 8 | import com.ddoerr.scriptit.api.scripts.ScriptManager; 9 | import com.mojang.brigadier.CommandDispatcher; 10 | import io.github.cottonmc.clientcommands.ClientCommandPlugin; 11 | import io.github.cottonmc.clientcommands.CottonClientCommandSource; 12 | import net.minecraft.client.MinecraftClient; 13 | import net.minecraft.server.command.CommandSource; 14 | import net.minecraft.text.LiteralText; 15 | import net.minecraft.util.Identifier; 16 | 17 | import java.util.List; 18 | import java.util.stream.Collectors; 19 | 20 | import static com.mojang.brigadier.arguments.StringArgumentType.*; 21 | import static io.github.cottonmc.clientcommands.ArgumentBuilders.argument; 22 | import static io.github.cottonmc.clientcommands.ArgumentBuilders.literal; 23 | import static net.minecraft.command.arguments.IdentifierArgumentType.identifier; 24 | 25 | public class ScriptItCommand implements ClientCommandPlugin { 26 | private ScriptManager scriptManager; 27 | private ScriptItRegistry registry; 28 | 29 | public ScriptItCommand() { 30 | try { 31 | Resolver resolver = Resolver.getInstance(); 32 | scriptManager = resolver.resolve(ScriptManager.class); 33 | registry = resolver.resolve(ScriptItRegistry.class); 34 | } catch (DependencyException e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | @Override 40 | public void registerCommands(CommandDispatcher dispatcher) { 41 | List languageNames = registry.languages.getIds().stream().map(Identifier::toString).collect(Collectors.toList()); 42 | 43 | dispatcher.register(literal("scriptit") 44 | .then(literal("run") 45 | .then(argument("language", identifier()) 46 | .suggests((ctx, builder) -> CommandSource.suggestMatching(languageNames, builder)) 47 | .then(argument("script", greedyString()) 48 | .executes(ctx -> execute(ctx.getSource(), 49 | ctx.getArgument("language", Identifier.class), 50 | getString(ctx, "script"))) 51 | ) 52 | ) 53 | ) 54 | .then(literal("start") 55 | .then(argument("file", word()) 56 | .executes(ctx -> execute(ctx.getSource(), getString(ctx, "file"))) 57 | ) 58 | ) 59 | ); 60 | } 61 | 62 | private int execute(CottonClientCommandSource ctx, Identifier language, String content) { 63 | if (content.startsWith("\"") && content.endsWith("\"")) { 64 | content = content.substring(1, content.length() - 1); 65 | } 66 | try { 67 | Script script = new ScriptBuilder() 68 | .language(language.toString()) 69 | .fromString(content); 70 | scriptManager.runScript(script); 71 | } catch (Exception e) { 72 | MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(new LiteralText(e.getMessage())); 73 | e.printStackTrace(); 74 | } 75 | 76 | return 1; 77 | } 78 | 79 | private int execute(CottonClientCommandSource ctx, String file) { 80 | try { 81 | Script script = new ScriptBuilder() 82 | .fromFile(file); 83 | scriptManager.runScript(script); 84 | } catch (Exception e) { 85 | MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(new LiteralText(e.getMessage())); 86 | e.printStackTrace(); 87 | } 88 | return 1; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/ddoerr/scriptit/elements/HudElementContainerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ddoerr.scriptit.elements; 2 | 3 | import com.ddoerr.scriptit.api.hud.HudElement; 4 | import com.ddoerr.scriptit.api.hud.HudElementContainer; 5 | import com.ddoerr.scriptit.api.hud.HudHorizontalAnchor; 6 | import com.ddoerr.scriptit.api.hud.HudVerticalAnchor; 7 | import com.ddoerr.scriptit.api.util.geometry.Point; 8 | import com.ddoerr.scriptit.api.util.geometry.Rectangle; 9 | import com.ddoerr.scriptit.callbacks.ConfigCallback; 10 | import com.ddoerr.scriptit.api.scripts.ScriptContainer; 11 | import com.ddoerr.scriptit.scripts.ScriptContainerImpl; 12 | import com.ddoerr.scriptit.extension.triggers.DurationTrigger; 13 | import net.minecraft.client.MinecraftClient; 14 | import net.minecraft.client.gui.DrawableHelper; 15 | import net.minecraft.client.gui.Element; 16 | 17 | public class HudElementContainerImpl extends DrawableHelper implements Element, HudElementContainer { 18 | private HudElement hudElement; 19 | private ScriptContainer scriptContainer; 20 | 21 | private double xDifference = 0; 22 | private double yDifference = 0; 23 | 24 | private int width = 0; 25 | private int height = 0; 26 | 27 | private HudHorizontalAnchor horizontalAnchor = HudHorizontalAnchor.LEFT; 28 | private HudVerticalAnchor verticalAnchor = HudVerticalAnchor.TOP; 29 | 30 | public HudElementContainerImpl(HudElement hudElement, double xPosition, double yPosition) { 31 | this.hudElement = hudElement; 32 | scriptContainer = new ScriptContainerImpl(); 33 | scriptContainer.setScript(hudElement.getDefaultScript()); 34 | scriptContainer.setTrigger(new DurationTrigger()); 35 | setRealPosition(new Point(xPosition, yPosition)); 36 | } 37 | 38 | @Override 39 | public void setAnchor(HudHorizontalAnchor horizontalAnchor, HudVerticalAnchor verticalAnchor) { 40 | this.horizontalAnchor = horizontalAnchor; 41 | this.verticalAnchor = verticalAnchor; 42 | } 43 | 44 | @Override 45 | public HudVerticalAnchor getVerticalAnchor() { 46 | return verticalAnchor; 47 | } 48 | 49 | @Override 50 | public HudHorizontalAnchor getHorizontalAnchor() { 51 | return horizontalAnchor; 52 | } 53 | 54 | @Override 55 | public void setRealPosition(Point position) { 56 | xDifference = position.getX() - horizontalAnchor.getBaseValue(); 57 | yDifference = position.getY() - verticalAnchor.getBaseValue(); 58 | 59 | ConfigCallback.EVENT.invoker().saveConfig(this.getClass()); 60 | } 61 | 62 | @Override 63 | public Point getRealPosition() { 64 | return new Point( 65 | horizontalAnchor.getBaseValue() + xDifference, 66 | verticalAnchor.getBaseValue() + yDifference 67 | ); 68 | } 69 | 70 | @Override 71 | public void setRelativePosition(Point position) { 72 | xDifference = position.getX(); 73 | yDifference = position.getY(); 74 | 75 | ConfigCallback.EVENT.invoker().saveConfig(this.getClass()); 76 | } 77 | 78 | @Override 79 | public Point getRelativePosition() { 80 | return new Point(xDifference, yDifference); 81 | } 82 | 83 | @Override 84 | public int getHeight() { 85 | return height; 86 | } 87 | 88 | @Override 89 | public int getWidth() { 90 | return width; 91 | } 92 | 93 | @Override 94 | public HudElement getHudElement() { 95 | return hudElement; 96 | } 97 | 98 | @Override 99 | public void render(int var1, int var2, float var3) { 100 | Rectangle rectangle = hudElement.render(getRealPosition(), this); 101 | width = rectangle.getWidth(); 102 | height = rectangle.getHeight(); 103 | } 104 | 105 | @Override 106 | public void tick() { 107 | MinecraftClient minecraft = MinecraftClient.getInstance(); 108 | 109 | if (minecraft.player == null || minecraft.world == null) 110 | return; 111 | 112 | scriptContainer.getTrigger().check(); 113 | } 114 | 115 | @Override 116 | public ScriptContainer getScriptContainer() { 117 | return scriptContainer; 118 | } 119 | } 120 | --------------------------------------------------------------------------------