From ccc9dfbfd2fc459f7c59b35b85acf0ed5499c957 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 11 Nov 2013 19:13:53 -0500 Subject: [PATCH] Added to ray trace helper --- src/dark/api/events/LaserEvent.java | 7 +++ src/dark/core/helpers/RayTraceHelper.java | 43 +++++++++++++++++++ .../machine/TileEntityEnergyMachine.java | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/dark/api/events/LaserEvent.java b/src/dark/api/events/LaserEvent.java index 22ff27a21..5db06cf8c 100644 --- a/src/dark/api/events/LaserEvent.java +++ b/src/dark/api/events/LaserEvent.java @@ -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 */ diff --git a/src/dark/core/helpers/RayTraceHelper.java b/src/dark/core/helpers/RayTraceHelper.java index fbaf7beb2..ac3080b85 100644 --- a/src/dark/core/helpers/RayTraceHelper.java +++ b/src/dark/core/helpers/RayTraceHelper.java @@ -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) { diff --git a/src/dark/core/prefab/machine/TileEntityEnergyMachine.java b/src/dark/core/prefab/machine/TileEntityEnergyMachine.java index 35e2b3f48..a1c87bb63 100644 --- a/src/dark/core/prefab/machine/TileEntityEnergyMachine.java +++ b/src/dark/core/prefab/machine/TileEntityEnergyMachine.java @@ -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";