Search in sources :

Example 16 with IMixinWorldServer

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

the class MixinBlock_Collisions method initializeCollisionState.

@Override
public void initializeCollisionState(World worldIn) {
    SpongeConfig<? extends GeneralConfigBase> activeConfig = ((IMixinWorldServer) worldIn).getActiveConfig();
    EntityCollisionCategory collisionCat = activeConfig.getConfig().getEntityCollisionCategory();
    this.setMaxCollisions(collisionCat.getMaxEntitiesWithinAABB());
    String[] ids = ((BlockType) this).getId().split(":");
    String modId = ids[0];
    String name = ids[1];
    CollisionModCategory collisionMod = collisionCat.getModList().get(modId);
    if (collisionMod == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
        collisionMod = new CollisionModCategory(modId);
        collisionCat.getModList().put(modId, collisionMod);
        collisionMod.getBlockList().put(name, this.getMaxCollisions());
        if (activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
            activeConfig.save();
        }
        return;
    } else if (collisionMod != null) {
        if (!collisionMod.isEnabled()) {
            this.setMaxCollisions(-1);
            return;
        }
        // check mod overrides
        Integer modCollisionMax = collisionMod.getDefaultMaxCollisions().get("blocks");
        if (modCollisionMax != null) {
            this.setMaxCollisions(modCollisionMax);
        }
        Integer blockMaxCollision = collisionMod.getBlockList().get(name);
        // entity overrides
        if (blockMaxCollision == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
            collisionMod.getBlockList().put(name, this.getMaxCollisions());
        } else if (blockMaxCollision != null) {
            this.setMaxCollisions(blockMaxCollision);
        }
    }
    if (this.getMaxCollisions() <= 0) {
        return;
    }
    if (activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
        activeConfig.save();
    }
}
Also used : CollisionModCategory(org.spongepowered.common.config.category.CollisionModCategory) EntityCollisionCategory(org.spongepowered.common.config.category.EntityCollisionCategory) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer)

Example 17 with IMixinWorldServer

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

the class MixinChunk_Collisions method allowEntityCollision.

private <T extends Entity> boolean allowEntityCollision(List<T> listToFill) {
    if (this.world instanceof IMixinWorldServer) {
        IMixinWorldServer spongeWorld = (IMixinWorldServer) this.world;
        if (spongeWorld.isProcessingExplosion()) {
            // allow explosions
            return true;
        }
        final PhaseContext<?> phaseContext = PhaseTracker.getInstance().getCurrentContext();
        LocatableBlock locatable = phaseContext.getSource(LocatableBlock.class).orElse(null);
        if (locatable != null) {
            BlockType blockType = locatable.getLocation().getBlockType();
            IModData_Collisions spongeBlock = (IModData_Collisions) blockType;
            if (spongeBlock.requiresCollisionsCacheRefresh()) {
                spongeBlock.initializeCollisionState(this.world);
                spongeBlock.requiresCollisionsCacheRefresh(false);
            }
            return !((spongeBlock.getMaxCollisions() >= 0) && (listToFill.size() >= spongeBlock.getMaxCollisions()));
        }
        IModData_Collisions spongeEntity = phaseContext.getSource(IModData_Collisions.class).orElse(null);
        if (spongeEntity != null) {
            if (spongeEntity.requiresCollisionsCacheRefresh()) {
                spongeEntity.initializeCollisionState(this.world);
                spongeEntity.requiresCollisionsCacheRefresh(false);
            }
            return !((spongeEntity.getMaxCollisions() >= 0) && (listToFill.size() >= spongeEntity.getMaxCollisions()));
        }
        return true;
    }
    return true;
}
Also used : IModData_Collisions(org.spongepowered.common.mixin.plugin.entitycollisions.interfaces.IModData_Collisions) BlockType(org.spongepowered.api.block.BlockType) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) LocatableBlock(org.spongepowered.api.world.LocatableBlock)

Example 18 with IMixinWorldServer

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

the class MixinChunk_Async_Lighting method checkWorldLight.

/**
 * Checks world light async.
 *
 * @param pos The block position
 * @param neighbors A thread-safe list of surrounding neighbor chunks
 * @return True if light update was successful, false if not
 */
