Java Code Examples for net.minecraft.util.Direction#BY_INDEX

The following examples show how to use net.minecraft.util.Direction#BY_INDEX . 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: CapabilityCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Notifies {@link CapabilityCache} of a {@link Block#onNeighborChange} event.<br/>
 * Marks all empty capabilities provided by <code>from</code> block, to be re-cached
 * next query.
 *
 * @param from The from position.
 */
public void onNeighborChanged(BlockPos from) {
    if (world == null || pos == null) {
        return;
    }
    BlockPos offset = from.subtract(pos);
    int diff = MathHelper.absSum(offset);
    int side = MathHelper.toSide(offset);
    if (side < 0 || diff != 1) {
        return;
    }
    Direction sideChanged = Direction.BY_INDEX[side];

    Iterables.concat(selfCache.entrySet(), getCacheForSide(sideChanged).entrySet()).forEach(entry -> {
        Object2IntPair<LazyOptional<?>> pair = entry.getValue();
        if (pair.getKey() != null && !pair.getKey().isPresent()) {
            pair.setKey(null);
            pair.setValue(ticks);
        }
    });
}
 
Example 3
Source File: TileEnderTank.java    From EnderStorage with MIT License 5 votes vote down vote up
private void ejectLiquid() {
    IFluidHandler source = getStorage();
    for (Direction side : Direction.BY_INDEX) {
        IFluidHandler dest = capCache.getCapabilityOr(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side, EmptyFluidHandler.INSTANCE);
        FluidStack drain = source.drain(100, IFluidHandler.FluidAction.SIMULATE);
        if (!drain.isEmpty()) {
            int qty = dest.fill(drain, IFluidHandler.FluidAction.EXECUTE);
            if (qty > 0) {
                source.drain(qty, IFluidHandler.FluidAction.EXECUTE);
            }
        }
    }
}
 
Example 4
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 5
Source File: AbstractPerspectiveLayeredModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected List<BakedQuad> getAllQuads(BlockState state, IModelData data) {
    List<BakedQuad> allQuads = new ArrayList<>();
    for (RenderType layer : RenderType.getBlockRenderTypes()) {
        allQuads.addAll(getLayerQuads(state, null, layer, new Random(0), data));
        for (Direction face : Direction.BY_INDEX) {
            allQuads.addAll(getLayerQuads(state, face, layer, new Random(0), data));
        }
    }
    return allQuads;
}
 
Example 6
Source File: InventoryRange.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Deprecated// Use EnumFacing version.
public InventoryRange(IInventory inv, int side) {
    this(inv, Direction.BY_INDEX[side]);
}
 
Example 7
Source File: IndexedCuboid6.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public CuboidRayTraceResult calculateIntercept(Vector3 start, Vector3 end) {
    Vector3 hit = null;
    Direction sideHit = null;
    double dist = Double.MAX_VALUE;

    for (Direction face : Direction.BY_INDEX) {
        Vector3 suspectHit = null;
        switch (face) {
            case DOWN:
                suspectHit = start.copy().XZintercept(end, min.y);
                break;
            case UP:
                suspectHit = start.copy().XZintercept(end, max.y);
                break;
            case NORTH:
                suspectHit = start.copy().XYintercept(end, min.z);
                break;
            case SOUTH:
                suspectHit = start.copy().XYintercept(end, max.z);
                break;
            case WEST:
                suspectHit = start.copy().YZintercept(end, min.x);
                break;
            case EAST:
                suspectHit = start.copy().YZintercept(end, max.x);
                break;
        }

        if (suspectHit == null) {
            continue;
        }

        switch (face) {

            case DOWN:
            case UP:
                if (!MathHelper.between(min.x, suspectHit.x, max.x) || !MathHelper.between(min.z, suspectHit.z, max.z)) {
                    continue;
                }
                break;
            case NORTH:
            case SOUTH:
                if (!MathHelper.between(min.x, suspectHit.x, max.x) || !MathHelper.between(min.y, suspectHit.y, max.y)) {
                    continue;
                }
                break;
            case WEST:
            case EAST:
                if (!MathHelper.between(min.y, suspectHit.y, max.y) || !MathHelper.between(min.z, suspectHit.z, max.z)) {
                    continue;
                }
                break;
        }
        double suspectDist = suspectHit.copy().subtract(start).magSquared();
        if (suspectDist < dist) {
            sideHit = face;
            dist = suspectDist;
            hit = suspectHit;
        }
    }

    if (sideHit != null && hit != null) {
        return new CuboidRayTraceResult(hit, sideHit, false, this, dist);
    }
    return null;
}