Search in sources :

Example 66 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ItemSeismicSensor method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) {
    if (!world.isRemote) {
        int testingY = y;
        while (testingY > 0) {
            testingY--;
            if (world.getBlock(x, testingY, z) == FluidRegistry.getFluid(Fluids.oil.getName()).getBlock()) {
                Set<ChunkPosition> oilPositions = new HashSet<ChunkPosition>();
                Stack<ChunkPosition> pendingPositions = new Stack<ChunkPosition>();
                pendingPositions.add(new ChunkPosition(x, testingY, z));
                while (!pendingPositions.empty()) {
                    ChunkPosition checkingPos = pendingPositions.pop();
                    for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                        ChunkPosition newPos = new ChunkPosition(checkingPos.chunkPosX + d.offsetX, checkingPos.chunkPosY + d.offsetY, checkingPos.chunkPosZ + d.offsetZ);
                        if (world.getBlock(newPos.chunkPosX, newPos.chunkPosY, newPos.chunkPosZ) == Fluids.oil.getBlock() && world.getBlockMetadata(newPos.chunkPosX, newPos.chunkPosY, newPos.chunkPosZ) == 0 && oilPositions.add(newPos)) {
                            pendingPositions.add(newPos);
                        }
                    }
                }
                player.addChatComponentMessage(new ChatComponentTranslation("message.seismicSensor.foundOilDetails", EnumChatFormatting.GREEN.toString() + (y - testingY), EnumChatFormatting.GREEN.toString() + oilPositions.size() / 10 * 10));
                return true;
            }
        }
        player.addChatComponentMessage(new ChatComponentTranslation("message.seismicSensor.noOilFound"));
    }
    // we don't want to use the item.
    return true;
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) ChunkPosition(net.minecraft.world.ChunkPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) Stack(java.util.Stack)

Example 67 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetAreaItemBase method updateVariables.

private boolean updateVariables() {
    boolean varChanged = false;
    for (Map.Entry<String, ChunkPosition> entry : areaVariableStates.entrySet()) {
        ChunkPosition newValue = aiManager.getCoordinate(entry.getKey());
        if (!newValue.equals(entry.getValue())) {
            varChanged = true;
            entry.setValue(newValue);
        }
    }
    return varChanged;
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 68 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetAreaItemBase method getCache.

public static IBlockAccess getCache(Collection<ChunkPosition> area, World world) {
    if (area.size() == 0)
        return world;
    int minX, minY, minZ, maxX, maxY, maxZ;
    Iterator<ChunkPosition> iterator = area.iterator();
    ChunkPosition p = iterator.next();
    minX = maxX = p.chunkPosX;
    minY = maxY = p.chunkPosY;
    minZ = maxZ = p.chunkPosZ;
    while (iterator.hasNext()) {
        p = iterator.next();
        minX = Math.min(minX, p.chunkPosX);
        minY = Math.min(minY, p.chunkPosY);
        minZ = Math.min(minZ, p.chunkPosZ);
        maxX = Math.max(maxX, p.chunkPosX);
        maxY = Math.max(maxY, p.chunkPosY);
        maxZ = Math.max(maxZ, p.chunkPosZ);
    }
    return new ChunkCache(world, minX, minY, minZ, maxX, maxY, maxZ, 0);
}
Also used : ChunkCache(net.minecraft.world.ChunkCache) ChunkPosition(net.minecraft.world.ChunkPosition)

Example 69 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ProgWidgetCoordinateCondition method evaluate.

@Override
public boolean evaluate(IDroneBase drone, IProgWidget widget) {
    ChunkPosition pos1 = ProgWidgetCoordinateOperator.calculateCoordinate(widget, 0, EnumOperator.PLUS_MINUS);
    ChunkPosition pos2 = ProgWidgetCoordinateOperator.calculateCoordinate(widget, 1, EnumOperator.PLUS_MINUS);
    if (checkingAxis[0] && !evaluate(pos1.chunkPosX, pos2.chunkPosX))
        return false;
    if (checkingAxis[1] && !evaluate(pos1.chunkPosY, pos2.chunkPosY))
        return false;
    if (checkingAxis[2] && !evaluate(pos1.chunkPosZ, pos2.chunkPosZ))
        return false;
    return true;
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition)

Example 70 with ChunkPosition

use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.

the class ItemGPSTool method getGPSLocation.

public static ChunkPosition getGPSLocation(ItemStack gpsTool) {
    NBTTagCompound compound = gpsTool.stackTagCompound;
    if (compound != null) {
        String var = getVariable(gpsTool);
        if (!var.equals("") && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
            ChunkPosition pos = GlobalVariableManager.getInstance().getPos(var);
            setGPSLocation(gpsTool, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        }
        int x = compound.getInteger("x");
        int y = compound.getInteger("y");
        int z = compound.getInteger("z");
        if (x != 0 || y != 0 || z != 0) {
            return new ChunkPosition(x, y, z);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

ChunkPosition (net.minecraft.world.ChunkPosition)94 ItemStack (net.minecraft.item.ItemStack)16 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 NBTTagList (net.minecraft.nbt.NBTTagList)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)9 TileEntity (net.minecraft.tileentity.TileEntity)9 ArrayList (java.util.ArrayList)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 Chunk (net.minecraft.world.chunk.Chunk)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 Stack (java.util.Stack)3 Block (net.minecraft.block.Block)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 IInventory (net.minecraft.inventory.IInventory)3 PathPoint (net.minecraft.pathfinding.PathPoint)3 Vec3 (net.minecraft.util.Vec3)3