mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-03 18:43:43 +01:00 
			
		
		
		
	refactoring
This commit is contained in:
		@@ -36,6 +36,7 @@ import java.util.List;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.concurrent.ThreadLocalRandom;
 | 
			
		||||
 | 
			
		||||
import static com.gmail.nossr50.util.ItemUtils.spawnItemsFromCollection;
 | 
			
		||||
import static com.gmail.nossr50.util.Misc.getBlockCenter;
 | 
			
		||||
import static com.gmail.nossr50.util.ItemUtils.spawnItem;
 | 
			
		||||
import static com.gmail.nossr50.util.skills.RankUtils.hasUnlockedSubskill;
 | 
			
		||||
@@ -322,14 +323,14 @@ public class WoodcuttingManager extends SkillManager {
 | 
			
		||||
                xp += processTreeFellerXPGains(blockState, processedLogCount);
 | 
			
		||||
 | 
			
		||||
                //Drop displaced block
 | 
			
		||||
                ItemUtils.spawnItemsFromCollection(player, getBlockCenter(blockState), block.getDrops(itemStack), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
 | 
			
		||||
                spawnItemsFromCollection(player, getBlockCenter(blockState), block.getDrops(itemStack), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
 | 
			
		||||
 | 
			
		||||
                //Bonus Drops / Harvest lumber checks
 | 
			
		||||
                processBonusDropCheck(blockState);
 | 
			
		||||
            } else if (BlockUtils.isNonWoodPartOfTree(blockState)) {
 | 
			
		||||
                // 75% of the time do not drop leaf blocks
 | 
			
		||||
                if (ThreadLocalRandom.current().nextInt(100) > 75) {
 | 
			
		||||
                    ItemUtils.spawnItemsFromCollection(player,
 | 
			
		||||
                    spawnItemsFromCollection(player,
 | 
			
		||||
                            getBlockCenter(blockState),
 | 
			
		||||
                            block.getDrops(itemStack),
 | 
			
		||||
                            ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
 | 
			
		||||
@@ -421,8 +422,8 @@ public class WoodcuttingManager extends SkillManager {
 | 
			
		||||
     *
 | 
			
		||||
     * @param blockState Block being broken
 | 
			
		||||
     */
 | 
			
		||||
    protected void spawnHarvestLumberBonusDrops(@NotNull BlockState blockState) {
 | 
			
		||||
        ItemUtils.spawnItemsFromCollection(
 | 
			
		||||
    void spawnHarvestLumberBonusDrops(@NotNull BlockState blockState) {
 | 
			
		||||
        spawnItemsFromCollection(
 | 
			
		||||
                getPlayer(),
 | 
			
		||||
                getBlockCenter(blockState),
 | 
			
		||||
                blockState.getBlock().getDrops(getPlayer().getInventory().getItemInMainHand()),
 | 
			
		||||
 
 | 
			
		||||
@@ -35,12 +35,11 @@ import java.util.function.Predicate;
 | 
			
		||||
import static java.util.Objects.requireNonNull;
 | 
			
		||||
 | 
			
		||||
public final class ItemUtils {
 | 
			
		||||
    /**
 | 
			
		||||
     * This is a static utility class, therefore we don't want any instances of
 | 
			
		||||
     * this class. Making the constructor private prevents accidents like that.
 | 
			
		||||
     */
 | 
			
		||||
    private ItemUtils() {}
 | 
			
		||||
    private ItemUtils() {
 | 
			
		||||
        // private constructor
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Reflection for setItemName only available in newer APIs
 | 
			
		||||
    private static final Method setItemName;
 | 
			
		||||
 | 
			
		||||
    static {
 | 
			
		||||
@@ -899,7 +898,12 @@ public final class ItemUtils {
 | 
			
		||||
     * @param speed the speed that the item should travel
 | 
			
		||||
     * @return Dropped Item entity or null if invalid or cancelled
 | 
			
		||||
     */
 | 
			
		||||
    public static @Nullable Item spawnItemTowardsLocation(@Nullable Player player, @NotNull Location fromLocation, @NotNull Location toLocation, @NotNull ItemStack itemToSpawn, double speed, @NotNull ItemSpawnReason itemSpawnReason) {
 | 
			
		||||
    public static @Nullable Item spawnItemTowardsLocation(@Nullable Player player,
 | 
			
		||||
                                                          @NotNull Location fromLocation,
 | 
			
		||||
                                                          @NotNull Location toLocation,
 | 
			
		||||
                                                          @NotNull ItemStack itemToSpawn,
 | 
			
		||||
                                                          double speed,
 | 
			
		||||
                                                          @NotNull ItemSpawnReason itemSpawnReason) {
 | 
			
		||||
        if (itemToSpawn.getType() == Material.AIR) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
@@ -935,7 +939,10 @@ public final class ItemUtils {
 | 
			
		||||
        return spawnedItem;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void spawnItemsFromCollection(@NotNull Player player, @NotNull Location location, @NotNull Collection<ItemStack> drops, @NotNull ItemSpawnReason itemSpawnReason) {
 | 
			
		||||
    public static void spawnItemsFromCollection(@NotNull Player player,
 | 
			
		||||
                                                @NotNull Location location,
 | 
			
		||||
                                                @NotNull Collection<ItemStack> drops,
 | 
			
		||||
                                                @NotNull ItemSpawnReason itemSpawnReason) {
 | 
			
		||||
        for (ItemStack drop : drops) {
 | 
			
		||||
            spawnItem(player, location, drop, itemSpawnReason);
 | 
			
		||||
        }
 | 
			
		||||
@@ -949,7 +956,11 @@ public final class ItemUtils {
 | 
			
		||||
     * @param drops collection to iterate over
 | 
			
		||||
     * @param sizeLimit the number of drops to process
 | 
			
		||||
     */
 | 
			
		||||
    public static void spawnItemsFromCollection(@Nullable Player player, @NotNull Location location, @NotNull Collection<ItemStack> drops, @NotNull ItemSpawnReason itemSpawnReason, int sizeLimit) {
 | 
			
		||||
    public static void spawnItemsFromCollection(@Nullable Player player,
 | 
			
		||||
                                                @NotNull Location location,
 | 
			
		||||
                                                @NotNull Collection<ItemStack> drops,
 | 
			
		||||
                                                @NotNull ItemSpawnReason itemSpawnReason,
 | 
			
		||||
                                                int sizeLimit) {
 | 
			
		||||
        ItemStack[] arrayDrops = drops.toArray(new ItemStack[0]);
 | 
			
		||||
 | 
			
		||||
        for(int i = 0; i < sizeLimit-1; i++) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user