Search in sources :

Example 1 with BlockCoord

use of am2.api.blocks.MultiblockStructureDefinition.BlockCoord 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 BlockCoord

use of am2.api.blocks.MultiblockStructureDefinition.BlockCoord 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 3 with BlockCoord

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

the class EntityAISpellmaking method updateTask.

@Override
public void updateTask() {
    AMVector3 targetLocation = host.getSearchLocation();
    AMVector3 dropLocation = host.getDropLocation();
    AMVector3 hostLocation = new AMVector3(host);
    ItemStack searchItem = host.getSearchItem();
    if (searchItem.getItem() == ItemsCommonProxy.essence && searchItem.getItemDamage() > ItemsCommonProxy.essence.META_MAX) {
        TileEntityCraftingAltar altar = host.getAltarTarget();
        if (altar.switchIsOn())
            return;
        BlockCoord bc = altar.getSwitchLocation();
        if (action_state == 0 && host.getNavigator().noPath()) {
            host.getNavigator().tryMoveToXYZ(altar.xCoord + bc.x, altar.yCoord + bc.y, altar.zCoord + bc.z, MOVE_SPEED);
        } else if (action_state == 0 && hostLocation.distanceSqTo(new AMVector3(altar.xCoord + bc.x, altar.yCoord + bc.y, altar.zCoord + bc.z)) < DISTANCE_THRESHOLD) {
            action_state = 1;
            altar.flipSwitch();
            wait_counter = 0;
        } else if (action_state == 1 && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 1 && wait_counter >= WAIT_TIME) {
            resetTask();
        }
    } else {
        if (action_state == 0 && host.getNavigator().noPath()) {
            //no item and too far away to grab			
            host.getNavigator().tryMoveToXYZ(targetLocation.x, targetLocation.y, targetLocation.z, MOVE_SPEED);
        } else if (action_state == 0 && hostLocation.distanceSqTo(targetLocation) < DISTANCE_THRESHOLD) {
            host.getNavigator().clearPathEntity();
            TileEntity te = host.worldObj.getTileEntity((int) targetLocation.x, (int) targetLocation.y, (int) targetLocation.z);
            if (te == null || !(te instanceof IInventory)) {
                resetTask();
                return;
            }
            ((IInventory) te).openInventory();
            if (!host.worldObj.isRemote)
                InventoryUtilities.deductFromInventory(((IInventory) te), host.getSearchItem(), 1);
            host.setHeldItem(host.getSearchItem());
            action_state = 1;
        } else if (action_state == 1 && host.getNavigator().noPath() && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 1 && host.getNavigator().noPath() && wait_counter >= WAIT_TIME) {
            wait_counter = 0;
            TileEntity te = host.worldObj.getTileEntity((int) targetLocation.x, (int) targetLocation.y, (int) targetLocation.z);
            if (te == null || !(te instanceof IInventory)) {
                resetTask();
                return;
            }
            ((IInventory) te).closeInventory();
            host.getNavigator().tryMoveToXYZ(dropLocation.x, dropLocation.y, dropLocation.z, MOVE_SPEED);
        } else if (action_state == 1 && hostLocation.distanceSqTo(dropLocation) < DISTANCE_THRESHOLD) {
            host.getNavigator().clearPathEntity();
            if (!host.worldObj.isRemote) {
                EntityItem droppedItem = host.entityDropItem(host.getSearchItem(), 0f);
                host.setHeldItem(new ItemStack(Items.paper));
            }
            action_state = 2;
        } else if (action_state == 2 && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 2 && wait_counter >= WAIT_TIME) {
            resetTask();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityCraftingAltar(am2.blocks.tileentities.TileEntityCraftingAltar) ItemStack(net.minecraft.item.ItemStack) BlockCoord(am2.api.blocks.MultiblockStructureDefinition.BlockCoord) EntityItem(net.minecraft.entity.item.EntityItem)

Example 4 with BlockCoord

use of am2.api.blocks.MultiblockStructureDefinition.BlockCoord 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 BlockCoord

use of am2.api.blocks.MultiblockStructureDefinition.BlockCoord 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)6 BlockDec (am2.api.blocks.MultiblockStructureDefinition.BlockDec)3 StructureGroup (am2.api.blocks.MultiblockStructureDefinition.StructureGroup)2 ItemStack (net.minecraft.item.ItemStack)2 AMVector3 (am2.api.math.AMVector3)1 TileEntityCraftingAltar (am2.blocks.tileentities.TileEntityCraftingAltar)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 EntityItem (net.minecraft.entity.item.EntityItem)1 IInventory (net.minecraft.inventory.IInventory)1 TileEntity (net.minecraft.tileentity.TileEntity)1