Search in sources :

Example 11 with Int3

use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.

the class ItemRitualDiviner method onUpdate.

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
    if (entity instanceof EntityPlayer && hasStoredLocation(stack) && world.getWorldTime() % 5 == 0) {
        Int3 loc = getStoredLocation(stack);
        int x = loc.xCoord;
        int y = loc.yCoord;
        int z = loc.zCoord;
        if (!this.placeRitualStoneAtMasterStone(stack, (EntityPlayer) entity, world, x, y, z)) {
            this.voidStoredLocation(stack);
        }
    }
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 12 with Int3

use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.

the class RitualEffectSphereCreator method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    if (world.getWorldTime() % 1 != 0) {
        return;
    }
    if (currentEssence < this.getCostPerRefresh()) {
        SoulNetworkHandler.causeNauseaToPlayer(owner);
    } else {
        TileEntity tile = world.getTileEntity(x, y + 1, z);
        if (!(tile instanceof IInventory)) {
            return;
        }
        int negYOffset = 0;
        int radius = 0;
        IInventory inv = (IInventory) tile;
        int invSize = inv.getSizeInventory();
        if (invSize < 1) {
            return;
        } else {
            if (invSize >= 2) {
                ItemStack invStack2 = inv.getStackInSlot(1);
                if (invStack2 != null) {
                    negYOffset = invStack2.stackSize;
                }
            }
            ItemStack invStack1 = inv.getStackInSlot(0);
            if (invStack1 == null) {
                return;
            }
            radius = invStack1.stackSize;
        }
        if (radius <= 0) {
            return;
        }
        radius = Math.min(radius, MAX_RADIUS);
        if (negYOffset < radius + 3) {
            negYOffset = radius + 3;
        }
        Int3 lastPos = this.getLastPosition(ritualStone.getCustomRitualTag(), radius);
        int j = -radius;
        int i = -radius;
        int k = -radius;
        if (lastPos != null) {
            j = Math.min(radius, Math.max(-radius, lastPos.yCoord));
            i = Math.min(radius, Math.max(-radius, lastPos.xCoord));
            k = Math.min(radius, Math.max(-radius, lastPos.zCoord));
        }
        int yP = y + negYOffset;
        int yN = y - negYOffset;
        boolean incrementNext = false;
        while (i <= radius) {
            while (j <= radius) {
                while (k <= radius) {
                    if (i * i + j * j + k * k >= (radius + 0.50f) * (radius + 0.50f)) {
                        k++;
                        continue;
                    }
                    if (incrementNext) {
                        this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
                        return;
                    }
                    Block blk = world.getBlock(x + i, yP + j, z + k);
                    if (world.isAirBlock(x + i, yN + j, z + k) || (!world.isAirBlock(x + i, yP + j, z + k) && !SpellHelper.isBlockFluid(blk))) {
                        k++;
                        continue;
                    }
                    if (BlockTeleposer.swapBlocks(this, world, world, x + i, yN + j, z + k, x + i, yP + j, z + k, false, 2)) {
                        SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh());
                        if (this.canDrainReagent(ritualStone, ReagentRegistry.terraeReagent, terraeDrain, true)) {
                            world.setBlock(x + i, yN + j, z + k, Blocks.dirt, 0, 2);
                        }
                    }
                    this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
                    incrementNext = true;
                    k++;
                }
                k = -radius;
                j++;
            }
            j = -radius;
            i++;
        // this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
        // return;
        }
        ritualStone.setActive(false);
        this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) Int3(WayofTime.alchemicalWizardry.api.Int3) Block(net.minecraft.block.Block) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack)

Example 13 with Int3

use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.

