Skip to content

Instantly share code, notes, and snippets.

@Knux14
Created February 8, 2014 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Knux14/8887545 to your computer and use it in GitHub Desktop.
Save Knux14/8887545 to your computer and use it in GitHub Desktop.
package fr.Knux14.Stuffies.Flycar;
import java.util.List;
import fr.Knux14.Stuffies.Stuffies;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumMovingObjectType;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
public class ItemFlycar extends Item
{
public ItemFlycar(int par1)
{
super(par1);
this.maxStackSize = 1;
this.setUnlocalizedName("stuffies_flycar");
this.setCreativeTab(Stuffies.instance.tab);
}
public ItemStack onItemRightClick(ItemStack is, World wrld, EntityPlayer ep)
{
float f = 1.0F;
float f1 = ep.prevRotationPitch + (ep.rotationPitch - ep.prevRotationPitch) * f;
float f2 = ep.prevRotationYaw + (ep.rotationYaw - ep.prevRotationYaw) * f;
double d0 = ep.prevPosX + (ep.posX - ep.prevPosX) * (double)f;
double d1 = ep.prevPosY + (ep.posY - ep.prevPosY) * (double)f + 1.62D - (double)ep.yOffset;
double d2 = ep.prevPosZ + (ep.posZ - ep.prevPosZ) * (double)f;
Vec3 vec3 = wrld.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 = 5.0D;
Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
MovingObjectPosition movingobjectposition = wrld.clip(vec3, vec31, true);
if (movingobjectposition == null)
{
return is;
}
else
{
Vec3 vec32 = ep.getLook(f);
boolean flag = false;
float f9 = 1.0F;
List list = wrld.getEntitiesWithinAABBExcludingEntity(ep, ep.boundingBox.addCoord(vec32.xCoord * d3, vec32.yCoord * d3, vec32.zCoord * d3).expand((double)f9, (double)f9, (double)f9));
int i;
for (i = 0; i < list.size(); ++i)
{
Entity entity = (Entity)list.get(i);
if (entity.canBeCollidedWith())
{
float f10 = entity.getCollisionBorderSize();
AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double)f10, (double)f10, (double)f10);
if (axisalignedbb.isVecInside(vec3))
{
flag = true;
}
}
}
if (flag)
{
return is;
}
else
{
if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
{
i = movingobjectposition.blockX;
int j = movingobjectposition.blockY;
int k = movingobjectposition.blockZ;
if (wrld.getBlockId(i, j, k) == Block.snow.blockID)
{
--j;
}
EntityFlycar entityFC = new EntityFlycar(wrld, (double)((float)i + 0.5F), (double)((float)j + 1.0F), (double)((float)k + 0.5F));
entityFC.updateOwner(ep.username);
entityFC.rotationYaw = (float)(((MathHelper.floor_double((double)(ep.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) - 1) * 90);
if (!wrld.getCollidingBoundingBoxes(entityFC, entityFC.boundingBox.expand(-0.1D, -0.1D, -0.1D)).isEmpty())
{
return is;
}
if (!wrld.isRemote)
{
wrld.spawnEntityInWorld(entityFC);
}
if (!ep.capabilities.isCreativeMode)
{
--is.stackSize;
}
}
return is;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment