diff --git a/gradle.properties b/gradle.properties index f29530c1..8ae60b94 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use # or better: https://modmuss50.me/fabric.html - minecraft_version=20w17a - yarn_mappings=20w17a+build.7 + minecraft_version=20w18a + yarn_mappings=20w18a+build.1 loader_version=0.8.2+build.194 # Mod Properties diff --git a/src/main/java/carpet/commands/SpawnCommand.java b/src/main/java/carpet/commands/SpawnCommand.java index d141b291..86aa9375 100644 --- a/src/main/java/carpet/commands/SpawnCommand.java +++ b/src/main/java/carpet/commands/SpawnCommand.java @@ -225,7 +225,7 @@ public class SpawnCommand private static int generalMobcaps(ServerCommandSource source) { - Messenger.send(source, SpawnReporter.printMobcapsForDimension(source.getWorld().getDimension().getType(), true)); + Messenger.send(source, SpawnReporter.printMobcapsForDimension(source.getWorld(), true)); return 1; } @@ -258,7 +258,7 @@ public class SpawnCommand private static int mobcapsForDimension(ServerCommandSource source, DimensionType dim) { - Messenger.send(source, SpawnReporter.printMobcapsForDimension(dim, true)); + Messenger.send(source, SpawnReporter.printMobcapsForDimension(source.getWorld(), true)); return 1; } diff --git a/src/main/java/carpet/mixins/RedstoneWireBlockMixin.java b/src/main/java/carpet/mixins/RedstoneWireBlockMixin.java index c1342018..1d7ec4f9 100644 --- a/src/main/java/carpet/mixins/RedstoneWireBlockMixin.java +++ b/src/main/java/carpet/mixins/RedstoneWireBlockMixin.java @@ -27,7 +27,9 @@ import static net.minecraft.block.RedstoneWireBlock.POWER; @Mixin(RedstoneWireBlock.class) public abstract class RedstoneWireBlockMixin implements RedstoneWireBlockInterface { - // = + /* + + needs reworking @Shadow private boolean wiresGivePower; @@ -72,7 +74,7 @@ public abstract class RedstoneWireBlockMixin implements RedstoneWireBlockInterfa /** * @author theosib, soykaf, gnembon - */ + * @Inject(method = "updateLogic", at = @At("HEAD"), cancellable = true) private void updateLogicAlternative(World world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { @@ -164,4 +166,6 @@ public abstract class RedstoneWireBlockMixin implements RedstoneWireBlockInterfa boolean boolean_1) { return fastUpdate(world_1, blockPos_1, blockState_1, blockPos_3); } + + */ } diff --git a/src/main/java/carpet/mixins/ServerChunkManagerMixin.java b/src/main/java/carpet/mixins/ServerChunkManagerMixin.java index 8b5bc7e4..e584ed52 100644 --- a/src/main/java/carpet/mixins/ServerChunkManagerMixin.java +++ b/src/main/java/carpet/mixins/ServerChunkManagerMixin.java @@ -31,8 +31,6 @@ public abstract class ServerChunkManagerMixin implements ServerChunkManagerInter { @Shadow @Final private ServerWorld world; - @Shadow @Final private static int CHUNKS_ELIGIBLE_FOR_SPAWNING; - @Shadow @Final private ChunkTicketManager ticketManager; @Override // shared between scarpet and spawnChunks setting @@ -41,33 +39,17 @@ public abstract class ServerChunkManagerMixin implements ServerChunkManagerInter return ticketManager; } - @Inject( - method = "tickChunks", - locals = LocalCapture.CAPTURE_FAILHARD, - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/server/world/ThreadedAnvilChunkStorage;entryIterator()Ljava/lang/Iterable;", - shift = At.Shift.AFTER, - ordinal = 0 - + @Redirect(method = "tickChunks", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/world/ChunkTicketManager;getLevelCount()I" )) //this runs once per world spawning cycle. Allows to grab mob counts and count spawn ticks - private void grabMobcaps(CallbackInfo ci, - long long_1, - long long_2, - class_5217 levelProperties_1, - boolean boolean_1, - boolean boolean_2, - int int_1, - boolean boolean_3, - int int_2, - EntityCategory[] entityCategorys_1, - Object2IntMap object2IntMap_1) + private int setupTracking(ChunkTicketManager chunkTicketManager) { + int j = chunkTicketManager.getLevelCount(); DimensionType dim = this.world.dimension.getType(); //((WorldInterface)world).getPrecookedMobs().clear(); not needed because mobs are compared with predefined BBs - SpawnReporter.mobCounts.put(dim, (Object2IntMap)object2IntMap_1); - SpawnReporter.chunkCounts.put(dim, int_2); + SpawnReporter.chunkCounts.put(dim, j); if (SpawnReporter.track_spawns > 0L) { @@ -82,67 +64,9 @@ public abstract class ServerChunkManagerMixin implements ServerChunkManagerInter SpawnReporter.spawn_tries.get(cat)); } } + return j; } - @SuppressWarnings("UnresolvedMixinReference") - @Redirect(method = "method_20801", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/SpawnHelper;spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/WorldChunk;)V" - )) - // inject our repeat of spawns if more spawn ticks per tick are chosen. - private void spawnMultipleTimes(EntityCategory entityCategory_1, ServerWorld world_1, WorldChunk worldChunk_1) - { - for (int i = 0; i < SpawnReporter.spawn_tries.get(entityCategory_1); i++) - { - SpawnHelper.spawnEntitiesInChunk(entityCategory_1, world_1, worldChunk_1); - } - } - - @SuppressWarnings("UnresolvedMixinReference") - @Redirect(method = "method_20801", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/entity/EntityCategory;getSpawnCap()I" - )) - // allows to change mobcaps and captures each category try per dimension before it fails due to full mobcaps. - private int getNewMobcaps(EntityCategory entityCategory) - { - DimensionType dim = this.world.dimension.getType(); - int newCap = (int) ((double)entityCategory.getSpawnCap()*(Math.pow(2.0,(SpawnReporter.mobcap_exponent/4)))); - if (SpawnReporter.track_spawns > 0L) - { - int int_2 = SpawnReporter.chunkCounts.get(dim); // eligible chunks for spawning - int int_3 = newCap * int_2 / CHUNKS_ELIGIBLE_FOR_SPAWNING; //current spawning limits - int mobCount = SpawnReporter.mobCounts.get(dim).getInt(entityCategory); - - if (SpawnReporter.track_spawns > 0L && !SpawnReporter.first_chunk_marker.contains(entityCategory)) - { - SpawnReporter.first_chunk_marker.add(entityCategory); - //first chunk with spawn eligibility for that category - Pair key = Pair.of(dim, entityCategory); - - - int spawnTries = SpawnReporter.spawn_tries.get(entityCategory); - - SpawnReporter.spawn_attempts.put(key, - SpawnReporter.spawn_attempts.get(key) + spawnTries); - - SpawnReporter.spawn_cap_count.put(key, - SpawnReporter.spawn_cap_count.get(key) + mobCount); - } - - if (mobCount <= int_3 || SpawnReporter.mock_spawns) - { - //place 0 to indicate there were spawn attempts for a category - //if (entityCategory != EntityCategory.CREATURE || world.getServer().getTicks() % 400 == 0) - // this will only be called once every 400 ticks anyways - SpawnReporter.local_spawns.putIfAbsent(entityCategory, 0L); - - //else - //full mobcaps - and key in local_spawns will be missing - } - } - return SpawnReporter.mock_spawns?Integer.MAX_VALUE:newCap; - } @Inject(method = "tickChunks", at = @At("RETURN")) private void onFinishSpawnWorldCycle(CallbackInfo ci) diff --git a/src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java b/src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java index 17bbd74d..cdf546b3 100644 --- a/src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java @@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.stat.Stat; import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,9 +25,10 @@ import static carpet.script.CarpetEventServer.Event.STATISTICS; @Mixin(ServerPlayerEntity.class) public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity { - public ServerPlayerEntity_scarpetEventMixin(World world_1, GameProfile gameProfile_1) + + public ServerPlayerEntity_scarpetEventMixin(World world, BlockPos blockPos, GameProfile gameProfile) { - super(world_1, gameProfile_1); + super(world, blockPos, gameProfile); } @Shadow protected abstract void consumeItem(); diff --git a/src/main/java/carpet/mixins/ServerWorld_tickMixin.java b/src/main/java/carpet/mixins/ServerWorld_tickMixin.java index 476bbf01..29672890 100644 --- a/src/main/java/carpet/mixins/ServerWorld_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerWorld_tickMixin.java @@ -3,6 +3,7 @@ package carpet.mixins; import carpet.helpers.TickSpeed; import carpet.utils.CarpetProfiler; import net.minecraft.class_5217; +import net.minecraft.class_5269; import net.minecraft.entity.raid.RaidManager; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.profiler.Profiler; @@ -153,10 +154,10 @@ public abstract class ServerWorld_tickMixin extends World @Redirect(method = "tick", at = @At( value = "INVOKE", - target = "Lnet/minecraft/class_5217;getGeneratorType()Lnet/minecraft/world/level/LevelGeneratorType;" + target = "Lnet/minecraft/class_5269;getGeneratorType()Lnet/minecraft/world/level/LevelGeneratorType;" //target = "Lnet/minecraft/world/level/LevelProperties;getGeneratorType()Lnet/minecraft/world/level/LevelGeneratorType;" )) - private LevelGeneratorType tickPendingBlocks(class_5217 levelProperties) + private LevelGeneratorType tickPendingBlocks(class_5269 levelProperties) { if (TickSpeed.process_entities) return levelProperties.getGeneratorType(); return LevelGeneratorType.DEBUG_ALL_BLOCK_STATES; diff --git a/src/main/java/carpet/mixins/SpawnHelperMixin.java b/src/main/java/carpet/mixins/SpawnHelperMixin.java index 255841d5..cdf526c6 100644 --- a/src/main/java/carpet/mixins/SpawnHelperMixin.java +++ b/src/main/java/carpet/mixins/SpawnHelperMixin.java @@ -27,7 +27,11 @@ import net.minecraft.world.SpawnHelper; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.WorldChunk; +import net.minecraft.world.dimension.DimensionType; +import org.apache.commons.lang3.tuple.Pair; +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.Redirect; @@ -39,6 +43,8 @@ public class SpawnHelperMixin // in World: private static Map precookedMobs= new HashMap<>(); + @Shadow @Final private static int field_24392; + @Redirect(method = "method_24934", at = @At( value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;doesNotCollide(Lnet/minecraft/util/math/Box;)Z" @@ -142,7 +148,7 @@ public class SpawnHelperMixin return entityType.create(world_1); } - @Redirect(method = "spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;)V", at = @At( + @Redirect(method = "spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/SpawnHelper$class_5261;Lnet/minecraft/world/SpawnHelper$class_5259;)V", at = @At( value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;spawnEntity(Lnet/minecraft/entity/Entity;)Z" )) @@ -165,7 +171,7 @@ public class SpawnHelperMixin return false; } - @Redirect(method = "spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;)V", at = @At( + @Redirect(method = "spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/SpawnHelper$class_5261;Lnet/minecraft/world/SpawnHelper$class_5259;)V", at = @At( value = "INVOKE", target = "Lnet/minecraft/entity/mob/MobEntity;initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;" )) @@ -176,7 +182,7 @@ public class SpawnHelperMixin return null; } - @Redirect(method = "spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;)V", at = @At( + @Redirect(method = "spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/SpawnHelper$class_5261;Lnet/minecraft/world/SpawnHelper$class_5259;)V", at = @At( value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;squaredDistanceTo(DDD)D" )) @@ -188,4 +194,69 @@ public class SpawnHelperMixin return 0.0; return distanceTo; } + + + + //// + + @Redirect(method = "method_27821", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/SpawnHelper;spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/world/SpawnHelper$class_5261;Lnet/minecraft/world/SpawnHelper$class_5259;)V" + )) + // inject our repeat of spawns if more spawn ticks per tick are chosen. + private static void spawnMultipleTimes(EntityCategory category, ServerWorld world, WorldChunk chunk, SpawnHelper.class_5261 arg, SpawnHelper.class_5259 arg2) + { + for (int i = 0; i < SpawnReporter.spawn_tries.get(category); i++) + { + SpawnHelper.spawnEntitiesInChunk(category, world, chunk, arg, arg2); + } + } + + @Redirect(method = "method_27821", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/SpawnHelper$class_5262;method_27826(Lnet/minecraft/entity/EntityCategory;)Z" + )) + // allows to change mobcaps and captures each category try per dimension before it fails due to full mobcaps. + private static boolean getNewMobcaps( + SpawnHelper.class_5262 class_526, EntityCategory entityCategory, + ServerWorld serverWorld, WorldChunk worldChunk, Object arg, boolean bl, boolean bl2, boolean bl3) + { + DimensionType dim = serverWorld.dimension.getType(); + int newCap = (int) ((double)entityCategory.getSpawnCap()*(Math.pow(2.0,(SpawnReporter.mobcap_exponent/4)))); + if (SpawnReporter.track_spawns > 0L) + { + int int_2 = SpawnReporter.chunkCounts.get(dim); // eligible chunks for spawning + int int_3 = newCap * int_2 / field_24392; //current spawning limits + int mobCount = class_526.method_27830().getInt(entityCategory); + + if (SpawnReporter.track_spawns > 0L && !SpawnReporter.first_chunk_marker.contains(entityCategory)) + { + SpawnReporter.first_chunk_marker.add(entityCategory); + //first chunk with spawn eligibility for that category + Pair key = Pair.of(dim, entityCategory); + + + int spawnTries = SpawnReporter.spawn_tries.get(entityCategory); + + SpawnReporter.spawn_attempts.put(key, + SpawnReporter.spawn_attempts.get(key) + spawnTries); + + SpawnReporter.spawn_cap_count.put(key, + SpawnReporter.spawn_cap_count.get(key) + mobCount); + } + + if (mobCount <= int_3 || SpawnReporter.mock_spawns) + { + //place 0 to indicate there were spawn attempts for a category + //if (entityCategory != EntityCategory.CREATURE || world.getServer().getTicks() % 400 == 0) + // this will only be called once every 400 ticks anyways + SpawnReporter.local_spawns.putIfAbsent(entityCategory, 0L); + + //else + //full mobcaps - and key in local_spawns will be missing + } + } + return SpawnReporter.mock_spawns || class_526.method_27830().getInt(entityCategory) < newCap; + } + } diff --git a/src/main/java/carpet/mixins/World_movableTEMixin.java b/src/main/java/carpet/mixins/World_movableTEMixin.java index 13582dcc..82862303 100644 --- a/src/main/java/carpet/mixins/World_movableTEMixin.java +++ b/src/main/java/carpet/mixins/World_movableTEMixin.java @@ -7,6 +7,7 @@ import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.class_5217; +import net.minecraft.class_5269; import net.minecraft.server.world.ChunkHolder; import net.minecraft.util.math.BlockPos; import net.minecraft.util.profiler.Profiler; @@ -29,7 +30,7 @@ public abstract class World_movableTEMixin implements WorldInterface public boolean isClient; @Shadow @Final - protected class_5217 properties; //LevelProperties + protected class_5269 properties; //LevelProperties @Shadow public abstract WorldChunk getWorldChunk(BlockPos blockPos_1); diff --git a/src/main/java/carpet/utils/HUDController.java b/src/main/java/carpet/utils/HUDController.java index 74d09caf..95eb1563 100644 --- a/src/main/java/carpet/utils/HUDController.java +++ b/src/main/java/carpet/utils/HUDController.java @@ -71,7 +71,7 @@ public class HUDController dim = DimensionType.THE_END; break; } - return new BaseText[]{SpawnReporter.printMobcapsForDimension(dim, false).get(0)}; + return new BaseText[]{SpawnReporter.printMobcapsForDimension(server.getWorld(dim), false).get(0)}; }); if(LoggerRegistry.__counter) diff --git a/src/main/java/carpet/utils/SpawnReporter.java b/src/main/java/carpet/utils/SpawnReporter.java index a271031c..5d311b1b 100644 --- a/src/main/java/carpet/utils/SpawnReporter.java +++ b/src/main/java/carpet/utils/SpawnReporter.java @@ -37,7 +37,6 @@ public class SpawnReporter public static boolean mock_spawns = false; public static Long track_spawns = 0L; - public static final HashMap> mobCounts = new HashMap<>(); public static final HashMap chunkCounts = new HashMap<>(); public static final HashMap, Object2LongMap> spawn_stats = new HashMap<>(); @@ -82,13 +81,15 @@ public class SpawnReporter } - public static List printMobcapsForDimension(DimensionType dim, boolean multiline) + public static List printMobcapsForDimension(ServerWorld world, boolean multiline) { + DimensionType dim = world.getDimension().getType(); String name = dim.toString(); List lst = new ArrayList<>(); if (multiline) lst.add(Messenger.s(String.format("Mobcaps for %s:",name))); - Object2IntMap dimCounts = mobCounts.get(dim); + SpawnHelper.class_5262 lastSpawner = world.getChunkManager().method_27908(); + Object2IntMap dimCounts = lastSpawner.method_27830(); int chunkcount = chunkCounts.getOrDefault(dim, -1); if (dimCounts == null || chunkcount < 0) { @@ -163,7 +164,7 @@ public class SpawnReporter } - public static List show_mobcaps(BlockPos pos, World worldIn) + public static List show_mobcaps(BlockPos pos, ServerWorld worldIn) { DyeColor under = WoolTool.getWoolColorAtPosition(worldIn, pos.down()); if (under == null) @@ -174,7 +175,7 @@ public class SpawnReporter } else { - return printMobcapsForDimension(worldIn.dimension.getType(), true ); + return printMobcapsForDimension(worldIn, true ); } } EntityCategory creature_type = get_type_code_from_wool_code(under); @@ -197,7 +198,7 @@ public class SpawnReporter } else { - return printMobcapsForDimension(worldIn.dimension.getType(), true ); + return printMobcapsForDimension(worldIn, true ); } }