forked from GTNewHorizons/GT5-Unofficial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finishing touches on black hole compressor (GTNewHorizons#3060)
Co-authored-by: Martin Robertz <dream-master@gmx.net> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: BucketBrigade <138534411+CookieBrigade@users.noreply.github.com>
- Loading branch information
1 parent
67607ed
commit f2c0a4f
Showing
45 changed files
with
2,296 additions
and
139 deletions.
There are no files selected for viewing
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
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
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
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
74 changes: 74 additions & 0 deletions
74
src/main/java/gregtech/common/blocks/BlockBlackholeRenderer.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,74 @@ | ||
package gregtech.common.blocks; | ||
|
||
import java.util.ArrayList; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.client.renderer.texture.IIconRegister; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.world.World; | ||
|
||
import cpw.mods.fml.common.registry.GameRegistry; | ||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import gregtech.common.tileentities.render.TileEntityBlackhole; | ||
|
||
public class BlockBlackholeRenderer extends Block { | ||
|
||
public BlockBlackholeRenderer() { | ||
super(Material.iron); | ||
this.setResistance(20f); | ||
this.setHardness(-1.0f); | ||
this.setBlockName("BlackHoleRenderer"); | ||
this.setLightLevel(100.0f); | ||
GameRegistry.registerBlock(this, getUnlocalizedName()); | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void registerBlockIcons(IIconRegister iconRegister) { | ||
blockIcon = iconRegister.registerIcon("gregtech:iconsets/TRANSPARENT"); | ||
} | ||
|
||
@Override | ||
public String getUnlocalizedName() { | ||
return "gt.blackholerenderer"; | ||
} | ||
|
||
@Override | ||
public boolean isOpaqueCube() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canRenderInPass(int a) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean renderAsNormalBlock() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean hasTileEntity(int metadata) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public TileEntity createTileEntity(World world, int metadata) { | ||
return new TileEntityBlackhole(); | ||
} | ||
|
||
@Override | ||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int meta, int fortune) { | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public boolean isCollidable() { | ||
return true; | ||
} | ||
|
||
} |
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
222 changes: 222 additions & 0 deletions
222
src/main/java/gregtech/common/render/BlackholeRenderer.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,222 @@ | ||
package gregtech.common.render; | ||
|
||
import static gregtech.api.enums.Mods.GregTech; | ||
|
||
import java.nio.FloatBuffer; | ||
|
||
import net.minecraft.client.renderer.ActiveRenderInfo; | ||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.client.model.AdvancedModelLoader; | ||
|
||
import org.joml.Matrix4fStack; | ||
import org.joml.Vector4f; | ||
import org.lwjgl.BufferUtils; | ||
import org.lwjgl.opengl.GL11; | ||
import org.lwjgl.opengl.GL20; | ||
|
||
import com.gtnewhorizon.gtnhlib.client.renderer.CapturingTessellator; | ||
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; | ||
import com.gtnewhorizon.gtnhlib.client.renderer.shader.ShaderProgram; | ||
import com.gtnewhorizon.gtnhlib.client.renderer.vbo.IModelCustomExt; | ||
import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer; | ||
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.DefaultVertexFormat; | ||
|
||
import cpw.mods.fml.client.registry.ClientRegistry; | ||
import gregtech.common.tileentities.render.TileEntityBlackhole; | ||
|
||
public class BlackholeRenderer extends TileEntitySpecialRenderer { | ||
|
||
private boolean initialized = false; | ||
|
||
private ShaderProgram blackholeProgram; | ||
private static int u_CameraPosition = -1, u_Scale = -1, u_Time = -1, u_Stability = -1; | ||
private static final Matrix4fStack modelMatrixStack = new Matrix4fStack(4); | ||
|
||
private static IModelCustomExt blackholeModel; | ||
private static ResourceLocation blackholeTexture; | ||
private static float modelScale = .5f; | ||
|
||
private ShaderProgram laserProgram; | ||
private static int u_LaserCameraPosition = -1, u_LaserColor = -1, u_LaserModelMatrix = -1; | ||
private static VertexBuffer laserVBO; | ||
private static ResourceLocation laserTexture; | ||
|
||
private static final Matrix4fStack modelMatrix = new Matrix4fStack(2); | ||
|
||
private static final float WIDTH = .1f; | ||
private static final float EXCLUSION = 1f; | ||
|
||
public BlackholeRenderer() { | ||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBlackhole.class, this); | ||
} | ||
|
||
private void init() { | ||
try { | ||
blackholeProgram = new ShaderProgram( | ||
GregTech.resourceDomain, | ||
"shaders/blackhole.vert.glsl", | ||
"shaders/blackhole.frag.glsl"); | ||
|
||
u_CameraPosition = blackholeProgram.getUniformLocation("u_CameraPosition"); | ||
|
||
u_Scale = blackholeProgram.getUniformLocation("u_Scale"); | ||
u_Time = blackholeProgram.getUniformLocation("u_Time"); | ||
u_Stability = blackholeProgram.getUniformLocation("u_Stability"); | ||
|
||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
return; | ||
} | ||
|
||
blackholeModel = (IModelCustomExt) AdvancedModelLoader | ||
.loadModel(new ResourceLocation(GregTech.resourceDomain, "textures/model/blackhole.obj")); | ||
blackholeTexture = new ResourceLocation(GregTech.resourceDomain, "textures/model/blackhole.png"); | ||
|
||
blackholeProgram.use(); | ||
GL20.glUniform1f(u_Scale, modelScale); | ||
GL20.glUniform1f(u_Stability, .1f); | ||
ShaderProgram.clear(); | ||
|
||
try { | ||
laserProgram = new ShaderProgram( | ||
GregTech.resourceDomain, | ||
"shaders/laser.vert.glsl", | ||
"shaders/laser.frag.glsl"); | ||
u_LaserCameraPosition = laserProgram.getUniformLocation("u_CameraPosition"); | ||
u_LaserColor = laserProgram.getUniformLocation("u_Color"); | ||
u_LaserModelMatrix = laserProgram.getUniformLocation("u_ModelMatrix"); | ||
|
||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
return; | ||
} | ||
|
||
laserTexture = new ResourceLocation(GregTech.resourceDomain, "textures/model/laser.png"); | ||
|
||
TessellatorManager.startCapturing(); | ||
CapturingTessellator tess = (CapturingTessellator) TessellatorManager.get(); | ||
|
||
tess.startDrawingQuads(); | ||
|
||
tess.addVertexWithUV(.5 + 8, 0, -WIDTH, 0, 0); | ||
tess.addVertexWithUV(.5 + 8, 0, WIDTH, 0, 1); | ||
tess.addVertexWithUV(EXCLUSION, 0, WIDTH / 5, 1, 1); | ||
tess.addVertexWithUV(EXCLUSION, 0, -WIDTH / 5, 1, 0); | ||
|
||
tess.addVertexWithUV(-.5 - 8, 0, -WIDTH, 0, 0); | ||
tess.addVertexWithUV(-.5 - 8, 0, WIDTH, 0, 1); | ||
tess.addVertexWithUV(-EXCLUSION, 0, WIDTH / 5, 1, 1); | ||
tess.addVertexWithUV(-EXCLUSION, 0, -WIDTH / 5, 1, 0); | ||
|
||
tess.draw(); | ||
|
||
laserVBO = TessellatorManager.stopCapturingToVBO(DefaultVertexFormat.POSITION_TEXTURE_NORMAL); | ||
|
||
initialized = true; | ||
} | ||
|
||
private void renderBlackHole(TileEntityBlackhole tile, double x, double y, double z, float timer) { | ||
|
||
blackholeProgram.use(); | ||
bindTexture(blackholeTexture); | ||
GL20.glUniform1f(u_Stability, tile.getStability()); | ||
modelMatrixStack.clear(); | ||
|
||
float xLocal = ((float) x + .5f); | ||
float yLocal = ((float) y + .5f); | ||
float zLocal = ((float) z + .5f); | ||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); | ||
GL11.glPushMatrix(); | ||
GL20.glUniform3f( | ||
u_CameraPosition, | ||
ActiveRenderInfo.objectX - xLocal, | ||
ActiveRenderInfo.objectY - yLocal, | ||
ActiveRenderInfo.objectZ - zLocal); | ||
|
||
GL20.glUniform1f(u_Time, timer); | ||
GL11.glTranslated(x + .5f, y + .5f, z + .5f); | ||
blackholeModel.renderAllVBO(); | ||
|
||
GL11.glPopMatrix(); | ||
GL11.glPopAttrib(); | ||
ShaderProgram.clear(); | ||
} | ||
|
||
private void renderLasers(TileEntityBlackhole tile, double x, double y, double z, float timer) { | ||
laserProgram.use(); | ||
bindTexture(laserTexture); | ||
|
||
float cx = ((float) x + .5f); | ||
float cy = ((float) y + .5f); | ||
float cz = ((float) z + .5f); | ||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); | ||
GL11.glDisable(GL11.GL_CULL_FACE); | ||
GL11.glPushMatrix(); | ||
GL20.glUniform3f(u_LaserColor, tile.getLaserR(), tile.getLaserG(), tile.getLaserB()); | ||
|
||
modelMatrix.clear(); | ||
modelMatrix.translate(cx, cy, cz); | ||
|
||
// First set | ||
FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16); | ||
GL20.glUniformMatrix4(u_LaserModelMatrix, false, modelMatrix.get(matrixBuffer)); | ||
modelMatrix.pushMatrix(); | ||
modelMatrix.invert(); | ||
Vector4f cameraPosition = new Vector4f( | ||
ActiveRenderInfo.objectX, | ||
ActiveRenderInfo.objectY, | ||
ActiveRenderInfo.objectZ, | ||
1); | ||
cameraPosition = modelMatrix.transform(cameraPosition); | ||
GL20.glUniform3f(u_LaserCameraPosition, cameraPosition.x, cameraPosition.y, cameraPosition.z); | ||
laserVBO.render(); | ||
|
||
// Second set | ||
|
||
modelMatrix.popMatrix(); | ||
matrixBuffer.clear(); | ||
modelMatrix.rotate((float) Math.PI / 2, 0, 1, 0); | ||
|
||
GL20.glUniformMatrix4(u_LaserModelMatrix, false, modelMatrix.get(matrixBuffer)); | ||
|
||
modelMatrix.invert(); | ||
cameraPosition.set(ActiveRenderInfo.objectX, ActiveRenderInfo.objectY, ActiveRenderInfo.objectZ, 1); | ||
cameraPosition = modelMatrix.transform(cameraPosition); | ||
GL20.glUniform3f(u_LaserCameraPosition, cameraPosition.x, cameraPosition.y, cameraPosition.z); | ||
laserVBO.render(); | ||
|
||
GL11.glPopMatrix(); | ||
GL11.glPopAttrib(); | ||
ShaderProgram.clear(); | ||
} | ||
|
||
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float timeSinceLastTick) { | ||
if (!(tile instanceof TileEntityBlackhole blackhole)) return; | ||
|
||
if (!initialized) { | ||
init(); | ||
if (!initialized) return; | ||
} | ||
if (((TileEntityBlackhole) tile).getLaserRender()) { | ||
renderLasers( | ||
blackhole, | ||
x, | ||
y, | ||
z, | ||
tile.getWorldObj() | ||
.getWorldTime() + timeSinceLastTick); | ||
} | ||
|
||
renderBlackHole( | ||
blackhole, | ||
x, | ||
y, | ||
z, | ||
tile.getWorldObj() | ||
.getWorldTime() + timeSinceLastTick); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.