Search in sources :

Example 1 with BlockDec

use of am2.api.blocks.MultiblockStructureDefinition.BlockDec in project ArsMagica2 by Mithion.

the class GuiArcaneCompendium method drawMultiblockLayer.

private void drawMultiblockLayer(int cx, int cy, int layer, BlockCoord pickedBlock, int mousex, int mousey) {
    TreeMap<BlockCoord, ArrayList<BlockDec>> layerBlocksSorted = getMultiblockLayer(layer);
    float step_x = 14f;
    float step_y = -16.0f;
    float step_z = 7f;
    cy -= step_y * entryMultiblock.getMinLayer() / 2;
    cy -= step_y * entryMultiblock.getMaxLayer() / 2;
    float px = cx - (step_x * (entryMultiblock.getWidth() / 2));
    float py = cy - (step_z * (entryMultiblock.getLength() / 2));
    for (BlockCoord bc : layerBlocksSorted.keySet()) {
        //if (bc.getX() == 0 && bc.getY() == 0 && bc.getZ() == 0) continue;
        BlockDec bd = layerBlocksSorted.get(bc).get(AMGuiHelper.instance.getSlowTicker() % layerBlocksSorted.get(bc).size());
        float x = px + ((bc.getX() - bc.getZ()) * step_x);
        float y = py + ((bc.getZ() + bc.getX()) * step_z) + (step_y * layer);
        GL11.glPushMatrix();
        GL11.glTranslatef(0, 0, 15 * bc.getX());
        boolean picked = pickedBlock != null && bc.equals(pickedBlock);
        renderBlock(bd.getBlock(), bd.getMeta(), x, y, bc.getX(), bc.getY(), bc.getZ(), picked);
        GL11.glPopMatrix();
        if (picked) {
            ItemStack stack = new ItemStack(bd.getBlock(), 1, bd.getMeta());
            if (stack.getItem() != null) {
                stackTip = stack;
                tipX = mousex;
                tipY = mousey;
            }
        }
    }
}
Also used : BlockDec(am2.api.blocks.MultiblockStructureDefinition.BlockDec) BlockCoord(am2.api.blocks.MultiblockStructureDefinition.BlockCoord) ItemStack(net.minecraft.item.ItemStack)

Example 2 with BlockDec

use of am2.api.blocks.MultiblockStructureDefinition.BlockDec in project ArsMagica2 by Mithion.

the class PlaceBlock method applyEffectBlock.

@Override
public boolean applyEffectBlock(ItemStack stack, World world, int blockx, int blocky, int blockz, int blockFace, double impactX, double impactY, double impactZ, EntityLivingBase caster) {
    if (!(caster instanceof EntityPlayer))
        return false;
    EntityPlayer player = (EntityPlayer) caster;
    ItemStack spellStack = player.getCurrentEquippedItem();
    if (spellStack == null || spellStack.getItem() != ItemsCommonProxy.spell || !SpellUtils.instance.componentIsPresent(spellStack, PlaceBlock.class, SpellUtils.instance.numStages(spellStack) - 1))
        return false;
    BlockDec bd = getPlaceBlock(spellStack);
    if (bd != null && !caster.isSneaking()) {
        if (world.isAirBlock(blockx, blocky, blockz) || !world.getBlock(blockx, blocky, blockz).getMaterial().isSolid())
            blockFace = -1;
        if (blockFace != -1) {
            switch(blockFace) {
                case 0:
                    blocky--;
                    break;
                case 1:
                    blocky++;
                    break;
                case 2:
                    blockz--;
                    break;
                case 3:
                    blockz++;
                    break;
                case 4:
                    blockx--;
                    break;
                case 5:
                    blockx++;
                    break;
            }
        }
        if (world.isAirBlock(blockx, blocky, blockz) || !world.getBlock(blockx, blocky, blockz).getMaterial().isSolid()) {
            ItemStack searchStack = new ItemStack(bd.getBlock(), 1, bd.getMeta());
            if (!world.isRemote && (player.capabilities.isCreativeMode || InventoryUtilities.inventoryHasItem(player.inventory, searchStack, 1))) {
                world.setBlock(blockx, blocky, blockz, bd.getBlock(), bd.getMeta(), 3);
                if (!player.capabilities.isCreativeMode)
                    InventoryUtilities.deductFromInventory(player.inventory, searchStack, 1);
            }
            return true;
        }
    } else if (caster.isSneaking()) {
        if (!world.isRemote && !world.isAirBlock(blockx, blocky, blockz)) {
            setPlaceBlock(spellStack, world.getBlock(blockx, blocky, blockz), world.getBlockMetadata(blockx, blocky, blockz));
        }
        return true;
    }
    return false;
}
Also used : BlockDec(am2.api.blocks.MultiblockStructureDefinition.BlockDec) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 3 with BlockDec

