Actually start actions

This commit is contained in:
skippyall
2024-09-18 21:21:18 +02:00
parent d6a324a93f
commit 6526f92a67
8 changed files with 55 additions and 20 deletions
@@ -1,15 +1,10 @@
package io.github.skippyall.minions.command; package io.github.skippyall.minions.command;
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.network.packet.LoginPackets;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
public interface Command { public interface Command extends CommandExecutor {
Text getName(); Text getName();
Text getDescription(); Text getDescription();
Item getItemRepresentation(); Item getItemRepresentation();
void onRun(ServerPlayerEntity player, MinionFakePlayer minion);
} }
@@ -0,0 +1,8 @@
package io.github.skippyall.minions.command;
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
import net.minecraft.server.network.ServerPlayerEntity;
public interface CommandExecutor {
void execute(ServerPlayerEntity player, MinionFakePlayer minion);
}
@@ -5,20 +5,17 @@ import net.minecraft.item.Item;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class SimpleCommand implements Command { public class SimpleCommand implements Command {
private final Text name; private final Text name;
private final Text description; private final Text description;
private final Item itemRepresentation; private final Item itemRepresentation;
private final BiConsumer<ServerPlayerEntity, MinionFakePlayer> onRun; private final CommandExecutor executor;
public SimpleCommand(Text name, Text description, Item itemRepresentation, BiConsumer<ServerPlayerEntity, MinionFakePlayer> onRun) { public SimpleCommand(Text name, Text description, Item itemRepresentation, CommandExecutor executor) {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.itemRepresentation = itemRepresentation; this.itemRepresentation = itemRepresentation;
this.onRun = onRun; this.executor = executor;
} }
@Override @Override
@@ -37,7 +34,7 @@ public class SimpleCommand implements Command {
} }
@Override @Override
public void onRun(ServerPlayerEntity player, MinionFakePlayer minion) { public void execute(ServerPlayerEntity player, MinionFakePlayer minion) {
onRun.accept(player, minion); executor.execute(player, minion);
} }
} }
@@ -5,7 +5,6 @@ import eu.pb4.sgui.api.gui.SimpleGui;
import io.github.skippyall.minions.command.Command; import io.github.skippyall.minions.command.Command;
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer; import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
import io.github.skippyall.minions.module.ModuleItem; import io.github.skippyall.minions.module.ModuleItem;
import net.minecraft.item.Item;
import net.minecraft.screen.ScreenHandlerType; import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@@ -44,7 +43,7 @@ public class CommandsGui {
.setItem(command.getItemRepresentation()) .setItem(command.getItemRepresentation())
.setName(command.getName()) .setName(command.getName())
.addLoreLine(command.getDescription()) .addLoreLine(command.getDescription())
.setCallback(() -> command.onRun(player, minion)) .setCallback(() -> command.execute(player, minion))
); );
} }
@@ -4,13 +4,11 @@ import io.github.skippyall.minions.command.Command;
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer; import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
import io.github.skippyall.minions.module.ModuleItem; import io.github.skippyall.minions.module.ModuleItem;
import io.github.skippyall.minions.program.block.CodeBlock; import io.github.skippyall.minions.program.block.CodeBlock;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventories; import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.SimpleInventory; import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.RegistryWrapper;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory; import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@@ -52,7 +52,7 @@ public class ModuleInventoryScreenHandler extends ScreenHandler {
@Override @Override
public ItemStack quickMove(PlayerEntity player, int slot) { public ItemStack quickMove(PlayerEntity player, int slot) {
ItemStack itemStack = ItemStack.EMPTY; ItemStack itemStack = ItemStack.EMPTY;
Slot slot2 = (Slot)this.slots.get(slot); Slot slot2 = this.slots.get(slot);
if (slot2 != null && slot2.hasStack()) { if (slot2 != null && slot2.hasStack()) {
ItemStack itemStack2 = slot2.getStack(); ItemStack itemStack2 = slot2.getStack();
itemStack = itemStack2.copy(); itemStack = itemStack2.copy();
@@ -0,0 +1,34 @@
package io.github.skippyall.minions.module;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
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 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 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 CommandExecutor detailSelectionExecutor(EntityPlayerActionPack.ActionType actionType, Text actionName) {
return (player, minion) -> {
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
gui.setTitle(Text.translatable("minions.command.action.details", actionName));
gui.setSlot(1, new GuiElementBuilder()
.setItem(Items.COMMAND_BLOCK)
.setName(Text.translatable("minions.command.action.once", actionName))
.setCallback(() -> executeOnce(actionType, player, minion))
);
};
}
}
@@ -6,5 +6,9 @@
"minions.gui.inventory.title": "%s's Inventory", "minions.gui.inventory.title": "%s's Inventory",
"minions.gui.module_commands.title": "Commands", "minions.gui.module_commands.title": "Commands",
"minions.gui.commands.title": "%s's Commands", "minions.gui.commands.title": "%s's Commands",
"minions.gui.modules.title": "%s's Modules" "minions.gui.modules.title": "%s's Modules",
"minions.command.action.details": "Set how to %s",
"minions.command.action.once": "%s once",
"minions.command.action.continuous": "%s continuously",
"minions.command.action.interval": "%s every x seconds"
} }