Search in sources :

Example 11 with Vector3d

use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.

the class IoConfigRenderer method renderSelection.

private void renderSelection() {
    if (selection == null) {
        return;
    }
    BoundingBox bb = new BoundingBox(selection.config.getLocation());
    TextureAtlasSprite icon = selectedFaceIcon.get(TextureAtlasSprite.class);
    List<Vertex> corners = bb.getCornersWithUvForFace(selection.face, icon.getMinU(), icon.getMaxU(), icon.getMinV(), icon.getMaxV());
    GlStateManager.disableDepth();
    GlStateManager.disableLighting();
    RenderUtil.bindBlockTexture();
    BufferBuilder tes = Tessellator.getInstance().getBuffer();
    GlStateManager.color(1, 1, 1);
    Vector3d trans = new Vector3d((-origin.x) + eye.x, (-origin.y) + eye.y, (-origin.z) + eye.z);
    tes.setTranslation(trans.x, trans.y, trans.z);
    RenderUtil.addVerticesToTessellator(corners, DefaultVertexFormats.POSITION_TEX, true);
    Tessellator.getInstance().draw();
    tes.setTranslation(0, 0, 0);
}
Also used : Vertex(com.enderio.core.common.vecmath.Vertex) Vector3d(com.enderio.core.common.vecmath.Vector3d) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) BoundingBox(com.enderio.core.client.render.BoundingBox) BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Example 12 with Vector3d

use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.

the class DefaultConduitRenderer method setupVertices.

protected void setupVertices(BoundingBox bound, VertexTransform xForm) {
    verts[0].set(bound.minX, bound.minY, bound.minZ);
    verts[1].set(bound.maxX, bound.minY, bound.minZ);
    verts[2].set(bound.maxX, bound.maxY, bound.minZ);
    verts[3].set(bound.minX, bound.maxY, bound.minZ);
    verts[4].set(bound.minX, bound.minY, bound.maxZ);
    verts[5].set(bound.maxX, bound.minY, bound.maxZ);
    verts[6].set(bound.maxX, bound.maxY, bound.maxZ);
    verts[7].set(bound.minX, bound.maxY, bound.maxZ);
    if (xForm != null) {
        for (Vector3d vec : verts) {
            xForm.apply(vec);
        }
    }
}
Also used : Vector3d(com.enderio.core.common.vecmath.Vector3d)

Example 13 with Vector3d

use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.

the class TESRPowerMonitor method renderTileEntity.

@Override
protected void renderTileEntity(@Nonnull TilePowerMonitor te, @Nonnull IBlockState blockState, float partialTicks, int destroyStage) {
    boolean isPainted = te.getPaintSource() != null;
    VertexRotationFacing xform = new VertexRotationFacing(te.getFacing());
    xform.setCenter(new Vector3d(0.5, 0.5, 0.5));
    xform.setRotation(EnumFacing.SOUTH);
    te.bindTexture();
    Helper helper = threadLocalHelper.get();
    BufferBuilder tes = Tessellator.getInstance().getBuffer();
    tes.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);
    if (isPainted) {
        helper.setupVertices(bb2, xform);
        helper.renderSingleFace(tes, EnumFacing.SOUTH, 0 * px, 14 * px, 0 * px, 14 * px, xform, Helper.stdBrightness, false);
    } else {
        helper.setupVertices(bb1, xform);
        helper.renderSingleFace(tes, EnumFacing.SOUTH, 1 * px, 15 * px, 1 * px, 15 * px, xform, Helper.stdBrightness, false);
    }
    Tessellator.getInstance().draw();
}
Also used : VertexRotationFacing(com.enderio.core.client.render.VertexRotationFacing) Vector3d(com.enderio.core.common.vecmath.Vector3d) BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Example 14 with Vector3d

use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.

the class TeleportUtil method serverTeleport.

