Added to ray trace helper
This commit is contained in:
parent
6d397bcf98
commit
ccc9dfbfd2
3 changed files with 51 additions and 1 deletions
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -38,6 +39,12 @@ public class LaserEvent extends Event
|
|||
super(world, spot, target);
|
||||
this.shooter = shooter;
|
||||
}
|
||||
|
||||
public LaserFireEvent(TileEntity tileEntity, MovingObjectPosition hit)
|
||||
{
|
||||
super(tileEntity.worldObj, new Vector3(tileEntity), new Vector3(hit));
|
||||
this.shooter = tileEntity;
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when a player fires a laser. Use this to cancel a laser hit event */
|
||||
|
|
|
@ -2,6 +2,9 @@ package dark.core.helpers;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import universalelectricity.core.vector.Quaternion;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
@ -151,6 +154,46 @@ public class RayTraceHelper
|
|||
return world.rayTraceBlocks_do_do(start, end, collisionFlag, !collisionFlag);
|
||||
}
|
||||
|
||||
public static Vector3 getPosFromRotation(Vector3 center, Vector3 spot, float yaw, float pitch)
|
||||
{
|
||||
double reachDistance = center.distance(spot);
|
||||
return getPosFromRotation(spot, reachDistance, pitch, pitch);
|
||||
}
|
||||
|
||||
public static Vector3 getPosFromRotation(Vector3 center, double reachDistance, float yaw, float pitch)
|
||||
{
|
||||
Quaternion q = new Quaternion();
|
||||
q.FromEuler(yaw, pitch, 0);
|
||||
return center.clone().translate(q.multi(Vector3.NORTH().scale(reachDistance)));
|
||||
}
|
||||
|
||||
public static MovingObjectPosition ray_trace_do(World world, Vec3 start, float yaw, float pitch, double reachDistance, boolean collisionFlag)
|
||||
{
|
||||
|
||||
Vec3 end = getPosFromRotation(new Vector3(start), reachDistance, yaw, pitch).toVec3();
|
||||
MovingObjectPosition hitBlock = raytraceBlocks(world, start, end, collisionFlag);
|
||||
MovingObjectPosition hitEntity = raytraceEntities(world, start, end, collisionFlag, null);
|
||||
if (hitEntity == null)
|
||||
{
|
||||
return hitBlock;
|
||||
}
|
||||
else if (hitBlock == null)
|
||||
{
|
||||
return hitEntity;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hitEntity.hitVec.distanceTo(start) < hitBlock.hitVec.distanceTo(start))
|
||||
{
|
||||
return hitEntity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hitBlock;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MovingObjectPosition ray_trace_do(World world, Entity entity, Vec3 e, double reachDistance, boolean collisionFlag)
|
||||
{
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ import dark.core.common.ExternalModHandler;
|
|||
* Based off both UE universal electrical tile, and electrical tile prefabs
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class TileEntityEnergyMachine extends TileEntityMachine implements IElectrical, IElectricalStorage, IPowerLess
|
||||
public abstract class TileEntityEnergyMachine extends TileEntityMachine implements IElectrical, IElectricalStorage, IPowerLess
|
||||
{
|
||||
/** Forge Ore Directory name of the item to toggle infinite power mode */
|
||||
public static String powerToggleItemID = "battery";
|
||||
|
|
Loading…
Add table
Reference in a new issue