-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
042879b
commit a4fba4a
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/northwestwind/moreboots/handler/packet/CPlayerKAPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.northwestwind.moreboots.handler.packet; | ||
|
||
import com.northwestwind.moreboots.init.ItemInit; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.inventory.EquipmentSlotType; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.EntityPredicates; | ||
import net.minecraft.util.math.AxisAlignedBB; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraftforge.fml.network.NetworkDirection; | ||
import net.minecraftforge.fml.network.NetworkEvent; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
public class CPlayerKAPacket implements Serializable { | ||
public void handle(final NetworkEvent.Context ctx) { | ||
if (!ctx.getDirection().equals(NetworkDirection.PLAY_TO_SERVER)) return; | ||
ServerPlayerEntity player = ctx.getSender(); | ||
if(player == null) return; | ||
ItemStack boots = player.getItemStackFromSlot(EquipmentSlotType.FEET); | ||
if(!boots.getItem().equals(ItemInit.KA_BOOTS)) return; | ||
BlockPos pos = new BlockPos(player.getPositionVec()); | ||
AxisAlignedBB area = new AxisAlignedBB(pos).expand(8, 8, 8); | ||
List<Entity> collidedEntities = player.world.getEntitiesInAABBexcluding(player, area, EntityPredicates.NOT_SPECTATING); | ||
LivingEntity closest = null; | ||
for (Entity entity : collidedEntities) { | ||
if (!(entity instanceof LivingEntity)) continue; | ||
if (closest == null || closest.getPositionVec().distanceTo(player.getPositionVec()) > entity.getPositionVec().distanceTo(player.getPositionVec())) closest = (LivingEntity) entity; | ||
} | ||
if (closest == null) return; | ||
player.attackTargetEntityWithCurrentItem(closest); | ||
} | ||
} |