Search in sources :

Example 36 with Vec3i

use of net.minecraft.util.math.Vec3i in project OreSpawn by MinecraftModDevelopmentMods.

the class FeatureBase method spawnMungeSW.

protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, final double radius, final ISpawnEntry spawnData, final int count) {
    final Random prng = this.random;
    int quantity = count;
    for (int dy = (int) (-1 * radius); dy < radius; dy++) {
        for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) {
            for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) {
                spawnMungeInner(prng, rSqr, quantity, new Vec3i(dx, dy, dz), spawnData, world, blockPos);
                if (quantity <= 0) {
                    return;
                }
            }
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) Random(java.util.Random)

Example 37 with Vec3i

use of net.minecraft.util.math.Vec3i in project OreSpawn by MinecraftModDevelopmentMods.

the class FeatureBase method cacheOverflowBlock.

private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, final int dimension) {
    final Vec3i chunkCoord = new Vec3i(coord.getX() / 16, coord.getY() / 16, dimension);
    if (overflowCache.containsKey(chunkCoord)) {
        cacheOrder.addLast(chunkCoord);
        if (cacheOrder.size() > MAX_CACHE_SIZE) {
            final Vec3i drop = cacheOrder.removeFirst();
            overflowCache.get(drop).clear();
            overflowCache.remove(drop);
        }
        overflowCache.put(chunkCoord, new HashMap<>());
    }
    final Map<BlockPos, IBlockState> cache = overflowCache.getOrDefault(chunkCoord, new HashMap<>());
    cache.put(coord, bs);
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 38 with Vec3i

use of net.minecraft.util.math.Vec3i in project Wurst-MC-1.12 by Wurst-Imperium.

the class FlyPathProcessor method process.

@Override
public void process() {
    // get positions
    BlockPos pos = new BlockPos(WMinecraft.getPlayer());
    Vec3d posVec = WMinecraft.getPlayer().getPositionVector();
    BlockPos nextPos = path.get(index);
    int posIndex = path.indexOf(pos);
    AxisAlignedBB nextBox = new AxisAlignedBB(nextPos.getX() + 0.3, nextPos.getY(), nextPos.getZ() + 0.3, nextPos.getX() + 0.7, nextPos.getY() + 0.2, nextPos.getZ() + 0.7);
    if (posIndex == -1)
        ticksOffPath++;
    else
        ticksOffPath = 0;
    // update index
    if (posIndex > index || posVec.xCoord >= nextBox.minX && posVec.xCoord <= nextBox.maxX && posVec.yCoord >= nextBox.minY && posVec.yCoord <= nextBox.maxY && posVec.zCoord >= nextBox.minZ && posVec.zCoord <= nextBox.maxZ) {
        if (posIndex > index)
            index = posIndex + 1;
        else
            index++;
        // stop when changing directions
        if (creativeFlying) {
            WMinecraft.getPlayer().motionX /= Math.max(Math.abs(WMinecraft.getPlayer().motionX) * 50, 1);
            WMinecraft.getPlayer().motionY /= Math.max(Math.abs(WMinecraft.getPlayer().motionY) * 50, 1);
            WMinecraft.getPlayer().motionZ /= Math.max(Math.abs(WMinecraft.getPlayer().motionZ) * 50, 1);
        }
        if (index >= path.size())
            done = true;
        return;
    }
    lockControls();
    WMinecraft.getPlayer().capabilities.isFlying = creativeFlying;
    boolean x = posVec.xCoord < nextBox.minX || posVec.xCoord > nextBox.maxX;
    boolean y = posVec.yCoord < nextBox.minY || posVec.yCoord > nextBox.maxY;
    boolean z = posVec.zCoord < nextBox.minZ || posVec.zCoord > nextBox.maxZ;
    boolean horizontal = x || z;
    // face next position
    if (horizontal) {
        facePosition(nextPos);
        if (Math.abs(WMath.wrapDegrees(RotationUtils.getHorizontalAngleToClientRotation(new Vec3d(nextPos).addVector(0.5, 0.5, 0.5)))) > 1)
            return;
    }
    // skip mid-air nodes
    Vec3i offset = nextPos.subtract(pos);
    while (index < path.size() - 1 && path.get(index).add(offset).equals(path.get(index + 1))) index++;
    if (creativeFlying) {
        if (!x)
            WMinecraft.getPlayer().motionX /= Math.max(Math.abs(WMinecraft.getPlayer().motionX) * 50, 1);
        if (!y)
            WMinecraft.getPlayer().motionY /= Math.max(Math.abs(WMinecraft.getPlayer().motionY) * 50, 1);
        if (!z)
            WMinecraft.getPlayer().motionZ /= Math.max(Math.abs(WMinecraft.getPlayer().motionZ) * 50, 1);
    }
    // horizontal movement
    if (horizontal) {
        if (!creativeFlying && WMinecraft.getPlayer().getDistance(nextPos.getX() + 0.5, pos.getY() + 0.1, nextPos.getZ() + 0.5) <= wurst.mods.flightMod.speed.getValueF()) {
            WMinecraft.getPlayer().setPosition(nextPos.getX() + 0.5, pos.getY() + 0.1, nextPos.getZ() + 0.5);
            return;
        }
        mc.gameSettings.keyBindForward.pressed = true;
        if (WMinecraft.getPlayer().isCollidedHorizontally)
            if (posVec.yCoord > nextBox.maxY)
                mc.gameSettings.keyBindSneak.pressed = true;
            else if (posVec.yCoord < nextBox.minY)
                mc.gameSettings.keyBindJump.pressed = true;
    // vertical movement
    } else if (y) {
        if (!creativeFlying && WMinecraft.getPlayer().getDistance(pos.getX() + 0.5, nextPos.getY() + 0.1, pos.getZ() + 0.5) <= wurst.mods.flightMod.speed.getValueF()) {
            WMinecraft.getPlayer().setPosition(pos.getX() + 0.5, nextPos.getY() + 0.1, pos.getZ() + 0.5);
            return;
        }
        if (posVec.yCoord < nextBox.minY)
            mc.gameSettings.keyBindJump.pressed = true;
        else
            mc.gameSettings.keyBindSneak.pressed = true;
        if (WMinecraft.getPlayer().isCollidedVertically) {
            mc.gameSettings.keyBindSneak.pressed = false;
            mc.gameSettings.keyBindForward.pressed = true;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vec3i(net.minecraft.util.math.Vec3i) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 39 with Vec3i

use of net.minecraft.util.math.Vec3i in project RecurrentComplex by Ivorforce.

the class GenericStructure method generate.

@Override
public void generate(@Nonnull final StructureSpawnContext context, @Nonnull InstanceData instanceData, @Nonnull TransformerMulti foreignTransformer) {
    WorldServer world = context.environment.world;
    IvWorldData worldData = constructWorldData();
    boolean asSource = context.generateAsSource;
    RunTransformer transformer = getRunTransformer(instanceData, foreignTransformer, asSource);
    instanceData.variableDomain.fill(context.environment.variables);
    // The world initializes the block event array after it generates the world - in the constructor
    // This hackily sets the field to a temporary value. Yay.
    // Hax
    RCAccessorWorldServer.ensureBlockEventArray(world);
    IvBlockCollection blockCollection = worldData.blockCollection;
    int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
    BlockPos origin = StructureBoundingBoxes.min(context.boundingBox);
    Map<BlockPos, NBTTagCompound> tileEntityCompounds = new HashMap<>();
    for (NBTTagCompound tileEntityCompound : worldData.tileEntities) {
        BlockPos src = RCMover.getTileEntityPos(tileEntityCompound);
        tileEntityCompounds.put(src, tileEntityCompound);
    }
    if (transformer != null)
        transformer.transformer.transform(transformer.instanceData, Transformer.Phase.BEFORE, context, worldData, transformer);
    StructureBoundingBox relevantSourceArea = context.sourceIntersection(BlockAreas.toBoundingBox(blockCollection.area()));
    if (// Why did we get asked to generate again?
    relevantSourceArea != null) {
        context.freezeHeightMap(relevantSourceArea);
        BlockPos.MutableBlockPos worldPos = new BlockPos.MutableBlockPos();
        for (int pass = 0; pass < 2; pass++) {
            for (BlockPos sourcePos : RCStructureBoundingBoxes.mutablePositions(relevantSourceArea)) {
                IvMutableBlockPos.add(context.transform.applyOn(sourcePos, worldPos, areaSize), origin);
                if (context.includesComplex(worldPos)) {
                    IBlockState state = PosTransformer.transformBlockState(blockCollection.getBlockState(sourcePos), context.transform);
                    if (pass == getPass(state) && (transformer == null || !transformer.transformer.skipGeneration(transformer.instanceData, context, worldPos, state, worldData, sourcePos))) {
                        setBlock(context, areaSize, worldPos, state, () -> tileEntityCompounds.get(sourcePos));
                    }
                }
            }
        }
        context.meltHeightMap();
    }
    if (transformer != null)
        transformer.transformer.transform(transformer.instanceData, Transformer.Phase.AFTER, context, worldData, transformer);
    for (NBTTagCompound entityCompound : worldData.entities) {
        double[] transformedEntityPos = context.transform.applyOn(getEntityPos(entityCompound), areaSize);
        if (context.includes(new Vec3i(transformedEntityPos[0] + origin.getX(), transformedEntityPos[1] + origin.getY(), transformedEntityPos[2] + origin.getZ()))) {
            Entity entity = EntityList.createEntityFromNBT(entityCompound, world);
            if (entity != null) {
                PosTransformer.transformEntityPos(entity, context.transform, areaSize);
                Mover.moveEntity(entity, origin);
                RCAccessorEntity.setEntityUniqueID(entity, UUID.randomUUID());
                generateEntityContents(context, entity);
                world.spawnEntity(entity);
            } else {
                RecurrentComplex.logger.error("Error loading entity with ID '" + entityCompound.getString("id") + "'");
            }
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) RCAccessorEntity(ivorius.reccomplex.utils.accessor.RCAccessorEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) IBlockState(net.minecraft.block.state.IBlockState) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) RCAccessorWorldServer(ivorius.reccomplex.utils.accessor.RCAccessorWorldServer) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) RunTransformer(ivorius.reccomplex.world.gen.feature.structure.generic.transformers.RunTransformer) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos)

Example 40 with Vec3i

use of net.minecraft.util.math.Vec3i in project GregTech by GregTechCEu.

the class ToolDrillLarge method findCorner.

/**
 * Returns the relative bottom left closest corner of the possible mining area for the drill.
 */
private static BlockPos findCorner(int max, BlockPos startPos, EntityPlayer player, EnumFacing facing) {
    Vec3i leftVec = RelativeDirection.LEFT.applyVec3i(facing);
    Vec3i downVec = RelativeDirection.DOWN.applyVec3i(facing);
    switch(facing) {
        case UP:
        case DOWN:
            // treat up and down as standard cube. just acquire leftmost corner, ignoring floor level
            return startPos.add(multiplyVec(leftVec, max / 2)).add(multiplyVec(downVec, max / 2));
        default:
            // try to find lowest pos
            Vec3i towardsVec = RelativeDirection.FRONT.applyVec3i(facing);
            if (max != 1) {
                // Find the relative downwards offset
                for (int i = 1; i <= max; i++) {
                    BlockPos currentPos = startPos.add(multiplyVec(downVec, i));
                    BlockPos forwardPos = currentPos.add(towardsVec);
                    IBlockState state = player.world.getBlockState(forwardPos);
                    if (!state.getBlock().isAir(state, player.world, forwardPos)) {
                        startPos = currentPos;
                        break;
                    }
                }
            }
            // Find the relative leftmost BlockPos
            return startPos.add(multiplyVec(leftVec, max / 2));
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Vec3i (net.minecraft.util.math.Vec3i)161 BlockPos (net.minecraft.util.math.BlockPos)88 IBlockState (net.minecraft.block.state.IBlockState)29 Vec3d (net.minecraft.util.math.Vec3d)25 EnumFacing (net.minecraft.util.EnumFacing)18 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)15 Block (net.minecraft.block.Block)12 Entity (net.minecraft.entity.Entity)11 ArrayList (java.util.ArrayList)10 World (net.minecraft.world.World)10 TileEntity (net.minecraft.tileentity.TileEntity)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)7 HashSet (java.util.HashSet)6 Tessellator (net.minecraft.client.renderer.Tessellator)6 EntityEnderCrystal (net.minecraft.entity.item.EntityEnderCrystal)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 HashMap (java.util.HashMap)5 Random (java.util.Random)5 Direction (net.minecraft.util.math.Direction)5