Added IDialogImage, a scripted object which is used by IDialog. Used to add dialog images.

IDialog:
-Added several new functions for dialogs' new visual attributes, as well as a way to add, get, create, remove, and clear dialog images.

Global NPC events:
-Added fields and variables from the old ScriptEvent events, in preparation to replace the old events with NpcEvent instances on local NPC scripts.
-Fixed issue where some event hooks would run on remote worlds.

Global NPC killed event:
-Added droppedItems and expDropped fields.

IWorld and NpcAPI:
-Now always uses a non-remove WorldServer object to create ScriptWorld objects and add them to the world cache.
This commit is contained in:
Luis C.M committed 2022-06-10 17:25:58 -05:00
1 parent 486e37cd7f
commit 8f16e6b20f
17 files changed
+710 -128

No files matched your search

@@ -9,6 +9,7 @@ import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.scripted.interfaces.*;
@@ -19,6 +20,8 @@ import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.item.IItemStack;
import noppes.npcs.scripted.NpcAPI;
import java.util.ArrayList;
public class NpcEvent extends CustomNPCsEvent {
public final ICustomNpc npc;
@@ -33,6 +36,10 @@ public class NpcEvent extends CustomNPCsEvent {
super(npc);
this.id = id;
}
public int getId(){
return id;
}
}
public static class CollideEvent extends NpcEvent {
@@ -49,13 +56,49 @@ public class NpcEvent extends CustomNPCsEvent {
public final IDamageSource damageSource;
public final IEntity source;
public float damage;
public boolean clearTarget = false;
private boolean clearTarget = false;
public boolean clear = false;
public final DamageSource damagesource;
public DamagedEvent(ICustomNpc npc, Entity source, float damage, DamageSource damagesource) {
super(npc);
this.source = NpcAPI.Instance().getIEntity(source);
this.damage = damage;
this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource);
//Old CNPC Script compatibility
this.damagesource = damagesource;
}
/**
* @return The source of the damage
*/
public IEntity getSource(){
return source;
}
/**
* @return Returns the damage value
*/
public float getDamage(){
return damage;
}
/**
* @param damage The new damage value
*/
public void setDamage(float damage){
this.damage = damage;
}
public void setClearTarget(boolean bo){
this.clearTarget = bo;
this.clear = bo;
}
public boolean getClearTarget(){
return clearTarget && clear;
}
public String getType(){
@@ -103,13 +146,33 @@ public class NpcEvent extends CustomNPCsEvent {
public IItemStack[] droppedItems;
public int expDropped;
public DiedEvent(ICustomNpc npc, DamageSource damagesource, Entity entity) {
public DiedEvent(ICustomNpc npc, DamageSource damagesource, Entity entity, ArrayList<ItemStack> droppedItems, int expDropped) {
super(npc);
this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource);
this.type = damagesource.damageType;
this.source = NpcAPI.Instance().getIEntity(entity);
ArrayList<IItemStack> iItemStacks = new ArrayList<>();
for (ItemStack itemStack : droppedItems) {
IItemStack iItemStack = NpcAPI.Instance().getIItemStack(itemStack);
iItemStacks.add(iItemStack);
}
this.droppedItems = iItemStacks.toArray(new IItemStack[0]);
this.expDropped = expDropped;
}
/**
* @return The source of the damage
*/
public IEntity getSource(){
return source;
}
public IDamageSource getDamageSource() { return damageSource; }
/**
* @return Returns the damage type
*/
public String getType(){
return damageSource.getMCDamageSource().damageType;
}
@@ -129,14 +192,43 @@ public class NpcEvent extends CustomNPCsEvent {
public final IPlayer player;
public final int id;
public final int optionId;
public final Dialog dialog;
public final Dialog dialogObj;
public final int dialog;
public final int option;
public DialogEvent(ICustomNpc npc, EntityPlayer player, int id, int optionId, Dialog dialog) {
super(npc);
this.player = (IPlayer)NpcAPI.Instance().getIEntity(player);
this.id = id;
this.optionId = optionId;
this.dialog = dialog;
this.dialogObj = dialog;
this.dialog = id;
this.option = optionId;
}
public IPlayer getPlayer() {
return player;
}
public Dialog getDialog() {
return dialogObj;
}
public int getDialogId() {
return dialog;
}
public int getOptionId() {
return option;
}
/**
* @deprecated
*/
public boolean isClosing(){
return true;
}
}
@@ -173,6 +265,17 @@ public class NpcEvent extends CustomNPCsEvent {
super(npc);
this.entity = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity);
}
/**
* @return The target source
*/
public IEntityLivingBase getTarget(){
return entity;
}
public void setTarget(IEntityLivingBase entity){
this.entity = entity;
}
}
public static class UpdateEvent extends NpcEvent {
@@ -186,4 +289,47 @@ public class NpcEvent extends CustomNPCsEvent {
super(npc);
}
}
public static class AttackEvent extends NpcEvent{
private float damage;
private IEntityLivingBase target;
private boolean isRanged;
public AttackEvent(ICustomNpc npc, float damage, EntityLivingBase target, boolean isRanged){
super(npc);
this.damage = damage;
this.isRanged = isRanged;
this.target = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target);
}
/**
* @return The source of the damage
* @deprecated
*/
public IEntityLivingBase getTarget(){
return target;
}
/**
* @return Returns the damage value
*/
public float getDamage(){
return damage;
}
/**
* @param damage The new damage value
*/
public void setDamage(float damage){
this.damage = damage;
}
/**
* @return Returns the damage type
*/
public boolean isRange(){
return isRanged;
}
}
}