Posted November 11, 201410 yr I am working on a Zelda mod, and I am trying to add a item that will allow the player to create a block using it. I am currently using entities to determine where it should place the block, however, I am trying to make it not depend on the entity, and only on the item, as I only want the player to be able to spawn the block 1 block in front of them. How would I go about testing which way the player is facing so I can determine how to set the block in the code? There's 10 types of people in this world; Those that understand binary and those that don't.
November 11, 201410 yr If you have an item class that you are using, override 'onItemUse' - it gives you the coordinates of the block clicked, the side that was clicked, and even more precise float coordinates for the exact position if needed. http://i.imgur.com/NdrFdld.png[/img]
November 11, 201410 yr You can also access the player entity's rotation. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
November 11, 201410 yr That facing method will fail (or at least not give expected results) if the player is looking up or down, though - if the item works at a distance greater than that of block-clicking, then you ought to use ray tracing to find the block hit by the player's look vector. http://i.imgur.com/NdrFdld.png[/img]
November 11, 201410 yr Yes, and it will probably be exactly what is needed - just thought I'd point out that depending on the requirements (up/down possibilities), it may not be enough http://i.imgur.com/NdrFdld.png[/img]
November 11, 201410 yr i solve this making something complicated meta return 0 when looking up meta return 1 when looking down meta return 2 when looking south meta return 3 when looking north meta return 4 when looking east meta return 5 when looking west meta return 6 when error first get the block xyz coordinates sum steve xyz coordinates and whit results set face of block steve is looking at mi methods starts like //block class public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase steve, ItemStack p_149689_6_){ int meta=util.meta(world, steve); System.out.println("util.meta(world, steve)="+meta); } //################################################## //class util public static int meta(World world, EntityLivingBase steve){ // Position de steve , pocision del blocke ArrayList<Integer> lia = new ArrayList<Integer>(); ArrayList<Integer> lib = new ArrayList<Integer>(); lia.clear(); lib.clear(); lib=util.coordenadaDeBlockeEnFocol(world, 10); lia.add((int) steve.posX); lia.add((int) steve.posY); lia.add((int) steve.posZ); int x=lib.get(0)-lia.get(0); int y=lib.get(1)-lia.get(1)-1; int z=lib.get(2)-lia.get(2); System.out.println("x="+x+" y="+y+" z="+z); if ((x>0)&&(z<0)){return 4;}//return 10;} if ((x<0)&&(z<0)){return 3;}//return 9;} if ((x<0)&&(z>0)){return 5;}//return 8;} if ((x>0)&&(z>0)){return 2;}//return 7;} if ((x<0)&&(z==0)){return 5;} if ((x>0)&&(z==0)){return 4;} if ((x==0)&&(z<0)){return 3;} if ((x==0)&&(z>0)){return 2;} if ((y<0)){return 1;} if ((y>0)){return 0;} return 6; } //################################################## public static ArrayList<Integer> coordenadaDeBlockeEnFocol(World world,int distancia){ //System.out.println("###coordenadaDeBlockeEnFocoL"); ArrayList<Integer> lin =new ArrayList<Integer>(); // x y z //lin.add(0);lin.add(0);lin.add(0); MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(distancia, 1.0F); //System.out.println("###mop="+mop); if(mop != null) { int blockHitSide = mop.sideHit; Block blockLookingAt = world.getBlock(mop.blockX, mop.blockY, mop.blockZ) ; int fx=(int)mop.blockX; int fy=(int)mop.blockY; int fz=(int)mop.blockZ; // System.out.println("fx="+fx+" fy="+fy+" fz="+fz); lin.add(0,fx); lin.add(1,fy); lin.add(2,fz); } // // int x=lin.get(0); // int y=lin.get(1); // int z=lin.get(2); // if (world.isAirBlock(x,y,z)) {System.out.println(">>>>>### el blocke x="+x+" y="+y+" z="+z+" es aire");} // System.out.println("x="+lin.get(0)+" y="+lin.get(1)+" z="+lin.get(2)); return lin; } //
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.