mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 20:49:05 +00:00
Merge remote-tracking branch 'origin/dev' into animation-events
# Conflicts: # src/api # src/main/java/noppes/npcs/controllers/data/AnimationData.java
This commit is contained in:
commit
d055d434df
377 files changed
+2385
-1098
No files matched your search
@@ -14,10 +14,8 @@ import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntitySign;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
@@ -1373,4 +1371,9 @@ public class ScriptWorld implements IWorld {
|
||||
public String toString() {
|
||||
return "DIM" + this.getDimensionID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(String message){
|
||||
world.func_73046_m().getConfigurationManager().sendChatMsg(new ChatComponentText(message));
|
||||
}
|
||||
}
|
||||
@@ -1319,7 +1319,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
return;
|
||||
this.npc.display.url = url;
|
||||
npc.textureLocation = null;
|
||||
npc.display.skinType = 2;
|
||||
if(npc.display.skinType < 2)
|
||||
npc.display.skinType = 2;
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -464,34 +464,29 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
* @param amount How many will be removed
|
||||
* @return Returns true if the items were removed succesfully. Returns false incase a bigger amount than what the player has was given
|
||||
*/
|
||||
public boolean removeItem(IItemStack item, int amount, boolean ignoreNBT, boolean ignoreDamage) {
|
||||
int count = inventoryItemCount(item);
|
||||
if(amount > count)
|
||||
return false;
|
||||
else if(count == amount)
|
||||
removeAllItems(item);
|
||||
else{
|
||||
for(int i = 0; i < player.inventory.mainInventory.length; i++){
|
||||
ItemStack is = player.inventory.mainInventory[i];
|
||||
if (is != null && NoppesUtilPlayer.compareItems(is, item.getMCItemStack(), ignoreDamage, ignoreNBT)) {
|
||||
if(amount > is.stackSize){
|
||||
player.inventory.mainInventory[i] = null;
|
||||
amount -= is.stackSize;
|
||||
}
|
||||
else{
|
||||
is.splitStack(amount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updatePlayerInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeAllItems(IItemStack item){
|
||||
removeAllItems(item, true, true);
|
||||
}
|
||||
public boolean removeItem(IItemStack item, int amount, boolean ignoreNBT, boolean ignoreDamage) {
|
||||
int count = inventoryItemCount(item,ignoreNBT,ignoreDamage);
|
||||
if(amount > count) {
|
||||
return false;
|
||||
} else if(count == amount) {
|
||||
removeAllItems(item, ignoreNBT, ignoreDamage);
|
||||
} else {
|
||||
for(int i = 0; i < player.inventory.mainInventory.length; i++) {
|
||||
ItemStack is = player.inventory.mainInventory[i];
|
||||
if (is != null && NoppesUtilPlayer.compareItems(is, item.getMCItemStack(), ignoreDamage, ignoreNBT)) {
|
||||
if(amount > is.stackSize){
|
||||
player.inventory.mainInventory[i] = null;
|
||||
amount -= is.stackSize;
|
||||
} else{
|
||||
is.splitStack(amount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updatePlayerInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item The item to be removed from the players inventory
|
||||
|
||||
@@ -156,7 +156,7 @@ public abstract class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
}
|
||||
|
||||
public String getHookName() {
|
||||
return EnumScriptType.INTERACT.function;
|
||||
return EnumScriptType.RIGHT_CLICK.function;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
|
||||
@@ -227,7 +227,7 @@ public abstract class NpcEvent extends CustomNPCsEvent implements INpcEvent {
|
||||
|
||||
public SwingEvent(ICustomNpc npc, ItemStack itemStack) {
|
||||
super(npc);
|
||||
this.itemStack = (IItemStack)NpcAPI.Instance().getIItemStack(itemStack);
|
||||
this.itemStack = itemStack == null ? null : (IItemStack)NpcAPI.Instance().getIItemStack(itemStack);
|
||||
}
|
||||
|
||||
public String getHookName() {
|
||||
@@ -237,7 +237,6 @@ public abstract class NpcEvent extends CustomNPCsEvent implements INpcEvent {
|
||||
/**
|
||||
* @return Returns the swung item
|
||||
*/
|
||||
@Override
|
||||
public IItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
public int maxItemUseDuration = 20;
|
||||
public int itemUseAction = 0; //0: none, 1: block, 2: bow, 3: eat, 4: drink
|
||||
|
||||
public boolean isNormalItem = false;
|
||||
public boolean isTool = false;
|
||||
public int digSpeed = 1;
|
||||
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 4: Fits in Head -> Boots slot respectively
|
||||
@@ -109,8 +110,8 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean bo) {
|
||||
this.enabled = bo;
|
||||
public void setEnabled(boolean enable) {
|
||||
this.enabled = enable;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
@@ -173,6 +174,16 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
return this.isTool;
|
||||
}
|
||||
|
||||
public void setIsNormalItem(boolean normalItem){
|
||||
this.isNormalItem = normalItem;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public boolean isNormalItem(){
|
||||
return this.isNormalItem;
|
||||
}
|
||||
|
||||
|
||||
public void setDigSpeed(int digSpeed){
|
||||
this.digSpeed = digSpeed;
|
||||
saveItemData();
|
||||
@@ -367,6 +378,7 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
compound.setFloat("TranslateZ",this.translateZ);
|
||||
|
||||
compound.setBoolean("IsTool", this.isTool);
|
||||
compound.setBoolean("IsNormalItem", this.isNormalItem);
|
||||
compound.setInteger("DigSpeed", this.digSpeed);
|
||||
compound.setInteger("ArmorType", this.armorType);
|
||||
compound.setInteger("Enchantability", this.enchantability);
|
||||
@@ -403,6 +415,7 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
this.translateZ = compound.getFloat("TranslateZ");
|
||||
|
||||
this.isTool = compound.getBoolean("IsTool");
|
||||
this.isNormalItem = compound.getBoolean("IsNormalItem");
|
||||
this.digSpeed = compound.getInteger("DigSpeed");
|
||||
this.armorType = compound.getInteger("ArmorType");
|
||||
this.enchantability = compound.getInteger("Enchantability");
|
||||
|
||||
@@ -6,18 +6,17 @@ 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.item.ItemSword;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTBase.NBTPrimitive;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.api.INbt;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.ScriptNbt;
|
||||
@@ -48,35 +47,35 @@ public class ScriptItemStack implements IItemStack {
|
||||
public String getName(){
|
||||
return Item.itemRegistry.getNameForObject(item.getItem());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the stacksize
|
||||
*/
|
||||
public int getStackSize(){
|
||||
return item.stackSize;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Return whether or not the item has a custom name
|
||||
*/
|
||||
public boolean hasCustomName(){
|
||||
return item.hasDisplayName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name The custom name this item will get
|
||||
*/
|
||||
public void setCustomName(String name){
|
||||
item.setStackDisplayName(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Return the ingame displayed name. This is either the item name or the custom name if it has one.
|
||||
*/
|
||||
public String getDisplayName(){
|
||||
return item.getDisplayName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Get the items ingame name. Use this incase the item ingame has custom name and you want the original name.
|
||||
*/
|
||||
@@ -99,21 +98,21 @@ public class ScriptItemStack implements IItemStack {
|
||||
size = 64;
|
||||
item.stackSize = size;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the item damage of this item. For tools this is the durability for other items the color and more.
|
||||
*/
|
||||
public int getItemDamage(){
|
||||
return item.getItemDamage();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param value The value to be set as item damage. For tools this is the durability for other items the color and more.
|
||||
*/
|
||||
public void setItemDamage(int value){
|
||||
item.setItemDamage(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key The key of this NBTTag
|
||||
* @param value The value to be stored. Can be a Number or String
|
||||
@@ -123,9 +122,9 @@ public class ScriptItemStack implements IItemStack {
|
||||
getTag().setDouble(key, ((Number) value).doubleValue());
|
||||
else if(value instanceof String)
|
||||
getTag().setString(key, (String) value);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key The key of the NBTTag
|
||||
* @return Returns whether or not the key exists
|
||||
@@ -135,7 +134,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
return false;
|
||||
return getTag().hasKey(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key The key of the NBTTag
|
||||
* @return Returns the value associated with the key. Returns null of it doesnt exist
|
||||
@@ -159,11 +158,11 @@ public class ScriptItemStack implements IItemStack {
|
||||
item.stackTagCompound = null;
|
||||
return nbt;
|
||||
}
|
||||
|
||||
|
||||
public boolean isEnchanted(){
|
||||
return item.isItemEnchanted();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.7.10d
|
||||
* @param id The enchantment id
|
||||
@@ -278,19 +277,18 @@ public class ScriptItemStack implements IItemStack {
|
||||
this.item.setTagCompound(compound = new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagList nbttaglist = compound.getTagList("display", 10);
|
||||
NBTTagList newList = new NBTTagList();
|
||||
String[] var4 = lore;
|
||||
int var5 = lore.length;
|
||||
NBTTagCompound display = compound.getCompoundTag("display");
|
||||
if(lore == null || lore.length == 0) {
|
||||
display.removeTag("Lore");
|
||||
return;
|
||||
}
|
||||
|
||||
for(int var6 = 0; var6 < var5; ++var6) {
|
||||
String s = var4[var6];
|
||||
newList.appendTag(new NBTTagString(s));
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setTag("Lore", newList);
|
||||
compound.setTag("display", nbttagcompound);
|
||||
NBTTagList nbtlist = new NBTTagList();
|
||||
for(String s : lore) {
|
||||
nbtlist.appendTag(new NBTTagString(s));
|
||||
}
|
||||
display.setTag("Lore", nbtlist);
|
||||
compound.setTag("display", display);
|
||||
}
|
||||
|
||||
public boolean hasAttribute(String name) {
|
||||
@@ -310,7 +308,34 @@ public class ScriptItemStack implements IItemStack {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static ScriptItemStack createNew(ItemStack item){
|
||||
if(item == null)
|
||||
return null;
|
||||
|
||||
if(item.getItem() instanceof ItemScripted) {
|
||||
return new ScriptCustomItem(item);
|
||||
}
|
||||
if(item.getItem() == Items.written_book || item.getItem() == Items.writable_book || item.getItem() instanceof ItemWritableBook || item.getItem() instanceof ItemEditableBook)
|
||||
return new ScriptItemBook(item);
|
||||
if(item.getItem() instanceof ItemArmor)
|
||||
return new ScriptItemArmor(item);
|
||||
if (item.getItem() instanceof ItemBlock)
|
||||
return new ScriptItemBlock(item);
|
||||
|
||||
return new ScriptItemStack(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack copy() {
|
||||
return createNew(item.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemDamage(){
|
||||
return item.getMaxDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10d
|
||||
* @return Returns whether this item is a book
|
||||
@@ -318,7 +343,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
public boolean isWrittenBook(){
|
||||
return item.getItem() == Items.written_book || item.getItem() == Items.writable_book;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.7.10d
|
||||
* @return Returns the books title
|
||||
@@ -334,28 +359,28 @@ public class ScriptItemStack implements IItemStack {
|
||||
public String getBookAuthor(){
|
||||
return item.getTagCompound().getString("author");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.7.10d
|
||||
* @return If the item is a book, returns a string array with book pages
|
||||
*/
|
||||
public String[] getBookText(){
|
||||
public String[] getBookText(){
|
||||
if(!isWrittenBook())
|
||||
return null;
|
||||
List<String> list = new ArrayList<String>();
|
||||
NBTTagList pages = item.getTagCompound().getTagList("pages", 8);
|
||||
for (int i = 0; i < pages.tagCount(); ++i){
|
||||
list.add(pages.getStringTagAt(i));
|
||||
}
|
||||
list.add(pages.getStringTagAt(i));
|
||||
}
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
|
||||
private NBTTagCompound getTag(){
|
||||
if(item.stackTagCompound == null)
|
||||
item.stackTagCompound = new NBTTagCompound();
|
||||
return item.stackTagCompound;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns whether or not this item is a block
|
||||
*/
|
||||
@@ -365,11 +390,11 @@ 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;
|
||||
@@ -413,4 +438,14 @@ public class ScriptItemStack implements IItemStack {
|
||||
public boolean equals(Object object) {
|
||||
return object instanceof ScriptItemStack && ((ScriptItemStack) object).getMCItemStack().equals(this.getMCItemStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compare(IItemStack item, boolean ignoreNBT) {
|
||||
return NoppesUtilPlayer.compareItems(getMCItemStack(), item.getMCItemStack(), false, ignoreNBT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compare(IItemStack item, boolean ignoreDamage, boolean ignoreNBT) {
|
||||
return NoppesUtilPlayer.compareItems(getMCItemStack(), item.getMCItemStack(), ignoreDamage, ignoreNBT);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user