-
Notifications
You must be signed in to change notification settings - Fork 79
/
VoxelNeighborRenderTracker.java
179 lines (149 loc) · 3.78 KB
/
VoxelNeighborRenderTracker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package mod.chiselsandbits.chiseledblock.data;
import java.lang.ref.WeakReference;
import mod.chiselsandbits.chiseledblock.BlockChiseled;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.render.chiseledblock.ModelRenderState;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.client.FMLClientHandler;
public final class VoxelNeighborRenderTracker
{
static final int IS_DYNAMIC = 1;
static final int IS_LOCKED = 2;
static final int IS_STATIC = 4;
private WeakReference<VoxelBlobStateReference> lastCenter;
private ModelRenderState lrs = null;
private byte isDynamic;
private boolean shouldUpdate = false;
Integer[] faceCount = new Integer[4];
public void unlockDynamic()
{
isDynamic = (byte) ( isDynamic & ~IS_LOCKED );
}
public VoxelNeighborRenderTracker()
{
faceCount = new Integer[BlockRenderLayer.values().length];
if ( ChiselsAndBits.getConfig().defaultToDynamicRenderer )
{
isDynamic = IS_DYNAMIC | IS_LOCKED;
for ( int x = 0; x < faceCount.length; ++x )
{
faceCount[x] = ChiselsAndBits.getConfig().dynamicModelFaceCount + 1;
}
}
else if ( ChiselsAndBits.getConfig().forceDynamicRenderer )
{
isDynamic = IS_DYNAMIC | IS_LOCKED;
}
}
private final ModelRenderState sides = new ModelRenderState( null );
public boolean isAboveLimit()
{
if ( FMLClientHandler.instance().hasOptifine() )
{
// I simply cannot figure out why the displaylist uploads for the
// dynamic renderer don't work with optifine, so unless someone else
// can solve it; I'm just disabling the dynamic renderer pipeline.
return false;
}
if ( ChiselsAndBits.getConfig().forceDynamicRenderer )
{
return true;
}
int faces = 0;
for ( int x = 0; x < faceCount.length; ++x )
{
if ( faceCount[x] == null )
{
return false;
}
faces += faceCount[x];
}
return faces >= ChiselsAndBits.getConfig().dynamicModelFaceCount;
}
public void setAbovelimit(
final BlockRenderLayer layer,
final int fc )
{
faceCount[layer.ordinal()] = fc;
}
public boolean isDynamic()
{
return ( isDynamic & IS_DYNAMIC ) != 0;
}
public void update(
final boolean isDynamic,
final IBlockAccess access,
final BlockPos pos )
{
if ( access == null || pos == null )
{
return;
}
if ( ( this.isDynamic & IS_LOCKED ) == 0 )
{
this.isDynamic = (byte) ( isDynamic ? IS_DYNAMIC : IS_STATIC );
}
for ( final EnumFacing f : EnumFacing.VALUES )
{
assert f != null;
final TileEntityBlockChiseled tebc = ModUtil.getChiseledTileEntity( access, pos.offset( f ) );
if ( tebc != null )
{
update( f, tebc.getBasicState().getValue( BlockChiseled.UProperty_VoxelBlob ) );
}
else
{
update( f, null );
}
}
}
private void update(
final EnumFacing f,
final VoxelBlobStateReference value )
{
if ( sides.get( f ) == value )
{
return;
}
synchronized ( this )
{
sides.put( f, value );
lrs = null;
}
}
public ModelRenderState getRenderState(
final VoxelBlobStateReference data )
{
if ( lrs == null || lastCenter == null )
{
lrs = new ModelRenderState( sides );
updateCenter( data );
}
else if ( lastCenter.get() != data )
{
updateCenter( data );
lrs = new ModelRenderState( sides );
}
return lrs;
}
private void updateCenter(
final VoxelBlobStateReference data )
{
lastCenter = new WeakReference<VoxelBlobStateReference>( data );
}
public void triggerUpdate()
{
shouldUpdate = true;
}
public boolean isShouldUpdate()
{
final boolean res = shouldUpdate;
shouldUpdate = false;
return res;
}
}