diff --git a/build.gradle b/build.gradle index ff61bcf49..49f75e853 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ configurations { apply plugin: 'forge' -version = "1.7-beta" +version = "1.6.5-beta2" group= "com.kamkeel.customnpc-plus" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "CustomNPC-Plus" diff --git a/docs/noppes/npcs/scripted/interfaces/IWorld.html b/docs/noppes/npcs/scripted/interfaces/IWorld.html index 43f27bad8..d9fe8e893 100644 --- a/docs/noppes/npcs/scripted/interfaces/IWorld.html +++ b/docs/noppes/npcs/scripted/interfaces/IWorld.html @@ -331,7 +331,7 @@ var activeTableTab = "activeTableTab"; getPlayerNames()  -noppes.npcs.scripted.ScriptScoreboard +noppes.npcs.scripted.scoreboard.ScriptScoreboard getScoreboard()  @@ -1873,7 +1873,7 @@ var activeTableTab = "activeTableTab"; diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 6c38cb421..8385467de 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -23,7 +23,6 @@ import net.minecraftforge.common.MinecraftForge; import nikedemos.markovnames.generators.*; import noppes.npcs.config.ConfigLoader; import noppes.npcs.config.ConfigProp; -import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.*; import noppes.npcs.enchants.EnchantInterface; import noppes.npcs.entity.*; @@ -33,7 +32,6 @@ import noppes.npcs.scripted.NpcAPI; import java.io.File; import java.util.ArrayList; import java.util.Set; -import java.util.Timer; import java.util.UUID; @Mod(modid = "customnpcs", name = "CustomNpcs", version = "1.6.4") @@ -61,12 +59,7 @@ public class CustomNpcs { "Every additional compound tag adds 65535 more characters to your script length limit. Use incrementally, with caution.") public static int ExpandedScriptLimit = 2; - @ConfigProp(info = "Enables if Player Information (WAND-USE) should be printed to CustomNPCs Logs. IF on Server \n" + - "Logs will only be present SERVER-SIDE only in CustomNPCs-latest, -1, -2, and -3") - public static boolean PlayerLogging = false; - - @ConfigProp(info = "Enables if Scripting Information should be printed to CustomNPCs Logs. IF on Server \n" + - "Logs will only be present SERVER-SIDE only in CustomNPCs-latest, -1, -2, and -3") + @ConfigProp(info = "Enables if Scripting Information should be printed to CustomNPCs Logs") public static boolean ScriptLogging = false; @ConfigProp(info = "Amount of Messages marked as SPAM [5, 3000]. Lower Number means MORE accurate messages \n" + @@ -76,10 +69,6 @@ public class CustomNpcs { @ConfigProp(info = "IN Milliseconds 1s = 1000s. If a recent LOG of the same event is SENT within this threshold it will be ignored.") public static int ScriptIgnoreTime = 2000; - @ConfigProp(info = "Comma separated list of NPC Script Types that will omit these from the logs,\n" + - "INIT,TICK,INTERACT,DIALOG,DAMAGED,KILLED,ATTACK,TARGET,COLLIDE,KILLS,DIALOG_CLOSE,TIMER") - public static String ScriptLogIgnoreType = "TICK"; - @ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96.") public static int NpcNavRange = 32; @@ -192,19 +181,6 @@ public class CustomNpcs { public static final MarkovGenerator[] MARKOV_GENERATOR = new MarkovGenerator[10]; - public static boolean InitIgnore = false; - public static boolean TickIgnore = false; - public static boolean InteractIgnore = false; - public static boolean DialogIgnore = false; - public static boolean DamagedIgnore = false; - public static boolean KilledIgnore = false; - public static boolean AttackIgnore = false; - public static boolean TargetIgnore = false; - public static boolean CollideIgnore = false; - public static boolean KillsIgnore = false; - public static boolean DialogCloseIgnore = false; - public static boolean TimerIgnore = false; - public CustomNpcs() { instance = this; } @@ -229,7 +205,7 @@ public class CustomNpcs { try { ScriptDevs.clear(); - String[] uuidStrings = ScriptDevIDs.split(","); + String[] uuidStrings = ScriptDevIDs.split(";"); for (String s : uuidStrings) { ScriptDevs.add(UUID.fromString(s)); } @@ -269,55 +245,6 @@ public class CustomNpcs { if (ScriptIgnoreTime < 0) ScriptIgnoreTime = 0; - try { - String[] ignoreTypes = ScriptLogIgnoreType.split(","); - for (String s : ignoreTypes) { - EnumScriptType type = EnumScriptType.valueOfIgnoreCase(s); - if(type != null){ - switch (type){ - case INIT: - InitIgnore = true; - break; - case TICK: - TickIgnore = true; - break; - case INTERACT: - InteractIgnore = true; - break; - case DIALOG: - DialogIgnore = true; - break; - case DAMAGED: - DamagedIgnore = true; - break; - case KILLED: - KilledIgnore = true; - break; - case ATTACK: - AttackIgnore = true; - break; - case TARGET: - TargetIgnore = true; - break; - case COLLIDE: - CollideIgnore = true; - break; - case KILLS: - KillsIgnore = true; - break; - case DIALOG_CLOSE: - DialogCloseIgnore = true; - break; - case TIMER: - TimerIgnore = true; - break; - default: - break; - } - } - } - } catch (Exception ignored) {} - EnchantInterface.load(); CustomItems.load(); diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 3966a47df..587aaf6cb 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -518,7 +518,7 @@ public class EventHooks { public static boolean onCNPCNaturalSpawn(INaturalSpawn naturalSpawn, BlockPos blockPos, boolean animalSpawnPassed, boolean monsterSpawnPassed, boolean liquidSpawnPassed, boolean airSpawnPassed) { ForgeDataScript handler = ScriptController.Instance.forgeScripts; if (handler.isEnabled()) { - IPos attemptPosition = new ScriptBlockPos(blockPos); + IPos attemptPosition = NpcAPI.Instance().getIPos(blockPos); CustomNPCsEvent.CNPCNaturalSpawnEvent event = new CustomNPCsEvent.CNPCNaturalSpawnEvent(naturalSpawn, attemptPosition, animalSpawnPassed, monsterSpawnPassed, liquidSpawnPassed, airSpawnPassed); handler.callScript("onCNPCNaturalSpawn", event); return NpcAPI.EVENT_BUS.post(event); diff --git a/src/main/java/noppes/npcs/LogWriter.java b/src/main/java/noppes/npcs/LogWriter.java index 538acf871..6a0911139 100644 --- a/src/main/java/noppes/npcs/LogWriter.java +++ b/src/main/java/noppes/npcs/LogWriter.java @@ -22,7 +22,6 @@ import java.util.logging.StreamHandler; public class LogWriter { private final static String name = "CustomNPCs"; - private final static String nameLog = "CustomNPCLog"; private final static Logger logger = Logger.getLogger(name); private final static WeakHashMap InitCacheMap = new WeakHashMap(); @@ -66,11 +65,8 @@ public class LogWriter { handler = new StreamHandler(new FileOutputStream(file), new Formatter() { @Override public String format(LogRecord record) { - String line = ""; - if (record.getLevel() != NPCLogLevel.CNPCLog){ - StackTraceElement element = Thread.currentThread().getStackTrace()[8]; - line = "[" + element.getClassName() + ":" + element.getLineNumber() + "] "; - } + StackTraceElement element = Thread.currentThread().getStackTrace()[8]; + String line = "[" + element.getClassName() + ":" + element.getLineNumber() + "] "; String time = "[" + dateformat.format(new Date(record.getMillis())) + "][" + record.getLevel() + "]" + line; if(record.getThrown() != null){ StringWriter sw = new StringWriter(); @@ -86,8 +82,9 @@ public class LogWriter { logger.setUseParentHandlers(false); Handler consoleHandler = new ConsoleHandler(); consoleHandler.setFormatter(handler.getFormatter()); - consoleHandler.setLevel(Level.ALL); + consoleHandler.setLevel(Level.FINEST); logger.addHandler(consoleHandler); + logger.setLevel(Level.ALL); info(new Date().toString()); } catch (SecurityException e) { @@ -102,63 +99,39 @@ public class LogWriter { public static void postScriptLog(UUID npcUUID, EnumScriptType type, String message) { switch (type){ case INIT: - if(!CustomNpcs.InitIgnore){ - scriptLogCalculator(InitCacheMap, npcUUID, message); - } + scriptLogCalculator(InitCacheMap, npcUUID, message); break; case TICK: - if(!CustomNpcs.TickIgnore){ - scriptLogCalculator(TickCacheMap, npcUUID, message); - } + scriptLogCalculator(TickCacheMap, npcUUID, message); break; case INTERACT: - if(!CustomNpcs.InteractIgnore){ - scriptLogCalculator(InteractCacheMap, npcUUID, message); - } + scriptLogCalculator(InteractCacheMap, npcUUID, message); break; case DIALOG: - if(!CustomNpcs.DialogIgnore){ - scriptLogCalculator(DialogCacheMap, npcUUID, message); - } + scriptLogCalculator(DialogCacheMap, npcUUID, message); break; case DAMAGED: - if(!CustomNpcs.DamagedIgnore){ - scriptLogCalculator(DamagedCacheMap, npcUUID, message); - } + scriptLogCalculator(DamagedCacheMap, npcUUID, message); break; case KILLED: - if(!CustomNpcs.KilledIgnore){ - scriptLogCalculator(KilledCacheMap, npcUUID, message); - } + scriptLogCalculator(KilledCacheMap, npcUUID, message); break; case ATTACK: - if(!CustomNpcs.AttackIgnore){ - scriptLogCalculator(AttackCacheMap, npcUUID, message); - } + scriptLogCalculator(AttackCacheMap, npcUUID, message); break; case TARGET: - if(!CustomNpcs.TargetIgnore){ - scriptLogCalculator(TargetCacheMap, npcUUID, message); - } + scriptLogCalculator(TargetCacheMap, npcUUID, message); break; case COLLIDE: - if(!CustomNpcs.CollideIgnore){ - scriptLogCalculator(CollideCacheMap, npcUUID, message); - } + scriptLogCalculator(CollideCacheMap, npcUUID, message); break; case KILLS: - if(!CustomNpcs.KillsIgnore){ - scriptLogCalculator(KillsCacheMap, npcUUID, message); - } + scriptLogCalculator(KillsCacheMap, npcUUID, message); case DIALOG_CLOSE: - if(!CustomNpcs.DialogCloseIgnore){ - scriptLogCalculator(DialogCloseCacheMap, npcUUID, message); - } + scriptLogCalculator(DialogCloseCacheMap, npcUUID, message); break; case TIMER: - if(!CustomNpcs.TimerIgnore){ - scriptLogCalculator(TimerCacheMap, npcUUID, message); - } + scriptLogCalculator(TimerCacheMap, npcUUID, message); break; default: break; @@ -172,7 +145,10 @@ public class LogWriter { long millisecSinceLast = TimeUnit.MILLISECONDS.toMillis(stamp.recentDate.getTime() - stamp.makeDate.getTime()); double frequency = (float)CustomNpcs.ScriptFrequency / 60; - // Reset Log if 2 Minutes Pass + + + + // Reset Log if 3 Minutes Pass if (secondsSinceFirst > 120) { LogWriter.script(message); stamp.counter = 1; @@ -202,7 +178,7 @@ public class LogWriter { } public static void script(Object msg) { - logger.log(NPCLogLevel.CNPCLog, msg.toString()); + logger.log(Level.ALL, msg.toString()); handler.flush(); } diff --git a/src/main/java/noppes/npcs/NPCLogLevel.java b/src/main/java/noppes/npcs/NPCLogLevel.java deleted file mode 100644 index c5c0ee159..000000000 --- a/src/main/java/noppes/npcs/NPCLogLevel.java +++ /dev/null @@ -1,11 +0,0 @@ -package noppes.npcs; - -import java.util.logging.Level; - -class NPCLogLevel extends Level { - public static final Level CNPCLog = new NPCLogLevel("CNPC", 0); - - public NPCLogLevel(String name, int value) { - super(name, value); - } -} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index f99c90988..51bb6b4e5 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -691,8 +691,8 @@ public class NoppesUtilServer { return entity; } - public static Entity spawnClone(NBTTagCompound compound, int x, int y, - int z, World worldObj) { + public static Entity getEntityFromNBT(NBTTagCompound compound, int x, int y, + int z, World worldObj) { ServerCloneController.Instance.cleanTags(compound); compound.setTag("Pos", NBTTags.nbtDoubleList(x + 0.5, y + 1, z + 0.5)); Entity entity = EntityList.createEntityFromNBT(compound, worldObj); @@ -705,6 +705,15 @@ public class NoppesUtilServer { npc.ticksExisted = 0; npc.totalTicksAlive = 0; } + return entity; + } + + public static Entity spawnClone(NBTTagCompound compound, int x, int y, + int z, World worldObj) { + Entity entity = NoppesUtilServer.getEntityFromNBT(compound,x,y,z,worldObj); + if(entity == null){ + return null; + } worldObj.spawnEntityInWorld(entity); return entity; } diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index e1602712b..0837aa329 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -1,7 +1,5 @@ package noppes.npcs; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.relauncher.Side; import foxz.utils.Market; import io.netty.buffer.ByteBuf; @@ -198,9 +196,6 @@ public class PacketHandlerServer{ npc.script.readFromNBT(Server.readNBT(buffer)); npc.updateAI = true; npc.script.hasInited = false; - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s SAVED NPC %s (%s, %s, %s) [%s]", "SCRIPTER", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)(npc).posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName())); - } } else if(type == EnumPacketServer.ScriptDataGet){ NBTTagCompound compound = npc.script.writeToNBT(new NBTTagCompound()); @@ -373,9 +368,6 @@ public class PacketHandlerServer{ private void wandPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws IOException{ if(type == EnumPacketServer.Delete){ - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s DELETE NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)npc.posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName())); - } npc.delete(); NoppesUtilServer.deleteNpc(npc,player); } @@ -411,9 +403,6 @@ public class PacketHandlerServer{ npc.reset(); if(npc.linkedData != null) LinkedNpcController.Instance.saveNpcData(npc); - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s CLOSE NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)npc.posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName())); - } NoppesUtilServer.setEditingNpc(player, null); } else if(type == EnumPacketServer.BanksGet){ @@ -440,18 +429,12 @@ public class PacketHandlerServer{ if(entity == null || !(entity instanceof EntityNPCInterface)) return; NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, (EntityNPCInterface) entity); - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), ((EntityNPCInterface)entity).display.getName(), entity.posX, entity.posY, entity.posZ, entity.worldObj.getWorldInfo().getWorldName())); - } } else if(type == EnumPacketServer.RemoteDelete){ Entity entity = player.worldObj.getEntityByID(buffer.readInt()); if(entity == null || !(entity instanceof EntityNPCInterface)) return; npc = (EntityNPCInterface) entity; - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s DELETE NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)npc.posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName())); - } npc.delete(); NoppesUtilServer.deleteNpc(npc,player); NoppesUtilServer.sendNearbyNpcs(player); @@ -879,9 +862,6 @@ public class PacketHandlerServer{ player.addChatMessage(new ChatComponentText("Failed to create an entity out of your clone")); return; } - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s SPAWNED ENTITY %s", "CLONER", player.getCommandSenderName(), entity)); - } } else if(type == EnumPacketServer.MobSpawner){ boolean server = buffer.readBoolean(); diff --git a/src/main/java/noppes/npcs/ScriptItemEventHandler.java b/src/main/java/noppes/npcs/ScriptItemEventHandler.java index cab2563b6..a81b6d271 100644 --- a/src/main/java/noppes/npcs/ScriptItemEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptItemEventHandler.java @@ -103,7 +103,7 @@ public class ScriptItemEventHandler { try { if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); - ItemEvent.InteractEvent eve = new ItemEvent.InteractEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock(event.entityPlayer.worldObj, new BlockPos(event.entityPlayer.posX, event.entityPlayer.posY, event.entityPlayer.posZ))); + ItemEvent.InteractEvent eve = new ItemEvent.InteractEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock(NpcAPI.Instance().getIWorld(event.entityPlayer.worldObj), NpcAPI.Instance().getIPos(event.entityPlayer.posX, event.entityPlayer.posY, event.entityPlayer.posZ))); event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); } } catch(Exception e) {} diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 4b7b6bfe9..bf8cc5620 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -119,7 +119,7 @@ public class ScriptPlayerEventHandler { if(!event.getPlayer().worldObj.isRemote && event.world instanceof WorldServer) { PlayerDataScript handler = ScriptController.Instance.playerScripts; IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.getPlayer()); - noppes.npcs.scripted.event.PlayerEvent.BreakEvent ev = new noppes.npcs.scripted.event.PlayerEvent.BreakEvent(scriptPlayer, NpcAPI.Instance().getIBlock(event.world, new BlockPos(event.x,event.y,event.z)), event.getExpToDrop()); + noppes.npcs.scripted.event.PlayerEvent.BreakEvent ev = new noppes.npcs.scripted.event.PlayerEvent.BreakEvent(scriptPlayer, NpcAPI.Instance().getIBlock(NpcAPI.Instance().getIWorld(event.world), NpcAPI.Instance().getIPos(event.x,event.y,event.z)), event.getExpToDrop()); event.setCanceled(EventHooks.onPlayerBreak(handler, ev)); event.setExpToDrop(ev.exp); } diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 3d81c3439..1f7a81cde 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -4,9 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.relauncher.Side; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -52,6 +50,25 @@ public class ServerEventsHandler { public static EntityVillager Merchant; public static Entity mounted; +// private HashMap exps = new HashMap(); +// +// @SubscribeEvent +// public void onUpdate(LivingUpdateEvent event){ +// if(!(event.entityLiving instanceof EntityPlayer)) +// return; +// EntityPlayer player = (EntityPlayer) event.entityLiving; +// if(exps.containsKey(player.getCommandSenderName())){ +// int prevExp = exps.get(player.getCommandSenderName()); +// if(prevExp > player.experienceTotal){ +// player.addChatMessage(new ChatComponentText("Omg exp was gotten:" + (player.experienceTotal - prevExp))); +// } +// else if(prevExp < player.experienceTotal){ +// player.addChatMessage(new ChatComponentText("Omg exp was lost:" + (prevExp - player.experienceTotal))); +// } +// } +// exps.put(player.getCommandSenderName(), player.experienceTotal); +// } + @SubscribeEvent public void invoke(EntityInteractEvent event) { ItemStack item = event.entityPlayer.getCurrentEquippedItem(); @@ -66,9 +83,6 @@ public class ServerEventsHandler { if(!isRemote && item.getItem() == CustomItems.soulstoneEmpty && event.target instanceof EntityLivingBase) { ((ItemSoulstoneEmpty)item.getItem()).store((EntityLivingBase)event.target, item, event.entityPlayer); - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s PICKED ENTITY %s", "SOULSTONE", event.entityPlayer.getCommandSenderName(), event.target)); - } } if(item.getItem() == CustomItems.wand && npcInteracted && !isRemote){ @@ -77,9 +91,6 @@ public class ServerEventsHandler { } event.setCanceled(true); NoppesUtilServer.sendOpenGui(event.entityPlayer, EnumGuiType.MainMenuDisplay, (EntityNPCInterface) event.target); - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "WAND", event.entityPlayer.getCommandSenderName(), ((EntityNPCInterface)(event.target)).display.getName(), (int)(event.target).posX, (int)(event.target).posY, (int)(event.target).posZ, (event.target).worldObj.getWorldInfo().getWorldName())); - } } else if(item.getItem() == CustomItems.cloner && !isRemote && !(event.target instanceof EntityPlayer)){ NBTTagCompound compound = new NBTTagCompound(); @@ -98,9 +109,6 @@ public class ServerEventsHandler { NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface)event.target); event.setCanceled(true); Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.GUI, EnumGuiType.Script.ordinal()); - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "SCRIPTER", event.entityPlayer.getCommandSenderName(), ((EntityNPCInterface)(event.target)).display.getName(), (int)(event.target).posX, (int)(event.target).posY, (int)(event.target).posZ, (event.target).worldObj.getWorldInfo().getWorldName())); - } } else if(item.getItem() == CustomItems.mount){ if(!CustomNpcsPermissions.Instance.hasPermission(event.entityPlayer, CustomNpcsPermissions.TOOL_MOUNTER)) diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java index 429164235..24fc568be 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java @@ -5,8 +5,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.relauncher.Side; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.Entity; @@ -15,8 +13,6 @@ import net.minecraft.entity.EntityLiving; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; -import noppes.npcs.CustomNpcs; -import noppes.npcs.LogWriter; import noppes.npcs.client.Client; import noppes.npcs.client.controllers.ClientCloneController; import noppes.npcs.client.gui.util.GuiCustomScroll; @@ -27,7 +23,6 @@ import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IGuiData; import noppes.npcs.constants.EnumPacketServer; -import noppes.npcs.entity.EntityNPCInterface; public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{ @@ -196,6 +191,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{ return; Client.sendData(EnumPacketServer.SpawnMob, false, posX, posY, posZ, compound); close(); + } } if(id == 2){ diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index f38458e15..d72f555a5 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -85,11 +85,6 @@ public enum EnumScriptType { public String function; - public static EnumScriptType valueOfIgnoreCase(String channelName) { - channelName = channelName.toUpperCase(); - return valueOf(channelName); - } - private EnumScriptType(String function) { this.function = function; } diff --git a/src/main/java/noppes/npcs/controllers/ServerCloneController.java b/src/main/java/noppes/npcs/controllers/ServerCloneController.java index 5fe56c42f..7b6e4fad7 100644 --- a/src/main/java/noppes/npcs/controllers/ServerCloneController.java +++ b/src/main/java/noppes/npcs/controllers/ServerCloneController.java @@ -19,6 +19,7 @@ import noppes.npcs.LogWriter; import noppes.npcs.NoppesUtilServer; import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.interfaces.IPos; import noppes.npcs.scripted.interfaces.handler.ICloneHandler; import noppes.npcs.scripted.interfaces.entity.IEntity; import noppes.npcs.scripted.interfaces.IWorld; @@ -209,10 +210,18 @@ public class ServerCloneController implements ICloneHandler { } } + public IEntity spawn(IPos pos, int tab, String name, IWorld world, boolean ignoreProtection) { + return this.spawn(pos.getX(),pos.getY(),pos.getZ(),tab,name,world,ignoreProtection); + } + public IEntity spawn(double x, double y, double z, int tab, String name, IWorld world) { return spawn(x, y, z, tab, name, world, true); } + public IEntity spawn(IPos pos, int tab, String name, IWorld world) { + return this.spawn(pos.getX(),pos.getY(),pos.getZ(),tab,name,world); + } + public IEntity[] getTab(int tab, IWorld world) { File dir = new File(getDir(), tab + ""); if (!dir.exists() || !dir.isDirectory() || dir.listFiles() == null) { diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index 94015eaaf..c4a3bb652 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -137,11 +137,7 @@ public class DataScript implements IScriptHandler { script.engine.put(obs[i].toString(), ob); } if(CustomNpcs.ScriptLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - if(obs.length > 1 && obs[1] == null){ - LogWriter.postScriptLog(npc.field_110179_h, type, String.format("[%s] NPC %s (%s, %s, %s)", ((String)type.function).toUpperCase(), npc.display.name, (int)npc.posX, (int)npc.posY, (int)npc.posZ)); - } else { - LogWriter.postScriptLog(npc.field_110179_h, type, String.format("[%s] NPC %s (%s, %s, %s) | Objects: %s", ((String)type.function).toUpperCase(), npc.display.name, (int)npc.posX, (int)npc.posY, (int)npc.posZ, Arrays.toString(obs))); - } + LogWriter.postScriptLog(npc.field_110179_h, type, String.format("[%s] NPC %s (%s, %s, %s) | Objects: %s", ((String)type.function).toUpperCase(), npc.display.name, (int)npc.posX, (int)npc.posY, (int)npc.posZ, Arrays.toString(obs))); } return callScript(script, event); } diff --git a/src/main/java/noppes/npcs/controllers/data/TransportLocation.java b/src/main/java/noppes/npcs/controllers/data/TransportLocation.java index 9d3256d38..c058c8ff3 100644 --- a/src/main/java/noppes/npcs/controllers/data/TransportLocation.java +++ b/src/main/java/noppes/npcs/controllers/data/TransportLocation.java @@ -2,6 +2,8 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.controllers.TransportController; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.interfaces.IPos; import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; public class TransportLocation implements ITransportLocation { @@ -78,6 +80,16 @@ public class TransportLocation implements ITransportLocation { this.posZ = z; } + public void setPosition(IPos pos) { + this.posX = pos.getX(); + this.posY = pos.getY(); + this.posZ = pos.getZ(); + } + + public IPos getPos() { + return NpcAPI.Instance().getIPos(this.posX, this.posY, this.posZ); + } + public double getX() { return posX; } diff --git a/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java b/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java index 914ba7bba..11c21e8e1 100644 --- a/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java +++ b/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java @@ -2,7 +2,6 @@ package noppes.npcs.items; import java.util.List; -import cpw.mods.fml.common.FMLCommonHandler; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.player.EntityPlayer; @@ -12,8 +11,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraft.world.World; -import noppes.npcs.CustomNpcs; -import noppes.npcs.LogWriter; import noppes.npcs.constants.EnumRoleType; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.controllers.PlayerDataController; @@ -76,9 +73,6 @@ public class ItemSoulstoneFilled extends Item { if(entity == null) return false; entity.setPosition(x + 0.5, y + 1 + 0.2F, z + 0.5); - if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.script(String.format("[%s] %s PLACED ENTITY %s", "SOULSTONE", player.getCommandSenderName(), entity)); - } if(entity instanceof EntityNPCInterface){ EntityNPCInterface npc = (EntityNPCInterface) entity; npc.ai.startPos = new int[]{x, y, z}; diff --git a/src/main/java/noppes/npcs/roles/JobSpawner.java b/src/main/java/noppes/npcs/roles/JobSpawner.java index 4e456a4f3..2358bf6ef 100644 --- a/src/main/java/noppes/npcs/roles/JobSpawner.java +++ b/src/main/java/noppes/npcs/roles/JobSpawner.java @@ -250,7 +250,7 @@ public class JobSpawner extends JobInterface{ return null; } - private boolean isEmpty(){ + public boolean isEmpty(){ if(compound1 != null && compound1.hasKey("id")) return false; if(compound2 != null && compound2.hasKey("id")) @@ -365,7 +365,7 @@ public class JobSpawner extends JobInterface{ return living; } - private NBTTagCompound getCompound(int i) { + public NBTTagCompound getCompound(int i) { if(i <= 1 && compound1 != null && compound1.hasKey("id")){ number = 1; return compound1; @@ -394,7 +394,7 @@ public class JobSpawner extends JobInterface{ } - private List getNearbySpawned(){ + public List getNearbySpawned(){ List spawnList = new ArrayList(); List list = npc.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, npc.boundingBox.expand(40, 40, 40)); for(EntityLivingBase entity : list){ diff --git a/src/main/java/noppes/npcs/roles/RoleTransporter.java b/src/main/java/noppes/npcs/roles/RoleTransporter.java index d6b61b391..3722dcfb0 100644 --- a/src/main/java/noppes/npcs/roles/RoleTransporter.java +++ b/src/main/java/noppes/npcs/roles/RoleTransporter.java @@ -12,6 +12,7 @@ import noppes.npcs.controllers.data.PlayerTransportData; import noppes.npcs.controllers.TransportController; import noppes.npcs.controllers.data.TransportLocation; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; public class RoleTransporter extends RoleInterface{ @@ -77,12 +78,12 @@ public class RoleTransporter extends RoleInterface{ } } - private void unlock(EntityPlayer player, TransportLocation loc){ + public void unlock(EntityPlayer player, ITransportLocation loc){ PlayerTransportData data = PlayerDataController.instance.getPlayerData(player).transportData; if(data.transports.contains(transportId)) return; data.transports.add(transportId); - player.addChatMessage(new ChatComponentTranslation("transporter.unlock", loc.name)); + player.addChatMessage(new ChatComponentTranslation("transporter.unlock", loc.getName())); } public TransportLocation getLocation(){ if(npc.isRemote()) @@ -94,9 +95,9 @@ public class RoleTransporter extends RoleInterface{ return loc != null && loc.id == transportId; } - public void setTransport(TransportLocation location) { - transportId = location.id; - name = location.name; + public void setTransport(ITransportLocation location) { + transportId = location.getId(); + name = location.getName(); } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlock.java b/src/main/java/noppes/npcs/scripted/ScriptBlock.java index e2f95d426..15f775868 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlock.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlock.java @@ -30,7 +30,7 @@ public class ScriptBlock implements IBlock { this.world = NpcAPI.Instance().getIWorld(world); this.block = block; this.pos = pos; - this.bPos = new ScriptBlockPos(pos); + this.bPos = NpcAPI.Instance().getIPos(pos); this.tile = new ScriptTileEntity<>(world.getTileEntity(pos.getX(),pos.getY(), pos.getZ())); } @@ -64,13 +64,13 @@ public class ScriptBlock implements IBlock { return this; } else { this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block); - return NpcAPI.Instance().getIBlock(world.getMCWorld(), block, new BlockPos(getX(),getY(),getZ())); + return NpcAPI.Instance().getIBlock(world, getX(),getY(),getZ()); } } public IBlock setBlock(IBlock block) { this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block.getMCBlock()); - return NpcAPI.Instance().getIBlock(world.getMCWorld(), block.getMCBlock(), new BlockPos(getX(),getY(),getZ())); + return NpcAPI.Instance().getIBlock(world, getX(),getY(),getZ()); } public boolean isContainer() { diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java b/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java index 675837165..6c4d67f31 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java @@ -10,7 +10,7 @@ import net.minecraft.util.math.BlockPos; import noppes.npcs.scripted.interfaces.IPos; public class ScriptBlockPos implements IPos { - private BlockPos blockPos; + public BlockPos blockPos; public ScriptBlockPos(BlockPos pos) { this.blockPos = pos; @@ -29,75 +29,75 @@ public class ScriptBlockPos implements IPos { } public IPos up() { - return new ScriptBlockPos(this.blockPos.up()); + return NpcAPI.Instance().getIPos(this.blockPos.up()); } public IPos up(int n) { - return new ScriptBlockPos(this.blockPos.up(n)); + return NpcAPI.Instance().getIPos(this.blockPos.up(n)); } public IPos down() { - return new ScriptBlockPos(this.blockPos.down()); + return NpcAPI.Instance().getIPos(this.blockPos.down()); } public IPos down(int n) { - return new ScriptBlockPos(this.blockPos.down(n)); + return NpcAPI.Instance().getIPos(this.blockPos.down(n)); } public IPos north() { - return new ScriptBlockPos(this.blockPos.north()); + return NpcAPI.Instance().getIPos(this.blockPos.north()); } public IPos north(int n) { - return new ScriptBlockPos(this.blockPos.north(n)); + return NpcAPI.Instance().getIPos(this.blockPos.north(n)); } public IPos east() { - return new ScriptBlockPos(this.blockPos.east()); + return NpcAPI.Instance().getIPos(this.blockPos.east()); } public IPos east(int n) { - return new ScriptBlockPos(this.blockPos.east(n)); + return NpcAPI.Instance().getIPos(this.blockPos.east(n)); } public IPos south() { - return new ScriptBlockPos(this.blockPos.south()); + return NpcAPI.Instance().getIPos(this.blockPos.south()); } public IPos south(int n) { - return new ScriptBlockPos(this.blockPos.south(n)); + return NpcAPI.Instance().getIPos(this.blockPos.south(n)); } public IPos west() { - return new ScriptBlockPos(this.blockPos.west()); + return NpcAPI.Instance().getIPos(this.blockPos.west()); } public IPos west(int n) { - return new ScriptBlockPos(this.blockPos.west(n)); + return NpcAPI.Instance().getIPos(this.blockPos.west(n)); } public IPos add(int x, int y, int z) { - return new ScriptBlockPos(this.blockPos.add(x, y, z)); + return NpcAPI.Instance().getIPos(this.blockPos.add(x, y, z)); } public IPos add(IPos pos) { - return new ScriptBlockPos(this.blockPos.add(this.blockPos)); + return NpcAPI.Instance().getIPos(this.blockPos.add(this.blockPos)); } public IPos subtract(int x, int y, int z) { - return new ScriptBlockPos(this.blockPos.add(-x, -y, -z)); + return NpcAPI.Instance().getIPos(this.blockPos.add(-x, -y, -z)); } public IPos subtract(IPos pos) { - return new ScriptBlockPos(this.blockPos.add(-pos.getX(), -pos.getY(), -pos.getZ())); + return NpcAPI.Instance().getIPos(this.blockPos.add(-pos.getX(), -pos.getY(), -pos.getZ())); } public IPos offset(int direction) { - return new ScriptBlockPos(this.blockPos.offset(EnumFacing.values()[direction])); + return NpcAPI.Instance().getIPos(this.blockPos.offset(EnumFacing.values()[direction])); } public IPos offset(int direction, int n) { - return new ScriptBlockPos(this.blockPos.offset(EnumFacing.values()[direction], n)); + return NpcAPI.Instance().getIPos(this.blockPos.offset(EnumFacing.values()[direction], n)); } public double[] normalize() { @@ -111,4 +111,8 @@ public class ScriptBlockPos implements IPos { double d2 = (double)(this.getZ() - pos.getZ()); return Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); } + + public BlockPos getMCPos() { + return this.blockPos; + } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptParticle.java b/src/main/java/noppes/npcs/scripted/ScriptParticle.java index a98c0c2da..1ea6d2e95 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptParticle.java +++ b/src/main/java/noppes/npcs/scripted/ScriptParticle.java @@ -3,6 +3,7 @@ package noppes.npcs.scripted; import net.minecraft.nbt.*; import noppes.npcs.NoppesUtilServer; import noppes.npcs.scripted.interfaces.IParticle; +import noppes.npcs.scripted.interfaces.IPos; import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.interfaces.entity.IEntity; @@ -230,6 +231,13 @@ public class ScriptParticle implements IParticle { return z; } + public void setPosition(IPos pos) { + this.setPosition(pos.getX(),pos.getY(),pos.getZ()); + } + public void getPos() { + NpcAPI.Instance().getIPos(x,y,z); + } + public void setMotion(double motionX, double motionY, double motionZ, float gravity){ this.motionX = motionX; this.motionY = motionY; diff --git a/src/main/java/noppes/npcs/scripted/ScriptSound.java b/src/main/java/noppes/npcs/scripted/ScriptSound.java index ed3359e56..76c93115f 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptSound.java +++ b/src/main/java/noppes/npcs/scripted/ScriptSound.java @@ -156,7 +156,7 @@ public class ScriptSound implements ISound { } public IPos getPos() { - return new ScriptBlockPos(new BlockPos(xPosF,yPosF,zPosF)); + return NpcAPI.Instance().getIPos(xPosF, yPosF, zPosF); } public float getX() { diff --git a/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java b/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java index e0d963d5e..d5f3895b2 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java @@ -4,27 +4,39 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; -import noppes.npcs.scripted.interfaces.IBlock; -import noppes.npcs.scripted.interfaces.INbt; -import noppes.npcs.scripted.interfaces.ITileEntity; +import noppes.npcs.scripted.interfaces.*; public class ScriptTileEntity implements ITileEntity { protected T tileEntity; + protected IWorld world; - public ScriptTileEntity(T tileEntity) { this.tileEntity = tileEntity; } + public ScriptTileEntity(T tileEntity) { + this.tileEntity = tileEntity; + this.world = NpcAPI.Instance().getIWorld(tileEntity.getWorldObj()); + } public int getBlockMetadata(){ return tileEntity.getBlockMetadata(); } - public ScriptWorld getWorld(){ - return (ScriptWorld) NpcAPI.Instance().getIWorld((WorldServer) tileEntity.getWorldObj()); + public IWorld getWorld(){ + return world; + } + + public void setWorld(IWorld world) { + this.tileEntity.setWorldObj(world.getMCWorld()); + this.world = world; } public TileEntity getMCTileEntity() { return this.tileEntity; } + public void markDirty() + { + this.tileEntity.markDirty(); + } + public void readFromNBT(INbt nbt){ this.tileEntity.readFromNBT(nbt.getMCNBT()); } @@ -33,8 +45,12 @@ public class ScriptTileEntity implements ITileEntity { return this.tileEntity.getDistanceFrom(x,y,z); } + public double getDistanceFrom(IPos pos){ + return this.getDistanceFrom(pos.getX(),pos.getY(),pos.getZ()); + } + public IBlock getBlockType(){ - return NpcAPI.Instance().getIBlock(tileEntity.getWorldObj(), tileEntity.getBlockType(), new BlockPos(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); + return NpcAPI.Instance().getIBlock(world, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); } public boolean isInvalid(){ diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptAnimal.java b/src/main/java/noppes/npcs/scripted/entity/ScriptAnimal.java index 33f0b28d5..3171cca84 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptAnimal.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptAnimal.java @@ -1,13 +1,19 @@ package noppes.npcs.scripted.entity; import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.entity.IAnimal; +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.item.IItemStack; public class ScriptAnimal extends ScriptLiving implements IAnimal { - + protected T entity; + public ScriptAnimal(T entity) { super(entity); + this.entity = entity; } @Override @@ -15,8 +21,35 @@ public class ScriptAnimal extends ScriptLiving implem return EntityType.ANIMAL; } + /** + * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on + * the animal type) + */ + public boolean isBreedingItem(IItemStack itemStack) { + return this.entity.isBreedingItem(itemStack.getMCItemStack()); + } + + /** + * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. + */ + public boolean interact(IPlayer player) { + return this.entity.interact((EntityPlayer) player.getMCEntity()); + } + + public boolean isInLove() { + return this.entity.isInLove(); + } + + public void resetInLove() { + this.entity.resetInLove(); + } + + public boolean canMateWith(IAnimal animal) { + return this.entity.canMateWith((EntityAnimal) animal.getMCEntity()); + } + @Override public boolean typeOf(int type){ - return type == EntityType.ANIMAL?true:super.typeOf(type); + return type == EntityType.ANIMAL || super.typeOf(type); } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index fc10f7447..41bdc1a95 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -363,6 +363,14 @@ public class ScriptEntity implements IEntity { this.setMotionZ(z); } + public void setMotion(IPos pos) { + this.setMotion(pos.getX(),pos.getY(),pos.getZ()); + } + + public IPos getMotion() { + return NpcAPI.Instance().getIPos(entity.motionX,entity.motionY,entity.motionZ); + } + public boolean isAirborne(){ return entity.isAirBorne; } @@ -398,13 +406,21 @@ public class ScriptEntity implements IEntity { } public IPos getPos() { - return new ScriptBlockPos(new BlockPos(entity.posX,entity.posY,entity.posZ)); + return NpcAPI.Instance().getIPos(entity.posX, entity.posY, entity.posZ); + } + + public IPos getPosition() { + return getPos(); } public void setPos(IPos pos) { this.entity.setPosition((double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F)); } + public void setPosition(IPos pos) { + this.setPos(pos); + } + public int getDimension(){ return entity.dimension; } @@ -730,6 +746,10 @@ public class ScriptEntity implements IEntity { entity.velocityChanged = true; } + public void knockback(IPos pos, float direction){ + this.knockback(pos.getX(),pos.getY(),pos.getZ(),direction); + } + public void setImmune(int ticks) { entity.hurtResistantTime = ticks; }; @@ -789,6 +809,11 @@ public class ScriptEntity implements IEntity { this.entity.readFromNBT(nbt.getMCNBT()); } + public INbt getNbtOptional() { + NBTTagCompound compound = new NBTTagCompound(); + return this.entity.writeToNBTOptional(compound) ? NpcAPI.Instance().getINbt(compound) : null; + } + public void storeAsClone(int tab, String name) { NBTTagCompound compound = new NBTTagCompound(); if (!this.entity.writeToNBTOptional(compound)) { diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java index 5d80811e2..216065035 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java @@ -63,4 +63,88 @@ public class ScriptLiving extends ScriptLivingBase im public boolean canSeeEntity(IEntity entity){ return this.entity.getEntitySenses().canSee(entity.getMCEntity()); } + + public void playLivingSound() { + this.entity.playLivingSound(); + } + + public void spawnExplosionParticle() + { + this.entity.spawnExplosionParticle(); + } + + public void setMoveForward(float speed) + { + this.entity.setMoveForward(speed); + } + + public void faceEntity(IEntity entity, float pitch, float yaw) + { + this.entity.faceEntity(entity.getMCEntity(), pitch, yaw); + } + + public boolean canPickUpLoot() + { + return this.entity.canPickUpLoot(); + } + + public void setCanPickUpLoot(boolean pickUp) + { + this.entity.setCanPickUpLoot(pickUp); + } + + public boolean isPersistent() + { + return this.entity.isNoDespawnRequired(); + } + + public void enablePersistence() { + this.entity.func_110163_bv(); + } + + public void setCustomNameTag(String text) + { + this.entity.setCustomNameTag(text); + } + + public String getCustomNameTag() + { + return this.entity.getCustomNameTag(); + } + + public boolean hasCustomNameTag() + { + return this.entity.hasCustomNameTag(); + } + + public void setAlwaysRenderNameTag(boolean alwaysRender) + { + this.entity.setAlwaysRenderNameTag(alwaysRender); + } + + public boolean getAlwaysRenderNameTag() + { + return this.entity.getAlwaysRenderNameTag(); + } + + public void clearLeashed(boolean sendPacket, boolean dropLeash) + { + this.entity.clearLeashed(sendPacket,dropLeash); + } + + public boolean allowLeashing() { + return this.entity.allowLeashing(); + } + + public boolean getLeashed() { + return this.entity.getLeashed(); + } + + public IEntity getLeashedTo() { + return NpcAPI.Instance().getIEntity(entity.getLeashedToEntity()); + } + + public void setLeashedTo(IEntity entity, boolean sendPacket) { + this.entity.setLeashedToEntity(entity.getMCEntity(), sendPacket); + } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 0ff394203..1b733959a 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -1,6 +1,5 @@ package noppes.npcs.scripted.entity; -import net.minecraft.block.BlockLiquid; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.potion.Potion; @@ -8,18 +7,14 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; import net.minecraft.util.EntityDamageSource; import net.minecraft.util.Vec3; -import net.minecraft.util.math.BlockPos; -import noppes.npcs.scripted.ScriptBlockPos; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.ScriptDamageSource; +import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.IBlock; import noppes.npcs.scripted.interfaces.IPos; import noppes.npcs.scripted.interfaces.entity.IEntity; -import noppes.npcs.scripted.interfaces.item.IItemStack; -import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.ScriptDamageSource; - -import java.util.ArrayList; +import noppes.npcs.scripted.interfaces.item.IItemStack; public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase { protected T entity; @@ -108,7 +103,7 @@ public class ScriptLivingBase extends ScriptEntity extends ScriptEntity extends ScriptLiving imp npc.script.clientNeedsUpdate = true; } + public IPos getHome() { + return NpcAPI.Instance().getIPos(npc.ai.startPos[0],npc.ai.startPos[1],npc.ai.startPos[2]); + } + /** * @return Home position x */ @@ -201,6 +206,11 @@ public class ScriptNpc extends ScriptLiving imp public void setHome(int x, int y, int z){ npc.ai.startPos = new int[]{x, y, z}; } + + public void setHome(IPos pos){ + npc.ai.startPos = new int[]{pos.getX(), pos.getY(), pos.getZ()}; + } + /** * @param health New max health */ @@ -1133,7 +1143,7 @@ public class ScriptNpc extends ScriptLiving imp public void setSkinType(byte type) { npc.display.skinType = type; - npc.updateClient = true; + npc.script.clientNeedsUpdate = true; } public byte getSkinType() { @@ -1146,7 +1156,7 @@ public class ScriptNpc extends ScriptLiving imp this.npc.display.url = url; npc.textureLocation = null; npc.display.skinType = 2; - npc.updateClient = true; + npc.script.clientNeedsUpdate = true; } public String getSkinUrl() { @@ -1155,7 +1165,7 @@ public class ScriptNpc extends ScriptLiving imp public void setCloakTexture(String cloakTexture) { npc.display.cloakTexture = cloakTexture; - npc.updateClient = true; + npc.script.clientNeedsUpdate = true; } public String getCloakTexture() { @@ -1168,7 +1178,7 @@ public class ScriptNpc extends ScriptLiving imp } this.getOverlays().add(0, NpcAPI.Instance().createSkinOverlay(overlayTexture)); - npc.updateClient = true; + npc.script.clientNeedsUpdate = true; } public String getOverlayTexture() { @@ -1190,4 +1200,6 @@ public class ScriptNpc extends ScriptLiving imp } public void updateClient() { this.npc.updateClient(); } + + public void updateAI() { this.npc.updateTasks(); } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 385744cf9..45b63c8e2 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -86,6 +86,10 @@ public class ScriptPlayer extends ScriptLivingBase NoppesUtilPlayer.teleportPlayer(player, x, y, z, player.dimension); } + public void setPosition(IPos pos) { + this.setPosition(pos.getX(),pos.getY(),pos.getZ()); + } + public void setPosition(double x, double y, double z, int dimensionId){ if (NpcAPI.Instance().getIWorld(dimensionId) == null) return; @@ -93,6 +97,10 @@ public class ScriptPlayer extends ScriptLivingBase NoppesUtilPlayer.teleportPlayer(player, x, y, z, dimensionId); } + public void setPosition(IPos pos, int dimensionId) { + this.setPosition(pos.getX(),pos.getY(),pos.getZ(), dimensionId); + } + public int getHunger(){ return player.getFoodStats().getFoodLevel(); } @@ -505,6 +513,10 @@ public class ScriptPlayer extends ScriptLivingBase y = ValueUtil.CorrectInt(y, 0, 256); player.setSpawnChunk(new ChunkCoordinates(x, y, z), true); } + + public void setSpawnpoint(IPos pos){ + this.setSpawnpoint(pos.getX(),pos.getY(),pos.getZ()); + } public void resetSpawnpoint(){ player.setSpawnChunk(null, false); diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index 5a617fc85..88fe5efe9 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -459,7 +459,7 @@ public class PlayerEvent extends CustomNPCsEvent { public Bonemeal(IPlayer player, int x, int y, int z, World world) { super(player); - this.block = API.getIBlock(world, x, y, z); + this.block = API.getIBlock(NpcAPI.Instance().getIWorld(world), x, y, z); this.x = x; this.y = y; this.z = z; diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IParticle.java b/src/main/java/noppes/npcs/scripted/interfaces/IParticle.java index 3c97f32f8..a5fdb84f2 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IParticle.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IParticle.java @@ -137,6 +137,9 @@ public interface IParticle { double getY(); double getZ(); + void setPosition(IPos pos); + void getPos(); + void setMotion(double motionX, double motionY, double motionZ, float gravity); double getMotionX(); double getMotionY(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IPos.java b/src/main/java/noppes/npcs/scripted/interfaces/IPos.java index 13a07fbb2..c56ac3a78 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IPos.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPos.java @@ -5,6 +5,8 @@ package noppes.npcs.scripted.interfaces; +import net.minecraft.util.math.BlockPos; + public interface IPos { int getX(); @@ -156,4 +158,6 @@ public interface IPos { * @return The distance between this IPos object and the other. */ double distanceTo(IPos pos); + + BlockPos getMCPos(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java index 0df505aae..caba3874c 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java @@ -16,7 +16,9 @@ public interface ITileEntity { * * @return The world this tile entity is in. */ - ScriptWorld getWorld(); + IWorld getWorld(); + + void setWorld(IWorld world); /** * @@ -24,6 +26,8 @@ public interface ITileEntity { */ TileEntity getMCTileEntity(); + void markDirty(); + /** * Reads an INbt compound tag, creates a tile entity based on the data, and replaces this entity with the new one. */ @@ -33,6 +37,7 @@ public interface ITileEntity { * @return The distance of this tile entity from the point given by the x, y, and z parameters. */ double getDistanceFrom(double x, double y, double z); + double getDistanceFrom(IPos pos); /** * @return A new IBlock object based on this tile entity's type. diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 55414b52f..98df9b79b 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -1,7 +1,7 @@ package noppes.npcs.scripted.interfaces; import net.minecraft.world.WorldServer; -import noppes.npcs.scripted.ScriptScoreboard; +import noppes.npcs.scripted.scoreboard.ScriptScoreboard; import noppes.npcs.scripted.interfaces.entity.IEntity; import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.handler.data.ISound; @@ -39,41 +39,65 @@ public interface IWorld { * @return The top-most block in the world as an IBlock object. */ IBlock getTopBlock(int x, int z); + IBlock getTopBlock(IPos pos); + boolean isBlockFreezable(IPos pos); boolean isBlockFreezable(int x, int y, int z); + boolean isBlockFreezableNaturally(IPos pos); boolean isBlockFreezableNaturally(int x, int y, int z); + boolean canBlockFreeze(IPos pos, boolean adjacentToWater); boolean canBlockFreeze(int x, int y, int z, boolean adjacentToWater); + boolean canBlockFreezeBody(IPos pos, boolean adjacentToWater); boolean canBlockFreezeBody(int x, int y, int z, boolean adjacentToWater); + boolean canSnowAt(IPos pos, boolean checkLight); boolean canSnowAt(int x, int y, int z, boolean checkLight); + boolean canSnowAtBody(IPos pos, boolean checkLight); boolean canSnowAtBody(int x, int y, int z, boolean checkLight); /** * @return The Y-value of the world at this x & z value based on the height map of the world. */ int getHeightValue(int x, int z); + int getHeightValue(IPos pos); /** * @return The minimum Y-value of the world at this x & z value based on the height map of the world. */ int getChunkHeightMapMinimum(int x, int z); + int getChunkHeightMapMinimum(IPos pos); /** * @return The metadata of the block at this position. */ int getBlockMetadata(int x, int y, int z); + int getBlockMetadata(IPos pos); boolean setBlockMetadataWithNotify(int x, int y, int z, int metadata, int flag); + boolean setBlockMetadataWithNotify(IPos pos, int metadata, int flag); - boolean canBlockSeeTheSky(int x, int y, int z); + /** + * @param x + * @param y + * @param z + * @return can the block at this position see the sky or are there no blocks above this one + */ + boolean canSeeSky(int x, int y, int z); + /** + * @param pos + * @return can the block at this position see the sky or are there no blocks above this one + */ + boolean canSeeSky(IPos pos); int getFullBlockLightValue(int x, int y, int z); + int getFullBlockLightValue(IPos pos); int getBlockLightValue(int x, int y, int z); + int getBlockLightValue(IPos pos); void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch); @@ -96,10 +120,12 @@ public interface IWorld { IPlayer getClosestPlayerToEntity(IEntity entity, double range); IPlayer getClosestPlayer(double x, double y, double z, double range); + IPlayer getClosestPlayer(IPos pos, double range); IPlayer getClosestVulnerablePlayerToEntity(IEntity entity, double range); IPlayer getClosestVulnerablePlayer(double x, double y, double z, double range); + IPlayer getClosestVulnerablePlayer(IPos pos, double range); /** * @@ -118,25 +144,31 @@ public interface IWorld { * Sets the block's tile entity at the given position. */ void setTileEntity(int x, int y, int z, ITileEntity tileEntity); + void setTileEntity(IPos pos, ITileEntity tileEntity); /** * Removes the block's tile entity at the given position. */ void removeTileEntity(int x, int y, int z); + void removeTileEntity(IPos pos); /** * * @return True if the block at this position is of cubic shape. (Not a stair, slab, etc.) */ boolean isBlockFullCube(int x, int y, int z); + boolean isBlockFullCube(IPos pos); long getSeed(); void setSpawnLocation(int x, int y, int z); + void setSpawnLocation(IPos pos); boolean canLightningStrikeAt(int x, int y, int z); + boolean canLightningStrikeAt(IPos pos); boolean isBlockHighHumidity(int x, int y, int z); + boolean isBlockHighHumidity(IPos pos); /** * @param x World position x @@ -146,6 +178,7 @@ public interface IWorld { * @since 1.7.10d */ String getSignText(int x, int y, int z); + String getSignText(IPos pos); /** * @param x World position x @@ -153,7 +186,8 @@ public interface IWorld { * @param z World position z * @param item The block to be set */ - public void setBlock(int x, int y, int z, IItemStack item); + void setBlock(int x, int y, int z, IItemStack item); + void setBlock(IPos pos, IItemStack item); /** * @param x World position x @@ -161,14 +195,16 @@ public interface IWorld { * @param z World position z * @param block The block to be set */ - public void setBlock(int x, int y, int z, IBlock block); + void setBlock(int x, int y, int z, IBlock block); + void setBlock(IPos pos, IBlock block); /** * @param x World position x * @param y World position y * @param z World position z */ - public void removeBlock(int x, int y, int z); + void removeBlock(int x, int y, int z); + void removeBlock(IPos pos); IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); @@ -208,20 +244,6 @@ public interface IWorld { IEntity[] rayCastEntities(IPos startPos, IPos lookVector, int maxDistance, double offset, double range); - /** - * @param x - * @param y - * @param z - * @return can the block at this position see the sky or are there no blocks above this one - */ - public boolean canSeeSky(int x, int y, int z); - - /** - * @param pos - * @return can the block at this position see the sky or are there no blocks above this one - */ - public boolean canSeeSky(IPos pos); - /** * @param name The name of the player to be returned * @return The Player with name. Null is returned when the player isnt found @@ -256,6 +278,7 @@ public interface IWorld { * @param z The z position */ void thunderStrike(double x, double y, double z); + void thunderStrike(IPos pos); /** * Sends a packet from the server to the client everytime its called. Probably should not use this too much. @@ -270,6 +293,7 @@ public interface IWorld { * @param count Particle count */ void spawnParticle(String particle, double x, double y, double z, double dx, double dy, double dz, double speed, int count); + void spawnParticle(String particle, IPos pos, double dx, double dy, double dz, double speed, int count); /** * @param id The items name @@ -353,6 +377,7 @@ public interface IWorld { * @param grief Whether or not the explosion does damage to blocks */ void explode(double x, double y, double z, float range, boolean fire, boolean grief); + void explode(IPos pos, float range, boolean fire, boolean grief); IPlayer[] getAllServerPlayers(); @@ -365,6 +390,7 @@ public interface IWorld { * @return Returns the name of the biome */ String getBiomeName(int x, int z); + String getBiomeName(IPos pos); /** * Lets you spawn a server side cloned entity @@ -377,8 +403,10 @@ public interface IWorld { * @return Returns the entity which was spawned */ IEntity spawnClone(int x, int y, int z, int tab, String name, boolean ignoreProtection); + IEntity spawnClone(IPos pos, int tab, String name, boolean ignoreProtection); IEntity spawnClone(int x, int y, int z, int tab, String name); + IEntity spawnClone(IPos pos, int tab, String name); ScriptScoreboard getScoreboard(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IAnimal.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IAnimal.java index 28a74b2ae..2f9dc4fe5 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IAnimal.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IAnimal.java @@ -6,6 +6,23 @@ package noppes.npcs.scripted.interfaces.entity; import net.minecraft.entity.passive.EntityAnimal; +import noppes.npcs.scripted.interfaces.item.IItemStack; public interface IAnimal extends IEntityLiving { + /** + * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on + * the animal type) + */ + boolean isBreedingItem(IItemStack itemStack); + + /** + * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. + */ + boolean interact(IPlayer player); + + boolean isInLove(); + + void resetInLove(); + + boolean canMateWith(IAnimal animal); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java index 789d32050..8e684cc71 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java @@ -6,6 +6,7 @@ package noppes.npcs.scripted.interfaces.entity; import net.minecraft.entity.EntityCreature; +import noppes.npcs.scripted.interfaces.IPos; import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.scripted.interfaces.handler.IOverlayHandler; import noppes.npcs.scripted.interfaces.handler.data.IFaction; @@ -72,6 +73,8 @@ public interface ICustomNpc extends IEntityLiving { */ void setTexture(String texture); + IPos getHome(); + /** * @return Home position x */ @@ -108,6 +111,9 @@ public interface ICustomNpc extends IEntityLiving { * @param z The home z position */ void setHome(int x, int y, int z); + + void setHome(IPos pos); + /** * @param health New max health */ @@ -808,4 +814,6 @@ public interface ICustomNpc extends IEntityLiving { int getCollisionType(); void updateClient(); + + void updateAI(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java index 2d35aaf9c..b6166ef00 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java @@ -95,6 +95,10 @@ public interface IEntity { void setMotion(double x, double y, double z); + void setMotion(IPos pos); + + IPos getMotion(); + boolean isAirborne(); /** @@ -119,9 +123,9 @@ public interface IEntity { */ void setPosition(double x, double y, double z); - IPos getPos(); + void setPosition(IPos pos); - void setPos(IPos pos); + IPos getPosition(); int getDimension(); @@ -305,6 +309,7 @@ public interface IEntity { void knockback(int power, float direction); void knockback(int xpower, int ypower, int zpower, float direction); + void knockback(IPos pos, float direction); void setImmune(int ticks); @@ -341,6 +346,8 @@ public interface IEntity { public void setNbt(INbt nbt); + INbt getNbtOptional(); + void storeAsClone(int tab, String name); IWorld getWorld(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntityLiving.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntityLiving.java index 6adef4fe3..b074eabc4 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntityLiving.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntityLiving.java @@ -15,4 +15,40 @@ public interface IEntityLiving extends IEntityLivingBase void navigateTo(double var1, double var3, double var5, double var7); T getMCEntity(); + + void playLivingSound(); + + void spawnExplosionParticle(); + + void setMoveForward(float speed); + + void faceEntity(IEntity entity, float pitch, float yaw); + + boolean canPickUpLoot(); + + void setCanPickUpLoot(boolean pickUp); + + boolean isPersistent(); + + void enablePersistence(); + + void setCustomNameTag(String text); + + String getCustomNameTag(); + + boolean hasCustomNameTag(); + + void setAlwaysRenderNameTag(boolean alwaysRender); + + boolean getAlwaysRenderNameTag(); + + void clearLeashed(boolean sendPacket, boolean dropLeash); + + boolean allowLeashing(); + + boolean getLeashed(); + + IEntity getLeashedTo(); + + void setLeashedTo(IEntity entity, boolean sendPacket); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntityLivingBase.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntityLivingBase.java index 3acc3b7d9..62e9b21ff 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntityLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntityLivingBase.java @@ -146,4 +146,12 @@ public interface IEntityLivingBase extends IEntity extends IEntityLivingBase void kick(String reason); void setPosition(double x, double y, double z); + void setPosition(IPos pos); void setPosition(double x, double y, double z, int dimensionId); + void setPosition(IPos pos, int dimensionId); int getHunger(); @@ -210,6 +212,7 @@ public interface IPlayer extends IEntityLivingBase * @param z The z position */ void setSpawnpoint(int x, int y, int z); + void setSpawnpoint(IPos pos); void resetSpawnpoint(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/ICloneHandler.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/ICloneHandler.java index 9fe8108fe..66487249a 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/handler/ICloneHandler.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/ICloneHandler.java @@ -5,14 +5,17 @@ package noppes.npcs.scripted.interfaces.handler; +import noppes.npcs.scripted.interfaces.IPos; import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.interfaces.entity.IEntity; public interface ICloneHandler { IEntity spawn(double x, double y, double z, int tab, String name, IWorld world, boolean ignoreProtection); + IEntity spawn(IPos pos, int tab, String name, IWorld world, boolean ignoreProtection); IEntity spawn(double x, double y, double z, int tab, String name, IWorld world); + IEntity spawn(IPos pos, int tab, String name, IWorld world); IEntity[] getTab(int tab, IWorld world); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java index 6978ae0b9..a754ccd37 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java @@ -1,5 +1,7 @@ package noppes.npcs.scripted.interfaces.handler.data; +import noppes.npcs.scripted.interfaces.IPos; + public interface ITransportLocation { int getId(); @@ -18,6 +20,8 @@ public interface ITransportLocation { void setPosition(int x, int y, int z); + void setPosition(IPos pos); + double getX(); double getY(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java index a9416d60e..55df048f5 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java @@ -5,4 +5,20 @@ public interface IJobBard extends IJob { String getSong(); void setSong(String song); + + void setInstrument(int i); + + int getInstrumentId(); + + void setMinRange(int range); + int getMinRange(); + + void setMaxRange(int range); + int getMaxRange(); + + void setStreaming(boolean streaming); + boolean getStreaming(); + + void hasOffRange(boolean value); + boolean hasOffRange(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java index 16710a8a7..20f5245df 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java @@ -1,4 +1,12 @@ package noppes.npcs.scripted.interfaces.jobs; public interface IJobGuard extends IJob { + boolean attackCreepers(); + void attackCreepers(boolean value); + + boolean attacksAnimals(); + void attacksAnimals(boolean value); + + boolean attackHostileMobs(); + void attackHostileMobs(boolean value); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java index 4cc335383..b5a4cb2ff 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java @@ -5,4 +5,10 @@ import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; public interface IJobHealer extends IJob { void heal(IEntityLivingBase entity, float amount); + + void setRange(int range); + int getRange(); + + void setSpeed(int speed); + int getSpeed(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java index b9ff96ac5..1e9763f6b 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java @@ -1,10 +1,31 @@ package noppes.npcs.scripted.interfaces.jobs; +import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.scripted.interfaces.IPos; +import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; +import noppes.npcs.scripted.interfaces.entity.IPlayer; public interface IJobSpawner extends IJob { - IEntityLivingBase spawnEntity(int number); + IEntityLivingBase spawnEntity(int number); + IEntityLivingBase getEntity(int number, int x, int y, int z, IWorld world); + + IEntityLivingBase getEntity(int number, IPos pos, IWorld world); + + void setEntity(int number, IEntityLivingBase entityLivingBase); + + /** + * Removes all spawned entities + */ void removeAllSpawned(); + + IEntityLivingBase[] getNearbySpawned(); + + boolean hasPixelmon(); + + boolean isEmpty(); + + boolean isOnCooldown(IPlayer player); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java index f309d7bd0..15b535177 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java @@ -1,6 +1,10 @@ package noppes.npcs.scripted.interfaces.roles; +import net.minecraft.entity.INpc; + public interface IRole { + INpc getNpc(); + int getType(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java index b5c9b8f4c..fc6c6c0c1 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java @@ -1,5 +1,19 @@ package noppes.npcs.scripted.interfaces.roles; -public interface IRoleTransporter extends IRole { +import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; +public interface IRoleTransporter extends IRole { + String getName(); + + int getTransportId(); + + void unlock(IPlayer player, ITransportLocation location); + + ITransportLocation getTransport(); + + boolean hasTransport(); + + void setTransport(ITransportLocation location); } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java index fe5811930..da81c8877 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java @@ -30,4 +30,50 @@ public class ScriptJobBard extends ScriptJobInterface implements IJobBard { job.song = song; npc.script.clientNeedsUpdate = true; } + + /** + * + * @param i The id of the instrument. IDs: + * 0 - None, + * 1 - Banjo, + * 2 - Violin, + * 3 - Guitar, + * 4 - Harp, + * 5 - FrenchHorn + */ + public void setInstrument(int i) { + this.job.setInstrument(i); + } + + public int getInstrumentId() { + return this.job.getInstrument().ordinal(); + } + + public void setMinRange(int range) { + this.job.minRange = range; + } + public int getMinRange() { + return this.job.minRange; + } + + public void setMaxRange(int range) { + this.job.maxRange = range; + } + public int getMaxRange() { + return this.job.maxRange; + } + + public void setStreaming(boolean streaming) { + this.job.isStreamer = streaming; + } + public boolean getStreaming() { + return this.job.isStreamer; + } + + public void hasOffRange(boolean value) { + this.job.hasOffRange = value; + } + public boolean hasOffRange() { + return this.job.hasOffRange; + } } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java index e16340f30..d00154541 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java @@ -11,6 +11,27 @@ public class ScriptJobGuard extends ScriptJobInterface implements IJobGuard { super(npc); this.job = (JobGuard) npc.jobInterface; } + + public boolean attackCreepers() { + return job.attackCreepers; + } + public void attackCreepers(boolean value) { + job.attackCreepers = value; + } + + public boolean attacksAnimals() { + return job.attacksAnimals; + } + public void attacksAnimals(boolean value) { + job.attacksAnimals = value; + } + + public boolean attackHostileMobs() { + return job.attackHostileMobs; + } + public void attackHostileMobs(boolean value) { + job.attackHostileMobs = value; + } @Override public int getType(){ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java index 85578453b..c7e99ab5c 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java @@ -16,6 +16,20 @@ public class ScriptJobHealer extends ScriptJobInterface implements IJobHealer { public void heal(IEntityLivingBase entity, float amount){ job.heal(entity.getMCEntity(), amount); } + + public void setRange(int range) { + this.job.range = range; + } + public int getRange() { + return this.job.range; + } + + public void setSpeed(int speed) { + this.job.speed = speed; + } + public int getSpeed() { + return this.job.speed; + } @Override public int getType(){ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java index c44f03aad..ed3f5cf97 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java @@ -1,17 +1,26 @@ package noppes.npcs.scripted.roles; import java.util.ArrayList; +import java.util.List; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobSpawner; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.INbt; +import noppes.npcs.scripted.interfaces.IPos; +import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; +import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.jobs.IJobSpawner; public class ScriptJobSpawner extends ScriptJobInterface implements IJobSpawner { - private JobSpawner job; + private final JobSpawner job; public ScriptJobSpawner(EntityNPCInterface npc){ super(npc); this.job = (JobSpawner) npc.jobInterface; @@ -27,21 +36,64 @@ public class ScriptJobSpawner extends ScriptJobInterface implements IJobSpawner * @param number The entity going to be spawned (1-6) * @return Returns spawned entity */ - public IEntityLivingBase spawnEntity(int number){ + public IEntityLivingBase spawnEntity(int number){ EntityLivingBase base = job.spawnEntity(number); if(base == null) return null; - return (IEntityLivingBase) NpcAPI.Instance().getIEntity(base); + return (IEntityLivingBase) NpcAPI.Instance().getIEntity(base); } - - /** - * Removes all spawned entities - */ + + public IEntityLivingBase getEntity(int number, int x, int y, int z, IWorld world) { + NBTTagCompound compound = this.job.getCompound(number); + if(compound == null || !compound.hasKey("id")) + return null; + Entity entity = NoppesUtilServer.getEntityFromNBT(compound,x,y,z,world.getMCWorld()); + if (!(entity instanceof EntityLivingBase)) { + return null; + } + return (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity); + } + + public IEntityLivingBase getEntity(int number, IPos pos, IWorld world) { + return this.getEntity(number,pos.getX(),pos.getY(),pos.getZ(),world); + } + + public void setEntity(int number, IEntityLivingBase entityLivingBase){ + INbt nbt = entityLivingBase.getNbtOptional(); + if (nbt == null) + return; + this.job.setJobCompound(number,nbt.getMCNBT()); + } + + /** + * Removes all spawned entities + */ public void removeAllSpawned(){ for(EntityLivingBase entity : job.spawned){ entity.isDead = true; } - job.spawned = new ArrayList(); + job.spawned = new ArrayList<>(); + } + + public IEntityLivingBase[] getNearbySpawned() { + List nearbySpawned = this.job.getNearbySpawned(); + List> list = new ArrayList<>(); + for (EntityLivingBase entity : nearbySpawned) { + list.add((IEntityLivingBase) NpcAPI.Instance().getIEntity(entity)); + } + return list.toArray(new IEntityLivingBase[0]); + } + + public boolean hasPixelmon() { + return this.job.hasPixelmon(); + } + + public boolean isEmpty() { + return this.job.isEmpty(); + } + + public boolean isOnCooldown(IPlayer player) { + return this.job.isOnCooldown(player.getName()); } } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java index eef73dd82..d4a41dffa 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java @@ -1,7 +1,9 @@ package noppes.npcs.scripted.roles; +import net.minecraft.entity.INpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleInterface; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.RoleType; import noppes.npcs.scripted.interfaces.roles.IRole; @@ -14,6 +16,10 @@ public class ScriptRoleInterface implements IRole { this.role = npc.roleInterface; } + public INpc getNpc() { + return (INpc) NpcAPI.Instance().getIEntity(npc); + } + /** * @see noppes.npcs.scripted.constants.RoleType * @return The RoleType of this role diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java index 3fbe5560b..c230e7ff6 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java @@ -1,13 +1,44 @@ package noppes.npcs.scripted.roles; +import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.roles.RoleTransporter; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; import noppes.npcs.scripted.interfaces.roles.IRoleTransporter; public class ScriptRoleTransporter extends ScriptRoleInterface implements IRoleTransporter { + private final RoleTransporter role; public ScriptRoleTransporter(EntityNPCInterface npc) { super(npc); + role = (RoleTransporter) npc.roleInterface; + + } + + public String getName() { + return role.name; + } + + public int getTransportId() { + return role.transportId; + } + + public void unlock(IPlayer player, ITransportLocation location) { + this.role.unlock(player.getMCEntity(), location); + } + + public ITransportLocation getTransport(){ + return this.role.getLocation(); + } + + public boolean hasTransport(){ + return this.role.hasTransport(); + } + + public void setTransport(ITransportLocation location) { + this.role.setTransport(location); } @Override diff --git a/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java b/src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboard.java similarity index 98% rename from src/main/java/noppes/npcs/scripted/ScriptScoreboard.java rename to src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboard.java index 513f9cc7f..3d08c23fe 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java +++ b/src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboard.java @@ -1,4 +1,4 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.scoreboard; import java.util.ArrayList; import java.util.List; @@ -15,8 +15,8 @@ import net.minecraft.server.MinecraftServer; */ public class ScriptScoreboard { private Scoreboard board; - - protected ScriptScoreboard(){ + + public ScriptScoreboard(){ board = MinecraftServer.getServer().worldServerForDimension(0).getScoreboard(); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptScoreboardObjective.java b/src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboardObjective.java similarity index 96% rename from src/main/java/noppes/npcs/scripted/ScriptScoreboardObjective.java rename to src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboardObjective.java index 7100640a1..63cea0160 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptScoreboardObjective.java +++ b/src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboardObjective.java @@ -1,4 +1,4 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.scoreboard; import net.minecraft.scoreboard.ScoreObjective; diff --git a/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java b/src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboardTeam.java similarity index 98% rename from src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java rename to src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboardTeam.java index bed2b0a24..1d6233dd8 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java +++ b/src/main/java/noppes/npcs/scripted/scoreboard/ScriptScoreboardTeam.java @@ -1,4 +1,4 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.scoreboard; import java.util.ArrayList; import java.util.List;