Search in sources :

Example 6 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey 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 7 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools by McJty.

the class SkyDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    dimlets = DimensionInformation.extractType(DimletType.DIMLET_SKY, dimlets);
    if (dimlets.isEmpty()) {
        if (random.nextFloat() < DimletConfiguration.randomSpecialSkyChance) {
            // If nothing was specified then there is random chance we get random sky stuff.
            List<DimletKey> skyIds = new ArrayList<DimletKey>(DimletObjectMapping.idToSkyDescriptor.keySet());
            for (int i = 0; i < 1 + random.nextInt(3); i++) {
                DimletKey key = skyIds.get(random.nextInt(skyIds.size()));
                List<DimletKey> modifiers = Collections.emptyList();
                dimlets.add(Pair.of(key, modifiers));
            }
        }
        if (random.nextFloat() < DimletConfiguration.randomSpecialSkyChance) {
            List<DimletKey> bodyKeys = new ArrayList<DimletKey>();
            for (DimletKey key : DimletObjectMapping.idToSkyDescriptor.keySet()) {
                if (DimletObjectMapping.celestialBodies.contains(key)) {
                    bodyKeys.add(key);
                }
            }
            for (int i = 0; i < random.nextInt(3); i++) {
                DimletKey key = bodyKeys.get(random.nextInt(bodyKeys.size()));
                List<DimletKey> modifiers = Collections.emptyList();
                dimlets.add(Pair.of(key, modifiers));
            }
        }
    }
    SkyDescriptor.Builder builder = new SkyDescriptor.Builder();
    for (Pair<DimletKey, List<DimletKey>> dimletWithModifiers : dimlets) {
        DimletKey key = dimletWithModifiers.getKey();
        builder.combine(DimletObjectMapping.idToSkyDescriptor.get(key));
    }
    if (dimensionInformation.isPatreonBitSet(Patreons.PATREON_DARKCORVUS)) {
        builder.skyType(SkyType.SKY_STARS3);
    }
    dimensionInformation.setSkyDescriptor(builder.build());
}
Also used : ArrayList(java.util.ArrayList) SkyDescriptor(mcjty.rftools.dimension.description.SkyDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) DimletKey(mcjty.rftools.items.dimlets.DimletKey)

Example 8 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools by McJty.

the class DimletTypeItemSorter method getDimletType.

private static DimletType getDimletType(Pair<ItemStack, Integer> object) {
    DimletType type = null;
    if (object.getKey().getItem() == DimletSetup.knownDimlet) {
        DimletKey key = KnownDimletConfiguration.getDimletKey(object.getKey(), null);
        type = key.getType();
    }
    return type;
}
Also used : DimletType(mcjty.rftools.items.dimlets.DimletType) DimletKey(mcjty.rftools.items.dimlets.DimletKey)

Example 9 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools by McJty.

the class DimletRarityItemSorter method getRarity.

private int getRarity(Pair<ItemStack, Integer> object) {
    int rarity = -1;
    if (object.getKey().getItem() == DimletSetup.knownDimlet) {
        DimletKey key = KnownDimletConfiguration.getDimletKey(object.getKey(), null);
        DimletEntry entry = KnownDimletConfiguration.getEntry(key);
        if (entry != null) {
            rarity = entry.getRarity();
        }
    }
    return rarity;
}
Also used : DimletEntry(mcjty.rftools.items.dimlets.DimletEntry) DimletKey(mcjty.rftools.items.dimlets.DimletKey)

Example 10 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools by McJty.

the class BiomeDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    Set<DimletKey> biomeKeys = new HashSet<DimletKey>();
    List<Pair<DimletKey, List<DimletKey>>> biomeDimlets = DimensionInformation.extractType(DimletType.DIMLET_BIOME, dimlets);
    List<Pair<DimletKey, List<DimletKey>>> controllerDimlets = DimensionInformation.extractType(DimletType.DIMLET_CONTROLLER, dimlets);
    ControllerType controllerType;
    // First determine the controller to use.
    if (controllerDimlets.isEmpty()) {
        if (random.nextFloat() < DimletConfiguration.randomControllerChance) {
            List<DimletKey> keys = new ArrayList<DimletKey>(DimletObjectMapping.idToControllerType.keySet());
            DimletKey key = keys.get(random.nextInt(keys.size()));
            controllerType = DimletObjectMapping.idToControllerType.get(key);
        } else {
            if (biomeDimlets.isEmpty()) {
                controllerType = ControllerType.CONTROLLER_DEFAULT;
            } else if (biomeDimlets.size() > 1) {
                controllerType = ControllerType.CONTROLLER_FILTERED;
            } else {
                controllerType = ControllerType.CONTROLLER_SINGLE;
            }
        }
    } else {
        DimletKey key = controllerDimlets.get(random.nextInt(controllerDimlets.size())).getLeft();
        controllerType = DimletObjectMapping.idToControllerType.get(key);
    }
    dimensionInformation.setControllerType(controllerType);
    // Now see if we have to add or randomize biomes.
    for (Pair<DimletKey, List<DimletKey>> dimletWithModifiers : biomeDimlets) {
        DimletKey key = dimletWithModifiers.getKey();
        biomeKeys.add(key);
    }
    int neededBiomes = controllerType.getNeededBiomes();
    if (neededBiomes == -1) {
        // Can work with any number of biomes.
        if (biomeKeys.size() >= 2) {
            // We already have enough biomes
            neededBiomes = biomeKeys.size();
        } else {
            neededBiomes = random.nextInt(10) + 3;
        }
    }
    while (biomeKeys.size() < neededBiomes) {
        DimletKey key;
        List<DimletKey> keys = new ArrayList<DimletKey>(DimletObjectMapping.idToBiome.keySet());
        key = keys.get(random.nextInt(keys.size()));
        while (biomeKeys.contains(key)) {
            key = keys.get(random.nextInt(keys.size()));
        }
        biomeKeys.add(key);
    }
    List<BiomeGenBase> biomes = dimensionInformation.getBiomes();
    biomes.clear();
    for (DimletKey key : biomeKeys) {
        biomes.add(DimletObjectMapping.idToBiome.get(key));
    }
}
Also used : DimletKey(mcjty.rftools.items.dimlets.DimletKey) ControllerType(mcjty.rftools.dimension.world.types.ControllerType) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

DimletKey (mcjty.rftools.items.dimlets.DimletKey)37 ItemStack (net.minecraft.item.ItemStack)9 List (java.util.List)7 ArrayList (java.util.ArrayList)6 DimletEntry (mcjty.rftools.items.dimlets.DimletEntry)5 Block (net.minecraft.block.Block)4 BlockMeta (mcjty.lib.varia.BlockMeta)3 TerrainType (mcjty.rftools.dimension.world.types.TerrainType)3 Slot (net.minecraft.inventory.Slot)3 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 Map (java.util.Map)2 MobDescriptor (mcjty.rftools.dimension.description.MobDescriptor)2 ControllerType (mcjty.rftools.dimension.world.types.ControllerType)2 FeatureType (mcjty.rftools.dimension.world.types.FeatureType)2 DimletType (mcjty.rftools.items.dimlets.DimletType)2 MerchantRecipe (net.minecraft.village.MerchantRecipe)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Counter (mcjty.lib.varia.Counter)1