Skip to content

Commit

Permalink
LambDynamicLights v1.3.0: Update to Minecraft 1.16.2 and fixed stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Aug 14, 2020
1 parent c5df018 commit 273fd2a
Show file tree
Hide file tree
Showing 51 changed files with 484 additions and 166 deletions.
59 changes: 56 additions & 3 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,61 @@ registerDynamicLightHandler(EntityType.ITEM_FRAME, entity -> {
- `DynamicLightHandler#makeCreeperEntityHandler` will optionally merge the given handler with a basic handler for creepers. May be useful for Creepers mod.
- `LambDynLights#getLuminanceFromItemStack` will return the luminance value of the given item stack.

## `#lambdynlights:water_sensitive` tag
## Item light sources

This is an item tag which lists water-sensitive light-emitting items.
By default every items will emit the same amount of light as their assigned block if possible.

Every items listed in this tag will not emit light in water. This tag mays be useful for server owners to keep control of this feature.
But for items that are not assigned to a block, or for items that should not lit up underwater, there's JSON files to write!

The JSONs are located in `<modid>:dynamiclights/item/<file>.json`.

### JSON item light source

The format is simple:

- `item` - The identifier of the affected item.
- `luminance` - Either a number between `0` and `15` and corresponds to the luminance value,
or is a string with either a block identifier to get the luminance from
or `"block"` to use the default assigned block luminance value.
- `water_sensitive` *(Optional)* - `true` if the item doesn't emit light when submerged in water, else `false`.

#### Examples

##### `lambdynlights:dynamiclights/item/fire_charge.json`

```json
{
"item": "minecraft:fire_charge",
"luminance": 10,
"water_sensitive": true
}
```

##### `lambdynlights:dynamiclights/item/lava_bucket.json`

```json
{
"item": "minecraft:lava_bucket",
"luminance": "minecraft:lava",
"water_sensitive": true
}
```

##### `lambdynlights:dynamiclights/item/nether_star.json`

```json
{
"item": "minecraft:nether_star",
"luminance": 8
}
```

##### `lambdynlights:dynamiclights/item/torch.json`

```json
{
"item": "minecraft:torch",
"luminance": "block",
"water_sensitive": true
}
```
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
- Changed video options dynamic lighting button to redirect to LambDynamicLights settings.
- Fixed random crash.

### v1.2.3
## v1.3.0

- Added Simplified Chinese translations.
- Added German translations.
- Added Russian translations ([#9](https://github.com/LambdAurora/LambDynamicLights/pull/9)).
- Updated [SpruceUI](https://github.com/LambdAurora/SpruceUI) to v1.5.11.
- Updated to Minecraft 1.16.2
- Updated [SpruceUI](https://github.com/LambdAurora/SpruceUI) to v1.6.1.
- Fixed dynamic lighting update issues at chunk borders ([#12](https://github.com/LambdAurora/LambDynamicLights/issues/12)).
- Fixed water-sensitive items lighting up in water on dedicated servers. ([#3](https://github.com/LambdAurora/LambDynamicLights/issues/3))
- Added new configuration entry `light_sources.water_sensitive`.
- Keep `#lambdynlights:water_sensitive` item tag for servers.
- Added new JSON API to add item luminance and water-sensitivity through resource packs.
- Added `DynamicLightHandler#isWaterSensitive` to make some entities water-sensitive like the blaze.
- Fixed incompatibility with latest Sodium development versions. ([#6](https://github.com/LambdAurora/LambDynamicLights/issues/6))
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ Just do `./gradlew shadowRemapJar` and everything should build just fine!
You can configure the mod by editing the file in `config/lambdynlights.toml`.
You also can use the configuration GUI of the mod, which is more recommended to avoid crashes.

The only thing that has to be configured in the configuration file is the list of items being water-sensitive. Everything else is available in the GUI.

## How does it work internally?

Check [this documentation](https://github.com/LambdAurora/LambDynamicLights/blob/mc1.16/HOW_DOES_IT_WORK.md).
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ configurations {

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
Expand All @@ -56,12 +56,12 @@ dependencies {

modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"
//modImplementation "grondag:canvas-mc116:1.0.+"
modImplementation "com.github.jellysquid3:sodium-fabric:1.16.x~dev-SNAPSHOT"
//modImplementation "me.jellysquid.mods:sodium:0.1.0+v8-SNAPSHOT"

shadow "com.electronwill.night-config:core:3.6.3"
shadow "com.electronwill.night-config:toml:3.6.3"

shadow("org.aperlambda:lambdajcommon:1.8.0") {
shadow("org.aperlambda:lambdajcommon:1.8.1") {
// Minecraft already has all that google crap.
exclude group: 'com.google.code.gson'
exclude group: 'com.google.guava'
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.1
yarn_mappings=1.16.1+build.19:v2
loader_version=0.8.9+build.203
minecraft_version=1.16.2
yarn_mappings=1.16.2+build.6
loader_version=0.9.1+build.205

# Mod Properties
mod_version = 1.2.3
mod_version = 1.3.0
maven_group = me.lambdaurora
archives_base_name = lambdynamiclights

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.15.0+build.379-1.16.1
spruceui_version=1.5.11
modmenu_version=1.14.5+build.30
fabric_version=0.17.2+build.396-1.16
spruceui_version=1.6.1
modmenu_version=1.14.6+build.31
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icon_400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Represents the mod configuration.
*
* @author LambdAurora
* @version 1.2.3
* @version 1.3.0
* @since 1.0.0
*/
public class DynamicLightsConfig
Expand All @@ -39,15 +39,6 @@ public class DynamicLightsConfig
private static final boolean DEFAULT_WATER_SENSITIVE_CHECK = true;
private static final ExplosiveLightingMode DEFAULT_CREEPER_LIGHTING_MODE = ExplosiveLightingMode.SIMPLE;
private static final ExplosiveLightingMode DEFAULT_TNT_LIGHTING_MODE = ExplosiveLightingMode.OFF;
private static final List<String> DEFAULT_WATER_SENSITIVE_ITEMS = Arrays.asList(
"minecraft:campfire",
"minecraft:fire_charge",
"minecraft:lava_bucket",
"minecraft:redstone_torch",
"minecraft:soul_campfire",
"minecraft:soul_torch",
"minecraft:torch"
);

public static final Path CONFIG_FILE_PATH = Paths.get("config/lambdynlights.toml");
protected final FileConfig config;
Expand All @@ -56,7 +47,6 @@ public class DynamicLightsConfig
private DynamicLightsMode dynamicLightsMode;
private ExplosiveLightingMode creeperLightingMode;
private ExplosiveLightingMode tntLightingMode;
private List<Identifier> waterSensitiveItems;

public final Option dynamicLightsModeOption = new SpruceCyclingOption("lambdynlights.option.mode",
amount -> this.setDynamicLightsMode(this.dynamicLightsMode.next()),
Expand Down Expand Up @@ -91,9 +81,6 @@ public void load()
this.tntLightingMode = ExplosiveLightingMode.byId(this.config.getOrElse("light_sources.tnt", DEFAULT_TNT_LIGHTING_MODE.getName()))
.orElse(DEFAULT_TNT_LIGHTING_MODE);

waterSensitiveItems = this.config.getOrElse("light_sources.water_sensitive", DEFAULT_WATER_SENSITIVE_ITEMS)
.stream().map(Identifier::new).collect(Collectors.toList());

if (dynamicLightsModeValue.equalsIgnoreCase("none")) {
this.firstTime = true;
}
Expand Down Expand Up @@ -270,14 +257,4 @@ public void setTntLightingMode(@NotNull ExplosiveLightingMode lightingMode)
this.mod.removeTntLightSources();
this.config.set("light_sources.tnt", lightingMode.getName());
}

/**
* Returns the list of water-sensitive items.
*
* @return The list of water-sensitive items.
*/
public @NotNull List<Identifier> getWaterSensitiveItems()
{
return this.waterSensitiveItems;
}
}
78 changes: 40 additions & 38 deletions src/main/java/me/lambdaurora/lambdynlights/LambDynLights.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import me.lambdaurora.lambdynlights.accessor.WorldRendererAccessor;
import me.lambdaurora.lambdynlights.api.DynamicLightHandlers;
import me.lambdaurora.lambdynlights.api.item.ItemLightSources;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.tag.TagRegistry;
import net.minecraft.block.Blocks;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.LightmapTextureManager;
Expand All @@ -25,18 +26,15 @@
import net.minecraft.entity.TntEntity;
import net.minecraft.entity.mob.CreeperEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tag.Tag;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.Registry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
Expand All @@ -50,19 +48,19 @@
* Represents the LambDynamicLights mod.
*
* @author LambdAurora
* @version 1.2.3
* @version 1.3.0
* @since 1.0.0
*/
public class LambDynLights implements ClientModInitializer
{
public static final Tag<Item> WATER_SENSITIVE_ITEMS = TagRegistry.item(new Identifier("lambdynlights", "water_sensitive"));
private static final double MAX_RADIUS = 7.75;
public static final String MODID = "lambdynlights";
private static final double MAX_RADIUS = 7.75;
private static LambDynLights INSTANCE;
public final Logger logger = LogManager.getLogger("lambdynlights");
public final DynamicLightsConfig config = new DynamicLightsConfig(this);
private final ConcurrentLinkedQueue<DynamicLightSource> dynamicLightSources = new ConcurrentLinkedQueue<>();
private long lastUpdate = System.currentTimeMillis();
private boolean notifiedFirstTime = false;
public final Logger logger = LogManager.getLogger(MODID);
public final DynamicLightsConfig config = new DynamicLightsConfig(this);
private final ConcurrentLinkedQueue<DynamicLightSource> dynamicLightSources = new ConcurrentLinkedQueue<>();
private long lastUpdate = System.currentTimeMillis();
private boolean notifiedFirstTime = false;

@Override
public void onInitializeClient()
Expand All @@ -77,13 +75,28 @@ public void onInitializeClient()
this.notifiedFirstTime = true;

MinecraftClient client = MinecraftClient.getInstance();
client.getToastManager().add(SystemToast.method_29047(client,
client.getToastManager().add(SystemToast.create(client,
SystemToast.Type.TUTORIAL_HINT,
new LiteralText("LambDynamicLights").formatted(Formatting.GOLD),
new TranslatableText("lambdynlights.toast.first_time")));
}
});

ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener()
{
@Override
public Identifier getFabricId()
{
return new Identifier(MODID, "dynamiclights_resources");
}

@Override
public void apply(ResourceManager manager)
{
ItemLightSources.load(manager);
}
});

DynamicLightHandlers.registerDefaultHandlers();
}

Expand Down Expand Up @@ -344,6 +357,16 @@ public void log(String info)
this.logger.info("[LambDynLights] " + info);
}

/**
* Prints a warning message to the terminal.
*
* @param info The message to print.
*/
public void warn(String info)
{
this.logger.warn("[LambDynLights] " + info);
}

/**
* Schedules a chunk rebuild at the specified chunk position.
*
Expand Down Expand Up @@ -396,28 +419,7 @@ public static void updateTracking(@NotNull DynamicLightSource lightSource)
*/
public static int getLuminanceFromItemStack(@NotNull ItemStack stack, boolean submergedInWater)
{
Identifier itemId = Registry.ITEM.getId(stack.getItem());
if (INSTANCE.config.hasWaterSensitiveCheck() && submergedInWater &&
// The water-sensitive items list can be partially override by the server with the tag.
(INSTANCE.config.getWaterSensitiveItems().contains(itemId) || WATER_SENSITIVE_ITEMS.contains(stack.getItem()))) {
return 0; // Don't emit light with water sensitive items while submerged in water.
}

if (stack.getItem() instanceof BlockItem) {
return ((BlockItem) stack.getItem()).getBlock().getDefaultState().getLuminance();
} else if (stack.getItem() == Items.LAVA_BUCKET) {
return Blocks.LAVA.getDefaultState().getLuminance();
} else if (stack.getItem() == Items.BLAZE_ROD
|| stack.getItem() == Items.BLAZE_POWDER
|| stack.getItem() == Items.FIRE_CHARGE) {
return 10;
} else if (stack.getItem() == Items.GLOWSTONE_DUST
|| stack.getItem() == Items.PRISMARINE_CRYSTALS) {
return 8;
} else if (stack.getItem() == Items.NETHER_STAR) {
return Blocks.BEACON.getDefaultState().getLuminance() / 2;
}
return 0;
return ItemLightSources.getLuminance(stack, submergedInWater);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Represents a utility class for compatibility.
*
* @author LambdAurora
* @version 1.1.0
* @version 1.3.0
* @since 1.0.0
*/
public final class LambDynLightsCompat
Expand Down Expand Up @@ -50,15 +50,4 @@ public static boolean isSodiumInstalled()
{
return FabricLoader.getInstance().isModLoaded("sodium");
}

/**
* Returns whether Sodium 0.1.0 is installed.
*
* @return True if Sodium 0.1.0 is installed, else false.
*/
public static boolean isSodium010Installed()
{
return FabricLoader.getInstance().getModContainer("sodium").map(mod -> mod.getMetadata().getVersion().getFriendlyString().equalsIgnoreCase("0.1.0"))
.orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* LambDynamicLights mixin plugin for conditional mixins.
*
* @author LambdAurora
* @version 1.2.0
* @version 1.3.0
* @since 1.0.0
*/
public class LambDynLightsMixinPlugin implements IMixinConfigPlugin
Expand All @@ -36,7 +36,6 @@ public LambDynLightsMixinPlugin()

boolean canvasInstalled = LambDynLightsCompat.isCanvasInstalled();
boolean sodiumInstalled = LambDynLightsCompat.isSodiumInstalled();
this.conditionalMixins.put("me.lambdaurora.lambdynlights.mixin.EntityLighterMixin", LambDynLightsCompat.isSodium010Installed());
this.conditionalMixins.put("me.lambdaurora.lambdynlights.mixin.WorldRendererMixin", !sodiumInstalled && !canvasInstalled);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @param <T> The type of the light source.
* @author LambdAurora
* @version 1.2.3
* @version 1.3.0
* @since 1.1.0
*/
public interface DynamicLightHandler<T>
Expand Down
Loading

0 comments on commit 273fd2a

Please sign in to comment.