use of org.spongepowered.common.config.inheritable.EntityCollisionCategory 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.config.inheritable.EntityCollisionCategory 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();
}
}
Aggregations