use of am2.api.blocks.MultiblockStructureDefinition.BlockDec in project ArsMagica2 by Mithion.

the class TileEntityCraftingAltar method checkStructure.

private void checkStructure() {
    if ((isCrafting && checkCounter++ < 50) || (!isCrafting && checkCounter++ < 200)) {
        return;
    }
    checkCounter = 0;
    boolean primaryvalid = primary.checkStructure(worldObj, xCoord, yCoord, zCoord);
    boolean secondaryvalid = secondary.checkStructure(worldObj, xCoord, yCoord, zCoord);
    if (!primaryvalid && !secondaryvalid) {
        if (isCrafting)
            setCrafting(false);
    }
    //locate lectern and lever & material groups
    if (primaryvalid || secondaryvalid) {
        maxEffects = 0;
        ArrayList<StructureGroup> lecternGroups = null;
        ArrayList<StructureGroup> augmatlGroups = null;
        ArrayList<StructureGroup> mainmatlGroups = null;
        if (primaryvalid) {
            lecternGroups = primary.getMatchedGroups(lectern_mutex, worldObj, xCoord, yCoord, zCoord);
            augmatlGroups = primary.getMatchedGroups(augmatl_mutex, worldObj, xCoord, yCoord, zCoord);
            mainmatlGroups = primary.getMatchedGroups(MultiblockStructureDefinition.MAINGROUP_MUTEX, worldObj, xCoord, yCoord, zCoord);
        } else if (secondaryvalid) {
            lecternGroups = secondary.getMatchedGroups(lectern_mutex, worldObj, xCoord, yCoord, zCoord);
            augmatlGroups = secondary.getMatchedGroups(augmatl_mutex, worldObj, xCoord, yCoord, zCoord);
            mainmatlGroups = secondary.getMatchedGroups(MultiblockStructureDefinition.MAINGROUP_MUTEX, worldObj, xCoord, yCoord, zCoord);
        }
        if (lecternGroups != null && lecternGroups.size() > 0) {
            StructureGroup group = lecternGroups.get(0);
            HashMap<BlockCoord, ArrayList<BlockDec>> blocks = group.getAllowedBlocks();
            for (BlockCoord bc : blocks.keySet()) {
                Block block = worldObj.getBlock(xCoord + bc.getX(), yCoord + bc.getY(), zCoord + bc.getZ());
                if (block == BlocksCommonProxy.blockLectern) {
                    podiumLocation = bc;
                } else if (block == Blocks.lever) {
                    switchLocation = bc;
                }
            }
        }
        if (augmatlGroups != null && augmatlGroups.size() == 1) {
            StructureGroup group = augmatlGroups.get(0);
            int index = -1;
            for (StructureGroup augmatlGroup : primaryvalid ? augMatl_primary : augMatl_secondary) {
                index++;
                if (augmatlGroup == group) {
                    break;
                }
            }
            maxEffects = index + 1;
        }
        if (mainmatlGroups != null && mainmatlGroups.size() == 1) {
            StructureGroup group = mainmatlGroups.get(0);
            if (group == wood_primary || group == wood_secondary)
                maxEffects += 1;
            else if (group == cobble_primary || group == cobble_secondary || group == sandstone_primary || group == sandstone_secondary)
                maxEffects += 1;
            else if (group == brick_primary || group == brick_secondary || group == witchwood_primary || group == witchwood_secondary)
                maxEffects += 2;
            else if (group == netherbrick_primary || group == netherbrick_secondary || group == quartz_primary || group == quartz_secondary)
                maxEffects += 3;
            else
                //default of stone brick
                maxEffects += 2;
        }
    } else {
        podiumLocation = null;
        switchLocation = null;
        maxEffects = 0;
    }
    //maxEffects = 2;
    setStructureValid(primaryvalid || secondaryvalid);
}
Also used : StructureGroup(am2.api.blocks.MultiblockStructureDefinition.StructureGroup) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) BlockCoord(am2.api.blocks.MultiblockStructureDefinition.BlockCoord)

