diff --git a/.github/SUPPORT.md b/.github/SUPPORT.md index 775c575..4a8d79d 100644 --- a/.github/SUPPORT.md +++ b/.github/SUPPORT.md @@ -8,4 +8,4 @@ Questions can be asked on [Discord](https://discordapp.com/invite/VYzsydb). ## I have found a bug -If you have found a bug, please report it on [GitHub issues](https://github.com/refinedmods/refinedarchitect-template/issues). \ No newline at end of file +If you have found a bug, please report it on [GitHub issues](https://github.com/refinedmods/refinedstorage-quartz-arsenal/issues). \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index cd6a9fc..bc6b31d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.1.0] - 2024-11-24 + +### Added + +- Wireless Crafting Grid + +### Changed + +- You can now configure the energy usage of the Wireless Crafting Grid's recipe transfer and autocrafting. +- You can now use the Wireless Crafting Grid without being connected to a network. + +[Unreleased]: https://github.com/refinedmods/refinedstorage-quartz-arsenal/compare/v0.1.0...HEAD + +[0.1.0]: https://github.com/refinedmods/refinedstorage-quartz-arsenal/compare/17fbf2a72609f4774ee599f31110939f6de34f98...v0.1.0 diff --git a/crowdin.yml b/crowdin.yml index 595307e..5aa668e 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -1,4 +1,4 @@ -project_identifier: change-me +project_identifier: refined-storage-quartz-arsenal commit_message: "chore: update translation %language% from crowdin" append_commit_message: false api_key_env: CROWDIN_API_KEY diff --git a/gradle.properties b/gradle.properties index a1b566f..cac55d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,5 @@ refinedarchitectVersion=0.19.1 +refinedstorageVersion=2.0.0-milestone.4.10 # Gradle org.gradle.jvmargs=-Xmx1G org.gradle.configureondemand=true diff --git a/refinedstorage-quartz-arsenal-common/build.gradle b/refinedstorage-quartz-arsenal-common/build.gradle deleted file mode 100644 index 51c84ad..0000000 --- a/refinedstorage-quartz-arsenal-common/build.gradle +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id("refinedarchitect.common") -} - -refinedarchitect { - common() -} - -base { - archivesName.set("refinedstorage-quartz-arsenal-common") -} diff --git a/refinedstorage-quartz-arsenal-common/build.gradle.kts b/refinedstorage-quartz-arsenal-common/build.gradle.kts new file mode 100644 index 0000000..d741bea --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/build.gradle.kts @@ -0,0 +1,27 @@ +plugins { + id("refinedarchitect.common") +} + +repositories { + maven { + url = uri("https://maven.pkg.github.com/refinedmods/refinedstorage2") + credentials { + username = "anything" + password = "\u0067hp_oGjcDFCn8jeTzIj4Ke9pLoEVtpnZMP4VQgaX" + } + } +} + +refinedarchitect { + common() +} + +base { + archivesName.set("refinedstorage-quartz-arsenal-common") +} + +val refinedstorageVersion: String by project + +dependencies { + api("com.refinedmods.refinedstorage:refinedstorage-common:${refinedstorageVersion}") +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/AbstractClientModInitializer.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/AbstractClientModInitializer.java new file mode 100644 index 0000000..ae1e004 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/AbstractClientModInitializer.java @@ -0,0 +1,24 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; + +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; +import net.minecraft.world.entity.player.Player; + +public abstract class AbstractClientModInitializer { + protected static void handleInputEvents() { + final Player player = Minecraft.getInstance().player; + if (player == null) { + return; + } + final KeyMapping openWirelessCraftingGrid = KeyMappings.INSTANCE.getOpenWirelessCraftingGrid(); + while (openWirelessCraftingGrid != null && openWirelessCraftingGrid.consumeClick()) { + RefinedStorageApi.INSTANCE.useSlotReferencedItem( + player, + Items.INSTANCE.getWirelessCraftingGrid(), + Items.INSTANCE.getCreativeWirelessCraftingGrid() + ); + } + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/AbstractModInitializer.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/AbstractModInitializer.java new file mode 100644 index 0000000..3f58e02 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/AbstractModInitializer.java @@ -0,0 +1,39 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import com.refinedmods.refinedstorage.common.content.ExtendedMenuTypeFactory; +import com.refinedmods.refinedstorage.common.content.RegistryCallback; +import com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid.WirelessCraftingGridContainerMenu; +import com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid.WirelessCraftingGridData; +import com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid.WirelessCraftingGridState; + +import net.minecraft.core.component.DataComponentType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; + +import static com.refinedmods.refinedstorage.quartzarsenal.common.QuartzArsenalIdentifierUtil.createQuartzArsenalIdentifier; + +public abstract class AbstractModInitializer { + protected static boolean allowComponentsUpdateAnimation(final ItemStack oldStack, final ItemStack newStack) { + return oldStack.getItem() != newStack.getItem(); + } + + protected final void registerMenus(final RegistryCallback> callback, + final ExtendedMenuTypeFactory extendedMenuTypeFactory) { + Menus.INSTANCE.setWirelessCraftingGrid(callback.register( + ContentIds.WIRELESS_CRAFTING_GRID, + () -> extendedMenuTypeFactory.create( + WirelessCraftingGridContainerMenu::new, + WirelessCraftingGridData.STREAM_CODEC + ) + )); + } + + protected final void registerDataComponents(final RegistryCallback> callback) { + DataComponents.INSTANCE.setWirelessCraftingGridState(callback.register( + createQuartzArsenalIdentifier("wireless_crafting_grid_state"), + () -> DataComponentType.builder() + .persistent(WirelessCraftingGridState.CODEC) + .networkSynchronized(WirelessCraftingGridState.STREAM_CODEC) + .build())); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Common.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Common.java deleted file mode 100644 index 557c691..0000000 --- a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Common.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.refinedmods.refinedstorage.quartzarsenal.common; - -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.level.block.Blocks; - -public class Common { - public static final String MOD_ID = "refinedstorage_quartz_arsenal"; - - private Common() { - } - - public static void helloWorld() { - System.out.println("Hello World! " + BuiltInRegistries.BLOCK.getKey(Blocks.DIRT)); - } -} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Config.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Config.java new file mode 100644 index 0000000..01ea463 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Config.java @@ -0,0 +1,19 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +public interface Config { + WirelessCraftingGridEntry getWirelessCraftingGrid(); + + interface WirelessCraftingGridEntry { + long getEnergyCapacity(); + + long getOpenEnergyUsage(); + + long getCraftingEnergyUsage(); + + long getAutocraftingEnergyUsage(); + + long getClearMatrixEnergyUsage(); + + long getRecipeTransferEnergyUsage(); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/ContentIds.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/ContentIds.java new file mode 100644 index 0000000..65fafc6 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/ContentIds.java @@ -0,0 +1,15 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import net.minecraft.resources.ResourceLocation; + +import static com.refinedmods.refinedstorage.quartzarsenal.common.QuartzArsenalIdentifierUtil.createQuartzArsenalIdentifier; + +public final class ContentIds { + public static final ResourceLocation WIRELESS_CRAFTING_GRID = + createQuartzArsenalIdentifier("wireless_crafting_grid"); + public static final ResourceLocation CREATIVE_WIRELESS_CRAFTING_GRID = + createQuartzArsenalIdentifier("creative_wireless_crafting_grid"); + + private ContentIds() { + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/ContentNames.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/ContentNames.java new file mode 100644 index 0000000..b0a8bd3 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/ContentNames.java @@ -0,0 +1,23 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import net.minecraft.network.chat.MutableComponent; + +import static com.refinedmods.refinedstorage.quartzarsenal.common.QuartzArsenalIdentifierUtil.QUARTZ_ARSENAL_MOD_ID; +import static com.refinedmods.refinedstorage.quartzarsenal.common.QuartzArsenalIdentifierUtil.createQuartzArsenalTranslation; +import static com.refinedmods.refinedstorage.quartzarsenal.common.QuartzArsenalIdentifierUtil.createQuartzArsenalTranslationKey; + +public final class ContentNames { + public static final String MOD_TRANSLATION_KEY = "mod." + QUARTZ_ARSENAL_MOD_ID; + public static final String OPEN_WIRELESS_CRAFTING_GRID_TRANSLATION_KEY = createQuartzArsenalTranslationKey( + "key", "open_wireless_crafting_grid" + ); + public static final MutableComponent WIRELESS_CRAFTING_GRID = createQuartzArsenalTranslation( + "item", "wireless_crafting_grid" + ); + public static final MutableComponent CREATIVE_WIRELESS_CRAFTING_GRID = createQuartzArsenalTranslation( + "item", "creative_wireless_crafting_grid" + ); + + private ContentNames() { + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/CreativeModeTabItems.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/CreativeModeTabItems.java new file mode 100644 index 0000000..8097716 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/CreativeModeTabItems.java @@ -0,0 +1,16 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import java.util.function.Consumer; + +import net.minecraft.world.item.ItemStack; + +public final class CreativeModeTabItems { + private CreativeModeTabItems() { + } + + public static void addItems(final Consumer consumer) { + consumer.accept(Items.INSTANCE.getWirelessCraftingGrid().getDefaultInstance()); + consumer.accept(Items.INSTANCE.getWirelessCraftingGrid().createAtEnergyCapacity()); + consumer.accept(Items.INSTANCE.getCreativeWirelessCraftingGrid().getDefaultInstance()); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/DataComponents.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/DataComponents.java new file mode 100644 index 0000000..648922f --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/DataComponents.java @@ -0,0 +1,30 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid.WirelessCraftingGridState; + +import java.util.function.Supplier; +import javax.annotation.Nullable; + +import net.minecraft.core.component.DataComponentType; + +import static java.util.Objects.requireNonNull; + +public final class DataComponents { + public static final DataComponents INSTANCE = new DataComponents(); + + @Nullable + private Supplier> wirelessCraftingGridState; + + private DataComponents() { + } + + public DataComponentType getWirelessCraftingGridState() { + return requireNonNull(wirelessCraftingGridState).get(); + } + + public void setWirelessCraftingGridState( + @Nullable final Supplier> supplier + ) { + this.wirelessCraftingGridState = supplier; + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/DefaultEnergyUsage.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/DefaultEnergyUsage.java new file mode 100644 index 0000000..9aa4be1 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/DefaultEnergyUsage.java @@ -0,0 +1,13 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +public final class DefaultEnergyUsage { + public static final long WIRELESS_CRAFTING_GRID_CAPACITY = 1000; + public static final long WIRELESS_CRAFTING_GRID_OPEN = 5; + public static final long WIRELESS_CRAFTING_GRID_CRAFTING = 5; + public static final long WIRELESS_CRAFTING_GRID_AUTOCRAFTING = 10; + public static final long WIRELESS_CRAFTING_GRID_CLEAR_MATRIX = 5; + public static final long WIRELESS_CRAFTING_GRID_RECIPE_TRANSFER = 5; + + private DefaultEnergyUsage() { + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Items.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Items.java new file mode 100644 index 0000000..e9e888e --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Items.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid.WirelessCraftingGridItem; + +import java.util.function.Supplier; +import javax.annotation.Nullable; + +import static java.util.Objects.requireNonNull; + +public final class Items { + public static final Items INSTANCE = new Items(); + + @Nullable + private Supplier wirelessCraftingGrid; + @Nullable + private Supplier creativeWirelessCraftingGrid; + + private Items() { + } + + public WirelessCraftingGridItem getWirelessCraftingGrid() { + return requireNonNull(wirelessCraftingGrid).get(); + } + + public void setWirelessCraftingGrid(final Supplier supplier) { + this.wirelessCraftingGrid = supplier; + } + + public WirelessCraftingGridItem getCreativeWirelessCraftingGrid() { + return requireNonNull(creativeWirelessCraftingGrid).get(); + } + + public void setCreativeWirelessCraftingGrid(final Supplier supplier) { + this.creativeWirelessCraftingGrid = supplier; + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/KeyMappings.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/KeyMappings.java new file mode 100644 index 0000000..6a3fc8c --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/KeyMappings.java @@ -0,0 +1,24 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import javax.annotation.Nullable; + +import net.minecraft.client.KeyMapping; + +public final class KeyMappings { + public static final KeyMappings INSTANCE = new KeyMappings(); + + @Nullable + private KeyMapping openWirelessCraftingGrid; + + private KeyMappings() { + } + + public void setOpenWirelessCraftingGrid(final KeyMapping openWirelessCraftingGrid) { + this.openWirelessCraftingGrid = openWirelessCraftingGrid; + } + + @Nullable + public KeyMapping getOpenWirelessCraftingGrid() { + return openWirelessCraftingGrid; + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Menus.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Menus.java new file mode 100644 index 0000000..90b2adf --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Menus.java @@ -0,0 +1,28 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid.WirelessCraftingGridContainerMenu; + +import java.util.function.Supplier; +import javax.annotation.Nullable; + +import net.minecraft.world.inventory.MenuType; + +import static java.util.Objects.requireNonNull; + +public final class Menus { + public static final Menus INSTANCE = new Menus(); + + @Nullable + private Supplier> wirelessCraftingGrid; + + private Menus() { + } + + public void setWirelessCraftingGrid(final Supplier> supplier) { + this.wirelessCraftingGrid = supplier; + } + + public MenuType getWirelessCraftingGrid() { + return requireNonNull(wirelessCraftingGrid).get(); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Platform.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Platform.java new file mode 100644 index 0000000..0396e6f --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/Platform.java @@ -0,0 +1,22 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import java.util.function.Supplier; +import javax.annotation.Nullable; + +import static java.util.Objects.requireNonNull; + +public final class Platform { + @Nullable + private static Supplier configProvider = null; + + private Platform() { + } + + public static void setConfigProvider(final Supplier configProvider) { + Platform.configProvider = configProvider; + } + + public static Config getConfig() { + return requireNonNull(configProvider, "Config isn't loaded yet").get(); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/QuartzArsenalIdentifierUtil.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/QuartzArsenalIdentifierUtil.java new file mode 100644 index 0000000..3b0df79 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/QuartzArsenalIdentifierUtil.java @@ -0,0 +1,24 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; + +public final class QuartzArsenalIdentifierUtil { + public static final String QUARTZ_ARSENAL_MOD_ID = "refinedstorage_quartz_arsenal"; + + private QuartzArsenalIdentifierUtil() { + } + + public static ResourceLocation createQuartzArsenalIdentifier(final String value) { + return ResourceLocation.fromNamespaceAndPath(QUARTZ_ARSENAL_MOD_ID, value); + } + + public static MutableComponent createQuartzArsenalTranslation(final String category, final String value) { + return Component.translatable(createQuartzArsenalTranslationKey(category, value)); + } + + public static String createQuartzArsenalTranslationKey(final String category, final String value) { + return String.format("%s.%s.%s", category, QUARTZ_ARSENAL_MOD_ID, value); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/package-info.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/package-info.java index 690089a..029bb6f 100644 --- a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/package-info.java +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/package-info.java @@ -1,4 +1,7 @@ @ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault package com.refinedmods.refinedstorage.quartzarsenal.common; +import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault; + import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGrid.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGrid.java new file mode 100644 index 0000000..4bd5712 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGrid.java @@ -0,0 +1,291 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import com.refinedmods.refinedstorage.api.autocrafting.preview.Preview; +import com.refinedmods.refinedstorage.api.core.Action; +import com.refinedmods.refinedstorage.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage.api.grid.operations.NoopGridOperations; +import com.refinedmods.refinedstorage.api.grid.watcher.GridWatcher; +import com.refinedmods.refinedstorage.api.grid.watcher.GridWatcherManager; +import com.refinedmods.refinedstorage.api.grid.watcher.GridWatcherManagerImpl; +import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.api.storage.Actor; +import com.refinedmods.refinedstorage.api.storage.NoopStorage; +import com.refinedmods.refinedstorage.api.storage.Storage; +import com.refinedmods.refinedstorage.api.storage.TrackedResourceAmount; +import com.refinedmods.refinedstorage.common.api.security.PlatformSecurityNetworkComponent; +import com.refinedmods.refinedstorage.common.api.storage.PlayerActor; +import com.refinedmods.refinedstorage.common.api.support.network.item.NetworkItemContext; +import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType; +import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference; +import com.refinedmods.refinedstorage.common.grid.CraftingGrid; +import com.refinedmods.refinedstorage.common.grid.DirectCommitExtractTransaction; +import com.refinedmods.refinedstorage.common.grid.ExtractTransaction; +import com.refinedmods.refinedstorage.common.grid.SecuredGridOperations; +import com.refinedmods.refinedstorage.common.grid.SnapshotExtractTransaction; +import com.refinedmods.refinedstorage.common.support.RecipeMatrix; +import com.refinedmods.refinedstorage.common.support.RecipeMatrixContainer; +import com.refinedmods.refinedstorage.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage.quartzarsenal.common.DataComponents; +import com.refinedmods.refinedstorage.quartzarsenal.common.Platform; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +import net.minecraft.core.NonNullList; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ResultContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingInput; +import net.minecraft.world.item.crafting.CraftingRecipe; +import net.minecraft.world.level.Level; + +import static java.util.Objects.requireNonNull; + +class WirelessCraftingGrid implements CraftingGrid { + private final NetworkItemContext context; + private final Level level; + private final GridWatcherManager watchers = new GridWatcherManagerImpl(); + @Nullable + private final RecipeMatrix craftingRecipe; + private final SlotReference slotReference; + + WirelessCraftingGrid(final Player player, + final NetworkItemContext context, + final SlotReference slotReference) { + this.level = player.level(); + this.context = context; + this.slotReference = slotReference; + this.craftingRecipe = createMatrix(player, () -> updateCraftingRecipe(player), slotReference); + } + + private static RecipeMatrix createMatrix(final Player player, + final Runnable listener, + final SlotReference slotReference) { + final RecipeMatrix recipe = RecipeMatrix.crafting(listener, player::level); + slotReference.resolve(player).ifPresent(stack -> setMatrixSlots(stack, recipe)); + return recipe; + } + + private static void setMatrixSlots(final ItemStack stack, + final RecipeMatrix recipe) { + final WirelessCraftingGridState state = stack.get(DataComponents.INSTANCE.getWirelessCraftingGridState()); + if (state == null) { + return; + } + final CraftingInput.Positioned positioned = state.input(); + final int left = positioned.left(); + final int top = positioned.top(); + final CraftingInput input = positioned.input(); + for (int y = 0; y < input.height(); ++y) { + for (int x = 0; x < input.width(); ++x) { + final int matrixIndex = x + left + (y + top) * recipe.getMatrix().getWidth(); + recipe.getMatrix().setItem(matrixIndex, input.getItem(x, y).copy()); + } + } + } + + private void updateCraftingRecipe(final Player player) { + if (craftingRecipe == null) { + return; + } + final CraftingInput.Positioned input = craftingRecipe.getMatrix().asPositionedCraftInput(); + slotReference.resolve(player).ifPresent(stack -> stack.set( + DataComponents.INSTANCE.getWirelessCraftingGridState(), + new WirelessCraftingGridState(input) + )); + } + + private Optional getStorage() { + return context.resolveNetwork().map(network -> network.getComponent(StorageNetworkComponent.class)); + } + + private Optional getSecurity() { + return context.resolveNetwork().map(network -> network.getComponent(PlatformSecurityNetworkComponent.class)); + } + + private Optional getAutocrafting() { + return context.resolveNetwork().map(network -> network.getComponent(AutocraftingNetworkComponent.class)); + } + + private Optional getNetworkForActiveGrid() { + if (!isGridActive()) { + return Optional.empty(); + } + return context.resolveNetwork(); + } + + @Override + public RecipeMatrixContainer getCraftingMatrix() { + return requireNonNull(craftingRecipe).getMatrix(); + } + + @Override + public ResultContainer getCraftingResult() { + return requireNonNull(craftingRecipe).getResult(); + } + + @Override + public NonNullList getRemainingItems(final Player player, final CraftingInput craftingInput) { + return requireNonNull(craftingRecipe).getRemainingItems(level, player, craftingInput); + } + + @Override + public ExtractTransaction startExtractTransaction(final Player player, final boolean directCommit) { + return getNetworkForActiveGrid() + .map(network -> network.getComponent(StorageNetworkComponent.class)) + .map(storage -> (ExtractTransaction) new WirelessCraftingGridExtractTransaction( + context, + createExtractTransaction(player, directCommit, storage) + )) + .orElse(ExtractTransaction.NOOP); + } + + private ExtractTransaction createExtractTransaction(final Player player, + final boolean directCommit, + final StorageNetworkComponent storage) { + return directCommit + ? new DirectCommitExtractTransaction(storage) + : new SnapshotExtractTransaction(player, storage, getCraftingMatrix()); + } + + @Override + public boolean clearMatrix(final Player player, final boolean toPlayerInventory) { + final boolean success = toPlayerInventory + ? getCraftingMatrix().clearToPlayerInventory(player) + : clearMatrixIntoStorage(player); + if (success) { + context.drainEnergy(Platform.getConfig().getWirelessCraftingGrid().getClearMatrixEnergyUsage()); + } + return success; + } + + private boolean clearMatrixIntoStorage(final Player player) { + return getNetworkForActiveGrid() + .map(network -> network.getComponent(StorageNetworkComponent.class)) + .map(storage -> getCraftingMatrix().clearIntoStorage(storage, player)) + .orElse(false); + } + + @Override + public void transferRecipe(final Player player, final List> recipe) { + context.drainEnergy(Platform.getConfig().getWirelessCraftingGrid().getRecipeTransferEnergyUsage()); + getCraftingMatrix().transferRecipe( + player, + getNetworkForActiveGrid().map(network -> network.getComponent(StorageNetworkComponent.class)) + .orElse(null), + recipe + ); + } + + @Override + public void acceptQuickCraft(final Player player, final ItemStack craftedStack) { + if (player.getInventory().add(craftedStack)) { + return; + } + final long inserted = getNetworkForActiveGrid() + .map(network -> network.getComponent(StorageNetworkComponent.class)) + .map(rootStorage -> rootStorage.insert( + ItemResource.ofItemStack(craftedStack), + craftedStack.getCount(), + Action.EXECUTE, + new PlayerActor(player) + )) + .orElse(0L); + if (inserted != craftedStack.getCount()) { + final long remainder = craftedStack.getCount() - inserted; + final ItemStack remainderStack = craftedStack.copyWithCount((int) remainder); + player.drop(remainderStack, false); + } + } + + @Override + public void addWatcher(final GridWatcher watcher, final Class actorType) { + context.drainEnergy(Platform.getConfig().getWirelessCraftingGrid().getOpenEnergyUsage()); + context.resolveNetwork().ifPresent(network -> watchers.addWatcher( + watcher, + actorType, + network.getComponent(StorageNetworkComponent.class) + )); + } + + @Override + public void removeWatcher(final GridWatcher watcher) { + context.resolveNetwork().ifPresent(network -> watchers.removeWatcher( + watcher, + network.getComponent(StorageNetworkComponent.class) + )); + } + + @Override + public Storage getItemStorage() { + return getStorage().map(Storage.class::cast).orElseGet(NoopStorage::new); + } + + @Override + public boolean isGridActive() { + final boolean networkActive = context.resolveNetwork() + .map(network -> network.getComponent(EnergyNetworkComponent.class).getStored() > 0) + .orElse(false); + return networkActive && context.isActive(); + } + + @Override + public List getResources(final Class actorType) { + return getStorage().map(storage -> storage.getResources(actorType)).orElse(Collections.emptyList()); + } + + @Override + public Set getAutocraftableResources() { + return getAutocrafting() + .map(AutocraftingNetworkComponent::getOutputs) + .map(outputs -> outputs.stream() + .filter(PlatformResourceKey.class::isInstance) + .map(PlatformResourceKey.class::cast) + .collect(Collectors.toSet())) + .orElse(Collections.emptySet()); + } + + @Override + public GridOperations createOperations(final ResourceType resourceType, final ServerPlayer player) { + return getStorage() + .flatMap(rootStorage -> getSecurity() + .map(security -> createGridOperations(resourceType, player, rootStorage, security))) + .map(operations -> (GridOperations) new WirelessCraftingGridOperations(operations, context, watchers)) + .orElseGet(NoopGridOperations::new); + } + + private GridOperations createGridOperations(final ResourceType resourceType, + final ServerPlayer player, + final StorageNetworkComponent rootStorage, + final PlatformSecurityNetworkComponent securityNetworkComponent) { + final PlayerActor playerActor = new PlayerActor(player); + final GridOperations operations = resourceType.createGridOperations(rootStorage, playerActor); + return new SecuredGridOperations(player, securityNetworkComponent, operations); + } + + @Override + public Optional getPreview(final ResourceKey resource, final long amount) { + return getAutocrafting().flatMap(component -> component.getPreview(resource, amount)); + } + + @Override + public boolean startTask(final ResourceKey resource, final long amount) { + return getAutocrafting().map(autocrafting -> { + if (autocrafting.startTask(resource, amount)) { + context.drainEnergy(Platform.getConfig().getWirelessCraftingGrid().getAutocraftingEnergyUsage()); + return true; + } + return false; + }).orElse(false); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridContainerMenu.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridContainerMenu.java new file mode 100644 index 0000000..a899d49 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridContainerMenu.java @@ -0,0 +1,27 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference; +import com.refinedmods.refinedstorage.common.grid.AbstractCraftingGridContainerMenu; +import com.refinedmods.refinedstorage.common.grid.CraftingGrid; +import com.refinedmods.refinedstorage.quartzarsenal.common.Menus; + +import net.minecraft.world.entity.player.Inventory; + +public class WirelessCraftingGridContainerMenu extends AbstractCraftingGridContainerMenu { + public WirelessCraftingGridContainerMenu(final int syncId, + final Inventory playerInventory, + final WirelessCraftingGridData gridData) { + super(Menus.INSTANCE.getWirelessCraftingGrid(), syncId, playerInventory, gridData.gridData()); + this.disabledSlot = gridData.slotReference(); + resized(0, 0, 0); + } + + WirelessCraftingGridContainerMenu(final int syncId, + final Inventory playerInventory, + final CraftingGrid craftingGrid, + final SlotReference slotReference) { + super(Menus.INSTANCE.getWirelessCraftingGrid(), syncId, playerInventory, craftingGrid); + this.disabledSlot = slotReference; + resized(0, 0, 0); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridData.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridData.java new file mode 100644 index 0000000..aeef697 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridData.java @@ -0,0 +1,18 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference; +import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceFactory; +import com.refinedmods.refinedstorage.common.grid.GridData; + +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; + +public record WirelessCraftingGridData(GridData gridData, SlotReference slotReference) { + public static final StreamCodec STREAM_CODEC = + StreamCodec.composite( + GridData.STREAM_CODEC, WirelessCraftingGridData::gridData, + SlotReferenceFactory.STREAM_CODEC, + WirelessCraftingGridData::slotReference, + WirelessCraftingGridData::new + ); +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridExtendedMenuProvider.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridExtendedMenuProvider.java new file mode 100644 index 0000000..70dbca7 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridExtendedMenuProvider.java @@ -0,0 +1,50 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference; +import com.refinedmods.refinedstorage.common.grid.CraftingGrid; +import com.refinedmods.refinedstorage.common.grid.GridData; +import com.refinedmods.refinedstorage.common.support.containermenu.ExtendedMenuProvider; + +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamEncoder; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; + +public class WirelessCraftingGridExtendedMenuProvider implements ExtendedMenuProvider { + private final Component name; + private final CraftingGrid craftingGrid; + private final SlotReference slotReference; + + WirelessCraftingGridExtendedMenuProvider(final Component name, + final CraftingGrid craftingGrid, + final SlotReference slotReference) { + this.name = name; + this.craftingGrid = craftingGrid; + this.slotReference = slotReference; + } + + @Override + public WirelessCraftingGridData getMenuData() { + return new WirelessCraftingGridData( + GridData.of(craftingGrid), + slotReference + ); + } + + @Override + public StreamEncoder getMenuCodec() { + return WirelessCraftingGridData.STREAM_CODEC; + } + + @Override + public Component getDisplayName() { + return name; + } + + @Override + public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + return new WirelessCraftingGridContainerMenu(syncId, inventory, craftingGrid, slotReference); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridExtractTransaction.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridExtractTransaction.java new file mode 100644 index 0000000..1ad0c95 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridExtractTransaction.java @@ -0,0 +1,29 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import com.refinedmods.refinedstorage.common.api.support.network.item.NetworkItemContext; +import com.refinedmods.refinedstorage.common.grid.ExtractTransaction; +import com.refinedmods.refinedstorage.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage.quartzarsenal.common.Platform; + +import net.minecraft.world.entity.player.Player; + +class WirelessCraftingGridExtractTransaction implements ExtractTransaction { + private final NetworkItemContext context; + private final ExtractTransaction delegate; + + WirelessCraftingGridExtractTransaction(final NetworkItemContext context, final ExtractTransaction delegate) { + this.context = context; + this.delegate = delegate; + } + + @Override + public boolean extract(final ItemResource itemResource, final Player player) { + return delegate.extract(itemResource, player); + } + + @Override + public void close() { + delegate.close(); + context.drainEnergy(Platform.getConfig().getWirelessCraftingGrid().getCraftingEnergyUsage()); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridItem.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridItem.java new file mode 100644 index 0000000..e835280 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridItem.java @@ -0,0 +1,67 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage; +import com.refinedmods.refinedstorage.api.network.impl.energy.EnergyStorageImpl; +import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.security.SecurityHelper; +import com.refinedmods.refinedstorage.common.api.support.energy.AbstractNetworkEnergyItem; +import com.refinedmods.refinedstorage.common.api.support.energy.EnergyItemHelper; +import com.refinedmods.refinedstorage.common.api.support.network.item.NetworkItemContext; +import com.refinedmods.refinedstorage.common.api.support.network.item.NetworkItemHelper; +import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference; +import com.refinedmods.refinedstorage.common.grid.CraftingGrid; +import com.refinedmods.refinedstorage.common.security.BuiltinPermission; +import com.refinedmods.refinedstorage.quartzarsenal.common.ContentNames; +import com.refinedmods.refinedstorage.quartzarsenal.common.Platform; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +import static java.util.Objects.requireNonNullElse; + +public class WirelessCraftingGridItem extends AbstractNetworkEnergyItem { + private final boolean creative; + + public WirelessCraftingGridItem(final boolean creative, + final EnergyItemHelper energyItemHelper, + final NetworkItemHelper networkItemHelper) { + super( + new Item.Properties().stacksTo(1), + energyItemHelper, + networkItemHelper + ); + this.creative = creative; + } + + public EnergyStorage createEnergyStorage(final ItemStack stack) { + final EnergyStorage energyStorage = new EnergyStorageImpl( + Platform.getConfig().getWirelessCraftingGrid().getEnergyCapacity() + ); + return RefinedStorageApi.INSTANCE.asItemEnergyStorage(energyStorage, stack); + } + + @Override + protected void use(@Nullable final Component name, + final ServerPlayer player, + final SlotReference slotReference, + final NetworkItemContext context) { + final boolean isAllowed = context.resolveNetwork() + .map(network -> SecurityHelper.isAllowed(player, BuiltinPermission.OPEN, network)) + .orElse(true); + if (!isAllowed) { + RefinedStorageApi.INSTANCE.sendNoPermissionToOpenMessage(player, ContentNames.WIRELESS_CRAFTING_GRID); + return; + } + final CraftingGrid craftingGrid = new WirelessCraftingGrid(player, context, slotReference); + final Component correctedName = requireNonNullElse( + name, + creative ? ContentNames.CREATIVE_WIRELESS_CRAFTING_GRID : ContentNames.WIRELESS_CRAFTING_GRID + ); + final var provider = new WirelessCraftingGridExtendedMenuProvider(correctedName, craftingGrid, slotReference); + com.refinedmods.refinedstorage.common.Platform.INSTANCE.getMenuOpener().openMenu(player, provider); + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridOperations.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridOperations.java new file mode 100644 index 0000000..7e702af --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridOperations.java @@ -0,0 +1,56 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import com.refinedmods.refinedstorage.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage.api.grid.operations.GridInsertMode; +import com.refinedmods.refinedstorage.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage.api.grid.watcher.GridWatcherManager; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.api.storage.ExtractableStorage; +import com.refinedmods.refinedstorage.api.storage.InsertableStorage; +import com.refinedmods.refinedstorage.common.Platform; +import com.refinedmods.refinedstorage.common.api.support.network.item.NetworkItemContext; + +class WirelessCraftingGridOperations implements GridOperations { + private final GridOperations delegate; + private final NetworkItemContext context; + private final GridWatcherManager watchers; + + WirelessCraftingGridOperations(final GridOperations delegate, + final NetworkItemContext context, + final GridWatcherManager watchers) { + this.delegate = delegate; + this.context = context; + this.watchers = watchers; + } + + @Override + public boolean extract(final ResourceKey resource, + final GridExtractMode extractMode, + final InsertableStorage destination) { + final boolean success = delegate.extract(resource, extractMode, destination); + if (success) { + drain(Platform.INSTANCE.getConfig().getWirelessGrid().getExtractEnergyUsage()); + } + return success; + } + + @Override + public boolean insert(final ResourceKey resource, + final GridInsertMode insertMode, + final ExtractableStorage source) { + final boolean success = delegate.insert(resource, insertMode, source); + if (success) { + drain(Platform.INSTANCE.getConfig().getWirelessGrid().getInsertEnergyUsage()); + } + return success; + } + + private void drain(final long amount) { + final boolean wasActive = context.isActive(); + context.drainEnergy(amount); + final boolean isActive = context.isActive(); + if (wasActive != isActive) { + watchers.activeChanged(isActive); + } + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridState.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridState.java new file mode 100644 index 0000000..bfd571b --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/WirelessCraftingGridState.java @@ -0,0 +1,51 @@ +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import java.util.ArrayList; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingInput; + +public record WirelessCraftingGridState(CraftingInput.Positioned input) { + private static final Codec INPUT_CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.fieldOf("width").forGetter(CraftingInput::width), + Codec.INT.fieldOf("height").forGetter(CraftingInput::height), + Codec.list(ItemStack.OPTIONAL_CODEC).fieldOf("items").forGetter(CraftingInput::items) + ).apply(instance, CraftingInput::of)); + + private static final Codec POSITIONED_INPUT_CODEC = + RecordCodecBuilder.create(instance -> instance.group( + INPUT_CODEC.fieldOf("input").forGetter(CraftingInput.Positioned::input), + Codec.INT.fieldOf("left").forGetter(CraftingInput.Positioned::left), + Codec.INT.fieldOf("top").forGetter(CraftingInput.Positioned::top) + ).apply(instance, CraftingInput.Positioned::new)); + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + POSITIONED_INPUT_CODEC.fieldOf("input").forGetter(WirelessCraftingGridState::input) + ).apply(instance, WirelessCraftingGridState::new)); + + private static final StreamCodec INPUT_STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.INT, CraftingInput::width, + ByteBufCodecs.INT, CraftingInput::height, + ByteBufCodecs.collection(ArrayList::new, ItemStack.OPTIONAL_STREAM_CODEC), CraftingInput::items, + CraftingInput::of + ); + + private static final StreamCodec POSITIONED_INPUT_STREAM_CODEC = + StreamCodec.composite( + INPUT_STREAM_CODEC, CraftingInput.Positioned::input, + ByteBufCodecs.INT, CraftingInput.Positioned::left, + ByteBufCodecs.INT, CraftingInput.Positioned::top, + CraftingInput.Positioned::new + ); + + public static final StreamCodec STREAM_CODEC = + StreamCodec.composite( + POSITIONED_INPUT_STREAM_CODEC, WirelessCraftingGridState::input, + WirelessCraftingGridState::new + ); +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/package-info.java b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/package-info.java new file mode 100644 index 0000000..cdd131d --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/common/wirelesscraftinggrid/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid; + +import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/lang/en_us.json b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/lang/en_us.json index 7a73a41..b6eb1b3 100644 --- a/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/lang/en_us.json +++ b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/lang/en_us.json @@ -1,2 +1,24 @@ { + "mod.refinedstorage_quartz_arsenal": "Refined Storage - Quartz Arsenal", + "item.refinedstorage_quartz_arsenal.wireless_crafting_grid": "Wireless Crafting Grid", + "item.refinedstorage_quartz_arsenal.creative_wireless_crafting_grid": "Creative Wireless Crafting Grid", + "key.refinedstorage_quartz_arsenal.open_wireless_crafting_grid": "Open Wireless Crafting Grid", + "text.autoconfig.refinedstorage_quartz_arsenal.title": "Refined Storage - Quartz Arsenal Configuration", + "refinedstorage_quartz_arsenal.configuration.title": "Refined Storage - Quartz Arsenal Configuration", + "refinedstorage_quartz_arsenal.configuration.section.refinedstorage_quartz_arsenal.common.toml": "Refined Storage - Quartz Arsenal Configuration", + "refinedstorage_quartz_arsenal.configuration.section.refinedstorage_quartz_arsenal.common.toml.title": "Refined Storage - Quartz Arsenal Configuration", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid": "Wireless Crafting Grid", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.tooltip": "Configuration for the Wireless Crafting Grid.", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.energyCapacity": "Energy capacity", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.energyCapacity.tooltip": "The energy capacity of the Wireless Crafting Grid.", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.openEnergyUsage": "Open energy usage", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.openEnergyUsage.tooltip": "The energy usage of opening the Wireless Crafting Grid.", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.craftingEnergyUsage": "Crafting energy usage", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.craftingEnergyUsage.tooltip": "The energy usage of crafting an item in the Wireless Crafting Grid.", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.autocraftingEnergyUsage": "Autocrafting energy usage", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.autocraftingEnergyUsage.tooltip": "The energy usage of autocrafting a resource with the Wireless Crafting Grid.", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.clearMatrixEnergyUsage": "Clear matrix energy usage", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.clearMatrixEnergyUsage.tooltip": "The energy usage of clearing the crafting matrix in the Wireless Crafting Grid.", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.recipeTransferEnergyUsage": "Recipe transfer energy usage", + "text.autoconfig.refinedstorage_quartz_arsenal.option.wirelessCraftingGrid.recipeTransferEnergyUsage.tooltip": "The energy usage of transferring a recipe in the Wireless Crafting Grid." } \ No newline at end of file diff --git a/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/creative_wireless_crafting_grid.json b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/creative_wireless_crafting_grid.json new file mode 100644 index 0000000..c86d0ee --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/creative_wireless_crafting_grid.json @@ -0,0 +1,17 @@ +{ + "parent": "item/generated", + "overrides": [ + { + "predicate": { + "refinedstorage:network_bound_active": 0 + }, + "model": "refinedstorage_quartz_arsenal:item/wireless_crafting_grid/inactive" + }, + { + "predicate": { + "refinedstorage:network_bound_active": 1 + }, + "model": "refinedstorage_quartz_arsenal:item/wireless_crafting_grid/active" + } + ] +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid.json b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid.json new file mode 100644 index 0000000..c86d0ee --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid.json @@ -0,0 +1,17 @@ +{ + "parent": "item/generated", + "overrides": [ + { + "predicate": { + "refinedstorage:network_bound_active": 0 + }, + "model": "refinedstorage_quartz_arsenal:item/wireless_crafting_grid/inactive" + }, + { + "predicate": { + "refinedstorage:network_bound_active": 1 + }, + "model": "refinedstorage_quartz_arsenal:item/wireless_crafting_grid/active" + } + ] +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid/active.json b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid/active.json new file mode 100644 index 0000000..cf57686 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid/active.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "refinedstorage_quartz_arsenal:item/wireless_crafting_grid/active" + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid/inactive.json b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid/inactive.json new file mode 100644 index 0000000..9edaf36 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/models/item/wireless_crafting_grid/inactive.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "refinedstorage_quartz_arsenal:item/wireless_crafting_grid/inactive" + } +} diff --git a/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/textures/item/wireless_crafting_grid/active.png b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/textures/item/wireless_crafting_grid/active.png new file mode 100644 index 0000000..c6a62c8 Binary files /dev/null and b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/textures/item/wireless_crafting_grid/active.png differ diff --git a/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/textures/item/wireless_crafting_grid/inactive.png b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/textures/item/wireless_crafting_grid/inactive.png new file mode 100644 index 0000000..deb360b Binary files /dev/null and b/refinedstorage-quartz-arsenal-common/src/main/resources/assets/refinedstorage_quartz_arsenal/textures/item/wireless_crafting_grid/inactive.png differ diff --git a/refinedstorage-quartz-arsenal-common/src/main/resources/data/refinedstorage_quartz_arsenal/recipe/wireless_crafting_grid.json b/refinedstorage-quartz-arsenal-common/src/main/resources/data/refinedstorage_quartz_arsenal/recipe/wireless_crafting_grid.json new file mode 100644 index 0000000..66cacd1 --- /dev/null +++ b/refinedstorage-quartz-arsenal-common/src/main/resources/data/refinedstorage_quartz_arsenal/recipe/wireless_crafting_grid.json @@ -0,0 +1,25 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "EPE", + "EGE", + "EAE" + ], + "key": { + "E": { + "item": "refinedstorage:quartz_enriched_iron" + }, + "P": { + "tag": "c:ender_pearls" + }, + "G": { + "tag": "refinedstorage:crafting_grids" + }, + "A": { + "item": "refinedstorage:advanced_processor" + } + }, + "result": { + "id": "refinedstorage_quartz_arsenal:wireless_crafting_grid" + } +} \ No newline at end of file diff --git a/refinedstorage-quartz-arsenal-fabric/build.gradle.kts b/refinedstorage-quartz-arsenal-fabric/build.gradle.kts index f8bfbb4..790cb2b 100644 --- a/refinedstorage-quartz-arsenal-fabric/build.gradle.kts +++ b/refinedstorage-quartz-arsenal-fabric/build.gradle.kts @@ -2,6 +2,24 @@ plugins { id("refinedarchitect.fabric") } +repositories { + maven { + url = uri("https://maven.pkg.github.com/refinedmods/refinedstorage2") + credentials { + username = "anything" + password = "\u0067hp_oGjcDFCn8jeTzIj4Ke9pLoEVtpnZMP4VQgaX" + } + } + maven { + name = "ModMenu" + url = uri("https://maven.terraformersmc.com/") + } + maven { + name = "Cloth Config" + url = uri("https://maven.shedaniel.me/") + } +} + refinedarchitect { modId = "refinedstorage_quartz_arsenal" fabric() @@ -11,6 +29,8 @@ base { archivesName.set("refinedstorage-quartz-arsenal-fabric") } +val refinedstorageVersion: String by project + val commonJava by configurations.existing val commonResources by configurations.existing @@ -18,4 +38,5 @@ dependencies { compileOnly(project(":refinedstorage-quartz-arsenal-common")) commonJava(project(path = ":refinedstorage-quartz-arsenal-common", configuration = "commonJava")) commonResources(project(path = ":refinedstorage-quartz-arsenal-common", configuration = "commonResources")) + modApi("com.refinedmods.refinedstorage:refinedstorage-fabric:${refinedstorageVersion}") } diff --git a/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ClientModInitializerImpl.java b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ClientModInitializerImpl.java index 05fd5de..4fbaef4 100644 --- a/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ClientModInitializerImpl.java +++ b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ClientModInitializerImpl.java @@ -1,10 +1,53 @@ package com.refinedmods.refinedstorage.quartzarsenal.fabric; +import com.refinedmods.refinedstorage.common.grid.screen.CraftingGridScreen; +import com.refinedmods.refinedstorage.common.support.network.item.NetworkItemPropertyFunction; +import com.refinedmods.refinedstorage.quartzarsenal.common.AbstractClientModInitializer; +import com.refinedmods.refinedstorage.quartzarsenal.common.ContentNames; +import com.refinedmods.refinedstorage.quartzarsenal.common.Items; +import com.refinedmods.refinedstorage.quartzarsenal.common.KeyMappings; +import com.refinedmods.refinedstorage.quartzarsenal.common.Menus; + +import com.mojang.blaze3d.platform.InputConstants; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.renderer.item.ItemProperties; -public class ClientModInitializerImpl implements ClientModInitializer { +public class ClientModInitializerImpl extends AbstractClientModInitializer implements ClientModInitializer { @Override public void onInitializeClient() { - System.out.println("Hello from the client"); + registerKeyMappings(); + registerItemProperties(); + registerMenus(); + } + + private void registerKeyMappings() { + KeyMappings.INSTANCE.setOpenWirelessCraftingGrid(KeyBindingHelper.registerKeyBinding(new KeyMapping( + ContentNames.OPEN_WIRELESS_CRAFTING_GRID_TRANSLATION_KEY, + InputConstants.Type.KEYSYM, + InputConstants.UNKNOWN.getValue(), + ContentNames.MOD_TRANSLATION_KEY + ))); + ClientTickEvents.END_CLIENT_TICK.register(client -> handleInputEvents()); + } + + private void registerItemProperties() { + ItemProperties.register( + Items.INSTANCE.getWirelessCraftingGrid(), + NetworkItemPropertyFunction.NAME, + new NetworkItemPropertyFunction() + ); + ItemProperties.register( + Items.INSTANCE.getCreativeWirelessCraftingGrid(), + NetworkItemPropertyFunction.NAME, + new NetworkItemPropertyFunction() + ); + } + + private static void registerMenus() { + MenuScreens.register(Menus.INSTANCE.getWirelessCraftingGrid(), CraftingGridScreen::new); } } diff --git a/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ConfigImpl.java b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ConfigImpl.java new file mode 100644 index 0000000..5695311 --- /dev/null +++ b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ConfigImpl.java @@ -0,0 +1,64 @@ +package com.refinedmods.refinedstorage.quartzarsenal.fabric; + +import com.refinedmods.refinedstorage.quartzarsenal.common.Config; +import com.refinedmods.refinedstorage.quartzarsenal.common.DefaultEnergyUsage; +import com.refinedmods.refinedstorage.quartzarsenal.common.QuartzArsenalIdentifierUtil; + +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.ConfigData; +import me.shedaniel.autoconfig.annotation.ConfigEntry; + +@me.shedaniel.autoconfig.annotation.Config(name = QuartzArsenalIdentifierUtil.QUARTZ_ARSENAL_MOD_ID) +@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal", "CanBeFinal"}) +public class ConfigImpl implements ConfigData, Config { + @ConfigEntry.Gui.CollapsibleObject + private WirelessCraftingGridEntryEntryImpl wirelessCraftingGrid = new WirelessCraftingGridEntryEntryImpl(); + + public static ConfigImpl get() { + return AutoConfig.getConfigHolder(ConfigImpl.class).getConfig(); + } + + @Override + public WirelessCraftingGridEntry getWirelessCraftingGrid() { + return wirelessCraftingGrid; + } + + private static class WirelessCraftingGridEntryEntryImpl implements WirelessCraftingGridEntry { + private long energyCapacity = DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_CAPACITY; + private long openEnergyUsage = DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_OPEN; + private long craftingEnergyUsage = DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_CRAFTING; + private long autocraftingEnergyUsage = DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_AUTOCRAFTING; + private long clearMatrixEnergyUsage = DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_CLEAR_MATRIX; + private long recipeTransferEnergyUsage = DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_RECIPE_TRANSFER; + + @Override + public long getEnergyCapacity() { + return energyCapacity; + } + + @Override + public long getOpenEnergyUsage() { + return openEnergyUsage; + } + + @Override + public long getCraftingEnergyUsage() { + return craftingEnergyUsage; + } + + @Override + public long getAutocraftingEnergyUsage() { + return autocraftingEnergyUsage; + } + + @Override + public long getClearMatrixEnergyUsage() { + return clearMatrixEnergyUsage; + } + + @Override + public long getRecipeTransferEnergyUsage() { + return recipeTransferEnergyUsage; + } + } +} diff --git a/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ModInitializerImpl.java b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ModInitializerImpl.java index f6a5175..f1b0fae 100644 --- a/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ModInitializerImpl.java +++ b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ModInitializerImpl.java @@ -1,12 +1,118 @@ package com.refinedmods.refinedstorage.quartzarsenal.fabric; -import com.refinedmods.refinedstorage.quartzarsenal.common.Common; +import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.content.DirectRegistryCallback; +import com.refinedmods.refinedstorage.common.content.ExtendedMenuTypeFactory; +import com.refinedmods.refinedstorage.common.content.RegistryCallback; +import com.refinedmods.refinedstorage.fabric.api.RefinedStoragePlugin; +import com.refinedmods.refinedstorage.fabric.support.energy.EnergyStorageAdapter; +import com.refinedmods.refinedstorage.quartzarsenal.common.AbstractModInitializer; +import com.refinedmods.refinedstorage.quartzarsenal.common.ContentIds; +import com.refinedmods.refinedstorage.quartzarsenal.common.CreativeModeTabItems; +import com.refinedmods.refinedstorage.quartzarsenal.common.Items; +import com.refinedmods.refinedstorage.quartzarsenal.common.Platform; +import com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid.WirelessCraftingGridItem; +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; +import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import team.reborn.energy.api.EnergyStorage; + +public class ModInitializerImpl extends AbstractModInitializer implements RefinedStoragePlugin, ModInitializer { + @Override + public void onApiAvailable(final RefinedStorageApi refinedStorageApi) { + Platform.setConfigProvider(ConfigImpl::get); + registerContent(refinedStorageApi); + registerCapabilities(); + registerCreativeModeTabListener(refinedStorageApi); + } + + private void registerContent(final RefinedStorageApi refinedStorageApi) { + final DirectRegistryCallback itemRegistryCallback = new DirectRegistryCallback<>(BuiltInRegistries.ITEM); + registerCustomItems(itemRegistryCallback, refinedStorageApi); + registerMenus(new DirectRegistryCallback<>(BuiltInRegistries.MENU), new ExtendedMenuTypeFactory() { + @Override + public MenuType create(final MenuSupplier supplier, + final StreamCodec + streamCodec) { + return new ExtendedScreenHandlerType<>(supplier::create, streamCodec); + } + }); + registerDataComponents(new DirectRegistryCallback<>(BuiltInRegistries.DATA_COMPONENT_TYPE)); + } + + private void registerCustomItems(final RegistryCallback callback, + final RefinedStorageApi refinedStorageApi) { + Items.INSTANCE.setWirelessCraftingGrid( + callback.register(ContentIds.WIRELESS_CRAFTING_GRID, () -> new WirelessCraftingGridItem( + false, + refinedStorageApi.getEnergyItemHelper(), + refinedStorageApi.getNetworkItemHelper() + ) { + @Override + public boolean allowComponentsUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowComponentsUpdateAnimation(oldStack, newStack); + } + }) + ); + Items.INSTANCE.setCreativeWirelessCraftingGrid( + callback.register(ContentIds.CREATIVE_WIRELESS_CRAFTING_GRID, () -> new WirelessCraftingGridItem( + true, + refinedStorageApi.getEnergyItemHelper(), + refinedStorageApi.getNetworkItemHelper() + ) { + @Override + public boolean allowComponentsUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowComponentsUpdateAnimation(oldStack, newStack); + } + }) + ); + } + + private void registerCapabilities() { + registerEnergyItemProviders(); + } + + private void registerEnergyItemProviders() { + EnergyStorage.ITEM.registerForItems( + (stack, context) -> + new EnergyStorageAdapter(Items.INSTANCE.getWirelessCraftingGrid().createEnergyStorage(stack)), + Items.INSTANCE.getWirelessCraftingGrid() + ); + } + + private void registerCreativeModeTabListener(final RefinedStorageApi refinedStorageApi) { + final ResourceKey creativeModeTab = ResourceKey.create( + Registries.CREATIVE_MODE_TAB, + refinedStorageApi.getCreativeModeTabId() + ); + ItemGroupEvents.modifyEntriesEvent(creativeModeTab).register( + entries -> CreativeModeTabItems.addItems(entries::accept) + ); + } -public class ModInitializerImpl implements ModInitializer { @Override public void onInitialize() { - Common.helloWorld(); + AutoConfig.register(ConfigImpl.class, Toml4jConfigSerializer::new); } } diff --git a/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ModMenuApiImpl.java b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ModMenuApiImpl.java new file mode 100644 index 0000000..9dc61c5 --- /dev/null +++ b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/ModMenuApiImpl.java @@ -0,0 +1,15 @@ +package com.refinedmods.refinedstorage.quartzarsenal.fabric; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import me.shedaniel.autoconfig.AutoConfig; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +@Environment(EnvType.CLIENT) +public class ModMenuApiImpl implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return parent -> AutoConfig.getConfigScreen(ConfigImpl.class, parent).get(); + } +} diff --git a/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/package-info.java b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/package-info.java index 870647e..a72b84f 100644 --- a/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/package-info.java +++ b/refinedstorage-quartz-arsenal-fabric/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/fabric/package-info.java @@ -1,4 +1,7 @@ @ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault package com.refinedmods.refinedstorage.quartzarsenal.fabric; +import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault; + import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage-quartz-arsenal-fabric/src/main/resources/fabric.mod.json b/refinedstorage-quartz-arsenal-fabric/src/main/resources/fabric.mod.json index 85250b5..7a3e2be 100644 --- a/refinedstorage-quartz-arsenal-fabric/src/main/resources/fabric.mod.json +++ b/refinedstorage-quartz-arsenal-fabric/src/main/resources/fabric.mod.json @@ -19,19 +19,32 @@ ], "client": [ "com.refinedmods.refinedstorage.quartzarsenal.fabric.ClientModInitializerImpl" + ], + "refinedstorage_plugin": [ + "com.refinedmods.refinedstorage.quartzarsenal.fabric.ModInitializerImpl" + ], + "modmenu": [ + "com.refinedmods.refinedstorage.quartzarsenal.fabric.ModMenuApiImpl" ] }, "custom": { "modmenu": { "links": { "modmenu.discord": "https://discordapp.com/invite/VYzsydb" - } + }, + "parent": "refinedstorage" } }, "depends": { "fabricloader": ">=0.14.6", "fabric-api": "*", "minecraft": "~1.21", - "java": ">=17" + "refinedstorage": ">=2.0.0-milestone.4.10", + "java": ">=21", + "cloth-config2": "*", + "team_reborn_energy": "*" + }, + "suggests": { + "modmenu": "*" } } diff --git a/refinedstorage-quartz-arsenal-neoforge/build.gradle.kts b/refinedstorage-quartz-arsenal-neoforge/build.gradle.kts index f9e2cbe..412315e 100644 --- a/refinedstorage-quartz-arsenal-neoforge/build.gradle.kts +++ b/refinedstorage-quartz-arsenal-neoforge/build.gradle.kts @@ -2,6 +2,16 @@ plugins { id("refinedarchitect.neoforge") } +repositories { + maven { + url = uri("https://maven.pkg.github.com/refinedmods/refinedstorage2") + credentials { + username = "anything" + password = "\u0067hp_oGjcDFCn8jeTzIj4Ke9pLoEVtpnZMP4VQgaX" + } + } +} + refinedarchitect { modId = "refinedstorage_quartz_arsenal" neoForge() @@ -11,6 +21,8 @@ base { archivesName.set("refinedstorage-quartz-arsenal-neoforge") } +val refinedstorageVersion: String by project + val commonJava by configurations.existing val commonResources by configurations.existing @@ -18,4 +30,5 @@ dependencies { compileOnly(project(":refinedstorage-quartz-arsenal-common")) commonJava(project(path = ":refinedstorage-quartz-arsenal-common", configuration = "commonJava")) commonResources(project(path = ":refinedstorage-quartz-arsenal-common", configuration = "commonResources")) + api("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorageVersion}") } diff --git a/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ClientModInitializer.java b/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ClientModInitializer.java index bf07348..d6c9cb9 100644 --- a/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ClientModInitializer.java +++ b/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ClientModInitializer.java @@ -1,14 +1,69 @@ package com.refinedmods.refinedstorage.quartzarsenal.neoforge; +import com.refinedmods.refinedstorage.common.grid.screen.CraftingGridScreen; +import com.refinedmods.refinedstorage.common.support.network.item.NetworkItemPropertyFunction; +import com.refinedmods.refinedstorage.quartzarsenal.common.AbstractClientModInitializer; +import com.refinedmods.refinedstorage.quartzarsenal.common.ContentNames; +import com.refinedmods.refinedstorage.quartzarsenal.common.Items; +import com.refinedmods.refinedstorage.quartzarsenal.common.KeyMappings; +import com.refinedmods.refinedstorage.quartzarsenal.common.Menus; + +import com.mojang.blaze3d.platform.InputConstants; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.renderer.item.ItemProperties; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.neoforge.client.event.InputEvent; +import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; +import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; +import net.neoforged.neoforge.client.settings.KeyConflictContext; +import net.neoforged.neoforge.common.NeoForge; -public final class ClientModInitializer { - private ClientModInitializer() { +public class ClientModInitializer extends AbstractClientModInitializer { + @SubscribeEvent + public static void onClientSetup(final FMLClientSetupEvent e) { + NeoForge.EVENT_BUS.addListener(ClientModInitializer::onKeyInput); + NeoForge.EVENT_BUS.addListener(ClientModInitializer::onMouseInput); + e.enqueueWork(ClientModInitializer::registerItemProperties); } @SubscribeEvent - public static void onClientSetup(final FMLClientSetupEvent e) { - System.out.println("Hello world from the client"); + public static void onKeyInput(final InputEvent.Key e) { + handleInputEvents(); + } + + @SubscribeEvent + public static void onMouseInput(final InputEvent.MouseButton.Pre e) { + handleInputEvents(); + } + + @SubscribeEvent + public static void onRegisterMenuScreens(final RegisterMenuScreensEvent e) { + e.register(Menus.INSTANCE.getWirelessCraftingGrid(), CraftingGridScreen::new); + } + + @SubscribeEvent + public static void onRegisterKeyMappings(final RegisterKeyMappingsEvent e) { + final KeyMapping openWirelessCraftingGrid = new KeyMapping( + ContentNames.OPEN_WIRELESS_CRAFTING_GRID_TRANSLATION_KEY, + KeyConflictContext.IN_GAME, + InputConstants.UNKNOWN, + ContentNames.MOD_TRANSLATION_KEY + ); + e.register(openWirelessCraftingGrid); + KeyMappings.INSTANCE.setOpenWirelessCraftingGrid(openWirelessCraftingGrid); + } + + private static void registerItemProperties() { + ItemProperties.register( + Items.INSTANCE.getWirelessCraftingGrid(), + NetworkItemPropertyFunction.NAME, + new NetworkItemPropertyFunction() + ); + ItemProperties.register( + Items.INSTANCE.getCreativeWirelessCraftingGrid(), + NetworkItemPropertyFunction.NAME, + new NetworkItemPropertyFunction() + ); } } diff --git a/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ConfigImpl.java b/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ConfigImpl.java new file mode 100644 index 0000000..783226d --- /dev/null +++ b/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ConfigImpl.java @@ -0,0 +1,98 @@ +package com.refinedmods.refinedstorage.quartzarsenal.neoforge; + +import com.refinedmods.refinedstorage.quartzarsenal.common.Config; +import com.refinedmods.refinedstorage.quartzarsenal.common.DefaultEnergyUsage; + +import net.neoforged.neoforge.common.ModConfigSpec; + +import static com.refinedmods.refinedstorage.quartzarsenal.common.QuartzArsenalIdentifierUtil.createQuartzArsenalTranslationKey; + +public class ConfigImpl implements Config { + private final ModConfigSpec.Builder builder = new ModConfigSpec.Builder(); + private final ModConfigSpec spec; + private final WirelessCraftingGridEntry wirelessCraftingGrid; + + public ConfigImpl() { + wirelessCraftingGrid = new WirelessCraftingGridEntryImpl(); + spec = builder.build(); + } + + public ModConfigSpec getSpec() { + return spec; + } + + @Override + public WirelessCraftingGridEntry getWirelessCraftingGrid() { + return wirelessCraftingGrid; + } + + private static String translationKey(final String value) { + return createQuartzArsenalTranslationKey("text.autoconfig", "option." + value); + } + + private class WirelessCraftingGridEntryImpl implements WirelessCraftingGridEntry { + private final ModConfigSpec.LongValue energyCapacity; + private final ModConfigSpec.LongValue openEnergyUsage; + private final ModConfigSpec.LongValue craftingEnergyUsage; + private final ModConfigSpec.LongValue autocraftingEnergyUsage; + private final ModConfigSpec.LongValue clearMatrixEnergyUsage; + private final ModConfigSpec.LongValue recipeTransferEnergyUsage; + + WirelessCraftingGridEntryImpl() { + builder.translation(translationKey("wirelessCraftingGrid")).push("wirelessCraftingGrid"); + energyCapacity = builder + .translation(translationKey("wirelessCraftingGrid.energyCapacity")) + .defineInRange("energyCapacity", DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_CAPACITY, 0, Long.MAX_VALUE); + openEnergyUsage = builder + .translation(translationKey("wirelessCraftingGrid.openEnergyUsage")) + .defineInRange("openEnergyUsage", DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_OPEN, 0, Long.MAX_VALUE); + craftingEnergyUsage = builder + .translation(translationKey("wirelessCraftingGrid.craftingEnergyUsage")) + .defineInRange("craftingEnergyUsage", DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_CRAFTING, 0, + Long.MAX_VALUE); + autocraftingEnergyUsage = builder + .translation(translationKey("wirelessCraftingGrid.autocraftingEnergyUsage")) + .defineInRange("autocraftingEnergyUsage", DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_AUTOCRAFTING, 0, + Long.MAX_VALUE); + clearMatrixEnergyUsage = builder + .translation(translationKey("wirelessCraftingGrid.clearMatrixEnergyUsage")) + .defineInRange("clearMatrixEnergyUsage", DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_CLEAR_MATRIX, 0, + Long.MAX_VALUE); + recipeTransferEnergyUsage = builder + .translation(translationKey("wirelessCraftingGrid.recipeTransferEnergyUsage")) + .defineInRange("recipeTransferEnergyUsage", DefaultEnergyUsage.WIRELESS_CRAFTING_GRID_RECIPE_TRANSFER, + 0, Long.MAX_VALUE); + builder.pop(); + } + + @Override + public long getEnergyCapacity() { + return energyCapacity.get(); + } + + @Override + public long getOpenEnergyUsage() { + return openEnergyUsage.get(); + } + + @Override + public long getCraftingEnergyUsage() { + return craftingEnergyUsage.get(); + } + + @Override + public long getAutocraftingEnergyUsage() { + return autocraftingEnergyUsage.get(); + } + + @Override + public long getClearMatrixEnergyUsage() { + return clearMatrixEnergyUsage.get(); + } + + @Override + public long getRecipeTransferEnergyUsage() { + return recipeTransferEnergyUsage.get(); + } + } +} diff --git a/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ModInitializer.java b/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ModInitializer.java index 5fa065a..6b8e32f 100644 --- a/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ModInitializer.java +++ b/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/ModInitializer.java @@ -1,25 +1,164 @@ package com.refinedmods.refinedstorage.quartzarsenal.neoforge; -import com.refinedmods.refinedstorage.quartzarsenal.common.Common; +import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.content.ExtendedMenuTypeFactory; +import com.refinedmods.refinedstorage.common.content.RegistryCallback; +import com.refinedmods.refinedstorage.neoforge.support.energy.EnergyStorageAdapter; +import com.refinedmods.refinedstorage.quartzarsenal.common.AbstractModInitializer; +import com.refinedmods.refinedstorage.quartzarsenal.common.ContentIds; +import com.refinedmods.refinedstorage.quartzarsenal.common.CreativeModeTabItems; +import com.refinedmods.refinedstorage.quartzarsenal.common.Items; +import com.refinedmods.refinedstorage.quartzarsenal.common.Platform; +import com.refinedmods.refinedstorage.quartzarsenal.common.QuartzArsenalIdentifierUtil; +import com.refinedmods.refinedstorage.quartzarsenal.common.wirelesscraftinggrid.WirelessCraftingGridItem; +import java.util.function.Supplier; + +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; -import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.loading.FMLEnvironment; -import net.neoforged.neoforge.registries.RegisterEvent; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.client.gui.ConfigurationScreen; +import net.neoforged.neoforge.client.gui.IConfigScreenFactory; +import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; +import net.neoforged.neoforge.registries.DeferredRegister; + +@Mod(QuartzArsenalIdentifierUtil.QUARTZ_ARSENAL_MOD_ID) +public class ModInitializer extends AbstractModInitializer { + private final DeferredRegister itemRegistry = + DeferredRegister.create(BuiltInRegistries.ITEM, QuartzArsenalIdentifierUtil.QUARTZ_ARSENAL_MOD_ID); + private final DeferredRegister> menuTypeRegistry = + DeferredRegister.create(BuiltInRegistries.MENU, QuartzArsenalIdentifierUtil.QUARTZ_ARSENAL_MOD_ID); + private final DeferredRegister> dataComponentTypeRegistry = DeferredRegister.create( + BuiltInRegistries.DATA_COMPONENT_TYPE, + QuartzArsenalIdentifierUtil.QUARTZ_ARSENAL_MOD_ID + ); -@Mod(Common.MOD_ID) -public class ModInitializer { - public ModInitializer(final IEventBus eventBus) { + public ModInitializer(final IEventBus eventBus, final ModContainer modContainer) { + final ConfigImpl config = new ConfigImpl(); + modContainer.registerConfig(ModConfig.Type.COMMON, config.getSpec()); + Platform.setConfigProvider(() -> config); if (FMLEnvironment.dist == Dist.CLIENT) { eventBus.addListener(ClientModInitializer::onClientSetup); + eventBus.addListener(ClientModInitializer::onRegisterMenuScreens); + eventBus.addListener(ClientModInitializer::onRegisterKeyMappings); + modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new); + } + registerContent(eventBus); + eventBus.addListener(this::registerCapabilities); + eventBus.addListener(this::registerCreativeModeTabListener); + } + + private void registerContent(final IEventBus eventBus) { + registerItems(eventBus); + registerMenus(eventBus); + registerDataComponents(eventBus); + } + + private void registerItems(final IEventBus eventBus) { + final RegistryCallback callback = new ForgeRegistryCallback<>(itemRegistry); + registerCustomItems(callback); + itemRegistry.register(eventBus); + } + + private void registerCustomItems(final RegistryCallback callback) { + Items.INSTANCE.setWirelessCraftingGrid( + callback.register(ContentIds.WIRELESS_CRAFTING_GRID, () -> new WirelessCraftingGridItem( + false, + RefinedStorageApi.INSTANCE.getEnergyItemHelper(), + RefinedStorageApi.INSTANCE.getNetworkItemHelper() + ) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowComponentsUpdateAnimation(oldStack, newStack); + } + }) + ); + Items.INSTANCE.setCreativeWirelessCraftingGrid( + callback.register(ContentIds.CREATIVE_WIRELESS_CRAFTING_GRID, () -> new WirelessCraftingGridItem( + true, + RefinedStorageApi.INSTANCE.getEnergyItemHelper(), + RefinedStorageApi.INSTANCE.getNetworkItemHelper() + ) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowComponentsUpdateAnimation(oldStack, newStack); + } + }) + ); + } + + private void registerMenus(final IEventBus eventBus) { + registerMenus(new ForgeRegistryCallback<>(menuTypeRegistry), new ExtendedMenuTypeFactory() { + @Override + public MenuType create(final MenuSupplier supplier, + final StreamCodec + streamCodec) { + return IMenuTypeExtension.create((syncId, inventory, buf) -> { + final D data = streamCodec.decode(buf); + return supplier.create(syncId, inventory, data); + }); + } + }); + menuTypeRegistry.register(eventBus); + } + + private void registerDataComponents(final IEventBus eventBus) { + final RegistryCallback> callback = new ForgeRegistryCallback<>(dataComponentTypeRegistry); + registerDataComponents(callback); + dataComponentTypeRegistry.register(eventBus); + } + + private void registerCapabilities(final RegisterCapabilitiesEvent event) { + registerEnergyItemProviders(event); + } + + private void registerEnergyItemProviders(final RegisterCapabilitiesEvent event) { + event.registerItem( + Capabilities.EnergyStorage.ITEM, + (stack, ctx) -> new EnergyStorageAdapter( + Items.INSTANCE.getWirelessCraftingGrid().createEnergyStorage(stack) + ), + Items.INSTANCE.getWirelessCraftingGrid() + ); + } + + private void registerCreativeModeTabListener(final BuildCreativeModeTabContentsEvent e) { + final ResourceKey creativeModeTab = ResourceKey.create( + Registries.CREATIVE_MODE_TAB, + RefinedStorageApi.INSTANCE.getCreativeModeTabId() + ); + if (!e.getTabKey().equals(creativeModeTab)) { + return; } - eventBus.addListener(this::onRegister); + CreativeModeTabItems.addItems(e::accept); } - @SubscribeEvent - public void onRegister(final RegisterEvent e) { - Common.helloWorld(); + private record ForgeRegistryCallback(DeferredRegister registry) implements RegistryCallback { + @Override + public Supplier register(final ResourceLocation id, final Supplier value) { + return registry.register(id.getPath(), value); + } } } diff --git a/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/package-info.java b/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/package-info.java index b178207..a81d9db 100644 --- a/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/package-info.java +++ b/refinedstorage-quartz-arsenal-neoforge/src/main/java/com/refinedmods/refinedstorage/quartzarsenal/neoforge/package-info.java @@ -1,4 +1,7 @@ @ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault package com.refinedmods.refinedstorage.quartzarsenal.neoforge; +import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault; + import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage-quartz-arsenal-neoforge/src/main/templates/META-INF/neoforge.mods.toml b/refinedstorage-quartz-arsenal-neoforge/src/main/templates/META-INF/neoforge.mods.toml index 81f6013..86bd5e2 100644 --- a/refinedstorage-quartz-arsenal-neoforge/src/main/templates/META-INF/neoforge.mods.toml +++ b/refinedstorage-quartz-arsenal-neoforge/src/main/templates/META-INF/neoforge.mods.toml @@ -6,8 +6,13 @@ license = "MIT" modId = "refinedstorage_quartz_arsenal" version = "${version}" displayName = "Refined Storage - Quartz Arsenal" -displayURL = "https://github.com/refinedmods/refinedstorage-quartz-arsenal" +displayURL = "https://refinedmods.com/refined-storage" authors = "Refined Mods" description = ''' Quartz Arsenal is an addon for Refined Storage that adds various new tools. ''' +[[dependencies.refinedstorage_quartz_arsenal]] +modId = "refinedstorage" +type = "required" +versionRange = "2.0.0-milestone.4.10" +side = "BOTH"