Posted May 12, 201411 yr i have an item when right clicked it spawns a wall. but the wall was only facing one direction. i would like some help to figure out how to turn the wall when the player turns. i have tried to turn it with player and block coords. but the coord system is a bit wired and i dont get it. here is what i have at the momment: package Talimagics.items; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class taliswall extends Item { public taliswall(int par1) { super(par1); this.setCreativeTab(CreativeTabs.tabMisc); this.setMaxStackSize(1); this.setMaxDamage(16); } int dirx; int dirz; int playx; int playz; float fplayx; float fplayz; public boolean onItemUse(ItemStack used, EntityPlayer player, World world, int bx, int by, int bz, int side, float px, float py, float pz) { //clicked bottom of the block if (side == 0 && player.isSneaking()) { //decreases the y position to get the actual clicked block --by; }else if (side == 0){ --by; --by; } //clicked top of the block if (side == 1 && player.isSneaking()) { //increases the y position to get the actual clicked block ++by; }else if (side == 1){ ++by; ++by; } //and so on... if (side == 2 && player.isSneaking()) { --bz; }else if (side == 2){ --bz; --bz; } if (side == 3 && player.isSneaking()) { ++bz; }else if (side == 3){ ++bz; ++bz; } if (side == 4 && player.isSneaking()) { --bx; }else if (side == 4){ --bx; --bx; } if (side == 5 && player.isSneaking()) { ++bx; }else if (side == 5){ ++bx; ++bx; } //check if player can edit the block. if (!player.canPlayerEdit(bx, by, bz, side, used)) { //Item didnt used. return false; } else { //When the block is air, if (world.isAirBlock(bx, by, bz)) { //play Sound at the center of the block. world.playSoundEffect((double)bx+ 0.5D, (double)by+ 0.5D, (double)bz+ 0.5D, "dig.stone", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F); dirx = bx; dirz = bz; fplayx = px; fplayz = pz; Math.round(fplayx); Math.round(fplayz); playx = (int)fplayx; playz = (int)fplayz; dirx = dirx - playx; dirz = dirz - playz; if(player.isSneaking()){ //Sets the Block! world.setBlock(bx, by, bz, Block.glass.blockID); }else{ if(dirx > dirz){ world.setBlock(bx, by, bz, Block.glass.blockID);//mid block world.setBlock(bx, --by, bz, Block.glass.blockID); world.setBlock(bx, by, --bz, Block.glass.blockID); world.setBlock(bx, ++by, bz, Block.glass.blockID); world.setBlock(bx, ++by, bz, Block.glass.blockID); world.setBlock(bx, by, ++bz, Block.glass.blockID); world.setBlock(bx, by, ++bz, Block.glass.blockID); world.setBlock(bx, --by, bz, Block.glass.blockID); world.setBlock(bx, --by, bz, Block.glass.blockID); }else if(dirz > dirx){ world.setBlock(bx, by, bz, Block.glass.blockID);//mid block world.setBlock(bx, --by, bz, Block.glass.blockID); } } } //Damages the Item. used.damageItem(1, player); //Item used. return true; } } } thanks in advance
May 12, 201411 yr Hi This link shows the coordinate system (you seem to have it right already?) http://greyminecraftcoder.blogspot.com.au/2013/07/blocks.html I don't understand what you mean "the wall was only facing one direction", and I'm not sure what you intend those ++bx etc to do? Perhaps you could show some screenshots of what it actually looks like, compared with what you want? -TGG
May 12, 201411 yr Author what happends in the code is that the x and z coords are added together so when i am at x100 z700 the code says z and x is 800. the bx...etc stuff is block x y z and the px...etc is player x y z here is what i want from my item. when i right click a block on the ground like this one. https://i.imgur.com/bdLtdYn.png i will spawn a wall(testing with glass) https://i.imgur.com/T0gMZ9w.png but when i turn the player and right clicks the wall still faces the same direction. https://i.imgur.com/GFHNIJT.png that is whats going on.
May 12, 201411 yr Author what happends in the code is that the x and z coords are added together so when i am at x100 z700 the code says z and x is 800. after further testing. it seems i was wrong. the block coords are right but the player coord are another story. it seems that it returns a 0.######## number. that does not go as well in my maths equation. so if anyone know how to fix this. that would be apriciated
May 12, 201411 yr Hi Thanks for the pics, that makes it much clearer. A few thoughts 1) I don't think that parameter is actually the player [x,y,z]. I think it's actually the coordinates of the point on the block face where the player's line of sight intersects. 2) I think you will need to retrieve the player's coordinates using player.posX, .posY etc. This is not ideal but it should work I think. 3) when comparing dirx with dirz, in order to see whether the wall is east-west or north-south, you should take Math.abs(), because they can be negative or positive. 4) what happens if dirx == dirz? 5) I understand how you want it to work for clicking on the top or bottom of block; but I'm not sure your east, west, north, south will do something reasonable /** * Handles a players right click. Args: player, world, x, y, z, side, hitVec */ public boolean onPlayerRightClick(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7, Vec3 par8Vec3) { this.syncCurrentPlayItem(); float f = (float)par8Vec3.xCoord - (float)par4; float f1 = (float)par8Vec3.yCoord - (float)par5; float f2 = (float)par8Vec3.zCoord - (float)par6; (f, f1, f2 are eventually passed to onItemUse(). re hitVec - see class MovingObjectPosition) -TGG
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.