Skip to content

Commit 8f39cee

Browse files
committed
- Code / Import refactor.
1 parent d31b428 commit 8f39cee

File tree

381 files changed

+4767
-3843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

381 files changed

+4767
-3843
lines changed

src/main/java/com/cleanroommc/client/preview/renderer/scene/FBOWorldSceneRenderer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
*/
3131
@SideOnly(Side.CLIENT)
3232
public class FBOWorldSceneRenderer extends WorldSceneRenderer {
33-
private int resolutionWidth = 1080;
34-
private int resolutionHeight = 1080;
33+
private int resolutionWidth = 1080;
34+
private int resolutionHeight = 1080;
3535
private Framebuffer fbo;
3636

3737
public FBOWorldSceneRenderer(LRDummyWorld world, int resolutionWidth, int resolutionHeight) {
@@ -73,7 +73,7 @@ public RayTraceResult screenPos2BlockPosFace(int mouseX, int mouseY) {
7373
return looking;
7474
}
7575

76-
public Vector3f blockPos2ScreenPos(BlockPos pos, boolean depth){
76+
public Vector3f blockPos2ScreenPos(BlockPos pos, boolean depth) {
7777
int lastID = bindFBO();
7878
Vector3f winPos = super.blockPos2ScreenPos(pos, depth, 0, 0, this.resolutionWidth, this.resolutionHeight);
7979
unbindFBO(lastID);
@@ -92,7 +92,7 @@ public void render(float x, float y, float width, float height, float mouseX, fl
9292
GlStateManager.disableLighting();
9393
lastID = GL11.glGetInteger(GL11.GL_TEXTURE_2D);
9494
GlStateManager.bindTexture(fbo.framebufferTexture);
95-
GlStateManager.color(1,1,1,1);
95+
GlStateManager.color(1, 1, 1, 1);
9696

9797
// render rect with FBO texture
9898
Tessellator tessellator = Tessellator.getInstance();
@@ -112,7 +112,7 @@ public void render(float x, float y, float width, float height, int mouseX, int
112112
render(x, y, width, height, (float) mouseX, (float) mouseY, traceBlock);
113113
}
114114

115-
private int bindFBO(){
115+
private int bindFBO() {
116116
int lastID = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
117117
fbo.setFramebufferColor(0.0F, 0.0F, 0.0F, 0.0F);
118118
fbo.framebufferClear();
@@ -121,7 +121,7 @@ private int bindFBO(){
121121
return lastID;
122122
}
123123

124-
private void unbindFBO(int lastID){
124+
private void unbindFBO(int lastID) {
125125
GlStateManager.popMatrix();
126126
fbo.unbindFramebufferTexture();
127127
OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, lastID);

src/main/java/com/cleanroommc/client/preview/renderer/scene/ImmediateWorldSceneRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import net.minecraft.client.Minecraft;
66
import net.minecraft.client.gui.ScaledResolution;
77
import net.minecraft.client.renderer.GlStateManager;
8-
import net.minecraft.world.World;
98
import net.minecraftforge.fml.relauncher.Side;
109
import net.minecraftforge.fml.relauncher.SideOnly;
1110
import org.lwjgl.opengl.GL11;
1211

1312
/**
1413
* Created with IntelliJ IDEA.
14+
*
1515
* @Author: KilaBash
1616
* @Date: 2021/8/24
1717
* @Description: Real-time rendering renderer.

src/main/java/com/cleanroommc/client/preview/renderer/scene/WorldSceneRenderer.java

Lines changed: 90 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package com.cleanroommc.client.preview.renderer.scene;
22

3-
import com.cleanroommc.client.util.*;
3+
import com.cleanroommc.client.util.EntityCamera;
4+
import com.cleanroommc.client.util.LRMap;
5+
import com.cleanroommc.client.util.LRVertexBuffer;
6+
import com.cleanroommc.client.util.Position;
7+
import com.cleanroommc.client.util.PositionedRect;
8+
import com.cleanroommc.client.util.Size;
9+
import com.cleanroommc.client.util.TrackedDummyWorld;
10+
import com.cleanroommc.client.util.Vector3;
411
import com.cleanroommc.client.util.world.LRDummyWorld;
512
import github.kasuminova.mmce.client.util.BufferBuilderPool;
613
import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController;
@@ -9,7 +16,12 @@
916
import net.minecraft.block.Block;
1017
import net.minecraft.block.state.IBlockState;
1118
import net.minecraft.client.Minecraft;
12-
import net.minecraft.client.renderer.*;
19+
import net.minecraft.client.renderer.BlockRendererDispatcher;
20+
import net.minecraft.client.renderer.BufferBuilder;
21+
import net.minecraft.client.renderer.GlStateManager;
22+
import net.minecraft.client.renderer.OpenGlHelper;
23+
import net.minecraft.client.renderer.RenderHelper;
24+
import net.minecraft.client.renderer.Tessellator;
1325
import net.minecraft.client.renderer.texture.TextureMap;
1426
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
1527
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
@@ -34,7 +46,11 @@
3446
import java.nio.ByteOrder;
3547
import java.nio.FloatBuffer;
3648
import java.nio.IntBuffer;
37-
import java.util.*;
49+
import java.util.Collection;
50+
import java.util.EnumMap;
51+
import java.util.HashSet;
52+
import java.util.Map;
53+
import java.util.Set;
3854
import java.util.concurrent.CompletableFuture;
3955
import java.util.concurrent.ConcurrentHashMap;
4056
import java.util.concurrent.atomic.AtomicInteger;
@@ -52,18 +68,16 @@
5268
@SuppressWarnings("ALL")
5369
@SideOnly(Side.CLIENT)
5470
public abstract class WorldSceneRenderer {
55-
protected static final FloatBuffer MODELVIEW_MATRIX_BUFFER = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
71+
protected static final FloatBuffer MODELVIEW_MATRIX_BUFFER = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
5672
protected static final FloatBuffer PROJECTION_MATRIX_BUFFER = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
57-
protected static final IntBuffer VIEWPORT_BUFFER = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
58-
protected static final FloatBuffer PIXEL_DEPTH_BUFFER = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asFloatBuffer();
59-
protected static final FloatBuffer OBJECT_POS_BUFFER = ByteBuffer.allocateDirect(3 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
73+
protected static final IntBuffer VIEWPORT_BUFFER = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
74+
protected static final FloatBuffer PIXEL_DEPTH_BUFFER = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asFloatBuffer();
75+
protected static final FloatBuffer OBJECT_POS_BUFFER = ByteBuffer.allocateDirect(3 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
6076

6177
protected static final AtomicInteger THREAD_ID = new AtomicInteger(0);
6278

6379
protected static final Object2IntMap<BlockRenderLayer> LAYER_PROGRESS_UNITS = new Object2IntOpenHashMap<>();
64-
protected static final int TOTAL_PROGRESS_UNIT;
65-
66-
protected volatile Map<BlockRenderLayer, BufferBuilder> layerBufferBuilders = new EnumMap<>(BlockRenderLayer.class);
80+
protected static final int TOTAL_PROGRESS_UNIT;
6781

6882
static {
6983
int totalProgressUnit = 0;
@@ -82,40 +96,56 @@ public abstract class WorldSceneRenderer {
8296
TOTAL_PROGRESS_UNIT = totalProgressUnit;
8397
}
8498

85-
enum CacheState {
86-
UNUSED,
87-
NEED,
88-
COMPILING,
89-
COMPILED
90-
}
91-
92-
private final LRDummyWorld dummyWorld;
93-
private final LRMap<Collection<BlockPos>, ISceneRenderHook> renderedBlocksMap;
94-
private final LRVertexBuffer vertexBuffers = new LRVertexBuffer();
95-
96-
protected Set<BlockPos> tileEntities = new HashSet<>();
97-
protected boolean useCache;
98-
protected AtomicReference<CacheState> cacheState;
99-
protected int maxProgress;
100-
protected final AtomicInteger progress = new AtomicInteger();
101-
protected Thread thread;
102-
protected EntityCamera viewEntity;
103-
104-
private Consumer<WorldSceneRenderer> beforeRender;
105-
private Consumer<WorldSceneRenderer> afterRender;
106-
private Consumer<RayTraceResult> onLookingAt;
107-
protected int clearColor;
108-
private RayTraceResult lastTraceResult;
109-
private Vector3f eyePos = new Vector3f(0, 0, 10f);
110-
private Vector3f lookAt = new Vector3f(0, 0, 0);
111-
private Vector3f worldUp = new Vector3f(0, 1, 0);
99+
protected final AtomicInteger progress = new AtomicInteger();
100+
private final LRDummyWorld dummyWorld;
101+
private final LRMap<Collection<BlockPos>, ISceneRenderHook> renderedBlocksMap;
102+
private final LRVertexBuffer vertexBuffers = new LRVertexBuffer();
103+
protected volatile Map<BlockRenderLayer, BufferBuilder> layerBufferBuilders = new EnumMap<>(BlockRenderLayer.class);
104+
protected Set<BlockPos> tileEntities = new HashSet<>();
105+
protected boolean useCache;
106+
protected AtomicReference<CacheState> cacheState;
107+
protected int maxProgress;
108+
protected Thread thread;
109+
protected EntityCamera viewEntity;
110+
protected int clearColor;
111+
private Consumer<WorldSceneRenderer> beforeRender;
112+
private Consumer<WorldSceneRenderer> afterRender;
113+
private Consumer<RayTraceResult> onLookingAt;
114+
private RayTraceResult lastTraceResult;
115+
private Vector3f eyePos = new Vector3f(0, 0, 10f);
116+
private Vector3f lookAt = new Vector3f(0, 0, 0);
117+
private Vector3f worldUp = new Vector3f(0, 1, 0);
112118

113119
public WorldSceneRenderer(LRDummyWorld world) {
114120
this.dummyWorld = world;
115121
renderedBlocksMap = new LRMap<>(new ConcurrentHashMap<>(), new ConcurrentHashMap<>());
116122
cacheState = new AtomicReference<>(CacheState.UNUSED);
117123
}
118124

125+
protected static boolean isMouseOver(final PositionedRect positionedRect, final int mouseX, final int mouseY) {
126+
return mouseX > positionedRect.position.x && mouseX < positionedRect.position.x + positionedRect.size.width
127+
&& mouseY > positionedRect.position.y && mouseY < positionedRect.position.y + positionedRect.size.height;
128+
}
129+
130+
public static void setDefaultPassRenderState(int pass) {
131+
GlStateManager.color(1, 1, 1, 1);
132+
if (pass == 0) { // SOLID
133+
GlStateManager.enableDepth();
134+
GlStateManager.disableBlend();
135+
GlStateManager.depthMask(true);
136+
GlStateManager.shadeModel(7424);
137+
} else { // TRANSLUCENT
138+
GlStateManager.disableBlend();
139+
GlStateManager.enableCull();
140+
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
141+
GlStateManager.alphaFunc(516, 0.1F);
142+
GlStateManager.enableBlend();
143+
GlStateManager.depthMask(false);
144+
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
145+
GlStateManager.shadeModel(7425);
146+
}
147+
}
148+
119149
public WorldSceneRenderer useCacheBuffer(boolean useCache) {
120150
if (this.useCache == useCache || !Minecraft.getMinecraft().isCallingFromMinecraftThread()) {
121151
return this;
@@ -163,8 +193,8 @@ public WorldSceneRenderer deleteCacheBuffer() {
163193
}
164194
});
165195
layerBufferBuilders.values().stream()
166-
.filter(buffer -> buffer != null)
167-
.forEach(BufferBuilderPool::returnBuffer);
196+
.filter(buffer -> buffer != null)
197+
.forEach(BufferBuilderPool::returnBuffer);
168198
layerBufferBuilders.clear();
169199
});
170200
}
@@ -255,11 +285,6 @@ public void render(float x, float y, float width, float height, int mouseX, int
255285
resetCamera();
256286
}
257287

258-
protected static boolean isMouseOver(final PositionedRect positionedRect, final int mouseX, final int mouseY) {
259-
return mouseX > positionedRect.position.x && mouseX < positionedRect.position.x + positionedRect.size.width
260-
&& mouseY > positionedRect.position.y && mouseY < positionedRect.position.y + positionedRect.size.height;
261-
}
262-
263288
public Vector3f getEyePos() {
264289
return eyePos;
265290
}
@@ -430,6 +455,15 @@ public VertexBuffer[] getVertexBuffers() {
430455
return vertexBuffers.getBuffer();
431456
}
432457

458+
public WorldSceneRenderer setVertexBuffers(VertexBuffer[] vertexBuffers) {
459+
this.vertexBuffers.setBuffer(vertexBuffers).setAnotherBuffer(vertexBuffers);
460+
for (int j = 0; j < BlockRenderLayer.values().length; ++j) {
461+
this.vertexBuffers.getBuffer()[j] = new VertexBuffer(DefaultVertexFormats.BLOCK);
462+
this.vertexBuffers.getAnotherBuffer()[j] = new VertexBuffer(DefaultVertexFormats.BLOCK);
463+
}
464+
return this;
465+
}
466+
433467
protected BufferBuilder getLayerBufferBuilder(final BlockRenderLayer layer) {
434468
BufferBuilder builder = layerBufferBuilders.get(layer);
435469
if (builder != null) {
@@ -444,24 +478,15 @@ protected BufferBuilder getLayerBufferBuilder(final BlockRenderLayer layer) {
444478
return builder;
445479
}
446480

447-
public WorldSceneRenderer setVertexBuffers(VertexBuffer[] vertexBuffers) {
448-
this.vertexBuffers.setBuffer(vertexBuffers).setAnotherBuffer(vertexBuffers);
449-
for (int j = 0; j < BlockRenderLayer.values().length; ++j) {
450-
this.vertexBuffers.getBuffer()[j] = new VertexBuffer(DefaultVertexFormats.BLOCK);
451-
this.vertexBuffers.getAnotherBuffer()[j] = new VertexBuffer(DefaultVertexFormats.BLOCK);
452-
}
453-
return this;
454-
}
455-
456481
public void refreshCache() {
457482
if (isCompiling() || isCompilerThreadAlive()) {
458483
return;
459484
}
460485
cacheState.set(CacheState.COMPILING);
461486
progress.set(0);
462487
maxProgress = renderedBlocksMap.getAnotherMap().keySet().stream()
463-
.map(Collection::size)
464-
.reduce(0, Integer::sum) * 11;
488+
.map(Collection::size)
489+
.reduce(0, Integer::sum) * 11;
465490

466491
BlockRenderLayer oldRenderLayer = MinecraftForgeClient.getRenderLayer();
467492
Minecraft mc = Minecraft.getMinecraft();
@@ -633,7 +658,9 @@ private void renderBlocks(final boolean checkDisabledModel,
633658
// }
634659
IBlockState state = world.getBlockState(pos);
635660
Block block = state.getBlock();
636-
if (block == Blocks.AIR) continue;
661+
if (block == Blocks.AIR) {
662+
continue;
663+
}
637664
state = state.getActualState(world, pos);
638665
if (block.canRenderInLayer(state, layer)) {
639666
rendererDispatcher.renderBlock(state, pos, world, buffer);
@@ -685,25 +712,6 @@ private void renderTESR(final int pass, float particle, boolean checkDisabledMod
685712
RenderHelper.disableStandardItemLighting();
686713
}
687714

688-
public static void setDefaultPassRenderState(int pass) {
689-
GlStateManager.color(1, 1, 1, 1);
690-
if (pass == 0) { // SOLID
691-
GlStateManager.enableDepth();
692-
GlStateManager.disableBlend();
693-
GlStateManager.depthMask(true);
694-
GlStateManager.shadeModel(7424);
695-
} else { // TRANSLUCENT
696-
GlStateManager.disableBlend();
697-
GlStateManager.enableCull();
698-
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
699-
GlStateManager.alphaFunc(516, 0.1F);
700-
GlStateManager.enableBlend();
701-
GlStateManager.depthMask(false);
702-
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
703-
GlStateManager.shadeModel(7425);
704-
}
705-
}
706-
707715
public RayTraceResult rayTrace(Vector3f hitPos) {
708716
Vec3d startPos = new Vec3d(this.eyePos.x, this.eyePos.y, this.eyePos.z);
709717
hitPos.scale(2); // Double view range to ensure pos can be seen.
@@ -829,4 +837,11 @@ protected Vector3f blockPos2ScreenPos(BlockPos pos, boolean depth, int x, int y,
829837
return winPos;
830838
}
831839

840+
enum CacheState {
841+
UNUSED,
842+
NEED,
843+
COMPILING,
844+
COMPILED
845+
}
846+
832847
}

src/main/java/com/cleanroommc/client/util/BlockInfo.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public class BlockInfo {
1616

1717
public static final BlockInfo EMPTY = new BlockInfo(Blocks.AIR);
1818

19-
private final IBlockState blockState;
20-
private TileEntity tileEntity;
21-
private final ItemStack itemStack;
22-
private NBTTagCompound teTag;
19+
private final IBlockState blockState;
20+
private final ItemStack itemStack;
21+
private TileEntity tileEntity;
22+
private NBTTagCompound teTag;
2323

2424
public BlockInfo(Block block) {
2525
this(block.getDefaultState());
@@ -52,14 +52,11 @@ public static BlockInfo fromBlockState(IBlockState state) {
5252
return new BlockInfo(state, tileEntity);
5353
}
5454
}
55-
} catch (Exception ignored){ }
55+
} catch (Exception ignored) {
56+
}
5657
return new BlockInfo(state);
5758
}
5859

59-
public void setTileEntity(TileEntity tileEntity) {
60-
this.tileEntity = tileEntity;
61-
}
62-
6360
public IBlockState getBlockState() {
6461
return blockState;
6562
}
@@ -68,6 +65,10 @@ public TileEntity getTileEntity() {
6865
return tileEntity;
6966
}
7067

68+
public void setTileEntity(TileEntity tileEntity) {
69+
this.tileEntity = tileEntity;
70+
}
71+
7172
public ItemStack getItemStackForm() {
7273
return itemStack == null ? new ItemStack(Item.getItemFromBlock(blockState.getBlock()), 1, blockState.getBlock().damageDropped(blockState)) : itemStack;
7374
}

src/main/java/com/cleanroommc/client/util/EntityCamera.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ public void setPositionAndRotation(double x, double y, double z, float yaw, floa
2727
this.prevRotationPitch = this.rotationPitch;
2828
double d0 = this.prevRotationYaw - yaw;
2929

30-
if (d0 < -180.0D)
31-
{
30+
if (d0 < -180.0D) {
3231
this.prevRotationYaw += 360.0F;
3332
}
3433

35-
if (d0 >= 180.0D)
36-
{
34+
if (d0 >= 180.0D) {
3735
this.prevRotationYaw -= 360.0F;
3836
}
3937

0 commit comments

Comments
 (0)