Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc6bbc448a | |||
| 9b61dba4c7 | |||
| 0382798a5d | |||
| 1e430ef506 | |||
| 5bd7c08f83 | |||
| 017b2ec590 | |||
| 382b394523 | |||
| 3f2a52fd0a | |||
| c5b3c883ca | |||
| b413592abf | |||
| cc1320d5c6 | |||
| da4351cff2 | |||
| 640e6f801a | |||
| bcfb406547 | |||
| b6f7bfc57b | |||
| e27b1698e4 | |||
| 216855d9c9 | |||
| e42e3adf84 | |||
| f5e0c1d426 |
@@ -1,5 +1,6 @@
|
|||||||
# User-specific stuff
|
# User-specific stuff
|
||||||
.idea/
|
.idea/
|
||||||
|
urlaub/
|
||||||
|
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
|
|||||||
+27
-12
@@ -1,21 +1,29 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.10-SNAPSHOT'
|
id 'net.fabricmc.fabric-loom-remap' version '1.14-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
version = project.mod_version
|
version = project.mod_version
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
loom {
|
|
||||||
accessWidenerPath = file("src/main/resources/minions.accesswidener")
|
|
||||||
}
|
|
||||||
|
|
||||||
base {
|
base {
|
||||||
archivesName = project.archives_base_name
|
archivesName = project.archives_base_name
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
accessWidenerPath = file("src/main/resources/minions.accesswidener")
|
accessWidenerPath = file("src/main/resources/minions.accesswidener")
|
||||||
|
splitEnvironmentSourceSets()
|
||||||
|
|
||||||
|
mods {
|
||||||
|
minions {
|
||||||
|
sourceSet sourceSets.main
|
||||||
|
sourceSet sourceSets.client
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runs.forEach {
|
||||||
|
it.vmArg("-XX:+AllowEnhancedClassRedefinition")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -47,10 +55,17 @@ dependencies {
|
|||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
modImplementation "eu.pb4:polymer-core:${project.polymer_version}"
|
modImplementation "eu.pb4:polymer-core:${project.polymer_version}"
|
||||||
|
modImplementation "eu.pb4:polymer-virtual-entity:${project.polymer_version}"
|
||||||
|
modImplementation "eu.pb4:polymer-resource-pack:${project.polymer_version}"
|
||||||
|
modLocalRuntime "eu.pb4:polymer-autohost:${project.polymer_version}"
|
||||||
modImplementation include("eu.pb4:sgui:${project.sgui_version}")
|
modImplementation include("eu.pb4:sgui:${project.sgui_version}")
|
||||||
modImplementation include("xyz.nucleoid:server-translations-api:${project.server_translations_version}")
|
modImplementation include("xyz.nucleoid:server-translations-api:${project.server_translations_version}")
|
||||||
|
|
||||||
|
implementation include("com.electronwill.night-config:toml:${project.night_config_version}")
|
||||||
|
compileOnly("io.netty:netty-codec-http:${project.netty_version}.Final")
|
||||||
|
|
||||||
modCompileOnly "maven.modrinth:universal-graves:${project.universal_graves_version}"
|
modCompileOnly "maven.modrinth:universal-graves:${project.universal_graves_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,14 +107,14 @@ java {
|
|||||||
|
|
||||||
jar {
|
jar {
|
||||||
from("LICENSE") {
|
from("LICENSE") {
|
||||||
rename { "${it}_${project.archivesBaseName}"}
|
rename { "${it}_${project.archives_base_name}"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure the maven publication
|
// configure the maven publication
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
minions (MavenPublication) {
|
maven (MavenPublication) {
|
||||||
from components.java
|
from components.java
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,14 +125,14 @@ publishing {
|
|||||||
// Notice: This block does NOT have the same function as the block in the top level.
|
// Notice: This block does NOT have the same function as the block in the top level.
|
||||||
// The repositories here will be used for publishing your artifact, not for
|
// The repositories here will be used for publishing your artifact, not for
|
||||||
// retrieving dependencies.
|
// retrieving dependencies.
|
||||||
|
if(project.hasProperty("foxgalaxy_user_name") && project.hasProperty("foxgalaxy_password")) {
|
||||||
maven {
|
maven {
|
||||||
def release = "https://maven.foxgalaxy.de/private-releases"
|
url = "https://maven.foxgalaxy.de/private"
|
||||||
def snapshot = "https://maven.foxgalaxy.de/private-snapshot"
|
|
||||||
url = version.endsWith('SNAPSHOT') ? snapshot : release
|
|
||||||
|
|
||||||
credentials {
|
credentials {
|
||||||
username = "${maven_user}"
|
username = project.property("foxgalaxy_user_name")
|
||||||
password = "${maven_password}"
|
password = project.property("foxgalaxy_password")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
yarn_mappings=1.21.7+build.2
|
yarn_mappings=1.21.7+build.2
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.2.1-SNAPSHOT
|
mod_version = 1.0.0-SNAPSHOT-1
|
||||||
maven_group = io.github.skippyall
|
maven_group = io.github.skippyall
|
||||||
archives_base_name = Minions
|
archives_base_name = Minions
|
||||||
|
|
||||||
@@ -20,4 +20,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
sgui_version=1.10.0+1.21.6
|
sgui_version=1.10.0+1.21.6
|
||||||
server_translations_version=2.5.1+1.21.5
|
server_translations_version=2.5.1+1.21.5
|
||||||
|
|
||||||
|
night_config_version=3.8.3
|
||||||
|
netty_version=4.1.130
|
||||||
|
|
||||||
universal_graves_version=3.8.0+1.21.6
|
universal_graves_version=3.8.0+1.21.6
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package io.github.skippyall.minions.client;
|
||||||
|
|
||||||
|
import eu.pb4.polymer.networking.api.client.PolymerClientNetworking;
|
||||||
|
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||||
|
import io.github.skippyall.minions.util.PolymerUtil;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.client.rendering.v1.BlockRenderLayerMap;
|
||||||
|
import net.minecraft.client.render.BlockRenderLayer;
|
||||||
|
|
||||||
|
public class MinionsClient implements ClientModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
BlockRenderLayerMap.putBlock(MinionBlocks.MINION_TRIGGER_BLOCK, BlockRenderLayer.TRANSLUCENT);
|
||||||
|
|
||||||
|
PolymerClientNetworking.registerCommonHandler(PolymerUtil.VersionSyncPayload.class, (client, handler, payload) -> {});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package io.github.skippyall.minions;
|
|
||||||
|
|
||||||
import eu.pb4.polymer.core.api.item.SimplePolymerItem;
|
|
||||||
import io.github.skippyall.minions.minion.MinionItem;
|
|
||||||
import io.github.skippyall.minions.module.Modules;
|
|
||||||
import net.minecraft.component.DataComponentTypes;
|
|
||||||
import net.minecraft.component.type.DamageResistantComponent;
|
|
||||||
import net.minecraft.entity.damage.DamageType;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.registry.Registries;
|
|
||||||
import net.minecraft.registry.Registry;
|
|
||||||
import net.minecraft.registry.RegistryKey;
|
|
||||||
import net.minecraft.registry.RegistryKeys;
|
|
||||||
import net.minecraft.registry.tag.TagKey;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.Minions.MOD_ID;
|
|
||||||
|
|
||||||
public class MinionItems {
|
|
||||||
public static final TagKey<DamageType> MINION_ITEM_RESISTS = TagKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of(MOD_ID, "minion_item_resists"));
|
|
||||||
public static final MinionItem MINION_ITEM = registerItem(Identifier.of(MOD_ID, "minion"), settings -> new MinionItem(settings.component(DataComponentTypes.DAMAGE_RESISTANT, new DamageResistantComponent(MINION_ITEM_RESISTS))));
|
|
||||||
public static final SimplePolymerItem BASIC_UPGRADE_BASE = registerItem(Identifier.of(MOD_ID, "basic_upgrade_base"), settings -> new SimplePolymerItem(settings, Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE));
|
|
||||||
public static final SimplePolymerItem ADVANCED_UPGRADE_BASE = registerItem(Identifier.of(MOD_ID, "advanced_upgrade_base"), settings -> new SimplePolymerItem(settings, Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE));
|
|
||||||
|
|
||||||
|
|
||||||
public static <T extends Item> T registerItem(Identifier identifier, Function<Item.Settings, T> constructor, Item.Settings settings) {
|
|
||||||
T item = constructor.apply(settings.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
|
|
||||||
|
|
||||||
MinionCreativeTab.add(item);
|
|
||||||
|
|
||||||
return Registry.register(Registries.ITEM, identifier, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends Item> T registerItem(Identifier identifier, Function<Item.Settings, T> constructor) {
|
|
||||||
return registerItem(identifier, constructor, new Item.Settings());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void register() {
|
|
||||||
Modules.register();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package io.github.skippyall.minions;
|
||||||
|
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||||
|
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class MinionMixinConfigPlugin implements IMixinConfigPlugin {
|
||||||
|
@Override
|
||||||
|
public void onLoad(String mixinPackage) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRefMapperConfig() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||||
|
if(mixinClassName.startsWith("io.github.skippyall.mixins.compat.universal_graves.")) {
|
||||||
|
return MinionsConfig.get().compat.enableGravesCompat && FabricLoader.getInstance().isModLoaded("universal-graves");
|
||||||
|
}
|
||||||
|
if(mixinClassName.startsWith("io.github.skippyall.mixins.antimobcap.")) {
|
||||||
|
return MinionsConfig.get().minion.enableMobCapHacks;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getMixins() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package io.github.skippyall.minions;
|
package io.github.skippyall.minions;
|
||||||
|
|
||||||
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||||
import io.github.skippyall.minions.command.MinionsCommand;
|
import io.github.skippyall.minions.command.MinionsCommand;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.minion.MinionData;
|
|
||||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
|
import io.github.skippyall.minions.registration.MinionRegistration;
|
||||||
|
import io.github.skippyall.minions.util.PolymerUtil;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
@@ -18,23 +19,28 @@ public class Minions implements ModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
MinionData.register();
|
MinionsConfig.get();
|
||||||
PolymerEntityUtils.registerType();
|
|
||||||
|
MinionRegistration.register();
|
||||||
|
|
||||||
|
PolymerUtil.register();
|
||||||
|
|
||||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||||
LOGGER.error("Initializing Minion data");
|
MinionPersistentState.get(server).getMinionData().forEach((uuid, data) -> {
|
||||||
MinionPersistentState.create(server);
|
|
||||||
MinionPersistentState.INSTANCE.getMinionData().forEach((uuid, data) -> {
|
|
||||||
if(data.isSpawned()) {
|
if(data.isSpawned()) {
|
||||||
MinionFakePlayer.spawnMinion(data, server.getOverworld(), null, null, true);
|
MinionFakePlayer.spawnMinion(data, server.getOverworld(), null, null, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
CommandRegistrationCallback.EVENT.register((commandDispatcher, commandRegistryAccess, registrationEnvironment) -> {
|
CommandRegistrationCallback.EVENT.register(MinionsCommand::register);
|
||||||
MinionsCommand.register(commandDispatcher);
|
|
||||||
});
|
|
||||||
|
|
||||||
MinionItems.register();
|
/*ServerBlockEntityEvents.BLOCK_ENTITY_LOAD.register((blockEntity, world) -> {
|
||||||
MinionCreativeTab.registerGroup();
|
if(blockEntity instanceof MinionTriggerBlockEntity) {
|
||||||
|
world.updateComparators(blockEntity.getPos(), MinionBlocks.MINION_TRIGGER_BLOCK);
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
|
||||||
|
PolymerResourcePackUtils.addModAssets(Minions.MOD_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package io.github.skippyall.minions;
|
||||||
|
|
||||||
|
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||||
|
import com.electronwill.nightconfig.core.io.ParsingException;
|
||||||
|
import com.electronwill.nightconfig.core.io.WritingException;
|
||||||
|
import com.electronwill.nightconfig.core.io.WritingMode;
|
||||||
|
import com.electronwill.nightconfig.core.serde.ObjectDeserializer;
|
||||||
|
import com.electronwill.nightconfig.core.serde.ObjectSerializer;
|
||||||
|
import com.electronwill.nightconfig.core.serde.SerdeException;
|
||||||
|
import com.electronwill.nightconfig.core.serde.annotations.SerdeComment;
|
||||||
|
import com.electronwill.nightconfig.core.serde.annotations.SerdeSkipDeserializingIf;
|
||||||
|
import com.electronwill.nightconfig.toml.TomlFormat;
|
||||||
|
import com.electronwill.nightconfig.toml.TomlParser;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import static com.electronwill.nightconfig.core.serde.annotations.SerdeSkipDeserializingIf.SkipDeIf.IS_MISSING;
|
||||||
|
|
||||||
|
public class MinionsConfig {
|
||||||
|
private static MinionsConfig INSTANCE;
|
||||||
|
|
||||||
|
@SerdeSkipDeserializingIf(IS_MISSING)
|
||||||
|
public Minion minion = new Minion();
|
||||||
|
|
||||||
|
public static class Minion {
|
||||||
|
@SerdeComment("The prefix for all minion names")
|
||||||
|
@SerdeSkipDeserializingIf(IS_MISSING)
|
||||||
|
public String minionPrefix = "+";
|
||||||
|
|
||||||
|
@SerdeComment("Makes minions not raise the mob cap if they can't spawn mobs.")
|
||||||
|
@SerdeComment("Might cause incompatibilities.")
|
||||||
|
@SerdeSkipDeserializingIf(IS_MISSING)
|
||||||
|
public boolean enableMobCapHacks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SerdeSkipDeserializingIf(IS_MISSING)
|
||||||
|
public Compat compat = new Compat();
|
||||||
|
|
||||||
|
public static class Compat {
|
||||||
|
@SerdeComment("Enables compat with Universal Graves, which allows everyone to pick up graves from minions")
|
||||||
|
@SerdeSkipDeserializingIf(IS_MISSING)
|
||||||
|
public boolean enableGravesCompat = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Path getPath() {
|
||||||
|
Path minionsDir = FabricLoader.getInstance().getConfigDir().resolve("minions");
|
||||||
|
if(!Files.isDirectory(minionsDir)) {
|
||||||
|
try {
|
||||||
|
Files.createDirectory(minionsDir);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Minions.LOGGER.error("Could not create config dir", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return minionsDir.resolve(Minions.MOD_ID + ".toml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinionsConfig get() {
|
||||||
|
if(INSTANCE == null) {
|
||||||
|
loadConfig();
|
||||||
|
}
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadConfig() {
|
||||||
|
try {
|
||||||
|
CommentedConfig config = new TomlParser().parse(getPath(), (file, configFormat) -> {
|
||||||
|
CommentedConfig defaultConfig = ObjectSerializer.standard().serializeFields(new MinionsConfig(), TomlFormat::newConfig);
|
||||||
|
configFormat.createWriter().write(defaultConfig, file, WritingMode.REPLACE);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
INSTANCE = ObjectDeserializer.standard().deserializeFields(config, MinionsConfig::new);
|
||||||
|
} catch (SerdeException | ParsingException | WritingException e) {
|
||||||
|
Minions.LOGGER.error("Error while reading config", e);
|
||||||
|
INSTANCE = new MinionsConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public static void saveConfig() {
|
||||||
|
try {
|
||||||
|
CommentedConfig config = ObjectSerializer.standard().serializeFields(INSTANCE, TomlFormat::newConfig);
|
||||||
|
new TomlWriter().write(config, getPath(), WritingMode.REPLACE);
|
||||||
|
} catch (SerdeException | ParsingException | WritingException e) {
|
||||||
|
System.out.println("[minions] Error while writing config");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
+177
@@ -0,0 +1,177 @@
|
|||||||
|
package io.github.skippyall.minions.block.miniontrigger;
|
||||||
|
|
||||||
|
import com.mojang.serialization.MapCodec;
|
||||||
|
import eu.pb4.polymer.core.api.block.PolymerBlock;
|
||||||
|
import eu.pb4.polymer.core.api.utils.PolymerClientDecoded;
|
||||||
|
import eu.pb4.polymer.core.api.utils.PolymerKeepModel;
|
||||||
|
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||||
|
import eu.pb4.polymer.virtualentity.api.BlockWithElementHolder;
|
||||||
|
import eu.pb4.polymer.virtualentity.api.ElementHolder;
|
||||||
|
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
|
||||||
|
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
|
import io.github.skippyall.minions.clipboard.InstructionClipboard;
|
||||||
|
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||||
|
import io.github.skippyall.minions.util.PolymerUtil;
|
||||||
|
import net.minecraft.block.AbstractRedstoneGateBlock;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.BlockWithEntity;
|
||||||
|
import net.minecraft.block.ShapeContext;
|
||||||
|
import net.minecraft.block.SideShapeType;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.component.DataComponentTypes;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.sound.SoundCategory;
|
||||||
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
import net.minecraft.state.StateManager;
|
||||||
|
import net.minecraft.state.property.BooleanProperty;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
|
import net.minecraft.world.BlockView;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldView;
|
||||||
|
import net.minecraft.world.block.WireOrientation;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import xyz.nucleoid.packettweaker.PacketContext;
|
||||||
|
|
||||||
|
public class MinionTriggerBlock extends BlockWithEntity implements PolymerBlock, PolymerKeepModel, PolymerClientDecoded, BlockWithElementHolder {
|
||||||
|
public static final MapCodec<MinionTriggerBlock> CODEC = createCodec(MinionTriggerBlock::new);
|
||||||
|
|
||||||
|
public static final BooleanProperty POWERED = BooleanProperty.of("powered");
|
||||||
|
public static final VoxelShape SHAPE = Block.createColumnShape(16.0, 0.0, 2.0);
|
||||||
|
|
||||||
|
public MinionTriggerBlock(Settings settings) {
|
||||||
|
super(settings);
|
||||||
|
setDefaultState(getDefaultState().with(POWERED, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||||
|
return SHAPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||||
|
BlockPos blockPos = pos.down();
|
||||||
|
return this.canPlaceAbove(world, blockPos, world.getBlockState(blockPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean canPlaceAbove(WorldView world, BlockPos pos, BlockState state) {
|
||||||
|
return state.isSideSolid(world, pos, Direction.UP, SideShapeType.RIGID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStateReplaced(BlockState state, ServerWorld world, BlockPos pos, boolean moved) {
|
||||||
|
super.onStateReplaced(state, world, pos, moved);
|
||||||
|
world.getBlockEntity(pos, MinionBlocks.MINION_TRIGGER_BE_TYPE).ifPresent(MinionTriggerBlockEntity::removeListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||||
|
builder.add(POWERED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
|
if(stack.get(MinionComponentTypes.REFERENCE) instanceof InstructionClipboard instruction) {
|
||||||
|
world.getBlockEntity(pos, MinionBlocks.MINION_TRIGGER_BE_TYPE).ifPresent(be -> {
|
||||||
|
be.setInstruction(instruction.selectedMinion(), instruction.selectedInstruction());
|
||||||
|
player.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_CHIME.value(), SoundCategory.BLOCKS, 1, 1);
|
||||||
|
stack.decrement(1);
|
||||||
|
});
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
||||||
|
if(world.isClient()) {
|
||||||
|
return ActionResult.CONSUME;
|
||||||
|
}
|
||||||
|
|
||||||
|
world.getBlockEntity(pos, MinionBlocks.MINION_TRIGGER_BE_TYPE).ifPresent(be -> {
|
||||||
|
String name = MinionPersistentState.get(world.getServer()).getMinionData(be.getMinionUuid()).name();
|
||||||
|
player.sendMessage(Text.translatable("minions.reference.instruction.tooltip", name, be.getInstructionName()), true);
|
||||||
|
});
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, @Nullable WireOrientation wireOrientation, boolean notify) {
|
||||||
|
if(!canPlaceAt(state, world, pos)) {
|
||||||
|
dropStacks(state, world, pos);
|
||||||
|
world.removeBlock(pos, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean newPower = world.isReceivingRedstonePower(pos);
|
||||||
|
if(state.get(POWERED) != newPower) {
|
||||||
|
world.setBlockState(pos, state.with(POWERED, newPower));
|
||||||
|
world.getBlockEntity(pos, MinionBlocks.MINION_TRIGGER_BE_TYPE).ifPresent(MinionTriggerBlockEntity::updatePower);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean hasComparatorOutput(BlockState state) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getComparatorOutput(BlockState state, World world, BlockPos pos) {
|
||||||
|
return world.getBlockEntity(pos, MinionBlocks.MINION_TRIGGER_BE_TYPE).map(MinionTriggerBlockEntity::getComparatorOutput).orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MapCodec<? extends BlockWithEntity> getCodec() {
|
||||||
|
return CODEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
return new MinionTriggerBlockEntity(pos, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
|
||||||
|
return PolymerUtil.isOnClient(context) ? state : net.minecraft.block.Blocks.COMPARATOR.getDefaultState().with(AbstractRedstoneGateBlock.POWERED, state.get(POWERED));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleMiningOnServer(ItemStack tool, BlockState state, BlockPos pos, ServerPlayerEntity player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
|
||||||
|
ElementHolder holder = new ElementHolder() {
|
||||||
|
@Override
|
||||||
|
public boolean startWatching(ServerPlayNetworkHandler player) {
|
||||||
|
if(PolymerResourcePackUtils.hasMainPack(player)) {
|
||||||
|
return super.startWatching(player);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ItemStack stack = new ItemStack(Items.BARRIER);
|
||||||
|
stack.set(DataComponentTypes.ITEM_MODEL, Identifier.of(Minions.MOD_ID, "minion_trigger_no_plate_" + (initialBlockState.get(MinionTriggerBlock.POWERED) ? "active" : "inactive")));
|
||||||
|
|
||||||
|
holder.addElement(new ItemDisplayElement(stack));
|
||||||
|
return holder;
|
||||||
|
}
|
||||||
|
}
|
||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
package io.github.skippyall.minions.block.miniontrigger;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.listener.BlockEntityMinionListener;
|
||||||
|
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
import net.minecraft.util.Uuids;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MinionTriggerBlockEntity extends BlockEntity {
|
||||||
|
private UUID minionUuid;
|
||||||
|
private String instructionName = "";
|
||||||
|
|
||||||
|
public MinionTriggerBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
super(MinionBlocks.MINION_TRIGGER_BE_TYPE, pos, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeListener() {
|
||||||
|
MinionTriggerMinionListener.removeListener(world, pos, minionUuid, instructionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListener() {
|
||||||
|
MinionTriggerMinionListener.addListener(world, pos, minionUuid, instructionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstruction(UUID minionUuid, String instructionName) {
|
||||||
|
removeListener();
|
||||||
|
this.minionUuid = minionUuid;
|
||||||
|
this.instructionName = instructionName;
|
||||||
|
addListener();
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePower() {
|
||||||
|
boolean powered = getCachedState().get(MinionTriggerBlock.POWERED);
|
||||||
|
|
||||||
|
MinionTriggerMinionListener listener = getListener();
|
||||||
|
if(listener != null) {
|
||||||
|
listener.incomingPowerCache = powered;
|
||||||
|
}
|
||||||
|
|
||||||
|
getMinion().ifPresent(minion -> {
|
||||||
|
getInstruction().ifPresent(instruction -> {
|
||||||
|
if(powered) {
|
||||||
|
instruction.run(minion.getInstructionManager());
|
||||||
|
} else {
|
||||||
|
instruction.stop(minion.getInstructionManager());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getComparatorOutput() {
|
||||||
|
MinionTriggerMinionListener listener = getListener();
|
||||||
|
if(listener != null && listener.runningCache) {
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<MinionFakePlayer> getMinion() {
|
||||||
|
if(minionUuid != null && world != null && world.getPlayerByUuid(minionUuid) instanceof MinionFakePlayer minion) {
|
||||||
|
return Optional.of(minion);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getMinionUuid() {
|
||||||
|
return minionUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInstructionName() {
|
||||||
|
return instructionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ConfiguredInstruction<MinionRuntime>> getInstruction(MinionFakePlayer minion) {
|
||||||
|
return Optional.ofNullable(minion.getInstructionManager().getInstruction(instructionName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ConfiguredInstruction<MinionRuntime>> getInstruction() {
|
||||||
|
return getMinion().flatMap(this::getInstruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionTriggerMinionListener getListener() {
|
||||||
|
return BlockEntityMinionListener.getListener(world, pos, minionUuid, MinionTriggerMinionListener.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readData(ReadView view) {
|
||||||
|
minionUuid = view.read("minionUuid", Uuids.CODEC).orElse(null);
|
||||||
|
instructionName = view.getString("instructionName", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeData(WriteView view) {
|
||||||
|
if(minionUuid != null) {
|
||||||
|
view.put("minionUuid", Uuids.CODEC, minionUuid);
|
||||||
|
}
|
||||||
|
view.putString("instructionName", instructionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package io.github.skippyall.minions.block.miniontrigger;
|
||||||
|
|
||||||
|
import eu.pb4.polymer.core.api.item.PolymerBlockItem;
|
||||||
|
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import xyz.nucleoid.packettweaker.PacketContext;
|
||||||
|
|
||||||
|
public class MinionTriggerBlockItem extends PolymerBlockItem {
|
||||||
|
public MinionTriggerBlockItem(Block block, Settings settings, Item polymerItem) {
|
||||||
|
super(block, settings, polymerItem, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||||
|
if(PolymerResourcePackUtils.hasMainPack(context)) {
|
||||||
|
return super.getPolymerItemModel(stack, context);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+126
@@ -0,0 +1,126 @@
|
|||||||
|
package io.github.skippyall.minions.block.miniontrigger;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.listener.BlockEntityMinionInstructionListener;
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstructionListener;
|
||||||
|
import net.minecraft.registry.RegistryKey;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.Uuids;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MinionTriggerMinionListener extends BlockEntityMinionInstructionListener<MinionTriggerBlockEntity> {
|
||||||
|
public static final Codec<MinionTriggerMinionListener> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
|
instance.group(
|
||||||
|
World.CODEC.fieldOf("world").forGetter(listener -> listener.worldKey),
|
||||||
|
BlockPos.CODEC.fieldOf("pos").forGetter(listener -> listener.pos),
|
||||||
|
Uuids.CODEC.fieldOf("minionUuid").forGetter(listener -> listener.minionUuid),
|
||||||
|
Codec.STRING.fieldOf("instructionName").forGetter(listener -> listener.instructionName)
|
||||||
|
).apply(instance, MinionTriggerMinionListener::new));
|
||||||
|
|
||||||
|
String instructionName;
|
||||||
|
final TriggerInstructionListener listener = new TriggerInstructionListener();
|
||||||
|
|
||||||
|
boolean runningCache;
|
||||||
|
boolean incomingPowerCache;
|
||||||
|
|
||||||
|
private MinionTriggerMinionListener(RegistryKey<World> worldKey, BlockPos pos, UUID minionUuid, String instructionName) {
|
||||||
|
super(worldKey, pos, minionUuid, MinionBlocks.MINION_TRIGGER_BE_TYPE);
|
||||||
|
this.instructionName = Objects.requireNonNull(instructionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addListener(World world, BlockPos pos, UUID minion, String instructionName) {
|
||||||
|
MinionTriggerMinionListener listener = new MinionTriggerMinionListener(world.getRegistryKey(), pos, minion, instructionName);
|
||||||
|
listener.add(world.getServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeListener(World world, BlockPos pos, UUID minion, String instructionName) {
|
||||||
|
MinionTriggerMinionListener old = getListener(world, pos, minion, MinionTriggerMinionListener.class);
|
||||||
|
if(old != null) {
|
||||||
|
old.remove(world.getServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, ConfiguredInstructionListener> getInstructionListeners() {
|
||||||
|
return Map.of(instructionName, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMinionSpawn(MinionFakePlayer minion) {
|
||||||
|
super.onMinionSpawn(minion);
|
||||||
|
runningCache = minion.getInstructionManager().getInstruction(instructionName).isRunning();
|
||||||
|
updateComparatorsIfLoaded(minion.getServer());
|
||||||
|
|
||||||
|
ConfiguredInstruction<MinionRuntime> instruction = minion.getInstructionManager().getInstruction(instructionName);
|
||||||
|
if(instruction.isRunning() && !incomingPowerCache) {
|
||||||
|
instruction.stop(minion.getInstructionManager());
|
||||||
|
} else if (!instruction.isRunning() && incomingPowerCache) {
|
||||||
|
instruction.run(minion.getInstructionManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMinionRemove(MinionFakePlayer minion) {
|
||||||
|
super.onMinionRemove(minion);
|
||||||
|
runningCache = false;
|
||||||
|
updateComparatorsIfLoaded(minion.getServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInstructionRename(MinionFakePlayer minion, ConfiguredInstruction<?> instruction, String oldName, String newName) {
|
||||||
|
super.onInstructionRename(minion, instruction, oldName, newName);
|
||||||
|
if(instructionName.equals(oldName)) {
|
||||||
|
instructionName = newName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void add(MinecraftServer server) {
|
||||||
|
super.add(server);
|
||||||
|
runningCache = minion.getInstructionManager().getInstruction(instructionName).isRunning();
|
||||||
|
updateComparatorsIfLoaded(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Identifier> getCodecId() {
|
||||||
|
return Optional.of(Identifier.of(Minions.MOD_ID, "minion_trigger"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateComparatorsIfLoaded(MinecraftServer server) {
|
||||||
|
World world = server.getWorld(worldKey);
|
||||||
|
if(world.isPosLoaded(pos)) {
|
||||||
|
world.updateComparators(pos, MinionBlocks.MINION_TRIGGER_BLOCK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return runningCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TriggerInstructionListener implements ConfiguredInstructionListener {
|
||||||
|
@Override
|
||||||
|
public void onRun(ConfiguredInstruction<?> instruction) {
|
||||||
|
runningCache = true;
|
||||||
|
updateComparatorsIfLoaded(minion.getServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop(ConfiguredInstruction<?> instruction) {
|
||||||
|
runningCache = false;
|
||||||
|
updateComparatorsIfLoaded(minion.getServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package io.github.skippyall.minions.clipboard;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.MapCodec;
|
||||||
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
|
import net.minecraft.item.tooltip.TooltipAppender;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public interface Clipboard extends TooltipAppender {
|
||||||
|
Codec<Clipboard> CODEC = MinionRegistries.CLIPBOARD_TYPES.getCodec().dispatch(Clipboard::getCodec, Function.identity());
|
||||||
|
|
||||||
|
MapCodec<? extends Clipboard> getCodec();
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package io.github.skippyall.minions.clipboard;
|
||||||
|
|
||||||
|
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||||
|
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||||
|
import io.github.skippyall.minions.registration.MinionItems;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.component.DataComponentTypes;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.item.tooltip.TooltipType;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import xyz.nucleoid.packettweaker.PacketContext;
|
||||||
|
|
||||||
|
public class ClipboardItem extends Item implements PolymerItem {
|
||||||
|
public ClipboardItem(Settings settings) {
|
||||||
|
super(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getPolymerItem(ItemStack itemStack, PacketContext context) {
|
||||||
|
return Items.PAPER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getPolymerItemStack(ItemStack itemStack, TooltipType tooltipType, PacketContext context) {
|
||||||
|
ItemStack stack = PolymerItem.super.getPolymerItemStack(itemStack, tooltipType, context);
|
||||||
|
stack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createInstructionReference(MinionFakePlayer minion, String instructionName) {
|
||||||
|
ItemStack stack = new ItemStack(MinionItems.REFERENCE_ITEM);
|
||||||
|
stack.set(MinionComponentTypes.REFERENCE, new InstructionClipboard(minion.getUuid(), instructionName, minion.getGameProfile().getName()));
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package io.github.skippyall.minions.clipboard;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.MapCodec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import net.minecraft.component.ComponentsAccess;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.tooltip.TooltipType;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Uuids;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public record InstructionClipboard(UUID selectedMinion, String selectedInstruction, String visualMinionName) implements Clipboard {
|
||||||
|
public static final MapCodec<InstructionClipboard> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||||
|
instance.group(
|
||||||
|
Uuids.CODEC.fieldOf("selectedMinion").forGetter(InstructionClipboard::selectedMinion),
|
||||||
|
Codec.STRING.fieldOf("selectedInstruction").forGetter(InstructionClipboard::selectedInstruction),
|
||||||
|
Codec.STRING.fieldOf("visualMinionName").forGetter(InstructionClipboard::visualMinionName)
|
||||||
|
).apply(instance, InstructionClipboard::new));
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MapCodec<? extends Clipboard> getCodec() {
|
||||||
|
return CODEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appendTooltip(Item.TooltipContext context, Consumer<Text> textConsumer, TooltipType type, ComponentsAccess components) {
|
||||||
|
textConsumer.accept(Text.translatable("minions.reference.instruction.tooltip", selectedInstruction, visualMinionName));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ public class ListSubcommand {
|
|||||||
.executes(ListSubcommand::list);
|
.executes(ListSubcommand::list);
|
||||||
|
|
||||||
public static int list(CommandContext<ServerCommandSource> context) {
|
public static int list(CommandContext<ServerCommandSource> context) {
|
||||||
Collection<MinionData> minions = MinionPersistentState.INSTANCE.getMinionData().values();
|
Collection<MinionData> minions = MinionPersistentState.get(context.getSource().getServer()).getMinionData().values();
|
||||||
for (MinionData minion : minions) {
|
for (MinionData minion : minions) {
|
||||||
context.getSource().sendFeedback(() -> Text.literal(minion.name() + "(" + minion.uuid() + "):" + minion.isSpawned()), false);
|
context.getSource().sendFeedback(() -> Text.literal(minion.name() + "(" + minion.uuid() + "):" + minion.isSpawned()), false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
|||||||
import io.github.skippyall.minions.minion.MinionData;
|
import io.github.skippyall.minions.minion.MinionData;
|
||||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
@@ -21,13 +22,13 @@ public class MinionArgument {
|
|||||||
|
|
||||||
public static final MinionSuggestionProvider SUGGESTION_PROVIDER = new MinionSuggestionProvider();
|
public static final MinionSuggestionProvider SUGGESTION_PROVIDER = new MinionSuggestionProvider();
|
||||||
|
|
||||||
public static MinionData parse(String argument) throws CommandSyntaxException {
|
public static MinionData parse(MinecraftServer server, String argument) throws CommandSyntaxException {
|
||||||
Optional<MinionData> data = Optional.empty();
|
Optional<MinionData> data = Optional.empty();
|
||||||
if(argument.startsWith(MinionProfileUtils.PREFIX)) {
|
if(argument.startsWith(MinionProfileUtils.getPrefix())) {
|
||||||
data = MinionPersistentState.INSTANCE.getMinionWithName(argument);
|
data = MinionPersistentState.get(server).getMinionWithName(argument);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
data = Optional.ofNullable(MinionPersistentState.INSTANCE.getMinionData(UUID.fromString(argument)));
|
data = Optional.ofNullable(MinionPersistentState.get(server).getMinionData(UUID.fromString(argument)));
|
||||||
} catch (IllegalArgumentException ignored) {}
|
} catch (IllegalArgumentException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ public class MinionArgument {
|
|||||||
public static class MinionSuggestionProvider implements SuggestionProvider<ServerCommandSource> {
|
public static class MinionSuggestionProvider implements SuggestionProvider<ServerCommandSource> {
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
|
public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
|
||||||
for (MinionData data : MinionPersistentState.INSTANCE.getMinionDataList()) {
|
for (MinionData data : MinionPersistentState.get(context.getSource().getServer()).getMinionDataList()) {
|
||||||
builder.suggest(data.name());
|
builder.suggest(data.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,26 @@
|
|||||||
package io.github.skippyall.minions.command;
|
package io.github.skippyall.minions.command;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import io.github.skippyall.minions.MinionsConfig;
|
||||||
|
import net.minecraft.command.CommandRegistryAccess;
|
||||||
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
|
||||||
public class MinionsCommand {
|
public class MinionsCommand {
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess access, CommandManager.RegistrationEnvironment environment) {
|
||||||
dispatcher.register(
|
LiteralArgumentBuilder<ServerCommandSource> builder = literal("minions")
|
||||||
literal("minions")
|
|
||||||
.then(SpawnSubcommand.SPAWN)
|
.then(SpawnSubcommand.SPAWN)
|
||||||
.then(MobCapDebugSubcommand.MOB_CAP_DEBUG)
|
.then(ListSubcommand.LIST);
|
||||||
.then(ListSubcommand.LIST)
|
|
||||||
);
|
if(MinionsConfig.get().minion.enableMobCapHacks) {
|
||||||
|
builder.then(MobCapDebugSubcommand.MOB_CAP_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispatcher.register(
|
||||||
|
builder
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package io.github.skippyall.minions.command;
|
|||||||
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkLevelManagerAccessor;
|
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManagerAccessor;
|
||||||
import io.github.skippyall.minions.mixins.antimobcap.ServerChunkManagerAccessor;
|
import io.github.skippyall.minions.mixins.antimobcap.ServerChunkManagerAccessor;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
@@ -16,8 +16,8 @@ public class MobCapDebugSubcommand {
|
|||||||
.executes(MobCapDebugSubcommand::mobcapdebugCommand);
|
.executes(MobCapDebugSubcommand::mobcapdebugCommand);
|
||||||
|
|
||||||
public static int mobcapdebugCommand(CommandContext<ServerCommandSource> context) {
|
public static int mobcapdebugCommand(CommandContext<ServerCommandSource> context) {
|
||||||
ChunkTicketManager ticketManager = ((ServerChunkManagerAccessor)context.getSource().getWorld().getChunkManager()).getTicketManager();
|
ChunkLevelManager levelManager = ((ServerChunkManagerAccessor)context.getSource().getWorld().getChunkManager()).getLevelManager();
|
||||||
int tickedChunkCount = ((ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor)((ChunkLevelManagerAccessor)ticketManager).minions$getMinionless()).minions$getTickedChunkCount();
|
int tickedChunkCount = ((ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor)((ChunkLevelManagerAccessor)levelManager).minions$getMinionless()).minions$getTickedChunkCount();
|
||||||
context.getSource().sendFeedback(() -> Text.of(String.valueOf(tickedChunkCount)), false);
|
context.getSource().sendFeedback(() -> Text.of(String.valueOf(tickedChunkCount)), false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ import static net.minecraft.server.command.CommandManager.literal;
|
|||||||
|
|
||||||
public class SpawnSubcommand {
|
public class SpawnSubcommand {
|
||||||
public static final LiteralArgumentBuilder<ServerCommandSource> SPAWN = literal("spawn")
|
public static final LiteralArgumentBuilder<ServerCommandSource> SPAWN = literal("spawn")
|
||||||
|
.requires(source -> source.hasPermissionLevel(2))
|
||||||
.then(argument("minion", StringArgumentType.word())
|
.then(argument("minion", StringArgumentType.word())
|
||||||
.suggests(MinionArgument.SUGGESTION_PROVIDER)
|
.suggests(MinionArgument.SUGGESTION_PROVIDER)
|
||||||
.then(argument("pos", Vec3ArgumentType.vec3()))
|
.then(argument("pos", Vec3ArgumentType.vec3())
|
||||||
.executes(context ->
|
.executes(context ->
|
||||||
spawnCommand(
|
spawnCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
@@ -26,7 +27,6 @@ public class SpawnSubcommand {
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
.then(argument("force", BoolArgumentType.bool())
|
.then(argument("force", BoolArgumentType.bool())
|
||||||
.executes(context ->
|
.executes(context ->
|
||||||
spawnCommand(
|
spawnCommand(
|
||||||
@@ -37,11 +37,19 @@ public class SpawnSubcommand {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
.executes(context ->
|
||||||
|
spawnCommand(
|
||||||
|
context.getSource(),
|
||||||
|
StringArgumentType.getString(context, "minion"),
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
public static int spawnCommand(ServerCommandSource source, String minion, PosArgument pos, boolean force) throws CommandSyntaxException {
|
public static int spawnCommand(ServerCommandSource source, String minion, PosArgument pos, boolean force) throws CommandSyntaxException {
|
||||||
MinionData data = MinionArgument.parse(minion);
|
MinionData data = MinionArgument.parse(source.getServer(), minion);
|
||||||
MinionFakePlayer.spawnMinion(data, source.getWorld(), pos.getPos(source), pos.getRotation(source), force);
|
MinionFakePlayer.spawnMinion(data, source.getWorld(), pos != null ? pos.getPos(source) : null, pos != null ? pos.getRotation(source) : null, force);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package io.github.skippyall.minions.docs;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.text.TextCodecs;
|
||||||
|
|
||||||
|
public record ReferenceEntry(Text shortDescription, Text longDescription) {
|
||||||
|
public static final Codec<ReferenceEntry> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
|
instance.group(
|
||||||
|
TextCodecs.CODEC.fieldOf("shortDescription").forGetter(ReferenceEntry::shortDescription),
|
||||||
|
TextCodecs.CODEC.fieldOf("longDescription").forGetter(ReferenceEntry::longDescription)
|
||||||
|
).apply(instance, ReferenceEntry::new));
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package io.github.skippyall.minions.gui;
|
|
||||||
|
|
||||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
|
||||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
|
||||||
import io.github.skippyall.minions.module.command.Command;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import io.github.skippyall.minions.module.ModuleItem;
|
|
||||||
import net.minecraft.screen.ScreenHandlerType;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CommandsGui {
|
|
||||||
public static void openServerModuleCommandGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
Collection<ModuleItem> modules = minion.getModuleInventory().getModuleItems();
|
|
||||||
|
|
||||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
|
||||||
|
|
||||||
gui.setTitle(Text.translatable("minions.gui.module_commands.title"));
|
|
||||||
|
|
||||||
for (ModuleItem module : modules) {
|
|
||||||
gui.addSlot(new GuiElementBuilder()
|
|
||||||
.setItem(module.asItem())
|
|
||||||
.setCallback(() -> openServerCommandGui(player, minion, module))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openServerCommandGui(ServerPlayerEntity player, MinionFakePlayer minion, ModuleItem module) {
|
|
||||||
List<Command> commands = module.getCommands();
|
|
||||||
|
|
||||||
SimpleGui commandGui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
|
||||||
|
|
||||||
commandGui.setTitle(Text.translatable("minions.gui.commands.title", module.asItem().getName()));
|
|
||||||
|
|
||||||
for(int j = 0; j < commands.size(); j++) {
|
|
||||||
Command command = commands.get(j);
|
|
||||||
commandGui.setSlot(j, new GuiElementBuilder()
|
|
||||||
.setItem(command.getItemRepresentation())
|
|
||||||
.setName(command.getName())
|
|
||||||
.addLoreLine(command.getDescription())
|
|
||||||
.setCallback(() -> command.execute(player, minion))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
commandGui.open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import io.github.skippyall.minions.gui.input.ChoiceInput;
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||||
|
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||||
|
import io.github.skippyall.minions.clipboard.ClipboardItem;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.sound.SoundCategory;
|
||||||
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public class ConfigureInstructionGui extends InstructionBoundSimpleGui {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private ConfigureInstructionGui(ScreenHandlerType<?> type, ServerPlayerEntity player, MinionFakePlayer minion, ConfiguredInstruction<MinionRuntime> configuredInstruction, String name) {
|
||||||
|
super(type, player, minion, configuredInstruction);
|
||||||
|
this.name = name;
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void configureInstructionMenu(String name, ConfiguredInstruction<MinionRuntime> instruction, MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
if(!InstructionGui.checkInstructionExists(name, instruction, minion, player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigureInstructionGui gui = new ConfigureInstructionGui(ScreenHandlerType.GENERIC_9X3, player, minion, instruction, name);
|
||||||
|
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
setTitle(Text.literal(name));
|
||||||
|
|
||||||
|
setSlot(7, new GuiElementBuilder(Items.ANVIL)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.configure.rename"))
|
||||||
|
.setCallback(() -> InstructionGui.inputInstructionName(minion, player, name).thenAccept(newName -> {
|
||||||
|
minion.getInstructionManager().setInstructionName(name, newName);
|
||||||
|
configureInstructionMenu(newName, instruction, minion, player);
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
setSlot(8, new GuiElementBuilder(Items.LAVA_BUCKET)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.configure.delete"))
|
||||||
|
.setCallback(() -> ChoiceInput.confirm(player, Text.translatable("minions.gui.instruction.configure.delete.confirm", name))
|
||||||
|
.thenAccept(v -> {
|
||||||
|
minion.getInstructionManager().removeInstruction(name);
|
||||||
|
InstructionGui.instructionList(minion, player);
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
updateSuppliers();
|
||||||
|
|
||||||
|
setSlot(13, InstructionGui.createInstructionElement(instruction.getInstruction(), player.getRegistryManager()));
|
||||||
|
|
||||||
|
setSlot(25, new GuiElementBuilder(Items.FEATHER)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.configure.copy"))
|
||||||
|
.addLoreLine(Text.translatable("minions.gui.instruction.configure.copy.description"))
|
||||||
|
.setCallback(() -> {
|
||||||
|
player.getInventory().offer(ClipboardItem.createInstructionReference(minion, name), true);
|
||||||
|
player.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_CHIME.value(), SoundCategory.BLOCKS, 1, 1);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
updateRunSlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInstructionRename(MinionFakePlayer minion, ConfiguredInstruction<?> instruction, String oldName, String newName) {
|
||||||
|
this.setTitle(Text.literal(newName));
|
||||||
|
name = newName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRun(ConfiguredInstruction<?> instruction) {
|
||||||
|
updateRunSlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop(ConfiguredInstruction<?> instruction) {
|
||||||
|
updateRunSlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSupplierChange(ConfiguredInstruction<?> instruction, Parameter<?> parameter) {
|
||||||
|
updateSuppliers();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateRunSlot() {
|
||||||
|
if(!instruction.isRunning()) {
|
||||||
|
setSlot(26, new GuiElementBuilder(Items.ARROW)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.run"))
|
||||||
|
.setCallback(() -> instruction.run(minion.getInstructionManager()))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setSlot(26, new GuiElementBuilder(Items.BARRIER)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.stop"))
|
||||||
|
.setCallback(() -> instruction.stop(minion.getInstructionManager()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSuppliers() {
|
||||||
|
int slot = 12;
|
||||||
|
for(Parameter<?> parameter : instruction.getInstruction().getParameters().reversed()) {
|
||||||
|
setSlot(slot, InstructionGui.createParameterElement(parameter, instruction.getArguments().getArgument(parameter), player.getRegistryManager())
|
||||||
|
.setCallback(() -> InstructionGui.configureArgumentMenu(name, instruction, parameter, minion, player))
|
||||||
|
);
|
||||||
|
slot--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
public interface Displayable {
|
||||||
|
GuiDisplay getDisplay();
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
|
import io.github.skippyall.minions.util.TranslationUtil;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ReferenceSortedSets;
|
||||||
|
import net.minecraft.component.DataComponentTypes;
|
||||||
|
import net.minecraft.component.type.ProfileComponent;
|
||||||
|
import net.minecraft.component.type.TooltipDisplayComponent;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.registry.DynamicRegistryManager;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.Rarity;
|
||||||
|
import net.minecraft.util.Uuids;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface GuiDisplay {
|
||||||
|
Codec<GuiDisplay> CODEC = MinionRegistries.GUI_DISPLAY_TYPE.getCodec().dispatch(GuiDisplay::getCodec, codec -> codec.fieldOf("data"));
|
||||||
|
GuiDisplay DEFAULT_DISPLAY = new ItemBased(Items.BARRIER);
|
||||||
|
|
||||||
|
static GuiDisplay getGuiDisplay(Identifier id, DynamicRegistryManager manager) {
|
||||||
|
return manager.getOptional(MinionRegistries.GUI_DISPLAY).map(registry -> registry.get(id)).orElse(DEFAULT_DISPLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T> GuiDisplay getGuiDisplayFor(Registry<T> registry, T element, DynamicRegistryManager manager) {
|
||||||
|
Identifier elementId = registry.getId(element);
|
||||||
|
if(elementId == null) {
|
||||||
|
return DEFAULT_DISPLAY;
|
||||||
|
}
|
||||||
|
Identifier displayId = elementId.withPrefixedPath(registry.getKey().getValue().getPath() + "/");
|
||||||
|
|
||||||
|
return getGuiDisplay(displayId, manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T> ItemStack getDisplayStack(Registry<T> registry, T element, DynamicRegistryManager manager) {
|
||||||
|
return getGuiDisplayFor(registry, element, manager).createItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T> ItemStack getDisplayStackWithName(Registry<T> registry, T element, DynamicRegistryManager manager) {
|
||||||
|
ItemStack stack = getDisplayStack(registry, element, manager);
|
||||||
|
stack.set(DataComponentTypes.ITEM_NAME, Text.translatable(TranslationUtil.getTranslationKey(element, registry)));
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack createItemStack();
|
||||||
|
|
||||||
|
Codec<? extends GuiDisplay> getCodec();
|
||||||
|
|
||||||
|
class ModelBased implements GuiDisplay {
|
||||||
|
public static final Codec<ModelBased> CODEC = Identifier.CODEC.xmap(ModelBased::new, display -> display.model);
|
||||||
|
|
||||||
|
private final Identifier model;
|
||||||
|
|
||||||
|
public ModelBased(Identifier model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack createItemStack() {
|
||||||
|
ItemStack stack = new ItemStack(Items.BARRIER);
|
||||||
|
stack.set(DataComponentTypes.ITEM_MODEL, model);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Codec<? extends GuiDisplay> getCodec() {
|
||||||
|
return CODEC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ItemBased implements GuiDisplay {
|
||||||
|
public static final Codec<ItemBased> CODEC = Registries.ITEM.getCodec().xmap(ItemBased::new, display -> display.item);
|
||||||
|
|
||||||
|
private final Item item;
|
||||||
|
|
||||||
|
public ItemBased(Item item) {
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack createItemStack() {
|
||||||
|
ItemStack stack = new ItemStack(item);
|
||||||
|
stack.set(DataComponentTypes.TOOLTIP_DISPLAY, new TooltipDisplayComponent(true, ReferenceSortedSets.emptySet()));
|
||||||
|
stack.set(DataComponentTypes.RARITY, Rarity.COMMON);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Codec<? extends GuiDisplay> getCodec() {
|
||||||
|
return CODEC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class HeadBased implements GuiDisplay {
|
||||||
|
public static final Codec<HeadBased> CODEC = Uuids.CODEC.xmap(HeadBased::new, display -> display.uuid);
|
||||||
|
|
||||||
|
private final UUID uuid;
|
||||||
|
|
||||||
|
public HeadBased(UUID uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack createItemStack() {
|
||||||
|
ItemStack stack = new ItemStack(Items.PLAYER_HEAD);
|
||||||
|
stack.set(DataComponentTypes.PROFILE, new ProfileComponent(Optional.empty(), Optional.of(uuid), new PropertyMap()));
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Codec<? extends GuiDisplay> getCodec() {
|
||||||
|
return CODEC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StackBased implements GuiDisplay {
|
||||||
|
public static final Codec<StackBased> CODEC = ItemStack.CODEC.xmap(StackBased::new, StackBased::createItemStack);
|
||||||
|
|
||||||
|
private final ItemStack stack;
|
||||||
|
|
||||||
|
public StackBased(ItemStack stack) {
|
||||||
|
this.stack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack createItemStack() {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Codec<? extends GuiDisplay> getCodec() {
|
||||||
|
return CODEC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstructionListener;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
|
public class InstructionBoundSimpleGui extends MinionBoundSimpleGui implements ConfiguredInstructionListener {
|
||||||
|
protected final ConfiguredInstruction<MinionRuntime> instruction;
|
||||||
|
|
||||||
|
public InstructionBoundSimpleGui(ScreenHandlerType<?> type, ServerPlayerEntity player, MinionFakePlayer minion, ConfiguredInstruction<MinionRuntime> instruction) {
|
||||||
|
super(type, player, minion);
|
||||||
|
this.instruction = instruction;
|
||||||
|
instruction.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInstructionRemove(ConfiguredInstruction<?> instruction) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
super.onClose();
|
||||||
|
instruction.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
|
import io.github.skippyall.minions.program.value.ValueType;
|
||||||
|
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||||
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
|
import io.github.skippyall.minions.gui.input.Result;
|
||||||
|
import io.github.skippyall.minions.gui.input.TextInput;
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.module.MinionModule;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplier;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierType;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionType;
|
||||||
|
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||||
|
import io.github.skippyall.minions.util.TranslationUtil;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.registry.DynamicRegistryManager;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class InstructionGui {
|
||||||
|
public static void openInstructionMainMenu(MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
SimpleGui gui = new MinionBoundSimpleGui(ScreenHandlerType.GENERIC_3X3, player, minion);
|
||||||
|
gui.setTitle(Text.translatable("minions.gui.instruction.title"));
|
||||||
|
|
||||||
|
gui.setSlot(3, new GuiElementBuilder()
|
||||||
|
.setItem(Items.BOOK)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.list"))
|
||||||
|
.setCallback(() -> instructionList(minion, player))
|
||||||
|
);
|
||||||
|
gui.setSlot(5, new GuiElementBuilder()
|
||||||
|
.setItem(Items.WRITABLE_BOOK)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.create"))
|
||||||
|
.setCallback(() -> createNewInstruction(minion, player))
|
||||||
|
);
|
||||||
|
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void instructionList(MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
SimpleGui gui = new MinionBoundSimpleGui(ScreenHandlerType.GENERIC_9X3, player, minion) {
|
||||||
|
@Override
|
||||||
|
public void onInstructionsUpdate(MinionFakePlayer minion) {
|
||||||
|
resetInstructionList(this, minion, player);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
gui.setTitle(Text.translatable("minions.gui.instruction.title"));
|
||||||
|
resetInstructionList(gui, minion, player);
|
||||||
|
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetInstructionList(SimpleGui gui, MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
int i = 0;
|
||||||
|
for (String instructionName : minion.getInstructionManager().getInstructionNames()) {
|
||||||
|
ConfiguredInstruction<MinionRuntime> instruction = minion.getInstructionManager().getInstruction(instructionName);
|
||||||
|
gui.setSlot(i, new GuiElementBuilder(GuiDisplay.getGuiDisplayFor(MinionRegistries.INSTRUCTION_TYPES, instruction.getInstruction(), player.getRegistryManager()).createItemStack())
|
||||||
|
.setName(Text.literal(instructionName))
|
||||||
|
.setCallback(() -> ConfigureInstructionGui.configureInstructionMenu(instructionName, instruction, minion, player))
|
||||||
|
);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createNewInstruction(MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
selectInstructionModuleMenu(minion, player).thenAccept(instructionType ->
|
||||||
|
inputInstructionName(minion, player, "Instruction").thenAccept(name -> {
|
||||||
|
if (!minion.isRemoved() && !minion.isDisconnected()) {
|
||||||
|
ConfiguredInstruction<MinionRuntime> configuredInstruction = minion.getInstructionManager().createInstruction(name, instructionType);
|
||||||
|
ConfigureInstructionGui.configureInstructionMenu(name, configuredInstruction, minion, player);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<String> inputInstructionName(MinionFakePlayer minion, ServerPlayerEntity player, String defaultValue) {
|
||||||
|
return TextInput.inputSync(player, Text.translatable("minions.gui.instruction.enter_name"), defaultValue, name -> {
|
||||||
|
if (minion.getInstructionManager().hasInstruction(name)) {
|
||||||
|
return new Result.Error<>(Text.translatable("minions.gui.instruction.name_already_used"));
|
||||||
|
}
|
||||||
|
return new Result.Success<>(name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkInstructionExists(String name, ConfiguredInstruction<?> instruction, MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
boolean stillExists = !minion.isRemoved() && !minion.isDisconnected() && minion.getInstructionManager().getInstruction(name) == instruction;
|
||||||
|
if (!stillExists) {
|
||||||
|
player.closeHandledScreen();
|
||||||
|
player.sendMessage(Text.translatable("minions.gui.instruction.removed"));
|
||||||
|
}
|
||||||
|
return stillExists;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static <T, A extends ValueSupplier<T, MinionRuntime>> void configureArgumentMenu(String instructionName, ConfiguredInstruction<MinionRuntime> instruction, Parameter<T> parameter, MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
if (!checkInstructionExists(instructionName, instruction, minion, player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable A argument = instruction.getArguments().getArgument(parameter);
|
||||||
|
|
||||||
|
if(argument == null) {
|
||||||
|
configureTypeAndValue(instructionName, instruction, parameter, minion, player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleGui gui = new InstructionBoundSimpleGui(ScreenHandlerType.GENERIC_3X3, player, minion, instruction);
|
||||||
|
|
||||||
|
ItemStack displayStack = GuiDisplay.getDisplayStack(MinionRegistries.VALUE_SUPPLIER_TYPES, argument.getType(), player.getRegistryManager());
|
||||||
|
|
||||||
|
gui.setSlot(3, new GuiElementBuilder(displayStack)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.argument.configure.type", Text.translatable(TranslationUtil.getTranslationKey(argument.getType(), MinionRegistries.VALUE_SUPPLIER_TYPES, "minions.gui.instruction.argument.configure.type.unset"))))
|
||||||
|
.setCallback(() -> configureTypeAndValue(instructionName, instruction, parameter, minion, player))
|
||||||
|
);
|
||||||
|
gui.setSlot(5, new GuiElementBuilder(Items.STRUCTURE_VOID)
|
||||||
|
.setName(Text.literal("Configure"))
|
||||||
|
.setCallback(() -> argument.getType().openConfiguration(player, argument.getValueType(), argument)
|
||||||
|
.thenAccept(newArgument -> instruction.getArguments().setArgument(parameter, newArgument))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<ValueSupplierType<MinionRuntime>> selectArgumentType(ServerPlayerEntity player, MinionFakePlayer minion, ValueType<?> valueType, ConfiguredInstruction<MinionRuntime> instruction) {
|
||||||
|
CompletableFuture<ValueSupplierType<MinionRuntime>> future = new CompletableFuture<>();
|
||||||
|
SimpleGui gui = new InstructionBoundSimpleGui(ScreenHandlerType.GENERIC_9X3, player, minion, instruction);
|
||||||
|
for (ValueSupplierType<MinionRuntime> type : MinionRegistries.VALUE_SUPPLIER_TYPES) {
|
||||||
|
if(type.isConfigurable(player, valueType, minion)) {
|
||||||
|
gui.addSlot(new GuiElementBuilder(GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_SUPPLIER_TYPES, type, player.getRegistryManager()))
|
||||||
|
.setCallback(() -> future.complete(type))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gui.open();
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void configureTypeAndValue(String name, ConfiguredInstruction<MinionRuntime> instruction, Parameter<T> parameter, MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
selectArgumentType(player, minion, parameter.type(), instruction)
|
||||||
|
.thenApply(type -> type.openConfiguration(player, parameter.type(), null)
|
||||||
|
.thenAccept(newArgument -> {
|
||||||
|
instruction.getArguments().setArgument(parameter, newArgument);
|
||||||
|
configureArgumentMenu(name, instruction, parameter, minion, player);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<InstructionType<MinionRuntime>> selectInstructionModuleMenu(MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
if (minion.getModuleInventory().getModules().isEmpty()) {
|
||||||
|
player.sendMessage(Text.translatable("minions.gui.instruction.no_modules"));
|
||||||
|
return CompletableFuture.failedFuture(new NoSuchElementException("No modules"));
|
||||||
|
}
|
||||||
|
|
||||||
|
CompletableFuture<InstructionType<MinionRuntime>> future = new CompletableFuture<>();
|
||||||
|
|
||||||
|
SimpleGui gui = new MinionBoundSimpleGui(ScreenHandlerType.GENERIC_9X3, player, minion) {
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
if (!future.isDone()) {
|
||||||
|
future.cancel(false);
|
||||||
|
}
|
||||||
|
super.onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
gui.setTitle(Text.translatable("minions.gui.instruction.select_instruction"));
|
||||||
|
|
||||||
|
for (int i = 0; i < minion.getModuleInventory().size(); i++) {
|
||||||
|
ItemStack moduleItem = minion.getModuleInventory().getStack(i);
|
||||||
|
MinionModule module = moduleItem.get(MinionComponentTypes.MODULE);
|
||||||
|
if (module != null && !module.instructions().isEmpty()) {
|
||||||
|
gui.addSlot(new GuiElementBuilder(moduleItem)
|
||||||
|
.setCallback(() -> selectInstructionMenu(module, minion, player)
|
||||||
|
.thenApply(future::complete)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.open();
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<InstructionType<MinionRuntime>> selectInstructionMenu(MinionModule module, MinionFakePlayer minion, ServerPlayerEntity player) {
|
||||||
|
CompletableFuture<InstructionType<MinionRuntime>> future = new CompletableFuture<>();
|
||||||
|
|
||||||
|
SimpleGui gui = new MinionBoundSimpleGui(ScreenHandlerType.GENERIC_9X3, player, minion) {
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
if (!future.isDone()) {
|
||||||
|
future.cancel(false);
|
||||||
|
}
|
||||||
|
super.onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
gui.setTitle(Text.translatable("minions.gui.instruction.select_instruction"));
|
||||||
|
|
||||||
|
for (InstructionType<MinionRuntime> instructionType : module.instructions()) {
|
||||||
|
gui.addSlot(createInstructionElement(instructionType, player.getRegistryManager())
|
||||||
|
.setCallback(() -> future.complete(instructionType))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.open();
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GuiElementBuilder createInstructionElement(InstructionType<MinionRuntime> instructionType, DynamicRegistryManager manager) {
|
||||||
|
GuiElementBuilder instructionBuilder;
|
||||||
|
if (instructionType != null) {
|
||||||
|
instructionBuilder = new GuiElementBuilder(GuiDisplay.getDisplayStackWithName(MinionRegistries.INSTRUCTION_TYPES, instructionType, manager));
|
||||||
|
} else {
|
||||||
|
instructionBuilder = new GuiElementBuilder(Items.RED_WOOL)
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.no_instruction_set"));
|
||||||
|
}
|
||||||
|
return instructionBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GuiElementBuilder createParameterElement(Parameter<?> parameter, @Nullable ValueSupplier<?,?> valueSupplier, DynamicRegistryManager manager) {
|
||||||
|
GuiElementBuilder builder = new GuiElementBuilder(GuiDisplay.getDisplayStack(MinionRegistries.VALUE_TYPES, parameter.type(), manager))
|
||||||
|
.setName(Text.translatable("minions.gui.instruction.parameter", parameter.name(), Text.translatable(TranslationUtil.getTranslationKey(parameter.type(), MinionRegistries.VALUE_TYPES))));
|
||||||
|
if(valueSupplier != null) {
|
||||||
|
builder.addLoreLine(Text.translatable("minions.gui.instruction.argument", valueSupplier.getDisplayText()));
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
|
import io.github.skippyall.minions.minion.MinionListener;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
|
public class MinionBoundSimpleGui extends SimpleGui implements MinionListener {
|
||||||
|
protected final MinionFakePlayer minion;
|
||||||
|
|
||||||
|
public MinionBoundSimpleGui(ScreenHandlerType<?> type, ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
super(type, player, false);
|
||||||
|
this.minion = minion;
|
||||||
|
minion.addMinionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionFakePlayer getMinion() {
|
||||||
|
return minion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMinionRemove(MinionFakePlayer minion) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
minion.removeMinionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof MinionBoundSimpleGui that)) return false;
|
||||||
|
return minion == that.minion && player == that.player;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,13 @@ package io.github.skippyall.minions.gui;
|
|||||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.module.ModuleInventory;
|
||||||
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.screen.ScreenHandlerType;
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.screen.slot.ArmorSlot;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
@@ -20,9 +25,9 @@ public class MinionGui {
|
|||||||
|
|
||||||
gui.setSlot(1, new GuiElementBuilder()
|
gui.setSlot(1, new GuiElementBuilder()
|
||||||
.setItem(Items.COMMAND_BLOCK)
|
.setItem(Items.COMMAND_BLOCK)
|
||||||
.setName(Text.translatable("minions.gui.main.commands"))
|
.setName(Text.translatable("minions.gui.main.instructions"))
|
||||||
.setCallback((i, clickType, slotActionType) -> {
|
.setCallback((i, clickType, slotActionType) -> {
|
||||||
openCommandsGui(player, minion);
|
InstructionGui.openInstructionMainMenu(minion, player);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
gui.setSlot(3, new GuiElementBuilder()
|
gui.setSlot(3, new GuiElementBuilder()
|
||||||
@@ -49,19 +54,32 @@ public class MinionGui {
|
|||||||
gui.open();
|
gui.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openCommandsGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
CommandsGui.openServerModuleCommandGui(player, minion);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openProgrammingInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openMinionInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
public static void openMinionInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
|
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false);
|
||||||
gui.setTitle(Text.translatable("minions.gui.inventory.title", minion.getName()));
|
gui.setTitle(Text.translatable("minions.gui.inventory.title"));
|
||||||
for (int i = 0; i < minion.getInventory().size(); i++) {
|
|
||||||
gui.setSlotRedirect(i, new Slot(minion.getInventory(), i, 0, 0));
|
for(int i = 0; i < 18; i++) {
|
||||||
|
gui.setSlot(i, new ItemStack(Items.BARRIER));
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.setSlot(2, new ItemStack(Items.LEATHER_HELMET));
|
||||||
|
gui.setSlot(3, new ItemStack(Items.LEATHER_CHESTPLATE));
|
||||||
|
gui.setSlot(4, new ItemStack(Items.LEATHER_LEGGINGS));
|
||||||
|
gui.setSlot(5, new ItemStack(Items.LEATHER_BOOTS));
|
||||||
|
gui.setSlot(6, new ItemStack(Items.SHIELD));
|
||||||
|
|
||||||
|
gui.setSlotRedirect(2 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.HEAD, EquipmentSlot.HEAD.getOffsetEntitySlotId(PlayerInventory.MAIN_SIZE), 0, 0, null));
|
||||||
|
gui.setSlotRedirect(3 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.CHEST, EquipmentSlot.CHEST.getOffsetEntitySlotId(PlayerInventory.MAIN_SIZE), 0, 0, null));
|
||||||
|
gui.setSlotRedirect(4 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.LEGS, EquipmentSlot.LEGS.getOffsetEntitySlotId(PlayerInventory.MAIN_SIZE), 0, 0, null));
|
||||||
|
gui.setSlotRedirect(5 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.FEET, EquipmentSlot.FEET.getOffsetEntitySlotId(PlayerInventory.MAIN_SIZE), 0, 0, null));
|
||||||
|
gui.setSlotRedirect(6 + 9, new Slot(minion.getInventory(), PlayerInventory.OFF_HAND_SLOT, 0, 0));
|
||||||
|
|
||||||
|
for (int i = PlayerInventory.HOTBAR_SIZE; i < PlayerInventory.MAIN_SIZE; i++) {
|
||||||
|
gui.setSlotRedirect(i + 9, new Slot(minion.getInventory(), i, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < PlayerInventory.HOTBAR_SIZE; i++) {
|
||||||
|
gui.setSlotRedirect(i + 45, new Slot(minion.getInventory(), i, 0, 0));
|
||||||
}
|
}
|
||||||
gui.open();
|
gui.open();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ package io.github.skippyall.minions.gui;
|
|||||||
|
|
||||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
import io.github.skippyall.minions.input.TextInput;
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
|
import io.github.skippyall.minions.gui.input.TextInput;
|
||||||
import io.github.skippyall.minions.minion.MinionData;
|
import io.github.skippyall.minions.minion.MinionData;
|
||||||
import io.github.skippyall.minions.minion.MinionItem;
|
import io.github.skippyall.minions.minion.MinionItem;
|
||||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||||
import io.github.skippyall.minions.minion.skin.SkinProvider;
|
import io.github.skippyall.minions.minion.skin.SkinProvider;
|
||||||
import io.github.skippyall.minions.minion.skin.SkinProviders;
|
import io.github.skippyall.minions.registration.SkinProviders;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.component.type.ProfileComponent;
|
import net.minecraft.component.type.ProfileComponent;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@@ -48,22 +49,22 @@ public class MinionLookGui extends SimpleGui {
|
|||||||
GuiElementBuilder builder = new GuiElementBuilder()
|
GuiElementBuilder builder = new GuiElementBuilder()
|
||||||
.setItem(Items.PLAYER_HEAD)
|
.setItem(Items.PLAYER_HEAD)
|
||||||
.setCallback(() -> currentSkinProvider.openSkinMenu(player).thenAccept(skin -> {
|
.setCallback(() -> currentSkinProvider.openSkinMenu(player).thenAccept(skin -> {
|
||||||
MinionItem.setData(getData().withSkin(skin), minionItem);
|
MinionItem.setData(player.getServer(), getData().withSkin(skin), minionItem);
|
||||||
}));
|
}));
|
||||||
if(MinionItem.getData(minionItem) != null && MinionItem.getData(minionItem).skin().isPresent()) {
|
if(MinionItem.getData(player.getServer(), minionItem) != null && MinionItem.getData(player.getServer(), minionItem).skin().isPresent()) {
|
||||||
builder.setComponent(DataComponentTypes.PROFILE, new ProfileComponent(Optional.empty(), Optional.empty(), getData().skin().get()));
|
builder.setComponent(DataComponentTypes.PROFILE, new ProfileComponent(Optional.empty(), Optional.empty(), getData().skin().get()));
|
||||||
}
|
}
|
||||||
setSlot(16, builder);
|
setSlot(16, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cycleSkinProvider() {
|
private void cycleSkinProvider() {
|
||||||
int currentId = SkinProviders.SKIN_PROVIDERS.getRawId(currentSkinProvider);
|
int currentId = MinionRegistries.SKIN_PROVIDERS.getRawId(currentSkinProvider);
|
||||||
currentId++;
|
currentId++;
|
||||||
if(SkinProviders.SKIN_PROVIDERS.size() == currentId) {
|
if(MinionRegistries.SKIN_PROVIDERS.size() == currentId) {
|
||||||
currentId = 0;
|
currentId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSkinProvider = SkinProviders.SKIN_PROVIDERS.get(currentId);
|
currentSkinProvider = MinionRegistries.SKIN_PROVIDERS.get(currentId);
|
||||||
updateSkinProvider();
|
updateSkinProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ public class MinionLookGui extends SimpleGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private MinionData getData() {
|
private MinionData getData() {
|
||||||
return MinionItem.getDataOrDefault(minionItem);
|
return MinionItem.getDataOrDefault(player.getServer(), minionItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void open(ServerPlayerEntity player, ItemStack minionItem) {
|
public static void open(ServerPlayerEntity player, ItemStack minionItem) {
|
||||||
@@ -86,9 +87,9 @@ public class MinionLookGui extends SimpleGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void openRenameGui(ServerPlayerEntity player, ItemStack minionItem) {
|
public void openRenameGui(ServerPlayerEntity player, ItemStack minionItem) {
|
||||||
TextInput.inputSync(player, Text.translatable("minions.gui.look.rename.title"), "Minion", MinionProfileUtils::checkMinionNameWithoutPrefix)
|
TextInput.inputSync(player, Text.translatable("minions.gui.look.rename.title"), "Minion", name -> MinionProfileUtils.checkMinionNameWithoutPrefix(player.getServer(), name))
|
||||||
.thenAccept(name -> {
|
.thenAccept(name -> {
|
||||||
MinionItem.setData(getData().withName(MinionProfileUtils.PREFIX + name), minionItem);
|
MinionItem.setData(player.getServer(), getData().withName(MinionProfileUtils.getPrefix() + name), minionItem);
|
||||||
open();
|
open();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
package io.github.skippyall.minions.gui;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.module.command.Command;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import io.github.skippyall.minions.module.ModuleItem;
|
|
||||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
|
||||||
import net.minecraft.inventory.Inventories;
|
|
||||||
import net.minecraft.inventory.SimpleInventory;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.storage.ReadView;
|
|
||||||
import net.minecraft.storage.WriteView;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ModuleInventory extends SimpleInventory {
|
|
||||||
private final Set<ModuleItem> modules = new HashSet<>();
|
|
||||||
public ModuleInventory() {
|
|
||||||
super(27);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openModuleInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player2) -> new ModuleInventoryScreenHandler(syncId, playerInventory, minion.getModuleInventory()), Text.translatable("minions.gui.modules.title", minion.getName())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMaxCountPerStack() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(int slot, ItemStack stack) {
|
|
||||||
return (stack.getCount() <= getMaxCountPerStack()) && stack.getItem() instanceof ModuleItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void markDirty() {
|
|
||||||
super.markDirty();
|
|
||||||
updateModules();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateModules() {
|
|
||||||
modules.clear();
|
|
||||||
for (ItemStack heldStack : heldStacks) {
|
|
||||||
if(heldStack.getItem() instanceof ModuleItem moduleItem) {
|
|
||||||
modules.add(moduleItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readData(ReadView view) {
|
|
||||||
Inventories.readData(view, heldStacks);
|
|
||||||
updateModules();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeData(WriteView view) {
|
|
||||||
Inventories.writeData(view, heldStacks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasModule(ModuleItem module) {
|
|
||||||
return modules.contains(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<ModuleItem> getModuleItems() {
|
|
||||||
return modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Command> getAllCommands() {
|
|
||||||
ArrayList<Command> commands = new ArrayList<>();
|
|
||||||
for(ItemStack stack : heldStacks) {
|
|
||||||
if(stack.getItem() instanceof ModuleItem module) {
|
|
||||||
commands.addAll(module.getCommands());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CodeBlock<?,?>> getAllCodeBlocks() {
|
|
||||||
ArrayList<CodeBlock<?,?>> commands = new ArrayList<>();
|
|
||||||
for(ItemStack stack : heldStacks) {
|
|
||||||
if(stack.getItem() instanceof ModuleItem module) {
|
|
||||||
commands.addAll(module.getCodeBlocks());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package io.github.skippyall.minions.gui.input;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
|
import io.github.skippyall.minions.gui.Displayable;
|
||||||
|
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ChoiceInput {
|
||||||
|
public static <T> BiFunction<ServerPlayerEntity, T, CompletableFuture<T>> createDialogOpener(ScreenHandlerType<?> screen, Text title, Function<T, GuiDisplay> displayFunction, T[] values, @Nullable T fallback) {
|
||||||
|
return (player, object) -> {
|
||||||
|
CompletableFuture<T> future = new CompletableFuture<>();
|
||||||
|
|
||||||
|
SimpleGui gui = new SimpleGui(screen, player, false) {
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
if(fallback == null) {
|
||||||
|
future.cancel(false);
|
||||||
|
} else {
|
||||||
|
future.complete(fallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
gui.setTitle(title);
|
||||||
|
|
||||||
|
for(T value : values) {
|
||||||
|
gui.addSlot(new GuiElementBuilder(displayFunction.apply(value).createItemStack())
|
||||||
|
.setCallback(() -> future.complete(value))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
gui.open();
|
||||||
|
return future;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Displayable> BiFunction<ServerPlayerEntity, T, CompletableFuture<T>> createDialogOpener(T[] values) {
|
||||||
|
return createDialogOpener(ScreenHandlerType.GENERIC_9X3, Text.empty(), t -> t != null ? t.getDisplay() : null, values, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Void> confirm(ServerPlayerEntity player, Text title) {
|
||||||
|
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||||
|
|
||||||
|
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false) {
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
future.cancel(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
gui.setTitle(title);
|
||||||
|
|
||||||
|
gui.setSlot(3, new GuiElementBuilder(Items.REDSTONE_BLOCK)
|
||||||
|
.setName(Text.translatable("minions.gui.abort"))
|
||||||
|
.setCallback(() -> future.cancel(false))
|
||||||
|
);
|
||||||
|
|
||||||
|
gui.setSlot(5, new GuiElementBuilder(Items.EMERALD_BLOCK)
|
||||||
|
.setName(Text.translatable("minions.gui.confirm"))
|
||||||
|
.setCallback(() -> future.complete(null))
|
||||||
|
);
|
||||||
|
|
||||||
|
gui.open();
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BiFunction<ServerPlayerEntity, Boolean, CompletableFuture<Boolean>> inputBoolean(Text title) {
|
||||||
|
return createDialogOpener(ScreenHandlerType.GENERIC_3X3, title, value -> {
|
||||||
|
if(value) {
|
||||||
|
return new GuiDisplay.ItemBased(Items.EMERALD_BLOCK);
|
||||||
|
} else {
|
||||||
|
return new GuiDisplay.ItemBased(Items.REDSTONE_BLOCK);
|
||||||
|
}
|
||||||
|
}, new Boolean[]{false, true}, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package io.github.skippyall.minions.input;
|
package io.github.skippyall.minions.gui.input;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public interface Result<T, E> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull T getOrThrow() {
|
public @NotNull T getOrThrow() {
|
||||||
throw new RuntimeException("Result was an error: " + message.toString());
|
throw new RuntimeException("Result was an error: " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -106,7 +106,7 @@ public interface Result<T, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ifError(Consumer<Error<T, E>> handler) {
|
public void ifError(@NotNull Consumer<Error<T, E>> handler) {
|
||||||
handler.accept(this);
|
handler.accept(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+9
-8
@@ -1,4 +1,4 @@
|
|||||||
package io.github.skippyall.minions.input;
|
package io.github.skippyall.minions.gui.input;
|
||||||
|
|
||||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
||||||
@@ -9,7 +9,6 @@ import net.minecraft.text.Text;
|
|||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class TextInput<T> extends AnvilInputGui {
|
public class TextInput<T> extends AnvilInputGui {
|
||||||
private final GuiElementBuilder valid = new GuiElementBuilder()
|
private final GuiElementBuilder valid = new GuiElementBuilder()
|
||||||
@@ -22,6 +21,7 @@ public class TextInput<T> extends AnvilInputGui {
|
|||||||
private final Function<String, CompletableFuture<Result<T, Text>>> parser;
|
private final Function<String, CompletableFuture<Result<T, Text>>> parser;
|
||||||
private final CompletableFuture<T> future;
|
private final CompletableFuture<T> future;
|
||||||
private Result<T, Text> result;
|
private Result<T, Text> result;
|
||||||
|
private boolean isConfirm;
|
||||||
|
|
||||||
public TextInput(ServerPlayerEntity player, Text title, String defaultValue, Function<String, CompletableFuture<Result<T, Text>>> parser, CompletableFuture<T> future) {
|
public TextInput(ServerPlayerEntity player, Text title, String defaultValue, Function<String, CompletableFuture<Result<T, Text>>> parser, CompletableFuture<T> future) {
|
||||||
super(player, false);
|
super(player, false);
|
||||||
@@ -47,12 +47,12 @@ public class TextInput<T> extends AnvilInputGui {
|
|||||||
return inputSync(player, title, defaultValue, Result.Success::new);
|
return inputSync(player, title, defaultValue, Result.Success::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompletableFuture<Integer> inputInt(ServerPlayerEntity player, Text title, String defaultValue) {
|
public static CompletableFuture<Long> inputLong(ServerPlayerEntity player, Text title, String defaultValue) {
|
||||||
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Integer.valueOf(string), Text.translatable("minions.command.input.int.fail")));
|
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Long.valueOf(string), Text.translatable("minions.command.input.int.fail")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompletableFuture<Float> inputFloat(ServerPlayerEntity player, Text title, String defaultValue) {
|
public static CompletableFuture<Double> inputDouble(ServerPlayerEntity player, Text title, String defaultValue) {
|
||||||
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Float.valueOf(string), Text.translatable("minions.command.input.float.fail")));
|
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Double.valueOf(string), Text.translatable("minions.command.input.float.fail")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,7 +74,7 @@ public class TextInput<T> extends AnvilInputGui {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
if(!future.isDone()) {
|
if(!future.isDone() && !isConfirm) {
|
||||||
future.cancel(false);
|
future.cancel(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,8 +82,9 @@ public class TextInput<T> extends AnvilInputGui {
|
|||||||
public void onConfirm() {
|
public void onConfirm() {
|
||||||
if(result != null) {
|
if(result != null) {
|
||||||
result.ifSuccess(success -> {
|
result.ifSuccess(success -> {
|
||||||
future.complete(success);
|
isConfirm = true;
|
||||||
close();
|
close();
|
||||||
|
future.complete(success);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package io.github.skippyall.minions.instruction;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
||||||
|
import io.github.skippyall.minions.program.consumer.ValueConsumerList;
|
||||||
|
import io.github.skippyall.minions.program.instruction.execution.ContinuousInstructionExecution;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierList;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
|
||||||
|
public class ActionExecution implements ContinuousInstructionExecution<MinionRuntime> {
|
||||||
|
private final EntityPlayerActionPack.ActionType action;
|
||||||
|
|
||||||
|
public ActionExecution(EntityPlayerActionPack.ActionType action) {
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(MinionRuntime minion) {
|
||||||
|
EntityPlayerActionPack ap = minion.getMinion().getMinionActionPack();
|
||||||
|
if(!ap.hasAction(action)) {
|
||||||
|
minion.getMinion().getMinionActionPack().start(action, EntityPlayerActionPack.Action.startContinuous());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop(MinionRuntime minion, ValueConsumerList<MinionRuntime> valueConsumers) {
|
||||||
|
minion.getMinion().getMinionActionPack().stop(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause(MinionRuntime runtime) {
|
||||||
|
runtime.getMinion().getMinionActionPack().stop(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume(MinionRuntime runtime) {
|
||||||
|
runtime.getMinion().getMinionActionPack().start(action, EntityPlayerActionPack.Action.continuous());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readArguments(ValueSupplierList<MinionRuntime> parameters, MinionRuntime minion) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(WriteView view, MinionRuntime minion) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(ReadView view, MinionRuntime runtime) {
|
||||||
|
runtime.getMinion().getMinionActionPack().start(action, EntityPlayerActionPack.Action.continuous());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
//partially code from https://github.com/gnembon/fabric-carpet (EntityPlayerActionPack)
|
||||||
|
package io.github.skippyall.minions.instruction;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.consumer.ValueConsumerList;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierList;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
import net.minecraft.util.hit.HitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
|
||||||
|
public class MineBlockExecution implements InstructionExecution<MinionRuntime> {
|
||||||
|
private BlockPos currentBlock;
|
||||||
|
private float currentBlockDamage = 0;
|
||||||
|
private boolean first = true;
|
||||||
|
private boolean done = false;
|
||||||
|
private boolean success = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(MinionRuntime runtime) {
|
||||||
|
MinionFakePlayer player = runtime.getMinion();
|
||||||
|
if(EntityPlayerActionPack.getTarget(player) instanceof BlockHitResult hit) {
|
||||||
|
this.currentBlock = hit.getBlockPos();
|
||||||
|
|
||||||
|
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||||
|
if (ap.blockHitDelay > 0) {
|
||||||
|
ap.blockHitDelay--;
|
||||||
|
done = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (player.isBlockBreakingRestricted(player.getWorld(), hit.getBlockPos(), player.interactionManager.getGameMode())) {
|
||||||
|
done = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(MinionRuntime runtime) {
|
||||||
|
if(done) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MinionFakePlayer player = runtime.getMinion();
|
||||||
|
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||||
|
|
||||||
|
HitResult newHit = EntityPlayerActionPack.getTarget(player);
|
||||||
|
if(!(newHit instanceof BlockHitResult newBlockHit)) {
|
||||||
|
done = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockPos newPos = newBlockHit.getBlockPos();
|
||||||
|
if(!newPos.equals(currentBlock)) {
|
||||||
|
done = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getWorld().getBlockState(currentBlock).isAir()) {
|
||||||
|
done = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockState state = player.getWorld().getBlockState(currentBlock);
|
||||||
|
boolean blockBroken = false;
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
player.interactionManager.processBlockBreakingAction(currentBlock, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, newBlockHit.getSide(), player.getWorld().getTopYInclusive(), -1);
|
||||||
|
boolean notAir = !state.isAir();
|
||||||
|
if (notAir)
|
||||||
|
{
|
||||||
|
state.onBlockBreakStart(player.getWorld(), currentBlock, player);
|
||||||
|
}
|
||||||
|
if (notAir && state.calcBlockBreakingDelta(player, player.getWorld(), currentBlock) >= 1)
|
||||||
|
{
|
||||||
|
//instamine??
|
||||||
|
blockBroken = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentBlockDamage += state.calcBlockBreakingDelta(player, player.getWorld(), currentBlock);
|
||||||
|
if (currentBlockDamage >= 1) {
|
||||||
|
player.interactionManager.processBlockBreakingAction(currentBlock, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, newBlockHit.getSide(), player.getWorld().getTopYInclusive(), -1);
|
||||||
|
ap.blockHitDelay = 5;
|
||||||
|
blockBroken = true;
|
||||||
|
}
|
||||||
|
player.getWorld().setBlockBreakingInfo(-1, currentBlock, (int) (currentBlockDamage * 10));
|
||||||
|
|
||||||
|
}
|
||||||
|
player.updateLastActionTime();
|
||||||
|
player.swingHand(Hand.MAIN_HAND);
|
||||||
|
|
||||||
|
if(blockBroken) {
|
||||||
|
done = true;
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDone(MinionRuntime runtime) {
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop(MinionRuntime runtime, ValueConsumerList<MinionRuntime> valueConsumers) {
|
||||||
|
MinionFakePlayer player = runtime.getMinion();
|
||||||
|
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||||
|
|
||||||
|
if(currentBlock != null) {
|
||||||
|
player.getWorld().setBlockBreakingInfo(-1, currentBlock, -1);
|
||||||
|
player.interactionManager.processBlockBreakingAction(currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopYInclusive(), -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readArguments(ValueSupplierList<MinionRuntime> arguments, MinionRuntime runtime) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(WriteView view, MinionRuntime runtime) {
|
||||||
|
view.put("currentBlock", BlockPos.CODEC, currentBlock);
|
||||||
|
view.putFloat("currentBlockDamage", currentBlockDamage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(ReadView view, MinionRuntime runtime) {
|
||||||
|
currentBlock = view.read("currentBlock", BlockPos.CODEC).orElse(null);
|
||||||
|
currentBlockDamage = view.getFloat("currentBlockDamage", 0);
|
||||||
|
if(currentBlock == null) {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+133
@@ -0,0 +1,133 @@
|
|||||||
|
package io.github.skippyall.minions.instruction.inventory;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.consumer.ValueConsumerList;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||||
|
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierList;
|
||||||
|
import io.github.skippyall.minions.registration.ValueTypes;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.screen.ScreenHandler;
|
||||||
|
import net.minecraft.screen.slot.Slot;
|
||||||
|
import net.minecraft.screen.slot.SlotActionType;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
|
||||||
|
public class SwapItemExecution implements InstructionExecution<MinionRuntime> {
|
||||||
|
public static final Parameter<Long> FROM_SLOT = new Parameter<>("from_slot", ValueTypes.LONG);
|
||||||
|
public static final Parameter<Boolean> FROM_SCREEN = new Parameter<>("from_screen", ValueTypes.BOOLEAN);
|
||||||
|
public static final Parameter<Long> TO_SLOT = new Parameter<>("to_slot", ValueTypes.LONG);
|
||||||
|
public static final Parameter<Boolean> TO_SCREEN = new Parameter<>("to_screen", ValueTypes.BOOLEAN);
|
||||||
|
|
||||||
|
private int fromSlot;
|
||||||
|
private boolean fromScreen;
|
||||||
|
private int toSlot;
|
||||||
|
private boolean toScreen;
|
||||||
|
|
||||||
|
private ItemStack cursor = ItemStack.EMPTY;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(MinionRuntime runtime) {
|
||||||
|
MinionFakePlayer minion = runtime.getMinion();
|
||||||
|
|
||||||
|
if((fromScreen || toScreen) && minion.currentScreenHandler == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!(checkBounds(minion, fromSlot, fromScreen) && checkBounds(minion, toSlot, toScreen))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack fromStack = getStack(minion, fromSlot, fromScreen);
|
||||||
|
ItemStack toStack = getStack(minion, toSlot, toScreen);
|
||||||
|
|
||||||
|
if(!(canExchange(minion, fromSlot, fromScreen, toStack) && canExchange(minion, toSlot, toScreen, fromStack))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
simulateClick(minion, fromSlot, fromScreen);
|
||||||
|
simulateClick(minion, toSlot, toScreen);
|
||||||
|
simulateClick(minion, fromSlot, fromScreen);
|
||||||
|
minion.getInventory().offerOrDrop(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScreenHandler getScreen(MinionFakePlayer minion, boolean screen) {
|
||||||
|
if(screen) {
|
||||||
|
return minion.currentScreenHandler;
|
||||||
|
} else {
|
||||||
|
return minion.playerScreenHandler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkBounds(MinionFakePlayer minion, int slot, boolean screen) {
|
||||||
|
return slot >= 0 && slot < getScreen(minion, screen).slots.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack getStack(MinionFakePlayer minion, int slot, boolean screen) {
|
||||||
|
return getScreen(minion, screen).getSlot(slot).getStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canExchange(MinionFakePlayer minion, int slotIndex, boolean screen, ItemStack newStack) {
|
||||||
|
ScreenHandler screenHandler = getScreen(minion, screen);
|
||||||
|
Slot slot = screenHandler.getSlot(slotIndex);
|
||||||
|
if(!slot.getStack().isEmpty() && !slot.canTakeItems(minion)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!newStack.isEmpty() && !slot.canInsert(newStack)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*else {
|
||||||
|
if(slotIndex >= PlayerInventory.MAIN_SIZE && slotIndex < PlayerInventory.OFF_HAND_SLOT) {
|
||||||
|
if(!minion.canEquip(newStack, PlayerInventory.EQUIPMENT_SLOTS.get(slotIndex))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(EnchantmentHelper.hasAnyEnchantmentsWith(minion.getInventory().getStack(slotIndex), EnchantmentEffectComponentTypes.PREVENT_ARMOR_CHANGE)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void simulateClick(MinionFakePlayer minion, int slotIndex, boolean screen) {
|
||||||
|
ScreenHandler screenHandler = getScreen(minion, screen);
|
||||||
|
ItemStack previousCursor = screenHandler.getCursorStack();
|
||||||
|
screenHandler.setCursorStack(cursor);
|
||||||
|
screenHandler.onSlotClick(slotIndex, 0, SlotActionType.SWAP, minion);
|
||||||
|
cursor = screenHandler.getCursorStack();
|
||||||
|
screenHandler.setCursorStack(previousCursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(MinionRuntime runtime) {
|
||||||
|
InstructionExecution.super.tick(runtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDone(MinionRuntime runtime) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop(MinionRuntime runtime, ValueConsumerList<MinionRuntime> valueConsumers) {
|
||||||
|
InstructionExecution.super.stop(runtime, valueConsumers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readArguments(ValueSupplierList<MinionRuntime> arguments, MinionRuntime runtime) {
|
||||||
|
fromSlot = Math.clamp(arguments.getValue(FROM_SLOT, runtime), 0, Integer.MAX_VALUE);
|
||||||
|
fromScreen = arguments.getValue(FROM_SCREEN, runtime);
|
||||||
|
toSlot = Math.clamp(arguments.getValue(TO_SLOT, runtime), 0, Integer.MAX_VALUE);
|
||||||
|
toScreen = arguments.getValue(TO_SCREEN, runtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(WriteView view, MinionRuntime runtime) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(ReadView view, MinionRuntime runtime) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package io.github.skippyall.minions.instruction.move;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
|
||||||
|
public abstract class AbstractTurnExecution implements InstructionExecution<MinionRuntime> {
|
||||||
|
protected float targetYaw;
|
||||||
|
protected float targetPitch;
|
||||||
|
|
||||||
|
private static final float anglePerTick = 10;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(MinionRuntime minion) {
|
||||||
|
float rotateYaw = targetYaw - minion.getMinion().getYaw();
|
||||||
|
float rotatePitch = targetPitch - minion.getMinion().getPitch();
|
||||||
|
|
||||||
|
minion.getMinion().getMinionActionPack().turn(Math.min(rotateYaw, anglePerTick), Math.min(rotatePitch, anglePerTick));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDone(MinionRuntime minion) {
|
||||||
|
return Math.abs(targetYaw - minion.getMinion().getYaw()) < 0.001F && Math.abs(targetPitch - minion.getMinion().getPitch()) < 0.001F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(WriteView view, MinionRuntime runtime) {
|
||||||
|
view.putFloat("targetYaw", targetYaw);
|
||||||
|
view.putFloat("targetPitch", targetPitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(ReadView view, MinionRuntime runtime) {
|
||||||
|
targetYaw = view.getFloat("targetYaw", 0);
|
||||||
|
targetPitch = view.getFloat("targetPitch", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package io.github.skippyall.minions.instruction.move;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||||
|
import io.github.skippyall.minions.program.instruction.execution.ContinuousInstructionExecution;
|
||||||
|
import net.minecraft.entity.MovementType;
|
||||||
|
|
||||||
|
public class ContinuousWalkExecution implements ContinuousInstructionExecution<MinionRuntime>, InstructionExecution.Stateless<MinionRuntime> {
|
||||||
|
@Override
|
||||||
|
public void tick(MinionRuntime minion) {
|
||||||
|
minion.getMinion().move(MovementType.SELF, minion.getMinion().getHorizontalFacing().getDoubleVector().normalize().multiply(minion.getMinion().getMovementSpeed()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package io.github.skippyall.minions.instruction.move;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import io.github.skippyall.minions.gui.Displayable;
|
||||||
|
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||||
|
import net.minecraft.util.StringIdentifiable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public enum TurnDirection implements StringIdentifiable, Displayable {
|
||||||
|
LEFT("left", -1, 0),
|
||||||
|
UP("up", 0, -1),
|
||||||
|
RIGHT("right", 1, 0),
|
||||||
|
DOWN("down", 0, 1);
|
||||||
|
|
||||||
|
public static final Codec<TurnDirection> CODEC = StringIdentifiable.createCodec(TurnDirection::values);
|
||||||
|
|
||||||
|
private static final UUID MHF_ArrowLeft = UUID.fromString("a68f0b64-8d14-4000-a95f-4b9ba14f8df9");
|
||||||
|
private static final UUID MHF_ArrowUp = UUID.fromString("fef039ef-e6cd-4987-9c84-26a3e6134277");
|
||||||
|
private static final UUID MHF_ArrowRight = UUID.fromString("50c8510b-5ea0-4d60-be9a-7d542d6cd156");
|
||||||
|
private static final UUID MHF_ArrowDown = UUID.fromString("68f59b9b-5b0b-4b05-a9f2-e1d1405aa348");
|
||||||
|
|
||||||
|
public final String name;
|
||||||
|
public final int xFactor;
|
||||||
|
public final int yFactor;
|
||||||
|
|
||||||
|
TurnDirection(String name, int xFactor, int yFactor) {
|
||||||
|
this.xFactor = xFactor;
|
||||||
|
this.yFactor = yFactor;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuiDisplay getDisplay() {
|
||||||
|
return switch (this) {
|
||||||
|
case LEFT -> new GuiDisplay.HeadBased(MHF_ArrowLeft);
|
||||||
|
case UP -> new GuiDisplay.HeadBased(MHF_ArrowUp);
|
||||||
|
case RIGHT -> new GuiDisplay.HeadBased(MHF_ArrowRight);
|
||||||
|
case DOWN -> new GuiDisplay.HeadBased(MHF_ArrowDown);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package io.github.skippyall.minions.instruction.move;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierList;
|
||||||
|
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||||
|
import io.github.skippyall.minions.registration.ValueTypes;
|
||||||
|
|
||||||
|
public class TurnExecution extends AbstractTurnExecution {
|
||||||
|
public static final Parameter<Double> ANGLE = new Parameter<>("maxAngle", ValueTypes.DOUBLE);
|
||||||
|
public static final Parameter<TurnDirection> DIRECTION = new Parameter<>("direction", ValueTypes.TURN_DIRECTION);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readArguments(ValueSupplierList<MinionRuntime> arguments, MinionRuntime minion) {
|
||||||
|
float maxAngle = arguments.getValue(ANGLE, minion).floatValue();
|
||||||
|
TurnDirection direction = arguments.getValue(DIRECTION, minion);
|
||||||
|
|
||||||
|
float turnYaw = maxAngle * direction.xFactor;
|
||||||
|
float turnPitch = maxAngle * direction.yFactor;
|
||||||
|
|
||||||
|
targetYaw = minion.getMinion().getYaw() + turnYaw;
|
||||||
|
targetPitch = minion.getMinion().getPitch() + turnPitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package io.github.skippyall.minions.instruction.move;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierList;
|
||||||
|
import io.github.skippyall.minions.registration.ValueTypes;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraft.util.math.Vec2f;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
public class TurnVectorExecution extends AbstractTurnExecution {
|
||||||
|
public static final Parameter<Double> X = new Parameter<>("x", ValueTypes.DOUBLE);
|
||||||
|
public static final Parameter<Double> Y = new Parameter<>("y", ValueTypes.DOUBLE);
|
||||||
|
public static final Parameter<Double> Z = new Parameter<>("z", ValueTypes.DOUBLE);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readArguments(ValueSupplierList<MinionRuntime> arguments, MinionRuntime runtime) {
|
||||||
|
double x = arguments.getValue(X, runtime);
|
||||||
|
double y = arguments.getValue(Y, runtime);
|
||||||
|
double z = arguments.getValue(Z, runtime);
|
||||||
|
|
||||||
|
Vec3d vector = new Vec3d(x, y, z);
|
||||||
|
Vec2f rotation = vectorToRotation(vector);
|
||||||
|
targetYaw = rotation.x;
|
||||||
|
targetPitch = rotation.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
//copied from Entity#lookAt (why no helper, Mojang?)
|
||||||
|
public static Vec2f vectorToRotation(Vec3d vector) {
|
||||||
|
double g = Math.sqrt(vector.x * vector.x + vector.z * vector.z);
|
||||||
|
float pitch = MathHelper.wrapDegrees((float)(-(MathHelper.atan2(vector.y, g) * 180.0F / (float)Math.PI)));
|
||||||
|
float yaw = MathHelper.wrapDegrees((float)(MathHelper.atan2(vector.z, vector.x) * 180.0F / (float)Math.PI) - 90.0F);
|
||||||
|
|
||||||
|
return new Vec2f(yaw, pitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package io.github.skippyall.minions.instruction.move;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||||
|
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierList;
|
||||||
|
import io.github.skippyall.minions.registration.ValueTypes;
|
||||||
|
import net.minecraft.entity.MovementType;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
|
||||||
|
public class WalkExecution implements InstructionExecution<MinionRuntime> {
|
||||||
|
public static final Parameter<Double> blocksToMoveParam = new Parameter<>("blocksToMove", ValueTypes.DOUBLE);
|
||||||
|
private static final float ACCURACY = 1F / 32F;
|
||||||
|
|
||||||
|
private double totalBlocksToMove;
|
||||||
|
private double blocksMoved;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(MinionRuntime minion) {
|
||||||
|
double speed = Math.min(minion.getMinion().getMovementSpeed(), totalBlocksToMove - blocksMoved);
|
||||||
|
minion.getMinion().move(MovementType.SELF, minion.getMinion().getHorizontalFacing().getDoubleVector().normalize().multiply(speed));
|
||||||
|
blocksMoved += speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDone(MinionRuntime minion) {
|
||||||
|
return totalBlocksToMove - blocksMoved < ACCURACY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readArguments(ValueSupplierList<MinionRuntime> parameters, MinionRuntime minion) {
|
||||||
|
totalBlocksToMove = parameters.getValue(blocksToMoveParam, minion).floatValue();
|
||||||
|
blocksMoved = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(WriteView view, MinionRuntime minion) {
|
||||||
|
view.putDouble("totalBlocksToMove", totalBlocksToMove);
|
||||||
|
view.putDouble("blocksMoved", blocksMoved);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(ReadView view, MinionRuntime minion) {
|
||||||
|
totalBlocksToMove = view.getDouble("totalBlocksToMove", 0F);
|
||||||
|
blocksMoved = view.getDouble("blocksMoved", 0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package io.github.skippyall.minions.listener;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstructionListener;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.registry.RegistryKey;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class BlockEntityMinionInstructionListener<E extends BlockEntity> extends BlockEntityMinionListener<E> {
|
||||||
|
protected BlockEntityMinionInstructionListener(RegistryKey<World> worldKey, BlockPos pos, UUID minionUuid, BlockEntityType<E> type) {
|
||||||
|
super(worldKey, pos, minionUuid, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Map<String, ConfiguredInstructionListener> getInstructionListeners();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMinionSpawn(MinionFakePlayer minion) {
|
||||||
|
super.onMinionSpawn(minion);
|
||||||
|
registerInstructionListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void add(MinecraftServer server) {
|
||||||
|
super.add(server);
|
||||||
|
if(minion != null) {
|
||||||
|
registerInstructionListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(MinecraftServer server) {
|
||||||
|
super.remove(server);
|
||||||
|
if(minion != null) {
|
||||||
|
removeInstructionListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerInstructionListeners() {
|
||||||
|
for(Map.Entry<String, ConfiguredInstructionListener> listener : getInstructionListeners().entrySet()) {
|
||||||
|
minion.getInstructionManager().getInstruction(listener.getKey()).addListener(listener.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeInstructionListeners() {
|
||||||
|
for(Map.Entry<String, ConfiguredInstructionListener> listener : getInstructionListeners().entrySet()) {
|
||||||
|
minion.getInstructionManager().getInstruction(listener.getKey()).removeListener(listener.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package io.github.skippyall.minions.listener;
|
||||||
|
|
||||||
|
import com.mojang.datafixers.util.Function3;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.github.skippyall.minions.minion.MinionListener;
|
||||||
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.registry.RegistryKey;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.Uuids;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class BlockEntityMinionListener<E extends BlockEntity> implements MinionListener {
|
||||||
|
protected RegistryKey<World> worldKey;
|
||||||
|
protected BlockPos pos;
|
||||||
|
protected UUID minionUuid;
|
||||||
|
protected BlockEntityType<E> type;
|
||||||
|
protected @Nullable MinionFakePlayer minion;
|
||||||
|
|
||||||
|
protected BlockEntityMinionListener(RegistryKey<World> worldKey, BlockPos pos, UUID minionUuid, BlockEntityType<E> type) {
|
||||||
|
this.worldKey = worldKey;
|
||||||
|
this.pos = pos;
|
||||||
|
this.minionUuid = minionUuid;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMinionSpawn(MinionFakePlayer minion) {
|
||||||
|
MinionListener.super.onMinionSpawn(minion);
|
||||||
|
this.minion = minion;
|
||||||
|
removeIfBeRemoved(minion.getServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMinionRemove(MinionFakePlayer minion) {
|
||||||
|
MinionListener.super.onMinionRemove(minion);
|
||||||
|
this.minion = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends BlockEntityMinionListener<?>> T getListener(World world, BlockPos pos, UUID minionUuid, Class<T> clazz) {
|
||||||
|
if(minionUuid != null) {
|
||||||
|
for (MinionListener listener : MinionPersistentState.get(world.getServer()).getMinionData(minionUuid).listeners()) {
|
||||||
|
if (listener instanceof BlockEntityMinionListener<?> tl && tl.pos.equals(pos) && tl.worldKey.equals(world.getRegistryKey()) && clazz.isInstance(tl)) {
|
||||||
|
return clazz.cast(tl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <L extends BlockEntityMinionListener<?>> Codec<L> getCodec(Function3<RegistryKey<World>, BlockPos, UUID, L> constructor) {
|
||||||
|
return RecordCodecBuilder.create(instance ->
|
||||||
|
instance.group(
|
||||||
|
World.CODEC.fieldOf("world").forGetter(listener -> listener.worldKey),
|
||||||
|
BlockPos.CODEC.fieldOf("pos").forGetter(listener -> listener.pos),
|
||||||
|
Uuids.CODEC.fieldOf("minionUuid").forGetter(listener -> listener.minionUuid)
|
||||||
|
).apply(instance, constructor));
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockEntityState getBlockEntityState(MinecraftServer server) {
|
||||||
|
World world = server.getWorld(worldKey);
|
||||||
|
if(world == null || !world.isPosLoaded(pos)) {
|
||||||
|
return BlockEntityState.UNLOADED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(world.getBlockEntity(pos, type).isPresent()) {
|
||||||
|
return BlockEntityState.LOADED;
|
||||||
|
} else {
|
||||||
|
return BlockEntityState.REMOVED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<E> getBlockEntity(MinecraftServer server) {
|
||||||
|
World world = server.getWorld(worldKey);
|
||||||
|
if(world != null && world.isPosLoaded(pos)) {
|
||||||
|
return world.getBlockEntity(pos, type);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeIfBeRemoved(MinecraftServer server) {
|
||||||
|
if(getBlockEntityState(server) == BlockEntityState.REMOVED) {
|
||||||
|
remove(server);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void add(MinecraftServer server) {
|
||||||
|
MinionPersistentState.get(server).getMinionData(minionUuid).listeners().addListener(this);
|
||||||
|
MinionPersistentState.get(server).markDirty();
|
||||||
|
this.minion = (MinionFakePlayer) server.getPlayerManager().getPlayer(minionUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(MinecraftServer server) {
|
||||||
|
MinionPersistentState.get(server).getMinionData(minionUuid).listeners().removeListener(this);
|
||||||
|
MinionPersistentState.get(server).markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum BlockEntityState {
|
||||||
|
LOADED,
|
||||||
|
REMOVED,
|
||||||
|
UNLOADED
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package io.github.skippyall.minions.listener;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
|
public class ListenerManager<T> implements Iterable<T> {
|
||||||
|
protected final Set<T> listeners;
|
||||||
|
|
||||||
|
public ListenerManager() {
|
||||||
|
this(new CopyOnWriteArraySet<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ListenerManager(Set<T> listeners) {
|
||||||
|
this.listeners = listeners;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListener(T listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeListener(T listener) {
|
||||||
|
listeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasListener(T listener) {
|
||||||
|
return listeners.contains(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Iterator<T> iterator() {
|
||||||
|
return listeners.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return super.equals(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package io.github.skippyall.minions.listener;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
|
public class SerializableListenerManager<T extends SerializableListenerManager.SerializableListener> extends ListenerManager<T> {
|
||||||
|
private final Registry<Codec<? extends T>> registry;
|
||||||
|
|
||||||
|
public SerializableListenerManager(Registry<Codec<? extends T>> registry) {
|
||||||
|
this.registry = registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SerializableListenerManager(Registry<Codec<? extends T>> registry, Set<T> listeners) {
|
||||||
|
super(listeners);
|
||||||
|
this.registry = registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends SerializableListener> Codec<SerializableListenerManager<T>> getCodec(Registry<Codec<? extends T>> registry) {
|
||||||
|
return registry.getCodec().<T>dispatch(
|
||||||
|
listener -> listener.getCodecId().map(registry::get).orElse(Codec.unit(null)),
|
||||||
|
codec -> codec.fieldOf("data")
|
||||||
|
).listOf().xmap(
|
||||||
|
list -> new SerializableListenerManager<>(registry, new CopyOnWriteArraySet<>(list)),
|
||||||
|
manager -> {
|
||||||
|
List<T> serializableListeners = new ArrayList<>();
|
||||||
|
for(T listener : manager.listeners) {
|
||||||
|
if(listener.getCodecId().isPresent()) {
|
||||||
|
serializableListeners.add(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return serializableListeners;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(WriteView view) {
|
||||||
|
WriteView.ListView listView = view.getList("listeners");
|
||||||
|
for (T listener : listeners) {
|
||||||
|
if(listener.getCodecId().isPresent()) {
|
||||||
|
WriteView listenerView = listView.add();
|
||||||
|
Codec<? extends T> codec = registry.get(listener.getCodecId().get());
|
||||||
|
listenerView.put("id", Identifier.CODEC, listener.getCodecId().get());
|
||||||
|
//noinspection unchecked
|
||||||
|
listenerView.put("data", (Codec<T>) codec, listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(ReadView view) {
|
||||||
|
ReadView.ListReadView listView = view.getListReadView("listeners");
|
||||||
|
for (ReadView listenerView : listView) {
|
||||||
|
Optional<Identifier> id = listenerView.read("id", Identifier.CODEC);
|
||||||
|
if(id.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Codec<? extends T> codec = registry.get(id.get());
|
||||||
|
|
||||||
|
Optional<? extends T> listener = listenerView.read("data", codec);
|
||||||
|
|
||||||
|
if(listener.isPresent()) {
|
||||||
|
listeners.add(listener.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface SerializableListener {
|
||||||
|
default Optional<Identifier> getCodecId() {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class MinionConfig {
|
||||||
|
public static final Codec<MinionConfig> CODEC = Codec.<Option<?>, Object>dispatchedMap(
|
||||||
|
MinionRegistries.MINION_CONFIG_OPTIONS.getCodec(),
|
||||||
|
Option::codec
|
||||||
|
).xmap(MinionConfig::new, config -> config.values);
|
||||||
|
|
||||||
|
private final Map<Option<?>, Object> values;
|
||||||
|
|
||||||
|
public MinionConfig() {
|
||||||
|
values = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MinionConfig(Map<Option<?>, Object> values) {
|
||||||
|
this.values = new HashMap<>(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getOption(Option<T> option) {
|
||||||
|
if(values.containsKey(option)) {
|
||||||
|
//noinspection unchecked
|
||||||
|
return (T) values.get(option);
|
||||||
|
} else {
|
||||||
|
return option.defaultValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof MinionConfig that)) return false;
|
||||||
|
return Objects.equals(values, that.values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Option<Boolean> booleanOption(Identifier key, boolean defaultValue) {
|
||||||
|
return new Option<>(key, defaultValue, Codec.BOOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Option<T>(Identifier key, T defaultValue, Codec<T> codec) {
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof Option<?> option)) return false;
|
||||||
|
return Objects.equals(key, option.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,65 +1,59 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import eu.pb4.polymer.core.api.other.PolymerComponent;
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
import io.github.skippyall.minions.Minions;
|
import io.github.skippyall.minions.listener.SerializableListenerManager;
|
||||||
import net.minecraft.component.ComponentType;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
|
||||||
import net.minecraft.nbt.NbtOps;
|
|
||||||
import net.minecraft.registry.Registries;
|
|
||||||
import net.minecraft.registry.Registry;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.Uuids;
|
import net.minecraft.util.Uuids;
|
||||||
import net.minecraft.util.dynamic.Codecs;
|
import net.minecraft.util.dynamic.Codecs;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public record MinionData(UUID uuid, String name, Optional<PropertyMap> skin, boolean isSpawned) {
|
public record MinionData(
|
||||||
|
UUID uuid,
|
||||||
|
String name,
|
||||||
|
Optional<PropertyMap> skin,
|
||||||
|
boolean isSpawned,
|
||||||
|
SerializableListenerManager<MinionListener> listeners,
|
||||||
|
MinionConfig config
|
||||||
|
) {
|
||||||
public static final Codec<MinionData> CODEC = RecordCodecBuilder.create(instance ->
|
public static final Codec<MinionData> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
instance.group(
|
instance.group(
|
||||||
Uuids.CODEC.fieldOf("uuid").forGetter(MinionData::uuid),
|
Uuids.CODEC.fieldOf("uuid").forGetter(MinionData::uuid),
|
||||||
Codec.STRING.fieldOf("name").forGetter(MinionData::name),
|
Codec.STRING.fieldOf("name").forGetter(MinionData::name),
|
||||||
Codecs.GAME_PROFILE_PROPERTY_MAP.optionalFieldOf("skin").forGetter(MinionData::skin),
|
Codecs.GAME_PROFILE_PROPERTY_MAP.optionalFieldOf("skin").forGetter(MinionData::skin),
|
||||||
Codec.BOOL.optionalFieldOf("isSpawned", false).forGetter(MinionData::isSpawned)
|
Codec.BOOL.optionalFieldOf("isSpawned", false).forGetter(MinionData::isSpawned),
|
||||||
|
SerializableListenerManager.getCodec(MinionRegistries.MINION_LISTENER_CODECS).optionalFieldOf("listeners").xmap(
|
||||||
|
optional -> optional.orElseGet(() -> new SerializableListenerManager<>(MinionRegistries.MINION_LISTENER_CODECS)),
|
||||||
|
Optional::of
|
||||||
|
).forGetter(MinionData::listeners),
|
||||||
|
MinionConfig.CODEC.optionalFieldOf("config", new MinionConfig()).forGetter(MinionData::config)
|
||||||
).apply(instance, MinionData::new)
|
).apply(instance, MinionData::new)
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final ComponentType<UUID> COMPONENT = Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(Minions.MOD_ID, "minion_data"), ComponentType.<UUID>builder().codec(Uuids.CODEC).build());
|
public static MinionData createDefault(MinecraftServer server) {
|
||||||
|
return new MinionData(
|
||||||
public static MinionData createDefault() {
|
UUID.randomUUID(),
|
||||||
return new MinionData(UUID.randomUUID(), MinionProfileUtils.newDefaultMinionName(), Optional.empty(), false);
|
MinionProfileUtils.newDefaultMinionName(server),
|
||||||
}
|
Optional.empty(),
|
||||||
|
false,
|
||||||
public MinionData withUuid(UUID uuid) {
|
new SerializableListenerManager<>(MinionRegistries.MINION_LISTENER_CODECS),
|
||||||
return new MinionData(uuid, name, skin, isSpawned);
|
new MinionConfig()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinionData withName(String name) {
|
public MinionData withName(String name) {
|
||||||
return new MinionData(uuid, name, skin, isSpawned);
|
return new MinionData(uuid, name, skin, isSpawned, listeners, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinionData withSkin(Optional<PropertyMap> skin) {
|
public MinionData withSkin(Optional<PropertyMap> skin) {
|
||||||
return new MinionData(uuid, name, skin, isSpawned);
|
return new MinionData(uuid, name, skin, isSpawned, listeners, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinionData withSpawned(boolean isSpawned) {
|
public MinionData withSpawned(boolean isSpawned) {
|
||||||
return new MinionData(uuid, name, skin, isSpawned);
|
return new MinionData(uuid, name, skin, isSpawned, listeners, config);
|
||||||
}
|
|
||||||
|
|
||||||
public NbtCompound writeNbt() {
|
|
||||||
return (NbtCompound) MinionData.CODEC.encode(this, NbtOps.INSTANCE, null).result().orElse(new NbtCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MinionData readNbt(NbtCompound nbt) {
|
|
||||||
return MinionData.CODEC.decode(NbtOps.INSTANCE, nbt).resultOrPartial().map(Pair::getFirst).orElseGet(MinionData::createDefault);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void register() {
|
|
||||||
PolymerComponent.registerDataComponent(COMPONENT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import eu.pb4.polymer.core.api.item.PolymerItem;
|
|||||||
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
|
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
|
||||||
import io.github.skippyall.minions.gui.MinionLookGui;
|
import io.github.skippyall.minions.gui.MinionLookGui;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.component.type.TooltipDisplayComponent;
|
import net.minecraft.component.type.TooltipDisplayComponent;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
@@ -12,6 +13,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.item.ItemUsageContext;
|
import net.minecraft.item.ItemUsageContext;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.item.tooltip.TooltipType;
|
import net.minecraft.item.tooltip.TooltipType;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
@@ -23,7 +25,6 @@ import net.minecraft.world.World;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import xyz.nucleoid.packettweaker.PacketContext;
|
import xyz.nucleoid.packettweaker.PacketContext;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class MinionItem extends Item implements PolymerItem {
|
public class MinionItem extends Item implements PolymerItem {
|
||||||
@@ -50,7 +51,7 @@ public class MinionItem extends Item implements PolymerItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendTooltip(ItemStack stack, TooltipContext context, TooltipDisplayComponent component, Consumer<Text> tooltip, TooltipType type) {
|
public void appendTooltip(ItemStack stack, TooltipContext context, TooltipDisplayComponent component, Consumer<Text> tooltip, TooltipType type) {
|
||||||
MinionData data = getData(stack);
|
MinionData data = null /*getData(stack)*/;
|
||||||
if(data != null) {
|
if(data != null) {
|
||||||
tooltip.accept(Text.translatable("minions.minion_item.tooltip", data.name()));
|
tooltip.accept(Text.translatable("minions.minion_item.tooltip", data.name()));
|
||||||
}
|
}
|
||||||
@@ -70,36 +71,36 @@ public class MinionItem extends Item implements PolymerItem {
|
|||||||
@Override
|
@Override
|
||||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||||
if(!context.getWorld().isClient) {
|
if(!context.getWorld().isClient) {
|
||||||
MinionData data = getDataOrDefault(context.getStack());
|
MinionData data = getDataOrDefault(context.getWorld().getServer(), context.getStack());
|
||||||
MinionFakePlayer.spawnMinion(data, (ServerWorld) context.getWorld(), context.getBlockPos().toCenterPos().add(0,0.5,0), new Vec2f(0, 0));
|
MinionFakePlayer.spawnMinion(data, (ServerWorld) context.getWorld(), context.getBlockPos().toCenterPos().add(0,0.5,0), new Vec2f(0, 0));
|
||||||
}
|
}
|
||||||
context.getStack().decrement(1);
|
context.getStack().decrement(1);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setData(MinionData data, ItemStack item) {
|
public static void setData(MinecraftServer server, MinionData data, ItemStack item) {
|
||||||
item.set(MinionData.COMPONENT, data.uuid());
|
item.set(MinionComponentTypes.MINION_DATA, data.uuid());
|
||||||
MinionPersistentState.INSTANCE.updateMinionData(data);
|
MinionPersistentState.get(server).updateMinionData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static MinionData getData(ItemStack item) {
|
public static MinionData getData(MinecraftServer server, ItemStack item) {
|
||||||
if(item.contains(MinionData.COMPONENT)) {
|
if(item.contains(MinionComponentTypes.MINION_DATA)) {
|
||||||
return MinionPersistentState.INSTANCE.getMinionData(item.get(MinionData.COMPONENT));
|
return MinionPersistentState.get(server).getMinionData(item.get(MinionComponentTypes.MINION_DATA));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MinionData getDataOrDefault(ItemStack item) {
|
public static MinionData getDataOrDefault(MinecraftServer server, ItemStack item) {
|
||||||
MinionData data = getData(item);
|
MinionData data = getData(server, item);
|
||||||
if(data == null) {
|
if(data == null) {
|
||||||
data = MinionData.createDefault();
|
data = MinionData.createDefault(server);
|
||||||
setData(data, item);
|
setData(server, data, item);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsData(ItemStack item) {
|
public static boolean containsData(ItemStack item) {
|
||||||
return item.contains(MinionData.COMPONENT);
|
return item.contains(MinionComponentTypes.MINION_DATA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||||
|
import io.github.skippyall.minions.listener.SerializableListenerManager;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface MinionListener extends SerializableListenerManager.SerializableListener {
|
||||||
|
default void onMinionSpawn(MinionFakePlayer minion) {}
|
||||||
|
|
||||||
|
default void onMinionRemove(MinionFakePlayer minion) {}
|
||||||
|
|
||||||
|
default void onInstructionsUpdate(MinionFakePlayer minion) {}
|
||||||
|
|
||||||
|
default void onInstructionRename(MinionFakePlayer minion, ConfiguredInstruction<?> instruction, String oldName, String newName) {}
|
||||||
|
|
||||||
|
interface Delegating extends MinionListener {
|
||||||
|
@Nullable MinionListener getBacking();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onMinionSpawn(MinionFakePlayer minion) {
|
||||||
|
if(getBacking() != null) {
|
||||||
|
getBacking().onMinionSpawn(minion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onMinionRemove(MinionFakePlayer minion) {
|
||||||
|
if(getBacking() != null) {
|
||||||
|
getBacking().onMinionRemove(minion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onInstructionsUpdate(MinionFakePlayer minion) {
|
||||||
|
if(getBacking() != null) {
|
||||||
|
getBacking().onInstructionsUpdate(minion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onInstructionRename(MinionFakePlayer minion, ConfiguredInstruction<?> instruction, String oldName, String newName) {
|
||||||
|
if(getBacking() != null) {
|
||||||
|
getBacking().onInstructionRename(minion, instruction, oldName, newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.PersistentState;
|
import net.minecraft.world.PersistentState;
|
||||||
import net.minecraft.world.PersistentStateType;
|
import net.minecraft.world.PersistentStateType;
|
||||||
@@ -18,8 +17,6 @@ public class MinionPersistentState extends PersistentState {
|
|||||||
|
|
||||||
public static PersistentStateType<MinionPersistentState> TYPE = new PersistentStateType<>("minion", MinionPersistentState::new, MinionPersistentState.CODEC, null);
|
public static PersistentStateType<MinionPersistentState> TYPE = new PersistentStateType<>("minion", MinionPersistentState::new, MinionPersistentState.CODEC, null);
|
||||||
|
|
||||||
public static MinionPersistentState INSTANCE;
|
|
||||||
|
|
||||||
private final Map<UUID, MinionData> minionData = new HashMap<>();
|
private final Map<UUID, MinionData> minionData = new HashMap<>();
|
||||||
|
|
||||||
public MinionPersistentState() {
|
public MinionPersistentState() {
|
||||||
@@ -63,8 +60,7 @@ public class MinionPersistentState extends PersistentState {
|
|||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void create(MinecraftServer server) {
|
public static MinionPersistentState get(MinecraftServer server) {
|
||||||
Minions.LOGGER.error("Creating Minion Persistent state");
|
return server.getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TYPE);
|
||||||
INSTANCE = server.getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TYPE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.ProfileLookupCallback;
|
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import com.mojang.authlib.yggdrasil.ProfileResult;
|
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import io.github.skippyall.minions.input.Result;
|
import io.github.skippyall.minions.MinionsConfig;
|
||||||
import net.minecraft.block.entity.SkullBlockEntity;
|
import io.github.skippyall.minions.gui.input.Result;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.StringHelper;
|
import net.minecraft.util.StringHelper;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ForkJoinPool;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.Minions.LOGGER;
|
import static io.github.skippyall.minions.Minions.LOGGER;
|
||||||
|
|
||||||
public class MinionProfileUtils {
|
public class MinionProfileUtils {
|
||||||
public static final String PREFIX = "+";
|
public static String getPrefix() {
|
||||||
|
return MinionsConfig.get().minion.minionPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
public static GameProfile makeNewMinionProfile(UUID uuidMinion, String username, PropertyMap skin) {
|
public static GameProfile makeNewMinionProfile(UUID uuidMinion, String username, PropertyMap skin) {
|
||||||
if(uuidMinion == null) {
|
if(uuidMinion == null) {
|
||||||
@@ -34,37 +31,37 @@ public class MinionProfileUtils {
|
|||||||
return newProfile;
|
return newProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<String, Text> checkMinionNameWithoutPrefix(String name) {
|
public static Result<String, Text> checkMinionNameWithoutPrefix(MinecraftServer server, String name) {
|
||||||
for(char c : name.toCharArray()) {
|
for(char c : name.toCharArray()) {
|
||||||
if(!StringReader.isAllowedInUnquotedString(c)) {
|
if(!StringReader.isAllowedInUnquotedString(c)) {
|
||||||
return new Result.Error<>(Text.translatable("minions.generic.name.invalid_char"));
|
return new Result.Error<>(Text.translatable("minions.generic.name.invalid_char"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((PREFIX + name).length() > 16) {
|
if((getPrefix() + name).length() > 16) {
|
||||||
return new Result.Error<>(Text.translatable("minions.generic.name.too_long"));
|
return new Result.Error<>(Text.translatable("minions.generic.name.too_long"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!StringHelper.isValidPlayerName(PREFIX + name)) {
|
if(!StringHelper.isValidPlayerName(getPrefix() + name)) {
|
||||||
return new Result.Error<>(Text.translatable("minions.generic.name.invalid"));
|
return new Result.Error<>(Text.translatable("minions.generic.name.invalid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(MinionPersistentState.INSTANCE.isMinionNameTaken(PREFIX + name)) {
|
if(MinionPersistentState.get(server).isMinionNameTaken(getPrefix() + name)) {
|
||||||
return new Result.Error<>(Text.translatable("minions.generic.name.taken"));
|
return new Result.Error<>(Text.translatable("minions.generic.name.taken"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Result.Success<>(name);
|
return new Result.Success<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String newDefaultMinionName() {
|
public static String newDefaultMinionName(MinecraftServer server) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (MinionPersistentState.INSTANCE.isMinionNameTaken("+Minion" + i)) {
|
while (MinionPersistentState.get(server).isMinionNameTaken("+Minion" + i)) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return "+Minion" + i;
|
return "+Minion" + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMinion(UUID uuid) {
|
public static boolean isMinion(MinecraftServer server, UUID uuid) {
|
||||||
return MinionPersistentState.INSTANCE.isMinion(uuid);
|
return MinionPersistentState.get(server).isMinion(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,168 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstructionListener;
|
||||||
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.InstructionRuntime;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierType;
|
||||||
|
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionType;
|
||||||
|
import io.github.skippyall.minions.program.consumer.ValueConsumerType;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class MinionRuntime implements InstructionRuntime<MinionRuntime> {
|
||||||
|
private final MinionFakePlayer minion;
|
||||||
|
private final Map<String, ConfiguredInstruction<MinionRuntime>> configuredInstructions = new HashMap<>();
|
||||||
|
private final Map<Integer, ConfiguredInstruction<MinionRuntime>> webSocketInstructions = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public MinionRuntime(MinionFakePlayer minion) {
|
||||||
|
this.minion = minion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionFakePlayer getMinion() {
|
||||||
|
return minion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
for (ConfiguredInstruction<MinionRuntime> instruction : configuredInstructions.values()) {
|
||||||
|
instruction.tick(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(ConfiguredInstruction<MinionRuntime> instruction : webSocketInstructions.values()) {
|
||||||
|
instruction.tick(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableInstructionType(InstructionType<MinionRuntime> instructionType) {
|
||||||
|
updatePausedStatus(instructionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableInstructionType(InstructionType<MinionRuntime> instructionType) {
|
||||||
|
updatePausedStatus(instructionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePausedStatus(InstructionType<MinionRuntime> instructionType) {
|
||||||
|
for(ConfiguredInstruction<MinionRuntime> instruction : configuredInstructions.values()) {
|
||||||
|
if(instruction.getInstruction() == instructionType) {
|
||||||
|
instruction.updatePauseStatus(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(ConfiguredInstruction<MinionRuntime> instruction : webSocketInstructions.values()) {
|
||||||
|
if(instruction.getInstruction() == instructionType) {
|
||||||
|
instruction.updatePauseStatus(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInstructionEnabled(InstructionType<MinionRuntime> type) {
|
||||||
|
return minion.getModuleInventory().hasInstruction(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getInstructionNames() {
|
||||||
|
return configuredInstructions.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredInstruction<MinionRuntime> createInstruction(String name, InstructionType<MinionRuntime> instructionType) {
|
||||||
|
if(configuredInstructions.containsKey(name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfiguredInstruction<MinionRuntime> instruction = new ConfiguredInstruction<>(instructionType);
|
||||||
|
configuredInstructions.put(name, instruction);
|
||||||
|
minion.forEachMinionListener(listener -> listener.onInstructionsUpdate(minion));
|
||||||
|
return instruction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeInstruction(String name) {
|
||||||
|
ConfiguredInstruction<MinionRuntime> instruction = getInstruction(name);
|
||||||
|
instruction.stop(this);
|
||||||
|
configuredInstructions.remove(name);
|
||||||
|
|
||||||
|
instruction.onInstructionRemove();
|
||||||
|
minion.forEachMinionListener(listener -> listener.onInstructionsUpdate(minion));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredInstruction<MinionRuntime> getInstruction(String name) {
|
||||||
|
return configuredInstructions.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasInstruction(String name) {
|
||||||
|
return configuredInstructions.containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstructionName(String oldName, String newName) {
|
||||||
|
if(!configuredInstructions.containsKey(newName) && configuredInstructions.containsKey(oldName)) {
|
||||||
|
ConfiguredInstruction<MinionRuntime> instruction = configuredInstructions.get(oldName);
|
||||||
|
configuredInstructions.remove(oldName);
|
||||||
|
configuredInstructions.put(newName, instruction);
|
||||||
|
|
||||||
|
|
||||||
|
minion.forEachMinionListener(minionListener -> {
|
||||||
|
minionListener.onInstructionRename(minion, instruction, oldName, newName);
|
||||||
|
minionListener.onInstructionsUpdate(minion);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addWebSocketInstruction(int id, ConfiguredInstruction<MinionRuntime> instruction) {
|
||||||
|
webSocketInstructions.put(id, instruction);
|
||||||
|
instruction.addListener(new ConfiguredInstructionListener() {
|
||||||
|
@Override
|
||||||
|
public void onStop(ConfiguredInstruction<?> instruction) {
|
||||||
|
webSocketInstructions.remove(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(WriteView view) {
|
||||||
|
WriteView.ListView list = view.getList("configuredInstructions");
|
||||||
|
for (Map.Entry<String, ConfiguredInstruction<MinionRuntime>> instruction : configuredInstructions.entrySet()) {
|
||||||
|
WriteView inner = list.add();
|
||||||
|
inner.putString("name", instruction.getKey());
|
||||||
|
instruction.getValue().save(inner, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(ReadView view) {
|
||||||
|
ReadView.ListReadView list = view.getListReadView("configuredInstructions");
|
||||||
|
for (ReadView inner : list) {
|
||||||
|
Optional<String> name = inner.getOptionalString("name");
|
||||||
|
if(name.isEmpty()) {
|
||||||
|
Minions.LOGGER.error("Tried deserializing configured instruction without a name of minion \"{}\":", minion.getGameProfile().getName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ConfiguredInstruction<MinionRuntime> instruction = ConfiguredInstruction.load(inner, this);
|
||||||
|
configuredInstructions.put(name.get(), instruction);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Minions.LOGGER.error("Could not deserialize configured instruction \"{}\" of minion \"{}\":", name.get(), minion.getGameProfile().getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Registry<ValueSupplierType<MinionRuntime>> getArgumentTypeRegistry() {
|
||||||
|
return MinionRegistries.VALUE_SUPPLIER_TYPES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Registry<InstructionType<MinionRuntime>> getInstructionTypeRegistry() {
|
||||||
|
return MinionRegistries.INSTRUCTION_TYPES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Registry<ValueConsumerType<MinionRuntime>> getValueConsumerTypeRegistry() {
|
||||||
|
return MinionRegistries.VALUE_CONSUMER_TYPES;
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
-28
@@ -34,12 +34,12 @@ import net.minecraft.util.math.Vec3d;
|
|||||||
|
|
||||||
public class EntityPlayerActionPack
|
public class EntityPlayerActionPack
|
||||||
{
|
{
|
||||||
private final ServerPlayerEntity player;
|
private final MinionFakePlayer player;
|
||||||
|
|
||||||
private final Map<ActionType, Action> actions = new EnumMap<>(ActionType.class);
|
private final Map<ActionType, Action> actions = new EnumMap<>(ActionType.class);
|
||||||
|
|
||||||
private BlockPos currentBlock;
|
private BlockPos currentBlock;
|
||||||
private int blockHitDelay;
|
public int blockHitDelay;
|
||||||
private boolean isHittingBlock;
|
private boolean isHittingBlock;
|
||||||
private float curBlockDamageMP;
|
private float curBlockDamageMP;
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class EntityPlayerActionPack
|
|||||||
|
|
||||||
private int itemUseCooldown;
|
private int itemUseCooldown;
|
||||||
|
|
||||||
public EntityPlayerActionPack(ServerPlayerEntity playerIn)
|
public EntityPlayerActionPack(MinionFakePlayer playerIn)
|
||||||
{
|
{
|
||||||
player = playerIn;
|
player = playerIn;
|
||||||
stopAll();
|
stopAll();
|
||||||
@@ -71,6 +71,14 @@ public class EntityPlayerActionPack
|
|||||||
itemUseCooldown = other.itemUseCooldown;
|
itemUseCooldown = other.itemUseCooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Action getAction(ActionType type) {
|
||||||
|
return actions.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAction(ActionType type) {
|
||||||
|
return actions.containsKey(type);
|
||||||
|
}
|
||||||
|
|
||||||
public EntityPlayerActionPack start(ActionType type, Action action)
|
public EntityPlayerActionPack start(ActionType type, Action action)
|
||||||
{
|
{
|
||||||
Action previous = actions.remove(type);
|
Action previous = actions.remove(type);
|
||||||
@@ -253,9 +261,13 @@ public class EntityPlayerActionPack
|
|||||||
if (strafing != 0.0F || player instanceof MinionFakePlayer) {
|
if (strafing != 0.0F || player instanceof MinionFakePlayer) {
|
||||||
player.sidewaysSpeed = strafing * vel;
|
player.sidewaysSpeed = strafing * vel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(blockHitDelay > 0) {
|
||||||
|
blockHitDelay--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static HitResult getTarget(ServerPlayerEntity player)
|
public static HitResult getTarget(ServerPlayerEntity player)
|
||||||
{
|
{
|
||||||
double reach = player.interactionManager.isCreative() ? 5 : 4.5f;
|
double reach = player.interactionManager.isCreative() ? 5 : 4.5f;
|
||||||
return Tracer.rayTrace(player, 1, reach, false);
|
return Tracer.rayTrace(player, 1, reach, false);
|
||||||
@@ -297,9 +309,9 @@ public class EntityPlayerActionPack
|
|||||||
USE(true)
|
USE(true)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
boolean execute(ServerPlayerEntity player, Action action)
|
boolean execute(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||||
if (ap.itemUseCooldown > 0)
|
if (ap.itemUseCooldown > 0)
|
||||||
{
|
{
|
||||||
ap.itemUseCooldown--;
|
ap.itemUseCooldown--;
|
||||||
@@ -366,21 +378,21 @@ public class EntityPlayerActionPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
void inactiveTick(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||||
ap.itemUseCooldown = 0;
|
ap.itemUseCooldown = 0;
|
||||||
player.stopUsingItem();
|
player.stopUsingItem();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ATTACK(true) {
|
ATTACK(true) {
|
||||||
@Override
|
@Override
|
||||||
boolean execute(ServerPlayerEntity player, Action action) {
|
boolean execute(MinionFakePlayer player, Action action) {
|
||||||
HitResult hit = getTarget(player);
|
HitResult hit = getTarget(player);
|
||||||
switch (hit.getType()) {
|
switch (hit.getType()) {
|
||||||
case ENTITY: {
|
case ENTITY: {
|
||||||
EntityHitResult entityHit = (EntityHitResult) hit;
|
EntityHitResult entityHit = (EntityHitResult) hit;
|
||||||
if (!action.isContinuous)
|
if (!action.isContinuous || action.first)
|
||||||
{
|
{
|
||||||
player.attack(entityHit.getEntity());
|
player.attack(entityHit.getEntity());
|
||||||
player.swingHand(Hand.MAIN_HAND);
|
player.swingHand(Hand.MAIN_HAND);
|
||||||
@@ -390,10 +402,9 @@ public class EntityPlayerActionPack
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case BLOCK: {
|
case BLOCK: {
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||||
if (ap.blockHitDelay > 0)
|
if (ap.blockHitDelay > 0)
|
||||||
{
|
{
|
||||||
ap.blockHitDelay--;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||||
@@ -459,9 +470,9 @@ public class EntityPlayerActionPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
void inactiveTick(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||||
if (ap.currentBlock == null) return;
|
if (ap.currentBlock == null) return;
|
||||||
player.getWorld().setBlockBreakingInfo(-1, ap.currentBlock, -1);
|
player.getWorld().setBlockBreakingInfo(-1, ap.currentBlock, -1);
|
||||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopYInclusive(), -1);
|
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopYInclusive(), -1);
|
||||||
@@ -471,7 +482,7 @@ public class EntityPlayerActionPack
|
|||||||
JUMP(true)
|
JUMP(true)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
boolean execute(ServerPlayerEntity player, Action action)
|
boolean execute(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
if (action.limit == 1)
|
if (action.limit == 1)
|
||||||
{
|
{
|
||||||
@@ -485,7 +496,7 @@ public class EntityPlayerActionPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
void inactiveTick(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
player.setJumping(false);
|
player.setJumping(false);
|
||||||
}
|
}
|
||||||
@@ -493,7 +504,7 @@ public class EntityPlayerActionPack
|
|||||||
DROP_ITEM(true)
|
DROP_ITEM(true)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
boolean execute(ServerPlayerEntity player, Action action)
|
boolean execute(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
player.updateLastActionTime();
|
player.updateLastActionTime();
|
||||||
player.dropSelectedItem(false); // dropSelectedItem
|
player.dropSelectedItem(false); // dropSelectedItem
|
||||||
@@ -503,7 +514,7 @@ public class EntityPlayerActionPack
|
|||||||
DROP_STACK(true)
|
DROP_STACK(true)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
boolean execute(ServerPlayerEntity player, Action action)
|
boolean execute(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
player.updateLastActionTime();
|
player.updateLastActionTime();
|
||||||
player.dropSelectedItem(true); // dropSelectedItem
|
player.dropSelectedItem(true); // dropSelectedItem
|
||||||
@@ -513,7 +524,7 @@ public class EntityPlayerActionPack
|
|||||||
SWAP_HANDS(true)
|
SWAP_HANDS(true)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
boolean execute(ServerPlayerEntity player, Action action)
|
boolean execute(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
player.updateLastActionTime();
|
player.updateLastActionTime();
|
||||||
ItemStack itemStack_1 = player.getStackInHand(Hand.OFF_HAND);
|
ItemStack itemStack_1 = player.getStackInHand(Hand.OFF_HAND);
|
||||||
@@ -530,10 +541,10 @@ public class EntityPlayerActionPack
|
|||||||
this.preventSpectator = preventSpectator;
|
this.preventSpectator = preventSpectator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start(ServerPlayerEntity player, Action action) {}
|
void start(MinionFakePlayer player, Action action) {}
|
||||||
abstract boolean execute(ServerPlayerEntity player, Action action);
|
abstract boolean execute(MinionFakePlayer player, Action action);
|
||||||
void inactiveTick(ServerPlayerEntity player, Action action) {}
|
void inactiveTick(MinionFakePlayer player, Action action) {}
|
||||||
void stop(ServerPlayerEntity player, Action action)
|
void stop(MinionFakePlayer player, Action action)
|
||||||
{
|
{
|
||||||
inactiveTick(player, action);
|
inactiveTick(player, action);
|
||||||
}
|
}
|
||||||
@@ -548,8 +559,9 @@ public class EntityPlayerActionPack
|
|||||||
private int count;
|
private int count;
|
||||||
private int next;
|
private int next;
|
||||||
private final boolean isContinuous;
|
private final boolean isContinuous;
|
||||||
|
boolean first = true;
|
||||||
|
|
||||||
private Action(int limit, int interval, int offset, boolean continuous)
|
private Action(int limit, int interval, int offset, boolean continuous, boolean first)
|
||||||
{
|
{
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
@@ -560,22 +572,27 @@ public class EntityPlayerActionPack
|
|||||||
|
|
||||||
public static Action once()
|
public static Action once()
|
||||||
{
|
{
|
||||||
return new Action(1, 1, 0, false);
|
return new Action(1, 1, 0, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Action startContinuous()
|
||||||
|
{
|
||||||
|
return new Action(-1, 1, 0, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Action continuous()
|
public static Action continuous()
|
||||||
{
|
{
|
||||||
return new Action(-1, 1, 0, true);
|
return new Action(-1, 1, 0, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Action interval(int interval)
|
public static Action interval(int interval)
|
||||||
{
|
{
|
||||||
return new Action(-1, interval, 0, false);
|
return new Action(-1, interval, 0, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Action interval(int interval, int offset)
|
public static Action interval(int interval, int offset)
|
||||||
{
|
{
|
||||||
return new Action(-1, interval, offset, false);
|
return new Action(-1, interval, offset, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean tick(EntityPlayerActionPack actionPack, ActionType type)
|
Boolean tick(EntityPlayerActionPack actionPack, ActionType type)
|
||||||
@@ -606,6 +623,7 @@ public class EntityPlayerActionPack
|
|||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
next = interval;
|
next = interval;
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,19 +3,22 @@ package io.github.skippyall.minions.minion.fakeplayer;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import io.github.skippyall.minions.MinionItems;
|
import io.github.skippyall.minions.registration.MinionConfigOptions;
|
||||||
|
import io.github.skippyall.minions.registration.MinionItems;
|
||||||
|
import io.github.skippyall.minions.minion.MinionListener;
|
||||||
import io.github.skippyall.minions.minion.MinionData;
|
import io.github.skippyall.minions.minion.MinionData;
|
||||||
import io.github.skippyall.minions.gui.MinionGui;
|
import io.github.skippyall.minions.gui.MinionGui;
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
import io.github.skippyall.minions.minion.MinionItem;
|
import io.github.skippyall.minions.minion.MinionItem;
|
||||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||||
import io.github.skippyall.minions.gui.ModuleInventory;
|
import io.github.skippyall.minions.module.ModuleInventory;
|
||||||
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
import io.github.skippyall.minions.registration.SpecialAbilities;
|
||||||
|
import io.github.skippyall.minions.listener.SerializableListenerManager;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
import net.minecraft.entity.ItemEntity;
|
import net.minecraft.entity.ItemEntity;
|
||||||
import net.minecraft.entity.MovementType;
|
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
import net.minecraft.entity.attribute.EntityAttributes;
|
||||||
import net.minecraft.entity.damage.DamageSource;
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
import net.minecraft.entity.player.HungerManager;
|
import net.minecraft.entity.player.HungerManager;
|
||||||
@@ -46,17 +49,15 @@ import net.minecraft.world.TeleportTarget;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class MinionFakePlayer extends ServerPlayerEntity {
|
public class MinionFakePlayer extends ServerPlayerEntity {
|
||||||
public Runnable fixStartingPosition = () -> {};
|
public Runnable fixStartingPosition = () -> {};
|
||||||
|
|
||||||
private float moveForward;
|
private EntityPlayerActionPack actionPack;
|
||||||
private float moveSideways;
|
|
||||||
|
|
||||||
private final ModuleInventory moduleInventory = new ModuleInventory();
|
private final ModuleInventory moduleInventory = new ModuleInventory(this);
|
||||||
private final MinionRuntime runtime = new MinionRuntime(this);
|
private final MinionRuntime instructionManager = new MinionRuntime(this);
|
||||||
|
|
||||||
private final MinionData data;
|
|
||||||
|
|
||||||
public static void spawnMinion(MinionData data, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
public static void spawnMinion(MinionData data, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
||||||
spawnMinion(data, level, pos, rot, false);
|
spawnMinion(data, level, pos, rot, false);
|
||||||
@@ -74,8 +75,8 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void doSpawn(MinionData data, GameProfile profile, MinecraftServer server, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
private static void doSpawn(MinionData data, GameProfile profile, MinecraftServer server, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
||||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, SyncedClientOptions.createDefault(), data);
|
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, SyncedClientOptions.createDefault());
|
||||||
MinionPersistentState.INSTANCE.updateMinionData(data.withSpawned(true));
|
MinionPersistentState.get(server).updateMinionData(data.withSpawned(true));
|
||||||
|
|
||||||
if(pos != null && rot != null) {
|
if(pos != null && rot != null) {
|
||||||
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, rot.x, rot.y);
|
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, rot.x, rot.y);
|
||||||
@@ -90,34 +91,64 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
instance.unsetRemoved();
|
instance.unsetRemoved();
|
||||||
instance.getAttributeInstance(EntityAttributes.STEP_HEIGHT).setBaseValue(0.6F);
|
instance.getAttributeInstance(EntityAttributes.STEP_HEIGHT).setBaseValue(0.6F);
|
||||||
instance.interactionManager.changeGameMode(GameMode.SURVIVAL);
|
instance.interactionManager.changeGameMode(GameMode.SURVIVAL);
|
||||||
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), level.getRegistryKey());//instance.dimension);
|
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), level.getRegistryKey());
|
||||||
server.getPlayerManager().sendToDimension(EntityPositionSyncS2CPacket.create(instance), level.getRegistryKey());//instance.dimension);
|
server.getPlayerManager().sendToDimension(EntityPositionSyncS2CPacket.create(instance), level.getRegistryKey());
|
||||||
//instance.world.getChunkManager(). updatePosition(instance);
|
instance.getWorld().getChunkManager().updatePosition(instance);
|
||||||
instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
|
instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
|
||||||
instance.getAbilities().flying = false;
|
instance.getAbilities().flying = false;
|
||||||
|
|
||||||
|
instance.listeners().forEach(listener -> listener.onMinionSpawn(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerWorld level, GameProfile profile, SyncedClientOptions cli, MinionData data)
|
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerWorld level, GameProfile profile, SyncedClientOptions cli)
|
||||||
{
|
{
|
||||||
return new MinionFakePlayer(server, level, profile, cli, data);
|
return new MinionFakePlayer(server, level, profile, cli);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MinionFakePlayer(MinecraftServer server, ServerWorld worldIn, GameProfile profile, SyncedClientOptions cli, MinionData data)
|
private MinionFakePlayer(MinecraftServer server, ServerWorld worldIn, GameProfile profile, SyncedClientOptions cli)
|
||||||
{
|
{
|
||||||
super(server, worldIn, profile, cli);
|
super(server, worldIn, profile, cli);
|
||||||
this.data = data;
|
actionPack = new EntityPlayerActionPack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModuleInventory getModuleInventory() {
|
public ModuleInventory getModuleInventory() {
|
||||||
return moduleInventory;
|
return moduleInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinionRuntime getRuntime() {
|
public EntityPlayerActionPack getMinionActionPack() {
|
||||||
return runtime;
|
return actionPack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityPlayerActionPack getMinionActionPack() {
|
public MinionRuntime getInstructionManager() {
|
||||||
return ((ServerPlayerInterface)this).minions$getActionPack();
|
return instructionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionData getData() {
|
||||||
|
return MinionPersistentState.get(getServer()).getMinionData(getUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
public SerializableListenerManager<MinionListener> listeners() {
|
||||||
|
return getData().listeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMinionListener(MinionListener listener) {
|
||||||
|
listeners().addListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeMinionListener(MinionListener listener) {
|
||||||
|
listeners().removeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEachMinionListener(Consumer<MinionListener> listenerConsumer) {
|
||||||
|
listeners().forEach(listenerConsumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canSpawnMobs() {
|
||||||
|
return moduleInventory.hasAbility(SpecialAbilities.MOB_SPAWNING) || getData().config().getOption(MinionConfigOptions.spawnAndDespawnMobs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canDespawnMobs() {
|
||||||
|
return canSpawnMobs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -139,14 +170,10 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public void kill()
|
|
||||||
{
|
|
||||||
kill(Text.literal("Killed"));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public void kill(Text reason)
|
public void kill(Text reason)
|
||||||
{
|
{
|
||||||
|
listeners().forEach(listener -> listener.onMinionRemove(this));
|
||||||
|
|
||||||
shakeOff();
|
shakeOff();
|
||||||
|
|
||||||
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
||||||
@@ -157,12 +184,13 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
MinionPersistentState.INSTANCE.updateMinionData(data.withSpawned(false));
|
MinionPersistentState.get(getServer()).updateMinionData(getData().withSpawned(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void tick()
|
||||||
{
|
{
|
||||||
|
actionPack.onUpdate();
|
||||||
if (this.getServer().getTicks() % 10 == 0)
|
if (this.getServer().getTicks() % 10 == 0)
|
||||||
{
|
{
|
||||||
this.networkHandler.syncWithPlayerPosition();
|
this.networkHandler.syncWithPlayerPosition();
|
||||||
@@ -172,13 +200,13 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
{
|
{
|
||||||
super.tick();
|
super.tick();
|
||||||
this.playerTick();
|
this.playerTick();
|
||||||
|
instructionManager.tick();
|
||||||
}
|
}
|
||||||
catch (NullPointerException ignored)
|
catch (NullPointerException ignored)
|
||||||
{
|
{
|
||||||
// happens with that paper port thingy - not sure what that would fix, but hey
|
// happens with that paper port thingy - not sure what that would fix, but hey
|
||||||
// the game not gonna crash violently.
|
// the game not gonna crash violently.
|
||||||
}
|
}
|
||||||
runtime.tick();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,72 +262,32 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
|||||||
return networkHandler.player;
|
return networkHandler.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveForward(float forward) {
|
|
||||||
this.moveForward += forward;
|
|
||||||
EntityPlayerActionPack actionPack = getMinionActionPack();
|
|
||||||
if (moveForward != 0) {
|
|
||||||
actionPack.setForward(moveForward > 0 ? 1 : -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void moveSideways(float sideways) {
|
|
||||||
this.moveSideways += sideways;
|
|
||||||
EntityPlayerActionPack actionPack = getMinionActionPack();
|
|
||||||
if (moveSideways != 0) {
|
|
||||||
actionPack.setStrafing(moveSideways > 0 ? 1 : -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void move(MovementType movementType, Vec3d movement) {
|
|
||||||
float newForward = (float) (moveForward - movement.z);
|
|
||||||
float newSideways = (float) (moveSideways - movement.x);
|
|
||||||
Vec3d newMovement = movement;
|
|
||||||
if ((newForward < 0 && moveForward > 0) || (newForward > 0 && moveForward < 0)) {
|
|
||||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveForward);
|
|
||||||
moveForward = 0;
|
|
||||||
getMinionActionPack().setForward(0);
|
|
||||||
}else {
|
|
||||||
moveForward = newForward;
|
|
||||||
}
|
|
||||||
if ((newSideways < 0 && moveSideways > 0) || (newSideways > 0 && moveSideways < 0)) {
|
|
||||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveSideways);
|
|
||||||
moveSideways = 0;
|
|
||||||
getMinionActionPack().setStrafing(0);
|
|
||||||
}else {
|
|
||||||
moveSideways = newSideways;
|
|
||||||
}
|
|
||||||
super.move(movementType, newMovement);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drop(ServerWorld world, DamageSource damageSource) {
|
public void drop(ServerWorld world, DamageSource damageSource) {
|
||||||
super.drop(world, damageSource);
|
super.drop(world, damageSource);
|
||||||
ItemEntity entity = dropStack(world, toItemStack());
|
ItemEntity entity = dropStack(world, toItemStack(getServer()));
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
entity.setNeverDespawn();
|
entity.setNeverDespawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack toItemStack() {
|
private ItemStack toItemStack(MinecraftServer server) {
|
||||||
ItemStack stack = new ItemStack(MinionItems.MINION_ITEM);
|
ItemStack stack = new ItemStack(MinionItems.MINION_ITEM);
|
||||||
MinionItem.setData(data, stack);
|
MinionItem.setData(server, getData(), stack);
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinionData getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeCustomData(WriteView view) {
|
public void writeCustomData(WriteView view) {
|
||||||
super.writeCustomData(view);
|
super.writeCustomData(view);
|
||||||
moduleInventory.writeData(view.get("modules"));
|
moduleInventory.writeData(view.get("modules"));
|
||||||
|
instructionManager.save(view.get("instructionManager"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readCustomData(ReadView view) {
|
public void readCustomData(ReadView view) {
|
||||||
super.readCustomData(view);
|
super.readCustomData(view);
|
||||||
moduleInventory.readData(view.getReadView("modules"));
|
moduleInventory.readData(view.getReadView("modules"));
|
||||||
|
instructionManager.load(view.getReadView("instructionManager"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
//code from https://github.com/gnembon/fabric-carpet
|
|
||||||
package io.github.skippyall.minions.minion.fakeplayer;
|
|
||||||
|
|
||||||
public interface ServerPlayerInterface
|
|
||||||
{
|
|
||||||
EntityPlayerActionPack minions$getActionPack();
|
|
||||||
}
|
|
||||||
@@ -2,22 +2,102 @@ package io.github.skippyall.minions.minion.skin;
|
|||||||
|
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import io.github.skippyall.minions.input.TextInput;
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import net.minecraft.dialog.AfterAction;
|
||||||
|
import net.minecraft.dialog.DialogActionButtonData;
|
||||||
|
import net.minecraft.dialog.DialogButtonData;
|
||||||
|
import net.minecraft.dialog.DialogCommonData;
|
||||||
|
import net.minecraft.dialog.action.DynamicCustomDialogAction;
|
||||||
|
import net.minecraft.dialog.input.TextInputControl;
|
||||||
|
import net.minecraft.dialog.type.Dialog;
|
||||||
|
import net.minecraft.dialog.type.DialogInput;
|
||||||
|
import net.minecraft.dialog.type.NoticeDialog;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.nbt.NbtElement;
|
||||||
|
import net.minecraft.registry.RegistryKey;
|
||||||
|
import net.minecraft.registry.RegistryKeys;
|
||||||
|
import net.minecraft.registry.entry.RegistryEntry;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class Base64SkinProvider implements SkinProvider {
|
public class Base64SkinProvider implements SkinProvider {
|
||||||
|
public static final RegistryKey<Dialog> DIALOG = RegistryKey.of(RegistryKeys.DIALOG, Identifier.of(Minions.MOD_ID, "base_64_input"));
|
||||||
|
public static final Identifier CUSTOM_DIALOG_ACTION = Identifier.of(Minions.MOD_ID, "base_64_submit");
|
||||||
|
|
||||||
|
private static long dialogIdCounter = 0;
|
||||||
|
private static Map<Long, CompletableFuture<Optional<PropertyMap>>> futures = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player) {
|
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player) {
|
||||||
return TextInput.inputString(player, Text.translatable("minions.gui.look.skin.base64.title"), "")
|
dialogIdCounter++;
|
||||||
.thenApply(base64String -> {
|
player.openDialog(getDialog());
|
||||||
|
CompletableFuture<Optional<PropertyMap>> future = new CompletableFuture<>();
|
||||||
|
futures.put(dialogIdCounter, future);
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onCustomDialogAction(Optional<NbtElement> element) {
|
||||||
|
if(element.isPresent() && element.get() instanceof NbtCompound compound) {
|
||||||
|
Optional<Long> id = compound.getLong("dialog_id");
|
||||||
|
Optional<String> base64 = compound.getString("base_64");
|
||||||
|
if(id.isPresent() && base64.isPresent() && !base64.get().isBlank()) {
|
||||||
|
if(futures.containsKey(id.get())) {
|
||||||
PropertyMap map = new PropertyMap();
|
PropertyMap map = new PropertyMap();
|
||||||
map.put("textures", new Property("textures", base64String));
|
map.put("textures", new Property("textures", base64.get().strip()));
|
||||||
return Optional.of(map);
|
|
||||||
});
|
futures.get(id.get()).complete(Optional.of(map));
|
||||||
|
futures.remove(id.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RegistryEntry<Dialog> getDialog() {
|
||||||
|
NbtCompound additionalData = new NbtCompound();
|
||||||
|
additionalData.putLong("dialog_id", dialogIdCounter);
|
||||||
|
return RegistryEntry.of(
|
||||||
|
new NoticeDialog(
|
||||||
|
new DialogCommonData(
|
||||||
|
Text.translatable("minions.gui.look.skin.base64.title"),
|
||||||
|
Optional.empty(),
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
AfterAction.CLOSE,
|
||||||
|
List.of(),
|
||||||
|
List.of(
|
||||||
|
new DialogInput("base_64", new TextInputControl(
|
||||||
|
200,
|
||||||
|
Text.empty(),
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
2000,
|
||||||
|
Optional.empty()
|
||||||
|
))
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new DialogActionButtonData(
|
||||||
|
new DialogButtonData(
|
||||||
|
Text.translatable("gui.ok"),
|
||||||
|
150
|
||||||
|
),
|
||||||
|
Optional.of(
|
||||||
|
new DynamicCustomDialogAction(
|
||||||
|
CUSTOM_DIALOG_ACTION,
|
||||||
|
Optional.of(
|
||||||
|
additionalData
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package io.github.skippyall.minions.minion.skin;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import io.github.skippyall.minions.input.TextInput;
|
import io.github.skippyall.minions.gui.input.TextInput;
|
||||||
import net.minecraft.block.entity.SkullBlockEntity;
|
import net.minecraft.block.entity.SkullBlockEntity;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|||||||
@@ -2,16 +2,10 @@ package io.github.skippyall.minions.minion.skin;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import com.mojang.serialization.Codec;
|
import io.github.skippyall.minions.gui.input.TextInput;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
||||||
import io.github.skippyall.minions.input.TextInput;
|
|
||||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
|
||||||
import net.minecraft.block.entity.SkullBlockEntity;
|
import net.minecraft.block.entity.SkullBlockEntity;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Uuids;
|
|
||||||
import net.minecraft.util.dynamic.Codecs;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package io.github.skippyall.minions.mixinhelper;
|
package io.github.skippyall.minions.mixinhelper.antimobcap;
|
||||||
|
|
||||||
public interface ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor {
|
public interface ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor {
|
||||||
void minions$markAsMinionless();
|
void minions$markAsMinionless();
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package io.github.skippyall.minions.mixinhelper;
|
package io.github.skippyall.minions.mixinhelper.antimobcap;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
@@ -4,18 +4,26 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
|||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||||
import net.minecraft.server.world.ChunkLevelManager;
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
import org.slf4j.Logger;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
@Mixin(value = ChunkLevelManager.class)
|
@Mixin(value = ChunkLevelManager.class)
|
||||||
public class ChunkTicketManagerFixMixin {
|
public class ChunkTicketManagerFixMixin {
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private static Logger LOGGER;
|
||||||
|
|
||||||
@WrapOperation(method = "handleChunkLeave", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectSet;remove(Ljava/lang/Object;)Z", remap = false))
|
@WrapOperation(method = "handleChunkLeave", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectSet;remove(Ljava/lang/Object;)Z", remap = false))
|
||||||
public boolean filterIfNull(ObjectSet instance, Object o, Operation<Boolean> original) {
|
public boolean filterIfNull(ObjectSet instance, Object o, Operation<Boolean> original) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
return original.call(instance, o);
|
return original.call(instance, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.error("Prevented NPE in handleChunkLeave");
|
||||||
|
|
||||||
return false;//Unused
|
return false;//Unused
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +33,8 @@ public class ChunkTicketManagerFixMixin {
|
|||||||
return original.call(instance);
|
return original.call(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.error("Prevented NPE in handleChunkLeave");
|
||||||
|
|
||||||
return true;//Unused
|
return true;//Unused
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(Entity.class)
|
||||||
|
public abstract class EntityMixin {
|
||||||
|
@Shadow
|
||||||
|
public abstract @Nullable LivingEntity getControllingPassenger();
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
@Inject(method = "isLogicalSideForUpdatingMovement", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void isFakePlayer(CallbackInfoReturnable<Boolean> cir)
|
||||||
|
{
|
||||||
|
if (getControllingPassenger() instanceof MinionFakePlayer) cir.setReturnValue(!world.isClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,21 +2,38 @@ package io.github.skippyall.minions.mixins;
|
|||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.minion.skin.Base64SkinProvider;
|
||||||
|
import io.github.skippyall.minions.registration.MinionConfigOptions;
|
||||||
|
import net.minecraft.nbt.NbtElement;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Mixin(MinecraftServer.class)
|
@Mixin(MinecraftServer.class)
|
||||||
public class MinecraftServerMixin {
|
public class MinecraftServerMixin {
|
||||||
|
|
||||||
@ModifyExpressionValue(method = "createMetadataPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;getPlayerList()Ljava/util/List;"))
|
@ModifyExpressionValue(method = "createMetadataPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;getPlayerList()Ljava/util/List;"))
|
||||||
public List<ServerPlayerEntity> ignoreFakePlayers(List<ServerPlayerEntity> original) {
|
public List<ServerPlayerEntity> ignoreFakePlayers(List<ServerPlayerEntity> original) {
|
||||||
return original.stream()
|
return original.stream()
|
||||||
.filter(player -> !(player instanceof MinionFakePlayer))
|
.filter(player -> !(player instanceof MinionFakePlayer minion
|
||||||
|
&& !minion.getData().config().getOption(MinionConfigOptions.showInServerList)))
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "handleCustomClickAction", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void onCustomClickAction(Identifier id, Optional<NbtElement> payload, CallbackInfo ci) {
|
||||||
|
if(id.equals(Base64SkinProvider.CUSTOM_DIALOG_ACTION)) {
|
||||||
|
Base64SkinProvider.onCustomDialogAction(payload);
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
|||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.mixinhelper.EntityViewMixinHelper;
|
import io.github.skippyall.minions.mixinhelper.EntityViewMixinHelper;
|
||||||
import io.github.skippyall.minions.module.MobSpawningModule;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.mob.MobEntity;
|
import net.minecraft.entity.mob.MobEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
@@ -18,7 +17,7 @@ public abstract class MobEntityMixin {
|
|||||||
public PlayerEntity checkMobDespawningMinion(World instance, Entity entity, double maxDistance, Operation<PlayerEntity> original) {
|
public PlayerEntity checkMobDespawningMinion(World instance, Entity entity, double maxDistance, Operation<PlayerEntity> original) {
|
||||||
EntityViewMixinHelper.ADDITIONAL_PREDICATE.set(entity2 -> {
|
EntityViewMixinHelper.ADDITIONAL_PREDICATE.set(entity2 -> {
|
||||||
if(entity2 instanceof MinionFakePlayer minion) {
|
if(entity2 instanceof MinionFakePlayer minion) {
|
||||||
return MobSpawningModule.canMinionDespawnMobs(minion);
|
return minion.canDespawnMobs();
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -2,6 +2,7 @@ package io.github.skippyall.minions.mixins;
|
|||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.registration.MinionConfigOptions;
|
||||||
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
|
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@@ -12,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
|
|||||||
public class PlayerListEntryS2CPacket$EntryMixin {
|
public class PlayerListEntryS2CPacket$EntryMixin {
|
||||||
@ModifyArg(method = "<init>(Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/PlayerListS2CPacket$Entry;<init>(Ljava/util/UUID;Lcom/mojang/authlib/GameProfile;ZILnet/minecraft/world/GameMode;Lnet/minecraft/text/Text;ZILnet/minecraft/network/encryption/PublicPlayerSession$Serialized;)V"), index = 2)
|
@ModifyArg(method = "<init>(Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/PlayerListS2CPacket$Entry;<init>(Ljava/util/UUID;Lcom/mojang/authlib/GameProfile;ZILnet/minecraft/world/GameMode;Lnet/minecraft/text/Text;ZILnet/minecraft/network/encryption/PublicPlayerSession$Serialized;)V"), index = 2)
|
||||||
private static boolean removeMinionFromTabList(boolean original, @Local(argsOnly = true) ServerPlayerEntity player) {
|
private static boolean removeMinionFromTabList(boolean original, @Local(argsOnly = true) ServerPlayerEntity player) {
|
||||||
if(player instanceof MinionFakePlayer) {
|
if(player instanceof MinionFakePlayer minion && !minion.getData().config().getOption(MinionConfigOptions.showInTabList)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import com.llamalad7.mixinextras.sugar.Local;
|
|||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.NetHandlerPlayServerFake;
|
import io.github.skippyall.minions.minion.fakeplayer.NetHandlerPlayServerFake;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import io.github.skippyall.minions.registration.MinionConfigOptions;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
@@ -55,14 +55,14 @@ public class PlayerListMixin {
|
|||||||
@WrapOperation(method = "respawnPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/world/ServerWorld;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/network/packet/c2s/common/SyncedClientOptions;)Lnet/minecraft/server/network/ServerPlayerEntity;"))
|
@WrapOperation(method = "respawnPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/world/ServerWorld;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/network/packet/c2s/common/SyncedClientOptions;)Lnet/minecraft/server/network/ServerPlayerEntity;"))
|
||||||
public ServerPlayerEntity makePlayerForRespawn(MinecraftServer minecraftServer, ServerWorld serverLevel, GameProfile gameProfile, SyncedClientOptions clientInformation, Operation<ServerPlayerEntity> original, ServerPlayerEntity serverPlayer, boolean bl) {
|
public ServerPlayerEntity makePlayerForRespawn(MinecraftServer minecraftServer, ServerWorld serverLevel, GameProfile gameProfile, SyncedClientOptions clientInformation, Operation<ServerPlayerEntity> original, ServerPlayerEntity serverPlayer, boolean bl) {
|
||||||
if (serverPlayer instanceof MinionFakePlayer minion) {
|
if (serverPlayer instanceof MinionFakePlayer minion) {
|
||||||
return MinionFakePlayer.respawnFake(minecraftServer, serverLevel, gameProfile, clientInformation, minion.getData());
|
return MinionFakePlayer.respawnFake(minecraftServer, serverLevel, gameProfile, clientInformation);
|
||||||
}
|
}
|
||||||
return original.call(minecraftServer, serverLevel, gameProfile, clientInformation);
|
return original.call(minecraftServer, serverLevel, gameProfile, clientInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WrapOperation(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
@WrapOperation(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
||||||
public void noLoginMessage(PlayerManager instance, Text message, boolean overlay, Operation<Void> original, @Local(argsOnly = true) ServerPlayerEntity player) {
|
public void noLoginMessage(PlayerManager instance, Text message, boolean overlay, Operation<Void> original, @Local(argsOnly = true) ServerPlayerEntity player) {
|
||||||
if(!(player instanceof MinionFakePlayer)) {
|
if(!(player instanceof MinionFakePlayer minion && !minion.getData().config().getOption(MinionConfigOptions.sendLoginMessage))) {
|
||||||
original.call(instance, message, overlay);
|
original.call(instance, message, overlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ public class PlayerListMixin {
|
|||||||
@ModifyReceiver(method = "checkCanJoin", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I"))
|
@ModifyReceiver(method = "checkCanJoin", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I"))
|
||||||
public List<ServerPlayerEntity> noMinionCounting(List<ServerPlayerEntity> instance) {
|
public List<ServerPlayerEntity> noMinionCounting(List<ServerPlayerEntity> instance) {
|
||||||
return instance.stream()
|
return instance.stream()
|
||||||
.filter(player -> !(player instanceof MinionFakePlayer))
|
.filter(player -> !(player instanceof MinionFakePlayer minion && !minion.getData().config().getOption(MinionConfigOptions.countForPlayerLimit)))
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//code from https://github.com/gnembon/fabric-carpet
|
||||||
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
@Mixin(PlayerEntity.class)
|
||||||
|
public abstract class PlayerMixin {
|
||||||
|
/**
|
||||||
|
* To make sure player attacks are able to knockback fake players
|
||||||
|
*/
|
||||||
|
@ModifyExpressionValue(
|
||||||
|
method = "attack",
|
||||||
|
at = @At(
|
||||||
|
value = "FIELD",
|
||||||
|
target = "Lnet/minecraft/entity/Entity;velocityModified:Z",
|
||||||
|
ordinal = 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private boolean velocityModifiedAndNotCarpetFakePlayer(boolean value, @Local(argsOnly = true) Entity entity) {
|
||||||
|
return value && !(entity instanceof MinionFakePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package io.github.skippyall.minions.mixins;
|
|||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.registration.MinionConfigOptions;
|
||||||
import net.minecraft.server.PlayerManager;
|
import net.minecraft.server.PlayerManager;
|
||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
@@ -18,7 +19,7 @@ public class ServerPlayNetworkHandlerMixin {
|
|||||||
|
|
||||||
@WrapOperation(method = "cleanUp", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
@WrapOperation(method = "cleanUp", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
||||||
public void noLogoutMessage(PlayerManager instance, Text message, boolean overlay, Operation<Void> original) {
|
public void noLogoutMessage(PlayerManager instance, Text message, boolean overlay, Operation<Void> original) {
|
||||||
if(!(player instanceof MinionFakePlayer)) {
|
if(!(player instanceof MinionFakePlayer minion && !minion.getData().config().getOption(MinionConfigOptions.sendLogoutMessage))) {
|
||||||
original.call(instance, message, overlay);
|
original.call(instance, message, overlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.ServerPlayerInterface;
|
|
||||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(ServerPlayerEntity.class)
|
|
||||||
public abstract class ServerPlayerMixin implements ServerPlayerInterface {
|
|
||||||
@Unique
|
|
||||||
public EntityPlayerActionPack actionPack;
|
|
||||||
@Override
|
|
||||||
public EntityPlayerActionPack minions$getActionPack()
|
|
||||||
{
|
|
||||||
return actionPack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At(value = "RETURN"))
|
|
||||||
private void onServerPlayerEntityConstructor(MinecraftServer minecraftServer, ServerWorld serverLevel, GameProfile gameProfile, SyncedClientOptions clientInformation, CallbackInfo ci)
|
|
||||||
{
|
|
||||||
this.actionPack = new EntityPlayerActionPack((ServerPlayerEntity) (Object) this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "tick", at = @At(value = "HEAD"))
|
|
||||||
private void onTick(CallbackInfo ci)
|
|
||||||
{
|
|
||||||
actionPack.onUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package io.github.skippyall.minions.mixins;
|
|||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.registration.MinionConfigOptions;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.SleepManager;
|
import net.minecraft.server.world.SleepManager;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@@ -12,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
public class SleepManagerMixin {
|
public class SleepManagerMixin {
|
||||||
@WrapOperation(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;isSpectator()Z"))
|
@WrapOperation(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;isSpectator()Z"))
|
||||||
public boolean excludeMinions(ServerPlayerEntity instance, Operation<Boolean> original) {
|
public boolean excludeMinions(ServerPlayerEntity instance, Operation<Boolean> original) {
|
||||||
if (instance instanceof MinionFakePlayer) {
|
if (instance instanceof MinionFakePlayer minion && !minion.getData().config().getOption(MinionConfigOptions.countForSleeping)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return original.call(instance);
|
return original.call(instance);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.module.MobSpawningModule;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.predicate.entity.EntityPredicates;
|
import net.minecraft.predicate.entity.EntityPredicates;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
@@ -18,7 +17,7 @@ public class SpawnHelperMixin {
|
|||||||
return instance.getClosestPlayer(x, y, z, maxDistance, EntityPredicates.EXCEPT_SPECTATOR.and(entity -> {
|
return instance.getClosestPlayer(x, y, z, maxDistance, EntityPredicates.EXCEPT_SPECTATOR.and(entity -> {
|
||||||
if(entity instanceof ServerPlayerEntity player) {
|
if(entity instanceof ServerPlayerEntity player) {
|
||||||
if(player instanceof MinionFakePlayer minion) {
|
if(player instanceof MinionFakePlayer minion) {
|
||||||
return MobSpawningModule.canMinionSpawnMobs(minion);
|
return minion.canSpawnMobs();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -1,14 +1,12 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkLevelManagerAccessor;
|
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManagerAccessor;
|
||||||
import io.github.skippyall.minions.module.MobSpawningModule;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ByteMap;
|
import it.unimi.dsi.fastutil.longs.Long2ByteMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ChunkLevelManager;
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
@@ -47,7 +45,7 @@ public abstract class ChunkLevelManager$DistanceFromNearestPlayerTrackerMixin ex
|
|||||||
if(players != null) {
|
if(players != null) {
|
||||||
contains = players.stream().anyMatch(player -> {
|
contains = players.stream().anyMatch(player -> {
|
||||||
if (player instanceof MinionFakePlayer minion) {
|
if (player instanceof MinionFakePlayer minion) {
|
||||||
return MobSpawningModule.canMinionSpawnMobs(minion);
|
return minion.canSpawnMobs();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkLevelManagerAccessor;
|
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManagerAccessor;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
@@ -21,7 +21,7 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
@Mixin(ChunkLevelManager.class)
|
@Mixin(ChunkLevelManager.class)
|
||||||
public class ChunkLevelManagerMixin implements ChunkLevelManagerAccessor {
|
public class ChunkLevelManagerMixin implements ChunkLevelManagerAccessor {
|
||||||
@Shadow @Final private Long2ObjectMap<ObjectSet<ServerPlayerEntity>> playersByChunkPos;
|
@Shadow @Final Long2ObjectMap<ObjectSet<ServerPlayerEntity>> playersByChunkPos;
|
||||||
@Shadow @Final private ChunkLevelManager.DistanceFromNearestPlayerTracker distanceFromNearestPlayerTracker;
|
@Shadow @Final private ChunkLevelManager.DistanceFromNearestPlayerTracker distanceFromNearestPlayerTracker;
|
||||||
@Unique
|
@Unique
|
||||||
ChunkLevelManager.DistanceFromNearestPlayerTracker minionless;
|
ChunkLevelManager.DistanceFromNearestPlayerTracker minionless;
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
import net.minecraft.server.world.ServerChunkManager;
|
import net.minecraft.server.world.ServerChunkManager;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
@@ -8,5 +8,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
|||||||
@Mixin(ServerChunkManager.class)
|
@Mixin(ServerChunkManager.class)
|
||||||
public interface ServerChunkManagerAccessor {
|
public interface ServerChunkManagerAccessor {
|
||||||
@Accessor
|
@Accessor
|
||||||
ChunkTicketManager getTicketManager();
|
ChunkLevelManager getLevelManager();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -1,9 +1,8 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkLevelManagerAccessor;
|
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManagerAccessor;
|
||||||
import net.minecraft.server.world.ChunkLevelManager;
|
import net.minecraft.server.world.ChunkLevelManager;
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import net.minecraft.server.world.ServerChunkManager;
|
import net.minecraft.server.world.ServerChunkManager;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
package io.github.skippyall.minions.mixins.compat.universal_graves;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import eu.pb4.graves.grave.Grave;
|
import eu.pb4.graves.grave.Grave;
|
||||||
@@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
|
||||||
@Mixin(Grave.class)
|
@Mixin(Grave.class)
|
||||||
public class GraveCompatMixin {
|
public class GraveMixin {
|
||||||
@ModifyArg(method = "createBlock", at = @At(value = "INVOKE", target = "Leu/pb4/graves/grave/Grave;<init>(JLcom/mojang/authlib/GameProfile;BLnet/minecraft/util/Arm;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Identifier;Leu/pb4/graves/grave/GraveType;JJILnet/minecraft/text/Text;Ljava/util/Collection;Ljava/util/Collection;ZI)V"))
|
@ModifyArg(method = "createBlock", at = @At(value = "INVOKE", target = "Leu/pb4/graves/grave/Grave;<init>(JLcom/mojang/authlib/GameProfile;BLnet/minecraft/util/Arm;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Identifier;Leu/pb4/graves/grave/GraveType;JJILnet/minecraft/text/Text;Ljava/util/Collection;Ljava/util/Collection;ZI)V"))
|
||||||
private static boolean createGrave(boolean profile, @Local(argsOnly = true) ServerPlayerEntity player) {
|
private static boolean createGrave(boolean profile, @Local(argsOnly = true) ServerPlayerEntity player) {
|
||||||
if(player instanceof MinionFakePlayer) {
|
if(player instanceof MinionFakePlayer) {
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
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.module.command.CommandExecutor;
|
|
||||||
import io.github.skippyall.minions.input.TextInput;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
|
||||||
import io.github.skippyall.minions.minion.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 executeContinuous(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.continuous());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void executeInterval(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
TextInput.inputFloat(player, Text.translatable("minions.command.action.interval.enter"), "3.5").thenAccept(interval -> {
|
|
||||||
int ticks = Math.round(interval * 20);
|
|
||||||
minion.getMinionActionPack().start(actionType, EntityPlayerActionPack.Action.interval(ticks));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void executeStop(EntityPlayerActionPack.ActionType actionType, ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
minion.getMinionActionPack().stop(actionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
|
||||||
);
|
|
||||||
gui.setSlot(3, new GuiElementBuilder()
|
|
||||||
.setItem(Items.REPEATING_COMMAND_BLOCK)
|
|
||||||
.setName(Text.translatable("minions.command.action.continuous", actionName))
|
|
||||||
.setCallback(() -> executeContinuous(actionType, player, minion))
|
|
||||||
);
|
|
||||||
gui.setSlot(5, new GuiElementBuilder()
|
|
||||||
.setItem(Items.CHAIN_COMMAND_BLOCK)
|
|
||||||
.setName(Text.translatable("minions.command.action.interval", actionName))
|
|
||||||
.setCallback(() -> executeInterval(actionType, player, minion))
|
|
||||||
);
|
|
||||||
gui.setSlot(4, new GuiElementBuilder()
|
|
||||||
.setItem(Items.BARRIER)
|
|
||||||
.setName(Text.translatable("minions.command.action.stop", actionName))
|
|
||||||
.setCallback(() -> executeStop(actionType, player, minion))
|
|
||||||
);
|
|
||||||
gui.open();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.module.command.SimpleCommand;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.module.Modules.register;
|
|
||||||
|
|
||||||
public class AttackModule {
|
|
||||||
public static final SimpleCommand ATTACK_COMMAND = new SimpleCommand(
|
|
||||||
Text.translatable("minions.command.attack.name"),
|
|
||||||
Text.translatable("minions.command.attack.description"),
|
|
||||||
Items.DIAMOND_PICKAXE,
|
|
||||||
ActionModules.detailSelectionExecutor(EntityPlayerActionPack.ActionType.ATTACK, Text.translatable("minions.command.attack.name"))
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final SimpleModuleItem ATTACK_MODULE = register(
|
|
||||||
Identifier.of(Minions.MOD_ID, "attack_module"),
|
|
||||||
List.of(),
|
|
||||||
List.of(ATTACK_COMMAND),
|
|
||||||
Items.DIAMOND_PICKAXE
|
|
||||||
);
|
|
||||||
|
|
||||||
public static void registerMe() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.module.command.SimpleCommand;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.module.Modules.register;
|
|
||||||
|
|
||||||
public class ChatModule {
|
|
||||||
public static final SimpleModuleItem CHAT_MODULE = register(Identifier.of(Minions.MOD_ID, "chat_module"),
|
|
||||||
new ArrayList<>(), Arrays.asList(
|
|
||||||
new SimpleCommand(Text.of("Message"), Text.of("Send Message in Public Chat"), Items.PAPER, (player, minion) -> minion.getServer().getPlayerManager().broadcast(Text.of("message"), true)),
|
|
||||||
new SimpleCommand(Text.of("Prvt-Message"), Text.of("Send Message to one Person"), Items.TRIAL_KEY, (player, minion) -> {})
|
|
||||||
), Items.PAPER);
|
|
||||||
|
|
||||||
public static void registerMe() {}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.module.command.SimpleCommand;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.module.Modules.register;
|
|
||||||
|
|
||||||
public class InteractModule {
|
|
||||||
public static final SimpleCommand INTERACT_COMMAND = new SimpleCommand(
|
|
||||||
Text.translatable("minions.command.interact.name"),
|
|
||||||
Text.translatable("minions.command.interact.description"),
|
|
||||||
Items.LEVER,
|
|
||||||
ActionModules.detailSelectionExecutor(EntityPlayerActionPack.ActionType.USE, Text.translatable("minions.command.interact.name"))
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final SimpleModuleItem INTERACT_MODULE = register(
|
|
||||||
Identifier.of(Minions.MOD_ID, "interact_module"),
|
|
||||||
List.of(),
|
|
||||||
List.of(INTERACT_COMMAND),
|
|
||||||
Items.LEVER
|
|
||||||
);
|
|
||||||
|
|
||||||
public static void registerMe() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record MinionModule(List<InstructionType<MinionRuntime>> instructions, List<SpecialAbility> specialAbilities) {
|
||||||
|
public static final Codec<MinionModule> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
|
instance.group(
|
||||||
|
MinionRegistries.INSTRUCTION_TYPES.getCodec().listOf().fieldOf("instructions").forGetter(MinionModule::instructions),
|
||||||
|
MinionRegistries.SPECIAL_ABILITIES.getCodec().listOf().fieldOf("specialAbilities").forGetter(MinionModule::specialAbilities)
|
||||||
|
).apply(instance, MinionModule::new)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final MinionModule EMPTY = new MinionModule(List.of());
|
||||||
|
|
||||||
|
public MinionModule(List<InstructionType<MinionRuntime>> instructions) {
|
||||||
|
this(instructions, List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinionModule(List<InstructionType<MinionRuntime>> instructions, List<SpecialAbility> specialAbilities) {
|
||||||
|
this.instructions = List.copyOf(instructions);
|
||||||
|
this.specialAbilities = List.copyOf(specialAbilities);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
|
||||||
|
public class MobSpawningAbility implements SpecialAbility {
|
||||||
|
@Override
|
||||||
|
public void onAdd(MinionFakePlayer minion) {
|
||||||
|
SpecialAbility.super.onAdd(minion);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemove(MinionFakePlayer minion) {
|
||||||
|
SpecialAbility.super.onRemove(minion);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.module.Modules.register;
|
|
||||||
|
|
||||||
public class MobSpawningModule {
|
|
||||||
public static final SimpleModuleItem MOB_SPAWNING_MODULE =
|
|
||||||
register(
|
|
||||||
Identifier.of(Minions.MOD_ID, "mob_spawning_module"),
|
|
||||||
List.of(),
|
|
||||||
List.of(),
|
|
||||||
Items.SPAWNER
|
|
||||||
);
|
|
||||||
|
|
||||||
public static boolean canMinionSpawnMobs(MinionFakePlayer minion) {
|
|
||||||
return minion.getModuleInventory().hasModule(MOB_SPAWNING_MODULE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canMinionDespawnMobs(MinionFakePlayer minion) {
|
|
||||||
return minion.getModuleInventory().hasModule(MOB_SPAWNING_MODULE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerMe() {}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionType;
|
||||||
|
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||||
|
import net.minecraft.inventory.Inventories;
|
||||||
|
import net.minecraft.inventory.SimpleInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.storage.ReadView;
|
||||||
|
import net.minecraft.storage.WriteView;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ModuleInventory extends SimpleInventory {
|
||||||
|
private final Set<MinionModule> modules = new HashSet<>();
|
||||||
|
private final Set<InstructionType<MinionRuntime>> instructions = new HashSet<>();
|
||||||
|
private final Set<SpecialAbility> specialAbilities = new HashSet<>();
|
||||||
|
|
||||||
|
private final MinionFakePlayer minion;
|
||||||
|
|
||||||
|
public ModuleInventory(MinionFakePlayer minion) {
|
||||||
|
super(27);
|
||||||
|
this.minion = minion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openModuleInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player2) -> new ModuleInventoryScreenHandler(syncId, playerInventory, minion.getModuleInventory()), Text.translatable("minions.gui.modules.title", minion.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxCountPerStack() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(int slot, ItemStack stack) {
|
||||||
|
return (stack.getCount() <= getMaxCountPerStack()) && stack.contains(MinionComponentTypes.MODULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markDirty() {
|
||||||
|
super.markDirty();
|
||||||
|
updateModules();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateModules() {
|
||||||
|
Set<MinionModule> oldModules = Set.copyOf(modules);
|
||||||
|
Set<InstructionType<MinionRuntime>> oldInstructions = Set.copyOf(instructions);
|
||||||
|
Set<SpecialAbility> oldAbilities = Set.copyOf(specialAbilities);
|
||||||
|
|
||||||
|
modules.clear();
|
||||||
|
instructions.clear();
|
||||||
|
specialAbilities.clear();
|
||||||
|
for (ItemStack heldStack : heldStacks) {
|
||||||
|
MinionModule module = heldStack.get(MinionComponentTypes.MODULE);
|
||||||
|
if(module != null) {
|
||||||
|
modules.add(module);
|
||||||
|
instructions.addAll(module.instructions());
|
||||||
|
specialAbilities.addAll(module.specialAbilities());
|
||||||
|
|
||||||
|
for(InstructionType<MinionRuntime> instructionType : module.instructions()) {
|
||||||
|
if(!oldInstructions.contains(instructionType)) {
|
||||||
|
minion.getInstructionManager().enableInstructionType(instructionType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(SpecialAbility ability : module.specialAbilities()) {
|
||||||
|
if(!oldAbilities.contains(ability)) {
|
||||||
|
ability.onAdd(minion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(InstructionType<MinionRuntime> instructionType : oldInstructions) {
|
||||||
|
if(!instructions.contains(instructionType)) {
|
||||||
|
minion.getInstructionManager().disableInstructionType(instructionType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(SpecialAbility ability : oldAbilities) {
|
||||||
|
if(!specialAbilities.contains(ability)) {
|
||||||
|
ability.onRemove(minion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readData(ReadView view) {
|
||||||
|
Inventories.readData(view, heldStacks);
|
||||||
|
updateModules();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeData(WriteView view) {
|
||||||
|
Inventories.writeData(view, heldStacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<MinionModule> getModules() {
|
||||||
|
return modules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAbility(SpecialAbility ability) {
|
||||||
|
return specialAbilities.contains(ability);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasInstruction(InstructionType<MinionRuntime> instructionType) {
|
||||||
|
return instructions.contains(instructionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<InstructionType<MinionRuntime>> getAllInstructions() {
|
||||||
|
return instructions;
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-18
@@ -1,4 +1,4 @@
|
|||||||
package io.github.skippyall.minions.gui;
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
@@ -11,21 +11,16 @@ import net.minecraft.screen.slot.Slot;
|
|||||||
public class ModuleInventoryScreenHandler extends ScreenHandler {
|
public class ModuleInventoryScreenHandler extends ScreenHandler {
|
||||||
private final int rows = 3;
|
private final int rows = 3;
|
||||||
private final ModuleInventory inventory;
|
private final ModuleInventory inventory;
|
||||||
public ModuleInventoryScreenHandler(int syncId, ModuleInventory inventory) {
|
|
||||||
super(ScreenHandlerType.GENERIC_9X3, syncId);
|
|
||||||
this.inventory = inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModuleInventoryScreenHandler(int syncId, PlayerInventory playerInventory, ModuleInventory inventory) {
|
public ModuleInventoryScreenHandler(int syncId, PlayerInventory playerInventory, ModuleInventory inventory) {
|
||||||
super(ScreenHandlerType.GENERIC_9X3, syncId);
|
super(ScreenHandlerType.GENERIC_9X3, syncId);
|
||||||
int k;
|
|
||||||
int j;
|
|
||||||
GenericContainerScreenHandler.checkSize(inventory, 3 * 9);
|
GenericContainerScreenHandler.checkSize(inventory, 3 * 9);
|
||||||
this.inventory = inventory;
|
this.inventory = inventory;
|
||||||
inventory.onOpen(playerInventory.player);
|
inventory.onOpen(playerInventory.player);
|
||||||
int i = (rows - 4) * 18;
|
|
||||||
for (j = 0; j < rows; ++j) {
|
for (int j = 0; j < rows; ++j) {
|
||||||
for (k = 0; k < 9; ++k) {
|
for (int k = 0; k < 9; ++k) {
|
||||||
this.addSlot(new Slot(inventory, k + j * 9, 8 + k * 18, 18 + j * 18) {
|
this.addSlot(new Slot(inventory, k + j * 9, 8 + k * 18, 18 + j * 18) {
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(ItemStack stack) {
|
public boolean canInsert(ItemStack stack) {
|
||||||
@@ -34,14 +29,8 @@ public class ModuleInventoryScreenHandler extends ScreenHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (j = 0; j < 3; ++j) {
|
|
||||||
for (k = 0; k < 9; ++k) {
|
addPlayerSlots(playerInventory, 8, 85);
|
||||||
this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (j = 0; j < 9; ++j) {
|
|
||||||
this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 161 + i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.module.command.Command;
|
|
||||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
|
||||||
import net.minecraft.item.ItemConvertible;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface ModuleItem extends ItemConvertible {
|
|
||||||
List<CodeBlock<?,?>> getCodeBlocks();
|
|
||||||
|
|
||||||
List<Command> getCommands();
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.MinionItems;
|
|
||||||
import io.github.skippyall.minions.module.command.Command;
|
|
||||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.registry.Registries;
|
|
||||||
import net.minecraft.registry.Registry;
|
|
||||||
import net.minecraft.registry.RegistryKey;
|
|
||||||
import net.minecraft.registry.RegistryKeys;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Modules {
|
|
||||||
public static void register() {
|
|
||||||
ChatModule.registerMe();
|
|
||||||
MountModule.registerMe();
|
|
||||||
MoveModule.registerMe();
|
|
||||||
MobSpawningModule.registerMe();
|
|
||||||
InteractModule.registerMe();
|
|
||||||
AttackModule.registerMe();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SimpleModuleItem register(Identifier id, List<CodeBlock<?,?>> codeBlocks, List<Command> commands, Item vanillaItem) {
|
|
||||||
return MinionItems.registerItem(id, settings -> new SimpleModuleItem(codeBlocks, commands, settings, vanillaItem));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.module.command.SimpleCommand;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.module.Modules.register;
|
|
||||||
|
|
||||||
public class MountModule {
|
|
||||||
public static final SimpleCommand MOUNT_COMMAND = new SimpleCommand(
|
|
||||||
Text.of("Mount"),
|
|
||||||
Text.of("Mount the minion to the nearest mountable Entity"),
|
|
||||||
Items.MINECART,
|
|
||||||
(player, minion) -> minion.getMinionActionPack().mount(true)
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final SimpleCommand DISMOUNT_COMMAND = new SimpleCommand(
|
|
||||||
Text.of("Dismount"),
|
|
||||||
Text.of("Dismount the minion"),
|
|
||||||
Items.BARRIER,
|
|
||||||
(player, minion) -> minion.getMinionActionPack().dismount()
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final SimpleModuleItem MOUNT_MODULE =
|
|
||||||
register(Identifier.of(Minions.MOD_ID, "mount_module"),
|
|
||||||
List.of(),
|
|
||||||
List.of(
|
|
||||||
MOUNT_COMMAND,
|
|
||||||
DISMOUNT_COMMAND
|
|
||||||
),
|
|
||||||
Items.MINECART
|
|
||||||
);
|
|
||||||
|
|
||||||
public static void registerMe() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.module.command.SimpleCommand;
|
|
||||||
import io.github.skippyall.minions.input.TextInput;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.module.Modules.register;
|
|
||||||
|
|
||||||
public class MoveModule {
|
|
||||||
public static final SimpleCommand WALK_COMMAND =
|
|
||||||
new SimpleCommand(
|
|
||||||
Text.literal("Walk"),
|
|
||||||
Text.literal("Walk a specific amount of blocks forward"),
|
|
||||||
Items.IRON_BOOTS,
|
|
||||||
(player, minion) -> TextInput.inputFloat(player, Text.literal("Amount of Blocks"), "1")
|
|
||||||
.thenAccept(minion::moveForward)
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final SimpleCommand TURN_RIGHT_COMMAND =
|
|
||||||
new SimpleCommand(
|
|
||||||
Text.literal("Turn Right"),
|
|
||||||
Text.literal("Turn a specific amount of degrees right"),
|
|
||||||
Items.COMPASS,
|
|
||||||
(player, minion) -> TextInput.inputFloat(player, Text.literal("Degrees"), "90")
|
|
||||||
.thenAccept(degrees -> minion.getMinionActionPack().turn(degrees, 0))
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final SimpleCommand TURN_LEFT_COMMAND =
|
|
||||||
new SimpleCommand(
|
|
||||||
Text.literal("Turn Left"),
|
|
||||||
Text.literal("Turn a specific amount of degrees left"),
|
|
||||||
Items.COMPASS,
|
|
||||||
(player, minion) -> TextInput.inputFloat(player, Text.literal("Degrees"), "90")
|
|
||||||
.thenAccept(degrees -> minion.getMinionActionPack().turn(-degrees, 0))
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final SimpleCommand TURN_UP_COMMAND =
|
|
||||||
new SimpleCommand(
|
|
||||||
Text.literal("Turn Up"),
|
|
||||||
Text.literal("Turn a specific amount of degrees up"),
|
|
||||||
Items.COMPASS,
|
|
||||||
(player, minion) -> TextInput.inputFloat(player, Text.literal("Degrees"), "90")
|
|
||||||
.thenAccept(degrees -> minion.getMinionActionPack().turn(0, -degrees))
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final SimpleCommand TURN_DOWN_COMMAND =
|
|
||||||
new SimpleCommand(
|
|
||||||
Text.literal("Turn Down"),
|
|
||||||
Text.literal("Turn a specific amount of degrees down"),
|
|
||||||
Items.COMPASS,
|
|
||||||
(player, minion) -> TextInput.inputFloat(player, Text.literal("Degrees"), "90")
|
|
||||||
.thenAccept(degrees -> minion.getMinionActionPack().turn(0, degrees))
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final SimpleModuleItem MOVE_MODULE =
|
|
||||||
register(Identifier.of(Minions.MOD_ID, "move_module"),
|
|
||||||
List.of(),
|
|
||||||
List.of(
|
|
||||||
WALK_COMMAND,
|
|
||||||
TURN_RIGHT_COMMAND,
|
|
||||||
TURN_LEFT_COMMAND,
|
|
||||||
TURN_UP_COMMAND,
|
|
||||||
TURN_DOWN_COMMAND
|
|
||||||
),
|
|
||||||
Items.IRON_BOOTS
|
|
||||||
);
|
|
||||||
|
|
||||||
public static void registerMe() {}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import eu.pb4.polymer.core.api.item.SimplePolymerItem;
|
|
||||||
import io.github.skippyall.minions.module.command.Command;
|
|
||||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SimpleModuleItem extends SimplePolymerItem implements ModuleItem {
|
|
||||||
private final List<CodeBlock<?,?>> codeBlocks;
|
|
||||||
private final List<Command> commands;
|
|
||||||
|
|
||||||
public SimpleModuleItem(List<CodeBlock<?,?>> codeBlocks, List<Command> commands, Settings settings, Item vanillaItem) {
|
|
||||||
super(settings.maxCount(1), vanillaItem);
|
|
||||||
this.codeBlocks = codeBlocks;
|
|
||||||
this.commands = commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<CodeBlock<?, ?>> getCodeBlocks() {
|
|
||||||
return codeBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Command> getCommands() {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package io.github.skippyall.minions.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||||
|
|
||||||
|
public interface SpecialAbility {
|
||||||
|
default void onAdd(MinionFakePlayer minion) {}
|
||||||
|
|
||||||
|
default void onRemove(MinionFakePlayer minion) {}
|
||||||
|
|
||||||
|
default void tick(MinionFakePlayer minion) {}
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module.command;
|
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
public interface Command extends CommandExecutor {
|
|
||||||
Text getName();
|
|
||||||
Text getDescription();
|
|
||||||
Item getItemRepresentation();
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module.command;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
|
|
||||||
public interface CommandExecutor {
|
|
||||||
void execute(ServerPlayerEntity player, MinionFakePlayer minion);
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module.command;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
public class SimpleCommand implements Command {
|
|
||||||
private final Text name;
|
|
||||||
private final Text description;
|
|
||||||
private final Item itemRepresentation;
|
|
||||||
private final CommandExecutor executor;
|
|
||||||
|
|
||||||
public SimpleCommand(Text name, Text description, Item itemRepresentation, CommandExecutor executor) {
|
|
||||||
this.name = name;
|
|
||||||
this.description = description;
|
|
||||||
this.itemRepresentation = itemRepresentation;
|
|
||||||
this.executor = executor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Text getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Text getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Item getItemRepresentation() {
|
|
||||||
return itemRepresentation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
executor.execute(player, minion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package io.github.skippyall.minions.program;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplier;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierList;
|
||||||
|
import io.github.skippyall.minions.program.supplier.ValueSupplierType;
|
||||||
|
import io.github.skippyall.minions.program.instruction.InstructionType;
|
||||||
|
import io.github.skippyall.minions.program.consumer.ValueConsumer;
|
||||||
|
import io.github.skippyall.minions.program.consumer.ValueConsumerList;
|
||||||
|
import io.github.skippyall.minions.program.consumer.ValueConsumerType;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
|
||||||
|
public interface InstructionRuntime<R extends InstructionRuntime<R>> {
|
||||||
|
Registry<ValueSupplierType<R>> getArgumentTypeRegistry();
|
||||||
|
|
||||||
|
Registry<InstructionType<R>> getInstructionTypeRegistry();
|
||||||
|
|
||||||
|
Registry<ValueConsumerType<R>> getValueConsumerTypeRegistry();
|
||||||
|
|
||||||
|
boolean isInstructionEnabled(InstructionType<R> type);
|
||||||
|
|
||||||
|
default Codec<ValueSupplierType<R>> getArgumentTypeCodec() {
|
||||||
|
return getArgumentTypeRegistry().getCodec();
|
||||||
|
}
|
||||||
|
|
||||||
|
default Codec<ValueSupplier<?,R>> getArgumentCodec() {
|
||||||
|
return ValueSupplier.createArgumentCodec(getArgumentTypeCodec());
|
||||||
|
}
|
||||||
|
|
||||||
|
default Codec<ValueSupplierList<R>> getArgumentListCodec() {
|
||||||
|
return ValueSupplierList.getCodec(getArgumentCodec());
|
||||||
|
}
|
||||||
|
|
||||||
|
default Codec<ValueConsumerType<R>> getValueConsumerTypeCodec() {
|
||||||
|
return getValueConsumerTypeRegistry().getCodec();
|
||||||
|
}
|
||||||
|
|
||||||
|
default Codec<ValueConsumer<?,R>> getValueConsumerCodec() {
|
||||||
|
return ValueConsumer.createValueConsumerCodec(getValueConsumerTypeCodec());
|
||||||
|
}
|
||||||
|
|
||||||
|
default Codec<ValueConsumerList<R>> getValueConsumerListCodec() {
|
||||||
|
return ValueConsumerList.getCodec(getValueConsumerCodec());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.argument;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
|
||||||
import io.github.skippyall.minions.program.variables.Type;
|
|
||||||
|
|
||||||
public interface Arg<T> {
|
|
||||||
T resolve(ProgramRuntime runtime);
|
|
||||||
Type<T> getType();
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.argument;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
|
||||||
import io.github.skippyall.minions.program.tuple.Tuple;
|
|
||||||
import io.github.skippyall.minions.program.tuple.Tuple0;
|
|
||||||
|
|
||||||
public class ArgUtils {
|
|
||||||
public static Tuple resolveArgs(Tuple args, ProgramRuntime runtime) {
|
|
||||||
Tuple tuple = new Tuple0();
|
|
||||||
for(Object object : args) {
|
|
||||||
Arg<?> arg =(Arg<?>) object;
|
|
||||||
tuple = tuple.add(arg.getType().cast(arg.resolve(runtime)));
|
|
||||||
}
|
|
||||||
return tuple;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user