-
Notifications
You must be signed in to change notification settings - Fork 754
/
ToolHarvestLogicTest.java
102 lines (81 loc) · 4.24 KB
/
ToolHarvestLogicTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package slimeknights.tconstruct.library.tools.helper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.registries.ForgeRegistries;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import slimeknights.mantle.data.predicate.block.BlockPredicate;
import slimeknights.tconstruct.fixture.MaterialItemFixture;
import slimeknights.tconstruct.fixture.MaterialStatsFixture;
import slimeknights.tconstruct.fixture.ToolDefinitionFixture;
import slimeknights.tconstruct.library.tools.definition.ToolDefinition;
import slimeknights.tconstruct.library.tools.definition.ToolDefinitionDataBuilder;
import slimeknights.tconstruct.library.tools.definition.module.material.PartStatsModule;
import slimeknights.tconstruct.library.tools.definition.module.mining.IsEffectiveModule;
import slimeknights.tconstruct.library.tools.definition.module.mining.MiningSpeedToolHook;
import slimeknights.tconstruct.library.tools.item.ModifiableItem;
import slimeknights.tconstruct.library.tools.item.ToolItemTest;
import slimeknights.tconstruct.library.tools.stat.ToolStats;
import static org.assertj.core.api.Assertions.assertThat;
class ToolHarvestLogicTest extends ToolItemTest {
private static ModifiableItem pickaxeTool;
@BeforeAll
synchronized static void beforeAllToolLogic() {
MaterialItemFixture.init();
if (pickaxeTool == null) {
pickaxeTool = new ModifiableItem(new Item.Properties().stacksTo(1), ToolDefinitionFixture.getStandardToolDefinition());
ForgeRegistries.ITEMS.register(new ResourceLocation("test", "pickaxe"), pickaxeTool);
}
}
@Test
void calcSpeed_dirt_notEffective() {
ItemStack tool = buildTestTool(pickaxeTool);
float speed = MiningSpeedToolHook.getDestroySpeed(tool, Blocks.DIRT.defaultBlockState());
assertThat(speed).isEqualTo(1f);
}
@Test
void calcSpeed_cobble_effective() {
ItemStack tool = buildTestTool(pickaxeTool);
float speed = MiningSpeedToolHook.getDestroySpeed(tool, Blocks.COBBLESTONE.defaultBlockState());
assertThat(speed).isEqualTo(MaterialStatsFixture.MATERIAL_STATS_HEAD.getMiningSpeed());
}
@Test
void calcSpeed_obsidian_notEnoughHarvestLevel() {
ItemStack tool = buildTestTool(pickaxeTool);
float speed = MiningSpeedToolHook.getDestroySpeed(tool, Blocks.OBSIDIAN.defaultBlockState());
assertThat(speed).isEqualTo(1f);
}
@Test
void calcSpeed_broken_slowButNotZero() {
ItemStack tool = buildTestTool(pickaxeTool);
breakTool(tool);
float speed = MiningSpeedToolHook.getDestroySpeed(tool, Blocks.DIRT.defaultBlockState());
assertThat(speed).isLessThan(1f);
assertThat(speed).isGreaterThan(0f);
}
@Test
void calcSpeed_effective_withMiningModifier() {
float modifier = 2f;
ToolDefinition definition = ToolDefinition.builder(new ResourceLocation("test", "mining_tool")).skipRegister().build();
definition.setData(ToolDefinitionDataBuilder
.builder()
.module(new IsEffectiveModule(BlockPredicate.set(Blocks.COBBLESTONE)))
.module(PartStatsModule.meleeHarvest()
.part(MaterialItemFixture.MATERIAL_ITEM_HEAD)
.part(MaterialItemFixture.MATERIAL_ITEM_HANDLE)
.part(MaterialItemFixture.MATERIAL_ITEM_EXTRA).build())
.multiplier(ToolStats.MINING_SPEED, modifier)
.build());
ModifiableItem toolWithMiningModifier = new ModifiableItem(new Item.Properties(), definition);
ForgeRegistries.ITEMS.register(new ResourceLocation("test", "tool_with_mining_modifier"), toolWithMiningModifier);
ItemStack tool = buildTestTool(toolWithMiningModifier);
// boosted by correct block
float speed = MiningSpeedToolHook.getDestroySpeed(tool, Blocks.COBBLESTONE.defaultBlockState());
assertThat(speed).isEqualTo(MaterialStatsFixture.MATERIAL_STATS_HEAD.getMiningSpeed() * modifier);
// default speed
speed = MiningSpeedToolHook.getDestroySpeed(tool, Blocks.STONE.defaultBlockState());
assertThat(speed).isEqualTo(1.0f);
}
}