mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Added local click position to PlayerInteractEvent.
This commit is contained in:
1 parent
ecfb9accaa
commit
f1ad05dd8e
7 files changed
+65
-6
No files matched your search
@@ -64,6 +64,7 @@ import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
@@ -923,4 +924,17 @@ public class ForgeHooks
|
||||
}
|
||||
return !event.isCanceled();
|
||||
}
|
||||
|
||||
public static MovingObjectPosition rayTraceEyes(EntityLivingBase entity, double length)
|
||||
{
|
||||
Vec3 startPos = new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
|
||||
Vec3 endPos = startPos.add(new Vec3(entity.getLookVec().xCoord * length, entity.getLookVec().yCoord * length, entity.getLookVec().zCoord * length));
|
||||
return entity.worldObj.rayTraceBlocks(startPos, endPos);
|
||||
}
|
||||
|
||||
public static Vec3 rayTraceEyeHitVec(EntityLivingBase entity, double length)
|
||||
{
|
||||
MovingObjectPosition movingObjectPosition = rayTraceEyes(entity, length);
|
||||
return movingObjectPosition == null ? null : movingObjectPosition.hitVec;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
@@ -117,9 +118,15 @@ public class ForgeEventFactory
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.newSpeed);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, World world, BlockPos pos, EnumFacing face)
|
||||
{
|
||||
PlayerInteractEvent event = new PlayerInteractEvent(player, action, pos, face, world);
|
||||
return onPlayerInteract(player, action, world, pos, face, null);
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, World world, BlockPos pos, EnumFacing face, Vec3 localPos)
|
||||
{
|
||||
PlayerInteractEvent event = new PlayerInteractEvent(player, action, pos, face, world, localPos);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import static net.minecraftforge.fml.common.eventhandler.Event.Result.DENY;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
|
||||
@@ -45,11 +46,18 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
public final World world;
|
||||
public final BlockPos pos;
|
||||
public final EnumFacing face; // Can be null if unknown
|
||||
public final Vec3 localPos; // Can be null if unknown
|
||||
|
||||
public Result useBlock = DEFAULT;
|
||||
public Result useItem = DEFAULT;
|
||||
|
||||
@Deprecated
|
||||
public PlayerInteractEvent(EntityPlayer player, Action action, BlockPos pos, EnumFacing face, World world)
|
||||
{
|
||||
this(player, action, pos, face, world, null);
|
||||
}
|
||||
|
||||
public PlayerInteractEvent(EntityPlayer player, Action action, BlockPos pos, EnumFacing face, World world, Vec3 localPos)
|
||||
{
|
||||
super(player);
|
||||
this.action = action;
|
||||
@@ -57,6 +65,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
this.face = face;
|
||||
if (face == null) useBlock = DENY;
|
||||
this.world = world;
|
||||
this.localPos = localPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user