Search in sources :

Example 1 with CollisionModCategory

use of org.spongepowered.common.config.category.CollisionModCategory in project SpongeCommon by SpongePowered.

the class MixinBlock_Collisions method initializeCollisionState.

@Override
public void initializeCollisionState(World worldIn) {
    SpongeConfig<? extends GeneralConfigBase> activeConfig = ((IMixinWorldServer) worldIn).getActiveConfig();
    EntityCollisionCategory collisionCat = activeConfig.getConfig().getEntityCollisionCategory();
    this.setMaxCollisions(collisionCat.getMaxEntitiesWithinAABB());
    String[] ids = ((BlockType) this).getId().split(":");
    String modId = ids[0];
    String name = ids[1];
    CollisionModCategory collisionMod = collisionCat.getModList().get(modId);
    if (collisionMod == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
        collisionMod = new CollisionModCategory(modId);
        collisionCat.getModList().put(modId, collisionMod);
        collisionMod.getBlockList().put(name, this.getMaxCollisions());
        if (activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
            activeConfig.save();
        }
        return;
    } else if (collisionMod != null) {
        if (!collisionMod.isEnabled()) {
            this.setMaxCollisions(-1);
            return;
        }
        // check mod overrides
        Integer modCollisionMax = collisionMod.getDefaultMaxCollisions().get("blocks");
        if (modCollisionMax != null) {
            this.setMaxCollisions(modCollisionMax);
        }
        Integer blockMaxCollision = collisionMod.getBlockList().get(name);
        // entity overrides
        if (blockMaxCollision == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
            collisionMod.getBlockList().put(name, this.getMaxCollisions());
        } else if (blockMaxCollision != null) {
            this.setMaxCollisions(blockMaxCollision);
        }
    }
    if (this.getMaxCollisions() <= 0) {
        return;
    }
    if (activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
        activeConfig.save();
    }
}
Also used : CollisionModCategory(org.spongepowered.common.config.category.CollisionModCategory) EntityCollisionCategory(org.spongepowered.common.config.category.EntityCollisionCategory) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer)

Example 2 with CollisionModCategory

use of org.spongepowered.common.config.category.CollisionModCategory in project SpongeCommon by SpongePowered.

the class MixinEntity_Collisions method initializeCollisionState.

@Override
public void initializeCollisionState(World worldObj) {
    SpongeConfig<? extends GeneralConfigBase> activeConfig = ((IMixinWorldServer) worldObj).getActiveConfig();
    EntityCollisionCategory collisionCat = activeConfig.getConfig().getEntityCollisionCategory();
    this.maxCollisions = collisionCat.getMaxEntitiesWithinAABB();
    boolean requiresSave = false;
    CollisionModCategory collisionMod = collisionCat.getModList().get(this.entityModId);
    if (collisionMod == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
        collisionMod = new CollisionModCategory(this.entityModId);
        collisionCat.getModList().put(this.entityModId, collisionMod);
        collisionMod.getEntityList().put(this.entityName, this.maxCollisions);
        activeConfig.save();
        return;
    } else if (collisionMod != null) {
        if (!collisionMod.isEnabled()) {
            this.maxCollisions = -1;
            return;
        }
        // check mod overrides
        Integer modCollisionMax = collisionMod.getDefaultMaxCollisions().get("entities");
        if (modCollisionMax != null) {
            this.maxCollisions = modCollisionMax;
        }
        Integer entityMaxCollision = null;
        if ((Object) this instanceof EntityItem) {
            // check if all items are overridden
            entityMaxCollision = collisionMod.getEntityList().get(this.spongeEntityType.getName());
        }
        if (entityMaxCollision == null) {
            entityMaxCollision = collisionMod.getEntityList().get(this.entityName);
        }
        // entity overrides
        if (entityMaxCollision == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
            collisionMod.getEntityList().put(this.entityName, this.maxCollisions);
            requiresSave = true;
        } else if (entityMaxCollision != null) {
            this.maxCollisions = entityMaxCollision;
        }
    }
    if (this.maxCollisions <= 0) {
        return;
    }
    if (requiresSave && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
        activeConfig.save();
    }
    return;
}
Also used : CollisionModCategory(org.spongepowered.common.config.category.CollisionModCategory) EntityCollisionCategory(org.spongepowered.common.config.category.EntityCollisionCategory) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

CollisionModCategory (org.spongepowered.common.config.category.CollisionModCategory)2 EntityCollisionCategory (org.spongepowered.common.config.category.EntityCollisionCategory)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 EntityItem (net.minecraft.entity.item.EntityItem)1