Jump to content

[1.7.10] Trying to get the block the player is looking at


HappyKiller1O1

Recommended Posts

So, what I need to do is get the block the player is looking at. Now, I have already done that but with one problem... It runs it on the server! See, I use:

 

MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(5, 1.0F);

 

This goes into my item classes "onItemRightClick" method. Considering this is a server method, it crashes the server when attempting to spawn the structure I set for it. I tried "player.rayTrace" but, it only gets the block directly below the player. How would I make this work on a server? Here's some of my class code:

 

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
	int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

	MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(5, 1.0F);

	if(!world.isRemote) {

		if(direction == 2) {
			spawnShopNorth(world, world.rand, mop.blockX, mop.blockY, mop.blockZ);
			stack.stackSize--;
		}else if(direction == 3) {
			spawnShopEast(world, world.rand, mop.blockX, mop.blockY, mop.blockZ);
			stack.stackSize--;
		}else if(direction == 0) {
			spawnShopSouth(world, world.rand, mop.blockX, mop.blockY, mop.blockZ);
			stack.stackSize--;	
		}else {
			spawnShopWest(world, world.rand, mop.blockX, mop.blockY, mop.blockZ);
			stack.stackSize--;
		}
	}else {
		//System.out.println("CLIENT SIDE");
	}

	return stack;
}

public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean flag) {
	list.add((EnumChatFormatting.GREEN + "Right click to spawn a small"));
	list.add((EnumChatFormatting.GREEN + "structure containing the shop."));
	list.add((""));
	list.add((EnumChatFormatting.RED + "WARNING: Structure spawns in a"));
	list.add((EnumChatFormatting.RED + "3 x 5 area. Make sure to clear one!"));
}

public boolean spawnShopNorth(World world, Random random, int x, int y, int z) {
	System.out.println("Shop method called.");

	Block shop = CrewMod.shopBlock;
	Block aLog = Blocks.log2;
	Block doLog = Blocks.log2;
	Block fence = Blocks.fence;
	Block sSlab = Blocks.wooden_slab;
	Block mCWall = Blocks.cobblestone_wall;
	Block wWool = Blocks.wool;
	Block rWool = Blocks.wool;
	Block doPlank = Blocks.planks;
	Block glowstone = Blocks.glowstone;

	while(world.isAirBlock(x, y, z) && y > 2) {
		y--;
	}

	y += 1;

	/* Mid Section */
	world.setBlock(x, y, z, shop);
	world.setBlockToAir(x + 1, y, z);
	world.setBlockToAir(x - 1, y, z);
	world.setBlock(x, y, z - 1, mCWall, 1, 2);
	world.setBlock(x - 1, y, z - 1, mCWall, 1, 2);
	world.setBlock(x + 1, y, z - 1, mCWall, 1, 2);
	world.setBlock(x - 2, y, z - 1, doLog, 1, 2);
	world.setBlock(x + 2, y, z - 1, doLog, 1, 2);
	world.setBlock(x - 2, y, z, sSlab, 1, 2);
	world.setBlock(x + 2, y, z, sSlab, 1, 2);
	world.setBlock(x - 2, y, z + 1, doLog, 1, 2);
	world.setBlock(x + 2, y, z + 1, doLog, 1, 2);
	world.setBlock(x - 1, y, z + 1, mCWall, 1, 2);
	world.setBlock(x + 1, y, z + 1, mCWall, 1, 2);

	/* Floor */
	world.setBlock(x, y - 1, z, doPlank, 5, 2);
	world.setBlock(x + 1, y - 1, z, doPlank, 5, 2);
	world.setBlock(x - 1, y - 1, z, doPlank, 5, 2);
	world.setBlock(x, y - 1, z - 1, aLog, 4, 2);
	world.setBlock(x + 1, y - 1, z - 1, aLog, 4, 2);
	world.setBlock(x - 1, y - 1, z - 1, aLog, 4, 2);
	world.setBlock(x, y - 1, z + 1, aLog, 4, 2);
	world.setBlock(x + 1, y - 1, z + 1, aLog, 4, 2);
	world.setBlock(x - 1, y - 1, z + 1, aLog, 4, 2);
	world.setBlock(x - 2, y - 1, z - 1, doLog, 1, 2);
	world.setBlock(x + 2, y - 1, z - 1, doLog, 1, 2);
	world.setBlock(x - 2, y - 1, z + 1, doLog, 1, 2);
	world.setBlock(x + 2, y - 1, z + 1, doLog, 1, 2);
	world.setBlock(x + 2, y - 1, z, aLog, 8, 2);
	world.setBlock(x - 2, y - 1, z, aLog, 8, 2);

	/* Roof */
	world.setBlock(x - 2, y + 1, z - 1, fence, 0, 2);
	world.setBlock(x + 2, y + 1, z - 1, fence, 0, 2);
	world.setBlock(x - 2, y + 1, z + 1, fence, 0, 2);
	world.setBlock(x + 2, y + 1, z + 1, fence, 0, 2);
	world.setBlock(x - 2, y + 2, z - 1, fence, 0, 2);
	world.setBlock(x + 2, y + 2, z - 1, fence, 0, 2);
	world.setBlock(x - 2, y + 2, z + 1, fence, 0, 2);
	world.setBlock(x + 2, y + 2, z + 1, fence, 0, 2);
	world.setBlock(x - 2, y + 3, z - 1, rWool, 14, 2);
	world.setBlock(x + 2, y + 3, z - 1, rWool, 14, 2);
	world.setBlock(x - 2, y + 3, z + 1, rWool, 14, 2);
	world.setBlock(x + 2, y + 3, z + 1, rWool, 14, 2);
	world.setBlock(x - 2, y + 3, z, wWool, 0, 2);
	world.setBlock(x + 2, y + 3, z, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z - 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z - 1, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z + 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z + 1, wWool, 0, 2);
	world.setBlock(x, y + 3, z + 1, rWool, 14, 2);
	world.setBlock(x, y + 3, z - 1, rWool, 14, 2);
	world.setBlock(x - 1, y + 4, z, rWool, 14, 2);
	world.setBlock(x + 1, y + 4, z, rWool, 14, 2);
	world.setBlock(x, y + 4, z, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z, glowstone, 0, 2);
	world.setBlock(x + 1, y + 3, z, glowstone, 0, 2);
	world.setBlock(x, y + 3, z, glowstone, 0, 2);


	return true;
}

