Java Code Examples for net.minecraft.util.BlockPos#getX()

The following examples show how to use net.minecraft.util.BlockPos#getX() . 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: StructureBuilder.java    From mobycraft with Apache License 2.0 6 votes vote down vote up
public static void room(World world, BlockPos start, BlockPos end,
		Block material) {
	fill(world, start, end, material);

	int airStartX = -(start.getX() - end.getX())
			/ Math.abs(start.getX() - end.getX());
	int airEndX = -(end.getX() - start.getX())
			/ Math.abs(end.getX() - start.getX());
	int airStartY = -(start.getY() - end.getY())
			/ Math.abs(start.getY() - end.getY());
	int airEndY = -(end.getY() - start.getY())
			/ Math.abs(end.getY() - start.getY());
	int airStartZ = -(start.getZ() - end.getZ())
			/ Math.abs(start.getZ() - end.getZ());
	int airEndZ = -(end.getZ() - start.getZ())
			/ Math.abs(end.getZ() - start.getZ());

	fill(world, start.add(airStartX, airStartY, airStartZ),
			end.add(airEndX, airEndY, airEndZ), Blocks.air);
}
 
Example 2
Source File: BuildContainerCommands.java    From mobycraft with Apache License 2.0 6 votes vote down vote up
public BlockPos getAverageContainerPosition() {
	double x = 0;
	double y = 0;
	int z = configurationCommands.getStartPos().getZ();

	for (BoxContainer container : boxContainers) {
		BlockPos containerPos = container.getPosition();
		x += containerPos.getX();
		y += containerPos.getY();
	}

	x /= boxContainers.size();
	y /= boxContainers.size();

	return new BlockPos(Math.floor(x), Math.floor(y), z);
}
 
Example 3
Source File: FWBlock.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
	Block blockInstance;

	// see onBlockHarvested for why the harvestedBlocks hack exists
	// this method will be called exactly once after destroying the block
	BlockPosition position = new BlockPosition((World) world, pos.getX(), pos.getY(), pos.getZ());
	if (harvestedBlocks.containsKey(position)) {
		blockInstance = harvestedBlocks.remove(position);
	} else {
		blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos));
	}

	Block.DropEvent event = new Block.DropEvent(blockInstance);
	blockInstance.events.publish(event);

	return event.drops
		.stream()
		.map(ItemConverter.instance()::toNative)
		.collect(Collectors.toCollection(ArrayList::new));
}
 
Example 4
Source File: StructureBuilder.java    From mobycraft with Apache License 2.0 5 votes vote down vote up
private static void fill(World world, BlockPos start, BlockPos end,
		Block material) {
	int startX = start.getX();
	int endX = end.getX();
	int startY = start.getY();
	int endY = end.getY();
	int startZ = start.getZ();
	int endZ = end.getZ();

	int[] intSwitchArray = new int[2];

	if (endX < startX) {
		intSwitchArray = switchNumbers(startX, endX);
		startX = intSwitchArray[0];
		endX = intSwitchArray[1];
	}

	if (endY < startY) {
		intSwitchArray = switchNumbers(startY, endY);
		startY = intSwitchArray[0];
		endY = intSwitchArray[1];
	}

	if (endZ < startZ) {
		intSwitchArray = switchNumbers(startZ, endZ);
		startZ = intSwitchArray[0];
		endZ = intSwitchArray[1];
	}

	for (int x = startX; x < endX + 1; x++) {
		for (int y = startY; y < endY + 1; y++) {
			for (int z = startZ; z < endZ + 1; z++) {
				world.setBlockState(new BlockPos(x, y, z),
						material.getDefaultState());
			}
		}
	}
}
 
Example 5
Source File: BuildContainerCommands.java    From mobycraft with Apache License 2.0 5 votes vote down vote up
public void refreshMinMaxPositions() {
	BlockPos startPos = configurationCommands.getStartPos();

	int minX = startPos.getX() - 2;
	int minY = startPos.getY();
	int minZ = startPos.getZ() - 10;
	int maxX;
	int maxY;
	int maxZ = startPos.getZ() + 10;

	int containerHeight = 0;

	int size = boxContainers.size();
	if (size < 10) {
		containerHeight = size;
	} else {
		containerHeight = 10;
	}

	maxY = startPos.getY() - 1 + (6 * containerHeight);

	int containerLength = ((size - (size % 10)) / 10) + 1;
	maxX = (minX - 1) + (containerLength * 6);

	minPos = new BlockPos(minX, minY, minZ);
	maxPos = new BlockPos(maxX, maxY, maxZ);
}
 
