diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/block/ConnectorBlock.java b/src/main/java/io/github/mattidragon/extendeddrawers/block/ConnectorBlock.java deleted file mode 100644 index f955614..0000000 --- a/src/main/java/io/github/mattidragon/extendeddrawers/block/ConnectorBlock.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.github.mattidragon.extendeddrawers.block; - -import io.github.mattidragon.extendeddrawers.block.base.NetworkComponent; -import net.minecraft.block.Block; - -public class ConnectorBlock extends Block implements NetworkComponent { - public ConnectorBlock(Settings settings) { - super(settings); - } -} diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/block/ControllerBlock.java b/src/main/java/io/github/mattidragon/extendeddrawers/block/ControllerBlock.java index 8dd9d0f..d1e26b4 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/block/ControllerBlock.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/block/ControllerBlock.java @@ -1,7 +1,7 @@ package io.github.mattidragon.extendeddrawers.block; import io.github.mattidragon.extendeddrawers.block.base.Lockable; -import io.github.mattidragon.extendeddrawers.block.base.NetworkComponent; +import io.github.mattidragon.extendeddrawers.util.NetworkHelper; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage; @@ -21,13 +21,12 @@ import static io.github.mattidragon.extendeddrawers.util.DrawerInteractionStatusManager.getAndResetInsertStatus; -@SuppressWarnings("UnstableApiUsage") -public class ControllerBlock extends Block implements Lockable, NetworkComponent { +@SuppressWarnings({"UnstableApiUsage", "deprecation"}) // transfer api and mojank block method deprecation +public class ControllerBlock extends Block implements Lockable { public ControllerBlock(Settings settings) { super(settings); - //noinspection UnstableApiUsage - ItemStorage.SIDED.registerForBlocks((world, pos, state, entity, dir) -> new CombinedStorage<>(NetworkComponent.getConnectedStorages(world, pos)), this); + ItemStorage.SIDED.registerForBlocks((world, pos, state, entity, dir) -> new CombinedStorage<>(NetworkHelper.getConnectedStorages(world, pos)), this); } @Override @@ -58,7 +57,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt @Override public ActionResult toggleLock(BlockState state, World world, BlockPos pos, Vec3d hitPos, Direction side) { - var storages = NetworkComponent.getConnectedStorages(world, pos); + var storages = NetworkHelper.getConnectedStorages(world, pos); var stateSum = storages.stream() .map(storage -> storage.locked) .reduce(0, (count, value) -> count + (value ? 1 : -1), Integer::sum); diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/block/DrawerBlock.java b/src/main/java/io/github/mattidragon/extendeddrawers/block/DrawerBlock.java index 0b511bd..c0ce341 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/block/DrawerBlock.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/block/DrawerBlock.java @@ -2,10 +2,8 @@ import io.github.mattidragon.extendeddrawers.block.base.BaseBlock; import io.github.mattidragon.extendeddrawers.block.base.Lockable; -import io.github.mattidragon.extendeddrawers.block.base.NetworkComponent; import io.github.mattidragon.extendeddrawers.block.base.Upgradable; import io.github.mattidragon.extendeddrawers.block.entity.DrawerBlockEntity; -import io.github.mattidragon.extendeddrawers.drawer.DrawerSlot; import io.github.mattidragon.extendeddrawers.item.UpgradeItem; import io.github.mattidragon.extendeddrawers.registry.ModBlocks; import io.github.mattidragon.extendeddrawers.util.DrawerRaycastUtil; @@ -37,7 +35,7 @@ import static io.github.mattidragon.extendeddrawers.util.DrawerInteractionStatusManager.getAndResetInsertStatus; @SuppressWarnings({"UnstableApiUsage", "deprecation"}) // transfer api and mojank block method deprecation -public class DrawerBlock extends BaseBlock implements Lockable, Upgradable, NetworkComponent { +public class DrawerBlock extends BaseBlock implements Lockable, Upgradable { public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; public final int slots; diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/block/ShadowDrawerBlock.java b/src/main/java/io/github/mattidragon/extendeddrawers/block/ShadowDrawerBlock.java index a3b1e44..fb147a1 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/block/ShadowDrawerBlock.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/block/ShadowDrawerBlock.java @@ -1,7 +1,6 @@ package io.github.mattidragon.extendeddrawers.block; import io.github.mattidragon.extendeddrawers.block.base.BaseBlock; -import io.github.mattidragon.extendeddrawers.block.base.NetworkComponent; import io.github.mattidragon.extendeddrawers.block.entity.ShadowDrawerBlockEntity; import io.github.mattidragon.extendeddrawers.registry.ModBlocks; import io.github.mattidragon.extendeddrawers.util.DrawerRaycastUtil; @@ -14,7 +13,6 @@ import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; import net.minecraft.state.property.DirectionProperty; @@ -32,8 +30,8 @@ import static io.github.mattidragon.extendeddrawers.util.DrawerInteractionStatusManager.getAndResetExtractionTimer; import static io.github.mattidragon.extendeddrawers.util.DrawerInteractionStatusManager.getAndResetInsertStatus; -@SuppressWarnings("UnstableApiUsage") -public class ShadowDrawerBlock extends BaseBlock implements NetworkComponent { +@SuppressWarnings({"UnstableApiUsage", "deprecation"}) // transfer api and mojank block method deprecation +public class ShadowDrawerBlock extends BaseBlock { public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; public ShadowDrawerBlock(Settings settings) { diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/block/entity/DrawerBlockEntity.java b/src/main/java/io/github/mattidragon/extendeddrawers/block/entity/DrawerBlockEntity.java index 8ca641c..abed8da 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/block/entity/DrawerBlockEntity.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/block/entity/DrawerBlockEntity.java @@ -1,11 +1,11 @@ package io.github.mattidragon.extendeddrawers.block.entity; import io.github.mattidragon.extendeddrawers.block.DrawerBlock; -import io.github.mattidragon.extendeddrawers.drawer.DrawerSlot; import io.github.mattidragon.extendeddrawers.block.ShadowDrawerBlock; -import io.github.mattidragon.extendeddrawers.block.base.NetworkComponent; +import io.github.mattidragon.extendeddrawers.drawer.DrawerSlot; import io.github.mattidragon.extendeddrawers.item.UpgradeItem; import io.github.mattidragon.extendeddrawers.registry.ModBlocks; +import io.github.mattidragon.extendeddrawers.util.NetworkHelper; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; @@ -44,7 +44,7 @@ private void onSlotChanged() { markDirty(); assert world != null; world.updateListeners(pos, getCachedState(), getCachedState(), Block.NOTIFY_LISTENERS); - NetworkComponent.findConnectedComponents(world, pos, (world1, pos1) -> world1.getBlockState(pos1).getBlock() instanceof ShadowDrawerBlock) + NetworkHelper.findConnectedComponents(world, pos, (world1, pos1) -> world1.getBlockState(pos1).getBlock() instanceof ShadowDrawerBlock) .forEach(pos1 -> { var state1 = world.getBlockState(pos1); world.updateListeners(pos1, state1, state1, Block.NOTIFY_LISTENERS); diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/block/entity/ShadowDrawerBlockEntity.java b/src/main/java/io/github/mattidragon/extendeddrawers/block/entity/ShadowDrawerBlockEntity.java index 9ac1347..42a8999 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/block/entity/ShadowDrawerBlockEntity.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/block/entity/ShadowDrawerBlockEntity.java @@ -1,7 +1,7 @@ package io.github.mattidragon.extendeddrawers.block.entity; -import io.github.mattidragon.extendeddrawers.block.base.NetworkComponent; import io.github.mattidragon.extendeddrawers.registry.ModBlocks; +import io.github.mattidragon.extendeddrawers.util.NetworkHelper; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; @@ -28,7 +28,7 @@ public ShadowDrawerBlockEntity(BlockPos pos, BlockState state) { } public Storage createStorage() { - return new CombinedStorage<>(NetworkComponent.getConnectedStorages(world, pos).stream().filter(slot -> slot.item.equals(item) || slot.item.isBlank()).toList()); + return new CombinedStorage<>(NetworkHelper.getConnectedStorages(world, pos).stream().filter(slot -> slot.item.equals(item) || slot.item.isBlank()).toList()); } @Nullable diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/client/renderer/DrawerBlockEntityRenderer.java b/src/main/java/io/github/mattidragon/extendeddrawers/client/renderer/DrawerBlockEntityRenderer.java index 008c6ae..bfda63e 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/client/renderer/DrawerBlockEntityRenderer.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/client/renderer/DrawerBlockEntityRenderer.java @@ -1,13 +1,8 @@ package io.github.mattidragon.extendeddrawers.client.renderer; -import com.google.common.collect.Collections2; -import com.ibm.icu.impl.locale.XCldrStub; import io.github.mattidragon.extendeddrawers.block.DrawerBlock; -import io.github.mattidragon.extendeddrawers.drawer.DrawerSlot; import io.github.mattidragon.extendeddrawers.block.entity.DrawerBlockEntity; -import io.github.mattidragon.extendeddrawers.item.UpgradeItem; -import io.github.mattidragon.extendeddrawers.registry.ModItems; -import io.github.mattidragon.extendeddrawers.util.CollectionUtils; +import io.github.mattidragon.extendeddrawers.drawer.DrawerSlot; import net.fabricmc.fabric.api.renderer.v1.RendererAccess; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.minecraft.client.MinecraftClient; @@ -25,12 +20,9 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Vec3f; -import org.apache.commons.compress.utils.Lists; import java.util.ArrayList; -import java.util.Collections; import java.util.Objects; -import java.util.function.Predicate; import java.util.stream.StreamSupport; import static io.github.mattidragon.extendeddrawers.ExtendedDrawers.id; diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/client/renderer/ShadowDrawerBlockEntityRenderer.java b/src/main/java/io/github/mattidragon/extendeddrawers/client/renderer/ShadowDrawerBlockEntityRenderer.java index 001e575..fb2e64f 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/client/renderer/ShadowDrawerBlockEntityRenderer.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/client/renderer/ShadowDrawerBlockEntityRenderer.java @@ -2,7 +2,6 @@ import io.github.mattidragon.extendeddrawers.block.ShadowDrawerBlock; import io.github.mattidragon.extendeddrawers.block.entity.ShadowDrawerBlockEntity; -import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.VertexConsumerProvider; diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersBlockTagProvider.java b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersBlockTagProvider.java index 3fe0c3c..3ad2676 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersBlockTagProvider.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersBlockTagProvider.java @@ -1,5 +1,7 @@ package io.github.mattidragon.extendeddrawers.datagen; +import io.github.mattidragon.extendeddrawers.registry.ModBlocks; +import io.github.mattidragon.extendeddrawers.registry.ModTags; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; @@ -10,5 +12,7 @@ public DrawersBlockTagProvider(FabricDataGenerator dataGenerator) { @Override protected void generateTags() { + getOrCreateTagBuilder(ModTags.BlockTags.DRAWERS).add(ModBlocks.SHADOW_DRAWER, ModBlocks.SINGLE_DRAWER, ModBlocks.DOUBLE_DRAWER, ModBlocks.QUAD_DRAWER); + getOrCreateTagBuilder(ModTags.BlockTags.NETWORK_COMPONENTS).addTag(ModTags.BlockTags.DRAWERS).add(ModBlocks.CONTROLLER, ModBlocks.CONNECTOR); } } diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersItemTagProvider.java b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersItemTagProvider.java index fd27c89..c45acdc 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersItemTagProvider.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersItemTagProvider.java @@ -1,6 +1,7 @@ package io.github.mattidragon.extendeddrawers.datagen; import io.github.mattidragon.extendeddrawers.registry.ModItems; +import io.github.mattidragon.extendeddrawers.registry.ModTags; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; import org.jetbrains.annotations.Nullable; @@ -12,6 +13,6 @@ public DrawersItemTagProvider(FabricDataGenerator dataGenerator, @Nullable Block @Override protected void generateTags() { - getOrCreateTagBuilder(ExtendedDrawersDatagen.DRAWERS).add(ModItems.SHADOW_DRAWER, ModItems.SINGLE_DRAWER, ModItems.DOUBLE_DRAWER, ModItems.QUAD_DRAWER); + getOrCreateTagBuilder(ModTags.ItemTags.DRAWERS).add(ModItems.SHADOW_DRAWER, ModItems.SINGLE_DRAWER, ModItems.DOUBLE_DRAWER, ModItems.QUAD_DRAWER); } } diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersModelProvider.java b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersModelProvider.java index cea4603..f26cc68 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersModelProvider.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersModelProvider.java @@ -4,7 +4,10 @@ import io.github.mattidragon.extendeddrawers.registry.ModItems; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider; -import net.minecraft.data.client.*; +import net.minecraft.data.client.BlockStateModelGenerator; +import net.minecraft.data.client.ItemModelGenerator; +import net.minecraft.data.client.Models; +import net.minecraft.data.client.TextureMap; import static io.github.mattidragon.extendeddrawers.ExtendedDrawers.id; diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersRecipeProvider.java b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersRecipeProvider.java index 3dfa43b..638fdd6 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersRecipeProvider.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/DrawersRecipeProvider.java @@ -1,6 +1,7 @@ package io.github.mattidragon.extendeddrawers.datagen; import io.github.mattidragon.extendeddrawers.registry.ModItems; +import io.github.mattidragon.extendeddrawers.registry.ModTags; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider; import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; @@ -87,7 +88,7 @@ private void offerControllerRecipe(Consumer exporter) { ShapedRecipeJsonBuilder.create(ModItems.CONTROLLER) .input('I', Items.IRON_INGOT) .input('C', Items.COBBLESTONE) - .input('D', ExtendedDrawersDatagen.DRAWERS) + .input('D', ModTags.ItemTags.DRAWERS) .pattern("CIC") .pattern("IDI") .pattern("CIC") diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/ExtendedDrawersDatagen.java b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/ExtendedDrawersDatagen.java index 87be0ef..7fb4900 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/datagen/ExtendedDrawersDatagen.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/datagen/ExtendedDrawersDatagen.java @@ -2,15 +2,8 @@ import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; -import net.minecraft.item.Item; -import net.minecraft.tag.TagKey; -import net.minecraft.util.registry.Registry; - -import static io.github.mattidragon.extendeddrawers.ExtendedDrawers.id; public class ExtendedDrawersDatagen implements DataGeneratorEntrypoint { - public static final TagKey DRAWERS = TagKey.of(Registry.ITEM_KEY, id("drawers")); - @Override public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) { dataGenerator.addProvider(DrawersModelProvider::new); @@ -19,5 +12,4 @@ public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) { var blockTagProvider = dataGenerator.addProvider(DrawersBlockTagProvider::new); dataGenerator.addProvider(new DrawersItemTagProvider(dataGenerator, blockTagProvider)); } - } diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/registry/ModBlocks.java b/src/main/java/io/github/mattidragon/extendeddrawers/registry/ModBlocks.java index d0465e0..95322fb 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/registry/ModBlocks.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/registry/ModBlocks.java @@ -1,6 +1,5 @@ package io.github.mattidragon.extendeddrawers.registry; -import io.github.mattidragon.extendeddrawers.block.ConnectorBlock; import io.github.mattidragon.extendeddrawers.block.ControllerBlock; import io.github.mattidragon.extendeddrawers.block.DrawerBlock; import io.github.mattidragon.extendeddrawers.block.ShadowDrawerBlock; @@ -8,6 +7,7 @@ import io.github.mattidragon.extendeddrawers.block.entity.ShadowDrawerBlockEntity; 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.MapColor; import net.minecraft.block.Material; import net.minecraft.block.entity.BlockEntityType; @@ -20,7 +20,7 @@ public class ModBlocks { public static final DrawerBlock SINGLE_DRAWER = new DrawerBlock(FabricBlockSettings.of(Material.WOOD).strength(2f, 3f).sounds(BlockSoundGroup.WOOD), 1); public static final DrawerBlock DOUBLE_DRAWER = new DrawerBlock(FabricBlockSettings.of(Material.WOOD).strength(2f, 3f).sounds(BlockSoundGroup.WOOD), 2); public static final DrawerBlock QUAD_DRAWER = new DrawerBlock(FabricBlockSettings.of(Material.WOOD).strength(2f, 3f).sounds(BlockSoundGroup.WOOD), 4); - public static final ConnectorBlock CONNECTOR = new ConnectorBlock(FabricBlockSettings.of(Material.WOOD).strength(2f, 3f).sounds(BlockSoundGroup.WOOD)); + public static final Block CONNECTOR = new Block(FabricBlockSettings.of(Material.WOOD).strength(2f, 3f).sounds(BlockSoundGroup.WOOD)); public static final ControllerBlock CONTROLLER = new ControllerBlock(FabricBlockSettings.of(Material.STONE).strength(3f, 9f).sounds(BlockSoundGroup.STONE)); public static final ShadowDrawerBlock SHADOW_DRAWER = new ShadowDrawerBlock(FabricBlockSettings.of(Material.STONE, MapColor.PALE_YELLOW).strength(3f, 9f).sounds(BlockSoundGroup.STONE)); diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/registry/ModTags.java b/src/main/java/io/github/mattidragon/extendeddrawers/registry/ModTags.java new file mode 100644 index 0000000..3fea739 --- /dev/null +++ b/src/main/java/io/github/mattidragon/extendeddrawers/registry/ModTags.java @@ -0,0 +1,21 @@ +package io.github.mattidragon.extendeddrawers.registry; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.tag.TagKey; +import net.minecraft.util.registry.Registry; + +import static io.github.mattidragon.extendeddrawers.ExtendedDrawers.id; + +public class ModTags { + public static class ItemTags { + public static final TagKey DRAWERS = TagKey.of(Registry.ITEM_KEY, id("drawers")); + + } + + public static class BlockTags { + public static final TagKey DRAWERS = TagKey.of(Registry.BLOCK_KEY, id("drawers")); + public static final TagKey NETWORK_COMPONENTS = TagKey.of(Registry.BLOCK_KEY, id("network_components")); + + } +} diff --git a/src/main/java/io/github/mattidragon/extendeddrawers/block/base/NetworkComponent.java b/src/main/java/io/github/mattidragon/extendeddrawers/util/NetworkHelper.java similarity index 73% rename from src/main/java/io/github/mattidragon/extendeddrawers/block/base/NetworkComponent.java rename to src/main/java/io/github/mattidragon/extendeddrawers/util/NetworkHelper.java index 8ce45d7..10ca347 100644 --- a/src/main/java/io/github/mattidragon/extendeddrawers/block/base/NetworkComponent.java +++ b/src/main/java/io/github/mattidragon/extendeddrawers/util/NetworkHelper.java @@ -1,9 +1,10 @@ -package io.github.mattidragon.extendeddrawers.block.base; +package io.github.mattidragon.extendeddrawers.util; import com.google.common.collect.Queues; import io.github.mattidragon.extendeddrawers.block.DrawerBlock; -import io.github.mattidragon.extendeddrawers.drawer.DrawerSlot; import io.github.mattidragon.extendeddrawers.block.entity.DrawerBlockEntity; +import io.github.mattidragon.extendeddrawers.drawer.DrawerSlot; +import io.github.mattidragon.extendeddrawers.registry.ModTags; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; @@ -11,9 +12,8 @@ import java.util.*; import java.util.function.BiPredicate; -public interface NetworkComponent { - - static Optional findFirstConnectedComponent(World world, BlockPos pos, BiPredicate predicate) { +public class NetworkHelper { + public static Optional findFirstConnectedComponent(World world, BlockPos pos, BiPredicate predicate) { var toSearch = Queues.newArrayDeque(Collections.singleton(pos)); var searched = new ArrayList<>(); @@ -22,7 +22,7 @@ static Optional findFirstConnectedComponent(World world, BlockPos pos, searched.add(searching); var state = world.getBlockState(searching); - if (!(state.getBlock() instanceof NetworkComponent)) + if (!state.isIn(ModTags.BlockTags.NETWORK_COMPONENTS)) continue; if (predicate.test(world, searching)) return Optional.of(searching); @@ -37,7 +37,7 @@ static Optional findFirstConnectedComponent(World world, BlockPos pos, return Optional.empty(); } - static List findConnectedComponents(World world, BlockPos pos, BiPredicate predicate) { + public static List findConnectedComponents(World world, BlockPos pos, BiPredicate predicate) { var toSearch = Queues.newArrayDeque(Collections.singleton(pos)); var searched = new ArrayList<>(); var found = new ArrayList(); @@ -47,7 +47,7 @@ static List findConnectedComponents(World world, BlockPos pos, BiPredi searched.add(searching); var state = world.getBlockState(searching); - if (!(state.getBlock() instanceof NetworkComponent)) + if (!state.isIn(ModTags.BlockTags.NETWORK_COMPONENTS)) continue; if (predicate.test(world, searching)) found.add(searching); @@ -62,7 +62,7 @@ static List findConnectedComponents(World world, BlockPos pos, BiPredi return found; } - static List getConnectedStorages(World world, BlockPos pos) { + public static List getConnectedStorages(World world, BlockPos pos) { return findAllDrawers(world, pos).stream() .map(world::getBlockEntity) .map(DrawerBlockEntity.class::cast) @@ -72,7 +72,7 @@ static List getConnectedStorages(World world, BlockPos pos) { .toList(); } - static List findAllDrawers(World world, BlockPos pos) { - return NetworkComponent.findConnectedComponents(world, pos, (world1, pos1) -> world1.getBlockState(pos1).getBlock() instanceof DrawerBlock); + public static List findAllDrawers(World world, BlockPos pos) { + return NetworkHelper.findConnectedComponents(world, pos, (world1, pos1) -> world1.getBlockState(pos1).getBlock() instanceof DrawerBlock); } }