Skip to content

Commit

Permalink
Add disabled tag for enchantments
Browse files Browse the repository at this point in the history
  • Loading branch information
frqnny committed Apr 2, 2022
1 parent a9bf538 commit 133f469
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 20 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ yarn_mappings=1.18.2+build.2
loader_version=0.13.3

#Fabric api
fabric_version=0.47.10+1.18.2
fabric_version=0.48.0+1.18.2

# Dependencies
libgui_version=5.3.1+1.18
libgui_version=5.3.2+1.18.2
config_version=1.2.3-1.18.1
mod_menu_version=3.0.1
# Mod Properties
mod_version = 0.6.4+1.18.2
mod_version = 0.7.0+1.18.2
maven_group = io.github.frqnny
archives_base_name = dark-enchanting
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import draylar.omegaconfig.OmegaConfig;
import io.github.frqnny.darkenchanting.config.DarkEnchantingConfig;
import io.github.frqnny.darkenchanting.init.ModBlocks;
import io.github.frqnny.darkenchanting.init.ModGUIs;
import io.github.frqnny.darkenchanting.init.ModItems;
import io.github.frqnny.darkenchanting.init.ModPackets;
import io.github.frqnny.darkenchanting.init.*;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.minecraft.item.ItemGroup;
Expand All @@ -31,6 +28,7 @@ public void onInitialize() {
ModItems.init();
ModBlocks.init();
ModGUIs.init();
ModTags.init();
ModPackets.init();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -47,6 +49,8 @@ public class DarkEnchanterGUI extends SyncedGuiDescription {
public String bookcase_stats_1;
public String bookcase_stats_2;
public String bookcase_stats_3;
//sorry, I don't know how to program
public RegistryEntry<Enchantment> cachedRegistryEntry;

public DarkEnchanterGUI(int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) {
super(ModGUIs.DARK_ENCHANTER_GUI, syncId, playerInventory);
Expand Down Expand Up @@ -150,15 +154,24 @@ public void populateList() {
for (Enchantment enchantment : Registry.ENCHANTMENT) {
Optional<ConfigEnchantment> configEnchantmentOptional = ConfigEnchantment.getConfigEnchantmentFor(enchantment);


//Users' preference is preferred over modders'.
if (configEnchantmentOptional.isPresent()) {
ConfigEnchantment configEnchantment = configEnchantmentOptional.get();
if (!configEnchantment.activated) {
continue;
}

}

if (enchantment.getMaxLevel() < 1) {
this.context.run((world, pos) -> cachedRegistryEntry = world.getRegistryManager().get(Registry.ENCHANTMENT_KEY).entryOf(RegistryKey.of(Registry.ENCHANTMENT_KEY, Registry.ENCHANTMENT.getId(enchantment))));
//if you are reading this, don't
boolean isMyTag = cachedRegistryEntry.streamTags().anyMatch((enchantmentTagKey -> enchantmentTagKey.id().toString().contains("dark-enchanting")));
if (isMyTag) {
continue;
}

if (enchantment.getMaxLevel() < 1) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class ModBlocks {

public static final DarkEnchanterBlock DARK_ENCHANTER = new DarkEnchanterBlock(FabricBlockSettings.copyOf(Blocks.ENCHANTING_TABLE).requiresTool());
public static final DarkConduitBlock DARK_TORCH = new DarkConduitBlock(FabricBlockSettings.copyOf(Blocks.TORCH), ParticleTypes.DRAGON_BREATH);
public static final WallDarkConduitBlock DARK_TORCH_WALL = new WallDarkConduitBlock(FabricBlockSettings.copyOf(Blocks.WALL_TORCH), ParticleTypes.DRAGON_BREATH);
public static final TagKey<Block> BOOKSHELVES = TagKey.of(Registry.BLOCK_KEY, new Identifier("c", "bookshelves"));
public static final BlockEntityType<DarkEnchanterBlockEntity> DE_BLOCK_ENTITY = FabricBlockEntityTypeBuilder.create(DarkEnchanterBlockEntity::new, DARK_ENCHANTER).build();

public static void init() {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/io/github/frqnny/darkenchanting/init/ModTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.frqnny.darkenchanting.init;

import io.github.frqnny.darkenchanting.DarkEnchanting;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class ModTags {
public static final TagKey<Block> BOOKSHELVES = TagKey.of(Registry.BLOCK_KEY, new Identifier("c", "bookshelves"));
public static final TagKey<Enchantment> DISABLED = TagKey.of(Registry.ENCHANTMENT_KEY, DarkEnchanting.id("enchantment/disabled"));

public static void init() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.frqnny.darkenchanting.DarkEnchanting;
import io.github.frqnny.darkenchanting.config.DarkEnchantingConfig;
import io.github.frqnny.darkenchanting.init.ModBlocks;
import io.github.frqnny.darkenchanting.init.ModTags;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand Down Expand Up @@ -64,7 +65,7 @@ public static int getBookshelfCount(World world, BlockPos blockPos) {
[0] [0]
[1][0][1][0][1]
*/
if (world.getBlockState(blockPos.add(x * 2, y, z * 2)).isIn(ModBlocks.BOOKSHELVES)) {
if (world.getBlockState(blockPos.add(x * 2, y, z * 2)).isIn(ModTags.BOOKSHELVES)) {
++bookshelves;
}
/*
Expand All @@ -78,10 +79,10 @@ public static int getBookshelfCount(World world, BlockPos blockPos) {
[1][0][1][0][1]
*/
if (x != 0 && z != 0) {
if (world.getBlockState(blockPos.add(x * 2, y, z)).isIn(ModBlocks.BOOKSHELVES)) {
if (world.getBlockState(blockPos.add(x * 2, y, z)).isIn(ModTags.BOOKSHELVES)) {
++bookshelves;
}
if (world.getBlockState(blockPos.add(x, y, z * 2)).isIn(ModBlocks.BOOKSHELVES)) {
if (world.getBlockState(blockPos.add(x, y, z * 2)).isIn(ModTags.BOOKSHELVES)) {
++bookshelves;
}
}
Expand Down Expand Up @@ -194,12 +195,12 @@ public static int getBookshelfCount_2(World world, BlockPos blockPos) {
-4 0 2,
-4 0 3
*/
if (world.getBlockState(blockPos.add(4, y, z)).isIn(ModBlocks.BOOKSHELVES)) {
if (world.getBlockState(blockPos.add(4, y, z)).isIn(ModTags.BOOKSHELVES)) {
//System.out.println("obsidian found at :" + 4 +","+y+","+z);
++bookshelves_2;
}
if (z != 4) {
if (world.getBlockState(blockPos.add(-4, y, z)).isIn(ModBlocks.BOOKSHELVES)) {
if (world.getBlockState(blockPos.add(-4, y, z)).isIn(ModTags.BOOKSHELVES)) {
//System.out.println("obsidian found at :" + -4 +","+y+","+ z);
++bookshelves_2;
}
Expand All @@ -222,12 +223,12 @@ public static int getBookshelfCount_2(World world, BlockPos blockPos) {
-3 0 -4 -3 0 4
-4 0 -4, -4 0 4
*/
if (world.getBlockState(blockPos.add(x, y, 4)).isIn(ModBlocks.BOOKSHELVES)) {
if (world.getBlockState(blockPos.add(x, y, 4)).isIn(ModTags.BOOKSHELVES)) {
//System.out.println("obsidian found at :" + x +","+y+","+4);
++bookshelves_2;
}
if (x != 4) {
if (world.getBlockState(blockPos.add(x, y, -4)).isIn(ModBlocks.BOOKSHELVES)) {
if (world.getBlockState(blockPos.add(x, y, -4)).isIn(ModTags.BOOKSHELVES)) {
// System.out.println("obsidian found at :" + x +","+y+","+-4);
++bookshelves_2;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"replace": false,
"values": [
]
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "dark-enchanting",
"version": "0.6.3+1.18",
"version": "0.7.0+1.18.2",
"name": "Dark Enchanting",
"description": "Adding Dark Enchantments, Dark Enchanter, and many other cool things since 2019.",
"authors": [
Expand Down

0 comments on commit 133f469

Please sign in to comment.