下面列出了net.minecraft.util.EnumFacing#WEST 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static EnumFacing getDirection(EnumRailDirection railDir, boolean forward){
switch(railDir){
case EAST_WEST:
return forward ? EnumFacing.EAST : EnumFacing.WEST;
case ASCENDING_EAST:
return forward ? EnumFacing.EAST : EnumFacing.WEST;
case ASCENDING_WEST:
return forward ? EnumFacing.WEST : EnumFacing.EAST;
case NORTH_SOUTH:
return forward ? EnumFacing.NORTH : EnumFacing.SOUTH;
case ASCENDING_NORTH:
return forward ? EnumFacing.NORTH : EnumFacing.SOUTH;
case ASCENDING_SOUTH:
return forward ? EnumFacing.SOUTH : EnumFacing.NORTH;
default:
throw new IllegalStateException("Invalid rail dir for teleport track: " + railDir);
}
}
public EnumFacing toForgeDirection() {
switch (this) {
case XNeg:
return EnumFacing.WEST;
case XPos:
return EnumFacing.EAST;
case YNeg:
return EnumFacing.DOWN;
case YPos:
return EnumFacing.UP;
case ZNeg:
return EnumFacing.NORTH;
case ZPos:
return EnumFacing.SOUTH;
default:
throw new IllegalArgumentException(toString());
}
}
private void placeBlock(BlockPos pos) {
final Minecraft mc = Minecraft.getMinecraft();
BlockPos[][] posit = {{pos.add(0, 0, 1), pos.add(0, 0, -1)}, {pos.add(0, 1, 0), pos.add(0, -1, 0)}, {pos.add(1, 0, 0),pos.add(-1, 0, 0)}};
EnumFacing[][] facing = {{EnumFacing.NORTH, EnumFacing.SOUTH}, {EnumFacing.DOWN, EnumFacing.UP}, {EnumFacing.WEST, EnumFacing.EAST}}; // Facing reversed as blocks are placed while facing in the opposite direction
for (int i=0; i<6; i++) {
final Block block = mc.world.getBlockState(posit[i/2][i%2]).getBlock();
final boolean activated = block.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
if (block != null && block != Blocks.AIR && !(block instanceof BlockLiquid)) {
if (activated)
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
if (mc.playerController.processRightClickBlock(mc.player, mc.world, posit[i/2][i%2], facing[i/2][i%2], new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL)
mc.player.swingArm(EnumHand.MAIN_HAND);
if (activated)
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
}
}
}
@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 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));
}
}
private 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 = (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);
}
}
private 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 = (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 PortalEnumType getPortalState(EnumFacing facing)
{
if(facing == EnumFacing.NORTH)
return northPortalState;
else if(facing == EnumFacing.SOUTH)
return southPortalState;
else if(facing == EnumFacing.EAST)
return eastPortalState;
else if(facing == EnumFacing.WEST)
return westPortalState;
return PortalEnumType.Disabled;
}
private 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 = (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 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 static void addBlockHitEffects(World world, Cuboid6 bounds, EnumFacing side, TextureAtlasSprite icon, int spriteColor, ParticleManager particleManager) {
float border = 0.1F;
Vector3 diff = bounds.max.copy().subtract(bounds.min).add(-2 * border);
diff.x *= world.rand.nextDouble();
diff.y *= world.rand.nextDouble();
diff.z *= world.rand.nextDouble();
Vector3 pos = diff.add(bounds.min).add(border);
float red = (spriteColor >> 16 & 255) / 255.0F;
float green = (spriteColor >> 8 & 255) / 255.0F;
float blue = (spriteColor & 255) / 255.0F;
if (side == EnumFacing.DOWN) {
diff.y = bounds.min.y - border;
}
if (side == EnumFacing.UP) {
diff.y = bounds.max.y + border;
}
if (side == EnumFacing.NORTH) {
diff.z = bounds.min.z - border;
}
if (side == EnumFacing.SOUTH) {
diff.z = bounds.max.z + border;
}
if (side == EnumFacing.WEST) {
diff.x = bounds.min.x - border;
}
if (side == EnumFacing.EAST) {
diff.x = bounds.max.x + border;
}
DigIconParticle digIconParticle = new DigIconParticle(world, pos.x, pos.y, pos.z, 0, 0, 0, icon);
digIconParticle.multiplyVelocity(0.2F);
digIconParticle.multipleParticleScaleBy(0.6F);
digIconParticle.setRBGColorF(red, green, blue);
particleManager.addEffect(digIconParticle);
}
public static EnumFacing toFacing(EnumHeading heading){
if(heading == null) return null;
switch(heading){
case NORTH:
return EnumFacing.NORTH;
case SOUTH:
return EnumFacing.SOUTH;
case WEST:
return EnumFacing.WEST;
case EAST:
return EnumFacing.EAST;
default:
throw new IllegalArgumentException();
}
}
@Override
public void update()
{
IBlockState master = worldObj.getBlockState(pos.add(0, -10, 0));
boolean powered = worldObj.isBlockPowered(pos.add(1, -10, 0))
|| worldObj.isBlockPowered(pos.add(-1, -10, 0))
|| worldObj.isBlockPowered(pos.add(0, -10, 1))
|| worldObj.isBlockPowered(pos.add(0, -10, -1));
boolean working = !powered && master.getBlock() == CyberwareContent.radioPost && master.getValue(BlockBeaconPost.TRANSFORMED) == 2;
if (!wasWorking && working)
{
this.enable();
}
if (wasWorking && !working)
{
disable();
}
wasWorking = working;
if (worldObj.isRemote && working)
{
count = (count + 1) % 20;
if (count == 0)
{
IBlockState state = worldObj.getBlockState(pos);
if (state.getBlock() == CyberwareContent.radioLarge)
{
boolean ns = state.getValue(BlockBeaconLarge.FACING) == EnumFacing.EAST || state.getValue(BlockBeaconLarge.FACING) == EnumFacing.WEST;
float dist = .5F;
float speedMod = .2F;
int degrees = 45;
for (int i = 0; i < 18; i++)
{
float sin = (float) Math.sin(Math.toRadians(degrees));
float cos = (float) Math.cos(Math.toRadians(degrees));
float xOffset = dist * sin;
float yOffset = .2F + dist * cos;
float xSpeed = speedMod * sin;
float ySpeed = speedMod * cos;
worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL,
pos.getX() + .5F + (ns ? xOffset : 0),
pos.getY() + .5F + yOffset,
pos.getZ() + .5F + (ns ? 0 : xOffset),
ns ? xSpeed : 0,
ySpeed,
ns ? 0 : xSpeed,
new int[] {255, 255, 255});
worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL,
pos.getX() + .5F - (ns ? xOffset : 0),
pos.getY() + .5F + yOffset,
pos.getZ() + .5F - (ns ? 0 : xOffset),
ns ? -xSpeed : 0,
ySpeed,
ns ? 0 : -xSpeed,
new int[] {255, 255, 255});
degrees += 5;
}
}
}
}
}
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;
}
}
@Override
public void update() {
//Freaky jenky crap to make sure the multiblock loads on chunkload etc
if(timeAlive == 0 && !world.isRemote) {
if(isComplete())
canRender = completeStructure = completeStructure(world.getBlockState(pos));
timeAlive = 0x1;
checkCanRun();
}
//TODO: drain energy
if(!this.world.isRemote) {
tickSinceLastOperation++;
if(!isAllowedToRun()) {
laserSat.deactivateLaser();
this.setFinished(true);
this.setRunning(false);
}
else
if(hasPowerForOperation() && isReadyForOperation() && laserSat.isAlive() && !laserSat.getJammed()) {
laserSat.performOperation();
batteries.setEnergyStored(batteries.getEnergyStored() - POWER_PER_OPERATION);
tickSinceLastOperation = 0;
}
}
if(laserSat.isFinished()) {
setRunning(false);
laserSat.deactivateLaser();
if(!laserSat.getJammed()) {
if(mode == MODE.SINGLE)
finished = true;
if(this.world.getStrongPower(getPos()) != 0) {
if(mode == MODE.LINE_X) {
this.laserX += 3;
}
else if(mode == MODE.LINE_Z) {
this.laserZ += 3;
}
else if(mode == MODE.SPIRAL) {
numSteps++;
if(radius < numSteps) {
numSteps = 0;
if(prevDir == EnumFacing.NORTH)
prevDir = EnumFacing.EAST;
else if(prevDir == EnumFacing.EAST){
prevDir = EnumFacing.SOUTH;
radius++;
}
else if(prevDir == EnumFacing.SOUTH)
prevDir = EnumFacing.WEST;
else {
prevDir = EnumFacing.NORTH;
radius++;
}
}
this.laserX += 3*prevDir.getFrontOffsetX();
this.laserZ += 3*prevDir.getFrontOffsetZ();
}
}
//TODO: unneeded?
checkCanRun();
}
}
}
public WrapperEnumFacing getWEST() {
return new WrapperEnumFacing(EnumFacing.WEST);
}