Skip to content

Commit

Permalink
Basic Scent System
Browse files Browse the repository at this point in the history
Possible Fix For Necromancer Crash
  • Loading branch information
sirolf2009 committed Sep 3, 2013
1 parent 747ba63 commit d17996b
Show file tree
Hide file tree
Showing 30 changed files with 947 additions and 330 deletions.
132 changes: 132 additions & 0 deletions common/com/sirolf2009/necromancy/Necromancy.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.sirolf2009.necromancy;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.logging.Logger;

import org.lwjgl.opengl.ARBFragmentShader;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.ARBVertexShader;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.server.dedicated.PropertyManager;
import net.minecraftforge.common.MinecraftForge;
Expand Down Expand Up @@ -47,6 +58,8 @@ public class Necromancy {
public static final CreativeTabs tabNecromancy = new CreativeTabNecro(CreativeTabs.getNextID(), "Necromancy", 1).setBackgroundImageName("necro_gui.png");
public static final CreativeTabs tabNecromancyBodyParts = new CreativeTabNecro(CreativeTabs.getNextID(), "BodyParts", 2).setBackgroundImageName("necro_gui.png");

public int scentProgram;

public static List<String> specialFolk = new ArrayList<String>();

public static int maxSpawn = -1;
Expand All @@ -66,6 +79,19 @@ public class Necromancy {
public void preInit(FMLPreInitializationEvent event) {
loggerNecromancy = Logger.getLogger("necromancy");
loggerNecromancy.setParent(FMLLog.getLogger());

try {
int vertShader = loadShader("assets/necromancy/shaders/scent/scentFragment.shader",GL20.GL_VERTEX_SHADER);
int fragShader = loadShader("assets/necromancy/shaders/scent/scentVertex.shader",GL20.GL_FRAGMENT_SHADER);
int scentProgram = GL20.glCreateProgram();
GL20.glAttachShader(scentProgram, vertShader);
GL20.glAttachShader(scentProgram, fragShader);
GL20.glLinkProgram(scentProgram);
GL20.glValidateProgram(scentProgram);
} catch (Exception e1) {
e1.printStackTrace();
System.exit(-1);
}

ConfigurationNecromancy.initProperties(event);

Expand Down Expand Up @@ -129,4 +155,110 @@ private void init() {

GameRegistry.registerWorldGenerator(new WorldGenerator());
}

public int loadShader(String filename, int type) {
StringBuilder shaderSource = new StringBuilder();
int shaderID = 0;

try {
BufferedReader reader = new BufferedReader(new FileReader(getClass().getClassLoader().getResource(filename).toURI().getPath()));
String line;
while ((line = reader.readLine()) != null) {
shaderSource.append(line).append("\n");
}
reader.close();
} catch (IOException e) {
System.err.println("Could not read file.");
e.printStackTrace();
System.exit(-1);
} catch (URISyntaxException e) {
System.err.println("Could not read file.");
e.printStackTrace();
System.exit(-1);
}

shaderID = GL20.glCreateShader(type);
GL20.glShaderSource(shaderID, shaderSource);
GL20.glCompileShader(shaderID);

return shaderID;
}

private int createShader(String filename, int shaderType) throws Exception {
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: " + ARBShaderObjects.glGetInfoLogARB(shader, ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB)));

return shader;
}
catch(Exception exc) {
ARBShaderObjects.glDeleteObjectARB(shader);
throw exc;
}
}

private String readFileAsString(String filename) throws Exception {
StringBuilder source = new StringBuilder();

FileInputStream in = new FileInputStream(getClass().getClassLoader().getResource(filename).toURI().getPath());

Exception exception = null;

BufferedReader reader;
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();
}
}
12 changes: 10 additions & 2 deletions common/com/sirolf2009/necromancy/block/BlockNecromancy.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.sirolf2009.necromancy.item.ItemGeneric;
import com.sirolf2009.necromancy.lib.ConfigurationNecromancy;
import com.sirolf2009.necromancy.tileentity.TileEntityAltar;
import com.sirolf2009.necromancy.tileentity.TileEntityScent;
import com.sirolf2009.necromancy.tileentity.TileEntityScentBurner;
import com.sirolf2009.necromancy.tileentity.TileEntitySewing;

Expand All @@ -22,6 +23,7 @@ public class BlockNecromancy {
public static Block altarBlock;
public static Block sewing;
public static Block scentBurner;
public static Block scent;
public static BlockBlood blood;

public static Fluid fluidBlood;
Expand All @@ -43,13 +45,19 @@ public static void initBlocks() {
GameRegistry.registerBlock(sewing, "Sewing Machine");
GameRegistry.registerTileEntity(TileEntitySewing.class, "Sewing");
LanguageRegistry.addName(sewing, "Sewing Machine");

scentBurner = new BlockScentBurner(ConfigurationNecromancy.ScentBurnerID).setHardness(4);
sewing.setUnlocalizedName("Scent Burner");
scentBurner.setUnlocalizedName("Scent Burner");
GameRegistry.registerBlock(scentBurner, "Scent Burner");
GameRegistry.registerTileEntity(TileEntityScentBurner.class, "Scent Burner");
LanguageRegistry.addName(scentBurner, "Scent Burner [WIP]");

scent = new BlockScent(ConfigurationNecromancy.ScentID);
scent.setUnlocalizedName("Scent");
GameRegistry.registerBlock(scent, "Scent");
GameRegistry.registerTileEntity(TileEntityScent.class, "Scent");
LanguageRegistry.addName(scent, "Scent");

fluidBlood = new Fluid("Blood");
FluidRegistry.registerFluid(fluidBlood);
fluidBlood.setBlockID(ConfigurationNecromancy.BloodID);
Expand Down
91 changes: 91 additions & 0 deletions common/com/sirolf2009/necromancy/block/BlockScent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.sirolf2009.necromancy.block;

import java.awt.Color;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.world.ColorizerFoliage;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import com.sirolf2009.necromancy.Necromancy;
import com.sirolf2009.necromancy.client.renderer.RenderScent;
import com.sirolf2009.necromancy.entity.EntityMinion;
import com.sirolf2009.necromancy.tileentity.TileEntityAltar;
import com.sirolf2009.necromancy.tileentity.TileEntityScent;
import com.sirolf2009.necromancy.tileentity.TileEntitySewing;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockScent extends Block implements ITileEntityProvider {

private Icon[] icons;

public BlockScent(int i) {
super(i, Material.air);
this.setCreativeTab(Necromancy.tabNecromancy);
func_111022_d("necromancy:scent");
}

public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) {
par1World.markBlockForRenderUpdate(par2, par3, par4);
}

public TileEntity createNewTileEntity(World par1World) {
return new TileEntityScent();
}

@Override
public boolean isOpaqueCube() {
return false;
}

@Override
public boolean renderAsNormalBlock() {
return false;
}

@Override
public int getRenderType() {
return RenderScent.renderID;
}

public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) {
return null;
}

@Override
public boolean canRenderInPass(int pass) {
RenderScent.renderPass = pass;
return pass == 0;
}

@Override
public int getRenderBlockPass() {
return 0;
}

public void registerIcons(IconRegister par1IconRegister) {
icons = new Icon[4];
for(int i = 0; i < 4; i++) {
icons[i] = par1IconRegister.registerIcon("necromancy:scent"+i);
}
}

public Icon getIcon(int par1, int par2) {
return icons[par2];
}
}
6 changes: 3 additions & 3 deletions common/com/sirolf2009/necromancy/block/BlockScentBurner.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public BlockScentBurner(int par1) {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int idk, float what, float these, float are) {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity == null || player.isSneaking())
return false;
else {
if (tileEntity != null && !player.isSneaking()) {
player.openGui(Necromancy.Instance, guiID, world, x, y, z);
return true;
}
super.onBlockActivated(world, x, y, z, player, idk, what, these, are);
return false;
}

@Override
Expand Down
18 changes: 16 additions & 2 deletions common/com/sirolf2009/necromancy/client/gui/GuiScentBurner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;
Expand All @@ -15,9 +16,12 @@
import com.sirolf2009.necromancy.tileentity.TileEntitySewing;

public class GuiScentBurner extends GuiContainer {

public TileEntityScentBurner burner;

public GuiScentBurner(InventoryPlayer par1InventoryPlayer, TileEntityScentBurner par2TileEntitySewing) {
super(new ContainerScentBurner(par1InventoryPlayer, par2TileEntitySewing));
public GuiScentBurner(InventoryPlayer par1InventoryPlayer, TileEntityScentBurner par2TileEntityScentBurner) {
super(new ContainerScentBurner(par1InventoryPlayer, par2TileEntityScentBurner));
burner = par2TileEntityScentBurner;
}

@Override
Expand All @@ -32,5 +36,15 @@ protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
int var5 = (width - xSize) / 2;
int var6 = (height - ySize) / 2;
drawTexturedModalRect(var5, var6, 0, 0, xSize, ySize);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int i1;

if (this.burner.isBurning)
{
i1 = 200;
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.util.ResourceLocation;

import com.sirolf2009.necromancy.entity.EntityIsaacBody;
import com.sirolf2009.necromancy.lib.ReferenceNecromancy;

public class RenderIsaac extends RenderLiving {

Expand All @@ -31,6 +32,6 @@ public void renderIsaacNormal(EntityLiving em, double d1, double d2, double d3,

@Override
protected ResourceLocation func_110775_a(Entity entity) {
return new ResourceLocation("necromancy:textures/entities/Isaac.png");
return ReferenceNecromancy.TEXTURES_ENTITIES_ISAAC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.util.ResourceLocation;

import com.sirolf2009.necromancy.entity.EntityIsaacBody;
import com.sirolf2009.necromancy.lib.ReferenceNecromancy;

public class RenderIsaacBlood extends RenderLiving {

Expand All @@ -31,6 +32,6 @@ public void renderIsaacNormal(EntityLiving em, double d1, double d2, double d3,

@Override
protected ResourceLocation func_110775_a(Entity entity) {
return new ResourceLocation("necromancy:textures/entities/IsaacBlood.png");
return ReferenceNecromancy.TEXTURES_ENTITIES_ISAACBLOOD;
}
}
Loading

0 comments on commit d17996b

Please sign in to comment.