Search in sources :

Example 96 with Vec3i

use of net.minecraft.util.math.Vec3i in project Random-Things by lumien231.

the class WorldUtil method getEntitiesWithinAABBs.

public static List getEntitiesWithinAABBs(World worldObj, Class clazz, Predicate filter, AxisAlignedBB... bbs) {
    ArrayList arraylist = new ArrayList();
    HashMap<Vec3i, ArrayList<AxisAlignedBB>> boxMap = new HashMap<>();
    for (AxisAlignedBB bb : bbs) {
        int minChunkX = MathHelper.floor((bb.minX - World.MAX_ENTITY_RADIUS) / 16.0D);
        int maxChunkX = MathHelper.floor((bb.maxX + World.MAX_ENTITY_RADIUS) / 16.0D);
        int minChunkZ = MathHelper.floor((bb.minZ - World.MAX_ENTITY_RADIUS) / 16.0D);
        int maxChunkZ = MathHelper.floor((bb.maxZ + World.MAX_ENTITY_RADIUS) / 16.0D);
        int minChunkY = MathHelper.floor((bb.minY - World.MAX_ENTITY_RADIUS) / 16.0D);
        int maxChunkY = MathHelper.floor((bb.maxY + World.MAX_ENTITY_RADIUS) / 16.0D);
        for (int x = minChunkX; x <= maxChunkX; x++) {
            for (int z = minChunkZ; z <= maxChunkZ; z++) {
                for (int y = minChunkY; y <= maxChunkY; y++) {
                    if (y >= 0 && y < worldObj.getHeight() / 16) {
                        Vec3i chunkVec = new Vec3i(x, y, z);
                        ArrayList<AxisAlignedBB> boxList = boxMap.get(chunkVec);
                        if (boxList == null) {
                            boxList = new ArrayList<>();
                            boxMap.put(chunkVec, boxList);
                        }
                        boxList.add(bb);
                    }
                }
            }
        }
    }
    for (Vec3i chunkVec : boxMap.keySet()) {
        Chunk chunk = worldObj.getChunkFromChunkCoords(chunkVec.getX(), chunkVec.getZ());
        ClassInheritanceMultiMap[] entityMapArray = chunk.getEntityLists();
        Iterator<Entity> iterator = entityMapArray[chunkVec.getY()].getByClass(clazz).iterator();
        while (iterator.hasNext()) {
            Entity entity = iterator.next();
            for (AxisAlignedBB bb : boxMap.get(chunkVec)) {
                if (entity.getEntityBoundingBox().intersects(bb) && (filter == null || filter.apply(entity))) {
                    arraylist.add(entity);
                    Entity[] entityParts = entity.getParts();
                    if (entityParts != null) {
                        for (int l = 0; l < entityParts.length; ++l) {
                            entity = entityParts[l];
                            if (entity.getEntityBoundingBox().intersects(bb) && (filter == null || filter.apply(entity))) {
                                arraylist.add(entity);
                            }
                        }
                    }
                }
            }
        }
    }
    return arraylist;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vec3i(net.minecraft.util.math.Vec3i) Entity(net.minecraft.entity.Entity) ClassInheritanceMultiMap(net.minecraft.util.ClassInheritanceMultiMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Chunk(net.minecraft.world.chunk.Chunk)

Example 97 with Vec3i

use of net.minecraft.util.math.Vec3i in project Random-Things by lumien231.

the class RenderAncientFurnace method render.

@Override
public void render(TileEntityAncientFurnace te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    STATE state = te.getState();
    int counter = te.getStartingCounter();
    float transparency = 0;
    if (state == STATE.RUNNING) {
        transparency = 1;
    } else if (state == STATE.STARTING && counter > 100) {
        transparency = Math.min(1, -1 * (float) Math.cos(((counter + partialTicks) - 100) / 300D * (Math.PI / 2)) + 1);
    }
    if (state == STATE.RUNNING || (state == STATE.STARTING && counter > 100)) {
        // System.out.println(transparency + "/" + counter);
        // transparency = 0.1f;
        GlStateManager.alphaFunc(GL11.GL_ALWAYS, 0);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
        this.setLightmapDisabled(true);
        GlStateManager.disableLighting();
        float yellow = ((float) Math.sin((RTEventHandler.clientAnimationCounter + partialTicks) / 25f) + 1) / 5 + 0.1f;
        GlStateManager.color(1f, yellow, 0, transparency);
        for (Overlay o : toDraw) {
            Pair<Integer, Integer> offset = o.offset;
            long rdm = MathHelper.getPositionRandom(new Vec3i(te.getPos().getX() + offset.getLeft(), te.getPos().getY(), te.getPos().getZ() + offset.getRight()));
            int model = getRandomInteger(4, Math.abs((int) rdm >> 16) % 4);
            for (EnumFacing f : o.facings) {
                ResourceLocation texture = textures[textureIndices[model][f.getHorizontalIndex()]];
                this.bindTexture(texture);
                Tessellator tessellator = Tessellator.getInstance();
                BufferBuilder renderer = tessellator.getBuffer();
                renderer.begin(7, DefaultVertexFormats.POSITION_TEX);
                double iX = x + offset.getLeft();
                double iZ = z + offset.getRight();
                switch(f) {
                    case NORTH:
                        renderer.pos(iX, y, iZ - 0.001).tex(1, 1).endVertex();
                        renderer.pos(iX, y + 1, iZ - 0.001).tex(1, 0).endVertex();
                        renderer.pos(iX + 1, y + 1, iZ - 0.001).tex(0, 0).endVertex();
                        renderer.pos(iX + 1, y, iZ - 0.001).tex(0, 1).endVertex();
                        break;
                    case SOUTH:
                        renderer.pos(iX, y, iZ + 1.001).tex(0, 1).endVertex();
                        renderer.pos(iX + 1, y, iZ + 1.001).tex(1, 1).endVertex();
                        renderer.pos(iX + 1, y + 1, iZ + 1.001).tex(1, 0).endVertex();
                        renderer.pos(iX, y + 1, iZ + 1.001).tex(0, 0).endVertex();
                        break;
                    case WEST:
                        renderer.pos(iX - 0.001, y, iZ).tex(0, 1).endVertex();
                        renderer.pos(iX - 0.001, y, iZ + 1).tex(1, 1).endVertex();
                        renderer.pos(iX - 0.001, y + 1, iZ + 1).tex(1, 0).endVertex();
                        renderer.pos(iX - 0.001, y + 1, iZ).tex(0, 0).endVertex();
                        break;
                    case EAST:
                        renderer.pos(iX + 1.001, y, iZ).tex(1, 1).endVertex();
                        renderer.pos(iX + 1.001, y + 1, iZ).tex(1, 0).endVertex();
                        renderer.pos(iX + 1.001, y + 1, iZ + 1).tex(0, 0).endVertex();
                        renderer.pos(iX + 1.001, y, iZ + 1).tex(0, 1).endVertex();
                        break;
                    default:
                        break;
                }
                tessellator.draw();
            }
        }
        this.setLightmapDisabled(false);
        GlStateManager.enableLighting();
        GlStateManager.disableBlend();
        GlStateManager.alphaFunc(516, 0.1F);
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) Tessellator(net.minecraft.client.renderer.Tessellator) EnumFacing(net.minecraft.util.EnumFacing) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) STATE(lumien.randomthings.tileentity.TileEntityAncientFurnace.STATE) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 98 with Vec3i

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

the class CommandNaturalSpace method placeNaturalAir.

public static void placeNaturalAir(MockWorld world, BlockArea area, int floorDistance, int maxClosedSides) {
    BlockGenericSpace spaceBlock = RCBlocks.genericSpace;
    BlockPos lowerPoint = area.getLowerCorner();
    BlockPos higherPoint = area.getHigherCorner();
    Set<BlockPos> set = new HashSet<>();
    for (BlockSurfacePos surfaceCoord : BlockSurfaceArea.from(area)) {
        int safePoint = lowerPoint.getY();
        for (int y = higherPoint.getY(); y >= lowerPoint.getY(); y--) {
            IBlockState blockState = world.getBlockState(surfaceCoord.blockPos(y));
            if ((blockState.getMaterial() != Material.AIR && blockState.getBlock() != spaceBlock) || sidesClosed(world, surfaceCoord.blockPos(y), area) >= maxClosedSides) {
                boolean isFloor = blockState == RCBlocks.genericSolid.getDefaultState();
                safePoint = y + (isFloor ? 1 : floorDistance);
                break;
            }
        }
        for (int y = safePoint; y <= higherPoint.getY(); y++) set.add(surfaceCoord.blockPos(y));
        if (safePoint > lowerPoint.getY()) {
            for (int y = lowerPoint.getY(); y <= higherPoint.getY(); y++) {
                IBlockState blockState = world.getBlockState(surfaceCoord.blockPos(y));
                if ((blockState.getMaterial() != Material.AIR && blockState.getBlock() != spaceBlock) || sidesClosed(world, surfaceCoord.blockPos(y), area) >= maxClosedSides) {
                    safePoint = y - 1;
                    break;
                }
            }
        }
        for (int y = lowerPoint.getY(); y <= safePoint; y++) set.add(surfaceCoord.blockPos(y));
    }
    set.forEach(pos -> {
        BlockPos down = pos.down();
        BlockPos down2 = pos.down(2);
        world.setBlockState(pos, pos.getY() > lowerPoint.getY() && !set.contains(down) && world.getBlockState(down).getBlock().isReplaceable(world, down) && world.getBlockState(down2).getBlock().isReplaceable(world, down2) && new BlockArea(pos.subtract(new Vec3i(2, 0, 2)), pos.add(new Vec3i(2, 0, 2))).stream().allMatch(set::contains) ? spaceBlock.getDefaultState().withProperty(BlockGenericSpace.TYPE, 1) : spaceBlock.getDefaultState());
    });
}
Also used : BlockArea(ivorius.ivtoolkit.blocks.BlockArea) Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) BlockGenericSpace(ivorius.reccomplex.block.BlockGenericSpace) BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 99 with Vec3i

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

the class MazeVisualizationContext method max.

public BlockPos max(MazeRoom room) {
    int[] one = new int[room.getDimensions()];
    Arrays.fill(one, 1);
    return apply(IvVecMathHelper.add(room.getCoordinates(), one)).subtract(new Vec3i(1, 1, 1));
}
Also used : Vec3i(net.minecraft.util.math.Vec3i)

Example 100 with Vec3i

use of net.minecraft.util.math.Vec3i in project BuildCraft by BuildCraft.

the class MutableQuadTest method testRotations.

@Test
public void testRotations() {
    for (EnumFacing from : EnumFacing.VALUES) {
        for (EnumFacing to : EnumFacing.VALUES) {
            Vec3i vec = from.getDirectionVec();
            MutableQuad q = new MutableQuad();
            q.vertex_0.positionf(vec.getX(), vec.getY(), vec.getZ());
            q.rotate(from, to, 0, 0, 0);
            float ex = to.getFrontOffsetX();
            float ey = to.getFrontOffsetY();
            float ez = to.getFrontOffsetZ();
            Assert.assertEquals(from + " -> " + to + " [X]", ex, q.vertex_0.position_x, 0.001f);
            Assert.assertEquals(from + " -> " + to + " [Y]", ey, q.vertex_0.position_y, 0.001f);
            Assert.assertEquals(from + " -> " + to + " [Z]", ez, q.vertex_0.position_z, 0.001f);
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) EnumFacing(net.minecraft.util.EnumFacing) MutableQuad(buildcraft.lib.client.model.MutableQuad) Test(org.junit.Test)

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