下面列出了net.minecraft.util.EnumFacing#getDirectionVec ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns a velocity vector for an ant particle that will spawn on the given face
* @param face The face of the block that the particle spawns on
* @param rand An RNG, generally the world's rand
* @param vScale The factor to scale the velocity by (if vScale = 1D, velocity values will be between -0.5D and 0.5D)
* @return A vec3D containing the (x,y,z) initial velocities of an ant particle
*/
public static Vec3d getParticleInitVelocityForFace(EnumFacing face, Random rand, double vScale)
{
Vec3i faceVec = face.getDirectionVec();
return new Vec3d(
faceVec.getX() != 0 ? 0D : (rand.nextDouble() - 0.5D) * vScale,
faceVec.getY() != 0 ? 0D : (rand.nextDouble() - 0.5D) * vScale,
faceVec.getZ() != 0 ? 0D : (rand.nextDouble() - 0.5D) * vScale);
}
public static void floor(World world, int width, int depth, IBlockState block_state, BlockPos pos, EnumFacing facing) {
Vec3i front = facing.getDirectionVec();
Vec3i side = facing.rotateY().getDirectionVec();
for (int j = 0; j < width; j++) {
BlockPos set = pos.add(side.getX() * j, 0, side.getZ() * j);
for (int i = 0; i < depth; i++) {
world.setBlockState(set, block_state);
set = set.add(front);
}
}
}
public static void wall(World world, int depth, int height, IBlockState block_state, BlockPos pos, EnumFacing facing) {
Vec3i front = facing.getDirectionVec();
for (int j = 0; j < height; j++) {
BlockPos set = pos.add(0, j, 0);
for (int i = 0; i < depth; i++) {
world.setBlockState(set, block_state);
set = set.add(front);
}
}
}
/**
* Makes a link of blocks in a shape
*/
public static void makeLine(int startX, int startY, int startZ, EnumFacing direction, int length, IShapeable shapeable) {
if (length < 0) return;
final Vec3i v = direction.getDirectionVec();
for (int offset = 0; offset <= length; offset++)
// Create a line in the direction of direction, length in size
shapeable.setBlock(
startX + (offset * v.getX()),
startY + (offset * v.getY()),
startZ + (offset * v.getZ()));
}
/**
* Makes a flat plane along two directions
*/
public static void makePlane(int startX, int startY, int startZ, int width, int height, EnumFacing right, EnumFacing up, IShapeable shapeable) {
if (width < 0 || height < 0) return;
int lineOffsetX, lineOffsetY, lineOffsetZ;
// We offset each line by up, and then apply it right
final Vec3i v = up.getDirectionVec();
for (int h = 0; h <= height; h++) {
lineOffsetX = startX + (h * v.getX());
lineOffsetY = startY + (h * v.getY());
lineOffsetZ = startZ + (h * v.getZ());
makeLine(lineOffsetX, lineOffsetY, lineOffsetZ, right, width, shapeable);
}
}
public static EntityItem ejectItemInDirection(World world, double x, double y, double z, EnumFacing direction, @Nonnull ItemStack stack) {
EntityItem item = BlockUtils.dropItemStackInWorld(world, x, y, z, stack);
final Vec3i v = direction.getDirectionVec();
item.motionX = v.getX() / 5F;
item.motionY = v.getY() / 5F;
item.motionZ = v.getZ() / 5F;
return item;
}
public void doPowerUsageProcess(int bulbTypeId) {
// Get modifier for current bulb
int bulbEnergyModifier = LightHelper.getEnergyUsageModifierForBulbById(bulbTypeId);
// Calculate energy required
int energyRequired = EmergingTechnologyConfig.HYDROPONICS_MODULE.GROWLIGHT.lightEnergyBaseUsage
* bulbEnergyModifier;
if (this.energy >= energyRequired) {
// If enough energy, extract it
this.energyHandler.extractEnergy(energyRequired, false);
} else {
// Otherwise empty all the power from the light.
this.energyHandler.extractEnergy(this.energy, false);
}
int transferEnergy = this.getEnergy();
// If enough energy to transfer...
if (this.energy >= transferEnergy) {
// Get the direction this grow light is facing
EnumFacing facing = this.world.getBlockState(this.pos).getValue(Light.FACING);
// Grab the vector
Vec3i vector = facing.getDirectionVec();
// Get neighbour based on facing vector
TileEntity neighbour = this.world.getTileEntity(this.pos.add(vector));
// Is neighbour a grow light?
if (neighbour instanceof LightTileEntity) {
LightTileEntity targetTileEntity = (LightTileEntity) neighbour;
// Send energy to the neighbour and get amount accepted
int accepted = targetTileEntity.energyHandler.receiveEnergy(transferEnergy, false);
if (accepted > 0) {
// Drain self from amount
this.energyHandler.extractEnergy(accepted, true);
this.setEnergy(this.energyHandler.getEnergyStored());
}
}
}
}
public void doWaterUsageProcess(boolean growSucceeded) {
if (this.getFluid() == null)
return;
int waterFluidUse = HydroponicHelper.getFluidUseForMedium(this.getGrowthMediumId());
int fluidUsage = growSucceeded ? waterFluidUse : 1;
// Drain water
this.fluidHandler
.drain(EmergingTechnologyConfig.HYDROPONICS_MODULE.GROWBED.growBedWaterUsePerCycle * fluidUsage, true);
// If enough water to transfer...
if (this.water >= EmergingTechnologyConfig.HYDROPONICS_MODULE.GROWBED.growBedWaterTransferRate) {
// Get the direction this grow bed is facing
EnumFacing facing = this.world.getBlockState(this.pos).getValue(Hydroponic.FACING);
// Grab the vector
Vec3i vector = facing.getDirectionVec();
// Get neighbour based on facing vector
TileEntity neighbour = this.world.getTileEntity(this.pos.add(vector));
// Is neighbour a grow bed?
if (neighbour instanceof HydroponicTileEntity) {
HydroponicTileEntity targetTileEntity = (HydroponicTileEntity) neighbour;
FluidStack fluidStack = this.getFluidStack();
if (fluidStack == null) {
return;
}
if (fluidStack.getFluid() == null) {
return;
}
// Fill the neighbour and get amount filled
int filled = targetTileEntity.fluidHandler.fill(new FluidStack(this.fluidHandler.getFluid().getFluid(),
EmergingTechnologyConfig.HYDROPONICS_MODULE.GROWBED.growBedWaterTransferRate), true);
if (filled > 0) {
// Drain self from amount
this.fluidHandler.drain(filled, true);
this.setWater(this.fluidHandler.getFluidAmount());
}
}
}
}