Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2d7c51d1e |
+4
-33
@@ -1,15 +1,11 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.8-SNAPSHOT'
|
id 'fabric-loom' version '1.5-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
|
||||||
}
|
}
|
||||||
@@ -21,18 +17,6 @@ repositories {
|
|||||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||||
// for more information about repositories.
|
// for more information about repositories.
|
||||||
maven { url 'https://maven.nucleoid.xyz' }
|
maven { url 'https://maven.nucleoid.xyz' }
|
||||||
|
|
||||||
exclusiveContent {
|
|
||||||
forRepository {
|
|
||||||
maven {
|
|
||||||
name = "Modrinth"
|
|
||||||
url = "https://api.modrinth.com/maven"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filter {
|
|
||||||
includeGroup "maven.modrinth"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -43,11 +27,8 @@ 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 include("eu.pb4:polymer-core:${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}")
|
|
||||||
|
|
||||||
modCompileOnly "maven.modrinth:universal-graves:${project.universal_graves_version}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
@@ -63,7 +44,7 @@ processResources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 21
|
def targetJavaVersion = 17
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||||
// this fixes some edge cases with special characters not displaying correctly
|
// this fixes some edge cases with special characters not displaying correctly
|
||||||
@@ -95,7 +76,7 @@ jar {
|
|||||||
// configure the maven publication
|
// configure the maven publication
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
minions (MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
from components.java
|
from components.java
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,15 +87,5 @@ 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.
|
||||||
maven {
|
|
||||||
def release = "https://maven.foxgalaxy.de/private-releases"
|
|
||||||
def snapshot = "https://maven.foxgalaxy.de/private-snapshot"
|
|
||||||
url = version.endsWith('SNAPSHOT') ? snapshot : release
|
|
||||||
|
|
||||||
credentials {
|
|
||||||
username = "${maven_user}"
|
|
||||||
password = "${maven_password}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-10
@@ -3,21 +3,18 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://modmuss50.me/fabric.html
|
||||||
minecraft_version=1.21.3
|
minecraft_version=1.20.4
|
||||||
loader_version=0.16.13
|
loader_version=0.15.6
|
||||||
yarn_mappings=1.21.3+build.2
|
yarn_mappings=1.20.4+build.3
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.1.2-SNAPSHOT
|
mod_version = 0.0.1
|
||||||
maven_group = io.github.skippyall
|
maven_group = io.github.skippyall
|
||||||
archives_base_name = Minions
|
archives_base_name = Minions
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# check this on https://modmuss50.me/fabric.html
|
# check this on https://modmuss50.me/fabric.html
|
||||||
fabric_version=0.107.0+1.21.3
|
fabric_version=0.95.4+1.20.4
|
||||||
|
|
||||||
polymer_version=0.10.0+1.21.2
|
polymer_version=0.7.5+1.20.4
|
||||||
sgui_version=1.7.1+1.21.2
|
sgui_version=1.4.1+1.20.4
|
||||||
server_translations_version=2.4.0+1.21.2-rc1
|
|
||||||
|
|
||||||
universal_graves_version=3.5.0+1.21.2
|
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
|
|||||||
@@ -1,88 +1,21 @@
|
|||||||
package io.github.skippyall.minions;
|
package io.github.skippyall.minions;
|
||||||
|
|
||||||
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
||||||
import eu.pb4.polymer.core.api.item.SimplePolymerItem;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
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.MinionPersistentState;
|
|
||||||
import io.github.skippyall.minions.module.Modules;
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
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.ServerTickEvents;
|
|
||||||
import net.minecraft.component.DataComponentTypes;
|
|
||||||
import net.minecraft.component.type.DamageResistantComponent;
|
|
||||||
import net.minecraft.entity.boss.WitherEntity;
|
|
||||||
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.Registries;
|
||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.registry.Registry;
|
||||||
import net.minecraft.registry.RegistryKey;
|
|
||||||
import net.minecraft.registry.RegistryKeys;
|
|
||||||
import net.minecraft.registry.tag.TagKey;
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class Minions implements ModInitializer {
|
public class Minions implements ModInitializer {
|
||||||
public static final String MOD_ID = "minions";
|
public static final String MOD_ID = "minions";
|
||||||
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 = Registry.register(Registries.ITEM, new Identifier(MOD_ID, "minion"), new MinionItem());
|
||||||
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)),false));
|
|
||||||
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 final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||||
|
|
||||||
private static final List<Runnable> executeOnNextTick = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
MinionData.register();
|
|
||||||
PolymerEntityUtils.registerType();
|
PolymerEntityUtils.registerType();
|
||||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
|
||||||
MinionPersistentState.create(server);
|
|
||||||
MinionPersistentState.INSTANCE.getMinionData().forEach(data -> {
|
|
||||||
MinionFakePlayer.spawnMinionAt(data, server.getOverworld(), null, null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
ServerTickEvents.START_SERVER_TICK.register(server -> {
|
|
||||||
exec(() -> {
|
|
||||||
for (Runnable run:executeOnNextTick) {
|
|
||||||
run.run();
|
|
||||||
}
|
|
||||||
executeOnNextTick.clear();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
CommandRegistrationCallback.EVENT.register((commandDispatcher, commandRegistryAccess, registrationEnvironment) -> {
|
|
||||||
MobCapCommand.registerCommand(commandDispatcher);
|
|
||||||
});
|
|
||||||
|
|
||||||
Modules.register();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T extends Item> T registerItem(Identifier identifier, Function<Item.Settings, T> constructor, Item.Settings settings) {
|
|
||||||
return Registry.register(Registries.ITEM, identifier, constructor.apply(settings.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier))));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T extends Item> T registerItem(Identifier identifier, Function<Item.Settings, T> constructor) {
|
|
||||||
return registerItem(identifier, constructor, new Item.Settings());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static synchronized void exec(Runnable run) {
|
|
||||||
run.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addExecuteOnNextTick(Runnable run) {
|
|
||||||
exec(() -> {
|
|
||||||
executeOnNextTick.add(run);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package io.github.skippyall.minions;
|
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor;
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManagerAccessor;
|
|
||||||
import io.github.skippyall.minions.mixins.antimobcap.ServerChunkManagerAccessor;
|
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
|
||||||
|
|
||||||
public class MobCapCommand {
|
|
||||||
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
|
|
||||||
dispatcher.register(literal("mobcapdebug")
|
|
||||||
.executes(context -> {
|
|
||||||
ChunkTicketManager ticketManager = ((ServerChunkManagerAccessor)context.getSource().getWorld().getChunkManager()).getTicketManager();
|
|
||||||
int tickedChunkCount = ((ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor)((ChunkTicketManagerAccessor)ticketManager).getMinionless()).minions$getTickedChunkCount();
|
|
||||||
context.getSource().sendFeedback(() -> Text.of(String.valueOf(tickedChunkCount)), false);
|
|
||||||
return 0;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package io.github.skippyall.minions.client;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.networking.ClientToServerNetworking;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationConnectionEvents;
|
||||||
|
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents;
|
||||||
|
|
||||||
|
public class MinionsClient implements ClientModInitializer {
|
||||||
|
/**
|
||||||
|
* Runs the mod initializer on the client environment.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
ClientConfigurationConnectionEvents.INIT.register(ClientToServerNetworking::onConfigurationInit);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package io.github.skippyall.minions.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.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.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
//code from https://github.com/gnembon/fabric-carpet
|
package io.github.skippyall.minions.fakeplayer;
|
||||||
package io.github.skippyall.minions.minion.fakeplayer;
|
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
|
||||||
+11
-21
@@ -1,13 +1,10 @@
|
|||||||
//partially code from https://github.com/gnembon/fabric-carpet
|
package io.github.skippyall.minions.fakeplayer;
|
||||||
package io.github.skippyall.minions.minion.fakeplayer;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import io.github.skippyall.minions.mixins.EntityAccessor;
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
@@ -83,12 +80,6 @@ public class EntityPlayerActionPack
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityPlayerActionPack stop(ActionType type) {
|
|
||||||
Action previous = actions.remove(type);
|
|
||||||
if (previous != null) type.stop(player, previous);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack setSneaking(boolean doSneak)
|
public EntityPlayerActionPack setSneaking(boolean doSneak)
|
||||||
{
|
{
|
||||||
sneaking = doSneak;
|
sneaking = doSneak;
|
||||||
@@ -176,13 +167,12 @@ public class EntityPlayerActionPack
|
|||||||
|
|
||||||
public EntityPlayerActionPack mount(boolean onlyRideables)
|
public EntityPlayerActionPack mount(boolean onlyRideables)
|
||||||
{
|
{
|
||||||
|
|
||||||
//test what happens
|
//test what happens
|
||||||
List<Entity> entities;
|
List<Entity> entities;
|
||||||
if (onlyRideables)
|
if (onlyRideables)
|
||||||
{
|
{
|
||||||
entities = player.getWorld().getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D),
|
entities = player.getWorld().getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D),
|
||||||
e -> (e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof AbstractHorseEntity) && ((EntityAccessor)e).invokeCanAddPassenger(player));
|
e -> e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof AbstractHorseEntity);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -208,7 +198,7 @@ public class EntityPlayerActionPack
|
|||||||
if (closest instanceof AbstractHorseEntity && onlyRideables)
|
if (closest instanceof AbstractHorseEntity && onlyRideables)
|
||||||
((AbstractHorseEntity) closest).interactMob(player, Hand.MAIN_HAND);
|
((AbstractHorseEntity) closest).interactMob(player, Hand.MAIN_HAND);
|
||||||
else
|
else
|
||||||
player.startRiding(closest, !onlyRideables);
|
player.startRiding(closest,true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public EntityPlayerActionPack dismount()
|
public EntityPlayerActionPack dismount()
|
||||||
@@ -321,12 +311,12 @@ public class EntityPlayerActionPack
|
|||||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||||
BlockPos pos = blockHit.getBlockPos();
|
BlockPos pos = blockHit.getBlockPos();
|
||||||
Direction side = blockHit.getSide();
|
Direction side = blockHit.getSide();
|
||||||
if (pos.getY() < player.getServerWorld().getTopYInclusive() - (side == Direction.UP ? 1 : 0) && world.canPlayerModifyAt(player, pos))
|
if (pos.getY() < player.getWorld().getTopY() - (side == Direction.UP ? 1 : 0) && world.canPlayerModifyAt(player, pos))
|
||||||
{
|
{
|
||||||
ActionResult result = player.interactionManager.interactBlock(player, world, player.getStackInHand(hand), hand, blockHit);
|
ActionResult result = player.interactionManager.interactBlock(player, world, player.getStackInHand(hand), hand, blockHit);
|
||||||
if (result instanceof ActionResult.Success success)
|
if (result.isAccepted())
|
||||||
{
|
{
|
||||||
if (success.swingSource() == ActionResult.SwingSource.SERVER) player.swingHand(hand);
|
if (result.shouldSwingHand()) player.swingHand(hand);
|
||||||
ap.itemUseCooldown = 3;
|
ap.itemUseCooldown = 3;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -409,7 +399,7 @@ public class EntityPlayerActionPack
|
|||||||
boolean blockBroken = false;
|
boolean blockBroken = false;
|
||||||
if (player.interactionManager.getGameMode().isCreative())
|
if (player.interactionManager.getGameMode().isCreative())
|
||||||
{
|
{
|
||||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
||||||
ap.blockHitDelay = 5;
|
ap.blockHitDelay = 5;
|
||||||
blockBroken = true;
|
blockBroken = true;
|
||||||
}
|
}
|
||||||
@@ -417,9 +407,9 @@ public class EntityPlayerActionPack
|
|||||||
{
|
{
|
||||||
if (ap.currentBlock != null)
|
if (ap.currentBlock != null)
|
||||||
{
|
{
|
||||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
||||||
}
|
}
|
||||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
||||||
boolean notAir = !state.isAir();
|
boolean notAir = !state.isAir();
|
||||||
if (notAir && ap.curBlockDamageMP == 0)
|
if (notAir && ap.curBlockDamageMP == 0)
|
||||||
{
|
{
|
||||||
@@ -442,7 +432,7 @@ public class EntityPlayerActionPack
|
|||||||
ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.getWorld(), pos);
|
ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.getWorld(), pos);
|
||||||
if (ap.curBlockDamageMP >= 1)
|
if (ap.curBlockDamageMP >= 1)
|
||||||
{
|
{
|
||||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.getWorld().getTopY(), -1);
|
||||||
ap.currentBlock = null;
|
ap.currentBlock = null;
|
||||||
ap.blockHitDelay = 5;
|
ap.blockHitDelay = 5;
|
||||||
blockBroken = true;
|
blockBroken = true;
|
||||||
@@ -464,7 +454,7 @@ public class EntityPlayerActionPack
|
|||||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).getActionPack();
|
||||||
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().getTopY(), -1);
|
||||||
ap.currentBlock = null;
|
ap.currentBlock = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
+5
-4
@@ -1,11 +1,10 @@
|
|||||||
//code from https://github.com/gnembon/fabric-carpet
|
package io.github.skippyall.minions.fakeplayer;
|
||||||
package io.github.skippyall.minions.minion.fakeplayer;
|
|
||||||
|
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.NetworkSide;
|
import net.minecraft.network.NetworkSide;
|
||||||
import net.minecraft.network.NetworkState;
|
|
||||||
import net.minecraft.network.listener.PacketListener;
|
import net.minecraft.network.listener.PacketListener;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
public class FakeClientConnection extends ClientConnection {
|
public class FakeClientConnection extends ClientConnection {
|
||||||
public FakeClientConnection(NetworkSide p)
|
public FakeClientConnection(NetworkSide p)
|
||||||
@@ -23,6 +22,7 @@ public class FakeClientConnection extends ClientConnection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleDisconnection() {
|
public void handleDisconnection() {
|
||||||
|
getPacketListener().onDisconnected(getDisconnectReason()==null ? Text.literal("Disconnected"): getDisconnectReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -31,6 +31,7 @@ public class FakeClientConnection extends ClientConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends PacketListener> void transitionInbound(NetworkState<T> state, T packetListener) {
|
public void setPacketListener(PacketListener packetListener) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
package io.github.skippyall.minions.fakeplayer;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.yggdrasil.ProfileResult;
|
||||||
|
import io.github.skippyall.minions.minion.MinionInventory;
|
||||||
|
import io.github.skippyall.minions.minion.ModuleInventory;
|
||||||
|
import net.fabricmc.fabric.api.entity.FakePlayer;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.entity.MovementType;
|
||||||
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
|
import net.minecraft.entity.player.HungerManager;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.network.NetworkSide;
|
||||||
|
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
||||||
|
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
|
||||||
|
import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket;
|
||||||
|
import net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket;
|
||||||
|
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.ServerTask;
|
||||||
|
import net.minecraft.server.network.ConnectedClientData;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.text.TranslatableTextContent;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.Uuids;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import net.minecraft.world.GameMode;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MinionFakePlayer extends ServerPlayerEntity {
|
||||||
|
public Runnable fixStartingPosition = () -> {};
|
||||||
|
public boolean isAShadow;
|
||||||
|
|
||||||
|
private float moveForward;
|
||||||
|
private float moveSideways;
|
||||||
|
|
||||||
|
private boolean programmable;
|
||||||
|
private ModuleInventory moduleInventory = new ModuleInventory();
|
||||||
|
|
||||||
|
public static void createMinion(String username, ServerWorld level, ServerPlayerEntity owner, boolean canProgram, Vec3d pos, double yaw, double pitch) {
|
||||||
|
MinecraftServer server = level.getServer();
|
||||||
|
server.getUserCache().findByNameAsync(username).thenAcceptAsync((optional) -> {
|
||||||
|
GameProfile profile = null;
|
||||||
|
if(optional.isPresent()){
|
||||||
|
UUID uuid = optional.get().getId();
|
||||||
|
ProfileResult result = server.getSessionService().fetchProfile(uuid, true);
|
||||||
|
if(result != null) {
|
||||||
|
profile = result.profile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(profile == null) {
|
||||||
|
profile = new GameProfile(Uuids.getOfflinePlayerUuid(username), username);
|
||||||
|
}
|
||||||
|
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, SyncedClientOptions.createDefault(), false, canProgram);
|
||||||
|
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
||||||
|
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance, new ConnectedClientData(profile, 0, instance.getClientOptions()));
|
||||||
|
instance.teleport(level, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
||||||
|
instance.setHealth(20.0F);
|
||||||
|
instance.unsetRemoved();
|
||||||
|
instance.interactionManager.changeGameMode(GameMode.SURVIVAL);
|
||||||
|
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), level.getRegistryKey());//instance.dimension);
|
||||||
|
server.getPlayerManager().sendToDimension(new EntityPositionS2CPacket(instance), level.getRegistryKey());//instance.dimension);
|
||||||
|
//instance.world.getChunkManager(). updatePosition(instance);
|
||||||
|
instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
|
||||||
|
instance.getAbilities().flying = false;
|
||||||
|
instance.setStepHeight(0.6F);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused") //Don't know if I'll need this
|
||||||
|
public static MinionFakePlayer createShadow(MinecraftServer server, ServerPlayerEntity player)
|
||||||
|
{
|
||||||
|
player.getServer().getPlayerManager().remove(player);
|
||||||
|
player.networkHandler.disconnect(Text.translatable("multiplayer.disconnect.duplicate_login"));
|
||||||
|
ServerWorld worldIn = player.getServerWorld();//.getWorld(player.dimension);
|
||||||
|
GameProfile gameprofile = player.getGameProfile();
|
||||||
|
MinionFakePlayer playerShadow = new MinionFakePlayer(server, worldIn, gameprofile, player.getClientOptions(), true, false);
|
||||||
|
playerShadow.setSession(player.getSession());
|
||||||
|
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), playerShadow, new ConnectedClientData(gameprofile, 0, player.getClientOptions()));
|
||||||
|
|
||||||
|
playerShadow.setHealth(player.getHealth());
|
||||||
|
playerShadow.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
|
||||||
|
playerShadow.interactionManager.changeGameMode(player.interactionManager.getGameMode());
|
||||||
|
((ServerPlayerInterface) playerShadow).getActionPack().copyFrom(((ServerPlayerInterface) player).getActionPack());
|
||||||
|
playerShadow.dataTracker.set(PLAYER_MODEL_PARTS, player.getDataTracker().get(PLAYER_MODEL_PARTS));
|
||||||
|
|
||||||
|
|
||||||
|
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(playerShadow, (byte) (player.headYaw * 256 / 360)), playerShadow.getWorld().getRegistryKey());
|
||||||
|
server.getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, playerShadow));
|
||||||
|
//player.world.getChunkManager().updatePosition(playerShadow);
|
||||||
|
playerShadow.getAbilities().flying = player.getAbilities().flying;
|
||||||
|
return playerShadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerWorld level, GameProfile profile, SyncedClientOptions cli, boolean programmable)
|
||||||
|
{
|
||||||
|
return new MinionFakePlayer(server, level, profile, cli, false, programmable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MinionFakePlayer(MinecraftServer server, ServerWorld worldIn, GameProfile profile, SyncedClientOptions cli, boolean shadow, boolean programmable)
|
||||||
|
{
|
||||||
|
super(server, worldIn, profile, cli);
|
||||||
|
isAShadow = shadow;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isProgrammable() {
|
||||||
|
return programmable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleInventory getModuleInventory() {
|
||||||
|
return moduleInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPlayerActionPack getActionPack() {
|
||||||
|
return ((ServerPlayerInterface)this).getActionPack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult interact(PlayerEntity player, Hand hand) {
|
||||||
|
if(player instanceof ServerPlayerEntity spe) {
|
||||||
|
MinionInventory.openInventory(spe, this);
|
||||||
|
}
|
||||||
|
return ActionResult.CONSUME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult interactAt(PlayerEntity player, Vec3d hitPos, Hand hand) {
|
||||||
|
return interact(player, hand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEquipStack(final EquipmentSlot slot, final ItemStack previous, final ItemStack stack)
|
||||||
|
{
|
||||||
|
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void kill()
|
||||||
|
{
|
||||||
|
kill(Text.literal("Killed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void kill(Text reason)
|
||||||
|
{
|
||||||
|
shakeOff();
|
||||||
|
|
||||||
|
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
||||||
|
this.networkHandler.onDisconnected(reason);
|
||||||
|
} else {
|
||||||
|
this.server.send(new ServerTask(this.server.getTicks(), () -> {
|
||||||
|
this.networkHandler.onDisconnected(reason);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick()
|
||||||
|
{
|
||||||
|
if (this.getServer().getTicks() % 10 == 0)
|
||||||
|
{
|
||||||
|
this.networkHandler.syncWithPlayerPosition();
|
||||||
|
this.getServerWorld().getChunkManager().updatePosition(this);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
super.tick();
|
||||||
|
this.playerTick();
|
||||||
|
}
|
||||||
|
catch (NullPointerException ignored)
|
||||||
|
{
|
||||||
|
// happens with that paper port thingy - not sure what that would fix, but hey
|
||||||
|
// the game not gonna crash violently.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shakeOff()
|
||||||
|
{
|
||||||
|
if (getVehicle() instanceof PlayerEntity) stopRiding();
|
||||||
|
for (Entity passenger : getPassengersDeep())
|
||||||
|
{
|
||||||
|
if (passenger instanceof PlayerEntity) passenger.stopRiding();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeath(DamageSource cause)
|
||||||
|
{
|
||||||
|
shakeOff();
|
||||||
|
super.onDeath(cause);
|
||||||
|
setHealth(20);
|
||||||
|
this.hungerManager = new HungerManager();
|
||||||
|
kill(this.getDamageTracker().getDeathMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIp()
|
||||||
|
{
|
||||||
|
return "127.0.0.1";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowsServerListing() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void fall(double y, boolean onGround, BlockState state, BlockPos pos) {
|
||||||
|
handleFall(0.0, y, 0.0, onGround);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entity moveToWorld(ServerWorld serverLevel)
|
||||||
|
{
|
||||||
|
super.moveToWorld(serverLevel);
|
||||||
|
if (notInAnyWorld) {
|
||||||
|
ClientStatusC2SPacket p = new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.PERFORM_RESPAWN);
|
||||||
|
networkHandler.onClientStatus(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If above branch was taken, *this* has been removed and replaced, the new instance has been set
|
||||||
|
// on 'our' connection (which is now theirs, but we still have a ref).
|
||||||
|
if (networkHandler.player.isInTeleportationState()) {
|
||||||
|
networkHandler.player.onTeleportationDone();
|
||||||
|
}
|
||||||
|
return networkHandler.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveForward(float forward) {
|
||||||
|
this.moveForward += forward;
|
||||||
|
EntityPlayerActionPack actionPack = getActionPack();
|
||||||
|
if (moveForward != 0) {
|
||||||
|
actionPack.setForward(moveForward > 0 ? 1 : -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveSideways(float sideways) {
|
||||||
|
this.moveSideways += sideways;
|
||||||
|
EntityPlayerActionPack actionPack = getActionPack();
|
||||||
|
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;
|
||||||
|
getActionPack().setForward(0);
|
||||||
|
}else {
|
||||||
|
moveForward = newForward;
|
||||||
|
}
|
||||||
|
if ((newSideways < 0 && moveSideways >= 0) || (newSideways > 0 && moveSideways <= 0)) {
|
||||||
|
newMovement = new Vec3d(newMovement.x, newMovement.y, moveSideways);
|
||||||
|
moveSideways = 0;
|
||||||
|
getActionPack().setStrafing(0);
|
||||||
|
}else {
|
||||||
|
moveSideways = newSideways;
|
||||||
|
}
|
||||||
|
super.move(movementType, newMovement);
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-5
@@ -1,7 +1,5 @@
|
|||||||
//code from https://github.com/gnembon/fabric-carpet
|
package io.github.skippyall.minions.fakeplayer;
|
||||||
package io.github.skippyall.minions.minion.fakeplayer;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerPosition;
|
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.packet.Packet;
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
||||||
@@ -35,9 +33,9 @@ public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void requestTeleport(PlayerPosition pos, Set<PositionFlag> set)
|
public void requestTeleport(double d, double e, double f, float g, float h, Set<PositionFlag> set)
|
||||||
{
|
{
|
||||||
super.requestTeleport(pos, set);
|
super.requestTeleport(d, e, f, g, h, set);
|
||||||
if (player.getServerWorld().getPlayerByUuid(player.getUuid()) != null) {
|
if (player.getServerWorld().getPlayerByUuid(player.getUuid()) != null) {
|
||||||
syncWithPlayerPosition();
|
syncWithPlayerPosition();
|
||||||
player.getServerWorld().getChunkManager().updatePosition(player);
|
player.getServerWorld().getChunkManager().updatePosition(player);
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package io.github.skippyall.minions.fakeplayer;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||||
|
|
||||||
|
public interface ServerPlayerInterface
|
||||||
|
{
|
||||||
|
EntityPlayerActionPack getActionPack();
|
||||||
|
}
|
||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
//code from https://github.com/gnembon/fabric-carpet
|
package io.github.skippyall.minions.fakeplayer;
|
||||||
package io.github.skippyall.minions.minion.fakeplayer;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@@ -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.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.List;
|
|
||||||
|
|
||||||
public class CommandsGui {
|
|
||||||
public static void openServerModuleCommandGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
List<ModuleItem> modules = minion.getModuleInventory().getModuleItems();
|
|
||||||
|
|
||||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
|
||||||
|
|
||||||
gui.setTitle(Text.translatable("minions.gui.module_commands.title"));
|
|
||||||
|
|
||||||
for (int i = 0; i < modules.size(); i++) {
|
|
||||||
ModuleItem module = modules.get(i);
|
|
||||||
gui.setSlot(i, 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +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.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.screen.ScreenHandlerType;
|
|
||||||
import net.minecraft.screen.slot.Slot;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
public class MinionGui {
|
|
||||||
public static void openInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
openServerSideInventory(player, minion);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openServerSideInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
|
||||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
|
|
||||||
gui.setTitle(minion.getName());
|
|
||||||
|
|
||||||
gui.setSlot(1, new GuiElementBuilder()
|
|
||||||
.setItem(Items.COMMAND_BLOCK)
|
|
||||||
.setName(Text.translatable("minions.gui.main.commands"))
|
|
||||||
.setCallback((i, clickType, slotActionType) -> {
|
|
||||||
openCommandsGui(player, minion);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
if(minion.isProgrammable()) {
|
|
||||||
gui.setSlot(4, new GuiElementBuilder()
|
|
||||||
.setItem(Items.REDSTONE)
|
|
||||||
.setName(Text.translatable("minions.gui.main.programming"))
|
|
||||||
.setCallback(() -> {
|
|
||||||
openProgrammingInventory(player, minion);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
gui.setSlot(3, new GuiElementBuilder()
|
|
||||||
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
|
||||||
.setName(Text.translatable("minions.gui.main.modules"))
|
|
||||||
.setCallback(() -> {
|
|
||||||
ModuleInventory.openModuleInventory(player, minion);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
gui.setSlot(5, new GuiElementBuilder()
|
|
||||||
.setItem(Items.CHEST)
|
|
||||||
.setName(Text.translatable("minions.gui.main.inventory"))
|
|
||||||
.setCallback(() -> {
|
|
||||||
openMinionInventory(player, minion);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
gui.setSlot(7, new GuiElementBuilder()
|
|
||||||
.setItem(Items.BARRIER)
|
|
||||||
.setName(Text.translatable("minions.gui.main.pickup"))
|
|
||||||
.setCallback(() -> {
|
|
||||||
minion.kill(minion.getServerWorld());
|
|
||||||
})
|
|
||||||
);
|
|
||||||
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) {
|
|
||||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
|
|
||||||
gui.setTitle(Text.translatable("minions.gui.inventory.title", minion.getName()));
|
|
||||||
for (int i = 0; i < minion.getInventory().size(); i++) {
|
|
||||||
gui.setSlotRedirect(i, new Slot(minion.getInventory(), i, 0, 0));
|
|
||||||
}
|
|
||||||
gui.open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package io.github.skippyall.minions.gui;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.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.nbt.NbtCompound;
|
|
||||||
import net.minecraft.registry.RegistryWrapper;
|
|
||||||
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ModuleInventory extends SimpleInventory {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
|
||||||
Inventories.readNbt(nbt, heldStacks, lookup);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
|
||||||
return Inventories.writeNbt(nbt, heldStacks, lookup);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasModule(ModuleItem module) {
|
|
||||||
for(ItemStack stack : heldStacks) {
|
|
||||||
if(stack.getItem() instanceof ModuleItem module2 && module2 == module) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ModuleItem> getModuleItems() {
|
|
||||||
ArrayList<ModuleItem> modules = new ArrayList<>();
|
|
||||||
for(ItemStack stack : heldStacks) {
|
|
||||||
if(stack.getItem() instanceof ModuleItem module) {
|
|
||||||
modules.add(module);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package io.github.skippyall.minions.gui;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
|
||||||
import net.minecraft.screen.ScreenHandler;
|
|
||||||
import net.minecraft.screen.ScreenHandlerType;
|
|
||||||
import net.minecraft.screen.slot.Slot;
|
|
||||||
|
|
||||||
public class ModuleInventoryScreenHandler extends ScreenHandler {
|
|
||||||
private final int rows = 3;
|
|
||||||
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) {
|
|
||||||
super(ScreenHandlerType.GENERIC_9X3, syncId);
|
|
||||||
int k;
|
|
||||||
int j;
|
|
||||||
GenericContainerScreenHandler.checkSize(inventory, 3 * 9);
|
|
||||||
this.inventory = inventory;
|
|
||||||
inventory.onOpen(playerInventory.player);
|
|
||||||
int i = (rows - 4) * 18;
|
|
||||||
for (j = 0; j < rows; ++j) {
|
|
||||||
for (k = 0; k < 9; ++k) {
|
|
||||||
this.addSlot(new Slot(inventory, k + j * 9, 8 + k * 18, 18 + j * 18) {
|
|
||||||
@Override
|
|
||||||
public boolean canInsert(ItemStack stack) {
|
|
||||||
return super.canInsert(stack) && inventory.isValid(getIndex(), stack);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (j = 0; j < 3; ++j) {
|
|
||||||
for (k = 0; k < 9; ++k) {
|
|
||||||
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
|
|
||||||
public boolean canUse(PlayerEntity player) {
|
|
||||||
return this.inventory.canPlayerUse(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack quickMove(PlayerEntity player, int slot) {
|
|
||||||
ItemStack itemStack = ItemStack.EMPTY;
|
|
||||||
Slot slot2 = this.slots.get(slot);
|
|
||||||
if (slot2 != null && slot2.hasStack()) {
|
|
||||||
ItemStack itemStack2 = slot2.getStack();
|
|
||||||
itemStack = itemStack2.copy();
|
|
||||||
if (slot < this.rows * 9 ? !this.insertItem(itemStack2, this.rows * 9, this.slots.size(), true) : !this.insertItem(itemStack2, 0, this.rows * 9, false)) {
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
if (itemStack2.isEmpty()) {
|
|
||||||
slot2.setStack(ItemStack.EMPTY);
|
|
||||||
} else {
|
|
||||||
slot2.markDirty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClosed(PlayerEntity player) {
|
|
||||||
super.onClosed(player);
|
|
||||||
this.inventory.onClose(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModuleInventory getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package io.github.skippyall.minions.input;
|
|
||||||
|
|
||||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
|
||||||
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.screen.AnvilScreenHandler;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class TextInput {
|
|
||||||
public static CompletableFuture<String> inputText(ServerPlayerEntity player, Text title, String defaultText) {
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
|
||||||
|
|
||||||
AnvilInputGui gui = new AnvilInputGui(player, false);
|
|
||||||
gui.setSlot(AnvilScreenHandler.OUTPUT_ID, new GuiElementBuilder()
|
|
||||||
.setItem(Items.EMERALD_BLOCK)
|
|
||||||
.setName(Text.literal("OK"))
|
|
||||||
.setCallback(() -> {
|
|
||||||
gui.close();
|
|
||||||
future.complete(gui.getInput());
|
|
||||||
})
|
|
||||||
);
|
|
||||||
gui.setTitle(title);
|
|
||||||
gui.setDefaultInputValue(defaultText);
|
|
||||||
gui.open();
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> CompletableFuture<T> inputParse(ServerPlayerEntity player, Text title, String defaultValue, Function<String, T> parser, Text failureMessage) {
|
|
||||||
return inputText(player, title, String.valueOf(defaultValue)).thenCompose(string -> {
|
|
||||||
try {
|
|
||||||
return CompletableFuture.completedFuture(parser.apply(string));
|
|
||||||
} catch (Exception e) {
|
|
||||||
player.sendMessage(failureMessage);
|
|
||||||
return CompletableFuture.failedFuture(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CompletableFuture<Integer> inputInt(ServerPlayerEntity player, Text title, String defaultValue) {
|
|
||||||
return inputParse(player, title, defaultValue, Integer::parseInt, Text.translatable("minions.command.input.int.fail"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CompletableFuture<Float> inputFloat(ServerPlayerEntity player, Text title, String defaultValue) {
|
|
||||||
return inputParse(player, title, defaultValue, Float::parseFloat, Text.translatable("minions.command.input.float.fail"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.inventory.Inventories;
|
||||||
|
import net.minecraft.inventory.Inventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple {@code Inventory} implementation with only default methods + an item list getter.
|
||||||
|
*
|
||||||
|
* Originally by Juuz
|
||||||
|
*/
|
||||||
|
public interface ImplementedInventory extends Inventory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the item list of this inventory.
|
||||||
|
* Must return the same instance every time it's called.
|
||||||
|
*/
|
||||||
|
DefaultedList<ItemStack> getItems();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an inventory from the item list.
|
||||||
|
*/
|
||||||
|
static ImplementedInventory of(DefaultedList<ItemStack> items) {
|
||||||
|
return () -> items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new inventory with the specified size.
|
||||||
|
*/
|
||||||
|
static ImplementedInventory ofSize(int size) {
|
||||||
|
return of(DefaultedList.ofSize(size, ItemStack.EMPTY));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the inventory size.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default int size() {
|
||||||
|
return getItems().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the inventory is empty.
|
||||||
|
* @return true if this inventory has only empty stacks, false otherwise.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default boolean isEmpty() {
|
||||||
|
for (int i = 0; i < size(); i++) {
|
||||||
|
ItemStack stack = getStack(i);
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the item in the slot.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default ItemStack getStack(int slot) {
|
||||||
|
return getItems().get(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes items from an inventory slot.
|
||||||
|
* @param slot The slot to remove from.
|
||||||
|
* @param count How many items to remove. If there are less items in the slot than what are requested,
|
||||||
|
* takes all items in that slot.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default ItemStack removeStack(int slot, int count) {
|
||||||
|
ItemStack result = Inventories.splitStack(getItems(), slot, count);
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all items from an inventory slot.
|
||||||
|
* @param slot The slot to remove from.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default ItemStack removeStack(int slot) {
|
||||||
|
return Inventories.removeStack(getItems(), slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces the current stack in an inventory slot with the provided stack.
|
||||||
|
* @param slot The inventory slot of which to replace the itemstack.
|
||||||
|
* @param stack The replacing itemstack. If the stack is too big for
|
||||||
|
* this inventory ({@link Inventory#getMaxCountPerStack()}),
|
||||||
|
* it gets resized to this inventory's maximum amount.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default void setStack(int slot, ItemStack stack) {
|
||||||
|
getItems().set(slot, stack);
|
||||||
|
if (stack.getCount() > stack.getMaxCount()) {
|
||||||
|
stack.setCount(stack.getMaxCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the inventory.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default void clear() {
|
||||||
|
getItems().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the state as dirty.
|
||||||
|
* Must be called after changes in the inventory, so that the game can properly save
|
||||||
|
* the inventory contents and notify neighboring blocks of inventory changes.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default void markDirty() {
|
||||||
|
// Override if you want behavior.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the player can use the inventory, false otherwise.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default boolean canPlayerUse(PlayerEntity player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
||||||
import eu.pb4.polymer.core.api.other.PolymerComponent;
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.component.ComponentType;
|
|
||||||
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 org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public record MinionData(UUID uuid, String name, @NotNull Optional<UUID> skinUuid) {
|
|
||||||
public static final Codec<MinionData> CODEC = RecordCodecBuilder.create(instance ->
|
|
||||||
instance.group(
|
|
||||||
Uuids.CODEC.fieldOf("uuid").forGetter(MinionData::uuid),
|
|
||||||
Codec.STRING.fieldOf("name").forGetter(MinionData::name),
|
|
||||||
Uuids.CODEC.optionalFieldOf("skinUuid").orElse(Optional.empty()).forGetter(MinionData::skinUuid)
|
|
||||||
).apply(instance, MinionData::new)
|
|
||||||
);
|
|
||||||
public static final ComponentType<MinionData> COMPONENT = Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(Minions.MOD_ID, "minion_data"), ComponentType.<MinionData>builder().codec(CODEC).build());
|
|
||||||
|
|
||||||
public MinionData withUuid(UUID uuid) {
|
|
||||||
return new MinionData(uuid, name, skinUuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MinionData withName(String name) {
|
|
||||||
return new MinionData(uuid, name, skinUuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MinionData withSkin(Optional<UUID> skinUuid) {
|
|
||||||
return new MinionData(uuid, name, skinUuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NbtCompound writeNbt() {
|
|
||||||
return (NbtCompound) MinionData.CODEC.encode(this, NbtOps.INSTANCE, null).getOrThrow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MinionData readNbt(NbtCompound nbt) {
|
|
||||||
return MinionData.CODEC.decode(NbtOps.INSTANCE, nbt).getOrThrow().getFirst();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MinionData fromMinion(MinionFakePlayer minion) {
|
|
||||||
return new MinionData(minion.getUuid(), minion.getMinionName(), minion.getSkinUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void register() {
|
|
||||||
PolymerComponent.registerDataComponent(COMPONENT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||||
|
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
|
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||||
|
import net.minecraft.screen.slot.Slot;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public class MinionInventory {
|
||||||
|
public static void openInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
openServerSideInventory(player, minion);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openServerSideInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
|
||||||
|
gui.setTitle(Text.literal("Minion"));
|
||||||
|
gui.setSlot(4, new GuiElementBuilder()
|
||||||
|
.setItem(Items.REDSTONE)
|
||||||
|
.setName(Text.literal("Programming"))
|
||||||
|
.setCallback((i, clickType, clickType1) -> {
|
||||||
|
openProgrammingInventory(player, minion);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
gui.setSlot(3, new GuiElementBuilder()
|
||||||
|
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
||||||
|
.setName(Text.literal("Modules and Detectors"))
|
||||||
|
.setCallback((i, clickType, clickType1) -> {
|
||||||
|
openModuleInventory(player, minion);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
gui.setSlot(5, new GuiElementBuilder()
|
||||||
|
.setItem(Items.CHEST)
|
||||||
|
.setName(Text.literal("Inventory"))
|
||||||
|
.setCallback((i, clickType, clickType1) -> {
|
||||||
|
openMinionInventory(player, minion);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openProgrammingInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openModuleInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player2) -> GenericContainerScreenHandler.createGeneric9x3(syncId, playerInventory, minion.getModuleInventory()), Text.literal("")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openMinionInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||||
|
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
|
||||||
|
gui.setTitle(Text.literal("Minion"));
|
||||||
|
for (int i = 0; i < minion.getInventory().size(); i++) {
|
||||||
|
gui.setSlotRedirect(i, new Slot(minion.getInventory(), i, 0, 0));
|
||||||
|
}
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,101 +2,49 @@ package io.github.skippyall.minions.minion;
|
|||||||
|
|
||||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
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.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||||
import net.minecraft.component.type.NbtComponent;
|
import net.minecraft.client.item.TooltipContext;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.enchantment.Enchantments;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.*;
|
||||||
import net.minecraft.item.ItemUsageContext;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.item.tooltip.TooltipType;
|
|
||||||
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.PlainTextContent;
|
||||||
|
import net.minecraft.text.TextContent;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.math.Vec2f;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import xyz.nucleoid.packettweaker.PacketContext;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MinionItem extends Item implements PolymerItem {
|
public class MinionItem extends Item implements PolymerItem {
|
||||||
private final boolean canProgram;
|
private boolean canProgram;
|
||||||
|
public MinionItem(boolean canProgram) {
|
||||||
public MinionItem(Settings settings, boolean canProgram) {
|
super(new FabricItemSettings());
|
||||||
super(settings);
|
|
||||||
this.canProgram = canProgram;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
|
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Item getPolymerItem(ItemStack itemStack, PacketContext player) {
|
|
||||||
return Items.ARMOR_STAND;
|
return Items.ARMOR_STAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getPolymerItemStack(ItemStack stack, TooltipType tooltipType, PacketContext player) {
|
public ItemStack getPolymerItemStack(ItemStack stack, TooltipContext flag, ServerPlayerEntity player) {
|
||||||
ItemStack out = PolymerItemUtils.createItemStack(stack, tooltipType, player);
|
ItemStack out = PolymerItemUtils.createItemStack(stack, flag, player);
|
||||||
out.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true);
|
out.addEnchantment(Enchantments.MENDING, 1);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
|
|
||||||
MinionData data = stack.get(MinionData.COMPONENT);
|
|
||||||
if(data != null) {
|
|
||||||
tooltip.add(Text.translatable("minions.minion_item.tooltip", data.name()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||||
String contents = context.getStack().getName().getLiteralString();
|
String contents = context.getStack().getName().getLiteralString();
|
||||||
String name;
|
String name;
|
||||||
if(contents != null && contents.length() <= 16) {
|
if(contents != null) {
|
||||||
name = contents;
|
name = contents;
|
||||||
} else {
|
} else {
|
||||||
name = "Minion";
|
name = "Minion";
|
||||||
}
|
}
|
||||||
if(!context.getWorld().isClient) {
|
if(!context.getWorld().isClient) {
|
||||||
MinionData data = getData(context.getStack());
|
MinionFakePlayer.createMinion(name, (ServerWorld) context.getWorld(), (ServerPlayerEntity) context.getPlayer(), canProgram, context.getBlockPos().toCenterPos().add(0,0.5,0), 0, 0);
|
||||||
|
|
||||||
if(data == null) {
|
|
||||||
data = new MinionData(null, name, Optional.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.uuid() == null) {
|
|
||||||
MinionFakePlayer.createMinion(data, (ServerWorld) context.getWorld(), (ServerPlayerEntity) context.getPlayer(), canProgram, context.getBlockPos().toCenterPos().add(0,0.5,0), new Vec2f(0, 0));
|
|
||||||
}else {
|
|
||||||
data = data.withName(name);
|
|
||||||
MinionFakePlayer.spawnMinionAt(data, (ServerWorld) context.getWorld(), context.getBlockPos().toCenterPos().add(0,0.5,0), new Vec2f(0, 0));
|
|
||||||
MinionPersistentState.INSTANCE.addMinion(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context.getStack().decrement(1);
|
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setData(MinionData data, ItemStack item) {
|
|
||||||
item.set(MinionData.COMPONENT, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static MinionData getData(ItemStack item) {
|
|
||||||
return item.get(MinionData.COMPONENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean containsData(ItemStack item) {
|
|
||||||
NbtComponent nbt = item.get(DataComponentTypes.CUSTOM_DATA);
|
|
||||||
if (nbt == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return nbt.copyNbt().contains("data");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.nbt.NbtCompound;
|
|
||||||
import net.minecraft.nbt.NbtElement;
|
|
||||||
import net.minecraft.nbt.NbtList;
|
|
||||||
import net.minecraft.registry.RegistryWrapper;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.world.PersistentState;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MinionPersistentState extends PersistentState {
|
|
||||||
public static Type<MinionPersistentState> TYPE = new Type<>(MinionPersistentState::new, MinionPersistentState::read, null);
|
|
||||||
|
|
||||||
public static MinionPersistentState INSTANCE;
|
|
||||||
|
|
||||||
private final List<MinionData> minionData = new ArrayList<>();
|
|
||||||
private final List<UUID> minionUuids = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
|
|
||||||
NbtList list = new NbtList();
|
|
||||||
for(MinionData data : minionData) {
|
|
||||||
list.add(data.writeNbt());
|
|
||||||
}
|
|
||||||
nbt.put("minions", list);
|
|
||||||
|
|
||||||
NbtList uuids = new NbtList();
|
|
||||||
for(UUID uuid : minionUuids) {
|
|
||||||
NbtCompound compound = new NbtCompound();
|
|
||||||
compound.putUuid("uuid", uuid);
|
|
||||||
uuids.add(compound);
|
|
||||||
}
|
|
||||||
nbt.put("uuids", uuids);
|
|
||||||
return nbt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MinionPersistentState read(NbtCompound compound, RegistryWrapper.WrapperLookup lookup) {
|
|
||||||
NbtList list = compound.getList("minions", NbtElement.COMPOUND_TYPE);
|
|
||||||
MinionPersistentState instance = new MinionPersistentState();
|
|
||||||
for(NbtElement element : list) {
|
|
||||||
instance.addMinion(MinionData.readNbt((NbtCompound) element));
|
|
||||||
}
|
|
||||||
|
|
||||||
NbtList uuids = compound.getList("uuids", NbtElement.COMPOUND_TYPE);
|
|
||||||
for(NbtElement element : uuids) {
|
|
||||||
instance.minionUuids.add(((NbtCompound) element).getUuid("uuid"));
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMinionUUID(UUID uuid) {
|
|
||||||
if(!minionUuids.contains(uuid)) {
|
|
||||||
minionUuids.add(uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMinion(MinionFakePlayer minion) {
|
|
||||||
addMinion(MinionData.fromMinion(minion));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMinion(MinionData data) {
|
|
||||||
System.out.println("add Minion " + data.name());
|
|
||||||
minionData.add(data);
|
|
||||||
markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeMinion(MinionFakePlayer minionData) {
|
|
||||||
removeMinion(minionData.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeMinion(UUID minionUUID) {
|
|
||||||
MinionData removal = null;
|
|
||||||
for (MinionData data : minionData) {
|
|
||||||
if (data.uuid().equals(minionUUID)) {
|
|
||||||
removal = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (removal != null) {
|
|
||||||
minionData.remove(removal);
|
|
||||||
}
|
|
||||||
markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MinionData> getMinionData() {
|
|
||||||
return minionData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMinion(UUID uuid) {
|
|
||||||
return minionUuids.contains(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void create(MinecraftServer server) {
|
|
||||||
INSTANCE = server.getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TYPE, "minion");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package io.github.skippyall.minions.minion;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.ProfileLookupCallback;
|
|
||||||
import com.mojang.authlib.yggdrasil.ProfileResult;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ForkJoinPool;
|
|
||||||
|
|
||||||
import static io.github.skippyall.minions.Minions.LOGGER;
|
|
||||||
|
|
||||||
public class MinionProfileUtils {
|
|
||||||
public static CompletableFuture<@Nullable GameProfile> lookupSkinOwnerProfile(MinecraftServer server, String username) {
|
|
||||||
CompletableFuture<GameProfile> future = new CompletableFuture<>();
|
|
||||||
|
|
||||||
ForkJoinPool.commonPool().execute(() -> {
|
|
||||||
try {
|
|
||||||
server.getGameProfileRepo().findProfilesByNames(new String[]{username}, new ProfileLookupCallback() {
|
|
||||||
@Override
|
|
||||||
public void onProfileLookupSucceeded(GameProfile found) {
|
|
||||||
LOGGER.info("SkinProfile: {}", found);
|
|
||||||
try {
|
|
||||||
getSkinOwnerProfile(server, found.getId()).thenAccept(future::complete);
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
LOGGER.warn("Exception during Game Profile creation", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProfileLookupFailed(String profileName, Exception exception) {
|
|
||||||
LOGGER.warn("Lookup Error: ", exception);
|
|
||||||
future.complete(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Throwable e) {
|
|
||||||
LOGGER.warn("Failed to get UUID for username " + username, e);
|
|
||||||
future.complete(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CompletableFuture<@Nullable GameProfile> getSkinOwnerProfile(MinecraftServer server, @Nullable UUID uuid) {
|
|
||||||
CompletableFuture<GameProfile> future = new CompletableFuture<>();
|
|
||||||
future.completeAsync(() -> {
|
|
||||||
GameProfile profile = null;
|
|
||||||
if(uuid != null) {
|
|
||||||
ProfileResult result = server.getSessionService().fetchProfile(uuid, true);
|
|
||||||
if (result != null) {
|
|
||||||
profile = result.profile();
|
|
||||||
LOGGER.info("Full SkinProfile: {}", profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return profile;
|
|
||||||
});
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameProfile makeNewMinionProfile(@Nullable UUID uuidMinion, String username, @Nullable GameProfile skinProfile) {
|
|
||||||
if(uuidMinion == null) {
|
|
||||||
uuidMinion = UUID.randomUUID();
|
|
||||||
}
|
|
||||||
MinionPersistentState.INSTANCE.addMinionUUID(uuidMinion);
|
|
||||||
|
|
||||||
GameProfile newProfile = new GameProfile(uuidMinion, username);
|
|
||||||
if (skinProfile != null) {
|
|
||||||
newProfile.getProperties().putAll(skinProfile.getProperties());
|
|
||||||
}
|
|
||||||
LOGGER.info("Minion Profile: {}", newProfile);
|
|
||||||
return newProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isMinion(UUID uuid) {
|
|
||||||
return MinionPersistentState.INSTANCE.isMinion(uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package io.github.skippyall.minions.minion;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import net.minecraft.inventory.Inventories;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.registry.RegistryKeys;
|
||||||
|
import net.minecraft.registry.tag.TagKey;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
|
||||||
|
public class ModuleInventory implements ImplementedInventory {
|
||||||
|
private static final TagKey<Item> MODULES = TagKey.of(RegistryKeys.ITEM, new Identifier(Minions.MOD_ID,"modules"));
|
||||||
|
private DefaultedList<ItemStack> stacks = DefaultedList.ofSize(27, ItemStack.EMPTY);
|
||||||
|
|
||||||
|
public ModuleInventory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxCountPerStack() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(int slot, ItemStack stack) {
|
||||||
|
return (stack.getCount() <= getMaxCountPerStack()) && stack.isIn(MODULES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultedList<ItemStack> getItems() {
|
||||||
|
return stacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readNbt(NbtCompound nbt) {
|
||||||
|
Inventories.readNbt(nbt, stacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeNbt(NbtCompound nbt) {
|
||||||
|
Inventories.writeNbt(nbt, stacks);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,342 +0,0 @@
|
|||||||
//partially code from https://github.com/gnembon/fabric-carpet
|
|
||||||
package io.github.skippyall.minions.minion.fakeplayer;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.minion.MinionData;
|
|
||||||
import io.github.skippyall.minions.gui.MinionGui;
|
|
||||||
import io.github.skippyall.minions.minion.MinionItem;
|
|
||||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
|
||||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
|
||||||
import io.github.skippyall.minions.gui.ModuleInventory;
|
|
||||||
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.component.DataComponentTypes;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
|
||||||
import net.minecraft.entity.MovementType;
|
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
|
||||||
import net.minecraft.entity.damage.DamageSource;
|
|
||||||
import net.minecraft.entity.player.HungerManager;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NbtCompound;
|
|
||||||
import net.minecraft.network.DisconnectionInfo;
|
|
||||||
import net.minecraft.network.NetworkSide;
|
|
||||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
|
||||||
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
|
|
||||||
import net.minecraft.network.packet.s2c.play.EntityPositionSyncS2CPacket;
|
|
||||||
import net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.ServerTask;
|
|
||||||
import net.minecraft.server.network.ConnectedClientData;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.text.TranslatableTextContent;
|
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Vec2f;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.GameMode;
|
|
||||||
import net.minecraft.world.TeleportTarget;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class MinionFakePlayer extends ServerPlayerEntity {
|
|
||||||
public Runnable fixStartingPosition = () -> {};
|
|
||||||
|
|
||||||
private float moveForward;
|
|
||||||
private float moveSideways;
|
|
||||||
|
|
||||||
private boolean programmable;
|
|
||||||
private final ModuleInventory moduleInventory = new ModuleInventory();
|
|
||||||
private final MinionRuntime runtime = new MinionRuntime(this);
|
|
||||||
|
|
||||||
private UUID skinUuid = null;
|
|
||||||
|
|
||||||
public static void createMinion(MinionData data, ServerWorld level, ServerPlayerEntity owner, boolean canProgram, Vec3d pos, Vec2f rot) {
|
|
||||||
spawnMinion(data, level, pos, rot,
|
|
||||||
(minion, skinProfile) -> {
|
|
||||||
if (skinProfile != null) {
|
|
||||||
minion.skinUuid = skinProfile.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
minion.programmable = canProgram;
|
|
||||||
},
|
|
||||||
minion -> {
|
|
||||||
MinionPersistentState.INSTANCE.addMinion(minion);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void spawnMinionAt(MinionData data, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
|
||||||
spawnMinion(data, level, pos, rot, (minion, skinProfile) -> {}, minion -> {});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void spawnMinion(MinionData data, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot, BiConsumer<MinionFakePlayer, GameProfile> beforeSpawn, Consumer<MinionFakePlayer> afterSpawn) {
|
|
||||||
MinecraftServer server = level.getServer();
|
|
||||||
|
|
||||||
CompletableFuture<GameProfile> future;
|
|
||||||
if(data.skinUuid().isPresent()) {
|
|
||||||
future = MinionProfileUtils.getSkinOwnerProfile(server, data.skinUuid().get());
|
|
||||||
} else {
|
|
||||||
future = MinionProfileUtils.lookupSkinOwnerProfile(server, data.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
future.thenAccept((skinProfile) -> {
|
|
||||||
GameProfile profile = MinionProfileUtils.makeNewMinionProfile(data.uuid(), data.name(), skinProfile);
|
|
||||||
Minions.addExecuteOnNextTick(() -> {
|
|
||||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, SyncedClientOptions.createDefault());
|
|
||||||
beforeSpawn.accept(instance, skinProfile);
|
|
||||||
|
|
||||||
if(pos != null && rot != null) {
|
|
||||||
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, rot.x, rot.y);
|
|
||||||
}
|
|
||||||
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance, new ConnectedClientData(profile, 0, instance.getClientOptions(), false));
|
|
||||||
System.out.println(instance.getPos());
|
|
||||||
if(pos != null && rot != null) {
|
|
||||||
instance.teleport(level, pos.x, pos.y, pos.z, Set.of(), rot.x, rot.y, true);
|
|
||||||
}
|
|
||||||
instance.setVelocity(0,0,0);
|
|
||||||
instance.setHealth(20.0F);
|
|
||||||
instance.unsetRemoved();
|
|
||||||
instance.getAttributeInstance(EntityAttributes.STEP_HEIGHT).setBaseValue(0.6F);
|
|
||||||
instance.interactionManager.changeGameMode(GameMode.SURVIVAL);
|
|
||||||
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), level.getRegistryKey());//instance.dimension);
|
|
||||||
server.getPlayerManager().sendToDimension(EntityPositionSyncS2CPacket.create(instance), level.getRegistryKey());//instance.dimension);
|
|
||||||
//instance.world.getChunkManager(). updatePosition(instance);
|
|
||||||
instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
|
|
||||||
instance.getAbilities().flying = false;
|
|
||||||
|
|
||||||
afterSpawn.accept(instance);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerWorld level, GameProfile profile, SyncedClientOptions cli)
|
|
||||||
{
|
|
||||||
return new MinionFakePlayer(server, level, profile, cli);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MinionFakePlayer(MinecraftServer server, ServerWorld worldIn, GameProfile profile, SyncedClientOptions cli)
|
|
||||||
{
|
|
||||||
super(server, worldIn, profile, cli);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isProgrammable() {
|
|
||||||
return programmable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProgrammable(boolean programmable) {
|
|
||||||
this.programmable = programmable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModuleInventory getModuleInventory() {
|
|
||||||
return moduleInventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MinionRuntime getRuntime() {
|
|
||||||
return runtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityPlayerActionPack getMinionActionPack() {
|
|
||||||
return ((ServerPlayerInterface)this).getActionPack();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResult interact(PlayerEntity player, Hand hand) {
|
|
||||||
if(player instanceof ServerPlayerEntity spe) {
|
|
||||||
MinionGui.openInventory(spe, this);
|
|
||||||
}
|
|
||||||
return ActionResult.CONSUME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResult interactAt(PlayerEntity player, Vec3d hitPos, Hand hand) {
|
|
||||||
return interact(player, hand);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEquipStack(final EquipmentSlot slot, final ItemStack previous, final ItemStack stack)
|
|
||||||
{
|
|
||||||
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public void kill()
|
|
||||||
{
|
|
||||||
kill(Text.literal("Killed"));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public void kill(Text reason)
|
|
||||||
{
|
|
||||||
shakeOff();
|
|
||||||
|
|
||||||
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
|
||||||
this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
|
|
||||||
} else {
|
|
||||||
this.server.send(new ServerTask(this.server.getTicks(), () -> {
|
|
||||||
this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
MinionPersistentState.INSTANCE.removeMinion(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick()
|
|
||||||
{
|
|
||||||
if (this.getServer().getTicks() % 10 == 0)
|
|
||||||
{
|
|
||||||
this.networkHandler.syncWithPlayerPosition();
|
|
||||||
this.getServerWorld().getChunkManager().updatePosition(this);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
super.tick();
|
|
||||||
this.playerTick();
|
|
||||||
}
|
|
||||||
catch (NullPointerException ignored)
|
|
||||||
{
|
|
||||||
// happens with that paper port thingy - not sure what that would fix, but hey
|
|
||||||
// the game not gonna crash violently.
|
|
||||||
}
|
|
||||||
runtime.tick();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shakeOff()
|
|
||||||
{
|
|
||||||
if (getVehicle() instanceof PlayerEntity) stopRiding();
|
|
||||||
for (Entity passenger : getPassengersDeep())
|
|
||||||
{
|
|
||||||
if (passenger instanceof PlayerEntity) passenger.stopRiding();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDeath(DamageSource cause)
|
|
||||||
{
|
|
||||||
shakeOff();
|
|
||||||
super.onDeath(cause);
|
|
||||||
setHealth(20);
|
|
||||||
this.hungerManager = new HungerManager();
|
|
||||||
kill(this.getDamageTracker().getDeathMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIp()
|
|
||||||
{
|
|
||||||
return "127.0.0.1";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean allowsServerListing() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fall(double y, boolean onGround, BlockState state, BlockPos pos) {
|
|
||||||
handleFall(0.0, y, 0.0, onGround);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServerPlayerEntity teleportTo(TeleportTarget target)
|
|
||||||
{
|
|
||||||
super.teleportTo(target);
|
|
||||||
if (notInAnyWorld) {
|
|
||||||
ClientStatusC2SPacket p = new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.PERFORM_RESPAWN);
|
|
||||||
networkHandler.onClientStatus(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If above branch was taken, *this* has been removed and replaced, the new instance has been set
|
|
||||||
// on 'our' connection (which is now theirs, but we still have a ref).
|
|
||||||
if (networkHandler.player.isInTeleportationState()) {
|
|
||||||
networkHandler.player.onTeleportationDone();
|
|
||||||
}
|
|
||||||
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
|
|
||||||
public void drop(ServerWorld world, DamageSource damageSource) {
|
|
||||||
super.drop(world, damageSource);
|
|
||||||
dropStack(world, toItemStack()).setNeverDespawn();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack toItemStack() {
|
|
||||||
ItemStack stack = new ItemStack(Minions.MINION_ITEM);
|
|
||||||
MinionItem.setData(MinionData.fromMinion(this), stack);
|
|
||||||
if (!getMinionName().equals("Minion")) {
|
|
||||||
stack.set(DataComponentTypes.CUSTOM_NAME, Text.of(getMinionName()));
|
|
||||||
}
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeCustomDataToNbt(NbtCompound nbt) {
|
|
||||||
super.writeCustomDataToNbt(nbt);
|
|
||||||
nbt.put("modules", moduleInventory.writeNbt(new NbtCompound(), getRegistryManager()));
|
|
||||||
nbt.putBoolean("programmable", programmable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readCustomDataFromNbt(NbtCompound nbt) {
|
|
||||||
super.readCustomDataFromNbt(nbt);
|
|
||||||
moduleInventory.readNbt(nbt.getCompound("modules"), getRegistryManager());
|
|
||||||
programmable = nbt.getBoolean("programmable");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMinionName() {
|
|
||||||
return getGameProfile().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<UUID> getSkinUuid() {
|
|
||||||
return Optional.ofNullable(skinUuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
//code from https://github.com/gnembon/fabric-carpet
|
|
||||||
package io.github.skippyall.minions.minion.fakeplayer;
|
|
||||||
|
|
||||||
public interface ServerPlayerInterface
|
|
||||||
{
|
|
||||||
EntityPlayerActionPack getActionPack();
|
|
||||||
}
|
|
||||||
-9
@@ -1,9 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixinhelper;
|
|
||||||
|
|
||||||
public interface ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor {
|
|
||||||
void minions$markAsMinionless();
|
|
||||||
void minions$markAsTarget();
|
|
||||||
int minions$getTickedChunkCount();
|
|
||||||
|
|
||||||
boolean minions$isRealPlayerInChunk(long chunkPos);
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixinhelper;
|
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
|
|
||||||
public interface ChunkTicketManagerAccessor {
|
|
||||||
ObjectSet<ServerPlayerEntity> getPlayers(long chunkpos);
|
|
||||||
|
|
||||||
ChunkTicketManager.DistanceFromNearestPlayerTracker getMinionless();
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
|
|
||||||
@Mixin(value = ChunkTicketManager.class)
|
|
||||||
public class ChunkTicketManagerFixMixin {
|
|
||||||
@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) {
|
|
||||||
if (instance != null) {
|
|
||||||
return original.call(instance, o);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;//Unused
|
|
||||||
}
|
|
||||||
|
|
||||||
@WrapOperation(method = "handleChunkLeave", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectSet;isEmpty()Z", remap = false))
|
|
||||||
public boolean filterIfNull(ObjectSet instance, Operation<Boolean> original) {
|
|
||||||
if (instance != null) {
|
|
||||||
return original.call(instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;//Unused
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
//code from https://github.com/gnembon/fabric-carpet
|
|
||||||
package io.github.skippyall.minions.mixins;
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.ClientConnectionInterface;
|
import io.github.skippyall.minions.fakeplayer.ClientConnectionInterface;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
|
||||||
|
|
||||||
@Mixin(Entity.class)
|
|
||||||
public interface EntityAccessor {
|
|
||||||
@Invoker("canAddPassenger")
|
|
||||||
boolean invokeCanAddPassenger(Entity other);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
|
||||||
import eu.pb4.graves.grave.Grave;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
|
||||||
|
|
||||||
@Mixin(Grave.class)
|
|
||||||
public class GraveCompatMixin {
|
|
||||||
@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) {
|
|
||||||
if(player instanceof MinionFakePlayer) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return profile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Mixin(MinecraftServer.class)
|
|
||||||
public class MinecraftServerMixin {
|
|
||||||
@ModifyExpressionValue(method = "createMetadataPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;getPlayerList()Ljava/util/List;"))
|
|
||||||
public List<ServerPlayerEntity> ignoreFakePlayers(List<ServerPlayerEntity> original) {
|
|
||||||
return original.stream()
|
|
||||||
.filter(player -> !(player instanceof MinionFakePlayer))
|
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import io.github.skippyall.minions.module.MobSpawningModule;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.mob.MobEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.predicate.entity.EntityPredicates;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
|
|
||||||
@Mixin(MobEntity.class)
|
|
||||||
public abstract class MobEntityMixin {
|
|
||||||
@Redirect(method = "checkDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getClosestPlayer(Lnet/minecraft/entity/Entity;D)Lnet/minecraft/entity/player/PlayerEntity;"))
|
|
||||||
public PlayerEntity checkMobDespawningMinion(World instance, Entity entity, double maxDistance) {
|
|
||||||
return instance.getClosestPlayer(entity.getX(), entity.getY(), entity.getZ(), maxDistance, EntityPredicates.EXCEPT_SPECTATOR.and(entity1 -> {
|
|
||||||
if(entity1 instanceof ServerPlayerEntity player) {
|
|
||||||
if(player instanceof MinionFakePlayer minion) {
|
|
||||||
return MobSpawningModule.canMinionDespawnMobs(minion);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
|
||||||
|
|
||||||
@Mixin(PlayerListS2CPacket.Entry.class)
|
|
||||||
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;ILnet/minecraft/network/encryption/PublicPlayerSession$Serialized;)V"))
|
|
||||||
private static boolean removeMinionFromTabList(boolean original, @Local(argsOnly = true) ServerPlayerEntity player) {
|
|
||||||
if(player instanceof MinionFakePlayer) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
//partially code from https://github.com/gnembon/fabric-carpet
|
|
||||||
package io.github.skippyall.minions.mixins;
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.ModifyReceiver;
|
|
||||||
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 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.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.NetHandlerPlayServerFake;
|
import io.github.skippyall.minions.fakeplayer.NetHandlerPlayServerFake;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
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;
|
||||||
@@ -17,16 +14,13 @@ import net.minecraft.server.network.ConnectedClientData;
|
|||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
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 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;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Mixin(PlayerManager.class)
|
@Mixin(PlayerManager.class)
|
||||||
public class PlayerListMixin {
|
public class PlayerListMixin {
|
||||||
|
|
||||||
@@ -52,22 +46,8 @@ 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);
|
return MinionFakePlayer.respawnFake(minecraftServer, serverLevel, gameProfile, clientInformation, minion.isProgrammable());
|
||||||
}
|
}
|
||||||
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"))
|
|
||||||
public void noLoginMessage(PlayerManager instance, Text message, boolean overlay, Operation<Void> original, @Local(argsOnly = true) ServerPlayerEntity player) {
|
|
||||||
if(!(player instanceof MinionFakePlayer)) {
|
|
||||||
original.call(instance, message, overlay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ModifyReceiver(method = "checkCanJoin", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I"))
|
|
||||||
public List<ServerPlayerEntity> noMinionCounting(List<ServerPlayerEntity> instance) {
|
|
||||||
return instance.stream()
|
|
||||||
.filter(player -> !(player instanceof MinionFakePlayer))
|
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.server.PlayerManager;
|
|
||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
|
|
||||||
@Mixin(ServerPlayNetworkHandler.class)
|
|
||||||
public class ServerPlayNetworkHandlerMixin {
|
|
||||||
@Shadow
|
|
||||||
public ServerPlayerEntity player;
|
|
||||||
|
|
||||||
@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) {
|
|
||||||
if(!(player instanceof MinionFakePlayer)) {
|
|
||||||
original.call(instance, message, overlay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
package io.github.skippyall.minions.mixins;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.ServerPlayerInterface;
|
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
||||||
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;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.server.world.SleepManager;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
|
|
||||||
@Mixin(SleepManager.class)
|
|
||||||
public class SleepManagerMixin {
|
|
||||||
@WrapOperation(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;isSpectator()Z"))
|
|
||||||
public boolean excludeMinions(ServerPlayerEntity instance, Operation<Boolean> original) {
|
|
||||||
if (instance instanceof MinionFakePlayer) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return original.call(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import io.github.skippyall.minions.module.MobSpawningModule;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.predicate.entity.EntityPredicates;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
|
||||||
import net.minecraft.world.SpawnHelper;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
|
|
||||||
@Mixin(SpawnHelper.class)
|
|
||||||
public class SpawnHelperMixin {
|
|
||||||
@Redirect(method = "spawnEntitiesInChunk(Lnet/minecraft/entity/SpawnGroup;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/SpawnHelper$Checker;Lnet/minecraft/world/SpawnHelper$Runner;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getClosestPlayer(DDDDZ)Lnet/minecraft/entity/player/PlayerEntity;"))
|
|
||||||
private static PlayerEntity checkMobSpawningMinion(ServerWorld instance, double x, double y, double z, double maxDistance, boolean b) {
|
|
||||||
return instance.getClosestPlayer(x, y, z, maxDistance, EntityPredicates.EXCEPT_SPECTATOR.and(entity -> {
|
|
||||||
if(entity instanceof ServerPlayerEntity player) {
|
|
||||||
if(player instanceof MinionFakePlayer minion) {
|
|
||||||
return MobSpawningModule.canMinionSpawnMobs(minion);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(net.minecraft.world.ChunkPosDistanceLevelPropagator.class)
|
|
||||||
public class ChunkPosDistanceLevelPropagatorMixin {
|
|
||||||
@Inject(method = "updateLevel", at = @At("HEAD"))
|
|
||||||
public void minions$updateLevel(long chunkPos, int distance, boolean decrease, CallbackInfo info) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-85
@@ -1,85 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor;
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManagerAccessor;
|
|
||||||
import io.github.skippyall.minions.module.MobSpawningModule;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ByteMap;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
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;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(value = ChunkTicketManager.DistanceFromNearestPlayerTracker.class)
|
|
||||||
public abstract class ChunkTicketManager$DistanceFromNearestPlayerTrackerMixin extends ChunkPosDistanceLevelPropagatorMixin implements ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor {
|
|
||||||
@Final
|
|
||||||
@Shadow
|
|
||||||
ChunkTicketManager field_17462;
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
@Final
|
|
||||||
protected Long2ByteMap distanceFromNearestPlayer;
|
|
||||||
|
|
||||||
@Shadow protected abstract boolean isPlayerInChunk(long chunkPos);
|
|
||||||
|
|
||||||
@Unique
|
|
||||||
boolean minions$minionless, minions$target;
|
|
||||||
|
|
||||||
@Inject(method = "isPlayerInChunk", at = @At("RETURN"), cancellable = true)
|
|
||||||
public void minions$filterMinions(long chunkPos, CallbackInfoReturnable<Boolean> cir) {
|
|
||||||
if (minions$minionless) {
|
|
||||||
cir.setReturnValue(minions$isRealPlayerInChunk(chunkPos));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean minions$isRealPlayerInChunk(long chunkPos) {
|
|
||||||
ObjectSet<ServerPlayerEntity> players = ((ChunkTicketManagerAccessor)field_17462).getPlayers(chunkPos);
|
|
||||||
boolean contains = false;
|
|
||||||
if(players != null) {
|
|
||||||
contains = players.stream().anyMatch(player -> {
|
|
||||||
if (player instanceof MinionFakePlayer minion) {
|
|
||||||
return MobSpawningModule.canMinionSpawnMobs(minion);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return contains;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "updateLevels", at = @At("HEAD"))
|
|
||||||
public void minions$sync(CallbackInfo info) {
|
|
||||||
if (minions$target) {
|
|
||||||
((ChunkTicketManagerAccessor)field_17462).getMinionless().updateLevels();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void minions$updateLevel(long chunkPos, int distance, boolean decrease, CallbackInfo info) {
|
|
||||||
if (minions$target && (distance == Integer.MAX_VALUE || minions$isRealPlayerInChunk(chunkPos))) {
|
|
||||||
((ChunkTicketManagerAccessor)field_17462).getMinionless().updateLevel(chunkPos, distance, decrease);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void minions$markAsMinionless() {
|
|
||||||
minions$minionless = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void minions$markAsTarget() {
|
|
||||||
minions$target = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int minions$getTickedChunkCount() {
|
|
||||||
return distanceFromNearestPlayer.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor;
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManagerAccessor;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import net.minecraft.util.math.ChunkSectionPos;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
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.CallbackInfo;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
@Mixin(ChunkTicketManager.class)
|
|
||||||
public class ChunkTicketManagerMixin implements ChunkTicketManagerAccessor {
|
|
||||||
@Shadow @Final private Long2ObjectMap<ObjectSet<ServerPlayerEntity>> playersByChunkPos;
|
|
||||||
@Shadow @Final private ChunkTicketManager.DistanceFromNearestPlayerTracker distanceFromNearestPlayerTracker;
|
|
||||||
ChunkTicketManager.DistanceFromNearestPlayerTracker minionless;
|
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
|
||||||
public void createMinionlessClone(Executor workerExecutor, Executor mainThreadExecutor, CallbackInfo ci) {
|
|
||||||
ChunkTicketManager manager = ((ChunkTicketManager)(Object)this);
|
|
||||||
minionless = manager.new DistanceFromNearestPlayerTracker(8);
|
|
||||||
((ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor)minionless).minions$markAsMinionless();
|
|
||||||
((ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor)distanceFromNearestPlayerTracker).minions$markAsTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectSet<ServerPlayerEntity> getPlayers(long chunkpos) {
|
|
||||||
return playersByChunkPos.get(chunkpos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChunkTicketManager.DistanceFromNearestPlayerTracker getMinionless() {
|
|
||||||
return minionless;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "handleChunkLeave", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectSet;remove(Ljava/lang/Object;)Z", shift = At.Shift.AFTER, remap = false))
|
|
||||||
public void minion$updateMinionlessIfNoMinionInChunk(ChunkSectionPos pos, ServerPlayerEntity player, CallbackInfo ci, @Local long chunk) {
|
|
||||||
if (!((ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor)minionless).minions$isRealPlayerInChunk(chunk)) {
|
|
||||||
minionless.updateLevel(chunk, Integer.MAX_VALUE, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
|
||||||
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import net.minecraft.server.world.ServerChunkManager;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
@Mixin(ServerChunkManager.class)
|
|
||||||
public interface ServerChunkManagerAccessor {
|
|
||||||
@Accessor
|
|
||||||
ChunkTicketManager getTicketManager();
|
|
||||||
}
|
|
||||||
-23
@@ -1,23 +0,0 @@
|
|||||||
package io.github.skippyall.minions.mixins.antimobcap;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor;
|
|
||||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManagerAccessor;
|
|
||||||
import net.minecraft.server.world.ChunkTicketManager;
|
|
||||||
import net.minecraft.server.world.ServerChunkManager;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
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.ModifyArg;
|
|
||||||
|
|
||||||
@Mixin(ServerChunkManager.class)
|
|
||||||
public class ServerChunkManagerMixin {
|
|
||||||
@Shadow
|
|
||||||
@Final
|
|
||||||
private ChunkTicketManager ticketManager;
|
|
||||||
|
|
||||||
@ModifyArg(method = "tickChunks(Lnet/minecraft/util/profiler/Profiler;JLjava/util/List;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/SpawnHelper;setupSpawn(ILjava/lang/Iterable;Lnet/minecraft/world/SpawnHelper$ChunkSource;Lnet/minecraft/world/SpawnDensityCapper;)Lnet/minecraft/world/SpawnHelper$Info;"))
|
|
||||||
public int useMinionless(int spawningChunkCount) {
|
|
||||||
return ((ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor)((ChunkTicketManagerAccessor)ticketManager).getMinionless()).minions$getTickedChunkCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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.command.CommandExecutor;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
import io.github.skippyall.minions.input.TextInput;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.screen.ScreenHandlerType;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
public class ActionModules {
|
|
||||||
public static 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.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.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.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() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -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() {}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.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,31 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.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 <T extends Item & ModuleItem> T register(Identifier id, T item) {
|
|
||||||
return Registry.register(Registries.ITEM, id, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SimpleModuleItem register(Identifier id, List<CodeBlock<?,?>> codeBlocks, List<Command> commands, Item vanillaItem) {
|
|
||||||
return Registry.register(Registries.ITEM, id, new SimpleModuleItem(codeBlocks, commands, new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id)), vanillaItem));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.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,74 +0,0 @@
|
|||||||
package io.github.skippyall.minions.module;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.Minions;
|
|
||||||
import io.github.skippyall.minions.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.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,40 @@
|
|||||||
|
package io.github.skippyall.minions.networking;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.Minions;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.network.ClientConfigurationNetworkHandler;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.network.ServerConfigurationNetworkHandler;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class ClientToServerNetworking {
|
||||||
|
public static final Identifier RL = new Identifier(Minions.MOD_ID, "network");
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public static void sendJoinPacket(PlayerEntity player) {
|
||||||
|
PacketByteBuf pbf = new PacketByteBuf(Unpooled.buffer());
|
||||||
|
pbf.writeString("BN|Init|V0.1");
|
||||||
|
ClientConfigurationNetworking.send(RL, pbf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public static void onConfigurationInit(ClientConfigurationNetworkHandler handler, MinecraftClient client) {
|
||||||
|
sendJoinPacket(client.player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Environment(EnvType.SERVER)
|
||||||
|
public static void receive(MinecraftServer server, ServerConfigurationNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
|
||||||
|
String message = buf.readString();
|
||||||
|
if (!message.startsWith("BN|")) {
|
||||||
|
Minions.LOGGER.debug("Message with wrong format: " + message);
|
||||||
|
}
|
||||||
|
String[] parts = message.split("|");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package io.github.skippyall.minions.networking;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
|
||||||
|
public class VersionChecker {
|
||||||
|
protected static List<UUID> hasSupportedMod = new ArrayList<>();
|
||||||
|
public static boolean supportVersion(String version) {
|
||||||
|
return version.equals("v0.1");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean useSupportedMod(PlayerEntity p) {
|
||||||
|
return hasSupportedMod.contains(p.getUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetPlayer(UUID uuid) {
|
||||||
|
hasSupportedMod.remove(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package io.github.skippyall.minions.program;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.program.statement.StatementList;
|
||||||
|
import io.github.skippyall.minions.program.variables.Variable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MinionRuntime implements Runnable{
|
||||||
|
private boolean run = true;
|
||||||
|
public final Map<String, Variable> variables = new HashMap<>();
|
||||||
|
private final List<StatementList.Run> runs = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while(run) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
run = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +1,23 @@
|
|||||||
package io.github.skippyall.minions.program.block;
|
package io.github.skippyall.minions.program.block;
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.argument.Arg;
|
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
import io.github.skippyall.minions.program.statement.Arg;
|
||||||
import io.github.skippyall.minions.program.statement.Statement;
|
|
||||||
import io.github.skippyall.minions.program.tuple.Tuple;
|
|
||||||
import io.github.skippyall.minions.program.variables.Type;
|
import io.github.skippyall.minions.program.variables.Type;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
|
||||||
|
|
||||||
public abstract class CodeBlock<R, A extends Tuple> {
|
public abstract class CodeBlock {
|
||||||
private String name;
|
private String name;
|
||||||
private final List<Type<?>> arguments;
|
private final List<Type> arguments;
|
||||||
private final Type<?> returnType;
|
private final Type returnType;
|
||||||
|
public CodeBlock(String name, List<Type> arguments, Type returnType) {
|
||||||
public CodeBlock(String name, List<Type<?>> arguments, Type<?> returnType) {
|
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract R execute(ProgramRuntime runtime, A args, Statement<R,A>.Run run);
|
public abstract Object execute(MinionFakePlayer minion, Object... args);
|
||||||
|
|
||||||
public boolean fits(Arg<?> arg, int slot) {
|
public boolean fits(Arg arg, int slot) {
|
||||||
return arguments.get(slot) == arg.getType();
|
return arguments.get(slot) == arg.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(ProgramRuntime runtime, A args, Statement<R,A>.Run run) {
|
|
||||||
ForkJoinPool.commonPool().execute(() -> {
|
|
||||||
R result = execute(runtime, args, run);
|
|
||||||
run.afterRun(result);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,25 @@
|
|||||||
package io.github.skippyall.minions.program.block;
|
package io.github.skippyall.minions.program.block;
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.ServerPlayerInterface;
|
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
||||||
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
import io.github.skippyall.minions.program.variables.IntegerType;
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
import io.github.skippyall.minions.program.variables.Type;
|
||||||
import io.github.skippyall.minions.program.statement.Statement;
|
|
||||||
import io.github.skippyall.minions.program.tuple.Tuple2;
|
|
||||||
import io.github.skippyall.minions.program.variables.Types;
|
import io.github.skippyall.minions.program.variables.Types;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GoBlock extends CodeBlock<Void, Tuple2<Float, Float>> {
|
public class GoBlock extends CodeBlock{
|
||||||
public GoBlock() {
|
public GoBlock() {
|
||||||
super("move", List.of(Types.FLOAT, Types.FLOAT), Types.VOID);
|
super("move", List.of(Types.FLOAT, Types.FLOAT), Types.VOID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Void execute(ProgramRuntime runtime, Tuple2<Float, Float> args, Statement<Void, Tuple2<Float, Float>>.Run run) {
|
public Object execute(MinionFakePlayer minion, Object... args) {
|
||||||
if(runtime instanceof MinionRuntime minionRuntime) {
|
|
||||||
MinionFakePlayer minion = minionRuntime.getMinion();
|
|
||||||
EntityPlayerActionPack action = ((ServerPlayerInterface)minion).getActionPack();
|
EntityPlayerActionPack action = ((ServerPlayerInterface)minion).getActionPack();
|
||||||
minion.moveForward(args.v0());
|
minion.moveForward((Float) args[0]);
|
||||||
minion.moveSideways(args.v1());
|
minion.moveSideways((Float) args[1]);
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,21 @@
|
|||||||
package io.github.skippyall.minions.program.block;
|
package io.github.skippyall.minions.program.block;
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
import io.github.skippyall.minions.program.variables.Type;
|
||||||
import io.github.skippyall.minions.program.statement.Statement;
|
|
||||||
import io.github.skippyall.minions.program.tuple.Tuple0;
|
|
||||||
import io.github.skippyall.minions.program.variables.Types;
|
import io.github.skippyall.minions.program.variables.Types;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UseBlock extends CodeBlock<Void, Tuple0>{
|
public class UseBlock extends CodeBlock{
|
||||||
public UseBlock(String name) {
|
public UseBlock(String name, List<Type> arguments, Type returnType) {
|
||||||
super("use", List.of(), Types.VOID);
|
super("use", List.of(), Types.VOID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void execute(ProgramRuntime runtime, Tuple0 args, Statement<Void,Tuple0>.Run run) {
|
public Object execute(MinionFakePlayer minion, Object... args) {
|
||||||
if(runtime instanceof MinionRuntime minionRuntime) {
|
minion.getActionPack().start(EntityPlayerActionPack.ActionType.USE, EntityPlayerActionPack.Action.once());
|
||||||
MinionFakePlayer minion = minionRuntime.getMinion();
|
|
||||||
minion.getMinionActionPack().start(EntityPlayerActionPack.ActionType.USE, EntityPlayerActionPack.Action.once());
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.github.skippyall.minions.program.module;
|
||||||
|
|
||||||
|
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||||
|
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||||
|
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class Module extends Item implements PolymerItem {
|
||||||
|
private final String name;
|
||||||
|
public Module(String name) {
|
||||||
|
super(new FabricItemSettings().maxCount(1));
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModuleName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract List<CodeBlock> getCodeBlocks();
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package io.github.skippyall.minions.program.module;
|
||||||
|
|
||||||
|
public class Modules {
|
||||||
|
MoveModule MOVE = new MoveModule();
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package io.github.skippyall.minions.program.module;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||||
|
import io.github.skippyall.minions.program.block.CodeBlocks;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MoveModule extends Module {
|
||||||
|
MoveModule() {
|
||||||
|
super("Movement");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CodeBlock> getCodeBlocks() {
|
||||||
|
List<CodeBlock> codeBlocks = new ArrayList<>();
|
||||||
|
codeBlocks.add(CodeBlocks.GO);
|
||||||
|
return codeBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||||
|
return Items.PURPLE_GLAZED_TERRACOTTA;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.runtime;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
|
||||||
|
|
||||||
public class MinionRuntime extends ProgramRuntime {
|
|
||||||
private final MinionFakePlayer minion;
|
|
||||||
|
|
||||||
public MinionRuntime(MinionFakePlayer minion) {
|
|
||||||
this.minion = minion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MinionFakePlayer getMinion() {
|
|
||||||
return minion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.runtime;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.statement.StatementList;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class ProgramRuntime {
|
|
||||||
private final Map<String, Object> variables = new HashMap<>();
|
|
||||||
private StatementList statements;
|
|
||||||
private StatementList.Run run;
|
|
||||||
|
|
||||||
public ProgramRuntime() {
|
|
||||||
this(new StatementList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProgramRuntime(StatementList statements) {
|
|
||||||
this.statements = statements;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
run = statements.start(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick() {
|
|
||||||
if(run != null) {
|
|
||||||
run.tick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public StatementList getStatementList() {
|
|
||||||
return statements;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getVariable(String name) {
|
|
||||||
return variables.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariable(String name, Object value) {
|
|
||||||
variables.put(name, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package io.github.skippyall.minions.program.statement;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.program.variables.Type;
|
||||||
|
|
||||||
|
public interface Arg {
|
||||||
|
Object getValue();
|
||||||
|
Type getType();
|
||||||
|
}
|
||||||
@@ -1,73 +1,15 @@
|
|||||||
package io.github.skippyall.minions.program.statement;
|
package io.github.skippyall.minions.program.statement;
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.argument.ArgUtils;
|
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
|
||||||
import io.github.skippyall.minions.program.tuple.Tuple;
|
|
||||||
import io.github.skippyall.minions.program.variables.ValueStorage;
|
|
||||||
|
|
||||||
public record Statement<R,A extends Tuple>(CodeBlock<R,A> codeBlock, A args, ValueStorage<R> valueStorage) {
|
import java.util.List;
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Run start(ProgramRuntime runtime) {
|
|
||||||
Run run = new Run(runtime);
|
|
||||||
codeBlock.start(runtime, (A) ArgUtils.resolveArgs(args, runtime), run);
|
|
||||||
return run;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Run {
|
public class Statement {
|
||||||
private boolean running = false;
|
private CodeBlock codeBlock;
|
||||||
private boolean waiting = false;
|
private List<Arg> args;
|
||||||
private boolean afterRun = false;
|
|
||||||
private R cachedResult;
|
|
||||||
private int ticksRunning = 0;
|
|
||||||
private int ticksLeft = 0;
|
|
||||||
|
|
||||||
private final ProgramRuntime runtime;
|
public void execute(MinionFakePlayer minion) {
|
||||||
|
|
||||||
Run(ProgramRuntime runtime) {
|
|
||||||
this.runtime = runtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDone() {
|
|
||||||
return !running;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick() {
|
|
||||||
if(running) {
|
|
||||||
ticksRunning ++;
|
|
||||||
ticksLeft --;
|
|
||||||
if(ticksLeft == 0 && waiting && afterRun) {
|
|
||||||
complete(cachedResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterRun(R result) {
|
|
||||||
afterRun = true;
|
|
||||||
if(ticksLeft == 0) {
|
|
||||||
complete(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void complete(R result) {
|
|
||||||
if(valueStorage != null) {
|
|
||||||
valueStorage.storeValue(result, runtime);
|
|
||||||
}
|
|
||||||
running = false;
|
|
||||||
waiting = false;
|
|
||||||
cachedResult = null;
|
|
||||||
ticksRunning = 0;
|
|
||||||
ticksLeft = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void completeAfter(int ticks, R value) {
|
|
||||||
waiting = true;
|
|
||||||
ticksLeft = ticks;
|
|
||||||
cachedResult = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTicksRunning() {
|
|
||||||
return ticksRunning;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +1,37 @@
|
|||||||
package io.github.skippyall.minions.program.statement;
|
package io.github.skippyall.minions.program.statement;
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StatementList {
|
public class StatementList {
|
||||||
private final List<Statement<?,?>> statements;
|
private final List<Statement> statements;
|
||||||
|
private boolean finish;
|
||||||
|
|
||||||
public StatementList() {
|
StatementList() {
|
||||||
this.statements = List.of();
|
this(new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public StatementList(List<Statement<?,?>> statements) {
|
StatementList(List<Statement> statements) {
|
||||||
this.statements = List.copyOf(statements);
|
this.statements = statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Run start(ProgramRuntime runtime) {
|
public void runNext(Run run) {
|
||||||
return new Run(runtime);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canRunNext(Run run) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFinish(Run run) {
|
||||||
|
return finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Run createRunInstance() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Run {
|
public class Run {
|
||||||
final ProgramRuntime runtime;
|
|
||||||
final Iterator<Statement<?,?>> iterator;
|
|
||||||
Statement<?,?>.Run run;
|
|
||||||
|
|
||||||
public Run(ProgramRuntime runtime) {
|
|
||||||
this.runtime = runtime;
|
|
||||||
iterator = statements.iterator();
|
|
||||||
startNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean startNext() {
|
|
||||||
if(iterator.hasNext()) {
|
|
||||||
run = iterator.next().start(runtime);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick() {
|
|
||||||
run.tick();
|
|
||||||
if(run.isDone()){
|
|
||||||
startNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.tuple;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface Tuple extends Iterable<Object>{
|
|
||||||
<T> Tuple add(T value);
|
|
||||||
Tuple removeLast();
|
|
||||||
List<Object> getValueList();
|
|
||||||
int size();
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
default Iterator<Object> iterator() {
|
|
||||||
return getValueList().iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Tuple ofList(List<?> list) {
|
|
||||||
return switch (list.size()) {
|
|
||||||
case 0 -> new Tuple0();
|
|
||||||
case 1 -> new Tuple1<Object>(list.get(0));
|
|
||||||
case 2 -> new Tuple2<Object, Object>(list.get(0), list.get(1));
|
|
||||||
case 3 -> new Tuple3<Object, Object, Object>(list.get(0), list.get(1), list.get(2));
|
|
||||||
default -> throw new UnsupportedOperationException();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.tuple;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public record Tuple0() implements Tuple{
|
|
||||||
@Override
|
|
||||||
public <T> Tuple add(T value) {
|
|
||||||
return new Tuple1<>(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tuple removeLast() {
|
|
||||||
throw new UnsupportedOperationException("Cannot remove element from length 0 tuple.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Object> getValueList() {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.tuple;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public record Tuple1<T0>(T0 v0) implements Tuple{
|
|
||||||
@Override
|
|
||||||
public <T> Tuple add(T value) {
|
|
||||||
return new Tuple2<>(v0, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tuple removeLast() {
|
|
||||||
return new Tuple0();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Object> getValueList() {
|
|
||||||
return List.of(v0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.tuple;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public record Tuple2<T0, T1>(T0 v0, T1 v1) implements Tuple {
|
|
||||||
@Override
|
|
||||||
public <T> Tuple add(T value) {
|
|
||||||
return new Tuple3<>(v0, v1, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tuple removeLast() {
|
|
||||||
return new Tuple1<>(v0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Object> getValueList() {
|
|
||||||
return List.of(v0, v1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.tuple;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public record Tuple3<T0, T1, T2>(T0 v0, T1 v1, T2 v2) implements Tuple {
|
|
||||||
@Override
|
|
||||||
public <T> Tuple add(T value) {
|
|
||||||
return new Tuple4<>(v0, v1, v2, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tuple removeLast() {
|
|
||||||
return new Tuple2<>(v0, v1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Object> getValueList() {
|
|
||||||
return List.of(v0, v1, v2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.tuple;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public record Tuple4<T0, T1, T2, T3, T4>(T0 v0, T1 v1, T2 v2, T3 v3) implements Tuple {
|
|
||||||
@Override
|
|
||||||
public <T> Tuple add(T value) {
|
|
||||||
return new Tuple5<>(v0, v1, v2, v3, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tuple removeLast() {
|
|
||||||
return new Tuple3<>(v0, v1, v2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Object> getValueList() {
|
|
||||||
return List.of(v0, v1, v2, v3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.tuple;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public record Tuple5<T0, T1, T2, T3, T4>(T0 v0, T1 v1, T2 v2, T3 v3, T4 v4) implements Tuple {
|
|
||||||
@Override
|
|
||||||
public <T> Tuple add(T value) {
|
|
||||||
throw new UnsupportedOperationException("Cannot add element to length 5 tuple.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tuple removeLast() {
|
|
||||||
return new Tuple4<>(v0, v1, v2, v3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Object> getValueList() {
|
|
||||||
return List.of(v0, v1, v2, v3, v4);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.github.skippyall.minions.program.variables;
|
package io.github.skippyall.minions.program.variables;
|
||||||
|
|
||||||
public class FloatType extends Type<Float>{
|
public class FloatType extends Type{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.github.skippyall.minions.program.variables;
|
package io.github.skippyall.minions.program.variables;
|
||||||
|
|
||||||
public class IntegerType extends Type<Integer>{
|
public class IntegerType extends Type{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
package io.github.skippyall.minions.program.variables;
|
package io.github.skippyall.minions.program.variables;
|
||||||
|
|
||||||
public abstract class Type<T> {
|
public abstract class Type {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public T cast(Object object) throws ClassCastException {
|
|
||||||
return (T) object;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ package io.github.skippyall.minions.program.variables;
|
|||||||
public class Types {
|
public class Types {
|
||||||
public static final IntegerType INTEGER = new IntegerType();
|
public static final IntegerType INTEGER = new IntegerType();
|
||||||
public static final FloatType FLOAT = new FloatType();
|
public static final FloatType FLOAT = new FloatType();
|
||||||
public static final Type<Void> VOID = new Type<>() {};
|
public static final Type VOID = new Type() {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.github.skippyall.minions.program.variables;
|
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
|
||||||
|
|
||||||
public interface ValueStorage<T> {
|
|
||||||
void storeValue(T value, ProgramRuntime runtime);
|
|
||||||
}
|
|
||||||
@@ -1,29 +1,24 @@
|
|||||||
package io.github.skippyall.minions.program.variables;
|
package io.github.skippyall.minions.program.variables;
|
||||||
|
|
||||||
import io.github.skippyall.minions.program.argument.Arg;
|
import io.github.skippyall.minions.program.statement.Arg;
|
||||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
|
||||||
|
|
||||||
public class Variable<T> implements Arg<T>, ValueStorage<T> {
|
public class Variable implements Arg {
|
||||||
private final Type<T> type;
|
private final Type type;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private Object value;
|
||||||
|
|
||||||
public Variable(Type<T> type, String name) {
|
public Variable(Type type, String name) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T resolve(ProgramRuntime runtime) {
|
public Object getValue() {
|
||||||
return type.cast(runtime.getVariable(name));
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type<T> getType() {
|
public Type getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void storeValue(T value, ProgramRuntime runtime) {
|
|
||||||
runtime.setVariable(name, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.github.skippyall.minions.server;
|
||||||
|
|
||||||
|
import io.github.skippyall.minions.networking.ClientToServerNetworking;
|
||||||
|
import io.github.skippyall.minions.networking.VersionChecker;
|
||||||
|
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.network.ServerConfigurationNetworkHandler;
|
||||||
|
|
||||||
|
public class MinionsServer implements DedicatedServerModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitializeServer() {
|
||||||
|
ServerConfigurationNetworking.registerGlobalReceiver(ClientToServerNetworking.RL, ClientToServerNetworking::receive);
|
||||||
|
ServerConfigurationConnectionEvents.CONFIGURE.register(new ServerConfigurationConnectionEvents.Configure() {
|
||||||
|
@Override
|
||||||
|
public void onSendConfiguration(ServerConfigurationNetworkHandler handler, MinecraftServer server) {
|
||||||
|
VersionChecker.resetPlayer(handler.getDebugProfile().getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"minions.gui.main.commands": "Commands",
|
|
||||||
"minions.gui.main.programming": "Programming",
|
|
||||||
"minions.gui.main.modules": "Modules",
|
|
||||||
"minions.gui.main.inventory": "Inventory",
|
|
||||||
"minions.gui.inventory.title": "%s's Inventory",
|
|
||||||
"minions.gui.module_commands.title": "Commands",
|
|
||||||
"minions.gui.commands.title": "%s's Commands",
|
|
||||||
"minions.gui.modules.title": "%s's Modules",
|
|
||||||
|
|
||||||
"minions.command.input.int.fail": "Not an integer",
|
|
||||||
"minions.command.input.float.fail": "Not a number",
|
|
||||||
"minions.command.action.details": "Set how to %s",
|
|
||||||
"minions.command.action.once": "%s once",
|
|
||||||
"minions.command.action.continuous": "%s continuously",
|
|
||||||
"minions.command.action.interval": "%s every x seconds",
|
|
||||||
"minions.command.action.stop": "Stop %s",
|
|
||||||
"minions.command.action.interval.enter": "Enter an interval in seconds",
|
|
||||||
"minions.command.interact.name": "Interact",
|
|
||||||
"minions.command.interact.description": "Use and place blocks",
|
|
||||||
"minions.command.attack.name": "Attack",
|
|
||||||
"minions.command.attack.description": "Attack and mine blocks",
|
|
||||||
|
|
||||||
"item.minions.attack_module": "Attack Module",
|
|
||||||
"item.minions.interact_module": "Interact Module",
|
|
||||||
"item.minions.mob_spawning_module": "Mob Spawning Module",
|
|
||||||
"item.minions.mount_module": "Mount Module",
|
|
||||||
"item.minions.move_module": "Move Module",
|
|
||||||
"item.minions.minion": "Minion",
|
|
||||||
"item.minions.basic_upgrade_base": "Basic Upgrade Base",
|
|
||||||
"item.minions.advanced_upgrade_base": "Advanced Upgrade Base",
|
|
||||||
|
|
||||||
"minions.minion_item.tooltip": "Name: %s"
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:crafting_shaped",
|
|
||||||
"pattern": [
|
|
||||||
"DND",
|
|
||||||
"NBN",
|
|
||||||
"DND"
|
|
||||||
],
|
|
||||||
"key": {
|
|
||||||
"D": "minecraft:diamond",
|
|
||||||
"N": "minecraft:netherite_scrap",
|
|
||||||
"B": "minions:basic_upgrade_base"
|
|
||||||
},
|
|
||||||
"result": {
|
|
||||||
"id": "minions:advanced_upgrade_base",
|
|
||||||
"count": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:smithing_transform",
|
|
||||||
"base": "minions:advanced_upgrade_base",
|
|
||||||
"addition": "minecraft:diamond_pickaxe",
|
|
||||||
"template": "minecraft:netherite_upgrade_smithing_template",
|
|
||||||
"result": {
|
|
||||||
"id": "minions:attack_module"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:crafting_shaped",
|
|
||||||
"pattern": [
|
|
||||||
"RGR",
|
|
||||||
"GDG",
|
|
||||||
"RGR"
|
|
||||||
],
|
|
||||||
"key": {
|
|
||||||
"R": "minecraft:redstone_block",
|
|
||||||
"G": "minecraft:gold_ingot",
|
|
||||||
"D": "minecraft:diamond"
|
|
||||||
},
|
|
||||||
"result": {
|
|
||||||
"id": "minions:basic_upgrade_base",
|
|
||||||
"count": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:smithing_transform",
|
|
||||||
"base": "minions:advanced_upgrade_base",
|
|
||||||
"addition": "minecraft:lever",
|
|
||||||
"template": "minecraft:netherite_upgrade_smithing_template",
|
|
||||||
"result": {
|
|
||||||
"id": "minions:interact_module"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:crafting_shaped",
|
|
||||||
"pattern": [
|
|
||||||
" H ",
|
|
||||||
"RAR",
|
|
||||||
" N "
|
|
||||||
],
|
|
||||||
"key": {
|
|
||||||
"H": "#minecraft:skulls",
|
|
||||||
"R": "minecraft:redstone_torch",
|
|
||||||
"A": "minecraft:armor_stand",
|
|
||||||
"N": "minecraft:netherite_ingot"
|
|
||||||
},
|
|
||||||
"result": {
|
|
||||||
"id": "minions:minion",
|
|
||||||
"count": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:smithing_transform",
|
|
||||||
"base": "minions:basic_upgrade_base",
|
|
||||||
"addition": "minecraft:rotten_flesh",
|
|
||||||
"template": "minecraft:netherite_upgrade_smithing_template",
|
|
||||||
"result": {
|
|
||||||
"id": "minions:mob_spawning_module"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:smithing_transform",
|
|
||||||
"base": "minions:basic_upgrade_base",
|
|
||||||
"addition": "minecraft:minecart",
|
|
||||||
"template": "minecraft:netherite_upgrade_smithing_template",
|
|
||||||
"result": {
|
|
||||||
"id": "minions:mount_module"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:smithing_transform",
|
|
||||||
"base": "minions:basic_upgrade_base",
|
|
||||||
"addition": "minecraft:iron_boots",
|
|
||||||
"template": "minecraft:netherite_upgrade_smithing_template",
|
|
||||||
"result": {
|
|
||||||
"id": "minions:move_module"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"values": [
|
|
||||||
"#minecraft:is_fire",
|
|
||||||
"#minecraft:is_explosion"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -12,18 +12,22 @@
|
|||||||
"icon": "assets/minions/icon.png",
|
"icon": "assets/minions/icon.png",
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
|
"client": [
|
||||||
|
"io.github.skippyall.minions.client.MinionsClient"
|
||||||
|
],
|
||||||
"main": [
|
"main": [
|
||||||
"io.github.skippyall.minions.Minions"
|
"io.github.skippyall.minions.Minions"
|
||||||
|
],
|
||||||
|
"server": [
|
||||||
|
"io.github.skippyall.minions.server.MinionsServer"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"minions.mixins.json"
|
"minions.mixins.json"
|
||||||
],
|
],
|
||||||
"accessWidener" : "minions.accesswidener",
|
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": "*",
|
"fabricloader": ">=${loader_version}",
|
||||||
"fabric": "*",
|
"fabric": "*",
|
||||||
"minecraft": "~1.21.3",
|
"minecraft": "${minecraft_version}"
|
||||||
"polymer-core": "*"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user