#TargetBlock location & look direction

1 messages · Page 1 of 1 (latest)

dark coral
#

hey! i wanna set an itemframe on to a block, that i'm looking at. it should be on the side of the block, you look at, and not somewhere else. thy already!

dark coral
#

push 😄

dark coral
tardy sage
#

this is like

#

a pretty simple question and nobody has answered you in 3 days

#

and i feel horrible

#

try this

#

@dark coral

dark coral
#

thy so much, i'll try ❤️

dark coral
tardy sage
#

?

#

get the hit block

#

get the hit face

dark coral
#
RayTraceResult rayTraceResult = ((Player) sender).rayTraceBlocks((double) 5);
Block block = rayTraceResult.getHitBlock();
BlockFace blockFace = rayTraceResult.getHitBlockFace();
assert block != null;
block.setType(Material.AIR);
Location location = block.getLocation();
location.setDirection() // TODO:
World world = ((Player) sender).getWorld();
placeItemFrame(world, location, ids);
dark coral
dark coral
# dark coral ```java RayTraceResult rayTraceResult = ((Player) sender).rayTraceBlocks((double...

here's what place itemframe does: (just that you have an overview of what i wanna do)

private ItemStack modifyMap(int i, int[] ids) {
  ItemStack map = new ItemStack(Material.FILLED_MAP);
  MapMeta mapMeta = (MapMeta) map.getItemMeta();
  mapMeta.setMapId(ids[i]);
  map.setItemMeta(mapMeta);
  return map;
}

private void placeItemFrame(World world, Location location, int[] ids) {
  ItemFrame itemFrame = (ItemFrame) world.spawnEntity(location, EntityType.ITEM_FRAME);
  itemFrame.setFixed(true);
  itemFrame.setVisible(false);
  itemFrame.setItem(modifyMap(0, ids));
}
tardy sage
#

get rid of the world parameter

#

extract the world from location

#
RayTraceResult rtResult = ((Player) sender).rayTraceBlocks(5d);
if (rtResult == null) {
    return;
}
Block block = rtResult.getHitBlock();
if (block == null) {
    return;
}

Block toFrame = block.getRelative(rtResult.getHitBlockFace());
placeItemFrame(toFrame.getLocation(), ids);
dark coral
#

perfect thy, i'll test it 😄

#

whats the problem?!? why does it prefer this block direction?

tardy sage
#

you have to set the direction

#

are you making a spray plugin

dark coral
#

a poster maker... so like map art out of image url

#

have to go to school now, but i'll be back in like 45 mins

dark coral
dark coral
tardy sage
#

itemFrame.setFacingDirection(blockFace)

dark coral
#

okee thy so much for all your support ❤️