mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 04:05:12 +00:00
Added implementations for ScriptItemArmor, ScriptItemBlock, and ScriptItemBook, which all extend ScriptItemStack.
This commit is contained in:
1 parent
cf33b90b26
commit
b20babbb35
5 files changed
+97
-23
No files matched your search
@@ -20,8 +20,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.DamageSource;
|
||||
@@ -48,8 +47,7 @@ import noppes.npcs.scripted.interfaces.item.IItemCustom;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
import noppes.npcs.scripted.interfaces.AbstractNpcAPI;
|
||||
import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
import noppes.npcs.scripted.item.ScriptItemStack;
|
||||
import noppes.npcs.scripted.item.*;
|
||||
import noppes.npcs.scripted.overlay.ScriptOverlay;
|
||||
import noppes.npcs.util.JsonException;
|
||||
import noppes.npcs.util.LRUHashMap;
|
||||
@@ -176,21 +174,35 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
}
|
||||
|
||||
public IItemStack getIItemStack(ItemStack itemstack) {
|
||||
if(itemstack.getItem() instanceof ItemScripted){
|
||||
return (IItemCustom) (itemstack.stackSize > 0 ? new ScriptCustomItem(itemstack) : new ScriptCustomItem(new ItemStack(Item.getItemById(0))));
|
||||
if (itemstack.getItem() instanceof ItemScripted) {
|
||||
return new ScriptCustomItem(itemstack);
|
||||
} else if(itemstack.getItem() instanceof ItemArmor) {
|
||||
return new ScriptItemArmor(itemstack);
|
||||
} else if(itemstack.getItem() instanceof ItemBook) {
|
||||
return new ScriptItemBook(itemstack);
|
||||
} else if(itemstack.getItem() instanceof ItemBlock) {
|
||||
return new ScriptItemBlock(itemstack);
|
||||
} else {
|
||||
return (IItemStack) (itemstack.stackSize > 0 ? new ScriptItemStack(itemstack) : new ScriptItemStack(new ItemStack(Item.getItemById(0))));
|
||||
return new ScriptItemStack(itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
public IItemStack createItem(String id, int damage, int size){
|
||||
Item item = (Item)Item.itemRegistry.getObject(id);
|
||||
if(item == null)
|
||||
public IItemStack createItem(String id, int damage, int size) {
|
||||
Item item = (Item) Item.itemRegistry.getObject(id);
|
||||
if (item == null)
|
||||
return null;
|
||||
if(item instanceof ItemScripted)
|
||||
|
||||
if (item instanceof ItemScripted) {
|
||||
return new ScriptCustomItem(new ItemStack(item, size, damage));
|
||||
else
|
||||
} else if(item instanceof ItemArmor) {
|
||||
return new ScriptItemArmor(new ItemStack(item, size, damage));
|
||||
} else if(item instanceof ItemBook) {
|
||||
return new ScriptItemBook(new ItemStack(item, size, damage));
|
||||
} else if(item instanceof ItemBlock) {
|
||||
return new ScriptItemBlock(new ItemStack(item, size, damage));
|
||||
} else {
|
||||
return new ScriptItemStack(new ItemStack(item, size, damage));
|
||||
}
|
||||
}
|
||||
|
||||
public IWorld getIWorld(WorldServer world) {
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
package noppes.npcs.scripted.item;
|
||||
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemArmor;
|
||||
|
||||
public class ScriptItemArmor extends ScriptItemStack implements IItemArmor {
|
||||
protected ItemArmor armor;
|
||||
|
||||
public ScriptItemArmor(ItemStack item) {
|
||||
super(item);
|
||||
this.armor = (ItemArmor) item.getItem();
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int getArmorSlot() {
|
||||
return 0;
|
||||
return armor.armorType;
|
||||
}
|
||||
|
||||
public String getArmorMaterial() {
|
||||
return null;
|
||||
return armor.getArmorMaterial().toString();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,23 @@
|
||||
package noppes.npcs.scripted.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemBlock;
|
||||
|
||||
public class ScriptItemBlock extends ScriptItemStack implements IItemBlock {
|
||||
protected String blockName;
|
||||
|
||||
public ScriptItemBlock(ItemStack item) {
|
||||
super(item);
|
||||
Block b = Block.getBlockFromItem(item.getItem());
|
||||
this.blockName = Block.blockRegistry.getNameForObject(b);
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public String getBlockName() {
|
||||
return null;
|
||||
return blockName;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
package noppes.npcs.scripted.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemBook;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptItemBook extends ScriptItemStack implements IItemBook {
|
||||
|
||||
public ScriptItemBook(ItemStack item) {
|
||||
@@ -10,26 +16,57 @@ public class ScriptItemBook extends ScriptItemStack implements IItemBook {
|
||||
}
|
||||
|
||||
public String[] getText() {
|
||||
return new String[0];
|
||||
List<String> list = new ArrayList<String>();
|
||||
NBTTagList pages = this.getTag().getTagList("pages", 8);
|
||||
|
||||
for(int i = 0; i < pages.tagCount(); ++i) {
|
||||
list.add(pages.getStringTagAt(i));
|
||||
}
|
||||
|
||||
return (String[])list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
public void setText(String[] var1) {
|
||||
public void setText(String[] pages) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
if (pages != null && pages.length > 0) {
|
||||
String[] var3 = pages;
|
||||
int var4 = pages.length;
|
||||
|
||||
for(int var5 = 0; var5 < var4; ++var5) {
|
||||
String page = var3[var5];
|
||||
list.appendTag(new NBTTagString(page));
|
||||
}
|
||||
}
|
||||
|
||||
this.getTag().setTag("pages", list);
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return null;
|
||||
return this.getTag().getString("author");
|
||||
}
|
||||
|
||||
public void setAuthor(String var1) {
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.getTag().setString("author",author);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return null;
|
||||
return this.getTag().getString("title");
|
||||
}
|
||||
|
||||
public void setTitle(String var1) {
|
||||
public void setTitle(String title) {
|
||||
this.getTag().setString("title",title);
|
||||
}
|
||||
|
||||
private NBTTagCompound getTag() {
|
||||
NBTTagCompound comp = this.item.getTagCompound();
|
||||
if (comp == null) {
|
||||
this.item.setTagCompound(comp = new NBTTagCompound());
|
||||
}
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,13 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
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.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.ScriptNbt;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
@@ -30,7 +32,15 @@ public class ScriptItemStack implements IItemStack {
|
||||
public ScriptItemStack(ItemStack item){
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
public int getType() {
|
||||
if (this.item.getItem() instanceof IPlantable) {
|
||||
return 5;
|
||||
} else {
|
||||
return this.item.getItem() instanceof ItemSword ? 4 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The minecraft name for this item
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user