Search in sources :

Example 1 with MobDescriptor

use of mcjty.rftools.dimension.description.MobDescriptor in project RFTools by McJty.

the class SpawnerTileEntity method checkStateServer.

@Override
protected void checkStateServer() {
    testSyringe();
    if (mobName.isEmpty()) {
        return;
    }
    List<SpawnerConfiguration.MobSpawnAmount> spawnAmounts = SpawnerConfiguration.mobSpawnAmounts.get(mobName);
    for (int i = 0; i < 3; i++) {
        if (matter[i] < spawnAmounts.get(i).getAmount()) {
            // Not enough material yet.
            return;
        }
    }
    // We have enough materials. Check power.
    int rf = SpawnerConfiguration.mobSpawnRf.get(mobName);
    rf = (int) (rf * (2.0f - getInfusedFactor()) / 2.0f);
    if (getEnergyStored(ForgeDirection.DOWN) < rf) {
        return;
    }
    consumeEnergy(rf);
    for (int i = 0; i < 3; i++) {
        matter[i] -= spawnAmounts.get(i).getAmount();
    }
    markDirty();
    // @todo for now, later we may want to support mobs that have no dimlets.
    DimletKey key = new DimletKey(DimletType.DIMLET_MOBS, mobName);
    int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
    ForgeDirection k = BlockTools.getOrientation(meta);
    int sx = xCoord;
    int sy = yCoord;
    int sz = zCoord;
    sx += k.offsetX;
    sy += k.offsetY;
    sz += k.offsetZ;
    // if (entityCheckBox == null) {
    // entityCheckBox = AxisAlignedBB.getBoundingBox(xCoord-9, yCoord-9, zCoord-9, xCoord+sx+10, yCoord+sy+10, zCoord+sz+10);
    // }
    // 
    // int cnt = countEntitiesWithinAABB(entityCheckBox);
    // if (cnt >= SpawnerConfiguration.maxEntitiesAroundSpawner) {
    // return;
    // }
    // 
    MobDescriptor descriptor = DimletObjectMapping.idtoMob.get(key);
    EntityLiving entityLiving;
    try {
        entityLiving = descriptor.getEntityClass().getConstructor(World.class).newInstance(worldObj);
    } catch (InstantiationException e) {
        Logging.logError("Fail to spawn mob: " + mobName);
        return;
    } catch (IllegalAccessException e) {
        Logging.logError("Fail to spawn mob: " + mobName);
        return;
    } catch (InvocationTargetException e) {
        Logging.logError("Fail to spawn mob: " + mobName);
        return;
    } catch (NoSuchMethodException e) {
        Logging.logError("Fail to spawn mob: " + mobName);
        return;
    }
    if (k == ForgeDirection.DOWN) {
        sy -= entityLiving.height - 1;
    }
    entityLiving.setLocationAndAngles(sx + 0.5D, (double) sy, sz + 0.5D, 0.0F, 0.0F);
    worldObj.spawnEntityInWorld(entityLiving);
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DimletKey(mcjty.rftools.items.dimlets.DimletKey) MobDescriptor(mcjty.rftools.dimension.description.MobDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with MobDescriptor

use of mcjty.rftools.dimension.description.MobDescriptor in project RFTools by McJty.

the class MobConfiguration method initModdedMobItem.

private static void initModdedMobItem(Configuration cfg, String entityName, String name, int chance, int mingroup, int maxgroup, int maxentity) {
    Class clazz = (Class) EntityList.stringToClassMapping.get(entityName);
    if (cfg != null) {
        chance = cfg.get(KnownDimletConfiguration.CATEGORY_MOBSPAWNS, name + ".chance", chance).getInt();
        mingroup = cfg.get(KnownDimletConfiguration.CATEGORY_MOBSPAWNS, name + ".mingroup", mingroup).getInt();
        maxgroup = cfg.get(KnownDimletConfiguration.CATEGORY_MOBSPAWNS, name + ".maxgroup", maxgroup).getInt();
        maxentity = cfg.get(KnownDimletConfiguration.CATEGORY_MOBSPAWNS, name + ".maxentity", maxentity).getInt();
    }
    mobClasses.put(name, new MobDescriptor(entityName, clazz, chance, mingroup, maxgroup, maxentity));
}
Also used : MobDescriptor(mcjty.rftools.dimension.description.MobDescriptor)

Example 3 with MobDescriptor

use of mcjty.rftools.dimension.description.MobDescriptor in project RFTools by McJty.

the class DimletRandomizer method setupWeightedRandomList.

static void setupWeightedRandomList() {
    randomDimlets = new WeightedRandomSelector<Integer, DimletKey>();
    setupRarity(randomDimlets, rarity0, rarity1, rarity2, rarity3, rarity4, rarity5, rarity6);
    randomMaterialDimlets = new WeightedRandomSelector<Integer, DimletKey>();
    setupRarity(randomMaterialDimlets, rarity0, rarity1, rarity2, rarity3, rarity4, rarity5, rarity6);
    randomLiquidDimlets = new WeightedRandomSelector<Integer, DimletKey>();
    setupRarity(randomLiquidDimlets, rarity0, rarity1, rarity2, rarity3, rarity4, rarity5, rarity6);
    randomMobDimlets = new WeightedRandomSelector<Integer, DimletKey>();
    setupRarity(randomMobDimlets, rarity0, rarity1, rarity2, rarity3, rarity4, rarity5, rarity6);
    randomStructureDimlets = new WeightedRandomSelector<Integer, DimletKey>();
    setupRarity(randomStructureDimlets, rarity0, rarity1, rarity2, rarity3, rarity4, rarity5, rarity6);
    randomEffectDimlets = new WeightedRandomSelector<Integer, DimletKey>();
    setupRarity(randomEffectDimlets, rarity0, rarity1, rarity2, rarity3, rarity4, rarity5, rarity6);
    randomFeatureDimlets = new WeightedRandomSelector<Integer, DimletKey>();
    setupRarity(randomFeatureDimlets, rarity0, rarity1, rarity2, rarity3, rarity4, rarity5, rarity6);
    for (Map.Entry<DimletKey, DimletEntry> entry : KnownDimletConfiguration.idToDimletEntry.entrySet()) {
        randomDimlets.addItem(entry.getValue().getRarity(), entry.getKey());
        DimletKey key = entry.getValue().getKey();
        if (key.getType() == DimletType.DIMLET_MATERIAL) {
            // Don't add the 'null' material.
            if (DimletObjectMapping.idToBlock.get(key) != null) {
                randomMaterialDimlets.addItem(entry.getValue().getRarity(), entry.getKey());
            }
        } else if (key.getType() == DimletType.DIMLET_LIQUID) {
            // Don't add the 'null' fluid.
            if (DimletObjectMapping.idToFluid.get(key) != null) {
                randomLiquidDimlets.addItem(entry.getValue().getRarity(), entry.getKey());
            }
        } else if (key.getType() == DimletType.DIMLET_MOBS) {
            // Don't add the 'null' mob.
            MobDescriptor descriptor = DimletObjectMapping.idtoMob.get(key);
            if (descriptor != null && descriptor.getEntityClass() != null) {
                randomMobDimlets.addItem(entry.getValue().getRarity(), entry.getKey());
            }
        } else if (key.getType() == DimletType.DIMLET_EFFECT) {
            // Don't add the 'null' effect.
            if (DimletObjectMapping.idToEffectType.get(key) != EffectType.EFFECT_NONE) {
                randomEffectDimlets.addItem(entry.getValue().getRarity(), entry.getKey());
            }
        } else if (key.getType() == DimletType.DIMLET_FEATURE) {
            // Don't add the 'null' feature.
            if (DimletObjectMapping.idToFeatureType.get(key) != FeatureType.FEATURE_NONE) {
                randomFeatureDimlets.addItem(entry.getValue().getRarity(), entry.getKey());
            }
        } else if (key.getType() == DimletType.DIMLET_STRUCTURE) {
            // Don't add the 'null' structure.
            if (DimletObjectMapping.idToStructureType.get(key) != StructureType.STRUCTURE_NONE) {
                randomStructureDimlets.addItem(entry.getValue().getRarity(), entry.getKey());
            }
        }
    }
}
Also used : MobDescriptor(mcjty.rftools.dimension.description.MobDescriptor)

Example 4 with MobDescriptor

use of mcjty.rftools.dimension.description.MobDescriptor in project RFTools by McJty.

the class MobConfiguration method initMobItem.

private static void initMobItem(Configuration cfg, Class<? extends EntityLiving> entity, String name, int chance, int mingroup, int maxgroup, int maxentity) {
    if (cfg != null) {
        chance = cfg.get(KnownDimletConfiguration.CATEGORY_MOBSPAWNS, name + ".chance", chance).getInt();
        mingroup = cfg.get(KnownDimletConfiguration.CATEGORY_MOBSPAWNS, name + ".mingroup", mingroup).getInt();
        maxgroup = cfg.get(KnownDimletConfiguration.CATEGORY_MOBSPAWNS, name + ".maxgroup", maxgroup).getInt();
        maxentity = cfg.get(KnownDimletConfiguration.CATEGORY_MOBSPAWNS, name + ".maxentity", maxentity).getInt();
    }
    mobClasses.put(name, new MobDescriptor(null, entity, chance, mingroup, maxgroup, maxentity));
}
Also used : MobDescriptor(mcjty.rftools.dimension.description.MobDescriptor)

Example 5 with MobDescriptor

use of mcjty.rftools.dimension.description.MobDescriptor in project RFTools by McJty.

the class MobDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    List<MobDescriptor> extraMobs = dimensionInformation.getExtraMobs();
    dimlets = DimensionInformation.extractType(DimletType.DIMLET_MOBS, dimlets);
    if (dimlets.isEmpty()) {
        while (random.nextFloat() < DimletConfiguration.randomExtraMobsChance) {
            DimletKey key = DimletRandomizer.getRandomMob(random, false);
            dimensionInformation.updateCostFactor(key);
            extraMobs.add(DimletObjectMapping.idtoMob.get(key));
        }
    } else {
        DimletKey key = dimlets.get(0).getLeft();
        MobDescriptor mobDescriptor = DimletObjectMapping.idtoMob.get(key);
        if (dimlets.size() == 1 && (mobDescriptor == null || mobDescriptor.getEntityClass() == null)) {
        // Just default.
        } else {
            for (Pair<DimletKey, List<DimletKey>> dimletWithModifiers : dimlets) {
                DimletKey modifierKey = dimletWithModifiers.getLeft();
                MobDescriptor descriptor = DimletObjectMapping.idtoMob.get(modifierKey);
                if (descriptor != null && descriptor.getEntityClass() != null) {
                    extraMobs.add(descriptor);
                }
            }
        }
    }
}
Also used : List(java.util.List) DimletKey(mcjty.rftools.items.dimlets.DimletKey) MobDescriptor(mcjty.rftools.dimension.description.MobDescriptor)

Aggregations

MobDescriptor (mcjty.rftools.dimension.description.MobDescriptor)5 DimletKey (mcjty.rftools.items.dimlets.DimletKey)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 EntityLiving (net.minecraft.entity.EntityLiving)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1