public boolean spawnShopSouth(World world, Random random, int x, int y, int z) {
	System.out.println("Shop method called.");

	Block shop = CrewMod.shopBlock;
	Block aLog = Blocks.log2;
	Block doLog = Blocks.log2;
	Block fence = Blocks.fence;
	Block sSlab = Blocks.wooden_slab;
	Block mCWall = Blocks.cobblestone_wall;
	Block wWool = Blocks.wool;
	Block rWool = Blocks.wool;
	Block doPlank = Blocks.planks;
	Block glowstone = Blocks.glowstone;

	while(world.isAirBlock(x, y, z) && y > 2) {
		y--;
	}

	y += 1;

	/* Mid Section */
	world.setBlock(x, y, z, shop);
	world.setBlockToAir(x + 1, y, z);
	world.setBlockToAir(x - 1, y, z);
	world.setBlock(x, y, z + 1, mCWall, 1, 2);
	world.setBlock(x - 1, y, z - 1, mCWall, 1, 2);
	world.setBlock(x + 1, y, z - 1, mCWall, 1, 2);
	world.setBlock(x - 2, y, z - 1, doLog, 1, 2);
	world.setBlock(x + 2, y, z - 1, doLog, 1, 2);
	world.setBlock(x - 2, y, z, sSlab, 1, 2);
	world.setBlock(x + 2, y, z, sSlab, 1, 2);
	world.setBlock(x - 2, y, z + 1, doLog, 1, 2);
	world.setBlock(x + 2, y, z + 1, doLog, 1, 2);
	world.setBlock(x - 1, y, z + 1, mCWall, 1, 2);
	world.setBlock(x + 1, y, z + 1, mCWall, 1, 2);

	/* Floor */
	world.setBlock(x, y - 1, z, doPlank, 5, 2);
	world.setBlock(x + 1, y - 1, z, doPlank, 5, 2);
	world.setBlock(x - 1, y - 1, z, doPlank, 5, 2);
	world.setBlock(x, y - 1, z - 1, aLog, 4, 2);
	world.setBlock(x + 1, y - 1, z - 1, aLog, 4, 2);
	world.setBlock(x - 1, y - 1, z - 1, aLog, 4, 2);
	world.setBlock(x, y - 1, z + 1, aLog, 4, 2);
	world.setBlock(x + 1, y - 1, z + 1, aLog, 4, 2);
	world.setBlock(x - 1, y - 1, z + 1, aLog, 4, 2);
	world.setBlock(x - 2, y - 1, z - 1, doLog, 1, 2);
	world.setBlock(x + 2, y - 1, z - 1, doLog, 1, 2);
	world.setBlock(x - 2, y - 1, z + 1, doLog, 1, 2);
	world.setBlock(x + 2, y - 1, z + 1, doLog, 1, 2);
	world.setBlock(x + 2, y - 1, z, aLog, 8, 2);
	world.setBlock(x - 2, y - 1, z, aLog, 8, 2);

	/* Roof */
	world.setBlock(x - 2, y + 1, z - 1, fence, 0, 2);
	world.setBlock(x + 2, y + 1, z - 1, fence, 0, 2);
	world.setBlock(x - 2, y + 1, z + 1, fence, 0, 2);
	world.setBlock(x + 2, y + 1, z + 1, fence, 0, 2);
	world.setBlock(x - 2, y + 2, z - 1, fence, 0, 2);
	world.setBlock(x + 2, y + 2, z - 1, fence, 0, 2);
	world.setBlock(x - 2, y + 2, z + 1, fence, 0, 2);
	world.setBlock(x + 2, y + 2, z + 1, fence, 0, 2);
	world.setBlock(x - 2, y + 3, z - 1, rWool, 14, 2);
	world.setBlock(x + 2, y + 3, z - 1, rWool, 14, 2);
	world.setBlock(x - 2, y + 3, z + 1, rWool, 14, 2);
	world.setBlock(x + 2, y + 3, z + 1, rWool, 14, 2);
	world.setBlock(x - 2, y + 3, z, wWool, 0, 2);
	world.setBlock(x + 2, y + 3, z, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z - 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z - 1, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z + 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z + 1, wWool, 0, 2);
	world.setBlock(x, y + 3, z + 1, rWool, 14, 2);
	world.setBlock(x, y + 3, z - 1, rWool, 14, 2);
	world.setBlock(x - 1, y + 4, z, rWool, 14, 2);
	world.setBlock(x + 1, y + 4, z, rWool, 14, 2);
	world.setBlock(x, y + 4, z, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z, glowstone, 0, 2);
	world.setBlock(x + 1, y + 3, z, glowstone, 0, 2);
	world.setBlock(x, y + 3, z, glowstone, 0, 2);

	return true;
}

