Search in sources :

Example 6 with Int3

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

the class TEReagentConduit method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound tag) {
    super.writeToNBT(tag);
    tag.setInteger("hasChanged", hasChanged);
    NBTTagList tagList = new NBTTagList();
    for (int i = 0; i < destinationList.size(); i++) {
        NBTTagCompound savedTag = new NBTTagCompound();
        tagList.appendTag(destinationList.get(i).writeToNBT(savedTag));
    }
    tag.setTag("destinationList", tagList);
    // TODO
    NBTTagList reagentTagList = new NBTTagList();
    for (Entry<Reagent, List<Int3>> entry : reagentTargetList.entrySet()) {
        NBTTagCompound savedTag = new NBTTagCompound();
        savedTag.setString("reagent", ReagentRegistry.getKeyForReagent(entry.getKey()));
        NBTTagList coordinateTagList = new NBTTagList();
        for (Int3 coord : entry.getValue()) {
            NBTTagCompound coordinateTag = new NBTTagCompound();
            coord.writeToNBT(coordinateTag);
            coordinateTagList.appendTag(coordinateTag);
        }
        savedTag.setTag("coordinateList", coordinateTagList);
        reagentTagList.appendTag(savedTag);
    }
    tag.setTag("reagentTargetList", reagentTagList);
    NBTTagList tankDesignationList = new NBTTagList();
    for (Entry<Reagent, Integer> entry : this.reagentTankDesignationList.entrySet()) {
        NBTTagCompound savedTag = new NBTTagCompound();
        savedTag.setString("reagent", ReagentRegistry.getKeyForReagent(entry.getKey()));
        savedTag.setInteger("integer", entry.getValue());
        tankDesignationList.appendTag(savedTag);
    }
    tag.setTag("tankDesignationList", tankDesignationList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Int3(WayofTime.alchemicalWizardry.api.Int3) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 7 with Int3

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

the class TEReagentConduit method addReagentDestinationViaOffset.

public boolean addReagentDestinationViaOffset(Reagent reagent, int xOffset, int yOffset, int zOffset) {
    int totalConnections = 0;
    for (Entry<Reagent, List<Int3>> entry : this.reagentTargetList.entrySet()) {
        if (entry.getValue() != null) {
            totalConnections += entry.getValue().size();
        }
    }
    if (totalConnections >= this.maxConnextions) {
        // Send message that it cannot be done? Maybe add a Player instance
        return false;
    }
    if (xOffset == 0 && yOffset == 0 && zOffset == 0) {
        return false;
    }
    Int3 newCoord = new Int3(xOffset, yOffset, zOffset);
    if (this.reagentTargetList.containsKey(reagent)) {
        List<Int3> coordList = this.reagentTargetList.get(reagent);
        if (coordList == null) {
            List<Int3> newCoordList = new LinkedList();
            newCoordList.add(newCoord);
            this.reagentTargetList.put(reagent, newCoordList);
        } else {
            coordList.add(newCoord);
        }
        return true;
    } else {
        List<Int3> newCoordList = new LinkedList();
        newCoordList.add(newCoord);
        this.reagentTargetList.put(reagent, newCoordList);
        return true;
    }
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 8 with Int3

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

the class BuildingSchematic method getGriddedPositions.

public List<Int3> getGriddedPositions(ForgeDirection dir) {
    List<Int3> positionList = new ArrayList();
    for (BlockSet blockSet : blockList) {
        for (Int3 pos : blockSet.getPositions()) {
            int xOff = pos.xCoord;
            int zOff = pos.zCoord;
            switch(dir) {
                case SOUTH:
                    xOff *= -1;
                    zOff *= -1;
                    break;
                case WEST:
                    int temp = zOff;
                    zOff = xOff * -1;
                    xOff = temp;
                    break;
                case EAST:
                    int temp2 = zOff * -1;
                    zOff = xOff;
                    xOff = temp2;
                    break;
                default:
            }
            Int3 nextPos = new Int3(xOff, 0, zOff);
            if (!positionList.contains(nextPos)) {
                positionList.add(nextPos);
            }
        }
    }
    return positionList;
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) ArrayList(java.util.ArrayList)

Example 9 with Int3

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

the class ItemAttunedCrystal method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
    if (world.isRemote) {
        return itemStack;
    }
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, false);
    if (movingobjectposition == null) {
        if (player.isSneaking()) {
            this.setHasSavedCoordinates(itemStack, false);
            player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.clearing"));
        }
        return itemStack;
    } else {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
            int x = movingobjectposition.blockX;
            int y = movingobjectposition.blockY;
            int z = movingobjectposition.blockZ;
            TileEntity tile = world.getTileEntity(x, y, z);
            if (!(tile instanceof IReagentHandler)) {
                return itemStack;
            }
            IReagentHandler relay = (IReagentHandler) tile;
            if (player.isSneaking()) {
                ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.UNKNOWN);
                if (infos != null) {
                    List<Reagent> reagentList = new LinkedList();
                    for (ReagentContainerInfo info : infos) {
                        if (info != null) {
                            ReagentStack reagentStack = info.reagent;
                            if (reagentStack != null) {
                                Reagent reagent = reagentStack.reagent;
                                if (reagent != null) {
                                    reagentList.add(reagent);
                                }
                            }
                        }
                    }
                    Reagent pastReagent = this.getReagent(itemStack);
                    if (reagentList.size() <= 0) {
                        return itemStack;
                    }
                    int reagentLocation;
                    reagentLocation = reagentList.indexOf(pastReagent);
                    if (reagentLocation == -1 || reagentLocation + 1 >= reagentList.size()) {
                        this.setReagentWithNotification(itemStack, reagentList.get(0), player);
                    } else {
                        this.setReagentWithNotification(itemStack, reagentList.get(reagentLocation + 1), player);
                    }
                }
            } else {
                if (this.getHasSavedCoordinates(itemStack)) {
                    Int3 coords = this.getCoordinates(itemStack);
                    int dimension = this.getDimension(itemStack);
                    if (coords == null) {
                        return itemStack;
                    }
                    if (dimension != world.provider.dimensionId || Math.abs(coords.xCoord - x) > maxDistance || Math.abs(coords.yCoord - y) > maxDistance || Math.abs(coords.zCoord - z) > maxDistance) {
                        player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.error.toofar"));
                        return itemStack;
                    }
                    TileEntity pastTile = world.getTileEntity(coords.xCoord, coords.yCoord, coords.zCoord);
                    if (!(pastTile instanceof TEReagentConduit)) {
                        player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.error.cannotfind"));
                        return itemStack;
                    }
                    Reagent reagent = this.getReagent(itemStack);
                    if (reagent == null) {
                        return itemStack;
                    }
                    TEReagentConduit pastRelay = (TEReagentConduit) pastTile;
                    if (player.isSneaking()) {
                        pastRelay.removeReagentDestinationViaActual(reagent, x, y, z);
                    } else {
                        if (pastRelay.addReagentDestinationViaActual(reagent, x, y, z)) {
                            player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("message.attunedcrystal.linked") + " " + reagent.name));
                        } else {
                            player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.error.noconnections"));
                        }
                    }
                    world.markBlockForUpdate(coords.xCoord, coords.yCoord, coords.zCoord);
                } else {
                    int dimension = world.provider.dimensionId;
                    this.setDimension(itemStack, dimension);
                    this.setCoordinates(itemStack, new Int3(x, y, z));
                    player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.linking"));
                }
            }
        }
    }
    return itemStack;
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) LinkedList(java.util.LinkedList) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) ChatComponentText(net.minecraft.util.ChatComponentText) TEReagentConduit(WayofTime.alchemicalWizardry.common.tileEntity.TEReagentConduit)

Example 10 with Int3

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

the class ItemRitualDiviner method voidStoredLocation.

public void voidStoredLocation(ItemStack stack) {
    NBTTagCompound tag = stack.getTagCompound();
    if (tag == null || !tag.hasKey("location")) {
        // tag = new NBTTagCompound();
        // stack.setTagCompound(tag);
        this.setStoredLocation(stack, new Int3(0, 0, 0));
        return;
    }
    NBTTagCompound locTag = (NBTTagCompound) tag.getTag("location");
    if (locTag != null) {
        locTag.setBoolean("isStored", false);
    }
}
Also used : Int3(WayofTime.alchemicalWizardry.api.Int3) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

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