mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 12:15:11 +00:00
Added various things to the API and other small changes
This adds some useful functions to the api and a few other changes. I had been creating a custom build of this mod while working on stuff because I couldn't figure out how to do certain things without changing the mod. So this is a collection api features that I think everyone would find useful. Api additions: -purchase counting, and disabling trades for the trader role. (if a trade is disabled the gui still says insufficient funds, maybe allow a custom message to appear) added get the traders currency items and sell items. -if an npc's projectile does explosive damage, you can disable it destroying blocks even if mob griefing is on -int arrays as stored data for entities -entity.playSound(...) -get set if npcs can drown -player read and unread dialog -player set faction points -extra player.sendMessage functions to add custom colors/bold/underline -player clear inventory -get set if a follower npc is following a player or waiting -a bunch of stuff to script faction -is an item food and how many food points? -get scoreboard team by it's name -get and create factions from the script world -world.rayCastBlockPos is used for getting what block a player is looking at. -world.getNearestAir is meant to get the block of air above or around the result of world.rayCastBlockPos, or at least that's how I've been using it. Changes: -in NoppesUtilServer I feel like if an npc is cloned it's ticksExisted or age should bee zero -follower npcs should have the canDespawn field automatically set to false...? maybe make it an option
This commit is contained in:
1 parent
6fe16d1929
commit
a4361b8420
21 files changed
+468
-13
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -15,6 +15,7 @@ public class JobFollower extends JobInterface{
|
||||
|
||||
public JobFollower(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
npc.stats.canDespawn = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,7 @@ public class RoleFollower extends RoleInterface{
|
||||
super(npc);
|
||||
inventory = new NpcMiscInventory(3);
|
||||
rates = new HashMap<Integer, Integer>();
|
||||
npc.stats.canDespawn = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<String> list = new ArrayList<String>(team.getMembershipCollection());
|
||||
for(String player : list){
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<T extends Entity> 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<T extends Entity> 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<T extends Entity> 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<T extends Entity> 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
|
||||
|
||||
@@ -269,6 +269,16 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> 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<T extends EntityNPCInterface> extends ScriptLiving<T> 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<T extends EntityNPCInterface> extends ScriptLiving<T> 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;
|
||||
|
||||
@@ -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<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
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<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
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<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
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<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
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<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
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;
|
||||
|
||||
@@ -162,6 +162,10 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
|
||||
* @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<T extends EntityCreature> extends IEntityLiving<T> {
|
||||
* @return The maximum XP gained from killing the NPC.
|
||||
*/
|
||||
public int getMaxLootXP();
|
||||
|
||||
|
||||
public boolean getCanDrown();
|
||||
|
||||
public void setCanDrown(boolean b);
|
||||
|
||||
/**
|
||||
* @param type The AnimationType
|
||||
*/
|
||||
|
||||
@@ -129,7 +129,8 @@ public interface IEntity<T extends Entity> {
|
||||
* @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<T extends Entity> {
|
||||
* @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<T extends Entity> {
|
||||
* @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
|
||||
|
||||
@@ -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<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
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<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
* @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<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
* @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<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
* @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<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
public ScriptPixelmonPlayerData getPixelmonData();
|
||||
|
||||
public Vec3 getLookingAtBlock(int maxDistance);
|
||||
|
||||
public ITimers getTimers();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(){
|
||||
|
||||
Reference in new issue
Block a user