Skip to content

Commit

Permalink
added tool leveling & unbreaking
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Jan 13, 2024
1 parent 570733c commit ed332f9
Show file tree
Hide file tree
Showing 29 changed files with 473 additions and 55 deletions.
90 changes: 48 additions & 42 deletions MODIFIERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,36 @@
This is a full list of modifiers in the game and a description of what they do.
## Breakers
These effects are applied when breaking blocks.
### Melting
**id:** `melting` | **crafting:** `minecraft:magma_cream` ![magma_cream](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/magma_cream.png)
### Magnetic
**id:** `attracting` | **crafting:** `minecraft:iron_block` ![iron_block](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/iron_block.png)

**Decription:** Items dropped by blocks broken with this tool will be smelted.
**Decription:** Upon breaking a block (allowed by tool type), all items at that block's position will teleport to you.
### Learning
**id:** `learning` | **crafting:** `minecraft:book` ![book](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/book.png)

**Decription:** After breaking 10 blocks as allowed by this tool, gain 3 experience points.
### Explosive
**id:** `explode` | **crafting:** `minecraft:tnt` ![tnt](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/tnt.png)

**Decription:** Upon breaking a block (allowed by tool type), the current block position will explode causing damage to surrounding blocks.
### Magnetic
**id:** `attracting` | **crafting:** `minecraft:iron_block` ![iron_block](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/iron_block.png)
### Melting
**id:** `melting` | **crafting:** `minecraft:magma_cream` ![magma_cream](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/magma_cream.png)

**Decription:** Upon breaking a block (allowed by tool type), all items at that block's position will teleport to you.
**Decription:** Items dropped by blocks broken with this tool will be smelted.
### Veiny
**id:** `veiny` | **crafting:** `minecraft:diamond_pickaxe` ![diamond_pickaxe](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/diamond_pickaxe.png)

**Decription:** Breaking any block while crouching will cause all blocks of the same type adjacent to it to break up to 5 in each direction.
### Explosive
**id:** `explode` | **crafting:** `minecraft:tnt` ![tnt](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/tnt.png)

**Decription:** Upon breaking a block (allowed by tool type), the current block position will explode causing damage to surrounding blocks.
## Holders
These effects are applied when holding the tool.
### Filling
**id:** `filling` | **crafting:** `minecraft:cake` ![cake](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/cake.png)

**Decription:** While holding the tool, get the saturation effect.
### Appley
**id:** `absorption` | **crafting:** `minecraft:golden_apple` ![golden_apple](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/golden_apple.png)

**Decription:** While holding the tool, get the absorption effect.
### Living
**id:** `living` | **crafting:** `minecraft:moss_block` ![moss_block](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/moss_block.png)

**Decription:** While holding the tool, it will randomly heal itself
### Hasty
**id:** `hasty` | **crafting:** `minecraft:sugar` ![sugar](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/sugar.png)

**Decription:** While holding the tool, get the Haste I effect.
### Detecting
**id:** `detecting` | **crafting:** `minecraft:spyglass` ![spyglass](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/spyglass.png)

Expand All @@ -44,42 +40,42 @@ These effects are applied when holding the tool.
**id:** `spawner` | **crafting:** `minecraft:mossy_cobblestone` ![mossy_cobblestone](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/mossy_cobblestone.png)

**Decription:** While holding the spawners around you will glow.
### Hasty
**id:** `hasty` | **crafting:** `minecraft:sugar` ![sugar](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/sugar.png)
### Appley
**id:** `absorption` | **crafting:** `minecraft:golden_apple` ![golden_apple](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/golden_apple.png)

**Decription:** While holding the tool, get the absorption effect.
### Filling
**id:** `filling` | **crafting:** `minecraft:cake` ![cake](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/cake.png)

**Decription:** While holding the tool, get the Haste effect.
**Decription:** While holding the tool, get the saturation effect.
### Rainy
**id:** `rainy` | **crafting:** `minecraft:cauldron` ![cauldron](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/cauldron.png)

**Decription:** While holding the tool in the rain, mine faster!
## Users
These effects are applied when right clicking.
### Heartha's Grace
**id:** `dirt_place` | **crafting:** `minecraft:dirt` ![dirt](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/dirt.png)

**Decription:** Right clicking on the top of a block with the tool in hand will place a dirt block and use 1 durability points.
### Fire Starter
**id:** `fire_place` | **crafting:** `minecraft:flint_and_steel` ![flint_and_steel](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/flint_and_steel.png)

**Decription:** Right clicking on the top of a block while crouching with the tool in hand will start a fire and use 2 durability points.
### Flame Thrower
**id:** `flame_thrower` | **crafting:** `minecraft:fire_charge` ![fire_charge](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/fire_charge.png)

