Posted October 14, 20186 yr I would like to find all sign-blocks and their position in the chunk at my player position. My problem is that I dont know how to iterate through the blocks in the chunk. EntityPlayer player = Minecraft.getMinecraft().player; World world = player.getEntityWorld(); Chunk chunk = world.getChunkFromBlockCoords(player.getPosition()); Map<BlockPos, TileEntity> myMap = chunk.getTileEntityMap(); for(double x = 0; x <= 16; x++) { System.out.println(chunk.getBlockState(new BlockPos(x+player.posX, player.posY , player.posZ))); } What I dont understand is how do I get the blocks of exactly the chunk where myPlayerPosition is. I can use loops with offsets but I dont understand how the coordinations work. because for "chunk.getBlockState() I need to set a blockposition but how do I get the position of the first/last block in that actual chunk? I'm looking for something like : for(double x = 0; x <= 16; x++) { System.out.println(chunk.getBlockState(new BlockPos(x+offset,blablabla))); } I know its only one dimensional but I want to get it right first before I go on for the other axis. I need to understand how I can turn this relative chunk coordinations into real worldcoordination. I already found this but the topic is more about blockproperties then the iterating. Edited October 14, 20186 yr by HenryFoster
October 14, 20186 yr Author Edit: I got it: @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent event) { if(KeyBindings.myKey.isPressed()) { System.out.println("KEY K"); EntityPlayer player = Minecraft.getMinecraft().player; World world = player.getEntityWorld(); Chunk chunk = world.getChunkFromBlockCoords(player.getPosition()); int a = chunk.x*16; int b = chunk.z*16; System.out.println("Chunk starts at: "+ a*16 + " " + b*16); for(double x = 0; x <= 15; x++) { for(double y = player.posY-2; y <= player.posY+10; y++) { for(double z = 0; z <= 15; z++) { //System.out.println(chunk.getBlockState(new BlockPos(a+x,player.posY , b+z))); BlockPos actualPosition = new BlockPos(a+x,y, b+z); IBlockState state = chunk.getBlockState(actualPosition); if(state.getBlock() instanceof BlockSign) { for(ITextComponent i: ((TileEntitySign)world.getTileEntity(actualPosition)).signText) { System.out.println(i.getUnformattedComponentText()); } } } } } } } I use the Chunk coordiantes a and b (yes I know bad names I will change them) and multiply them with 16 to get the start coordinates of the chunk where my player is. Later I define the position of the block "I'm looking at" with the starting position of the chunk + x/z to get the global-coordinates of that block.
October 15, 20186 yr 20 hours ago, HenryFoster said: multiply them Don’t multiply, use bit shifting. The results are different (integer multiplication rounds down) About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
October 15, 20186 yr Multiplying works out the same. Its dividing that causes problems. (You should still bitshift) 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.
October 16, 20186 yr Theres also a performance gain with bitshifting About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
October 16, 20186 yr Author 10 hours ago, Draco18s said: Multiplying works out the same. Its dividing that causes problems. (You should still bitshift) I will look into this thanks for the help.
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.