private boolean checkWorldLight(BlockPos pos, List<Chunk> neighbors) {
    boolean flag = false;
    final Chunk chunk = this.getLightChunk(pos.getX() >> 4, pos.getZ() >> 4, neighbors);
    if (chunk == null) {
        return false;
    }
    if (this.world.provider.hasSkyLight()) {
        flag |= ((IMixinWorldServer) this.world).updateLightAsync(EnumSkyBlock.SKY, pos, (Chunk) (Object) chunk);
    }
    flag = flag | ((IMixinWorldServer) this.world).updateLightAsync(EnumSkyBlock.BLOCK, pos, (Chunk) (Object) chunk);
    return flag;
}
Also used : IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk)

Example 19 with IMixinWorldServer

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

the class EntityActivationRange method addEntityToConfig.

public static void addEntityToConfig(World world, SpongeEntityType type, byte activationType) {
    checkNotNull(world, "world");
    checkNotNull(type, "type");
    SpongeConfig<? extends GeneralConfigBase> config = ((IMixinWorldServer) world).getActiveConfig();
    if (config == null || type == null) {
        return;
    }
    final boolean autoPopulate = config.getConfig().getEntityActivationRange().autoPopulateData();
    boolean requiresSave = false;
    String entityType = "misc";
    entityType = EntityActivationRange.activationTypeMappings.get(activationType);
    final String entityModId = type.getModId().toLowerCase();
    final String entityId = type.getName().toLowerCase();
    EntityActivationRangeCategory activationCategory = config.getConfig().getEntityActivationRange();
    EntityActivationModCategory entityMod = activationCategory.getModList().get(entityModId);
    Integer defaultActivationRange = activationCategory.getDefaultRanges().get(entityType);
    if (defaultActivationRange == null) {
        defaultActivationRange = 32;
    }
    Integer activationRange = activationCategory.getDefaultRanges().get(entityType);
    if (autoPopulate && entityMod == null) {
        entityMod = new EntityActivationModCategory();
        activationCategory.getModList().put(entityModId, entityMod);
        requiresSave = true;
    }
    if (entityMod != null) {
        final Integer modActivationRange = entityMod.getDefaultRanges().get(entityType);
        if (autoPopulate && modActivationRange == null) {
            entityMod.getDefaultRanges().put(entityType, defaultActivationRange);
            requiresSave = true;
        } else if (modActivationRange != null && modActivationRange > activationRange) {
            activationRange = modActivationRange;
        }
        final Integer entityActivationRange = entityMod.getEntityList().get(entityId);
        if (autoPopulate && entityActivationRange == null) {
            entityMod.getEntityList().put(entityId, entityMod.getDefaultRanges().get(entityType));
            requiresSave = true;
        }
        if (entityActivationRange != null && entityActivationRange > activationRange) {
            activationRange = entityActivationRange;
        }
    }
    // check max ranges
    Integer maxRange = maxActivationRanges.get(activationType);
    if (maxRange == null) {
        maxActivationRanges.put(activationType, activationRange);
    } else if (activationRange > maxRange) {
        maxActivationRanges.put(activationType, activationRange);
    }
    if (autoPopulate && requiresSave) {
        config.save();
    }
}
Also used : IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) EntityActivationRangeCategory(org.spongepowered.common.config.category.EntityActivationRangeCategory) EntityActivationModCategory(org.spongepowered.common.config.category.EntityActivationModCategory)

Example 20 with IMixinWorldServer

use of org.spongepowered.common.interfaces.world.IMixinWorldServer 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)

Aggregations

IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)61 WorldServer (net.minecraft.world.WorldServer)25 BlockPos (net.minecraft.util.math.BlockPos)19 ArrayList (java.util.ArrayList)17 Entity (org.spongepowered.api.entity.Entity)15 World (org.spongepowered.api.world.World)15 IBlockState (net.minecraft.block.state.IBlockState)13 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)13 CauseStackManager (org.spongepowered.api.event.CauseStackManager)11 Overwrite (org.spongepowered.asm.mixin.Overwrite)11 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)9 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)9 EntityItem (net.minecraft.entity.item.EntityItem)8 User (org.spongepowered.api.entity.living.player.User)8 LocatableBlock (org.spongepowered.api.world.LocatableBlock)8 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)7 Entity (net.minecraft.entity.Entity)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 Chunk (net.minecraft.world.chunk.Chunk)6 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)6