Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Add Miner
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldorion committed Jun 24, 2022
1 parent eaa286f commit c2ecdd7
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 10 deletions.
3 changes: 2 additions & 1 deletion ENCHANTMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
- Lightning Bolt Protection: Fewer damages when struck by a lightning bolt
- Second chance (Chestplate): The player is kept to 0.5 hearth, but if durability is 1, the chestplate breaks, otherwise the durability is set to 1.
- Magma Walker: Change lava into magma blocks when walking on it and disable damages when walking on magma blocks, but removes 1 durability for every damage
- Farmer: Till the dirt and grass blocks in a square with a radius of *level* * 2 + 1
- Farmer: Till the dirt and grass blocks in a square with a diameter of *level* * 2 + 1
- Miner: Mine blocks in a square with a diameter of *level* * 2 + 1
- Sleepless Night: You can't sleep!
- Multi Arrows (Bow): +1 arrow / level
- Unvanishable: Each time, the entity item life reaches 0 tick, 5 more minutes will be added for each level. Remove 1 level/5 minutes
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ CurseForge: [https://www.curseforge.com/minecraft/mc-mods/enchanter](https://www
* 4: 23 damages before taking one

### Tools:
* Farmer: Till the dirt and grass blocks in a square with a radius of level * 2 + 1
* Farmer: Till the dirt and grass blocks in a square with a diameter of level * 2 + 1
* Miner: Mine blocks in a square with a diameter of *level* * 2 + 1

### Weapons:
* Multi Arrows (Bow): +1 arrow / level
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/goldorion/enchanter/ModEnchantments.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.goldorion.enchanter.enchantments.Farmer;
import net.goldorion.enchanter.enchantments.MagmaWalker;
import net.goldorion.enchanter.enchantments.Miner;
import net.goldorion.enchanter.enchantments.ModProtection;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ShieldItem;
Expand All @@ -22,6 +23,7 @@ public class ModEnchantments {
public static final EquipmentSlot[] ALL = new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST,
EquipmentSlot.LEGS, EquipmentSlot.FEET, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND};


//Protections
public static final RegistryObject<Enchantment> CACTUS_PROTECTION = register("cactus_protection", new ModProtection(Rarity.UNCOMMON,
ModProtection.Type.CACTUS, EnchantmentCategory.ARMOR, ARMORS));
Expand All @@ -30,22 +32,31 @@ public class ModEnchantments {
public static final RegistryObject<Enchantment> LIGHTNING_BOLT_PROTECTION = register("lightning_bolt_protection", new ModProtection(Rarity.UNCOMMON,
ModProtection.Type.LIGHTNING_BOLT, EnchantmentCategory.ARMOR, ARMORS));


// Tools
public static final RegistryObject<Enchantment> FARMER = register("farmer", new Farmer());
public static final RegistryObject<Enchantment> MINER = register("miner", new Miner());


// Weapons
public static final RegistryObject<Enchantment> MULTI_ARROWS = register("multi_arrows", new GenericEnchantment(new EnchantmentBuilder(Rarity.RARE, EnchantmentCategory.BOW, HANDS).setMaxLevel(4).setMinCost(20).setMaxCost(50).setCheckCompatibility(enchantment -> enchantment != Enchantments.INFINITY_ARROWS)));
public static final RegistryObject<Enchantment> HYLIAN_SHIELD = register("hylian_shield", new GenericEnchantment(new EnchantmentBuilder(Rarity.VERY_RARE, EnchantmentCategory.BREAKABLE, HANDS)
.setMinCost(30).setMaxCost(55).setTreasure().setCheckCompatibility(e -> !(e == Enchantments.MENDING || e == Enchantments.UNBREAKING))
.setCanEnchant(itemStack -> itemStack.getItem() instanceof ShieldItem)));


// Curses
public static final RegistryObject<Enchantment> SLEEPLESS_NIGHT = register("sleepless_night", new GenericEnchantment(new EnchantmentBuilder(Rarity.VERY_RARE, EnchantmentCategory.ARMOR, ARMORS).setMinCost(25).setMaxCost(50).setTreasure().setCurse()));
public static final RegistryObject<Enchantment> WRONG_BLOCK = register("wrong_block", new GenericEnchantment(new EnchantmentBuilder(Rarity.RARE, EnchantmentCategory.ARMOR, ARMORS).setMaxLevel(5).setTreasure().setTreasure().setCurse()));
public static final RegistryObject<Enchantment> SLIPPERY_ROPE = register("slippery_rope", new GenericEnchantment(new EnchantmentBuilder(Rarity.RARE, EnchantmentCategory.BOW, HANDS).setMaxLevel(4).setMinCost(20).setMaxCost(50).setTreasure().setCurse()));
public static final RegistryObject<Enchantment> SLIPPERY_HOOK = register("slippery_hook", new GenericEnchantment(new EnchantmentBuilder(Rarity.RARE, EnchantmentCategory.FISHING_ROD, HANDS).setMaxLevel(4).setMinCost(20).setMaxCost(50).setTreasure().setCurse()));


//Misc
public static final RegistryObject<Enchantment> MAGMA_WALKER = register("magma_walker", new MagmaWalker(Rarity.RARE, EquipmentSlot.FEET));
public static final RegistryObject<Enchantment> UNVANISHABLE = register("unvanishable", new GenericEnchantment(new EnchantmentBuilder(Enchantment.Rarity.VERY_RARE, EnchantmentCategory.VANISHABLE, ALL).setMaxLevel(3).setTreasure()));


// Treasures
public static RegistryObject<Enchantment> SECOND_CHANCE = register("second_chance", new GenericEnchantment(new EnchantmentBuilder(Rarity.VERY_RARE, EnchantmentCategory.ARMOR_CHEST, new EquipmentSlot[]{EquipmentSlot.CHEST})
.setMinCost(25).setMaxCost(50).setCheckCompatibility(e -> !(e instanceof MendingEnchantment))));
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/goldorion/enchanter/Utils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package net.goldorion.enchanter;

import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.GameType;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -69,4 +73,14 @@ public static void removeEnchant(Enchantment enchantment, ItemStack stack) {
}
}
}

