use of org.spongepowered.common.applaunch.config.common.CommonConfig in project SpongeCommon by SpongePowered.
the class EntityMixin_EntityCollision method collision$initializeCollisionState.
@Override
public void collision$initializeCollisionState(final net.minecraft.world.level.Level world) {
final InheritableConfigHandle<WorldConfig> worldConfigAdapter = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$configAdapter();
final ConfigHandle<CommonConfig> globalConfigAdapter = SpongeConfigs.getCommon();
final EntityCollisionCategory.ModSubCategory worldCollMod = worldConfigAdapter.getOrCreateValue(s -> s.entityCollision.mods.get(this.entityCollision$key.namespace()), c -> {
// TODO: save after populating?
final EntityCollisionCategory.ModSubCategory globalCollision = new EntityCollisionCategory.ModSubCategory(this.entityCollision$key.namespace());
c.entityCollision.mods.put(this.entityCollision$key.namespace(), globalCollision);
globalCollision.entities.put(this.entityCollision$key.namespace(), this.collision$getMaxCollisions());
}, worldConfigAdapter.get().entityCollision.autoPopulate);
final EntityCollisionCategory worldCollCat = worldConfigAdapter.get().entityCollision;
this.collision$setMaxCollisions(worldCollCat.maxEntitiesWithinAABB);
boolean requiresSave = false;
if (worldCollMod != null) {
if (!worldCollMod.enabled) {
this.collision$setMaxCollisions(-1);
return;
}
// check mod overrides
final Integer modCollisionMax = worldCollMod.entityDefault;
if (modCollisionMax != null) {
this.collision$setMaxCollisions(modCollisionMax);
}
Integer entityMaxCollision = null;
if ((net.minecraft.world.entity.Entity) (Object) this instanceof ItemEntity) {
// check if all items are overridden
entityMaxCollision = worldCollMod.entities.get(this.entityCollision$key.value());
}
if (entityMaxCollision == null) {
entityMaxCollision = worldCollMod.entities.get(this.entityCollision$key.value());
}
// entity overrides
if (entityMaxCollision == null && worldCollCat.autoPopulate) {
// TODO(zml): Populate better
// globalCollMod.getEntityList().put(this.entityCollision$key.getValue(), this.collision$getMaxCollisions());
requiresSave = true;
} else if (entityMaxCollision != null) {
this.collision$setMaxCollisions(entityMaxCollision);
}
}
// don't bother saving for negative values
if (this.collision$getMaxCollisions() <= 0) {
return;
}
if (requiresSave) {
globalConfigAdapter.save();
}
}
use of org.spongepowered.common.applaunch.config.common.CommonConfig in project SpongeCommon by SpongePowered.
the class BlockMixin_EntityCollision method collision$initializeCollisionState.
@Override
public void collision$initializeCollisionState(final net.minecraft.world.level.Level world) {
final InheritableConfigHandle<WorldConfig> worldConfigAdapter = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$configAdapter();
final ConfigHandle<CommonConfig> globalConfigAdapter = SpongeConfigs.getCommon();
final EntityCollisionCategory worldCollCat = worldConfigAdapter.get().entityCollision;
this.collision$setMaxCollisions(worldCollCat.maxEntitiesWithinAABB);
boolean requiresSave = false;
String[] ids = Sponge.game().registry(RegistryTypes.BLOCK_TYPE).valueKey((BlockType) this).toString().split(":");
String modId = ids[0];
String name = ids[1];
final EntityCollisionCategory.ModSubCategory worldCollMod = worldConfigAdapter.getOrCreateValue(s -> s.entityCollision.mods.get(modId), c -> {
// TODO: finish after populating?
final EntityCollisionCategory.ModSubCategory globalCollision = new EntityCollisionCategory.ModSubCategory(modId);
c.entityCollision.mods.put(modId, globalCollision);
globalCollision.blocks.put(name, this.collision$getMaxCollisions());
}, worldCollCat.autoPopulate);
if (worldCollMod != null) {
if (!worldCollMod.enabled) {
this.collision$setMaxCollisions(-1);
return;
}
// check mod overrides
Integer modCollisionMax = worldCollMod.blockDefault;
if (modCollisionMax != null) {
this.collision$setMaxCollisions(modCollisionMax);
}
// entity overrides
Integer blockMaxCollision = worldCollMod.blocks.get(name);
if (blockMaxCollision == null && worldCollCat.autoPopulate) {
worldCollMod.blocks.put(name, this.collision$getMaxCollisions());
requiresSave = true;
} else if (blockMaxCollision != null) {
this.collision$setMaxCollisions(blockMaxCollision);
}
}
// don't bother saving for negative values
if (this.collision$getMaxCollisions() <= 0) {
return;
}
if (requiresSave) {
globalConfigAdapter.save();
}
}
use of org.spongepowered.common.applaunch.config.common.CommonConfig in project SpongeCommon by SpongePowered.
the class PhasePrinter method checkMaxBlockProcessingDepth.
static boolean checkMaxBlockProcessingDepth(final IPhaseState<@NonNull ?> state, final PhaseContext<@NonNull ?> context, final int currentDepth) {
final ConfigHandle<CommonConfig> globalConfigAdapter = SpongeConfigs.getCommon();
final PhaseTrackerCategory trackerConfig = globalConfigAdapter.get().phaseTracker;
int maxDepth = trackerConfig.maxBlockProcessingDepth;
if (currentDepth < maxDepth) {
return false;
}
if (!trackerConfig.verbose && PhasePrinter.printedExceptionForMaximumProcessDepth.contains(state)) {
// We still want to abort processing even if we're not logigng an error
return true;
}
PhasePrinter.printedExceptionForMaximumProcessDepth.add(state);
final String message = String.format("Sponge is still trying to process captured blocks after %s iterations of depth-first processing." + " This is likely due to a mod doing something unusual.", currentDepth);
PhasePrinter.printMessageWithCaughtException(PhasePrinter.EMPTY, "Maximum block processing depth exceeded!", message, state, context, null);
return true;
}
Aggregations