2022-05-11 22:08:31 -05:00
|
|
|
package noppes.npcs.scripted;
|
2021-09-30 21:44:30 -05:00
|
|
|
|
2025-03-11 22:18:39 -04:00
|
|
|
import cpw.mods.fml.common.Loader;
|
2021-09-30 21:44:30 -05:00
|
|
|
import cpw.mods.fml.common.eventhandler.EventBus;
|
2022-12-18 15:54:14 -06:00
|
|
|
import foxz.command.ScriptedCommand;
|
2026-02-18 05:13:51 -05:00
|
|
|
import kamkeel.npcs.controllers.AbilityController;
|
2025-03-14 05:35:23 -04:00
|
|
|
import kamkeel.npcs.controllers.AttributeController;
|
2025-02-21 17:30:57 -05:00
|
|
|
import kamkeel.npcs.controllers.ProfileController;
|
2026-01-24 02:35:26 -05:00
|
|
|
import kamkeel.npcs.controllers.TelegraphController;
|
2026-02-16 01:03:05 -05:00
|
|
|
import kamkeel.npcs.entity.EntityAbilityBeam;
|
|
|
|
|
import kamkeel.npcs.entity.EntityAbilityDisc;
|
2026-03-01 03:00:17 -05:00
|
|
|
import kamkeel.npcs.entity.EntityEnergyDome;
|
2026-02-16 01:03:05 -05:00
|
|
|
import kamkeel.npcs.entity.EntityAbilityLaser;
|
|
|
|
|
import kamkeel.npcs.entity.EntityAbilityOrb;
|
2026-03-01 03:00:17 -05:00
|
|
|
import kamkeel.npcs.entity.EntityEnergyPanel;
|
|
|
|
|
import kamkeel.npcs.entity.EntityEnergySweeper;
|
2026-02-17 14:32:13 -05:00
|
|
|
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
2026-02-21 14:40:14 -05:00
|
|
|
import kamkeel.npcs.entity.EntityEnergySlicer;
|
2022-05-17 18:02:09 -05:00
|
|
|
import net.minecraft.block.Block;
|
2022-12-18 15:54:14 -06:00
|
|
|
import net.minecraft.command.CommandHandler;
|
2021-09-30 21:44:30 -05:00
|
|
|
import net.minecraft.entity.Entity;
|
2021-10-21 22:14:12 -05:00
|
|
|
import net.minecraft.entity.EntityLiving;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2022-11-06 01:59:34 -05:00
|
|
|
import net.minecraft.entity.INpc;
|
2023-03-16 05:07:38 -05:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2021-10-21 22:14:12 -05:00
|
|
|
import net.minecraft.entity.monster.EntityMob;
|
|
|
|
|
import net.minecraft.entity.passive.EntityAnimal;
|
|
|
|
|
import net.minecraft.entity.passive.EntityTameable;
|
2024-02-20 21:08:48 -05:00
|
|
|
import net.minecraft.entity.passive.EntityVillager;
|
2021-10-18 06:33:39 -05:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2025-07-08 16:56:35 -04:00
|
|
|
import net.minecraft.entity.projectile.EntityArrow;
|
|
|
|
|
import net.minecraft.entity.projectile.EntityFishHook;
|
|
|
|
|
import net.minecraft.entity.projectile.EntityThrowable;
|
2024-01-25 14:54:34 -05:00
|
|
|
import net.minecraft.init.Items;
|
2021-09-30 21:44:30 -05:00
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
2025-07-23 14:22:52 -04:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemArmor;
|
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
|
import net.minecraft.item.ItemEditableBook;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.item.ItemWritableBook;
|
2024-12-22 17:26:09 -06:00
|
|
|
import net.minecraft.nbt.NBTBase;
|
2021-09-30 21:44:30 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2024-12-22 17:26:09 -06:00
|
|
|
import net.minecraft.nbt.NBTTagString;
|
2021-11-22 01:10:27 -06:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
2022-11-05 20:19:14 -05:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2021-09-30 21:44:30 -05:00
|
|
|
import net.minecraft.util.DamageSource;
|
2021-10-25 00:58:03 -05:00
|
|
|
import net.minecraft.util.EntityDamageSource;
|
2021-09-30 21:44:30 -05:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import net.minecraft.world.WorldServer;
|
2022-06-29 00:06:38 -05:00
|
|
|
import net.minecraft.world.biome.BiomeGenBase;
|
2025-07-07 05:37:31 -04:00
|
|
|
import net.minecraftforge.common.BiomeDictionary;
|
|
|
|
|
import net.minecraftforge.common.BiomeDictionary.Type;
|
2021-09-30 21:44:30 -05:00
|
|
|
import noppes.npcs.CustomNpcs;
|
|
|
|
|
import noppes.npcs.NoppesUtilServer;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.api.AbstractNpcAPI;
|
|
|
|
|
import noppes.npcs.api.IBlock;
|
|
|
|
|
import noppes.npcs.api.ICommand;
|
|
|
|
|
import noppes.npcs.api.IContainer;
|
|
|
|
|
import noppes.npcs.api.IDamageSource;
|
|
|
|
|
import noppes.npcs.api.INbt;
|
|
|
|
|
import noppes.npcs.api.IParticle;
|
|
|
|
|
import noppes.npcs.api.IPos;
|
|
|
|
|
import noppes.npcs.api.ISkinOverlay;
|
2026-02-18 05:13:51 -05:00
|
|
|
import noppes.npcs.api.ITelegraph;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.api.ITileEntity;
|
|
|
|
|
import noppes.npcs.api.IWorld;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.api.entity.ICustomNpc;
|
|
|
|
|
import noppes.npcs.api.entity.IEntity;
|
|
|
|
|
import noppes.npcs.api.entity.IPlayer;
|
|
|
|
|
import noppes.npcs.api.gui.ICustomGui;
|
2026-02-24 20:23:44 -03:00
|
|
|
import noppes.npcs.api.handler.*;
|
2023-01-16 13:53:15 -06:00
|
|
|
import noppes.npcs.api.handler.data.IAnimation;
|
|
|
|
|
import noppes.npcs.api.handler.data.IFrame;
|
|
|
|
|
import noppes.npcs.api.handler.data.IFramePart;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.api.handler.data.ISound;
|
|
|
|
|
import noppes.npcs.api.item.IItemStack;
|
|
|
|
|
import noppes.npcs.api.overlay.ICustomOverlay;
|
2023-07-19 11:17:11 -04:00
|
|
|
import noppes.npcs.compat.PixelmonHelper;
|
2023-01-07 00:21:08 -05:00
|
|
|
import noppes.npcs.config.ConfigScript;
|
2023-01-16 13:53:15 -06:00
|
|
|
import noppes.npcs.constants.EnumAnimationPart;
|
2022-11-05 20:19:14 -05:00
|
|
|
import noppes.npcs.containers.ContainerNpcInterface;
|
2026-02-24 20:23:44 -03:00
|
|
|
import noppes.npcs.controllers.*;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.controllers.data.Animation;
|
|
|
|
|
import noppes.npcs.controllers.data.Frame;
|
|
|
|
|
import noppes.npcs.controllers.data.FramePart;
|
|
|
|
|
import noppes.npcs.controllers.data.SkinOverlay;
|
2025-06-30 18:13:31 +03:00
|
|
|
import noppes.npcs.controllers.data.action.ActionManager;
|
2021-09-30 21:44:30 -05:00
|
|
|
import noppes.npcs.entity.EntityCustomNpc;
|
|
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
2023-03-16 02:51:40 -05:00
|
|
|
import noppes.npcs.entity.EntityProjectile;
|
2025-02-13 18:11:58 -06:00
|
|
|
import noppes.npcs.items.ItemLinked;
|
2022-11-05 20:19:14 -05:00
|
|
|
import noppes.npcs.items.ItemScripted;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.scripted.entity.ScriptAnimal;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptArrow;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptDBCPlayer;
|
2026-02-16 01:03:05 -05:00
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergyBeam;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergyDisc;
|
2026-02-21 14:40:14 -05:00
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergyDome;
|
2026-02-16 01:03:05 -05:00
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergyLaser;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergyOrb;
|
2026-02-21 14:40:14 -05:00
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergyPanel;
|
2026-02-17 14:32:13 -05:00
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergyProjectile;
|
2026-02-21 14:40:14 -05:00
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergySlicer;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptEnergySweeper;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.scripted.entity.ScriptEntity;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptEntityItem;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptFishHook;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptLiving;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptLivingBase;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptMonster;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptPixelmon;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptPlayer;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptProjectile;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptThrowable;
|
|
|
|
|
import noppes.npcs.scripted.entity.ScriptVillager;
|
2022-01-12 04:44:08 -06:00
|
|
|
import noppes.npcs.scripted.gui.ScriptGui;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.scripted.item.ScriptCustomItem;
|
|
|
|
|
import noppes.npcs.scripted.item.ScriptItemArmor;
|
|
|
|
|
import noppes.npcs.scripted.item.ScriptItemBlock;
|
|
|
|
|
import noppes.npcs.scripted.item.ScriptItemBook;
|
|
|
|
|
import noppes.npcs.scripted.item.ScriptItemStack;
|
|
|
|
|
import noppes.npcs.scripted.item.ScriptLinkedItem;
|
2022-01-30 04:05:01 -06:00
|
|
|
import noppes.npcs.scripted.overlay.ScriptOverlay;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.util.CacheHashMap;
|
|
|
|
|
import noppes.npcs.util.JsonException;
|
|
|
|
|
import noppes.npcs.util.LRUHashMap;
|
|
|
|
|
import noppes.npcs.util.NBTJsonUtil;
|
|
|
|
|
import noppes.npcs.util.SizeOfObjectUtil;
|
2021-09-30 21:44:30 -05:00
|
|
|
|
2025-07-23 14:22:52 -04:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
2024-07-20 16:46:41 -05:00
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
2025-07-23 14:22:52 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
2024-07-20 19:50:23 -05:00
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.Executors;
|
2022-11-05 20:19:14 -05:00
|
|
|
|
2022-05-11 17:12:48 -05:00
|
|
|
public class NpcAPI extends AbstractNpcAPI {
|
2025-03-13 17:14:45 -04:00
|
|
|
private static final Map<String, Object> tempData = new HashMap<>();
|
2022-11-05 20:19:14 -05:00
|
|
|
private static final Map<Integer, ScriptWorld> worldCache = new LRUHashMap<>(10);
|
2025-03-13 17:14:45 -04:00
|
|
|
private static final CacheHashMap<ItemStack, CacheHashMap.CachedObject<ScriptItemStack>> scriptItemCache = new CacheHashMap<>(60 * 1000);
|
|
|
|
|
public static final HashMap<String, Object> engineObjects = new HashMap<>();
|
2021-09-30 21:44:30 -05:00
|
|
|
public static final EventBus EVENT_BUS = new EventBus();
|
2022-05-11 17:12:48 -05:00
|
|
|
private static AbstractNpcAPI instance = null;
|
2021-09-30 21:44:30 -05:00
|
|
|
|
2024-07-20 16:46:41 -05:00
|
|
|
private final static String API_USER_AGENT = "CNPC+API";
|
2024-07-20 19:50:23 -05:00
|
|
|
private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
|
2024-07-20 16:46:41 -05:00
|
|
|
|
2023-05-30 01:27:34 -05:00
|
|
|
private NpcAPI() {
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void clearCache() {
|
|
|
|
|
worldCache.clear();
|
2023-06-02 23:30:23 -05:00
|
|
|
scriptItemCache.clear();
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public Object getTempData(String key) {
|
2024-12-22 17:26:09 -06:00
|
|
|
return tempData.get(key);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void setTempData(String key, Object value) {
|
2024-12-22 17:26:09 -06:00
|
|
|
tempData.put(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public boolean hasTempData(String key) {
|
2024-12-22 17:26:09 -06:00
|
|
|
return tempData.containsKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void removeTempData(String key) {
|
2024-12-22 17:26:09 -06:00
|
|
|
tempData.remove(key);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void clearTempData() {
|
2024-12-22 17:26:09 -06:00
|
|
|
tempData.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String[] getTempDataKeys() {
|
|
|
|
|
return tempData.keySet().toArray(new String[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public Object getStoredData(String key) {
|
2024-12-22 17:26:09 -06:00
|
|
|
NBTTagCompound compound = ScriptController.Instance.compound;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (!compound.hasKey(key))
|
2024-12-22 17:26:09 -06:00
|
|
|
return null;
|
|
|
|
|
NBTBase base = compound.getTag(key);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (base instanceof NBTBase.NBTPrimitive)
|
|
|
|
|
return ((NBTBase.NBTPrimitive) base).func_150286_g();
|
|
|
|
|
return ((NBTTagString) base).func_150285_a_();
|
2024-12-22 17:26:09 -06:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void setStoredData(String key, Object value) {
|
2024-12-22 17:26:09 -06:00
|
|
|
NBTTagCompound compound = ScriptController.Instance.compound;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (value instanceof Number)
|
2024-12-22 17:26:09 -06:00
|
|
|
compound.setDouble(key, ((Number) value).doubleValue());
|
2025-03-13 17:14:45 -04:00
|
|
|
else if (value instanceof String)
|
|
|
|
|
compound.setString(key, (String) value);
|
2024-12-22 17:26:09 -06:00
|
|
|
ScriptController.Instance.shouldSave = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public boolean hasStoredData(String key) {
|
2024-12-22 17:26:09 -06:00
|
|
|
return ScriptController.Instance.compound.hasKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void removeStoredData(String key) {
|
2024-12-22 17:26:09 -06:00
|
|
|
ScriptController.Instance.compound.removeTag(key);
|
|
|
|
|
ScriptController.Instance.shouldSave = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void clearStoredData() {
|
2024-12-22 17:26:09 -06:00
|
|
|
ScriptController.Instance.compound = new NBTTagCompound();
|
|
|
|
|
ScriptController.Instance.shouldSave = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String[] getStoredDataKeys() {
|
|
|
|
|
NBTTagCompound compound = ScriptController.Instance.compound;
|
|
|
|
|
if (compound != null) {
|
|
|
|
|
Set keySet = compound.func_150296_c();
|
|
|
|
|
List<String> list = new ArrayList<>();
|
2025-03-13 17:14:45 -04:00
|
|
|
for (Object o : keySet) {
|
2024-12-22 17:26:09 -06:00
|
|
|
list.add((String) o);
|
|
|
|
|
}
|
|
|
|
|
String[] array = list.toArray(new String[list.size()]);
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
return new String[0];
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-18 15:54:14 -06:00
|
|
|
public void registerICommand(ICommand command) {
|
2025-03-13 17:14:45 -04:00
|
|
|
((CommandHandler) CustomNpcs.getServer().getCommandManager()).registerCommand((ScriptedCommand) command);
|
2022-12-18 15:54:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand getICommand(String commandName, int priorityLevel) {
|
2025-03-13 17:14:45 -04:00
|
|
|
return new ScriptedCommand(commandName, priorityLevel);
|
2022-12-18 15:54:14 -06:00
|
|
|
}
|
|
|
|
|
|
2022-12-14 17:53:57 -06:00
|
|
|
public void addGlobalObject(String key, Object obj) {
|
2025-03-13 17:14:45 -04:00
|
|
|
NpcAPI.engineObjects.put(key, obj);
|
2022-12-14 17:53:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeGlobalObject(String key) {
|
|
|
|
|
NpcAPI.engineObjects.remove(key);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 19:36:39 -06:00
|
|
|
public boolean hasGlobalObject(String key) {
|
|
|
|
|
return NpcAPI.engineObjects.containsKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public HashMap<String, Object> getEngineObjects() {
|
2022-12-14 17:53:57 -06:00
|
|
|
return NpcAPI.engineObjects;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 17:02:40 -05:00
|
|
|
public long sizeOfObject(Object obj) {
|
2024-03-11 16:10:04 -04:00
|
|
|
return SizeOfObjectUtil.sizeOfObject(obj);
|
2022-07-01 17:02:40 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 18:54:11 -05:00
|
|
|
public void stopServer() {
|
2022-11-06 01:59:34 -05:00
|
|
|
MinecraftServer.getServer().initiateShutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getCurrentPlayerCount() {
|
|
|
|
|
return MinecraftServer.getServer().getConfigurationManager().getCurrentPlayerCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMaxPlayers() {
|
|
|
|
|
return MinecraftServer.getServer().getConfigurationManager().getMaxPlayers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void kickAllPlayers() {
|
|
|
|
|
MinecraftServer.getServer().getConfigurationManager().removeAllPlayers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isHardcore() {
|
|
|
|
|
return MinecraftServer.getServer().isHardcore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File getFile(String path) {
|
|
|
|
|
return MinecraftServer.getServer().getFile(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getServerOwner() {
|
|
|
|
|
return MinecraftServer.getServer().getServerOwner();
|
2022-05-31 18:54:11 -05:00
|
|
|
}
|
|
|
|
|
|
2022-01-10 15:21:48 -06:00
|
|
|
public IFactionHandler getFactions() {
|
|
|
|
|
this.checkWorld();
|
|
|
|
|
return FactionController.getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IRecipeHandler getRecipes() {
|
|
|
|
|
this.checkWorld();
|
2023-06-05 22:12:48 -04:00
|
|
|
return RecipeController.Instance;
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IQuestHandler getQuests() {
|
|
|
|
|
this.checkWorld();
|
2023-06-05 22:12:48 -04:00
|
|
|
return QuestController.Instance;
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IDialogHandler getDialogs() {
|
2023-06-05 22:12:48 -04:00
|
|
|
return DialogController.Instance;
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICloneHandler getClones() {
|
|
|
|
|
return ServerCloneController.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public INaturalSpawnsHandler getNaturalSpawns() {
|
|
|
|
|
return SpawnController.Instance;
|
|
|
|
|
}
|
2022-06-29 00:06:38 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public IProfileHandler getProfileHandler() {
|
|
|
|
|
return ProfileController.Instance;
|
|
|
|
|
}
|
2025-02-21 17:30:57 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public ICustomEffectHandler getCustomEffectHandler() {
|
|
|
|
|
return CustomEffectController.Instance;
|
|
|
|
|
}
|
2025-02-21 17:30:57 -05:00
|
|
|
|
2025-03-13 17:20:23 -04:00
|
|
|
public IMagicHandler getMagicHandler() {
|
|
|
|
|
return MagicController.getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public IPartyHandler getPartyHandler() {
|
|
|
|
|
return PartyController.Instance();
|
|
|
|
|
}
|
2025-02-25 17:24:43 -05:00
|
|
|
|
2025-03-14 05:35:23 -04:00
|
|
|
public IAttributeHandler getAttributeHandler() {
|
|
|
|
|
return AttributeController.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 01:26:23 -05:00
|
|
|
public ITransportHandler getLocations() {
|
|
|
|
|
return TransportController.getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 14:14:13 -06:00
|
|
|
public IAnimationHandler getAnimations() {
|
|
|
|
|
this.checkWorld();
|
2023-06-05 22:12:48 -04:00
|
|
|
return AnimationController.Instance;
|
2023-01-26 14:14:13 -06:00
|
|
|
}
|
|
|
|
|
|
2026-02-24 20:23:44 -03:00
|
|
|
public ILinkedItemHandler getLinkedItems() {
|
|
|
|
|
return LinkedItemController.getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 17:15:13 -05:00
|
|
|
public IScriptHookHandler getScriptHooks() {
|
|
|
|
|
return ScriptHookController.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-09 15:29:00 -05:00
|
|
|
@Override
|
|
|
|
|
public IAbilityHandler getAbilities() {
|
|
|
|
|
this.checkWorld();
|
|
|
|
|
return AbilityController.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 02:35:26 -05:00
|
|
|
@Override
|
|
|
|
|
public ITelegraphHandler getTelegraphs() {
|
|
|
|
|
this.checkWorld();
|
|
|
|
|
return TelegraphController.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ITelegraph createTelegraph(String type) {
|
|
|
|
|
this.checkWorld();
|
|
|
|
|
return TelegraphController.Instance.create(type);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 15:11:50 -05:00
|
|
|
@Override
|
|
|
|
|
public IAuctionHandler getAuctions() {
|
|
|
|
|
this.checkWorld();
|
|
|
|
|
if (!noppes.npcs.config.ConfigMarket.AuctionEnabled) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return AuctionController.getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-29 00:06:38 -05:00
|
|
|
@Override
|
|
|
|
|
public String[] getAllBiomeNames() {
|
2022-11-05 20:19:14 -05:00
|
|
|
List<String> biomes = new ArrayList<>();
|
2025-07-07 05:37:31 -04:00
|
|
|
Set<BiomeGenBase> allBiomes = new HashSet<BiomeGenBase>();
|
|
|
|
|
for (Type type : BiomeDictionary.Type.values()) {
|
2025-07-07 06:30:37 -04:00
|
|
|
Collections.addAll(allBiomes, BiomeDictionary.getBiomesForType(type));
|
2025-07-07 05:37:31 -04:00
|
|
|
}
|
2022-06-29 00:06:38 -05:00
|
|
|
for (BiomeGenBase base : BiomeGenBase.getBiomeGenArray()) {
|
2025-07-07 05:37:31 -04:00
|
|
|
if (base != null)
|
|
|
|
|
allBiomes.add(base);
|
|
|
|
|
}
|
|
|
|
|
for (BiomeGenBase base : allBiomes) {
|
2022-06-29 00:06:38 -05:00
|
|
|
if (base != null && base.biomeName != null) {
|
|
|
|
|
biomes.add(base.biomeName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return biomes.toArray(new String[]{});
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-11 22:18:39 -04:00
|
|
|
|
|
|
|
|
public static Boolean dbcLoaded = null;
|
2025-03-13 17:14:45 -04:00
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public IEntity<?> getIEntity(Entity entity) {
|
2025-03-13 17:14:45 -04:00
|
|
|
if (entity == null)
|
2021-10-18 06:33:39 -05:00
|
|
|
return null;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (entity instanceof EntityNPCInterface)
|
|
|
|
|
return ((EntityNPCInterface) entity).wrappedNPC;
|
|
|
|
|
else {
|
2021-10-21 22:14:12 -05:00
|
|
|
ScriptEntityData data = (ScriptEntityData) entity.getExtendedProperties("ScriptedObject");
|
2025-03-11 22:18:39 -04:00
|
|
|
if (data == null) {
|
2024-10-24 17:12:00 -05:00
|
|
|
if (entity instanceof EntityPlayerMP) {
|
2025-03-13 17:14:45 -04:00
|
|
|
if (dbcLoaded == null) {
|
2025-03-11 22:18:39 -04:00
|
|
|
dbcLoaded = Loader.isModLoaded("jinryuujrmcore");
|
2024-10-24 17:12:00 -05:00
|
|
|
}
|
2025-03-11 22:18:39 -04:00
|
|
|
data = dbcLoaded ? new ScriptEntityData(new ScriptDBCPlayer<>((EntityPlayerMP) entity)) : new ScriptEntityData(new ScriptPlayer<>((EntityPlayerMP) entity));
|
2025-03-13 17:14:45 -04:00
|
|
|
} else if (PixelmonHelper.isPixelmon(entity))
|
2024-10-24 17:12:00 -05:00
|
|
|
return new ScriptPixelmon<EntityTameable>((EntityTameable) entity);
|
|
|
|
|
else if (entity instanceof EntityAnimal)
|
|
|
|
|
data = new ScriptEntityData(new ScriptAnimal<>((EntityAnimal) entity));
|
|
|
|
|
else if (entity instanceof EntityMob)
|
|
|
|
|
data = new ScriptEntityData(new ScriptMonster<>((EntityMob) entity));
|
|
|
|
|
else if (entity instanceof EntityVillager)
|
|
|
|
|
data = new ScriptEntityData(new ScriptVillager<>((EntityVillager) entity));
|
|
|
|
|
else if (entity instanceof EntityLiving)
|
|
|
|
|
data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity));
|
|
|
|
|
else if (entity instanceof EntityLivingBase)
|
|
|
|
|
data = new ScriptEntityData(new ScriptLivingBase<>((EntityLivingBase) entity));
|
|
|
|
|
else if (entity instanceof EntityProjectile)
|
|
|
|
|
data = new ScriptEntityData(new ScriptProjectile<>((EntityProjectile) entity));
|
|
|
|
|
else if (entity instanceof EntityItem)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEntityItem<>((EntityItem) entity));
|
2025-07-08 16:56:35 -04:00
|
|
|
else if (entity instanceof EntityThrowable)
|
|
|
|
|
data = new ScriptEntityData(new ScriptThrowable<>((EntityThrowable) entity));
|
|
|
|
|
else if (entity instanceof EntityArrow)
|
|
|
|
|
data = new ScriptEntityData(new ScriptArrow<>((EntityArrow) entity));
|
|
|
|
|
else if (entity instanceof EntityFishHook)
|
|
|
|
|
data = new ScriptEntityData(new ScriptFishHook<>((EntityFishHook) entity));
|
2026-02-16 01:03:05 -05:00
|
|
|
else if (entity instanceof EntityAbilityOrb)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergyOrb<>((EntityAbilityOrb) entity));
|
|
|
|
|
else if (entity instanceof EntityAbilityBeam)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergyBeam<>((EntityAbilityBeam) entity));
|
|
|
|
|
else if (entity instanceof EntityAbilityDisc)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergyDisc<>((EntityAbilityDisc) entity));
|
|
|
|
|
else if (entity instanceof EntityAbilityLaser)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergyLaser<>((EntityAbilityLaser) entity));
|
2026-02-21 14:40:14 -05:00
|
|
|
else if (entity instanceof EntityEnergySlicer)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergySlicer<>((EntityEnergySlicer) entity));
|
2026-02-17 14:32:13 -05:00
|
|
|
else if (entity instanceof EntityEnergyProjectile)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergyProjectile((EntityEnergyProjectile) entity));
|
2026-03-01 03:00:17 -05:00
|
|
|
else if (entity instanceof EntityEnergyDome)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergyDome<>((EntityEnergyDome) entity));
|
|
|
|
|
else if (entity instanceof EntityEnergyPanel)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergyPanel<>((EntityEnergyPanel) entity));
|
|
|
|
|
else if (entity instanceof EntityEnergySweeper)
|
|
|
|
|
data = new ScriptEntityData(new ScriptEnergySweeper<>((EntityEnergySweeper) entity));
|
2024-10-24 17:12:00 -05:00
|
|
|
else
|
|
|
|
|
data = new ScriptEntityData(new ScriptEntity<>(entity));
|
|
|
|
|
entity.registerExtendedProperties("ScriptedObject", data);
|
|
|
|
|
}
|
2021-10-21 22:14:12 -05:00
|
|
|
return data.base;
|
2021-10-18 06:33:39 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 01:59:34 -05:00
|
|
|
public INpc[] getChunkLoadingNPCs() {
|
|
|
|
|
ArrayList<INpc> list = new ArrayList<>();
|
2023-06-05 22:12:48 -04:00
|
|
|
Set<Entity> npcSet = ChunkController.Instance.tickets.keySet();
|
2022-11-06 01:59:34 -05:00
|
|
|
for (Entity entity : npcSet) {
|
|
|
|
|
if (entity instanceof EntityNPCInterface) {
|
|
|
|
|
list.add((INpc) NpcAPI.Instance().getIEntity(entity));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list.toArray(new INpc[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public IEntity<?>[] getLoadedEntities() {
|
|
|
|
|
ArrayList<IEntity<?>> list = new ArrayList<>();
|
2022-06-12 01:26:23 -05:00
|
|
|
|
|
|
|
|
for (IWorld world : worldCache.values()) {
|
|
|
|
|
for (Object obj : world.getMCWorld().loadedEntityList) {
|
|
|
|
|
list.add(NpcAPI.Instance().getIEntity((Entity) obj));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list.toArray(new IEntity[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public IBlock getIBlock(IWorld world, int x, int y, int z) {
|
|
|
|
|
Block block = world.getMCWorld().getBlock(x, y, z);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (block == null || block.isAir(world.getMCWorld(), x, y, z))
|
2022-11-05 20:19:14 -05:00
|
|
|
return null;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
return new ScriptBlock(world.getMCWorld(), world.getMCWorld().getBlock(x, y, z), new BlockPos(x, y, z));
|
2022-11-05 20:19:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IBlock getIBlock(IWorld world, IPos pos) {
|
2025-03-13 17:14:45 -04:00
|
|
|
return pos == null ? null : this.getIBlock(world, pos.getX(), pos.getY(), pos.getZ());
|
2022-11-05 20:19:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ITileEntity getITileEntity(IWorld world, IPos pos) {
|
2023-05-31 23:59:11 -05:00
|
|
|
if (pos == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
TileEntity tileEntity = world.getMCWorld().getTileEntity(pos.getX(), pos.getY(), pos.getZ());
|
2022-11-06 01:23:54 -06:00
|
|
|
return this.getITileEntity(tileEntity);
|
2022-11-05 20:19:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ITileEntity getITileEntity(IWorld world, int x, int y, int z) {
|
2025-03-13 17:14:45 -04:00
|
|
|
TileEntity tileEntity = world.getMCWorld().getTileEntity(x, y, z);
|
2022-11-06 01:23:54 -06:00
|
|
|
return this.getITileEntity(tileEntity);
|
2021-10-12 02:57:32 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public ITileEntity getITileEntity(TileEntity tileEntity) {
|
2022-11-06 01:23:54 -06:00
|
|
|
return tileEntity == null ? null : new ScriptTileEntity<>(tileEntity);
|
2022-05-17 18:02:09 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public IPos getIPos(BlockPos pos) {
|
|
|
|
|
return new ScriptBlockPos(pos);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-07 17:51:51 -05:00
|
|
|
public IPos getIPos(double x, double y, double z) {
|
2025-03-13 17:14:45 -04:00
|
|
|
return this.getIPos(new BlockPos(x, y, z));
|
2022-11-05 20:19:14 -05:00
|
|
|
}
|
|
|
|
|
|
2023-07-07 17:51:51 -05:00
|
|
|
public IPos getIPos(int x, int y, int z) {
|
|
|
|
|
return this.getIPos((double) x, (double) y, (double) z);
|
2022-11-05 20:19:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IPos getIPos(float x, float y, float z) {
|
2023-07-07 17:51:51 -05:00
|
|
|
return this.getIPos((double) x, (double) y, (double) z);
|
2021-10-18 06:33:39 -05:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 14:32:43 -05:00
|
|
|
public IPos getIPos(long serializedPos) {
|
|
|
|
|
return this.getIPos(BlockPos.fromLong(serializedPos));
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 15:08:58 -06:00
|
|
|
public IPos[] getAllInBox(IPos from, IPos to, boolean sortByDistance) {
|
|
|
|
|
ArrayList<IPos> list = new ArrayList<>();
|
2023-05-31 23:59:11 -05:00
|
|
|
if (from != null && to != null) {
|
2025-03-13 17:14:45 -04:00
|
|
|
Iterator<BlockPos> posIterable = BlockPos.getAllInBox(from.getMCPos(), to.getMCPos()).iterator();
|
2023-05-31 23:59:11 -05:00
|
|
|
posIterable.forEachRemaining(BlockPos -> list.add(this.getIPos(BlockPos)));
|
|
|
|
|
if (sortByDistance) {
|
|
|
|
|
list.sort(Comparator.comparingDouble(pos -> pos.distanceTo(from)));
|
|
|
|
|
}
|
2022-11-06 15:08:58 -06:00
|
|
|
}
|
|
|
|
|
return list.toArray(new IPos[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IPos[] getAllInBox(IPos from, IPos to) {
|
2025-03-13 17:14:45 -04:00
|
|
|
return this.getAllInBox(from, to, true);
|
2022-11-06 15:08:58 -06:00
|
|
|
}
|
|
|
|
|
|
2022-05-17 18:02:09 -05:00
|
|
|
public INbt getINbt(NBTTagCompound nbtTagCompound) {
|
2025-03-13 17:14:45 -04:00
|
|
|
return nbtTagCompound == null ? new ScriptNbt(new NBTTagCompound()) : new ScriptNbt(nbtTagCompound);
|
2021-10-12 03:23:56 -05:00
|
|
|
}
|
|
|
|
|
|
2022-01-10 15:21:48 -06:00
|
|
|
public INbt stringToNbt(String str) {
|
|
|
|
|
if (str != null && !str.isEmpty()) {
|
|
|
|
|
try {
|
|
|
|
|
return this.getINbt(NBTJsonUtil.Convert(str));
|
|
|
|
|
} catch (JsonException var3) {
|
2022-11-05 20:19:14 -05:00
|
|
|
throw new CustomNPCsException(var3, "Failed converting " + str);
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
} else {
|
2022-11-05 20:19:14 -05:00
|
|
|
throw new CustomNPCsException("Cant cast empty string to nbt");
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public ICustomNpc<?> createNPC(IWorld world) {
|
|
|
|
|
if (world.getMCWorld().isRemote) {
|
2021-09-30 21:44:30 -05:00
|
|
|
return null;
|
|
|
|
|
} else {
|
2022-11-05 20:19:14 -05:00
|
|
|
EntityCustomNpc npc = new EntityCustomNpc(world.getMCWorld());
|
2021-09-30 21:44:30 -05:00
|
|
|
return npc.wrappedNPC;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public ICustomNpc<?> spawnNPC(IWorld world, int x, int y, int z) {
|
|
|
|
|
if (world.getMCWorld().isRemote) {
|
2021-09-30 21:44:30 -05:00
|
|
|
return null;
|
|
|
|
|
} else {
|
2022-11-05 20:19:14 -05:00
|
|
|
EntityCustomNpc npc = new EntityCustomNpc(world.getMCWorld());
|
2025-03-13 17:14:45 -04:00
|
|
|
npc.setPositionAndRotation((double) x + 0.5D, y, (double) z + 0.5D, 0.0F, 0.0F);
|
2021-09-30 21:44:30 -05:00
|
|
|
npc.setHealth(npc.getMaxHealth());
|
2022-11-05 20:19:14 -05:00
|
|
|
world.getMCWorld().spawnEntityInWorld(npc);
|
2021-09-30 21:44:30 -05:00
|
|
|
return npc.wrappedNPC;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public ICustomNpc<?> spawnNPC(IWorld world, IPos pos) {
|
2023-05-31 23:59:11 -05:00
|
|
|
if (pos == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-11-05 20:19:14 -05:00
|
|
|
return this.spawnNPC(world, pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 17:12:48 -05:00
|
|
|
public static AbstractNpcAPI Instance() {
|
2021-09-30 21:44:30 -05:00
|
|
|
if (instance == null) {
|
2022-05-11 17:12:48 -05:00
|
|
|
instance = new NpcAPI();
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EventBus events() {
|
|
|
|
|
return EVENT_BUS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IItemStack getIItemStack(ItemStack itemstack) {
|
2025-03-13 17:14:45 -04:00
|
|
|
if (itemstack == null)
|
2022-05-13 23:14:55 -05:00
|
|
|
return null;
|
|
|
|
|
|
2023-05-30 01:46:29 -05:00
|
|
|
synchronized (scriptItemCache) {
|
2023-05-31 00:35:57 -05:00
|
|
|
ScriptItemStack scriptStack;
|
|
|
|
|
if (scriptItemCache.containsKey(itemstack)) {
|
|
|
|
|
scriptStack = scriptItemCache.get(itemstack).getObject();
|
|
|
|
|
} else {
|
2025-02-15 19:37:25 -05:00
|
|
|
if (itemstack.getItem() instanceof ItemLinked) {
|
2025-02-13 18:11:58 -06:00
|
|
|
scriptStack = new ScriptLinkedItem(itemstack);
|
|
|
|
|
} else if (itemstack.getItem() instanceof ItemScripted) {
|
2023-05-31 00:35:57 -05:00
|
|
|
scriptStack = new ScriptCustomItem(itemstack);
|
|
|
|
|
} else if (itemstack.getItem() instanceof ItemArmor) {
|
|
|
|
|
scriptStack = new ScriptItemArmor(itemstack);
|
2024-01-25 14:54:34 -05:00
|
|
|
} else if (itemstack.getItem() instanceof ItemWritableBook || itemstack.getItem() instanceof ItemEditableBook || itemstack.getItem() == Items.written_book || itemstack.getItem() == Items.writable_book) {
|
2023-05-31 00:35:57 -05:00
|
|
|
scriptStack = new ScriptItemBook(itemstack);
|
|
|
|
|
} else if (itemstack.getItem() instanceof ItemBlock) {
|
|
|
|
|
scriptStack = new ScriptItemBlock(itemstack);
|
|
|
|
|
} else {
|
|
|
|
|
scriptStack = new ScriptItemStack(itemstack);
|
2023-05-30 01:46:29 -05:00
|
|
|
}
|
2025-03-03 18:25:29 -05:00
|
|
|
scriptItemCache.put(itemstack, new CacheHashMap.CachedObject<>(scriptStack));
|
2023-05-30 01:33:18 -05:00
|
|
|
}
|
2023-05-31 00:35:57 -05:00
|
|
|
return scriptStack;
|
|
|
|
|
}
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2022-12-14 16:44:13 -06:00
|
|
|
public IItemStack createItemFromNBT(INbt nbt) {
|
|
|
|
|
return getIItemStack(ItemStack.loadItemStackFromNBT(nbt.getMCNBT()));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 22:42:31 -05:00
|
|
|
public IItemStack createItem(String id, int damage, int size) {
|
|
|
|
|
Item item = (Item) Item.itemRegistry.getObject(id);
|
|
|
|
|
if (item == null)
|
2022-05-11 17:12:48 -05:00
|
|
|
return null;
|
2022-05-11 22:42:31 -05:00
|
|
|
|
2022-05-13 23:14:55 -05:00
|
|
|
return getIItemStack(new ItemStack(item, size, damage));
|
2022-05-11 17:12:48 -05:00
|
|
|
}
|
|
|
|
|
|
2022-06-10 17:25:58 -05:00
|
|
|
public IWorld getIWorld(World world) {
|
|
|
|
|
ScriptWorld w = worldCache.get(world.provider.dimensionId);
|
2021-09-30 21:44:30 -05:00
|
|
|
if (w != null) {
|
2022-06-10 17:25:58 -05:00
|
|
|
w.world.provider.dimensionId = world.provider.dimensionId;
|
2021-09-30 21:44:30 -05:00
|
|
|
} else {
|
2022-06-10 17:25:58 -05:00
|
|
|
worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world.provider.dimensionId));
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2022-11-05 20:19:14 -05:00
|
|
|
return w;
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IWorld getIWorld(int dimensionId) {
|
|
|
|
|
WorldServer[] var2 = CustomNpcs.getServer().worldServers;
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
for (WorldServer world : var2) {
|
2021-09-30 21:44:30 -05:00
|
|
|
if (world.provider.dimensionId == dimensionId) {
|
|
|
|
|
return this.getIWorld(world);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
throw new CustomNPCsException("Unknown dimension id: " + dimensionId);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2024-02-12 04:10:38 -05:00
|
|
|
public IWorld getIWorldLoad(int dimensionId) {
|
|
|
|
|
try {
|
|
|
|
|
IWorld iWorld = this.getIWorld(dimensionId);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (iWorld != null)
|
2024-02-12 04:10:38 -05:00
|
|
|
return iWorld;
|
2025-03-13 17:14:45 -04:00
|
|
|
} catch (CustomNPCsException ignored) {
|
2024-02-12 04:10:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WorldServer worldServer = CustomNpcs.getServer().worldServerForDimension(dimensionId);
|
|
|
|
|
if (worldServer != null) {
|
|
|
|
|
return this.getIWorld(worldServer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new CustomNPCsException("Unknown dimension id: " + dimensionId);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 21:44:30 -05:00
|
|
|
public IContainer getIContainer(IInventory inventory) {
|
|
|
|
|
return new ScriptContainer(inventory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IContainer getIContainer(Container container) {
|
2025-03-13 17:14:45 -04:00
|
|
|
return container instanceof ContainerNpcInterface ? ContainerNpcInterface.getOrCreateIContainer((ContainerNpcInterface) container) : new ScriptContainer(container);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2025-06-28 10:06:14 +03:00
|
|
|
public IActionManager getActionManager() {
|
2025-07-08 14:34:39 +03:00
|
|
|
return ActionManager.GLOBAL;
|
2025-06-28 10:06:14 +03:00
|
|
|
}
|
|
|
|
|
|
2021-09-30 21:44:30 -05:00
|
|
|
private void checkWorld() {
|
|
|
|
|
if (CustomNpcs.getServer() == null || CustomNpcs.getServer().isServerStopped()) {
|
2022-11-05 20:19:14 -05:00
|
|
|
throw new CustomNPCsException("No world is loaded right now");
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IWorld[] getIWorlds() {
|
|
|
|
|
this.checkWorld();
|
|
|
|
|
IWorld[] worlds = new IWorld[CustomNpcs.getServer().worldServers.length];
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
for (int i = 0; i < CustomNpcs.getServer().worldServers.length; ++i) {
|
2021-09-30 21:44:30 -05:00
|
|
|
worlds[i] = this.getIWorld(CustomNpcs.getServer().worldServers[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return worlds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File getGlobalDir() {
|
|
|
|
|
return CustomNpcs.Dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File getWorldDir() {
|
|
|
|
|
return CustomNpcs.getWorldSaveDirectory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IDamageSource getIDamageSource(DamageSource damagesource) {
|
|
|
|
|
return new ScriptDamageSource(damagesource);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 20:19:14 -05:00
|
|
|
public IDamageSource getIDamageSource(IEntity<?> entity) {
|
2025-03-13 17:14:45 -04:00
|
|
|
if (entity.getType() == 1)//if player
|
|
|
|
|
return new ScriptDamageSource(new EntityDamageSource("player", entity.getMCEntity()));
|
2022-01-22 22:50:01 -06:00
|
|
|
else
|
2025-03-13 17:14:45 -04:00
|
|
|
return new ScriptDamageSource(new EntityDamageSource(entity.getTypeName(), entity.getMCEntity()));
|
2021-10-25 00:58:03 -05:00
|
|
|
}
|
|
|
|
|
|
2021-10-19 19:49:43 -05:00
|
|
|
public void executeCommand(IWorld world, String command) {
|
|
|
|
|
//if(!world.getMCWorld().isRemote)
|
2025-03-13 17:14:45 -04:00
|
|
|
NoppesUtilServer.runCommand(world.getMCWorld(), "API", command);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2022-05-17 18:02:09 -05:00
|
|
|
|
2021-09-30 21:44:30 -05:00
|
|
|
public String getRandomName(int dictionary, int gender) {
|
|
|
|
|
return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender);
|
|
|
|
|
}
|
2021-11-22 01:10:27 -06:00
|
|
|
|
2022-11-06 01:59:34 -05:00
|
|
|
/**
|
|
|
|
|
* @param username The username of the player to be returned
|
|
|
|
|
* @return The Player with name. Null is returned when the player isn't found
|
|
|
|
|
*/
|
|
|
|
|
public IPlayer<?> getPlayer(String username) {
|
|
|
|
|
EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().func_152612_a(username);
|
|
|
|
|
return player == null ? null : (IPlayer<?>) NpcAPI.Instance().getIEntity(player);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public IPlayer<?>[] getAllServerPlayers() {
|
2022-11-05 20:19:14 -05:00
|
|
|
List<?> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
|
|
|
|
|
IPlayer<?>[] arr = new IPlayer[list.size()];
|
2025-03-13 17:14:45 -04:00
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
arr[i] = (IPlayer<?>) NpcAPI.Instance().getIEntity((EntityPlayerMP) list.get(i));
|
2021-11-22 01:10:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-13 19:27:27 -05:00
|
|
|
public String[] getPlayerNames() {
|
2022-11-06 01:59:34 -05:00
|
|
|
return MinecraftServer.getServer().getConfigurationManager().getAllUsernames();
|
2022-07-13 19:27:27 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void playSoundAtEntity(IEntity<?> entity, String sound, float volume, float pitch) {
|
2022-05-03 23:09:21 -05:00
|
|
|
entity.getWorld().getMCWorld().playSoundAtEntity(entity.getMCEntity(), sound, volume, pitch);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void playSoundToNearExcept(IPlayer<?> player, String sound, float volume, float pitch) {
|
2022-11-05 20:19:14 -05:00
|
|
|
player.getWorld().getMCWorld().playSoundToNearExcept(player.getMCEntity(), sound, volume, pitch);
|
2022-05-03 23:09:21 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public String getMOTD() {
|
2022-05-03 23:09:21 -05:00
|
|
|
return MinecraftServer.getServer().getMOTD();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void setMOTD(String motd) {
|
2022-05-03 23:09:21 -05:00
|
|
|
MinecraftServer.getServer().setMOTD(motd);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public IParticle createParticle(String directory) {
|
2022-05-06 03:38:24 -05:00
|
|
|
return new ScriptParticle(directory);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-07 03:46:37 -05:00
|
|
|
@Deprecated
|
2025-03-13 17:14:45 -04:00
|
|
|
public IParticle createEntityParticle(String directory) {
|
2022-05-06 03:38:24 -05:00
|
|
|
return new ScriptParticle(directory);
|
2021-11-22 01:10:27 -06:00
|
|
|
}
|
2021-11-22 02:33:28 -06:00
|
|
|
|
2022-07-13 19:27:27 -05:00
|
|
|
public ISound createSound(String directory) {
|
|
|
|
|
return new ScriptSound(directory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void playSound(int id, ISound sound) {
|
|
|
|
|
NoppesUtilServer.playSound(id, (ScriptSound) sound);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 19:07:19 -06:00
|
|
|
public void playSound(ISound sound) {
|
|
|
|
|
NoppesUtilServer.playSound((ScriptSound) sound);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-13 19:27:27 -05:00
|
|
|
public void stopSound(int id) {
|
|
|
|
|
NoppesUtilServer.stopSound(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void pauseSounds() {
|
|
|
|
|
NoppesUtilServer.pauseSounds();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void continueSounds() {
|
|
|
|
|
NoppesUtilServer.continueSounds();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stopSounds() {
|
|
|
|
|
NoppesUtilServer.stopSounds();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-22 02:33:28 -06:00
|
|
|
public int getServerTime() {
|
|
|
|
|
return MinecraftServer.getServer().getTickCounter();
|
|
|
|
|
}
|
2022-01-12 04:44:08 -06:00
|
|
|
|
2022-05-16 00:42:40 -05:00
|
|
|
public boolean arePlayerScriptsEnabled() {
|
2023-01-07 00:21:08 -05:00
|
|
|
return ConfigScript.GlobalPlayerScripts;
|
2022-05-16 00:42:40 -05:00
|
|
|
}
|
2022-05-16 22:04:54 -05:00
|
|
|
|
2022-05-16 00:42:40 -05:00
|
|
|
public boolean areForgeScriptsEnabled() {
|
2023-01-07 00:21:08 -05:00
|
|
|
return ConfigScript.GlobalForgeScripts;
|
2022-05-16 00:42:40 -05:00
|
|
|
}
|
2022-05-16 22:04:54 -05:00
|
|
|
|
2022-05-16 00:42:40 -05:00
|
|
|
public boolean areGlobalNPCScriptsEnabled() {
|
2023-01-07 00:21:08 -05:00
|
|
|
return ConfigScript.GlobalNPCScripts;
|
2022-05-16 00:42:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void enablePlayerScripts(boolean enable) {
|
2023-01-07 00:21:08 -05:00
|
|
|
ConfigScript.GlobalPlayerScripts = enable;
|
2022-05-16 00:42:40 -05:00
|
|
|
}
|
2022-05-16 22:04:54 -05:00
|
|
|
|
2022-05-16 00:42:40 -05:00
|
|
|
public void enableForgeScripts(boolean enable) {
|
2023-01-07 00:21:08 -05:00
|
|
|
ConfigScript.GlobalForgeScripts = enable;
|
2022-05-16 00:42:40 -05:00
|
|
|
}
|
2022-05-16 22:04:54 -05:00
|
|
|
|
2022-05-16 00:42:40 -05:00
|
|
|
public void enableGlobalNPCScripts(boolean enable) {
|
2023-01-07 00:21:08 -05:00
|
|
|
ConfigScript.GlobalNPCScripts = enable;
|
2022-05-16 00:42:40 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-16 22:04:54 -05:00
|
|
|
public ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame) {
|
|
|
|
|
return new ScriptGui(id, width, height, pauseGame);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-30 04:05:01 -06:00
|
|
|
public ICustomOverlay createCustomOverlay(int id) {
|
|
|
|
|
return new ScriptOverlay(id);
|
|
|
|
|
}
|
2022-05-16 22:04:54 -05:00
|
|
|
|
|
|
|
|
public ISkinOverlay createSkinOverlay(String texture) {
|
2022-05-23 20:47:32 -05:00
|
|
|
return new SkinOverlay(texture);
|
2022-05-16 22:04:54 -05:00
|
|
|
}
|
2022-12-20 09:21:39 -06:00
|
|
|
|
|
|
|
|
public String millisToTime(long millis) {
|
|
|
|
|
return NoppesUtilServer.millisToTime(millis);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String ticksToTime(long ticks) {
|
|
|
|
|
return this.millisToTime(ticks * 50);
|
|
|
|
|
}
|
2023-01-16 13:53:15 -06:00
|
|
|
|
2023-01-26 14:14:13 -06:00
|
|
|
public IAnimation createAnimation(String name) {
|
2023-11-01 21:39:08 -04:00
|
|
|
return new Animation(-1, name);
|
2023-01-25 23:18:27 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-26 14:14:13 -06:00
|
|
|
public IAnimation createAnimation(String name, float speed, byte smooth) {
|
2023-11-01 21:39:08 -04:00
|
|
|
return new Animation(-1, name, speed, smooth);
|
2023-01-16 13:53:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IFrame createFrame(int duration) {
|
|
|
|
|
return new Frame(duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IFrame createFrame(int duration, float speed, byte smooth) {
|
2025-03-13 17:14:45 -04:00
|
|
|
return new Frame(duration, speed, smooth);
|
2023-01-16 13:53:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IFramePart createPart(String name) {
|
|
|
|
|
try {
|
|
|
|
|
return new FramePart(EnumAnimationPart.valueOf(name));
|
|
|
|
|
} catch (IllegalArgumentException ignored) {
|
|
|
|
|
throw new CustomNPCsException("Invalid frame part name: " + name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 13:08:10 -06:00
|
|
|
public IFramePart createPart(String name, float[] rotation, float[] pivot) {
|
2023-01-16 13:53:15 -06:00
|
|
|
if (rotation.length != 3 || pivot.length != 3) {
|
|
|
|
|
throw new CustomNPCsException("Rotation and pivot arrays for frame parts must have a length of 3.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FramePart part = (FramePart) this.createPart(name);
|
|
|
|
|
part.setRotations(rotation);
|
|
|
|
|
part.setPivots(pivot);
|
|
|
|
|
return part;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 13:08:10 -06:00
|
|
|
public IFramePart createPart(String name, float[] rotation, float[] pivot, float speed, byte smooth) {
|
2025-03-13 17:14:45 -04:00
|
|
|
FramePart part = (FramePart) this.createPart(name, rotation, pivot);
|
2023-01-16 13:53:15 -06:00
|
|
|
part.setSpeed(speed);
|
|
|
|
|
part.setSmooth(smooth);
|
|
|
|
|
return part;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IFramePart createPart(int partId) {
|
|
|
|
|
for (EnumAnimationPart part : EnumAnimationPart.values()) {
|
2025-03-17 17:05:04 -05:00
|
|
|
if (part.ordinal() == partId) {
|
2023-01-16 13:53:15 -06:00
|
|
|
return new FramePart(part);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new CustomNPCsException("Invalid frame part ID: " + partId);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 13:08:10 -06:00
|
|
|
public IFramePart createPart(int partId, float[] rotation, float[] pivot) {
|
2023-01-16 13:53:15 -06:00
|
|
|
if (rotation.length != 3 || pivot.length != 3) {
|
|
|
|
|
throw new CustomNPCsException("Rotation and pivot arrays for frame parts must have a length of 3.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FramePart part = (FramePart) this.createPart(partId);
|
|
|
|
|
part.setRotations(rotation);
|
|
|
|
|
part.setPivots(pivot);
|
|
|
|
|
return part;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 13:08:10 -06:00
|
|
|
public IFramePart createPart(int partId, float[] rotation, float[] pivot, float speed, byte smooth) {
|
2025-03-13 17:14:45 -04:00
|
|
|
FramePart part = (FramePart) this.createPart(partId, rotation, pivot);
|
2023-01-16 13:53:15 -06:00
|
|
|
part.setSpeed(speed);
|
|
|
|
|
part.setSmooth(smooth);
|
|
|
|
|
return part;
|
|
|
|
|
}
|
2024-07-20 16:46:41 -05:00
|
|
|
|
2024-07-20 19:50:23 -05:00
|
|
|
public void postJsonHTTP(String url, String jsonPayload) {
|
|
|
|
|
this.postJsonHTTP(url, jsonPayload, API_USER_AGENT);
|
2024-07-20 16:46:41 -05:00
|
|
|
}
|
|
|
|
|
|
2024-07-20 19:50:23 -05:00
|
|
|
public void postJsonHTTP(String url, String jsonPayload, String userAgent) {
|
|
|
|
|
this.postHTTP(url, jsonPayload, "application/json", userAgent);
|
2024-07-20 16:46:41 -05:00
|
|
|
}
|
|
|
|
|
|
2024-07-20 19:50:23 -05:00
|
|
|
public void postHTTP(String url, String params, String contentType) {
|
|
|
|
|
this.postHTTP(url, params, contentType, API_USER_AGENT);
|
2024-07-20 16:46:41 -05:00
|
|
|
}
|
|
|
|
|
|
2024-07-20 19:50:23 -05:00
|
|
|
public void postHTTP(String url, String params, String contentType, String userAgent) {
|
|
|
|
|
executorService.submit(() -> {
|
|
|
|
|
try {
|
|
|
|
|
HttpURLConnection con = NpcAPI.getConnection("POST", url, userAgent, contentType);
|
|
|
|
|
|
|
|
|
|
// For POST only - set doOutput to true
|
|
|
|
|
con.setDoOutput(true);
|
|
|
|
|
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
|
|
|
|
|
wr.writeBytes(params);
|
|
|
|
|
wr.flush();
|
|
|
|
|
wr.close();
|
|
|
|
|
|
|
|
|
|
int responseCode = con.getResponseCode();
|
|
|
|
|
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
|
|
|
|
String inputLine;
|
|
|
|
|
StringBuilder response = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
|
|
|
response.append(inputLine);
|
|
|
|
|
}
|
|
|
|
|
in.close();
|
2024-07-20 16:46:41 -05:00
|
|
|
}
|
2024-07-20 19:50:23 -05:00
|
|
|
} catch (Exception ignored) {
|
2024-07-20 16:46:41 -05:00
|
|
|
}
|
2024-07-20 19:50:23 -05:00
|
|
|
});
|
2024-07-20 16:46:41 -05:00
|
|
|
}
|
|
|
|
|
|
2024-07-20 19:50:23 -05:00
|
|
|
private static HttpURLConnection getConnection(String requestMethod, String url, String userAgent, String contentType) throws IOException {
|
2024-07-20 16:46:41 -05:00
|
|
|
URL obj = new URL(url);
|
|
|
|
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
|
|
|
|
|
|
|
|
|
con.setRequestMethod(requestMethod);
|
|
|
|
|
con.setRequestProperty("User-Agent", userAgent);
|
|
|
|
|
//con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
|
|
|
|
|
if (!contentType.isEmpty()) {
|
|
|
|
|
con.setRequestProperty("Content-Type", contentType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return con;
|
|
|
|
|
}
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|