Skip to content

Commit

Permalink
Finishing touches on black hole compressor (GTNewHorizons#3060)
Browse files Browse the repository at this point in the history
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
4 people authored Sep 7, 2024
1 parent 67607ed commit f2c0a4f
Show file tree
Hide file tree
Showing 45 changed files with 2,296 additions and 139 deletions.
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/GregTechAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public class GregTechAPI {
public static Block sBlockTintedGlass;
public static Block sLaserRender;
public static Block sWormholeRender;
public static Block sBlackholeRender;
/**
* Getting assigned by the Config
*/
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/gregtech/api/enums/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ public enum BlockIcons implements IIconContainer, Runnable {
OVERLAY_FRONT_MULTI_COMPRESSOR_COOLING,
OVERLAY_FRONT_MULTI_COMPRESSOR_COOLING_GLOW,

OVERLAY_HATCH_HEAT_SENSOR,
OVERLAY_HATCH_HEAT_SENSOR_GLOW,

OVERLAY_MULTI_NEUTRONIUM,
OVERLAY_MULTI_NEUTRONIUM_GLOW,
OVERLAY_MULTI_NEUTRONIUM_ACTIVE,
OVERLAY_MULTI_NEUTRONIUM_ACTIVE_GLOW,

OVERLAY_MULTI_BLACKHOLE,
OVERLAY_MULTI_BLACKHOLE_GLOW,
OVERLAY_MULTI_BLACKHOLE_ACTIVE,
OVERLAY_MULTI_BLACKHOLE_ACTIVE_GLOW,
OVERLAY_MULTI_BLACKHOLE_UNSTABLE,
OVERLAY_MULTI_BLACKHOLE_UNSTABLE_GLOW,

OVERLAY_FRONT_INDUSTRIAL_EXTRACTOR,
OVERLAY_FRONT_INDUSTRIAL_EXTRACTOR_ACTIVE,
OVERLAY_FRONT_INDUSTRIAL_EXTRACTOR_ACTIVE_GLOW,
Expand Down Expand Up @@ -1343,9 +1358,6 @@ public enum BlockIcons implements IIconContainer, Runnable {
OVERLAY_HATCH_PH_SENSOR,
OVERLAY_HATCH_PH_SENSOR_GLOW,

OVERLAY_HATCH_BLACKHOLE,
OVERLAY_HATCH_BLACKHOLE_GLOW,

STRUCTURE_MARK,

MV_TOP_CYCLOTRON_SOLENOID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static gregtech.api.metatileentity.BaseTileEntity.STALLED_VENT_TOOLTIP;
import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY;
import static gregtech.api.metatileentity.BaseTileEntity.UNUSED_SLOT_TOOLTIP;
import static gregtech.api.util.GTRecipeConstants.COMPRESSION_TIER;
import static gregtech.api.util.GTRecipeConstants.EXPLODE;
import static gregtech.api.util.GTRecipeConstants.ON_FIRE;
import static gregtech.api.util.GTUtility.moveMultipleItemStacks;
Expand Down Expand Up @@ -1078,7 +1079,7 @@ public int checkRecipe(boolean skipOC) {
getBaseMetaTileEntity().setOnFire();
return DID_NOT_FIND_RECIPE;
}

if (tRecipe.getMetadataOrDefault(COMPRESSION_TIER, 0) > 0) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
if (GTMod.gregtechproxy.mLowGravProcessing && (tRecipe.mSpecialValue == -100 || tRecipe.mSpecialValue == -300)
&& !isValidForLowGravity(tRecipe, getBaseMetaTileEntity().getWorld().provider.dimensionId))
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/common/GTClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import gregtech.client.SeekingOggCodec;
import gregtech.common.blocks.BlockFrameBox;
import gregtech.common.blocks.ItemMachines;
import gregtech.common.render.BlackholeRenderer;
import gregtech.common.render.DroneRender;
import gregtech.common.render.FlaskRenderer;
import gregtech.common.render.FluidDisplayStackRenderer;
Expand Down Expand Up @@ -631,6 +632,7 @@ public void onLoad() {
new DroneRender();
new LaserRenderer();
new WormholeRenderer();
new BlackholeRenderer();

metaGeneratedItemRenderer = new MetaGeneratedItemRenderer();
for (MetaGeneratedItem item : MetaGeneratedItem.sInstances.values()) {
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/gregtech/common/blocks/BlockBlackholeRenderer.java
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;
}

}
4 changes: 2 additions & 2 deletions src/main/java/gregtech/common/items/MetaGeneratedItem01.java
Original file line number Diff line number Diff line change
Expand Up @@ -3203,14 +3203,14 @@ public MetaGeneratedItem01() {
ItemList.Black_Hole_Opener.set(
addItem(
Black_Hole_Opener.ID,
"Black Hole Activation Catalyst",
"Black Hole Seed",
"Opens a semi-stable black hole",
new TCAspects.TC_AspectStack(TCAspects.ALIENIS, 32),
new TCAspects.TC_AspectStack(TCAspects.ORDO, 64)));
ItemList.Black_Hole_Closer.set(
addItem(
Black_Hole_Closer.ID,
"Black Hole Deactivation Catalyst",
"Black Hole Collapser",
"Safely closes a semi-stable black hole",
new TCAspects.TC_AspectStack(TCAspects.ALIENIS, 32),
new TCAspects.TC_AspectStack(TCAspects.PERDITIO, 64)));
Expand Down
222 changes: 222 additions & 0 deletions src/main/java/gregtech/common/render/BlackholeRenderer.java
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);

}

}
Loading

0 comments on commit f2c0a4f

Please sign in to comment.