public static boolean serverTeleport(@Nonnull Entity entity, @Nonnull BlockPos pos, int targetDim, boolean conserveMotion, @Nonnull TravelSource source) {
    TeleportEntityEvent evt = new TeleportEntityEvent(entity, source, pos, targetDim);
    if (MinecraftForge.EVENT_BUS.post(evt)) {
        return false;
    }
    EntityPlayerMP player = null;
    if (entity instanceof EntityPlayerMP) {
        player = (EntityPlayerMP) entity;
    }
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    int from = entity.dimension;
    if (from != targetDim) {
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        WorldServer fromDim = server.getWorld(from);
        WorldServer toDim = server.getWorld(targetDim);
        Teleporter teleporter = new TeleporterEIO(toDim);
        // play sound at the dimension we are leaving for others to hear
        SoundHelper.playSound(server.getWorld(entity.dimension), entity, source.sound, 1.0F, 1.0F);
        if (player != null) {
            server.getPlayerList().transferPlayerToDimension(player, targetDim, teleporter);
            if (from == 1 && entity.isEntityAlive()) {
                // get around vanilla End
                // hacks
                toDim.spawnEntity(entity);
                toDim.updateEntityWithOptionalForce(entity, false);
            }
        } else {
            NBTTagCompound tagCompound = new NBTTagCompound();
            float rotationYaw = entity.rotationYaw;
            float rotationPitch = entity.rotationPitch;
            entity.writeToNBT(tagCompound);
            Class<? extends Entity> entityClass = entity.getClass();
            fromDim.removeEntity(entity);
            try {
                Entity newEntity = entityClass.getConstructor(World.class).newInstance(toDim);
                newEntity.readFromNBT(tagCompound);
                newEntity.setLocationAndAngles(x, y, z, rotationYaw, rotationPitch);
                newEntity.forceSpawn = true;
                toDim.spawnEntity(newEntity);
                // necessary?
                newEntity.forceSpawn = false;
            } catch (Exception e) {
                // Throwables.propagate(e);
                Log.error("serverTeleport: Error creating a entity to be created in new dimension.");
                return false;
            }
        }
    }
    // Force the chunk to load
    if (!entity.world.isBlockLoaded(pos)) {
        entity.world.getChunkFromBlockCoords(pos);
    }
    if (player != null) {
        player.connection.setPlayerLocation(x + 0.5, y + 1.1, z + 0.5, player.rotationYaw, player.rotationPitch);
    } else {
        entity.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
    }
    entity.fallDistance = 0;
    SoundHelper.playSound(entity.world, entity, source.sound, 1.0F, 1.0F);
    if (player != null) {
        if (conserveMotion) {
            Vector3d velocityVex = Util.getLookVecEio(player);
            SPacketEntityVelocity p = new SPacketEntityVelocity(entity.getEntityId(), velocityVex.x, velocityVex.y, velocityVex.z);
            player.connection.sendPacket(p);
        }
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) TeleportEntityEvent(crazypants.enderio.api.teleport.TeleportEntityEvent) Teleporter(net.minecraft.world.Teleporter) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) Vector3d(com.enderio.core.common.vecmath.Vector3d) SPacketEntityVelocity(net.minecraft.network.play.server.SPacketEntityVelocity) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 15 with Vector3d

use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.

the class TravelController method updateSelectedTarget.

@SideOnly(Side.CLIENT)
private void updateSelectedTarget(@Nonnull EntityPlayerSP player) {
    selectedCoord = null;
    if (candidates.isEmpty()) {
        return;
    }
    double closestDistance = Double.MAX_VALUE;
    for (BlockPos bc : candidates.keySet()) {
        if (!bc.equals(onBlockCoord)) {
            double d = addRatio(bc);
            if (d < closestDistance) {
                selectedCoord = bc;
                closestDistance = d;
            }
        }
    }
    if (selectedCoord != null) {
        Vector3d blockCenter = new Vector3d(selectedCoord.getX() + 0.5, selectedCoord.getY() + 0.5, selectedCoord.getZ() + 0.5);
        Vector2d blockCenterPixel = currentView.getScreenPoint(blockCenter);
        Vector2d screenMidPixel = new Vector2d(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
        screenMidPixel.scale(0.5);
        double pixDist = blockCenterPixel.distance(screenMidPixel);
        double rat = pixDist / Minecraft.getMinecraft().displayHeight;
        if (rat != rat) {
            rat = 0;
        }
        if (rat > 0.07) {
            selectedCoord = null;
        }
    }
}
Also used : Vector2d(com.enderio.core.common.vecmath.Vector2d) Vector3d(com.enderio.core.common.vecmath.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

Vector3d (com.enderio.core.common.vecmath.Vector3d)35 BoundingBox (com.enderio.core.client.render.BoundingBox)9 EnumFacing (net.minecraft.util.EnumFacing)7 BlockPos (net.minecraft.util.math.BlockPos)7 Nonnull (javax.annotation.Nonnull)6 Vertex (com.enderio.core.common.vecmath.Vertex)4 ArrayList (java.util.ArrayList)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 TileEntity (net.minecraft.tileentity.TileEntity)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3 Vec3d (net.minecraft.util.math.Vec3d)3 VertexRotationFacing (com.enderio.core.client.render.VertexRotationFacing)2 Vector2d (com.enderio.core.common.vecmath.Vector2d)2 Vector4f (com.enderio.core.common.vecmath.Vector4f)2 IBlockState (net.minecraft.block.state.IBlockState)2 Minecraft (net.minecraft.client.Minecraft)2 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2