Implemented Scripted Custom Items.

This commit is contained in:
Luis C.M committed 2022-05-11 01:10:31 -05:00
1 parent 5520fc5f2b
commit 26f5f86dca
34 files changed
+1476 -137

No files matched your search

@@ -20,6 +20,7 @@ import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.item.ScriptItemStack;
public abstract class NpcAPI {
private static NpcAPI instance = null;
@@ -86,7 +87,7 @@ public abstract class NpcAPI {
public abstract ScriptPlayer[] getAllServerPlayers();
public abstract ScriptItemStack createItem(String id, int damage, int size);
public abstract IItemStack createItem(String id, int damage, int size);
public abstract ScriptParticle createParticle(String directory);
@@ -15,6 +15,7 @@ import noppes.npcs.containers.ContainerCustomGui;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.interfaces.IContainer;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
public class ScriptContainer implements IContainer {
private IInventory inventory;
@@ -26,10 +26,15 @@ import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileBigSign;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.interfaces.IBlock;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.scripted.item.ScriptCustomItem;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
public class ScriptWorld implements IWorld {
private static Map<String,Object> tempData = new HashMap<String,Object>();
@@ -322,11 +327,8 @@ public class ScriptWorld implements IWorld {
* @param size The number of items in the item
* @return Returns the item
*/
public ScriptItemStack createItem(String id, int damage, int size){
Item item = (Item)Item.itemRegistry.getObject(id);
if(item == null)
return null;
return new ScriptItemStack(new ItemStack(item, size, damage));
public IItemStack createItem(String id, int damage, int size){
return WrapperNpcAPI.Instance().createItem(id,damage,size);
}
/**
@@ -5,11 +5,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptItemStack;
import java.util.ArrayList;
import java.util.Locale;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T>{
public T player;
@@ -430,7 +427,7 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T>{
return compound.getCompoundTag("JRMCEP").getString("extracode");
}
public ScriptItemStack[] getInventory(){
public IItemStack[] getInventory(){
NBTTagCompound compound = new NBTTagCompound();
this.player.writeToNBT(compound);
@@ -28,6 +28,7 @@ import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IEntity;
import noppes.npcs.scripted.interfaces.INbt;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.item.ScriptItemStack;
public class ScriptEntity<T extends Entity> implements IEntity {
protected T entity;
@@ -7,12 +7,13 @@ import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.MathHelper;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IEntityLivingBase;
import noppes.npcs.scripted.wrapper.ScriptDamageSource;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase {
protected T entity;
@@ -173,11 +174,8 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
* @since 1.7.10c
* @return The item the entity is holding
*/
public ScriptItemStack getHeldItem(){
ItemStack item = entity.getHeldItem();
if(item == null)
return null;
return new ScriptItemStack(item);
public IItemStack getHeldItem(){
return WrapperNpcAPI.Instance().getIItemStack(entity.getHeldItem());
}
/**
@@ -194,11 +192,8 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
* @param slot Slot of what armor piece to get, 0:boots, 1:pants, 2:body, 3:head
* @return The item in the given slot
*/
public ScriptItemStack getArmor(int slot){
ItemStack item = entity.getEquipmentInSlot(slot + 1);
if(item == null)
return null;
return new ScriptItemStack(item);
public IItemStack getArmor(int slot){
return WrapperNpcAPI.Instance().getIItemStack(entity.getEquipmentInSlot(slot + 1));
}
/**
@@ -8,7 +8,8 @@ import noppes.npcs.controllers.Line;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.ScriptFaction;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.constants.AnimationType;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.ICustomNpc;
@@ -28,6 +29,7 @@ import noppes.npcs.scripted.roles.ScriptRoleInterface;
import noppes.npcs.scripted.roles.ScriptRoleMailman;
import noppes.npcs.scripted.roles.ScriptRoleTrader;
import noppes.npcs.scripted.roles.ScriptRoleTransporter;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
import noppes.npcs.util.ValueUtil;
import java.util.ArrayList;
@@ -358,11 +360,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
/**
* @return The item held in the right hand
*/
public ScriptItemStack getRightItem(){
ItemStack item = npc.inventory.getWeapon();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
public IItemStack getRightItem(){
return WrapperNpcAPI.Instance().getIItemStack(npc.inventory.getWeapon());
}
/**
@@ -379,11 +378,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
/**
* @return The item held in the left hand
*/
public ScriptItemStack getLefttItem(){
ItemStack item = npc.getOffHand();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
public IItemStack getLefttItem(){
return WrapperNpcAPI.Instance().getIItemStack(npc.getOffHand());
}
/**
@@ -400,11 +396,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
/**
* @return Returns the projectile the npc uses
*/
public ScriptItemStack getProjectileItem(){
ItemStack item = npc.inventory.getProjectile();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
public IItemStack getProjectileItem(){
return WrapperNpcAPI.Instance().getIItemStack(npc.inventory.getProjectile());
}
/**
@@ -488,11 +481,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @return Returns the worn armor in slot
*/
@Override
public ScriptItemStack getArmor(int slot){
ItemStack item = npc.inventory.armor.get(slot);
if(item == null)
return null;
return new ScriptItemStack(item);
public IItemStack getArmor(int slot){
return WrapperNpcAPI.Instance().getIItemStack(npc.inventory.armor.get(slot));
}
/**
@@ -514,8 +504,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param slot The slot from the NPC's drop list to return (0-8)
* @return
*/
public ScriptItemStack getLootItem(int slot) {
return new ScriptItemStack(npc.inventory.getStackInSlot(slot+7));
public IItemStack getLootItem(int slot) {
return WrapperNpcAPI.Instance().getIItemStack(npc.inventory.getStackInSlot(slot+7));
}
/**
@@ -1,7 +1,6 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -20,11 +19,12 @@ import noppes.npcs.controllers.*;
import noppes.npcs.entity.EntityDialogNpc;
import noppes.npcs.scripted.*;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.event.FactionEvent;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.handler.data.IQuest;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.overlay.ScriptOverlay;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
import noppes.npcs.util.ValueUtil;
import java.util.ArrayList;
@@ -238,12 +238,12 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
* @since 1.7.10d
* @return Returns a IItemStack array size 36
*/
public ScriptItemStack[] getInventory(){
ScriptItemStack[] items = new ScriptItemStack[36];
public IItemStack[] getInventory(){
IItemStack[] items = new IItemStack[36];
for(int i = 0; i < player.inventory.mainInventory.length; i++){
ItemStack item = player.inventory.mainInventory[i];
if(item != null)
items[i] = new ScriptItemStack(item);
items[i] = WrapperNpcAPI.Instance().getIItemStack(item);
}
return items;
}
@@ -0,0 +1,89 @@
package noppes.npcs.scripted.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.interfaces.IEntity;
import noppes.npcs.scripted.interfaces.IPlayer;
import noppes.npcs.scripted.item.ScriptCustomItem;
public class ItemEvent extends CustomNPCsEvent {
public ScriptCustomItem item;
public ItemEvent(ScriptCustomItem item) {
this.item = item;
}
public static class InitEvent extends ItemEvent {
public InitEvent(ScriptCustomItem item) {
super(item);
}
}
public static class UpdateEvent extends ItemEvent {
public IPlayer player;
public UpdateEvent(ScriptCustomItem item, IPlayer player) {
super(item);
this.player = player;
}
}
@Cancelable
public static class TossedEvent extends ItemEvent {
public IEntity entity;
public IPlayer player;
public TossedEvent(ScriptCustomItem item, IPlayer player, IEntity entity) {
super(item);
this.entity = entity;
this.player = player;
}
}
public static class PickedUpEvent extends ItemEvent {
public IPlayer player;
public PickedUpEvent(ScriptCustomItem item, IPlayer player) {
super(item);
this.player = player;
}
}
@Cancelable
public static class SpawnEvent extends ItemEvent {
public IEntity entity;
public SpawnEvent(ScriptCustomItem item, IEntity entity){
super(item);
this.entity = entity;
}
}
@Cancelable
public static class InteractEvent extends ItemEvent {
public final int type;
public final Object target;
public IPlayer player;
public InteractEvent(ScriptCustomItem item, IPlayer player, int type, Object target) {
super(item);
this.type = type;
this.target = target;
this.player = player;
}
}
@Cancelable
public static class AttackEvent extends ItemEvent {
public final int type;//1: Hit, 2: Whiff //TODO: Implement type 2
public final Object target;
public IPlayer player;
public AttackEvent(ScriptCustomItem item, IPlayer player, int type, Object target) {
super(item);
this.type = type;
this.target = target;
this.player = player;
}
}
}
@@ -6,17 +6,16 @@
package noppes.npcs.scripted.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import noppes.npcs.scripted.*;
import noppes.npcs.scripted.entity.ScriptLivingBase;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.item.ScriptItemStack;
public class PlayerEvent extends CustomNPCsEvent {
public final IPlayer player;
@@ -5,10 +5,9 @@
package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.entity.ScriptPlayer;
public interface IContainer {
@@ -0,0 +1,25 @@
package noppes.npcs.scripted.interfaces;
public interface ICustomItem extends IItemStack {
String getTexture();
void setTexture(String var2);
void setMaxStackSize(int var1);
double getDurabilityValue();
void setDurabilityValue(float var1);
boolean getDurabilityShow();
void setDurabilityShow(boolean var1);
int getDurabilityColor();
void setDurabilityColor(int var1);
int getColor();
void setColor(int var1);
}
@@ -6,9 +6,8 @@
package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.EntityCreature;
import noppes.npcs.constants.EnumNavType;
import noppes.npcs.scripted.ScriptFaction;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.entity.ScriptLivingBase;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.roles.*;
@@ -196,7 +195,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
/**
* @return The item held in the right hand
*/
public ScriptItemStack getRightItem();
public IItemStack getRightItem();
/**
* @param item Item to be held in the right hand
@@ -206,7 +205,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
/**
* @return The item held in the left hand
*/
public ScriptItemStack getLefttItem();
public IItemStack getLefttItem();
/**
* @param item Item to be held in the left hand
@@ -216,7 +215,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
/**
* @return Returns the projectile the npc uses
*/
public ScriptItemStack getProjectileItem();
public IItemStack getProjectileItem();
/**
* @param item Item to be used as projectile
@@ -272,7 +271,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
* @param slot The armor slot to return. 0:head, 1:body, 2:legs, 3:boots
* @return Returns the worn armor in slot
*/
public ScriptItemStack getArmor(int slot);
public IItemStack getArmor(int slot);
/**
* @param slot The armor slot to set. 0:head, 1:body, 2:legs, 3:boots
@@ -285,7 +284,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
* @param slot The slot from the NPC's drop list to return (0-8)
* @return The item in the NPC's drop list slot
*/
public ScriptItemStack getLootItem(int slot);
public IItemStack getLootItem(int slot);
/**
*
@@ -7,7 +7,7 @@ package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.Entity;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
public interface IEntity<T extends Entity> {
public double getYOffset();
@@ -2,7 +2,7 @@ package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.entity.ScriptLivingBase;
public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T> {
@@ -82,7 +82,7 @@ public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T
* @since 1.7.10c
* @return The item the entity is holding
*/
public ScriptItemStack getHeldItem();
public IItemStack getHeldItem();
/**
* Note not all Living Entities support this
@@ -96,7 +96,7 @@ public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T
* @param slot Slot of what armor piece to get, 0:boots, 1:pants, 2:body, 3:head
* @return The item in the given slot
*/
public ScriptItemStack getArmor(int slot);
public IItemStack getArmor(int slot);
/**
* Note not all Living Entities support this
@@ -1,7 +1,7 @@
package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.ScriptPixelmonPlayerData;
public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T> {
@@ -90,7 +90,7 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
* @since 1.7.10d
* @return Returns a IItemStack array size 36
*/
public ScriptItemStack[] getInventory();
public IItemStack[] getInventory();
/**
* @param item The Item type to be removed
@@ -5,6 +5,7 @@ import net.minecraft.world.WorldServer;
import noppes.npcs.scripted.*;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.item.ScriptItemStack;
public interface IWorld {
/**
@@ -166,7 +167,7 @@ public interface IWorld {
* @param size The number of items in the item
* @return Returns the item
*/
public ScriptItemStack createItem(String id, int damage, int size);
public IItemStack createItem(String id, int damage, int size);
/**
* @param directory The particle's texture directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png"
@@ -0,0 +1,413 @@
package noppes.npcs.scripted.item;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.EventHooks;
import noppes.npcs.NBTTags;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.IScriptHandler;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.interfaces.ICustomItem;
import java.util.*;
public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IScriptHandler {
public List<ScriptContainer> scripts = new ArrayList();
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public long lastInited = -1L;
public boolean durabilityShow = false;
public double durabilityValue = 1.0D;
public int durabilityColor = -1;
public int itemColor = 0x8B4513;
public int stackSize = 64;
public int maxItemUseDuration = 20;
public boolean loaded = false;
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public int width = -1, height = -1;
public float translateX, translateY, translateZ;
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public float rotationX, rotationY, rotationZ;
public ScriptCustomItem(ItemStack item) {
super(item);
loadScriptData();
loadItemData();
}
public NBTTagCompound getScriptNBT(NBTTagCompound compound) {
compound.setTag("Scripts", NBTTags.NBTScript(this.scripts));
compound.setString("ScriptLanguage", this.scriptLanguage);
compound.setBoolean("ScriptEnabled", this.enabled);
return compound;
}
public void setScriptNBT(NBTTagCompound compound) {
if (compound.hasKey("Scripts")) {
this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this);
this.scriptLanguage = compound.getString("ScriptLanguage");
this.enabled = compound.getBoolean("ScriptEnabled");
}
}
public int getType() {
return 6;
}
public void callScript(EnumScriptType type, Event event) {
if (!this.loaded) {
this.loadScriptData();
this.loaded = true;
}
if (this.isEnabled()) {
if (ScriptController.Instance.lastLoaded > this.lastInited) {
this.lastInited = ScriptController.Instance.lastLoaded;
if (type != EnumScriptType.INIT) {
EventHooks.onScriptItemInit(this);
}
}
Iterator var3 = this.scripts.iterator();
while(var3.hasNext()) {
ScriptContainer script = (ScriptContainer)var3.next();
script.run(type, event);
}
}
}
private boolean isEnabled() {
return this.enabled && ScriptController.HasStart;
}
public boolean isClient() {
return false;
}
public boolean getEnabled() {
return this.enabled;
}
public void setEnabled(boolean bo) {
this.enabled = bo;
}
public String getLanguage() {
return this.scriptLanguage;
}
public void setLanguage(String lang) {
this.scriptLanguage = lang;
}
public List<ScriptContainer> getScripts() {
return this.scripts;
}
public String noticeString() {
return "ScriptedItem";
}
public Map<Long, String> getConsoleText() {
Map<Long, String> map = new TreeMap();
int tab = 0;
Iterator var3 = this.getScripts().iterator();
while(var3.hasNext()) {
ScriptContainer script = (ScriptContainer)var3.next();
++tab;
Iterator var5 = script.console.entrySet().iterator();
while(var5.hasNext()) {
Map.Entry<Long, String> entry = (Map.Entry)var5.next();
map.put(entry.getKey(), " tab " + tab + ":\n" + (String)entry.getValue());
}
}
return map;
}
public void clearConsole() {
Iterator var1 = this.getScripts().iterator();
while(var1.hasNext()) {
ScriptContainer script = (ScriptContainer)var1.next();
script.console.clear();
}
}
public String getTexture() {
return this.texture == null ? "" : this.texture;
}
public void setTexture(String texture){
if(texture == null)
texture = "";
this.texture = texture;
saveItemData();
}
public int getMaxStackSize() {
return this.stackSize;
}
public void setMaxStackSize(int size) {
if (size >= 1 && size <= 64) {
this.stackSize = size;
saveItemData();
} else {
throw new CustomNPCsException("Stacksize has to be between 1 and 64", new Object[0]);
}
}
public double getDurabilityValue() {
return this.durabilityValue;
}
public void setDurabilityValue(float value) {
this.durabilityValue = (double)value;
saveItemData();
}
public boolean getDurabilityShow() {
return this.durabilityShow;
}
public void setDurabilityShow(boolean bo) {
this.durabilityShow = bo;
saveItemData();
}
public int getDurabilityColor() {
return this.durabilityColor;
}
public void setDurabilityColor(int color) {
this.durabilityColor = color;
saveItemData();
}
public int getColor() {
return this.itemColor;
}
public void setColor(int color) {
this.itemColor = color;
saveItemData();
}
public int getMaxItemUseDuration(){
return this.maxItemUseDuration;
}
public void setMaxItemUseDuration(int duration){
this.maxItemUseDuration = duration;
saveItemData();
}
public void setRotation(float rotationX, float rotationY, float rotationZ){
this.rotationX = rotationX;
this.rotationY = rotationY;
this.rotationZ = rotationZ;
saveItemData();
}
public void setScale(float scaleX, float scaleY, float scaleZ){
this.scaleX = scaleX;
this.scaleY = scaleY;
this.scaleZ = scaleZ;
saveItemData();
}
public void setTranslate(float translateX, float translateY, float translateZ){
this.translateX = translateX;
this.translateY = translateY;
this.translateZ = translateZ;
saveItemData();
}
public void setRotationX(float rotationX) {
this.rotationX = rotationX;
saveItemData();
}
public void setRotationY(float rotationY) {
this.rotationY = rotationY;
saveItemData();
}
public void setRotationZ(float rotationZ) {
this.rotationZ = rotationZ;
saveItemData();
}
public void setScaleX(float scaleX) {
this.scaleX = scaleX;
saveItemData();
}
public void setScaleY(float scaleY) {
this.scaleY = scaleY;
saveItemData();
}
public void setScaleZ(float scaleZ) {
this.scaleZ = scaleZ;
saveItemData();
}
public void setTranslateX(float translateX) {
this.translateX = translateX;
saveItemData();
}
public void setTranslateY(float translateY) {
this.translateY = translateY;
saveItemData();
}
public void setTranslateZ(float translateZ) {
this.translateZ = translateZ;
saveItemData();
}
public float getRotationX() {
return rotationX;
}
public float getRotationY() {
return rotationY;
}
public float getRotationZ() {
return rotationZ;
}
public float getScaleX() {
return scaleX;
}
public float getScaleY() {
return scaleY;
}
public float getScaleZ() {
return scaleZ;
}
public float getTranslateX() {
return translateX;
}
public float getTranslateY() {
return translateY;
}
public float getTranslateZ() {
return translateZ;
}
public NBTTagCompound getMCNbt() {
NBTTagCompound compound = super.getMCNbt();
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
compound.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
return compound;
}
public void setMCNbt(NBTTagCompound compound) {
setScriptNBT(compound.getCompoundTag("ScriptedData"));
setItemNBT(compound.getCompoundTag("ItemData"));
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
compound.setBoolean("DurabilityShow",this.durabilityShow);
compound.setDouble("DurabilityValue",this.durabilityValue);
compound.setInteger("DurabilityColor",this.durabilityColor );
compound.setInteger("ItemColor",this.itemColor);
compound.setInteger("MaxStackSize",this.stackSize);
compound.setString("ItemTexture",this.texture);
compound.setFloat("RotationX",this.rotationX);
compound.setFloat("RotationY",this.rotationY);
compound.setFloat("RotationZ",this.rotationZ);
compound.setFloat("ScaleX",this.scaleX);
compound.setFloat("ScaleY",this.scaleY);
compound.setFloat("ScaleZ",this.scaleZ);
compound.setFloat("TranslateX",this.translateX);
compound.setFloat("TranslateY",this.translateY);
compound.setFloat("TranslateZ",this.translateZ);
compound.setInteger("Width", this.width);
compound.setInteger("Height", this.height);
return compound;
}
public void setItemNBT(NBTTagCompound compound) {
this.durabilityShow = compound.getBoolean("DurabilityShow");
this.durabilityValue = compound.getDouble("DurabilityValue");
if (compound.hasKey("DurabilityColor")) {
this.durabilityColor = compound.getInteger("DurabilityColor");
}
this.itemColor = compound.getInteger("ItemColor");
this.stackSize = compound.getInteger("MaxStackSize");
this.texture = compound.getString("ItemTexture");
this.rotationX = compound.getFloat("RotationX");
this.rotationY = compound.getFloat("RotationY");
this.rotationZ = compound.getFloat("RotationZ");
this.scaleX = compound.getFloat("ScaleX");
this.scaleY = compound.getFloat("ScaleY");
this.scaleZ = compound.getFloat("ScaleZ");
this.translateX = compound.getFloat("TranslateX");
this.translateY = compound.getFloat("TranslateY");
this.translateZ = compound.getFloat("TranslateZ");
this.width = compound.getInteger("Width");
this.height = compound.getInteger("Height");
}
public void saveScriptData() {
NBTTagCompound c = this.item.getTagCompound();
if (c == null) {
this.item.setTagCompound(c = new NBTTagCompound());
}
c.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
}
public void loadScriptData() {
NBTTagCompound c = this.item.getTagCompound();
if (c != null) {
this.setScriptNBT(c.getCompoundTag("ScriptedData"));
}
}
public void saveItemData() {
NBTTagCompound c = this.item.getTagCompound();
if (c == null) {
this.item.setTagCompound(c = new NBTTagCompound());
}
c.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
}
public void loadItemData() {
NBTTagCompound c = this.item.getTagCompound();
if (c != null){
this.setItemNBT(c.getCompoundTag("ItemData"));
}
}
}
@@ -1,4 +1,4 @@
package noppes.npcs.scripted;
package noppes.npcs.scripted.item;
import java.util.ArrayList;
import java.util.Iterator;
@@ -18,12 +18,16 @@ import net.minecraft.nbt.NBTBase.NBTPrimitive;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptNbt;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.interfaces.INbt;
public class ScriptItemStack implements IItemStack {
public ItemStack item;
private NBTTagCompound storedData = new NBTTagCompound();
public ScriptItemStack(ItemStack item){
this.item = item;
}
@@ -69,7 +73,12 @@ public class ScriptItemStack implements IItemStack {
public String getItemName(){
return item.getItem().getItemStackDisplayName(item);
}
public int getMaxStackSize() {
return this.item.getMaxStackSize();
}
/**
* @param size The size of the itemstack. A number between 1 and 64
*/
@@ -136,7 +145,7 @@ public class ScriptItemStack implements IItemStack {
}
public INbt removeTags() {
ScriptNbt nbt = (ScriptNbt)NpcAPI.Instance().getINbt(item.stackTagCompound);
ScriptNbt nbt = (ScriptNbt) NpcAPI.Instance().getINbt(item.stackTagCompound);
item.stackTagCompound = null;
return nbt;
}
@@ -362,6 +371,14 @@ public class ScriptItemStack implements IItemStack {
return NpcAPI.Instance().getINbt(compound);
}
public NBTTagCompound getMCNbt() {
NBTTagCompound compound = new NBTTagCompound();
this.item.writeToNBT(compound);
return compound;
}
public void setMCNbt(NBTTagCompound compound) {}
/**
* No support is given for this method. Dont use if you dont know what you are doing.
* @return Minecraft ItemStack
@@ -2,7 +2,7 @@ package noppes.npcs.scripted.roles;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleTrader;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.constants.RoleType;
import foxz.utils.Market;
@@ -32,6 +32,7 @@ import net.minecraft.world.WorldServer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.controllers.*;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.*;
import noppes.npcs.containers.ContainerNpcInterface;
import noppes.npcs.entity.EntityCustomNpc;
@@ -41,6 +42,8 @@ import noppes.npcs.scripted.entity.*;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.handler.*;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.item.ScriptCustomItem;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.overlay.ScriptOverlay;
import noppes.npcs.util.JsonException;
import noppes.npcs.util.LRUHashMap;
@@ -167,8 +170,11 @@ public class WrapperNpcAPI extends NpcAPI {
}
public IItemStack getIItemStack(ItemStack itemstack) {
return (IItemStack)(itemstack != null && itemstack.stackSize > 0 ? new ScriptItemStack(itemstack) : new ScriptItemStack(new ItemStack(Item.getItemById(0))));
if(itemstack.getItem() instanceof ItemScripted){
return (ICustomItem) (itemstack != null && itemstack.stackSize > 0 ? new ScriptCustomItem(itemstack) : new ScriptCustomItem(new ItemStack(Item.getItemById(0))));
} else {
return (IItemStack) (itemstack != null && itemstack.stackSize > 0 ? new ScriptItemStack(itemstack) : new ScriptItemStack(new ItemStack(Item.getItemById(0))));
}
}
public IWorld getIWorld(WorldServer world) {
@@ -258,11 +264,14 @@ public class WrapperNpcAPI extends NpcAPI {
return arr;
}
public ScriptItemStack createItem(String id, int damage, int size){
public IItemStack createItem(String id, int damage, int size){
Item item = (Item)Item.itemRegistry.getObject(id);
if(item == null)
return null;
return new ScriptItemStack(new ItemStack(item, size, damage));
if(item instanceof ItemScripted)
return new ScriptCustomItem(new ItemStack(item, size, damage));
else
return new ScriptItemStack(new ItemStack(item, size, damage));
}
public void playSoundAtEntity(ScriptEntity entity, String sound, float volume, float pitch){