**Decription:** Right clicking throws a fire ball.
### Spelunking
**id:** `torch_place` | **crafting:** `minecraft:glowstone` ![glowstone](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/glowstone.png)

**Decription:** Right clicking on the top of a block with the tool in hand will place a torch and use 10 durability points.
### Flame Thrower
**id:** `flame_thrower` | **crafting:** `minecraft:fire_charge` ![fire_charge](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/fire_charge.png)
### Heartha's Grace
**id:** `dirt_place` | **crafting:** `minecraft:dirt` ![dirt](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/dirt.png)

**Decription:** Right clicking throws a fire ball.
**Decription:** Right clicking on the top of a block with the tool in hand will place a dirt block and use 1 durability points.
## Hurters
These effects are applied when hurting enemies.
### Dexterous
**id:** `combo` | **crafting:** `minecraft:chorus_fruit` ![chorus_fruit](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/chorus_fruit.png)

**Decription:** Hitting enemies within 2 seconds after hitting them deals an extra 25% damage.
### Necrotic
**id:** `necrotic` | **crafting:** `minecraft:wither_skeleton_skull` ![wither_skeleton_skull](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/wither_skeleton_skull.png)
### Charged
**id:** `charged` | **crafting:** `minecraft:lightning_rod` ![lightning_rod](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/lightning_rod.png)

**Decription:** Heals 10% of damage dealt to target.
**Decription:** After 7 seconds, hitting and enemy will summon a lightning bolt and empty the charge meter.
### Withering
**id:** `wither` | **crafting:** `minecraft:wither_rose` ![wither_rose](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/wither_rose.png)

Expand All @@ -88,19 +84,29 @@ These effects are applied when hurting enemies.
**id:** `critical` | **crafting:** `minecraft:ghast_tear` ![ghast_tear](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/ghast_tear.png)

**Decription:** Always critically strikes enemy.
### Poisonous
**id:** `poison` | **crafting:** `minecraft:poisonous_potato` ![poisonous_potato](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/poisonous_potato.png)

**Decription:** When attacking with tool, apply the poison effect to the target.
### Blinding
**id:** `blinding` | **crafting:** `minecraft:carrot` ![carrot](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/carrot.png)

**Decription:** When attacking with tool, apply the blindness effect to the target.
### Dexterous
**id:** `combo` | **crafting:** `minecraft:chorus_fruit` ![chorus_fruit](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/chorus_fruit.png)

**Decription:** Hitting enemies within 2 seconds after hitting them deals an extra 25% damage.
### Necrotic
**id:** `necrotic` | **crafting:** `minecraft:wither_skeleton_skull` ![wither_skeleton_skull](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/wither_skeleton_skull.png)

**Decription:** Heals 10% of damage dealt to target.
### Poisonous
**id:** `poison` | **crafting:** `minecraft:poisonous_potato` ![poisonous_potato](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/poisonous_potato.png)

**Decription:** When attacking with tool, apply the poison effect to the target.
### Flaming
**id:** `flaming` | **crafting:** `minecraft:blaze_rod` ![blaze_rod](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/blaze_rod.png)

**Decription:** Sets enemy on fire for 2 seconds.
### Charged
**id:** `charged` | **crafting:** `minecraft:lightning_rod` ![lightning_rod](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/lightning_rod.png)
## Misc.
These effects are general and don't fit into any other categories.
### Unbreaking
**id:** `unbreaking` | **crafting:** `minecraft:obsidian` ![obsidian](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/obsidian.png)

**Decription:** After 7 seconds, hitting and enemy will summon a lightning bolt and empty the charge meter.
**Decription:** This tool has a 20% chance of not taking damage.
3 changes: 3 additions & 0 deletions src/main/java/dev/marston/randomloot/GenWiki.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private static void writeModifiers(FileWriter f) throws IOException {
write("These effects are applied when hurting enemies.", f);
writeMods(ModifierRegistry.HURTERS, f);

write("## Misc.", f);
write("These effects are general and don't fit into any other categories.", f);
writeMods(ModifierRegistry.MISC, f);
}

public static void genWiki() {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/dev/marston/randomloot/loot/LootItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import dev.marston.randomloot.loot.modifiers.EntityHurtModifier;
import dev.marston.randomloot.loot.modifiers.HoldModifier;
import dev.marston.randomloot.loot.modifiers.Modifier;
import dev.marston.randomloot.loot.modifiers.Unbreaking;
import dev.marston.randomloot.loot.modifiers.UseModifier;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -230,6 +231,18 @@ public boolean hurtEnemy(ItemStack itemstack, LivingEntity hurtee, LivingEntity
}

}

