Search in sources :

Example 21 with DimletKey

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

the class GenericWorldGenerator method generateDungeon.

private void generateDungeon(World world, Random random, int midx, int starty, int midz) {
    boolean doSmallAntenna = random.nextInt(4) == 0;
    boolean doExtraFeature = random.nextInt(4) == 0;
    Block cornerBlock;
    switch(random.nextInt(3)) {
        case 0:
            cornerBlock = DimletSetup.dimensionalCrossBlock;
            break;
        case 1:
            cornerBlock = DimletSetup.dimensionalPattern1Block;
            break;
        case 2:
            cornerBlock = DimletSetup.dimensionalPattern2Block;
            break;
        default:
            cornerBlock = DimletSetup.dimensionalCross2Block;
    }
    Block buildingBlock = Blocks.stained_hardened_clay;
    int color = random.nextInt(5);
    if (color == 0) {
        color = 3;
    } else if (color == 1) {
        color = 9;
    } else if (color == 2) {
        color = 11;
    } else {
        color = 0;
        buildingBlock = DimletSetup.dimensionalBlankBlock;
    }
    // Spawn the building
    for (int x = midx - 3; x <= midx + 3; x++) {
        for (int z = midz - 3; z <= midz + 3; z++) {
            boolean corner = (x == midx - 3 || x == midx + 3) && (z == midz - 3 || z == midz + 3);
            boolean xside = x == midx - 3 || x == midx + 3;
            boolean zside = z == midz - 3 || z == midz + 3;
            boolean antenna = (x == midx - 2 && z == midz - 2);
            boolean smallAntenna = doSmallAntenna && (x == midx + 2 && z == midz + 2);
            world.setBlock(x, starty, z, Blocks.double_stone_slab, 0, 2);
            if (corner) {
                world.setBlock(x, starty + 1, z, cornerBlock, 1, 2);
                world.setBlock(x, starty + 2, z, cornerBlock, 1, 2);
                world.setBlock(x, starty + 3, z, cornerBlock, 1, 2);
            } else if (xside) {
                world.setBlock(x, starty + 1, z, buildingBlock, color, 2);
                if (z >= midz - 1 && z <= midz + 1) {
                    world.setBlock(x, starty + 2, z, Blocks.glass_pane, 0, 2);
                } else {
                    world.setBlock(x, starty + 2, z, buildingBlock, color, 2);
                }
                world.setBlock(x, starty + 3, z, buildingBlock, color, 2);
            } else if (zside) {
                world.setBlock(x, starty + 1, z, buildingBlock, color, 2);
                world.setBlock(x, starty + 2, z, buildingBlock, color, 2);
                world.setBlock(x, starty + 3, z, buildingBlock, color, 2);
            } else {
                world.setBlockToAir(x, starty + 1, z);
                world.setBlockToAir(x, starty + 2, z);
                world.setBlockToAir(x, starty + 3, z);
            }
            if (antenna) {
                world.setBlock(x, starty + 4, z, Blocks.double_stone_slab, 0, 2);
                world.setBlock(x, starty + 5, z, Blocks.iron_bars, 0, 2);
                world.setBlock(x, starty + 6, z, Blocks.iron_bars, 0, 2);
                world.setBlock(x, starty + 7, z, Blocks.iron_bars, 0, 2);
                world.setBlock(x, starty + 8, z, Blocks.glowstone, 0, 3);
            } else if (smallAntenna) {
                world.setBlock(x, starty + 4, z, Blocks.double_stone_slab, 0, 2);
                world.setBlock(x, starty + 5, z, Blocks.iron_bars, 0, 2);
                world.setBlockToAir(x, starty + 6, z);
                world.setBlockToAir(x, starty + 7, z);
                world.setBlockToAir(x, starty + 8, z);
            } else {
                world.setBlock(x, starty + 4, z, Blocks.stone_slab, 0, 2);
                world.setBlockToAir(x, starty + 5, z);
                world.setBlockToAir(x, starty + 6, z);
                world.setBlockToAir(x, starty + 7, z);
                world.setBlockToAir(x, starty + 8, z);
            }
            // Spawn stone under the building for as long as it is air.
            WorldGenerationTools.fillEmptyWithStone(world, x, starty - 1, z);
        }
    }
    if (doExtraFeature) {
        if (!WorldGenerationTools.isSolid(world, midx + 4, starty, midz - 3)) {
            world.setBlock(midx + 4, starty, midz - 3, Blocks.iron_bars, 0, 2);
        }
        world.setBlock(midx + 4, starty + 1, midz - 3, Blocks.iron_bars, 0, 2);
        world.setBlock(midx + 4, starty + 2, midz - 3, Blocks.iron_bars, 0, 2);
        if (!WorldGenerationTools.isSolid(world, midx + 5, starty, midz - 3)) {
            world.setBlock(midx + 5, starty, midz - 3, buildingBlock, color, 2);
        }
        world.setBlock(midx + 5, starty + 1, midz - 3, buildingBlock, color, 2);
        world.setBlock(midx + 5, starty + 2, midz - 3, buildingBlock, color, 2);
        WorldGenerationTools.fillEmptyWithStone(world, midx + 4, starty - 1, midz - 3);
        WorldGenerationTools.fillEmptyWithStone(world, midx + 5, starty - 1, midz - 3);
    }
    // Clear the space before the door.
    for (int x = midx - 3; x <= midx + 3; x++) {
        for (int y = starty + 1; y <= starty + 3; y++) {
            world.setBlockToAir(x, y, midz - 4);
        }
    }
    // Small platform before the door
    world.setBlock(midx - 1, starty, midz - 4, Blocks.double_stone_slab, 0, 2);
    world.setBlock(midx, starty, midz - 4, Blocks.double_stone_slab, 0, 2);
    world.setBlock(midx + 1, starty, midz - 4, Blocks.double_stone_slab, 0, 2);
    world.setBlock(midx, starty + 1, midz - 3, Blocks.iron_door, 1, 2);
    world.setBlock(midx, starty + 2, midz - 3, Blocks.iron_door, 8, 2);
    world.setBlock(midx - 1, starty + 2, midz - 4, Blocks.stone_button, 4, 2);
    world.setBlock(midx + 1, starty + 2, midz - 2, Blocks.stone_button, 3, 2);
    world.setBlock(midx, starty + 3, midz + 3, Blocks.redstone_lamp, 0, 2);
    world.setBlock(midx, starty + 3, midz + 2, Blocks.lever, 4, 2);
    world.setBlock(midx + 2, starty + 1, midz - 2, Blocks.chest, 0, 2);
    TileEntityChest chest = (TileEntityChest) world.getTileEntity(midx + 2, starty + 1, midz - 2);
    for (int i = 0; i < random.nextInt(2) + 2; i++) {
        chest.setInventorySlotContents(random.nextInt(chest.getSizeInventory()), new ItemStack(DimletSetup.unknownDimlet, random.nextInt(6) + 3));
    }
    WeightedRandomSelector.Distribution<Integer> goodDistribution = DimletRandomizer.randomDimlets.createDistribution(0.01f);
    for (int i = 0; i < random.nextInt(2) + 1; i++) {
        DimletKey randomDimlet = DimletRandomizer.getRandomDimlet(goodDistribution, random);
        chest.setInventorySlotContents(random.nextInt(chest.getSizeInventory()), KnownDimletConfiguration.makeKnownDimlet(randomDimlet, world));
    }
    WeightedRandomSelector.Distribution<Integer> bestDistribution = DimletRandomizer.randomDimlets.createDistribution(0.15f);
    EntityItemFrame frame1 = spawnItemFrame(world, midx - 1, starty + 2, midz + 2);
    DimletKey rd1 = DimletRandomizer.getRandomDimlet(bestDistribution, random);
    frame1.setDisplayedItem(KnownDimletConfiguration.makeKnownDimlet(rd1, world));
    EntityItemFrame frame2 = spawnItemFrame(world, midx, starty + 2, midz + 2);
    DimletKey rd2 = DimletRandomizer.getRandomDimlet(bestDistribution, random);
    frame2.setDisplayedItem(KnownDimletConfiguration.makeKnownDimlet(rd2, world));
    EntityItemFrame frame3 = spawnItemFrame(world, midx + 1, starty + 2, midz + 2);
    DimletKey rd3 = DimletRandomizer.getRandomDimlet(bestDistribution, random);
    frame3.setDisplayedItem(KnownDimletConfiguration.makeKnownDimlet(rd3, world));
}
Also used : TileEntityChest(net.minecraft.tileentity.TileEntityChest) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) DimletKey(mcjty.rftools.items.dimlets.DimletKey)

