类net.minecraft.util.Direction源码实例Demo

下面列出了怎么用net.minecraft.util.Direction的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: CodeChickenLib   文件: VertexDataUtils.java
public static BakedQuad buildQuad(VertexFormat format, TextureAtlasSprite sprite, Direction face, Colour colour, UVTransformation t, Vertex5 v1, Vertex5 v2, Vertex5 v3, Vertex5 v4) {
    //        BakedQuadBuilder builder = new BakedQuadBuilder(format);
    //        builder.setQuadTint(-1);
    //        builder.setQuadOrientation(face);
    //        builder.setTexture(sprite);
    //
    //        t.apply(v1.uv);
    //        t.apply(v2.uv);
    //        t.apply(v3.uv);
    //        t.apply(v4.uv);
    //        putVertex(builder, format, face, v1, colour);
    //        putVertex(builder, format, face, v2, colour);
    //        putVertex(builder, format, face, v3, colour);
    //        putVertex(builder, format, face, v4, colour);
    //
    //        return copyQuad(builder.build());
    return null;
}
 
源代码2 项目: bleachhack-1.14   文件: Scaffold.java
public void placeBlockAuto(BlockPos block) {
	if (lastPlaced.containsKey(block)) return;
	for (Direction d: Direction.values()) {
		if (!WorldUtils.NONSOLID_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
			if (WorldUtils.RIGHTCLICKABLE_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
				mc.player.connection.sendPacket(new CEntityActionPacket(mc.player, Action.START_SNEAKING));}
			mc.player.connection.sendPacket(new CPlayerTryUseItemOnBlockPacket(Hand.MAIN_HAND,
					new BlockRayTraceResult(new Vec3d(block), d.getOpposite(), block.offset(d), false)));
			mc.player.swingArm(Hand.MAIN_HAND);
			mc.world.playSound(block, SoundEvents.BLOCK_NOTE_BLOCK_HAT, SoundCategory.BLOCKS, 1f, 1f, false);
			if (WorldUtils.RIGHTCLICKABLE_BLOCKS.contains(mc.world.getBlockState(block.offset(d)).getBlock())) {
				mc.player.connection.sendPacket(new CEntityActionPacket(mc.player, Action.STOP_SNEAKING));}
			lastPlaced.put(block, 5);
			return;
		}
	}
}
 
源代码3 项目: CodeChickenLib   文件: CapabilityCache.java
/**
 * Gets a capability from the block in <code>to</code> direction from {@link CapabilityCache}'s
 * position. For example, calling this with <code>NORTH</code>, will get a capability from the block
 * IN <code>NORTH</code> direction on ITS <code>SOUTH</code> face.
 *
 * @param capability The capability to get.
 * @param to         The direction to ask.
 * @return A {@link LazyOptional} of the capability, may be empty.
 */
public <T> LazyOptional<T> getCapability(Capability<T> capability, Direction to) {
    Objects.requireNonNull(capability, "Null capability.");
    if (world == null || pos == null) {
        return LazyOptional.empty().cast();
    }
    Map<Capability<?>, Object2IntPair<LazyOptional<?>>> sideCache = getCacheForSide(to);
    Object2IntPair<LazyOptional<?>> cache = sideCache.get(capability);
    if (cache == null) {
        cache = new Object2IntPair<>(null, ticks);
        sideCache.put(capability, cache);
        return tryReCache(capability, to, cache).cast();
    }
    LazyOptional<?> lookup = cache.getKey();
    if (lookup == null || !lookup.isPresent()) {
        return tryReCache(capability, to, cache).cast();
    }
    return lookup.cast();
}
 
源代码4 项目: CodeChickenLib   文件: VectorUtils.java
/**
 * Calculates the EnumFacing for a given normal.
 *
 * @param normal The normal to calculate from.
 * @return The direction the normal is facing.
 */
public static Direction calcNormalSide(Vector3 normal) {
    if (normal.y <= -0.99) {
        return Direction.DOWN;
    }
    if (normal.y >= 0.99) {
        return Direction.UP;
    }
    if (normal.z <= -0.99) {
        return Direction.NORTH;
    }
    if (normal.z >= 0.99) {
        return Direction.SOUTH;
    }
    if (normal.x <= -0.99) {
        return Direction.WEST;
    }
    if (normal.x >= 0.99) {
        return Direction.EAST;
    }
    return null;
}
 
