Search in sources :

Example 16 with Int3

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

the class RitualEffectItemRouting 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() % 20 != 0) {
        return;
    }
    Map<Int3, IInventory> tileMap = new HashMap();
    List<IInventory> outputList = new ArrayList();
    for (// Check output foci chests, return if none available
    int i = 0; // Check output foci chests, return if none available
    i < 4; // Check output foci chests, return if none available
    i++) {
        Int3 outputFocusChest = this.getOutputBufferChestLocation(i);
        TileEntity outputFocusInv = world.getTileEntity(x + outputFocusChest.xCoord, y + outputFocusChest.yCoord, z + outputFocusChest.zCoord);
        if (outputFocusInv instanceof IInventory) {
            outputList.add((IInventory) outputFocusInv);
        }
    }
    if (outputList.isEmpty()) {
        return;
    }
    for (IInventory outputFocusInventory : outputList) {
        {
            OutputRoutingFocus outputFocus;
            ;
            RoutingFocusParadigm parad = new RoutingFocusParadigm();
            // Destination
            TileEntity outputChest = null;
            ForgeDirection inputDirection;
            {
                IInventory outputChestInventory = null;
                boolean lastItemWasFocus = true;
                for (int j = 0; j < outputFocusInventory.getSizeInventory(); j++) {
                    ItemStack keyStack = outputFocusInventory.getStackInSlot(j);
                    if (keyStack == null) {
                        continue;
                    }
                    if (keyStack.getItem() instanceof OutputRoutingFocus) {
                        if (!lastItemWasFocus) {
                            parad.clear();
                        }
                        outputFocus = (OutputRoutingFocus) keyStack.getItem();
                        parad.addRoutingFocusPosAndFacing(outputFocus.getPosAndFacing(keyStack));
                        parad.addLogic(outputFocus.getLogic(keyStack));
                        lastItemWasFocus = true;
                        continue;
                    } else {
                        lastItemWasFocus = false;
                    }
                    for (RoutingFocusPosAndFacing posAndFacing : parad.locationList) {
                        if (posAndFacing == null) {
                            continue;
                        }
                        inputDirection = posAndFacing.facing;
                        if (outputChest == null || !posAndFacing.location.equals(new Int3(outputChest.xCoord, outputChest.yCoord, outputChest.zCoord))) {
                            outputChest = world.getTileEntity(posAndFacing.location.xCoord, posAndFacing.location.yCoord, posAndFacing.location.zCoord);
                            if (outputChest instanceof IInventory) {
                                outputChestInventory = (IInventory) outputChest;
                            } else {
                                continue;
                            }
                        }
                        for (int i = 0; i < 4; i++) {
                            Int3 inputFocusChest = this.getInputBufferChestLocation(i);
                            TileEntity inputFocusInv = world.getTileEntity(x + inputFocusChest.xCoord, y + inputFocusChest.yCoord, z + inputFocusChest.zCoord);
                            if (inputFocusInv instanceof IInventory) {
                                for (// Iterate through foci inventory
                                int ji = 0; // Iterate through foci inventory
                                ji < ((IInventory) inputFocusInv).getSizeInventory(); // Iterate through foci inventory
                                ji++) {
                                    ItemStack inputFocusStack = ((IInventory) inputFocusInv).getStackInSlot(ji);
                                    if (inputFocusStack != null && inputFocusStack.getItem() instanceof InputRoutingFocus) {
                                        InputRoutingFocus inputFocus = (InputRoutingFocus) inputFocusStack.getItem();
                                        TileEntity inputChest = world.getTileEntity(inputFocus.xCoord(inputFocusStack), inputFocus.yCoord(inputFocusStack), inputFocus.zCoord(inputFocusStack));
                                        if (inputChest instanceof IInventory) {
                                            IInventory inputChestInventory = (IInventory) inputChest;
                                            ForgeDirection syphonDirection = inputFocus.getSetDirection(inputFocusStack);
                                            boolean[] canSyphonList = new boolean[inputChestInventory.getSizeInventory()];
                                            if (inputChest instanceof ISidedInventory) {
                                                int[] validSlots = ((ISidedInventory) inputChest).getAccessibleSlotsFromSide(syphonDirection.ordinal());
                                                for (int in : validSlots) {
                                                    canSyphonList[in] = true;
                                                }
                                            } else {
                                                for (int ni = 0; ni < inputChestInventory.getSizeInventory(); ni++) {
                                                    canSyphonList[ni] = true;
                                                }
                                            }
                                            for (int ni = 0; ni < inputChestInventory.getSizeInventory(); ni++) {
                                                if (canSyphonList[ni]) {
                                                    // Has a syphoned item linked, next need to find a destination
                                                    ItemStack syphonedStack = inputChestInventory.getStackInSlot(ni);
                                                    if (syphonedStack == null || (inputChestInventory instanceof ISidedInventory && !((ISidedInventory) inputChestInventory).canExtractItem(ni, syphonedStack, syphonDirection.ordinal()))) {
                                                        continue;
                                                    }
                                                    int size = syphonedStack.stackSize;
                                                    if (parad.doesItemMatch(keyStack, syphonedStack)) {
                                                        ItemStack newStack = null;
                                                        if (parad.maximumAmount <= 0) {
                                                            newStack = SpellHelper.insertStackIntoInventory(syphonedStack, outputChestInventory, inputDirection);
                                                        } else {
                                                            newStack = SpellHelper.insertStackIntoInventory(syphonedStack, outputChestInventory, inputDirection, parad.maximumAmount);
                                                        }
                                                        if (size == newStack.stackSize) {
                                                            continue;
                                                        }
                                                        int numberSyphoned = size - newStack.stackSize;
                                                        if (newStack != null && newStack.stackSize <= 0) {
                                                            size = newStack.stackSize;
                                                            newStack = null;
                                                        }
                                                        inputChestInventory.setInventorySlotContents(ni, newStack);
                                                    // break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) HashMap(java.util.HashMap) Int3(WayofTime.alchemicalWizardry.api.Int3) ArrayList(java.util.ArrayList) InputRoutingFocus(WayofTime.alchemicalWizardry.common.items.routing.InputRoutingFocus) OutputRoutingFocus(WayofTime.alchemicalWizardry.common.items.routing.OutputRoutingFocus) RoutingFocusParadigm(WayofTime.alchemicalWizardry.api.RoutingFocusParadigm) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) ISidedInventory(net.minecraft.inventory.ISidedInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) RoutingFocusPosAndFacing(WayofTime.alchemicalWizardry.api.RoutingFocusPosAndFacing)

Example 17 with Int3

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

the class RitualEffectMagnetic 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();
    boolean hasPotentia = this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, false);
    if (world.getWorldTime() % (hasPotentia ? 10 : 40) != 0) {
        return;
    }
    boolean hasTerrae = this.canDrainReagent(ritualStone, ReagentRegistry.terraeReagent, terraeDrain, false);
    boolean hasOrbisTerrae = this.canDrainReagent(ritualStone, ReagentRegistry.orbisTerraeReagent, orbisTerraeDrain, false);
    int radius = this.getRadiusForReagents(hasTerrae, hasOrbisTerrae);
    if (currentEssence < this.getCostPerRefresh()) {
        SoulNetworkHandler.causeNauseaToPlayer(owner);
    } else {
        int xRep = 0;
        int yRep = 0;
        int zRep = 0;
        boolean replace = false;
        outer: for (int j = 1; j <= 3; j++) {
            for (int i = -1; i <= 1; i++) {
                for (int k = -1; k <= 1; k++) {
                    if ((!replace) && world.isAirBlock(x + i, y + j, z + k)) {
                        xRep = x + i;
                        yRep = y + j;
                        zRep = z + k;
                        replace = true;
                        break outer;
                    }
                }
            }
        }
        if (replace) {
            Int3 lastPos = this.getLastPosition(ritualStone.getCustomRitualTag());
            int j = y - 1;
            int i = 0;
            int k = 0;
            if (lastPos != null) {
                j = lastPos.yCoord;
                i = Math.min(radius, Math.max(-radius, lastPos.xCoord));
                k = Math.min(radius, Math.max(-radius, lastPos.zCoord));
            }
            while (j >= 0) {
                while (i <= radius) {
                    while (k <= radius) {
                        Block block = world.getBlock(x + i, j, z + k);
                        int meta = world.getBlockMetadata(x + i, j, z + k);
                        if (isBlockOre(block, meta)) {
                            // Allow swapping code. This means the searched block is an ore.
                            BlockTeleposer.swapBlocks(this, world, world, x + i, j, z + k, xRep, yRep, zRep);
                            SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh());
                            if (hasPotentia) {
                                this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, true);
                            }
                            if (hasTerrae) {
                                this.canDrainReagent(ritualStone, ReagentRegistry.terraeReagent, terraeDrain, true);
                            }
                            if (hasOrbisTerrae) {
                                this.canDrainReagent(ritualStone, ReagentRegistry.orbisTerraeReagent, orbisTerraeDrain, true);
                            }
                            this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
                            return;
                        }
                        k++;
                    }
                    k = -radius;
                    i++;
                }
                i = -radius;
                j--;
                this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
                return;
            }
            j = y - 1;
            this.setLastPosition(ritualStone.getCustomRitualTag(), new Int3(i, j, k));
            return;
        }
    }
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) Block(net.minecraft.block.Block) World(net.minecraft.world.World)

Example 18 with Int3

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

the class EntityDemonAIHurtByTarget method startExecuting.

@Override
public void startExecuting() {
    Int3 portalPosition = ((IHoardDemon) this.taskOwner).getPortalLocation();
    if (portalPosition == null) {
        super.startExecuting();
        return;
    }
    TileEntity portal = this.taskOwner.worldObj.getTileEntity(portalPosition.xCoord, portalPosition.yCoord, portalPosition.zCoord);
    if ((this.taskOwner.getAITarget() instanceof IHoardDemon && portalPosition.equals(((IHoardDemon) this.taskOwner.getAITarget()).getPortalLocation()))) {
        return;
    }
    this.taskOwner.setAttackTarget(this.taskOwner.getAITarget());
    if (this.entityCallsForHelp && this.taskOwner instanceof IHoardDemon) {
        if (portal instanceof TEDemonPortal) {
            ((TEDemonPortal) portal).notifyDemons(taskOwner, this.taskOwner.getAITarget(), 25);
        }
    // double d0 = this.getTargetDistance();
    // List list = this.taskOwner.worldObj.getEntitiesWithinAABB(this.taskOwner.getClass(), AxisAlignedBB.getBoundingBox(this.taskOwner.posX, this.taskOwner.posY, this.taskOwner.posZ, this.taskOwner.posX + 1.0D, this.taskOwner.posY + 1.0D, this.taskOwner.posZ + 1.0D).expand(d0, 10.0D, d0));
    // Iterator iterator = list.iterator();
    // 
    // while (iterator.hasNext())
    // {
    // EntityCreature entitycreature = (EntityCreature)iterator.next();
    // 
    // if (this.taskOwner != entitycreature && entitycreature.getAttackTarget() == null && !entitycreature.isOnSameTeam(this.taskOwner.getAITarget()))
    // {
    // entitycreature.setAttackTarget(this.taskOwner.getAITarget());
    // }
    // }
    }
    super.startExecuting();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Int3(WayofTime.alchemicalWizardry.api.Int3) TEDemonPortal(WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.TEDemonPortal) IHoardDemon(WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.demon.IHoardDemon)

Example 19 with Int3

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

the class TEDemonPortal method createPortalBuilding.

/**
 * The Stage is at what point the portal is in reacting to the creation of the Demon Portal.
 * Stage == 0 means just the saving
 * Stage == 1 means to telepose the portal
 * Stage == 2 means the teleposition is complete and that the building may be constructed
 */
public void createPortalBuilding(int stage, String name, int tier) {
    for (DemonBuilding build : TEDemonPortal.buildingList) {
        if (build.buildingType != DemonBuilding.BUILDING_PORTAL || build.buildingTier != tier) {
            continue;
        }
        if (build.getName().equals(this.nextDemonPortalName)) {
            int x = 0;
            int z = 0;
            GridSpace home = this.getGridSpace(x, z);
            int yLevel = home.getYLevel();
            GridSpaceHolder grid = this.createGSH();
            ForgeDirection chosenDirection = this.nextDemonPortalDirection;
            Int3 portalSpace = build.getDoorSpace(chosenDirection);
            int yOffset = portalSpace.yCoord;
            switch(stage) {
                case 0:
                    break;
                case 1:
                    int yDestination = yLevel + yOffset;
                    if (yCoord != yDestination) {
                        BlockTeleposer.swapBlocks(this, worldObj, worldObj, xCoord, yCoord, zCoord, xCoord, yDestination, zCoord);
                    } else {
                    // Nuthin - just as a reminder that we can now increment properly
                    }
                    break;
                case 2:
                    build.destroyAllInField(worldObj, xCoord + (x) * 5, yLevel, zCoord + (z) * 5, chosenDirection.getOpposite());
                    build.buildAll(this, worldObj, xCoord + (x) * 5, yLevel, zCoord + (z) * 5, chosenDirection.getOpposite(), true);
                    build.setAllGridSpaces(x, z, yLevel, chosenDirection.getOpposite(), GridSpace.MAIN_PORTAL, grid);
                    this.loadGSH(grid);
                    break;
            }
            return;
        }
    }
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) DemonBuilding(WayofTime.alchemicalWizardry.common.demonVillage.DemonBuilding) GridSpaceHolder(WayofTime.alchemicalWizardry.common.demonVillage.GridSpaceHolder) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) GridSpace(WayofTime.alchemicalWizardry.common.demonVillage.GridSpace)

Example 20 with Int3

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

the class TEDemonPortal method createGriddedRoad.

public // Total grid length
int createGriddedRoad(// Total grid length
int gridXi, // Total grid length
int yi, // Total grid length
int gridZi, // Total grid length
ForgeDirection dir, // Total grid length
int gridLength, // Total grid length
boolean convertStarter) {
    if (gridLength == 0 || gridLength == 1) {
        return 0;
    }
    int initGridX = gridXi;
    int initGridZ = gridZi;
    int initY = yi;
    if (convertStarter) {
        this.setGridSpace(initGridX, initGridZ, new GridSpace(GridSpace.CROSSROAD, initY));
        DemonCrosspath crosspath = new DemonCrosspath(xCoord + initGridX * 5, initY, zCoord + initGridZ * 5);
        crosspath.createCrosspath(worldObj);
    }
    for (int index = 0; index < gridLength - 1; index++) {
        DemonVillagePath path = new DemonVillagePath(xCoord + initGridX * 5, initY, zCoord + initGridZ * 5, dir, 6);
        Int3AndBool temp = path.constructFullPath(this, worldObj, this.getRoadStepClearance());
        Int3 next = temp.coords;
        if (next != null) {
            initY = next.yCoord;
            if (printDebug)
                AlchemicalWizardry.logger.info("" + initY);
        }
        if (!temp.bool) {
            return index;
        }
        initGridX += dir.offsetX;
        initGridZ += dir.offsetZ;
        if (!this.getGridSpace(initGridX, initGridZ).isRoadSegment()) {
            this.setGridSpace(initGridX, initGridZ, new GridSpace(GridSpace.ROAD, initY));
        }
    }
    return gridLength - 1;
}
Also used : Int3AndBool(WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath.Int3AndBool) DemonCrosspath(WayofTime.alchemicalWizardry.common.demonVillage.DemonCrosspath) Int3(WayofTime.alchemicalWizardry.api.Int3) GridSpace(WayofTime.alchemicalWizardry.common.demonVillage.GridSpace) DemonVillagePath(WayofTime.alchemicalWizardry.common.demonVillage.DemonVillagePath)

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