Search in sources :

Example 21 with BlockMeta

use of mcjty.lib.varia.BlockMeta 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 22 with BlockMeta

use of mcjty.lib.varia.BlockMeta in project RFTools by McJty.

the class PacketChamberInfoReady method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(blocks.size());
    for (Map.Entry<BlockMeta, Integer> entry : blocks.entrySet()) {
        Block block = entry.getKey().getBlock();
        buf.writeInt(Block.blockRegistry.getIDForObject(block));
        buf.writeByte(entry.getKey().getMeta());
        buf.writeInt(entry.getValue());
        buf.writeInt(costs.get(entry.getKey()));
    }
    buf.writeInt(entities.size());
    for (Map.Entry<String, Integer> entry : entities.entrySet()) {
        NetworkTools.writeString(buf, entry.getKey());
        buf.writeInt(entry.getValue());
        buf.writeInt(entityCosts.get(entry.getKey()));
    }
}
Also used : Block(net.minecraft.block.Block) Map(java.util.Map) HashMap(java.util.HashMap) BlockMeta(mcjty.lib.varia.BlockMeta)

Example 23 with BlockMeta

use of mcjty.lib.varia.BlockMeta in project RFTools by McJty.

the class BuilderTileEntity method buildBlock.

private boolean buildBlock(int rfNeeded, int sx, int sy, int sz) {
    if (isEmptyOrReplacable(worldObj, sx, sy, sz)) {
        BlockMeta block = consumeBlock(null, 0);
        if (block == null) {
            // We could not find a block. Wait
            return true;
        }
        worldObj.setBlock(sx, sy, sz, block.getBlock(), block.getMeta(), 3);
        worldObj.setBlockMetadataWithNotify(sx, sy, sz, block.getMeta(), 3);
        if (!silent) {
            RFToolsTools.playSound(worldObj, block.getBlock().stepSound.getBreakSound(), sx, sy, sz, 1.0f, 1.0f);
        }
        consumeEnergy(rfNeeded);
    }
    return false;
}
Also used : BlockMeta(mcjty.lib.varia.BlockMeta)

Example 24 with BlockMeta

use of mcjty.lib.varia.BlockMeta in project RFTools by McJty.

the class BuilderTileEntity method findAndConsumeBlock.

// Also works if block is null and just picks the first available block.
private BlockMeta findAndConsumeBlock(IInventory inventory, Block block, int meta) {
    if (block == null) {
        // We are not looking for a specific block. Pick a random one out of the chest.
        List<Integer> slots = new ArrayList<Integer>();
        for (int i = 0; i < inventory.getSizeInventory(); i++) {
            ItemStack stack = inventory.getStackInSlot(i);
            if (stack != null && stack.stackSize > 0 && stack.getItem() instanceof ItemBlock) {
                slots.add(i);
            }
        }
        if (slots.size() == 0) {
            return null;
        }
        int randomSlot = slots.get(random.nextInt(slots.size()));
        ItemStack stack = inventory.getStackInSlot(randomSlot);
        ItemBlock itemBlock = (ItemBlock) stack.getItem();
        inventory.decrStackSize(randomSlot, 1);
        return new BlockMeta(itemBlock.field_150939_a, stack.getItemDamage());
    } else {
        for (int i = 0; i < inventory.getSizeInventory(); i++) {
            ItemStack stack = inventory.getStackInSlot(i);
            if (stack != null && stack.stackSize > 0 && stack.getItem() instanceof ItemBlock) {
                ItemBlock itemBlock = (ItemBlock) stack.getItem();
                if (itemBlock.field_150939_a == block && (meta == -1 || stack.getItemDamage() == meta)) {
                    inventory.decrStackSize(i, 1);
                    return new BlockMeta(itemBlock.field_150939_a, stack.getItemDamage());
                }
            }
        }
    }
    return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) BlockMeta(mcjty.lib.varia.BlockMeta)

Example 25 with BlockMeta

use of mcjty.lib.varia.BlockMeta in project RFTools by McJty.

the class MapGenOrbs method generate.

public void generate(World world, int chunkX, int chunkZ, Block[] ablock, byte[] ameta) {
    BlockMeta[] blocks = large ? provider.dimensionInformation.getHugeSphereBlocks() : provider.dimensionInformation.getSphereBlocks();
    for (int cx = -r; cx <= r; cx++) {
        for (int cz = -r; cz <= r; cz++) {
            Random random = new Random((world.getSeed() + (chunkX + cx)) * 113 + (chunkZ + cz) * 31 + 77);
            random.nextFloat();
            if (random.nextFloat() < .05f) {
                int x = cx * 16 + random.nextInt(16);
                int y = 40 + random.nextInt(40);
                int z = cz * 16 + random.nextInt(16);
                int radius = random.nextInt(large ? 20 : 6) + (large ? 10 : 4);
                BlockMeta block = BlockMeta.STONE;
                if (blocks.length > 1) {
                    block = blocks[random.nextInt(blocks.length)];
                } else if (blocks.length == 1) {
                    block = blocks[0];
                }
                fillSphere(ablock, ameta, x, y, z, radius, block);
            }
        }
    }
}
Also used : Random(java.util.Random) BlockMeta(mcjty.lib.varia.BlockMeta)

Aggregations

BlockMeta (mcjty.lib.varia.BlockMeta)31 Block (net.minecraft.block.Block)18 ItemStack (net.minecraft.item.ItemStack)6 Random (java.util.Random)5 DimletKey (mcjty.rftools.items.dimlets.DimletKey)3 World (net.minecraft.world.World)3 BiomeGenBase (net.minecraft.world.biome.BiomeGenBase)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Entity (net.minecraft.entity.Entity)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)1 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 Label (mcjty.lib.gui.widgets.Label)1 Panel (mcjty.lib.gui.widgets.Panel)1 Coordinate (mcjty.lib.varia.Coordinate)1