Skip to content

Commit

Permalink
- incompat with abnormalscore
Browse files Browse the repository at this point in the history
  • Loading branch information
Pannoniae committed Jan 4, 2021
1 parent fe85ee6 commit f69f44b
Show file tree
Hide file tree
Showing 50 changed files with 4,173 additions and 2 deletions.
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();
}
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();
}
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);
}
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);
}
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);
}
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();
}
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);
}
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);
}
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);
}
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);

}
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);
}
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);
}
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);
}
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();
}
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();
}
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();
}
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);
}
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);
}
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);
}
}
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];
}
}
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;
}
}
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;
}
}
Loading

0 comments on commit f69f44b

Please sign in to comment.