net.minecraft.util.Direction Java Examples

The following examples show how to use net.minecraft.util.Direction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example #2
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example #3
Source File: AbstractBakedPropertiesModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
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);
}
 
Example #4
Source File: CapabilityCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
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();
}
 
Example #5
Source File: Quad.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: RotationUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: VectorUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: BlockLaserBeam.java    From Artifacts with MIT License 6 votes vote down vote up
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;
       }
}
 
Example #9
Source File: Scaffold.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
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;
		}
	}
}
 
Example #10
Source File: CapabilityCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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();
}
 
Example #11
Source File: RotationUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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);
}
 
Example #12
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
    //            }
    //        }
}
 
Example #13
Source File: InventoryRange.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public InventoryRange(IInventory inv, Direction side) {
    this.inv = inv;
    this.face = side;
    if (inv instanceof ISidedInventory) {
        sidedInv = (ISidedInventory) inv;
        slots = sidedInv.getSlotsForFace(face);
    } else {
        slots = new int[inv.getSizeInventory()];
        for (int i = 0; i < slots.length; i++) {
            slots[i] = i;
        }
    }
}
 
Example #14
Source File: AbstractBakedPropertiesModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example #15
Source File: BlockQuantumLogic.java    From qcraft-mod with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canConnectRedstone( IBlockAccess world, int x, int y, int z, int side )
{
    int metadata = world.getBlockMetadata( x, y, z );
    int direction = Direction.rotateOpposite[ getDirection( metadata ) ];
    return ( side == direction );
}
 
Example #16
Source File: Cuboid6.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public double getSideSize(Direction side) {
    switch (side.getAxis()) {
        case X:
            return (max.x - min.x) + 1;
        case Y:
            return (max.y - min.y) + 1;
        case Z:
            return (max.z - min.z) + 1;
    }
    return 0;
}
 
Example #17
Source File: Cuboid6.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Cuboid6 expandSide(Direction side, int amount) {
    switch (side.getAxisDirection()) {
        case NEGATIVE:
            min.add(Vector3.fromVec3i(side.getDirectionVec()).multiply(amount));
            break;
        case POSITIVE:
            max.add(Vector3.fromVec3i(side.getDirectionVec()).multiply(amount));
            break;
    }
    return this;
}
 
Example #18
Source File: RotationUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #19
Source File: PerspectiveAwareOverrideModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
    if (state == null && side == null) {
        return quads;
    }
    return Collections.emptyList();
}
 
Example #20
Source File: TextureUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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];
}
 
Example #21
Source File: VertexDataUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Map<Direction, List<BakedQuad>> sortFaceData(List<BakedQuad> quads) {
    Map<Direction, List<BakedQuad>> faceQuadMap = new HashMap<>();
    for (BakedQuad quad : quads) {
        List<BakedQuad> faceQuads = faceQuadMap.computeIfAbsent(quad.getFace(), k -> new ArrayList<>());
        faceQuads.add(quad);
    }
    return faceQuadMap;
}
 
Example #22
Source File: PerspectiveAwareMultiModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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;
}
 
Example #23
Source File: DryingRackTileEntity.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing)
{
    if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
        return itemsProvider.cast();
    return super.getCapability(capability, facing);
}
 
Example #24
Source File: BlockQuantumLogic.java    From qcraft-mod with Apache License 2.0 5 votes vote down vote up
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 );
}
 
Example #25
Source File: VoxelShapeCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Cuboid6 getCuboid(VoxelShape shape) {
    MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape);
    if (entry.getRight() == null) {
        entry.setRight(new Cuboid6(// I hope this is okay, don't want to rely on AABB cache.
                shape.getStart(Direction.Axis.X), shape.getStart(Direction.Axis.Y), shape.getStart(Direction.Axis.Z),//
                shape.getEnd(Direction.Axis.X), shape.getEnd(Direction.Axis.Y), shape.getEnd(Direction.Axis.Z)//
        ));
    }
    return entry.getRight();
}
 
Example #26
Source File: RotationUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Rotate this Facing around the Y axis counter-clockwise (NORTH => EAST => SOUTH => WEST => NORTH)
 *
 * @param facing Current facing.
 * @return Next facing.
 */
public static Direction rotateClockwise(Direction facing) {
    switch (facing) {
        case NORTH:
            return Direction.EAST;
        case EAST:
            return Direction.SOUTH;
        case SOUTH:
            return Direction.WEST;
        case WEST:
            return Direction.NORTH;
        default:
            throw new IllegalStateException("Unable to get CW facing of " + facing);
    }
}
 
Example #27
Source File: BlockLaserBeam.java    From Artifacts with MIT License 5 votes vote down vote up
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);
    }
}
 
Example #28
Source File: PerspectiveAwareLayeredModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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();
}
 
Example #29
Source File: CapabilityCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
}
 
Example #30
Source File: PerspectiveAwareBakedModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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();
}