Search in sources :

Example 1 with BlockMeta

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

the class MapGenRuinedCities method createBlockMap.

private void createBlockMap() {
    if (blockMap != null) {
        return;
    }
    blockMap = new HashMap<Character, BlockMeta>();
    blockMap.put(' ', null);
    blockMap.put('B', new BlockMeta(ModBlocks.dimensionalBlock, 0));
    blockMap.put('b', new BlockMeta(ModBlocks.dimensionalBlankBlock, 0));
    blockMap.put('p', new BlockMeta(ModBlocks.dimensionalCrossBlock, 2));
    blockMap.put('P', new BlockMeta(ModBlocks.dimensionalCrossBlock, 0));
    blockMap.put('X', new BlockMeta(ModBlocks.dimensionalPattern1Block, 0));
    blockMap.put('x', new BlockMeta(ModBlocks.dimensionalPattern2Block, 0));
    blockMap.put('g', new BlockMeta(Blocks.stained_glass, 11));
}
Also used : BlockMeta(mcjty.lib.varia.BlockMeta)

Example 2 with BlockMeta

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

the class BuilderTileEntity method consumeBlock.

private BlockMeta consumeBlock(Block block, int meta) {
    TileEntity te = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
    if (te instanceof IInventory) {
        BlockMeta b = findAndConsumeBlock((IInventory) te, block, meta);
        if (b != null) {
            return b;
        }
    }
    te = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
    if (te instanceof IInventory) {
        BlockMeta b = findAndConsumeBlock((IInventory) te, block, meta);
        if (b != null) {
            return b;
        }
    }
    // }
    return null;
}
Also used : GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) BlockMeta(mcjty.lib.varia.BlockMeta)

Example 3 with BlockMeta

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

the class PacketGetChamberInfo method onMessage.

@Override
public PacketChamberInfoReady onMessage(PacketGetChamberInfo message, MessageContext ctx) {
    EntityPlayer player = ctx.getServerHandler().playerEntity;
    ItemStack cardItem = player.getHeldItem();
    if (cardItem == null || cardItem.getTagCompound() == null) {
        return null;
    }
    int channel = cardItem.getTagCompound().getInteger("channel");
    if (channel == -1) {
        return null;
    }
    SpaceChamberRepository repository = SpaceChamberRepository.getChannels(player.worldObj);
    SpaceChamberRepository.SpaceChamberChannel chamberChannel = repository.getChannel(channel);
    if (chamberChannel == null) {
        return null;
    }
    int dimension = chamberChannel.getDimension();
    World world = DimensionManager.getWorld(dimension);
    if (world == null) {
        return null;
    }
    Counter<BlockMeta> blocks = new Counter<BlockMeta>();
    Counter<BlockMeta> costs = new Counter<BlockMeta>();
    Coordinate minCorner = chamberChannel.getMinCorner();
    Coordinate maxCorner = chamberChannel.getMaxCorner();
    for (int x = minCorner.getX(); x <= maxCorner.getX(); x++) {
        for (int y = minCorner.getY(); y <= maxCorner.getY(); y++) {
            for (int z = minCorner.getZ(); z <= maxCorner.getZ(); z++) {
                Block block = world.getBlock(x, y, z);
                if (!BuilderTileEntity.isEmpty(block)) {
                    int meta = world.getBlockMetadata(x, y, z);
                    BlockMeta bm = new BlockMeta(block, meta);
                    blocks.increment(bm);
                    TileEntity te = world.getTileEntity(x, y, z);
                    SpaceProjectorSetup.BlockInformation info = BuilderTileEntity.getBlockInformation(world, x, y, z, block, te);
                    if (info.getBlockLevel() == SupportBlock.STATUS_ERROR) {
                        costs.put(bm, -1);
                    } else {
                        costs.increment(bm, (int) (SpaceProjectorConfiguration.builderRfPerOperation * info.getCostFactor()));
                    }
                }
            }
        }
    }
    Counter<String> entitiesWithCount = new Counter<String>();
    Counter<String> entitiesWithCost = new Counter<String>();
    List entities = world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(minCorner.getX(), minCorner.getY(), minCorner.getZ(), maxCorner.getX() + 1, maxCorner.getY() + 1, maxCorner.getZ() + 1));
    for (Object o : entities) {
        Entity entity = (Entity) o;
        String canonicalName = entity.getClass().getCanonicalName();
        entitiesWithCount.increment(canonicalName);
        if (entity instanceof EntityPlayer) {
            entitiesWithCost.increment(canonicalName, SpaceProjectorConfiguration.builderRfPerPlayer);
        } else {
            entitiesWithCost.increment(canonicalName, SpaceProjectorConfiguration.builderRfPerEntity);
        }
    }
    return new PacketChamberInfoReady(blocks, costs, entitiesWithCount, entitiesWithCost);
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) Counter(mcjty.lib.varia.Counter) Coordinate(mcjty.lib.varia.Coordinate) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) BlockMeta(mcjty.lib.varia.BlockMeta)