public static boolean checkGamemode(Player player, GameType gameType) {
if (player instanceof ServerPlayer serverPlayer) {
return serverPlayer.gameMode.getGameModeForPlayer() == gameType;
} else if (player.level.isClientSide()) {
return Minecraft.getInstance().getConnection().getPlayerInfo(player.getGameProfile().getId()) != null
&& Minecraft.getInstance().getConnection().getPlayerInfo(player.getGameProfile().getId()).getGameMode() == gameType;
}
return false;
}
}
81 changes: 81 additions & 0 deletions src/main/java/net/goldorion/enchanter/enchantments/Miner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package net.goldorion.enchanter.enchantments;

import net.goldorion.enchanter.ModEnchantments;
import net.goldorion.enchanter.Utils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.LevelAccessor;

public class Miner extends Enchantment {

public Miner() {
super(Rarity.UNCOMMON, EnchantmentCategory.DIGGER, ModEnchantments.HANDS);
}

public static void applyEffectOnBlocks(LevelAccessor level, Player player, BlockPos pos, ItemStack stack, int radius) {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();

if (!player.isShiftKeyDown()) {
radius++;
if (player.getXRot() > 65 + 3.5 * radius || player.getXRot() < -65 - 3.5 * radius) {
for (int i = 0; i < radius; i++) {
for (int j = 0; j < radius; j++) {
breakBlock(level, player, new BlockPos(x + i, y, z + j), stack);
breakBlock(level, player, new BlockPos(x + i, y, z - j), stack);
breakBlock(level, player, new BlockPos(x - i, y, z + j), stack);
breakBlock(level, player, new BlockPos(x - i, y, z - j), stack);
}
}
} else if ((player.getDirection()) == Direction.NORTH || (player.getDirection()) == Direction.SOUTH) {
for (int i = 0; i < radius; i++) {
for (int j = 0; j < radius; j++) {
breakBlock(level, player, new BlockPos(x + i, y + j, z), stack);
breakBlock(level, player, new BlockPos(x + i, y - j, z), stack);
breakBlock(level, player, new BlockPos(x - i, y + j, z), stack);
breakBlock(level, player, new BlockPos(x - i, y - j, z), stack);
}
}
} else if ((player.getDirection()) == Direction.WEST || (player.getDirection()) == Direction.EAST) {
for (int i = 0; i < radius; i++) {
for (int j = 0; j < radius; j++) {
breakBlock(level, player, new BlockPos(x, y + i, z + j), stack);
breakBlock(level, player, new BlockPos(x, y + i, z - j), stack);
breakBlock(level, player, new BlockPos(x, y - i, z + j), stack);
breakBlock(level, player, new BlockPos(x, y - i, z - j), stack);
}
}
}
stack.setDamageValue(stack.getDamageValue() - 1);
}
}

private static void breakBlock(LevelAccessor level, Player player, BlockPos pos, ItemStack stack) {
if (level.getBlockState(pos).canOcclude() && stack.getItem().isCorrectToolForDrops((level.getBlockState(pos)))
&& level.getBlockState(pos).getDestroySpeed(level, pos) >= 0) {
if (Utils.checkGamemode(player, GameType.CREATIVE)) {
level.destroyBlock(pos, false);
} else {
level.destroyBlock(pos, true);
if (stack.hurt(1, RandomSource.create(), null)) {
stack.shrink(1);
stack.setDamageValue(0);
}
}
}
}

@Override
public int getMaxLevel() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import net.goldorion.enchanter.ModEnchantments;
import net.goldorion.enchanter.Utils;
import net.goldorion.enchanter.enchantments.Farmer;
import net.goldorion.enchanter.enchantments.Miner;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.GrassBlock;
Expand Down Expand Up @@ -57,16 +59,23 @@ public static void shieldBlocksDamage(ShieldBlockEvent event) {

@SubscribeEvent
public static void onItemUsed(BlockEvent.BlockToolModificationEvent event) {
ItemStack itemstack = event.getContext().getItemInHand();
if (event.getToolAction() == ToolActions.HOE_TILL) {
ItemStack itemstack = event.getContext().getItemInHand();
if (itemstack.getItem() instanceof HoeItem && EnchantmentHelper.getTagEnchantmentLevel(
ModEnchantments.FARMER.get(), itemstack) != 0) {
if (event.getContext().getLevel().getBlockState(event.getPos()).getBlock() instanceof GrassBlock ||
event.getContext().getLevel().getBlockState(event.getPos()).getBlock() == Blocks.DIRT) {
Farmer.applyEffectOnBlocks(event.getPlayer(), event.getContext().getHand(), event.getContext().getClickedPos(), itemstack,
EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.FARMER.get(), itemstack));
}
if (itemstack.getItem() instanceof HoeItem && EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.FARMER.get(), itemstack) != 0 &&
(event.getContext().getLevel().getBlockState(event.getPos()).getBlock() instanceof GrassBlock ||
event.getContext().getLevel().getBlockState(event.getPos()).getBlock() == Blocks.DIRT)) {
Farmer.applyEffectOnBlocks(event.getPlayer(), event.getContext().getHand(), event.getContext().getClickedPos(), itemstack,
EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.FARMER.get(), itemstack));
}
}
}

