Search in sources :

Example 1 with SpongeTileEntityType

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

Example 2 with SpongeTileEntityType

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);
}
Also used : TileEntityChest(net.minecraft.tileentity.TileEntityChest) SpongeTileEntityType(org.spongepowered.common.data.type.SpongeTileEntityType) SpongeTileEntityType(org.spongepowered.common.data.type.SpongeTileEntityType) TileEntityType(org.spongepowered.api.block.tileentity.TileEntityType) TileEntityEnderChest(net.minecraft.tileentity.TileEntityEnderChest)

Aggregations

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