Search in sources :

Example 6 with IMixinWorld

use of org.spongepowered.common.interfaces.world.IMixinWorld in project SpongeCommon by SpongePowered.

the class EntityActivationRange method initializeEntityActivationState.

/**
 * These entities are excluded from Activation range checks.
 *
 * @param entity Entity to check
 * @return boolean If it should always tick.
 */
public static boolean initializeEntityActivationState(Entity entity) {
    if (((IMixinWorld) entity.world).isFake()) {
        return true;
    }
    // types that should always be active
    if (entity instanceof EntityPlayer && !SpongeImplHooks.isFakePlayer(entity) || entity instanceof EntityThrowable || entity instanceof EntityDragon || entity instanceof MultiPartEntityPart || entity instanceof EntityWither || entity instanceof EntityFireball || entity instanceof EntityWeatherEffect || entity instanceof EntityTNTPrimed || entity instanceof EntityEnderCrystal || entity instanceof EntityFireworkRocket || // Always tick falling blocks
    entity instanceof EntityFallingBlock) {
        return true;
    }
    EntityActivationRangeCategory config = ((IMixinWorldServer) entity.world).getActiveConfig().getConfig().getEntityActivationRange();
    EntityType type = ((org.spongepowered.api.entity.Entity) entity).getType();
    IModData_Activation spongeEntity = (IModData_Activation) entity;
    if (type == EntityTypes.UNKNOWN || !(type instanceof SpongeEntityType)) {
        return false;
    }
    final SpongeEntityType spongeType = (SpongeEntityType) type;
    final byte activationType = spongeEntity.getActivationType();
    if (!spongeType.isActivationRangeInitialized()) {
        addEntityToConfig(entity.world, spongeType, activationType);
        spongeType.setActivationRangeInitialized(true);
    }
    EntityActivationModCategory entityMod = config.getModList().get(spongeType.getModId().toLowerCase());
    int defaultActivationRange = config.getDefaultRanges().get(activationTypeMappings.get(activationType));
    if (entityMod == null) {
        // use default activation range
        spongeEntity.setActivationRange(defaultActivationRange);
        if (defaultActivationRange <= 0) {
            return true;
        }
        return false;
    } else if (!entityMod.isEnabled()) {
        spongeEntity.setActivationRange(defaultActivationRange);
        return true;
    }
    Integer defaultModActivationRange = entityMod.getDefaultRanges().get(activationTypeMappings.get(activationType));
    Integer entityActivationRange = entityMod.getEntityList().get(type.getName().toLowerCase());
    if (defaultModActivationRange != null && entityActivationRange == null) {
        spongeEntity.setActivationRange(defaultModActivationRange);
        if (defaultModActivationRange <= 0) {
            return true;
        }
        return false;
    } else if (entityActivationRange != null) {
        spongeEntity.setActivationRange(entityActivationRange);
        if (entityActivationRange <= 0) {
            return true;
        }
    }
    return false;
}
Also used : EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) EntityDragon(net.minecraft.entity.boss.EntityDragon) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Entity(net.minecraft.entity.Entity) IModData_Activation(org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) EntityWeatherEffect(net.minecraft.entity.effect.EntityWeatherEffect) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityType(org.spongepowered.api.entity.EntityType) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) EntityFireworkRocket(net.minecraft.entity.item.EntityFireworkRocket) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityWither(net.minecraft.entity.boss.EntityWither) EntityActivationRangeCategory(org.spongepowered.common.config.category.EntityActivationRangeCategory) EntityActivationModCategory(org.spongepowered.common.config.category.EntityActivationModCategory) EntityFireball(net.minecraft.entity.projectile.EntityFireball)

Example 7 with IMixinWorld

use of org.spongepowered.common.interfaces.world.IMixinWorld in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method callWorldSaveEvent.

private static SaveWorldEvent callWorldSaveEvent(Event event) {
    SaveWorldEvent spongeEvent = (SaveWorldEvent) event;
    // Since Forge only uses a single save handler, we need to make sure to pass the overworld's handler.
    // This makes sure that mods dont attempt to save/read their data from the wrong location.
    ((IMixinWorld) spongeEvent.getTargetWorld()).setCallingWorldEvent(true);
    ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(new WorldEvent.Save((net.minecraft.world.World) spongeEvent.getTargetWorld()), true);
    ((IMixinWorld) spongeEvent.getTargetWorld()).setCallingWorldEvent(false);
    return spongeEvent;
}
Also used : IMixinEventBus(org.spongepowered.mod.interfaces.IMixinEventBus) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) LoadWorldEvent(org.spongepowered.api.event.world.LoadWorldEvent) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) UnloadWorldEvent(org.spongepowered.api.event.world.UnloadWorldEvent) WorldEvent(net.minecraftforge.event.world.WorldEvent) SaveWorldEvent(org.spongepowered.api.event.world.SaveWorldEvent) TargetWorldEvent(org.spongepowered.api.event.world.TargetWorldEvent) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) SaveWorldEvent(org.spongepowered.api.event.world.SaveWorldEvent)

Aggregations

IMixinWorld (org.spongepowered.common.interfaces.world.IMixinWorld)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 World (org.spongepowered.api.world.World)3 Entity (net.minecraft.entity.Entity)2 BlockPos (net.minecraft.util.math.BlockPos)2 EntityJoinWorldEvent (net.minecraftforge.event.entity.EntityJoinWorldEvent)2 WorldEvent (net.minecraftforge.event.world.WorldEvent)2 LoadWorldEvent (org.spongepowered.api.event.world.LoadWorldEvent)2 SaveWorldEvent (org.spongepowered.api.event.world.SaveWorldEvent)2 TargetWorldEvent (org.spongepowered.api.event.world.TargetWorldEvent)2 UnloadWorldEvent (org.spongepowered.api.event.world.UnloadWorldEvent)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)2 IModData_Activation (org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation)2 IMixinEventBus (org.spongepowered.mod.interfaces.IMixinEventBus)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 IBlockState (net.minecraft.block.state.IBlockState)1 MultiPartEntityPart (net.minecraft.entity.MultiPartEntityPart)1 EntityDragon (net.minecraft.entity.boss.EntityDragon)1