Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ea5411450c | |||
| f533ae8515 | |||
| d84190ee3c | |||
| ac4f58b9a2 |
+2
-2
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.5-SNAPSHOT'
|
||||
id 'fabric-loom' version '1.6-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ processResources {
|
||||
}
|
||||
}
|
||||
|
||||
def targetJavaVersion = 17
|
||||
def targetJavaVersion = 21
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
// 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
|
||||
|
||||
+6
-6
@@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.20.4
|
||||
loader_version=0.15.6
|
||||
yarn_mappings=1.20.4+build.3
|
||||
minecraft_version=1.21.1
|
||||
loader_version=0.16.3
|
||||
yarn_mappings=1.21.1+build.3
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.0.1
|
||||
@@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Dependencies
|
||||
# check this on https://modmuss50.me/fabric.html
|
||||
fabric_version=0.95.4+1.20.4
|
||||
fabric_version=0.103.0+1.21.1
|
||||
|
||||
polymer_version=0.7.5+1.20.4
|
||||
sgui_version=1.4.1+1.20.4
|
||||
polymer_version=0.9.12+1.21.1
|
||||
sgui_version=1.6.0+1.21
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
|
||||
@@ -1,21 +1,58 @@
|
||||
package io.github.skippyall.minions;
|
||||
|
||||
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.minion.MinionItem;
|
||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Minions implements ModInitializer {
|
||||
public static final String MOD_ID = "minions";
|
||||
public static final MinionItem MINION_ITEM = Registry.register(Registries.ITEM, new Identifier(MOD_ID, "minion"), new MinionItem());
|
||||
public static final MinionItem MINION_ITEM = Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "minion"), new MinionItem(false));
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
private static final List<Runnable> executeOnNextTick = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
LOGGER.debug("Add Customthing");
|
||||
PolymerEntityUtils.registerType();
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||
MinionPersistentState.create(server);
|
||||
MinionPersistentState.INSTANCE.getMinionData().forEach(data -> {
|
||||
System.out.println("spawn Minion " + data.name);
|
||||
MinionFakePlayer.spawnMinion(data, server.getOverworld());
|
||||
});
|
||||
});
|
||||
ServerTickEvents.START_SERVER_TICK.register(server -> {
|
||||
exec(() -> {
|
||||
for (Runnable run:executeOnNextTick) {
|
||||
run.run();
|
||||
}
|
||||
executeOnNextTick.clear();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static synchronized void exec(Runnable run) {
|
||||
run.run();
|
||||
}
|
||||
|
||||
public static void addExecuteOnNextTick(Runnable run) {
|
||||
exec(() -> {
|
||||
executeOnNextTick.add(run);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,6 @@ public class MinionsClient implements ClientModInitializer {
|
||||
*/
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ClientConfigurationConnectionEvents.INIT.register(ClientToServerNetworking::onConfigurationInit);
|
||||
//ClientConfigurationConnectionEvents.INIT.register(ClientToServerNetworking::onConfigurationInit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.skippyall.minions.fakeplayer;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.NetworkState;
|
||||
import net.minecraft.network.listener.PacketListener;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
@@ -22,7 +23,6 @@ public class FakeClientConnection extends ClientConnection {
|
||||
|
||||
@Override
|
||||
public void handleDisconnection() {
|
||||
getPacketListener().onDisconnected(getDisconnectReason()==null ? Text.literal("Disconnected"): getDisconnectReason());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,7 +31,6 @@ public class FakeClientConnection extends ClientConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPacketListener(PacketListener packetListener) {
|
||||
|
||||
public <T extends PacketListener> void transitionInbound(NetworkState<T> state, T packetListener) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,26 @@ package io.github.skippyall.minions.fakeplayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.yggdrasil.ProfileResult;
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import io.github.skippyall.minions.minion.MinionInventory;
|
||||
import io.github.skippyall.minions.minion.MinionItem;
|
||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||
import io.github.skippyall.minions.minion.ModuleInventory;
|
||||
import net.fabricmc.fabric.api.entity.FakePlayer;
|
||||
import io.github.skippyall.minions.mixins.GameProfileMixin;
|
||||
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.component.ComponentType;
|
||||
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;
|
||||
@@ -28,10 +37,12 @@ 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 net.minecraft.world.TeleportTarget;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
@@ -42,38 +53,119 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
private float moveSideways;
|
||||
|
||||
private boolean programmable;
|
||||
private ModuleInventory moduleInventory = new ModuleInventory();
|
||||
private final ModuleInventory moduleInventory = new ModuleInventory();
|
||||
private final MinionRuntime runtime = new MinionRuntime(this);
|
||||
|
||||
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) -> {
|
||||
try {
|
||||
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(new UUID(0,0), username);
|
||||
}
|
||||
GameProfile newProfile = new GameProfile(UUID.randomUUID(), username);
|
||||
newProfile.getProperties().putAll(profile.getProperties());
|
||||
GameProfile finalProfile = newProfile;
|
||||
((GameProfileMixin)finalProfile).setId(UUID.randomUUID());
|
||||
Minions.addExecuteOnNextTick(() -> {
|
||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, finalProfile, 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(finalProfile, 0, instance.getClientOptions(), false));
|
||||
instance.teleport(level, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
||||
instance.setHealth(20.0F);
|
||||
instance.unsetRemoved();
|
||||
instance.getAttributeInstance(EntityAttributes.GENERIC_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(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;
|
||||
MinionPersistentState.INSTANCE.addMinion(instance);
|
||||
});
|
||||
}catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void spawnMinion(MinionPersistentState.MinionData data, ServerWorld level) {
|
||||
MinecraftServer server = level.getServer();
|
||||
server.getUserCache().findByNameAsync(data.name).thenAcceptAsync((optional) -> {
|
||||
GameProfile profile = null;
|
||||
if(optional.isPresent()){
|
||||
UUID uuid = optional.get().getId();
|
||||
ProfileResult result = server.getSessionService().fetchProfile(uuid, true);
|
||||
if(result != null) {
|
||||
if (optional.isPresent()) {
|
||||
ProfileResult result = server.getSessionService().fetchProfile(optional.get().getId(), true);
|
||||
if (result != null) {
|
||||
profile = result.profile();
|
||||
}
|
||||
}
|
||||
if(profile == null) {
|
||||
profile = new GameProfile(Uuids.getOfflinePlayerUuid(username), username);
|
||||
if (profile == null) {
|
||||
profile = new GameProfile(new UUID(0, 0), data.name);
|
||||
}
|
||||
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);
|
||||
GameProfile newProfile = new GameProfile(data.uuid, data.name);
|
||||
newProfile.getProperties().putAll(profile.getProperties());
|
||||
GameProfile finalProfile = newProfile;
|
||||
((GameProfileMixin)finalProfile).setId(data.uuid);
|
||||
Minions.addExecuteOnNextTick(() -> {
|
||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, finalProfile, SyncedClientOptions.createDefault(), false, data.programmable);
|
||||
System.out.println(instance.getPos());
|
||||
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance, new ConnectedClientData(finalProfile, 0, instance.getClientOptions(), false));
|
||||
System.out.println(instance.getPos());
|
||||
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;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void spawnMinionAt(MinionPersistentState.MinionData data, ServerWorld level, Vec3d pos, double yaw, double pitch) {
|
||||
MinecraftServer server = level.getServer();
|
||||
server.getUserCache().findByNameAsync(data.name).thenAcceptAsync((optional) -> {
|
||||
GameProfile profile = null;
|
||||
if (optional.isPresent()) {
|
||||
ProfileResult result = server.getSessionService().fetchProfile(optional.get().getId(), true);
|
||||
if (result != null) {
|
||||
profile = result.profile();
|
||||
}
|
||||
}
|
||||
if (profile == null) {
|
||||
profile = new GameProfile(new UUID(0, 0), data.name);
|
||||
}
|
||||
GameProfile newProfile = new GameProfile(data.uuid, data.name);
|
||||
newProfile.getProperties().putAll(profile.getProperties());
|
||||
GameProfile finalProfile = newProfile;
|
||||
((GameProfileMixin)finalProfile).setId(data.uuid);
|
||||
Minions.addExecuteOnNextTick(() -> {
|
||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, finalProfile, SyncedClientOptions.createDefault(), false, data.programmable);
|
||||
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
||||
System.out.println(instance.getPos());
|
||||
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance, new ConnectedClientData(finalProfile, 0, instance.getClientOptions(), false));
|
||||
System.out.println(instance.getPos());
|
||||
instance.teleport(level, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
||||
instance.setVelocity(0,0,0);
|
||||
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;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused") //Don't know if I'll need this
|
||||
@@ -85,7 +177,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
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()));
|
||||
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), playerShadow, new ConnectedClientData(gameprofile, 0, player.getClientOptions(), false));
|
||||
|
||||
playerShadow.setHealth(player.getHealth());
|
||||
playerShadow.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
|
||||
@@ -110,7 +202,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
{
|
||||
super(server, worldIn, profile, cli);
|
||||
isAShadow = shadow;
|
||||
|
||||
this.programmable = programmable;
|
||||
}
|
||||
|
||||
public boolean isProgrammable() {
|
||||
@@ -121,7 +213,11 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
return moduleInventory;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack getActionPack() {
|
||||
public MinionRuntime getRuntime() {
|
||||
return runtime;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack getMinionActionPack() {
|
||||
return ((ServerPlayerInterface)this).getActionPack();
|
||||
}
|
||||
|
||||
@@ -144,23 +240,25 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@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);
|
||||
this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
|
||||
} else {
|
||||
this.server.send(new ServerTask(this.server.getTicks(), () -> {
|
||||
this.networkHandler.onDisconnected(reason);
|
||||
this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
|
||||
}));
|
||||
}
|
||||
|
||||
MinionPersistentState.INSTANCE.removeMinion(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,7 +279,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
// happens with that paper port thingy - not sure what that would fix, but hey
|
||||
// the game not gonna crash violently.
|
||||
}
|
||||
|
||||
runtime.tick();
|
||||
|
||||
}
|
||||
|
||||
@@ -221,9 +319,9 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity moveToWorld(ServerWorld serverLevel)
|
||||
public Entity teleportTo(TeleportTarget target)
|
||||
{
|
||||
super.moveToWorld(serverLevel);
|
||||
super.teleportTo(target);
|
||||
if (notInAnyWorld) {
|
||||
ClientStatusC2SPacket p = new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.PERFORM_RESPAWN);
|
||||
networkHandler.onClientStatus(p);
|
||||
@@ -239,7 +337,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
|
||||
public void moveForward(float forward) {
|
||||
this.moveForward += forward;
|
||||
EntityPlayerActionPack actionPack = getActionPack();
|
||||
EntityPlayerActionPack actionPack = getMinionActionPack();
|
||||
if (moveForward != 0) {
|
||||
actionPack.setForward(moveForward > 0 ? 1 : -1);
|
||||
}
|
||||
@@ -247,7 +345,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
|
||||
public void moveSideways(float sideways) {
|
||||
this.moveSideways += sideways;
|
||||
EntityPlayerActionPack actionPack = getActionPack();
|
||||
EntityPlayerActionPack actionPack = getMinionActionPack();
|
||||
if (moveSideways != 0) {
|
||||
actionPack.setStrafing(moveSideways > 0 ? 1 : -1);
|
||||
}
|
||||
@@ -258,20 +356,55 @@ public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
float newForward = (float) (moveForward - movement.z);
|
||||
float newSideways = (float) (moveSideways - movement.x);
|
||||
Vec3d newMovement = movement;
|
||||
if ((newForward < 0 && moveForward >= 0) || (newForward > 0 && moveForward <= 0)) {
|
||||
if ((newForward < 0 && moveForward > 0) || (newForward > 0 && moveForward < 0)) {
|
||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveForward);
|
||||
moveForward = 0;
|
||||
getActionPack().setForward(0);
|
||||
getMinionActionPack().setForward(0);
|
||||
}else {
|
||||
moveForward = newForward;
|
||||
}
|
||||
if ((newSideways < 0 && moveSideways >= 0) || (newSideways > 0 && moveSideways <= 0)) {
|
||||
if ((newSideways < 0 && moveSideways > 0) || (newSideways > 0 && moveSideways < 0)) {
|
||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveSideways);
|
||||
moveSideways = 0;
|
||||
getActionPack().setStrafing(0);
|
||||
getMinionActionPack().setStrafing(0);
|
||||
}else {
|
||||
moveSideways = newSideways;
|
||||
}
|
||||
super.move(movementType, newMovement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drop(ServerWorld world, DamageSource damageSource) {
|
||||
super.drop(world, damageSource);
|
||||
dropItem(toItemStack(), true, false);
|
||||
for(ItemStack item : moduleInventory.getItems()) {
|
||||
dropItem(item, true, false);
|
||||
}
|
||||
moduleInventory.clear();
|
||||
}
|
||||
|
||||
private ItemStack toItemStack() {
|
||||
ItemStack stack = new ItemStack(Minions.MINION_ITEM);
|
||||
MinionItem.setData(MinionPersistentState.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()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomDataFromNbt(NbtCompound nbt) {
|
||||
super.readCustomDataFromNbt(nbt);
|
||||
moduleInventory.readNbt(nbt.getCompound("modules"), getRegistryManager());
|
||||
}
|
||||
|
||||
public String getMinionName() {
|
||||
return getGameProfile().getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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.ScreenHandlerType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class CommandsInventory {
|
||||
public static void openServerCommandsInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||
|
||||
gui.setSlot(0, new GuiElementBuilder()
|
||||
.setItem(Items.MINECART)
|
||||
.setName(Text.literal("Get into minecart"))
|
||||
.setCallback(() -> {
|
||||
minion.getMinionActionPack().mount(true);
|
||||
})
|
||||
);
|
||||
|
||||
gui.open();
|
||||
}
|
||||
}
|
||||
@@ -19,30 +19,44 @@ public class MinionInventory {
|
||||
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(1, new GuiElementBuilder()
|
||||
.setItem(Items.COMMAND_BLOCK)
|
||||
.setName(Text.literal("Commands"))
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openCommandsGui(player, minion);
|
||||
})
|
||||
);
|
||||
if(minion.isProgrammable()) {
|
||||
gui.setSlot(4, new GuiElementBuilder()
|
||||
.setItem(Items.REDSTONE)
|
||||
.setName(Text.literal("Programming"))
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openProgrammingInventory(player, minion);
|
||||
})
|
||||
);
|
||||
}
|
||||
gui.setSlot(3, new GuiElementBuilder()
|
||||
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
||||
.setName(Text.literal("Modules and Detectors"))
|
||||
.setCallback((i, clickType, clickType1) -> {
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openModuleInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.setSlot(5, new GuiElementBuilder()
|
||||
.setItem(Items.CHEST)
|
||||
.setName(Text.literal("Inventory"))
|
||||
.setCallback((i, clickType, clickType1) -> {
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openMinionInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.open();
|
||||
}
|
||||
|
||||
public static void openCommandsGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
CommandsInventory.openServerCommandsInventory(player, minion);
|
||||
}
|
||||
|
||||
public static void openProgrammingInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,22 +3,25 @@ package io.github.skippyall.minions.minion;
|
||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.client.render.VertexFormatElement;
|
||||
import net.minecraft.component.ComponentType;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.NbtComponent;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.item.tooltip.TooltipType;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.PlainTextContent;
|
||||
import net.minecraft.text.TextContent;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MinionItem extends Item implements PolymerItem {
|
||||
private boolean canProgram;
|
||||
private final boolean canProgram;
|
||||
public MinionItem(boolean canProgram) {
|
||||
super(new FabricItemSettings());
|
||||
super(new Item.Settings());
|
||||
this.canProgram = canProgram;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,9 +30,9 @@ public class MinionItem extends Item implements PolymerItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPolymerItemStack(ItemStack stack, TooltipContext flag, ServerPlayerEntity player) {
|
||||
ItemStack out = PolymerItemUtils.createItemStack(stack, flag, player);
|
||||
out.addEnchantment(Enchantments.MENDING, 1);
|
||||
public ItemStack getPolymerItemStack(ItemStack stack, TooltipType tooltipType, RegistryWrapper.WrapperLookup lookup, ServerPlayerEntity player) {
|
||||
ItemStack out = PolymerItemUtils.createItemStack(stack, lookup, player);
|
||||
out.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -43,8 +46,37 @@ public class MinionItem extends Item implements PolymerItem {
|
||||
name = "Minion";
|
||||
}
|
||||
if(!context.getWorld().isClient) {
|
||||
MinionFakePlayer.createMinion(name, (ServerWorld) context.getWorld(), (ServerPlayerEntity) context.getPlayer(), canProgram, context.getBlockPos().toCenterPos().add(0,0.5,0), 0, 0);
|
||||
MinionPersistentState.MinionData data = getData(context.getStack());
|
||||
if (data == null) {
|
||||
MinionFakePlayer.createMinion(name, (ServerWorld) context.getWorld(), (ServerPlayerEntity) context.getPlayer(), canProgram, context.getBlockPos().toCenterPos().add(0,0.5,0), 0, 0);
|
||||
}else {
|
||||
MinionFakePlayer.spawnMinionAt(data, (ServerWorld) context.getWorld(), context.getBlockPos().toCenterPos().add(0,0.5,0), 0, 0);
|
||||
MinionPersistentState.INSTANCE.addMinion(data);
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
public static void setData(MinionPersistentState.MinionData data, ItemStack item) {
|
||||
NbtCompound nbt = item.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).copyNbt();
|
||||
nbt.put("data", data.writeNbt());
|
||||
item.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MinionPersistentState.MinionData getData(ItemStack item) {
|
||||
NbtCompound nbt = item.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).copyNbt();
|
||||
if (nbt.getType("data") == NbtElement.COMPOUND_TYPE) {
|
||||
return MinionPersistentState.MinionData.readNbt(nbt.getCompound("data"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean containsData(ItemStack item) {
|
||||
NbtComponent nbt = item.get(DataComponentTypes.CUSTOM_DATA);
|
||||
if (nbt == null) {
|
||||
return false;
|
||||
}
|
||||
return nbt.copyNbt().contains("data");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.nbt.*;
|
||||
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 List<MinionData> minionData = 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);
|
||||
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));
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
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 static void create(MinecraftServer server) {
|
||||
INSTANCE = server.getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TYPE, "minion");
|
||||
}
|
||||
|
||||
public static class MinionData {
|
||||
public UUID uuid;
|
||||
public String name;
|
||||
public boolean programmable;
|
||||
|
||||
public MinionData(UUID uuid, String name, boolean programmable) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.programmable = programmable;
|
||||
}
|
||||
|
||||
public NbtCompound writeNbt() {
|
||||
NbtCompound nbt = new NbtCompound();
|
||||
|
||||
/*NbtList posList = new NbtList();
|
||||
posList.add(NbtDouble.of(pos.getX()));
|
||||
posList.add(NbtDouble.of(pos.getY()));
|
||||
posList.add(NbtDouble.of(pos.getZ()));
|
||||
nbt.put("pos", posList);
|
||||
|
||||
NbtList rotList = new NbtList();
|
||||
rotList.add(NbtFloat.of(rot.x));
|
||||
rotList.add(NbtFloat.of(rot.y));
|
||||
nbt.put("rotation", rotList);*/
|
||||
|
||||
nbt.putUuid("uuid", uuid);
|
||||
nbt.putString("name", name);
|
||||
nbt.putBoolean("programmable", programmable);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public static MinionData readNbt(NbtCompound nbt) {
|
||||
/*NbtList posList = nbt.getList("pos", NbtElement.DOUBLE_TYPE);
|
||||
double x = posList.getDouble(0);
|
||||
double y = posList.getDouble(1);
|
||||
double z = posList.getDouble(2);
|
||||
Vec3d pos = new Vec3d(x, y, z);
|
||||
|
||||
NbtList rotList = nbt.getList("rotation", NbtElement.FLOAT_TYPE);
|
||||
float yaw = rotList.getFloat(0);
|
||||
float pitch = rotList.getFloat(1);
|
||||
Vec2f rot = new Vec2f(yaw, pitch);*/
|
||||
|
||||
UUID uuid = nbt.getUuid("uuid");
|
||||
String name = nbt.getString("name");
|
||||
boolean programmable = nbt.getBoolean("programmable");
|
||||
|
||||
return new MinionData(uuid, name, programmable);
|
||||
}
|
||||
|
||||
public static MinionData fromMinion(MinionFakePlayer minion) {
|
||||
return new MinionData(minion.getUuid(), minion.getMinionName(), minion.isProgrammable());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,13 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
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 static final TagKey<Item> MODULES = TagKey.of(RegistryKeys.ITEM, Identifier.of(Minions.MOD_ID,"modules"));
|
||||
private DefaultedList<ItemStack> stacks = DefaultedList.ofSize(27, ItemStack.EMPTY);
|
||||
|
||||
public ModuleInventory() {
|
||||
@@ -32,11 +33,11 @@ public class ModuleInventory implements ImplementedInventory {
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public void readNbt(NbtCompound nbt) {
|
||||
Inventories.readNbt(nbt, stacks);
|
||||
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
||||
Inventories.readNbt(nbt, stacks, lookup);
|
||||
}
|
||||
|
||||
public void writeNbt(NbtCompound nbt) {
|
||||
Inventories.writeNbt(nbt, stacks);
|
||||
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
||||
return Inventories.writeNbt(nbt, stacks, lookup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
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, remap = false)
|
||||
public class ChunkTicketManagerFixMixin {
|
||||
@WrapOperation(method = "handleChunkLeave", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectSet;remove(Ljava/lang/Object;)Z"))
|
||||
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"))
|
||||
public boolean filterIfNull(ObjectSet instance, Operation<Boolean> original) {
|
||||
if (instance != null) {
|
||||
return original.call(instance);
|
||||
}
|
||||
|
||||
return true;//Unused
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.skippyall.minions.mixins;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.world.PlayerSaveHandler;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(PlayerSaveHandler.class)
|
||||
public class Debug2Mixin {
|
||||
@Inject(method = "method_55788", at = @At("HEAD"))
|
||||
public void debug(PlayerEntity playerEntity, NbtCompound nbt, CallbackInfoReturnable<NbtCompound> cir) {
|
||||
System.out.println("loadPlayerData " + playerEntity.getNameForScoreboard());
|
||||
}
|
||||
|
||||
@Inject(method = "loadPlayerData(Lnet/minecraft/entity/player/PlayerEntity;Ljava/lang/String;)Ljava/util/Optional;", at = @At("RETURN"))
|
||||
public void debug(PlayerEntity player, String extension, CallbackInfoReturnable<Optional<NbtCompound>> cir) {
|
||||
System.out.println(cir.getReturnValue().isEmpty() + player.getUuidAsString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.skippyall.minions.mixins;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
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(SectionedEntityCache.class)
|
||||
@Mixin(Entity.class)
|
||||
public class DebugMixin {
|
||||
/*@Inject(method = "forEachInBox", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/ChunkSectionPos;asLong(III)J", shift = At.Shift.BEFORE, ordinal = 0))
|
||||
private void debug(Box box, LazyIterationConsumer<EntityTrackingSection<?>> consumer, CallbackInfo ci) {
|
||||
System.out.println("call");
|
||||
}*/
|
||||
@Inject(method = "readNbt", at = @At("HEAD"))
|
||||
public void debug(NbtCompound nbt, CallbackInfo ci) {
|
||||
if ((Object) this instanceof MinionFakePlayer) {
|
||||
System.out.println("readNBT");
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "setPos", at = @At("HEAD"))
|
||||
public void debug(double x, double y, double z, CallbackInfo ci) {
|
||||
if ((Object) this instanceof MinionFakePlayer) {
|
||||
System.out.println("Set Minion Pos to " + x + " " + y + " " + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.github.skippyall.minions.mixins;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(value = GameProfile.class, remap = false)
|
||||
public interface GameProfileMixin{
|
||||
@Mutable
|
||||
@Accessor("id")
|
||||
void setId(UUID id);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.github.skippyall.minions.mixins;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||
import io.github.skippyall.minions.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));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package io.github.skippyall.minions.mixins;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import io.github.skippyall.minions.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;Lnet/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;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.github.skippyall.minions.mixins;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.fakeplayer.NetHandlerPlayServerFake;
|
||||
@@ -14,6 +15,8 @@ import net.minecraft.server.network.ConnectedClientData;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import org.apache.logging.log4j.core.jmx.Server;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -50,4 +53,11 @@ public class PlayerListMixin {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ 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");
|
||||
/*public static final Identifier RL = Identifier.of(Minions.MOD_ID, "network");
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static void sendJoinPacket(PlayerEntity player) {
|
||||
PacketByteBuf pbf = new PacketByteBuf(Unpooled.buffer());
|
||||
@@ -36,5 +36,5 @@ public class ClientToServerNetworking {
|
||||
}
|
||||
String[] parts = message.split("|");
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
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,23 +1,34 @@
|
||||
package io.github.skippyall.minions.program.block;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.statement.Arg;
|
||||
import io.github.skippyall.minions.program.argument.Arg;
|
||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
||||
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 java.util.List;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
public abstract class CodeBlock {
|
||||
public abstract class CodeBlock<R, A extends Tuple> {
|
||||
private String name;
|
||||
private final List<Type> arguments;
|
||||
private final Type returnType;
|
||||
public CodeBlock(String name, List<Type> arguments, Type returnType) {
|
||||
private final List<Type<?>> arguments;
|
||||
private final Type<?> returnType;
|
||||
|
||||
public CodeBlock(String name, List<Type<?>> arguments, Type<?> returnType) {
|
||||
this.arguments = arguments;
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
public abstract Object execute(MinionFakePlayer minion, Object... args);
|
||||
protected abstract R execute(ProgramRuntime runtime, A args, Statement<R,A>.Run run);
|
||||
|
||||
public boolean fits(Arg arg, int slot) {
|
||||
public boolean fits(Arg<?> arg, int slot) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,23 +3,26 @@ package io.github.skippyall.minions.program.block;
|
||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
||||
import io.github.skippyall.minions.program.variables.IntegerType;
|
||||
import io.github.skippyall.minions.program.variables.Type;
|
||||
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GoBlock extends CodeBlock{
|
||||
public class GoBlock extends CodeBlock<Void, Tuple2<Float, Float>> {
|
||||
public GoBlock() {
|
||||
super("move", List.of(Types.FLOAT, Types.FLOAT), Types.VOID);
|
||||
}
|
||||
|
||||
public Object execute(MinionFakePlayer minion, Object... args) {
|
||||
EntityPlayerActionPack action = ((ServerPlayerInterface)minion).getActionPack();
|
||||
minion.moveForward((Float) args[0]);
|
||||
minion.moveSideways((Float) args[1]);
|
||||
public Void execute(ProgramRuntime runtime, Tuple2<Float, Float> args, Statement<Void, Tuple2<Float, Float>>.Run run) {
|
||||
if(runtime instanceof MinionRuntime minionRuntime) {
|
||||
MinionFakePlayer minion = minionRuntime.getMinion();
|
||||
EntityPlayerActionPack action = ((ServerPlayerInterface) minion).getActionPack();
|
||||
minion.moveForward(args.v0());
|
||||
minion.moveSideways(args.v1());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,25 @@ package io.github.skippyall.minions.program.block;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
|
||||
import io.github.skippyall.minions.program.variables.Type;
|
||||
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
||||
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 java.util.List;
|
||||
|
||||
public class UseBlock extends CodeBlock{
|
||||
public UseBlock(String name, List<Type> arguments, Type returnType) {
|
||||
public class UseBlock extends CodeBlock<Void, Tuple0>{
|
||||
public UseBlock(String name) {
|
||||
super("use", List.of(), Types.VOID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(MinionFakePlayer minion, Object... args) {
|
||||
minion.getActionPack().start(EntityPlayerActionPack.ActionType.USE, EntityPlayerActionPack.Action.once());
|
||||
public Void execute(ProgramRuntime runtime, Tuple0 args, Statement<Void,Tuple0>.Run run) {
|
||||
if(runtime instanceof MinionRuntime minionRuntime) {
|
||||
MinionFakePlayer minion = minionRuntime.getMinion();
|
||||
minion.getMinionActionPack().start(EntityPlayerActionPack.ActionType.USE, EntityPlayerActionPack.Action.once());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ 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;
|
||||
@@ -10,7 +9,7 @@ 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));
|
||||
super(new Item.Settings().maxCount(1));
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -18,5 +17,5 @@ public abstract class Module extends Item implements PolymerItem {
|
||||
return name;
|
||||
}
|
||||
|
||||
public abstract List<CodeBlock> getCodeBlocks();
|
||||
public abstract List<CodeBlock<?,?>> getCodeBlocks();
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ public class MoveModule extends Module {
|
||||
super("Movement");
|
||||
}
|
||||
|
||||
public List<CodeBlock> getCodeBlocks() {
|
||||
List<CodeBlock> codeBlocks = new ArrayList<>();
|
||||
public List<CodeBlock<?,?>> getCodeBlocks() {
|
||||
List<CodeBlock<?,?>> codeBlocks = new ArrayList<>();
|
||||
codeBlocks.add(CodeBlocks.GO);
|
||||
return codeBlocks;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.github.skippyall.minions.program.runtime;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityCombatEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
|
||||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||
|
||||
public class MinionRuntime extends ProgramRuntime {
|
||||
private final MinionFakePlayer minion;
|
||||
|
||||
public MinionRuntime(MinionFakePlayer minion) {
|
||||
this.minion = minion;
|
||||
}
|
||||
|
||||
public MinionFakePlayer getMinion() {
|
||||
return minion;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package io.github.skippyall.minions.program.statement;
|
||||
|
||||
import io.github.skippyall.minions.program.variables.Type;
|
||||
|
||||
public interface Arg {
|
||||
Object getValue();
|
||||
Type getType();
|
||||
}
|
||||
@@ -1,15 +1,73 @@
|
||||
package io.github.skippyall.minions.program.statement;
|
||||
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.argument.ArgUtils;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
public record Statement<R,A extends Tuple>(CodeBlock<R,A> codeBlock, A args, ValueStorage<R> valueStorage) {
|
||||
@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 Statement {
|
||||
private CodeBlock codeBlock;
|
||||
private List<Arg> args;
|
||||
public class Run {
|
||||
private boolean running = false;
|
||||
private boolean waiting = false;
|
||||
private boolean afterRun = false;
|
||||
private R cachedResult;
|
||||
private int ticksRunning = 0;
|
||||
private int ticksLeft = 0;
|
||||
|
||||
public void execute(MinionFakePlayer minion) {
|
||||
private final ProgramRuntime runtime;
|
||||
|
||||
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,37 +1,50 @@
|
||||
package io.github.skippyall.minions.program.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class StatementList {
|
||||
private final List<Statement> statements;
|
||||
private boolean finish;
|
||||
private final List<Statement<?,?>> statements;
|
||||
|
||||
StatementList() {
|
||||
this(new ArrayList<>());
|
||||
public StatementList() {
|
||||
this.statements = List.of();
|
||||
}
|
||||
|
||||
StatementList(List<Statement> statements) {
|
||||
this.statements = statements;
|
||||
public StatementList(List<Statement<?,?>> statements) {
|
||||
this.statements = List.copyOf(statements);
|
||||
}
|
||||
|
||||
public void runNext(Run run) {
|
||||
|
||||
}
|
||||
|
||||
public boolean canRunNext(Run run) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isFinish(Run run) {
|
||||
return finish;
|
||||
}
|
||||
|
||||
public Run createRunInstance() {
|
||||
return null;
|
||||
public Run start(ProgramRuntime runtime) {
|
||||
return new Run(runtime);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
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();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
|
||||
public class FloatType extends Type{
|
||||
public class FloatType extends Type<Float>{
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.github.skippyall.minions.program.variables;
|
||||
|
||||
public class IntegerType extends Type{
|
||||
public class IntegerType extends Type<Integer>{
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
package io.github.skippyall.minions.program.variables;
|
||||
|
||||
public abstract class Type {
|
||||
public abstract class Type<T> {
|
||||
@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 static final IntegerType INTEGER = new IntegerType();
|
||||
public static final FloatType FLOAT = new FloatType();
|
||||
public static final Type VOID = new Type() {};
|
||||
public static final Type<Void> VOID = new Type<>() {};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
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,24 +1,29 @@
|
||||
package io.github.skippyall.minions.program.variables;
|
||||
|
||||
import io.github.skippyall.minions.program.statement.Arg;
|
||||
import io.github.skippyall.minions.program.argument.Arg;
|
||||
import io.github.skippyall.minions.program.runtime.ProgramRuntime;
|
||||
|
||||
public class Variable implements Arg {
|
||||
private final Type type;
|
||||
public class Variable<T> implements Arg<T>, ValueStorage<T> {
|
||||
private final Type<T> type;
|
||||
private final String name;
|
||||
private Object value;
|
||||
|
||||
public Variable(Type type, String name) {
|
||||
public Variable(Type<T> type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
public T resolve(ProgramRuntime runtime) {
|
||||
return type.cast(runtime.getVariable(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
public Type<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeValue(T value, ProgramRuntime runtime) {
|
||||
runtime.setVariable(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,13 @@ import net.minecraft.server.network.ServerConfigurationNetworkHandler;
|
||||
public class MinionsServer implements DedicatedServerModInitializer {
|
||||
@Override
|
||||
public void onInitializeServer() {
|
||||
ServerConfigurationNetworking.registerGlobalReceiver(ClientToServerNetworking.RL, ClientToServerNetworking::receive);
|
||||
/*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());
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,16 @@
|
||||
"package": "io.github.skippyall.minions.mixins",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ChunkTicketManagerFixMixin",
|
||||
"ConnectionMixin",
|
||||
"Debug2Mixin",
|
||||
"DebugMixin",
|
||||
"GameProfileMixin",
|
||||
"MinecraftServerMixin",
|
||||
"PlayerListEntryS2CPacket$EntryMixin",
|
||||
"PlayerListMixin",
|
||||
"ServerPlayerMixin"
|
||||
"ServerPlayerMixin",
|
||||
"ServerPlayNetworkHandlerMixin"
|
||||
],
|
||||
"client": [],
|
||||
"server": [],
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user