Merge branch 'dev' into dev

This commit is contained in:
Kam authored and GitHub committed 2025-03-06 02:19:17 -05:00
commit 43c940f7ed
799 files changed
+49724 -13791

No files matched your search

+11 -3
View File
@@ -2,6 +2,7 @@ package noppes.npcs.scripted;
import cpw.mods.fml.common.eventhandler.EventBus;
import foxz.command.ScriptedCommand;
import kamkeel.npcs.controllers.ProfileController;
import net.minecraft.block.Block;
import net.minecraft.command.CommandHandler;
import net.minecraft.entity.Entity;
@@ -55,6 +56,7 @@ import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.entity.EntityProjectile;
import noppes.npcs.items.ItemLinked;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.entity.*;
import noppes.npcs.scripted.gui.ScriptGui;
@@ -64,7 +66,6 @@ import noppes.npcs.util.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ExecutorService;
@@ -241,6 +242,12 @@ public class NpcAPI extends AbstractNpcAPI {
public INaturalSpawnsHandler getNaturalSpawns() { return SpawnController.Instance; }
public IProfileHandler getProfileHandler() { return ProfileController.Instance; }
public ICustomEffectHandler getCustomEffectHandler() { return CustomEffectController.Instance; }
public IPartyHandler getPartyHandler() { return PartyController.Instance(); }
public ITransportHandler getLocations() {
return TransportController.getInstance();
}
@@ -473,7 +480,9 @@ public class NpcAPI extends AbstractNpcAPI {
if (scriptItemCache.containsKey(itemstack)) {
scriptStack = scriptItemCache.get(itemstack).getObject();
} else {
if (itemstack.getItem() instanceof ItemScripted) {
if (itemstack.getItem() instanceof ItemLinked) {
scriptStack = new ScriptLinkedItem(itemstack);
} else if (itemstack.getItem() instanceof ItemScripted) {
scriptStack = new ScriptCustomItem(itemstack);
} else if (itemstack.getItem() instanceof ItemArmor) {
scriptStack = new ScriptItemArmor(itemstack);
@@ -486,7 +495,6 @@ public class NpcAPI extends AbstractNpcAPI {
}
scriptItemCache.put(itemstack, new CacheHashMap.CachedObject<>(scriptStack));
}
return scriptStack;
}
}
@@ -146,8 +146,20 @@ public class ScriptParticle implements IParticle {
}
public void spawn(IWorld world, double x, double y, double z){
double prevX = this.x;
double prevY = this.y;
double prevZ = this.z;
this.x = x;
this.y = y;
this.z = z;
NBTTagCompound compound = this.writeToNBT();
NoppesUtilServer.spawnScriptedParticle(compound, world.getDimensionID());
this.x = prevX;
this.y = prevY;
this.z = prevZ;
}
public void spawnOnEntity(IEntity entity) {
@@ -7,15 +7,11 @@ import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTBase.NBTPrimitive;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySign;
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;
@@ -30,7 +26,6 @@ import noppes.npcs.api.handler.data.ISound;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.api.scoreboard.IScoreboard;
import noppes.npcs.blocks.tiles.TileBigSign;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.scoreboard.ScriptScoreboard;
@@ -0,0 +1,189 @@
package noppes.npcs.scripted;
import noppes.npcs.api.handler.IActionManager;
import noppes.npcs.api.handler.data.IAction;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.function.Consumer;
public class ScriptedActionManager implements IActionManager {
private boolean isWorking;
private Queue<IAction> actionQueue = new LinkedList<>();
@Override
public IAction createAction(String name, int maxDuration, int startAfterTicks, Consumer<IAction> action) {
return new CustomAction(name, maxDuration, startAfterTicks, action);
}
@Override
public void start() {
isWorking = true;
}
@Override
public void stop() {
isWorking = false;
}
@Override
public void addScheduledAction(IAction action) {
actionQueue.add(action);
}
@Override
public void addScheduledAction(String name, int maxDuration, int startAfterTicks, Consumer<IAction> action) {
addScheduledAction(createAction(name, maxDuration, startAfterTicks, action));
}
@Override
public void addScheduledActionAt(int index, IAction action) {
((LinkedList) actionQueue).add(index, action);
}
@Override
public void scheduleActionAfter(IAction after, IAction toSchedule) {
int index = getActionIndex(after);
if (index != -1)
addScheduledActionAt(index + 1, toSchedule);
}
@Override
public int getActionIndex(IAction action) {
if (action == null)
return -1;
return ((LinkedList) actionQueue).indexOf(action);
}
@Override
public IAction getCurrentAction() {
return actionQueue.peek();
}
@Override
public Queue<IAction> getActionQueue() {
return actionQueue;
}
public void clear(){
actionQueue.clear();
}
public void tick(int ticksExisted) {
if (isWorking) {
CustomAction current = (CustomAction) getCurrentAction();
if (current != null) {
current.tick(ticksExisted);
if (current.isDone || current.duration >= current.maxDuration) {
current.destroy();
actionQueue.poll();
}
}
}
}
//Nested not static to access outer class instance
public class CustomAction implements IAction {
Consumer<IAction> action;
private HashMap<String, Object> data = new HashMap<>();
private String name;
private int startAfterTicks; //number of ticks to start action after
private int count; //number of times action ran
private int duration, maxDuration; //duration since action began
private int updateEveryXTick = 5;
private boolean isDone;
public CustomAction(String name, int maxDuration, int startAfterTicks, Consumer<IAction> task) {
this.name = name;
this.maxDuration = maxDuration;
this.startAfterTicks = startAfterTicks;
this.action = task;
}
private void tick(int ticksExisted) {
if (startAfterTicks <= 0) {
if (ticksExisted % updateEveryXTick == 0) {
action.accept(this);
count++;
}
duration++;
} else
startAfterTicks--;
}
private void destroy() {
data.clear();
}
@Override
public int getCount() {
return count;
}
@Override
public int getDuration() {
return duration;
}
@Override
public String getName() {
return name;
}
@Override
public int getMaxDuration() {
return maxDuration;
}
@Override
public void setDone(boolean done) {
isDone = done;
}
@Override
public boolean isDone() {
return isDone;
}
@Override
public Object getData(String key) {
return data.get(key);
}
@Override
public void addData(String key, Object value) {
data.put(key, value);
}
@Override
public int getUpdateEveryXTick() {
return updateEveryXTick;
}
@Override
public void setUpdateEveryXTick(int X) {
this.updateEveryXTick = X;
}
@Override
public int getStartAfterTicks() {
return startAfterTicks;
}
@Override
public IAction create(String name, int maxDuration, int startAfterTicks, Consumer<IAction> action) {
return createAction(name, maxDuration, startAfterTicks, action);
}
@Override
public void scheduleAfter(IAction action) {
scheduleActionAfter(this, action);
}
}
}
@@ -149,4 +149,16 @@ public class ScriptLiving<T extends EntityLiving> extends ScriptLivingBase<T> im
public boolean canBeSteered() {
return this.entity.canBeSteered();
}
@Override
public void setRotation(float rotation){
super.setRotation(rotation);
entity.getLookHelper().setLookPosition(getX(), getY(), getZ(), rotation, getPitch());
}
@Override
public void setPitch(float rotation){
super.setPitch(rotation);
entity.getLookHelper().setLookPosition(getX(), getY(), getZ(), getRotation(), rotation);
}
}
@@ -225,6 +225,16 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
return getMCEntity();
}
@Override
public float getRotation(){
return entity.renderYawOffset;
}
@Override
public void setRotation(float rotation){
entity.renderYawOffset = rotation;
}
/**
* Makes the entity swing its hand
*/
@@ -9,11 +9,9 @@ import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.entity.data.IModelData;
import noppes.npcs.api.handler.IActionManager;
import noppes.npcs.api.handler.IOverlayHandler;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.api.handler.data.IDialog;
import noppes.npcs.api.handler.data.IFaction;
import noppes.npcs.api.handler.data.ILines;
import noppes.npcs.api.handler.data.*;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.api.jobs.IJob;
import noppes.npcs.api.roles.IRole;
@@ -93,21 +91,28 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
}
public void setRotation(float rotation){
npc.ai.orientation = (int)rotation;
super.setRotation(rotation);
super.setRotation(rotation);
int r = (int) rotation;
if(npc.ais.orientation != r) {
npc.updateClient = true;
npc.rotationYawHead = npc.rotationYaw = npc.renderYawOffset = npc.ais.orientation = r;
npc.prevRenderYawOffset = r;
npc.prevRotationYaw = r;
npc.prevRotationYawHead = r;
}
}
public void setRotationType(int rotationType){
for (EnumStandingType e : EnumStandingType.values()) {
if (e.ordinal() == rotationType) {
npc.ai.standingType = e;
npc.ais.standingType = e;
break;
}
}
}
public int getRotationType(){
return npc.ai.standingType.ordinal();
return npc.ais.standingType.ordinal();
}
/**
@@ -116,7 +121,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
public void setMovingType(int movingType){
for(EnumMovingType e : EnumMovingType.values()) {
if (e.ordinal() == movingType) {
npc.ai.movingType = e;
npc.ais.movingType = e;
break;
}
}
@@ -126,7 +131,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @return The moving type of the npc. 0 = standing, 1 = wandering, 2 = moving path
*/
public int getMovingType(){
return npc.ai.movingType.ordinal();
return npc.ais.movingType.ordinal();
}
/**
@@ -170,7 +175,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
}
public IPos getHome() {
return NpcAPI.Instance().getIPos(npc.ai.startPos[0],npc.ai.startPos[1],npc.ai.startPos[2]);
return NpcAPI.Instance().getIPos(npc.ais.startPos[0],npc.ais.startPos[1],npc.ais.startPos[2]);
}
/**
@@ -184,7 +189,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param x The home x position
*/
public void setHomeX(int x){
npc.ai.startPos[0] = x;
npc.ais.startPos[0] = x;
}
/**
@@ -198,7 +203,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param y The home y position
*/
public void setHomeY(int y){
npc.ai.startPos[1] = y;
npc.ais.startPos[1] = y;
}
/**
@@ -212,7 +217,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param z The home x position
*/
public void setHomeZ(int z){
npc.ai.startPos[2] = z;
npc.ais.startPos[2] = z;
}
/**
@@ -221,11 +226,11 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param z The home z position
*/
public void setHome(int x, int y, int z){
npc.ai.startPos = new int[]{x, y, z};
npc.ais.startPos = new int[]{x, y, z};
}
public void setHome(IPos pos){
npc.ai.startPos = new int[]{pos.getX(), pos.getY(), pos.getZ()};
npc.ais.startPos = new int[]{pos.getX(), pos.getY(), pos.getZ()};
}
/**
@@ -240,14 +245,14 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param bo Whether or not the npc will try to return to his home position
*/
public void setReturnToHome(boolean bo){
npc.ai.returnToStart = bo;
npc.ais.returnToStart = bo;
}
/**
* @return Whether or not the npc returns home
*/
public boolean getReturnToHome(){
return npc.ai.returnToStart;
return npc.ais.returnToStart;
}
/**
@@ -697,29 +702,29 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
*/
public void setAnimation(int type){
if(type == AnimationType.NORMAL)
npc.ai.animationType = EnumAnimation.NONE;
npc.ais.animationType = EnumAnimation.NONE;
else if(type == AnimationType.SITTING)
npc.ai.animationType = EnumAnimation.SITTING;
npc.ais.animationType = EnumAnimation.SITTING;
else if(type == AnimationType.DANCING)
npc.ai.animationType = EnumAnimation.DANCING;
npc.ais.animationType = EnumAnimation.DANCING;
else if(type == AnimationType.SNEAKING)
npc.ai.animationType = EnumAnimation.SNEAKING;
npc.ais.animationType = EnumAnimation.SNEAKING;
else if(type == AnimationType.LYING)
npc.ai.animationType = EnumAnimation.LYING;
npc.ais.animationType = EnumAnimation.LYING;
else if(type == AnimationType.HUGGING)
npc.ai.animationType = EnumAnimation.HUG;
npc.ais.animationType = EnumAnimation.HUG;
}
public void setTacticalVariant(int variant){
if(variant > EnumNavType.values().length-1 || variant < 0)
return;
npc.ai.tacticalVariant = EnumNavType.values()[variant];
npc.ai.directLOS = EnumNavType.values()[variant] != EnumNavType.Stalk && npc.ai.directLOS;
npc.ais.tacticalVariant = EnumNavType.values()[variant];
npc.ais.directLOS = EnumNavType.values()[variant] != EnumNavType.Stalk && npc.ais.directLOS;
}
public int getTacticalVariant(){
return npc.ai.tacticalVariant.ordinal();
return npc.ais.tacticalVariant.ordinal();
}
public void setTacticalVariant(String variant){
@@ -732,22 +737,22 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
if(!found)
return;
npc.ai.tacticalVariant = EnumNavType.valueOf(variant);
npc.ais.tacticalVariant = EnumNavType.valueOf(variant);
}
public String getTacticalVariantName(){
return npc.ai.tacticalVariant.name();
return npc.ais.tacticalVariant.name();
}
public void setCombatPolicy(int variant){
if(variant > EnumCombatPolicy.values().length-1 || variant < 0)
return;
npc.ai.combatPolicy = EnumCombatPolicy.values()[variant];
npc.ais.combatPolicy = EnumCombatPolicy.values()[variant];
}
public int getCombatPolicy(){
return npc.ai.combatPolicy.ordinal();
return npc.ais.combatPolicy.ordinal();
}
public void setCombatPolicy(String variant){
@@ -760,22 +765,22 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
if(!found)
return;
npc.ai.combatPolicy = EnumCombatPolicy.valueOf(variant);
npc.ais.combatPolicy = EnumCombatPolicy.valueOf(variant);
}
public String getCombatPolicyName(){
return npc.ai.combatPolicy.name();
return npc.ais.combatPolicy.name();
}
public void setTacticalRadius(int tacticalRadius){
if(tacticalRadius < 0)
tacticalRadius = 0;
npc.ai.tacticalRadius = tacticalRadius;
npc.ais.tacticalRadius = tacticalRadius;
}
public int getTacticalRadius(){
return npc.ai.tacticalRadius;
return npc.ais.tacticalRadius;
}
public void setIgnoreCobweb(boolean ignore){
@@ -789,21 +794,21 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
public void setOnFoundEnemy(int onAttack){
if(onAttack < 0 || onAttack > 3)
return;
npc.ai.onAttack = onAttack;
npc.ais.onAttack = onAttack;
}
public int onFoundEnemy(){
return npc.ai.onAttack;
return npc.ais.onAttack;
}
public void setShelterFrom(int shelterFrom){
if(shelterFrom < 0 || shelterFrom > 2)
return;
npc.ai.findShelter = shelterFrom;
npc.ais.findShelter = shelterFrom;
}
public int getShelterFrom(){
return npc.ai.findShelter;
return npc.ais.findShelter;
}
public boolean hasLivingAnimation() {
@@ -1188,7 +1193,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
if (type > 3)
type = 3;
npc.ai.onAttack = type;
npc.ais.onAttack = type;
npc.updateTasks();
}
@@ -1254,22 +1259,22 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
fly = 1;
else fly = 0;
npc.ai.movementType = fly;
npc.ais.movementType = fly;
}
public boolean canFly(){
return npc.ai.movementType == 1;
return npc.ais.movementType == 1;
}
public void setFlySpeed(double flySpeed){
if(flySpeed < 0.0D)
flySpeed = 0.0D;
npc.ai.flySpeed = flySpeed;
npc.ais.flySpeed = flySpeed;
}
public double getFlySpeed(double flySpeed){
return npc.ai.flySpeed;
return npc.ais.flySpeed;
}
public void setFlyGravity(double flyGravity){
@@ -1278,36 +1283,36 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
if(flyGravity > 1.0D)
flyGravity = 1.0D;
npc.ai.flyGravity = flyGravity;
npc.ais.flyGravity = flyGravity;
}
public double getFlyGravity(double flySpeed){
return npc.ai.flyGravity;
return npc.ais.flyGravity;
}
public void setFlyHeightLimit(int flyHeightLimit){
if(flyHeightLimit < 0)
flyHeightLimit = 0;
this.npc.ai.flyHeightLimit = flyHeightLimit;
this.npc.ais.flyHeightLimit = flyHeightLimit;
}
public int getFlyHeightLimit(int flyHeightLimit){
return this.npc.ai.flyHeightLimit;
return this.npc.ais.flyHeightLimit;
}
public void limitFlyHeight(boolean limit){
this.npc.ai.hasFlyLimit = limit;
this.npc.ais.hasFlyLimit = limit;
}
public boolean isFlyHeightLimited(boolean limit){
return this.npc.ai.hasFlyLimit;
return this.npc.ais.hasFlyLimit;
}
public void setSpeed(double speed) {
npc.ai.setWalkingSpeed(speed);
npc.ais.setWalkingSpeed(speed);
}
public double getSpeed() {
return npc.ai.getWalkingSpeed();
return npc.ais.getWalkingSpeed();
}
public void setSkinType(byte type) {
@@ -1372,4 +1377,12 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
public void updateClient() { this.npc.updateClient(); }
public void updateAI() { this.npc.updateTasks(); }
public IActionManager getActionManager() {
return npc.actionManager;
}
public IMagicData getMagicData() {
return npc.stats.magicData;
}
}
@@ -1,5 +1,10 @@
package noppes.npcs.scripted.entity;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.AchievementPacket;
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
import kamkeel.npcs.network.packets.data.gui.GuiClosePacket;
import kamkeel.npcs.network.packets.data.script.ScriptOverlayClosePacket;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
@@ -13,22 +18,20 @@ import net.minecraft.util.ChatStyle;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.WorldSettings;
import noppes.npcs.*;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.*;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.handler.IOverlayHandler;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.api.handler.data.IDialog;
import noppes.npcs.api.handler.data.IQuest;
import noppes.npcs.api.handler.data.ISound;
import noppes.npcs.api.handler.data.*;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.api.overlay.ICustomOverlay;
import noppes.npcs.compat.PixelmonHelper;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumQuestRepeat;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.containers.ContainerCustomGui;
import noppes.npcs.controllers.*;
@@ -45,7 +48,6 @@ import noppes.npcs.util.ValueUtil;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T> implements IPlayer {
public T player;
@@ -263,8 +265,9 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
return;
QuestData questdata = new QuestData(quest);
data.questData.activeQuests.put(id, questdata);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
AchievementPacket.sendAchievement((EntityPlayerMP) player, false, "quest.newquest", quest.title);
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "quest.newquest", ": ", quest.title);
data.updateClient = true;
}
@@ -277,10 +280,7 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
if (quest == null)
return;
PlayerData data = PlayerData.get(player);
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY)
data.questData.finishedQuests.put(quest.id, System.currentTimeMillis());
else
data.questData.finishedQuests.put(quest.id, player.worldObj.getTotalWorldTime());
PlayerQuestController.setQuestFinishedUtil(player, quest, data.questData);
data.updateClient = true;
}
@@ -756,7 +756,7 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
public void closeGui() {
((EntityPlayerMP)this.entity).closeContainer();
Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.GUI_CLOSE, -1, new NBTTagCompound());
GuiClosePacket.closeGUI(player, -1 , new NBTTagCompound());
}
public void showCustomOverlay(ICustomOverlay overlay) {
@@ -764,8 +764,8 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
}
public void closeOverlay(int id) {
Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.SCRIPT_OVERLAY_CLOSE, id, new NBTTagCompound());
}
PacketHandler.Instance.sendToPlayer(new ScriptOverlayClosePacket(id), (EntityPlayerMP)this.entity);
}
public IOverlayHandler getOverlays() {
return this.getData().skinOverlays;
@@ -798,4 +798,8 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
public boolean conqueredEnd() {
return this.player.playerConqueredTheEnd;
}
public IMagicData getMagicData() {
return this.getData().magicData;
}
}
@@ -0,0 +1,108 @@
package noppes.npcs.scripted.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import noppes.npcs.api.entity.IAnimatable;
import noppes.npcs.api.event.IAnimationEvent;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.api.handler.data.IFrame;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Frame;
public abstract class AnimationEvent extends CustomNPCsEvent implements IAnimationEvent {
protected final IAnimation animation;
protected final IAnimationData animationData;
protected final IAnimatable entity;
public AnimationEvent(IAnimation animation) {
this.animation = animation;
this.animationData = animation.getParent();
this.entity = this.animationData.getEntity();
}
@Override
public IAnimation getAnimation() {
return this.animation;
}
@Override
public IAnimationData getAnimationData() {
return this.animationData;
}
@Override
public IAnimatable getEntity() {
return this.entity;
}
@Cancelable
public static class Started extends AnimationEvent {
public Started(IAnimation animation) {
super(animation);
}
@Override
public String getHookName() {
return EnumScriptType.ANIMATION_START.function;
}
}
public static class Ended extends AnimationEvent {
public Ended(IAnimation animation) {
super(animation);
}
@Override
public String getHookName() {
return EnumScriptType.ANIMATION_END.function;
}
}
public static abstract class FrameEvent extends AnimationEvent implements IFrameEvent {
private final IFrame frame;
private final int index;
public FrameEvent(IAnimation animation, IFrame frame) {
super(animation);
this.frame = frame;
this.index = ((Animation)this.getAnimation()).frames.indexOf((Frame) this.frame);
}
@Override
public int getIndex() {
return this.index;
}
@Override
public IFrame getFrame() {
return this.frame;
}
public static class Entered extends FrameEvent {
public Entered(IAnimation animation, IFrame frame) {
super(animation, frame);
}
@Override
public String getHookName() {
return EnumScriptType.ANIMATION_FRAME_ENTER.function;
}
}
public static class Exited extends FrameEvent {
public Exited(IAnimation animation, IFrame frame) {
super(animation, frame);
}
@Override
public String getHookName() {
return EnumScriptType.ANIMATION_FRAME_EXIT.function;
}
}
}
}
@@ -4,17 +4,18 @@ import cpw.mods.fml.common.eventhandler.Cancelable;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.event.IItemEvent;
import noppes.npcs.api.item.IItemCustom;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.constants.EnumScriptType;
public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IItemCustom item;
public final IItemCustomizable item;
public ItemEvent(IItemCustom item) {
public ItemEvent(IItemCustomizable item) {
this.item = item;
}
public IItemCustom getItem() {
public IItemCustomizable getItem() {
return item;
}
@@ -23,7 +24,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
}
public static class InitEvent extends ItemEvent implements IItemEvent.InitEvent {
public InitEvent(IItemCustom item) {
public InitEvent(IItemCustomizable item) {
super(item);
}
@@ -35,7 +36,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public static class UpdateEvent extends ItemEvent implements IItemEvent.UpdateEvent {
public final IEntity entity;
public UpdateEvent(IItemCustom item, IEntity entity) {
public UpdateEvent(IItemCustomizable item, IEntity entity) {
super(item);
this.entity = entity;
}
@@ -54,7 +55,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IEntity entity;
public final IPlayer player;
public TossedEvent(IItemCustom item, IPlayer player, IEntity entity) {
public TossedEvent(IItemCustomizable item, IPlayer player, IEntity entity) {
super(item);
this.entity = entity;
this.player = player;
@@ -76,7 +77,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public static class PickedUpEvent extends ItemEvent implements IItemEvent.PickedUpEvent {
public final IPlayer player;
public PickedUpEvent(IItemCustom item, IPlayer player) {
public PickedUpEvent(IItemCustomizable item, IPlayer player) {
super(item);
this.player = player;
}
@@ -94,7 +95,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public static class SpawnEvent extends ItemEvent implements IItemEvent.SpawnEvent {
public final IEntity entity;
public SpawnEvent(IItemCustom item, IEntity entity){
public SpawnEvent(IItemCustomizable item, IEntity entity){
super(item);
this.entity = entity;
}
@@ -114,7 +115,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IEntity target;
public final IPlayer player;
public InteractEvent(IItemCustom item, IPlayer player, int type, IEntity target) {
public InteractEvent(IItemCustomizable item, IPlayer player, int type, IEntity target) {
super(item);
this.type = type;
this.target = target;
@@ -148,7 +149,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final Object target;
public final IPlayer player;
public RightClickEvent(IItemCustom item, IPlayer player, int type, Object target) {
public RightClickEvent(IItemCustomizable item, IPlayer player, int type, Object target) {
super(item);
this.type = type;
this.target = target;
@@ -178,7 +179,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IEntity target;
public final IEntity swingingEntity;
public AttackEvent(IItemCustom item, IEntity swingingEntity, int type, IEntity target) {
public AttackEvent(IItemCustomizable item, IEntity swingingEntity, int type, IEntity target) {
super(item);
this.type = type;
this.target = target;
@@ -207,7 +208,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IPlayer player;
public final int duration;
public StartUsingItem(IItemCustom item, IPlayer player, int duration){
public StartUsingItem(IItemCustomizable item, IPlayer player, int duration){
super(item);
this.player = player;
this.duration = duration;
@@ -231,7 +232,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IPlayer player;
public final int duration;
public UsingItem(IItemCustom item, IPlayer player, int duration){
public UsingItem(IItemCustomizable item, IPlayer player, int duration){
super(item);
this.player = player;
this.duration = duration;
@@ -255,7 +256,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IPlayer player;
public final int duration;
public StopUsingItem(IItemCustom item, IPlayer player, int duration){
public StopUsingItem(IItemCustomizable item, IPlayer player, int duration){
super(item);
this.player = player;
this.duration = duration;
@@ -279,7 +280,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
public final IPlayer player;
public final int duration;
public FinishUsingItem(IItemCustom item, IPlayer player, int duration){
public FinishUsingItem(IItemCustomizable item, IPlayer player, int duration){
super(item);
this.player = player;
this.duration = duration;
@@ -297,4 +298,69 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
return duration;
}
}
public static class BreakItem extends ItemEvent implements IItemEvent.BreakItem {
public final IPlayer player;
public BreakItem(IItemCustomizable item, IPlayer player) {
super(item);
this.player = player;
}
public String getHookName() {
return EnumScriptType.BREAK_ITEM.function;
}
@Override
public IItemStack getBrokenStack() {
return this.item;
}
@Override
public IPlayer getPlayer() {
return this.player;
}
}
public static class RepairItem extends ItemEvent implements IItemEvent.RepairItem {
public final IPlayer player;
public final IItemStack left, right;
public final float anvilBreakChance;
public RepairItem(IItemCustomizable item, IPlayer player, IItemStack left, IItemStack right, float anvilBreakChance) {
super(item);
this.player = player;
this.left = left;
this.right = right;
this.anvilBreakChance = anvilBreakChance;
}
public String getHookName() {
return EnumScriptType.REPAIR_ITEM.function;
}
public IPlayer getPlayer() {
return this.player;
}
@Override
public IItemStack getLeft() {
return this.left;
}
@Override
public IItemStack getRight() {
return this.right;
}
@Override
public IItemStack getOutput() {
return this.item;
}
@Override
public float getAnvilBreakChance() {
return this.anvilBreakChance;
}
}
}
@@ -0,0 +1,46 @@
package noppes.npcs.scripted.event;
import noppes.npcs.api.event.ILinkedItemEvent;
import noppes.npcs.api.item.IItemLinked;
import noppes.npcs.constants.EnumScriptType;
public class LinkedItemEvent extends ItemEvent implements ILinkedItemEvent {
public LinkedItemEvent(IItemLinked item) {
super(item);
}
public static class VersionChangeEvent extends ItemEvent implements ILinkedItemEvent.VersionChangeEvent {
public final int version, prevVersion;
public VersionChangeEvent(IItemLinked item, int version, int prevVersion) {
super(item);
this.version = version;
this.prevVersion = prevVersion;
}
@Override
public int getVersion() {
return this.version;
}
@Override
public int getPreviousVersion() {
return this.prevVersion;
}
public String getHookName() {
return EnumScriptType.LINKED_ITEM_VERSION.function;
}
}
public static class BuildEvent extends ItemEvent implements ILinkedItemEvent.BuildEvent {
public BuildEvent(IItemLinked item) {
super(item);
}
public String getHookName() {
return EnumScriptType.LINKED_ITEM_BUILD.function;
}
}
}
@@ -14,6 +14,8 @@ import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.event.IPlayerEvent;
import noppes.npcs.api.handler.data.IPlayerEffect;
import noppes.npcs.api.handler.data.IProfile;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.scripted.NpcAPI;
@@ -949,4 +951,128 @@ public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent {
return EnumScriptType.RANGED_LAUNCHED.function;
}
}
public static class EffectEvent extends PlayerEvent implements IPlayerEvent.EffectEvent {
public final IPlayerEffect effect;
public EffectEvent(IPlayer player, IPlayerEffect statusEffect) {
super(player);
this.effect = statusEffect;
}
@Override
public IPlayerEffect getEffect() {
return this.effect;
}
public static class Added extends PlayerEvent.EffectEvent implements IPlayerEvent.EffectEvent.Added {
public Added(IPlayer player, IPlayerEffect statusEffect) {
super(player, statusEffect);
}
}
public static class Ticked extends PlayerEvent.EffectEvent implements IPlayerEvent.EffectEvent.Ticked {
public Ticked(IPlayer player, IPlayerEffect statusEffect) {
super(player, statusEffect);
}
}
public static class Removed extends PlayerEvent.EffectEvent implements IPlayerEvent.EffectEvent.Removed {
private final ExpirationType type;
public Removed(IPlayer player, IPlayerEffect statusEffect, ExpirationType type) {
super(player, statusEffect);
this.type = type;
}
@Override
public boolean hasTimerRunOut() {
return type == ExpirationType.RUN_OUT;
}
@Override
public boolean causedByDeath() {
return type == ExpirationType.DEATH;
}
}
public enum ExpirationType {
REMOVED,
RUN_OUT,
DEATH
}
}
@Cancelable
public static class ProfileEvent extends PlayerEvent implements IPlayerEvent.ProfileEvent {
public final IProfile profile;
public final int slot;
public ProfileEvent(IPlayer player, IProfile profile, int slot) {
super(player);
this.profile = profile;
this.slot = slot;
}
public String getHookName() {
return EnumScriptType.PROFILE.function;
}
@Override
public IProfile getProfile() {
return this.profile;
}
@Override
public int getSlot() {
return this.slot;
}
@Cancelable
public static class Changed extends PlayerEvent.ProfileEvent implements IPlayerEvent.ProfileEvent.Changed {
public final int prevSlot;
public Changed(IPlayer player, IProfile profile, int slot, int prevSlot) {
super(player, profile, slot);
this.prevSlot = prevSlot;
}
@Override
public int getPrevSlot() {
return this.prevSlot;
}
public String getHookName() {
return EnumScriptType.PROFILE_CHANGE.function;
}
}
@Cancelable
public static class Removed extends PlayerEvent.ProfileEvent implements IPlayerEvent.ProfileEvent.Removed {
public Removed(IPlayer player, IProfile profile, int slot) {
super(player, profile, slot);
}
public String getHookName() {
return EnumScriptType.PROFILE_REMOVE.function;
}
}
@Cancelable
public static class Create extends PlayerEvent.ProfileEvent implements IPlayerEvent.ProfileEvent.Create {
public Create(IPlayer player, IProfile profile, int slot) {
super(player, profile, slot);
}
public String getHookName() {
return EnumScriptType.PROFILE_CREATE.function;
}
}
}
}
@@ -1,11 +1,8 @@
package noppes.npcs.scripted.gui;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.gui.IItemSlot;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.scripted.NpcAPI;
public class ScriptGuiItemSlot extends ScriptGuiComponent implements IItemSlot {
IItemStack stack;
@@ -14,17 +14,14 @@ import noppes.npcs.scripted.CustomNPCsException;
import java.util.*;
public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, INpcScriptHandler {
public class ScriptCustomItem extends ScriptCustomizableItem implements IItemCustom, INpcScriptHandler {
public List<ScriptContainer> scripts = new ArrayList();
public List<Integer> errored = new ArrayList();
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public boolean loaded = false;
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;
@@ -36,12 +33,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 4: Fits in Head -> Boots slot respectively
public int enchantability;
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public float translateX, translateY, translateZ;
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public float rotationX, rotationY, rotationZ;
public float rotationXRate, rotationYRate, rotationZRate;
public long lastInited = -1;
public ScriptCustomItem(ItemStack item) {
@@ -72,6 +63,11 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
return this.enabled && ScriptController.HasStart;
}
@Override
public INpcScriptHandler getScriptHandler() {
return this;
}
public void callScript(EnumScriptType type, Event event) {
this.callScript(type.function, event);
}
@@ -147,17 +143,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
public void clearConsole() {
}
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;
}
@@ -217,33 +202,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
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;
}
@@ -271,165 +229,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
saveItemData();
}
public void setRotation(float rotationX, float rotationY, float rotationZ){
this.rotationX = rotationX;
this.rotationY = rotationY;
this.rotationZ = rotationZ;
saveItemData();
}
public void setRotationRate(float rotationXRate, float rotationYRate, float rotationZRate){
this.rotationXRate = rotationXRate;
this.rotationYRate = rotationYRate;
this.rotationZRate = rotationZRate;
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 float getRotationX() {
return rotationX;
}
public float getRotationY() {
return rotationY;
}
public float getRotationZ() {
return rotationZ;
}
public float getRotationXRate() {
return rotationXRate;
}
public float getRotationYRate() {
return rotationYRate;
}
public float getRotationZRate() {
return rotationZRate;
}
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("RotationXRate",this.rotationXRate);
compound.setFloat("RotationYRate",this.rotationYRate);
compound.setFloat("RotationZRate",this.rotationZRate);
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.setBoolean("IsTool", this.isTool);
compound.setBoolean("IsNormalItem", this.isNormalItem);
compound.setInteger("DigSpeed", this.digSpeed);
compound.setInteger("ArmorType", this.armorType);
compound.setInteger("Enchantability", this.enchantability);
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
compound.setInteger("ItemUseAction", this.itemUseAction);
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.rotationXRate = compound.getFloat("RotationXRate");
this.rotationYRate = compound.getFloat("RotationYRate");
this.rotationZRate = compound.getFloat("RotationZRate");
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.isTool = compound.getBoolean("IsTool");
this.isNormalItem = compound.getBoolean("IsNormalItem");
this.digSpeed = compound.getInteger("DigSpeed");
this.armorType = compound.getInteger("ArmorType");
this.enchantability = compound.getInteger("Enchantability");
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
this.itemUseAction = compound.getInteger("ItemUseAction");
}
public void saveScriptData() {
NBTTagCompound c = this.item.getTagCompound();
if (c == null) {
@@ -446,19 +245,45 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
}
}
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 NBTTagCompound getMCNbt() {
NBTTagCompound compound = super.getMCNbt();
compound.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
return compound;
}
public void loadItemData() {
NBTTagCompound c = this.item.getTagCompound();
if (c != null && !c.getCompoundTag("ItemData").hasNoTags()){
this.setItemNBT(c.getCompoundTag("ItemData"));
}
public void setMCNbt(NBTTagCompound compound) {
super.setMCNbt(compound);
setScriptNBT(compound.getCompoundTag("ScriptedData"));
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
super.getItemNBT(compound);
compound.setDouble("DurabilityValue",this.durabilityValue);
compound.setInteger("MaxStackSize",this.stackSize);
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);
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
compound.setInteger("ItemUseAction", this.itemUseAction);
return compound;
}
public void setItemNBT(NBTTagCompound compound) {
super.setItemNBT(compound);
this.durabilityValue = compound.getDouble("DurabilityValue");
this.stackSize = compound.getInteger("MaxStackSize");
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");
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
this.itemUseAction = compound.getInteger("ItemUseAction");
}
}
@@ -0,0 +1,184 @@
package noppes.npcs.scripted.item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.controllers.data.ItemDisplayData;
public abstract class ScriptCustomizableItem extends ScriptItemStack implements IItemCustomizable {
public final ItemDisplayData itemDisplay = new ItemDisplayData();
public ScriptCustomizableItem(ItemStack item) {
super(item);
}
public abstract int getMaxStackSize();
public abstract int getArmorType();
public abstract boolean isTool();
public abstract boolean isNormalItem();
public abstract int getDigSpeed();
public abstract double getDurabilityValue();
public abstract int getMaxItemUseDuration();
public abstract int getItemUseAction();
public abstract int getEnchantability();
public String getTexture() {
return this.itemDisplay.texture == null ? "" : this.itemDisplay.texture;
}
public void setTexture(String texture){
if(texture == null)
texture = "";
this.itemDisplay.texture = texture;
saveItemData();
}
public Boolean getDurabilityShow() {
return this.itemDisplay.durabilityShow != null ? this.itemDisplay.durabilityShow : false;
}
public void setDurabilityShow(Boolean bo) {
this.itemDisplay.durabilityShow = bo;
saveItemData();
}
public Integer getDurabilityColor() {
return this.itemDisplay.durabilityColor != null ? this.itemDisplay.durabilityColor : -1;
}
public void setDurabilityColor(Integer color) {
this.itemDisplay.durabilityColor = color;
saveItemData();
}
public Integer getColor() {
return this.itemDisplay.itemColor != null ? this.itemDisplay.itemColor : 0x8B4513;
}
public void setColor(Integer color) {
this.itemDisplay.itemColor = color;
saveItemData();
}
public void setRotation(Float rotationX, Float rotationY, Float rotationZ){
this.itemDisplay.rotationX = rotationX;
this.itemDisplay.rotationY = rotationY;
this.itemDisplay.rotationZ = rotationZ;
saveItemData();
}
public void setRotationRate(Float rotationXRate, Float rotationYRate, Float rotationZRate){
this.itemDisplay.rotationXRate = rotationXRate;
this.itemDisplay.rotationYRate = rotationYRate;
this.itemDisplay.rotationZRate = rotationZRate;
saveItemData();
}
public void setScale(Float scaleX, Float scaleY, Float scaleZ){
this.itemDisplay.scaleX = scaleX;
this.itemDisplay.scaleY = scaleY;
this.itemDisplay.scaleZ = scaleZ;
saveItemData();
}
public void setTranslate(Float translateX, Float translateY, Float translateZ){
this.itemDisplay.translateX = translateX;
this.itemDisplay.translateY = translateY;
this.itemDisplay.translateZ = translateZ;
saveItemData();
}
public Float getRotationX() {
return this.itemDisplay.rotationX != null ? this.itemDisplay.rotationX : 0;
}
public Float getRotationY() {
return this.itemDisplay.rotationY != null ? this.itemDisplay.rotationY : 0;
}
public Float getRotationZ() {
return this.itemDisplay.rotationZ != null ? this.itemDisplay.rotationZ : 0;
}
public Float getRotationXRate() {
return this.itemDisplay.rotationXRate != null ? this.itemDisplay.rotationXRate : 0;
}
public Float getRotationYRate() {
return this.itemDisplay.rotationYRate != null ? this.itemDisplay.rotationYRate : 0;
}
public Float getRotationZRate() {
return this.itemDisplay.rotationZRate != null ? this.itemDisplay.rotationZRate : 0;
}
public Float getScaleX() {
return this.itemDisplay.scaleX != null ? this.itemDisplay.scaleX : 0;
}
public Float getScaleY() {
return this.itemDisplay.scaleY != null ? this.itemDisplay.scaleY : 0;
}
public Float getScaleZ() {
return this.itemDisplay.scaleZ != null ? this.itemDisplay.scaleZ : 0;
}
public Float getTranslateX() {
return this.itemDisplay.translateX != null ? this.itemDisplay.translateX : 0;
}
public Float getTranslateY() {
return this.itemDisplay.translateY != null ? this.itemDisplay.translateY : 0;
}
public Float getTranslateZ() {
return this.itemDisplay.translateZ != null ? this.itemDisplay.translateZ : 0;
}
public NBTTagCompound getMCNbt() {
NBTTagCompound compound = super.getMCNbt();
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
return compound;
}
public void setMCNbt(NBTTagCompound compound) {
super.setMCNbt(compound);
setItemNBT(compound.getCompoundTag("ItemData"));
}
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 && !c.getCompoundTag("ItemData").hasNoTags()){
this.setItemNBT(c.getCompoundTag("ItemData"));
}
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
this.itemDisplay.writeToNBT(compound);
return compound;
}
public void setItemNBT(NBTTagCompound compound) {
this.itemDisplay.readFromNBT(compound);
}
}
@@ -16,6 +16,7 @@ import net.minecraftforge.common.IPlantable;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.api.INbt;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.items.ItemLinked;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
@@ -313,6 +314,9 @@ public class ScriptItemStack implements IItemStack {
if(item == null)
return null;
if (item.getItem() instanceof ItemLinked) {
return new ScriptLinkedItem(item);
}
if(item.getItem() instanceof ItemScripted) {
return new ScriptCustomItem(item);
}
@@ -0,0 +1,212 @@
package noppes.npcs.scripted.item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.item.IItemLinked;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.data.INpcScriptHandler;
import noppes.npcs.controllers.data.LinkedItem;
public class ScriptLinkedItem extends ScriptCustomizableItem implements IItemLinked {
public LinkedItem linkedItem = new LinkedItem();
public double durabilityValue = 1.0D;
public int linkedVersion = 1;
public ScriptLinkedItem(ItemStack item) {
super(item);
setDefaults();
loadItemData();
}
// For Building new Linked Item
public ScriptLinkedItem(ItemStack item, LinkedItem linkedItem) {
super(item);
this.linkedItem = linkedItem.clone();
this.linkedVersion = this.linkedItem.version;
setDefaults();
saveItemData();
}
public void setDefaults(){
this.itemDisplay.texture = null;
this.itemDisplay.translateX = null;
this.itemDisplay.translateY = null;
this.itemDisplay.translateZ = null;
this.itemDisplay.itemColor = null;
this.itemDisplay.scaleX = null;
this.itemDisplay.scaleY = null;
this.itemDisplay.scaleZ = null;
this.itemDisplay.rotationX = null;
this.itemDisplay.rotationY = null;
this.itemDisplay.rotationZ = null;
this.itemDisplay.rotationXRate = null;
this.itemDisplay.rotationYRate = null;
this.itemDisplay.rotationZRate = null;
this.itemDisplay.durabilityShow = null;
this.itemDisplay.durabilityColor = null;
}
public LinkedItem getLinkedItem() {
return LinkedItemController.getInstance().get(this.linkedItem.getId());
}
@Override
public INpcScriptHandler getScriptHandler() {
if(this.getLinkedItem() == null)
return null;
return this.getLinkedItem().getScriptHandler();
}
@Override
public int getMaxStackSize() {
return this.linkedItem.stackSize;
}
@Override
public int getArmorType() {
return this.linkedItem.armorType;
}
@Override
public boolean isTool() {
return this.linkedItem.isTool;
}
@Override
public boolean isNormalItem() {
return this.linkedItem.isNormalItem;
}
@Override
public int getDigSpeed() {
return this.linkedItem.digSpeed;
}
@Override
public double getDurabilityValue() {
return this.durabilityValue;
}
@Override
public int getMaxItemUseDuration() {
return this.linkedItem.maxItemUseDuration;
}
@Override
public int getItemUseAction() {
return this.linkedItem.itemUseAction;
}
@Override
public int getEnchantability() {
return this.linkedItem.enchantability;
}
@Override
public String getTexture() {
return this.itemDisplay.texture == null ? this.linkedItem.display.texture : this.itemDisplay.texture;
}
@Override
public Boolean getDurabilityShow() {
return this.itemDisplay.durabilityShow != null ? this.itemDisplay.durabilityShow : this.linkedItem.display.durabilityShow;
}
@Override
public Integer getDurabilityColor() {
return this.itemDisplay.durabilityColor != null ? this.itemDisplay.durabilityColor : this.linkedItem.display.durabilityColor;
}
@Override
public Integer getColor() {
return this.itemDisplay.itemColor != null ? this.itemDisplay.itemColor : this.linkedItem.display.itemColor;
}
@Override
public Float getRotationX() {
return this.itemDisplay.rotationX != null ? this.itemDisplay.rotationX : this.linkedItem.display.rotationX;
}
@Override
public Float getRotationY() {
return this.itemDisplay.rotationY != null ? this.itemDisplay.rotationY : this.linkedItem.display.rotationY;
}
@Override
public Float getRotationZ() {
return this.itemDisplay.rotationZ != null ? this.itemDisplay.rotationZ : this.linkedItem.display.rotationZ;
}
@Override
public Float getRotationXRate() {
return this.itemDisplay.rotationXRate != null ? this.itemDisplay.rotationXRate : this.linkedItem.display.rotationXRate;
}
@Override
public Float getRotationYRate() {
return this.itemDisplay.rotationYRate != null ? this.itemDisplay.rotationYRate : this.linkedItem.display.rotationYRate;
}
@Override
public Float getRotationZRate() {
return this.itemDisplay.rotationZRate != null ? this.itemDisplay.rotationZRate : this.linkedItem.display.rotationZRate;
}
@Override
public Float getScaleX() {
return this.itemDisplay.scaleX != null ? this.itemDisplay.scaleX : this.linkedItem.display.scaleX;
}
@Override
public Float getScaleY() {
return this.itemDisplay.scaleY != null ? this.itemDisplay.scaleY : this.linkedItem.display.scaleY;
}
@Override
public Float getScaleZ() {
return this.itemDisplay.scaleZ != null ? this.itemDisplay.scaleZ : this.linkedItem.display.scaleZ;
}
@Override
public Float getTranslateX() {
return this.itemDisplay.translateX != null ? this.itemDisplay.translateX : this.linkedItem.display.translateX;
}
public NBTTagCompound getMCNbt() {
NBTTagCompound compound = super.getMCNbt();
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
return compound;
}
public void setMCNbt(NBTTagCompound compound) {
super.setMCNbt(compound);
setItemNBT(compound.getCompoundTag("ItemData"));
}
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 && !c.getCompoundTag("ItemData").hasNoTags()){
this.setItemNBT(c.getCompoundTag("ItemData"));
}
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
this.itemDisplay.writeToNBT(compound);
compound.setTag(LinkedItem.LINKED_DATA_NBT_TAG, this.linkedItem.writeToNBT(false));
compound.setInteger(LinkedItem.LINKED_VERSION_VERSION_TAG, this.linkedVersion);
return compound;
}
public void setItemNBT(NBTTagCompound compound) {
this.itemDisplay.readFromNBT(compound);
this.linkedItem.readFromNBT(compound.getCompoundTag(LinkedItem.LINKED_DATA_NBT_TAG));
this.linkedVersion = compound.getInteger(LinkedItem.LINKED_VERSION_VERSION_TAG);
}
}