the class RitualEffectCrafting method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    // long startTime = System.nanoTime();
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    boolean hasPotentia = this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, false);
    if (world.getWorldTime() % (hasPotentia ? 1 : 4) != 0) {
        return;
    }
    if (currentEssence < this.getCostPerRefresh()) {
        SoulNetworkHandler.causeNauseaToPlayer(owner);
    } else {
        NBTTagCompound tag = ritualStone.getCustomRitualTag();
        if (tag == null) {
            ritualStone.setCustomRitualTag(new NBTTagCompound());
            tag = ritualStone.getCustomRitualTag();
        }
        boolean lastFailed = tag.getBoolean("didLastCraftFail");
        int slotDesignation = tag.getInteger("slotDesignation");
        if (lastFailed) {
            slotDesignation++;
            tag.setInteger("slotDesignation", slotDesignation);
            tag.setBoolean("didLastCraftFail", false);
        }
        int direction = ritualStone.getDirection();
        boolean canContinue = false;
        ItemStack[] recipe = new ItemStack[9];
        InventoryCrafting inventory = new InventoryCrafting(new Container() {

            public boolean canInteractWith(EntityPlayer player) {
                return false;
            }
        }, 3, 3);
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                int gridSpace = (i + 1) * 3 + (j + 1);
                Int3 pos = this.getSlotPositionForDirection(gridSpace, direction);
                TileEntity inv = world.getTileEntity(x + pos.xCoord, y + pos.yCoord, z + pos.zCoord);
                if (inv instanceof IInventory) {
                    if (((IInventory) inv).getSizeInventory() <= slotDesignation || !((IInventory) inv).isItemValidForSlot(slotDesignation, ((IInventory) inv).getStackInSlot(slotDesignation))) {
                        continue;
                    } else {
                        ItemStack invStack = ((IInventory) inv).getStackInSlot(slotDesignation);
                        if (invStack != null) {
                            inventory.setInventorySlotContents(gridSpace, invStack);
                            recipe[gridSpace] = invStack;
                            canContinue = true;
                        }
                    }
                }
            }
        }
        if (!canContinue) {
            tag.setInteger("slotDesignation", 0);
            return;
        }
        ItemStack returnStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world);
        if (returnStack == null) {
            tag.setBoolean("didLastCraftFail", true);
        } else {
            boolean hasVirtus = this.canDrainReagent(ritualStone, ReagentRegistry.virtusReagent, virtusDrain, false);
            boolean addOutputToInputs = hasVirtus;
            IInventory outputInv = null;
            List<IInventory> invList = new ArrayList();
            TileEntity northEntity = world.getTileEntity(x, y - 1, z - 2);
            TileEntity southEntity = world.getTileEntity(x, y - 1, z + 2);
            TileEntity eastEntity = world.getTileEntity(x + 2, y - 1, z);
            TileEntity westEntity = world.getTileEntity(x - 2, y - 1, z);
            switch(direction) {
                case 1:
                    if (southEntity instanceof IInventory) {
                        outputInv = (IInventory) southEntity;
                    } else {
                        return;
                    }
                    if (northEntity instanceof IInventory) {
                        invList.add((IInventory) northEntity);
                    }
                    if (eastEntity instanceof IInventory) {
                        invList.add((IInventory) eastEntity);
                    }
                    if (westEntity instanceof IInventory) {
                        invList.add((IInventory) westEntity);
                    }
                    break;
                case 2:
                    if (westEntity instanceof IInventory) {
                        outputInv = (IInventory) westEntity;
                    } else {
                        return;
                    }
                    if (northEntity instanceof IInventory) {
                        invList.add((IInventory) northEntity);
                    }
                    if (eastEntity instanceof IInventory) {
                        invList.add((IInventory) eastEntity);
                    }
                    if (southEntity instanceof IInventory) {
                        invList.add((IInventory) southEntity);
                    }
                    break;
                case 3:
                    if (northEntity instanceof IInventory) {
                        outputInv = (IInventory) northEntity;
                    } else {
                        return;
                    }
                    if (eastEntity instanceof IInventory) {
                        invList.add((IInventory) eastEntity);
                    }
                    if (southEntity instanceof IInventory) {
                        invList.add((IInventory) southEntity);
                    }
                    if (westEntity instanceof IInventory) {
                        invList.add((IInventory) westEntity);
                    }
                    break;
                case 4:
                    if (eastEntity instanceof IInventory) {
                        outputInv = (IInventory) eastEntity;
                    } else {
                        return;
                    }
                    if (northEntity instanceof IInventory) {
                        invList.add((IInventory) northEntity);
                    }
                    if (southEntity instanceof IInventory) {
                        invList.add((IInventory) southEntity);
                    }
                    if (westEntity instanceof IInventory) {
                        invList.add((IInventory) westEntity);
                    }
                    break;
            }
            if (outputInv != null) {
                if (!(!limitToSingleStack ? SpellHelper.canInsertStackFullyIntoInventory(returnStack, outputInv, ForgeDirection.DOWN) : SpellHelper.canInsertStackFullyIntoInventory(returnStack, outputInv, ForgeDirection.DOWN, true, returnStack.getMaxStackSize()))) {
                    tag.setBoolean("didLastCraftFail", true);
                    return;
                }
                if (addOutputToInputs) {
                    invList.add(outputInv);
                }
                // Inventory, Slot, how much claimed
                Map<Integer, Map<Integer, Integer>> syphonMap = new HashMap();
                for (// Look for the correct items
                int n = 0; // Look for the correct items
                n < recipe.length; // Look for the correct items
                n++) {
                    ItemStack recipeStack = recipe[n];
                    if (recipeStack == null) {
                        continue;
                    }
                    boolean isItemTaken = false;
                    for (int i = 0; i < invList.size(); i++) {
                        if (isItemTaken) {
                            break;
                        }
                        IInventory inputInv = invList.get(i);
                        if (inputInv == null) {
                            continue;
                        }
                        for (int j = 0; j < inputInv.getSizeInventory(); j++) {
                            if (!inputInv.isItemValidForSlot(j, recipeStack)) {
                                continue;
                            }
                            ItemStack invItem = inputInv.getStackInSlot(j);
                            if (invItem == null) {
                                continue;
                            }
                            if (this.areItemsEqualForCrafting(recipeStack, invItem)) {
                                // TODO
                                inventory.setInventorySlotContents(n, invItem);
                                // ItemStack returnedStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world);
                                // if(returnedStack == null || returnedStack.getItem() == null || returnedStack.getItem() != returnStack.getItem())
                                // {
                                // continue;
                                // }
                                Map<Integer, Integer> slotMap = syphonMap.get(i);
                                if (slotMap == null) {
                                    slotMap = new HashMap();
                                    syphonMap.put(i, slotMap);
                                }
                                if (slotMap.containsKey(j)) {
                                    int syphoned = slotMap.get(j);
                                    if (invItem.stackSize - syphoned > 0) {
                                        slotMap.put(j, syphoned + 1);
                                        isItemTaken = true;
                                        break;
                                    }
                                } else {
                                    slotMap.put(j, 1);
                                    isItemTaken = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!isItemTaken) {
                        tag.setBoolean("didLastCraftFail", true);
                        return;
                    }
                }
                /* The recipe is valid and the items have been found */
                SpellHelper.insertStackIntoInventory(CraftingManager.getInstance().findMatchingRecipe(inventory, world), outputInv, ForgeDirection.DOWN);
                for (Entry<Integer, Map<Integer, Integer>> entry1 : syphonMap.entrySet()) {
                    IInventory inputInv = invList.get(entry1.getKey());
                    for (Entry<Integer, Integer> entry2 : entry1.getValue().entrySet()) {
                        ItemStack drainedStack = inputInv.getStackInSlot(entry2.getKey());
                        Item item = drainedStack.getItem();
                        if (item.hasContainerItem(drainedStack)) {
                            inputInv.setInventorySlotContents(entry2.getKey(), item.getContainerItem(drainedStack));
                        } else {
                            drainedStack.stackSize -= entry2.getValue();
                            if (drainedStack.stackSize <= 0) {
                                inputInv.setInventorySlotContents(entry2.getKey(), null);
                            }
                        }
                    }
                }
                if (addOutputToInputs && syphonMap.containsKey(invList.size())) {
                    this.canDrainReagent(ritualStone, ReagentRegistry.virtusReagent, virtusDrain, true);
                }
                SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh());
                if (hasPotentia) {
                    this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, true);
                }
                world.markBlockForUpdate(x, y - 1, z + 2);
                world.markBlockForUpdate(x, y - 1, z - 2);
                world.markBlockForUpdate(x + 2, y - 1, z);
                world.markBlockForUpdate(x - 2, y - 1, z);
            // long endTime = System.nanoTime();
            // 
            // long duration = (endTime - startTime);  //divide by 1000000 to get milliseconds.
            // System.out.println("(Total) method time in ms: " + (float)(duration)/1000000.0);
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) HashMap(java.util.HashMap) Int3(WayofTime.alchemicalWizardry.api.Int3) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) Container(net.minecraft.inventory.Container) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Int3

use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.

the class RitualEffectDemonPortal method checkJars.

public boolean checkJars(IMasterRitualStone ritualStone) {
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    for (Int3 pos : jarLocations) {
        if (!(ritualStone.getWorld().getTileEntity(x + pos.xCoord, y + pos.yCoord, z + pos.zCoord) instanceof TEBellJar)) {
            return false;
        }
    }
    return true;
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) TEBellJar(WayofTime.alchemicalWizardry.common.tileEntity.TEBellJar)

Example 15 with Int3

use of WayofTime.alchemicalWizardry.api.Int3 in project BloodMagic by WayofTime.

the class RitualEffectOmegaTest method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    if (world.getWorldTime() % 200 != 0) {
        return;
    }
    OmegaStructureParameters param = OmegaStructureHandler.getStructureStabilityFactor(world, x, y, z, 5, new Int3(0, 1, 0));
    int stab = param.stability;
    int enchantability = param.enchantability;
    int enchantmentLevel = param.enchantmentLevel;
    if (stab <= 0) {
        return;
    }
    // System.out.println("Stability: " + stab + ", Enchantability: " + enchantability + ", Enchantment Level: " + enchantmentLevel);
    double range = 0.5;
    List<EntityPlayer> playerList = SpellHelper.getPlayersInRange(world, x + 0.5, y + 1.5, z + 0.5, range, range);
    Reagent reagent = null;
    Map<Reagent, Integer> reagentMap = new HashMap();
    for (int i = 0; i < 4; i++) {
        Int3 jarLoc = this.getJarLocation(i);
        TileEntity tile = world.getTileEntity(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
        if (tile instanceof IReagentHandler) {
            IReagentHandler container = (IReagentHandler) tile;
            ReagentContainerInfo[] containerInfoArray = container.getContainerInfo(ForgeDirection.UP);
            if (containerInfoArray == null) {
                continue;
            }
            for (ReagentContainerInfo containerInfo : containerInfoArray) {
                ReagentStack containedReagent = containerInfo.reagent;
                if (containedReagent == null) {
                    continue;
                }
                Reagent rea = containedReagent.reagent;
                int amt = containedReagent.amount;
                if (reagentMap.containsKey(rea)) {
                    reagentMap.put(rea, reagentMap.get(rea) + amt);
                } else {
                    reagentMap.put(rea, amt);
                }
            }
        }
    }
    for (Entry<Reagent, Integer> entry : reagentMap.entrySet()) {
        if (entry.getValue() >= drainTotal) {
            reagent = entry.getKey();
            break;
        }
    }
    if (reagent == null) {
        return;
    }
    int tickDuration = isTesting ? 20 * 30 : 15 * 20 * 60 + (int) ((15 * 20 * 60) * Math.sqrt(stab / 700));
    int affinity = 0;
    for (EntityPlayer player : playerList) {
        OmegaParadigm waterParadigm = OmegaRegistry.getParadigmForReagent(reagent);
        if (waterParadigm != null && waterParadigm.convertPlayerArmour(player, x, y, z, stab, affinity, enchantability, enchantmentLevel)) {
            APISpellHelper.setPlayerCurrentReagentAmount(player, tickDuration);
            APISpellHelper.setPlayerMaxReagentAmount(player, tickDuration);
            APISpellHelper.setPlayerReagentType(player, reagent);
            APISpellHelper.setCurrentAdditionalMaxHP(player, waterParadigm.getMaxAdditionalHealth());
            NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getReagentBarPacket(reagent, APISpellHelper.getPlayerCurrentReagentAmount(player), APISpellHelper.getPlayerMaxReagentAmount(player)), (EntityPlayerMP) player);
            if (!isTesting) {
                int drainLeft = this.drainTotal;
                for (int i = 0; i < 4; i++) {
                    if (drainLeft <= 0) {
                        break;
                    }
                    Int3 jarLoc = this.getJarLocation(i);
                    TileEntity tile = world.getTileEntity(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
                    if (tile instanceof IReagentHandler) {
                        IReagentHandler container = (IReagentHandler) tile;
                        ReagentStack drained = container.drain(ForgeDirection.UP, new ReagentStack(reagent, drainLeft), true);
                        if (drained != null) {
                            drainLeft -= drained.amount;
                            world.markBlockForUpdate(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
                            world.addWeatherEffect(new EntityLightningBolt(world, x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord));
                        }
                    }
                }
                ritualStone.setActive(false);
            }
            break;
        }
    }
}
Also used : HashMap(java.util.HashMap) ReagentContainerInfo(WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo) Int3(WayofTime.alchemicalWizardry.api.Int3) OmegaStructureParameters(WayofTime.alchemicalWizardry.common.omega.OmegaStructureParameters) ReagentStack(WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) World(net.minecraft.world.World) Reagent(WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent) IReagentHandler(WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) OmegaParadigm(WayofTime.alchemicalWizardry.common.omega.OmegaParadigm)

Aggregations

Int3 (WayofTime.alchemicalWizardry.api.Int3)34 TileEntity (net.minecraft.tileentity.TileEntity)10 LinkedList (java.util.LinkedList)7 Block (net.minecraft.block.Block)6 NBTTagList (net.minecraft.nbt.NBTTagList)6 World (net.minecraft.world.World)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 IInventory (net.minecraft.inventory.IInventory)4 ItemStack (net.minecraft.item.ItemStack)4 GridSpace (WayofTime.alchemicalWizardry.common.demonVillage.GridSpace)3 DemonBuilding (WayofTime.alchemicalWizardry.common.demonVillage.DemonBuilding)2 DemonVillagePath (WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath)2 Int3AndBool (WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath.Int3AndBool)2 GridSpaceHolder (WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder)2 TEDemonPortal (WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.TEDemonPortal)2