From 53276b62c4fec29eb616b8e7a554793b0ccb4a96 Mon Sep 17 00:00:00 2001 From: deirn Date: Wed, 19 Jun 2024 20:02:18 +0700 Subject: [PATCH] add productive bees compat #73 --- build.gradle.kts | 10 +- buildSrc/src/main/kotlin/Dependencies.kt | 2 + .../main/kotlin/FetchLatestVersionsTask.kt | 12 +- buildSrc/src/main/kotlin/Repositories.kt | 1 + buildSrc/src/main/kotlin/Uploads.kt | 3 + dependencies.json | 16 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- modules/fabric/build.gradle.kts | 3 +- modules/forge/build.gradle.kts | 7 +- .../forge/productive-bees/build.gradle.kts | 17 +++ .../productivebees/MeganeProductiveBees.java | 76 ++++++++++++ .../provider/AdvancedBeehiveProvider.java | 111 ++++++++++++++++++ .../productivebees/provider/JarProvider.java | 97 +++++++++++++++ .../provider/ProductiveBeeProvider.java | 97 +++++++++++++++ .../provider/RecipeProcessingProvider.java | 34 ++++++ .../provider/SolitaryNestProvider.java | 86 ++++++++++++++ .../forge/resource-chickens/build.gradle.kts | 1 + settings.gradle.kts | 1 + src/translation/resources/lang/en_us.json | 25 ++++ 19 files changed, 581 insertions(+), 20 deletions(-) create mode 100644 modules/forge/productive-bees/build.gradle.kts create mode 100644 modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/MeganeProductiveBees.java create mode 100644 modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/AdvancedBeehiveProvider.java create mode 100644 modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/JarProvider.java create mode 100644 modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/ProductiveBeeProvider.java create mode 100644 modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/RecipeProcessingProvider.java create mode 100644 modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/SolitaryNestProvider.java diff --git a/build.gradle.kts b/build.gradle.kts index 252b124..8c837e6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import java.nio.charset.StandardCharsets plugins { java - id("lol.bai.explosion") version "0.1.0" apply false + id("lol.bai.explosion") version "0.2.0" apply false id("me.modmuss50.mod-publish-plugin") version "0.4.5" apply false } @@ -30,11 +30,17 @@ allprojects { } repositories { - mavenCentral() + mavenCentral { + content { + excludeGroupByRegex("org.lwjgl") + } + } + badasintended() cursemaven() modrinth() mavenLocal() + minecraft() } } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 5d28c1d..eb19109 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -84,6 +84,8 @@ object deps { val jei by json() val lapisReserve by json() val resourceChickens by json() + val productiveBees by json() + val top by json() object mekanism : DependencyPath { override val prefix = "forge.mekanism" diff --git a/buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt b/buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt index 1f65346..6052d5b 100644 --- a/buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt +++ b/buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt @@ -14,7 +14,7 @@ import java.net.http.HttpClient import java.util.* import kotlin.reflect.KProperty -@Suppress("LeakingThis") +@Suppress("LeakingThis", "DuplicatedCode") abstract class FetchLatestVersionsTask : DefaultTask() { @get:InputFile abstract val output: Property @@ -85,8 +85,8 @@ abstract class FetchLatestVersionsTask : DefaultTask() { fetch(fabric::rebornCore, cfIds.rebornCore) { "RebornCore:RebornCore-1.19:${it.download.fileName.removePrefix("RebornCore-")}" } fetch(fabric::techReborn, cfIds.techReborn) { "TechReborn:TechReborn-1.19:${it.download.fileName.removePrefix("TechReborn-")}" } fetch(fabric::wirelessNet, cfIds.wirelessNet, "1.19") { it.maven } - fetch(fabric::lapisReserve, cfIds.lapisReserve, "1.19.2") { it.maven } - fetch(fabric::resourceChickens, cfIds.resourceChickens, "1.19.2") { it.api } + fetch(fabric::lapisReserve, cfIds.lapisReserve) { it.maven } + fetch(fabric::resourceChickens, cfIds.resourceChickens) { it.api } } fetcher(ModrinthVersionFetcher, "forge", forge.wthit) { @@ -116,8 +116,10 @@ abstract class FetchLatestVersionsTask : DefaultTask() { } fetcher(CurseForgeVersionFetcher, "forge", forge) { - fetch(forge::lapisReserve, cfIds.lapisReserve, "1.19.2") { it.maven } - fetch(forge::resourceChickens, cfIds.resourceChickens, "1.19.2") { it.api } + fetch(forge::lapisReserve, cfIds.lapisReserve) { it.maven } + fetch(forge::resourceChickens, cfIds.resourceChickens) { it.api } + fetch(forge::productiveBees, cfIds.productiveBees) { it.maven } + fetch(forge::top, cfIds.top) { it.maven } } mapper diff --git a/buildSrc/src/main/kotlin/Repositories.kt b/buildSrc/src/main/kotlin/Repositories.kt index a890406..98a4cc0 100644 --- a/buildSrc/src/main/kotlin/Repositories.kt +++ b/buildSrc/src/main/kotlin/Repositories.kt @@ -2,6 +2,7 @@ import org.gradle.kotlin.dsl.ivy import org.gradle.kotlin.dsl.maven import org.gradle.api.artifacts.dsl.RepositoryHandler as Repo +fun Repo.minecraft() = maven("https://libraries.minecraft.net") fun Repo.badasintended() = maven("https://maven.bai.lol") fun Repo.bbkr() = maven("https://server.bbkr.space/artifactory/libs-release") fun Repo.shedaniel() = maven("https://maven.shedaniel.me/") diff --git a/buildSrc/src/main/kotlin/Uploads.kt b/buildSrc/src/main/kotlin/Uploads.kt index 8154db4..dcab206 100644 --- a/buildSrc/src/main/kotlin/Uploads.kt +++ b/buildSrc/src/main/kotlin/Uploads.kt @@ -13,6 +13,8 @@ object cfIds { val wirelessNet = "461316" val lapisReserve = "399679" val resourceChickens = "632145" + val productiveBees = "377897" + val top = "245211" } object cfSlugs { @@ -36,6 +38,7 @@ object cfSlugs { val wirelessNet = "wireless-networks" val lapisReserve = "lapis-reserve" val resourceChickens = "resource-chickens" + val productiveBees = "productivebees" } object mrIds { diff --git a/dependencies.json b/dependencies.json index f2c259b..ec0585c 100644 --- a/dependencies.json +++ b/dependencies.json @@ -1,6 +1,6 @@ { - "fabric.wthit.api" : "mcp.mobius.waila:wthit-api:fabric-5.25.0", - "fabric.wthit.runtime" : "mcp.mobius.waila:wthit:fabric-5.25.0", + "fabric.wthit.api" : "mcp.mobius.waila:wthit-api:fabric-5.28.0", + "fabric.wthit.runtime" : "mcp.mobius.waila:wthit:fabric-5.28.0", "fabric.badpackets" : "lol.bai:badpackets:fabric-0.2.3", "fabric.ae2" : "appeng:appliedenergistics2-fabric:12.9.9", "fabric.alloyForge" : "maven.modrinth:jhl28YkY:q1L7hbA8", @@ -9,7 +9,7 @@ "fabric.clothConfig" : "me.shedaniel.cloth:cloth-config-fabric:8.3.115", "fabric.extraGen" : "maven.modrinth:VXtwLg17:2p7qWneI", "fabric.fabricApi" : "net.fabricmc.fabric-api:fabric-api:0.77.0+1.19.2", - "fabric.flk" : "net.fabricmc:fabric-language-kotlin:1.10.19+kotlin.1.9.23", + "fabric.flk" : "net.fabricmc:fabric-language-kotlin:1.11.0+kotlin.2.0.0", "fabric.kibe" : "maven.modrinth:OvlwmUdC:6GPdTrdx", "fabric.modernDynamics" : "maven.modrinth:fMpvLrnF:uSorcoNB", "fabric.modmenu" : "com.terraformersmc:modmenu:4.2.0-beta.2", @@ -26,19 +26,21 @@ "fabric.wirelessNet" : "curse.maven:cursemod-461316:3876132", "fabric.lapisReserve" : "curse.maven:cursemod-399679:3345208", "fabric.resourceChickens" : "curse.api:632145:4985700", - "forge.wthit.api" : "mcp.mobius.waila:wthit-api:forge-5.25.0", - "forge.wthit.runtime" : "mcp.mobius.waila:wthit:forge-5.25.0", + "forge.wthit.api" : "mcp.mobius.waila:wthit-api:forge-5.28.0", + "forge.wthit.runtime" : "mcp.mobius.waila:wthit:forge-5.28.0", "forge.badpackets" : "lol.bai:badpackets:forge-0.2.3", "forge.ae2" : "appeng:appliedenergistics2-forge:12.9.9", "forge.create" : "maven.modrinth:LNytGWDc:Vfzp1Xaz", "forge.ie" : "maven.modrinth:tIm2nV03:VzTXQKEm", "forge.rs" : "maven.modrinth:KDvYkUg3:q3LiZwUb", - "forge.jei" : "maven.modrinth:u6dRKJwZ:Y1en3Fb4", + "forge.jei" : "maven.modrinth:u6dRKJwZ:2vJsVMlk", "forge.mekanism.core" : "mekanism:Mekanism:1.20.1-10.3.9.13", "forge.mekanism.generators" : "mekanism:Mekanism:1.20.1-10.3.9.13:generators", "forge.thermal.cofhCore" : "maven.modrinth:OWSRM4vD:ssRHxD6e", "forge.thermal.foundation" : "maven.modrinth:Xvg6q5Wp:kaIOIjDc", "forge.thermal.expansion" : "maven.modrinth:hmD6rrUJ:W9opx6mY", "forge.lapisReserve" : "curse.maven:cursemod-399679:3787247", - "forge.resourceChickens" : "curse.api:632145:5088913" + "forge.resourceChickens" : "curse.api:632145:5088913", + "forge.productiveBees" : "curse.maven:cursemod-377897:4566382", + "forge.top" : "curse.maven:cursemod-245211:3965693" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 84a729f..03d09ac 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase = GRADLE_USER_HOME distributionPath = wrapper/dists -distributionUrl = https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl = https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase = GRADLE_USER_HOME zipStorePath = wrapper/dists diff --git a/modules/fabric/build.gradle.kts b/modules/fabric/build.gradle.kts index 8057bc6..187bd23 100644 --- a/modules/fabric/build.gradle.kts +++ b/modules/fabric/build.gradle.kts @@ -1,8 +1,7 @@ import me.modmuss50.mpp.ReleaseType plugins { - id("fabric-loom") version "1.5.+" - + id("fabric-loom") version "1.6.12" id("me.modmuss50.mod-publish-plugin") } diff --git a/modules/forge/build.gradle.kts b/modules/forge/build.gradle.kts index af7956b..0c3d974 100644 --- a/modules/forge/build.gradle.kts +++ b/modules/forge/build.gradle.kts @@ -3,9 +3,8 @@ import me.modmuss50.mpp.ReleaseType import net.minecraftforge.gradle.common.util.RunConfig plugins { - id("net.minecraftforge.gradle") version "[6.0.16, 6.2)" - id("org.spongepowered.mixin") version "0.7.+" - + id("net.minecraftforge.gradle") version "6.0.25" + id("org.spongepowered.mixin") version "0.7.38" id("me.modmuss50.mod-publish-plugin") } @@ -96,7 +95,9 @@ allprojects { minecraft { runs { val runConfig = Action { + ideaModule(rootProject.name + project.path.replace(':', '.') + ".main") workingDirectory(file("run")) + jvmArgs("-XX:+AllowEnhancedClassRedefinition") mods.create("megane") { source(sourceSets["main"]) diff --git a/modules/forge/productive-bees/build.gradle.kts b/modules/forge/productive-bees/build.gradle.kts new file mode 100644 index 0000000..d6f21e6 --- /dev/null +++ b/modules/forge/productive-bees/build.gradle.kts @@ -0,0 +1,17 @@ +metadata("lol.bai.megane.module.productivebees") { + waila("MeganeProductiveBees") { + required("productivebees") + } + + forgeFml() + packMcmeta() + language() + + modsToml{ + depends("productivebees" to any) + } +} + +dependencies { + implementation(fg.deobf(deps.forge.productiveBees)) +} diff --git a/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/MeganeProductiveBees.java b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/MeganeProductiveBees.java new file mode 100644 index 0000000..45f4a67 --- /dev/null +++ b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/MeganeProductiveBees.java @@ -0,0 +1,76 @@ +package lol.bai.megane.module.productivebees; + +import cy.jdkdigital.productivebees.common.block.entity.AdvancedBeehiveBlockEntity; +import cy.jdkdigital.productivebees.common.block.entity.BreedingChamberBlockEntity; +import cy.jdkdigital.productivebees.common.block.entity.CentrifugeBlockEntity; +import cy.jdkdigital.productivebees.common.block.entity.IncubatorBlockEntity; +import cy.jdkdigital.productivebees.common.block.entity.InventoryHandlerHelper; +import cy.jdkdigital.productivebees.common.block.entity.JarBlockEntity; +import cy.jdkdigital.productivebees.common.block.entity.SolitaryNestBlockEntity; +import cy.jdkdigital.productivebees.common.entity.bee.ProductiveBee; +import it.unimi.dsi.fastutil.ints.IntList; +import lol.bai.megane.module.productivebees.provider.AdvancedBeehiveProvider; +import lol.bai.megane.module.productivebees.provider.JarProvider; +import lol.bai.megane.module.productivebees.provider.ProductiveBeeProvider; +import lol.bai.megane.module.productivebees.provider.RecipeProcessingProvider; +import lol.bai.megane.module.productivebees.provider.SolitaryNestProvider; +import mcp.mobius.waila.api.IRegistrar; +import mcp.mobius.waila.api.IWailaPlugin; +import mcp.mobius.waila.api.TooltipPosition; +import net.minecraft.resources.ResourceLocation; + +public class MeganeProductiveBees implements IWailaPlugin { + + public static final ResourceLocation CONFIG_BEE_TYPE = id("bee_type"); + public static final ResourceLocation CONFIG_BEE_PRODUCTIVITY = id("bee_productivity"); + public static final ResourceLocation CONFIG_BEE_TOLERANCE = id("bee_tolerance"); + public static final ResourceLocation CONFIG_BEE_BEHAVIOR = id("bee_behavior"); + public static final ResourceLocation CONFIG_BEE_ENDURANCE = id("bee_endurance"); + public static final ResourceLocation CONFIG_BEE_TEMPER = id("bee_temper"); + + public static final ResourceLocation CONFIG_HIVE_HONEY_LEVEL = id("hive_honey_level"); + public static final ResourceLocation CONFIG_HIVE_OCCUPANTS = id("hive_occupants"); + public static final ResourceLocation CONFIG_HIVE_COOLDOWN = id("hive_cooldown"); + + public static ResourceLocation id(String path) { + return new ResourceLocation("megane:productive_bees." + path); + } + + @Override + public void register(IRegistrar registrar) { + var jarProvider = new JarProvider(); + registrar.addDataType(JarProvider.DATA, JarProvider.Data.class, JarProvider.Data::new); + registrar.addBlockData(jarProvider, JarBlockEntity.class); + registrar.addComponent(jarProvider, TooltipPosition.HEAD, JarBlockEntity.class); + registrar.addComponent(jarProvider, TooltipPosition.TAIL, JarBlockEntity.class); + + var beeProvider = new ProductiveBeeProvider(); + registrar.addFeatureConfig(CONFIG_BEE_TYPE, false); + registrar.addFeatureConfig(CONFIG_BEE_PRODUCTIVITY, false); + registrar.addFeatureConfig(CONFIG_BEE_TOLERANCE, false); + registrar.addFeatureConfig(CONFIG_BEE_BEHAVIOR, false); + registrar.addFeatureConfig(CONFIG_BEE_ENDURANCE, false); + registrar.addFeatureConfig(CONFIG_BEE_TEMPER, false); + registrar.addDataType(ProductiveBeeProvider.DATA, ProductiveBeeProvider.Data.class, ProductiveBeeProvider.Data::new); + registrar.addEntityData(beeProvider, ProductiveBee.class); + registrar.addComponent(beeProvider, TooltipPosition.BODY, ProductiveBee.class); + + var advBeehiveProvider = new AdvancedBeehiveProvider(); + registrar.addFeatureConfig(CONFIG_HIVE_HONEY_LEVEL, true); + registrar.addFeatureConfig(CONFIG_HIVE_OCCUPANTS, false); + registrar.addDataType(AdvancedBeehiveProvider.OCCUPANTS_DATA, AdvancedBeehiveProvider.OccupantsData.class, AdvancedBeehiveProvider.OccupantsData::new); + registrar.addBlockData(advBeehiveProvider, AdvancedBeehiveBlockEntity.class); + registrar.addComponent(advBeehiveProvider, TooltipPosition.BODY, AdvancedBeehiveBlockEntity.class); + + var solitaryNestProvider = new SolitaryNestProvider(); + registrar.addFeatureConfig(CONFIG_HIVE_COOLDOWN, false); + registrar.addDataType(SolitaryNestProvider.DATA, SolitaryNestProvider.Data.class, SolitaryNestProvider.Data::new); + registrar.addBlockData(solitaryNestProvider, SolitaryNestBlockEntity.class, 900); + registrar.addComponent(solitaryNestProvider, TooltipPosition.BODY, SolitaryNestBlockEntity.class); + + registrar.addBlockData(new RecipeProcessingProvider<>(IntList.of(0, 1, 2, 3, 4), IntList.of(5)), BreedingChamberBlockEntity.class); + registrar.addBlockData(new RecipeProcessingProvider<>(IntList.of(InventoryHandlerHelper.INPUT_SLOT), IntList.of(InventoryHandlerHelper.OUTPUT_SLOTS)), CentrifugeBlockEntity.class); + registrar.addBlockData(new RecipeProcessingProvider<>(IntList.of(0, 1), IntList.of(2)), IncubatorBlockEntity.class); + } + +} diff --git a/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/AdvancedBeehiveProvider.java b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/AdvancedBeehiveProvider.java new file mode 100644 index 0000000..ea9e91f --- /dev/null +++ b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/AdvancedBeehiveProvider.java @@ -0,0 +1,111 @@ +package lol.bai.megane.module.productivebees.provider; + +import java.util.ArrayList; +import java.util.List; + +import cy.jdkdigital.productivebees.common.block.entity.AdvancedBeehiveBlockEntityAbstract; +import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; +import lol.bai.megane.module.productivebees.MeganeProductiveBees; +import mcp.mobius.waila.api.IBlockAccessor; +import mcp.mobius.waila.api.IBlockComponentProvider; +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.ITooltip; +import mcp.mobius.waila.api.component.PairComponent; +import net.minecraft.nbt.Tag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.block.BeehiveBlock; +import net.minecraftforge.registries.ForgeRegistries; +import org.jetbrains.annotations.Nullable; + +public class AdvancedBeehiveProvider implements IBlockComponentProvider, IDataProvider { + + public static final ResourceLocation OCCUPANTS_DATA = MeganeProductiveBees.id("occupants"); + + @Override + public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { + var occupants = accessor.getData().get(OccupantsData.class); + if (occupants != null && config.getBoolean(MeganeProductiveBees.CONFIG_HIVE_OCCUPANTS)) { + var names = new Object2IntLinkedOpenHashMap(occupants.occupants.size()); + + for (var occupant : occupants.occupants) { + Component component = null; + if (occupant.customName != null) component = Component.Serializer.fromJson(occupant.customName); + if (component == null) component = occupant.entityType.getDescription(); + + var name = component.getString(); + names.put(name, names.getOrDefault(name, 0) + 1); + } + + for (var entry : names.object2IntEntrySet()) { + var name = entry.getKey(); + var count = entry.getIntValue(); + if (count > 1) tooltip.addLine(Component.literal(count + " " + name)); + else tooltip.addLine(Component.literal(name)); + } + } + + if (config.getBoolean(MeganeProductiveBees.CONFIG_HIVE_HONEY_LEVEL)) { + var state = accessor.getBlockState(); + if (state.hasProperty(BeehiveBlock.HONEY_LEVEL)) tooltip.addLine(new PairComponent( + Component.translatable("tooltip.waila.honey_level"), + Component.literal(state.getValue(BeehiveBlock.HONEY_LEVEL).toString()))); + } + } + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (config.getBoolean(MeganeProductiveBees.CONFIG_HIVE_OCCUPANTS)) data.add(OccupantsData.class, res -> { + var stored = accessor.getTarget().getBeeList(); + if (!stored.isEmpty()) { + var occupants = new ArrayList(stored.size()); + + for (var beeData : stored) { + var beeNbt = beeData.nbt; + + var entityType = EntityType.by(beeNbt); + if (entityType.isEmpty()) continue; + + var customName = beeNbt.contains("CustomName", Tag.TAG_STRING) + ? beeNbt.getString("CustomName") + : null; + + occupants.add(new OccupantsData.Occupant(entityType.get(), customName)); + } + + if (!occupants.isEmpty()) res.add(new OccupantsData(occupants)); + } + }); + } + + public record OccupantsData( + List occupants + ) implements IData { + + public OccupantsData(FriendlyByteBuf buf) { + this(buf.readList(b -> new Occupant( + b.readRegistryIdUnsafe(ForgeRegistries.ENTITY_TYPES), + b.readNullable(FriendlyByteBuf::readUtf)))); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeCollection(occupants, (b, occupant) -> { + b.writeRegistryIdUnsafe(ForgeRegistries.ENTITY_TYPES, occupant.entityType); + b.writeNullable(occupant.customName, FriendlyByteBuf::writeUtf); + }); + } + + public record Occupant(EntityType entityType, @Nullable String customName) { + + } + + } + +} diff --git a/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/JarProvider.java b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/JarProvider.java new file mode 100644 index 0000000..8210578 --- /dev/null +++ b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/JarProvider.java @@ -0,0 +1,97 @@ +package lol.bai.megane.module.productivebees.provider; + +import cy.jdkdigital.productivebees.common.block.entity.JarBlockEntity; +import cy.jdkdigital.productivebees.common.item.BeeCage; +import lol.bai.megane.module.productivebees.MeganeProductiveBees; +import mcp.mobius.waila.api.IBlockAccessor; +import mcp.mobius.waila.api.IBlockComponentProvider; +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IModInfo; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.ITooltip; +import mcp.mobius.waila.api.IWailaConfig; +import mcp.mobius.waila.api.WailaConstants; +import mcp.mobius.waila.api.data.ItemData; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.registries.ForgeRegistries; +import org.jetbrains.annotations.Nullable; + +public class JarProvider implements IBlockComponentProvider, IDataProvider { + + public static final ResourceLocation DATA = MeganeProductiveBees.id("jar"); + + private int updateId = 0; + private @Nullable Entity entity; + + private @Nullable Entity getEntity(IBlockAccessor accessor) { + if (updateId != accessor.getUpdateId()) { + updateId = accessor.getUpdateId(); + entity = null; + + var data = accessor.getData().get(Data.class); + var jar = accessor.getBlockEntity(); + + if (data != null && jar != null) { + entity = jar.getCachedEntity(data.beeStack); + } + } + + return entity; + } + + @Override + public void appendHead(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { + var entity = getEntity(accessor); + if (entity == null) return; + + var formatter = IWailaConfig.get().getFormatter(); + tooltip.setLine(WailaConstants.OBJECT_NAME_TAG, formatter.blockName(entity.getName().getString())); + if (config.getBoolean(WailaConstants.CONFIG_SHOW_REGISTRY)) { + tooltip.setLine(WailaConstants.REGISTRY_NAME_TAG, formatter.registryName(ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()))); + } + } + + @Override + public void appendTail(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { + var entity = getEntity(accessor); + if (entity == null) return; + + tooltip.setLine(WailaConstants.MOD_NAME_TAG, IWailaConfig.get().getFormatter().modName(IModInfo.get(entity).getName())); + } + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + data.blockAll(ItemData.class); + + var jar = accessor.getTarget(); + jar.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(inv -> { + var stack = inv.getStackInSlot(0); + if (BeeCage.isFilled(stack)) { + data.addImmediate(new Data(stack)); + } + }); + } + + public record Data( + ItemStack beeStack + ) implements IData { + + public Data(FriendlyByteBuf buf) { + this(buf.readItem()); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeItem(beeStack); + } + + } + +} diff --git a/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/ProductiveBeeProvider.java b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/ProductiveBeeProvider.java new file mode 100644 index 0000000..c958232 --- /dev/null +++ b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/ProductiveBeeProvider.java @@ -0,0 +1,97 @@ +package lol.bai.megane.module.productivebees.provider; + +import cy.jdkdigital.productivebees.common.entity.bee.ProductiveBee; +import cy.jdkdigital.productivebees.util.BeeAttributes; +import cy.jdkdigital.productivebees.util.ColorUtil; +import lol.bai.megane.module.productivebees.MeganeProductiveBees; +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IEntityAccessor; +import mcp.mobius.waila.api.IEntityComponentProvider; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.ITooltip; +import mcp.mobius.waila.api.component.PairComponent; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +public class ProductiveBeeProvider implements IEntityComponentProvider, IDataProvider { + + public static final ResourceLocation DATA = MeganeProductiveBees.id("bee"); + + @Override + public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) { + var data = accessor.getData().get(Data.class); + if (data == null) return; + + if (config.getBoolean(MeganeProductiveBees.CONFIG_BEE_TYPE)) tooltip.addLine(new PairComponent( + Component.translatable("megane.productive_bees.bee.type"), + Component.translatable("productivebees.information.attribute.type." + data.type).withStyle(ColorUtil.getColor(data.type)))); + + if (config.getBoolean(MeganeProductiveBees.CONFIG_BEE_PRODUCTIVITY)) tooltip.addLine(new PairComponent( + Component.translatable("megane.productive_bees.bee.productivity"), + Component.translatable(BeeAttributes.keyMap.get(BeeAttributes.PRODUCTIVITY).get(data.productivity)).withStyle(ColorUtil.getColor(data.productivity)))); + + if (config.getBoolean(MeganeProductiveBees.CONFIG_BEE_TOLERANCE)) tooltip.addLine(new PairComponent( + Component.translatable("megane.productive_bees.bee.tolerance"), + Component.translatable(BeeAttributes.keyMap.get(BeeAttributes.WEATHER_TOLERANCE).get(data.weatherTolerance)).withStyle(ColorUtil.getColor(data.weatherTolerance)))); + + if (config.getBoolean(MeganeProductiveBees.CONFIG_BEE_BEHAVIOR)) tooltip.addLine(new PairComponent( + Component.translatable("megane.productive_bees.bee.behavior"), + Component.translatable(BeeAttributes.keyMap.get(BeeAttributes.BEHAVIOR).get(data.behavior)).withStyle(ColorUtil.getColor(data.behavior)))); + + if (config.getBoolean(MeganeProductiveBees.CONFIG_BEE_ENDURANCE)) tooltip.addLine(new PairComponent( + Component.translatable("megane.productive_bees.bee.endurance"), + Component.translatable(BeeAttributes.keyMap.get(BeeAttributes.ENDURANCE).get(data.endurance)).withStyle(ColorUtil.getColor(data.endurance)))); + + if (config.getBoolean(MeganeProductiveBees.CONFIG_BEE_TEMPER)) tooltip.addLine(new PairComponent( + Component.translatable("megane.productive_bees.bee.temper"), + Component.translatable(BeeAttributes.keyMap.get(BeeAttributes.TEMPER).get(data.temper)).withStyle(ColorUtil.getColor(data.temper)))); + } + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + var bee = accessor.getTarget(); + data.addImmediate(new Data( + bee.getAttributeValue(BeeAttributes.TYPE), + bee.getAttributeValue(BeeAttributes.PRODUCTIVITY), + bee.getAttributeValue(BeeAttributes.WEATHER_TOLERANCE), + bee.getAttributeValue(BeeAttributes.BEHAVIOR), + bee.getAttributeValue(BeeAttributes.ENDURANCE), + bee.getAttributeValue(BeeAttributes.TEMPER))); + } + + public record Data( + String type, + int productivity, + int weatherTolerance, + int behavior, + int endurance, + int temper + ) implements IData { + + public Data(FriendlyByteBuf buf) { + this( + buf.readUtf(), + buf.readVarInt(), + buf.readVarInt(), + buf.readVarInt(), + buf.readVarInt(), + buf.readVarInt()); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeUtf(type); + buf.writeVarInt(productivity); + buf.writeVarInt(weatherTolerance); + buf.writeVarInt(behavior); + buf.writeVarInt(endurance); + buf.writeVarInt(temper); + } + + } + +} diff --git a/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/RecipeProcessingProvider.java b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/RecipeProcessingProvider.java new file mode 100644 index 0000000..d674cc0 --- /dev/null +++ b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/RecipeProcessingProvider.java @@ -0,0 +1,34 @@ +package lol.bai.megane.module.productivebees.provider; + +import cy.jdkdigital.productivebees.common.block.entity.IRecipeProcessingBlockEntity; +import it.unimi.dsi.fastutil.ints.IntList; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.data.ProgressData; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.capabilities.ForgeCapabilities; + +public class RecipeProcessingProvider implements IDataProvider { + + private final int[] input, output; + + public RecipeProcessingProvider(IntList input, IntList output) { + this.input = input.toIntArray(); + this.output = output.toIntArray(); + } + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + data.add(ProgressData.class, res -> { + var target = accessor.getTarget(); + target.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(inv -> res.add(ProgressData + .ratio((float) target.getRecipeProgress() / target.getProcessingTime()) + .itemGetter(inv::getStackInSlot) + .input(input) + .output(output))); + }); + } + +} diff --git a/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/SolitaryNestProvider.java b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/SolitaryNestProvider.java new file mode 100644 index 0000000..bfed8d1 --- /dev/null +++ b/modules/forge/productive-bees/src/main/java/lol/bai/megane/module/productivebees/provider/SolitaryNestProvider.java @@ -0,0 +1,86 @@ +package lol.bai.megane.module.productivebees.provider; + +import cy.jdkdigital.productivebees.common.block.entity.SolitaryNestBlockEntity; +import lol.bai.megane.module.productivebees.MeganeProductiveBees; +import mcp.mobius.waila.api.IBlockAccessor; +import mcp.mobius.waila.api.IBlockComponentProvider; +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.ITooltip; +import mcp.mobius.waila.api.component.PairComponent; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +public class SolitaryNestProvider implements IBlockComponentProvider, IDataProvider { + + public static final ResourceLocation DATA = MeganeProductiveBees.id("solitary_nest"); + + private static final String TIMER = "%02d:%02d"; + + private long lastCooldown; + private long lastDataSync; + + @Override + public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { + var data = accessor.getData().get(Data.class); + if (data == null || !config.getBoolean(MeganeProductiveBees.CONFIG_HIVE_COOLDOWN)) return; + + if (lastDataSync != accessor.getServerDataTime()) { + lastDataSync = accessor.getServerDataTime(); + lastCooldown = data.tickCooldown; + var delay = (System.currentTimeMillis() - lastDataSync) / 50; + lastCooldown -= delay; + } + + if (lastCooldown > 0) { + var seconds = ((lastCooldown) / 20) + 1; + var minutes = seconds / 60; + seconds = seconds - (minutes * 60); + tooltip.addLine(new PairComponent( + Component.translatable("megane.productive_bees.hive.cooldown"), + Component.literal(TIMER.formatted(minutes, seconds)))); + } else { + tooltip.addLine(new PairComponent( + Component.translatable("megane.productive_bees.hive.can_repopulate"), + data.canRepopulate ? CommonComponents.GUI_YES : CommonComponents.GUI_NO)); + } + + lastCooldown--; + } + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + var target = accessor.getTarget(); + + if (config.getBoolean(MeganeProductiveBees.CONFIG_HIVE_OCCUPANTS)) data.add(AdvancedBeehiveProvider.OccupantsData.class, res -> { + if (!target.isEmpty()) res.block(); + }); + + if (config.getBoolean(MeganeProductiveBees.CONFIG_HIVE_COOLDOWN) && target.isEmpty()) { + data.addImmediate(new Data(target.getNestTickCooldown(), target.canRepopulate())); + } + } + + public record Data( + int tickCooldown, + boolean canRepopulate + ) implements IData { + + public Data(FriendlyByteBuf buf) { + this(buf.readVarInt(), buf.readBoolean()); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeVarInt(tickCooldown); + buf.writeBoolean(canRepopulate); + } + + } + +} diff --git a/modules/forge/resource-chickens/build.gradle.kts b/modules/forge/resource-chickens/build.gradle.kts index 91fcd61..ec96d79 100644 --- a/modules/forge/resource-chickens/build.gradle.kts +++ b/modules/forge/resource-chickens/build.gradle.kts @@ -18,4 +18,5 @@ repositories { dependencies { implementation(fg.deobf(deps.forge.resourceChickens)) + runtimeOnly(fg.deobf(deps.forge.top)) } diff --git a/settings.gradle.kts b/settings.gradle.kts index be27d4a..1c73166 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -47,6 +47,7 @@ forge("create") forge("immersive-engineering") forge("lapis-reserve") //forge("mekanism") +forge("productive-bees") //forge("refined-storage") forge("resource-chickens") //forge("thermal-expansion") diff --git a/src/translation/resources/lang/en_us.json b/src/translation/resources/lang/en_us.json index 6742fa9..bd25263 100644 --- a/src/translation/resources/lang/en_us.json +++ b/src/translation/resources/lang/en_us.json @@ -48,6 +48,31 @@ "config.waila.plugin_megane.ie.assembler_recipes": "Show Assembler Recipes" }, + "productive-bees" : { + "megane.productive_bees.bee.type" : "Type", + "megane.productive_bees.bee.productivity" : "Productivity", + "megane.productive_bees.bee.tolerance" : "Tolerance", + "megane.productive_bees.bee.behavior" : "Behavior", + "megane.productive_bees.bee.endurance" : "Endurance", + "megane.productive_bees.bee.temper" : "Temper", + + "megane.productive_bees.hive.cooldown" : "Temper", + "megane.productive_bees.hive.can_repopulate" : "Can Repopulate", + + "config.waila.plugin_megane.productive_bees" : "Productive Bees", + + "config.waila.plugin_megane.productive_bees.bee_type" : "Show Bee Type", + "config.waila.plugin_megane.productive_bees.bee_productivity": "Show Bee Productivity", + "config.waila.plugin_megane.productive_bees.bee_tolerance" : "Show Bee Tolerance", + "config.waila.plugin_megane.productive_bees.bee_behavior" : "Show Bee Behavior", + "config.waila.plugin_megane.productive_bees.bee_endurance" : "Show Bee Endurance", + "config.waila.plugin_megane.productive_bees.bee_temper" : "Show Bee Temper", + + "config.waila.plugin_megane.productive_bees.hive_honey_level": "Show Beehive Honey Level", + "config.waila.plugin_megane.productive_bees.hive_occupants" : "Show Beehive Occupants", + "config.waila.plugin_megane.productive_bees.hive_cooldown" : "Show Solitary Nest Cooldown" + }, + "resource-chickens" : { "megane.resource_chickens.next_drop" : "Next Drop", "megane.resource_chickens.gain" : "Gain",