Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. package com.github.soravoid.exceed.util;
  2.  
  3. import net.minecraft.block.BlockState;
  4. import net.minecraft.entity.item.ItemEntity;
  5. import net.minecraft.entity.player.PlayerEntity;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.tags.BlockTags;
  8. import net.minecraft.util.math.BlockPos;
  9. import net.minecraft.world.World;
  10. import net.minecraft.world.server.ServerWorld;
  11. import net.minecraft.world.storage.loot.LootContext;
  12.  
  13. import java.util.ArrayList;
  14. import java.util.List;
  15.  
  16. public class TreeChoppingUtils
  17. {
  18. public static void handleFelling(PlayerEntity player, World world, BlockPos pos, ItemStack stack, List<BlockPos> list, List<BlockPos> handled, RunHandleFelling handler, int iteration, int itMax)
  19. {
  20. world.getServer().deferTask(() -> {
  21.  
  22. for(int x = -1; x <= 1; x++)
  23. {
  24. for(int y = -1; y <= 1; y++)
  25. {
  26. for(int z = -1; z <= 1; z++)
  27. {
  28. BlockPos pos1 = new BlockPos(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
  29. if(!handled.contains(pos1))
  30. {
  31. if(pos1.equals(pos) && iteration == 1)
  32. {
  33. list.add(pos1);
  34. }
  35. else if(BlockTags.LOGS.contains(world.getBlockState(pos1).getBlock()) || BlockTags.LEAVES.contains(world.getBlockState(pos1).getBlock()))
  36. {
  37. list.add(pos1);
  38. }
  39. }
  40. }
  41. }
  42. }
  43. for(BlockPos pos2 : list)
  44. {
  45. world.getServer().deferTask(() -> {
  46. BlockState state1 = world.getBlockState(pos2);
  47. world.destroyBlock(pos2, true);
  48. stack.onBlockDestroyed(world, state1, pos2, player);
  49. handler.run(world, pos2, stack);
  50. });
  51. handled.add(pos2);
  52. if(iteration < itMax && !(stack == null || stack.getDamage() == stack.getMaxDamage())) handleFelling(player, world, pos2, stack, new ArrayList<>(), handled, handler, iteration + 1, itMax);
  53. }
  54. });
  55. }
  56.  
  57. public interface RunHandleFelling
  58. {
  59. void run(World world, BlockPos pos, ItemStack stack);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement