Jump to content

Recommended Posts

Posted

A texture with a circle drawn on it and rendered so that it always faces the player doesn't require much know how, just a little trig

 

I don't know if i come up like an idiot if i say this, but i seriously have no idea :S

Really, i don't even know where to start. Trigonometry is fine for me. Just a pen and paper is enough to find out the perfect numbers. I just have no idea how to start the rendering process of something, anything. The only thing that i know about OpenGL is that it uses some primitives ( Lines, Points, Quads, Polygons ... ) to draw complex (in case of minecraft, very simple) objects. I don't know, however, how OpenGL does this.

So your black hole is entity, right?

First, try to render simple model in place of black hole. For that, just google entity rendering and a lot of tutorials will show up.

When you will know how to render simple model for your entity, you can start making complex renderers.

Posted

Well, apparently i was much more of an idiot than i thought. I had forgotten to register my entity and everything that i did on my render class had no effect on game. It started to frustrate me though because checking everywhere for different things, trying them all out and getting nothing every time is very frustrating. After i registered my entity, i tried to render a square using a tessellator. Success on that. I didn't go through more testing and went back to jabelar's tutorial on rendering a sphere. The sphere does render however but only if you are close to it. Actually it only renders if you are in the radius that the entity has to suck on things. So as soon as you are affected by motion you can see the black hole, but not at any other place. I also figured that you can always see the sphere if you are above. No matter how high. As long as the fog doesn't block the view of course. Also if i point towards the entityBlackHole, every other entity turns black. also, sometimes the item that i currently am holding. I did some screenshots for each case.

 

You can always see the black hole from above, also every other entity is black:

http://prntscr.com/9mu8ve

 

When from the side you can only see the black hole if you are within its "sucking" range:

http://prntscr.com/9mu94u

 

When from the side you can't see the black hole if you are to far:

http://prntscr.com/9mu9h5

 

Renderer Code:

 

 

public class BlackHoleRenderer extends Render{

public BlackHoleRenderer() {
	super(Minecraft.getMinecraft().getRenderManager());
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return new ResourceLocation(AdvancedElectronics.MODID+":textures/entities/bh.png");
}

@Override
public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks) {

	GL11.glPushMatrix();
    GL11.glTranslated(x, y + entity.height / 2, z);
    GL11.glScalef(1.0F, 1.0F, 1.0F);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDepthMask(false);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(0.0F, 0.0F, 0.0F, 1.0F);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glCallList(clientProxy.sphereIdOut);
    GL11.glCallList(clientProxy.sphereIdIn);
    GL11.glPopMatrix(); 

	super.doRender(entity, x, y, z, p_76986_8_, partialTicks);
}

}

 

 

EntityBlackHole Code:

 

 

public class EntityBlackHole extends Entity {

public EntityBlackHole(World worldIn) {
	super(worldIn);

}

private double Mass;
private double radius = Mass / 888.8888888888889;

@Override
public void onUpdate() {

	List<Entity> EntitiesAround = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.fromBounds
			(this.posX - 10 - radius, this.posY - 10 - radius, this.posZ - 10 - radius, 
			this.posX + 10 + radius, this.posY + 10 + radius, this.posZ + 10 + radius));

	for(Entity e : EntitiesAround){

		if(e instanceof EntityBlackHole && e != this){
			this.Mass += ((EntityBlackHole) e).Mass;
			worldObj.removeEntity(e);
		}else{

		double motionX = this.posX - (e.posX);
		double motionY = this.posY - (e.posY);
		double motionZ = this.posZ - (e.posZ);

		e.motionX = motionX * 0.1F;
		e.motionY = motionY * 0.1F;
		e.motionZ = motionZ * 0.1F;

		for(int i = -2; i <= 2; i++){
			if(e.posX >= this.posX + i 
			   && e.posY >= this.posY + i 
			   && e.posZ >= this.posZ + i){
				e.attackEntityFrom(DamageSource.generic, 7.5F);
			}
		}

		}
	}

	if(Mass >= 80000){
		if(!worldObj.isRemote){
		worldObj.removeEntity(this);
		worldObj.createExplosion(this, this.posX, this.posY, 
				this.posZ, 1000F, true);
		}
	}
	super.onUpdate();	
}

@Override
protected void entityInit() {
	// TODO Auto-generated method stub

}

@Override
protected void readEntityFromNBT(NBTTagCompound tagCompund) {
	tagCompund.getDouble("Mass");

}

