mapping updates

This commit is contained in:
gnembon committed 2020-05-04 00:09:22 -03:00
1 parent cdb79f9768
commit b16991d84b
8 files changed
+64 -59

No files matched your search

@@ -1,8 +1,8 @@
package carpet.fakes;
import net.minecraft.class_5263;
import net.minecraft.util.math.GravityField;
public interface SpawnHelperInnerInterface
{
class_5263 getPotentialCalculator();
GravityField getPotentialCalculator();
}
@@ -21,7 +21,7 @@ public abstract class InfestedBlockMixin extends Block
super(block$Settings_1);
}
@Inject(method = "method_24797", at = @At(value = "INVOKE", shift = At.Shift.AFTER,
@Inject(method = "spawnSilverfish", at = @At(value = "INVOKE", shift = At.Shift.AFTER,
target = "Lnet/minecraft/entity/mob/SilverfishEntity;playSpawnEffects()V"))
private void onOnStacksDropped(World world, BlockPos blockPos, CallbackInfo ci)
{
@@ -41,12 +41,12 @@ public abstract class ServerChunkManagerMixin implements ServerChunkManagerInter
@Redirect(method = "tickChunks", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/world/ChunkTicketManager;getLevelCount()I"
target = "Lnet/minecraft/server/world/ChunkTicketManager;getSpawningChunkCount()I"
))
//this runs once per world spawning cycle. Allows to grab mob counts and count spawn ticks
private int setupTracking(ChunkTicketManager chunkTicketManager)
{
int j = chunkTicketManager.getLevelCount();
int j = chunkTicketManager.getSpawningChunkCount();
DimensionType dim = this.world.dimension.getType();
//((WorldInterface)world).getPrecookedMobs().clear(); not needed because mobs are compared with predefined BBs
SpawnReporter.chunkCounts.put(dim, j);
@@ -30,16 +30,15 @@ import java.util.function.Supplier;
@Mixin(ServerWorld.class)
public abstract class ServerWorld_tickMixin extends World
{
@Shadow protected abstract void processSyncedBlockEvents();
//@Shadow protected abstract void sendBlockActions();
protected ServerWorld_tickMixin(LevelProperties levelProperties, DimensionType dimensionType, BiFunction<World, Dimension, ChunkManager> chunkManagerProvider, Supplier<Profiler> supplier, boolean isClient)
{
super(levelProperties, dimensionType, chunkManagerProvider, supplier, isClient);
}
@Shadow protected abstract void sendBlockActions();
CarpetProfiler.ProfilerToken currentSection;
private CarpetProfiler.ProfilerToken currentSection;
@Inject(method = "tick", at = @At(
value = "CONSTANT",
@@ -183,11 +182,11 @@ public abstract class ServerWorld_tickMixin extends World
@Redirect(method = "tick", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/world/ServerWorld;sendBlockActions()V"
target = "Lnet/minecraft/server/world/ServerWorld;processSyncedBlockEvents()V" // aka sendBlockActions
))
private void tickConditionally(ServerWorld serverWorld)
{
if (TickSpeed.process_entities) sendBlockActions();
if (TickSpeed.process_entities) processSyncedBlockEvents();
}
@@ -3,8 +3,8 @@ package carpet.mixins;
import carpet.fakes.SpawnHelperInnerInterface;
import carpet.utils.SpawnReporter;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.class_5263;
import net.minecraft.entity.EntityCategory;
import net.minecraft.util.math.GravityField;
import net.minecraft.world.SpawnHelper;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -15,27 +15,34 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
// temporary mixin until naming for spawnhelper gets fixed.
@Mixin(SpawnHelper.class_5262.class)
@Mixin(SpawnHelper.Info.class)
public class SpawnHelperInnerMixin implements SpawnHelperInnerInterface
{
@Shadow @Final private int field_24394;
//@Shadow @Final private int field_24394;
@Shadow @Final private Object2IntMap<EntityCategory> field_24395;
//@Shadow @Final private Object2IntMap<EntityCategory> field_24395;
@Shadow @Final private class_5263 field_24396;
//@Shadow @Final private class_5263 field_24396;
@Inject(method = "method_27826", at = @At("HEAD"), cancellable = true)
@Shadow @Final private int spawningChunkCount;
@Shadow @Final private Object2IntMap<EntityCategory> categoryToCount;
@Shadow @Final private GravityField densityField;
@Inject(method = "isBelowCap", at = @At("HEAD"), cancellable = true)
private void changeMobCaps(EntityCategory entityCategory, CallbackInfoReturnable<Boolean> cir)
{
int newCap = (int) ((double)entityCategory.getSpawnCap()*(Math.pow(2.0,(SpawnReporter.mobcap_exponent/4))));
int i = newCap * field_24394 / (int)Math.pow(17.0D, 2.0D);
cir.setReturnValue(field_24395.getInt(entityCategory) < i);
int i = newCap * spawningChunkCount / (int)Math.pow(17.0D, 2.0D);
cir.setReturnValue(categoryToCount.getInt(entityCategory) < i);
}
@Override
public class_5263 getPotentialCalculator()
public GravityField getPotentialCalculator()
{
return field_24396;
return densityField;
}
@@ -42,14 +42,11 @@ import java.util.Map;
@Mixin(SpawnHelper.class)
public class SpawnHelperMixin
{
@Shadow @Final private static int CHUNK_AREA;
// in World: private static Map<EntityType, Entity> precookedMobs= new HashMap<>();
@Shadow @Final private static EntityCategory[] SPAWNABLE_CATEGORIES;
@Shadow @Final private static int field_24392;
@Shadow @Final private static EntityCategory[] field_24393;
@Redirect(method = "method_24934", at = @At(
@Redirect(method = "canSpawn(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/gen/chunk/ChunkGenerator;Lnet/minecraft/world/biome/Biome$SpawnEntry;Lnet/minecraft/util/math/BlockPos$Mutable;D)Z", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/world/ServerWorld;doesNotCollide(Lnet/minecraft/util/math/Box;)Z"
))
@@ -133,7 +130,7 @@ public class SpawnHelperMixin
return true;
}
@Redirect(method = "method_24931", at = @At(
@Redirect(method = "createMob", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/EntityType;create(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;"
))
@@ -152,7 +149,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;Lnet/minecraft/world/SpawnHelper$class_5261;Lnet/minecraft/world/SpawnHelper$class_5259;)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$Checker;Lnet/minecraft/world/SpawnHelper$Runner;)V", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/world/ServerWorld;spawnEntity(Lnet/minecraft/entity/Entity;)Z"
))
@@ -175,7 +172,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;Lnet/minecraft/world/SpawnHelper$class_5261;Lnet/minecraft/world/SpawnHelper$class_5259;)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$Checker;Lnet/minecraft/world/SpawnHelper$Runner;)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;"
))
@@ -186,7 +183,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;Lnet/minecraft/world/SpawnHelper$class_5261;Lnet/minecraft/world/SpawnHelper$class_5259;)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$Checker;Lnet/minecraft/world/SpawnHelper$Runner;)V", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/player/PlayerEntity;squaredDistanceTo(DDD)D"
))
@@ -203,37 +200,38 @@ public class SpawnHelperMixin
////
@Redirect(method = "method_27821", at = @At(
@Redirect(method = "spawn", 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"
target = "Lnet/minecraft/world/SpawnHelper;spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/world/SpawnHelper$Checker;Lnet/minecraft/world/SpawnHelper$Runner;)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)
private static void spawnMultipleTimes(EntityCategory category, ServerWorld world, WorldChunk chunk, SpawnHelper.Checker checker, SpawnHelper.Runner runner)
{
for (int i = 0; i < SpawnReporter.spawn_tries.get(category); i++)
{
SpawnHelper.spawnEntitiesInChunk(category, world, chunk, arg, arg2);
SpawnHelper.spawnEntitiesInChunk(category, world, chunk, checker, runner);
}
}
/* shrug - why no inject, no idea. need to inject twice more. Will check with the names next week
@Redirect(method = "method_27821", at = @At(
// shrug - why no inject, no idea. need to inject twice more. Will check with the names next week
/*
@Redirect(method = "spawn", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/SpawnHelper$class_5262;method_27826(Lnet/minecraft/entity/EntityCategory;)Z"
target = "Lnet/minecraft/world/SpawnHelper$Info;isBelowCap(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 changeMobcaps(
SpawnHelper.class_5262 class_526, EntityCategory entityCategory,
ServerWorld serverWorld, WorldChunk worldChunk, SpawnHelper.class_5262 arg, boolean bl, boolean bl2, boolean bl3)
SpawnHelper.Info info, EntityCategory entityCategory,
ServerWorld serverWorld, WorldChunk chunk, SpawnHelper.Info info_outer, boolean spawnAnimals, boolean spawnMonsters, boolean shouldSpawnAnimals
)
{
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);
int int_3 = newCap * int_2 / CHUNK_AREA; //current spawning limits
int mobCount = info.getCategoryToCount().getInt(entityCategory);
if (SpawnReporter.track_spawns > 0L && !SpawnReporter.first_chunk_marker.contains(entityCategory))
{
@@ -262,30 +260,31 @@ public class SpawnHelperMixin
//full mobcaps - and key in local_spawns will be missing
}
}
return SpawnReporter.mock_spawns || class_526.method_27830().getInt(entityCategory) < newCap;
return SpawnReporter.mock_spawns || info.getCategoryToCount().getInt(entityCategory) < newCap;
}
*/
*/
//temporary mixin until naming gets fixed
@Inject(method = "method_27821", at = @At("HEAD"))
@Inject(method = "spawn", at = @At("HEAD"))
// allows to change mobcaps and captures each category try per dimension before it fails due to full mobcaps.
private static void checkSpawns(ServerWorld serverWorld, WorldChunk worldChunk, SpawnHelper.class_5262 arg, boolean bl, boolean bl2, boolean bl3, CallbackInfo ci)
private static void checkSpawns(ServerWorld world, WorldChunk chunk, SpawnHelper.Info info,
boolean spawnAnimals, boolean spawnMonsters, boolean shouldSpawnAnimals, CallbackInfo ci)
{
if (SpawnReporter.track_spawns > 0L)
{
EntityCategory[] var6 = field_24393;
EntityCategory[] var6 = SPAWNABLE_CATEGORIES;
int var7 = var6.length;
for(int var8 = 0; var8 < var7; ++var8) {
EntityCategory entityCategory = var6[var8];
if ((bl || !entityCategory.isPeaceful()) && (bl2 || entityCategory.isPeaceful()) && (bl3 || !entityCategory.isAnimal()) )
if ((spawnAnimals || !entityCategory.isPeaceful()) && (spawnMonsters || entityCategory.isPeaceful()) && (shouldSpawnAnimals || !entityCategory.isAnimal()) )
{
DimensionType dim = serverWorld.dimension.getType();
DimensionType dim = world.dimension.getType();
int newCap = (int) ((double)entityCategory.getSpawnCap()*(Math.pow(2.0,(SpawnReporter.mobcap_exponent/4))));
int int_2 = SpawnReporter.chunkCounts.get(dim); // eligible chunks for spawning
int int_3 = newCap * int_2 / field_24392; //current spawning limits
int mobCount = arg.method_27830().getInt(entityCategory);
int int_3 = newCap * int_2 / CHUNK_AREA; //current spawning limits
int mobCount = info.getCategoryToCount().getInt(entityCategory);
if (SpawnReporter.track_spawns > 0L && !SpawnReporter.first_chunk_marker.contains(entityCategory))
{
@@ -910,7 +910,7 @@ public class CarpetExpression
if (playerBreak && state.getHardness(world, where) < 0.0) return LazyValue.FALSE;
boolean removed = world.removeBlock(where, false);
if (!removed) return LazyValue.FALSE;
world.playLevelEvent(null, 2001, where, Block.getRawIdFromState(state));
world.syncWorldEvent(null, 2001, where, Block.getRawIdFromState(state));
boolean toolBroke = false;
boolean dropLoot = true;
@@ -979,7 +979,7 @@ public class CarpetExpression
if (!((block == Blocks.BEDROCK || block == Blocks.BARRIER) && player.interactionManager.isSurvivalLike()))
success = tryBreakBlock_copy_from_ServerPlayerInteractionManager(player, where);
if (success)
world.playLevelEvent(null, 2001, where, Block.getRawIdFromState(state));
world.syncWorldEvent(null, 2001, where, Block.getRawIdFromState(state));
return success ? LazyValue.TRUE : LazyValue.FALSE;
});
@@ -1356,11 +1356,11 @@ public class CarpetExpression
double required_charge = 1;
if (lv.size() > locator.offset)
required_charge = NumericValue.asNumber(lv.get(locator.offset).evalValue(c)).getDouble();
SpawnHelper.class_5262 charger = cc.s.getWorld().getChunkManager().method_27908();
SpawnHelper.Info charger = cc.s.getWorld().getChunkManager().getSpawnInfo();
if (charger == null) return LazyValue.NULL;
Value ret = new NumericValue(
((SpawnHelperInnerInterface)charger).getPotentialCalculator().
method_27832(pos, required_charge )
calculate(pos, required_charge )
);
return (_c, _t) -> ret;
});
@@ -88,8 +88,8 @@ public class SpawnReporter
List<BaseText> lst = new ArrayList<>();
if (multiline)
lst.add(Messenger.s(String.format("Mobcaps for %s:",name)));
SpawnHelper.class_5262 lastSpawner = world.getChunkManager().method_27908();
Object2IntMap<EntityCategory> dimCounts = lastSpawner.method_27830();
SpawnHelper.Info lastSpawner = world.getChunkManager().getSpawnInfo();
Object2IntMap<EntityCategory> dimCounts = lastSpawner.getCategoryToCount();
int chunkcount = chunkCounts.getOrDefault(dim, -1);
if (dimCounts == null || chunkcount < 0)
{