Skip to content

Commit

Permalink
fix compatible with include LDL mods (maybe? idk), use `renderWorld…
Browse files Browse the repository at this point in the history
…LastEvent`, change modid to `ryoamiclights`
  • Loading branch information
TexBlock committed Oct 2, 2023
1 parent 44e7486 commit e86b721
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 110 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Publish Release

on: [workflow_dispatch] # Manual trigger
on:
release:
types:
- published

permissions:
contents: write
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
## Changelog
- port to forge
- change modid to `ryoamiclights`
- fix compatible with `include LDL` mods (maybe? idk).
- use `renderWorldLastEvent`.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ quilt_mappings=1.19.3+build.8
forge_version=1.19.3-44.1.23

# Mod Properties
mod_version = 0.1.1
mod_version = 0.1.2
maven_group = dev.lambdaurora
archives_base_name = Ryoamiclights
modrinth_id=reCfnRvJ
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/dev/lambdaurora/lambdynlights/DynamicLightSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ public interface DynamicLightSource {
*
* @return the X coordinate
*/
double getDynamicLightX();
double ryoamicLights$getDynamicLightX();

/**
* Returns the dynamic light source Y coordinate.
*
* @return the Y coordinate
*/
double getDynamicLightY();
double ryoamicLights$getDynamicLightY();

/**
* Returns the dynamic light source Z coordinate.
*
* @return the Z coordinate
*/
double getDynamicLightZ();
double ryoamicLights$getDynamicLightZ();

/**
* Returns the dynamic light source world.
*
* @return the world instance
*/
World getDynamicLightWorld();
World ryoamicLights$getDynamicLightWorld();

/**
* Returns whether the dynamic light is enabled or not.
Expand All @@ -68,36 +68,36 @@ default boolean isDynamicLightEnabled() {
*/
@ApiStatus.Internal
default void setDynamicLightEnabled(boolean enabled) {
this.resetDynamicLight();
this.ryoamicLights$resetDynamicLight();
if (enabled)
LambDynLights.get().addLightSource(this);
else
LambDynLights.get().removeLightSource(this);
}

void resetDynamicLight();
void ryoamicLights$resetDynamicLight();

/**
* Returns the luminance of the light source.
* The maximum is 15, below 1 values are ignored.
*
* @return the luminance of the light source
*/
int getLuminance();
int ryoamicLights$getLuminance();

/**
* Executed at each tick.
*/
void dynamicLightTick();
void ryoamicLights$dynamicLightTick();

/**
* Returns whether this dynamic light source should update.
*
* @return {@code true} if this dynamic light source should update, else {@code false}
*/
boolean shouldUpdateDynamicLight();
boolean ryoamicLights$shouldUpdateDynamicLight();

boolean lambdynlights$updateDynamicLight(@NotNull WorldRenderer renderer);
boolean ryoamicLights$updateDynamicLight(@NotNull WorldRenderer renderer);

void lambdynlights$scheduleTrackedChunksRebuild(@NotNull WorldRenderer renderer);
void ryoamicLights$scheduleTrackedChunksRebuild(@NotNull WorldRenderer renderer);
}
45 changes: 28 additions & 17 deletions src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderLevelStageEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -55,7 +57,7 @@
*/
@Mod(LambDynLights.NAMESPACE)
public class LambDynLights {
public static final String NAMESPACE = "lambdynlights";
public static final String NAMESPACE = "ryoamiclights";
private static final double MAX_RADIUS = 7.75;
private static final double MAX_RADIUS_SQUARED = MAX_RADIUS * MAX_RADIUS;
private static LambDynLights INSTANCE;
Expand All @@ -69,6 +71,7 @@ public class LambDynLights {
public LambDynLights() {
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true));
EnvExecutor.runInEnv(Dist.CLIENT, () -> this::onInitializeClient);
EnvExecutor.runInEnv(Dist.CLIENT, () -> () -> Mod.EventBusSubscriber.Bus.FORGE.bus().get().addListener(this::renderWorldLastEvent));
}

