From 5f147d6adbe9898239a0cb86e4daaa74c9e4c08a Mon Sep 17 00:00:00 2001 From: Vixid <52578495+VixidDev@users.noreply.github.com> Date: Sat, 11 Mar 2023 23:51:41 +0000 Subject: Dynamic Light Items (#646) Co-authored-by: Vixid <52578495+Vixid1@users.noreply.github.com> --- .../envcheck/NEUMixinConfigPlugin.java | 4 +++ .../mixins/MixinOFDynamicLights.java | 40 ++++++++++++++++++++++ .../notenoughupdates/options/NEUConfig.java | 4 +++ 3 files changed, 48 insertions(+) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinOFDynamicLights.java (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java index 44e24ff4..1d12813c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java @@ -1,5 +1,6 @@ package io.github.moulberry.notenoughupdates.envcheck; +import io.github.moulberry.notenoughupdates.miscgui.DynamicLightItemsEditor; import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; @@ -42,5 +43,8 @@ public class NEUMixinConfigPlugin implements IMixinConfigPlugin { @Override public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + if ("io.github.moulberry.notenoughupdates.mixins.MixinOFDynamicLights".equals(mixinClassName)) { + DynamicLightItemsEditor.setDidApplyMixin(true); + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinOFDynamicLights.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinOFDynamicLights.java new file mode 100644 index 00000000..68f75d49 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinOFDynamicLights.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.miscgui.DynamicLightItemsEditor; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Pseudo +@Mixin(targets = "net.optifine.DynamicLights", remap = false) +public class MixinOFDynamicLights { + + @Inject(method = "getLightLevel(Lnet/minecraft/item/ItemStack;)I", at = @At("TAIL"), cancellable = true) + private static void getLightLevel(ItemStack itemStack, CallbackInfoReturnable cir) { + int lightLevel = DynamicLightItemsEditor.findDynamicLightItems(itemStack); + if (lightLevel != 0) cir.setReturnValue(lightLevel); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index e2a483f7..498b3b0d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -82,9 +82,11 @@ import net.minecraftforge.client.ClientCommandHandler; import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; public class NEUConfig extends Config { public void editOverlay() { @@ -471,6 +473,8 @@ public class NEUConfig extends Config { public ArrayList quickCommands = createDefaultQuickCommands(); @Expose public ArrayList enchantColours = createDefaultEnchantColours(); + @Expose + public Set dynamicLightItems = new HashSet<>(); @Expose public boolean firstTimeSearchFocus = true; -- cgit