3 Commits

Author SHA1 Message Date
skippyall 66cbad38cb Fixes 2025-07-06 12:49:16 +02:00
skippyall 6640f95291 Fixes 2025-07-02 00:27:49 +02:00
skippyall 362bf15a19 Update to 1.21.6 2025-06-21 00:52:12 +02:00
14 changed files with 71 additions and 75 deletions
+9 -9
View File
@@ -3,21 +3,21 @@ 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.5 minecraft_version=1.21.7
loader_version=0.16.13 loader_version=0.16.14
yarn_mappings=1.21.5+build.1 yarn_mappings=1.21.7+build.2
# Mod Properties # Mod Properties
mod_version = 0.2.0-SNAPSHOT mod_version = 0.2.1-SNAPSHOT
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.121.0+1.21.5 fabric_version=0.128.1+1.21.7
polymer_version=0.12.3+1.21.5 polymer_version=0.13.3+1.21.6
sgui_version=1.9.0+1.21.5 sgui_version=1.10.0+1.21.6
server_translations_version=2.5.0+1.21.5-rc1 server_translations_version=2.5.1+1.21.5
universal_graves_version=3.7.1+1.21.5 universal_graves_version=3.8.0+1.21.6
@@ -21,10 +21,11 @@ public class Minions implements ModInitializer {
MinionData.register(); MinionData.register();
PolymerEntityUtils.registerType(); PolymerEntityUtils.registerType();
ServerLifecycleEvents.SERVER_STARTED.register(server -> { ServerLifecycleEvents.SERVER_STARTED.register(server -> {
LOGGER.error("Initializing Minion data");
MinionPersistentState.create(server); MinionPersistentState.create(server);
MinionPersistentState.INSTANCE.getMinionData().forEach((uuid, data) -> { MinionPersistentState.INSTANCE.getMinionData().forEach((uuid, data) -> {
if(data.isSpawned()) { if(data.isSpawned()) {
MinionFakePlayer.spawnMinion(data, server.getOverworld(), null, null); MinionFakePlayer.spawnMinion(data, server.getOverworld(), null, null, true);
} }
}); });
}); });
@@ -1,27 +0,0 @@
package io.github.skippyall.minions;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MinionsTickExecutor {
private static final List<Runnable> executeOnNextTick = Collections.synchronizedList(new ArrayList<>());
public static void register() {
ServerTickEvents.START_SERVER_TICK.register(server -> {
synchronized (executeOnNextTick) {
for (Runnable run:executeOnNextTick) {
run.run();
}
executeOnNextTick.clear();
}
});
}
public static void addExecuteOnNextTick(Runnable run) {
executeOnNextTick.add(run);
}
}
@@ -0,0 +1,25 @@
package io.github.skippyall.minions.command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import io.github.skippyall.minions.minion.MinionData;
import io.github.skippyall.minions.minion.MinionPersistentState;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import java.util.Collection;
import static net.minecraft.server.command.CommandManager.literal;
public class ListSubcommand {
public static final LiteralArgumentBuilder<ServerCommandSource> LIST = literal("list")
.executes(ListSubcommand::list);
public static int list(CommandContext<ServerCommandSource> context) {
Collection<MinionData> minions = MinionPersistentState.INSTANCE.getMinionData().values();
for (MinionData minion : minions) {
context.getSource().sendFeedback(() -> Text.literal(minion.name() + "(" + minion.uuid() + "):" + minion.isSpawned()), false);
}
return 0;
}
}
@@ -1,8 +1,6 @@
package io.github.skippyall.minions.command; package io.github.skippyall.minions.command;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandExceptionType;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.SuggestionProvider;
@@ -11,6 +11,7 @@ public class MinionsCommand {
literal("minions") literal("minions")
.then(SpawnSubcommand.SPAWN) .then(SpawnSubcommand.SPAWN)
.then(MobCapDebugSubcommand.MOB_CAP_DEBUG) .then(MobCapDebugSubcommand.MOB_CAP_DEBUG)
.then(ListSubcommand.LIST)
); );
} }
@@ -9,19 +9,19 @@ import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import java.util.Collection;
import java.util.List; import java.util.List;
public class CommandsGui { public class CommandsGui {
public static void openServerModuleCommandGui(ServerPlayerEntity player, MinionFakePlayer minion) { public static void openServerModuleCommandGui(ServerPlayerEntity player, MinionFakePlayer minion) {
List<ModuleItem> modules = minion.getModuleInventory().getModuleItems(); Collection<ModuleItem> modules = minion.getModuleInventory().getModuleItems();
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false); SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
gui.setTitle(Text.translatable("minions.gui.module_commands.title")); gui.setTitle(Text.translatable("minions.gui.module_commands.title"));
for (int i = 0; i < modules.size(); i++) { for (ModuleItem module : modules) {
ModuleItem module = modules.get(i); gui.addSlot(new GuiElementBuilder()
gui.setSlot(i, new GuiElementBuilder()
.setItem(module.asItem()) .setItem(module.asItem())
.setCallback(() -> openServerCommandGui(player, minion, module)) .setCallback(() -> openServerCommandGui(player, minion, module))
); );
@@ -43,7 +43,7 @@ public class MinionGui {
.setItem(Items.BARRIER) .setItem(Items.BARRIER)
.setName(Text.translatable("minions.gui.main.pickup")) .setName(Text.translatable("minions.gui.main.pickup"))
.setCallback(() -> { .setCallback(() -> {
minion.kill(minion.getServerWorld()); minion.kill(minion.getWorld());
}) })
); );
gui.open(); gui.open();
@@ -4,16 +4,13 @@ import io.github.skippyall.minions.module.command.Command;
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer; import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
import io.github.skippyall.minions.module.ModuleItem; import io.github.skippyall.minions.module.ModuleItem;
import io.github.skippyall.minions.program.block.CodeBlock; import io.github.skippyall.minions.program.block.CodeBlock;
import net.fabricmc.fabric.impl.transfer.item.ComposterWrapper;
import net.fabricmc.fabric.mixin.transfer.JukeboxBlockEntityMixin;
import net.minecraft.block.ComposterBlock;
import net.minecraft.inventory.Inventories; import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.SimpleInventory; import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory; import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.storage.ReadView;
import net.minecraft.storage.WriteView;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import java.util.ArrayList; import java.util.ArrayList;
@@ -57,13 +54,13 @@ public class ModuleInventory extends SimpleInventory {
} }
} }
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) { public void readData(ReadView view) {
Inventories.readNbt(nbt, heldStacks, lookup); Inventories.readData(view, heldStacks);
updateModules(); updateModules();
} }
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) { public void writeData(WriteView view) {
return Inventories.writeNbt(nbt, heldStacks, lookup); Inventories.writeData(view, heldStacks);
} }
public boolean hasModule(ModuleItem module) { public boolean hasModule(ModuleItem module) {
@@ -1,16 +1,12 @@
package io.github.skippyall.minions.minion; package io.github.skippyall.minions.minion;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import net.minecraft.nbt.NbtCompound; import io.github.skippyall.minions.Minions;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.world.PersistentState; import net.minecraft.world.PersistentState;
import net.minecraft.world.PersistentStateType; import net.minecraft.world.PersistentStateType;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -68,6 +64,7 @@ public class MinionPersistentState extends PersistentState {
} }
public static void create(MinecraftServer server) { public static void create(MinecraftServer server) {
Minions.LOGGER.error("Creating Minion Persistent state");
INSTANCE = server.getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TYPE); INSTANCE = server.getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TYPE);
} }
} }
@@ -317,11 +317,11 @@ public class EntityPlayerActionPack
case BLOCK: case BLOCK:
{ {
player.updateLastActionTime(); player.updateLastActionTime();
ServerWorld world = player.getServerWorld(); ServerWorld world = player.getWorld();
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.canEntityModifyAt(player, pos)) if (pos.getY() < player.getWorld().getTopYInclusive() - (side == Direction.UP ? 1 : 0) && world.canEntityModifyAt(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 instanceof ActionResult.Success success)
@@ -21,7 +21,6 @@ import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.HungerManager; import net.minecraft.entity.player.HungerManager;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.DisconnectionInfo; import net.minecraft.network.DisconnectionInfo;
import net.minecraft.network.NetworkSide; import net.minecraft.network.NetworkSide;
import net.minecraft.network.packet.c2s.common.SyncedClientOptions; import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
@@ -33,6 +32,8 @@ import net.minecraft.server.ServerTask;
import net.minecraft.server.network.ConnectedClientData; import net.minecraft.server.network.ConnectedClientData;
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.storage.ReadView;
import net.minecraft.storage.WriteView;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent; import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@@ -68,7 +69,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
PropertyMap skin = data.skin().orElse(null); PropertyMap skin = data.skin().orElse(null);
GameProfile profile = MinionProfileUtils.makeNewMinionProfile(data.uuid(), data.name(), skin); GameProfile profile = MinionProfileUtils.makeNewMinionProfile(data.uuid(), data.name(), skin);
doSpawn(data, profile, server, level, pos, rot); server.send(server.createTask(() -> doSpawn(data, profile, server, level, pos, rot)));
} }
} }
@@ -151,7 +152,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) { if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
this.networkHandler.onDisconnected(new DisconnectionInfo(reason)); this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
} else { } else {
this.server.send(new ServerTask(this.server.getTicks(), () -> { this.getServer().send(new ServerTask(this.getServer().getTicks(), () -> {
this.networkHandler.onDisconnected(new DisconnectionInfo(reason)); this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
})); }));
} }
@@ -165,7 +166,7 @@ public class MinionFakePlayer extends ServerPlayerEntity {
if (this.getServer().getTicks() % 10 == 0) if (this.getServer().getTicks() % 10 == 0)
{ {
this.networkHandler.syncWithPlayerPosition(); this.networkHandler.syncWithPlayerPosition();
this.getServerWorld().getChunkManager().updatePosition(this); this.getWorld().getChunkManager().updatePosition(this);
} }
try try
{ {
@@ -291,14 +292,14 @@ public class MinionFakePlayer extends ServerPlayerEntity {
} }
@Override @Override
public void writeCustomDataToNbt(NbtCompound nbt) { public void writeCustomData(WriteView view) {
super.writeCustomDataToNbt(nbt); super.writeCustomData(view);
nbt.put("modules", moduleInventory.writeNbt(new NbtCompound(), getRegistryManager())); moduleInventory.writeData(view.get("modules"));
} }
@Override @Override
public void readCustomDataFromNbt(NbtCompound nbt) { public void readCustomData(ReadView view) {
super.readCustomDataFromNbt(nbt); super.readCustomData(view);
moduleInventory.readNbt(nbt.getCompoundOrEmpty("modules"), getRegistryManager()); moduleInventory.readData(view.getReadView("modules"));
} }
} }
@@ -38,9 +38,9 @@ public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler
public void requestTeleport(PlayerPosition pos, Set<PositionFlag> set) public void requestTeleport(PlayerPosition pos, Set<PositionFlag> set)
{ {
super.requestTeleport(pos, set); super.requestTeleport(pos, set);
if (player.getServerWorld().getPlayerByUuid(player.getUuid()) != null) { if (player.getWorld().getPlayerByUuid(player.getUuid()) != null) {
syncWithPlayerPosition(); syncWithPlayerPosition();
player.getServerWorld().getChunkManager().updatePosition(player); player.getWorld().getChunkManager().updatePosition(player);
} }
} }
@@ -17,7 +17,9 @@ 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.storage.ReadView;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ErrorReporter;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -25,17 +27,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Mixin(PlayerManager.class) @Mixin(PlayerManager.class)
public class PlayerListMixin { public class PlayerListMixin {
@Inject(method = "loadPlayerData", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) @Inject(method = "loadPlayerData", at = @At(value = "RETURN", shift = At.Shift.BEFORE))
private void fixStartingPos(ServerPlayerEntity serverPlayerEntity_1, CallbackInfoReturnable<NbtCompound> cir) private void fixStartingPos(ServerPlayerEntity player, ErrorReporter errorReporter, CallbackInfoReturnable<Optional<ReadView>> cir)
{ {
if (serverPlayerEntity_1 instanceof MinionFakePlayer) if (player instanceof MinionFakePlayer)
{ {
((MinionFakePlayer) serverPlayerEntity_1).fixStartingPosition.run(); ((MinionFakePlayer) player).fixStartingPosition.run();
} }
} }