Search in sources :

Example 1 with TileEntityActivationCategory

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

the class TileEntityActivation method addTileEntityToConfig.

public static void addTileEntityToConfig(World world, SpongeTileEntityType type) {
    checkNotNull(world, "world");
    checkNotNull(type, "type");
    SpongeConfig<? extends GeneralConfigBase> config = ((IMixinWorldServer) world).getActiveConfig();
    if (config == null || type == null || !config.getConfig().getTileEntityActivationRange().autoPopulateData()) {
        return;
    }
    boolean requiresSave = false;
    final String tileModId = type.getModId().toLowerCase();
    TileEntityActivationCategory activationCategory = config.getConfig().getTileEntityActivationRange();
    TileEntityActivationModCategory tileEntityMod = activationCategory.getModList().get(tileModId);
    int defaultRange = activationCategory.getDefaultBlockRange();
    int defaultTickRate = activationCategory.getDefaultTickRate();
    if (tileEntityMod == null) {
        tileEntityMod = new TileEntityActivationModCategory(tileModId);
        activationCategory.getModList().put(tileModId, tileEntityMod);
        requiresSave = true;
    }
    if (tileEntityMod != null) {
        // check for tileentity range overrides
        final String tileId = type.getName().toLowerCase();
        Integer tileEntityActivationRange = tileEntityMod.getTileEntityRangeList().get(tileId);
        Integer modDefaultRange = tileEntityMod.getDefaultBlockRange();
        if (modDefaultRange == null) {
            modDefaultRange = defaultRange;
        }
        if (tileEntityActivationRange == null) {
            tileEntityMod.getTileEntityRangeList().put(tileId, modDefaultRange);
            requiresSave = true;
        }
        // check for tileentity tick rate overrides
        Integer modDefaultTickRate = tileEntityMod.getDefaultTickRate();
        if (modDefaultTickRate == null) {
            modDefaultTickRate = defaultTickRate;
        }
        Integer tileEntityActivationTickRate = tileEntityMod.getTileEntityTickRateList().get(tileId);
        if (tileEntityActivationTickRate == null) {
            tileEntityMod.getTileEntityTickRateList().put(tileId, modDefaultTickRate);
            requiresSave = true;
        }
    }
    if (requiresSave) {
        config.save();
    }
}
Also used : TileEntityActivationModCategory(org.spongepowered.common.config.category.TileEntityActivationModCategory) TileEntityActivationCategory(org.spongepowered.common.config.category.TileEntityActivationCategory) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer)

Example 2 with TileEntityActivationCategory

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

the class TileEntityActivation method initializeTileEntityActivationState.

/**
 * These tileentities are excluded from Activation range checks.
 *
 * @param tileEntity The tileentity to check
 * @return boolean If it should always tick.
 */
public static boolean initializeTileEntityActivationState(TileEntity tileEntity) {
    if (tileEntity.getWorld() == null || tileEntity.getWorld().isRemote || !(tileEntity instanceof ITickable)) {
        return true;
    }
    TileEntityActivationCategory config = ((IMixinWorldServer) tileEntity.getWorld()).getActiveConfig().getConfig().getTileEntityActivationRange();
    TileEntityType type = ((org.spongepowered.api.block.tileentity.TileEntity) tileEntity).getType();
    IModData_Activation spongeTileEntity = (IModData_Activation) tileEntity;
    SpongeTileEntityType spongeType = (SpongeTileEntityType) type;
    if (spongeType == null || spongeType.getModId() == null) {
        return true;
    }
    TileEntityActivationModCategory tileEntityMod = config.getModList().get(spongeType.getModId().toLowerCase());
    int defaultActivationRange = config.getDefaultBlockRange();
    int defaultTickRate = config.getDefaultTickRate();
    if (tileEntityMod == null) {
        // use default activation range
        spongeTileEntity.setActivationRange(defaultActivationRange);
        if (defaultActivationRange <= 0) {
            return true;
        }
        return false;
    } else if (!tileEntityMod.isEnabled()) {
        spongeTileEntity.setActivationRange(defaultActivationRange);
        spongeTileEntity.setSpongeTickRate(defaultTickRate);
        return true;
    }
    Integer defaultModActivationRange = tileEntityMod.getDefaultBlockRange();
    Integer tileEntityActivationRange = tileEntityMod.getTileEntityRangeList().get(type.getName().toLowerCase());
    if (defaultModActivationRange != null && tileEntityActivationRange == null) {
        spongeTileEntity.setActivationRange(defaultModActivationRange);
        if (defaultModActivationRange <= 0) {
            return true;
        }
    } else if (tileEntityActivationRange != null) {
        spongeTileEntity.setActivationRange(tileEntityActivationRange);
        if (tileEntityActivationRange <= 0) {
            return true;
        }
    }
    Integer defaultModTickRate = tileEntityMod.getDefaultTickRate();
    Integer tileEntityTickRate = tileEntityMod.getTileEntityTickRateList().get(type.getName().toLowerCase());
    if (defaultModTickRate != null && tileEntityTickRate == null) {
        spongeTileEntity.setSpongeTickRate(defaultModTickRate);
        if (defaultModTickRate <= 0) {
            return true;
        }
        return false;
    } else if (tileEntityTickRate != null) {
        spongeTileEntity.setSpongeTickRate(tileEntityTickRate);
        if (tileEntityTickRate <= 0) {
            return true;
        }
    }
    return false;
}
Also used : IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IModData_Activation(org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation) TileEntityActivationModCategory(org.spongepowered.common.config.category.TileEntityActivationModCategory) ITickable(net.minecraft.util.ITickable) SpongeTileEntityType(org.spongepowered.common.data.type.SpongeTileEntityType) SpongeTileEntityType(org.spongepowered.common.data.type.SpongeTileEntityType) TileEntityType(org.spongepowered.api.block.tileentity.TileEntityType) TileEntityActivationCategory(org.spongepowered.common.config.category.TileEntityActivationCategory) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer)

Aggregations

TileEntityActivationCategory (org.spongepowered.common.config.category.TileEntityActivationCategory)2 TileEntityActivationModCategory (org.spongepowered.common.config.category.TileEntityActivationModCategory)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 TileEntity (net.minecraft.tileentity.TileEntity)1 ITickable (net.minecraft.util.ITickable)1 TileEntityType (org.spongepowered.api.block.tileentity.TileEntityType)1 SpongeTileEntityType (org.spongepowered.common.data.type.SpongeTileEntityType)1 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)1 IModData_Activation (org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation)1