mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-11 15:57:42 +00:00
Added full block model and planar light matrix
Added set function to Rectangle4i
This commit is contained in:
1 parent
408e45ef25
commit
215715f7c5
5 files changed
+102
No files matched your search
@@ -89,6 +89,7 @@ public class LightMatrix implements CCRenderState.IVertexOperation
|
||||
Block b = access.getBlock(x, y, z);
|
||||
bSamples[i] = access.getLightBrightnessForSkyBlocks(x, y, z, b.getLightValue(access, x, y, z));
|
||||
aSamples[i] = b.getAmbientOcclusionLightValue();
|
||||
sampled |= 1 << i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package codechicken.lib.lighting;
|
||||
|
||||
import codechicken.lib.render.CCRenderState;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public class PlanarLightMatrix extends PlanarLightModel
|
||||
{
|
||||
public static final int operationIndex = CCRenderState.registerOperation();
|
||||
public static PlanarLightMatrix instance = new PlanarLightMatrix();
|
||||
|
||||
public IBlockAccess access;
|
||||
public BlockCoord pos = new BlockCoord();
|
||||
|
||||
private int sampled = 0;
|
||||
public int[] brightness = new int[6];
|
||||
|
||||
public PlanarLightMatrix() {
|
||||
super(PlanarLightModel.standardLightModel.colours);
|
||||
}
|
||||
|
||||
public PlanarLightMatrix locate(IBlockAccess a, int x, int y, int z) {
|
||||
access = a;
|
||||
pos.set(x, y, z);
|
||||
sampled = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int brightness(int side) {
|
||||
if((sampled & 1 << side) == 0) {
|
||||
Block b = access.getBlock(pos.x, pos.y, pos.z);
|
||||
brightness[side] = access.getLightBrightnessForSkyBlocks(pos.x, pos.y, pos.z, b.getLightValue(access, pos.x, pos.y, pos.z));
|
||||
sampled |= 1 << side;
|
||||
}
|
||||
return brightness[side];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean load() {
|
||||
CCRenderState.pipeline.addDependency(CCRenderState.sideAttrib);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operate() {
|
||||
super.operate();
|
||||
CCRenderState.setBrightness(brightness(CCRenderState.side));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int operationID() {
|
||||
return operationIndex;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package codechicken.lib.render;
|
||||
|
||||
import codechicken.lib.lighting.LC;
|
||||
import codechicken.lib.render.CCRenderState.VertexAttribute;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
|
||||
public class BlockRenderer
|
||||
@@ -105,6 +106,39 @@ public class BlockRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public static class FullBlock implements CCRenderState.IVertexSource
|
||||
{
|
||||
public Vertex5[] verts = CCModel.quadModel(24).generateBlock(0, Cuboid6.full).verts;
|
||||
public LC[] lightCoords = new LC[24];
|
||||
|
||||
public FullBlock() {
|
||||
for(int i = 0; i < 24; i++)
|
||||
lightCoords[i] = new LC().compute(verts[i].vec, i/4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vertex5[] getVertices() {
|
||||
return verts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getAttributes(VertexAttribute<T> attr) {
|
||||
return attr == CCRenderState.lightCoordAttrib ? (T) lightCoords : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAttribute(VertexAttribute<?> attr) {
|
||||
return attr == CCRenderState.sideAttrib || attr == CCRenderState.lightCoordAttrib;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareVertex() {
|
||||
CCRenderState.side = CCRenderState.vertexIndex>>2;
|
||||
}
|
||||
}
|
||||
|
||||
public static FullBlock fullBlock = new FullBlock();
|
||||
|
||||
private static BlockFace face = new BlockFace();
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@ package codechicken.lib.render;
|
||||
import codechicken.lib.colour.ColourRGBA;
|
||||
import codechicken.lib.lighting.LC;
|
||||
import codechicken.lib.lighting.LightMatrix;
|
||||
import codechicken.lib.lighting.PlanarLightMatrix;
|
||||
import codechicken.lib.util.Copyable;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.lib.vec.Transformation;
|
||||
@@ -296,6 +297,10 @@ public class CCRenderState
|
||||
|
||||
public static void setModel(IVertexSource source, int start, int end) {
|
||||
bindModel(source);
|
||||
setVertexRange(start, end);
|
||||
}
|
||||
|
||||
public static void setVertexRange(int start, int end) {
|
||||
firstVertexIndex = start;
|
||||
lastVertexIndex = end;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,13 @@ public class Rectangle4i
|
||||
public int y2() {
|
||||
return y+h-1;
|
||||
}
|
||||
|
||||
public void set(int x, int y, int w, int h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
public Rectangle4i offset(int dx, int dy)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user