@Override
protected void writeEntityToNBT(NBTTagCompound tagCompound) {
	tagCompound.setDouble("Mass", Mass);

}

}

 

 

clientProxy code:

 

 

public class clientProxy extends serverProxy{

public static int sphereIdOut;
public static int sphereIdIn;

@Override
public void registerRenderInfo(){
	ItemRenderer.registerItemRender();
	BlockRenderer.registerBlockRender();
	bhCallList();
	RenderingRegistry.registerEntityRenderingHandler(EntityBlackHole.class, new BlackHoleRenderer());
}

public void bhCallList(){
	 Sphere sphere = new Sphere();
       sphere.setDrawStyle(GLU.GLU_FILL);
       sphere.setNormals(GLU.GLU_SMOOTH);
       sphere.setOrientation(GLU.GLU_OUTSIDE);
       sphereIdOut = GL11.glGenLists(1);
       GL11.glNewList(sphereIdOut, GL11.GL_COMPILE);
       ResourceLocation rL = new ResourceLocation(AdvancedElectronics.MODID+":textures/entities/bh.png");
       Minecraft.getMinecraft().getTextureManager().bindTexture(rL);
       sphere.draw(0.5F, 16, 16);
       GL11.glEndList();
       sphere.setOrientation(GLU.GLU_INSIDE);
       sphereIdIn = GL11.glGenLists(1);
       GL11.glNewList(sphereIdIn, GL11.GL_COMPILE);
       Minecraft.getMinecraft().getTextureManager().bindTexture(rL);
       sphere.draw(0.5F, 32, 32);
       GL11.glEndList();  
}
}

Posted

Well, apparently i was much more of an idiot than i thought. I had forgotten to register my entity and everything that i did on my render class had no effect on game. It started to frustrate me though because checking everywhere for different things, trying them all out and getting nothing every time is very frustrating. After i registered my entity, i tried to render a square using a tessellator. Success on that. I didn't go through more testing and went back to jabelar's tutorial on rendering a sphere. The sphere does render however but only if you are close to it. Actually it only renders if you are in the radius that the entity has to suck on things. So as soon as you are affected by motion you can see the black hole, but not at any other place. I also figured that you can always see the sphere if you are above. No matter how high. As long as the fog doesn't block the view of course. Also if i point towards the entityBlackHole, every other entity turns black. also, sometimes the item that i currently am holding. I did some screenshots for each case.

 

You can always see the black hole from above, also every other entity is black:

http://prntscr.com/9mu8ve

 

When from the side you can only see the black hole if you are within its "sucking" range:

http://prntscr.com/9mu94u

 

When from the side you can't see the black hole if you are to far:

http://prntscr.com/9mu9h5

 

Renderer Code:

 

 

public class BlackHoleRenderer extends Render{

public BlackHoleRenderer() {
	super(Minecraft.getMinecraft().getRenderManager());
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return new ResourceLocation(AdvancedElectronics.MODID+":textures/entities/bh.png");
}

@Override
public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks) {

	GL11.glPushMatrix();
    GL11.glTranslated(x, y + entity.height / 2, z);
    GL11.glScalef(1.0F, 1.0F, 1.0F);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDepthMask(false);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(0.0F, 0.0F, 0.0F, 1.0F);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glCallList(clientProxy.sphereIdOut);
    GL11.glCallList(clientProxy.sphereIdIn);
    GL11.glPopMatrix(); 

	super.doRender(entity, x, y, z, p_76986_8_, partialTicks);
}

}

 

 

EntityBlackHole Code:

 

 

public class EntityBlackHole extends Entity {

public EntityBlackHole(World worldIn) {
	super(worldIn);

}

private double Mass;
private double radius = Mass / 888.8888888888889;

@Override
public void onUpdate() {

	List<Entity> EntitiesAround = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.fromBounds
			(this.posX - 10 - radius, this.posY - 10 - radius, this.posZ - 10 - radius, 
			this.posX + 10 + radius, this.posY + 10 + radius, this.posZ + 10 + radius));

	for(Entity e : EntitiesAround){

		if(e instanceof EntityBlackHole && e != this){
			this.Mass += ((EntityBlackHole) e).Mass;
			worldObj.removeEntity(e);
		}else{

		double motionX = this.posX - (e.posX);
		double motionY = this.posY - (e.posY);
		double motionZ = this.posZ - (e.posZ);

		e.motionX = motionX * 0.1F;
		e.motionY = motionY * 0.1F;
		e.motionZ = motionZ * 0.1F;

		for(int i = -2; i <= 2; i++){
			if(e.posX >= this.posX + i 
			   && e.posY >= this.posY + i 
			   && e.posZ >= this.posZ + i){
				e.attackEntityFrom(DamageSource.generic, 7.5F);
			}
		}

		}
	}