源代码5 项目: CodeChickenLib   文件: Quad.java
/**
 * Re-calculates the Orientation of this quad,
 * optionally the normal vector.
 *
 * @param setNormal If the normal vector should be updated.
 */
public void calculateOrientation(boolean setNormal) {
    v1.set(vertices[3].vec).subtract(t.set(vertices[1].vec));
    v2.set(vertices[2].vec).subtract(t.set(vertices[0].vec));

    Vector3 normal = v2.crossProduct(v1).normalize();

    if (format.hasNormal && setNormal) {
        for (Vertex vertex : vertices) {
            vertex.normal[0] = (float) normal.x;
            vertex.normal[1] = (float) normal.y;
            vertex.normal[2] = (float) normal.z;
            vertex.normal[3] = 0;
        }
    }
    orientation = Direction.getFacingFromVector(normal.x, normal.y, normal.z);
}
 
源代码6 项目: CodeChickenLib   文件: CapabilityCache.java
private LazyOptional<?> tryReCache(Capability<?> capability, Direction to, Object2IntPair<LazyOptional<?>> cache) {
    boolean isFirst = cache.getKey() == null;
    if (isFirst || !cache.getKey().isPresent()) {
        if (isFirst || cache.getValue() + waitTicks <= ticks) {
            LazyOptional<?> lookup = requestCapability(capability, to);
            if (lookup.isPresent()) {
                cache.setKey(lookup);
                cache.setValue(ticks);
                lookup.addListener(l -> {//TODO, probably not needed? we check every lookup anyway..
                    //When the LazyOptional notifies us that its gone,
                    //set the cache to empty, and mark ticks.
                    cache.setKey(LazyOptional.empty());
                    cache.setValue(ticks);
                });
            } else {
                cache.setKey(LazyOptional.empty());
                cache.setValue(ticks);
            }
        }
    }
    return cache.getKey();
}
 
源代码7 项目: CodeChickenLib   文件: ModelBakery.java
public static IBakedModel generateItemModel(ItemStack stack) {
    Item item = stack.getItem();
    if (item instanceof IBakeryProvider) {

        IItemBakery bakery = (IItemBakery) ((IBakeryProvider) item).getBakery();

        List<BakedQuad> generalQuads = new LinkedList<>();
        Map<Direction, List<BakedQuad>> faceQuads = new HashMap<>();
        generalQuads.addAll(bakery.bakeItemQuads(null, stack));

        for (Direction face : Direction.BY_INDEX) {
            List<BakedQuad> quads = new LinkedList<>();

            quads.addAll(bakery.bakeItemQuads(face, stack));

            faceQuads.put(face, quads);
        }

        PerspectiveProperties properties = bakery.getModelProperties(stack);
        return new PerspectiveAwareBakedModel(faceQuads, generalQuads, properties);
    }
    return missingModel;
}
 
protected boolean checkDepth(BakedQuad quad, Vector3 hit, Direction hitFace) {
    int[] quadData = quad.getVertexData();
    CachedFormat format = CachedFormat.lookup(DefaultVertexFormats.BLOCK);

    Vector3 posVec = new Vector3();
    float[] pos = new float[4];
    for (int v = 0; v < 4; v++) {
        LightUtil.unpack(quadData, pos, format.format, v, format.positionIndex);
        posVec.add(pos[0], pos[1], pos[2]);
    }
    posVec.divide(4);

    double diff = 0;
    switch (hitFace.getAxis()) {
        case X:
            diff = Math.abs(hit.x - posVec.x);
            break;
        case Y:
            diff = Math.abs(hit.y - posVec.y);
            break;
        case Z:
            diff = Math.abs(hit.z - posVec.z);
            break;
    }
    return !(diff > 0.01);
}
 
源代码9 项目: CodeChickenLib   文件: RotationUtils.java
/**
 * Rotate this Facing around all axises counter-clockwise (NORTH => DOWN => UP => WEST => EAST => SOUTH => NORTH)
 *
 * @param facing Current facing.
 * @return Next facing.
 */
public static Direction rotateBackwards(Direction facing) {
    switch (facing) {
        case NORTH:
            return Direction.SOUTH;
        case SOUTH:
            return Direction.EAST;
        case EAST:
            return Direction.WEST;
        case WEST:
            return Direction.UP;
        case UP:
            return Direction.DOWN;
        case DOWN:
            return Direction.NORTH;
    }
    return Direction.NORTH;
}
 
