3 Commits

Author SHA1 Message Date
skippyall 271d584161 Update ActionModules.java 2024-09-20 10:15:49 +02:00
skippyall 82dbf9ca95 Update ActionModules.java 2024-09-19 10:14:28 +02:00
skippyall 09a7b7c0ff Add stop(ActionType) 2024-09-19 10:10:57 +02:00
2 changed files with 44 additions and 3 deletions
@@ -159,6 +159,12 @@ public class EntityPlayerActionPack
return this;
}
public EntityPlayerActionPack stop(ActionType type) {
type.stop(player, actions.get(type));
actions.remove(type);
return this;
}
public EntityPlayerActionPack stopAll()
{
@@ -5,18 +5,38 @@ import eu.pb4.sgui.api.gui.SimpleGui;
import io.github.skippyall.minions.command.CommandExecutor;
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
import io.github.skippyall.minions.input.TextInput;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
public class ActionModules {
public static ModuleItem makeModule(EntityPlayerActionPack.ActionType actionType, Text actionName, Item vanillaItem, Text name, Text description) {
return new SimpleModuleItem(List.of(), List.of(new SimpleCommand(name, description, vanillaItem, detailSelectionExecutor(actionType, actionName))), vanillaItem);
}
public static void executeOnce(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.once());
}
public static void intervalExecutor(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.interval());
public static void executeInterval(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
TextInput.inputText(player, Text.translatable("minions.command.action.interval.enter_interval"), "1")
.thenAccept(string -> {
try {
int ticks = Integer.parseInt(string);
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.interval(ticks));
} catch (NumberFormatException ignored) {}
});
}
public static void executeContinuous(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.continuous());
}
public static void stop(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
minion.getMinionActionPack().stop(actionType);
}
public static CommandExecutor detailSelectionExecutor(EntityPlayerActionPack.ActionType actionType, Text actionName) {
@@ -24,11 +44,26 @@ public class ActionModules {
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
gui.setTitle(Text.translatable("minions.command.action.details", actionName));
gui.setSlot(1, new GuiElementBuilder()
gui.setSlot(3, new GuiElementBuilder()
.setItem(Items.COMMAND_BLOCK)
.setName(Text.translatable("minions.command.action.once", actionName))
.setCallback(() -> executeOnce(actionType, player, minion))
);
gui.setSlot(4, new GuiElementBuilder()
.setItem(Items.CHAIN_COMMAND_BLOCK)
.setName(Text.translatable("minions.command.action.interval", actionName))
.setCallback(() -> executeInterval(actionType, player, minion))
);
gui.setSlot(5, new GuiElementBuilder()
.setItem(Items.REPEATING_COMMAND_BLOCK)
.setName(Text.translatable("minions.command.action.continuous", actionName))
.setCallback(() -> executeContinuous())
);
gui.setSlot(7, new GuiElementBuilder()
.setItem(Items.BARRIER)
.setName(Text.translatable("minions.command.action.stop", actionName))
.setCallback(() -> stop(actionType, player, minion))
);
};
}
}