	if(Mass >= 80000){
		if(!worldObj.isRemote){
		worldObj.removeEntity(this);
		worldObj.createExplosion(this, this.posX, this.posY, 
				this.posZ, 1000F, true);
		}
	}
	super.onUpdate();	
}

@Override
protected void entityInit() {
	// TODO Auto-generated method stub

}

@Override
protected void readEntityFromNBT(NBTTagCompound tagCompund) {
	tagCompund.getDouble("Mass");

}

@Override
protected void writeEntityToNBT(NBTTagCompound tagCompound) {
	tagCompound.setDouble("Mass", Mass);

}

}

 

 

clientProxy code:

 

 

public class clientProxy extends serverProxy{

public static int sphereIdOut;
public static int sphereIdIn;

@Override
public void registerRenderInfo(){
	ItemRenderer.registerItemRender();
	BlockRenderer.registerBlockRender();
	bhCallList();
	RenderingRegistry.registerEntityRenderingHandler(EntityBlackHole.class, new BlackHoleRenderer());
}

public void bhCallList(){
	 Sphere sphere = new Sphere();
       sphere.setDrawStyle(GLU.GLU_FILL);
       sphere.setNormals(GLU.GLU_SMOOTH);
       sphere.setOrientation(GLU.GLU_OUTSIDE);
       sphereIdOut = GL11.glGenLists(1);
       GL11.glNewList(sphereIdOut, GL11.GL_COMPILE);
       ResourceLocation rL = new ResourceLocation(AdvancedElectronics.MODID+":textures/entities/bh.png");
       Minecraft.getMinecraft().getTextureManager().bindTexture(rL);
       sphere.draw(0.5F, 16, 16);
       GL11.glEndList();
       sphere.setOrientation(GLU.GLU_INSIDE);
       sphereIdIn = GL11.glGenLists(1);
       GL11.glNewList(sphereIdIn, GL11.GL_COMPILE);
       Minecraft.getMinecraft().getTextureManager().bindTexture(rL);
       sphere.draw(0.5F, 32, 32);
       GL11.glEndList();  
}
}

I'll say some notes, not sure if it will help though:

-Do you have do call

super.doRender

? If yes, then do it inside push/pop matrix.

-For rendering far, somewhere there must be render distance parameter. Not sure where, sorry. So, just google it.

Posted

@elix the super.doRender had no effect at all. Either removing it from the method, putting it inside or out Push/Pop matrix, it does nothing.

About the far thing. I am not sure if that is a thing. Can't find anything similar to "rendering far"

And yet it doesn't seem to me that render distance has to do anything with it, since i can see the sphere from up. No matter how much up i go i can see the sphere if i am directly above the entity. However if i am at the ground level (Calling ground level, the level in which entity is placed), i cannot see the sphere, unless the Black Hole starts pulling me in.

Posted

@elix the super.doRender had no effect at all. Either removing it from the method, putting it inside or out Push/Pop matrix, it does nothing.

About the far thing. I am not sure if that is a thing. Can't find anything similar to "rendering far"

And yet it doesn't seem to me that render distance has to do anything with it, since i can see the sphere from up. No matter how much up i go i can see the sphere if i am directly above the entity. However if i am at the ground level (Calling ground level, the level in which entity is placed), i cannot see the sphere, unless the Black Hole starts pulling me in.

http://lmgtfy.com/?q=minecraft+forge+changing+entity+render+distance

Posted

Elix that didn't work, i already did that before. I have no idea why sometimes is visible and sometimes it is not. I think that it has to do with GL11.glTranslate or something. I don't understand anything. Also, now for some reason, the entity stopped "pulling in items". It is probably not calling the "onUpdate" method. But why ?

 

EDIT: While on the "Pause" menu screen i can actually see the black hole sphere on the background. So when the game it's paused the sphere is rendered correctly.

 

@EventHandler
public void Init(FMLInitializationEvent event) {

	EntityRegistry.registerModEntity(EntityBlackHole.class, "entityBlackHole", 1, this.instance, 100, 5, false);
	proxy.registerRenderInfo();

}

Posted

I will step out of the rendering thing for awhile cause it's driving me nuts. Anyway, after messing up with random things in the renderer, for some reason, my "black-hole" is not giving motion to any nearby entities (It is not pulling anything). This is very weird and i can't think of a cause for this. Does the renderer affects entity methods? That is confusing.

 

