Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamalam360 committed Oct 25, 2024
1 parent 1e9a3ab commit 6e68b2b
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 13 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
- (fix) crash when trying to automatically insert items into belt (#55)
- (feat) compat with LambDynamicLights
- When LambDynamicLights is installed, you will be able to put light sources into your Utility Belt and they will illuminate the world around you.
- If you have suggestions for other dynamic lights mods to add compat for, please open an issue on GitHub.
- Closes #56
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
modImplementation(libs.accessories.common) {
exclude group: "mezz.jei"
}

compileOnly libs.mixin.extras.common
annotationProcessor libs.mixin.extras.common
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.jamalam360.utility_belt.mixin;

import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.util.DynamicTags;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.tags.TagEntry;
import net.minecraft.tags.TagLoader;
import net.minecraft.world.item.Item;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Mixin(TagLoader.class)
public class TagLoaderMixin {
@Inject(
method = "load",
at = @At("TAIL")
)
private void utilitybelt$injectDynamicTags(ResourceManager resourceManager, CallbackInfoReturnable<Map<ResourceLocation, List<TagLoader.EntryWithSource>>> cir) {
Map<ResourceLocation, List<TagLoader.EntryWithSource>> map = cir.getReturnValue();
List<TagLoader.EntryWithSource> list = map.computeIfAbsent(UtilityBelt.ALLOWED_IN_UTILITY_BELT.location(), id -> new ArrayList<>());

for (ResourceLocation item : DynamicTags.getExtraItemsAllowedInUtilityBelt()) {
list.add(new TagLoader.EntryWithSource(TagEntry.element(item), "utilitybelt"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.jamalam360.utility_belt.util;

import dev.architectury.platform.Platform;
import io.github.jamalam360.utility_belt.UtilityBelt;
import net.minecraft.resources.ResourceLocation;

import java.util.ArrayList;
import java.util.List;

public class DynamicTags {
private static final String LAMB_DYNAMIC_LIGHTS = "lambdynlights";

public static List<ResourceLocation> getExtraItemsAllowedInUtilityBelt() {
List<ResourceLocation> list = new ArrayList<>();

if (Platform.isModLoaded(LAMB_DYNAMIC_LIGHTS)) {
UtilityBelt.LOGGER.info("Registering extra Utility Belt entries for LambDynamicLights compatibility.");
list.add(minecraft("torch"));
list.add(minecraft("redstone_torch"));
list.add(minecraft("soul_torch"));
list.add(minecraft("lantern"));
}

return list;
}

private static ResourceLocation minecraft(String path) {
return ResourceLocation.fromNamespaceAndPath("minecraft", path);
}
}
3 changes: 2 additions & 1 deletion common/src/main/resources/utility_belt.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"LivingEntityMixin",
"PlayerMixin",
"ServerGamePacketListenerImplMixin",
"ServerPlayerMixin"
"ServerPlayerMixin",
"TagLoaderMixin"
],
"client": [
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Blocks;

import java.util.concurrent.CompletableFuture;

Expand Down
14 changes: 12 additions & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ configurations {
developmentFabric.extendsFrom common
}

repositories {
maven {
name = "Gegy's Maven"
url = "https://maven.gegy.dev"
}
}

dependencies {
modImplementation libs.fabric.loader
modImplementation libs.fabric.api
modImplementation libs.architectury.fabric
modImplementation libs.jamlib.fabric
modImplementation libs.accessories.fabric
modRuntimeOnly libs.modmenu
modRuntimeOnly libs.accessories.fabric

// Compat
modImplementation libs.lambdynamiclights

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
Expand All @@ -38,7 +48,7 @@ if (System.getenv("CURSEFORGE_API_KEY") != null && System.getenv("MODRINTH_API_K
displayName = "V${project.version} (Fabric ${project.minecraft_version})"
changelog = rootProject.file("CHANGELOG.md").text
releaseType = project.version.contains("beta") ? "beta" : "release"
gameVersions = [project.minecraft_version]
gameVersions = [project.minecraft_version, *project.additional_minecraft_versions.split(",")]
gameLoaders = ["fabric", "quilt"]

mainPublication tasks.remapJar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.jamalam360.utility_belt.fabric.compat;

import dev.lambdaurora.lambdynlights.LambDynLights;
import dev.lambdaurora.lambdynlights.api.DynamicLightHandler;
import dev.lambdaurora.lambdynlights.api.DynamicLightHandlers;
import dev.lambdaurora.lambdynlights.api.DynamicLightsInitializer;
import dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;
import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.UtilityBeltInventory;
import io.github.jamalam360.utility_belt.state.StateManager;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

public class LambDynamicLightsCompat implements DynamicLightsInitializer {
@Override
public void onInitializeDynamicLights(ItemLightSourceManager manager) {
UtilityBelt.LOGGER.info("Initializing LambDynamicLights compat for Utility Belt.");
DynamicLightHandlers.registerDynamicLightHandler(EntityType.PLAYER, DynamicLightHandler.makeHandler(this::getLuminanceInBelt, player -> false));
}

private int getLuminanceInBelt(Player player) {
boolean submerged = isEyeSubmergedInFluid(player);
int luminance = 0;

StateManager stateManager = StateManager.getStateManager(player);
if (stateManager.hasBelt(player)) {
UtilityBeltInventory inv = stateManager.getInventory(player);

for (ItemStack stack : inv.items()) {
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(stack, submerged));

This comment has been minimized.

Copy link
@LambdAurora

LambdAurora Nov 2, 2024

LambDynLights should be considered internal and thus unstable.

The ItemLightSourceManager provides you the same method but in a stable supported way.

}
}

return luminance;
}

// From LambDynLights mod
private static boolean isEyeSubmergedInFluid(LivingEntity entity) {
if (!LambDynLights.get().config.getWaterSensitiveCheck().get()) {
return false;
} else {
BlockPos eyePos = BlockPos.containing(entity.getX(), entity.getEyeY(), entity.getZ());
return !entity.level().getFluidState(eyePos).isEmpty();
}
}
}
3 changes: 3 additions & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
],
"client": [
"io.github.jamalam360.utility_belt.fabric.UtilityBeltFabricClient"
],
"dynamiclights": [
"io.github.jamalam360.utility_belt.fabric.compat.LambDynamicLightsCompat"
]
},
"mixins": [
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.parallel=true

version=2.4.3+1.21
minecraft_version=1.21
version=2.5.0+1.21.1
minecraft_version=1.21.1
additional_minecraft_versions=1.21
branch=main
group=io.github.jamalam360
mod_name=Utility Belt
Expand Down
17 changes: 11 additions & 6 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
[versions]
# https://modrinth.com/mod/architectury-api/versions
architectury = "13.0.6"
architectury = "13.0.8"

# https://projects.neoforged.net/neoforged/neoforge
neoforge = "21.0.144"
neoforge = "21.1.72"

# https://fabricmc.net/develop
fabric-loader = "0.15.11"
fabric-api = "0.100.7+1.21"
fabric-api = "0.106.0+1.21.1"

# https://maven.jamalam.tech/#/releases
jamlib = "1.0.10+1.21"
jamlib = "1.2.1+1.21"

# https://modrinth.com/mod/accessories/versions
accessories = "1.0.0-beta.24+1.21"
accessories = "1.1.0-beta.11+1.21.1"

# https://github.com/LlamaLad7/MixinExtras/releases
mixin-extras = "0.3.6"
mixin-extras = "0.4.1"

# https://modrinth.com/mod/modmenu/versions
modmenu = "11.0.1"

# https://modrinth.com/mod/lambdynamiclights/versions
lambdynamiclights = "3.1.0+1.21.1"

[libraries]
architectury-common = { module = "dev.architectury:architectury", version.ref = "architectury" }
architectury-fabric = { module = "dev.architectury:architectury-fabric", version.ref = "architectury" }
Expand All @@ -42,3 +45,5 @@ accessories-neoforge = { module = "io.wispforest:accessories-neoforge", version.
mixin-extras-common = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixin-extras" }

modmenu = { module = "maven.modrinth:modmenu", version.ref = "modmenu" }

lambdynamiclights = { module = "dev.lambdaurora.lambdynamiclights:lambdynamiclights-runtime", version.ref = "lambdynamiclights" }
2 changes: 1 addition & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (System.getenv("CURSEFORGE_API_KEY") != null && System.getenv("MODRINTH_API_K
displayName = "V${project.version} (NeoForge ${project.minecraft_version})"
changelog = rootProject.file("CHANGELOG.md").text
releaseType = project.version.contains("beta") ? "beta" : "release"
gameVersions = [project.minecraft_version]
gameVersions = [project.minecraft_version, *project.additional_minecraft_versions.split(",")]
gameLoaders = ["neoforge"]

mainPublication tasks.remapJar
Expand Down

0 comments on commit 6e68b2b

Please sign in to comment.