public boolean spawnShopEast(World world, Random random, int x, int y, int z) {
	System.out.println("Shop method called.");

	Block shop = CrewMod.shopBlock;
	Block aLog = Blocks.log2;
	Block doLog = Blocks.log2;
	Block fence = Blocks.fence;
	Block sSlab = Blocks.wooden_slab;
	Block mCWall = Blocks.cobblestone_wall;
	Block wWool = Blocks.wool;
	Block rWool = Blocks.wool;
	Block doPlank = Blocks.planks;
	Block glowstone = Blocks.glowstone;

	while(world.isAirBlock(x, y, z) && y > 2) {
		y--;
	}

	y += 1;

	/* Mid Section */
	world.setBlock(x, y, z, shop);
	world.setBlockToAir(x, y, z + 1);
	world.setBlockToAir(x, y, z - 1);
	world.setBlock(x + 1, y, z, mCWall, 1, 2);
	world.setBlock(x - 1, y, z - 1, mCWall, 1, 2);
	world.setBlock(x - 1, y, z + 1, mCWall, 1, 2);
	world.setBlock(x - 1, y, z - 2, doLog, 1, 2);
	world.setBlock(x - 1, y, z + 2, doLog, 1, 2);
	world.setBlock(x, y, z - 2, sSlab, 1, 2);
	world.setBlock(x, y, z + 2, sSlab, 1, 2);
	world.setBlock(x + 1, y, z - 2, doLog, 1, 2);
	world.setBlock(x + 1, y, z + 2, doLog, 1, 2);
	world.setBlock(x + 1, y, z - 1, mCWall, 1, 2);
	world.setBlock(x + 1, y, z + 1, mCWall, 1, 2);

	/* Floor */
	world.setBlock(x, y - 1, z, doPlank, 5, 2);
	world.setBlock(x, y - 1, z + 1, doPlank, 5, 2);
	world.setBlock(x, y - 1, z - 1, doPlank, 5, 2);
	world.setBlock(x - 1, y - 1, z, aLog, 8, 2);
	world.setBlock(x - 1, y - 1, z + 1, aLog, 8, 2);
	world.setBlock(x - 1, y - 1, z - 1, aLog, 8, 2);
	world.setBlock(x + 1, y - 1, z, aLog, 8, 2);
	world.setBlock(x + 1, y - 1, z + 1, aLog, 8, 2);
	world.setBlock(x + 1, y - 1, z - 1, aLog, 8, 2);
	world.setBlock(x - 1, y - 1, z - 2, doLog, 1, 2);
	world.setBlock(x - 1, y - 1, z + 2, doLog, 1, 2);
	world.setBlock(x + 1, y - 1, z - 2, doLog, 1, 2);
	world.setBlock(x + 1, y - 1, z + 2, doLog, 1, 2);
	world.setBlock(x, y - 1, z + 2, aLog, 4, 2);
	world.setBlock(x, y - 1, z - 2, aLog, 4, 2);

	/* Roof */
	world.setBlock(x - 1, y + 1, z - 2, fence, 0, 2);
	world.setBlock(x - 1, y + 1, z + 2, fence, 0, 2);
	world.setBlock(x + 1, y + 1, z - 2, fence, 0, 2);
	world.setBlock(x + 1, y + 1, z + 2, fence, 0, 2);
	world.setBlock(x - 1, y + 2, z - 2, fence, 0, 2);
	world.setBlock(x - 1, y + 2, z + 2, fence, 0, 2);
	world.setBlock(x + 1, y + 2, z - 2, fence, 0, 2);
	world.setBlock(x + 1, y + 2, z + 2, fence, 0, 2);
	world.setBlock(x - 1, y + 3, z - 2, rWool, 14, 2);
	world.setBlock(x - 1, y + 3, z + 2, rWool, 14, 2);
	world.setBlock(x + 1, y + 3, z - 2, rWool, 14, 2);
	world.setBlock(x + 1, y + 3, z + 2, rWool, 14, 2);
	world.setBlock(x, y + 3, z - 2, wWool, 0, 2);
	world.setBlock(x, y + 3, z + 2, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z - 1, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z + 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z - 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z + 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z, rWool, 14, 2);
	world.setBlock(x - 1, y + 3, z, rWool, 14, 2);
	world.setBlock(x, y + 4, z - 1, rWool, 14, 2);
	world.setBlock(x, y + 4, z + 1, rWool, 14, 2);
	world.setBlock(x, y + 4, z, wWool, 0, 2);
	world.setBlock(x , y + 3, z - 1, glowstone, 0, 2);
	world.setBlock(x, y + 3, z + 1, glowstone, 0, 2);
	world.setBlock(x, y + 3, z, glowstone, 0, 2);

	return true;
}

