Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .architectury-transformer/debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Architectury Transformer DEBUG] Closed File Systems for /home/elefant/engine/common/build/libs/playerengine-common-1.0.0.jar
4 changes: 4 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ dependencies {

// Architectury API. This is optional, and you can comment it out if you don't need it.
modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version"

// schematic parsing
implementation 'net.sandrohc:schematic4j:1.1.0'
include 'net.sandrohc:schematic4j:1.1.0'
}
80 changes: 74 additions & 6 deletions common/src/main/java/com/player2/playerengine/MCCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.player2.playerengine;

import java.util.UUID;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.mojang.brigadier.arguments.StringArgumentType;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
Expand All @@ -15,10 +20,15 @@
import org.apache.logging.log4j.Logger;
import dev.architectury.event.events.common.LifecycleEvent;
import net.minecraft.world.entity.player.Player;




import com.player2.playerengine.player2api.AgentSideEffects;
import net.minecraft.server.level.ServerPlayer;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.player2.playerengine.player2api.AgentConversationData;
import com.player2.playerengine.player2api.AgentSideEffects;
import com.player2.playerengine.player2api.Player2APIService;
import com.player2.playerengine.player2api.auth.AuthenticationManager;
import com.player2.playerengine.player2api.manager.ConversationManager;
import dev.architectury.event.events.common.LifecycleEvent;

public class MCCommands {

Expand All @@ -39,19 +49,77 @@ public static void register(MinecraftServer server) {
private static void registerFromDispatch(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("playerengine")
.then(registerRelog()));
.then(registerRelog())
.then(registerSummon())
.then(registerHelp()));
}
private static LiteralArgumentBuilder<CommandSourceStack> registerHelp() {
return Commands.literal("help")
.executes(context -> {
LOGGER.info("help command");
Player player = context.getSource().getPlayerOrException();

String message = """
Help: here are the following
- 'playerengine relog':
- 'help': displays this help
- 'tpto <username>': teleports you to AI
- 'list': lists AI usernames
""";

AgentSideEffects.broadcastChatToPlayer(player.level().getServer(), message, (ServerPlayer) player);
return 1;
});
}

private static LiteralArgumentBuilder<CommandSourceStack> registerRelog() {

return Commands.literal("relog")
.executes(context -> {
for (Player2APIService service : PlayerEngineController.staticAPIServices.values()) {
LOGGER.info("relog command");
String clientId = service.getClientId();
Player player = context.getSource().getPlayer();
Player player = context.getSource().getPlayerOrException();
AuthenticationManager.getInstance().invalidateToken(player, clientId);
}
return 1;
});
}


