Made Tesla do raytrace
This commit is contained in:
parent
0496b44c0d
commit
d18265e44b
3 changed files with 159 additions and 131 deletions
|
@ -208,6 +208,15 @@ public class Vector3
|
||||||
return new Vector3(Math.cos(Math.toRadians(rotationYaw)), Math.sin(Math.toRadians(rotationPitch)), Math.sin(Math.toRadians(rotationYaw)));
|
return new Vector3(Math.cos(Math.toRadians(rotationYaw)), Math.sin(Math.toRadians(rotationPitch)), Math.sin(Math.toRadians(rotationYaw)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double[] getDeltaRotationFromPosition()
|
||||||
|
{
|
||||||
|
double rotationYaw = Math.toDegrees(Math.atan2(this.z, this.x));
|
||||||
|
double rotationPitch = Math.toDegrees(Math.asin(this.y));
|
||||||
|
rotationYaw = rotationYaw - 90;
|
||||||
|
rotationPitch = -rotationPitch;
|
||||||
|
return new double[] { rotationPitch, rotationYaw };
|
||||||
|
}
|
||||||
|
|
||||||
public double getAngle(Vector3 vector)
|
public double getAngle(Vector3 vector)
|
||||||
{
|
{
|
||||||
return this.getAnglePreNorm(vector.clone().normalize());
|
return this.getAnglePreNorm(vector.clone().normalize());
|
||||||
|
|
|
@ -47,6 +47,16 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
tileEntity.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage());
|
tileEntity.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage());
|
||||||
|
|
||||||
|
if (!entityPlayer.capabilities.isCreativeMode)
|
||||||
|
{
|
||||||
|
entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (entityPlayer.getCurrentEquippedItem().itemID == Item.redstone.itemID)
|
||||||
|
{
|
||||||
|
tileEntity.toggleEntityAttack();
|
||||||
|
|
||||||
if (!entityPlayer.capabilities.isCreativeMode)
|
if (!entityPlayer.capabilities.isCreativeMode)
|
||||||
{
|
{
|
||||||
entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
|
entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.tileentity.TileEntityFurnace;
|
import net.minecraft.tileentity.TileEntityFurnace;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.util.DamageSource;
|
||||||
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import resonantinduction.ITesla;
|
import resonantinduction.ITesla;
|
||||||
import resonantinduction.PacketHandler;
|
import resonantinduction.PacketHandler;
|
||||||
import resonantinduction.ResonantInduction;
|
import resonantinduction.ResonantInduction;
|
||||||
|
@ -79,8 +80,10 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
||||||
/**
|
/**
|
||||||
* Only transfer if it is the bottom controlling Tesla tower.
|
* Only transfer if it is the bottom controlling Tesla tower.
|
||||||
*/
|
*/
|
||||||
|
if (this.isController())
|
||||||
|
{
|
||||||
// TODO: Fix client side issue. || this.worldObj.isRemote
|
// TODO: Fix client side issue. || this.worldObj.isRemote
|
||||||
if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && this.isController() && ((this.getEnergyStored() > 0 && this.doTransfer) || this.worldObj.isRemote) && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))
|
if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && ((this.getEnergyStored() > 0 && this.doTransfer) || this.worldObj.isRemote) && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))
|
||||||
{
|
{
|
||||||
List<ITesla> transferTeslaCoils = new ArrayList<ITesla>();
|
List<ITesla> transferTeslaCoils = new ArrayList<ITesla>();
|
||||||
|
|
||||||
|
@ -109,7 +112,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
||||||
}
|
}
|
||||||
|
|
||||||
final TileEntityTesla topTesla = this.getTopTelsa();
|
final TileEntityTesla topTesla = this.getTopTelsa();
|
||||||
|
final Vector3 topTeslaVector = new Vector3(topTesla);
|
||||||
/**
|
/**
|
||||||
* Sort by distance.
|
* Sort by distance.
|
||||||
*/
|
*/
|
||||||
|
@ -150,36 +153,41 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
||||||
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, ResonantInduction.PREFIX + "electricshock", this.getEnergyStored() / 25, (float) (1.3f - 0.5f * ((float) this.dyeID / 16f)));
|
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, ResonantInduction.PREFIX + "electricshock", this.getEnergyStored() / 25, (float) (1.3f - 0.5f * ((float) this.dyeID / 16f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 teslaVector = new Vector3((TileEntity) tesla);
|
Vector3 targetVector = new Vector3((TileEntity) tesla);
|
||||||
|
|
||||||
if (tesla instanceof TileEntityTesla)
|
if (tesla instanceof TileEntityTesla)
|
||||||
{
|
{
|
||||||
((TileEntityTesla) tesla).getControllingTelsa().outputBlacklist.add(this);
|
((TileEntityTesla) tesla).getControllingTelsa().outputBlacklist.add(this);
|
||||||
teslaVector = new Vector3(((TileEntityTesla) tesla).getTopTelsa());
|
targetVector = new Vector3(((TileEntityTesla) tesla).getTopTelsa());
|
||||||
}
|
}
|
||||||
|
|
||||||
ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).translate(new Vector3(0.5)), teslaVector.translate(new Vector3(0.5)), (float) dyeColors[this.dyeID].x, (float) dyeColors[this.dyeID].y, (float) dyeColors[this.dyeID].z);
|
double distance = topTeslaVector.distance(targetVector);
|
||||||
|
ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).translate(new Vector3(0.5)), targetVector.translate(new Vector3(0.5)), (float) dyeColors[this.dyeID].x, (float) dyeColors[this.dyeID].y, (float) dyeColors[this.dyeID].z);
|
||||||
|
|
||||||
tesla.transfer(transferEnergy * (1 - (this.worldObj.rand.nextFloat() * 0.1f)));
|
tesla.transfer(transferEnergy * (1 - (this.worldObj.rand.nextFloat() * 0.1f)));
|
||||||
this.transfer(-transferEnergy);
|
this.transfer(-transferEnergy);
|
||||||
|
|
||||||
|
if (this.attackEntities && this.zapCounter % 10 == 0)
|
||||||
|
{
|
||||||
|
double[] rotations = topTeslaVector.getDeltaRotationFromPosition();
|
||||||
|
MovingObjectPosition mop = topTeslaVector.rayTraceEntities(this.worldObj, (float) rotations[1], (float) rotations[0], true, distance);
|
||||||
|
System.out.println("HIT " + mop);
|
||||||
|
|
||||||
|
if (mop != null && mop.entityHit != null)
|
||||||
|
{
|
||||||
|
if (mop.entityHit instanceof EntityLivingBase)
|
||||||
|
{
|
||||||
|
mop.entityHit.attackEntityFrom(DamageSource.magic, 1);
|
||||||
|
ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).translate(new Vector3(0.5)), new Vector3(mop.entityHit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (count++ > 1)
|
if (count++ > 1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.attackEntities && this.zapCounter % 10 == 0)
|
|
||||||
{
|
|
||||||
int radius = 3;
|
|
||||||
List<EntityLivingBase> entities = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getAABBPool().getAABB(this.xCoord - radius, this.yCoord - radius, this.zCoord - radius, this.xCoord + radius, this.yCoord + radius, this.zCoord + radius));
|
|
||||||
|
|
||||||
for (EntityLivingBase entity : entities)
|
|
||||||
{
|
|
||||||
entity.attackEntityFrom(DamageSource.magic, 1);
|
|
||||||
ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).translate(new Vector3(0.5)), new Vector3(entity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.zapCounter++;
|
this.zapCounter++;
|
||||||
|
@ -247,6 +255,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
||||||
{
|
{
|
||||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.clearCache();
|
this.clearCache();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue