Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. public class GraftlingCertaintyFeat {
  2. private static final ResourceLocation NAME = new ResourceLocation(EposAPI.ID, "graftling_certainty");
  3. @SuppressWarnings({"ConstantConditions", "deprecation"})
  4. public static final Feat FEAT =
  5. FeatBuilder.start(NAME)
  6. .withEventHandler(BlockEvent.HarvestDropsEvent.class,
  7. (harvestDropsEvent, entity, iCharacterStats) -> {
  8. if (harvestDropsEvent.getState().getBlock() instanceof LeavesBlock && !harvestDropsEvent.isSilkTouching()) {
  9. LeavesBlock block = (LeavesBlock) harvestDropsEvent.getState().getBlock();
  10. boolean containsSapling = false;
  11. List<ItemStack> stacks = harvestDropsEvent.getDrops();
  12. for (ItemStack stack : stacks) {
  13. if (stack.getItem().isIn(ItemTags.SAPLINGS)) {
  14. containsSapling = true;
  15. }
  16. }
  17. if (block.isIn(BlockTags.LEAVES) && !containsSapling) {
  18. LootContext.Builder context = new LootContext.Builder(entity.world.getServer().getWorld(entity.dimension));
  19. List<ItemStack> stackList = new ArrayList<>();
  20. for (int i = 0; i < 10; i++) stackList.addAll(block.getDrops(harvestDropsEvent.getState(), context));
  21. for (ItemStack stack : stackList) {
  22. if (stack.getItem().isIn(ItemTags.SAPLINGS)) {
  23. harvestDropsEvent.getDrops().add(new ItemStack(stack.getItem(), 1));
  24. }
  25. }
  26. }
  27. harvestDropsEvent.setDropChance(1f);
  28. }
  29. }).finish();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement