Mob Cap fix
This commit is contained in:
@@ -6,6 +6,10 @@ plugins {
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ 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.21.3
|
||||||
loader_version=0.16.7
|
loader_version=0.16.13
|
||||||
yarn_mappings=1.21.3+build.2
|
yarn_mappings=1.21.3+build.2
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import io.github.skippyall.minions.minion.MinionItem;
|
|||||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||||
import io.github.skippyall.minions.module.Modules;
|
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.ServerLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
@@ -21,6 +22,7 @@ import net.minecraft.registry.Registry;
|
|||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.registry.tag.TagKey;
|
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;
|
||||||
@@ -59,6 +61,10 @@ public class Minions implements ModInitializer {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CommandRegistrationCallback.EVENT.register((commandDispatcher, commandRegistryAccess, registrationEnvironment) -> {
|
||||||
|
MobCapCommand.registerCommand(commandDispatcher);
|
||||||
|
});
|
||||||
|
|
||||||
Modules.register();
|
Modules.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
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;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package io.github.skippyall.minions.mixinhelper;
|
||||||
|
|
||||||
|
public interface ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor {
|
||||||
|
void minions$markAsMinionless();
|
||||||
|
void minions$markAsTarget();
|
||||||
|
int minions$getTickedChunkCount();
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
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
@@ -0,0 +1,85 @@
|
|||||||
|
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 minionless, target;
|
||||||
|
|
||||||
|
@Inject(method = "isPlayerInChunk", at = @At("RETURN"), cancellable = true)
|
||||||
|
public void filterMinions(long chunkPos, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
if (minionless) {
|
||||||
|
cir.setReturnValue(isRealPlayerInChunk(chunkPos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public boolean 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 sync(CallbackInfo info) {
|
||||||
|
if (target) {
|
||||||
|
((ChunkTicketManagerAccessor)field_17462).getMinionless().updateLevels();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void minions$updateLevel(long chunkPos, int distance, boolean decrease, CallbackInfo info) {
|
||||||
|
if (target && (distance != 0 || isRealPlayerInChunk(chunkPos))) {
|
||||||
|
((ChunkTicketManagerAccessor)field_17462).getMinionless().updateLevel(chunkPos, distance, decrease);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void minions$markAsMinionless() {
|
||||||
|
minionless = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void minions$markAsTarget() {
|
||||||
|
target = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int minions$getTickedChunkCount() {
|
||||||
|
return distanceFromNearestPlayer.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package io.github.skippyall.minions.mixins.antimobcap;
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
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
@@ -0,0 +1,23 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
"mixins": [
|
"mixins": [
|
||||||
"minions.mixins.json"
|
"minions.mixins.json"
|
||||||
],
|
],
|
||||||
|
"accessWidener" : "minions.accesswidener",
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": "*",
|
"fabricloader": "*",
|
||||||
"fabric": "*",
|
"fabric": "*",
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
accessWidener v2 named
|
||||||
|
|
||||||
|
accessible class net/minecraft/server/world/ChunkTicketManager$DistanceFromNearestPlayerTracker
|
||||||
|
accessible method net/minecraft/server/world/ChunkTicketManager$DistanceFromNearestPlayerTracker <init> (Lnet/minecraft/server/world/ChunkTicketManager;I)V
|
||||||
@@ -15,7 +15,12 @@
|
|||||||
"ServerPlayerMixin",
|
"ServerPlayerMixin",
|
||||||
"ServerPlayNetworkHandlerMixin",
|
"ServerPlayNetworkHandlerMixin",
|
||||||
"SleepManagerMixin",
|
"SleepManagerMixin",
|
||||||
"SpawnHelperMixin"
|
"SpawnHelperMixin",
|
||||||
|
"antimobcap.ChunkPosDistanceLevelPropagatorMixin",
|
||||||
|
"antimobcap.ChunkTicketManager$DistanceFromNearestPlayerTrackerMixin",
|
||||||
|
"antimobcap.ChunkTicketManagerMixin",
|
||||||
|
"antimobcap.ServerChunkManagerAccessor",
|
||||||
|
"antimobcap.ServerChunkManagerMixin"
|
||||||
],
|
],
|
||||||
"client": [],
|
"client": [],
|
||||||
"server": [],
|
"server": [],
|
||||||
|
|||||||
Reference in New Issue
Block a user