I'm writing a mod in which the player can pick up blocks (turning them into EntityFallingSand) and fling them about. I've run into the problem that for some reason I can't seem to override the fact that EntityFallingSand always falls downward, regardless of what I write into my custom class to counteract it.
Here is the item that I'm using to pick up blocks:
package arcanepower.items;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySmallFireball;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import arcanepower.ArcanePower;
import arcanepower.entities.EarthBolt;
import arcanepower.lib.ModInfo;
import arcanepower.lib.Names;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class EarthWand extends WoodWand
{
private int targetBlock = -1;
private MovingObjectPosition hitEnt;
private int ix;
private int iy;
private int iz;
private EarthBolt bolt;
public EarthWand(int id)
{
super(id);
setCreativeTab(ArcanePower.tabArcanePower);
setUnlocalizedName(Names.earthWand_unlocalizedName);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister icon)
{
itemIcon = icon.registerIcon(ModInfo.ID.toLowerCase() + ":" + Names.earthWand_unlocalizedName);
}
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
{
if (!world.isRemote)
{
if (targetBlock == -1)
{
if (world.getBlockMaterial(x, y, z) == Material.ground || world.getBlockMaterial(x, y, z) == Material.sand || world.getBlockMaterial(x, y, z) == Material.rock || world.getBlockMaterial(x, y, z) == Material.grass)
{
if (world.getBlockMaterial(x, y, z) == Material.grass)
{
targetBlock = Block.dirt.blockID;
}
ix = x;
iy = y;
iz = z;
world.destroyBlock(x, y, z, false);
bolt = new EarthBolt(world);
bolt.blockID = targetBlock;
bolt.metadata = world.getBlockMetadata(x, y, z);
bolt.setTar(x + 0.5, y + 4, z + 0.5);
bolt.setPosition(x + 0.5, y + 1, z + 0.5);
world.spawnEntityInWorld(bolt);
}
else
{
System.out.println("Bad block type!");
}
}
else
{
float f = 1.0F;
float f1 = entityplayer.prevRotationPitch + (entityplayer.rotationPitch - entityplayer.prevRotationPitch) * f;
float f2 = entityplayer.prevRotationYaw + (entityplayer.rotationYaw - entityplayer.prevRotationYaw) * f;
double d0 = entityplayer.prevPosX + (entityplayer.posX - entityplayer.prevPosX) * (double) f;
double d1 = entityplayer.prevPosY + (entityplayer.posY - entityplayer.prevPosY) * (double) f + 1.62D - (double) entityplayer.yOffset;
double d2 = entityplayer.prevPosZ + (entityplayer.posZ - entityplayer.prevPosZ) * (double) f;
Vec3 vec3 = world.getWorldVec3Pool().getVecFromPool(d0, d1, d2);
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
float f6 = MathHelper.sin(-f1 * 0.017453292F);
float f7 = f4 * f5;
float f8 = f3 * f5;
double d3 = 60.0D;
Vec3 vec31 = vec3.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
hitEnt = world.rayTraceBlocks_do_do(vec3, vec31, false, true);
}
}
return true;
}
public void onUpdate(ItemStack itemstack, World world, Entity entityplayer, int par4, boolean par5)
{
if (targetBlock != -1)
{
if (entityplayer.getDistance(ix, iy, iz) > 10)
{
System.out.println("Moved out of range, deselecting block.");
bolt.setTar(ix, iy, iz);
targetBlock = -1;
}
}
}
public void throwBolt(EarthBolt bolt, EntityPlayer entityplayer)
{
float f = 0.4F;
bolt.motionX = (double) (-MathHelper.sin(entityplayer.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(entityplayer.rotationPitch / 180.0F * (float) Math.PI) * f);
bolt.motionZ = (double) (MathHelper.cos(entityplayer.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(entityplayer.rotationPitch / 180.0F * (float) Math.PI) * f);
bolt.motionY = (double) (-MathHelper.sin((entityplayer.rotationPitch) / 180.0F * (float) Math.PI) * f);
}
}
Here is my custom Entity:
package arcanepower.entities;
import java.util.Random;
import net.minecraft.entity.item.EntityFallingSand;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public class EarthBolt extends EntityFallingSand
{
private EntityPlayer thrower;
private float deltaPitch;
private float deltaYaw;
private double tarX;
private double tarY;
private double tarZ;
private double deltaX;
private double deltaY;
private double deltaZ;
public float speedMul = 10.0F;
public EarthBolt(World world)
{
super(world);
Random rand = new Random();
deltaPitch = -1 + rand.nextFloat() * 2;
deltaYaw = -1 + rand.nextFloat() * 2;
this.shouldDropItem = true;
}
@Override
public void onUpdate()
{
Random rand = new Random();
worldObj.spawnParticle("smoke", this.posX - 0.5 + rand.nextDouble(), this.posY - 0.5 + rand.nextDouble(), this.posZ - 0.5 + rand.nextDouble(), 0, 0, 0);
this.rotationPitch += deltaPitch;
this.rotationYaw += deltaYaw;
deltaX = (this.posX - tarX) * speedMul;
deltaY = (this.posY - tarY) * speedMul;
deltaZ = (this.posZ - tarZ) * speedMul;
this.posX += deltaX;
this.posY += deltaY;
this.posZ += deltaZ;
}
public void setTar(double x, double y, double z)
{
tarX = x;
tarY = y;
tarZ = z;
}
}
Many thanks in advance, I'm totally stumped at this.