use of org.spongepowered.common.data.type.SpongeTileEntityType 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;
}
use of org.spongepowered.common.data.type.SpongeTileEntityType in project SpongeCommon by SpongePowered.
the class TileEntityTypeRegistryModule method doTileEntityRegistration.
@SuppressWarnings("unchecked")
public void doTileEntityRegistration(Class<?> clazz, String name) {
final String id = TileEntityTypeRegistryModule.getInstance().getIdForName(name);
boolean canTick = true;
try {
if (ITickable.class.isAssignableFrom(clazz)) {
String mapping = SpongeImplHooks.isDeobfuscatedEnvironment() ? "update" : "func_73660_a";
Class<?> declaringClazz = clazz.getMethod(mapping).getDeclaringClass();
if (declaringClazz.equals(TileEntityChest.class) || declaringClazz.equals(TileEntityEnderChest.class)) {
canTick = false;
}
}
} catch (Throwable e) {
// ignore
}
final String modId = SpongeImplHooks.getModIdFromClass(clazz);
final String tileId = modId + ":" + id;
final TileEntityType tileEntityType = new SpongeTileEntityType((Class<? extends org.spongepowered.api.block.tileentity.TileEntity>) clazz, name, tileId, canTick, modId);
TileEntityTypeRegistryModule.getInstance().registerAdditionalCatalog(tileEntityType);
}
Aggregations