Skip to content

Commit

Permalink
add productive bees compat
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Jun 19, 2024
1 parent db5bf8c commit 53276b6
Show file tree
Hide file tree
Showing 19 changed files with 581 additions and 20 deletions.
10 changes: 8 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -30,11 +30,17 @@ allprojects {
}

repositories {
mavenCentral()
mavenCentral {
content {
excludeGroupByRegex("org.lwjgl")
}
}

badasintended()
cursemaven()
modrinth()
mavenLocal()
minecraft()
}
}

Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<File>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Repositories.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Uploads.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ object cfIds {
val wirelessNet = "461316"
val lapisReserve = "399679"
val resourceChickens = "632145"
val productiveBees = "377897"
val top = "245211"
}

object cfSlugs {
Expand All @@ -36,6 +38,7 @@ object cfSlugs {
val wirelessNet = "wireless-networks"
val lapisReserve = "lapis-reserve"
val resourceChickens = "resource-chickens"
val productiveBees = "productivebees"
}

object mrIds {
Expand Down
16 changes: 9 additions & 7 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions modules/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}

Expand Down
7 changes: 4 additions & 3 deletions modules/forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -96,7 +95,9 @@ allprojects {
minecraft {
runs {
val runConfig = Action<RunConfig> {
ideaModule(rootProject.name + project.path.replace(':', '.') + ".main")
workingDirectory(file("run"))
jvmArgs("-XX:+AllowEnhancedClassRedefinition")

mods.create("megane") {
source(sourceSets["main"])
Expand Down
17 changes: 17 additions & 0 deletions modules/forge/productive-bees/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<AdvancedBeehiveBlockEntityAbstract> {

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<String>(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<AdvancedBeehiveBlockEntityAbstract> 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<OccupantsData.Occupant>(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<Occupant> 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) {

}

}

}
Loading

0 comments on commit 53276b6

Please sign in to comment.