lethinh Posted February 21, 2017 Posted February 21, 2017 Does anyone know how to create a pickaxe that break unbreakable blocks? Quote
Animefan8888 Posted February 21, 2017 Posted February 21, 2017 Use the PlayerEvent.HavestCheck event and the PlayerEvent.BreakSpeed event. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
lethinh Posted February 21, 2017 Author Posted February 21, 2017 9 hours ago, Animefan8888 said: Use the PlayerEvent.HavestCheck event and the PlayerEvent.BreakSpeed event. How can I use it? Example? Quote
TheMasterGabriel Posted February 21, 2017 Posted February 21, 2017 2 hours ago, lethinh said: How can I use it? Example? You can read about Events here on the Forge docs. 1 Quote
lethinh Posted February 22, 2017 Author Posted February 22, 2017 22 hours ago, TheMasterGabriel said: You can read about Events here on the Forge docs. I already know that. And I am doing an pickaxe that mine 10x10 blocks. Base on the TerraPick in Botania. But I am asking how to do that (in the event). My unfinished code: Spoiler @SubscribeEvent public void onPlayerDig(PlayerInteractEvent event) { if (event.getFace() == null || event.getWorld().isRemote || event.getEntityPlayer().applyPlayerInteraction(event.getEntityPlayer(), event.getEntityPlayer().getForward(), event.getItemStack(), event.getHand()) == EnumActionResult.PASS || event.getEntityPlayer().getHeldItem(event.getHand()) == null || event.getEntityPlayer().capabilities.isCreativeMode) return; IBlockState state = event.getWorld().getBlockState(event.getPos()); Block block = state.getBlock(); Random random = new Random(); if (block.getBlockHardness(state, event.getWorld(), event.getPos()) <= -1 && event.getEntityPlayer().getHeldItem(event.getHand()).getItem() == LudicrousItems.infinity_pickaxe && (block.getMaterial(state) == Material.ROCK || block.getMaterial(state) == Material.IRON)) { LudicrousItems.infinity_pickaxe.onBlockStartBreak(event.getEntityPlayer().getHeldItem(event.getHand()), event.getPos(), event.getEntityPlayer()); } else { ItemStack drops = block.getPickBlock(state, ToolCommons.raytraceFromEntity(event.getWorld(), event.getEntityPlayer(), true, 10), event.getWorld(), event.getPos(), event.getEntityPlayer()); if (block.quantityDropped(random) == 0) { if (drops == null) drops = new ItemStack(block, 1, block.getMetaFromState(state)); dropItems(drops, event.getWorld(), event.getPos()); } else block.harvestBlock(event.getWorld(), event.getEntityPlayer(), event.getPos(), state, event.getWorld().getTileEntity(event.getPos()), drops); event.getWorld().setBlockToAir(event.getPos()); event.getWorld().playEvent(2001, event.getPos(), Block.getIdFromBlock(block) + (block.getMetaFromState(state) << 12)); } } } Quote
lethinh Posted February 23, 2017 Author Posted February 23, 2017 (edited) 12 hours ago, diesieben07 said: Don't subscribe to the raw PlayerInteractEvent. Choose one of the sub-events. Why are you calling applyPlayerInteraction like that? It makes no sense, you are telling the player to interact with itself. getForward is annotated with @SideOnly(CLIENT), which means you cannot use it in common code like this. You can learn more about sides in the documentation. Why are you creating a new Random instance every time? Block::getBlockHardness is deprecated, you should use IBlockState::getBlockHardness instead. hardness <= -1 is not the condition for unbreakable. A block is unbreakable if it's hardness is below 0. In 1.10.2 ItemStacks can still be null hence you cannot simply call getItem on the result of EntityPlayer::getHeldItem, since it might be null. Block::getMaterial is deprecated, use IBlockState::getMaterial instead. Why are you doing a ray-trace? You know which block was hit and you can also obtain the hit vector needed to create the RayTraceResult from the event. You should not be calling quantityDropped, it is not accurate for all blocks. The only way to truly obtain a block's drops is to call Block::getDrops. You should almost never call Block::getMetaFromState, especially not to construct an ItemStack. Use Block.getStateId instead of manually constructing the ID from metadata. Still doesn't work. Here is my newest code: Spoiler @SubscribeEvent public void onPlayerMine(PlayerInteractEvent.LeftClickBlock event) { if (event.getFace() == null || event.getWorld().isRemote || event.getEntityPlayer().getHeldItem(event.getHand()) == null || event.getEntityPlayer().capabilities.isCreativeMode) return; IBlockState state = event.getWorld().getBlockState(event.getPos()); Block block = state.getBlock(); if (state.getBlockHardness(event.getWorld(), event.getPos()) < 0 && event.getEntityPlayer().getHeldItem(event.getHand()).getItem() == LudicrousItems.infinity_pickaxe && (state.getMaterial() == Material.ROCK || state.getMaterial() == Material.IRON)) { LudicrousItems.infinity_pickaxe.onBlockStartBreak(event.getEntityPlayer().getHeldItem(event.getHand()), event.getPos(), event.getEntityPlayer()); } else { ItemStack drop = block.getPickBlock(state, ToolHelper.raytraceFromEntity(event.getWorld(), event.getEntityPlayer(), true, 10), event.getWorld(), event.getPos(), event.getEntityPlayer()); if (block.getDrops(event.getWorld(), event.getPos(), state, EnchantmentHelper .getEnchantmentLevel(Enchantments.FORTUNE, new ItemStack(LudicrousItems.infinity_pickaxe))) == null) { if (drop == null) drop = new ItemStack(block, 1, block.getMetaFromState(state)); dropItems(drop, event.getWorld(), event.getPos()); } else block.harvestBlock(event.getWorld(), event.getEntityPlayer(), event.getPos(), state, event.getWorld().getTileEntity(event.getPos()), drop); event.getWorld().setBlockToAir(event.getPos()); event.getWorld().playEvent(2001, event.getPos(), Block.getStateId(state)); } } } Edited February 23, 2017 by lethinh Quote
Leomelonseeds Posted February 23, 2017 Posted February 23, 2017 Can you use the code tag please? (<>)that thing. Currently I cant even tell what you are doing Quote Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.
CrazyGriefer1337 Posted February 23, 2017 Posted February 23, 2017 Just try the following: -Test if the block is unbreakable (Bedrock, or something modded) -If yes, execute the command "fill" (Minecraft command, not Java) -If it doesn't work, throw your PC out of the window. Quote
lethinh Posted February 27, 2017 Author Posted February 27, 2017 On 23/2/2017 at 3:46 PM, CrazyGriefer1337 said: Just try the following: -Test if the block is unbreakable (Bedrock, or something modded) -If yes, execute the command "fill" (Minecraft command, not Java) -If it doesn't work, throw your PC out of the window. This is coding not normal MC! Quote
lethinh Posted March 23, 2017 Author Posted March 23, 2017 On 27/2/2017 at 3:27 PM, diesieben07 said: I am still not clear as to why you are calling onBlockStartBreak. If anything you need to completely emulate the block-breaking process as it normally occurs in PlayerInteractionManager. You are still ray-tracing without the need to do that. Block::getDrops will never return null. You are still calling Block::getMetaFromState. Still doesn't work! Quote
lethinh Posted April 4, 2017 Author Posted April 4, 2017 On 23/3/2017 at 3:47 PM, diesieben07 said: Oh no! Well, how about you show us what you changed? Seriously... Here is my final newest code: https://gist.github.com/anonymous/28b892b90e2f73d2242a3f2b077e77ca Quote
Draco18s Posted April 4, 2017 Posted April 4, 2017 On your newest code.... You are comparing ItemStack instances using == which will never work. Except that what you are comparing is the return of block.getItem(world, pos, state) with the return of block.getItem(world, pos, state) (i.e.. itself) which will always be true. On 2/27/2017 at 3:27 AM, diesieben07 said: You are still calling Block::getMetaFromState. Quote 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.
lethinh Posted April 5, 2017 Author Posted April 5, 2017 22 hours ago, Draco18s said: On your newest code.... You are comparing ItemStack instances using == which will never work. Except that what you are comparing is the return of block.getItem(world, pos, state) with the return of block.getItem(world, pos, state) (i.e.. itself) which will always be true. Do you know how to fix those errors? I have tried all! Quote
lethinh Posted April 6, 2017 Author Posted April 6, 2017 22 hours ago, diesieben07 said: Please show what you tried and why it didn't work. All the code that I have shown to you. And could you show me how to not call Block::getMetaFromState? Quote
lethinh Posted April 6, 2017 Author Posted April 6, 2017 (edited) 10 minutes ago, diesieben07 said: You should not construct the dropped item stacks manually. Use Block::getDrops to obtain the drops, like I already said in my first post. I can't. Block::getDrops is List<ItemStack> but the drop is a item stack. Edited April 6, 2017 by lethinh Quote
Jay Avery Posted April 6, 2017 Posted April 6, 2017 17 minutes ago, lethinh said: I can't. Block::getDrops is List<ItemStack> but the drop is a item stack. So return a list that contains just one stack. Quote
lethinh Posted April 6, 2017 Author Posted April 6, 2017 18 minutes ago, Jay Avery said: So return a list that contains just one stack. Can't be. If I do that, the method InventoryHelper::spawnItemStack and Block::harvestBlock WILL NOT WORK Quote
lethinh Posted April 6, 2017 Author Posted April 6, 2017 1 minute ago, diesieben07 said: What is "the drop"? What? It is: @SubscribeEvent public void onPlayerDig(PlayerInteractEvent.LeftClickBlock event) { World world = event.getWorld(); EntityPlayer player = event.getEntityPlayer(); if (event.getFace() == null || world.isRemote || StackUtils.isEmpty(player.getHeldItem(EnumHand.MAIN_HAND)) || player.isCreative()) return; BlockPos pos = event.getPos(); IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); List<ItemStack> drop = new ArrayList<>(); if (block.getDrops(world, pos, state, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, new ItemStack(this))) == drop) { if (drop == null) drop = new ArrayList<>(block.getDrops(world, pos, state, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, new ItemStack(this)))); InventoryHelper.spawnItemStack(world, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), drop); } else block.harvestBlock(world, player, pos, state, world.getTileEntity(pos), drop); world.setBlockToAir(pos); world.playEvent(2001, pos, Block.getStateId(state)); } Quote
Jay Avery Posted April 6, 2017 Posted April 6, 2017 Quote if (block.getDrops(world, pos, state, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, new ItemStack(this))) == drop Now you are comparing a List<ItemStack> to an ItemStack, so the result will always be false. Why are you making this comparison anyway? What result are you actually trying to get? You still keep using ==, which only checks for the exact same object, rather than for meaningfully equivalent objects. Two different ItemStacks made of the same Item and stacksize will not be equal with the == operator. Quote List<ItemStack> drop = new ArrayList<>() ... if (drop == null) How could drop possibly be null here after you have set it to a new ArrayList? (Hint: it couldn't). You seem to be having trouble with some fairly fundamental Java/OOP concepts, you might be better off learning some general programming first. Quote
lethinh Posted April 7, 2017 Author Posted April 7, 2017 19 hours ago, Jay Avery said: Now you are comparing a List<ItemStack> to an ItemStack, so the result will always be false. Why are you making this comparison anyway? What result are you actually trying to get? You still keep using ==, which only checks for the exact same object, rather than for meaningfully equivalent objects. Two different ItemStacks made of the same Item and stacksize will not be equal with the == operator. How could drop possibly be null here after you have set it to a new ArrayList? (Hint: it couldn't). You seem to be having trouble with some fairly fundamental Java/OOP concepts, you might be better off learning some general programming first. I have just learned java for few months. And the code didn't work: @SubscribeEvent public void onPlayerDig(PlayerInteractEvent.LeftClickBlock event) { World world = event.getWorld(); EntityPlayer player = event.getEntityPlayer(); if (event.getFace() == null || world.isRemote || StackUtils.isEmpty(player.getHeldItem(EnumHand.MAIN_HAND)) || player.isCreative()) return; BlockPos pos = event.getPos(); IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); List<ItemStack> drop = new ArrayList<>(); if (drop == null) drop = new ArrayList<>(block.getDrops(world, pos, state, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, new ItemStack(this)))); block.harvestBlock(world, player, pos, state, world.getTileEntity(pos), new ItemStack(block)); InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(block)); world.setBlockToAir(pos); world.playEvent(2001, pos, Block.getStateId(state)); } Quote
Jay Avery Posted April 7, 2017 Posted April 7, 2017 50 minutes ago, lethinh said: List<ItemStack> drop = new ArrayList<>(); if (drop == null) You're still doing this pointless check. And now you do nothing with the drop variable after you create it anyway. When you say the code doesn't work, please be more specific. Exactly what does and doesn't happen, and what are you expecting to happen? At this point I've lost track of the problem. Quote
lethinh Posted April 7, 2017 Author Posted April 7, 2017 2 hours ago, Jay Avery said: You're still doing this pointless check. And now you do nothing with the drop variable after you create it anyway. When you say the code doesn't work, please be more specific. Exactly what does and doesn't happen, and what are you expecting to happen? At this point I've lost track of the problem. It doesn't break unbreakable block. That's the point of the code. Quote
Draco18s Posted April 7, 2017 Posted April 7, 2017 List<ItemStack> drop = new ArrayList<>(); Cool, I have an array object if (drop == null) Nope, it's not null. It's an ArrayList of size zero. block.harvestBlock(world, player, pos, state, world.getTileEntity(pos), new ItemStack(block)); InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(block)); And now, I ignore the fuck out of my array object. Quote 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.
Jay Avery Posted April 7, 2017 Posted April 7, 2017 1 hour ago, lethinh said: It doesn't break unbreakable block. That's the point of the code. Does it break ordinary breakable blocks? Does the game crash? Does the event get called? Quote
lethinh Posted April 8, 2017 Author Posted April 8, 2017 23 hours ago, Jay Avery said: Does it break ordinary breakable blocks? Does the game crash? Does the event get called? It breaks ordinary breakable blocks. The game doesn't crash. And I have called the event by using MinecraftForge.EventBus::register Quote
Recommended Posts
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.