Java Code Examples for net.minecraft.util.EnumFacing#getDirectionVec()

The following examples show how to use net.minecraft.util.EnumFacing#getDirectionVec() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockAntCoveredCake.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: ShapeGen.java    From pycode-minecraft with MIT License 5 votes vote down vote up
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);
        }
    }
}
 
Example 3
Source File: ShapeGen.java    From pycode-minecraft with MIT License 5 votes vote down vote up
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);
        }
    }
}
 
Example 4
Source File: GeometryUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
/**
 * 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()));

}
 
Example 5
Source File: GeometryUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 6
Source File: BlockUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
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;
}
 
Example 7
Source File: LightTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
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());
                }
            }
        }
    }
 
Example 8
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
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());
                }
            }
        }
    }