Example 22 with DimletKey

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

the class RFToolsTradeHandler method getRandomBuyDimlet.

private void getRandomBuyDimlet(EntityVillager villager, MerchantRecipeList recipeList, Random random, int bonus) {
    DimletKey dimlet = DimletRandomizer.getRandomDimlet(random);
    if (dimlet != null) {
        DimletEntry entry = KnownDimletConfiguration.idToDimletEntry.get(dimlet);
        if (entry != null) {
            int rarity = entry.getRarity();
            ItemStack dimletStack = KnownDimletConfiguration.makeKnownDimlet(dimlet, villager.worldObj);
            recipeList.add(new MerchantRecipe(dimletStack, new ItemStack(Items.emerald, (bonus + random.nextInt(2)) * (rarity / 2 + 1))));
        }
    }
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) DimletEntry(mcjty.rftools.items.dimlets.DimletEntry) DimletKey(mcjty.rftools.items.dimlets.DimletKey) ItemStack(net.minecraft.item.ItemStack)

Example 23 with DimletKey

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

the class DimletFilterTileEntity method canExtractItem.

@Override
public boolean canExtractItem(int index, ItemStack stack, int side) {
    if (!isOutputMode(side)) {
        return false;
    }
    if (stack == null) {
        return false;
    }
    DimletKey key = KnownDimletConfiguration.getDimletKey(stack, worldObj);
    if (key == null) {
        return false;
    }
    if (types[side] != null && !types[side].equals(key.getType())) {
        return false;
    }
    DimletEntry entry = KnownDimletConfiguration.getEntry(key);
    if (entry == null) {
        return false;
    }
    int rarity = entry.getRarity();
    if (rarity < minRarity[side] || rarity > maxRarity[side]) {
        return false;
    }
    if (craftable[side] != 0) {
        int cr = KnownDimletConfiguration.craftableDimlets.contains(key) ? CRAFTABLE_YES : CRAFTABLE_NO;
        if (cr != craftable[side]) {
            return false;
        }
    }
    // Is this the best match?
    return findMostSpecificExtractionSide(entry) == side;
}
Also used : DimletEntry(mcjty.rftools.items.dimlets.DimletEntry) DimletKey(mcjty.rftools.items.dimlets.DimletKey)