源代码10 项目: Artifacts   文件: BlockLaserBeam.java
public static boolean func_72148_a(IBlockAccess world, int x, int y, int z, int l, int i) {
	int j1 = x + Direction.offsetX[i];
       int k1 = z + Direction.offsetZ[i];
       Block l1 = world.getBlock(j1, y, k1);
       boolean flag = (l & 2) == 2;
       
       int i2;

       if (l1 == BlockLaserBeamSource.instance)
       {
       	i2 = world.getBlockMetadata(j1, y, k1);
           int j2 = i2 & 3;
           return j2 == Direction.rotateOpposite[i];
           //return true;
       }
       else if (l1 == BlockLaserBeam.instance)
       {
           i2 = world.getBlockMetadata(j1, y, k1);
           boolean flag1 = (i2 & 2) == 2;
           return flag == flag1;
       }
       else
       {
           return false;
       }
}
 
源代码11 项目: CodeChickenLib   文件: VertexDataUtils.java
private static void putVertex(BakedQuadBuilder builder, VertexFormat format, Direction face, Vertex5 vert, Colour colour) {
    //        for (int e = 0; e < format.getElementCount(); e++) {
    //            VertexFormatElement element = format.getElement(e);
    //            switch (element.getUsage()) {
    //
    //                case POSITION:
    //                    Vector3 vec = vert.vec;
    //                    builder.put(e, (float) vec.x, (float) vec.y, (float) vec.z, 1);
    //                    break;
    //                case NORMAL:
    //                    builder.put(e, face.getXOffset(), face.getYOffset(), face.getZOffset(), 0);
    //                    break;
    //                case COLOR:
    //                    builder.put(e, (colour.r & 0xFF) / 255F, (colour.g & 0xFF) / 255F, (colour.b & 0xFF) / 255F, (colour.a & 0xFF) / 255F);
    //                    break;
    //                case UV:
    //                    UV uv = vert.uv;
    //                    builder.put(e, (float) uv.u, (float) uv.v, 0, 1);
    //                    break;
    //                default:
    //                    builder.put(e);
    //                    break;
    //            }
    //        }
}
 
源代码12 项目: CodeChickenLib   文件: RotationUtils.java
/**
 * Gets rotation for placing a block, Will use Up and Down.
 *
 * @param pos    Pos placement is happening.
 * @param entity Entity placing block.
 * @return Direction placed.
 */
public static Direction getPlacedRotation(BlockPos pos, LivingEntity entity) {
    int entityRotation = (int) Math.floor(entity.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
    if (Math.abs(entity.getPosX() - pos.getX()) < 2.0D && Math.abs(entity.getPosZ() - pos.getZ()) < 2.0D) {

        double eyeDistance = entity.getPosY() + 1.82D - pos.getY();

        if (eyeDistance > 2.0D) {
            return Direction.DOWN;
        }

        if (eyeDistance < 0.0D) {
            return Direction.UP;
        }
    }

    return entityRotationToSide(entityRotation);
}
 
源代码13 项目: bleachhack-1.14   文件: OffhandCrash.java
public void onUpdate() {
	if (this.isToggled()) {
		for (int i = 0; i < getSettings().get(0).toSlider().getValue(); i++) {
			mc.player.connection.sendPacket(new CPlayerDiggingPacket(Action.SWAP_HELD_ITEMS, BlockPos.ZERO, Direction.UP));
			if (getSettings().get(1).toToggle().state) mc.player.connection.sendPacket(new CPlayerPacket(true));
		}
	}
}
 
源代码14 项目: MiningGadgets   文件: MiningCollect.java
public static List<BlockPos> collect(PlayerEntity player, BlockRayTraceResult startBlock, World world, int range) {
    List<BlockPos> coordinates = new ArrayList<>();
    BlockPos startPos = startBlock.getPos();

    if (range == 1) {
        if( !isValid(player, startBlock.getPos(), world) )
            return coordinates;

        coordinates.add(startBlock.getPos());
        return coordinates;
    }

    Direction side = startBlock.getFace();
    boolean vertical = side.getAxis().isVertical();
    Direction up = vertical ? player.getHorizontalFacing() : Direction.UP;
    Direction down = up.getOpposite();
    Direction right = vertical ? up.rotateY() : side.rotateYCCW();
    Direction left = right.getOpposite();

    coordinates.add(startPos.offset(up).offset(left));
    coordinates.add(startPos.offset(up));
    coordinates.add(startPos.offset(up).offset(right));
    coordinates.add(startPos.offset(left));
    coordinates.add(startPos);
    coordinates.add(startPos.offset(right));
    coordinates.add(startPos.offset(down).offset(left));
    coordinates.add(startPos.offset(down));
    coordinates.add(startPos.offset(down).offset(right));

    return coordinates.stream().filter(e -> isValid(player, e, world)).collect(Collectors.toList());
}
 
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
    if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
        return handler.cast();
    }
    return super.getCapability(cap, side);
}
 
