Skip to content

Commit

Permalink
Tree Feller non-wood drop rate reduced by 90%
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Jan 15, 2024
1 parent dda5b45 commit 301239d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Version 2.2.000
TODO: Add unit test to determine crossbow or bow skill
TODO: Add unit test for trident xp processing
TODO: Add missing entries to changelog
Tree Feller now drops 90% less non-wood blocks (leaves/etc) on average
Replaced 'Experience_Formula.Modifier' in experience.yml with 'Experience_Formula.Skill_Multiplier' which is easier to understand and less prone to divide by zero bugs
Treasure drop rate from Shake, Fishing, Hylian, and Excavation now benefit from the Luck perk
Added 'Send_To_Console' settings to chat.yml to toggle sending party or admin chat messages to console
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.2.000-BETA-02-SNAPSHOT</version>
<version>2.2.000-BETA-03-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

//TODO: Seems to not be using the item drop event for bonus drops, may want to change that.. or may not be able to be changed?
public class WoodcuttingManager extends SkillManager {
Expand Down Expand Up @@ -89,6 +90,13 @@ private boolean checkCleanCutsActivation(Material material) {
*/
public void processBonusDropCheck(@NotNull BlockState blockState) {
//TODO: Why isn't this using the item drop event? Potentially because of Tree Feller? This should be adjusted either way.
if (BlockUtils.isNonWoodPartOfTree(blockState)) {
// Leafs should drop less
if (ThreadLocalRandom.current().nextInt(100) < 90) {
return;
}
}

if(mcMMO.p.getGeneralConfig().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, blockState.getType())) {
//Mastery enabled for player
if(Permissions.canUseSubSkill(getPlayer(), SubSkillType.WOODCUTTING_CLEAN_CUTS)) {
Expand Down
55 changes: 30 additions & 25 deletions src/test/java/com/gmail/nossr50/MMOTestEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.logging.Logger;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

public abstract class MMOTestEnvironment {
protected MockedStatic<mcMMO> mockedMcMMO;
Expand Down Expand Up @@ -62,23 +63,24 @@ public abstract class MMOTestEnvironment {
protected String playerName = "testPlayer";

protected ChunkManager chunkManager;
protected MaterialMapStore materialMapStore;

protected void mockBaseEnvironment(Logger logger) throws InvalidSkillException {
mockedMcMMO = Mockito.mockStatic(mcMMO.class);
mcMMO.p = Mockito.mock(mcMMO.class);
Mockito.when(mcMMO.p.getLogger()).thenReturn(logger);
when(mcMMO.p.getLogger()).thenReturn(logger);

// place store
chunkManager = Mockito.mock(ChunkManager.class);
Mockito.when(mcMMO.getPlaceStore()).thenReturn(chunkManager);
when(mcMMO.getPlaceStore()).thenReturn(chunkManager);

// shut off mod manager for woodcutting
Mockito.when(mcMMO.getModManager()).thenReturn(Mockito.mock(ModManager.class));
Mockito.when(mcMMO.getModManager().isCustomLog(any())).thenReturn(false);
when(mcMMO.getModManager()).thenReturn(Mockito.mock(ModManager.class));
when(mcMMO.getModManager().isCustomLog(any())).thenReturn(false);

// chat config
mockedChatConfig = Mockito.mockStatic(ChatConfig.class);
Mockito.when(ChatConfig.getInstance()).thenReturn(Mockito.mock(ChatConfig.class));
when(ChatConfig.getInstance()).thenReturn(Mockito.mock(ChatConfig.class));

// general config
mockGeneralConfig();
Expand All @@ -94,54 +96,57 @@ protected void mockBaseEnvironment(Logger logger) throws InvalidSkillException {

// wire skill tools
this.skillTools = new SkillTools(mcMMO.p);
Mockito.when(mcMMO.p.getSkillTools()).thenReturn(skillTools);
when(mcMMO.p.getSkillTools()).thenReturn(skillTools);

this.transientEntityTracker = new TransientEntityTracker();
Mockito.when(mcMMO.getTransientEntityTracker()).thenReturn(transientEntityTracker);
when(mcMMO.getTransientEntityTracker()).thenReturn(transientEntityTracker);

mockPermissions();

mockedRankUtils = Mockito.mockStatic(RankUtils.class);

// wire server
this.server = Mockito.mock(Server.class);
Mockito.when(mcMMO.p.getServer()).thenReturn(server);
when(mcMMO.p.getServer()).thenReturn(server);

// wire plugin manager
this.pluginManager = Mockito.mock(PluginManager.class);
Mockito.when(server.getPluginManager()).thenReturn(pluginManager);
when(server.getPluginManager()).thenReturn(pluginManager);

// wire world
this.world = Mockito.mock(World.class);

// wire Misc
this.mockedMisc = Mockito.mockStatic(Misc.class);
Mockito.when(Misc.getBlockCenter(any())).thenReturn(new Location(world, 0, 0, 0));
when(Misc.getBlockCenter(any())).thenReturn(new Location(world, 0, 0, 0));

// setup player and player related mocks after everything else
this.player = Mockito.mock(Player.class);
Mockito.when(player.getUniqueId()).thenReturn(playerUUID);
when(player.getUniqueId()).thenReturn(playerUUID);

// wire inventory
this.playerInventory = Mockito.mock(PlayerInventory.class);
Mockito.when(player.getInventory()).thenReturn(playerInventory);
when(player.getInventory()).thenReturn(playerInventory);

// PlayerProfile and McMMOPlayer are partially mocked
playerProfile = new PlayerProfile("testPlayer", player.getUniqueId(), 0);
mmoPlayer = Mockito.spy(new McMMOPlayer(player, playerProfile));

// wire user manager
this.mockedUserManager = Mockito.mockStatic(UserManager.class);
Mockito.when(UserManager.getPlayer(player)).thenReturn(mmoPlayer);
when(UserManager.getPlayer(player)).thenReturn(mmoPlayer);

this.materialMapStore = new MaterialMapStore();
when(mcMMO.getMaterialMapStore()).thenReturn(materialMapStore);
}

private void mockPermissions() {
mockedPermissions = Mockito.mockStatic(Permissions.class);
Mockito.when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(true);
Mockito.when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(true);
Mockito.when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(true);
Mockito.when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(true);
Mockito.when(Permissions.lucky(player, PrimarySkillType.WOODCUTTING)).thenReturn(false); // player is not lucky
when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(true);
when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(true);
when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(true);
when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(true);
when(Permissions.lucky(player, PrimarySkillType.WOODCUTTING)).thenReturn(false); // player is not lucky
}

private void mockRankConfig() {
Expand All @@ -150,24 +155,24 @@ private void mockRankConfig() {

private void mockAdvancedConfig() {
this.advancedConfig = Mockito.mock(AdvancedConfig.class);
Mockito.when(mcMMO.p.getAdvancedConfig()).thenReturn(advancedConfig);
when(mcMMO.p.getAdvancedConfig()).thenReturn(advancedConfig);
}

private void mockGeneralConfig() {
generalConfig = Mockito.mock(GeneralConfig.class);
Mockito.when(generalConfig.getTreeFellerThreshold()).thenReturn(100);
Mockito.when(generalConfig.getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, Material.OAK_LOG)).thenReturn(true);
Mockito.when(generalConfig.getLocale()).thenReturn("en_US");
Mockito.when(mcMMO.p.getGeneralConfig()).thenReturn(generalConfig);
when(generalConfig.getTreeFellerThreshold()).thenReturn(100);
when(generalConfig.getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, Material.OAK_LOG)).thenReturn(true);
when(generalConfig.getLocale()).thenReturn("en_US");
when(mcMMO.p.getGeneralConfig()).thenReturn(generalConfig);
}

private void mockExperienceConfig() {
experienceConfig = Mockito.mockStatic(ExperienceConfig.class);

Mockito.when(ExperienceConfig.getInstance()).thenReturn(Mockito.mock(ExperienceConfig.class));
when(ExperienceConfig.getInstance()).thenReturn(Mockito.mock(ExperienceConfig.class));

// Combat
Mockito.when(ExperienceConfig.getInstance().getCombatXP("Cow")).thenReturn(1D);
when(ExperienceConfig.getInstance().getCombatXP("Cow")).thenReturn(1D);
}

protected void cleanupBaseEnvironment() {
Expand Down

0 comments on commit 301239d

Please sign in to comment.