Example 24 with DimletKey

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

the class FeatureDimletType method getRandomFluidArray.

private Block[] getRandomFluidArray(Random random, DimensionInformation dimensionInformation, Set<FeatureType> featureTypes, Map<FeatureType, List<DimletKey>> modifiersForFeature, FeatureType t, boolean allowEmpty) {
    Block[] fluidsForLakes;
    if (featureTypes.contains(t)) {
        List<BlockMeta> blocks = new ArrayList<BlockMeta>();
        List<Block> fluids = new ArrayList<Block>();
        DimensionInformation.getMaterialAndFluidModifiers(modifiersForFeature.get(t), blocks, fluids);
        // If no fluids are specified we will usually have default fluid generation (water+lava). Otherwise some random selection.
        if (fluids.isEmpty()) {
            while (random.nextFloat() < DimletConfiguration.randomLakeFluidChance) {
                DimletKey key = DimletRandomizer.getRandomFluidBlock(random, true);
                dimensionInformation.updateCostFactor(key);
                fluids.add(DimletObjectMapping.idToFluid.get(key));
            }
        } else if (fluids.size() == 1 && fluids.get(0) == null) {
            fluids.clear();
        }
        fluidsForLakes = fluids.toArray(new Block[fluids.size()]);
        for (int i = 0; i < fluidsForLakes.length; i++) {
            if (fluidsForLakes[i] == null) {
                fluidsForLakes[i] = Blocks.water;
            }
        }
    } else {
        fluidsForLakes = new Block[0];
    }
    if (allowEmpty || fluidsForLakes.length > 0) {
        return fluidsForLakes;
    }
    return new Block[] { Blocks.water };
}
Also used : Block(net.minecraft.block.Block) DimletKey(mcjty.rftools.items.dimlets.DimletKey) BlockMeta(mcjty.lib.varia.BlockMeta)

Example 25 with DimletKey

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

the class StructureDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    Set<StructureType> structureTypes = dimensionInformation.getStructureTypes();
    Set<String> dimensionTypes = new HashSet<String>();
    dimlets = DimensionInformation.extractType(DimletType.DIMLET_STRUCTURE, dimlets);
    if (dimlets.isEmpty()) {
        while (random.nextFloat() < DimletConfiguration.randomStructureChance) {
            DimletKey key = DimletRandomizer.getRandomStructure(random, false);
            StructureType structureType = DimletObjectMapping.idToStructureType.get(key);
            if (!structureTypes.contains(structureType) || (structureType == StructureType.STRUCTURE_RECURRENTCOMPLEX)) {
                dimensionInformation.updateCostFactor(key);
                structureTypes.add(structureType);
                if (structureType == StructureType.STRUCTURE_RECURRENTCOMPLEX) {
                    dimensionTypes.add(DimletObjectMapping.idToRecurrentComplexType.get(key));
                }
            }
        }
    } else {
        for (Pair<DimletKey, List<DimletKey>> dimletWithModifier : dimlets) {
            DimletKey key = dimletWithModifier.getLeft();
            StructureType structureType = DimletObjectMapping.idToStructureType.get(key);
            structureTypes.add(structureType);
            if (structureType == StructureType.STRUCTURE_RECURRENTCOMPLEX) {
                dimensionTypes.add(DimletObjectMapping.idToRecurrentComplexType.get(key));
            }
        }
    }
    dimensionInformation.setDimensionTypes(dimensionTypes.toArray(new String[dimensionTypes.size()]));
}
Also used : StructureType(mcjty.rftools.dimension.world.types.StructureType) List(java.util.List) DimletKey(mcjty.rftools.items.dimlets.DimletKey) HashSet(java.util.HashSet)

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