Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

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.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.