mirror of
https://github.com/GTNewHorizons/Electro-Magic-Tools.git
synced 2026-11-20 20:12:23 +00:00
now works =)
This commit is contained in:
1 parent
58e387e761
commit
0b8b56a74b
5 files changed
+196
-66
No files matched your search
@@ -19,45 +19,60 @@ public class RenderElectroBall extends Render {
|
||||
@Override
|
||||
public void doRender(Entity entity, double x, double y, double z, float p1, float p2) {
|
||||
EntityElectroBall ball = (EntityElectroBall) entity;
|
||||
|
||||
if (ball != null && ball.entityPositions != null) {
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
if (ball.shootingEntity == null) {
|
||||
if (ball.worldObj.isRemote) {
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
glPushMatrix();
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_FOG);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glTranslated(x, y, z);
|
||||
|
||||
renderBolt(ball, tessellator, 0, 0, 0, 8);
|
||||
|
||||
if (ball.inTile) {
|
||||
|
||||
renderBolt(ball, tessellator, 0, 0, 0, 0.5F);
|
||||
|
||||
if (ball.entityPositions != null) {
|
||||
for (Point pos : ball.entityPositions) {
|
||||
double trX = pos.x - entity.posX;
|
||||
double trY = pos.y - entity.posY;
|
||||
double trZ = pos.z - entity.posZ;
|
||||
|
||||
renderBolt(ball, tessellator, trX, trY, trZ, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
glEnable(GL_FOG);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void renderBolt(EntityElectroBall ball, Tessellator tess, double x, double y, double z, double scale) {
|
||||
for (int i = 0; i < ball.bolts.length; i++) {
|
||||
Bolt bolt = ball.bolts[i];
|
||||
|
||||
glPushMatrix();
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_FOG);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glTranslated(x, y, z);
|
||||
glRotatef(bolt.angleZ, 0, 0, 1);
|
||||
glRotatef(bolt.angleY, 0, 1, 0);
|
||||
glLineWidth(2);
|
||||
|
||||
for (Point pos : ball.entityPositions) {
|
||||
double trX = pos.x - entity.posX;
|
||||
double trY = pos.y - entity.posY;
|
||||
double trZ = pos.z - entity.posZ;
|
||||
|
||||
for (int i = 0; i < ball.bolts.length; i++) {
|
||||
Bolt bolt = ball.bolts[i];
|
||||
|
||||
glPushMatrix();
|
||||
glTranslated(trX, trY, trZ);
|
||||
glRotatef(bolt.angleZ, 0, 0, 1);
|
||||
glRotatef(bolt.angleY, 0, 1, 0);
|
||||
glLineWidth(2);
|
||||
|
||||
tessellator.startDrawing(GL_LINE_STRIP);
|
||||
tessellator.setColorRGBA(255, 255, 255, 255);
|
||||
tessellator.addVertex(0, 0, 0);
|
||||
for (Point point : bolt.points) {
|
||||
tessellator.addVertex((point.x / 10f), (point.y / 10f), (point.z / 10f));
|
||||
}
|
||||
tessellator.draw();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
tess.startDrawing(GL_LINE_STRIP);
|
||||
tess.setColorRGBA(255, 255, 255, 255);
|
||||
for (Point point : bolt.points) {
|
||||
tess.addVertex((point.x / scale), (point.y / scale), (point.z / scale));
|
||||
}
|
||||
tess.draw();
|
||||
|
||||
glPopMatrix();
|
||||
glEnable(GL_FOG);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,44 @@
|
||||
package emt.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import emt.util.EMTRandomHelper.Bolt;
|
||||
import emt.util.EMTRandomHelper.Point;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.entity.projectile.EntityFireball;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class EntityElectroBall extends Entity {
|
||||
public class EntityElectroBall extends Entity implements IProjectile, IEntityAdditionalSpawnData {
|
||||
public EntityLivingBase shootingEntity;
|
||||
public Bolt[] bolts = new Bolt[20];
|
||||
public Bolt[] bolts = new Bolt[25];
|
||||
public Point[] entityPositions;
|
||||
public boolean onGround = false;
|
||||
public boolean inTile = false;
|
||||
private int ticksAlive;
|
||||
private int ticksInAir;
|
||||
public double accelerationX;
|
||||
public double accelerationY;
|
||||
public double accelerationZ;
|
||||
public static final int searchRadius = 16;
|
||||
public static final float length = 10f;
|
||||
public static final int radius = 8;
|
||||
public static final float length = 16f;
|
||||
public static final float dist = 1f;
|
||||
public static final float height = 4f;
|
||||
public static final float height = 8f;
|
||||
|
||||
public EntityElectroBall(World world, EntityLivingBase shootingEntity, double rotX, double rotY, double rotZ) {
|
||||
this(world, shootingEntity);
|
||||
@@ -64,48 +73,136 @@ public class EntityElectroBall extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(ByteBuf buffer) {
|
||||
buffer.writeDouble(accelerationX);
|
||||
buffer.writeDouble(accelerationY);
|
||||
buffer.writeDouble(accelerationZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(ByteBuf buffer) {
|
||||
accelerationX = buffer.readDouble();
|
||||
accelerationY = buffer.readDouble();
|
||||
accelerationZ = buffer.readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
|
||||
for (int i = 0; i < bolts.length; i++) {
|
||||
bolts[i].regenerate();
|
||||
}
|
||||
/** If in Tile **/
|
||||
if (this.inTile) {
|
||||
this.ticksAlive++;
|
||||
|
||||
ArrayList<Entity> entities = new ArrayList();
|
||||
if (this.ticksAlive >= 60) {
|
||||
this.setDead();
|
||||
}
|
||||
|
||||
int chunkSize = ((searchRadius - 1) >> 4) + 1;
|
||||
/** Generating Coords for every Entity **/
|
||||
ArrayList<Entity> entities = new ArrayList();
|
||||
|
||||
for (int chX = -chunkSize; chX < chunkSize; chX++) {
|
||||
for (int chZ = -chunkSize; chZ < chunkSize; chZ++) {
|
||||
Chunk chunk = worldObj.getChunkFromChunkCoords(chX + (int) (this.posX / 16), chZ + (int) (this.posZ / 16));
|
||||
int chunkSize = ((radius - 1) >> 4) + 2;
|
||||
|
||||
if (chunk.isChunkLoaded && chunk.hasEntities) {
|
||||
for (int i = 0; i < chunk.entityLists.length; i++) {
|
||||
for (int k = 0; k < chunk.entityLists[i].size(); k++) {
|
||||
Entity entity = (Entity) chunk.entityLists[i].get(k);
|
||||
double width = entity.posX - this.posX;
|
||||
double height = entity.posY - this.posY;
|
||||
double length = entity.posZ - this.posZ;
|
||||
for (int chX = -chunkSize; chX < chunkSize; chX++) {
|
||||
for (int chZ = -chunkSize; chZ < chunkSize; chZ++) {
|
||||
Chunk chunk = worldObj.getChunkFromChunkCoords(chX + (int) (this.posX / 16), chZ + (int) (this.posZ / 16));
|
||||
|
||||
if (MathHelper.sqrt_double((width * width) + (length * length) + (height * height)) <= searchRadius) {
|
||||
entities.add(entity);
|
||||
if (chunk.isChunkLoaded && chunk.hasEntities) {
|
||||
for (int i = 0; i < chunk.entityLists.length; i++) {
|
||||
for (int k = 0; k < chunk.entityLists[i].size(); k++) {
|
||||
Entity entity = (Entity) chunk.entityLists[i].get(k);
|
||||
double width = entity.posX - this.posX;
|
||||
double height = entity.posY - this.posY;
|
||||
double length = entity.posZ - this.posZ;
|
||||
double hyp = MathHelper.sqrt_double((width * width) + (length * length) + (height * height));
|
||||
|
||||
if (hyp <= radius) {
|
||||
entities.add(entity);
|
||||
/** Closer - Harder */
|
||||
entity.attackEntityFrom(DamageSource.magic, (float) (radius - hyp));
|
||||
entity.performHurtAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entityPositions = new Point[entities.size()];
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity entity = entities.get(i);
|
||||
entityPositions[i] = new Point(entity.posX, entity.posY, entity.posZ);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
}
|
||||
/** If not in Tile **/
|
||||
else {
|
||||
/** Collision detection **/
|
||||
Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
Vec3 vec3next = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
MovingObjectPosition mop = this.worldObj.rayTraceBlocks(vec3, vec3next);
|
||||
|
||||
this.ticksInAir++;
|
||||
if (mop != null) {
|
||||
inTile = true;
|
||||
}
|
||||
|
||||
/** Updating position */
|
||||
this.posX += this.motionX;
|
||||
this.posY += this.motionY;
|
||||
this.posZ += this.motionZ;
|
||||
float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
this.rotationYaw = (float) (Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F;
|
||||
|
||||
for (this.rotationPitch = (float) (Math.atan2((double) f1, this.motionY) * 180.0D / Math.PI) - 90.0F; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
|
||||
;
|
||||
}
|
||||
|
||||
while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
|
||||
this.prevRotationPitch += 360.0F;
|
||||
}
|
||||
|
||||
while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
|
||||
this.prevRotationYaw -= 360.0F;
|
||||
}
|
||||
|
||||
while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
|
||||
this.prevRotationYaw += 360.0F;
|
||||
}
|
||||
|
||||
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
|
||||
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
|
||||
|
||||
double factor = this.getMotionFactor();
|
||||
this.motionX += this.accelerationX;
|
||||
this.motionY += this.accelerationY;
|
||||
this.motionZ += this.accelerationZ;
|
||||
this.motionX *= factor;
|
||||
this.motionY *= factor;
|
||||
this.motionZ *= factor;
|
||||
this.setPosition(this.posX, this.posY, this.posZ);
|
||||
/************************************************************************/
|
||||
}
|
||||
|
||||
entityPositions = new Point[entities.size()];
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity entity = entities.get(i);
|
||||
entity.performHurtAnimation();
|
||||
entityPositions[i] = new Point(entity.posX, entity.posY, entity.posZ);
|
||||
if (this.worldObj.isRemote) {
|
||||
for (int i = 0; i < bolts.length; i++) {
|
||||
bolts[i].regenerate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected float getMotionFactor() {
|
||||
return 0.75F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getBrightnessForRender(float p_70070_1_) {
|
||||
return 240;
|
||||
@@ -122,10 +219,29 @@ public class EntityElectroBall extends Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {
|
||||
public void writeEntityToNBT(NBTTagCompound nbt) {
|
||||
nbt.setByte("inTile", (byte) (this.inTile ? 1 : 0));
|
||||
nbt.setTag("direction", this.newDoubleNBTList(new double[] { this.motionX, this.motionY, this.motionZ }));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {
|
||||
public void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
if (!inTile) {
|
||||
this.inTile = nbt.getByte("inTile") == 1;
|
||||
}
|
||||
|
||||
if (nbt.hasKey("direction", 9)) {
|
||||
NBTTagList nbttaglist = nbt.getTagList("direction", 6);
|
||||
this.motionX = nbttaglist.func_150309_d(0);
|
||||
this.motionY = nbttaglist.func_150309_d(1);
|
||||
this.motionZ = nbttaglist.func_150309_d(2);
|
||||
}
|
||||
else {
|
||||
this.setDead();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setThrowableHeading(double x, double y, double z, float p1, float p2) {
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,6 @@ public class EMTEntities {
|
||||
EntityRegistry.registerModEntity(EntityArcher.class, "archer", entityIDs++, ElectroMagicTools.instance, 80, 3, true);
|
||||
registerEntityEgg(EntityArcher.class, 0x99111F, 0xE5685);
|
||||
EntityRegistry.registerModEntity(EntityShield.class, "shield", entityIDs++, ElectroMagicTools.instance, 80, 3, true);
|
||||
EntityRegistry.registerModEntity(EntityElectroBall.class, "electroBall", entityIDs++, ElectroMagicTools.instance, 80, 3, true);
|
||||
EntityRegistry.registerModEntity(EntityElectroBall.class, "electroBall", entityIDs++, ElectroMagicTools.instance, 80, 60, true);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class ItemNoNameFocus extends ItemBaseFocus {
|
||||
float rotX = (-MathHelper.sin(player.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI)) * 100;
|
||||
float rotY = (-MathHelper.sin(player.rotationPitch / 180.0F * (float) Math.PI)) * 100;
|
||||
float rotZ = (MathHelper.cos(player.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI)) * 100;
|
||||
world.spawnEntityInWorld(new EntityElectroBall(world, player));
|
||||
world.spawnEntityInWorld(new EntityElectroBall(world, player, rotX, rotY, rotZ));
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,5 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityArcher.class, new RenderSnowMan());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityShield.class, new RenderShield());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityElectroBall.class, new RenderElectroBall());
|
||||
RenderManager.instance.entityRenderMap.put(EntityElectroBall.class, new RenderElectroBall());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user