mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-10-26 12:25:28 +00:00
Compare commits
22
Commits
tunnelling
...
54eadb13c2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54eadb13c2 | ||
|
|
07d086b26f | ||
|
|
6335252b8a | ||
|
|
fd69600b3e | ||
|
|
17e183669f | ||
|
|
e0f5b3a0d7 | ||
|
|
6ab3d47699 | ||
|
|
21946bfe3b | ||
|
|
0f628fb3fc | ||
|
|
c769a0905e | ||
|
|
b93718cce2 | ||
|
|
b3998f8937 | ||
|
|
7f530a1e87 | ||
|
|
e62bff7c73 | ||
|
|
9050004dae | ||
|
|
3f76e0a431 | ||
|
|
0f20ce8520 | ||
|
|
72321d362f | ||
|
|
bd4d4bb80b | ||
|
|
542b95caff | ||
|
|
8276d10047 | ||
|
|
fdc7d21685 |
@@ -10,13 +10,13 @@ jobs:
|
||||
build-commit:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v6
|
||||
with:
|
||||
java-version: 21
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
- name: Set short commit hash
|
||||
run: fullCommit=${{ github.sha }} && echo "SHORT_SHA=${fullCommit:0:8}" >> $GITHUB_ENV
|
||||
|
||||
@@ -16,12 +16,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v7
|
||||
- name: Build Astro page
|
||||
uses: withastro/action@v4
|
||||
uses: withastro/action@v6
|
||||
with:
|
||||
path: ./docs
|
||||
node-version: '22'
|
||||
node-version: '24'
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
@@ -31,4 +31,4 @@ jobs:
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
uses: actions/deploy-pages@v5
|
||||
|
||||
@@ -11,7 +11,7 @@ export default defineConfig({
|
||||
sidebar: [
|
||||
{
|
||||
label: 'Documentation',
|
||||
autogenerate: { directory: 'documentation' },
|
||||
items: [{ autogenerate: { "directory": "documentation" } }]
|
||||
},
|
||||
{
|
||||
label: 'Configuration',
|
||||
|
||||
Generated
+2313
-3542
File diff suppressed because it is too large
Load Diff
+2
-3
@@ -10,8 +10,7 @@
|
||||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/starlight": "^0.34.3",
|
||||
"astro": "^5.6.1",
|
||||
"sharp": "^0.32.5"
|
||||
"@astrojs/starlight": "^0.42.4",
|
||||
"astro": "^7.2.10"
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,41 @@ description: How to specify common input types in configuration
|
||||
---
|
||||
|
||||
## Tags
|
||||
There are 2 types of tags that can be used in the configuration:
|
||||
- `minecraft:item_name` - For specific items, use namespaced vanilla item id. If namespace is not provided, `minecraft` is assumed.
|
||||
- `#minecraft:item_tag_name` - For <a href="https://minecraft.wiki/w/Item_tag_(Java_Edition)" target="_blank">item tags</a>,
|
||||
use namespaced tag id. If namespace is not provided, `minecraft` is assumed. Custom tags from other plugins and
|
||||
datapacks are also supported.
|
||||
|
||||
### Items
|
||||
|
||||
#### Item reference
|
||||
Example: `minecraft:stick`
|
||||
|
||||
For specific items, use namespaced vanilla item id. If namespace is not provided, `minecraft` is assumed.
|
||||
|
||||
#### Item tag
|
||||
Example: `#minecraft:axes`
|
||||
|
||||
For <a href="https://minecraft.wiki/w/Item_tag_(Java_Edition)" target="_blank">item tags</a>, use namespaced tag id. If
|
||||
namespace is not provided, `minecraft` is assumed. Custom tags from other plugins and datapacks are also supported.
|
||||
|
||||
### Blocks
|
||||
|
||||
#### Block reference
|
||||
Example: `minecraft:dirt`
|
||||
|
||||
For specific items, use namespaced vanilla item id. If namespace is not provided, `minecraft` is assumed.
|
||||
|
||||
#### Block tag
|
||||
Example: `#minecraft:planks`
|
||||
|
||||
For <a href="https://minecraft.wiki/w/Block_tag_(Java_Edition)" target="_blank">block tags</a>, use namespaced tag id. If
|
||||
namespace is not provided, `minecraft` is assumed. Custom tags from other plugins and datapacks are also supported.
|
||||
|
||||
|
||||
### Enchantments
|
||||
|
||||
#### Enchantment tag
|
||||
Example: `#minecraft:in_enchanting_table`
|
||||
|
||||
For <a href="https://minecraft.wiki/w/Enchantment_tag_(Java_Edition)" target="_blank">enchantment tags</a>, use namespaced tag id. If
|
||||
namespace is not provided, `minecraft` is assumed. Custom tags from other plugins and datapacks are also supported.
|
||||
|
||||
## Slot types
|
||||
- `ANY` - Any slot.
|
||||
|
||||
@@ -18,8 +18,8 @@ Cost that will be added to the item when adding the enchantment to it in anvil.
|
||||
|
||||
- **Type**: `int`
|
||||
|
||||
Weight of the enchantment. Used if `canGetFromEnchantingTable` is set to true. Higher numbers mean it will come up more
|
||||
frequently in the enchanting table.
|
||||
Weight of the enchantment. Higher numbers mean it will come up more frequently in the enchanting table. Used if
|
||||
`#minecraft:in_enchanting_table` is present in enchantment tags.
|
||||
|
||||
### minimumCost
|
||||
|
||||
@@ -29,7 +29,7 @@ Minimum cost that will be required for the enchantment to show up in the enchant
|
||||
|
||||
- **Type**: `int`
|
||||
|
||||
Base cost of the enchant.
|
||||
Base cost of the enchantment.
|
||||
|
||||
#### perLevel
|
||||
|
||||
@@ -45,7 +45,7 @@ Maximum cost that will be required for the enchantment to show up in the enchant
|
||||
|
||||
- **Type**: `int`
|
||||
|
||||
Base cost of the enchant.
|
||||
Base cost of the enchantment.
|
||||
|
||||
#### perLevel
|
||||
|
||||
@@ -55,23 +55,22 @@ Cost to add per level of the enchantment.
|
||||
|
||||
### enchantmentTags
|
||||
|
||||
- **Type**: `key[]`
|
||||
- **Type**: [`Enchantment Tags`](/configuration/input-types/#enchantment-tag)
|
||||
|
||||
This is list of [tags](/configuration/input-types#tags) that the enchantment will be tagged with. This can be used to put the enchantment in enchanting table,
|
||||
mark it as a curse, etc. <a href="https://minecraft.wiki/w/Enchantment_tag_(Java_Edition)" target="_blank">All vanilla</a>
|
||||
and custom tags are supported.
|
||||
This is list of tags that the enchantment will be tagged with. This can be used to put the enchantment in enchanting table,
|
||||
mark it as a curse, etc.
|
||||
|
||||
### supportedItemTags
|
||||
|
||||
- **Type**: `key[]`
|
||||
- **Type**: [`Item Tags`](/configuration/input-types/#items)
|
||||
|
||||
[Items and/or item tags](/configuration/input-types#tags) that the enchantment can be applied to.
|
||||
Items and/or item tags that the enchantment can be applied to.
|
||||
|
||||
### activeSlots
|
||||
|
||||
- **Type**: `string[]`
|
||||
- **Type**: [`Slot types`](/configuration/input-types/#slot-types)
|
||||
|
||||
[Slots](/configuration/input-types#slot-types) that the enchantment will be active in.
|
||||
Inventory slots that the enchantment will be active in.
|
||||
|
||||
|
||||
### enabled
|
||||
@@ -96,9 +95,11 @@ of the enchantment does not support multiple levels.
|
||||
|
||||
## Telepathy
|
||||
|
||||
### onlyUserCanPickupItems
|
||||
|
||||
- **Type**: `boolean`
|
||||
|
||||
If set to true, items teleported by the enchant will only be able to be picked up by the player that broke the block.
|
||||
If set to true, items teleported by the enchantment will only be able to be picked up by the player that broke the block.
|
||||
|
||||
## Executioner
|
||||
|
||||
@@ -155,6 +156,26 @@ Cooldown in ticks that will be applied to the activating items cooldown group.
|
||||
|
||||
Namespaced key of the sound that will play when enchantment blocks a hit.
|
||||
|
||||
## Tunnelling
|
||||
|
||||
### affectedBlockTags
|
||||
|
||||
- **Type**: [`Block Tags`](/configuration/input-types/#blocks)
|
||||
|
||||
List of blocks and block tags that will be affected by the enchantment's mining effect.
|
||||
|
||||
### blocksPerLevel
|
||||
|
||||
- **Type**: `int`
|
||||
|
||||
How many blocks in each direction enchantment should mine per enchantment level.
|
||||
|
||||
### visualizeBreaking
|
||||
|
||||
- **Type**: `boolean`
|
||||
|
||||
Display visualisation of blocks being broken by the enchantment along with breaking the base block.
|
||||
|
||||
## Panic
|
||||
|
||||
### panicChancePerLevel
|
||||
|
||||
@@ -73,6 +73,14 @@ Automatically blocks hits, but triggers a configurable cooldown every time it do
|
||||
the enchanted items cooldown group, so if you make this enchantment support more than just 1 item, you're going to have
|
||||
to handle applying the cooldown group to them yourself.
|
||||
|
||||
### Tunnelling
|
||||
**Translation key**: `enchantio.enchantment.tunnelling`
|
||||
|
||||
**Description**:
|
||||
Mines multiple blocks around initially destroyed block. Activates when mining affected block and breaks all the affected
|
||||
blocks in a `range x range x 1` pattern.
|
||||
|
||||
|
||||
## Curses
|
||||
|
||||
### Curse of Panic
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<revision>1.15.2</revision>
|
||||
<revision>1.16.1</revision>
|
||||
</properties>
|
||||
<url>https://youhavetrouble.me</url>
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@ public final class Enchantio extends JavaPlugin {
|
||||
if (EnchantioConfig.ENCHANTS.containsKey(WardEnchant.KEY)) {
|
||||
getServer().getPluginManager().registerEvents(new WardListener(), this);
|
||||
}
|
||||
if (EnchantioConfig.ENCHANTS.containsKey(TunnellingEnchant.KEY)) {
|
||||
getServer().getPluginManager().registerEvents(new TunnellingListener(), this);
|
||||
}
|
||||
|
||||
if (EnchantioConfig.ENCHANTS.containsKey(PanicEnchant.KEY)) {
|
||||
getServer().getPluginManager().registerEvents(new PanicListener(), this);
|
||||
|
||||
@@ -6,14 +6,20 @@ import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.TypedKey;
|
||||
import io.papermc.paper.registry.event.RegistryEvents;
|
||||
import io.papermc.paper.registry.keys.tags.BlockTypeTagKeys;
|
||||
import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys;
|
||||
import io.papermc.paper.registry.tag.TagKey;
|
||||
import io.papermc.paper.tag.TagEntry;
|
||||
import me.youhavetrouble.enchantio.enchants.EnchantioEnchant;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.bukkit.block.BlockType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@@ -42,6 +48,18 @@ public class EnchantioBootstrap implements PluginBootstrap {
|
||||
}
|
||||
}));
|
||||
|
||||
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.BLOCK).newHandler((event) -> {
|
||||
for (EnchantioEnchant enchant : enchantioEnchants) {
|
||||
for (Map.Entry<Key, Set<TagEntry<BlockType>>> entry : enchant.getBlockTagsToRegister().entrySet()) {
|
||||
logger.info("Registering block tag {}", entry.getKey());
|
||||
event.registrar().addToTag(
|
||||
BlockTypeTagKeys.create(entry.getKey()),
|
||||
entry.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.compose().newHandler(event -> {
|
||||
for (EnchantioEnchant enchant : enchantioEnchants) {
|
||||
logger.info("Registering enchantment {}", enchant.getKey());
|
||||
|
||||
@@ -2,12 +2,14 @@ package me.youhavetrouble.enchantio;
|
||||
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.TypedKey;
|
||||
import io.papermc.paper.registry.keys.tags.BlockTypeTagKeys;
|
||||
import io.papermc.paper.registry.keys.tags.EnchantmentTagKeys;
|
||||
import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys;
|
||||
import io.papermc.paper.registry.tag.TagKey;
|
||||
import io.papermc.paper.tag.TagEntry;
|
||||
import me.youhavetrouble.enchantio.enchants.*;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.bukkit.block.BlockType;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -78,6 +80,9 @@ public class EnchantioConfig {
|
||||
ConfigurationSection wardSection = getConfigSection(enchantsSection, "ward");
|
||||
WardEnchant.create(wardSection);
|
||||
|
||||
ConfigurationSection tunnellingSection = getConfigSection(enchantsSection, "tunnelling");
|
||||
TunnellingEnchant.create(tunnellingSection);
|
||||
|
||||
ConfigurationSection cursesSection = getConfigSection(configuration, "curses");
|
||||
migrateEnchantTags(cursesSection);
|
||||
|
||||
@@ -210,6 +215,32 @@ public class EnchantioConfig {
|
||||
return enchantTagKeys;
|
||||
}
|
||||
|
||||
public static Set<TagEntry<BlockType>> getBlockTagKeysFromList(@NotNull List<String> tags) {
|
||||
Set<TagEntry<BlockType>> blockTagKeys = new HashSet<>();
|
||||
for (String blockTag : tags) {
|
||||
if (blockTag == null) continue;
|
||||
if (blockTag.startsWith("#")) {
|
||||
blockTag = blockTag.substring(1);
|
||||
try {
|
||||
Key key = Key.key(blockTag);
|
||||
TagKey<BlockType> tagKey = BlockTypeTagKeys.create(key);
|
||||
TagEntry<BlockType> tagEntry = TagEntry.tagEntry(tagKey);
|
||||
blockTagKeys.add(tagEntry);
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
Key key = Key.key(blockTag);
|
||||
TypedKey<BlockType> typedKey = TypedKey.create(RegistryKey.BLOCK, key);
|
||||
TagEntry<BlockType> tagEntry = TagEntry.valueEntry(typedKey);
|
||||
blockTagKeys.add(tagEntry);
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
}
|
||||
}
|
||||
return blockTagKeys;
|
||||
}
|
||||
|
||||
public static ConfigurationSection getConfigSection(ConfigurationSection section, String key) {
|
||||
ConfigurationSection value = section.getConfigurationSection(key);
|
||||
if (value == null) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.youhavetrouble.enchantio.enchants;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.TypedKey;
|
||||
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
|
||||
@@ -7,6 +8,7 @@ import io.papermc.paper.registry.tag.TagKey;
|
||||
import io.papermc.paper.tag.TagEntry;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.block.BlockType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlotGroup;
|
||||
@@ -15,6 +17,8 @@ import org.bukkit.inventory.ItemType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@@ -57,6 +61,14 @@ public interface EnchantioEnchant {
|
||||
return TagEntry.valueEntry(TypedKey.create(RegistryKey.ENCHANTMENT, getKey()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block tags to register to use for this enchantment and what tags/blocks it should contain
|
||||
*/
|
||||
@NotNull
|
||||
default Map<Key, Set<TagEntry<BlockType>>> getBlockTagsToRegister() {
|
||||
return ImmutableMap.of();
|
||||
}
|
||||
|
||||
static @Nullable ItemStack findFirstWithEnchant(
|
||||
@NotNull EntityEquipment equipment,
|
||||
@NotNull Enchantment enchantment
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
package me.youhavetrouble.enchantio.enchants;
|
||||
|
||||
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
|
||||
import io.papermc.paper.registry.tag.TagKey;
|
||||
import io.papermc.paper.tag.TagEntry;
|
||||
import me.youhavetrouble.enchantio.EnchantioConfig;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.block.BlockType;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.EquipmentSlotGroup;
|
||||
import org.bukkit.inventory.ItemType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static me.youhavetrouble.enchantio.EnchantioConfig.ENCHANTS;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class TunnellingEnchant implements EnchantioEnchant {
|
||||
|
||||
public static final Key KEY = Key.key("enchantio", "tunnelling");
|
||||
|
||||
public static final Key AFFECTED_BLOCKS_KEY = Key.key("enchantio", "affected_by_tunnelling");
|
||||
|
||||
private final int anvilCost, weight, maxLevel, blocksPerLevel;
|
||||
private final boolean visualizeBreaking;
|
||||
private final EnchantmentRegistryEntry.EnchantmentCost minimumCost;
|
||||
private final EnchantmentRegistryEntry.EnchantmentCost maximumCost;
|
||||
private final Set<TagEntry<ItemType>> supportedItemTags = new HashSet<>();
|
||||
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
|
||||
private final Map<Key, Set<TagEntry<BlockType>>> affectedBlockTags = new HashMap<>();
|
||||
|
||||
private TunnellingEnchant(
|
||||
int anvilCost,
|
||||
int weight,
|
||||
EnchantmentRegistryEntry.EnchantmentCost minimumCost,
|
||||
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
|
||||
Collection<TagKey<Enchantment>> enchantTagKeys,
|
||||
Collection<TagEntry<ItemType>> supportedItemTags,
|
||||
Map<Key, Set<TagEntry<BlockType>>> affectedBlockTags,
|
||||
int maxLevel,
|
||||
int blocksPerLevel,
|
||||
boolean visualizeBreaking
|
||||
) {
|
||||
this.anvilCost = anvilCost;
|
||||
this.weight = weight;
|
||||
this.minimumCost = minimumCost;
|
||||
this.maximumCost = maximumCost;
|
||||
this.maxLevel = maxLevel;
|
||||
this.blocksPerLevel = blocksPerLevel;
|
||||
this.visualizeBreaking = visualizeBreaking;
|
||||
this.supportedItemTags.addAll(supportedItemTags);
|
||||
this.enchantTagKeys.addAll(enchantTagKeys);
|
||||
this.affectedBlockTags.putAll(affectedBlockTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component getDescription() {
|
||||
return Component.translatable("enchantio.enchant.tunnelling", "Tunnelling");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAnvilCost() {
|
||||
return anvilCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
|
||||
return minimumCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
|
||||
return maximumCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
|
||||
return Set.of(EquipmentSlotGroup.MAINHAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
|
||||
return supportedItemTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
|
||||
return Collections.unmodifiableSet(enchantTagKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<Key, Set<TagEntry<BlockType>>> getBlockTagsToRegister() {
|
||||
return affectedBlockTags;
|
||||
}
|
||||
|
||||
public int getBlocksPerLevel() {
|
||||
return blocksPerLevel;
|
||||
}
|
||||
|
||||
public boolean shouldVisualizeBreaking() {
|
||||
return visualizeBreaking;
|
||||
}
|
||||
|
||||
public static TunnellingEnchant create(ConfigurationSection configurationSection) {
|
||||
TunnellingEnchant tunnellingEnchant = new TunnellingEnchant(
|
||||
EnchantioConfig.getInt(configurationSection, "anvilCost", 1),
|
||||
EnchantioConfig.getInt(configurationSection, "weight", 10),
|
||||
EnchantmentRegistryEntry.EnchantmentCost.of(
|
||||
EnchantioConfig.getInt(configurationSection, "minimumCost.base", 40),
|
||||
EnchantioConfig.getInt(configurationSection, "minimumCost.additionalPerLevel", 3)
|
||||
),
|
||||
EnchantmentRegistryEntry.EnchantmentCost.of(
|
||||
EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65),
|
||||
EnchantioConfig.getInt(configurationSection, "maximumCost.additionalPerLevel", 1)
|
||||
),
|
||||
EnchantioConfig.getEnchantmentTagKeysFromList(EnchantioConfig.getStringList(
|
||||
configurationSection,
|
||||
"enchantmentTags",
|
||||
List.of("#in_enchanting_table")
|
||||
)),
|
||||
EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList(
|
||||
configurationSection,
|
||||
"supportedItemTags",
|
||||
List.of(
|
||||
"#minecraft:enchantable/mining"
|
||||
)
|
||||
)),
|
||||
Map.of(
|
||||
AFFECTED_BLOCKS_KEY,
|
||||
EnchantioConfig.getBlockTagKeysFromList(EnchantioConfig.getStringList(
|
||||
configurationSection,
|
||||
"affectedBlockTags",
|
||||
List.of(
|
||||
"#minecraft:base_stone_overworld",
|
||||
"#minecraft:base_stone_nether",
|
||||
"#minecraft:ores",
|
||||
"#minecraft:terracotta",
|
||||
"#minecraft:glazed_terracotta",
|
||||
"#minecraft:concrete",
|
||||
"#minecraft:stone_bricks",
|
||||
"minecraft:end_stone",
|
||||
"minecraft:cobblestone",
|
||||
"minecraft:cobbled_deepslate"
|
||||
)
|
||||
))
|
||||
),
|
||||
EnchantioConfig.getInt(configurationSection, "maxLevel", 1),
|
||||
EnchantioConfig.getInt(configurationSection, "blocksPerLevel", 1),
|
||||
EnchantioConfig.getBoolean(configurationSection, "visualizeBreaking", true)
|
||||
);
|
||||
|
||||
if (EnchantioConfig.getBoolean(configurationSection, "enabled", true)) {
|
||||
ENCHANTS.put(TunnellingEnchant.KEY, tunnellingEnchant);
|
||||
}
|
||||
|
||||
return tunnellingEnchant;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package me.youhavetrouble.enchantio.listeners;
|
||||
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.keys.tags.BlockTypeTagKeys;
|
||||
import me.youhavetrouble.enchantio.Enchantio;
|
||||
import me.youhavetrouble.enchantio.EnchantioConfig;
|
||||
import me.youhavetrouble.enchantio.enchants.TunnellingEnchant;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDamageAbortEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class TunnellingListener implements Listener {
|
||||
|
||||
private final static Set<Block> blockBreakSkips = new HashSet<>();
|
||||
private final static Map<UUID, BlockBreakData> blockBreakData = new ConcurrentHashMap<>();
|
||||
private final Enchantment tunnelling = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).get(TunnellingEnchant.KEY);
|
||||
private final TunnellingEnchant tunnellingEnchant;
|
||||
|
||||
public TunnellingListener() {
|
||||
if (EnchantioConfig.ENCHANTS.get(TunnellingEnchant.KEY) instanceof TunnellingEnchant enchant) {
|
||||
this.tunnellingEnchant = enchant;
|
||||
} else {
|
||||
throw new RuntimeException("Tunnelling enchantment is not registered, but something tried to create a listener for it. Don't do that.");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
if (!tunnellingEnchant.shouldVisualizeBreaking()) return;
|
||||
event.getPlayer().getScheduler().runAtFixedRate(Enchantio.getPlugin(Enchantio.class), (task) -> {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null || !player.isOnline()) {
|
||||
task.cancel();
|
||||
return;
|
||||
}
|
||||
BlockBreakData data = blockBreakData.get(uuid);
|
||||
if (data == null) return;
|
||||
if (player.isSneaking()) {
|
||||
updateBlockBreakProgress(player, data, 0);
|
||||
return;
|
||||
}
|
||||
long elapsed = System.currentTimeMillis() - data.startedBreakingAt();
|
||||
long elapsedTicks = elapsed / 50;
|
||||
float breakSpeed = data.block.getBreakSpeed(player);
|
||||
float ticksNeeded = 1.0f / breakSpeed;
|
||||
float progress = Math.min(elapsedTicks / ticksNeeded, 1.0f);
|
||||
if (progress >= 1.0f) return;
|
||||
updateBlockBreakProgress(player, data, progress);
|
||||
}, null, 1, 1);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onTunnelBlockStartBreak(BlockDamageEvent event) {
|
||||
if (tunnelling == null) return;
|
||||
Player player = event.getPlayer();
|
||||
if (GameMode.CREATIVE.equals(player.getGameMode())) return;
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (item.isEmpty()) return;
|
||||
int enchantLevel = item.getEnchantmentLevel(tunnelling);
|
||||
if (enchantLevel == -1) return;
|
||||
if (blockBreakData.containsKey(player.getUniqueId())) return;
|
||||
Block block = event.getBlock();
|
||||
Set<Block> blocksToBreak = getSquare(block, event.getBlockFace(), tunnellingEnchant.getBlocksPerLevel() * enchantLevel);
|
||||
blockBreakData.put(player.getUniqueId(), new BlockBreakData(block, System.currentTimeMillis(), event.getBlockFace(), blocksToBreak));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onTunnelBlockStopBreak(BlockDamageAbortEvent event) {
|
||||
BlockBreakData data = blockBreakData.remove(event.getPlayer().getUniqueId());
|
||||
if (data == null) return;
|
||||
updateBlockBreakProgress(event.getPlayer(), data, 0f);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
blockBreakData.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerTpToAnotherWorld(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
BlockBreakData data = blockBreakData.get(player.getUniqueId());
|
||||
if (data == null) return;
|
||||
if (data.block.getWorld().getUID().equals(player.getWorld().getUID())) return;
|
||||
blockBreakData.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onTunnelBlockBreak(BlockBreakEvent event) {
|
||||
if (tunnelling == null) return;
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
BlockBreakData data = blockBreakData.remove(player.getUniqueId());
|
||||
if (blockBreakSkips.contains(block)) return;
|
||||
if (data != null) updateBlockBreakProgress(player, data, 0f);
|
||||
if (GameMode.CREATIVE.equals(player.getGameMode())) return;
|
||||
if (player.isSneaking()) return;
|
||||
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
|
||||
int enchantLevel = item.getEnchantmentLevel(tunnelling);
|
||||
if (enchantLevel <= 0) return;
|
||||
BlockType blockType = block.getType().asBlockType();
|
||||
if (!Registry.BLOCK.getTagValues(BlockTypeTagKeys.create(TunnellingEnchant.AFFECTED_BLOCKS_KEY)).contains(blockType)) return;
|
||||
if (data == null) return;
|
||||
Set<Block> blocksToBreak = getSquare(block, data.blockFace, tunnellingEnchant.getBlocksPerLevel() * enchantLevel);
|
||||
blockBreakSkips.addAll(blocksToBreak);
|
||||
for (Block b : blocksToBreak) {
|
||||
if (player.getInventory().getItemInMainHand().isEmpty()) {
|
||||
event.setCancelled(true);
|
||||
blockBreakSkips.removeAll(blocksToBreak);
|
||||
break;
|
||||
}
|
||||
event.getPlayer().breakBlock(b);
|
||||
blockBreakSkips.remove(b);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBlockBreakProgress(Player player, BlockBreakData data, float progress) {
|
||||
if (!tunnellingEnchant.shouldVisualizeBreaking()) return;
|
||||
int id = Integer.MIN_VALUE;
|
||||
for (Block block : data.blocksToSyncDamage) {
|
||||
player.sendBlockDamage(block.getLocation(), progress, id++);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Block> getSquare(Block block, BlockFace face, int range) {
|
||||
switch (face) {
|
||||
case DOWN, UP -> {
|
||||
return getBlocksToTunnel(block.getLocation(), range, 0, range);
|
||||
}
|
||||
case EAST, WEST -> {
|
||||
return getBlocksToTunnel(block.getLocation(), 0, range, range);
|
||||
}
|
||||
case NORTH, SOUTH -> {
|
||||
return getBlocksToTunnel(block.getLocation(), range, range, 0);
|
||||
}
|
||||
}
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all blocks that will be broken by Tunnelling enchantment
|
||||
* @param base location at the centre of selection
|
||||
* @return All blocks that will get broken
|
||||
*/
|
||||
private Set<Block> getBlocksToTunnel(Location base, int changeX, int changeY, int changeZ) {
|
||||
Set<Block> blocks = new HashSet<>();
|
||||
for (int x = (base.getBlockX() - changeX); x <= (base.getBlockX() + changeX); x++) {
|
||||
for (int y = (base.getBlockY() - changeY); y <= (base.getBlockY() + changeY); y++) {
|
||||
for (int z = (base.getBlockZ() - changeZ); z <= (base.getBlockZ() + changeZ); z++) {
|
||||
Location loc = new Location(base.getWorld(), x, y, z);
|
||||
if (base.equals(loc)) continue; // ignore the base block
|
||||
Block block = loc.getBlock();
|
||||
BlockType blockType = block.getType().asBlockType();
|
||||
if (!Registry.BLOCK.getTagValues(BlockTypeTagKeys.create(TunnellingEnchant.AFFECTED_BLOCKS_KEY)).contains(blockType)) continue;
|
||||
if (block.getType().isAir()) continue;
|
||||
blocks.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private record BlockBreakData(Block block, long startedBreakingAt, BlockFace blockFace, Set<Block> blocksToSyncDamage) {}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user