Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.github.soravoid.exceed.util;
- import net.minecraft.block.BlockState;
- import net.minecraft.entity.item.ItemEntity;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tags.BlockTags;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import net.minecraft.world.server.ServerWorld;
- import net.minecraft.world.storage.loot.LootContext;
- import java.util.ArrayList;
- import java.util.List;
- public class TreeChoppingUtils
- {
- public static void handleFelling(PlayerEntity player, World world, BlockPos pos, ItemStack stack, List<BlockPos> list, List<BlockPos> handled, RunHandleFelling handler, int iteration, int itMax)
- {
- world.getServer().deferTask(() -> {
- for(int x = -1; x <= 1; x++)
- {
- for(int y = -1; y <= 1; y++)
- {
- for(int z = -1; z <= 1; z++)
- {
- BlockPos pos1 = new BlockPos(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
- if(!handled.contains(pos1))
- {
- if(pos1.equals(pos) && iteration == 1)
- {
- list.add(pos1);
- }
- else if(BlockTags.LOGS.contains(world.getBlockState(pos1).getBlock()) || BlockTags.LEAVES.contains(world.getBlockState(pos1).getBlock()))
- {
- list.add(pos1);
- }
- }
- }
- }
- }
- for(BlockPos pos2 : list)
- {
- world.getServer().deferTask(() -> {
- BlockState state1 = world.getBlockState(pos2);
- world.destroyBlock(pos2, true);
- stack.onBlockDestroyed(world, state1, pos2, player);
- handler.run(world, pos2, stack);
- });
- handled.add(pos2);
- if(iteration < itMax && !(stack == null || stack.getDamage() == stack.getMaxDamage())) handleFelling(player, world, pos2, stack, new ArrayList<>(), handled, handler, iteration + 1, itMax);
- }
- });
- }
- public interface RunHandleFelling
- {
- void run(World world, BlockPos pos, ItemStack stack);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement