Skip to content

Commit

Permalink
Merge branch 'mcMMO-Dev:master' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Nov 5, 2024
2 parents e85bac4 + 406a7ba commit e67e1a2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Version 2.2.024
Fixed a bug where Giga Drill breaker was giving out more drop chance than intended
Fixed errors when Fishing or using Shake ability
Significant optimizations made to reading new chunks for mcMMO
Significant optimizations to most block interactions in mcMMO code
Fixed a horrendous edge case where Tree Feller could cause a lot of lag

Notes:
Got a bit carried away and started to optimize stuff.
I was able to make Tree Feller way faster with optimizations in this update, I tested with a custom gigantic tree that had over 200,000 blocks felled (huge) and it only took 4 seconds total, in the previous version of mcMMO this would take over 2-3 minutes.

Part of this update focused on optimization, there's improvements of around 30% in CPU time for most code involving block interactions in mcMMO, which happens to be most code in mcMMO.
One of the optimizations made in this update removes an edge case where Tree Feller could cause a lot of lag, but the optimizations really are across the board in regards to any abilities that interact with blocks.

Version 2.2.023
Compatibility with Minecraft 1.21.3
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.2.024-SNAPSHOT</version>
<version>2.2.024</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>
Expand All @@ -15,6 +15,7 @@
</scm>

<properties>
<!-- <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>-->
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
<adventure.version>4.3.5-SNAPSHOT</adventure.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void excavationBlockCheck(BlockState blockState) {
excavationBlockCheck(blockState.getBlock());
}


public void excavationBlockCheck(Block block) {
int xp = ExperienceConfig.getInstance().getXp(PrimarySkillType.EXCAVATION, block.getType());
requireNonNull(block, "excavationBlockCheck: block cannot be null");
Expand Down Expand Up @@ -135,6 +134,7 @@ public void printExcavationDebug(Player player, Block block) {
*/
public void gigaDrillBreaker(Block block) {
excavationBlockCheck(block);
excavationBlockCheck(block);

SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(),
mcMMO.p.getGeneralConfig().getAbilityToolDamage());
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.adapter.BiomeAdapter;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

public final class Fishing {

protected static final HashMap<Material, List<Enchantment>> ENCHANTABLE_CACHE = new HashMap<>();

public static Set<Biome> masterAnglerBiomes = BiomeAdapter.WATER_BIOMES;
public static Set<Biome> iceFishingBiomes = BiomeAdapter.ICE_BIOMES;
static final HashMap<Material, List<Enchantment>> ENCHANTABLE_CACHE = new HashMap<>();

private Fishing() {}

Expand All @@ -30,7 +24,7 @@ private Fishing() {}
* Targeted entity
* @return possibleDrops List of ItemStack that can be dropped
*/
protected static List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
static List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
if (FishingTreasureConfig.getInstance().shakeMap.containsKey(target.getType()))
return FishingTreasureConfig.getInstance().shakeMap.get(target.getType());

Expand All @@ -44,7 +38,7 @@ protected static List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
* List of ItemStack that can be dropped
* @return Chosen ItemStack
*/
protected static ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
static ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
int dropProbability = Misc.getRandom().nextInt(100);
double cumulatedProbability = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.gmail.nossr50.runnables.skills.MasterAnglerTask;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.*;
import com.gmail.nossr50.util.adapter.BiomeAdapter;
import com.gmail.nossr50.util.compat.layers.skills.MasterAnglerCompatibilityLayer;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.random.ProbabilityUtil;
Expand Down Expand Up @@ -173,7 +174,8 @@ public boolean canIceFish(Block block) {
}

// Make sure this is a body of water, not just a block of ice.
if (!Fishing.iceFishingBiomes.contains(block.getBiome()) && (block.getRelative(BlockFace.DOWN, 3).getType() != Material.WATER)) {
if (!BiomeAdapter.ICE_BIOMES.contains(block.getBiome())
&& (block.getRelative(BlockFace.DOWN, 3).getType() != Material.WATER)) {
return false;
}

Expand Down
57 changes: 28 additions & 29 deletions src/main/java/com/gmail/nossr50/util/adapter/BiomeAdapter.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
package com.gmail.nossr50.util.adapter;

import org.bukkit.block.Biome;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.function.Function;

public class BiomeAdapter {
public static final Set<Biome> WATER_BIOMES;
public static final Set<Biome> ICE_BIOMES;

static final List<String> knownColdBiomes = Arrays.asList("COLD_OCEAN", "DEEP_COLD_OCEAN", "ICE_SPIKES",
"FROZEN_PEAKS", "FROZEN_OCEAN", "FROZEN_RIVER", "DEEP_FROZEN_OCEAN", "SNOWY_TAIGA",
"OLD_GROWTH_PINE_TAIGA", "OLD_GROWTH_SPRUCE_TAIGA", "TAIGA", "SNOWY_SLOPES", "SNOWY_BEACH");

static {
final List<Biome> allBiomes = getAllBiomes();
final Set<Biome> waterBiomes = new HashSet<>();
final Set<Biome> iceBiomes = new HashSet<>();
for (Biome biome : allBiomes) {
String biomeName = getBiomeName(biome);
if (isWater(biomeName) && !isCold(biomeName)) {
waterBiomes.add(biome);
} else if (isCold(biomeName)) {
iceBiomes.add(biome);
}
}
WATER_BIOMES = Collections.unmodifiableSet(waterBiomes);
knownColdBiomes.stream()
.map(biomeFromString())
.filter(Objects::nonNull)
.forEach(iceBiomes::add);
ICE_BIOMES = Collections.unmodifiableSet(iceBiomes);
}

@SuppressWarnings("deprecation")
private static List<Biome> getAllBiomes() {
return Arrays.asList(Biome.values());
}

@SuppressWarnings("deprecation")
private static String getBiomeName(Biome biome) {
return biome.name();
}

private static boolean isWater(String name) {
return name.contains("RIVER") || name.contains("OCEAN");
}

private static boolean isCold(String name) {
return (name.contains("COLD") || name.contains("ICE")
|| name.contains("FROZEN") || name.contains("TAIGA")) && !name.contains("WARM");
private static @NotNull Function<String, Biome> biomeFromString() {
return potentialBiome -> {
try {
Class<?> biomeClass = Class.forName("org.bukkit.block.Biome");
Method methodValueOf = biomeClass.getMethod("valueOf", String.class);
return methodValueOf.invoke(null, potentialBiome) == null
? null
: (Biome) methodValueOf.invoke(null, potentialBiome);
} catch (IllegalArgumentException | NullPointerException e) {
return null;
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException
| IllegalAccessException e) {
// Thrown when the method is not found or the class is not found
throw new RuntimeException(e);
}
};
}
}

0 comments on commit e67e1a2

Please sign in to comment.