mirror of
https://github.com/GTNewHorizons/Eternal-Singularity.git
synced 2026-11-19 03:39:17 +00:00
This commit is contained in:
1 parent
c02fcba4f1
commit
371c8a53f6
10 files changed
+30
-386
No files matched your search
+4
-3
@@ -1,9 +1,10 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.0-GTNH:dev")
|
||||
implementation("com.github.GTNewHorizons:Avaritia:1.75:dev")
|
||||
implementation("com.github.GTNewHorizons:Universal-Singularities:8.10.0:dev")
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.8.34")
|
||||
implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.44-GTNH:dev")
|
||||
implementation("com.github.GTNewHorizons:Avaritia:1.78:dev")
|
||||
implementation("com.github.GTNewHorizons:Universal-Singularities:8.12.0:dev")
|
||||
implementation("com.github.GTNewHorizons:WanionLib:1.10.0:dev")
|
||||
compileOnly("com.github.GTNewHorizons:CraftTweaker:3.4.2:dev") // optional
|
||||
}
|
||||
@@ -30,9 +30,6 @@ import singulariteam.eternalsingularity.proxy.CommonProxy;
|
||||
dependencies = "required-after:Avaritia;required-after:wanionlib@[1.7.10-1.3,);after:thermsingul;after:universalsingularities;after:aobdsingularities")
|
||||
public class EternalSingularityMod {
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static EternalSingularityMod instance;
|
||||
|
||||
public static Logger logger;
|
||||
|
||||
@SidedProxy(serverSide = COMMON_PROXY, clientSide = CLIENT_PROXY)
|
||||
|
||||
@@ -4,21 +4,14 @@ import net.minecraftforge.client.MinecraftForgeClient;
|
||||
|
||||
import singulariteam.eternalsingularity.item.EternalSingularityItem;
|
||||
import singulariteam.eternalsingularity.render.EternalItemRenderer;
|
||||
import singulariteam.eternalsingularity.render.ShaderHelper;
|
||||
|
||||
public final class ClientProxy extends CommonProxy {
|
||||
|
||||
EternalItemRenderer fancies = new EternalItemRenderer();
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
MinecraftForgeClient.registerItemRenderer(EternalSingularityItem.instance, fancies);
|
||||
ShaderHelper.initShaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
super.postInit();
|
||||
EternalItemRenderer fancies = new EternalItemRenderer();
|
||||
MinecraftForgeClient.registerItemRenderer(EternalSingularityItem.instance, fancies);
|
||||
if (compoundSingularityItem != null)
|
||||
MinecraftForgeClient.registerItemRenderer(compoundSingularityItem, fancies);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import singulariteam.eternalsingularity.item.EternalSingularityItem;
|
||||
public class CommonProxy {
|
||||
|
||||
private static ShapelessOreRecipe eternalSingularityRecipe = null;
|
||||
private static final Set<Class<?>> classSet = new HashSet<>();
|
||||
private static Set<Class<?>> classSet = new HashSet<>();
|
||||
protected CompoundSingularityItem compoundSingularityItem = null;
|
||||
private File configFile;
|
||||
|
||||
@@ -63,7 +63,6 @@ public class CommonProxy {
|
||||
return eternalSingularityRecipe;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void postInit() {
|
||||
if (classSet.isEmpty() || craftingOnly) return;
|
||||
final List<ItemStack> singularities = new ArrayList<>();
|
||||
@@ -97,7 +96,7 @@ public class CommonProxy {
|
||||
new ItemStack(
|
||||
EternalSingularityItem.instance,
|
||||
easyMode ? MathHelper.clamp_int(compoundMax, 1, 64) : 1))).getInput().addAll(singularities);
|
||||
if (useCompoundSingularities) {
|
||||
if (true) {
|
||||
GameRegistry.registerItem(
|
||||
compoundSingularityItem = new CompoundSingularityItem(compoundMax),
|
||||
"combined_singularity");
|
||||
@@ -112,7 +111,7 @@ public class CommonProxy {
|
||||
if (!(input instanceof ItemStack)) continue;
|
||||
compoundRecipe.getInput().add(((ItemStack) input).copy());
|
||||
}
|
||||
if (compoundRecipe.getInput().size() > 0) GameRegistry.addRecipe(compoundRecipe);
|
||||
if (!compoundRecipe.getInput().isEmpty()) GameRegistry.addRecipe(compoundRecipe);
|
||||
}
|
||||
eternalSingularityRecipeInputs.clear();
|
||||
for (int i = 0; i < compoundMax; i++)
|
||||
@@ -120,5 +119,7 @@ public class CommonProxy {
|
||||
}
|
||||
ExtremeCraftingManager.getInstance().getRecipeList().add(eternalSingularityRecipe);
|
||||
Grinder.catalyst.getInput().add(new ItemStack(EternalSingularityItem.instance));
|
||||
|
||||
classSet = null;
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package singulariteam.eternalsingularity.render;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import fox.spiteful.avaritia.render.LudicrousRenderEvents;
|
||||
|
||||
public class CosmicRenderStuffs {
|
||||
|
||||
public static final ShaderCallback shaderCallback;
|
||||
|
||||
public static float[] lightlevel = new float[3];
|
||||
|
||||
public static String[] lightmapobf = new String[] { "lightmapColors", "field_78504_Q", "U" };
|
||||
public static boolean inventoryRender = false;
|
||||
public static float cosmicOpacity = 1.0f;
|
||||
|
||||
static {
|
||||
shaderCallback = new ShaderCallback() {
|
||||
|
||||
@Override
|
||||
public void call(int shader) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
float yaw = 0;
|
||||
float pitch = 0;
|
||||
float scale = 1.0f;
|
||||
|
||||
if (!inventoryRender) {
|
||||
yaw = (float) ((mc.thePlayer.rotationYaw * 2 * Math.PI) / 360.0);
|
||||
pitch = -(float) ((mc.thePlayer.rotationPitch * 2 * Math.PI) / 360.0);
|
||||
} else {
|
||||
scale = 25.0f;
|
||||
}
|
||||
|
||||
int time2 = ARBShaderObjects.glGetUniformLocationARB(shader, "time2");
|
||||
ARBShaderObjects.glUniform1fARB(time2, mc.thePlayer.ticksExisted);
|
||||
|
||||
int x = ARBShaderObjects.glGetUniformLocationARB(shader, "yaw");
|
||||
ARBShaderObjects.glUniform1fARB(x, yaw);
|
||||
|
||||
int z = ARBShaderObjects.glGetUniformLocationARB(shader, "pitch");
|
||||
ARBShaderObjects.glUniform1fARB(z, pitch);
|
||||
|
||||
int l = ARBShaderObjects.glGetUniformLocationARB(shader, "lightlevel");
|
||||
ARBShaderObjects.glUniform3fARB(l, lightlevel[0], lightlevel[1], lightlevel[2]);
|
||||
|
||||
int lightmix = ARBShaderObjects.glGetUniformLocationARB(shader, "lightmix");
|
||||
ARBShaderObjects.glUniform1fARB(lightmix, 0.2f);
|
||||
|
||||
int uvs = ARBShaderObjects.glGetUniformLocationARB(shader, "cosmicuvs");
|
||||
ARBShaderObjects.glUniformMatrix2ARB(uvs, false, LudicrousRenderEvents.cosmicUVs);
|
||||
|
||||
int s = ARBShaderObjects.glGetUniformLocationARB(shader, "externalScale");
|
||||
ARBShaderObjects.glUniform1fARB(s, scale);
|
||||
|
||||
int o = ARBShaderObjects.glGetUniformLocationARB(shader, "opacity");
|
||||
ARBShaderObjects.glUniform1fARB(o, cosmicOpacity);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void useShader() {
|
||||
ShaderHelper.useShader(ShaderHelper.cosmicShader, shaderCallback);
|
||||
}
|
||||
|
||||
public static void releaseShader() {
|
||||
ShaderHelper.releaseShader();
|
||||
}
|
||||
|
||||
private static Field mapfield = ReflectionHelper.findField(EntityRenderer.class, lightmapobf);
|
||||
|
||||
public static void setLightFromLocation(World world, int x, int y, int z) {
|
||||
if (world == null) {
|
||||
setLightLevel(1.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
int[] map = null;
|
||||
try {
|
||||
map = (int[]) mapfield.get(Minecraft.getMinecraft().entityRenderer);
|
||||
} catch (Exception e) {}
|
||||
if (map == null) {
|
||||
setLightLevel(1.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
setLightLevel(1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
public static void setLightLevel(float level) {
|
||||
setLightLevel(level, level, level);
|
||||
}
|
||||
|
||||
public static void setLightLevel(float r, float g, float b) {
|
||||
lightlevel[0] = Math.max(0.0f, Math.min(1.0f, r));
|
||||
lightlevel[1] = Math.max(0.0f, Math.min(1.0f, g));
|
||||
lightlevel[2] = Math.max(0.0f, Math.min(1.0f, b));
|
||||
}
|
||||
|
||||
public static void bindItemTexture() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.renderEngine.bindTexture(TextureMap.locationItemsTexture);
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
@@ -18,16 +18,18 @@ import net.minecraftforge.client.IItemRenderer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.postprocessing.shaders.UniversiumShader;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.shader.ShaderProgram;
|
||||
|
||||
import fox.spiteful.avaritia.render.ICosmicRenderItem;
|
||||
import fox.spiteful.avaritia.render.IHaloRenderItem;
|
||||
|
||||
public class EternalItemRenderer implements IItemRenderer {
|
||||
|
||||
public Random rand = new Random();
|
||||
public final Random rand = new Random();
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
// return type != ItemRenderType.INVENTORY;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,9 +47,8 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
IIcon halo = null;
|
||||
int haloColour = 0;
|
||||
|
||||
net.minecraft.item.Item itype = item.getItem();
|
||||
if (itype instanceof IHaloRenderItem) {
|
||||
IHaloRenderItem ihri = (IHaloRenderItem) itype;
|
||||
Item itype = item.getItem();
|
||||
if (itype instanceof IHaloRenderItem ihri) {
|
||||
|
||||
spread = ihri.getHaloSize(item);
|
||||
halo = ihri.getHaloTexture(item);
|
||||
@@ -61,7 +62,6 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
Tessellator t = Tessellator.instance;
|
||||
this.processLightLevel(type, item, data);
|
||||
// ShaderHelper.useShader(ShaderHelper.testShader, this.shaderCallback);
|
||||
switch (type) {
|
||||
case ENTITY: {
|
||||
GL11.glPushMatrix();
|
||||
@@ -69,19 +69,13 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
if (item.isOnItemFrame()) GL11.glTranslatef(0F, -0.3F, 0.01F);
|
||||
render(item, null);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
break;
|
||||
}
|
||||
case EQUIPPED: {
|
||||
render(item, data[1] instanceof EntityPlayer ? (EntityPlayer) data[1] : null);
|
||||
break;
|
||||
}
|
||||
case EQUIPPED_FIRST_PERSON: {
|
||||
case EQUIPPED, EQUIPPED_FIRST_PERSON: {
|
||||
render(item, data[1] instanceof EntityPlayer ? (EntityPlayer) data[1] : null);
|
||||
break;
|
||||
}
|
||||
case INVENTORY: {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
@@ -127,28 +121,7 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
|
||||
r.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);
|
||||
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
r.renderWithColor = true;
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
// middle?
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
r.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);
|
||||
|
||||
if (item.getItem() instanceof ICosmicRenderItem) {
|
||||
if (item.getItem() instanceof ICosmicRenderItem icri) {
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
@@ -156,15 +129,12 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
ICosmicRenderItem icri = (ICosmicRenderItem) (item.getItem());
|
||||
|
||||
CosmicRenderStuffs.cosmicOpacity = icri.getMaskMultiplier(item, null);
|
||||
CosmicRenderStuffs.inventoryRender = true;
|
||||
CosmicRenderStuffs.useShader();
|
||||
final float opacity = icri.getMaskMultiplier(item, mc.thePlayer);
|
||||
UniversiumShader.getInstance().setCosmicOpacity(opacity).setRenderInInventory().use();
|
||||
|
||||
IIcon cosmicicon = icri.getMaskTexture(item, null);
|
||||
|
||||
GL11.glColor4d(1, 1, 1, 1);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
float minu = cosmicicon.getMinU();
|
||||
float maxu = cosmicicon.getMaxU();
|
||||
@@ -178,8 +148,7 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
t.addVertexWithUV(16, 0, 0, maxu, minv);
|
||||
t.draw();
|
||||
|
||||
CosmicRenderStuffs.releaseShader();
|
||||
CosmicRenderStuffs.inventoryRender = false;
|
||||
ShaderProgram.unbind();
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
@@ -189,15 +158,11 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
r.renderWithColor = true;
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// ShaderHelper.releaseShader();
|
||||
|
||||
// Lumberjack.log(Level.INFO, light+"");
|
||||
}
|
||||
|
||||
public void render(ItemStack item, EntityPlayer player) {
|
||||
@@ -206,24 +171,17 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
passes = item.getItem().getRenderPasses(item.getItemDamage());
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
// ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(),
|
||||
// scale);
|
||||
|
||||
IIcon icon;
|
||||
float f, f1, f2, f3;
|
||||
float scale = 1F / 16F;
|
||||
|
||||
// Lumberjack.log(Level.INFO, "passes: "+passes);
|
||||
|
||||
for (int i = 0; i < passes; i++) {
|
||||
icon = this.getStackIcon(item, i, player);
|
||||
|
||||
// Lumberjack.log(Level.INFO, "icon "+i+": "+icon);
|
||||
|
||||
f = icon.getMinU();
|
||||
f1 = icon.getMaxU();
|
||||
f2 = icon.getMinV();
|
||||
@@ -245,8 +203,8 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDepthFunc(GL11.GL_EQUAL);
|
||||
ICosmicRenderItem icri = (ICosmicRenderItem) (item.getItem());
|
||||
CosmicRenderStuffs.cosmicOpacity = icri.getMaskMultiplier(item, player);
|
||||
CosmicRenderStuffs.useShader();
|
||||
final float opacity = icri.getMaskMultiplier(item, player);
|
||||
UniversiumShader.getInstance().setCosmicOpacity(opacity).use();
|
||||
|
||||
IIcon cosmicicon = icri.getMaskTexture(item, player);
|
||||
|
||||
@@ -263,34 +221,22 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
cosmicicon.getIconWidth(),
|
||||
cosmicicon.getIconHeight(),
|
||||
scale);
|
||||
CosmicRenderStuffs.releaseShader();
|
||||
ShaderProgram.unbind();
|
||||
GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
}
|
||||
|
||||
public void processLightLevel(ItemRenderType type, ItemStack item, Object... data) {
|
||||
switch (type) {
|
||||
case ENTITY: {
|
||||
EntityItem ent = (EntityItem) (data[1]);
|
||||
if (ent != null) {
|
||||
CosmicRenderStuffs.setLightFromLocation(
|
||||
ent.worldObj,
|
||||
MathHelper.floor_double(ent.posX),
|
||||
MathHelper.floor_double(ent.posY),
|
||||
MathHelper.floor_double(ent.posZ));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EQUIPPED: {
|
||||
case ENTITY, EQUIPPED, EQUIPPED_FIRST_PERSON: {
|
||||
EntityLivingBase ent = (EntityLivingBase) (data[1]);
|
||||
if (ent != null) {
|
||||
CosmicRenderStuffs.setLightFromLocation(
|
||||
UniversiumShader.getInstance().setLightFromLocation(
|
||||
ent.worldObj,
|
||||
MathHelper.floor_double(ent.posX),
|
||||
MathHelper.floor_double(ent.posY),
|
||||
@@ -298,24 +244,8 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EQUIPPED_FIRST_PERSON: {
|
||||
EntityLivingBase ent = (EntityLivingBase) (data[1]);
|
||||
if (ent != null) {
|
||||
CosmicRenderStuffs.setLightFromLocation(
|
||||
ent.worldObj,
|
||||
MathHelper.floor_double(ent.posX),
|
||||
MathHelper.floor_double(ent.posY),
|
||||
MathHelper.floor_double(ent.posZ));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case INVENTORY: {
|
||||
CosmicRenderStuffs.setLightLevel(1.2f);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
CosmicRenderStuffs.setLightLevel(1.0f);
|
||||
return;
|
||||
UniversiumShader.getInstance().setLightLevel(1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package singulariteam.eternalsingularity.render;
|
||||
|
||||
public abstract class ShaderCallback {
|
||||
|
||||
public abstract void call(int paramInt);
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package singulariteam.eternalsingularity.render;
|
||||
|
||||
// import fox.spiteful.avaritia.Lumberjack;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
|
||||
import org.lwjgl.opengl.ARBFragmentShader;
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
import org.lwjgl.opengl.ARBVertexShader;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public final class ShaderHelper {
|
||||
|
||||
private static final int VERT = ARBVertexShader.GL_VERTEX_SHADER_ARB;
|
||||
private static final int FRAG = ARBFragmentShader.GL_FRAGMENT_SHADER_ARB;
|
||||
private static final String PREFIX = "/assets/eternalsingularity/shader/";
|
||||
|
||||
public static int cosmicShader = 0;
|
||||
|
||||
public static void initShaders() {
|
||||
if (!useShaders()) return;
|
||||
|
||||
cosmicShader = createProgram("cosmic.vert", "cosmic.frag");
|
||||
}
|
||||
|
||||
public static void useShader(int shader, ShaderCallback callback) {
|
||||
if (!useShaders()) return;
|
||||
|
||||
ARBShaderObjects.glUseProgramObjectARB(shader);
|
||||
|
||||
if (shader != 0) {
|
||||
int time = ARBShaderObjects.glGetUniformLocationARB(shader, "time");
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.thePlayer != null && mc.thePlayer.worldObj != null) {
|
||||
ARBShaderObjects.glUniform1iARB(time, (int) (mc.thePlayer.worldObj.getWorldTime() % Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
if (callback != null) callback.call(shader);
|
||||
}
|
||||
}
|
||||
|
||||
public static void useShader(int shader) {
|
||||
useShader(shader, null);
|
||||
}
|
||||
|
||||
public static void releaseShader() {
|
||||
useShader(0);
|
||||
}
|
||||
|
||||
public static boolean useShaders() {
|
||||
return OpenGlHelper.shadersSupported;
|
||||
}
|
||||
|
||||
// Most of the code taken from the LWJGL wiki
|
||||
// http://lwjgl.org/wiki/index.php?title=GLSL_Shaders_with_LWJGL
|
||||
|
||||
private static int createProgram(String vert, String frag) {
|
||||
int vertId = 0, fragId = 0, program = 0;
|
||||
if (vert != null) vertId = createShader(PREFIX + vert, VERT);
|
||||
if (frag != null) fragId = createShader(PREFIX + frag, FRAG);
|
||||
|
||||
program = ARBShaderObjects.glCreateProgramObjectARB();
|
||||
if (program == 0) return 0;
|
||||
|
||||
if (vert != null) ARBShaderObjects.glAttachObjectARB(program, vertId);
|
||||
if (frag != null) ARBShaderObjects.glAttachObjectARB(program, fragId);
|
||||
|
||||
ARBShaderObjects.glLinkProgramARB(program);
|
||||
if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB)
|
||||
== GL11.GL_FALSE) {
|
||||
// Lumberjack.log(Level.ERROR, getLogInfo(program));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ARBShaderObjects.glValidateProgramARB(program);
|
||||
if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB)
|
||||
== GL11.GL_FALSE) {
|
||||
// Lumberjack.log(Level.ERROR, getLogInfo(program));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
private static int createShader(String filename, int shaderType) {
|
||||
int shader = 0;
|
||||
try {
|
||||
shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);
|
||||
|
||||
if (shader == 0) return 0;
|
||||
|
||||
ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
|
||||
ARBShaderObjects.glCompileShaderARB(shader);
|
||||
|
||||
if (ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB)
|
||||
== GL11.GL_FALSE)
|
||||
throw new RuntimeException("Error creating shader \"" + filename + "\": " + getLogInfo(shader));
|
||||
|
||||
return shader;
|
||||
} catch (Exception e) {
|
||||
ARBShaderObjects.glDeleteObjectARB(shader);
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLogInfo(int obj) {
|
||||
return ARBShaderObjects.glGetInfoLogARB(
|
||||
obj,
|
||||
ARBShaderObjects.glGetObjectParameteriARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB));
|
||||
}
|
||||
|
||||
private static String readFileAsString(String filename) throws Exception {
|
||||
StringBuilder source = new StringBuilder();
|
||||
InputStream in = ShaderHelper.class.getResourceAsStream(filename);
|
||||
Exception exception = null;
|
||||
BufferedReader reader;
|
||||
|
||||
if (in == null) return "";
|
||||
|
||||
try {
|
||||
reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
||||
|
||||
Exception innerExc = null;
|
||||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) source.append(line).append('\n');
|
||||
} catch (Exception exc) {
|
||||
exception = exc;
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (Exception exc) {
|
||||
if (innerExc == null) innerExc = exc;
|
||||
else exc.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (innerExc != null) throw innerExc;
|
||||
} catch (Exception exc) {
|
||||
exception = exc;
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception exc) {
|
||||
if (exception == null) exception = exc;
|
||||
else exc.printStackTrace();
|
||||
}
|
||||
|
||||
if (exception != null) throw exception;
|
||||
}
|
||||
|
||||
return source.toString();
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 215 B After Width: | Height: | Size: 151 B |
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.5 KiB |
Reference in new issue
Block a user