Example 4 with BlockMeta

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

the class GuiChamberDetails method populateLists.

private void populateLists() {
    blockList.removeChildren();
    if (items == null) {
        return;
    }
    int totalCost = 0;
    for (Map.Entry<BlockMeta, Integer> entry : items.entrySet()) {
        BlockMeta bm = entry.getKey();
        int count = entry.getValue();
        int cost = costs.get(bm);
        Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout()).setDesiredHeight(16);
        ItemStack stack = new ItemStack(bm.getBlock(), 0, bm.getMeta());
        BlockRender blockRender = new BlockRender(mc, this).setRenderItem(stack).setOffsetX(-1).setOffsetY(-1);
        Label nameLabel = new Label(mc, this).setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setColor(StyleConfig.colorTextInListNormal);
        if (stack.getItem() == null) {
            nameLabel.setText("?").setDesiredWidth(160);
        } else {
            nameLabel.setText(stack.getDisplayName()).setDesiredWidth(160);
        }
        Label countLabel = new Label(mc, this).setText(String.valueOf(count)).setColor(StyleConfig.colorTextInListNormal);
        countLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setDesiredWidth(50);
        Label costLabel = new Label(mc, this).setColor(StyleConfig.colorTextInListNormal);
        costLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT);
        if (cost == -1) {
            costLabel.setText("NOT MOVABLE!");
        } else {
            costLabel.setText("Move Cost " + cost + " RF");
            totalCost += cost;
        }
        panel.addChild(blockRender).addChild(nameLabel).addChild(countLabel).addChild(costLabel);
        blockList.addChild(panel);
    }
    int totalCostEntities = 0;
    RenderHelper.rot += .5f;
    for (Map.Entry<String, Integer> entry : entities.entrySet()) {
        String className = entry.getKey();
        Class<?> aClass = null;
        try {
            aClass = Class.forName(className);
        } catch (ClassNotFoundException e) {
        }
        int count = entry.getValue();
        int cost = entityCosts.get(className);
        Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout()).setDesiredHeight(16);
        Entity entity = null;
        try {
            entity = (Entity) aClass.getConstructor(World.class).newInstance(mc.theWorld);
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        } catch (InvocationTargetException e) {
        } catch (NoSuchMethodException e) {
        }
        BlockRender blockRender = new BlockRender(mc, this).setRenderItem(entity).setOffsetX(-1).setOffsetY(-1);
        Label nameLabel = new Label(mc, this).setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT);
        nameLabel.setText(aClass.getSimpleName()).setDesiredWidth(160);
        Label countLabel = new Label(mc, this).setText(String.valueOf(count));
        countLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setDesiredWidth(50);
        Label costLabel = new Label(mc, this);
        costLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT);
        if (cost == -1) {
            costLabel.setText("NOT MOVABLE!");
        } else {
            costLabel.setText("Move Cost " + cost + " RF");
            totalCostEntities += cost;
        }
        panel.addChild(blockRender).addChild(nameLabel).addChild(countLabel).addChild(costLabel);
        blockList.addChild(panel);
    }
    infoLabel.setText("Total cost blocks: " + totalCost + " RF");
    info2Label.setText("Total cost entities: " + totalCostEntities + " RF");
}
Also used : Entity(net.minecraft.entity.Entity) Label(mcjty.lib.gui.widgets.Label) World(net.minecraft.world.World) InvocationTargetException(java.lang.reflect.InvocationTargetException) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Panel(mcjty.lib.gui.widgets.Panel) ItemStack(net.minecraft.item.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) BlockMeta(mcjty.lib.varia.BlockMeta)

Example 5 with BlockMeta

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

the class PacketChamberInfoReady method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    int size = buf.readInt();
    blocks = new HashMap<BlockMeta, Integer>(size);
    costs = new HashMap<BlockMeta, Integer>(size);
    for (int i = 0; i < size; i++) {
        int id = buf.readInt();
        byte meta = buf.readByte();
        int count = buf.readInt();
        int cost = buf.readInt();
        Block block = (Block) Block.blockRegistry.getObjectById(id);
        BlockMeta bm = new BlockMeta(block, meta);
        blocks.put(bm, count);
        costs.put(bm, cost);
    }
    size = buf.readInt();
    entities = new HashMap<String, Integer>(size);
    entityCosts = new HashMap<String, Integer>(size);
    for (int i = 0; i < size; i++) {
        String className = NetworkTools.readString(buf);
        int count = buf.readInt();
        int cost = buf.readInt();
        entities.put(className, count);
        entityCosts.put(className, cost);
    }
}
Also used : Block(net.minecraft.block.Block) 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