-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
375 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ public static String getModVersion() { | |
throw new AssertionError(); | ||
} | ||
|
||
|
||
} |
33 changes: 33 additions & 0 deletions
33
common/src/main/java/dev/imabad/theatrical/api/DynamicLightProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.imabad.theatrical.api; | ||
|
||
import dev.imabad.theatrical.lighting.LightManager; | ||
import net.minecraft.client.renderer.LevelRenderer; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
import org.joml.Vector3f; | ||
|
||
public interface DynamicLightProvider { | ||
|
||
BlockPos getOwnerPos(); | ||
Vector3f getLightPos(); | ||
Level getLevel(); | ||
default boolean isLightEnabled() { | ||
return LightManager.containsLightSource(this); | ||
} | ||
default void setLightEnabled(boolean enabled) { | ||
resetLight(); | ||
if(enabled){ | ||
LightManager.addLightSource(this); | ||
} else { | ||
LightManager.removeLightSource(this); | ||
} | ||
} | ||
void resetLight(); | ||
int getLightLuminance(); | ||
void lightTick(); | ||
boolean shouldUpdateLight(); | ||
boolean updateDynamicLight(LevelRenderer renderer); | ||
void scheduleTrackedChunksRebuild(LevelRenderer renderer); | ||
int getLightColour(); | ||
int getLightSpread(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
common/src/main/java/dev/imabad/theatrical/compat/ModCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.imabad.theatrical.compat; | ||
|
||
import dev.architectury.platform.Platform; | ||
|
||
public class ModCompat { | ||
|
||
public static final boolean SHIMMER = Platform.isModLoaded("shimmer"); | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
common/src/main/java/dev/imabad/theatrical/compat/ShimmerCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dev.imabad.theatrical.compat; | ||
|
||
import com.lowdragmc.shimmer.client.light.ColorPointLight; | ||
import com.lowdragmc.shimmer.client.light.LightManager; | ||
import dev.imabad.theatrical.api.DynamicLightProvider; | ||
import dev.imabad.theatrical.blockentities.light.BaseLightBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.joml.Vector3f; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
public class ShimmerCompat { | ||
|
||
private static final Map<BlockPos, ColorPointLight> pos2PointLight = new ConcurrentHashMap<>(); | ||
private final static ReentrantReadWriteLock lightSourcesLock = new ReentrantReadWriteLock(); | ||
|
||
public static void setup(){} | ||
|
||
public static void addLight(DynamicLightProvider dynamicLightProvider){ | ||
if(!ModCompat.SHIMMER) return; | ||
lightSourcesLock.writeLock().lock(); | ||
ColorPointLight light = LightManager.INSTANCE.addLight(dynamicLightProvider.getLightPos(), dynamicLightProvider.getLightColour(), 8); | ||
|
||
if(light != null){ | ||
pos2PointLight.put(dynamicLightProvider.getOwnerPos(), light); | ||
} | ||
lightSourcesLock.writeLock().unlock(); | ||
} | ||
|
||
public static void removeLight(BlockPos fixturePos){ | ||
if(!ModCompat.SHIMMER) return; | ||
lightSourcesLock.writeLock().lock(); | ||
if(pos2PointLight.containsKey(fixturePos)){ | ||
pos2PointLight.get(fixturePos).remove(); | ||
} | ||
pos2PointLight.remove(fixturePos); | ||
lightSourcesLock.writeLock().unlock(); | ||
} | ||
|
||
public static void worldClose(){ | ||
if(!ModCompat.SHIMMER) return; | ||
lightSourcesLock.writeLock().lock(); | ||
pos2PointLight.forEach((blockPos, colorPointLight) -> { | ||
colorPointLight.remove(); | ||
}); | ||
pos2PointLight.clear(); | ||
lightSourcesLock.writeLock().unlock(); | ||
} | ||
|
||
public static void handleLightUpdate(BaseLightBlockEntity light){ | ||
if(!pos2PointLight.containsKey(light.getBlockPos())) return; | ||
ColorPointLight colorPointLight = pos2PointLight.get(light.getBlockPos()); | ||
Vector3f lightPos = light.getLightPos(); | ||
colorPointLight.setPos(lightPos.x, lightPos.y, lightPos.z); | ||
colorPointLight.setColor(light.getLightColour()); | ||
colorPointLight.setEnable(light.isLightEnabled()); | ||
colorPointLight.update(); | ||
} | ||
} |
Oops, something went wrong.