下面列出了net.minecraft.util.EnumFacing#EAST 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
IBlockState north = worldIn.getBlockState(pos.north());
IBlockState east = worldIn.getBlockState(pos.east());
IBlockState south = worldIn.getBlockState(pos.south());
IBlockState west = worldIn.getBlockState(pos.west());
EnumFacing face = (EnumFacing) state.getValue(FACING);
if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) {
face = EnumFacing.SOUTH;
} else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) {
face = EnumFacing.NORTH;
} else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) {
face = EnumFacing.WEST;
} else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) {
face = EnumFacing.EAST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, face));
}
}
public static EnumFacing getRelativeHorizonal(BlockPos original, BlockPos neighbor){
int relX = neighbor.getX() - original.getX();
int relZ = neighbor.getZ() - original.getZ();
if(relZ == 0) {
if(relX == 1) return EnumFacing.EAST;
if(relX == -1) return EnumFacing.WEST;
}
if(relX == 0) {
if(relZ > 0) return EnumFacing.SOUTH;
if(relZ < 0) return EnumFacing.NORTH;
}
return null;
}
public EnumFacing getFacingFromMeta(int meta) {
if (meta == 0 || meta == 6) {
return EnumFacing.EAST;
}
if (meta == 1 || meta == 7) {
return EnumFacing.WEST;
}
if (meta == 2 || meta == 8) {
return EnumFacing.NORTH;
}
if (meta == 3 || meta == 9) {
return EnumFacing.SOUTH;
}
if (meta == 4 || meta == 10) {
return EnumFacing.UP;
}
if (meta == 5 || meta == 11) {
return EnumFacing.DOWN;
}
return EnumFacing.EAST;
}
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
IBlockState north = worldIn.getBlockState(pos.north());
IBlockState east = worldIn.getBlockState(pos.east());
IBlockState south = worldIn.getBlockState(pos.south());
IBlockState west = worldIn.getBlockState(pos.west());
EnumFacing face = (EnumFacing) state.getValue(FACING);
if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) {
face = EnumFacing.SOUTH;
} else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) {
face = EnumFacing.NORTH;
} else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) {
face = EnumFacing.WEST;
} else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) {
face = EnumFacing.EAST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, face));
}
}
public EnumFacing getFacingFromMeta(int meta) {
if (meta == 0) {
return EnumFacing.EAST;
}
if (meta == 1) {
return EnumFacing.WEST;
}
if (meta == 2) {
return EnumFacing.NORTH;
}
if (meta == 3) {
return EnumFacing.SOUTH;
}
if (meta == 4) {
return EnumFacing.UP;
}
if (meta == 5) {
return EnumFacing.DOWN;
}
return EnumFacing.EAST;
}
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
IBlockState north = worldIn.getBlockState(pos.north());
IBlockState east = worldIn.getBlockState(pos.east());
IBlockState south = worldIn.getBlockState(pos.south());
IBlockState west = worldIn.getBlockState(pos.west());
EnumFacing face = (EnumFacing) state.getValue(FACING);
if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) {
face = EnumFacing.SOUTH;
} else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) {
face = EnumFacing.NORTH;
} else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) {
face = EnumFacing.WEST;
} else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) {
face = EnumFacing.EAST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, face));
}
}
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
IBlockState north = worldIn.getBlockState(pos.north());
IBlockState east = worldIn.getBlockState(pos.east());
IBlockState south = worldIn.getBlockState(pos.south());
IBlockState west = worldIn.getBlockState(pos.west());
EnumFacing face = (EnumFacing) state.getValue(FACING);
if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) {
face = EnumFacing.SOUTH;
} else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) {
face = EnumFacing.NORTH;
} else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) {
face = EnumFacing.WEST;
} else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) {
face = EnumFacing.EAST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, face));
}
}
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
IBlockState north = worldIn.getBlockState(pos.north());
IBlockState east = worldIn.getBlockState(pos.east());
IBlockState south = worldIn.getBlockState(pos.south());
IBlockState west = worldIn.getBlockState(pos.west());
EnumFacing face = (EnumFacing) state.getValue(FACING);
if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) {
face = EnumFacing.SOUTH;
} else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) {
face = EnumFacing.NORTH;
} else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) {
face = EnumFacing.WEST;
} else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) {
face = EnumFacing.EAST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, face));
}
}
@Override
public EnumFacing toNative(Direction novaObj) {
switch (novaObj) {
case DOWN: return EnumFacing.DOWN;
case UP: return EnumFacing.UP;
case NORTH: return EnumFacing.NORTH;
case SOUTH: return EnumFacing.SOUTH;
case WEST: return EnumFacing.WEST;
case EAST: return EnumFacing.EAST;
default: return (EnumFacing) null;
}
}
public void enablePortal(EnumFacing facing)
{
if(facing == EnumFacing.NORTH)
northPortalState = PortalEnumType.Enabled;
else if(facing == EnumFacing.SOUTH)
southPortalState = PortalEnumType.Enabled;
else if(facing == EnumFacing.EAST)
eastPortalState = PortalEnumType.Enabled;
else if(facing == EnumFacing.WEST)
westPortalState = PortalEnumType.Enabled;
}
public void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
IBlockState iblockstate = worldIn.getBlockState(pos.north());
IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = state.getValue(FACING);
if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
{
enumfacing = EnumFacing.SOUTH;
}
else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
{
enumfacing = EnumFacing.NORTH;
}
else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
{
enumfacing = EnumFacing.EAST;
}
else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
{
enumfacing = EnumFacing.WEST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
}
}
public void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
IBlockState iblockstate = worldIn.getBlockState(pos.north());
IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = state.getValue(FACING);
if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
{
enumfacing = EnumFacing.SOUTH;
}
else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
{
enumfacing = EnumFacing.NORTH;
}
else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
{
enumfacing = EnumFacing.EAST;
}
else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
{
enumfacing = EnumFacing.WEST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
}
}
protected EnumFacing getPortalOrientation(World world, BlockPos portalPos)
{
if (world.getBlockState(portalPos.west()).getBlock() == Blocks.PORTAL ||
world.getBlockState(portalPos.east()).getBlock() == Blocks.PORTAL)
{
return EnumFacing.EAST;
}
else if (world.getBlockState(portalPos.north()).getBlock() == Blocks.PORTAL ||
world.getBlockState(portalPos.south()).getBlock() == Blocks.PORTAL)
{
return EnumFacing.SOUTH;
}
return EnumFacing.NORTH;
}
public static EnumFacing intToFacing(int id) {
switch(id) {
case 1:
return EnumFacing.NORTH;
case 2:
return EnumFacing.EAST;
case 3:
return EnumFacing.SOUTH;
case 4:
return EnumFacing.WEST;
default:
return EnumFacing.NORTH;
}
}
public static int getRailHeightOffset(NetworkRail<MCPos> rail, EnumFacing dir){
switch(((MCNetworkRail)rail).getCurDir()){
case ASCENDING_EAST:
return dir == EnumFacing.EAST ? 1 : (dir == EnumFacing.WEST ? -1 : 0);
case ASCENDING_NORTH:
return dir == EnumFacing.NORTH ? 1 : (dir == EnumFacing.SOUTH ? -1 : 0);
case ASCENDING_SOUTH:
return dir == EnumFacing.SOUTH ? 1 : (dir == EnumFacing.NORTH ? -1 : 0);
case ASCENDING_WEST:
return dir == EnumFacing.WEST ? 1 : (dir == EnumFacing.EAST ? -1 : 0);
default:
return 0;
}
}
public boolean generate(World worldIn, Random rand, BlockPos position) {
int num = rand.nextInt(5);
EnumFacing orientation;
if (num == 0) {
orientation = EnumFacing.EAST;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X);
} else if (num == 1) {
orientation = EnumFacing.WEST;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X);
} else if (num == 1) {
orientation = EnumFacing.SOUTH;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Z);
} else {
orientation = EnumFacing.NORTH;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Z);
}
int i = rand.nextInt(2) + this.minTreeLength;
boolean flag = true;
if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
int k = 1;
if (j == position.getY()) {
k = 0;
}
if (j >= position.getY() + 1 + i - 2) {
k = 2;
}
BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
if (j >= 0 && j < worldIn.getHeight()) {
if (!this.isReplaceable(worldIn, mutablePos.setPos(l, j, i1))) {
flag = false;
}
} else {
flag = false;
}
}
}
}
if (!flag) {
return false;
} else {
IBlockState state = worldIn.getBlockState(position.down());
if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
state.getBlock().onPlantGrow(state, worldIn, position.down(), position);
for (int j3 = 0; j3 < i; ++j3) {
BlockPos offsetPos = position.offset(orientation, j3);
state = worldIn.getBlockState(offsetPos);
if (state.getBlock().isAir(state, worldIn, offsetPos) || state.getBlock().isLeaves(state, worldIn, offsetPos) || state.getMaterial() == Material.VINE) {
this.setBlockAndNotifyAdequately(worldIn, position.offset(orientation, j3), this.stateWood);
}
}
return true;
} else {
return false;
}
}
} else {
return false;
}
}
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn)
{
EnumFacing face = state.getValue(FACING);
boolean open = state.getValue(OPEN);
if (state.getValue(HALF) == EnumChamberHalf.UPPER)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, top);
if (!open || face != EnumFacing.SOUTH)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, south);
}
if (!open || face != EnumFacing.NORTH)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, north);
}
if (!open || face != EnumFacing.EAST)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, east);
}
if (!open || face != EnumFacing.WEST)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, west);
}
}
else
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, bottom);
if (!open || face != EnumFacing.SOUTH)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, south);
}
if (!open || face != EnumFacing.NORTH)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, north);
}
if (!open || face != EnumFacing.EAST)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, east);
}
if (!open || face != EnumFacing.WEST)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, west);
}
}
}
public static void drawFace(AxisAlignedBB aabb, float[] color, EnumFacing facing)
{
//TODO: Add UV coords for other faces
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer buffer = tessellator.getBuffer();
if(facing == EnumFacing.UP)
{
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
buffer.pos(aabb.minX, aabb.maxY, aabb.maxZ).tex(0, 1).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).tex(0, 0).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.minZ).tex(1, 0).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).tex(1, 1).color(color[0], color[1], color[2], color[3]).endVertex();
tessellator.draw();
}
else if(facing == EnumFacing.DOWN)
{
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
tessellator.draw();
}
else if(facing == EnumFacing.WEST)
{
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
tessellator.draw();
}
else if(facing == EnumFacing.EAST)
{
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(aabb.maxX, aabb.minY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
tessellator.draw();
}
else if(facing == EnumFacing.NORTH)
{
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(aabb.minX, aabb.minY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.minY, aabb.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
tessellator.draw();
}
else if(facing == EnumFacing.SOUTH)
{
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(aabb.maxX, aabb.minY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.minX, aabb.maxY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
buffer.pos(aabb.minX, aabb.minY, aabb.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
tessellator.draw();
}
}
private EnumFacing calculateFaceForPlacement(final BlockPos structurePosition,
final BlockPos blockPosition) {
final BiFunction<Integer, String, Integer> throwingClamp = (number, axis) -> {
if (number < -1 || number > 1)
throw new IllegalArgumentException(
String.format("Difference in %s is illegal, " +
"positions are too far apart.", axis));
return number;
};
final int diffX = throwingClamp.apply(
structurePosition.getX() - blockPosition.getX(), "x-axis");
switch (diffX) {
case 1:
return EnumFacing.WEST;
case -1:
return EnumFacing.EAST;
default:
break;
}
final int diffY = throwingClamp.apply(
structurePosition.getY() - blockPosition.getY(), "y-axis");
switch (diffY) {
case 1:
return EnumFacing.DOWN;
case -1:
return EnumFacing.UP;
default:
break;
}
final int diffZ = throwingClamp.apply(
structurePosition.getZ() - blockPosition.getZ(), "z-axis");
switch (diffZ) {
case 1:
return EnumFacing.NORTH;
case -1:
return EnumFacing.SOUTH;
default:
break;
}
return null;
}
public boolean generate(World worldIn, Random rand, BlockPos position) {
int num = rand.nextInt(5);
EnumFacing orientation;
if (num == 0) {
orientation = EnumFacing.EAST;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X);
} else if (num == 1) {
orientation = EnumFacing.WEST;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X);
} else if (num == 1) {
orientation = EnumFacing.SOUTH;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Z);
} else {
orientation = EnumFacing.NORTH;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Z);
}
int i = rand.nextInt(2) + this.minTreeLength;
boolean flag = true;
if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
int k = 1;
if (j == position.getY()) {
k = 0;
}
if (j >= position.getY() + 1 + i - 2) {
k = 2;
}
BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
if (j >= 0 && j < worldIn.getHeight()) {
if (!this.isReplaceable(worldIn, mutablePos.setPos(l, j, i1))) {
flag = false;
}
} else {
flag = false;
}
}
}
}
if (!flag) {
return false;
} else {
IBlockState state = worldIn.getBlockState(position.down());
if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
state.getBlock().onPlantGrow(state, worldIn, position.down(), position);
for (int j3 = 0; j3 < i; ++j3) {
BlockPos offsetPos = position.offset(orientation, j3);
state = worldIn.getBlockState(offsetPos);
if (state.getBlock().isAir(state, worldIn, offsetPos) || state.getBlock().isLeaves(state, worldIn, offsetPos) || state.getMaterial() == Material.VINE) {
this.setBlockAndNotifyAdequately(worldIn, position.offset(orientation, j3), this.stateWood);
}
}
return true;
} else {
return false;
}
}
} else {
return false;
}
}