forked from CaffeineMC/sodium
-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
50 changed files
with
4,173 additions
and
2 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/main/java/me/jellysquid/mods/phosphor/common/block/BlockStateLightInfo.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 me.jellysquid.mods.phosphor.common.block; | ||
|
||
import net.minecraft.util.math.shapes.VoxelShape; | ||
|
||
public interface BlockStateLightInfo { | ||
VoxelShape[] getExtrudedFaces(); | ||
|
||
int getLightSubtracted(); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/me/jellysquid/mods/phosphor/common/block/BlockStateLightInfoAccess.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,5 @@ | ||
package me.jellysquid.mods.phosphor.common.block; | ||
|
||
public interface BlockStateLightInfoAccess { | ||
BlockStateLightInfo getLightInfo(); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/me/jellysquid/mods/phosphor/common/chunk/level/LevelPropagatorExtended.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,17 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.level; | ||
|
||
import net.minecraft.block.BlockState; | ||
|
||
public interface LevelPropagatorExtended { | ||
/** | ||
* Mirrors {@link LevelPropagator#propagateLevel(long, int, boolean)}, but allows a block state to be passed to | ||
* prevent subsequent lookup later. | ||
*/ | ||
void propagateLevel(long sourceId, BlockState sourceState, long targetId, int level, boolean decrease); | ||
|
||
/** | ||
* Copy of {@link LevelPropagator#getPropagatedLevel(long, long, int)} but with an additional argument to pass the | ||
* block state belonging to {@param sourceId}. | ||
*/ | ||
int getPropagatedLevel(long sourceId, BlockState sourceState, long targetId, int level); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/jellysquid/mods/phosphor/common/chunk/level/LevelUpdateListener.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,7 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.level; | ||
|
||
public interface LevelUpdateListener { | ||
void onPendingUpdateRemoved(long key); | ||
|
||
void onPendingUpdateAdded(long key); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/BlockLightStorageAccess.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,5 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
public interface BlockLightStorageAccess { | ||
boolean isLightEnabled(long sectionPos); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/IReadonly.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,5 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
public interface IReadonly { | ||
boolean isReadonly(); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/InitialLightingAccess.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,7 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
public interface InitialLightingAccess { | ||
void enableSourceLight(long chunkPos); | ||
|
||
void enableLightUpdates(long chunkPos); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LevelPropagatorAccess.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,5 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
public interface LevelPropagatorAccess { | ||
void invokePropagateLevel(long sourceId, long targetId, int level, boolean decrease); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LightInitializer.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,5 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
public interface LightInitializer { | ||
void spreadLightInto(long a, long b); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LightProviderBlockAccess.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,26 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.Direction; | ||
import net.minecraft.util.math.shapes.VoxelShape; | ||
|
||
public interface LightProviderBlockAccess { | ||
/** | ||
* Returns the BlockState which represents the block at the specified coordinates in the world. This may return | ||
* a different BlockState than what actually exists at the coordinates (such as if it is out of bounds), but will | ||
* always represent a state with valid light properties for that coordinate. | ||
*/ | ||
BlockState getBlockStateForLighting(int x, int y, int z); | ||
|
||
/** | ||
* Returns the amount of light which is blocked at the specified coordinates by the BlockState. | ||
*/ | ||
int getSubtractedLight(BlockState state, int x, int y, int z); | ||
|
||
/** | ||
* Returns the VoxelShape of a block for lighting without making a second call to | ||
* {@link LightProviderBlockAccess#getBlockStateForLighting(int, int, int)}. | ||
*/ | ||
VoxelShape getOpaqueShape(BlockState state, int x, int y, int z, Direction dir); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LightProviderUpdateTracker.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,8 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
public interface LightProviderUpdateTracker { | ||
/** | ||
* Discards all pending updates for the specified chunk section. | ||
*/ | ||
void cancelUpdatesForChunk(long sectionPos); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LightStorageAccess.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,21 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
import net.minecraft.world.chunk.NibbleArray; | ||
|
||
public interface LightStorageAccess { | ||
NibbleArray callGetLightSection(long sectionPos, boolean cached); | ||
|
||
/** | ||
* Returns the light value for a position that does not have an associated lightmap. | ||
* This is analogous to {@link net.minecraft.world.lighting.SectionLightStorage#getLight(long)}, but uses the cached light data. | ||
*/ | ||
int getLightWithoutLightmap(long blockPos); | ||
|
||
/** | ||
* Enables or disables light updates for the provided <code>chunkPos</code>. | ||
* Disabling light updates additionally disables source light and removes all data associated to the chunk. | ||
*/ | ||
void setLightUpdatesEnabled(long chunkPos, boolean enabled); | ||
|
||
void invokeSetColumnEnabled(long chunkPos, boolean enabled); | ||
} |
9 changes: 9 additions & 0 deletions
9
...ain/java/me/jellysquid/mods/phosphor/common/chunk/light/ServerLightingProviderAccess.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 me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import net.minecraft.world.chunk.IChunk; | ||
|
||
public interface ServerLightingProviderAccess { | ||
CompletableFuture<IChunk> setupLightmaps(IChunk chunk); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/SharedBlockLightData.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,8 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
public interface SharedBlockLightData { | ||
/** | ||
* Marks this instance as a shared copy which cannot be directly written into. | ||
*/ | ||
void makeSharedCopy(); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/SharedLightStorageAccess.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,18 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
import net.minecraft.world.lighting.LightDataMap; | ||
|
||
import java.util.concurrent.locks.StampedLock; | ||
|
||
public interface SharedLightStorageAccess<M extends LightDataMap<M>> { | ||
/** | ||
* Bridge method to LightStorage#getStorageUncached(). | ||
*/ | ||
M getStorage(); | ||
|
||
/** | ||
* Returns the lock which wraps the {@link SharedLightStorageAccess#getStorage()}. Locking should always be | ||
* performed when accessing values in the aforementioned storage. | ||
*/ | ||
StampedLock getStorageLock(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/SharedNibbleArrayMap.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,23 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
import me.jellysquid.mods.phosphor.common.util.collections.DoubleBufferedLong2ObjectHashMap; | ||
import net.minecraft.world.chunk.NibbleArray; | ||
|
||
public interface SharedNibbleArrayMap { | ||
/** | ||
* Initializes the data for this extended chunk array map. This should only be called once with the initialization | ||
* of a subtype. | ||
* @throws IllegalStateException If the map has already been initialized | ||
*/ | ||
void init(); | ||
|
||
/** | ||
* Makes this map a shared copy of another. The shared copy cannot be directly written into. | ||
*/ | ||
void makeSharedCopy(SharedNibbleArrayMap map); | ||
|
||
/** | ||
* Returns the queue of pending changes for this map. | ||
*/ | ||
DoubleBufferedLong2ObjectHashMap<NibbleArray> getUpdateQueue(); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/SharedSkyLightData.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,14 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; | ||
import me.jellysquid.mods.phosphor.common.util.collections.DoubleBufferedLong2IntHashMap; | ||
|
||
public interface SharedSkyLightData { | ||
/** | ||
* Make this instance a copy of another, copying the object references from another instance into this one. | ||
* | ||
* @param map The sync-view of the {@param queue} | ||
* @param queue The queue of light updates | ||
*/ | ||
void makeSharedCopy(Long2IntOpenHashMap map, DoubleBufferedLong2IntHashMap queue); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/SkyLightStorageDataAccess.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,17 @@ | ||
package me.jellysquid.mods.phosphor.common.chunk.light; | ||
|
||
import me.jellysquid.mods.phosphor.common.util.collections.DoubleBufferedLong2IntHashMap; | ||
|
||
public interface SkyLightStorageDataAccess { | ||
/** | ||
* Bridge method to SkyLightStorageData#defaultHeight(). | ||
*/ | ||
int getDefaultHeight(); | ||
|
||
/** | ||
* Returns the height map value for the given block column in the world. | ||
*/ | ||
int getHeight(long pos); | ||
|
||
void updateMinHeight(int y); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/me/jellysquid/mods/phosphor/common/util/LightUtil.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,45 @@ | ||
package me.jellysquid.mods.phosphor.common.util; | ||
|
||
import net.minecraft.util.math.shapes.IBooleanFunction; | ||
import net.minecraft.util.math.shapes.VoxelShape; | ||
import net.minecraft.util.math.shapes.VoxelShapes; | ||
|
||
public class LightUtil { | ||
/** | ||
* Replacement for {@link VoxelShapes#unionCoversFullCube(VoxelShape, VoxelShape)}. This implementation early-exits | ||
* in some common situations to avoid unnecessary computation. | ||
* | ||
* @author JellySquid | ||
*/ | ||
public static boolean unionCoversFullCube(VoxelShape a, VoxelShape b) { | ||
// At least one shape is a full cube and will match | ||
if (a == VoxelShapes.fullCube() || b == VoxelShapes.fullCube()) { | ||
return true; | ||
} | ||
|
||
boolean ae = a.isEmpty(); | ||
boolean be = b.isEmpty(); | ||
|
||
// If both shapes are empty, they can never overlap a full cube | ||
if (ae && be) { | ||
return false; | ||
} | ||
|
||
// If both shapes are the same, it is pointless to merge them | ||
if (a == b) { | ||
return coversFullCube(a); | ||
} | ||
|
||
// If one of the shapes is empty, we can skip merging as any shape merged with an empty shape is the same shape | ||
if (ae || be) { | ||
return coversFullCube(ae ? b : a); | ||
} | ||
|
||
// No special optimizations can be performed, so we need to merge both shapes and test them | ||
return coversFullCube(VoxelShapes.combine(a, b, IBooleanFunction.OR)); | ||
} | ||
|
||
private static boolean coversFullCube(VoxelShape shape) { | ||
return !VoxelShapes.compare(VoxelShapes.fullCube(), shape, IBooleanFunction.ONLY_FIRST); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/me/jellysquid/mods/phosphor/common/util/chunk/light/EmptyChunkNibbleArray.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,11 @@ | ||
package me.jellysquid.mods.phosphor.common.util.chunk.light; | ||
|
||
public class EmptyChunkNibbleArray extends ReadonlyChunkNibbleArray { | ||
public EmptyChunkNibbleArray() { | ||
} | ||
|
||
@Override | ||
public byte[] getData() { | ||
return new byte[2048]; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...in/java/me/jellysquid/mods/phosphor/common/util/chunk/light/ReadonlyChunkNibbleArray.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,23 @@ | ||
package me.jellysquid.mods.phosphor.common.util.chunk.light; | ||
|
||
import me.jellysquid.mods.phosphor.common.chunk.light.IReadonly; | ||
import net.minecraft.world.chunk.NibbleArray; | ||
|
||
public class ReadonlyChunkNibbleArray extends NibbleArray implements IReadonly { | ||
public ReadonlyChunkNibbleArray() { | ||
} | ||
|
||
public ReadonlyChunkNibbleArray(byte[] bs) { | ||
super(bs); | ||
} | ||
|
||
@Override | ||
public NibbleArray copy() { | ||
return new NibbleArray(this.getData()); | ||
} | ||
|
||
@Override | ||
public boolean isReadonly() { | ||
return true; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...in/java/me/jellysquid/mods/phosphor/common/util/chunk/light/SkyLightChunkNibbleArray.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,25 @@ | ||
package me.jellysquid.mods.phosphor.common.util.chunk.light; | ||
|
||
import net.minecraft.world.chunk.NibbleArray; | ||
|
||
public class SkyLightChunkNibbleArray extends ReadonlyChunkNibbleArray { | ||
public SkyLightChunkNibbleArray(final NibbleArray inheritedLightmap) { | ||
super(inheritedLightmap.getData()); | ||
} | ||
|
||
@Override | ||
protected int getCoordinateIndex(final int x, final int y, final int z) { | ||
return super.getCoordinateIndex(x, 0, z); | ||
} | ||
|
||
@Override | ||
public byte[] getData() { | ||
byte[] byteArray = new byte[2048]; | ||
|
||
for(int i = 0; i < 16; ++i) { | ||
System.arraycopy(this.data, 0, byteArray, i * 128, 128); | ||
} | ||
|
||
return byteArray; | ||
} | ||
} |
Oops, something went wrong.