mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 15:49:43 +00:00
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:
1 parent
486e37cd7f
commit
8f16e6b20f
17 files changed
+710
-128
No files matched your search
@@ -207,13 +207,13 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
return getIItemStack(new ItemStack(item, size, damage));
|
||||
}
|
||||
|
||||
public IWorld getIWorld(WorldServer world) {
|
||||
ScriptWorld w = (ScriptWorld)worldCache.get(world.provider.dimensionId);
|
||||
public IWorld getIWorld(World world) {
|
||||
ScriptWorld w = worldCache.get(world.provider.dimensionId);
|
||||
if (w != null) {
|
||||
w.world = world;
|
||||
w.world.provider.dimensionId = world.provider.dimensionId;
|
||||
return w;
|
||||
} else {
|
||||
worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world));
|
||||
worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world.provider.dimensionId));
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.tileentity.TileEntitySign;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.blocks.tiles.TileBigSign;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
@@ -41,7 +42,15 @@ public class ScriptWorld implements IWorld {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public static ScriptWorld createNew(WorldServer world) {
|
||||
public static ScriptWorld createNew(int dimensionId) {
|
||||
WorldServer[] worlds = CustomNpcs.getServer().worldServers;
|
||||
|
||||
WorldServer world = worlds[0];
|
||||
for (WorldServer w : worlds) {
|
||||
if (w.provider.dimensionId == dimensionId) {
|
||||
world = w;
|
||||
}
|
||||
}
|
||||
return new ScriptWorld(world);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import noppes.npcs.scripted.ScriptBlockPos;
|
||||
import noppes.npcs.scripted.ScriptWorld;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
import noppes.npcs.scripted.interfaces.IParticle;
|
||||
import noppes.npcs.scripted.interfaces.IWorld;
|
||||
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
||||
import noppes.npcs.scripted.interfaces.INbt;
|
||||
import noppes.npcs.scripted.interfaces.IPos;
|
||||
@@ -755,7 +756,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptWorld getWorld() {
|
||||
return (ScriptWorld) NpcAPI.Instance().getIWorld((WorldServer) entity.worldObj);
|
||||
public IWorld getWorld() {
|
||||
return NpcAPI.Instance().getIWorld(entity.worldObj);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public abstract class AbstractNpcAPI {
|
||||
|
||||
public abstract IItemStack getIItemStack(ItemStack var1);
|
||||
|
||||
public abstract IWorld getIWorld(WorldServer var1);
|
||||
public abstract IWorld getIWorld(World var1);
|
||||
|
||||
public abstract IWorld getIWorld(int var1);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import noppes.npcs.scripted.ScriptWorld;
|
||||
import noppes.npcs.scripted.interfaces.INbt;
|
||||
import noppes.npcs.scripted.interfaces.IParticle;
|
||||
import noppes.npcs.scripted.interfaces.IPos;
|
||||
import noppes.npcs.scripted.interfaces.IWorld;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
|
||||
public interface IEntity<T extends Entity> {
|
||||
@@ -342,5 +343,5 @@ public interface IEntity<T extends Entity> {
|
||||
|
||||
void storeAsClone(int tab, String name);
|
||||
|
||||
ScriptWorld getWorld();
|
||||
IWorld getWorld();
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
//
|
||||
|
||||
package noppes.npcs.scripted.interfaces.handler.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IDialog {
|
||||
@@ -50,4 +49,90 @@ public interface IDialog {
|
||||
String getSound();
|
||||
|
||||
void save();
|
||||
|
||||
void setColor(int color);
|
||||
|
||||
int getColor();
|
||||
|
||||
void setTitleColor(int titleColor);
|
||||
|
||||
int getTitleColor();
|
||||
|
||||
void renderGradual(boolean gradual);
|
||||
|
||||
boolean renderGradual();
|
||||
|
||||
void showPreviousBlocks(boolean show);
|
||||
|
||||
boolean showPreviousBlocks();
|
||||
|
||||
void showOptionLine(boolean show);
|
||||
|
||||
boolean showOptionLine();
|
||||
|
||||
void setTextSound(String textSound);
|
||||
|
||||
String getTextSound();
|
||||
|
||||
void setTextPitch(float textPitch);
|
||||
|
||||
float getTextPitch();
|
||||
|
||||
void setTitlePos(int pos);
|
||||
|
||||
int getTitlePos();
|
||||
|
||||
void setNPCScale(float scale);
|
||||
|
||||
float getNpcScale();
|
||||
|
||||
void setNpcOffset(int offsetX, int offsetY);
|
||||
|
||||
int getNpcOffsetX();
|
||||
|
||||
int getNpcOffsetY();
|
||||
|
||||
void textWidthHeight(int textWidth, int textHeight);
|
||||
|
||||
int getTextWidth();
|
||||
|
||||
int setTextHeight();
|
||||
|
||||
void setTextOffset(int offsetX, int offsetY);
|
||||
|
||||
int getTextOffsetX();
|
||||
|
||||
int getTextOffsetY();
|
||||
|
||||
void setTitleOffset(int offsetX, int offsetY);
|
||||
|
||||
int getTitleOffsetX();
|
||||
|
||||
int getTitleOffsetY();
|
||||
|
||||
void setOptionOffset(int offsetX, int offsetY);
|
||||
|
||||
int getOptionOffsetX();
|
||||
|
||||
int getOptionOffsetY();
|
||||
|
||||
void setOptionSpacing(int spaceX, int spaceY);
|
||||
|
||||
int getOptionSpaceX();
|
||||
|
||||
int getOptionSpaceY();
|
||||
|
||||
void addImage(int id, IDialogImage image);
|
||||
|
||||
IDialogImage getImage(int id);
|
||||
|
||||
IDialogImage createImage();
|
||||
|
||||
IDialogImage[] getImages();
|
||||
|
||||
boolean hasImage(int id);
|
||||
|
||||
void removeImage(int id);
|
||||
|
||||
void clearImages();
|
||||
}
|
||||
Reference in new issue
Block a user