public boolean spawnShopWest(World world, Random random, int x, int y, int z) {
	System.out.println("Shop method called.");

	Block shop = CrewMod.shopBlock;
	Block aLog = Blocks.log2;
	Block doLog = Blocks.log2;
	Block fence = Blocks.fence;
	Block sSlab = Blocks.wooden_slab;
	Block mCWall = Blocks.cobblestone_wall;
	Block wWool = Blocks.wool;
	Block rWool = Blocks.wool;
	Block doPlank = Blocks.planks;
	Block glowstone = Blocks.glowstone;

	while(world.isAirBlock(x, y, z) && y > 2) {
		y--;
	}

	y += 1;

	/* Mid Section */
	world.setBlock(x, y, z, shop);
	world.setBlockToAir(x, y, z + 1);
	world.setBlockToAir(x, y, z - 1);
	world.setBlock(x - 1, y, z, mCWall, 1, 2);
	world.setBlock(x - 1, y, z - 1, mCWall, 1, 2);
	world.setBlock(x - 1, y, z + 1, mCWall, 1, 2);
	world.setBlock(x - 1, y, z - 2, doLog, 1, 2);
	world.setBlock(x - 1, y, z + 2, doLog, 1, 2);
	world.setBlock(x, y, z - 2, sSlab, 1, 2);
	world.setBlock(x, y, z + 2, sSlab, 1, 2);
	world.setBlock(x + 1, y, z - 2, doLog, 1, 2);
	world.setBlock(x + 1, y, z + 2, doLog, 1, 2);
	world.setBlock(x + 1, y, z - 1, mCWall, 1, 2);
	world.setBlock(x + 1, y, z + 1, mCWall, 1, 2);

	/* Floor */
	world.setBlock(x, y - 1, z, doPlank, 5, 2);
	world.setBlock(x, y - 1, z + 1, doPlank, 5, 2);
	world.setBlock(x, y - 1, z - 1, doPlank, 5, 2);
	world.setBlock(x - 1, y - 1, z, aLog, 8, 2);
	world.setBlock(x - 1, y - 1, z + 1, aLog, 8, 2);
	world.setBlock(x - 1, y - 1, z - 1, aLog, 8, 2);
	world.setBlock(x + 1, y - 1, z, aLog, 8, 2);
	world.setBlock(x + 1, y - 1, z + 1, aLog, 8, 2);
	world.setBlock(x + 1, y - 1, z - 1, aLog, 8, 2);
	world.setBlock(x - 1, y - 1, z - 2, doLog, 1, 2);
	world.setBlock(x - 1, y - 1, z + 2, doLog, 1, 2);
	world.setBlock(x + 1, y - 1, z - 2, doLog, 1, 2);
	world.setBlock(x + 1, y - 1, z + 2, doLog, 1, 2);
	world.setBlock(x, y - 1, z + 2, aLog, 4, 2);
	world.setBlock(x, y - 1, z - 2, aLog, 4, 2);

	/* Roof */
	world.setBlock(x - 1, y + 1, z - 2, fence, 0, 2);
	world.setBlock(x - 1, y + 1, z + 2, fence, 0, 2);
	world.setBlock(x + 1, y + 1, z - 2, fence, 0, 2);
	world.setBlock(x + 1, y + 1, z + 2, fence, 0, 2);
	world.setBlock(x - 1, y + 2, z - 2, fence, 0, 2);
	world.setBlock(x - 1, y + 2, z + 2, fence, 0, 2);
	world.setBlock(x + 1, y + 2, z - 2, fence, 0, 2);
	world.setBlock(x + 1, y + 2, z + 2, fence, 0, 2);
	world.setBlock(x - 1, y + 3, z - 2, rWool, 14, 2);
	world.setBlock(x - 1, y + 3, z + 2, rWool, 14, 2);
	world.setBlock(x + 1, y + 3, z - 2, rWool, 14, 2);
	world.setBlock(x + 1, y + 3, z + 2, rWool, 14, 2);
	world.setBlock(x, y + 3, z - 2, wWool, 0, 2);
	world.setBlock(x, y + 3, z + 2, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z - 1, wWool, 0, 2);
	world.setBlock(x - 1, y + 3, z + 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z - 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z + 1, wWool, 0, 2);
	world.setBlock(x + 1, y + 3, z, rWool, 14, 2);
	world.setBlock(x - 1, y + 3, z, rWool, 14, 2);
	world.setBlock(x, y + 4, z - 1, rWool, 14, 2);
	world.setBlock(x, y + 4, z + 1, rWool, 14, 2);
	world.setBlock(x, y + 4, z, wWool, 0, 2);
	world.setBlock(x, y + 3, z - 1, glowstone, 0, 2);
	world.setBlock(x, y + 3, z + 1, glowstone, 0, 2);
	world.setBlock(x, y + 3, z, glowstone, 0, 2);

	return true;
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.