下面列出了怎么用net.minecraft.util.Facing的API类实例代码及写法,或者点击链接到github查看源代码。
private void outputInChamber(){
TileEntityPressureChamberValve valve = getCore();
if(valve != null) {
for(int i = 0; i < 6; i++) {
int x = xCoord + Facing.offsetsXForSide[i];
int y = yCoord + Facing.offsetsYForSide[i];
int z = zCoord + Facing.offsetsZForSide[i];
if(valve.isCoordWithinChamber(worldObj, x, y, z)) {
enoughAir = Math.abs(valve.currentAir) > inventory[0].stackSize * PneumaticValues.USAGE_CHAMBER_INTERFACE;
if(enoughAir) {
valve.addAir((valve.currentAir > 0 ? -1 : 1) * inventory[0].stackSize * PneumaticValues.USAGE_CHAMBER_INTERFACE, ForgeDirection.UNKNOWN);
EntityItem item = new EntityItem(worldObj, x + 0.5D, y + 0.5D, z + 0.5D, inventory[0].copy());
worldObj.spawnEntityInWorld(item);
setInventorySlotContents(0, null);
break;
}
}
}
}
}
private boolean isTouchingLiquid()
{
for( int i = 1; i < 6; ++i ) // ignore down
{
int x = xCoord + Facing.offsetsXForSide[ i ];
int y = yCoord + Facing.offsetsYForSide[ i ];
int z = zCoord + Facing.offsetsZForSide[ i ];
Block block = worldObj.getBlock( x, y, z );
if( block != null && block instanceof BlockLiquid )
{
return true;
}
}
return false;
}
private boolean checkCooling()
{
for( int i = 0; i < 6; ++i )
{
int x = xCoord + Facing.offsetsXForSide[ i ];
int y = yCoord + Facing.offsetsYForSide[ i ];
int z = zCoord + Facing.offsetsZForSide[ i ];
Block block = worldObj.getBlock( x, y, z );
if( block != null && (block.getMaterial() == Material.ice || block.getMaterial() == Material.packedIce) )
{
return true;
}
}
return false;
}
private boolean isPortalCorner( int x, int y, int z, int dir )
{
if( y < 0 || y >= 256 )
{
return false;
}
TileEntity entity = worldObj.getTileEntity( x, y, z );
if( entity != null && entity instanceof TileEntityQBlock )
{
TileEntityQBlock quantum = (TileEntityQBlock) entity;
int[] types = quantum.getTypes();
for( int i = 0; i < 6; ++i )
{
if( i == dir || i == Facing.oppositeSide[ dir ] )
{
if( types[ i ] != 31 ) // GOLD
{
return false;
}
}
else
{
if( types[ i ] != 21 ) // OBSIDIAN
{
return false;
}
}
}
return true;
}
return false;
}
private void updateOutput( World world, int x, int y, int z )
{
if( world.isRemote )
{
return;
}
// Redetermine subtype
int metadata = world.getBlockMetadata( x, y, z );
int direction = getDirection( metadata );
int subType = getSubType( metadata );
int newSubType = evaluateInput( world, x, y, z ) ? SubType.ObserverOn : SubType.ObserverOff;
if( newSubType != subType )
{
// Set new subtype
setDirectionAndSubType( world, x, y, z, direction, newSubType );
subType = newSubType;
// Notify
world.markBlockForUpdate( x, y, z );
world.notifyBlocksOfNeighborChange( x, y, z, this );
}
// Observe
int facing = Facing.oppositeSide[ Direction.directionToFacing[ direction ] ];
observe( world, x, y, z, facing, subType == SubType.ObserverOn );
}
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 );
}
private boolean getRedstoneSignal( World world, int i, int j, int k, int dir )
{
i += Facing.offsetsXForSide[ dir ];
j += Facing.offsetsYForSide[ dir ];
k += Facing.offsetsZForSide[ dir ];
int side = Facing.oppositeSide[ dir ];
return QuantumUtil.getRedstoneSignal( world, i, j, k, side );
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote)
return true;
else {
Block block = world.getBlock(x, y, z);
x += Facing.offsetsXForSide[side];
y += Facing.offsetsYForSide[side];
z += Facing.offsetsZForSide[side];
double d0 = 0.0D;
if (side == 1 && block.getRenderType() == 11)
d0 = 0.5D;
Entity entity = spawnEntity(world, stack.getItemDamage(), x + 0.5D, y + d0, z + 0.5D);
if (entity != null) {
if (entity instanceof EntityLivingBase && stack.hasDisplayName())
((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());
if (!player.capabilities.isCreativeMode)
stack.stackSize--;
}
return true;
}
}
private ArrayList<PortalLocation> findRestOfPortal(int[] cornerPair) {
ArrayList<PortalLocation> returnValue = new ArrayList();
int x1 = cornerPair[0]; //x = east/west = dir 4 5
int y1 = cornerPair[1]; //y = up/down = dir 0 1
int z1 = cornerPair[2]; //z = north/south = dir 2 3
int x2 = cornerPair[3];
int y2 = cornerPair[4];
int z2 = cornerPair[5];
int lookDir = cornerPair[6]; //direction the portal should be looking
int searchDir = ((lookDir - (lookDir % 2)) % 4) + 2; //converts {2, 3, 4, 5} to {4, 4, 2, 2}
if (Math.abs(y1 - y2) < 4 && (Math.abs(x1 - x2) < 3) && (Math.abs(z1 - z2) < 3)) { //if the portal would be too small if this pair of corners would make a portal
return null;
} else if (y1 == y2){ //both corners and the glass between them would form the upper OR lower portal border
for (int dir = 0; dir < 2; dir++) {
int tempY = y2;
for (int i = 0; i < QCraft.maxPortalSize + 1; i++) { //check for maximal portal size
tempY += Facing.offsetsYForSide[ dir ];
if (!isGlass(x1, tempY, z1) || !isGlass(x2, tempY,z2)) { //once connected glass stops
break;
}
}
if (isGlass(x1, tempY, z1) || isGlass(x2, tempY, z2) || Math.abs(y1 - tempY) < 4) { //if not both are non-glass OR the portal wouldn't be high enough
continue;
}
if (isPortalCorner(x1, tempY, z1, lookDir) && isPortalCorner(x2, tempY, z2, lookDir)) {
int c1;
int c2;
if (x1 == x2) {
c1 = z1;
c2 = z2;
} else {
c1 = x1;
c2 = x2;
}
//check for completeness of last horizontal border.
for(int i = Math.min(c1, c2) + 1; i < Math.max(c1, c2); i++ ) {
if (!isGlass((x1 == x2) ? x1 : i, tempY, (z1 == z2) ? z1 : i )) {
break;
}
if (i == Math.max(c1, c2) - 1) {
returnValue.add(new PortalLocation(x1, y1, z1, x2, tempY, z2, worldObj.provider.dimensionId));
}
}
}
}
} else { //if the z and x coordinates of both corners are equal (corners are above eachother)
for (int dir = searchDir; dir < searchDir+2 ; dir++) {
int tempX = x2;
int tempZ = z2;
for (int i = 0; i < QCraft.maxPortalSize + 1; i++) { //check for maximal portal size
tempX += Facing.offsetsXForSide[ dir ];
tempZ += Facing.offsetsZForSide[ dir ];
if (!isGlass(tempX, y1, tempZ) || !isGlass(tempX, y2,tempZ)) { //once connected glass stops
break;
}
}
if (isGlass(tempX, y1, tempZ) || isGlass(tempX, y2, tempZ) || (Math.abs(x1 - tempX) < 3 && Math.abs(z1 - tempZ) < 3) ) { //if not both are non-glass OR the portal wouldn't be high enough
continue;
}
if (isPortalCorner(tempX, y1, tempZ, lookDir) && isPortalCorner(tempX, y2, tempZ, lookDir)) {
//check for completeness of last vertical border.
for(int i = Math.min(y1, y2) + 1; i < Math.max(y1, y2); i++ ) {
if (!isGlass(tempX, i, tempZ )) {
break;
}
if (i == Math.max(y1, y2) - 1) {
returnValue.add(new PortalLocation(x1, y1, z1, tempX, y2, tempZ, worldObj.provider.dimensionId));
}
}
}
}
}
return returnValue; //contains 0 up to 2 portal locations
}
private PortalLocation findPortal()
{
ArrayList<PortalLocation> portalLocations = new ArrayList();
tooManyPossiblePortals = false;
for( int dir = 0; dir < 6; ++dir )
{
// See if this adjoining block is part of a portal:
int x = xCoord + Facing.offsetsXForSide[ dir ];
int y = yCoord + Facing.offsetsYForSide[ dir ];
int z = zCoord + Facing.offsetsZForSide[ dir ];
if( !isGlass( x, y, z ) && !isPortalCorner( x, y, z, 2 ) && !isPortalCorner( x, y, z, 4 ) )
{
continue;
}
ArrayList<PortalLocation> tempLocations = findPortalsAt(x, y, z);
if ( (tempLocations.size() == 2 && ! (isPortalCorner( x, y, z, 2 ) || isPortalCorner( x, y, z, 4 ) ) ) || tempLocations.size() > 2) {
tooManyPossiblePortals = true;
return null;
}
portalLocations.addAll(tempLocations);
if (portalLocations.size() > 2) {
tooManyPossiblePortals = true;
return null;
}
}
if (portalLocations.size() < 1) {
return null;
} else if (portalLocations.size() == 2) {
PortalLocation portal1 = portalLocations.get(0);
PortalLocation portal2 = portalLocations.get(1);
if( Math.min(portal1.m_x1, portal1.m_x2) == Math.min(portal2.m_x1, portal2.m_x2) &&
Math.min(portal1.m_y1, portal1.m_y2) == Math.min(portal2.m_y1, portal2.m_y2) &&
Math.min(portal1.m_z1, portal1.m_z2) == Math.min(portal2.m_z1, portal2.m_z2))
{
return portalLocations.get(0);
} else {
tooManyPossiblePortals = true;
return null;
}
} else if (portalLocations.size() > 2) {
tooManyPossiblePortals = true;
return null;
} else {
return portalLocations.get(0);
}
}
/**
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
*/
@Override
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9){
return Facing.oppositeSide[par5];
}