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

@@ -4,7 +4,9 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.EventHooks;
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.EnumAnimationPart;
import noppes.npcs.controllers.AnimationController;
@@ -13,262 +15,283 @@ import java.util.ArrayList;
public class Animation implements IAnimation {
public AnimationData parent; //Client-sided only
public int id = -1; // Only for internal usage
public AnimationData parent; //Client-sided only
public int id = -1; // Only for internal usage
public ArrayList<Frame> frames = new ArrayList<>();
public int currentFrame = 0;
public int currentFrameTime = 0;
public ArrayList<Frame> frames = new ArrayList<>();
public int currentFrame = 0;
public int currentFrameTime = 0;
public String name = "";
public float speed = 1.0F;
public byte smooth = 0;
public int loop = -1; //If greater than 0 and less than the amount of frames, the animation will begin looping when it reaches this frame.
public boolean renderTicks = false; // If true, MC ticks are used. If false, render ticks are used.
public String name = "";
public float speed = 1.0F;
public byte smooth = 0;
public int loop = -1; //If greater than 0 and less than the amount of frames, the animation will begin looping when it reaches this frame.
public boolean whileStanding = true;
public boolean whileAttacking = true;
public boolean whileMoving = true;
public boolean whileStanding = true;
public boolean whileAttacking = true;
public boolean whileMoving = true;
//Client-sided
public boolean paused;
//Client-sided
public boolean paused;
public Animation(){}
public Animation(){}
public Animation(int id, String name){
this.name = name;
this.id = id;
}
public Animation(int id, String name){
this.name = name;
this.id = id;
}
public Animation(int id, String name, float speed, byte smooth){
this.name = name;
this.speed = speed;
this.smooth = smooth;
public Animation(int id, String name, float speed, byte smooth){
this.name = name;
this.speed = speed;
this.smooth = smooth;
this.id = id;
}
this.id = id;
}
public IFrame currentFrame() {
return currentFrame < frames.size() ? frames.get(currentFrame) : null;
}
public IAnimationData getParent() {
return this.parent;
}
public IFrame[] getFrames() {
return frames.toArray(new Frame[0]);
}
public IFrame currentFrame() {
return currentFrame < frames.size() ? frames.get(currentFrame) : null;
}
public IAnimation setFrames(IFrame[] frames) {
this.clearFrames();
for (IFrame frame : frames) {
this.frames.add((Frame) frame);
}
return this;
}
public IFrame[] getFrames() {
return frames.toArray(new Frame[0]);
}
public IAnimation clearFrames() {
this.frames.clear();
return this;
}
public IAnimation setFrames(IFrame[] frames) {
this.clearFrames();
for (IFrame frame : frames) {
this.frames.add((Frame) frame);
}
return this;
}
public IAnimation addFrame(IFrame frame) {
this.frames.add((Frame) frame);
return this;
}
public IAnimation clearFrames() {
this.frames.clear();
return this;
}
public IAnimation addFrame(int index, IFrame frame) {
this.frames.add(index, (Frame) frame);
return this;
}
public IAnimation addFrame(IFrame frame) {
this.frames.add((Frame) frame);
return this;
}
public IAnimation removeFrame(IFrame frame) {
this.frames.remove((Frame) frame);
return this;
}
public IAnimation addFrame(int index, IFrame frame) {
this.frames.add(index, (Frame) frame);
return this;
}
public IAnimation setName(String name) {
this.name = name;
return this;
}
public IAnimation removeFrame(IFrame frame) {
this.frames.remove((Frame) frame);
return this;
}
public String getName() {
return this.name;
}
public IAnimation setName(String name) {
this.name = name;
return this;
}
public IAnimation setSpeed(float speed) {
this.speed = speed;
return this;
}
public String getName() {
return this.name;
}
public float getSpeed() {
return this.speed;
}
public IAnimation setSpeed(float speed) {
this.speed = speed;
return this;
}
public IAnimation setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public float getSpeed() {
return this.speed;
}
public byte isSmooth() {
return this.smooth;
}
public IAnimation setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public IAnimation useRenderTicks(boolean renderTicks) {
this.renderTicks = renderTicks;
return this;
}
public byte isSmooth() {
return this.smooth;
}
public boolean useRenderTicks() {
return this.renderTicks;
}
public IAnimation doWhileStanding(boolean whileStanding) {
this.whileStanding = whileStanding;
return this;
}
public IAnimation doWhileStanding(boolean whileStanding) {
this.whileStanding = whileStanding;
return this;
}
public boolean doWhileStanding() {
return this.whileStanding;
}
public boolean doWhileStanding() {
return this.whileStanding;
}
public IAnimation doWhileMoving(boolean whileMoving) {
this.whileMoving = whileMoving;
return this;
}
public IAnimation doWhileMoving(boolean whileMoving) {
this.whileMoving = whileMoving;
return this;
}
public boolean doWhileMoving() {
return this.whileMoving;
}
public boolean doWhileMoving() {
return this.whileMoving;
}
public IAnimation doWhileAttacking(boolean whileAttacking) {
this.whileAttacking = whileAttacking;
return this;
}
public IAnimation doWhileAttacking(boolean whileAttacking) {
this.whileAttacking = whileAttacking;
return this;
}
public boolean doWhileAttacking() {
return this.whileAttacking;
}
public boolean doWhileAttacking() {
return this.whileAttacking;
}
public IAnimation setLoop(int loopAtFrame) {
this.loop = loopAtFrame;
return this;
}
public IAnimation setLoop(int loopAtFrame) {
this.loop = loopAtFrame;
return this;
}
public int loop() {
return this.loop;
}
public int loop() {
return this.loop;
}
public IAnimation save() {
return AnimationController.Instance.saveAnimation(this);
}
public IAnimation save() {
return AnimationController.Instance.saveAnimation(this);
}
@Override
public int getID() {
return id;
}
@Override
public int getID() {
return id;
}
@Override
public void setID(int newID) {
id = newID;
}
@Override
public void setID(int newID) {
id = newID;
}
public long getTotalTime() {
long time = 0;
for (Frame frame : this.frames) {
time += frame.duration;
}
return time;
}
public void readFromNBT(NBTTagCompound compound){
if(compound.hasKey("ID")){
id = compound.getInteger("ID");
}
else if (AnimationController.Instance != null) {
id = AnimationController.Instance.getUnusedId();
}
public void readFromNBT(NBTTagCompound compound){
if(compound.hasKey("ID")){
id = compound.getInteger("ID");
}
else if (AnimationController.Instance != null) {
id = AnimationController.Instance.getUnusedId();
}
name = compound.getString("Name");
speed = compound.getFloat("Speed");
smooth = compound.getByte("Smooth");
loop = compound.getInteger("Loop");
name = compound.getString("Name");
speed = compound.getFloat("Speed");
smooth = compound.getByte("Smooth");
loop = compound.getInteger("Loop");
renderTicks = compound.getBoolean("RenderTicks");
ArrayList<Frame> frames = new ArrayList<Frame>();
NBTTagList list = compound.getTagList("Frames", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
Frame frame = new Frame();
frame.parent = this;
frame.readFromNBT(item);
frames.add(frame);
}
this.frames = frames;
ArrayList<Frame> frames = new ArrayList<Frame>();
NBTTagList list = compound.getTagList("Frames", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
Frame frame = new Frame();
frame.parent = this;
frame.readFromNBT(item);
frames.add(frame);
}
this.frames = frames;
this.whileStanding = compound.getBoolean("WhileStanding");
this.whileMoving = compound.getBoolean("WhileWalking");
this.whileAttacking = compound.getBoolean("WhileAttacking");
this.whileStanding = compound.getBoolean("WhileStanding");
this.whileMoving = compound.getBoolean("WhileWalking");
this.whileAttacking = compound.getBoolean("WhileAttacking");
}
this.currentFrame = compound.getInteger("CurrentFrame");
this.currentFrameTime = compound.getInteger("CurrentFrameTime");
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("ID", id);
compound.setString("Name", name);
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setInteger("Loop",loop);
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("ID", id);
compound.setString("Name", name);
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setInteger("Loop",loop);
compound.setBoolean("RenderTicks", renderTicks);
NBTTagList list = new NBTTagList();
for(Frame frame : frames){
NBTTagCompound item = frame.writeToNBT();
list.appendTag(item);
}
compound.setTag("Frames", list);
NBTTagList list = new NBTTagList();
for(Frame frame : frames){
NBTTagCompound item = frame.writeToNBT();
list.appendTag(item);
}
compound.setTag("Frames", list);
compound.setBoolean("WhileStanding", whileStanding);
compound.setBoolean("WhileWalking", whileMoving);
compound.setBoolean("WhileAttacking", whileAttacking);
compound.setBoolean("WhileStanding", whileStanding);
compound.setBoolean("WhileWalking", whileMoving);
compound.setBoolean("WhileAttacking", whileAttacking);
return compound;
}
compound.setInteger("CurrentFrame", currentFrame);
compound.setInteger("CurrentFrameTime", currentFrameTime);
return compound;
}
@SideOnly(Side.CLIENT)
public void increaseTime() {
if (paused)
return;
public boolean increaseTime() {
if (paused)
return false;
if (this.parent != null && this.currentFrame < this.frames.size()) {
this.parent.finishedFrame = this.currentFrame;
}
if (this.parent != null && this.currentFrame < this.frames.size()) {
this.parent.finishedFrame = this.currentFrame;
}
this.currentFrameTime++;
if (this.currentFrameTime == this.currentFrame().getDuration()) {
Frame prevFrame = (Frame) this.currentFrame();
Frame nextFrame = null;
this.currentFrameTime = 0;
this.currentFrame++;
if (this.currentFrame < this.frames.size()) {
nextFrame = this.frames.get(this.currentFrame);
} else if (this.loop >= 0 && this.loop < this.frames.size()) {
this.currentFrame = this.loop;
}
if (nextFrame != null) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
if (prevFrame.frameParts.containsKey(part) && nextFrame.frameParts.containsKey(part)) {
nextFrame.frameParts.get(part).prevRotations = prevFrame.frameParts.get(part).prevRotations;
nextFrame.frameParts.get(part).prevPivots = prevFrame.frameParts.get(part).prevPivots;
}
}
} else if (this.parent != null && this.currentFrame > this.loop) {
this.parent.finishedTime = this.parent.animationEntity.getAge();
}
}
}
this.currentFrameTime++;
if (this.currentFrame() != null && this.currentFrameTime == this.currentFrame().getDuration()) {
EventHooks.onAnimationFrameExited(this, this.currentFrame());
@SideOnly(Side.CLIENT)
public void jumpToCurrentFrame() {
this.currentFrameTime = 0;
Frame frame = (Frame) this.currentFrame();
if(frame != null){
for (EnumAnimationPart part : EnumAnimationPart.values()) {
if(part != null){
if (frame.frameParts.containsKey(part)) {
frame.frameParts.get(part).jumpToCurrentFrame();
}
}
}
}
}
Frame prevFrame = (Frame) this.currentFrame();
Frame nextFrame = null;
this.currentFrameTime = 0;
this.currentFrame++;
if (this.currentFrame < this.frames.size()) {
nextFrame = this.frames.get(this.currentFrame);
} else if (this.loop >= 0 && this.loop < this.frames.size()) {
this.currentFrame = this.loop;
}
if (this.currentFrame() != null) {
EventHooks.onAnimationFrameEntered(this, this.currentFrame());
} else {
EventHooks.onAnimationEnded(this);
}
if (nextFrame != null) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
if (prevFrame.frameParts.containsKey(part) && nextFrame.frameParts.containsKey(part)) {
nextFrame.frameParts.get(part).prevRotations = prevFrame.frameParts.get(part).prevRotations;
nextFrame.frameParts.get(part).prevPivots = prevFrame.frameParts.get(part).prevPivots;
}
}
} else if (this.parent != null && this.currentFrame > this.loop) {
this.parent.finishedTime = this.parent.getMCEntity().getAge();
}
}
return true;
}
@SideOnly(Side.CLIENT)
public void jumpToCurrentFrame() {
this.jumpToFrameAtTime(this.currentFrame, 0);
}
@SideOnly(Side.CLIENT)
public void jumpToFrameAtTime(int frameIndex, int time) {
this.currentFrame = frameIndex;
this.currentFrameTime = time;
Frame frame = (Frame) this.currentFrame();
if(frame != null){
for (EnumAnimationPart part : EnumAnimationPart.values()) {
if(part != null){
if (frame.frameParts.containsKey(part)) {
frame.frameParts.get(part).jumpToCurrentFrame();
}
}
}
}
}
}
@@ -1,24 +1,27 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.UpdateAnimationsPacket;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import noppes.npcs.CustomNpcs;
import noppes.npcs.DataDisplay;
import noppes.npcs.Server;
import noppes.npcs.EventHooks;
import noppes.npcs.api.entity.IAnimatable;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.NpcAPI;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -29,20 +32,53 @@ public class AnimationData implements IAnimationData {
public Animation animation;
public boolean allowAnimation = false;
public long animatingTime = 0;
private final HashSet<Integer> cachedAnimationIDs = new HashSet<>();
public Animation currentClientAnimation;
private boolean isClientAnimating;
//Client-side values
public EntityLivingBase animationEntity;
public int finishedTime = -1;
public int finishedFrame = -1;
public AnimationData(Object parent){
this.parent = parent;
if (parent instanceof DataDisplay) {
this.animationEntity = ((DataDisplay) parent).npc;
} else if (parent instanceof EntityPlayer) {
this.animationEntity = (EntityLivingBase) parent;
}
public static AnimationData getData(Entity entity) {
if (entity == null) {
return null;
}
if (entity.worldObj.isRemote) {
return CustomNpcs.proxy.getClientAnimationData(entity);
}
if (entity instanceof EntityPlayerMP) {
return PlayerData.get((EntityPlayer) entity).animationData;
} else if (entity instanceof EntityNPCInterface) {
return ((EntityNPCInterface)entity).display.animationData;
} else {
return null;
}
}
public IAnimatable getEntity() {
IEntity<?> entity = NpcAPI.Instance().getIEntity(this.getMCEntity());
if (entity instanceof IAnimatable) {
return (IAnimatable) entity;
}
return null;
}
public EntityLivingBase getMCEntity() {
if (this.parent instanceof DataDisplay) {
return ((DataDisplay) this.parent).npc;
} else {
if (this.parent instanceof PlayerData) {
return ((PlayerData) this.parent).player;
} else {
return (EntityPlayer) this.parent;
}
}
}
@@ -57,25 +93,47 @@ public class AnimationData implements IAnimationData {
if(sendingEntity.dimension != sendingEntity.worldObj.provider.dimensionId)
sendingEntity.dimension = sendingEntity.worldObj.provider.dimensionId;
this.animatingTime = 0;
boolean prevIsClientAnimating = this.isClientAnimating && this.currentClientAnimation.currentFrame() != null;
this.isClientAnimating = this.allowAnimation && this.animation != null;
if (prevIsClientAnimating && (!this.isClientAnimating || this.animation != this.currentClientAnimation)) {
EventHooks.onAnimationEnded(this.currentClientAnimation);
}
if (this.isClientAnimating) {
this.currentClientAnimation = this.animation;
}
if (this.animation != null && this.allowAnimation) {
if (EventHooks.onAnimationStarted(this.animation))
return;
EventHooks.onAnimationFrameEntered(this.animation, this.animation.currentFrame());
}
List<EntityPlayer> entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(
sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range,
sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range));
entities.removeIf(player -> Arrays.stream(excludedPlayers).anyMatch(exp -> player == exp));
NBTTagCompound animationNBT = null;
for (EntityPlayer player : entities) {
AnimationData animationData = PlayerDataController.Instance.getPlayerData(player).animationData;
if (animationNBT == null && this.animation != null && !animationData.isCached(this.animation.getID())) {
animationNBT = this.animation.writeToNBT();
}
animationData.viewAnimation(this.animation, sendingEntity, this, animationNBT);
NBTTagCompound animationNBT = this.animation != null ? this.animation.writeToNBT() : null;
animationData.viewAnimation(this.animation, this, animationNBT);
}
}
}
public boolean isClientAnimating() {
return this.isClientAnimating;
}
public boolean isActive() {
if (!this.allowAnimation || this.animation == null || this.animation.currentFrame == this.animation.frames.size() || animation.currentFrame() == null)
return this.isActive(this.animation);
}
public boolean isActive(Animation animation) {
if (!this.allowAnimation || animation == null || animation.currentFrame == animation.frames.size() || animation.currentFrame() == null)
return false;
if (this.parent instanceof DataDisplay) {
@@ -100,43 +158,94 @@ public class AnimationData implements IAnimationData {
}
}
public boolean isCached(int id) {
return this.cachedAnimationIDs.contains(id);
}
public void cacheAnimation(int id) {
this.cachedAnimationIDs.add(id);
}
public void uncacheAnimation(int id) {
this.cachedAnimationIDs.remove(id);
}
public void clearCache() {
this.cachedAnimationIDs.clear();
}
public void viewAnimation(Animation animation, EntityLivingBase entity, AnimationData animationData, NBTTagCompound animationNBT) {
NBTTagCompound data = animationData.writeToNBT(new NBTTagCompound());
if (animation != null) {
if (this.cachedAnimationIDs.contains(animation.getID())) {
data.setInteger("AnimationID", animation.getID());
} else {
data.setTag("Animation", animationNBT);
public void increaseTime() {
Animation updateAnimation = null;
if (this.animation != null && this.isActive(this.animation.parent.currentClientAnimation)) {
updateAnimation = this.currentClientAnimation;
} else {
this.isClientAnimating = false;
if (this.isActive()) {
updateAnimation = this.animation;
}
}
if (updateAnimation != null && updateAnimation.increaseTime()) {
Frame frame = (Frame) updateAnimation.currentFrame();
if (frame != null) {
this.animatingTime++;
}
}
}
public void viewAnimation(Animation animation, AnimationData animationData, NBTTagCompound animationNBT) {
this.viewAnimation(animation, animationData, animationNBT, animationData.allowAnimation, -1, -1);
}
public boolean viewAnimation(Animation animation, AnimationData animationData, NBTTagCompound animationNBT, boolean enabled, int currentFrame, int time) {
if (animation != null
&& (currentFrame >= animation.frames.size()
|| currentFrame >= 0 && animation.frames.get(currentFrame).getDuration() < time)) {
return false;
}
boolean prevEnabled = animationData.allowAnimation;
animationData.allowAnimation = enabled;
NBTTagCompound data = animationData.viewWriteNBT(new NBTTagCompound());
animationData.allowAnimation = prevEnabled;
if (animation != null && currentFrame >= 0 && currentFrame < animation.frames.size()) {
data.setInteger("Frame", currentFrame);
data.setInteger("Time", time);
}
if (animationNBT != null) {
data.setTag("Animation", animationNBT);
} else if (animation != null) {
data.setTag("Animation", animation.writeToNBT());
}
IAnimatable animatable = animationData.getEntity();
Entity entity = ((IEntity<?>) animatable).getMCEntity();
if (!(entity instanceof EntityPlayer)) {
data.setInteger("EntityId", entity.getEntityId());
}
Server.sendData((EntityPlayerMP) ((PlayerData) parent).player, EnumPacketClient.UPDATE_ANIMATIONS, data, entity.getCommandSenderName());
PacketHandler.Instance.sendToPlayer(new UpdateAnimationsPacket(data, entity.getCommandSenderName()), (EntityPlayerMP) ((PlayerData) parent).player);
return true;
}
public NBTTagCompound viewWriteNBT(NBTTagCompound compound) {
compound.setBoolean("AllowAnimation", allowAnimation);
return compound;
}
public void viewReadFromNBT(NBTTagCompound compound) {
this.setEnabled(compound.getBoolean("AllowAnimation"));
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
if (this.currentClientAnimation != null) {
compound.setBoolean("IsClientAnimating", isClientAnimating);
if (this.isClientAnimating) {
compound.setTag("CurrentAnimation", currentClientAnimation.writeToNBT());
}
}
compound.setBoolean("AllowAnimation", allowAnimation);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
Entity entity = this.getMCEntity();
boolean isServer = entity != null && !entity.worldObj.isRemote;
if (compound.hasKey("IsClientAnimating") && isServer) {
this.isClientAnimating = compound.getBoolean("IsClientAnimating");
if (this.isClientAnimating) {
this.currentClientAnimation = new Animation();
this.currentClientAnimation.parent = this;
this.currentClientAnimation.readFromNBT(compound.getCompoundTag("CurrentAnimation"));
this.animation = this.currentClientAnimation;
}
}
this.setEnabled(compound.getBoolean("AllowAnimation"));
}
@@ -154,32 +263,38 @@ public class AnimationData implements IAnimationData {
}
public void setAnimation(IAnimation animation) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
this.animation = animation != null ? (Animation) animation : null;
} else {
if (animation != null) {
Animation newAnim = new Animation();
newAnim.readFromNBT(((Animation) animation).writeToNBT());
if (this.isActive() && !newAnim.frames.isEmpty()) {
Frame frame = (Frame) this.animation.currentFrame();
if (frame != null) {
Frame firstFrame = newAnim.frames.get(0);
for (Map.Entry<EnumAnimationPart, FramePart> entry : frame.frameParts.entrySet()) {
if (firstFrame.frameParts.containsKey(entry.getKey())) {
FramePart prevFramePart = entry.getValue();
FramePart newFramePart = firstFrame.frameParts.get(entry.getKey());
for (int i = 0; i < 3; i++) {
newFramePart.prevPivots[i] = prevFramePart.prevPivots[i];
newFramePart.prevRotations[i] = prevFramePart.prevRotations[i];
}
}
Animation newAnim = null;
if (animation != null) {
newAnim = new Animation();
newAnim.readFromNBT(((Animation) animation).writeToNBT());
newAnim.currentFrame = 0;
newAnim.currentFrameTime = 0;
newAnim.parent = this;
}
if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote && newAnim != null) {
this.animatingTime = 0;
}
Animation prevAnim = this.animation;
this.animation = newAnim;
if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote &&
this.isActive() && prevAnim != null && newAnim != null && !newAnim.frames.isEmpty()) {
Frame frame = (Frame) prevAnim.currentFrame();
if (frame != null) {
Frame firstFrame = newAnim.frames.get(0);
for (Map.Entry<EnumAnimationPart, FramePart> entry : frame.frameParts.entrySet()) {
if (firstFrame.frameParts.containsKey(entry.getKey())) {
FramePart prevFramePart = entry.getValue();
FramePart newFramePart = firstFrame.frameParts.get(entry.getKey());
for (int i = 0; i < 3; i++) {
newFramePart.prevPivots[i] = prevFramePart.prevPivots[i];
newFramePart.prevRotations[i] = prevFramePart.prevRotations[i];
}
}
}
this.animation = newAnim;
newAnim.parent = this;
} else {
this.animation = null;
}
}
}
@@ -187,4 +302,8 @@ public class AnimationData implements IAnimationData {
public IAnimation getAnimation() {
return animation;
}
public long getAnimatingTime() {
return this.animatingTime;
}
}
@@ -1,8 +1,11 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import noppes.npcs.ICompatibilty;
import noppes.npcs.VersionCompatibility;
import noppes.npcs.api.entity.IPlayer;
@@ -13,6 +16,9 @@ import noppes.npcs.controllers.PlayerQuestController;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.scripted.CustomNPCsException;
import java.util.ArrayList;
import java.util.List;
public class Availability implements ICompatibilty, IAvailability {
public int version = VersionCompatibility.ModRev;
@@ -124,6 +130,31 @@ public class Availability implements ICompatibilty, IAvailability {
compound.setInteger("AvailabilityMinPlayerLevel", minPlayerLevel);
return compound;
}
public boolean isDefault() {
return dialogAvailable == EnumAvailabilityDialog.Always &&
dialog2Available == EnumAvailabilityDialog.Always &&
dialog3Available == EnumAvailabilityDialog.Always &&
dialog4Available == EnumAvailabilityDialog.Always &&
dialogId == -1 &&
questAvailable == EnumAvailabilityQuest.Always &&
quest2Available == EnumAvailabilityQuest.Always &&
quest3Available == EnumAvailabilityQuest.Always &&
quest4Available == EnumAvailabilityQuest.Always &&
questId == -1 &&
factionAvailable == EnumAvailabilityFactionType.Always &&
faction2Available == EnumAvailabilityFactionType.Always &&
factionId == -1 &&
faction2Id == -1 &&
factionStance == EnumAvailabilityFaction.Friendly &&
faction2Stance == EnumAvailabilityFaction.Friendly &&
daytime == EnumDayTime.Always &&
minPlayerLevel == 0;
}
public void setFactionAvailability(int value) {
factionAvailable = EnumAvailabilityFactionType.values()[value];
}
@@ -177,6 +208,64 @@ public class Availability implements ICompatibilty, IAvailability {
return true;
}
@SideOnly(Side.CLIENT)
public List<String> isAvailableText(EntityPlayer player) {
List<String> errors = new ArrayList<String>();
// Check daytime conditions.
if (daytime == EnumDayTime.Day) {
long time = player.worldObj.getWorldTime() % 24000;
if (time > 12000) {
errors.add(StatCollector.translateToLocal("availability.error.day"));
}
} else if (daytime == EnumDayTime.Night) {
long time = player.worldObj.getWorldTime() % 24000;
if (time < 12000) {
errors.add(StatCollector.translateToLocal("availability.error.night"));
}
}
// Check dialog conditions.
if (!dialogAvailable(dialogId, dialogAvailable, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialogAvailable.toString(), dialogId));
}
if (!dialogAvailable(dialog2Id, dialog2Available, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog2Available.toString(), dialog2Id));
}
if (!dialogAvailable(dialog3Id, dialog3Available, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog3Available.toString(), dialog3Id));
}
if (!dialogAvailable(dialog4Id, dialog4Available, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog4Available.toString(), dialog4Id));
}
// Check quest conditions.
if (!questAvailable(questId, questAvailable, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", questAvailable.toString(), questId));
}
if (!questAvailable(quest2Id, quest2Available, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest2Available.toString(), quest2Id));
}
if (!questAvailable(quest3Id, quest3Available, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest3Available.toString(), quest3Id));
}
if (!questAvailable(quest4Id, quest4Available, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest4Available.toString(), quest4Id));
}
// Check faction conditions.
if (!factionAvailable(factionId, factionStance, factionAvailable, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.faction", factionAvailable.toString(), factionStance.toString(), factionId));
}
if (!factionAvailable(faction2Id, faction2Stance, faction2Available, player)) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.faction", faction2Available.toString(), faction2Stance.toString(), faction2Id));
}
if (player.experienceLevel < minPlayerLevel) {
errors.add(StatCollector.translateToLocalFormatted("availability.error.xp", minPlayerLevel));
}
return errors;
}
private boolean factionAvailable(int id, EnumAvailabilityFaction stance, EnumAvailabilityFactionType available, EntityPlayer player) {
if(available == EnumAvailabilityFactionType.Always)
return true;
@@ -1,5 +1,6 @@
package noppes.npcs.controllers.data;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
@@ -9,9 +10,7 @@ import net.minecraft.nbt.NBTTagList;
import noppes.npcs.NBTTags;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.NpcMiscInventory;
import noppes.npcs.Server;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.containers.ContainerNPCBankInterface;
import noppes.npcs.controllers.BankController;
import noppes.npcs.entity.EntityNPCInterface;
@@ -108,7 +107,8 @@ public class BankData {
if (container != null)
container.setCurrency(item);
}
Server.sendDataChecked((EntityPlayerMP) player, EnumPacketClient.GUI_DATA, compound);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
private ContainerNPCBankInterface getContainer(EntityPlayer player){
Container con = player.openContainer;
@@ -0,0 +1,317 @@
package noppes.npcs.controllers.data;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.data.ICustomEffect;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.scripted.event.PlayerEvent;
import java.util.function.Consumer;
public class CustomEffect implements ICustomEffect {
public int id = -1;
public String name = "";
public boolean lossOnDeath = true;
public int length = 30;
// Must be a multiple of 10
public int everyXTick = 20;
public String icon = "";
public int iconX = 0, iconY = 0;
/**
* Experimental script stuff.
*/
public Consumer<PlayerEvent.EffectEvent.Added> onAddedConsumer;
public Consumer<PlayerEvent.EffectEvent.Ticked> onTickConsumer;
public Consumer<PlayerEvent.EffectEvent.Removed> onRemovedConsumer;
public String menuName = "§aNEW EFFECT";
public int width = 16, height = 16;
public int index = 0;
public CustomEffect() {}
public CustomEffect(int id) {
this.id = id;
}
public CustomEffect(int id, String name) {
this(id);
this.name = name;
}
@Override
public int getID() {
return this.id;
}
@Override
public String getName() {
return this.name;
}
@Override
public void setMenuName(String name) {
if (name != null && !name.isEmpty())
this.menuName = name.replaceAll("&", "§");
}
@Override
public String getMenuName() {
return menuName;
}
@Override
public void setName(String name) {
if (name != null && !name.isEmpty())
this.name = name;
}
@Override
public String getIcon() {
return icon;
}
@Override
public void setIcon(String icon) {
this.icon = icon;
}
@Override
public int getEveryXTick() {
return everyXTick;
}
@Override
public void setEveryXTick(int everyXTick) {
if (everyXTick < 10)
everyXTick = 10;
int remainder = everyXTick % 10;
if (remainder >= 5)
everyXTick += 10 - remainder;
else
everyXTick -= remainder;
this.everyXTick = everyXTick;
}
@Override
public int getIconX() {
return iconX;
}
@Override
public void setIconX(int iconX) {
this.iconX = iconX;
}
@Override
public int getIconY() {
return iconY;
}
@Override
public void setIconY(int iconY) {
this.iconY = iconY;
}
@Override
public int getWidth() {
return this.width;
}
@Override
public int getHeight() {
return this.height;
}
@Override
public void setWidth(int width) {
this.width = width;
}
@Override
public void setHeight(int height) {
this.height = height;
}
@Override
public boolean isLossOnDeath() {
return lossOnDeath;
}
@Override
public void setLossOnDeath(boolean lossOnDeath) {
this.lossOnDeath = lossOnDeath;
}
@Override
public ICustomEffect save() {
return CustomEffectController.getInstance().saveEffect(this);
}
@Override
public void setID(int id) {
this.id = id;
}
@Override
public int getIndex() {
return this.index;
}
public void onAdded(Consumer<PlayerEvent.EffectEvent.Added> function) {
onAddedConsumer = function;
}
public void onTick(Consumer<PlayerEvent.EffectEvent.Ticked> function) {
onTickConsumer = function;
}
public void onRemoved(Consumer<PlayerEvent.EffectEvent.Removed> function) {
onRemovedConsumer = function;
}
public void onAdded(EntityPlayer player, PlayerEffect playerEffect) {
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
if (onAddedConsumer != null) onAddedConsumer.accept(event);
EffectScript script = getScriptHandler();
if (script == null) {
return;
}
script.callScript(EffectScript.ScriptType.OnAdd, event);
}
public void onTick(EntityPlayer player, PlayerEffect playerEffect) {
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
if (onTickConsumer != null) {
onTickConsumer.accept(event);
}
EffectScript script = getScriptHandler();
if (script == null) {
return;
}
script.callScript(EffectScript.ScriptType.OnTick, event);
}
public void onRemoved(EntityPlayer player, PlayerEffect playerEffect, PlayerEvent.EffectEvent.ExpirationType type) {
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
if (onRemovedConsumer != null) {
onRemovedConsumer.accept(event);
}
EffectScript script = getScriptHandler();
if (script == null) {
return;
}
script.callScript(EffectScript.ScriptType.OnRemove, event);
}
public NBTTagCompound writeToNBT(boolean saveScripts) {
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("ID", id);
compound.setString("name", name);
compound.setString("menuName", menuName);
compound.setInteger("length", length);
compound.setInteger("everyXTick", everyXTick);
compound.setInteger("iconX", iconX);
compound.setInteger("iconY", iconY);
compound.setInteger("iconWidth", width);
compound.setInteger("iconHeight", height);
compound.setString("icon", icon);
compound.setBoolean("lossOnDeath", lossOnDeath);
// if (saveScripts && scriptContainer != null) {
if (saveScripts) {
NBTTagCompound scriptData = new NBTTagCompound();
EffectScript handler = getScriptHandler();
if (handler != null)
handler.writeToNBT(scriptData);
compound.setTag("ScriptData", scriptData);
}
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
if (compound.hasKey("ID"))
id = compound.getInteger("ID");
else
id = CustomEffectController.Instance.getUnusedId();
name = compound.getString("name");
if (compound.hasKey("menuName", Constants.NBT.TAG_STRING))
menuName = compound.getString("menuName");
else
menuName = name;
length = compound.getInteger("length");
everyXTick = compound.getInteger("everyXTick");
iconX = compound.getInteger("iconX");
iconY = compound.getInteger("iconY");
if (compound.hasKey("iconWidth", Constants.NBT.TAG_INT))
width = compound.getInteger("iconWidth");
else
width = 16;
if (compound.hasKey("iconHeight", Constants.NBT.TAG_INT))
height = compound.getInteger("iconHeight");
else
height = 16;
icon = compound.getString("icon");
lossOnDeath = compound.getBoolean("lossOnDeath");
if (compound.hasKey("ScriptData", Constants.NBT.TAG_COMPOUND)) {
EffectScript handler = new EffectScript();
handler.readFromNBT(compound.getCompoundTag("ScriptData"));
setScriptHandler(handler);
}
}
public CustomEffect cloneEffect() {
CustomEffect newEffect = new CustomEffect();
newEffect.readFromNBT(this.writeToNBT(true));
newEffect.id = -1;
return newEffect;
}
public EffectScript getScriptHandler() {
return CustomEffectController.getInstance().customEffectScriptHandlers.get(this.id);
}
public void setScriptHandler(EffectScript handler) {
CustomEffectController.getInstance().customEffectScriptHandlers.put(this.id, handler);
}
public EffectScript getOrCreateScriptHandler() {
EffectScript data = getScriptHandler();
if (data == null)
setScriptHandler(data =new EffectScript());
return data;
}
public void runEffect(EntityPlayer player, PlayerEffect playerEffect) {
if (player.ticksExisted % everyXTick == 0) {
onTick(player, playerEffect);
}
}
}
@@ -18,13 +18,13 @@ public class DataTransform {
public NBTTagCompound stats;
public NBTTagCompound role;
public NBTTagCompound job;
public boolean hasDisplay, hasAi, hasAdvanced, hasInv, hasStats, hasRole, hasJob, isActive;
private EntityNPCInterface npc;
public boolean editingModus = false;
public DataTransform(EntityNPCInterface npc){
this.npc = npc;
}
@@ -47,11 +47,11 @@ public class DataTransform {
compound.setTag("TransformRole", role);
if(hasJob)
compound.setTag("TransformJob", job);
return compound;
}
public Object writeOptions(NBTTagCompound compound) {
public NBTTagCompound writeOptions(NBTTagCompound compound) {
compound.setBoolean("TransformHasDisplay", hasDisplay);
compound.setBoolean("TransformHasAI", hasAi);
compound.setBoolean("TransformHasAdvanced", hasAdvanced);
@@ -62,20 +62,20 @@ public class DataTransform {
compound.setBoolean("TransformEditingModus", editingModus);
return compound;
}
public void readToNBT(NBTTagCompound compound) {
isActive = compound.getBoolean("TransformIsActive");
readOptions(compound);
display = hasDisplay?compound.getCompoundTag("TransformDisplay"): getDisplay();
ai = hasAi?compound.getCompoundTag("TransformAI"): npc.ai.writeToNBT(new NBTTagCompound());
ai = hasAi?compound.getCompoundTag("TransformAI"): npc.ais.writeToNBT(new NBTTagCompound());
advanced = hasAdvanced?compound.getCompoundTag("TransformAdvanced"): getAdvanced();
inv = hasInv?compound.getCompoundTag("TransformInv"): npc.inventory.writeEntityToNBT(new NBTTagCompound());
stats = hasStats?compound.getCompoundTag("TransformStats"): npc.stats.writeToNBT(new NBTTagCompound());
job = hasJob?compound.getCompoundTag("TransformJob"): getJob();
role = hasRole?compound.getCompoundTag("TransformRole"): getRole();
}
public NBTTagCompound getJob() {
NBTTagCompound compound = new NBTTagCompound();
@@ -83,17 +83,17 @@ public class DataTransform {
if (npc.advanced.job != EnumJobType.None && npc.jobInterface != null) {
npc.jobInterface.writeToNBT(compound);
}
return compound;
}
public NBTTagCompound getRole() {
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Role", npc.advanced.role.ordinal());
compound.setInteger("Role", npc.advanced.role.ordinal());
if (npc.advanced.role != EnumRoleType.None && npc.roleInterface != null) {
npc.roleInterface.writeToNBT(compound);
}
return compound;
}
@@ -102,7 +102,7 @@ public class DataTransform {
if(npc instanceof EntityCustomNpc){
compound.setTag("ModelData", ((EntityCustomNpc)npc).modelData.writeToNBT());
}
return compound;
}
@@ -119,7 +119,7 @@ public class DataTransform {
npc.advanced.job = jopType;
npc.advanced.role = roleType;
return compound;
}
@@ -132,7 +132,7 @@ public class DataTransform {
boolean hadStats = hasStats;
boolean hadRole = hasRole;
boolean hadJob = hasJob;
hasDisplay = compound.getBoolean("TransformHasDisplay");
hasAi = compound.getBoolean("TransformHasAI");
hasAdvanced = compound.getBoolean("TransformHasAdvanced");
@@ -146,7 +146,7 @@ public class DataTransform {
display = getDisplay();
}
if(hasAi && !hadAI)
ai = npc.ai.writeToNBT(new NBTTagCompound());
ai = npc.ais.writeToNBT(new NBTTagCompound());
if(hasStats && !hadStats)
stats = npc.stats.writeToNBT(new NBTTagCompound());
if(hasInv && !hadInv)
@@ -158,7 +158,7 @@ public class DataTransform {
if(hasRole && !hadRole)
role = getRole();
}
public boolean isValid(){
return hasAdvanced || hasAi || hasDisplay || hasInv || hasStats || hasJob || hasRole;
}
@@ -166,14 +166,14 @@ public class DataTransform {
public NBTTagCompound processAdvanced(NBTTagCompound compoundAdv,
NBTTagCompound compoundRole, NBTTagCompound compoundJob) {
if(hasAdvanced)
compoundAdv = advanced;
if(hasRole)
compoundRole = role;
if(hasJob)
compoundJob = job;
Set<String> names = compoundRole.func_150296_c();
for(String name : names)
compoundAdv.setTag(name, compoundRole.getTag(name));
@@ -181,10 +181,10 @@ public class DataTransform {
names = compoundJob.func_150296_c();
for(String name : names)
compoundAdv.setTag(name, compoundJob.getTag(name));
return compoundAdv;
}
public void transform(boolean isActive){
if(this.isActive == isActive)
return;
@@ -205,14 +205,14 @@ public class DataTransform {
NBTTagCompound compoundAdv = getAdvanced();
NBTTagCompound compoundRole = getRole();
NBTTagCompound compoundJob = getJob();
NBTTagCompound compound = processAdvanced(compoundAdv, compoundRole, compoundJob);
npc.advanced.readToNBT(compound);
if (npc.advanced.role != EnumRoleType.None && npc.roleInterface != null)
if (npc.advanced.role != EnumRoleType.None && npc.roleInterface != null)
npc.roleInterface.readFromNBT(NBTTags.NBTMerge(compoundRole, compound));
if (npc.advanced.job != EnumJobType.None && npc.jobInterface != null)
npc.jobInterface.readFromNBT(NBTTags.NBTMerge(compoundJob, compound));
npc.jobInterface.readFromNBT(NBTTags.NBTMerge(compoundJob, compound));
if(hasAdvanced)
advanced = compoundAdv;
if(hasRole)
@@ -221,8 +221,8 @@ public class DataTransform {
job = compoundJob;
}
if(hasAi){
NBTTagCompound compound = npc.ai.writeToNBT(new NBTTagCompound());
npc.ai.readToNBT(NBTTags.NBTMerge(compound, ai));
NBTTagCompound compound = npc.ais.writeToNBT(new NBTTagCompound());
npc.ais.readToNBT(NBTTags.NBTMerge(compound, ai));
ai = compound;
npc.setCurrentAnimation(EnumAnimation.NONE);
}
@@ -0,0 +1,37 @@
package noppes.npcs.controllers.data;
public class EffectKey {
private final int id;
private final int index;
public EffectKey(int key1, int key2) {
this.id = key1;
this.index = key2;
}
public int getId() {
return id;
}
public int getIndex() {
return index;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof EffectKey)) return false;
EffectKey that = (EffectKey) o;
return id == that.id && index == that.index;
}
@Override
public int hashCode() {
return 31 * id + index;
}
@Override
public String toString() {
return "EffectKey{" + "key1=" + id + ", key2=" + index + '}';
}
}
@@ -0,0 +1,177 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.event.PlayerEvent;
import java.io.IOException;
import java.util.*;
public class EffectScript implements INpcScriptHandler {
public ScriptContainer container;
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setString("ScriptLanguage", scriptLanguage);
compound.setBoolean("ScriptEnabled", enabled);
if (container != null)
compound.setTag("ScriptContent", container.writeToNBT(new NBTTagCompound()));
return compound;
}
public EffectScript readFromNBT(NBTTagCompound compound) {
scriptLanguage = compound.getString("ScriptLanguage");
enabled = compound.getBoolean("ScriptEnabled");
if (compound.hasKey("ScriptContent", Constants.NBT.TAG_COMPOUND)) {
container = new ScriptContainer(this);
container.readFromNBT(compound.getCompoundTag("ScriptContent"));
}
return this;
}
public void callScript(ScriptType type, PlayerEvent.EffectEvent event) {
callScript(type.function, event);
}
public boolean isEnabled() {
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
}
@Override
public void callScript(EnumScriptType type, Event event) {
this.callScript(type.function, event);
}
@Override
public void callScript(String s, Event event) {
if (!this.isEnabled()) {
return;
}
container.run(s, event);
}
@Override
public boolean isClient() {
return FMLCommonHandler.instance().getEffectiveSide().isClient();
}
@Override
public boolean getEnabled() {
return this.enabled;
}
@Override
public void setEnabled(boolean b) {
this.enabled = b;
}
@Override
public String getLanguage() {
return this.scriptLanguage;
}
@Override
public void setLanguage(String s) {
this.scriptLanguage = s;
}
@Override
public void setScripts(List<ScriptContainer> list) {
if (list == null || list.isEmpty()) {
container = null;
return;
}
container = list.get(0);
}
@Override
public List<ScriptContainer> getScripts() {
if (container == null)
return new ArrayList<>();
return Collections.singletonList(container);
}
@Override
public String noticeString() {
return "";
}
@Override
public Map<Long, String> getConsoleText() {
TreeMap<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> longStringEntry = (Map.Entry)var5.next();
map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + (String)longStringEntry.getValue());
}
}
return map;
}
@Override
public void clearConsole() {
Iterator var1 = this.getScripts().iterator();
while(var1.hasNext()) {
ScriptContainer script = (ScriptContainer)var1.next();
script.console.clear();
}
}
public void saveScript(ByteBuf buffer) throws IOException {
int tab = buffer.readInt();
int totalScripts = buffer.readInt();
if (totalScripts == 0) {
this.container = null;
}
if (tab == 0) {
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
ScriptContainer script = new ScriptContainer(this);
script.readFromNBT(tabCompound);
this.container = script;
} else {
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
this.setLanguage(compound.getString("ScriptLanguage"));
if (!ScriptController.Instance.languages.containsKey(this.getLanguage())) {
if (!ScriptController.Instance.languages.isEmpty()) {
this.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
} else {
this.setLanguage("ECMAScript");
}
}
this.setEnabled(compound.getBoolean("ScriptEnabled"));
}
}
public enum ScriptType {
OnAdd("onAdded"),
OnTick("onTick"),
OnRemove("onRemove");
public final String function;
ScriptType(String functionName) {
this.function = functionName;
}
}
}
@@ -11,188 +11,185 @@ import java.util.Map;
public class Frame implements IFrame {
public Animation parent;
public HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
public int duration = 0;
boolean customized = false;
public float speed = 1.0F;
public byte smooth = 0;
public boolean renderTicks = false; // If true, MC ticks are used. If false, render ticks are used.
public Animation parent;
public HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
public int duration = 0;
private int colorMarker = 0xFFFFFF;
boolean customized = false;
public float speed = 1.0F;
public byte smooth = 0;
public Frame(){}
private int colorMarker = 0xFFFFFF;
private String comment = "";
public Frame(int duration) {
this.duration = duration;
}
public Frame(){}
public Frame(int duration, float speed, byte smooth) {
this.duration = duration;
this.speed = speed;
this.smooth = smooth;
this.customized = true;
}
public Frame(int duration) {
this.duration = duration;
}
public HashMap<EnumAnimationPart,FramePart> getFrameMap() {
return frameParts;
}
public Frame(int duration, float speed, byte smooth) {
this.duration = duration;
this.speed = speed;
this.smooth = smooth;
this.customized = true;
}
public IFramePart[] getParts() {
return frameParts.values().toArray(new IFramePart[0]);
}
public HashMap<EnumAnimationPart,FramePart> getFrameMap() {
return frameParts;
}
public IFrame addPart(IFramePart partConfig) {
this.frameParts.put(((FramePart)partConfig).getPart(),(FramePart) partConfig);
return this;
}
public IFramePart[] getParts() {
return frameParts.values().toArray(new IFramePart[0]);
}
public IFrame removePart(String partName) {
try {
this.frameParts.remove(EnumAnimationPart.valueOf(partName));
} catch (IllegalArgumentException ignored) {}
return this;
}
public IFrame addPart(IFramePart partConfig) {
this.frameParts.put(((FramePart)partConfig).getPart(),(FramePart) partConfig);
return this;
}
public IFrame removePart(int partId) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
this.frameParts.remove(part);
}
return this;
}
public IFrame removePart(String partName) {
try {
this.frameParts.remove(EnumAnimationPart.valueOf(partName));
} catch (IllegalArgumentException ignored) {}
return this;
}
public IFrame clearParts() {
frameParts.clear();
return this;
}
public IFrame removePart(int partId) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
this.frameParts.remove(part);
}
return this;
}
public int getDuration() {
return duration;
}
public IFrame clearParts() {
frameParts.clear();
return this;
}
public IFrame setDuration(int duration) {
this.duration = duration;
return this;
}
public int getDuration() {
return duration;
}
public boolean isCustomized() {
return customized;
}
public IFrame setDuration(int duration) {
this.duration = duration;
return this;
}
public IFrame setCustomized(boolean customized) {
this.customized = customized;
return this;
}
public boolean isCustomized() {
return customized;
}
public float getSpeed() {
return speed;
}
public IFrame setCustomized(boolean customized) {
this.customized = customized;
return this;
}
public IFrame setSpeed(float speed) {
this.speed = speed;
return this;
}
public float getSpeed() {
return speed;
}
public byte smoothType() {
return smooth;
}
public IFrame setSpeed(float speed) {
this.speed = speed;
return this;
}
public IFrame setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public byte smoothType() {
return smooth;
}
public IFrame useRenderTicks(boolean renderTicks) {
this.renderTicks = renderTicks;
return this;
}
public IFrame setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public boolean useRenderTicks() {
return this.renderTicks;
}
public int getColorMarker() {
return this.colorMarker;
}
public int getColorMarker() {
return this.colorMarker;
}
public void setColorMarker(int color) {
this.colorMarker = color;
}
public void setColorMarker(int color) {
this.colorMarker = color;
}
public String getComment() {
return this.comment;
}
public void readFromNBT(NBTTagCompound compound){
duration = compound.getInteger("Duration");
if (compound.hasKey("ColorMarker")) {
this.setColorMarker(compound.getInteger("ColorMarker"));
}
public void setComment(String comment) {
this.comment = comment;
}
// Customized = TRUE if Speed or Smooth Exist
if(compound.hasKey("Speed")){
customized = true;
speed = compound.getFloat("Speed");
}
if(compound.hasKey("Smooth")){
customized = true;
smooth = compound.getByte("Smooth");
}
if(compound.hasKey("RenderTicks")){
customized = true;
renderTicks = compound.getBoolean("RenderTicks");
}
public void readFromNBT(NBTTagCompound compound){
duration = compound.getInteger("Duration");
if (compound.hasKey("ColorMarker")) {
this.setColorMarker(compound.getInteger("ColorMarker"));
}
if (compound.hasKey("Comment")) {
this.comment = compound.getString("Comment");
}
if (!customized) {
this.speed = parent.speed;
this.smooth = parent.smooth;
this.renderTicks = parent.renderTicks;
}
// Customized = TRUE if Speed or Smooth Exist
if(compound.hasKey("Speed")){
customized = true;
speed = compound.getFloat("Speed");
}
if(compound.hasKey("Smooth")){
customized = true;
smooth = compound.getByte("Smooth");
}
HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
NBTTagList list = compound.getTagList("FrameParts", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
FramePart framePart = new FramePart();
framePart.readFromNBT(item);
if (!framePart.customized) {
framePart.smooth = this.smooth;
framePart.speed = this.speed;
}
frameParts.put(framePart.part,framePart);
}
this.frameParts = frameParts;
}
if (!customized && parent != null) {
this.speed = parent.speed;
this.smooth = parent.smooth;
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Duration", duration);
compound.setInteger("ColorMarker", this.colorMarker);
HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
NBTTagList list = compound.getTagList("FrameParts", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
FramePart framePart = new FramePart();
framePart.readFromNBT(item);
if (!framePart.customized) {
framePart.smooth = this.smooth;
framePart.speed = this.speed;
}
frameParts.put(framePart.part,framePart);
}
this.frameParts = frameParts;
}
if(customized){
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setBoolean("RenderTicks", renderTicks);
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Duration", duration);
compound.setInteger("ColorMarker", this.colorMarker);
compound.setString("Comment", this.comment);
NBTTagList list = new NBTTagList();
for(FramePart framePart : frameParts.values()){
NBTTagCompound item = framePart.writeToNBT();
list.appendTag(item);
}
compound.setTag("FrameParts", list);
return compound;
}
if(customized){
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
}
public Frame copy() {
Frame frame = new Frame(this.duration);
HashMap<EnumAnimationPart,FramePart> frameParts = this.frameParts;
for (Map.Entry<EnumAnimationPart,FramePart> entry : frameParts.entrySet()) {
frame.frameParts.put(entry.getKey(),entry.getValue().copy());
}
frame.parent = this.parent;
frame.duration = this.duration;
frame.customized = this.customized;
frame.speed = this.speed;
frame.smooth = this.smooth;
frame.renderTicks = this.renderTicks;
frame.colorMarker = this.colorMarker;
return frame;
}
NBTTagList list = new NBTTagList();
for(FramePart framePart : frameParts.values()){
NBTTagCompound item = framePart.writeToNBT();
list.appendTag(item);
}
compound.setTag("FrameParts", list);
return compound;
}
public Frame copy() {
Frame frame = new Frame(this.duration);
HashMap<EnumAnimationPart,FramePart> frameParts = this.frameParts;
for (Map.Entry<EnumAnimationPart,FramePart> entry : frameParts.entrySet()) {
frame.frameParts.put(entry.getKey(),entry.getValue().copy());
}
frame.parent = this.parent;
frame.duration = this.duration;
frame.customized = this.customized;
frame.speed = this.speed;
frame.smooth = this.smooth;
frame.colorMarker = this.colorMarker;
return frame;
}
}
@@ -0,0 +1,119 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
public class ItemDisplayData {
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public Float translateX = 0F, translateY = 0F, translateZ = 0F;
public Integer itemColor = 0x8B4513;
public Float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public Float rotationX = 0F, rotationY = 0F, rotationZ = 0F;
public Float rotationXRate = 0F, rotationYRate = 0F, rotationZRate = 0F;
public Boolean durabilityShow = false;
public Integer durabilityColor = -1;
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
this.writeToNBT(compound);
return compound;
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
this.setBoolean(compound, "DurabilityShow", this.durabilityShow);
this.setInteger(compound, "DurabilityColor", this.durabilityColor);
this.setInteger(compound, "ItemColor", this.itemColor);
if (this.texture != null) {
compound.setString("ItemTexture", this.texture);
}
this.setFloat(compound, "RotationX", this.rotationX);
this.setFloat(compound, "RotationY", this.rotationY);
this.setFloat(compound, "RotationZ", this.rotationZ);
this.setFloat(compound, "RotationXRate", this.rotationXRate);
this.setFloat(compound, "RotationYRate", this.rotationYRate);
this.setFloat(compound, "RotationZRate", this.rotationZRate);
this.setFloat(compound, "ScaleX", this.scaleX);
this.setFloat(compound, "ScaleY", this.scaleY);
this.setFloat(compound, "ScaleZ", this.scaleZ);
this.setFloat(compound, "TranslateX", this.translateX);
this.setFloat(compound, "TranslateY", this.translateY);
this.setFloat(compound, "TranslateZ", this.translateZ);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
if (compound.hasKey("DurabilityShow")) {
this.durabilityShow = compound.getBoolean("DurabilityShow");
}
if (compound.hasKey("DurabilityColor")) {
this.durabilityColor = compound.getInteger("DurabilityColor");
}
if (compound.hasKey("ItemColor")) {
this.itemColor = compound.getInteger("ItemColor");
}
if (compound.hasKey("ItemTexture")) {
this.texture = compound.getString("ItemTexture");
}
if (compound.hasKey("RotationX")) {
this.rotationX = compound.getFloat("RotationX");
}
if (compound.hasKey("RotationY")) {
this.rotationY = compound.getFloat("RotationY");
}
if (compound.hasKey("RotationZ")) {
this.rotationZ = compound.getFloat("RotationZ");
}
if (compound.hasKey("RotationXRate")) {
this.rotationXRate = compound.getFloat("RotationXRate");
}
if (compound.hasKey("RotationYRate")) {
this.rotationYRate = compound.getFloat("RotationYRate");
}
if (compound.hasKey("RotationZRate")) {
this.rotationZRate = compound.getFloat("RotationZRate");
}
if (compound.hasKey("ScaleX")) {
this.scaleX = compound.getFloat("ScaleX");
}
if (compound.hasKey("ScaleY")) {
this.scaleY = compound.getFloat("ScaleY");
}
if (compound.hasKey("ScaleZ")) {
this.scaleZ = compound.getFloat("ScaleZ");
}
if (compound.hasKey("TranslateX")) {
this.translateX = compound.getFloat("TranslateX");
}
if (compound.hasKey("TranslateY")) {
this.translateY = compound.getFloat("TranslateY");
}
if (compound.hasKey("TranslateZ")) {
this.translateZ = compound.getFloat("TranslateZ");
}
}
private void setBoolean(NBTTagCompound compound, String key, Boolean value) {
if (value != null) {
compound.setBoolean(key, value);
}
}
private void setInteger(NBTTagCompound compound, String key, Integer value) {
if (value != null) {
compound.setInteger(key, value);
}
}
private void setFloat(NBTTagCompound compound, String key, Float value) {
if (value != null) {
compound.setFloat(key, value);
}
}
}
@@ -0,0 +1,254 @@
package noppes.npcs.controllers.data;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.CustomItems;
import noppes.npcs.EventHooks;
import noppes.npcs.api.handler.data.ILinkedItem;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.item.ScriptLinkedItem;
public class LinkedItem implements ILinkedItem {
public static final String LINKED_VERSION_VERSION_TAG = "LinkedVersion";
public static final String LINKED_DATA_NBT_TAG = "LinkedData";
public int id = -1;
public int version = 0;
public String name;
public final ItemDisplayData display = new ItemDisplayData();
public double durabilityValue = 1.0D;
public int stackSize = 64;
public int maxItemUseDuration = 20;
public int itemUseAction = 0; //0: none, 1: block, 2: bow, 3: eat, 4: drink
public boolean isNormalItem = false;
public boolean isTool = false;
public int digSpeed = 1;
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 3: Fits in Head -> Boots slot respectively
public int enchantability;
public LinkedItem() {
this("New");
}
public LinkedItem(String name) {
this.name = name;
}
public LinkedItemScript getScriptHandler() {
return (LinkedItemScript) LinkedItemController.getInstance().getScriptHandler(this.getId());
}
public NBTTagCompound writeToNBT(boolean saveScripts) {
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Id", this.id);
compound.setInteger("Version", this.version);
compound.setString("Name", this.name);
compound.setTag("Display", this.display.writeToNBT());
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);
if (saveScripts) {
NBTTagCompound scriptData = new NBTTagCompound();
LinkedItemScript handler = getScriptHandler();
if (handler != null)
handler.writeToNBT(scriptData);
compound.setTag("ScriptData", scriptData);
}
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
this.id = compound.hasKey("Id") ? compound.getInteger("Id") : LinkedItemController.getInstance().getUnusedId();
this.name = compound.getString("Name");
this.version = compound.getInteger("Version");
this.display.readFromNBT(compound.getCompoundTag("Display"));
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");
if (compound.hasKey("ScriptData", Constants.NBT.TAG_COMPOUND)) {
LinkedItemScript handler = new LinkedItemScript();
handler.readFromNBT(compound.getCompoundTag("ScriptData"));
setScriptHandler(handler);
}
}
@Override
public ILinkedItem save() {
return LinkedItemController.getInstance().saveLinkedItem(this);
}
public void setScriptHandler(LinkedItemScript handler) {
LinkedItemController.getInstance().linkedItemsScripts.put(this.id, handler);
}
@Override
public IItemStack createStack() {
LinkedItem copy = this.clone();
ItemStack stack = new ItemStack(CustomItems.linked_item, 1);
ScriptLinkedItem scriptLinkedItem = new ScriptLinkedItem(stack, copy);
EventHooks.onLinkedItemBuild(scriptLinkedItem);
return NpcAPI.Instance().getIItemStack(scriptLinkedItem.item);
}
@Override
public int getId() {
return id;
}
@Override
public void setId(int id) {
this.id = id;
}
@Override
public int getVersion() {
return version;
}
@Override
public void setVersion(int version) {
this.version = version;
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public double getDurabilityValue() {
return durabilityValue;
}
@Override
public void setDurabilityValue(double durabilityValue) {
this.durabilityValue = durabilityValue;
}
@Override
public int getStackSize() {
return stackSize;
}
@Override
public void setStackSize(int stackSize) {
this.stackSize = stackSize;
}
@Override
public int getMaxItemUseDuration() {
return maxItemUseDuration;
}
@Override
public void setMaxItemUseDuration(int maxItemUseDuration) {
this.maxItemUseDuration = maxItemUseDuration;
}
@Override
public int getItemUseAction() {
return itemUseAction;
}
@Override
public void setItemUseAction(int itemUseAction) {
this.itemUseAction = itemUseAction;
}
@Override
public boolean isNormalItem() {
return isNormalItem;
}
@Override
public void setNormalItem(boolean normalItem) {
isNormalItem = normalItem;
}
@Override
public boolean isTool() {
return isTool;
}
@Override
public void setTool(boolean tool) {
isTool = tool;
}
@Override
public int getDigSpeed() {
return digSpeed;
}
@Override
public void setDigSpeed(int digSpeed) {
this.digSpeed = digSpeed;
}
@Override
public int getArmorType() {
return armorType;
}
@Override
public void setArmorType(int armorType) {
this.armorType = armorType;
}
@Override
public int getEnchantability() {
return enchantability;
}
@Override
public void setEnchantability(int enchantability) {
this.enchantability = enchantability;
}
public LinkedItem clone() {
NBTTagCompound nbt = this.writeToNBT(true);
LinkedItem clone = new LinkedItem(this.name);
clone.readFromNBT(nbt);
return clone;
}
public LinkedItemScript getOrCreateScriptHandler() {
LinkedItemScript data = getScriptHandler();
if (data == null)
setScriptHandler(data =new LinkedItemScript());
return data;
}
}
@@ -0,0 +1,160 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import java.io.IOException;
import java.util.*;
public class LinkedItemScript implements INpcScriptHandler {
public ScriptContainer container;
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setString("ScriptLanguage", scriptLanguage);
compound.setBoolean("ScriptEnabled", enabled);
if (container != null)
compound.setTag("ScriptContent", container.writeToNBT(new NBTTagCompound()));
return compound;
}
public LinkedItemScript readFromNBT(NBTTagCompound compound) {
scriptLanguage = compound.getString("ScriptLanguage");
enabled = compound.getBoolean("ScriptEnabled");
if (compound.hasKey("ScriptContent", Constants.NBT.TAG_COMPOUND)) {
container = new ScriptContainer(this);
container.readFromNBT(compound.getCompoundTag("ScriptContent"));
}
return this;
}
public boolean isEnabled() {
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
}
@Override
public void callScript(EnumScriptType type, Event event) {
this.callScript(type.function, event);
}
@Override
public void callScript(String s, Event event) {
if (!this.isEnabled()) {
return;
}
container.run(s, event);
}
@Override
public boolean isClient() {
return FMLCommonHandler.instance().getEffectiveSide().isClient();
}
@Override
public boolean getEnabled() {
return this.enabled;
}
@Override
public void setEnabled(boolean b) {
this.enabled = b;
}
@Override
public String getLanguage() {
return this.scriptLanguage;
}
@Override
public void setLanguage(String s) {
this.scriptLanguage = s;
}
@Override
public void setScripts(List<ScriptContainer> list) {
if (list == null || list.isEmpty()) {
container = null;
return;
}
container = list.get(0);
}
@Override
public List<ScriptContainer> getScripts() {
if (container == null)
return new ArrayList<>();
return Collections.singletonList(container);
}
@Override
public String noticeString() {
return "LinkedItem";
}
@Override
public Map<Long, String> getConsoleText() {
TreeMap<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> longStringEntry = (Map.Entry)var5.next();
map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + (String)longStringEntry.getValue());
}
}
return map;
}
@Override
public void clearConsole() {
Iterator var1 = this.getScripts().iterator();
while(var1.hasNext()) {
ScriptContainer script = (ScriptContainer)var1.next();
script.console.clear();
}
}
public void saveScript(ByteBuf buffer) throws IOException {
int tab = buffer.readInt();
int totalScripts = buffer.readInt();
if (totalScripts == 0) {
this.container = null;
}
if (tab == 0) {
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
ScriptContainer script = new ScriptContainer(this);
script.readFromNBT(tabCompound);
this.container = script;
} else {
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
this.setLanguage(compound.getString("ScriptLanguage"));
if (!ScriptController.Instance.languages.containsKey(this.getLanguage())) {
if (!ScriptController.Instance.languages.isEmpty()) {
this.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
} else {
this.setLanguage("ECMAScript");
}
}
this.setEnabled(compound.getBoolean("ScriptEnabled"));
}
}
}
@@ -1,54 +1,159 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.api.handler.data.IMagic;
import noppes.npcs.constants.EnumTextureType;
import noppes.npcs.controllers.MagicController;
import java.util.HashMap;
import java.util.Map;
public class Magic implements IMagic {
public String name = "";
public int color = Integer.parseInt("FF00", 16);
public String name = "";
public String displayName = "";
public int color = Integer.parseInt("FF00", 16);
public int id = -1;
public int id = -1;
public ItemStack item = null;
public Magic(){}
public EnumTextureType type = EnumTextureType.BASE;
public String iconTexture = "";
public Map<Integer, Float> interactions = new HashMap<>();
public Magic(int id, String name, int color){
this.name = name;
this.color = color;
this.id = id;
}
public static String formatName(String name){
name = name.toLowerCase().trim();
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
public void readNBT(NBTTagCompound compound){
public Magic() {}
public Magic(int id, String name, int color) {
this.name = name;
this.displayName = name;
this.color = color;
this.id = id;
}
public static String formatName(String name) {
name = name.toLowerCase().trim();
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
public void readNBT(NBTTagCompound compound) {
name = compound.getString("Name");
displayName = compound.getString("DisplayName");
color = compound.getInteger("Color");
id = compound.getInteger("Slot");
}
public void writeNBT(NBTTagCompound compound){
compound.setInteger("Slot", id);
compound.setString("Name", name);
compound.setInteger("Color", color);
}
public int getId() {
return this.id;
}
type = EnumTextureType.values()[compound.getInteger("Type")];
iconTexture = compound.getString("IconTexture");
if(type == EnumTextureType.ITEM && !iconTexture.isEmpty()){
String[] parts = iconTexture.split(":");
if (parts.length == 2) {
String modID = parts[0];
String itemName = parts[1];
Item item = GameRegistry.findItem(modID, itemName);
this.item = (item != null) ? new ItemStack(item) : null;
}
}
public String getName() {
return this.name;
}
interactions.clear();
if(compound.hasKey("Interactions")) {
NBTTagList interactionsList = compound.getTagList("Interactions", 10);
for (int i = 0; i < interactionsList.tagCount(); i++){
NBTTagCompound interactionTag = interactionsList.getCompoundTagAt(i);
int magicId = interactionTag.getInteger("MagicID");
float percentage = interactionTag.getFloat("Percentage");
interactions.put(magicId, percentage);
}
}
}
public void setName(String name) { this.name = name; }
public void writeNBT(NBTTagCompound compound) {
compound.setInteger("Slot", id);
compound.setString("Name", name);
compound.setString("DisplayName", displayName);
compound.setInteger("Color", color);
compound.setString("IconTexture", iconTexture);
compound.setInteger("Type", type.ordinal());
NBTTagList interactionsList = new NBTTagList();
for (Map.Entry<Integer, Float> entry : interactions.entrySet()){
NBTTagCompound interactionTag = new NBTTagCompound();
interactionTag.setInteger("MagicID", entry.getKey());
interactionTag.setFloat("Percentage", entry.getValue());
interactionsList.appendTag(interactionTag);
}
compound.setTag("Interactions", interactionsList);
public void setColor(int color) { this.color = color; }
if(type == EnumTextureType.ITEM && !iconTexture.isEmpty()){
String[] parts = iconTexture.split(":");
if (parts.length == 2) {
String modID = parts[0];
String itemName = parts[1];
Item item = GameRegistry.findItem(modID, itemName);
this.item = (item != null) ? new ItemStack(item) : null;
}
}
}
public int getColor() {
return this.color;
}
public int getId() {
return this.id;
}
public void save() {
MagicController.getInstance().saveMagic(this);
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public void setColor(int c) {
this.color = c;
}
@Override
public int getColor() {
return this.color;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public void save() {
MagicController.getInstance().saveMagic(this);
}
public void setItem(ItemStack item) {
GameRegistry.UniqueIdentifier identifier = GameRegistry.findUniqueIdentifierFor(item.getItem());
if(identifier != null){
this.item = item;
this.type = EnumTextureType.ITEM;
this.iconTexture = identifier.modId + ":" + identifier.name;
}
}
public ItemStack getItem() {
return this.item;
}
public void setIconTexture(String texture) {
this.iconTexture = texture;
}
public String getIconTexture() {
return this.iconTexture;
}
public void setInteractions(Map<Integer, Float> interactions) {
this.interactions = interactions;
}
public Map<Integer, Float> getInteractions() {
return this.interactions;
}
}
@@ -0,0 +1,11 @@
package noppes.npcs.controllers.data;
/**
* A helper class that represents the relationship between a Magic and a Category.
* It holds per-category ordering data.
*/
public class MagicAssociation {
public int magicId;
public int index;
public int priority;
}
@@ -0,0 +1,89 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.constants.EnumDiagramLayout;
import java.util.HashMap;
/**
* Holds category information for magic.
* Each category can have many magic associations.
*/
public class MagicCycle {
public int id = -1;
public String name = "";
public String displayName = "";
public EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR;
public HashMap<Integer, MagicAssociation> associations = new HashMap<>();
public MagicCycle() {}
public void readNBT(NBTTagCompound compound) {
id = compound.getInteger("ID");
name = compound.getString("Name");
displayName = compound.getString("DisplayName");
layout = EnumDiagramLayout.values()[compound.getInteger("Layout")];
associations.clear();
NBTTagList list = compound.getTagList("Associations", 10); // compound tags
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound assocTag = list.getCompoundTagAt(i);
MagicAssociation assoc = new MagicAssociation();
assoc.magicId = assocTag.getInteger("MagicID");
assoc.index = assocTag.getInteger("Index");
assoc.priority = assocTag.getInteger("Priority");
associations.put(assoc.magicId, assoc);
}
}
public void writeNBT(NBTTagCompound compound) {
compound.setInteger("ID", id);
compound.setString("Name", name);
compound.setString("DisplayName", displayName);
compound.setInteger("Layout", layout.ordinal());
NBTTagList list = new NBTTagList();
for (MagicAssociation assoc : associations.values()) {
NBTTagCompound assocTag = new NBTTagCompound();
assocTag.setInteger("MagicID", assoc.magicId);
assocTag.setInteger("Index", assoc.index);
assocTag.setInteger("Priority", assoc.priority);
list.appendTag(assocTag);
}
compound.setTag("Associations", list);
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public EnumDiagramLayout getLayout() {
return layout;
}
public void setLayout(EnumDiagramLayout layout) {
this.layout = layout;
}
public HashMap<Integer, MagicAssociation> getAssociations() {
return associations;
}
public void setAssociations(HashMap<Integer, MagicAssociation> associations) {
this.associations = associations;
}
}
@@ -0,0 +1,79 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IMagicData;
import java.util.HashMap;
public class MagicData implements IMagicData {
private HashMap<Integer, MagicEntry> magics = new HashMap<>();
public void writeToNBT(NBTTagCompound compound) {
NBTTagCompound magicData = new NBTTagCompound();
for (int key : magics.keySet()) {
magicData.setTag(String.valueOf(key), magics.get(key).writeToNBT());
}
compound.setTag("MagicData", magicData);
}
public void readToNBT(NBTTagCompound compound) {
NBTTagCompound magicData = compound.getCompoundTag("MagicData");
magics.clear();
if(magicData == null)
return;
for (Object key : magicData.func_150296_c()) {
int i = Integer.parseInt((String) key);
MagicEntry entry = new MagicEntry();
entry.readToNBT(magicData.getCompoundTag((String) key));
magics.put(i, entry);
}
}
public MagicEntry getMagic(int id) {
return magics.get(id);
}
@Override
public void removeMagic(int id) {
magics.remove(id);
}
@Override
public boolean hasMagic(int id) {
return magics.containsKey(id);
}
public HashMap<Integer, MagicEntry> getMagics() {
return magics;
}
@Override
public void clear() {
magics.clear();
}
@Override
public boolean isEmpty() {
return magics.isEmpty();
}
@Override
public void addMagic(int id, float damage, float split) {
MagicEntry entry = new MagicEntry();
entry.damage = damage;
entry.split = split;
magics.put(id, entry);
}
@Override
public float getMagicDamage(int id) {
MagicEntry entry = magics.get(id);
return entry == null ? 0 : entry.damage;
}
@Override
public float getMagicSplit(int id) {
MagicEntry entry = magics.get(id);
return entry == null ? 0 : entry.split;
}
}
@@ -0,0 +1,20 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
public class MagicEntry {
public float damage;
public float split;
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setFloat("Dmg", damage);
compound.setFloat("Split", split);
return compound;
}
public void readToNBT(NBTTagCompound compound) {
damage = compound.getFloat("Dmg");
split = compound.getFloat("Split");
}
}
@@ -1,15 +1,15 @@
package noppes.npcs.controllers.data;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.MarkDataPacket;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import noppes.npcs.Server;
import noppes.npcs.api.entity.data.IMark;
import noppes.npcs.api.handler.data.IAvailability;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.MarkType;
import noppes.npcs.entity.EntityNPCInterface;
@@ -102,7 +102,7 @@ public class MarkData implements IExtendedEntityProperties {
public void init(Entity entity, World world) {}
public void syncClients() {
Server.sendToAll(EnumPacketClient.MARK_DATA, entity.getEntityId(), getNBT());
PacketHandler.Instance.sendToAll(new MarkDataPacket(entity.getEntityId(), getNBT()));
}
public class Mark implements IMark {
@@ -1,6 +1,11 @@
package noppes.npcs.controllers.data;
import kamkeel.addon.DBCAddon;
import kamkeel.npcs.addon.DBCAddon;
import kamkeel.npcs.controllers.ProfileController;
import kamkeel.npcs.controllers.data.profile.Profile;
import kamkeel.npcs.network.packets.data.AchievementPacket;
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
import kamkeel.npcs.network.packets.request.party.PartyInvitePacket;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -10,13 +15,11 @@ import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.PacketHandlerServer;
import noppes.npcs.Server;
import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.handler.*;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.controllers.PartyController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.entity.EntityCustomNpc;
@@ -43,9 +46,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this);
public PlayerMailData mailData = new PlayerMailData(this);
public AnimationData animationData = new AnimationData(this);
public PlayerEffectData effectData = new PlayerEffectData(this);
public DataTimers timers = new DataTimers(this);
public DataSkinOverlays skinOverlays = new DataSkinOverlays(this);
public MagicData magicData = new MagicData();
public EntityNPCInterface editingNpc;
public NBTTagCompound cloned;
@@ -68,13 +72,28 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public ScreenSize screenSize = new ScreenSize(-1,-1);
public int profileSlot = 0;
public void onLogin() {
this.animationData.clearCache();
}
// Continue playing animation for self when re-logging
AnimationData animationData = this.animationData;
if (animationData != null && animationData.isClientAnimating()) {
Animation currentAnimation = animationData.currentClientAnimation;
NBTTagCompound compound = currentAnimation.writeToNBT();
animationData.viewAnimation(currentAnimation, animationData, compound,
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime);
}
CustomEffectController controller = CustomEffectController.getInstance();
UUID playerID = player.getPersistentID();
// Only add if there are saved effects and none are registered yet.
if (!controller.playerEffects.containsKey(playerID)) {
controller.playerEffects.put(playerID, effectData.getEffects());
}
}
public void onLogout() {
this.partyInvites.clear();
this.animationData.clearCache();
}
@Override
@@ -96,6 +115,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
timers.readFromNBT(data);
skinOverlays.readFromNBT(data);
animationData.readFromNBT(data);
effectData.readFromNBT(data);
magicData.readToNBT(data);
if(player != null){
playername = player.getCommandSenderName();
@@ -106,6 +127,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
uuid = data.getString("UUID");
}
companionID = data.getInteger("PlayerCompanionId");
profileSlot = data.getInteger("ProfileSlot");
if(data.hasKey("PlayerCompanion") && !hasCompanion()){
EntityCustomNpc npc = new EntityCustomNpc(player.worldObj);
npc.readEntityFromNBT(data.getCompoundTag("PlayerCompanion"));
@@ -135,11 +157,14 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
timers.writeToNBT(compound);
skinOverlays.writeToNBT(compound);
animationData.writeToNBT(compound);
effectData.writeToNBT(compound);
magicData.writeToNBT(compound);
compound.setString("PlayerName", playername);
compound.setString("UUID", uuid);
compound.setInteger("PlayerCompanionId", companionID);
compound.setBoolean("isGUIOpen",isGUIOpen);
compound.setInteger("ProfileSlot", profileSlot);
if(hasCompanion()){
NBTTagCompound nbt = new NBTTagCompound();
@@ -164,6 +189,16 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
factionData.loadNBTData(data);
}
public NBTTagCompound getPlayerEffects(){
NBTTagCompound compound = new NBTTagCompound();
effectData.writeToNBT(compound);
return compound;
}
public void setPlayerEffects(NBTTagCompound data){
effectData.readFromNBT(data);
}
public NBTTagCompound getSyncNBTFull() {
if(player != null){
playername = player.getCommandSenderName();
@@ -265,15 +300,16 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public void inviteToParty(Party party) {
if (party != null && this.partyUUID == null && !this.partyInvites.contains(party.getPartyUUID())) {
this.partyInvites.add(party.getPartyUUID());
Server.sendData((EntityPlayerMP)this.player, EnumPacketClient.PARTY_MESSAGE, "party.inviteAlert", party.getPartyLeader().getCommandSenderName());
Server.sendData((EntityPlayerMP)this.player, EnumPacketClient.CHAT, "\u00A7a", "party.inviteChat", " ", party.getPartyLeader().getCommandSenderName(), "!");
AchievementPacket.sendAchievement((EntityPlayerMP) player, true, "party.inviteAlert", party.getPartyLeader().getCommandSenderName());
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "\u00A7a", "party.inviteChat", " ", party.getPartyLeader().getCommandSenderName(), "!");
}
}
public void ignoreInvite(UUID uuid) {
if (uuid != null) {
this.partyInvites.remove(uuid);
PacketHandlerServer.sendInviteData((EntityPlayerMP) player);
PartyInvitePacket.sendInviteData((EntityPlayerMP) player);
}
}
@@ -342,6 +378,13 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
}
public synchronized void save() {
// Don't Save this is a Modification of a Profile's PlayerData
Profile profile = ProfileController.Instance.getProfile(UUID.fromString(uuid));
if(profile != null && profile.currentSlotId != this.profileSlot){
ProfileController.Instance.saveOffline(profile, UUID.fromString(uuid));
return;
}
final NBTTagCompound compound = getNBT();
final String filename;
if(ConfigMain.DatFormat){
@@ -97,7 +97,7 @@ public class PlayerDataScript implements INpcScriptHandler {
}
public boolean isClient() {
return this.player.isClientWorld();
return this.player != null && this.player.isClientWorld();
}
public boolean getEnabled() {
return ScriptController.Instance.playerScripts.enabled;
@@ -0,0 +1,78 @@
package noppes.npcs.controllers.data;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.data.IPlayerEffect;
import noppes.npcs.controllers.CustomEffectController;
public class PlayerEffect implements IPlayerEffect {
public int id;
public int duration;
public byte level;
public int index;
public PlayerEffect(int id, int duration, byte level, int index) {
this.id = id;
this.duration = duration;
this.level = level;
this.index = index;
}
@Override
public void kill() {
duration = 0;
}
@Override
public int getId() {
return id;
}
@Override
public int getDuration() {
return duration;
}
@Override
public void setDuration(int duration) {
this.duration = duration;
}
@Override
public byte getLevel() {
return level;
}
@Override
public void setLevel(byte level) {
this.level = level;
}
@Override
public String getName() {
CustomEffect effect = CustomEffectController.getInstance().get(this.id, this.index);
if(effect != null)
return effect.getName();
return "UNKNOWN";
}
@Override
public void performEffect(IPlayer player) {
if (player != null && player.getMCEntity() != null && player.getMCEntity() instanceof EntityPlayer) {
CustomEffect effect = CustomEffectController.getInstance().get(this.id, this.index);
if(effect != null)
effect.onTick((EntityPlayer) player.getMCEntity(), this);
}
}
@Override
public int getIndex() {
return this.index;
}
@Override
public void setIndex(int index) {
this.index = index;
}
}
@@ -0,0 +1,87 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class PlayerEffectData {
private final PlayerData parent;
private ConcurrentHashMap<EffectKey, PlayerEffect> effects = new ConcurrentHashMap<>();
public PlayerEffectData(PlayerData playerData){
this.parent = playerData;
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
NBTTagList list = new NBTTagList();
for (Map.Entry<EffectKey, PlayerEffect> entry : effects.entrySet()) {
NBTTagCompound effectCompound = new NBTTagCompound();
effectCompound.setInteger("id", entry.getKey().getId());
effectCompound.setInteger("index", entry.getKey().getIndex());
effectCompound.setInteger("duration", entry.getValue().duration);
effectCompound.setByte("level", entry.getValue().level);
list.appendTag(effectCompound);
}
compound.setTag("Effects", list);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
HashSet<EffectKey> newKeys = new HashSet<>();
if (compound.hasKey("Effects")) {
NBTTagList list = compound.getTagList("Effects", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound effectCompound = list.getCompoundTagAt(i);
int id = effectCompound.getInteger("id");
int index = effectCompound.getInteger("index");
int duration = effectCompound.getInteger("duration");
byte level = effectCompound.getByte("level");
EffectKey key = new EffectKey(id, index);
newKeys.add(key);
PlayerEffect effect = effects.get(key);
if (effect != null) {
effect.duration = duration;
effect.level = level;
} else {
effect = new PlayerEffect(id, duration, level, index);
effects.put(key, effect);
}
}
}
Iterator<EffectKey> it = effects.keySet().iterator();
while (it.hasNext()) {
EffectKey key = it.next();
if (!newKeys.contains(key)) {
it.remove();
}
}
}
public ConcurrentHashMap<EffectKey, PlayerEffect> getEffects() {
return effects;
}
public void setEffects(ConcurrentHashMap<EffectKey, PlayerEffect> effects) {
this.effects = effects;
}
public PlayerEffect getPlayerEffect(int id, int index) {
return effects.get(new EffectKey(id, index));
}
public PlayerEffect getPlayerEffect(int id) {
return getPlayerEffect(id, 0);
}
public boolean hasPlayerEffect(int id, int index) {
return effects.containsKey(new EffectKey(id, index));
}
public boolean hasPlayerEffect(int id) {
return hasPlayerEffect(id, 0);
}
}
@@ -23,9 +23,9 @@ public class PlayerMail implements IInventory, IPlayerMail {
public int questId = -1;
public String questTitle = "";
public ItemStack[] items = new ItemStack[4];
public long timePast;
public void readNBT(NBTTagCompound compound) {
subject = compound.getString("Subject");
sender = compound.getString("Sender");
@@ -81,7 +81,7 @@ public class PlayerMail implements IInventory, IPlayerMail {
compound.setTag("MailItems", nbttaglist);
return compound;
}
public boolean isValid(){
return !subject.isEmpty() && !message.hasNoTags() && !sender.isEmpty();
}
@@ -168,20 +168,20 @@ public class PlayerMail implements IInventory, IPlayerMail {
@Override
public String getInventoryName() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasCustomInventoryName() {
// TODO Auto-generated method stub
return false;
}
@Override
public void markDirty() {
// TODO Auto-generated method stub
}
@Override
@@ -191,7 +191,7 @@ public class PlayerMail implements IInventory, IPlayerMail {
@Override
public void openInventory() {
}
@Override
@@ -1,21 +1,24 @@
package noppes.npcs.controllers.data;
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.OverlayQuestTrackingPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.EventHooks;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.Server;
import noppes.npcs.api.handler.IPlayerQuestData;
import noppes.npcs.api.handler.data.IParty;
import noppes.npcs.api.handler.data.IQuest;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumQuestCompletion;
import noppes.npcs.constants.EnumQuestRepeat;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.controllers.PartyController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.PlayerQuestController;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.quests.QuestInterface;
@@ -201,8 +204,8 @@ public class PlayerQuestData implements IPlayerQuestData {
public void untrackQuest() {
if (this.trackedQuest != null) {
this.trackedQuest = null;
Server.sendData((EntityPlayerMP) this.parent.player, EnumPacketClient.OVERLAY_QUEST_TRACKING);
}
PacketHandler.Instance.sendToPlayer(new OverlayQuestTrackingPacket(new NBTTagCompound()), (EntityPlayerMP) this.parent.player);
}
}
public IQuest getTrackedQuest() {
@@ -217,9 +220,9 @@ public class PlayerQuestData implements IPlayerQuestData {
return;
QuestData questdata = new QuestData(quest);
activeQuests.put(id, questdata);
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
AchievementPacket.sendAchievement((EntityPlayerMP) parent.player, false, "quest.newquest", quest.title);
ChatAlertPacket.sendChatAlert((EntityPlayerMP) parent.player, "quest.newquest", ": ", quest.title);
parent.updateClient = true;
}
@@ -227,12 +230,7 @@ public class PlayerQuestData implements IPlayerQuestData {
Quest quest = QuestController.Instance.quests.get(id);
if (quest == null)
return;
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY)
finishedQuests.put(quest.id, System.currentTimeMillis());
else
finishedQuests.put(quest.id, parent.player.worldObj.getTotalWorldTime());
PlayerQuestController.setQuestFinished(quest, parent.player);
parent.updateClient = true;
}
@@ -0,0 +1,88 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IProfileOptions;
import noppes.npcs.constants.EnumProfileSync;
public class ProfileOptions implements IProfileOptions {
public boolean enableOptions = false;
public EnumProfileSync cooldownControl = EnumProfileSync.Individual;
public EnumProfileSync completeControl = EnumProfileSync.Individual;
public void readFromNBT(NBTTagCompound compound)
{
// Party Management
enableOptions = compound.getBoolean("EnableProfiles");
if(enableOptions){
cooldownControl = EnumProfileSync.values()[compound.getInteger("CooldownControl")];
completeControl = EnumProfileSync.values()[compound.getInteger("CompleteControl")];
}
else {
if(compound.hasKey("CooldownControl")){
compound.removeTag("CooldownControl");
}
if(compound.hasKey("CompleteControl")){
compound.removeTag("CompleteControl");
}
cooldownControl = EnumProfileSync.Individual;
completeControl = EnumProfileSync.Individual;
}
}
public NBTTagCompound writeToNBT()
{
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("EnableProfiles", enableOptions);
if(enableOptions){
compound.setInteger("CooldownControl", cooldownControl.ordinal());
compound.setInteger("CompleteControl", completeControl.ordinal());
}
else {
if(compound.hasKey("CooldownControl")){
compound.removeTag("CooldownControl");
}
if(compound.hasKey("CompleteControl")){
compound.removeTag("CompleteControl");
}
}
return compound;
}
@Override
public boolean hasProfileOptions() {
return enableOptions;
}
@Override
public void setProfileOptions(boolean enable) {
this.enableOptions = enable;
}
@Override
public void setCooldownControl(int profileType) {
if (profileType < 0 || profileType >= EnumProfileSync.values().length) {
return;
}
this.cooldownControl = EnumProfileSync.values()[profileType];
}
@Override
public int getCooldownControl(){
return this.cooldownControl.ordinal();
}
@Override
public void setCompleteControl(int profileType) {
if (profileType < 0 || profileType >= EnumProfileSync.values().length) {
return;
}
this.completeControl = EnumProfileSync.values()[profileType];
}
@Override
public int getCompleteControl(){
return this.completeControl.ordinal();
}
}
@@ -1,26 +1,28 @@
package noppes.npcs.controllers.data;
import kamkeel.npcs.controllers.ProfileController;
import noppes.npcs.api.handler.data.ISlot;
import kamkeel.npcs.controllers.data.profile.Profile;
import kamkeel.npcs.network.packets.data.QuestCompletionPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.*;
import noppes.npcs.api.IContainer;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.IPlayerData;
import noppes.npcs.api.handler.IPlayerQuestData;
import noppes.npcs.api.handler.data.*;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumProfileSync;
import noppes.npcs.constants.EnumQuestCompletion;
import noppes.npcs.constants.EnumQuestRepeat;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.quests.*;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.quests.QuestDialog;
import noppes.npcs.quests.QuestInterface;
import noppes.npcs.quests.QuestItem;
import noppes.npcs.quests.QuestKill;
import noppes.npcs.quests.QuestLocation;
import noppes.npcs.quests.QuestManual;
public class Quest implements ICompatibilty, IQuest {
public int version = VersionCompatibility.ModRev;
@@ -39,13 +41,14 @@ public class Quest implements ICompatibilty, IQuest {
public String command = "";
public QuestInterface questInterface = new QuestItem();
public long customCooldown = 0;
public int rewardExp = 0;
public NpcMiscInventory rewardItems = new NpcMiscInventory(9);
public boolean randomReward = false;
public FactionOptions factionOptions = new FactionOptions();
public PartyOptions partyOptions = new PartyOptions();
public ProfileOptions profileOptions = new ProfileOptions();
public void readNBT(NBTTagCompound compound) {
id = compound.getInteger("Id");
@@ -73,11 +76,12 @@ public class Quest implements ICompatibilty, IQuest {
completion = EnumQuestCompletion.values()[compound.getInteger("QuestCompletion")];
repeat = EnumQuestRepeat.values()[compound.getInteger("QuestRepeat")];
customCooldown = compound.getLong("CustomCooldown");
questInterface.readEntityFromNBT(compound);
factionOptions.readFromNBT(compound.getCompoundTag("QuestFactionPoints"));
partyOptions.readFromNBT(compound.getCompoundTag("PartyOptions"));
profileOptions.readFromNBT(compound.getCompoundTag("ProfileOptions"));
mail.readNBT(compound.getCompoundTag("QuestMail"));
}
@@ -116,6 +120,7 @@ public class Quest implements ICompatibilty, IQuest {
compound.setTag("Rewards", rewardItems.getToNBT());
compound.setString("QuestCommand", command);
compound.setBoolean("RandomReward", randomReward);
compound.setLong("CustomCooldown", customCooldown);
compound.setInteger("QuestCompletion", completion.ordinal());
compound.setInteger("QuestRepeat", repeat.ordinal());
@@ -123,6 +128,7 @@ public class Quest implements ICompatibilty, IQuest {
this.questInterface.writeEntityToNBT(compound);
compound.setTag("QuestFactionPoints", factionOptions.writeToNBT(new NBTTagCompound()));
compound.setTag("PartyOptions", partyOptions.writeToNBT());
compound.setTag("ProfileOptions", profileOptions.writeToNBT());
compound.setTag("QuestMail", mail.writeNBT());
return compound;
@@ -139,7 +145,7 @@ public class Quest implements ICompatibilty, IQuest {
public boolean instantComplete(EntityPlayer player, QuestData data) {
if(completion == EnumQuestCompletion.Instant && NoppesUtilPlayer.questCompletion((EntityPlayerMP) player, data.quest.id)){
Server.sendData((EntityPlayerMP)player, EnumPacketClient.QUEST_COMPLETION, data.quest.writeToNBT(new NBTTagCompound()));
QuestCompletionPacket.sendQuestComplete((EntityPlayerMP)player, data.quest.writeToNBT(new NBTTagCompound()));
return true;
}
return false;
@@ -155,23 +161,96 @@ public class Quest implements ICompatibilty, IQuest {
return quest;
}
public long getTimeUntilRepeat(EntityPlayer player) {
long questTime = PlayerDataController.Instance.getPlayerData(player).getQuestData().getLastCompletedTime(this.id);
public long getTimeUntilRepeat(EntityPlayer player) {
if(ConfigMain.ProfilesEnabled && profileOptions.enableOptions && profileOptions.cooldownControl == EnumProfileSync.Shared){
Profile profile = ProfileController.Instance.getProfile(player);
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
long timeRemaining = 0L;
for(ISlot slot : profile.getSlots().values()){
IPlayerData playerData = ProfileController.Instance.getSlotPlayerData(iPlayer, slot.getId());
IPlayerQuestData iPlayerQuestData = playerData.getQuestData();
timeRemaining = Math.max(timeRemaining, getTimeUntilRepeatQuestData(player, iPlayerQuestData));
}
return timeRemaining;
}
IPlayerQuestData questData = PlayerDataController.Instance.getPlayerData(player).getQuestData();
return getTimeUntilRepeatQuestData(player, questData);
}
switch (repeat) {
case MCDAILY:
return Math.max(0, (questTime + 24000 - player.worldObj.getTotalWorldTime()) * 50);
case MCWEEKLY:
return Math.max(0, (questTime + 168000 - player.worldObj.getTotalWorldTime()) * 50);
case RLDAILY:
return Math.max(0, questTime + 86400000 - System.currentTimeMillis());
case RLWEEKLY:
return Math.max(0, questTime + 604800000 - System.currentTimeMillis());
}
return 0L;
}
public long getTimeUntilRepeatQuestData(EntityPlayer player, IPlayerQuestData questData){
long questTime = questData.getLastCompletedTime(this.id);
@Override
switch (repeat) {
case MCDAILY: {
long now = player.worldObj.getTotalWorldTime();
long allowedTicks = 24000;
// If questTime is in the future and the excess is greater than allowed, reset it.
if (questTime > now && (questTime - now) > allowedTicks) {
questTime = now;
questData.setLastCompletedTime(this.id, questTime);
}
long remainingTicks = questTime + allowedTicks - now;
return Math.max(0, remainingTicks * 50);
}
case MCWEEKLY: {
long now = player.worldObj.getTotalWorldTime();
long allowedTicks = 168000;
if (questTime > now && (questTime - now) > allowedTicks) {
questTime = now;
questData.setLastCompletedTime(this.id, questTime);
}
long remainingTicks = questTime + allowedTicks - now;
return Math.max(0, remainingTicks * 50);
}
case RLDAILY: {
long now = System.currentTimeMillis();
long allowedMillis = 86400000;
if (questTime > now && (questTime - now) > allowedMillis) {
questTime = now;
questData.setLastCompletedTime(this.id, questTime);
}
long remainingMillis = questTime + allowedMillis - now;
return Math.max(0, remainingMillis);
}
case RLWEEKLY: {
long now = System.currentTimeMillis();
long allowedMillis = 604800000;
if (questTime > now && (questTime - now) > allowedMillis) {
questTime = now;
questData.setLastCompletedTime(this.id, questTime);
}
long remainingMillis = questTime + allowedMillis - now;
return Math.max(0, remainingMillis);
}
case MCCUSTOM: {
// For MCCUSTOM, customCooldown is assumed to be defined in ticks.
long now = player.worldObj.getTotalWorldTime();
long allowedTicks = this.customCooldown;
if (questTime > now && (questTime - now) > allowedTicks) {
questTime = now;
questData.setLastCompletedTime(this.id, questTime);
}
long remainingTicks = questTime + allowedTicks - now;
return Math.max(0, remainingTicks * 50);
}
case RLCUSTOM: {
// For RLCUSTOM, customCooldown is assumed to be in milliseconds.
long now = System.currentTimeMillis();
long allowedMillis = this.customCooldown;
if (questTime > now && (questTime - now) > allowedMillis) {
questTime = now;
questData.setLastCompletedTime(this.id, questTime);
}
long remainingMillis = questTime + allowedMillis - now;
return Math.max(0, remainingMillis);
}
default:
return 0L;
}
}
@Override
public int getVersion() {
return version;
}
@@ -289,4 +368,16 @@ public class Quest implements ICompatibilty, IQuest {
public IPartyOptions getPartyOptions() {
return this.partyOptions;
}
public IProfileOptions getProfileOptions() {
return this.profileOptions;
}
public long getCustomCooldown() {
return this.customCooldown;
}
public void setCustomCooldown(long newCooldown) {
this.customCooldown = newCooldown;
}
}
@@ -0,0 +1,150 @@
package noppes.npcs.controllers.data;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.handler.data.IAnvilRecipe;
public class RecipeAnvil implements IAnvilRecipe {
public int id = -1;
public String name = "";
public Availability availability = new Availability();
public boolean ignoreRepairItemNBT = false;
public boolean ignoreRepairMaterialNBT = false;
public boolean ignoreRepairMaterialDamage = false;
public ItemStack itemToRepair;
public ItemStack repairMaterial;
public int xpCost;
public float repairPercentage;
private boolean isAnvil = true;
public RecipeAnvil() { }
public RecipeAnvil(String name, ItemStack itemToRepair, ItemStack repairMaterial, int xpCost, float repairPercentage) {
this.name = name;
this.itemToRepair = itemToRepair;
this.repairMaterial = repairMaterial;
this.xpCost = xpCost;
this.repairPercentage = repairPercentage;
}
public static RecipeAnvil read(NBTTagCompound compound) {
RecipeAnvil recipe = new RecipeAnvil();
recipe.id = compound.getInteger("ID");
recipe.name = compound.getString("Name");
recipe.availability.readFromNBT(compound.getCompoundTag("Availability"));
recipe.xpCost = compound.getInteger("XPCost");
recipe.repairPercentage = compound.getFloat("RepairPercentage");
recipe.itemToRepair = NoppesUtilServer.readItem(compound.getCompoundTag("ItemToRepair"));
recipe.repairMaterial = NoppesUtilServer.readItem(compound.getCompoundTag("RepairMaterial"));
recipe.ignoreRepairMaterialNBT = compound.getBoolean("IgnoreRepairMatNBT");
recipe.ignoreRepairItemNBT = compound.getBoolean("IgnoreRepairItemNBT");
recipe.ignoreRepairMaterialDamage = compound.getBoolean("IgnoreRepairMatDamage");
recipe.isAnvil = true;
return recipe;
}
public NBTTagCompound writeNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("ID", id);
compound.setString("Name", name);
compound.setTag("Availability", availability.writeToNBT(new NBTTagCompound()));
compound.setInteger("XPCost", xpCost);
compound.setFloat("RepairPercentage", repairPercentage);
if(itemToRepair != null){
compound.setTag("ItemToRepair", NoppesUtilServer.writeItem(itemToRepair, new NBTTagCompound()));
}
if(repairMaterial != null){
compound.setTag("RepairMaterial", NoppesUtilServer.writeItem(repairMaterial, new NBTTagCompound()));
}
compound.setBoolean("IgnoreRepairMatNBT", ignoreRepairMaterialNBT);
compound.setBoolean("IgnoreRepairItemNBT", ignoreRepairItemNBT);
compound.setBoolean("IgnoreRepairMatDamage", ignoreRepairMaterialDamage);
compound.setBoolean("IsAnvil", true);
return compound;
}
@Override
public int getXpCost() {
return xpCost;
}
@Override
public float getRepairPercentage() {
return repairPercentage;
}
@Override
public boolean matches(ItemStack inputItem, ItemStack inputRepairMaterial) {
if (inputItem == null || inputRepairMaterial == null) return false;
if (!NoppesUtilPlayer.compareItems(this.itemToRepair, inputItem, true, this.ignoreRepairItemNBT)) {
return false;
}
if (!NoppesUtilPlayer.compareItems(this.repairMaterial, inputRepairMaterial, this.ignoreRepairMaterialDamage, this.ignoreRepairMaterialNBT)) {
return false;
}
return true;
}
@Override
public ItemStack getResult(ItemStack inputItem) {
if (inputItem == null)
return null;
ItemStack result = inputItem.copy();
if (!result.isItemStackDamageable())
return result;
int maxDamage = result.getMaxDamage();
int repairAmount = (int) (maxDamage * repairPercentage);
int currentDamage = result.getItemDamage();
int newDamage = currentDamage - repairAmount;
if (newDamage < 0) newDamage = 0;
result.setItemDamage(newDamage);
return result;
}
@Override
public String getName() {
return name;
}
@Override
public int getID() {
return this.id;
}
public static RecipeAnvil saveRecipe(RecipeAnvil recipe, ItemStack output, ItemStack repairMaterial) {
if (output != null) {
recipe.itemToRepair = output.copy();
if (recipe.itemToRepair.isItemStackDamageable()) {
recipe.itemToRepair.setItemDamage(0);
}
} else {
recipe.itemToRepair = null;
}
recipe.repairMaterial = (repairMaterial == null ? null : repairMaterial.copy());
return recipe;
}
public boolean isValid() {
return itemToRepair != null && repairMaterial != null;
}
/**
* Creates and returns a deep copy of this RecipeAnvil.
*/
public void copy(RecipeAnvil recipe) {
this.id = recipe.id;
this.name = recipe.name;
this.availability = recipe.availability;
this.ignoreRepairMaterialDamage = recipe.ignoreRepairMaterialDamage;
this.ignoreRepairItemNBT = recipe.ignoreRepairItemNBT;
this.ignoreRepairMaterialNBT = recipe.ignoreRepairMaterialNBT;
this.repairPercentage = recipe.repairPercentage;;
this.xpCost = recipe.xpCost;
}
}
@@ -23,7 +23,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
public boolean isGlobal = false;
public boolean ignoreDamage = false;
public boolean ignoreNBT = false;
public RecipeCarpentry(int width, int height, ItemStack[] recipe, ItemStack result){
super(width, height, recipe, result);
@@ -32,9 +32,9 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
super(0, 0, new ItemStack[0], null);
this.name = name;
}
public static RecipeCarpentry read(NBTTagCompound compound){
RecipeCarpentry recipe = new RecipeCarpentry(compound.getInteger("Width"), compound.getInteger("Height"),
RecipeCarpentry recipe = new RecipeCarpentry(compound.getInteger("Width"), compound.getInteger("Height"),
NBTTags.getItemStackArray(compound.getTagList("Materials", 10)), NoppesUtilServer.readItem(compound.getCompoundTag("Item")));
recipe.name = compound.getString("Name");
recipe.id = compound.getInteger("ID");
@@ -42,7 +42,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
recipe.ignoreDamage = compound.getBoolean("IgnoreDamage");
recipe.ignoreNBT = compound.getBoolean("IgnoreNBT");
recipe.isGlobal = compound.getBoolean("Global");
return recipe;
}
@@ -188,15 +188,14 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
var15[var9] = null;
}
}
RecipeCarpentry newrecipe = new RecipeCarpentry(var5, var6, var15, par1ItemStack);
RecipeCarpentry newrecipe = new RecipeCarpentry(var5, var6, var15, par1ItemStack);
newrecipe.copy(recipe);
if(var5 == 4 || var6 == 4)
newrecipe.isGlobal = false;
return newrecipe;
}
public void copy(RecipeCarpentry recipe) {
this.id = recipe.id;
this.name = recipe.name;
@@ -205,7 +204,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
this.ignoreDamage = recipe.ignoreDamage;
this.ignoreNBT = recipe.ignoreNBT;
}
public ItemStack getCraftingItem(int i){
if(recipeItems == null || i >= recipeItems.length)
return null;
@@ -19,10 +19,10 @@ public class RecipesDefault {
else
item = (ItemStack) ob;
RecipeCarpentry recipeAnvil = new RecipeCarpentry(name);
recipeAnvil.isGlobal = isGlobal;
recipeAnvil = RecipeCarpentry.saveRecipe(recipeAnvil, item, recipe);
RecipeController.Instance.addRecipe(recipeAnvil);
RecipeCarpentry recipeCarpentry = new RecipeCarpentry(name);
recipeCarpentry.isGlobal = isGlobal;
recipeCarpentry = RecipeCarpentry.saveRecipe(recipeCarpentry, item, recipe);
RecipeController.Instance.addRecipe(recipeCarpentry);
}
public static void loadDefaultRecipes(int i) {
if(i < 0){
@@ -30,6 +30,10 @@ public class RecipesDefault {
addRecipe("Mob Cloner", CustomItems.cloner, true, "XX","XY"," Y",'X', Items.bread,'Y', Items.stick);
addRecipe("Carpentry Bench", CustomItems.carpentyBench, true, "XYX","Z Z","Z Z", 'X', Blocks.planks, 'Z', Items.stick, 'Y', Blocks.crafting_table);
ItemStack anvil = new ItemStack(CustomItems.carpentyBench);
anvil.setItemDamage(1);
addRecipe("Anvil", anvil, true, "XXX","Z Z","Z Z", 'X', Blocks.iron_block, 'Z', Items.iron_ingot);
if(!ConfigMain.DisableExtraItems){
addRecipe("Mana", CustomItems.mana, true, "XY",'X',Items.redstone,'Y',Items.glowstone_dust);
addRecipe("Gun Wooden", CustomItems.gunWood, false, "XXXY"," ZM "," M ",'Y', Blocks.lever, 'M', Items.stick, 'Z', Blocks.stone_button,'X', Blocks.planks);
@@ -146,7 +150,7 @@ public class RecipesDefault {
addRecipe("Sign Wood5", new ItemStack(CustomItems.sign, 1, 4), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,4), 'Y', Items.iron_ingot);
addRecipe("Sign Wood6", new ItemStack(CustomItems.sign, 1, 5), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,5), 'Y', Items.iron_ingot);
addRecipe("Lamp", new ItemStack(CustomItems.lamp), false, "XXX","YZY","XXX", 'X', Items.iron_ingot, 'Y', Blocks.glass, 'Z', Blocks.torch);
addRecipe("Lamp", new ItemStack(CustomItems.lantern), false, "XXX","YZY","XXX", 'X', Items.iron_ingot, 'Y', Blocks.glass, 'Z', Blocks.torch);
addRecipe("Candle", new ItemStack(CustomItems.candle), false, "XZX"," X ", 'X', Items.iron_ingot, 'Z', Blocks.torch);
addRecipe("BigSign", new ItemStack(CustomItems.bigsign, 2), false, "XXX","XXX","XXX", 'X', Blocks.planks);