Skip to content

Commit

Permalink
makes it a bit easier to interact with pokemobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Thutmose committed Apr 24, 2020
1 parent c4f4c58 commit ca18045
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
27 changes: 21 additions & 6 deletions src/main/java/pokecube/core/client/EventsHandlerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,24 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.RayTraceResult.Type;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.InputEvent.KeyInputEvent;
import net.minecraftforge.client.event.InputEvent.MouseInputEvent;
import net.minecraftforge.client.event.InputEvent.RawMouseEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import pokecube.core.PokecubeCore;
import pokecube.core.ai.logic.LogicMountedControl;
Expand Down Expand Up @@ -185,16 +189,27 @@ public static IPokemob getRenderMob(final PokedexEntry entry, final World world)
return pokemob;
}

@SubscribeEvent
public static void mouseInput(final MouseInputEvent evt)
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void mouseInput(final RawMouseEvent evt)
{
final ClientPlayerEntity player = Minecraft.getInstance().player;
// We only handle these ingame anyway.
if (player == null) return;
//
// if (evt.getAction() == GLFW.GLFW_PRESS && evt.getButton() ==
// GLFW.GLFW_MOUSE_BUTTON_RIGHT) System.out.println(
// "test");
if (evt.getAction() == GLFW.GLFW_PRESS && evt.getButton() == GLFW.GLFW_MOUSE_BUTTON_RIGHT) if (Minecraft
.getInstance().objectMouseOver == null || Minecraft.getInstance().objectMouseOver
.getType() == Type.MISS)
{
final Entity entity = Tools.getPointedEntity(player, 5);
if (entity != null) hands:
for (final Hand hand : Hand.values())
if (Minecraft.getInstance().playerController.interactWithEntity(player, entity,
hand) == ActionResultType.SUCCESS)
{
evt.setCanceled(true);
break hands;
}
}
}

@SubscribeEvent
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/pokecube/core/utils/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ public static Entity getPointedEntity(final Entity entity, final double distance

public static Entity getPointedEntity(final Entity entity, double distance, final Predicate<Entity> selector)
{
final Vec3d vec3 = new Vec3d(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
final Vector3 pos = Vector3.getNewVector().set(vec3);
final Vector3 pos = Vector3.getNewVector().set(entity, true);
final Vector3 loc = Tools.getPointedLocation(entity, distance);
if (loc != null) distance = loc.distanceTo(pos);
final Vec3d vec31 = entity.getLook(0);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/thut/api/maths/Vector3.java
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ public Entity firstEntityExcluding(final double range, final Vec3d vec31, final
double ds = range;
final Vec3d vec3 = this.toVec3d();
final Vec3d vec32 = vec3.add(vec31.x * ds, vec31.y * ds, vec31.z * ds);
final float f = 0.5F;
final float f = 2.5F;
final AxisAlignedBB aabb = this.getAABB().expand(vec31.x * ds, vec31.y * ds, vec31.z * ds).grow(f, f, f);
final List<Entity> mobs = world.getEntitiesInAABBexcluding(entity, aabb, predicate);
ds *= ds;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/thut/core/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickItem;
import net.minecraftforge.event.world.WorldEvent.Load;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.thread.EffectiveSide;
Expand All @@ -37,7 +38,7 @@ public class ClientProxy extends CommonProxy
private long lastRightClickItemMain = 0;
private long lastRightClickItemOff = 0;

@SubscribeEvent
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void mouseFloodCtrl(final RawMouseEvent evt)
{
final ClientPlayerEntity player = Minecraft.getInstance().player;
Expand All @@ -52,7 +53,7 @@ public void mouseFloodCtrl(final RawMouseEvent evt)
this.lastMouseRightClickDown = time;
}

@SubscribeEvent
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void mouseFloodCtrl(final RightClickBlock evt)
{
final ClientPlayerEntity player = Minecraft.getInstance().player;
Expand All @@ -69,7 +70,7 @@ public void mouseFloodCtrl(final RightClickBlock evt)
else this.lastRightClickBlockOff = time;
}

@SubscribeEvent
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void mouseFloodCtrl(final RightClickItem evt)
{
final ClientPlayerEntity player = Minecraft.getInstance().player;
Expand Down

0 comments on commit ca18045

Please sign in to comment.