Division by zero.

This commit is contained in:
Alex Spinks committed 2015-07-20 01:27:27 +01:00
1 parent 53f522017f
commit c300542805
12 files changed
+872 -10

No files matched your search

@@ -9,6 +9,7 @@ import fox.spiteful.avaritia.items.LudicrousItems;
import fox.spiteful.avaritia.render.CosmicItemRenderer;
import fox.spiteful.avaritia.render.FancyHaloRenderer;
import fox.spiteful.avaritia.render.LudicrousRenderEvents;
import fox.spiteful.avaritia.render.RenderGapingVoid;
import fox.spiteful.avaritia.render.ShaderHelper;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraftforge.client.MinecraftForgeClient;
@@ -16,6 +17,8 @@ import net.minecraftforge.common.MinecraftForge;
public class ClientProxy extends CommonProxy {
public static final double toDeg = (1.0/(Math.PI*2))*360.0;
@Override
public void makeThingsPretty() {
FancyHaloRenderer shiny = new FancyHaloRenderer();
@@ -25,7 +28,7 @@ public class ClientProxy extends CommonProxy {
MinecraftForgeClient.registerItemRenderer(LudicrousItems.endest_pearl, shiny);
RenderingRegistry.registerEntityRenderingHandler(EntityEndestPearl.class, new RenderSnowball(LudicrousItems.endest_pearl));
RenderingRegistry.registerEntityRenderingHandler(EntityGapingVoid.class, new RenderSnowball(LudicrousItems.cosmic_meatballs));
RenderingRegistry.registerEntityRenderingHandler(EntityGapingVoid.class, new RenderGapingVoid());
CosmicItemRenderer sparkly = new CosmicItemRenderer();
@@ -8,6 +8,7 @@ import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class EntityEndestPearl extends EntityThrowable {
@@ -30,9 +31,9 @@ public class EntityEndestPearl extends EntityThrowable {
pos.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
}
for (int i = 0; i < 32; ++i)
for (int i = 0; i < 100; ++i)
{
this.worldObj.spawnParticle("portal", this.posX, this.posY + this.rand.nextDouble() * 2.0D, this.posZ, this.rand.nextGaussian(), 0.0D, this.rand.nextGaussian());
this.worldObj.spawnParticle("portal", this.posX, this.posY, this.posZ, this.rand.nextGaussian()*3, this.rand.nextGaussian()*3, this.rand.nextGaussian()*3);
}
if (!this.worldObj.isRemote)
@@ -41,12 +42,11 @@ public class EntityEndestPearl extends EntityThrowable {
Entity ent = new EntityGapingVoid(this.worldObj);
//Entity ent = new EntityChicken(this.worldObj);
ent.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit);
ent.setLocationAndAngles(this.posX + dir.offsetX*0.25, this.posY + dir.offsetY*0.25, this.posZ + dir.offsetZ*0.25, this.rotationYaw, 0.0F);
this.worldObj.spawnEntityInWorld(ent);
this.setDead();
Lumberjack.info("ded");
}
}
@@ -1,37 +1,195 @@
package fox.spiteful.avaritia.entity;
import java.util.List;
import java.util.Random;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import fox.spiteful.avaritia.Lumberjack;
import net.minecraft.block.Block;
import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
public class EntityGapingVoid extends Entity {
public static final int maxLifetime = 200;
private static Random randy = new Random();
public static final int maxLifetime = 186;
public static double collapse = .95;
public static double suckrange = 20.0;
public static final IEntitySelector sucklector = new IEntitySelector() {
@Override
public boolean isEntityApplicable(Entity ent) {
if (ent instanceof EntityPlayer) {
EntityPlayer p = (EntityPlayer)ent;
if (p.capabilities.isCreativeMode && p.capabilities.isFlying) {
return false;
}
}
return true;
}
};
public static final IEntitySelector nomlector = new IEntitySelector() {
@Override
public boolean isEntityApplicable(Entity ent) {
if(!(ent instanceof EntityLivingBase)) { return false; }
if (ent instanceof EntityPlayer) {
EntityPlayer p = (EntityPlayer)ent;
if (p.capabilities.isCreativeMode) {
return false;
}
}
return true;
}
};
public EntityGapingVoid(World world) {
super(world);
this.isImmuneToFire = true;
this.setSize(0.1F, 0.1F);
this.ignoreFrustumCheck = true;
this.renderDistanceWeight = 100.0;
}
@Override
protected void entityInit() {
dataWatcher.addObject(12, 0);
dataWatcher.setObjectWatched(12);
Lumberjack.info("SPAWN");
}
@SuppressWarnings("unchecked")
@Override
public void onUpdate() {
super.onUpdate();
// tick, tock
int age = this.getAge();
if (age >= maxLifetime) {
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 6.0f, true);
this.setDead();
} else {
if (age == 0) {
this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "Avaritia:gapingVoid", 8.0F, 1.0F);
}
this.setAge(age+1);
}
// poot poot
double particlespeed = 4.5;
double size = getVoidScale(age)*0.5 - 0.2;
for(int i=0; i<50; i++) {
Vec3 pootdir = Vec3.createVectorHelper(0, 0, size);
pootdir.rotateAroundY(randy.nextFloat()*180f);
pootdir.rotateAroundX(randy.nextFloat()*360f);
Vec3 pootspeed = pootdir.normalize();
pootspeed.xCoord *= particlespeed;
pootspeed.yCoord *= particlespeed;
pootspeed.zCoord *= particlespeed;
this.worldObj.spawnParticle("portal", this.posX + pootdir.xCoord, this.posY + pootdir.yCoord, this.posZ + pootdir.zCoord, pootspeed.xCoord, pootspeed.yCoord, pootspeed.zCoord);
}
// *slurping noises*
AxisAlignedBB suckzone = AxisAlignedBB.getBoundingBox(this.posX - suckrange, this.posY - suckrange, this.posZ - suckrange, this.posX + suckrange, this.posY + suckrange, this.posZ + suckrange);
List<Entity> sucked = this.worldObj.selectEntitiesWithinAABB(Entity.class, suckzone, sucklector);
double radius = getVoidScale(age)*0.5;
for (Entity suckee : sucked) {
if (suckee != this) {
double dx = this.posX - suckee.posX;
double dy = this.posY - suckee.posY;
double dz = this.posZ - suckee.posZ;
double lensquared = dx*dx + dy*dy + dz*dz;
double len = Math.sqrt(lensquared);
double lenn = len/suckrange;
if (len <= suckrange) {
double strength = (1-lenn)*(1-lenn);
double power = 0.075 * radius;
suckee.motionX += (dx/len)*strength*power;
suckee.motionY += (dy/len)*strength*power;
suckee.motionZ += (dz/len)*strength*power;
}
}
}
// om nom nom
double nomrange = radius*0.95;
AxisAlignedBB nomzone = AxisAlignedBB.getBoundingBox(this.posX - nomrange, this.posY - nomrange, this.posZ - nomrange, this.posX + nomrange, this.posY + nomrange, this.posZ + nomrange);
List<Entity> nommed = this.worldObj.selectEntitiesWithinAABB(EntityLivingBase.class, nomzone, nomlector);
for (Entity nommee : nommed) {
if (nommee != this) {
double dx = this.posX - nommee.posX;
double dy = this.posY - nommee.posY;
double dz = this.posZ - nommee.posZ;
double lensquared = dx*dx + dy*dy + dz*dz;
double len = Math.sqrt(lensquared);
if (len <= nomrange) {
nommee.attackEntityFrom(DamageSource.outOfWorld, 3.0f);
}
}
}
// every half second, SMASH STUFF
if (age % 10 == 0) {
int bx = (int) Math.floor(this.posX);
int by = (int) Math.floor(this.posY);
int bz = (int) Math.floor(this.posZ);
int blockrange = (int) Math.round(nomrange);
int lx,ly,lz;
for (int y = -blockrange; y <= blockrange; y++) {
for (int z = -blockrange; z <= blockrange; z++) {
for (int x = -blockrange; x <= blockrange; x++) {
lx = bx+x;
ly = by+y;
lz = bz+z;
if (ly < 0 || ly > 255) {
continue;
}
double dist = Math.sqrt(x*x+y*y+z*z);
if (dist <= nomrange && !this.worldObj.isAirBlock(lx, ly, lz)) {
Block b = this.worldObj.getBlock(lx, ly, lz);
int meta = this.worldObj.getBlockMetadata(lx, ly, lz);
float resist = b.getExplosionResistance(this, this.worldObj, lx, ly, lz, this.posX, this.posY, this.posZ);
if (resist <= 10.0) {
b.dropBlockAsItemWithChance(worldObj, lx, ly, lz, meta, 0.9f, 0);
this.worldObj.setBlockToAir(lx, ly, lz);
}
}
}
}
}
}
}
@@ -39,7 +197,7 @@ public class EntityGapingVoid extends Entity {
dataWatcher.updateObject(12, age);
}
private int getAge() {
public int getAge() {
return dataWatcher.getWatchableObjectInt(12);
}
@@ -52,4 +210,34 @@ public class EntityGapingVoid extends Entity {
protected void writeEntityToNBT(NBTTagCompound tag) {
tag.setInteger("age", this.getAge());
}
public static double getVoidScale(double age) {
double life = age / (double)maxLifetime;
double curve;
if (life < collapse) {
curve = 0.005 + ease(1-((collapse-life)/collapse))* 0.995;
} else {
curve = ease(1-((life-collapse)/(1-collapse)));
}
return 10.0*curve;
}
private static double ease(double in) {
double t = in-1;
return Math.sqrt(1 - t*t);
}
@Override
@SideOnly(Side.CLIENT)
public float getShadowSize()
{
return 0.0F;
}
@Override
public boolean canBeCollidedWith()
{
return false;
}
}
@@ -7,6 +7,6 @@ public class LudicrousEntities {
public static void letLooseTheDogsOfWar() {
EntityRegistry.registerModEntity(EntityEndestPearl.class, "EndestPearl", 1, Avaritia.instance, 64, 10, true);
EntityRegistry.registerModEntity(EntityGapingVoid.class, "GapingVoid", 2, Avaritia.instance, 64, 10, false);
EntityRegistry.registerModEntity(EntityGapingVoid.class, "GapingVoid", 2, Avaritia.instance, 256, 10, false);
}
}
@@ -0,0 +1,153 @@
package fox.spiteful.avaritia.render;
import org.lwjgl.opengl.GL11;
import fox.spiteful.avaritia.ClientProxy;
import fox.spiteful.avaritia.Lumberjack;
import fox.spiteful.avaritia.entity.EntityGapingVoid;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
public class RenderGapingVoid extends Render {
private ResourceLocation fill = new ResourceLocation("avaritia", "textures/entity/void.png");
private ResourceLocation halo = new ResourceLocation("avaritia", "textures/entity/voidhalo.png");
private IModelCustom model;
public RenderGapingVoid() {
this.model = AdvancedModelLoader.loadModel(new ResourceLocation("avaritia", "model/hemisphere.obj"));
}
@Override
public void doRender(Entity ent, double x, double y, double z, float p_76986_8_, float partialTicks) {
EntityGapingVoid egv = (EntityGapingVoid)ent;
Minecraft mc =Minecraft.getMinecraft();
mc.renderEngine.bindTexture(this.halo);
Tessellator tess = Tessellator.instance;
double age = egv.getAge() + partialTicks;
setColour(age, 1.0);
double scale = EntityGapingVoid.getVoidScale(age);
double fullfadedist = 0.6 * scale;
double fadedist = fullfadedist + 1.5;
double halocoord = 0.58 * scale;
double haloscaledist = 2.2 * scale;
double dx = ent.posX - RenderManager.renderPosX;
double dy = ent.posY - RenderManager.renderPosY;
double dz = ent.posZ - RenderManager.renderPosZ;
double xzlen = Math.sqrt(dx*dx + dz*dz);
double len = Math.sqrt(dx*dx + dy*dy + dz*dz);
if (len <= haloscaledist) {
double close = (haloscaledist-len)/haloscaledist;
halocoord *= 1.0 + close*close*close*close*1.5;
}
double yang = Math.atan2(xzlen, dy) * ClientProxy.toDeg;
double xang = Math.atan2(dx, dz) * ClientProxy.toDeg;
//Lumberjack.info("dx: "+dx+", dy: "+dy+", dz: "+dz+", xang: "+xang);
//Lumberjack.info("x: "+x+", y: "+y+", z: "+z);
GL11.glDisable(GL11.GL_LIGHTING);
mc.entityRenderer.disableLightmap(0.0);
GL11.glPushMatrix();
{
GL11.glTranslated(x, y, z);
GL11.glRotated(xang, 0, 1, 0);
GL11.glRotated(yang+90, 1, 0, 0);
GL11.glPushMatrix();
{
GL11.glRotated(90, 1, 0, 0);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDepthMask(false);
tess.startDrawingQuads();
tess.addVertexWithUV(-halocoord,0.0,-halocoord, 0.0, 0.0);
tess.addVertexWithUV(-halocoord,0.0, halocoord, 0.0, 1.0);
tess.addVertexWithUV( halocoord,0.0, halocoord, 1.0, 1.0);
tess.addVertexWithUV( halocoord,0.0,-halocoord, 1.0, 0.0);
tess.draw();
GL11.glDepthMask(true);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
}
GL11.glPopMatrix();
Minecraft.getMinecraft().renderEngine.bindTexture(this.fill);
GL11.glScaled(scale, scale, scale);
model.renderAll();
}
GL11.glPopMatrix();
if (len <= fadedist) {
double alpha = 1.0;
if (len >= fullfadedist) {
alpha = 1.0 - ((len - fullfadedist) / (fadedist - fullfadedist));
alpha = alpha*alpha*(3 - 2*alpha);
}
setColour(age, alpha);
GL11.glPushMatrix();
{
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
double d = 0;
tess.startDrawingQuads();
tess.addVertexWithUV(-100, 100, d, 0.0, 0.0);
tess.addVertexWithUV(-100,-100, d, 0.0, 1.0);
tess.addVertexWithUV( 100,-100, d, 1.0, 1.0);
tess.addVertexWithUV( 100, 100, d, 1.0, 0.0);
tess.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
}
GL11.glPopMatrix();
}
mc.entityRenderer.enableLightmap(0.0);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glColor4d(1, 1, 1, 1);
}
@Override
protected ResourceLocation getEntityTexture(Entity ent) {
return this.fill;
}
private void setColour(double age, double alpha) {
double life = (age / (double)EntityGapingVoid.maxLifetime);
double f = Math.max(0, (life - EntityGapingVoid.collapse)/(1-EntityGapingVoid.collapse));
f = Math.max(f, 1-(life*30));
GL11.glColor4d(f, f, f, alpha);
}
}