Initial commit

This commit is contained in:
UltraLionfr
2025-11-02 02:39:51 +01:00
commit 6a3a7f4f27
18 changed files with 951 additions and 0 deletions
@@ -0,0 +1,14 @@
package fr.ultralion.veinmining;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.enchantment.Enchantment;
public class ModEnchantments {
public static final ResourceKey<Enchantment> VEINMINING = ResourceKey.create(
Registries.ENCHANTMENT,
ResourceLocation.fromNamespaceAndPath(Veinmining.MODID, "veinmining")
);
}
@@ -0,0 +1,15 @@
package fr.ultralion.veinmining;
import fr.ultralion.veinmining.event.BlockBreakHandler;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.common.NeoForge;
@Mod(Veinmining.MODID)
public class Veinmining {
public static final String MODID = "veinmining";
public Veinmining(IEventBus modEventBus) {
NeoForge.EVENT_BUS.register(new BlockBreakHandler());
}
}
@@ -0,0 +1,111 @@
package fr.ultralion.veinmining.event;
import fr.ultralion.veinmining.ModEnchantments;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.level.BlockEvent;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
public class BlockBreakHandler {
private static final int MAX_BLOCKS = 64;
private static final int SEARCH_RANGE = 1;
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent event) {
if (!(event.getLevel() instanceof ServerLevel serverLevel)) return;
if (!(event.getPlayer() instanceof ServerPlayer player)) return;
ItemStack tool = player.getMainHandItem();
int enchantmentLevel = EnchantmentHelper.getItemEnchantmentLevel(
serverLevel.registryAccess().registryOrThrow(Registries.ENCHANTMENT).getHolderOrThrow(ModEnchantments.VEINMINING),
tool
);
if (enchantmentLevel <= 0) return;
BlockState brokenBlock = event.getState();
String blockName = brokenBlock.getBlock().toString().toLowerCase();
if (!blockName.contains("ore")) return;
veinMine(serverLevel, player, event.getPos(), brokenBlock, tool, enchantmentLevel);
}
private void veinMine(ServerLevel level, ServerPlayer player, BlockPos startPos,
BlockState targetBlock, ItemStack tool, int enchantmentLevel) {
Block targetBlockType = targetBlock.getBlock();
Set<BlockPos> visited = new HashSet<>();
Queue<BlockPos> toCheck = new LinkedList<>();
toCheck.add(startPos);
visited.add(startPos);
int blocksDestroyed = 0;
int maxBlocks = MAX_BLOCKS * enchantmentLevel;
while (!toCheck.isEmpty() && blocksDestroyed < maxBlocks) {
BlockPos currentPos = toCheck.poll();
for (int x = -SEARCH_RANGE; x <= SEARCH_RANGE; x++) {
for (int y = -SEARCH_RANGE; y <= SEARCH_RANGE; y++) {
for (int z = -SEARCH_RANGE; z <= SEARCH_RANGE; z++) {
if (x == 0 && y == 0 && z == 0) continue;
BlockPos neighborPos = currentPos.offset(x, y, z);
if (visited.contains(neighborPos)) continue;
visited.add(neighborPos);
BlockState neighborState = level.getBlockState(neighborPos);
if (neighborState.getBlock() == targetBlockType) {
toCheck.add(neighborPos);
if (breakBlock(level, player, neighborPos, neighborState, tool)) {
blocksDestroyed++;
}
if (blocksDestroyed >= maxBlocks) break;
}
}
if (blocksDestroyed >= maxBlocks) break;
}
if (blocksDestroyed >= maxBlocks) break;
}
}
}
private boolean breakBlock(ServerLevel level, ServerPlayer player, BlockPos pos,
BlockState state, ItemStack tool) {
if (!tool.isCorrectToolForDrops(state)) return false;
boolean broken = level.destroyBlock(pos, false, player);
if (broken) {
Block.dropResources(state, level, pos, level.getBlockEntity(pos), player, tool);
tool.hurtAndBreak(1, player, net.minecraft.world.entity.EquipmentSlot.MAINHAND);
int exp = state.getBlock().getExpDrop(state, level, pos, level.getBlockEntity(pos), player, tool);
if (exp > 0) {
state.getBlock().popExperience(level, pos, exp);
}
}
return broken;
}
}
@@ -0,0 +1,4 @@
{
"enchantment.veinmining.veinmining": "Veinmining",
"enchantment.veinmining.veinmining.desc": "Mines entire ore veins at once"
}
@@ -0,0 +1,4 @@
{
"enchantment.veinmining.veinmining": "Extraction de veine",
"enchantment.veinmining.veinmining.desc": "Mine des filons entiers de minerais en une seul fois"
}
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"veinmining:veinmining"
]
}
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"veinmining:veinmining"
]
}
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"veinmining:veinmining"
]
}
@@ -0,0 +1,21 @@
{
"description": {
"translate": "enchantment.veinmining.veinmining"
},
"supported_items": "#minecraft:pickaxes",
"primary_items": "#minecraft:pickaxes",
"weight": 10,
"max_level": 3,
"min_cost": {
"base": 10,
"per_level_above_first": 10
},
"max_cost": {
"base": 60,
"per_level_above_first": 10
},
"anvil_cost": 4,
"slots": [
"mainhand"
]
}
@@ -0,0 +1,79 @@
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader = "javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the the FML version. This is currently 47.
loaderVersion = "${loader_version_range}" #mandatory
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license = "${mod_license}"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId = "${mod_id}" #mandatory
# The version number of the mod
version = "${mod_version}" #mandatory
# A display name for the mod
displayName = "${mod_name}" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://docs.neoforge.net/docs/misc/updatechecker/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL = "https://ultralion.xyz" #optional
# A file name (in the root of the mod JAR) containing a logo for display
logoFile="logo.png"
# A text field displayed in the mod UI
#credits="" #optional
# A text field displayed in the mod UI
authors = "${mod_authors}" #optional
# The description text for the mod (multi line!) (#mandatory)
description = '''${mod_description}'''
# The [[mixins]] block allows you to declare your mixin config to FML so that it gets loaded.
#[[mixins]]
#config="${mod_id}.mixins.json"
# The [[accessTransformers]] block allows you to declare where your AT file is.
# If this block is omitted, a fallback attempt will be made to load an AT from META-INF/accesstransformer.cfg
#[[accessTransformers]]
#file="META-INF/accesstransformer.cfg"
# The coremods config file path is not configurable and is always loaded from META-INF/coremods.json
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies."${mod_id}"]] #optional
# the modid of the dependency
modId = "neoforge" #mandatory
# The type of the dependency. Can be one of "required", "optional", "incompatible" or "discouraged" (case insensitive).
# 'required' requires the mod to exist, 'optional' does not
# 'incompatible' will prevent the game from loading when the mod exists, and 'discouraged' will show a warning
type = "required" #mandatory
# Optional field describing why the dependency is required or why it is incompatible
# reason="..."
# The version range of the dependency
versionRange = "${neo_version_range}" #mandatory
# An ordering relationship for the dependency.
# BEFORE - This mod is loaded BEFORE the dependency
# AFTER - This mod is loaded AFTER the dependency
ordering = "NONE"
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
side = "BOTH"
# Here's another dependency
[[dependencies."${mod_id}"]]
modId = "minecraft"
type = "required"
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange = "${minecraft_version_range}"
ordering = "NONE"
side = "BOTH"
# Features are specific properties of the game environment, that you may want to declare you require. This example declares
# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
# stop your mod loading on the server for example.
#[features."${mod_id}"]
#openGLVersion="[3.2,)"