diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index eff4322f9..eef05193c 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -658,6 +658,8 @@ public class NoppesUtilServer { if(entity instanceof EntityNPCInterface){ EntityNPCInterface npc = (EntityNPCInterface) entity; npc.ai.startPos = new int[]{MathHelper.floor_double(npc.posX),MathHelper.floor_double(npc.posY),MathHelper.floor_double(npc.posZ)}; + npc.ticksExisted = 0; + npc.totalTicksAlive = 0; } worldObj.spawnEntityInWorld(entity); return entity; diff --git a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java index 77a3b8a43..5459ccc0a 100644 --- a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java +++ b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java @@ -66,6 +66,7 @@ public class ContainerNPCTrader extends ContainerNpcInterface{ NoppesUtilPlayer.consumeItem(entityplayer, role.inventoryCurrency.getStackInSlot(i + 18), role.ignoreDamage, role.ignoreNBT); ItemStack soldItem = item.copy(); givePlayer(soldItem, entityplayer); + ++role.purchases[i]; return soldItem; } @@ -74,7 +75,7 @@ public class ContainerNPCTrader extends ContainerNpcInterface{ ItemStack currency2 = role.inventoryCurrency.getStackInSlot(slot + 18); if(currency == null && currency2 == null) return true; - + if (role.disableSlot[slot] > 0) return false; if(currency == null){ currency = currency2; currency2 = null; diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index c8b672a82..a0b075600 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -139,7 +139,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public boolean updateClient = false; public boolean updateAI = false; - + public boolean projectilesKeepTerrain = false; + public FlyingMoveHelper flyMoveHelper = new FlyingMoveHelper(this); public PathNavigate flyNavigator = new PathNavigateFlying(this, worldObj); @@ -956,6 +957,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti totalTicksAlive = compound.getLong("TotalTicksAlive"); linkedName = compound.getString("LinkedNpcName"); + + projectilesKeepTerrain = compound.getBoolean("ProjectilesKeepTerrain"); + if(!isRemote()) LinkedNpcController.Instance.loadNpcData(this); @@ -987,6 +991,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti compound.setLong("TotalTicksAlive", totalTicksAlive); compound.setInteger("ModRev", npcVersion); compound.setString("LinkedNpcName", linkedName); + compound.setBoolean("ProjectilesKeepTerrain", projectilesKeepTerrain); } public void updateHitbox() { diff --git a/src/main/java/noppes/npcs/entity/EntityProjectile.java b/src/main/java/noppes/npcs/entity/EntityProjectile.java index dec7f789e..dad83d04c 100644 --- a/src/main/java/noppes/npcs/entity/EntityProjectile.java +++ b/src/main/java/noppes/npcs/entity/EntityProjectile.java @@ -77,6 +77,7 @@ public class EntityProjectile extends EntityThrowable { public boolean accelerate = false; public boolean explosive = false; public boolean explosiveDamage = true; + public boolean destroyTerrain = true; public int explosiveRadius = 0; public EnumPotionType effect = EnumPotionType.None; public int duration = 5; @@ -138,6 +139,7 @@ public class EntityProjectile extends EntityThrowable { if (isNPC) { this.npc = (EntityNPCInterface) this.thrower; this.getStatProperties(this.npc.stats); + this.destroyTerrain = !this.npc.projectilesKeepTerrain; } } @@ -562,7 +564,7 @@ public class EntityProjectile extends EntityThrowable { if (explosive){ if (this.explosiveRadius != 0 || this.effect == EnumPotionType.None){ - boolean terraindamage = this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing") && explosiveDamage; + boolean terraindamage = this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing") && explosiveDamage && destroyTerrain; Explosion explosion = new Explosion(worldObj, this, posX, posY, posZ, explosiveRadius); explosion.isFlaming = this.effect == EnumPotionType.Fire; explosion.isSmoking = terraindamage; diff --git a/src/main/java/noppes/npcs/roles/JobFollower.java b/src/main/java/noppes/npcs/roles/JobFollower.java index 69e44850a..7d6e6d65b 100644 --- a/src/main/java/noppes/npcs/roles/JobFollower.java +++ b/src/main/java/noppes/npcs/roles/JobFollower.java @@ -15,6 +15,7 @@ public class JobFollower extends JobInterface{ public JobFollower(EntityNPCInterface npc) { super(npc); + npc.stats.canDespawn = false; } @Override diff --git a/src/main/java/noppes/npcs/roles/RoleFollower.java b/src/main/java/noppes/npcs/roles/RoleFollower.java index 67a578f3c..8c885820c 100644 --- a/src/main/java/noppes/npcs/roles/RoleFollower.java +++ b/src/main/java/noppes/npcs/roles/RoleFollower.java @@ -35,6 +35,7 @@ public class RoleFollower extends RoleInterface{ super(npc); inventory = new NpcMiscInventory(3); rates = new HashMap(); + npc.stats.canDespawn = false; } @Override diff --git a/src/main/java/noppes/npcs/roles/RoleTrader.java b/src/main/java/noppes/npcs/roles/RoleTrader.java index d8da53a7c..b6f21eda6 100644 --- a/src/main/java/noppes/npcs/roles/RoleTrader.java +++ b/src/main/java/noppes/npcs/roles/RoleTrader.java @@ -24,10 +24,15 @@ public class RoleTrader extends RoleInterface{ public boolean toSave = false; + public int[] purchases; + public int[] disableSlot; + public RoleTrader(EntityNPCInterface npc) { super(npc); inventoryCurrency = new NpcMiscInventory(36); inventorySold = new NpcMiscInventory(18); + purchases = new int[18]; + disableSlot = new int[18]; } @Override @@ -46,6 +51,8 @@ public class RoleTrader extends RoleInterface{ nbttagcompound.setTag("TraderSold", inventorySold.getToNBT()); nbttagcompound.setBoolean("TraderIgnoreDamage", ignoreDamage); nbttagcompound.setBoolean("TraderIgnoreNBT", ignoreNBT); + nbttagcompound.setIntArray("Purchases", purchases); + nbttagcompound.setIntArray("DisableSlot", disableSlot); return nbttagcompound; } @@ -67,7 +74,16 @@ public class RoleTrader extends RoleInterface{ inventorySold.setFromNBT(nbttagcompound.getCompoundTag("TraderSold")); ignoreDamage = nbttagcompound.getBoolean("TraderIgnoreDamage"); ignoreNBT = nbttagcompound.getBoolean("TraderIgnoreNBT"); - + purchases = nbttagcompound.getIntArray("Purchases"); + if (purchases == null || purchases.length < 18) { + purchases = new int[18]; + for (int i = 0; i < purchases.length; ++i) purchases[i] = 0; + } + disableSlot = nbttagcompound.getIntArray("DisableSlot"); + if (disableSlot == null || disableSlot.length < 18) { + disableSlot = new int[18]; + for (int i = 0; i < disableSlot.length; ++i) disableSlot[i] = 0; + } } @Override diff --git a/src/main/java/noppes/npcs/scripted/ScriptFaction.java b/src/main/java/noppes/npcs/scripted/ScriptFaction.java index 972ecaf2b..2fc999337 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptFaction.java +++ b/src/main/java/noppes/npcs/scripted/ScriptFaction.java @@ -1,11 +1,17 @@ package noppes.npcs.scripted; import noppes.npcs.controllers.Faction; +import noppes.npcs.controllers.FactionController; import noppes.npcs.scripted.entity.ScriptNpc; import noppes.npcs.scripted.entity.ScriptPlayer; public class ScriptFaction { + private Faction faction; + + public void saveFaction() { + FactionController.getInstance().saveFaction(faction); + } public ScriptFaction(Faction faction){ this.faction = faction; @@ -25,14 +31,58 @@ public class ScriptFaction { return faction.name; } + public void setName(String name) { + faction.name = name; + } + public int getDefaultPoints(){ return faction.defaultPoints; } + + public void setDefaultPoints(int p) { + faction.defaultPoints = p; + } + + public int getFriendlyPoints() { + return faction.friendlyPoints; + } + + public void setFriendlyPoints(int p) { + faction.friendlyPoints = p; + } + + public int getNeutralPoints() { + return faction.neutralPoints; + } + + public void setNeutralPoints(int p) { + faction.neutralPoints = p; + } + + public boolean getHideFaction() { + return faction.hideFaction; + } + + public void setHideFaction(boolean b) { + faction.hideFaction = b; + } + + public boolean getGetsAttacked() { + return faction.getsAttacked; + } + + public void setGetsAttacked(boolean b) { + faction.getsAttacked = b; + } public int getColor(){ return faction.color; } + public void setColor(int c) { + faction.color = c; + } + public boolean isFriendlyToPlayer(ScriptPlayer player){ return faction.isFriendlyToPlayer(player.player); } @@ -48,4 +98,31 @@ public class ScriptFaction { public boolean isAggressiveToNpc(ScriptNpc npc){ return faction.isAggressiveToNpc(npc.npc); } + + public int[] getFactionEnemies() { + if (faction.attackFactions == null) return null; + int[] r = new int[faction.attackFactions.size()]; + Object[] objects = faction.attackFactions.toArray(); + for (int i = 0; i < r.length; ++i) { + r[i] = (Integer)objects[i]; + } + return r; + } + + public boolean isEnemyFaction(int id) { + if (faction.attackFactions == null) return false; + int[] enemies = getFactionEnemies(); + for (int i = 0; i < enemies.length; ++i) { + if (enemies[i] == id) return true; + } + return false; + } + + public void addFactionEnemy(int id) { + if (!faction.attackFactions.contains(id)) faction.attackFactions.add(id); + } + + public void removeFactionEnemy(int id) { + faction.attackFactions.remove(id); + } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java index 81fb082a0..f15b8d41a 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java @@ -6,12 +6,14 @@ import java.util.List; import java.util.Map; import com.google.common.collect.Multimap; + import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; +import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase.NBTPrimitive; @@ -346,6 +348,15 @@ public class ScriptItemStack implements IItemStack { return false; return true; } + + public boolean isFood() { + return item.getItem() instanceof ItemFood; + } + + public int getFoodPoints() { + if (isFood()) return ((ItemFood)item.getItem()).func_150905_g(item); + return -1; + } public INbt getNbt() { NBTTagCompound compound = this.item.getTagCompound(); diff --git a/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java b/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java index 603f88ec8..513f9cc7f 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java +++ b/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java @@ -152,6 +152,16 @@ public class ScriptScoreboard { return teams; } + public ScriptScoreboardTeam getTeamByName(String name) { + ScriptScoreboardTeam[] teams = getTeams(); + for (int i = 0; i < teams.length; i++) { + if (teams[i].getName().equals(name)) { + return teams[i]; + } + } + return null; + } + public boolean hasTeam(String name){ return board.getPlayersTeam(name) != null; } diff --git a/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java b/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java index 639ee0b3e..bed2b0a24 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java +++ b/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java @@ -44,6 +44,10 @@ public class ScriptScoreboardTeam { return list.toArray(new String[list.size()]); } + public int getTeamsize() { + return team.getMembershipCollection().size(); + } + public void clearPlayers(){ List list = new ArrayList(team.getMembershipCollection()); for(String player : list){ diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index cbcc43f48..b2e7fe1cd 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -3,6 +3,7 @@ package noppes.npcs.scripted; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import net.minecraft.block.Block; import net.minecraft.entity.Entity; @@ -18,11 +19,14 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.Vec3; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileBigSign; +import noppes.npcs.controllers.Faction; +import noppes.npcs.controllers.FactionController; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.scripted.entity.ScriptEntity; @@ -93,6 +97,14 @@ public class ScriptWorld implements IWorld { return null; } + public void setBlock(int x, int y, int z, Block block){ + if(block == null || block == Blocks.air){ + removeBlock(x, y, z); + return; + } + world.setBlock(x, y, z, block); + } + /** * @param x World position x * @param y World position y @@ -119,6 +131,61 @@ public class ScriptWorld implements IWorld { world.setBlock(x, y, z, Blocks.air); } + public Vec3 rayCastBlockPos(Vec3 pos, Vec3 look, int maxDistance) { + Vec3 currentPos = pos; int rep = 0; + while (rep++ < maxDistance + 10) { + currentPos = currentPos.addVector(look.xCoord, look.yCoord, look.zCoord); + IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + //System.out.println("Checking block at ["+(int)currentPos.xCoord+","+(int)currentPos.yCoord+","+(int)currentPos.zCoord+"]"); + if (block == null) continue; + double distance = Math.pow( + Math.pow(currentPos.xCoord-pos.xCoord,2) + +Math.pow(currentPos.yCoord-pos.yCoord,2) + +Math.pow(currentPos.zCoord-pos.zCoord,2) + , 0.5); + //System.out.println("current distance check: "+distance+" on rep "+rep); + if (distance > maxDistance) return null; + return currentPos; + } + //System.out.println("ScriptWorld:WARNING: Repeated a ray cast to many times"); + return null; + } + + public Vec3 getNearestAir(Vec3 pos, int maxHeight) { + if (pos == null) return null; + Vec3 currentPos = pos; + IBlock block = null; int rep = 0; + while (rep++ < maxHeight) { + //check +x + currentPos = currentPos.addVector(1, 0, 0); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + //check -x + currentPos = currentPos.addVector(-2, 0, 0); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + //check +z + currentPos = currentPos.addVector(1, 0, 1); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + //check -z + currentPos = currentPos.addVector(0, 0, -2); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + //check up 1 + currentPos = currentPos.addVector(0, 1, 1); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + } + Vec3 posInt = Vec3.createVectorHelper((int)currentPos.xCoord, + (int)currentPos.yCoord, (int)currentPos.zCoord); + return posInt; + } + + public boolean canSeeSky(int x, int y, int z) { + return world.canBlockSeeTheSky(x, y, z); + } + /** * @param name The name of the player to be returned * @return The Player with name. Null is returned when the player isnt found @@ -317,6 +384,13 @@ public class ScriptWorld implements IWorld { return arr; } + public String[] getPlayerNames() { + ScriptPlayer[] players = getAllServerPlayers(); + String[] names = new String[players.length]; + for (int i = 0; i < names.length; ++i) names[i] = players[i].getDisplayName(); + return names; + } + /** * @since 1.7.10c * @param x Position x @@ -346,6 +420,40 @@ public class ScriptWorld implements IWorld { return ScriptController.Instance.getScriptForEntity(entity); } + public boolean spawnEntity(Entity e) { + if (world.spawnEntityInWorld(e)) return true; + return false; + } + + /** + * Create a new default faction + * @param name The name of the new faction. If the name already exists an '_' will be added at the end + * @return The faction object which was created + */ + public ScriptFaction createFaction(String name) { + //System.out.println("Attempting to create new faction "+name); + int maxValue = 0xFFFFFF; + Random r = new Random(); + int randomColor = r.nextInt(maxValue + 1); + + Faction fac = new Faction(-1, name, randomColor, 1000); + FactionController.getInstance().saveFaction(fac); + + return new ScriptFaction(fac); + } + + public ScriptFaction getFactionFromName(String name) { + Faction f = FactionController.getInstance().getFactionFromName(name); + if (f == null) return null; + return new ScriptFaction(f); + } + + public ScriptFaction getFactionFromId(int id) { + Faction f = FactionController.getInstance().get(id); + if (f == null) return null; + return new ScriptFaction(f); + } + public ScriptScoreboard getScoreboard(){ return new ScriptScoreboard(); } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index ca7d500b2..5434300ad 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -15,8 +15,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase.NBTPrimitive; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagIntArray; import net.minecraft.nbt.NBTTagString; -import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; @@ -24,7 +24,12 @@ import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.*; +import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.ScriptBlockPos; +import noppes.npcs.scripted.ScriptEntityParticle; +import noppes.npcs.scripted.ScriptItemStack; +import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.IEntity; import noppes.npcs.scripted.interfaces.INbt; @@ -313,6 +318,10 @@ public class ScriptEntity implements IEntity { public void setPos(IPos pos) { this.entity.setPosition((double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F)); } + + public int getDimension() { + return entity.dimension; + } /** * @param range The search range for entities around this entity @@ -413,6 +422,8 @@ public class ScriptEntity implements IEntity { NBTBase base = compound.getTag(key); if(base instanceof NBTPrimitive) return ((NBTPrimitive)base).func_150286_g(); + else if (base instanceof NBTTagIntArray) + return ((NBTTagIntArray)base).func_150302_c(); return ((NBTTagString)base).func_150285_a_(); } @@ -430,6 +441,12 @@ public class ScriptEntity implements IEntity { compound.setString(key, (String)value); saveStoredCompound(compound); } + + public void setStoredData(String key, int[] array){ + NBTTagCompound compound = getStoredCompound(); + compound.setIntArray(key, array); + saveStoredCompound(compound); + } /** * @param key The key of the data to be checked @@ -528,6 +545,10 @@ public class ScriptEntity implements IEntity { public String getTypeName(){ return EntityList.getEntityString(entity); } + + public void playSound(String name, float volume, float pitch) { + entity.playSound(name, volume, pitch); + } /** * @param item Item to be dropped diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index a777901ae..7775de977 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -269,6 +269,16 @@ public class ScriptNpc extends ScriptLiving imp npc.shoot(target.entity, accuracy, item.item, false); } + public void setProjectilesKeepTerrain(boolean t) { + npc.projectilesKeepTerrain = t; + } + + public boolean getProjectilesKeepTerrain() { + return npc.projectilesKeepTerrain; + } + + + /** * @param message The message the npc will say */ @@ -524,7 +534,8 @@ public class ScriptNpc extends ScriptLiving imp * @param item The item the drop list slot will be changed to */ public void setLootItem(int slot, ScriptItemStack item) { - npc.inventory.setInventorySlotContents(slot+7, item.item); + if (item == null) npc.inventory.setInventorySlotContents(slot+7, null); + else npc.inventory.setInventorySlotContents(slot+7, item.item); } /** @@ -1000,6 +1011,13 @@ public class ScriptNpc extends ScriptLiving imp npc.stats.healthRegen = (float)(Math.floor(regen)); } + public boolean getCanDrown() { + return npc.stats.canDrown; + } + public void setCanDrown(boolean d) { + npc.stats.canDrown = d; + } + @Override public long getAge(){ return npc.totalTicksAlive; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index d3b1fc98f..855188037 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -9,7 +9,10 @@ import net.minecraft.stats.Achievement; import net.minecraft.stats.StatBase; import net.minecraft.stats.StatList; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChatStyle; import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Vec3; import net.minecraft.world.WorldSettings; import noppes.npcs.*; import noppes.npcs.constants.EnumPacketClient; @@ -21,6 +24,7 @@ import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; +import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.event.FactionEvent; import noppes.npcs.scripted.gui.ScriptGui; @@ -120,6 +124,14 @@ public class ScriptPlayer extends ScriptLivingBase PlayerDialogData data = PlayerDataController.instance.getPlayerData(player).dialogData; return data.dialogsRead.contains(id); } + + public void readDialog(int id) { + PlayerDataController.instance.getPlayerData(player).dialogData.dialogsRead.add(id); + } + + public void unreadDialog(int id) { + PlayerDataController.instance.getPlayerData(player).dialogData.dialogsRead.remove(id); + } /** * Add the quest from active quest list @@ -192,6 +204,14 @@ public class ScriptPlayer extends ScriptLivingBase PlayerData data = PlayerDataController.instance.getPlayerData(player); data.factionData.increasePoints(faction, points, player); } + /** + * @param faction The faction id + * @param points The new point value for this faction + */ + public void setFactionPoints(int faction, int points) { + PlayerData data = PlayerDataController.instance.getPlayerData(player); + data.factionData.increasePoints(faction, points-getFactionPoints(faction), player); + } /** * @param faction The faction id @@ -209,6 +229,36 @@ public class ScriptPlayer extends ScriptLivingBase player.addChatMessage(new ChatComponentTranslation(NoppesStringUtils.formatText(message,player))); } + /** + * @param message The message you want to send + */ + public void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean underlined) { + ChatComponentTranslation chat = new ChatComponentTranslation(NoppesStringUtils.formatText(message,player)); + ChatStyle style = new ChatStyle(); + style.setColor(color); + style.setBold(bold); + style.setItalic(italic); + style.setUnderlined(underlined); + chat.setChatStyle(style); + player.addChatMessage(chat); + } + + /** + * @param message The message you want to send + */ + public void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean obfuscated, boolean strikethrough, boolean underlined) { + ChatComponentTranslation chat = new ChatComponentTranslation(NoppesStringUtils.formatText(message,player)); + ChatStyle style = new ChatStyle(); + style.setColor(color); + style.setBold(bold); + style.setItalic(italic); + style.setObfuscated(obfuscated); + style.setStrikethrough(strikethrough); + style.setUnderlined(underlined); + chat.setChatStyle(style); + player.addChatMessage(chat); + } + /** * @return Return gamemode. 0: Survival, 1: Creative, 2: Adventure */ @@ -352,6 +402,11 @@ public class ScriptPlayer extends ScriptLivingBase player.inventory.mainInventory[i] = null; } } + + public void clearInventory() { + for(int i = 0; i < player.inventory.mainInventory.length; i++) player.inventory.mainInventory[i] = null; + for(int i = 0; i < player.inventory.armorInventory.length; i++) player.inventory.armorInventory[i] = null; + } public void setRotation(float rotationYaw){ NoppesUtilPlayer.teleportPlayer(player, player.posX, player.posY, player.posZ, rotationYaw, player.rotationPitch, player.dimension); @@ -407,6 +462,13 @@ public class ScriptPlayer extends ScriptLivingBase return null; return new ScriptPixelmonPlayerData(player); } + + public Vec3 getLookingAtBlock(int maxDistance) { + Vec3 posVec = Vec3.createVectorHelper(player.posX, + player.posY+player.getEyeHeight(), player.posZ); + Vec3 lookVec = player.getLookVec(); + return NpcAPI.Instance().getIWorld(player.dimension).rayCastBlockPos(posVec, lookVec, maxDistance); + } public ITimers getTimers() { return PlayerDataController.instance.getPlayerData(player).timers; diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java index 47f0fa7ab..6f3e5bdcc 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java @@ -162,6 +162,10 @@ public interface ICustomNpc extends IEntityLiving { * @param accuracy Accuracy of the shot (0-100) */ public void shootItem(ScriptLivingBase target, ScriptItemStack item, int accuracy); + + public void setProjectilesKeepTerrain(boolean b); + + public boolean getProjectilesKeepTerrain(); /** * @param message The message the npc will say @@ -343,7 +347,11 @@ public interface ICustomNpc extends IEntityLiving { * @return The maximum XP gained from killing the NPC. */ public int getMaxLootXP(); - + + public boolean getCanDrown(); + + public void setCanDrown(boolean b); + /** * @param type The AnimationType */ diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java index a806676d9..83618ef57 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java @@ -129,7 +129,8 @@ public interface IEntity { * @param z The z position */ public void setPosition(double x, double y, double z); - + + public int getDimension(); /** * @param range The search range for entities around this entity @@ -190,6 +191,8 @@ public interface IEntity { * @param value The data stored. This data can be either a Number or a String. Other data is not stored */ public void setStoredData(String key, Object value); + + public void setStoredData(String key, int[] array); /** * @param key The key of the data to be checked @@ -251,6 +254,8 @@ public interface IEntity { * @return Name as which it's registered in minecraft */ public String getTypeName(); + + public void playSound(String name, float volume, float pitch); /** * @param item Item to be dropped diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java index cafe9629e..6d1799193 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java @@ -1,6 +1,8 @@ package noppes.npcs.scripted.interfaces; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Vec3; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; @@ -26,6 +28,10 @@ public interface IPlayer extends IEntityLivingBase public void showDialog(int id); public boolean hasReadDialog(int id); + + public void readDialog(int id); + + public void unreadDialog(int id); /** * Add the quest from active quest list @@ -58,7 +64,11 @@ public interface IPlayer extends IEntityLivingBase * @param points The points to increase. Use negative values to decrease */ public void addFactionPoints(int faction, int points); - + /** + * @param faction The faction id + * @param points The new point value for this faction + */ + public void setFactionPoints(int faction, int points); /** * @param faction The faction id * @return points @@ -69,7 +79,11 @@ public interface IPlayer extends IEntityLivingBase * @param message The message you want to send */ public void sendMessage(String message); - + + public void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean underlined); + + public void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean obfuscated, boolean strikethrough, boolean underlined); + /** * @return Return gamemode. 0: Survival, 1: Creative, 2: Adventure */ @@ -139,6 +153,8 @@ public interface IPlayer extends IEntityLivingBase * @param item The item to be removed from the players inventory */ public void removeAllItems(ScriptItemStack item); + + public void clearInventory(); /** @@ -170,6 +186,8 @@ public interface IPlayer extends IEntityLivingBase * @since 1.7.10d */ public ScriptPixelmonPlayerData getPixelmonData(); + + public Vec3 getLookingAtBlock(int maxDistance); public ITimers getTimers(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 9c7b14534..fe09a6df1 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -1,5 +1,8 @@ package noppes.npcs.scripted.interfaces; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.util.Vec3; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -42,13 +45,27 @@ public interface IWorld { * @param item The block to be set */ public void setBlock(int x, int y, int z, ScriptItemStack item); - + + /** + * @param x World position x + * @param y World position y + * @param z World position z + * @param block The block to be set + */ + public void setBlock(int x, int y, int z, Block 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); + + public Vec3 rayCastBlockPos(Vec3 pos, Vec3 look, int maxDistance); + + public Vec3 getNearestAir(Vec3 pos, int maxHeight); + + public boolean canSeeSky(int x, int y, int z); /** * @param name The name of the player to be returned @@ -180,6 +197,8 @@ public interface IWorld { public void explode(double x, double y, double z, float range, boolean fire, boolean grief); public ScriptPlayer[] getAllServerPlayers(); + + public String[] getPlayerNames(); /** * @since 1.7.10c @@ -199,7 +218,20 @@ public interface IWorld { * @return Returns the entity which was spawned */ public ScriptEntity spawnClone(int x, int y, int z, int tab, String name); - + + public boolean spawnEntity(Entity e); + + /** + * Create a new default faction + * @param name The name of the new faction. If the name already exists an '_' will be added at the end + * @return The faction object which was created + */ + public ScriptFaction createFaction(String name); + + public ScriptFaction getFactionFromName(String name); + + public ScriptFaction getFactionFromId(int id); + public ScriptScoreboard getScoreboard(); BlockPos getMCBlockPos(int x, int y, int z); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java index d10bd8dad..1041e3f17 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java @@ -46,6 +46,14 @@ public class ScriptRoleFollower extends ScriptRoleInterface{ return role.owner != null; } + public boolean isFollowing() { + return role.isFollowing(); + } + + public void setIsFollowing(boolean following) { + if (role.owner != null && role.getDaysLeft() > 0) role.isFollowing = following; + } + /** * @since 1.7.10c * @return Returns days left diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 353afc2fb..1a128d214 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -46,6 +46,32 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ setSellOption(slot, currency, null, sold); } + /** + * @param slot + * @return The item being sold in this slot. + */ + public ScriptItemStack getSellOption(int slot) { + if (slot >= 18 || slot < 0) return null; + if (role.inventorySold.items.get(slot) == null) return null; + return new ScriptItemStack(role.inventorySold.items.get(slot)); + } + + /** + * @param slot + * @return a ScriptItemStack array of size 2 which contains the currency of this trade + */ + public ScriptItemStack[] getCurrency(int slot) { + if (slot >= 18 || slot < 0) return null; + ScriptItemStack[] currency = new ScriptItemStack[2]; + if (role.inventoryCurrency.items.get(slot) != null) { + currency[0] = new ScriptItemStack(role.inventoryCurrency.items.get(slot)); + } + if (role.inventoryCurrency.items.get(slot + 18) != null) { + currency[1] = new ScriptItemStack(role.inventoryCurrency.items.get(slot + 18)); + } + return currency; + } + /** * @param slot Slot number 0-17 */ @@ -70,6 +96,25 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ public String getMarket(){ return role.marketName; } + + public int getPurchaseNum(int slot) { + if(slot >= 18 || slot < 0) return -1; + return role.purchases[slot]; + } + + public void resetPurchaseNum() { + for (int i = 0; i < role.purchases.length; ++i) role.purchases[i] = 0; + } + + public void disableSlot(int slot) { + if(slot >= 18 || slot < 0) return; + role.disableSlot[slot] = 1; + } + + public void enableSlot(int slot) { + if(slot >= 18 || slot < 0) return; + role.disableSlot[slot] = 0; + } @Override public int getType(){