My entity code:

 

 

package com.ae.entities;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

public class EntityBlackHole extends Entity {

public EntityBlackHole(World worldIn) {
	super(worldIn);

}

public double Mass;
private double radius = 0.2 % Mass;

@Override
public void onUpdate() {

	List<Entity> EntitiesAround = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.fromBounds
			(this.posX - 10 - radius, this.posY - 10 - radius, this.posZ - 10 - radius, 
			this.posX + 10 + radius, this.posY + 10 + radius, this.posZ + 10 + radius));

	for(Entity e : EntitiesAround){

		if(e instanceof EntityBlackHole && e != this){
			this.Mass += ((EntityBlackHole) e).Mass;
			worldObj.removeEntity(e);
			worldObj.createExplosion(e, e.posX, e.posY, e.posZ, 10.0F, true);
		}else{

		double motionX = this.posX - e.posX;
		double motionY = this.posY - e.posY;
		double motionZ = this.posZ - e.posZ;

		e.motionX = motionX * 0.1F;
		e.motionY = motionY * 0.1F;
		e.motionZ = motionZ * 0.1F;

		for(int i = -2; i <= 2; i++){
			if(e.posX >= this.posX + i 
			   && e.posY >= this.posY + i 
			   && e.posZ >= this.posZ + i){
				e.attackEntityFrom(DamageSource.generic, 7.5F);
			}
		}

		}
	}

	if(Mass >= 500000){
		worldObj.removeEntity(this);
		worldObj.createExplosion(this, this.posX, this.posY, 
				this.posZ, 1000F, true);
	}
	super.onUpdate();	
}

@Override
protected void entityInit() {
	// TODO Auto-generated method stub

}

@Override
protected void readEntityFromNBT(NBTTagCompound tagCompund) {
	tagCompund.getDouble("Mass");

}

@Override
protected void writeEntityToNBT(NBTTagCompound tagCompound) {
	tagCompound.setDouble("Mass", Mass);

}

}

 

Posted

I will step out of the rendering thing for awhile cause it's driving me nuts. Anyway, after messing up with random things in the renderer, for some reason, my "black-hole" is not giving motion to any nearby entities (It is not pulling anything). This is very weird and i can't think of a cause for this. Does the renderer affects entity methods? That is confusing.

 

My entity code:

 

 

package com.ae.entities;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

public class EntityBlackHole extends Entity {

public EntityBlackHole(World worldIn) {
	super(worldIn);

}

public double Mass;
private double radius = 0.2 % Mass;

@Override
public void onUpdate() {

	List<Entity> EntitiesAround = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.fromBounds
			(this.posX - 10 - radius, this.posY - 10 - radius, this.posZ - 10 - radius, 
			this.posX + 10 + radius, this.posY + 10 + radius, this.posZ + 10 + radius));

	for(Entity e : EntitiesAround){

		if(e instanceof EntityBlackHole && e != this){
			this.Mass += ((EntityBlackHole) e).Mass;
			worldObj.removeEntity(e);
			worldObj.createExplosion(e, e.posX, e.posY, e.posZ, 10.0F, true);
		}else{

		double motionX = this.posX - e.posX;
		double motionY = this.posY - e.posY;
		double motionZ = this.posZ - e.posZ;

		e.motionX = motionX * 0.1F;
		e.motionY = motionY * 0.1F;
		e.motionZ = motionZ * 0.1F;

		for(int i = -2; i <= 2; i++){
			if(e.posX >= this.posX + i 
			   && e.posY >= this.posY + i 
			   && e.posZ >= this.posZ + i){
				e.attackEntityFrom(DamageSource.generic, 7.5F);
			}
		}

		}
	}

	if(Mass >= 500000){
		worldObj.removeEntity(this);
		worldObj.createExplosion(this, this.posX, this.posY, 
				this.posZ, 1000F, true);
	}
	super.onUpdate();	
}

@Override
protected void entityInit() {
	// TODO Auto-generated method stub

}

@Override
protected void readEntityFromNBT(NBTTagCompound tagCompund) {
	tagCompund.getDouble("Mass");

}

@Override
protected void writeEntityToNBT(NBTTagCompound tagCompound) {
	tagCompound.setDouble("Mass", Mass);

}

}

 

It should not.

Unless you change entities values from renderer... But those only affect client.

Posted

There is no line of code in the renderer that could possibly change the entity's value. Iam confused. I will try removing the renderer from entity when i get home and will post result

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.