Skip to content

Commit 14b18a1

Browse files
committed
feat: Offhand dynamic lights support
1 parent 468b958 commit 14b18a1

File tree

4 files changed

+95
-4
lines changed

4 files changed

+95
-4
lines changed

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,7 @@ dependencies {
302302
// LittleTiles 1.2.0
303303
compileOnly(deobfCurse("littletiles-257818:2462370"))
304304
// runtimeOnlyNonPublishable(deobfCurse("creativecore-257814:2462369"))
305+
compileOnly(deobfModrinth("backhand:1.4.1"))
306+
compileOnly(deobfCurse("mb-battlegear-2-59710:2286765"))
307+
compileOnly("com.github.GTNewHorizons:Battlegear2:1.4.3:dev")
305308
}

src/main/java/com/falsepattern/falsetweaks/FalseTweaks.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import lombok.val;
2828
import lombok.var;
2929

30+
import net.minecraft.launchwrapper.Launch;
3031
import net.minecraft.util.EnumChatFormatting;
3132
import cpw.mods.fml.common.Loader;
3233
import cpw.mods.fml.common.Mod;
@@ -110,6 +111,12 @@ public void preInit(FMLPreInitializationEvent e) {
110111
"Remove the DynamicLights mod and restart the game!\n" +
111112
"FalseTweaks has built-in dynamic lights support.");
112113
}
114+
try {
115+
if (Launch.classLoader.getClassBytes("cn.tesseract.offhandlights.OffhandLights") != null) {
116+
createSidedException("Remove the OffhandLights mod and restart the game!\n" +
117+
"FalseTweaks has built-in offhand lights support.");
118+
}
119+
} catch (Throwable ignored) {}
113120
proxy.preInit(e);
114121
}
115122

src/main/java/com/falsepattern/falsetweaks/modules/dynlights/base/DynamicLights.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import net.minecraft.entity.monster.EntityBlaze;
4343
import net.minecraft.entity.monster.EntityCreeper;
4444
import net.minecraft.entity.monster.EntityMagmaCube;
45+
import net.minecraft.entity.player.EntityPlayer;
4546
import net.minecraft.entity.projectile.EntityFireball;
4647
import net.minecraft.init.Blocks;
4748
import net.minecraft.init.Items;
@@ -326,12 +327,16 @@ public int getLightLevel(Entity entity) {
326327
}
327328

328329
if (entity instanceof EntityLivingBase) {
329-
EntityLivingBase player = (EntityLivingBase) entity;
330-
ItemStack stackMain = player.getHeldItem();
330+
EntityLivingBase living = (EntityLivingBase) entity;
331+
ItemStack stackMain = living.getHeldItem();
331332
int levelMain = getLightLevel(stackMain);
332-
ItemStack stackHead = player.getEquipmentInSlot(4);
333+
ItemStack stackHead = living.getEquipmentInSlot(4);
333334
int levelHead = getLightLevel(stackHead);
334-
return Math.max(levelMain, levelHead);
335+
int level = Math.max(levelMain, levelHead);
336+
if (entity instanceof EntityPlayer) {
337+
level = Math.max(level, getLightLevel(OffhandMod.CURRENT.getOffhandItem((EntityPlayer) entity)));
338+
}
339+
return level;
335340
} else if (entity instanceof EntityItem) {
336341
EntityItem entityItem = (EntityItem) entity;
337342
ItemStack itemStack = getItemStack(entityItem);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* This file is part of FalseTweaks.
3+
*
4+
* Copyright (C) 2022-2025 FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice and this permission notice shall be included
8+
* in all copies or substantial portions of the Software.
9+
*
10+
* FalseTweaks is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, only version 3 of the License.
13+
*
14+
* FalseTweaks is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package com.falsepattern.falsetweaks.modules.dynlights.base;
24+
25+
import mods.battlegear2.api.core.IInventoryPlayerBattle;
26+
import mods.battlegear2.api.core.InventoryPlayerBattle;
27+
import xonin.backhand.api.core.BackhandUtils;
28+
29+
import net.minecraft.entity.player.EntityPlayer;
30+
import net.minecraft.item.ItemStack;
31+
import net.minecraft.launchwrapper.Launch;
32+
import cpw.mods.fml.common.Loader;
33+
34+
public enum OffhandMod {
35+
None,
36+
Backhand {
37+
@Override
38+
public ItemStack getOffhandItem(EntityPlayer player) {
39+
return BackhandUtils.getOffhandItem(player);
40+
}
41+
},
42+
Battlegear2 {
43+
@Override
44+
public ItemStack getOffhandItem(EntityPlayer player) {
45+
return ((InventoryPlayerBattle) player.inventory).getCurrentOffhandWeapon();
46+
}
47+
},
48+
Battlegear2GTNH {
49+
@Override
50+
public ItemStack getOffhandItem(EntityPlayer player) {
51+
return ((IInventoryPlayerBattle) player.inventory).battlegear2$getCurrentOffhandWeapon();
52+
}
53+
};
54+
55+
public static final OffhandMod CURRENT = detectCurrent();
56+
57+
private static OffhandMod detectCurrent() {
58+
if (Loader.isModLoaded("battlegear2")) {
59+
try {
60+
if (Launch.classLoader.getClassBytes("mods.battlegear2.api.core.InventoryPlayerBattle") != null) {
61+
return OffhandMod.Battlegear2;
62+
}
63+
} catch (Throwable ignored) {
64+
}
65+
return OffhandMod.Battlegear2GTNH;
66+
}
67+
if (Loader.isModLoaded("backhand")) {
68+
return OffhandMod.Backhand;
69+
}
70+
return None;
71+
}
72+
73+
public ItemStack getOffhandItem(EntityPlayer player) {
74+
return null;
75+
}
76+
}

0 commit comments

Comments
 (0)