下面列出了net.minecraft.util.EnumFacing#VALUES 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Get a list of sides of a given block that ant particles can spawn on.
* Ant particles can spawn on a face if any of the following are true:
* -- the adjacent block returns false for doesSideBlockRendering (most blocks just call isOpaqueCube for this)
* -- the given block's collision AABB does not fully extend to that side
* @param world The world
* @param pos The blockpos of the relevant block
* @return A List of EnumFacings that ant particles can spawn on
*/
public static List<EnumFacing> getAntableSides(World world, BlockPos pos)
{
List<EnumFacing> out = new LinkedList<EnumFacing>();
AxisAlignedBB aabb = world.getBlockState(pos).getCollisionBoundingBox(world, pos);
for (EnumFacing face : EnumFacing.VALUES)
{
if (!world.getBlockState(pos.offset(face)).doesSideBlockRendering(world, pos, face.getOpposite())
|| !doesAABBExtendToFace(aabb, face))
{
out.add(face);
}
}
return out;
}
/**
* The initial nodes used to build out the network from.
* Signals, Station Markers, rail links. Only used when force rebuilding the network.
* @return
*/
private Set<MCPos> getStartNodes(){
Set<MCPos> nodes = new HashSet<>();
for(World world : DimensionManager.getWorlds()) {
for(TileEntity te : world.loadedTileEntityList) {
if(te instanceof TileEntityBase) { //Any Signals TE for testing purposes
nodes.add(new MCPos(world, te.getPos()));
for(EnumFacing facing : EnumFacing.VALUES) {
BlockPos pos = te.getPos().offset(facing);
nodes.add(new MCPos(world, pos));
}
}
}
}
return nodes;
}
@Test
public void toolRotationOnAnySideChangesFrontToClickedSideOrOpposite() {
for (Orientation orientation : MODE.getValidDirections()) {
for (EnumFacing rotatedSide : EnumFacing.VALUES) {
checkFrontDirectionsAfterFourRotations(MODE, rotatedSide, orientation, rotatedSide, rotatedSide.getOpposite());
}
}
}
private void pushToFluidConsumers() {
for (EnumFacing facing : EnumFacing.VALUES) {
if (this.getNutrientFluid() < EmergingTechnologyConfig.HYDROPONICS_MODULE.INJECTOR.injectorFluidTransferRate) {
return;
}
TileEntity neighbour = this.world.getTileEntity(this.pos.offset(facing));
// Return if no tile entity
if (neighbour == null) {
continue;
}
IFluidHandler neighbourFluidHandler = neighbour
.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());
// Return if neighbour has no fluid tank
if (neighbourFluidHandler == null) {
continue;
}
// Fill the neighbour
int filled = neighbourFluidHandler.fill(new FluidStack(ModFluids.NUTRIENT,
EmergingTechnologyConfig.HYDROPONICS_MODULE.INJECTOR.injectorFluidTransferRate), true);
this.nutrientFluidHandler.drain(filled, true);
}
}
/**
*
* @param cart
* @return true if there was a valid hopper (not necessarily if extracted an item)
*/
private boolean extractFuelFromHopper(EntityMinecart cart, BlockPos pos){
boolean foundHopper = false;
for(EnumFacing dir : EnumFacing.VALUES) {
BlockPos neighbor = pos;
for(int offsetTimes = 0; offsetTimes < (dir == EnumFacing.UP ? 2 : 1); offsetTimes++) {
neighbor = neighbor.offset(dir);
TileEntity te = cart.world.getTileEntity(neighbor);
if(te instanceof TileEntityHopper) {
EnumFacing hopperDir = cart.world.getBlockState(neighbor).getValue(BlockHopper.FACING);
if(hopperDir.getOpposite() == dir) {
TileEntityHopper hopper = (TileEntityHopper)te;
for(int i = 0; i < hopper.getSizeInventory(); i++) {
ItemStack stack = hopper.getStackInSlot(i);
if(!stack.isEmpty() && getFuelInv().isItemValidForSlot(0, stack)) {
ItemStack inserted = stack.copy();
inserted.setCount(1);
ItemStack left = ItemHandlerHelper.insertItemStacked(getEngineItemHandler(), inserted, false);
if(left.isEmpty()) {
stack.shrink(1);
hopper.markDirty();
return true;
}
}
}
foundHopper = true;
}
}
}
}
return foundHopper;
}
@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
super.receiveCustomData(dataId, buf);
if (dataId == 100) {
this.outputFacing = EnumFacing.VALUES[buf.readByte()];
getHolder().scheduleChunkForRenderUpdate();
} else if (dataId == 101) {
this.autoOutputItems = buf.readBoolean();
getHolder().scheduleChunkForRenderUpdate();
} else if (dataId == 102) {
this.autoOutputFluids = buf.readBoolean();
getHolder().scheduleChunkForRenderUpdate();
}
}
@SideOnly(Side.CLIENT)
public void render(CCRenderState renderState, Matrix4 translation, IVertexOperation[] ops, Cuboid6 bounds, EnumFacing frontFacing, boolean isActive) {
for (EnumFacing renderSide : EnumFacing.VALUES) {
OverlayFace overlayFace = OverlayFace.bySide(renderSide, frontFacing);
if (sprites.containsKey(overlayFace)) {
TextureAtlasSprite renderSprite = sprites.get(overlayFace).getSprite(isActive);
Textures.renderFace(renderState, translation, ops, renderSide, bounds, renderSprite);
}
}
}
public void updateInputRedstoneSignals() {
for (EnumFacing side : EnumFacing.VALUES) {
int redstoneValue = GTUtility.getRedstonePower(getWorld(), getPos(), side);
int currentValue = sidedRedstoneInput[side.getIndex()];
if(redstoneValue != currentValue) {
this.sidedRedstoneInput[side.getIndex()] = redstoneValue;
CoverBehavior coverBehavior = getCoverAtSide(side);
if(coverBehavior != null) {
coverBehavior.onRedstoneInputSignalChange(redstoneValue);
}
}
}
}
public void removeSeal(World worldIn, BlockPos pos) {
AtmosphereHandler atmhandler = AtmosphereHandler.getOxygenHandler(worldIn.provider.getDimension());
if(atmhandler == null)
return;
for(EnumFacing dir : EnumFacing.VALUES) {
BlobHandler handler = blobList.remove(new HashedBlockPosition(pos.offset(dir)));
if (handler != null) atmhandler.unregisterBlob(handler);
}
}
public void readInitialSyncData(PacketBuffer buf) {
for (EnumFacing coverSide : EnumFacing.VALUES) {
int coverId = buf.readVarInt();
if (coverId != -1) {
CoverDefinition coverDefinition = CoverDefinition.getCoverByNetworkId(coverId);
CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, coverSide);
coverBehavior.readInitialSyncData(buf);
this.coverBehaviors[coverSide.getIndex()] = coverBehavior;
}
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private Map<EnumFacing, BakedQuad> generateCoreQuads(GTBlockBaseConnect wire, int min, int max) {
Vector3f minF = new Vector3f((float) min, (float) min, (float) min);
Vector3f maxF = new Vector3f((float) max, (float) max, (float) max);
BlockPartFace face = new BlockPartFace((EnumFacing) null, 0, "", new BlockFaceUV(new float[] { (float) min,
(float) min, (float) max, (float) max }, 0));
Map<EnumFacing, BakedQuad> quads = new EnumMap(EnumFacing.class);
EnumFacing[] var8 = EnumFacing.VALUES;
int var9 = var8.length;
for (int var10 = 0; var10 < var9; ++var10) {
EnumFacing side = var8[var10];
quads.put(side, this.getBakery().makeBakedQuad(minF, maxF, face, wire.getTextureFromState(this.state, side), side, ModelRotation.X0_Y0, (BlockPartRotation) null, true, true));
}
return quads;
}
@Test
public void testInversionAfterMirrorURotation() {
for (EnumFacing dir : EnumFacing.VALUES)
testInversion(BlockTextureTransform.builder().mirrorU(dir).build());
}
private static void buildQuadsForLayer(List<BakedQuad> quads, IBakedModel model) {
quads.addAll(model.getQuads(null, null, 0));
for (EnumFacing side : EnumFacing.VALUES)
quads.addAll(model.getQuads(null, side, 0));
}
public void fireCheckAllDirections(World worldIn, BlockPos startBlock, EnumFacing directionFrom) {
for(EnumFacing dir : EnumFacing.VALUES) {
if(directionFrom.getOpposite() != dir)
fireCheck(worldIn, startBlock.offset(dir));
}
}
public static void pushPacketsToAdjacentMachines(World world, BlockPos pos, OptimiserPacket packet) {
for (EnumFacing facing : EnumFacing.VALUES) {
for (int i = 1; i < EmergingTechnologyConfig.ELECTRICS_MODULE.OPTIMISER.range; i++) {
TileEntity tile = world.getTileEntity(pos.offset(facing, i));
if (tile == null)
continue;
if (tile instanceof IOptimisableTile == false)
continue;
IOptimisableTile machine = (IOptimisableTile) tile;
machine.getPacket().merge(packet);
}
}
}
@Test
public void testInversionAfterMirrorUVRotation() {
for (EnumFacing dir : EnumFacing.VALUES)
testInversion(BlockTextureTransform.builder().mirrorUV(dir).build());
}
@Override
protected EnumFacing convert(int bit) {
return EnumFacing.VALUES[bit];
}
@Test
public void testInversionAfterMirrorVRotation() {
for (EnumFacing dir : EnumFacing.VALUES)
testInversion(BlockTextureTransform.builder().mirrorV(dir).build());
}
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
EnumFacing faceHit = spell.getFaceHit();
Set<BlockPos> blockSet = spell.getDataWithFallback(SpellData.DefaultKeys.BLOCK_SET, new BlockSet(new HashSet<>())).getBlockSet();
Map<BlockPos, IBlockState> blockStateCache = spell.getDataWithFallback(SpellData.DefaultKeys.BLOCKSTATE_CACHE, new BlockStateCache(new HashMap<>())).getBlockStateCache();
HashMap<BlockPos, IBlockState> tmpCache = new HashMap<>(blockStateCache);
double duration = spellRing.getAttributeValue(world, AttributeRegistry.DURATION, spell) * 20;
PhasedBlockRenderer.addPhase(world, blockSet, (int) duration);
if (faceHit != null) {
for (Map.Entry<BlockPos, IBlockState> entry : tmpCache.entrySet()) {
IBlockState thisState = entry.getValue();
if (thisState.getBlock() != ModBlocks.FAKE_AIR) continue;
ParticleBuilder glitter2 = new ParticleBuilder(10);
glitter2.setRenderNormalLayer(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
glitter2.disableRandom();
ParticleSpawner.spawn(glitter2, world, new StaticInterp<>(new Vec3d(entry.getKey()).add(0.5, 0.5, 0.5)), 5, (int) duration, (aFloat, build) -> {
build.setColor(Color.CYAN);
//build.setAlphaFunction(new InterpFloatInOut(1f, 0.1f));
build.setAlpha(RandUtil.nextFloat(0.05f, 0.2f));
build.setPositionOffset(new Vec3d(
RandUtil.nextDouble(-0.5, 0.5),
RandUtil.nextDouble(-0.5, 0.5),
RandUtil.nextDouble(-0.5, 0.5)
));
build.setMotion(new Vec3d(
RandUtil.nextDouble(-0.001, 0.001),
RandUtil.nextDouble(-0.001, 0.001),
RandUtil.nextDouble(-0.001, 0.001)
));
build.setLifetime(RandUtil.nextInt(20, 40));
build.setScaleFunction(new InterpFloatInOut(0.9f, 0.9f));
build.setScale(RandUtil.nextFloat(0.1f, 0.3f));
});
BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos(entry.getKey());
for (EnumFacing facing : EnumFacing.VALUES) {
mutable.move(facing);
IBlockState adjState;
if (!blockStateCache.containsKey(mutable)) {
adjState = world.getBlockState(mutable);
blockStateCache.put(mutable.toImmutable(), adjState);
} else adjState = blockStateCache.get(mutable);
if (adjState.getBlock() != Blocks.AIR && adjState.getBlock() != ModBlocks.FAKE_AIR) {
Vec3d directionOffsetVec = new Vec3d(facing.getOpposite().getDirectionVec()).scale(0.5);
Vec3d adjPos = new Vec3d(mutable).add(0.5, 0.5, 0.5).add(directionOffsetVec);
for (EnumFacing subFacing : getPerpendicularFacings(facing)) {
mutable.move(subFacing);
IBlockState subState;
if (!blockStateCache.containsKey(mutable)) {
subState = world.getBlockState(mutable);
blockStateCache.put(mutable.toImmutable(), subState);
} else subState = blockStateCache.get(mutable);
if (BlockUtils.isAnyAir(subState)) {
Vec3d subPos = new Vec3d(mutable).add(0.5, 0.5, 0.5).add(directionOffsetVec);
Vec3d midPointVec = new Vec3d(
(adjPos.x + subPos.x) / 2.0,
(adjPos.y + subPos.y) / 2.0,
(adjPos.z + subPos.z) / 2.0);
Vec3d sub = subPos.subtract(adjPos);
EnumFacing adjSubFacing = EnumFacing.getFacingFromVector((float) sub.x, (float) sub.y, (float) sub.z);
Vec3d cross = new Vec3d(adjSubFacing.getDirectionVec()).crossProduct(new Vec3d(facing.getDirectionVec())).normalize().scale(0.5);
ParticleBuilder glitter = new ParticleBuilder(10);
glitter.setRenderNormalLayer(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
glitter.disableRandom();
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(midPointVec), 50, (int) duration, (aFloat, build) -> {
build.setColor(Color.CYAN);
//build.setAlphaFunction(new InterpFloatInOut(1f, 0.1f));
build.setAlpha(RandUtil.nextFloat(0.3f, 0.7f));
build.setPositionOffset(cross.scale(RandUtil.nextFloat(-1, 1)));
build.setLifetime(RandUtil.nextInt(20, 40));
build.setScaleFunction(new InterpFloatInOut(0.9f, 0.9f));
build.setScale(RandUtil.nextFloat(0.2f, 0.5f));
});
}
mutable.move(subFacing.getOpposite());
}
}
mutable.move(facing.getOpposite());
}
}
}
}
public void testInversion(BlockTextureTransform t) {
for (EnumFacing dir : EnumFacing.VALUES)
testInversion(t, dir);
}