Skip to content

Commit

Permalink
Fire starter, enchanting, and bug squashing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Sep 9, 2023
1 parent 7251d99 commit cf61871
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Random Loot
![CF downloads](https://cf.way2muchnoise.eu/301631.svg) ![CF Version](https://cf.way2muchnoise.eu/versions/301631.svg) [![Gradle Build](https://github.com/TheMarstonConnell/randomloot/actions/workflows/gradle.yml/badge.svg)](https://github.com/TheMarstonConnell/randomloot/actions/workflows/gradle.yml)

Introducing Looting like you've never seen it before! Have you ever felt that Minecraft didn't have enough tools and weapons to make you happy? Are you dissatisfied with the low amount of character each tool has? Ever wanted your tools to get better as you use them? Yes?!? Well then this is the mod for you!

Expand Down
44 changes: 43 additions & 1 deletion src/main/java/dev/marston/randomloot/loot/LootItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -133,14 +136,26 @@ public float getDestroySpeed(ItemStack stack, BlockState block) {
} else if (type == ToolType.SWORD) {
if (block.getBlock() == Blocks.COBWEB) {
return 15.0f;
}
}
return 1.0f;
}else {
return 1.0f;
}

return block.is(blocks) ? getDigSpeed(stack, type) : 1.0F;
}


@Override
public boolean isRepairable(ItemStack stack) {
return true;
}

@Override
public boolean isValidRepairItem(ItemStack tool, ItemStack material) {
return material.getItem().equals(Items.DIAMOND);
}

@Override
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {

Expand Down Expand Up @@ -207,6 +222,33 @@ public boolean hurtEnemy(ItemStack itemstack, LivingEntity hurtee, LivingEntity
});
return true;
}

@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment)
{

if (enchantment.category.equals(EnchantmentCategory.BREAKABLE)) { // all these items are breakable so we can enchant them first!
return true;
}

ToolType type = LootUtils.getToolType(stack);
if (enchantment.category.equals(EnchantmentCategory.DIGGER)) {
if (type == ToolType.AXE || type == ToolType.SHOVEL || type == ToolType.PICKAXE) {
return true;
}
}

if (enchantment.category.equals(EnchantmentCategory.WEAPON)) {
if (type == ToolType.AXE || type == ToolType.SWORD) {
return true;
}
}




return enchantment.category.canEnchant(stack.getItem());
}

@Override
public boolean mineBlock(ItemStack stack, Level level, BlockState blockState, BlockPos pos, LivingEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import dev.marston.randomloot.loot.modifiers.hurter.Fire;
import dev.marston.randomloot.loot.modifiers.hurter.HurtEffect;
import dev.marston.randomloot.loot.modifiers.users.DirtPlace;
import dev.marston.randomloot.loot.modifiers.users.FirePlace;
import dev.marston.randomloot.loot.modifiers.users.TorchPlace;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.effect.MobEffects;
Expand All @@ -34,7 +35,8 @@ public class ModifierRegistry {

public static Modifier TORCH_PLACE = register(new TorchPlace());
public static Modifier DIRT_PLACE = register(new DirtPlace());

public static Modifier FIRE_PLACE = register(new FirePlace());

public static Modifier FLAMING = register(new Fire());
public static Modifier CRITICAL = register(new Critical());
public static Modifier CHARGING = register(new Charging());
Expand All @@ -55,7 +57,7 @@ public class ModifierRegistry {
public static Modifier SPAWNER_FINDER = register(new TreasureFinder());

public static final Set<Modifier> BREAKERS = Set.of(/**EXPLODE,*/ LEARNING, ATTRACTING);
public static final Set<Modifier> USERS = Set.of(TORCH_PLACE, DIRT_PLACE);
public static final Set<Modifier> USERS = Set.of(TORCH_PLACE, DIRT_PLACE, FIRE_PLACE);
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.marston.randomloot.loot.modifiers.HoldModifier;
import dev.marston.randomloot.loot.modifiers.Modifier;
import net.minecraft.ChatFormatting;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -80,7 +81,7 @@ public String color() {

@Override
public String description() {
return "While holding the tool, get the " + effect.getDisplayName() + " effect.";
return "While holding the tool, get the " + I18n.get(effect.getDisplayName().getString()).toLowerCase() + " effect.";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.marston.randomloot.loot.modifiers.EntityHurtModifier;
import dev.marston.randomloot.loot.modifiers.Modifier;
import net.minecraft.ChatFormatting;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -79,7 +80,7 @@ public String color() {

@Override
public String description() {
return "When attacking with tool, apply the " + effect.getDisplayName() + " effect to the target.";
return "When attacking with tool, apply the " + I18n.get(effect.getDisplayName().getString()).toLowerCase() + " effect to the target.";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void use(UseOnContext ctx) {

@Override
public String description() {
return "Right clicking on the top of a block with the tool in hand will place a torch and use " + this.damage
return "Right clicking on the top of a block with the tool in hand will place a dirt block and use " + this.damage
+ " durability points.";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package dev.marston.randomloot.loot.modifiers.users;

import java.util.List;

import javax.annotation.Nullable;

import dev.marston.randomloot.loot.LootItem.ToolType;
import dev.marston.randomloot.loot.modifiers.Modifier;
import dev.marston.randomloot.loot.modifiers.ModifierRegistry;
import dev.marston.randomloot.loot.modifiers.UseModifier;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;

public class FirePlace implements UseModifier{
private String name;
private int damage;
private static final String DAMAGE = "DAMAGE";


public FirePlace(String name, int damage) {
this.name = name;
this.damage = damage;
}

public FirePlace() {
this.name = "Fire Starter";
this.damage = 2;
}

public Modifier clone() {
return new FirePlace();
}

@Override
public CompoundTag toNBT() {

CompoundTag tag = new CompoundTag();

tag.putString(NAME, name);
tag.putInt(DAMAGE, damage);

return tag;
}

@Override
public Modifier fromNBT(CompoundTag tag) {
return new FirePlace(tag.getString(NAME), tag.getInt(DAMAGE));
}

@Override
public String name() {
return name;
}

@Override
public String tagName() {
return "fire_place";
}

@Override
public String color() {
return ChatFormatting.RED.getName();
}

@Override
public void use(UseOnContext ctx) {


if (!ctx.getPlayer().isCrouching()) {
return;
}

BlockPos pos = ctx.getClickedPos();

if (ctx.getClickedFace() != Direction.UP) {
return;
}

pos = pos.above();


Level l = ctx.getLevel();

BlockState state = Blocks.FIRE.defaultBlockState();


l.setBlock(pos, state, 0);
l.gameEvent(GameEvent.BLOCK_PLACE, pos, GameEvent.Context.of(ctx.getPlayer(), state));


ctx.getItemInHand().hurtAndBreak(this.damage, ctx.getPlayer(), (event) -> {
event.broadcastBreakEvent(EquipmentSlot.MAINHAND);
});


}

@Override
public String description() {
return "Right clicking on the top of a block while crouching with the tool in hand will start a fire and use " + this.damage + " durability points.";
}

@Override
public void writeToLore(List<Component> list, boolean shift) {

MutableComponent comp = Modifier.makeComp(this.name(), this.color());
list.add(comp);



}

@Override
public Component writeDetailsToLore(@Nullable Level level) {

return null;
}

@Override
public boolean compatible(Modifier mod) {
return !ModifierRegistry.USERS.contains(mod);
}


@Override
public boolean forTool(ToolType type) {
return true;
}

}

0 comments on commit cf61871

Please sign in to comment.