@SubscribeEvent
public static void onBlockBreak(BlockEvent.BreakEvent event) {
ItemStack itemstack = event.getPlayer().getItemInHand(event.getPlayer().getUsedItemHand());
if (EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.MINER.get(), itemstack) != 0) {
Miner.applyEffectOnBlocks(event.getWorld(), event.getPlayer(), event.getPos(), itemstack,
EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.MINER.get(), itemstack));
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/enchanter/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"enchantment.enchanter.second_chance": "Second Chance",
"enchantment.enchanter.magma_walker": "Magma Walker",
"enchantment.enchanter.farmer": "Farmer",
"enchantment.enchanter.miner": "Miner",
"enchantment.enchanter.multi_arrows": "Multi Arrows",
"enchantment.enchanter.sleepless_night": "Sleepless Night",
"enchantment.enchanter.unvanishable": "Unvanishable",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/enchanter/lang/fr_ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"enchantment.enchanter.second_chance": "Deuxième chance",
"enchantment.enchanter.magma_walker": "Semelles chauffantes",
"enchantment.enchanter.farmer": "Agriculteur",
"enchantment.enchanter.miner": "Mineur",
"enchantment.enchanter.multi_arrows": "Multi flèches",
"enchantment.enchanter.sleepless_night": "Insomnie",
"enchantment.enchanter.unvanishable": "Persistance",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/enchanter/lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"enchantment.enchanter.second_chance": "Deuxième chance",
"enchantment.enchanter.magma_walker": "Semelles chauffantes",
"enchantment.enchanter.farmer": "Agriculteur",
"enchantment.enchanter.miner": "Mineur",
"enchantment.enchanter.multi_arrows": "Multi flèches",
"enchantment.enchanter.sleepless_night": "Insomnie",
"enchantment.enchanter.unvanishable": "Persistance",
Expand Down

0 comments on commit c2ecdd7

Please sign in to comment.