2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.items;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.util.ChatComponentText;
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import noppes.npcs.CustomItems;
|
|
|
|
|
import noppes.npcs.CustomNpcsPermissions;
|
|
|
|
|
import noppes.npcs.NoppesUtilServer;
|
2023-01-07 00:21:08 -05:00
|
|
|
import noppes.npcs.config.ConfigMain;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.constants.EnumGuiType;
|
|
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
2023-01-12 21:33:06 -05:00
|
|
|
|
|
|
|
|
import java.util.List;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public class ItemNpcMovingPath extends Item {
|
|
|
|
|
public ItemNpcMovingPath() {
|
2018-09-13 12:03:28 -04:00
|
|
|
maxStackSize = 1;
|
|
|
|
|
setCreativeTab(CustomItems.tab);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@Override
|
|
|
|
|
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
|
|
|
|
if (par2World.isRemote || !CustomNpcsPermissions.Instance.hasPermission(par3EntityPlayer, CustomNpcsPermissions.TOOL_MOUNTER))
|
|
|
|
|
return par1ItemStack;
|
|
|
|
|
EntityNPCInterface npc = getNpc(par1ItemStack, par2World);
|
|
|
|
|
if (npc != null)
|
|
|
|
|
NoppesUtilServer.sendOpenGui(par3EntityPlayer, EnumGuiType.MovingPath, npc);
|
2018-09-13 12:03:28 -04:00
|
|
|
return par1ItemStack;
|
|
|
|
|
}
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@Override
|
|
|
|
|
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, World par3World, int x, int y, int z, int par7, float par8, float par9, float par10) {
|
|
|
|
|
if (par3World.isRemote || !CustomNpcsPermissions.Instance.hasPermission(player, CustomNpcsPermissions.TOOL_MOUNTER))
|
|
|
|
|
return false;
|
|
|
|
|
EntityNPCInterface npc = getNpc(par1ItemStack, par3World);
|
|
|
|
|
if (npc == null)
|
|
|
|
|
return false;
|
|
|
|
|
List<int[]> list = npc.ais.getMovingPath();
|
|
|
|
|
int[] pos = list.get(list.size() - 1);
|
|
|
|
|
list.add(new int[]{x, y, z});
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
double d3 = x - pos[0];
|
|
|
|
|
double d4 = y - pos[1];
|
|
|
|
|
double d5 = z - pos[2];
|
2025-03-13 17:14:45 -04:00
|
|
|
double distance = (double) MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
player.addChatMessage(new ChatComponentText("Added point x:" + x + " y:" + y + " z:" + z + " to npc " + npc.getCommandSenderName()));
|
|
|
|
|
if (distance > ConfigMain.NpcNavRange)
|
|
|
|
|
player.addChatMessage(new ChatComponentText("Warning: point is too far away from previous point. Max block walk distance = " + ConfigMain.NpcNavRange));
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
return true;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
private EntityNPCInterface getNpc(ItemStack item, World world) {
|
|
|
|
|
if (world.isRemote || item.stackTagCompound == null)
|
|
|
|
|
return null;
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
Entity entity = world.getEntityByID(item.stackTagCompound.getInteger("NPCID"));
|
|
|
|
|
if (entity == null || !(entity instanceof EntityNPCInterface))
|
|
|
|
|
return null;
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
return (EntityNPCInterface) entity;
|
|
|
|
|
}
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
@Override
|
2025-03-13 17:14:45 -04:00
|
|
|
public int getColorFromItemStack(ItemStack par1ItemStack, int par2) {
|
|
|
|
|
return 0x8B4513;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-03-13 17:14:45 -04:00
|
|
|
public boolean requiresMultipleRenderPasses() {
|
2018-09-13 12:03:28 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
2024-03-16 00:52:43 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
@Override
|
2025-03-13 17:14:45 -04:00
|
|
|
public void registerIcons(IIconRegister par1IconRegister) {
|
2018-09-13 12:03:28 -04:00
|
|
|
this.itemIcon = Items.iron_sword.getIconFromDamage(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-03-13 17:14:45 -04:00
|
|
|
public Item setUnlocalizedName(String name) {
|
|
|
|
|
GameRegistry.registerItem(this, name);
|
|
|
|
|
return super.setUnlocalizedName(name);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
}
|