源代码16 项目: EnderStorage   文件: TileEnderChest.java
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
    if (!removed && cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
        return itemHandler.cast();
    }
    return super.getCapability(cap, side);
}
 
源代码17 项目: Survivalist   文件: SawmillTileEntity.java
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing)
{
    if (capability == ITEMS_CAP)
    {
        if (facing == Direction.UP) return top_provider.cast();
        if (facing == Direction.DOWN) return bottom_provider.cast();
        if (facing != null) return sides_provider.cast();
        return combined_provider.cast();
    }

    return super.getCapability(capability, facing);
}
 
源代码18 项目: EnderStorage   文件: EnderPouchBakery.java
@Override
public List<BakedQuad> bakeItemQuads(Direction face, ItemStack stack) {
    List<BakedQuad> quads = new ArrayList<>();
    if (face == null) {
        Frequency frequency = Frequency.readFromStack(stack);
        boolean open =  EnderStorageManager.instance(true).getStorage(frequency, EnderItemStorage.TYPE).openCount() > 0;
        TextureAtlasSprite bagTexture = BAG_TEXTURES[frequency.hasOwner() ? 1 : 0][open ? 1 : 0];
        TextureAtlasSprite leftButton = COLOUR_TEXTURES[0][frequency.getLeft().getWoolMeta()];
        TextureAtlasSprite middleButton = COLOUR_TEXTURES[1][frequency.getMiddle().getWoolMeta()];
        TextureAtlasSprite rightButton = COLOUR_TEXTURES[2][frequency.getRight().getWoolMeta()];
        quads.addAll(ItemQuadBakery.bakeItem(bagTexture, leftButton, middleButton, rightButton));
    }
    return quads;
}
 
