mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 02:42:18 +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
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user