if (mod instanceof Unbreaking) {
if (!Config.traitEnabled(mod.tagName())) {
continue;
}
Unbreaking unbreaking = (Unbreaking) mod;

if (unbreaking.test(hurtee.level())) {
shouldSkipBreak = true;
}

}
}
if (!shouldSkipBreak) {
itemstack.hurtAndBreak(1, hurter, (p_43296_) -> {
Expand Down Expand Up @@ -280,6 +293,18 @@ public boolean mineBlock(ItemStack stack, Level level, BlockState blockState, Bl
shouldSkipBreak = true;
}
}

if (mod instanceof Unbreaking) {
if (!Config.traitEnabled(mod.tagName())) {
continue;
}
Unbreaking unbreaking = (Unbreaking) mod;

if (unbreaking.test(level)) {
shouldSkipBreak = true;
}

}
}

if (!shouldSkipBreak) {
Expand Down
89 changes: 85 additions & 4 deletions src/main/java/dev/marston/randomloot/loot/LootUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,28 @@ public static List<Modifier> getModifiers(ItemStack item) {
public static ItemStack addModifier(ItemStack item, Modifier mod) {

CompoundTag modifiers = item.getOrCreateTagElement(Modifier.MODTAG);

CompoundTag newTag = mod.toNBT();
modifiers.put(mod.tagName(), newTag);

boolean oldModFound = modifiers.contains(mod.tagName()); // does that tag already exist on the tool?

if (!oldModFound) { // tag doesn't exist so we're adding a new trait.

modifiers.put(mod.tagName(), newTag);
item.removeTagKey(Modifier.MODTAG);
item.addTagElement(Modifier.MODTAG, modifiers);
return item;

}

CompoundTag oldmod = modifiers.getCompound(mod.tagName());
Modifier oldModifier = mod.fromNBT(oldmod);

if (!oldModifier.canLevel()) {
return item;
}

oldModifier.levelUp();
modifiers.put(oldModifier.tagName(), oldModifier.toNBT());

item.removeTagKey(Modifier.MODTAG);
item.addTagElement(Modifier.MODTAG, modifiers);
Expand Down Expand Up @@ -343,8 +362,10 @@ public static void generateNewTrait(ItemStack stack, ToolType type) {
for (Modifier modifier : mods) {

if (modifier.tagName() == newMod.tagName()) {
compatible = false;
break;
if (!modifier.canLevel()) {
compatible = false;
break;
}
}

if (!modifier.compatible(newMod)) {
Expand Down Expand Up @@ -512,4 +533,64 @@ public static boolean generateTool(ServerPlayer player, Level level) {
return true;
}

public static String roman(int input) {
if (input < 1 || input > 3999)
return "Invalid Roman Number Value";
String s = "";
while (input >= 1000) {
s += "M";
input -= 1000;
}
while (input >= 900) {
s += "CM";
input -= 900;
}
while (input >= 500) {
s += "D";
input -= 500;
}
while (input >= 400) {
s += "CD";
input -= 400;
}
while (input >= 100) {
s += "C";
input -= 100;
}
while (input >= 90) {
s += "XC";
input -= 90;
}
while (input >= 50) {
s += "L";
input -= 50;
}
while (input >= 40) {
s += "XL";
input -= 40;
}
while (input >= 10) {
s += "X";
input -= 10;
}
while (input >= 9) {
s += "IX";
input -= 9;
}
while (input >= 5) {
s += "V";
input -= 5;
}
while (input >= 4) {
s += "IV";
input -= 4;
}
while (input >= 1) {
s += "I";
input -= 1;
}
return s;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ public static void TrackEntityParticle(Level level, Entity e, ParticleOptions pa
public boolean compatible(Modifier mod);

public boolean forTool(ToolType type);

public boolean canLevel();

public void levelUp();
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ public class ModifierRegistry {
public static Modifier SPAWNER_FINDER = register(new TreasureFinder());
public static Modifier LIVING = register(new Healing());

public static Modifier UNBREAKING = register(new Unbreaking());

public static final Set<Modifier> BREAKERS = Set.of(EXPLODE, LEARNING, ATTRACTING, VEINY, MELTING);
public static final Set<Modifier> USERS = Set.of(TORCH_PLACE, DIRT_PLACE, FIRE_PLACE, FIRE_BALL);
public static final Set<Modifier> HURTERS = Set.of(CRITICAL, CHARGING, FLAMING, COMBO, DRAINING, POISONOUS,
WITHERING, BLINDING);
public static final Set<Modifier> HOLDERS = Set.of(HASTY, ABSORBTION, FILLING, RAINY, ORE_FINDER, SPAWNER_FINDER,
LIVING);

public static final Set<Modifier> MISC = Set.of(UNBREAKING);

public static Modifier register(Modifier modifier) {

String tagName = modifier.tagName();
Expand Down
Loading

0 comments on commit ed332f9

Please sign in to comment.