源代码19 项目: CodeChickenLib   文件: CustomParticleHandler.java
@OnlyIn (Dist.CLIENT)
public static void addBlockHitEffects(World world, Cuboid6 bounds, Direction side, TextureAtlasSprite icon, ParticleManager particleManager) {
    float border = 0.1F;
    Vector3 diff = bounds.max.copy().subtract(bounds.min).add(-2 * border);
    diff.x *= world.rand.nextDouble();
    diff.y *= world.rand.nextDouble();
    diff.z *= world.rand.nextDouble();
    Vector3 pos = diff.add(bounds.min).add(border);

    if (side == Direction.DOWN) {
        diff.y = bounds.min.y - border;
    }
    if (side == Direction.UP) {
        diff.y = bounds.max.y + border;
    }
    if (side == Direction.NORTH) {
        diff.z = bounds.min.z - border;
    }
    if (side == Direction.SOUTH) {
        diff.z = bounds.max.z + border;
    }
    if (side == Direction.WEST) {
        diff.x = bounds.min.x - border;
    }
    if (side == Direction.EAST) {
        diff.x = bounds.max.x + border;
    }

    particleManager.addEffect(new CustomBreakingParticle(world, pos.x, pos.y, pos.z, 0, 0, 0, icon).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
}
 
源代码20 项目: CodeChickenLib   文件: SimpleCapProvider.java
@Nonnull
@Override
public <R> LazyOptional<R> getCapability(@Nonnull Capability<R> cap, @Nullable Direction side) {
    if (capability == cap) {
        return instanceOpt.cast();
    }
    return null;
}
 
源代码21 项目: CodeChickenLib   文件: CapabilityCache.java
private LazyOptional<?> requestCapability(Capability<?> capability, Direction to) {
    TileEntity tile = world.getTileEntity(pos.offset(to));
    Direction inverse = to == null ? null : to.getOpposite();
    if (tile != null) {
        return tile.getCapability(capability, inverse);
    }
    return LazyOptional.empty();
}
 
@Override
public List<BakedQuad> getLayerQuads(BlockState state, Direction side, RenderType layer, Random rand, IModelData data) {
    if (side == null) {
        if (layerGeneralQuads.containsKey(layer)) {
            return layerGeneralQuads.get(layer);
        }
    } else if (layerFaceQuadMap.containsKey(layer)) {
        Map<Direction, List<BakedQuad>> faceQuadMap = layerFaceQuadMap.get(layer);
        if (faceQuadMap.containsKey(side)) {
            return faceQuadMap.get(side);
        }
    }
    return Collections.emptyList();
}
 
源代码23 项目: Artifacts   文件: BlockLaserBeam.java
private void func_72149_e(World par1World, int par2, int par3, int par4, int par5)
{
    int i1 = 0;
    boolean foundSource = false;
    boolean[] flag = new boolean[4];
    while (i1 < 4)
    {
        int j1 = 1;

        while (true)
        {
            if (j1 < 16)
            {
                int k1 = par2 + Direction.offsetX[i1] * j1;
                int l1 = par4 + Direction.offsetZ[i1] * j1;
                
                Block i2 = par1World.getBlock(k1, par3, l1);

                if (i2 == BlockLaserBeamSource.instance.instance)
                {
                    BlockLaserBeamSource.instance.updateLaserState(par1World, k1, par3, l1, i2, par1World.getBlockMetadata(k1, par3, l1), true, j1, par5);
                    foundSource = true;
                    flag[i1] = true;
                }
                else if (i2 == this.instance || !par1World.getBlock(k1, par3, l1).isOpaqueCube())
                {
                    ++j1;
                    continue;
                }
            }

            ++i1;
            break;
        }
    }
    if(!foundSource) {
    	par1World.setBlockToAir(par2, par3, par4);
    }
}
 
protected List<BakedQuad> getAllQuads(BlockState state, IModelData modelData) {
    List<BakedQuad> allQuads = new ArrayList<>();
    allQuads.addAll(getQuads(state, null, new Random(0), modelData));
    for (Direction face : Direction.BY_INDEX) {
        allQuads.addAll(getQuads(state, face, new Random(0), modelData));
    }
    return allQuads;
}
 
源代码25 项目: qcraft-mod   文件: BlockQuantumLogic.java
private boolean evaluateInput( World world, int i, int j, int k )
{
    int metadata = world.getBlockMetadata( i, j, k );
    int direction = Facing.oppositeSide[ Direction.directionToFacing[ getDirection( metadata ) ] ];
    int backDir = Facing.oppositeSide[ direction ];
    return getRedstoneSignal( world, i, j, k, backDir );
}
 
@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand) {
    if (side == null) {
        return generalQuads;
    } else {
        if (faceQuads.containsKey(side)) {
            return faceQuads.get(side);
        }
    }
    return ImmutableList.of();
}
 
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
    if (state == null && side == null) {
        return quads;
    }
    return Collections.emptyList();
}
 
源代码28 项目: CodeChickenLib   文件: TextureUtils.java
@Deprecated
public static TextureAtlasSprite[] getIconsForBlock(BlockState state, Direction side) {
    IBakedModel model = Minecraft.getInstance().getBlockRendererDispatcher().getModelForState(state);
    if (model != null) {
        List<BakedQuad> quads = model.getQuads(state, side, new Random(0));
        if (quads != null && quads.size() > 0) {
            TextureAtlasSprite[] sprites = new TextureAtlasSprite[quads.size()];
            for (int i = 0; i < quads.size(); i++) {
                sprites[i] = quads.get(i).func_187508_a();
            }
            return sprites;
        }
    }
    return new TextureAtlasSprite[0];
}
 
源代码29 项目: CodeChickenLib   文件: RotationUtils.java
/**
 * Rotate this Facing around the Y axis counter-clockwise (NORTH => WEST => SOUTH => EAST => NORTH)
 *
 * @param facing Current facing.
 * @return Next facing.
 */
public static Direction rotateCounterClockwise(Direction facing) {
    switch (facing) {
        case NORTH:
            return Direction.WEST;
        case EAST:
            return Direction.NORTH;
        case SOUTH:
            return Direction.EAST;
        case WEST:
            return Direction.SOUTH;
        default:
            throw new IllegalStateException("Unable to get CCW facing of " + facing);
    }
}
 
@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData data) {
    List<BakedQuad> quads = new LinkedList<>();
    if (baseModel != null) {
        quads.addAll(baseModel.getQuads(state, side, rand, data));
    }
    for (IBakedModel subModel : subModels) {
        quads.addAll(subModel.getQuads(state, side, rand, data));
    }
    return quads;
}
 
 类所在包
 同包方法