Example 6
Source File: StaticForwarder.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void chunkSetBlockEvent(Chunk chunk, BlockPos pos, IBlockState oldBlockState, IBlockState newBlockState) {
	nova.core.world.World world = WorldConverter.instance().toNova(chunk.getWorld());
	Vector3D position = new Vector3D((chunk.xPosition << 4) + pos.getX(), pos.getY(), (chunk.zPosition << 4) + pos.getZ());
	Block oldBlockInstance;
	Block newBlockInstance;

	if (oldBlockState.getBlock() instanceof FWBlock) {
		oldBlockInstance = ((FWBlock) oldBlockState.getBlock()).getFactory().build();
		oldBlockInstance.components.add(new MCBlockTransform(oldBlockInstance, world, position));
	} else {
		oldBlockInstance = new BWBlock(oldBlockState.getBlock(), world, position);
		Game.blocks().get(Objects.toString(net.minecraft.block.Block.blockRegistry.getNameForObject(oldBlockState.getBlock())))
			.ifPresent(blockFactory -> oldBlockInstance.components.getOrAdd(new FactoryProvider(blockFactory)));
	}

	if (newBlockState.getBlock() instanceof FWBlock) {
		newBlockInstance = ((FWBlock) newBlockState.getBlock()).getFactory().build();
		oldBlockInstance.components.add(new MCBlockTransform(oldBlockInstance, world, position));
	} else {
		newBlockInstance = new BWBlock(newBlockState.getBlock());
		Game.blocks().get(Objects.toString(net.minecraft.block.Block.blockRegistry.getNameForObject(newBlockState.getBlock())))
			.ifPresent(blockFactory -> newBlockInstance.components.getOrAdd(new FactoryProvider(blockFactory)));
	}

	// Publish the event
	Game.events().publish(new BlockEvent.Change(world, position, oldBlockInstance, newBlockInstance));
}
 
Example 7
Source File: RenderUtils.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
public static void drawBlockBox(final BlockPos blockPos, final Color color, final boolean outline) {
    final RenderManager renderManager = mc.getRenderManager();
    final Timer timer = mc.timer;

    final double x = blockPos.getX() - renderManager.renderPosX;
    final double y = blockPos.getY() - renderManager.renderPosY;
    final double z = blockPos.getZ() - renderManager.renderPosZ;

    AxisAlignedBB axisAlignedBB = new AxisAlignedBB(x, y, z, x + 1.0, y + 1.0, z + 1.0);
    final Block block = BlockUtils.getBlock(blockPos);

    if (block != null) {
        final EntityPlayer player = mc.thePlayer;

        final double posX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) timer.renderPartialTicks;
        final double posY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) timer.renderPartialTicks;
        final double posZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) timer.renderPartialTicks;
        axisAlignedBB = block.getSelectedBoundingBox(mc.theWorld, blockPos)
                .expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D)
                .offset(-posX, -posY, -posZ);
    }

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    enableGlCap(GL_BLEND);
    disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST);
    glDepthMask(false);

    glColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() != 255 ? color.getAlpha() : outline ? 26 : 35);
    drawFilledBox(axisAlignedBB);

    if (outline) {
        glLineWidth(1F);
        enableGlCap(GL_LINE_SMOOTH);
        glColor(color);

        drawSelectionBoundingBox(axisAlignedBB);
    }

    GlStateManager.resetColor();
    glDepthMask(true);
    resetCaps();
}
 
Example 8
Source File: StructureBuilder.java    From mobycraft with Apache License 2.0 4 votes vote down vote up
public static void replace(World world, BlockPos start, BlockPos end,
		Block blockToReplace, Block blockToReplaceWith) {
	int startX = start.getX();
	int endX = end.getX();
	int startY = start.getY();
	int endY = end.getY();
	int startZ = start.getZ();
	int endZ = end.getZ();

	int[] intSwitchArray = new int[2];

	if (endX < startX) {
		intSwitchArray = switchNumbers(startX, endX);
		startX = intSwitchArray[0];
		endX = intSwitchArray[1];
	}

	if (endY < startY) {
		intSwitchArray = switchNumbers(startY, endY);
		startY = intSwitchArray[0];
		endY = intSwitchArray[1];
	}

	if (endZ < startZ) {
		intSwitchArray = switchNumbers(startZ, endZ);
		startZ = intSwitchArray[0];
		endZ = intSwitchArray[1];
	}

	for (int x = startX; x < endX + 1; x++) {
		for (int y = startY; y < endY + 1; y++) {
			for (int z = startZ; z < endZ + 1; z++) {
				if (world.getBlockState(new BlockPos(x, y, z)) == blockToReplace
						.getDefaultState()) {
					world.setBlockState(new BlockPos(x, y, z),
							blockToReplaceWith.getDefaultState());

				}
			}
		}
	}
}
 
