From a47d76f2cf5dc3a350511d82aa54d0e6bea688f0 Mon Sep 17 00:00:00 2001 From: YocyCraft Date: Sun, 22 Dec 2024 02:54:20 +0800 Subject: [PATCH 1/8] Fix GiantAnvil falling doesn't trigger updateShape --- .../anvilcraft/block/GiantAnvilBlock.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java b/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java index 8cd1c64d7..3ff9535f6 100644 --- a/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java +++ b/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java @@ -1,5 +1,7 @@ package dev.dubhe.anvilcraft.block; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import dev.dubhe.anvilcraft.api.event.anvil.AnvilFallOnLandEvent; import dev.dubhe.anvilcraft.api.event.anvil.GiantAnvilFallOnLandEvent; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; @@ -113,6 +115,81 @@ public class GiantAnvilBlock extends AbstractMultiplePartBlock .reduce((v1, v2) -> Shapes.join(v1, v2, BooleanOp.OR)) .get(); + private static final ImmutableMap> UPDATE_OFFSET = ImmutableMap.of( + Direction.DOWN, + ImmutableList.of( + new Vec3i(-1, 3, -1), + new Vec3i(-1, 3, 0), + new Vec3i(-1, 3, 1), + new Vec3i(0, 3, -1), + new Vec3i(0, 3, 0), + new Vec3i(0, 3, 1), + new Vec3i(1, 3, -1), + new Vec3i(1, 3, 0), + new Vec3i(1, 3, 1) + ), + Direction.UP, + ImmutableList.of( + new Vec3i(-1, -1, -1), + new Vec3i(-1, -1, 0), + new Vec3i(-1, -1, 1), + new Vec3i(0, -1, -1), + new Vec3i(0, -1, 0), + new Vec3i(0, -1, 1), + new Vec3i(1, -1, -1), + new Vec3i(1, -1, 0), + new Vec3i(1, -1, 1) + ), + Direction.EAST, + ImmutableList.of( + new Vec3i(-2, 0, -1), + new Vec3i(-2, 0, 0), + new Vec3i(-2, 0, 1), + new Vec3i(-2, 1, -1), + new Vec3i(-2, 1, 0), + new Vec3i(-2, 1, 1), + new Vec3i(-2, 2, -1), + new Vec3i(-2, 2, 0), + new Vec3i(-2, 2, 1) + ), + Direction.WEST, + ImmutableList.of( + new Vec3i(2, 0, -1), + new Vec3i(2, 0, 0), + new Vec3i(2, 0, 1), + new Vec3i(2, 1, -1), + new Vec3i(2, 1, 0), + new Vec3i(2, 1, 1), + new Vec3i(2, 2, -1), + new Vec3i(2, 2, 0), + new Vec3i(2, 2, 1) + ), + Direction.SOUTH, + ImmutableList.of( + new Vec3i(-1, 0, -2), + new Vec3i(0, 0, -2), + new Vec3i(1, 0, -2), + new Vec3i(-1, 1, -2), + new Vec3i(0, 1, -2), + new Vec3i(1, 1, -2), + new Vec3i(-1, 2, -2), + new Vec3i(0, 2, -2), + new Vec3i(1, 2, -2) + ), + Direction.NORTH, + ImmutableList.of( + new Vec3i(-1, 0, 2), + new Vec3i(0, 0, 2), + new Vec3i(1, 0, 2), + new Vec3i(-1, 1, 2), + new Vec3i(0, 1, 2), + new Vec3i(1, 1, 2), + new Vec3i(-1, 2, 2), + new Vec3i(0, 2, 2), + new Vec3i(1, 2, 2) + ) + ); + /** * @param properties 属性 */ @@ -246,9 +323,23 @@ public void tick( BlockPos bp = pos.offset(dx, dy, dz); BlockState blockState = level.getBlockState(bp); level.setBlock(bp, blockState.getFluidState().createLegacyBlock(), 3, 0); +// level.setBlock(bp, blockState.getFluidState().createLegacyBlock(), 18); } } } + + UPDATE_OFFSET.forEach((direction, offestList) -> offestList.forEach(offset -> { + BlockPos updatedPos = pos.offset(offset); + BlockPos fromPos = pos.relative(direction); + level.neighborShapeChanged(direction, + level.getBlockState(fromPos), + updatedPos, + fromPos, + 3, + 512 + ); + })); + FallingBlockEntity fallingBlockEntity = FallingGiantAnvilEntity.fall(level, above, state1, false); this.falling(fallingBlockEntity); } From fb72438314ab2701ff002d57d25d66486e910a64 Mon Sep 17 00:00:00 2001 From: YocyCraft Date: Sun, 22 Dec 2024 02:58:16 +0800 Subject: [PATCH 2/8] Make redstone wire connect behavior of block comparator be same as observer --- .../dubhe/anvilcraft/block/BlockComparatorBlock.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/dev/dubhe/anvilcraft/block/BlockComparatorBlock.java b/src/main/java/dev/dubhe/anvilcraft/block/BlockComparatorBlock.java index 6acc7153c..508e3f311 100644 --- a/src/main/java/dev/dubhe/anvilcraft/block/BlockComparatorBlock.java +++ b/src/main/java/dev/dubhe/anvilcraft/block/BlockComparatorBlock.java @@ -3,6 +3,7 @@ import com.mojang.serialization.MapCodec; import dev.dubhe.anvilcraft.api.hammer.HammerRotateBehavior; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; +import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -25,8 +26,12 @@ import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault public class BlockComparatorBlock extends HorizontalDirectionalBlock implements HammerRotateBehavior, IHammerRemovable { public static final MapCodec CODEC = simpleCodec(BlockComparatorBlock::new); @@ -152,6 +157,11 @@ protected void updateNeighborsInFront(Level level, BlockPos pos, BlockState stat level.updateNeighborsAtExceptFromFacing(blockpos, this, direction); } + @Override + public boolean canConnectRedstone(BlockState state, BlockGetter level, BlockPos pos, @Nullable Direction direction) { + return direction == state.getValue(FACING); + } + @Override protected boolean isSignalSource(BlockState state) { return true; From 6d65439cbf7a18ead0af996cc4e2890b623b008e Mon Sep 17 00:00:00 2001 From: YocyCraft Date: Sun, 22 Dec 2024 03:20:24 +0800 Subject: [PATCH 3/8] Remove comments --- .../java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java b/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java index 3ff9535f6..f4cff4e73 100644 --- a/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java +++ b/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java @@ -9,7 +9,6 @@ import dev.dubhe.anvilcraft.block.state.GiantAnvilCube; import dev.dubhe.anvilcraft.entity.FallingGiantAnvilEntity; import dev.dubhe.anvilcraft.init.ModBlocks; - import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -45,10 +44,8 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; - import net.neoforged.neoforge.common.NeoForge; import org.jetbrains.annotations.Nullable; - import javax.annotation.ParametersAreNonnullByDefault; import java.util.stream.Stream; @@ -323,14 +320,13 @@ public void tick( BlockPos bp = pos.offset(dx, dy, dz); BlockState blockState = level.getBlockState(bp); level.setBlock(bp, blockState.getFluidState().createLegacyBlock(), 3, 0); -// level.setBlock(bp, blockState.getFluidState().createLegacyBlock(), 18); } } } UPDATE_OFFSET.forEach((direction, offestList) -> offestList.forEach(offset -> { BlockPos updatedPos = pos.offset(offset); - BlockPos fromPos = pos.relative(direction); + BlockPos fromPos = updatedPos.relative(direction); level.neighborShapeChanged(direction, level.getBlockState(fromPos), updatedPos, From 0a81e19d399930bd33228f95910fcba8caa84932 Mon Sep 17 00:00:00 2001 From: YocyCraft Date: Sun, 22 Dec 2024 15:55:15 +0800 Subject: [PATCH 4/8] Fix conflict with mekanism --- .../dubhe/anvilcraft/block/AbstractMultiplePartBlock.java | 5 +---- .../dev/dubhe/anvilcraft/event/BreakBlockEventListener.java | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/dubhe/anvilcraft/block/AbstractMultiplePartBlock.java b/src/main/java/dev/dubhe/anvilcraft/block/AbstractMultiplePartBlock.java index fd3b64cbc..386e20a2b 100644 --- a/src/main/java/dev/dubhe/anvilcraft/block/AbstractMultiplePartBlock.java +++ b/src/main/java/dev/dubhe/anvilcraft/block/AbstractMultiplePartBlock.java @@ -22,7 +22,6 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Property; -import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.Nullable; @@ -116,9 +115,7 @@ private void preventCreativeDropFromMainPart( BlockState mainPartState = level.getBlockState(mainPartPos); if (!mainPartState.is(this)) return; if (!mainPartState.hasProperty(this.getPart())) return; - BlockState blockState2 = mainPartState.getFluidState().is(Fluids.WATER) - ? Blocks.WATER.defaultBlockState() - : Blocks.AIR.defaultBlockState(); + BlockState blockState2 = mainPartState.getFluidState().createLegacyBlock(); level.setBlock(mainPartPos, blockState2, 35); level.levelEvent(player, 2001, mainPartPos, Block.getId(mainPartState)); } diff --git a/src/main/java/dev/dubhe/anvilcraft/event/BreakBlockEventListener.java b/src/main/java/dev/dubhe/anvilcraft/event/BreakBlockEventListener.java index 1aea1fb36..d2c290e2c 100644 --- a/src/main/java/dev/dubhe/anvilcraft/event/BreakBlockEventListener.java +++ b/src/main/java/dev/dubhe/anvilcraft/event/BreakBlockEventListener.java @@ -14,9 +14,10 @@ public class BreakBlockEventListener { @SubscribeEvent public static void onBlockRemoved(BlockEvent.BreakEvent event) { Player player = event.getPlayer(); + if(!(player.level() instanceof ServerLevel serverLevel)) return; ItemStack stack = player.getMainHandItem(); ModEnchantmentHelper.onPostBreakBlock( - (ServerLevel) player.level(), + serverLevel, stack, player, EquipmentSlot.MAINHAND, From 9d990fddfaaff17ad5147f927478601c6ea75464 Mon Sep 17 00:00:00 2001 From: YocyCraft Date: Sun, 22 Dec 2024 16:30:48 +0800 Subject: [PATCH 5/8] Add CompatMods class for mod integrations Fix mekanism cardblock can wrap multiple part blocks --- .../tags/block/cardboard_blacklist.json | 9 +++++ .../java/dev/dubhe/anvilcraft/AnvilCraft.java | 4 +-- .../client/renderer/RenderState.java | 4 +-- .../anvilcraft/data/tags/BlockTagLoader.java | 35 +++++++++++-------- .../anvilcraft/data/tags/ItemTagLoader.java | 34 +++++++++--------- .../dubhe/anvilcraft/init/ModBlockTags.java | 8 +++++ .../anvilcraft/integration/CompatMods.java | 32 +++++++++++++++++ .../dubhe/anvilcraft/item/GuideBookItem.java | 4 +-- .../java/dev/dubhe/anvilcraft/util/Util.java | 3 +- 9 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 src/generated/resources/data/mekanism/tags/block/cardboard_blacklist.json create mode 100644 src/main/java/dev/dubhe/anvilcraft/integration/CompatMods.java diff --git a/src/generated/resources/data/mekanism/tags/block/cardboard_blacklist.json b/src/generated/resources/data/mekanism/tags/block/cardboard_blacklist.json new file mode 100644 index 000000000..d2481a5c8 --- /dev/null +++ b/src/generated/resources/data/mekanism/tags/block/cardboard_blacklist.json @@ -0,0 +1,9 @@ +{ + "values": [ + "anvilcraft:giant_anvil", + "anvilcraft:transmission_pole", + "anvilcraft:remote_transmission_pole", + "anvilcraft:tesla_tower", + "anvilcraft:overseer" + ] +} \ No newline at end of file diff --git a/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java b/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java index 6683c7e47..0157061dd 100644 --- a/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java +++ b/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java @@ -21,10 +21,10 @@ import dev.dubhe.anvilcraft.init.ModNetworks; import dev.dubhe.anvilcraft.init.ModRecipeTypes; import dev.dubhe.anvilcraft.init.ModVillagers; +import dev.dubhe.anvilcraft.integration.CompatMods; import dev.dubhe.anvilcraft.integration.top.AnvilCraftTopPlugin; import dev.dubhe.anvilcraft.recipe.anvil.cache.RecipeCaches; import dev.dubhe.anvilcraft.util.ModInteractionMap; -import dev.dubhe.anvilcraft.util.Util; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -137,7 +137,7 @@ public static void addReloadListeners(@NotNull AddReloadListenerEvent event) { public static void loadComplete(@NotNull FMLLoadCompleteEvent event) { event.enqueueWork(() -> { ModInteractionMap.initInteractionMap(); - if (Util.isLoaded("theoneprobe")) { + if (CompatMods.THE_ONE_PROBE.isLoaded()) { LOGGER.info("TheOneProbe found. Loading AnvilCraft TheOneProbe plugin..."); AnvilCraftTopPlugin.init(); } diff --git a/src/main/java/dev/dubhe/anvilcraft/client/renderer/RenderState.java b/src/main/java/dev/dubhe/anvilcraft/client/renderer/RenderState.java index b3587b2be..88add2e33 100644 --- a/src/main/java/dev/dubhe/anvilcraft/client/renderer/RenderState.java +++ b/src/main/java/dev/dubhe/anvilcraft/client/renderer/RenderState.java @@ -2,10 +2,10 @@ import com.mojang.logging.LogUtils; import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.integration.CompatMods; import dev.dubhe.anvilcraft.integration.iris.IrisState; import lombok.Getter; import net.minecraft.client.Minecraft; -import net.neoforged.fml.ModList; import org.slf4j.Logger; public class RenderState { @@ -15,7 +15,7 @@ public class RenderState { private static final Logger logger = LogUtils.getLogger(); static { - IRIS_PRESENT = ModList.get().isLoaded("iris"); + IRIS_PRESENT = CompatMods.IRIS.isLoaded(); } public static boolean isIrisPresent() { diff --git a/src/main/java/dev/dubhe/anvilcraft/data/tags/BlockTagLoader.java b/src/main/java/dev/dubhe/anvilcraft/data/tags/BlockTagLoader.java index a998b7789..c3cf51fc8 100644 --- a/src/main/java/dev/dubhe/anvilcraft/data/tags/BlockTagLoader.java +++ b/src/main/java/dev/dubhe/anvilcraft/data/tags/BlockTagLoader.java @@ -88,22 +88,22 @@ public static void init(@NotNull RegistrateTagsProvider provider) { .add(findResourceKey(Blocks.ANVIL)) .add(findResourceKey(Blocks.CHIPPED_ANVIL)) .add(findResourceKey(Blocks.DAMAGED_ANVIL)) - .add(findResourceKey(ModBlocks.HEAVY_IRON_BLOCK.get())) - .add(findResourceKey(ModBlocks.HEAVY_IRON_BEAM.get())) - .add(findResourceKey(ModBlocks.HEAVY_IRON_COLUMN.get())) - .add(findResourceKey(ModBlocks.HEAVY_IRON_PLATE.get())) - .add(findResourceKey(ModBlocks.CUT_HEAVY_IRON_BLOCK.get())) - .add(findResourceKey(ModBlocks.CUT_HEAVY_IRON_SLAB.get())) - .add(findResourceKey(ModBlocks.CUT_HEAVY_IRON_STAIRS.get())) - .add(findResourceKey(ModBlocks.POLISHED_HEAVY_IRON_BLOCK.get())) - .add(findResourceKey(ModBlocks.POLISHED_HEAVY_IRON_SLAB.get())) - .add(findResourceKey(ModBlocks.POLISHED_HEAVY_IRON_STAIRS.get())); + .add(ModBlocks.HEAVY_IRON_BLOCK.getKey()) + .add(ModBlocks.HEAVY_IRON_BEAM.getKey()) + .add(ModBlocks.HEAVY_IRON_COLUMN.getKey()) + .add(ModBlocks.HEAVY_IRON_PLATE.getKey()) + .add(ModBlocks.CUT_HEAVY_IRON_BLOCK.getKey()) + .add(ModBlocks.CUT_HEAVY_IRON_SLAB.getKey()) + .add(ModBlocks.CUT_HEAVY_IRON_STAIRS.getKey()) + .add(ModBlocks.POLISHED_HEAVY_IRON_BLOCK.getKey()) + .add(ModBlocks.POLISHED_HEAVY_IRON_SLAB.getKey()) + .add(ModBlocks.POLISHED_HEAVY_IRON_STAIRS.getKey()); provider.addTag(ModBlockTags.UNDER_CAULDRON) .addTag(BlockTags.CAMPFIRES) .add(findResourceKey(Blocks.MAGMA_BLOCK)) - .add(findResourceKey(ModBlocks.HEATER.get())) - .add(findResourceKey(ModBlocks.CORRUPTED_BEACON.get())); + .add(ModBlocks.HEATER.getKey()) + .add(ModBlocks.CORRUPTED_BEACON.getKey()); provider.addTag(ModBlockTags.BLOCK_DEVOURER_PROBABILITY_DROPPING) .add(findResourceKey(Blocks.STONE)) @@ -132,7 +132,14 @@ public static void init(@NotNull RegistrateTagsProvider provider) { provider.addTag(ModBlockTags.NEUTRONIUM_CANNOT_PASS_THROUGH) .add(findResourceKey(Blocks.END_STONE)) .add(findResourceKey(Blocks.BEDROCK)) - .add(findResourceKey(ModBlocks.END_DUST.get())) - .add(findResourceKey(ModBlocks.NEGATIVE_MATTER_BLOCK.get())); + .add(ModBlocks.END_DUST.getKey()) + .add(ModBlocks.NEGATIVE_MATTER_BLOCK.getKey()); + + provider.addTag(ModBlockTags.MEKANISM_CARDBOARD_BOX_BLACKLIST) + .add(ModBlocks.GIANT_ANVIL.getKey()) + .add(ModBlocks.TRANSMISSION_POLE.getKey()) + .add(ModBlocks.REMOTE_TRANSMISSION_POLE.getKey()) + .add(ModBlocks.TESLA_TOWER.getKey()) + .add(ModBlocks.OVERSEER_BLOCK.getKey()); } } diff --git a/src/main/java/dev/dubhe/anvilcraft/data/tags/ItemTagLoader.java b/src/main/java/dev/dubhe/anvilcraft/data/tags/ItemTagLoader.java index f4fff1418..79121a13a 100644 --- a/src/main/java/dev/dubhe/anvilcraft/data/tags/ItemTagLoader.java +++ b/src/main/java/dev/dubhe/anvilcraft/data/tags/ItemTagLoader.java @@ -29,52 +29,52 @@ public static void init(@NotNull RegistrateTagsProvider provider) { provider.addTag(ModItemTags.GOLD_PLATES).add(findResourceKey(Items.LIGHT_WEIGHTED_PRESSURE_PLATE)); provider.addTag(ModItemTags.ROYAL_STEEL_PICKAXE_BASE) - .add(findResourceKey(ModItems.AMETHYST_PICKAXE.get())) + .add(ModItems.AMETHYST_PICKAXE.getKey()) .add(findResourceKey(Items.GOLDEN_PICKAXE)) .add(findResourceKey(Items.IRON_PICKAXE)) .add(findResourceKey(Items.DIAMOND_PICKAXE)); provider.addTag(ModItemTags.ROYAL_STEEL_AXE_BASE) - .add(findResourceKey(ModItems.AMETHYST_AXE.get())) + .add(ModItems.AMETHYST_AXE.getKey()) .add(findResourceKey(Items.GOLDEN_AXE)) .add(findResourceKey(Items.IRON_AXE)) .add(findResourceKey(Items.DIAMOND_AXE)); provider.addTag(ModItemTags.ROYAL_STEEL_HOE_BASE) - .add(findResourceKey(ModItems.AMETHYST_HOE.get())) + .add(ModItems.AMETHYST_HOE.getKey()) .add(findResourceKey(Items.GOLDEN_HOE)) .add(findResourceKey(Items.IRON_HOE)) .add(findResourceKey(Items.DIAMOND_HOE)); provider.addTag(ModItemTags.ROYAL_STEEL_SWORD_BASE) - .add(findResourceKey(ModItems.AMETHYST_SWORD.get())) + .add(ModItems.AMETHYST_SWORD.getKey()) .add(findResourceKey(Items.GOLDEN_SWORD)) .add(findResourceKey(Items.IRON_SWORD)) .add(findResourceKey(Items.DIAMOND_SWORD)); provider.addTag(ModItemTags.ROYAL_STEEL_SHOVEL_BASE) - .add(findResourceKey(ModItems.AMETHYST_SHOVEL.get())) + .add(ModItems.AMETHYST_SHOVEL.getKey()) .add(findResourceKey(Items.GOLDEN_SHOVEL)) .add(findResourceKey(Items.IRON_SHOVEL)) .add(findResourceKey(Items.DIAMOND_SHOVEL)); provider.addTag(ModItemTags.EMBER_METAL_PICKAXE_BASE) - .add(findResourceKey(ModItems.ROYAL_STEEL_PICKAXE.get())) + .add(ModItems.ROYAL_STEEL_PICKAXE.getKey()) .add(findResourceKey(Items.NETHERITE_PICKAXE)); provider.addTag(ModItemTags.EMBER_METAL_AXE_BASE) - .add(findResourceKey(ModItems.ROYAL_STEEL_AXE.get())) + .add(ModItems.ROYAL_STEEL_AXE.getKey()) .add(findResourceKey(Items.NETHERITE_AXE)); provider.addTag(ModItemTags.EMBER_METAL_HOE_BASE) - .add(findResourceKey(ModItems.ROYAL_STEEL_HOE.get())) + .add(ModItems.ROYAL_STEEL_HOE.getKey()) .add(findResourceKey(Items.NETHERITE_HOE)); provider.addTag(ModItemTags.EMBER_METAL_SWORD_BASE) - .add(findResourceKey(ModItems.ROYAL_STEEL_SWORD.get())) + .add(ModItems.ROYAL_STEEL_SWORD.getKey()) .add(findResourceKey(Items.NETHERITE_SWORD)); provider.addTag(ModItemTags.EMBER_METAL_SHOVEL_BASE) - .add(findResourceKey(ModItems.ROYAL_STEEL_SHOVEL.get())) + .add(ModItems.ROYAL_STEEL_SHOVEL.getKey()) .add(findResourceKey(Items.NETHERITE_SHOVEL)); provider.addTag(ModItemTags.GEMS) .add(findResourceKey(Items.EMERALD)) - .add(findResourceKey(ModItems.RUBY.get())) - .add(findResourceKey(ModItems.SAPPHIRE.get())) - .add(findResourceKey(ModItems.TOPAZ.get())); + .add(ModItems.RUBY.getKey()) + .add(ModItems.SAPPHIRE.getKey()) + .add(ModItems.TOPAZ.getKey()); provider.addTag(ModItemTags.GEM_BLOCKS) .add(findResourceKey(Items.EMERALD_BLOCK)) .add(findResourceKey(ModBlocks.RUBY_BLOCK.asItem())) @@ -103,9 +103,9 @@ public static void init(@NotNull RegistrateTagsProvider provider) { .add(findResourceKey(Items.SWEET_BERRIES)) .add(findResourceKey(Items.GLOW_BERRIES)); provider.addTag(ModItemTags.WRENCH) - .add(findResourceKey(ModItems.ANVIL_HAMMER.get())) - .add(findResourceKey(ModItems.ROYAL_ANVIL_HAMMER.get())) - .add(findResourceKey(ModItems.EMBER_ANVIL_HAMMER.get())); + .add(ModItems.ANVIL_HAMMER.getKey()) + .add(ModItems.ROYAL_ANVIL_HAMMER.getKey()) + .add(ModItems.EMBER_ANVIL_HAMMER.getKey()); provider.addTag(ModItemTags.FIRE_STARTER) .add(findResourceKey(Items.TORCH)) .add(findResourceKey(Items.SOUL_TORCH)) @@ -129,7 +129,7 @@ public static void init(@NotNull RegistrateTagsProvider provider) { provider.addTag(ModItemTags.EXPLOSION_PROOF) .add(findResourceKey(ModBlocks.EARTH_CORE_SHARD_BLOCK.asItem())) .add(findResourceKey(ModBlocks.EARTH_CORE_SHARD_ORE.asItem())) - .add(findResourceKey(ModItems.EARTH_CORE_SHARD.get())); + .add(ModItems.EARTH_CORE_SHARD.getKey()); } private static ResourceKey findResourceKey(Item item) { diff --git a/src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java b/src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java index ab7d80674..8e8fd100f 100644 --- a/src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java +++ b/src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java @@ -2,6 +2,7 @@ import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.integration.CompatMods; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; @@ -59,10 +60,17 @@ public class ModBlockTags { public static final TagKey INCORRECT_FOR_AMYTHEST_TOOL = bind("incorrect_for_amythest_tool"); public static final TagKey INCORRECT_FOR_EMBER_TOOL = bind("incorrect_for_ember_tool"); + //mekanism tags + public static final TagKey MEKANISM_CARDBOARD_BOX_BLACKLIST = bindMekanism("cardboard_blacklist"); + private static @NotNull TagKey bindC(String id) { return TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("c", id)); } + private static @NotNull TagKey bindMekanism(String id){ + return TagKey.create(Registries.BLOCK, CompatMods.MEKANISM.of(id)); + } + private static @NotNull TagKey bind(String id) { return TagKey.create(Registries.BLOCK, AnvilCraft.of(id)); } diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/CompatMods.java b/src/main/java/dev/dubhe/anvilcraft/integration/CompatMods.java new file mode 100644 index 000000000..903466199 --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/integration/CompatMods.java @@ -0,0 +1,32 @@ +package dev.dubhe.anvilcraft.integration; + +import net.minecraft.resources.ResourceLocation; +import net.neoforged.fml.ModList; + +public enum CompatMods { + CURIOS("curios"), + EMBEDDIUM("embeddium"), + IRIS("iris"), + JADE("jade"), + JEI("jei"), + KUBEJS("kubejs"), + MEKANISM("mekanism"), + PATCHOULI("patchouli"), + SODIUM("sodium"), + THE_ONE_PROBE("theoneprobe"), + WTHIT("wthit"); + + public final String modId; + + CompatMods(String modId) { + this.modId = modId; + } + + public boolean isLoaded(){ + return ModList.get().isLoaded(this.modId); + } + + public ResourceLocation of(String path){ + return ResourceLocation.fromNamespaceAndPath(this.modId, path); + } +} diff --git a/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java b/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java index 8bc9a6649..fa995b3dc 100644 --- a/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java +++ b/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java @@ -1,7 +1,7 @@ package dev.dubhe.anvilcraft.item; +import dev.dubhe.anvilcraft.integration.CompatMods; import dev.dubhe.anvilcraft.integration.patchouli.PatchouliUtil; -import dev.dubhe.anvilcraft.util.Util; import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; @@ -27,7 +27,7 @@ public GuideBookItem(Properties properties) { @Override public InteractionResultHolder use(Level level, Player player, InteractionHand usedHand) { if (player instanceof ServerPlayer serverPlayer) { - if (Util.isLoaded("patchouli")) { + if (CompatMods.PATCHOULI.isLoaded()) { PatchouliUtil.openBook(serverPlayer); return new InteractionResultHolder<>(InteractionResult.CONSUME, player.getItemInHand(usedHand)); } else { diff --git a/src/main/java/dev/dubhe/anvilcraft/util/Util.java b/src/main/java/dev/dubhe/anvilcraft/util/Util.java index d729d0757..959dacf8d 100644 --- a/src/main/java/dev/dubhe/anvilcraft/util/Util.java +++ b/src/main/java/dev/dubhe/anvilcraft/util/Util.java @@ -1,5 +1,6 @@ package dev.dubhe.anvilcraft.util; +import dev.dubhe.anvilcraft.integration.CompatMods; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.InteractionResult; @@ -21,7 +22,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class Util { - public static final Lazy jadePresent = new Lazy<>(() -> isLoaded("jade") || isLoaded("wthit")); + public static final Lazy jadePresent = new Lazy<>(() -> CompatMods.JADE.isLoaded() || CompatMods.WTHIT.isLoaded()); private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); public static final Direction[] HORIZONTAL_DIRECTIONS = new Direction[] { Direction.SOUTH, From 415516358f3a50f8080c92e0d8af237210fe0960 Mon Sep 17 00:00:00 2001 From: YocyCraft Date: Sun, 22 Dec 2024 17:07:58 +0800 Subject: [PATCH 6/8] revert changes --- src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java | 4 ++-- .../dev/dubhe/anvilcraft/client/renderer/RenderState.java | 4 ++-- src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java | 5 +++-- src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java | 4 ++-- src/main/java/dev/dubhe/anvilcraft/util/Util.java | 3 +-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java b/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java index 0157061dd..34d02890b 100644 --- a/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java +++ b/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java @@ -21,11 +21,11 @@ import dev.dubhe.anvilcraft.init.ModNetworks; import dev.dubhe.anvilcraft.init.ModRecipeTypes; import dev.dubhe.anvilcraft.init.ModVillagers; -import dev.dubhe.anvilcraft.integration.CompatMods; import dev.dubhe.anvilcraft.integration.top.AnvilCraftTopPlugin; import dev.dubhe.anvilcraft.recipe.anvil.cache.RecipeCaches; import dev.dubhe.anvilcraft.util.ModInteractionMap; +import dev.dubhe.anvilcraft.util.Util; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; @@ -137,7 +137,7 @@ public static void addReloadListeners(@NotNull AddReloadListenerEvent event) { public static void loadComplete(@NotNull FMLLoadCompleteEvent event) { event.enqueueWork(() -> { ModInteractionMap.initInteractionMap(); - if (CompatMods.THE_ONE_PROBE.isLoaded()) { + if (Util.isLoaded("theoneprobe")) { LOGGER.info("TheOneProbe found. Loading AnvilCraft TheOneProbe plugin..."); AnvilCraftTopPlugin.init(); } diff --git a/src/main/java/dev/dubhe/anvilcraft/client/renderer/RenderState.java b/src/main/java/dev/dubhe/anvilcraft/client/renderer/RenderState.java index 88add2e33..dda03776c 100644 --- a/src/main/java/dev/dubhe/anvilcraft/client/renderer/RenderState.java +++ b/src/main/java/dev/dubhe/anvilcraft/client/renderer/RenderState.java @@ -2,8 +2,8 @@ import com.mojang.logging.LogUtils; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.integration.CompatMods; import dev.dubhe.anvilcraft.integration.iris.IrisState; +import dev.dubhe.anvilcraft.util.Util; import lombok.Getter; import net.minecraft.client.Minecraft; import org.slf4j.Logger; @@ -15,7 +15,7 @@ public class RenderState { private static final Logger logger = LogUtils.getLogger(); static { - IRIS_PRESENT = CompatMods.IRIS.isLoaded(); + IRIS_PRESENT = Util.isLoaded("iris"); } public static boolean isIrisPresent() { diff --git a/src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java b/src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java index 8e8fd100f..889d74391 100644 --- a/src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java +++ b/src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java @@ -2,7 +2,6 @@ import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.integration.CompatMods; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; @@ -11,6 +10,8 @@ import org.jetbrains.annotations.NotNull; public class ModBlockTags { + + private static final String MEKANISM_MODID = "mekanism"; // mod tags public static final TagKey UNDER_CAULDRON = bind("under_cauldron"); public static final TagKey MAGNET = bind("magnet"); @@ -68,7 +69,7 @@ public class ModBlockTags { } private static @NotNull TagKey bindMekanism(String id){ - return TagKey.create(Registries.BLOCK, CompatMods.MEKANISM.of(id)); + return TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(MEKANISM_MODID, id)); } private static @NotNull TagKey bind(String id) { diff --git a/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java b/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java index fa995b3dc..3ebde0f60 100644 --- a/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java +++ b/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java @@ -1,8 +1,8 @@ package dev.dubhe.anvilcraft.item; -import dev.dubhe.anvilcraft.integration.CompatMods; import dev.dubhe.anvilcraft.integration.patchouli.PatchouliUtil; +import dev.dubhe.anvilcraft.util.Util; import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.network.chat.Component; @@ -27,7 +27,7 @@ public GuideBookItem(Properties properties) { @Override public InteractionResultHolder use(Level level, Player player, InteractionHand usedHand) { if (player instanceof ServerPlayer serverPlayer) { - if (CompatMods.PATCHOULI.isLoaded()) { + if (Util.isLoaded("patchouli")) { PatchouliUtil.openBook(serverPlayer); return new InteractionResultHolder<>(InteractionResult.CONSUME, player.getItemInHand(usedHand)); } else { diff --git a/src/main/java/dev/dubhe/anvilcraft/util/Util.java b/src/main/java/dev/dubhe/anvilcraft/util/Util.java index 959dacf8d..d729d0757 100644 --- a/src/main/java/dev/dubhe/anvilcraft/util/Util.java +++ b/src/main/java/dev/dubhe/anvilcraft/util/Util.java @@ -1,6 +1,5 @@ package dev.dubhe.anvilcraft.util; -import dev.dubhe.anvilcraft.integration.CompatMods; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.InteractionResult; @@ -22,7 +21,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class Util { - public static final Lazy jadePresent = new Lazy<>(() -> CompatMods.JADE.isLoaded() || CompatMods.WTHIT.isLoaded()); + public static final Lazy jadePresent = new Lazy<>(() -> isLoaded("jade") || isLoaded("wthit")); private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); public static final Direction[] HORIZONTAL_DIRECTIONS = new Direction[] { Direction.SOUTH, From 79c72dcc6e3fd9107c1c3d6e61b9ac8d94420f38 Mon Sep 17 00:00:00 2001 From: YocyCraft Date: Sun, 22 Dec 2024 17:12:29 +0800 Subject: [PATCH 7/8] Rearrange imports --- src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java | 2 +- src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java b/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java index 34d02890b..6683c7e47 100644 --- a/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java +++ b/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java @@ -24,8 +24,8 @@ import dev.dubhe.anvilcraft.integration.top.AnvilCraftTopPlugin; import dev.dubhe.anvilcraft.recipe.anvil.cache.RecipeCaches; import dev.dubhe.anvilcraft.util.ModInteractionMap; - import dev.dubhe.anvilcraft.util.Util; + import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; diff --git a/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java b/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java index 3ebde0f60..8bc9a6649 100644 --- a/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java +++ b/src/main/java/dev/dubhe/anvilcraft/item/GuideBookItem.java @@ -1,8 +1,8 @@ package dev.dubhe.anvilcraft.item; import dev.dubhe.anvilcraft.integration.patchouli.PatchouliUtil; - import dev.dubhe.anvilcraft.util.Util; + import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.network.chat.Component; From 8f5d87d6a851f035bd24e158a9186141c1511281 Mon Sep 17 00:00:00 2001 From: YocyCraft Date: Sun, 22 Dec 2024 19:08:40 +0800 Subject: [PATCH 8/8] Remove CompatMods class --- .../anvilcraft/integration/CompatMods.java | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 src/main/java/dev/dubhe/anvilcraft/integration/CompatMods.java diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/CompatMods.java b/src/main/java/dev/dubhe/anvilcraft/integration/CompatMods.java deleted file mode 100644 index 903466199..000000000 --- a/src/main/java/dev/dubhe/anvilcraft/integration/CompatMods.java +++ /dev/null @@ -1,32 +0,0 @@ -package dev.dubhe.anvilcraft.integration; - -import net.minecraft.resources.ResourceLocation; -import net.neoforged.fml.ModList; - -public enum CompatMods { - CURIOS("curios"), - EMBEDDIUM("embeddium"), - IRIS("iris"), - JADE("jade"), - JEI("jei"), - KUBEJS("kubejs"), - MEKANISM("mekanism"), - PATCHOULI("patchouli"), - SODIUM("sodium"), - THE_ONE_PROBE("theoneprobe"), - WTHIT("wthit"); - - public final String modId; - - CompatMods(String modId) { - this.modId = modId; - } - - public boolean isLoaded(){ - return ModList.get().isLoaded(this.modId); - } - - public ResourceLocation of(String path){ - return ResourceLocation.fromNamespaceAndPath(this.modId, path); - } -}