下面列出了net.minecraft.util.EnumFacing#getOpposite ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private int fillInternal(World world, BlockPos coord, EnumFacing side, int maxDrain) {
final TileEntity otherTank = BlockUtils.getTileInDirection(world, coord, side);
final EnumFacing drainSide = side.getOpposite();
final IFluidHandler handler = CompatibilityUtils.getFluidHandler(otherTank, drainSide);
if (handler != null) {
final FluidStack drained = handler.drain(maxDrain, false);
if (drained != null && filter.canAcceptFluid(drained)) {
final int filled = fill(drained, true);
if (filled > 0) {
handler.drain(filled, true);
return filled;
}
}
}
return 0;
}
@Override
@SuppressWarnings("deprecation")
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
IBlockState actualState = state;
for (EnumFacing facing : EnumFacing.values()) {
IBlockState offsetState = worldIn.getBlockState(pos.offset(facing));
Block offsetBlock = offsetState.getBlock();
if (offsetBlock instanceof IProtocolProvider && ((IProtocolProvider) offsetBlock).getProtocol() == protocol) {
if (offsetBlock instanceof BlockRoutiduct && offsetState.getValue(BlockRoutiduct.AXIS) == AxisUtils.getAxis(facing) ||
offsetBlock instanceof BlockRelay ||
offsetBlock instanceof BlockPackager && offsetState.getValue(BlockPackager.FACING) == facing.getOpposite() ||
offsetBlock instanceof BlockUnpackager && offsetState.getValue(BlockUnpackager.FACING) == facing.getOpposite()
)
actualState = actualState.withProperty(getProperty(facing), true);
}
}
return actualState;
}
@Override
public void update() {
if (getMetaTileEntity().getWorld().isRemote)
return;
if (getEnergyStored() >= getOutputVoltage() && getOutputVoltage() > 0 && getOutputAmperage() > 0) {
long outputVoltage = getOutputVoltage();
long outputAmperes = Math.min(getEnergyStored() / outputVoltage, getOutputAmperage());
if (outputAmperes == 0) return;
long amperesUsed = 0;
for (EnumFacing side : EnumFacing.VALUES) {
if (!outputsEnergy(side)) continue;
TileEntity tileEntity = metaTileEntity.getWorld().getTileEntity(metaTileEntity.getPos().offset(side));
EnumFacing oppositeSide = side.getOpposite();
if (tileEntity != null && tileEntity.hasCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, oppositeSide)) {
IEnergyContainer energyContainer = tileEntity.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, oppositeSide);
if (energyContainer == null || !energyContainer.inputsEnergy(oppositeSide)) continue;
amperesUsed += energyContainer.acceptEnergyFromNetwork(oppositeSide, outputVoltage, outputAmperes - amperesUsed);
if (amperesUsed == outputAmperes) break;
}
}
if (amperesUsed > 0) {
setEnergyStored(getEnergyStored() - amperesUsed * outputVoltage);
}
}
}
@Override
protected int getActiveVisualConnections(IPipeTile<FluidPipeType, FluidPipeProperties> selfTile) {
int activeNodeConnections = 0;
for (EnumFacing side : EnumFacing.VALUES) {
BlockPos offsetPos = selfTile.getPipePos().offset(side);
TileEntity tileEntity = selfTile.getPipeWorld().getTileEntity(offsetPos);
if(tileEntity != null) {
EnumFacing opposite = side.getOpposite();
IFluidHandler sourceHandler = selfTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
IFluidHandler receivedHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opposite);
if (sourceHandler != null && receivedHandler != null) {
activeNodeConnections |= 1 << side.getIndex();
}
}
}
return activeNodeConnections;
}
private static boolean breakSchematicBlocks(Minecraft mc)
{
Entity entity = fi.dy.masa.malilib.util.EntityUtils.getCameraEntity();
RayTraceWrapper wrapper = RayTraceUtils.getSchematicWorldTraceWrapperIfClosest(mc.world, entity, 20);
if (wrapper != null)
{
RayTraceResult trace = wrapper.getRayTraceResult();
BlockPos pos = trace.getBlockPos();
EnumFacing playerFacingH = mc.player.getHorizontalFacing();
EnumFacing direction = fi.dy.masa.malilib.util.PositionUtils.getTargetedDirection(trace.sideHit, playerFacingH, pos, trace.hitVec);
// Center region
if (direction == trace.sideHit)
{
direction = direction.getOpposite();
}
BlockPos posEnd = getReplacementBoxEndPos(pos, direction);
return setSchematicBlockStates(pos, posEnd, Blocks.AIR.getDefaultState());
}
return false;
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (!content.opensWithHands)
return true;
if (state.getValue(OPEN))
{
state = state.withProperty(OPEN, Boolean.FALSE);
worldIn.setBlockState(pos, state, 10);
} else
{
EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw);
if (state.getValue(FACING) == enumfacing.getOpposite())
{
state = state.withProperty(FACING, enumfacing);
}
state = state.withProperty(OPEN, Boolean.TRUE);
worldIn.setBlockState(pos, state, 10);
}
worldIn.playEvent(playerIn, state.getValue(OPEN) ? 1008 : 1014, pos, 0);
return true;
}
public static OverlayFace bySide(EnumFacing side, EnumFacing frontFacing) {
if (side == frontFacing) {
return FRONT;
} else if (side.getOpposite() == frontFacing) {
return BACK;
} else if (side == EnumFacing.UP) {
return TOP;
} else if (side == EnumFacing.DOWN) {
return BOTTOM;
} else return SIDE;
}
/**
* Helper method to add back a way to do left hand rotations, like ForgeDirection had.
*/
public static EnumFacing getRotation(EnumFacing facing, EnumFacing axis)
{
EnumFacing newFacing = facing.rotateAround(axis.getAxis());
if (axis.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
return newFacing;
}
// Negative axis direction, if the facing was actually rotated then get the opposite
return newFacing != facing ? newFacing.getOpposite() : facing;
}
@Nullable
private static HitPosition getAdjacentClickPositionForSlab(BlockPos targetBlockPos, IBlockState stateSchematic, boolean isTop, World worldClient)
{
EnumFacing clickSide = isTop ? EnumFacing.DOWN : EnumFacing.UP;
EnumFacing clickSideOpposite = clickSide.getOpposite();
BlockPos posSide = targetBlockPos.offset(clickSideOpposite);
// Can click on the existing block above or below
if (canClickOnAdjacentBlockToPlaceSingleSlabAt(targetBlockPos, stateSchematic, clickSideOpposite, worldClient))
{
return HitPosition.of(posSide, getHitPositionForSidePosition(posSide, clickSideOpposite), clickSide);
}
// Try the sides
else
{
for (EnumFacing side : PositionUtils.HORIZONTAL_DIRECTIONS)
{
if (canClickOnAdjacentBlockToPlaceSingleSlabAt(targetBlockPos, stateSchematic, side, worldClient))
{
posSide = targetBlockPos.offset(side);
Vec3d hitPos = getHitPositionForSidePosition(posSide, side);
double y = isTop ? 0.9 : 0.1;
return HitPosition.of(posSide, new Vec3d(hitPos.x, posSide.getY() + y, hitPos.z), side.getOpposite());
}
}
}
return null;
}
@Test
public void toolRotationOnBackDoesntChangeFront() {
for (Orientation orientation : mode.getValidDirections()) {
final EnumFacing front = mode.getFront(orientation);
final EnumFacing back = front.getOpposite();
final Orientation rotatedOrientation = mode.calculateToolRotation(orientation, back);
final EnumFacing rotatedFront = mode.getFront(rotatedOrientation);
Assert.assertEquals(front, rotatedFront);
}
}
private LocalDirections(EnumFacing front, EnumFacing top) {
this.front = front;
this.back = front.getOpposite();
this.top = top;
this.bottom = top.getOpposite();
final HalfAxis frontHa = HalfAxis.fromEnumFacing(front);
final HalfAxis topHa = HalfAxis.fromEnumFacing(top);
this.right = frontHa.cross(topHa).dir;
this.left = topHa.cross(frontHa).dir;
}
public static Vec3d rotatePointAroundAxis(double x, double y, double z, Vec3d reference, EnumFacing from, EnumFacing to)
{
if (to == from.getOpposite())
{
double rx = reference.x;
if (from.getAxis().isHorizontal())
{
//System.out.printf("rotatePointAroundAxis - opposite, horizontal, from: %s to: %s\n", from, to);
double rz = reference.z;
x = rx + (rx - x);
z = rz + (rz - z);
}
// Rotate around the z-axis when the to/from axes are vertical
else
{
//System.out.printf("rotatePointAroundAxis - opposite, vertical, from: %s to: %s\n", from, to);
double ry = reference.y;
x = rx + (rx - x);
y = ry + (ry - y);
}
return new Vec3d(x, y, z);
}
return rotatePointCWAroundAxis(x, y, z, reference, FROM_TO_CW_ROTATION_AXES[from.getIndex()][to.getIndex()]);
}
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
EnumFacing facingHorizontal = placer.getHorizontalFacing();
if (!placer.isSneaking()) {
facingHorizontal = facingHorizontal.getOpposite();
}
return this.getDefaultState().withProperty(BlockHorizontal.FACING, facingHorizontal);
}
@Override
@SuppressWarnings("deprecation")
@Nonnull
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
EnumFacing facingHorizontal = placer.getHorizontalFacing();
if (!placer.isSneaking()) {
facingHorizontal = facingHorizontal.getOpposite();
}
return this.getDefaultState().withProperty(BlockHorizontal.FACING, facingHorizontal);
}
private static int tryFillNeighbour(FluidStack drainedFluid, EnumFacing side, TileEntity otherTank) {
final FluidStack toFill = drainedFluid.copy();
final EnumFacing fillSide = side.getOpposite();
final IFluidHandler fluidHandler = CompatibilityUtils.getFluidHandler(otherTank, fillSide);
return fluidHandler != null? fluidHandler.fill(toFill, true) : 0;
}
/**
* Get the (non-optimized) transformations to transform a plane defined by the
* vectors p1Up and p1Right to match the other plane defined by p2Up and p2Right.
*/
public static List<EnumFacing> getTransformationsToMatchPlanes(EnumFacing p1Up, EnumFacing p1Right, EnumFacing p2Up, EnumFacing p2Right)
{
List<EnumFacing> list = new ArrayList<EnumFacing>();
EnumFacing tmp1 = p1Up;
EnumFacing rot = p1Up;
// First get the rotations to match p1Up to p2Up
if (p2Up == p1Right)
{
rot = BlockPosEU.getRotation(p1Up, p1Right.getOpposite());
//System.out.printf("TR right - p1Up: %s p2Up: %s p1Right: %s p2Right: %s rot: %s\n", p1Up, p2Up, p1Right, p2Right, rot);
list.add(rot);
p1Right = BlockPosEU.getRotation(p1Right, rot);
p1Up = p2Up;
}
else if (p2Up == p1Right.getOpposite())
{
rot = BlockPosEU.getRotation(p1Up, p1Right);
//System.out.printf("TR left - p1Up: %s p2Up: %s p1Right: %s p2Right: %s rot: %s\n", p1Up, p2Up, p1Right, p2Right, rot);
list.add(rot);
p1Right = BlockPosEU.getRotation(p1Right, rot);
p1Up = p2Up;
}
else
{
for (int i = 0; i < 4; i++)
{
if (tmp1 == p2Up)
{
break;
}
//System.out.printf("TR loop 1 - p1Right %s ", p1Right);
tmp1 = BlockPosEU.getRotation(tmp1, p1Right);
list.add(p1Right);
}
}
//System.out.printf("\np1Right: %s p2Right: %s\n", p1Right, p2Right);
p1Up = tmp1;
tmp1 = p1Right;
// Then get the rotations to match p1Right to p2Right, rotating around p2Up
for (int i = 0; i < 4; i++)
{
if (tmp1 == p2Right)
{
break;
}
//System.out.printf("TR loop 2: %s ", p2Up);
tmp1 = BlockPosEU.getRotation(tmp1, p2Up);
list.add(p2Up);
}
//System.out.printf("\n");
return list;
}
public void fireCheckAllDirections(World worldIn, BlockPos startBlock, EnumFacing directionFrom) {
for(EnumFacing dir : EnumFacing.VALUES) {
if(directionFrom.getOpposite() != dir)
fireCheck(worldIn, startBlock.offset(dir));
}
}
private void renderSide(ITessellator tessellator, EnumFacing dir, byte connection, TextureAtlasSprite icon) {
if (connection < 0 || connection > 1) {
return;
}
//data about side to render
boolean xAxis = dir.getAxis() == EnumFacing.Axis.X;
int index = xAxis ? dir.getFrontOffsetX() : dir.getFrontOffsetZ();
int min = index < 0 ? 0 : 14;
int max = index < 0 ? 2 : 16;
//render upper face
tessellator.drawScaledFace(xAxis ? min : 0, xAxis ? 0 : min, xAxis ? max : 16, xAxis ? 16 : max, EnumFacing.UP, icon, 16);
//render side
if (connection == 0) {
tessellator.drawScaledFace(0, 0, 16, 16, dir, icon, index > 0 ? 16 : 0);
tessellator.drawScaledFace(0, 0, 16, 16, dir.getOpposite(), icon, index > 0 ? 14 : 2);
} else {
//vertical faces
//lower part, under the channel
tessellator.drawScaledFace(0, 0, 16, 5, dir, icon, index > 0 ? 16 : 0);
tessellator.drawScaledFace(0, 0, 16, 5, dir.getOpposite(), icon, index > 0 ? 14 : 2);
//left center part, same height as the channel
tessellator.drawScaledFace(0, 5, 5, 12, dir, icon, index > 0 ? 16 : 0);
tessellator.drawScaledFace(0, 5, 5, 12, dir.getOpposite(), icon, index > 0 ? 14 : 2);
//right center part, same height as the channel
tessellator.drawScaledFace(11, 5, 16, 12, dir, icon, index > 0 ? 16 : 0);
tessellator.drawScaledFace(11, 5, 16, 12, dir.getOpposite(), icon, index > 0 ? 14 : 2);
//upper part, above the channel
tessellator.drawScaledFace(0, 12, 16, 16, dir, icon, index > 0 ? 16 : 0);
tessellator.drawScaledFace(0, 12, 16, 16, dir.getOpposite(), icon, index > 0 ? 14 : 2);
//inside of the gap
tessellator.drawScaledFace(xAxis ? min : 5, xAxis ? 5 : min, xAxis ? max : 11, xAxis ? 11 : max, EnumFacing.UP, icon, 5);
tessellator.drawScaledFace(xAxis ? min : 5, xAxis ? 5 : min, xAxis ? max : 11, xAxis ? 11 : max, EnumFacing.DOWN, icon, 12);
EnumFacing left = xAxis ? EnumFacing.NORTH : EnumFacing.WEST;
EnumFacing right = left.getOpposite();
tessellator.drawScaledFace(min, 5, max, 12, left, icon, 11);
tessellator.drawScaledFace(min, 5, max, 12, right, icon, 5);
}
}
public static void drawFaceOutline(@Nonnull BlockPos pos, @Nonnull EnumFacing facing, Color color) {
GlStateManager.pushMatrix();
GlStateManager.disableDepth();
GlStateManager.disableLighting();
GlStateManager.disableCull();
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.shadeModel(GL11.GL_SMOOTH);
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE);
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.disableTexture2D();
GlStateManager.enableColorMaterial();
Tessellator tessellator = Tessellator.getInstance();
tessellator.getBuffer().begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
Vec3d directionOffsetVec = new Vec3d(facing.getDirectionVec()).scale(0.5);
Vec3d adjPos = new Vec3d(pos).add(0.5, 0.5, 0.5).add(directionOffsetVec);
GlStateManager.glLineWidth(0.5f);
for (EnumFacing facing1 : getPerpendicularFacings(facing)) {
for (EnumFacing facing2 : getPerpendicularFacings(facing)) {
if (facing1 == facing2 || facing1.getOpposite() == facing2 || facing2.getOpposite() == facing1)
continue;
Vec3d p1 = new Vec3d(facing1.getDirectionVec()).scale(0.5);
Vec3d p2 = new Vec3d(facing2.getDirectionVec()).scale(0.5);
Vec3d edge = adjPos.add(p1.add(p2));
tessellator.getBuffer().pos(edge.x, edge.y, edge.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
}
}
tessellator.draw();
GlStateManager.disableBlend();
GlStateManager.enableDepth();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
GlStateManager.disableColorMaterial();
GlStateManager.enableDepth();
GlStateManager.popMatrix();
}
private boolean doMove(World worldIn, BlockPos pos, EnumFacing direction, boolean extending)
{
if (!extending)
{
worldIn.setBlockToAir(pos.offset(direction));
}
BlockPistonStructureHelper blockpistonstructurehelper = new BlockPistonStructureHelper(worldIn, pos, direction, extending);
if (!blockpistonstructurehelper.canMove())
{
return false;
}
else
{
List<BlockPos> list = blockpistonstructurehelper.getBlocksToMove();
List<IBlockState> list1 = Lists.<IBlockState>newArrayList();
for (int i = 0; i < list.size(); ++i)
{
BlockPos blockpos = (BlockPos)list.get(i);
list1.add(worldIn.getBlockState(blockpos).getActualState(worldIn, blockpos));
}
List<BlockPos> list2 = blockpistonstructurehelper.getBlocksToDestroy();
int k = list.size() + list2.size();
IBlockState[] aiblockstate = new IBlockState[k];
EnumFacing enumfacing = extending ? direction : direction.getOpposite();
for (int j = list2.size() - 1; j >= 0; --j)
{
BlockPos blockpos1 = (BlockPos)list2.get(j);
IBlockState iblockstate = worldIn.getBlockState(blockpos1);
// Forge: With our change to how snowballs are dropped this needs to disallow to mimic vanilla behavior.
float chance = iblockstate.getBlock() instanceof BlockSnow ? -1.0f : 1.0f;
iblockstate.getBlock().dropBlockAsItemWithChance(worldIn, blockpos1, iblockstate, chance, 0);
worldIn.setBlockToAir(blockpos1);
--k;
aiblockstate[k] = iblockstate;
}
for (int l = list.size() - 1; l >= 0; --l)
{
BlockPos blockpos3 = (BlockPos)list.get(l);
IBlockState iblockstate2 = worldIn.getBlockState(blockpos3);
worldIn.setBlockState(blockpos3, Blocks.AIR.getDefaultState(), 2);
blockpos3 = blockpos3.offset(enumfacing);
worldIn.setBlockState(blockpos3, Blocks.PISTON_EXTENSION.getDefaultState().withProperty(FACING, direction), 4);
worldIn.setTileEntity(blockpos3, BlockPistonMoving.createTilePiston((IBlockState)list1.get(l), direction, extending, false));
--k;
aiblockstate[k] = iblockstate2;
}
BlockPos blockpos2 = pos.offset(direction);
if (extending)
{
BlockPistonExtension.EnumPistonType blockpistonextension$enumpistontype = BlockPistonExtension.EnumPistonType.DEFAULT;
IBlockState iblockstate3 = Blocks.PISTON_HEAD.getDefaultState().withProperty(BlockPistonExtension.FACING, direction).withProperty(BlockPistonExtension.TYPE, blockpistonextension$enumpistontype);
IBlockState iblockstate1 = Blocks.PISTON_EXTENSION.getDefaultState().withProperty(BlockPistonMoving.FACING, direction).withProperty(BlockPistonMoving.TYPE, BlockPistonExtension.EnumPistonType.DEFAULT);
worldIn.setBlockState(blockpos2, iblockstate1, 4);
worldIn.setTileEntity(blockpos2, BlockPistonMoving.createTilePiston(iblockstate3, direction, true, false));
}
for (int i1 = list2.size() - 1; i1 >= 0; --i1)
{
worldIn.notifyNeighborsOfStateChange((BlockPos)list2.get(i1), aiblockstate[k++].getBlock(), true);
}
for (int j1 = list.size() - 1; j1 >= 0; --j1)
{
worldIn.notifyNeighborsOfStateChange((BlockPos)list.get(j1), aiblockstate[k++].getBlock(), true);
}
if (extending)
{
worldIn.notifyNeighborsOfStateChange(blockpos2, Blocks.PISTON_HEAD, true);
worldIn.notifyNeighborsOfStateChange(pos, this, true);
}
return true;
}
}