Example 9
Source File: EntityChaosMonkey.java    From mobycraft with Apache License 2.0 4 votes vote down vote up
/**
 * Called to update the entity's position/logic.
 */
public void onUpdate() {
	super.onUpdate();
	this.motionY *= 0.6000000238418579D;

	if (chaosCountdown > 0) {
		chaosCountdown--;
		return;
	}

	BlockPos pos = this.getPosition();
	BlockPos minPos = buildCommands.getMinPos();
	BlockPos maxPos = buildCommands.getMaxPos();

	int x = pos.getX();
	int y = pos.getY();
	int z = pos.getZ();
	int minX = minPos.getX();
	int minY = minPos.getY();
	int minZ = minPos.getZ();
	int maxX = maxPos.getX();
	int maxY = maxPos.getY();
	int maxZ = maxPos.getZ();

	if (x < minX || y < minY || z < minZ || x > maxX || y > maxY
			|| z > maxZ) {
		this.setLocationAndAngles(Utils.negativeNextInt(minX, maxX),
				Utils.negativeNextInt(minY, maxY), minZ + 8, 0, 0);
	}

	World world = this.worldObj;
	if (world.getTileEntity(this.getPosition()) == null) {
		return;
	}

	TileEntity entity = world.getTileEntity(this.getPosition());
	if (!(entity instanceof TileEntitySign)) {
		return;
	}

	TileEntitySign sign = (TileEntitySign) entity;

	if (!sign.signText[0].getUnformattedText().contains("Name:")) {
		return;
	}

	String name = sign.signText[1].getUnformattedText().concat(
			sign.signText[2].getUnformattedText().concat(
					sign.signText[3].getUnformattedText()));

	if (listCommands.getWithName(name) == null) {
		return;
	}

	Container container = listCommands.getWithName(name);
	lifecycleCommands.removeContainer(container.getId());
	if (!world.isRemote) {
		sendErrorMessage("Oh no! The Chaos Monkey has destroyed the container \""
				+ name + "\"!");
	}

	if (sender instanceof EntityPlayer) {
		((EntityPlayer) sender).inventory
				.addItemStackToInventory(new ItemStack(
						Mobycraft.container_essence, new Random().nextInt(3)));
	}

	chaosCountdown = maxChaosCountdown;

	buildCommands.updateContainers(false);
}
 
Example 10
Source File: FWItem.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
	return ItemWrapperMethods.super.onItemUse(itemStack, player, world, pos.getX(), pos.getY(), pos.getZ(), side.ordinal(), hitX, hitY, hitZ);
}
 
Example 11
Source File: FWItemBlock.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
	return ItemWrapperMethods.super.onItemUse(itemStack, player, world, pos.getX(), pos.getY(), pos.getZ(), side.ordinal(), hitX, hitY, hitZ);
}
 
Example 12
Source File: ForgePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FaweLocation getLocation() {
    World world = parent.worldObj;
    BlockPos pos = parent.getPosition();
    return new FaweLocation(Fawe.<FaweForge>imp().getWorldName(world), pos.getX(), pos.getY(), pos.getZ());
}
 
Example 13
Source File: BlockCoord.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public BlockCoord(BlockPos pos) {
    this(pos.getX(), pos.getY(), pos.getZ());
}
 
Example 14
Source File: Vector3.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Vector3(BlockPos pos) {
    x = pos.getX();
    y = pos.getY();
    z = pos.getZ();
}
 
Example 15
Source File: RenderUtils.java    From LiquidBounce with GNU General Public License v3.0 2 votes vote down vote up
public static void draw2D(final BlockPos blockPos, final int color, final int backgroundColor) {
    final RenderManager renderManager = mc.getRenderManager();

    final double posX = (blockPos.getX() + 0.5) - renderManager.renderPosX;
    final double posY = blockPos.getY() - renderManager.renderPosY;
    final double posZ = (blockPos.getZ() + 0.5) - renderManager.renderPosZ;

    GlStateManager.pushMatrix();
    GlStateManager.translate(posX, posY, posZ);
    GlStateManager.rotate(-mc.getRenderManager().playerViewY, 0F, 1F, 0F);
    GlStateManager.scale(-0.1D, -0.1D, 0.1D);

    glDisable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glDisable(GL_TEXTURE_2D);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    GlStateManager.depthMask(true);

    glColor(color);

    glCallList(DISPLAY_LISTS_2D[0]);

    glColor(backgroundColor);

    glCallList(DISPLAY_LISTS_2D[1]);

    GlStateManager.translate(0, 9, 0);

    glColor(color);

    glCallList(DISPLAY_LISTS_2D[2]);

    glColor(backgroundColor);

    glCallList(DISPLAY_LISTS_2D[3]);

    // Stop render
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    GlStateManager.popMatrix();
}