From 18284ed84e3a216a4cf8792f006ae73ad6c77fa6 Mon Sep 17 00:00:00 2001 From: LambdAurora Date: Mon, 2 Aug 2021 00:37:20 +0200 Subject: [PATCH] LambDynamicLights 2.0.2. Fix #63, fix #70, fix #71, fix #72, fix #75, fix #76. --- .github/workflows/gradlepublish.yml | 10 +- .github/workflows/modrinth_update.yml | 2 +- CHANGELOG.md | 10 ++ build.gradle | 19 +-- gradle.properties | 12 +- settings.gradle | 12 +- .../api/DynamicLightHandlers.java | 11 +- .../api/item/ItemLightSource.java | 139 ++++++++++++++---- .../api/item/ItemLightSources.java | 14 +- .../gui/DynamicLightsOptionsOption.java | 2 +- .../lambdynlights/gui/SettingsScreen.java | 2 +- .../AbstractMinecartEntityMixin.java | 32 +++- .../mixin/lightsource/BlockEntityMixin.java | 28 ++-- .../mixin/lightsource/EntityMixin.java | 59 ++++---- .../mixin/lightsource/LivingEntityMixin.java | 16 +- .../mixin/lightsource/PlayerEntityMixin.java | 21 +-- .../mixin/lightsource/TntEntityMixin.java | 19 ++- .../dynamiclights/item/glow_berries.json | 4 + .../dynamiclights/item/glow_ink_sac.json | 4 + 19 files changed, 285 insertions(+), 131 deletions(-) create mode 100644 src/main/resources/assets/lambdynlights/dynamiclights/item/glow_berries.json create mode 100644 src/main/resources/assets/lambdynlights/dynamiclights/item/glow_ink_sac.json diff --git a/.github/workflows/gradlepublish.yml b/.github/workflows/gradlepublish.yml index 55d75dd3..e7902491 100755 --- a/.github/workflows/gradlepublish.yml +++ b/.github/workflows/gradlepublish.yml @@ -6,7 +6,7 @@ on: - '*' jobs: - build: + publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -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 diff --git a/.github/workflows/modrinth_update.yml b/.github/workflows/modrinth_update.yml index c4ca2d9b..56168bdd 100755 --- a/.github/workflows/modrinth_update.yml +++ b/.github/workflows/modrinth_update.yml @@ -1,4 +1,4 @@ -name: Gradle Build +name: Modrinth Publish on: release: diff --git a/CHANGELOG.md b/CHANGELOG.md index f7f64a59..486c545c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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" diff --git a/build.gradle b/build.gradle index 75517571..8dc1a654 100644 --- a/build.gradle +++ b/build.gradle @@ -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' @@ -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 '' } } } diff --git a/gradle.properties b/gradle.properties index 65c5a776..45154728 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,14 @@ 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 @@ -18,4 +18,4 @@ 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 diff --git a/settings.gradle b/settings.gradle index fcedb126..5dddeec3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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() } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/api/DynamicLightHandlers.java b/src/main/java/dev/lambdaurora/lambdynlights/api/DynamicLightHandlers.java index eda91ae0..3a2da79f 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/api/DynamicLightHandlers.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/api/DynamicLightHandlers.java @@ -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; @@ -23,7 +24,7 @@ /** * @author LambdAurora - * @version 1.3.2 + * @version 2.0.2 * @since 1.1.0 */ public final class DynamicLightHandlers { @@ -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) + ); } /** diff --git a/src/main/java/dev/lambdaurora/lambdynlights/api/item/ItemLightSource.java b/src/main/java/dev/lambdaurora/lambdynlights/api/item/ItemLightSource.java index c62728a7..a02fb9d1 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/api/item/ItemLightSource.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/api/item/ItemLightSource.java @@ -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; @@ -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() + '}'; } @@ -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 > BlockState with(BlockState state, Property property, String name) { + return property.parse(name).map(value -> state.with(property, value)).orElse(state); + } } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/api/item/ItemLightSources.java b/src/main/java/dev/lambdaurora/lambdynlights/api/item/ItemLightSources.java index 6f8a364d..b540ee68 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/api/item/ItemLightSources.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/api/item/ItemLightSources.java @@ -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 { @@ -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) { @@ -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) { @@ -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; } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/gui/DynamicLightsOptionsOption.java b/src/main/java/dev/lambdaurora/lambdynlights/gui/DynamicLightsOptionsOption.java index 42bb78b8..642c6495 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/gui/DynamicLightsOptionsOption.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/gui/DynamicLightsOptionsOption.java @@ -32,6 +32,6 @@ public DynamicLightsOptionsOption(Screen parent) { @Override public ClickableWidget createButton(GameOptions options, int x, int y, int width) { - return new ButtonWidget(x, y, width, 20, this.text, btn -> MinecraftClient.getInstance().openScreen(new SettingsScreen(this.parent))); + return new ButtonWidget(x, y, width, 20, this.text, btn -> MinecraftClient.getInstance().setScreen(new SettingsScreen(this.parent))); } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/gui/SettingsScreen.java b/src/main/java/dev/lambdaurora/lambdynlights/gui/SettingsScreen.java index 63f084c9..e9c63f43 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/gui/SettingsScreen.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/gui/SettingsScreen.java @@ -106,7 +106,7 @@ protected void init() { this.addDrawableChild(this.resetOption.createWidget(Position.of(this, this.width / 2 - 155, this.height - 29), 150)); this.addDrawableChild(new SpruceButtonWidget(Position.of(this, this.width / 2 - 155 + 160, this.height - 29), 150, 20, SpruceTexts.GUI_DONE, - (btn) -> this.client.openScreen(this.parent))); + btn -> this.client.setScreen(this.parent))); } @Override diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/AbstractMinecartEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/AbstractMinecartEntityMixin.java index c21710bf..e719bf7a 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/AbstractMinecartEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/AbstractMinecartEntityMixin.java @@ -11,11 +11,15 @@ import dev.lambdaurora.lambdynlights.DynamicLightSource; import dev.lambdaurora.lambdynlights.LambDynLights; +import dev.lambdaurora.lambdynlights.api.DynamicLightHandlers; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.vehicle.AbstractMinecartEntity; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -24,19 +28,25 @@ * Adds the tick method for dynamic light source tracking in minecart entities. * * @author LambdAurora - * @version 1.3.2 + * @version 2.0.2 * @since 1.3.2 */ @Mixin(AbstractMinecartEntity.class) public abstract class AbstractMinecartEntityMixin extends Entity implements DynamicLightSource { + @Shadow + public abstract BlockState getContainedBlock(); + + @Unique + private int luminance; + public AbstractMinecartEntityMixin(EntityType type, World world) { super(type, world); } - @Inject(method = "tick", at = @At("TAIL")) + @Inject(method = "tick", at = @At("HEAD")) private void onTick(CallbackInfo ci) { // We do not want to update the entity on the server. - if (this.getEntityWorld().isClient()) { + if (this.world.isClient()) { if (this.isRemoved()) { this.setDynamicLightEnabled(false); } else { @@ -45,4 +55,20 @@ private void onTick(CallbackInfo ci) { } } } + + @Override + public void dynamicLightTick() { + this.luminance = Math.max( + Math.max( + this.isOnFire() ? 15 : 0, + this.getContainedBlock().getLuminance() + ), + DynamicLightHandlers.getLuminanceFrom(this) + ); + } + + @Override + public int getLuminance() { + return this.luminance; + } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/BlockEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/BlockEntityMixin.java index 0145ccab..23d73124 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/BlockEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/BlockEntityMixin.java @@ -24,6 +24,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -42,9 +43,14 @@ public abstract class BlockEntityMixin implements DynamicLightSource { @Shadow protected boolean removed; - private int lambdynlights_luminance = 0; - private int lambdynlights_lastLuminance = 0; - private long lambdynlights_lastUpdate = 0; + + @Unique + private int luminance = 0; + @Unique + private int lastLuminance = 0; + @Unique + private long lastUpdate = 0; + @Unique private LongOpenHashSet trackedLitChunkPos = new LongOpenHashSet(); @Override @@ -74,7 +80,7 @@ private void onRemoved(CallbackInfo ci) { @Override public void resetDynamicLight() { - this.lambdynlights_lastLuminance = 0; + this.lastLuminance = 0; } @Override @@ -83,18 +89,18 @@ public void dynamicLightTick() { if (this.world == null || !this.world.isClient()) return; if (!this.removed) { - this.lambdynlights_luminance = DynamicLightHandlers.getLuminanceFrom((BlockEntity) (Object) this); + this.luminance = DynamicLightHandlers.getLuminanceFrom((BlockEntity) (Object) this); LambDynLights.updateTracking(this); if (!this.isDynamicLightEnabled()) { - this.lambdynlights_lastLuminance = 0; + this.lastLuminance = 0; } } } @Override public int getLuminance() { - return this.lambdynlights_luminance; + return this.luminance; } @Override @@ -104,11 +110,11 @@ public boolean shouldUpdateDynamicLight() { return false; if (mode.hasDelay()) { long currentTime = System.currentTimeMillis(); - if (currentTime < this.lambdynlights_lastUpdate + mode.getDelay()) { + if (currentTime < this.lastUpdate + mode.getDelay()) { return false; } - this.lambdynlights_lastUpdate = currentTime; + this.lastUpdate = currentTime; } return true; } @@ -120,8 +126,8 @@ public boolean shouldUpdateDynamicLight() { int luminance = this.getLuminance(); - if (luminance != this.lambdynlights_lastLuminance) { - this.lambdynlights_lastLuminance = luminance; + if (luminance != this.lastLuminance) { + this.lastLuminance = luminance; if (this.trackedLitChunkPos.isEmpty()) { var chunkPos = new BlockPos.Mutable(MathHelper.floorDiv(this.pos.getX(), 16), diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/EntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/EntityMixin.java index 2f6258c4..e7bbf66c 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/EntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/EntityMixin.java @@ -17,14 +17,12 @@ import net.minecraft.client.render.WorldRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.*; import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -61,12 +59,19 @@ public abstract class EntityMixin implements DynamicLightSource { @Shadow public abstract ChunkPos getChunkPos(); - private int lambdynlights$luminance = 0; - private int lambdynlights$lastLuminance = 0; - private long lambdynlights$lastUpdate = 0; - private double lambdynlights$prevX; - private double lambdynlights$prevY; - private double lambdynlights$prevZ; + @Unique + private int luminance = 0; + @Unique + private int lastLuminance = 0; + @Unique + private long lastUpdate = 0; + @Unique + private double prevX; + @Unique + private double prevY; + @Unique + private double prevZ; + @Unique private LongOpenHashSet trackedLitChunkPos = new LongOpenHashSet(); @Inject(method = "tick", at = @At("TAIL")) @@ -78,7 +83,7 @@ public void onTick(CallbackInfo ci) { } else { this.dynamicLightTick(); if (!LambDynLights.get().config.hasEntitiesLightSource() && this.getType() != EntityType.PLAYER) - this.lambdynlights$luminance = 0; + this.luminance = 0; LambDynLights.updateTracking(this); } } @@ -112,7 +117,7 @@ public World getDynamicLightWorld() { @Override public void resetDynamicLight() { - this.lambdynlights$lastLuminance = 0; + this.lastLuminance = 0; } @Override @@ -122,50 +127,50 @@ public boolean shouldUpdateDynamicLight() { return false; if (mode.hasDelay()) { long currentTime = System.currentTimeMillis(); - if (currentTime < this.lambdynlights$lastUpdate + mode.getDelay()) { + if (currentTime < this.lastUpdate + mode.getDelay()) { return false; } - this.lambdynlights$lastUpdate = currentTime; + this.lastUpdate = currentTime; } return true; } @Override public void dynamicLightTick() { - this.lambdynlights$luminance = this.isOnFire() ? 15 : 0; + this.luminance = this.isOnFire() ? 15 : 0; int luminance = DynamicLightHandlers.getLuminanceFrom((Entity) (Object) this); - if (luminance > this.lambdynlights$luminance) - this.lambdynlights$luminance = luminance; + if (luminance > this.luminance) + this.luminance = luminance; } @Override public int getLuminance() { - return this.lambdynlights$luminance; + return this.luminance; } @Override public boolean lambdynlights$updateDynamicLight(@NotNull WorldRenderer renderer) { if (!this.shouldUpdateDynamicLight()) return false; - double deltaX = this.getX() - this.lambdynlights$prevX; - double deltaY = this.getY() - this.lambdynlights$prevY; - double deltaZ = this.getZ() - this.lambdynlights$prevZ; + double deltaX = this.getX() - this.prevX; + double deltaY = this.getY() - this.prevY; + double deltaZ = this.getZ() - this.prevZ; int luminance = this.getLuminance(); - if (Math.abs(deltaX) > 0.1D || Math.abs(deltaY) > 0.1D || Math.abs(deltaZ) > 0.1D || luminance != this.lambdynlights$lastLuminance) { - this.lambdynlights$prevX = this.getX(); - this.lambdynlights$prevY = this.getY(); - this.lambdynlights$prevZ = this.getZ(); - this.lambdynlights$lastLuminance = luminance; + if (Math.abs(deltaX) > 0.1D || Math.abs(deltaY) > 0.1D || Math.abs(deltaZ) > 0.1D || luminance != this.lastLuminance) { + this.prevX = this.getX(); + this.prevY = this.getY(); + this.prevZ = this.getZ(); + this.lastLuminance = luminance; var newPos = new LongOpenHashSet(); if (luminance > 0) { var entityChunkPos = this.getChunkPos(); - var chunkPos = new BlockPos.Mutable(entityChunkPos.x, MathHelper.floorDiv((int) this.getEyeY(), 16), entityChunkPos.z); + var chunkPos = new BlockPos.Mutable(entityChunkPos.x, ChunkSectionPos.getSectionCoord(this.getEyeY()), entityChunkPos.z); LambDynLights.scheduleChunkRebuild(renderer, chunkPos); LambDynLights.updateTrackedChunks(chunkPos, this.trackedLitChunkPos, newPos); diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/LivingEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/LivingEntityMixin.java index 315e668a..4252d531 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/LivingEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/LivingEntityMixin.java @@ -18,10 +18,12 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; @Mixin(LivingEntity.class) public abstract class LivingEntityMixin extends Entity implements DynamicLightSource { - private int lambdynlights$luminance; + @Unique + private int luminance; public LivingEntityMixin(EntityType type, World world) { super(type, world); @@ -30,7 +32,7 @@ public LivingEntityMixin(EntityType type, World world) { @Override public void dynamicLightTick() { if (this.isOnFire() || this.isGlowing()) { - this.lambdynlights$luminance = 15; + this.luminance = 15; } else { int luminance = 0; var eyePos = new BlockPos(this.getX(), this.getEyeY(), this.getZ()); @@ -40,19 +42,19 @@ public void dynamicLightTick() { luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped, submergedInFluid)); } - this.lambdynlights$luminance = luminance; + this.luminance = luminance; } int luminance = DynamicLightHandlers.getLuminanceFrom(this); - if (luminance > this.lambdynlights$luminance) - this.lambdynlights$luminance = luminance; + if (luminance > this.luminance) + this.luminance = luminance; if (!LambDynLights.get().config.hasEntitiesLightSource() && this.getType() != EntityType.PLAYER) - this.lambdynlights$luminance = 0; + this.luminance = 0; } @Override public int getLuminance() { - return this.lambdynlights$luminance; + return this.luminance; } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/PlayerEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/PlayerEntityMixin.java index 08e9ce2c..262996d5 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/PlayerEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/PlayerEntityMixin.java @@ -18,14 +18,17 @@ import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; @Mixin(PlayerEntity.class) public abstract class PlayerEntityMixin extends LivingEntity implements DynamicLightSource { @Shadow public abstract boolean isSpectator(); - private int lambdynlights$luminance; - private World lambdynlights$lastWorld; + @Unique + private int luminance; + @Unique + private World lastWorld; protected PlayerEntityMixin(EntityType entityType, World world) { super(entityType, world); @@ -34,7 +37,7 @@ protected PlayerEntityMixin(EntityType entityType, World @Override public void dynamicLightTick() { if (this.isOnFire() || this.isGlowing()) { - this.lambdynlights$luminance = 15; + this.luminance = 15; } else { int luminance = 0; var eyePos = new BlockPos(this.getX(), this.getEyeY(), this.getZ()); @@ -44,20 +47,20 @@ public void dynamicLightTick() { luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped, submergedInFluid)); } - this.lambdynlights$luminance = luminance; + this.luminance = luminance; } if (this.isSpectator()) - this.lambdynlights$luminance = 0; + this.luminance = 0; - if (this.lambdynlights$lastWorld != this.getEntityWorld()) { - this.lambdynlights$lastWorld = this.getEntityWorld(); - this.lambdynlights$luminance = 0; + if (this.lastWorld != this.getEntityWorld()) { + this.lastWorld = this.getEntityWorld(); + this.luminance = 0; } } @Override public int getLuminance() { - return this.lambdynlights$luminance; + return this.luminance; } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/TntEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/TntEntityMixin.java index 3e2098ad..9d93c889 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/TntEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/TntEntityMixin.java @@ -18,6 +18,7 @@ import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -27,8 +28,10 @@ public abstract class TntEntityMixin extends Entity implements DynamicLightSourc @Shadow public abstract int getFuse(); - private int lambdynlights$startFuseTimer = 80; - private int lambdynlights$luminance; + @Unique + private int startFuseTimer = 80; + @Unique + private int luminance; public TntEntityMixin(EntityType type, World world) { super(type, world); @@ -36,7 +39,7 @@ public TntEntityMixin(EntityType type, World world) { @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("TAIL")) private void onNew(EntityType entityType, World world, CallbackInfo ci) { - this.lambdynlights$startFuseTimer = this.getFuse(); + this.startFuseTimer = this.getFuse(); } @Inject(method = "tick", at = @At("TAIL")) @@ -58,20 +61,20 @@ private void onTick(CallbackInfo ci) { @Override public void dynamicLightTick() { if (this.isOnFire()) { - this.lambdynlights$luminance = 15; + this.luminance = 15; } else { ExplosiveLightingMode lightingMode = LambDynLights.get().config.getTntLightingMode(); if (lightingMode == ExplosiveLightingMode.FANCY) { - var fuse = this.getFuse() / this.lambdynlights$startFuseTimer; - this.lambdynlights$luminance = (int) (-(fuse * fuse) * 10.0) + 10; + var fuse = this.getFuse() / this.startFuseTimer; + this.luminance = (int) (-(fuse * fuse) * 10.0) + 10; } else { - this.lambdynlights$luminance = 10; + this.luminance = 10; } } } @Override public int getLuminance() { - return this.lambdynlights$luminance; + return this.luminance; } } diff --git a/src/main/resources/assets/lambdynlights/dynamiclights/item/glow_berries.json b/src/main/resources/assets/lambdynlights/dynamiclights/item/glow_berries.json new file mode 100644 index 00000000..ad984b41 --- /dev/null +++ b/src/main/resources/assets/lambdynlights/dynamiclights/item/glow_berries.json @@ -0,0 +1,4 @@ +{ + "item": "minecraft:glow_berries", + "luminance": 14 +} diff --git a/src/main/resources/assets/lambdynlights/dynamiclights/item/glow_ink_sac.json b/src/main/resources/assets/lambdynlights/dynamiclights/item/glow_ink_sac.json new file mode 100644 index 00000000..ec5bf7fc --- /dev/null +++ b/src/main/resources/assets/lambdynlights/dynamiclights/item/glow_ink_sac.json @@ -0,0 +1,4 @@ +{ + "item": "minecraft:glow_ink_sac", + "luminance": 12 +}