下面列出了net.minecraft.util.Direction#BY_INDEX 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
/**
* 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);
}
});
}
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);
}
}
}
}
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;
}
@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;
}
@Deprecated// Use EnumFacing version.
public InventoryRange(IInventory inv, int side) {
this(inv, Direction.BY_INDEX[side]);
}
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;
}