public void onInitializeClient() {
Expand All @@ -83,6 +86,14 @@ public void onInitializeClient() {
DynamicLightHandlers.registerDefaultHandlers();
}

@SubscribeEvent
public void renderWorldLastEvent(RenderLevelStageEvent event) {
if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_TRIPWIRE_BLOCKS) {
MinecraftClient.getInstance().getProfiler().push("dynamic_lighting");
get().updateAll(event.getLevelRenderer());
}
}

/**
* Updates all light sources.
*
Expand All @@ -99,7 +110,7 @@ public void updateAll(@NotNull WorldRenderer renderer) {

this.lightSourcesLock.readLock().lock();
for (var lightSource : this.dynamicLightSources) {
if (lightSource.lambdynlights$updateDynamicLight(renderer)) this.lastUpdateCount++;
if (lightSource.ryoamicLights$updateDynamicLight(renderer)) this.lastUpdateCount++;
}
this.lightSourcesLock.readLock().unlock();
}
Expand Down Expand Up @@ -134,7 +145,7 @@ public int getLightmapWithDynamicLight(@NotNull BlockPos pos, int lightmap) {
*/
public int getLightmapWithDynamicLight(@NotNull Entity entity, int lightmap) {
int posLightLevel = (int) this.getDynamicLightLevel(entity.getBlockPos());
int entityLuminance = ((DynamicLightSource) entity).getLuminance();
int entityLuminance = ((DynamicLightSource) entity).ryoamicLights$getLuminance();

return this.getLightmapWithDynamicLight(Math.max(posLightLevel, entityLuminance), lightmap);
}
Expand Down Expand Up @@ -189,12 +200,12 @@ public double getDynamicLightLevel(@NotNull BlockPos pos) {
* @return the dynamic light level at the specified position
*/
public static double maxDynamicLightLevel(@NotNull BlockPos pos, @NotNull DynamicLightSource lightSource, double currentLightLevel) {
int luminance = lightSource.getLuminance();
int luminance = lightSource.ryoamicLights$getLuminance();
if (luminance > 0) {
// Can't use Entity#squaredDistanceTo because of eye Y coordinate.
double dx = pos.getX() - lightSource.getDynamicLightX() + 0.5;
double dy = pos.getY() - lightSource.getDynamicLightY() + 0.5;
double dz = pos.getZ() - lightSource.getDynamicLightZ() + 0.5;
double dx = pos.getX() - lightSource.ryoamicLights$getDynamicLightX() + 0.5;
double dy = pos.getY() - lightSource.ryoamicLights$getDynamicLightY() + 0.5;
double dz = pos.getZ() - lightSource.ryoamicLights$getDynamicLightZ() + 0.5;

double distanceSquared = dx * dx + dy * dy + dz * dz;
// 7.75 because else we would have to update more chunks and that's not a good idea.
Expand All @@ -216,7 +227,7 @@ public static double maxDynamicLightLevel(@NotNull BlockPos pos, @NotNull Dynami
* @param lightSource the light source to add
*/
public void addLightSource(@NotNull DynamicLightSource lightSource) {
if (!lightSource.getDynamicLightWorld().isClient())
if (!lightSource.ryoamicLights$getDynamicLightWorld().isClient())
return;
if (!this.config.getDynamicLightsMode().isEnabled())
return;
Expand All @@ -234,7 +245,7 @@ public void addLightSource(@NotNull DynamicLightSource lightSource) {
* @return {@code true} if the light source is tracked, else {@code false}
*/
public boolean containsLightSource(@NotNull DynamicLightSource lightSource) {
if (!lightSource.getDynamicLightWorld().isClient())
if (!lightSource.ryoamicLights$getDynamicLightWorld().isClient())
return false;

boolean result;
Expand Down Expand Up @@ -274,7 +285,7 @@ public void removeLightSource(@NotNull DynamicLightSource lightSource) {
if (it.equals(lightSource)) {
dynamicLightSources.remove();
if (MinecraftClient.getInstance().worldRenderer != null)
lightSource.lambdynlights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer);
lightSource.ryoamicLights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer);
break;
}
}
Expand All @@ -294,9 +305,9 @@ public void clearLightSources() {
it = dynamicLightSources.next();
dynamicLightSources.remove();
if (MinecraftClient.getInstance().worldRenderer != null) {
if (it.getLuminance() > 0)
it.resetDynamicLight();
it.lambdynlights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer);
if (it.ryoamicLights$getLuminance() > 0)
it.ryoamicLights$resetDynamicLight();
it.ryoamicLights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer);
}
}

Expand All @@ -318,9 +329,9 @@ public void removeLightSources(@NotNull Predicate<DynamicLightSource> filter) {
if (filter.test(it)) {
dynamicLightSources.remove();
if (MinecraftClient.getInstance().worldRenderer != null) {
if (it.getLuminance() > 0)
it.resetDynamicLight();
it.lambdynlights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer);
if (it.ryoamicLights$getLuminance() > 0)
it.ryoamicLights$resetDynamicLight();
it.ryoamicLights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer);
}
break;
}
Expand Down Expand Up @@ -424,7 +435,7 @@ public static void updateTrackedChunks(@NotNull BlockPos chunkPos, @Nullable Lon
*/
public static void updateTracking(@NotNull DynamicLightSource lightSource) {
boolean enabled = lightSource.isDynamicLightEnabled();
int luminance = lightSource.getLuminance();
int luminance = lightSource.ryoamicLights$getLuminance();

if (!enabled && luminance > 0) {
lightSource.setDynamicLightEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void onGetBlockLight(T entity, BlockPos pos, CallbackInfoReturnable<Inte
return; // Do not touch to the value.

int vanilla = cir.getReturnValueI();
int entityLuminance = ((DynamicLightSource) entity).getLuminance();
int entityLuminance = ((DynamicLightSource) entity).ryoamicLights$getLuminance();
if (entityLuminance >= 15)
cir.setReturnValue(entityLuminance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void onBlockEntityTick(CallbackInfo ci, Profiler profiler, Iterator<Bloc
if (this.isClient() && LambDynLights.get().config.getBlockEntitiesLightSource().get()) {
var blockEntity = this.getBlockEntity(blockEntityTickInvoker.getPos());
if (blockEntity != null)
((DynamicLightSource) blockEntity).dynamicLightTick();
((DynamicLightSource) blockEntity).ryoamicLights$dynamicLightTick();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ private void onTick(CallbackInfo ci) {
this.setDynamicLightEnabled(false);
} else {
if (!LambDynLights.get().config.getEntitiesLightSource().get() || !DynamicLightHandlers.canLightUp(this))
this.resetDynamicLight();
this.ryoamicLights$resetDynamicLight();
else
this.dynamicLightTick();
this.ryoamicLights$dynamicLightTick();
LambDynLights.updateTracking(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ private void onTick(CallbackInfo ci) {
if (!LambDynLights.get().config.getEntitiesLightSource().get() || !DynamicLightHandlers.canLightUp(this))
this.lambdynlights$luminance = 0;
else
this.dynamicLightTick();
this.ryoamicLights$dynamicLightTick();
LambDynLights.updateTracking(this);
}
}
}

@Override
public void dynamicLightTick() {
public void ryoamicLights$dynamicLightTick() {
this.lambdynlights$luminance = Math.max(
Math.max(
this.isOnFire() ? 15 : 0,
Expand All @@ -71,7 +71,7 @@ public void dynamicLightTick() {
}

@Override
public int getLuminance() {
public int ryoamicLights$getLuminance() {
return this.lambdynlights$luminance;
}
}
Loading

0 comments on commit e86b721

Please sign in to comment.