Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
LambDynamicLights 2.0.2. Fix LambdAurora#63, fix LambdAurora#70, fix L…
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Aug 1, 2021
1 parent bf36d6e commit 18284ed
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 131 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/gradlepublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '*'

jobs:
build:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -17,14 +17,6 @@ jobs:
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build with Gradle
run: ./gradlew build

- uses: actions/upload-artifact@v2
with:
name: Artifacts
path: ./build/libs/

# The USERNAME and PASSWORD need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
- name: Publish to GitHub Packages and other Mavens
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/modrinth_update.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Gradle Build
name: Modrinth Publish

on:
release:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@
- Removed any usage of a library.
- Updated [SpruceUI].

### 2.0.2

- Added Swedish translations ([#68](https://github.com/LambdAurora/LambDynamicLights/pull/68)).
- Block items now respect the `BlockStateTag` in item's NBT ([#71](https://github.com/LambdAurora/LambDynamicLights/issues/71)).
- Fixed glow item frames not emitting light ([#63](https://github.com/LambdAurora/LambDynamicLights/issues/63)).
- Fixed minecart not emitting light when holding a light source ([#70](https://github.com/LambdAurora/LambDynamicLights/issues/70)).
- Fixed glow berries not emitting light ([#72](https://github.com/LambdAurora/LambDynamicLights/issues/72)).
- Fixed glow squids not dimming when attacked ([#75](https://github.com/LambdAurora/LambDynamicLights/issues/75)).
- Fixed LambDynamicLights not rebuilding the correct chunks when at Y -18 or Y -50 ([#76](https://github.com/LambdAurora/LambDynamicLights/issues/76)).

[SpruceUI]: https://github.com/LambdAurora/SpruceUI "SpruceUI page"
[Sodium]: https://modrinth.com/mod/sodium "Sodium Modrinth page"
[Canvas Renderer]: https://www.curseforge.com/minecraft/mc-mods/canvas-renderer "Canvas Renderer CurseForge page"
19 changes: 10 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'fabric-loom' version '0.9.+'
id 'fabric-loom' version '0.9.25'
id 'io.github.juuxel.loom-quiltflower' version '1.1.1'
id 'java-library'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.0.0'
Expand Down Expand Up @@ -58,23 +59,23 @@ repositories {
mavenLocal()
mavenCentral()
maven {
name = 'Terraformers'
url = 'https://maven.terraformersmc.com/releases/'
name 'Terraformers'
url 'https://maven.terraformersmc.com/releases/'
}
maven {
name = 'AperLambda'
url = 'https://aperlambda.github.io/maven'
name 'AperLambda'
url 'https://aperlambda.github.io/maven'
}
maven {
name 'Gegy'
url 'https://maven.gegy.dev'
}
maven {
name = "grondag"
url = "https://grondag-repo.appspot.com"
name 'grondag'
url 'https://grondag-repo.appspot.com'
credentials {
username "guest"
password ""
username 'guest'
password ''
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.17
yarn_mappings=1
loader_version=0.11.3
minecraft_version=1.17.1
yarn_mappings=31
loader_version=0.11.6
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_api_version=0.34.9+1.17
fabric_api_version=0.37.1+1.17

# Mod Properties
mod_version = 2.0.1
mod_version = 2.0.2
maven_group = dev.lambdaurora
archives_base_name = lambdynamiclights
modrinth_id=yBW8D80W

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
spruceui_version=3.2.0+1.17
modmenu_version=2.0.0-beta.7
modmenu_version=2.0.4
12 changes: 10 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
name 'Quilt'
url 'https://maven.quiltmc.org/repository/release'
}
maven {
name 'Fabric'
url 'https://maven.fabricmc.net/'
}
maven {
name 'Cotton'
url 'https://server.bbkr.space/artifactory/libs-release/'
}
gradlePluginPortal()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -23,7 +24,7 @@

/**
* @author LambdAurora
* @version 1.3.2
* @version 2.0.2
* @since 1.1.0
*/
public final class DynamicLightHandlers {
Expand Down Expand Up @@ -51,9 +52,15 @@ public static void registerDefaultHandlers() {
var world = entity.getEntityWorld();
return LambDynLights.getLuminanceFromItemStack(entity.getHeldItemStack(), !world.getFluidState(entity.getBlockPos()).isEmpty());
});
registerDynamicLightHandler(EntityType.GLOW_ITEM_FRAME, entity -> {
var world = entity.getEntityWorld();
return Math.max(14, LambDynLights.getLuminanceFromItemStack(entity.getHeldItemStack(), !world.getFluidState(entity.getBlockPos()).isEmpty()));
});
registerDynamicLightHandler(EntityType.MAGMA_CUBE, entity -> (entity.stretch > 0.6) ? 11 : 8);
registerDynamicLightHandler(EntityType.SPECTRAL_ARROW, entity -> 8);
registerDynamicLightHandler(EntityType.GLOW_SQUID, entity -> 12);
registerDynamicLightHandler(EntityType.GLOW_SQUID,
entity -> (int) MathHelper.clampedLerp(0.f, 12.f, 1.f - entity.getDarkTicksRemaining() / 10.f)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

import com.google.gson.JsonObject;
import dev.lambdaurora.lambdynlights.LambDynLights;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.state.property.Property;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.NotNull;
Expand All @@ -26,34 +28,64 @@
* Represents an item light source.
*
* @author LambdAurora
* @version 2.0.0
* @version 2.0.2
* @since 1.3.0
*/
public record ItemLightSource(Identifier id, Item item, int luminance, boolean waterSensitive) {
public ItemLightSource(@NotNull Identifier id, @NotNull Item item, int luminance) {
this(id, item, luminance, false);
public abstract class ItemLightSource {
private final Identifier id;
private final Item item;
private final boolean waterSensitive;

public ItemLightSource(Identifier id, Item item, boolean waterSensitive) {
this.id = id;
this.item = item;
this.waterSensitive = waterSensitive;
}

public ItemLightSource(Identifier id, Item item) {
this(id, item, false);
}

public Identifier id() {
return this.id;
}

public Item item() {
return this.item;
}

public boolean waterSensitive() {
return this.waterSensitive;
}

/**
* Gets the luminance of the item.
*
* @param stack The item stack.
* @param submergedInWater True if submerged in water, else false.
* @return The luminance value between 0 and 15.
* @param stack the item stack
* @param submergedInWater {@code true} if submerged in water, else {@code false}.
* @return the luminance value between {@code 0} and {@code 15}
*/
public int getLuminance(@NotNull ItemStack stack, boolean submergedInWater) {
if (this.waterSensitive && LambDynLights.get().config.hasWaterSensitiveCheck() && submergedInWater)
public int getLuminance(ItemStack stack, boolean submergedInWater) {
if (this.waterSensitive() && LambDynLights.get().config.hasWaterSensitiveCheck() && submergedInWater)
return 0; // Don't emit light with water sensitive items while submerged in water.

return this.luminance;
return this.getLuminance(stack);
}

/**
* Gets the luminance of the item.
*
* @param stack the item stack
* @return the luminance value between {@code 0} and {@code 15}
*/
public abstract int getLuminance(ItemStack stack);

@Override
public String toString() {
return "ItemLightSource{" +
"item=" + item +
", luminance=" + luminance +
", water_sensitive=" + waterSensitive +
"id=" + this.id() +
"item=" + this.item() +
", water_sensitive=" + this.waterSensitive() +
'}';
}

Expand All @@ -69,34 +101,85 @@ public String toString() {
if (item == Items.AIR)
return Optional.empty();

int luminance;
boolean waterSensitive = false;
if (json.has("water_sensitive"))
waterSensitive = json.get("water_sensitive").getAsBoolean();

var luminanceElement = json.get("luminance").getAsJsonPrimitive();
if (luminanceElement.isNumber()) {
luminance = luminanceElement.getAsInt();
return Optional.of(new StaticItemLightSource(id, item, luminanceElement.getAsInt(), waterSensitive));
} else if (luminanceElement.isString()) {
var luminanceStr = luminanceElement.getAsString();
if (luminanceStr.equals("block")) {
if (item instanceof BlockItem blockItem) {
luminance = blockItem.getBlock().getDefaultState().getLuminance();
} else {
return Optional.empty();
return Optional.of(new BlockItemLightSource(id, item, blockItem.getBlock().getDefaultState(), waterSensitive));
}
} else {
var block = Registry.BLOCK.get(new Identifier(luminanceStr));
if (block == Blocks.AIR)
return Optional.empty();

luminance = block.getDefaultState().getLuminance();
var blockId = Identifier.tryParse(luminanceStr);
if (blockId != null) {
var block = Registry.BLOCK.get(blockId);
if (block != Blocks.AIR)
return Optional.of(new BlockItemLightSource(id, item, block.getDefaultState(), waterSensitive));
}
}
} else {
LambDynLights.get().warn("Failed to parse item light source \"" + id + "\", invalid format: \"luminance\" field value isn't string or integer.");
return Optional.empty();
}

boolean waterSensitive = false;
if (json.has("water_sensitive"))
waterSensitive = json.get("water_sensitive").getAsBoolean();
return Optional.empty();
}

public static class StaticItemLightSource extends ItemLightSource {
private final int luminance;

public StaticItemLightSource(Identifier id, Item item, int luminance, boolean waterSensitive) {
super(id, item, waterSensitive);
this.luminance = luminance;
}

public StaticItemLightSource(Identifier id, Item item, int luminance) {
super(id, item);
this.luminance = luminance;
}

@Override
public int getLuminance(ItemStack stack) {
return this.luminance;
}
}

return Optional.of(new ItemLightSource(id, item, luminance, waterSensitive));
public static class BlockItemLightSource extends ItemLightSource {
private final BlockState mimic;

public BlockItemLightSource(Identifier id, Item item, BlockState block, boolean waterSensitive) {
super(id, item, waterSensitive);
this.mimic = block;
}

@Override
public int getLuminance(ItemStack stack) {
return getLuminance(stack, this.mimic);
}

static int getLuminance(ItemStack stack, BlockState state) {
var nbt = stack.getNbt();
if (nbt != null) {
var blockStateTag = nbt.getCompound("BlockStateTag");
var stateManager = state.getBlock().getStateManager();

for (var key : blockStateTag.getKeys()) {
var property = stateManager.getProperty(key);
if (property != null) {
var value = blockStateTag.get(key).asString();
state = with(state, property, value);
}
}
}
return state.getLuminance();
}

private static <T extends Comparable<T>> BlockState with(BlockState state, Property<T> property, String name) {
return property.parse(name).map(value -> state.with(property, value)).orElse(state);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Represents an item light sources manager.
*
* @author LambdAurora
* @version 2.0.1
* @version 2.0.2
* @since 1.3.0
*/
public final class ItemLightSources {
Expand Down Expand Up @@ -87,7 +87,7 @@ private static void register(@NotNull ItemLightSource data) {
/**
* Registers an item light source data.
*
* @param data The item light source data.
* @param data the item light source data
*/
public static void registerItemLightSource(@NotNull ItemLightSource data) {
for (var other : STATIC_ITEM_LIGHT_SOURCES) {
Expand All @@ -104,9 +104,9 @@ public static void registerItemLightSource(@NotNull ItemLightSource data) {
/**
* Returns the luminance of the item in the stack.
*
* @param stack The item stack.
* @param submergedInWater True if the stack is submerged in water, else false.
* @return A luminance value.
* @param stack the item stack
* @param submergedInWater {@code true} if the stack is submerged in water, else {@code false}
* @return a luminance value
*/
public static int getLuminance(@NotNull ItemStack stack, boolean submergedInWater) {
for (var data : ITEM_LIGHT_SOURCES) {
Expand All @@ -115,7 +115,7 @@ public static int getLuminance(@NotNull ItemStack stack, boolean submergedInWate
}
}
if (stack.getItem() instanceof BlockItem blockItem)
return blockItem.getBlock().getDefaultState().getLuminance();
return 0;
return ItemLightSource.BlockItemLightSource.getLuminance(stack, blockItem.getBlock().getDefaultState());
else return 0;
}
}
Loading

0 comments on commit 18284ed

Please sign in to comment.