private static final SuggestionProvider<CommandSourceStack> NPC_SUGGEST = (context, builder) -> {
CommandSourceStack src = context.getSource();
Player player = src.getPlayerOrException();
UUID ownerUUID = player.getUUID();
String remaining = builder.getRemaining().toLowerCase();

for (AgentConversationData data : ConversationManager.getDataByOwner(ownerUUID)) {
String name = data.getName();

if (name.toLowerCase().startsWith(remaining)) {
builder.suggest(name);
}
}
return builder.buildFuture();
};
private static LiteralArgumentBuilder<CommandSourceStack> registerSummon() {
return Commands.literal("tpto")
.then(Commands.argument("username", StringArgumentType.string())
.suggests(NPC_SUGGEST)
.executes(context -> {
String username = StringArgumentType.getString(context, "username");
Player owner = context.getSource().getPlayerOrException();
UUID ownerUUID = owner.getUUID();
LOGGER.info("tpto command: {} {}", username, ownerUUID);
for (AgentConversationData data : ConversationManager.getDataByOwner(ownerUUID)) {
LOGGER.info("looking for name {}", data.getName());
if(data.getName().equals(username)){
LOGGER.info("Match on username: {}", username);
AgentSideEffects.teleportOwnerTo(data);
}
}
return 1;
}));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static void onInitializeClient() {
EntityRendererRegistry.register(PlayerEngine.FISHING_BOBBER, CustomFishingBobberRenderer::new);
STTUtils.onInitialize();
NetworkManager.registerReceiver(NetworkManager.Side.S2C, new ResourceLocation("playerengine", "stream_tts"), (buf, context) -> {
if(!enabledTTS){
return;
}
String clientId = buf.readUtf();
String token = buf.readUtf();
String text = buf.readUtf();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
package com.player2.playerengine;

import com.player2.playerengine.commands.AttackPlayerOrMobCommand;
import com.player2.playerengine.commands.BodyLanguageCommand;
import com.player2.playerengine.commands.BuildStructureCommand;
import com.player2.playerengine.commands.DepositCommand;
import com.player2.playerengine.commands.EquipCommand;
import com.player2.playerengine.commands.FarmCommand;
import com.player2.playerengine.commands.FishCommand;
import com.player2.playerengine.commands.FollowCommand;
import com.player2.playerengine.commands.FoodCommand;
import com.player2.playerengine.commands.GamerCommand;
import com.player2.playerengine.commands.GetCommand;
import com.player2.playerengine.commands.GiveCommand;
import com.player2.playerengine.commands.GotoCommand;
import com.player2.playerengine.commands.HeroCommand;
import com.player2.playerengine.commands.IdleCommand;
import com.player2.playerengine.commands.LocateStructureCommand;
import com.player2.playerengine.commands.MeatCommand;
import com.player2.playerengine.commands.ReloadSettingsCommand;
import com.player2.playerengine.commands.ResetMemoryCommand;
import com.player2.playerengine.commands.SetAIBridgeEnabledCommand;
import com.player2.playerengine.commands.StopCommand;
import com.player2.playerengine.commands.random.ScanCommand;
import com.player2.playerengine.commands.*;
import com.player2.playerengine.commands.*;
import com.player2.playerengine.commands.random.*;
import com.player2.playerengine.commands.base.CommandException;
import com.player2.playerengine.commands.SimpleExploreCommand;

public class PlayerEngineCommands {
public static void init(PlayerEngineController controller) throws CommandException {
Expand Down Expand Up @@ -51,6 +30,9 @@ public static void init(PlayerEngineController controller) throws CommandExcepti
new SetAIBridgeEnabledCommand(),
new FarmCommand(),
new SimpleExploreCommand(),
new EatFoodCommand(),
new SetHostileAttackCommand(),
new PickupDropsCommand(),
new FishCommand());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class PlayerEngineController {
public boolean isStopping = false;
private Player owner;
public static HashMap<UUID, Player2APIService> staticAPIServices = new HashMap<>();
private boolean shouldDefendFromHostiles = false;

public PlayerEngineController(IBaritone baritone, Character character, String player2GameId) {
this.baritone = baritone;
Expand Down Expand Up @@ -407,4 +408,12 @@ public Optional<ServerPlayer> getClosestPlayer() {
return Float.compare(adist, bdist);
}).findFirst();
}

public boolean getShouldDefendFromHostiles(){
return this.shouldDefendFromHostiles;
}

public void setShouldDefendFromHostiles(boolean toSet){
this.shouldDefendFromHostiles = toSet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void add(int food, float saturationModifier) {
this.foodSaturationLevel = Math.min(this.foodSaturationLevel + food * saturationModifier * 2.0F, (float)this.foodLevel);
}

public void eat(Item item, ItemStack stack) {
public void eat(Item item) {
if (item.isEdible()) {
FoodProperties foodComponent = item.getFoodProperties();
this.add(foodComponent.getNutrition(), foodComponent.getSaturationModifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ private static int getDangerousnessScore(List<LivingEntity> toDealWithList) {

@Override
public float getPriority() {
if(this.controller.getShouldDefendFromHostiles()){
return 0.0F;
}
this.cachedLastPriority = this.getPriorityInner();
if (this.getCurrentTask() == null) {
this.cachedLastPriority = 0.0F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,38 @@
import com.player2.playerengine.commands.base.CommandException;
import com.player2.playerengine.tasks.construction.build_structure.BuildStructureTask;

import net.minecraft.core.BlockPos;

public class BuildStructureCommand extends Command {
public BuildStructureCommand() throws CommandException {
super("build_structure",
"Agent can build any thing in Minecraft given the description and position. The description should be a string generated to capture a clear and concise summary of the structure the user asked to be built. Agent does not need to collect materials to build the structure when using this function.\\n"
"Agent can build any thing in Minecraft given a 3d coordinate, search query, and a description. The coordinates define the center bottom of the building. The search query comes first and should be a very brief query to search for a schematic that matches the build requirements. The description should be a longer (but still short) string generated to capture a clear and concise summary of the structure the user asked to be built. Agent does not need to collect materials to build the structure when using this function.\\n"
+ //
"IMPORTANT: The first 3 arguments should be the coordinates. If the player you are talking to doesn't give any hints on where to build it, put in that player's position as the first 3 arguments, or some positional information. You MUST start with the coordinates to build at. If you don't know the player's position, then put your own position. \\n"
+ //
"IMPORTANT: You must put a position into the description. If the player you are talking to doesn't give any hints on where to build it, put in that player's position into the description, or some positional information. You MUST give a coordiante to build at. If you don't know the player's position, then put your own position. \\n"
"IMPORTANT: The latter 2 arguments should be surrounded by quotes. That is how we separate the search query and the description from each other.\n"
+ //
" Example call would be `build_structure a gray modern house with a garden of roses in front of it. Build at position (-305, 406, 72)`",
new Arg<>(String.class, "description"));
" Example call would be `build_structure -305 406 72 \"gray modern house\" \"a gray modern house with a garden of roses in front of it.\"`",
// new Arg<>(String.class, "arguments")
new Arg<>(Integer.class, "x"),
new Arg<>(Integer.class, "y"),
new Arg<>(Integer.class, "x"),
new Arg<>(String.class, "search_query"),
new Arg<>(String.class, "description")
);
}

@Override
protected void call(PlayerEngineController mod, ArgParser parser) throws CommandException {
// String args = parser.get(String.class);
int x = parser.get(Integer.class);
int y = parser.get(Integer.class);
int z = parser.get(Integer.class);
String query = parser.get(String.class);
String description = parser.get(String.class);
mod.runUserTask(new BuildStructureTask(description, mod), () -> {
System.out.println("ASDF ARGS: " + x + ", " + y + ", " + z + ", " + query + ", " + description);
mod.runUserTask(new BuildStructureTask(new BlockPos(x, y, z), query, description, mod), () -> {
this.finish();
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.player2.playerengine.commands;

import com.player2.playerengine.PlayerEngineController;
import com.player2.playerengine.commands.base.ArgParser;
import com.player2.playerengine.commands.base.Command;
import com.player2.playerengine.commands.base.CommandException;
import com.player2.playerengine.tasks.misc.EatFoodTask;
import java.util.Optional;
import net.minecraft.world.item.Item;
import com.player2.playerengine.util.helpers.ItemHelper;
public class EatFoodCommand extends Command {
public EatFoodCommand() throws CommandException {
super("eat_food", "Eats food item from your inventory. ONLY CALL IF hunger < 20");
}

@Override
protected void call(PlayerEngineController controller, ArgParser parser) throws CommandException {
if(controller.getBaritone().getEntityContext().hungerManager().getFoodLevel() >= 20){
throw new CommandException("Tried to call eatFood, but hunger was too high. You may not eat if hunger is full.");
}

Item[] items;

if (parser.getArgUnits().length != 1) {
return;
}
String itemNameAsString = parser.getArgUnits()[0].toLowerCase();
Optional<Item> ma = ItemHelper.getItemFromString(itemNameAsString, ItemHelper.FOODS);
if(!ma.isPresent()){
return;
}
Item a = ma.get();
controller.runUserTask(new EatFoodTask(a), () -> this.finish());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.player2.playerengine.commands;

import com.player2.playerengine.PlayerEngineController;
import com.player2.playerengine.commands.base.Arg;
import com.player2.playerengine.commands.base.ArgParser;
import com.player2.playerengine.commands.base.Command;
import com.player2.playerengine.commands.base.CommandException;
import com.player2.playerengine.tasks.movement.PickupDroppedItemTask;
import com.player2.playerengine.util.ItemTarget;
public class PickupDropsCommand extends Command {
public PickupDropsCommand() throws CommandException {
super(
"pickup_drops",
"picks up all item drops nearby"
);
}

@Override
protected void call(PlayerEngineController mod, ArgParser parser) throws CommandException {
mod.runUserTask(new PickupDroppedItemTask(new ItemTarget[]{}, true), () -> this.finish());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.player2.playerengine.commands;

import com.player2.playerengine.PlayerEngineController;
import com.player2.playerengine.util.Debug;
import com.player2.playerengine.commands.base.Arg;
import com.player2.playerengine.commands.base.ArgParser;
import com.player2.playerengine.commands.base.Command;
import com.player2.playerengine.commands.base.CommandException;

public class SetHostileAttackCommand extends Command {
public SetHostileAttackCommand() throws CommandException {
super(
"set_attack_hostiles",
"will disable automatic attacking of hostiles. Only use when the user tells you to stop attacking/etc.",
new Arg<>(SetHostileAttackCommand.ToggleState.class, "onOrOff")
);
}

@Override
protected void call(PlayerEngineController mod, ArgParser parser) throws CommandException {
SetHostileAttackCommand.ToggleState toggle = parser.get(SetHostileAttackCommand.ToggleState.class);
switch (toggle) {
case ON:
Debug.logMessage(
"Enabling attack hostiles! You will now automatically attack nearby hostiles"
);
mod.setChatClefEnabled(true);
break;
case OFF:
Debug.logMessage("Disabling attack hostiles! You will NOT attack nearby hostiles automatically.");
mod.setChatClefEnabled(false);
}

this.finish();
}

public static enum ToggleState {
ON,
OFF;
}
}
Loading