From cf618715d596d3fdd2d3c4b66afa7b759be9a3ee Mon Sep 17 00:00:00 2001 From: marston Date: Sat, 9 Sep 2023 17:54:40 -0400 Subject: [PATCH] Fire starter, enchanting, and bug squashing --- README.md | 1 + .../dev/marston/randomloot/loot/LootItem.java | 44 +++++- .../loot/modifiers/ModifierRegistry.java | 6 +- .../loot/modifiers/holders/Effect.java | 3 +- .../loot/modifiers/hurter/HurtEffect.java | 3 +- .../loot/modifiers/users/DirtPlace.java | 2 +- .../loot/modifiers/users/FirePlace.java | 141 ++++++++++++++++++ 7 files changed, 194 insertions(+), 6 deletions(-) create mode 100644 src/main/java/dev/marston/randomloot/loot/modifiers/users/FirePlace.java diff --git a/README.md b/README.md index 8b9960c..ddd1b70 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/src/main/java/dev/marston/randomloot/loot/LootItem.java b/src/main/java/dev/marston/randomloot/loot/LootItem.java index c4f0b4b..cf9f983 100644 --- a/src/main/java/dev/marston/randomloot/loot/LootItem.java +++ b/src/main/java/dev/marston/randomloot/loot/LootItem.java @@ -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; @@ -133,7 +136,8 @@ 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; } @@ -141,6 +145,17 @@ public float getDestroySpeed(ItemStack stack, BlockState block) { 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) { @@ -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) { diff --git a/src/main/java/dev/marston/randomloot/loot/modifiers/ModifierRegistry.java b/src/main/java/dev/marston/randomloot/loot/modifiers/ModifierRegistry.java index 98a314b..116bb29 100644 --- a/src/main/java/dev/marston/randomloot/loot/modifiers/ModifierRegistry.java +++ b/src/main/java/dev/marston/randomloot/loot/modifiers/ModifierRegistry.java @@ -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; @@ -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()); @@ -55,7 +57,7 @@ public class ModifierRegistry { public static Modifier SPAWNER_FINDER = register(new TreasureFinder()); public static final Set BREAKERS = Set.of(/**EXPLODE,*/ LEARNING, ATTRACTING); - public static final Set USERS = Set.of(TORCH_PLACE, DIRT_PLACE); + public static final Set USERS = Set.of(TORCH_PLACE, DIRT_PLACE, FIRE_PLACE); public static final Set HURTERS = Set.of(CRITICAL, CHARGING, FLAMING, COMBO, DRAINING, POISONOUS, WITHERING, BLINDING); public static final Set HOLDERS = Set.of(HASTY, ABSORBTION, FILLING, RAINY, ORE_FINDER, SPAWNER_FINDER); diff --git a/src/main/java/dev/marston/randomloot/loot/modifiers/holders/Effect.java b/src/main/java/dev/marston/randomloot/loot/modifiers/holders/Effect.java index 70d15ba..87aad23 100644 --- a/src/main/java/dev/marston/randomloot/loot/modifiers/holders/Effect.java +++ b/src/main/java/dev/marston/randomloot/loot/modifiers/holders/Effect.java @@ -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; @@ -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 diff --git a/src/main/java/dev/marston/randomloot/loot/modifiers/hurter/HurtEffect.java b/src/main/java/dev/marston/randomloot/loot/modifiers/hurter/HurtEffect.java index 934310c..05d69e9 100644 --- a/src/main/java/dev/marston/randomloot/loot/modifiers/hurter/HurtEffect.java +++ b/src/main/java/dev/marston/randomloot/loot/modifiers/hurter/HurtEffect.java @@ -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; @@ -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 diff --git a/src/main/java/dev/marston/randomloot/loot/modifiers/users/DirtPlace.java b/src/main/java/dev/marston/randomloot/loot/modifiers/users/DirtPlace.java index a90b1b3..d6968f2 100644 --- a/src/main/java/dev/marston/randomloot/loot/modifiers/users/DirtPlace.java +++ b/src/main/java/dev/marston/randomloot/loot/modifiers/users/DirtPlace.java @@ -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."; } diff --git a/src/main/java/dev/marston/randomloot/loot/modifiers/users/FirePlace.java b/src/main/java/dev/marston/randomloot/loot/modifiers/users/FirePlace.java new file mode 100644 index 0000000..bbaab7c --- /dev/null +++ b/src/main/java/dev/marston/randomloot/loot/modifiers/users/FirePlace.java @@ -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 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; + } + +}