Example 4 with BlockDec

use of am2.api.blocks.MultiblockStructureDefinition.BlockDec in project ArsMagica2 by Mithion.

the class GuiArcaneCompendium method drawRightPage_Multiblock.

private void drawRightPage_Multiblock(int cx, int cy, int mousex, int mousey) {
    String label = String.format("%s: %s", StatCollector.translateToLocal("am2.gui.layer"), curLayer == -1 ? StatCollector.translateToLocal("am2.gui.all") : "" + curLayer);
    fontRendererObj.drawString(label, cx - fontRendererObj.getStringWidth(label) / 2, cy - 90, 0x000000);
    GL11.glPushMatrix();
    GL11.glPushAttrib(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_TEXTURE_BIT | GL11.GL_LIGHTING_BIT);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_LIGHTING);
    /*ArrayList<BlockDec> blox = entryMultiblock.getAllowedBlocksAt(entryMultiblock.new BlockCoord(0, 0, 0));
		if (blox != null){
			renderBlock(Block.blocksList[blox.get(0).getID()], blox.get(0).getMeta(), cx, cy);
		}*/
    BlockCoord pickedBlock = getPickedBlock(cx, cy, mousex, mousey);
    if (curLayer == -1) {
        for (int i = entryMultiblock.getMinLayer(); i <= entryMultiblock.getMaxLayer(); ++i) {
            int y = (i - entryMultiblock.getMinLayer());
            GL11.glTranslatef(0.0f, 0.0f, 20f * y);
            drawMultiblockLayer(cx, cy, i, pickedBlock, mousex, mousey);
        }
    } else {
        int i = entryMultiblock.getMinLayer() + curLayer;
        GL11.glTranslatef(0.0f, 0.0f, 20f * curLayer);
        drawMultiblockLayer(cx, cy, i, pickedBlock, mousex, mousey);
    }
    GL11.glPopAttrib();
    GL11.glPopMatrix();
}
Also used : BlockCoord(am2.api.blocks.MultiblockStructureDefinition.BlockCoord)

Example 5 with BlockDec

use of am2.api.blocks.MultiblockStructureDefinition.BlockDec in project ArsMagica2 by Mithion.

the class GuiArcaneCompendium method getPickedBlock.

private BlockCoord getPickedBlock(int cx, int cy, int mousex, int mousey) {
    BlockCoord block = null;
    float step_x = 14f;
    float step_y = -16.0f;
    float step_z = 7f;
    cy -= step_y * entryMultiblock.getMinLayer() / 2;
    cy -= step_y * entryMultiblock.getMaxLayer() / 2;
    int start = curLayer == -1 ? entryMultiblock.getMinLayer() : entryMultiblock.getMinLayer() + curLayer;
    int end = curLayer == -1 ? entryMultiblock.getMaxLayer() : entryMultiblock.getMinLayer() + curLayer;
    for (int i = start; i <= end; ++i) {
        TreeMap<BlockCoord, ArrayList<BlockDec>> layerBlocksSorted = getMultiblockLayer(i);
        float px = cx - (step_x * (entryMultiblock.getWidth() / 2));
        float py = cy - (step_z * (entryMultiblock.getLength() / 2));
        for (BlockCoord bc : layerBlocksSorted.keySet()) {
            //if (bc.getX() == 0 && bc.getY() == 0 && bc.getZ() == 0) continue;
            BlockDec bd = layerBlocksSorted.get(bc).get(0);
            float x = px + ((bc.getX() - bc.getZ()) * step_x);
            float y = py + ((bc.getZ() + bc.getX()) * step_z) + (step_y * i);
            x += 20;
            y -= 10;
            if (mousex > x && mousex < x + 32) {
                if (mousey > y && mousey < y + 32) {
                    block = bc;
                }
            }
        }
    }
    return block;
}
Also used : BlockDec(am2.api.blocks.MultiblockStructureDefinition.BlockDec) BlockCoord(am2.api.blocks.MultiblockStructureDefinition.BlockCoord)

Aggregations

BlockCoord (am2.api.blocks.MultiblockStructureDefinition.BlockCoord)5 BlockDec (am2.api.blocks.MultiblockStructureDefinition.BlockDec)4 StructureGroup (am2.api.blocks.MultiblockStructureDefinition.StructureGroup)2 ItemStack (net.minecraft.item.ItemStack)2 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1