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();
}
}
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;
}
Aggregations