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

Hello, i started modding a few weeks ago(1.12.2 modding btw) and i am making a mod that has some enchantments like an enchantment called Miners Touch(It is supposed to give a player a iron ingot and leave stone where the ore was broken), but i can't seem to get a way to detect the player breaking a block... my current code is this:

if (player != null) { BlockPos block = findBlockAtCursor(10, player, world); if (block != null && world.getBlockState(block) == Blocks.IRON_ORE.getDefaultState()) { player.addItemStackToInventory(new ItemStack(Items.IRON_INGOT)); displayMessage("Iron Mined",world,player); } } } //Methods protected static BlockPos findBlockAtCursor(float range, EntityPlayer player, World world) { Vec3d posVec = new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ); Vec3d lookVec = player.getLookVec(); // Draw a line from the player to where the player is aiming, save it if // we hit a block. // TODO: 1.12 Change - lookVec uses x, y, z RayTraceResult blockHit = world.rayTraceBlocks(posVec, posVec.addVector(lookVec.x * range, lookVec.y * range, lookVec.z * range)); if (blockHit == null) return null; BlockPos block = blockHit.getBlockPos().offset(blockHit.sideHit); return block; } protected static void displayMessage(String message, World world, EntityPlayer player) { if (!world.isRemote) { player.sendMessage(new TextComponentString(message)); } } }

 

Any help is appreciated!

Thanks in advance - Chocolate_Cherry

Guest
This topic is now closed to further replies.

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.