generated from JamCoreModding/multi-loader-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e9a3ab
commit 6e68b2b
Showing
12 changed files
with
152 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
common/src/main/java/io/github/jamalam360/utility_belt/mixin/TagLoaderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
common/src/main/java/io/github/jamalam360/utility_belt/util/DynamicTags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...rc/main/java/io/github/jamalam360/utility_belt/fabric/compat/LambDynamicLightsCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
} | ||
} | ||
|
||
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LambDynLights
should be considered internal and thus unstable.The
ItemLightSourceManager
provides you the same method but in a stable supported way.