mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 02:34:49 +00:00
Fixed API interface errors, added casts for custom item script handlers in EventHooks, and added some event interfaces.
This commit is contained in:
1 parent
be9ae94163
commit
aa02e5dcc3
41 files changed
+181
-66
No files matched your search
@@ -42,6 +42,7 @@ import noppes.npcs.api.item.IItemCustom;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -51,70 +52,70 @@ public class EventHooks {
|
||||
}
|
||||
|
||||
public static void onScriptItemInit(IItemCustom handler) {
|
||||
if (!handler.isClient()) {
|
||||
if (!((ScriptCustomItem) handler).isClient()) {
|
||||
ItemEvent.InitEvent event = new ItemEvent.InitEvent(handler);
|
||||
handler.callScript(EnumScriptType.INIT, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.INIT, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onScriptItemUpdate(IItemCustom handler, EntityLivingBase player) {
|
||||
if (!handler.isClient()) {
|
||||
if (!((ScriptCustomItem) handler).isClient()) {
|
||||
ItemEvent.UpdateEvent event = new ItemEvent.UpdateEvent(handler, NpcAPI.Instance().getIEntity(player));
|
||||
handler.callScript(EnumScriptType.TICK, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.TICK, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean onScriptItemTossed(IItemCustom handler, EntityPlayer player, EntityItem entity) {
|
||||
ItemEvent.TossedEvent event = new ItemEvent.TossedEvent(handler, (IPlayer)NpcAPI.Instance().getIEntity(player), NpcAPI.Instance().getIEntity(entity));
|
||||
handler.callScript(EnumScriptType.TOSSED, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.TOSSED, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onScriptItemPickedUp(IItemCustom handler, EntityPlayer player) {
|
||||
ItemEvent.PickedUpEvent event = new ItemEvent.PickedUpEvent(handler, (IPlayer)NpcAPI.Instance().getIEntity(player));
|
||||
handler.callScript(EnumScriptType.PICKEDUP, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.PICKEDUP, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onScriptItemSpawn(IItemCustom handler, EntityItem entity) {
|
||||
ItemEvent.SpawnEvent event = new ItemEvent.SpawnEvent(handler, NpcAPI.Instance().getIEntity(entity));
|
||||
handler.callScript(EnumScriptType.SPAWN, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.SPAWN, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onScriptItemInteract(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.InteractEvent event) {
|
||||
handler.callScript(EnumScriptType.INTERACT, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.INTERACT, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onScriptItemAttack(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.AttackEvent event) {
|
||||
handler.callScript(EnumScriptType.ATTACK, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.ATTACK, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onStartUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
|
||||
ItemEvent.StartUsingItem event = new ItemEvent.StartUsingItem(handler, player, duration);
|
||||
handler.callScript(EnumScriptType.START_USING_ITEM, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.START_USING_ITEM, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
|
||||
ItemEvent.UsingItem event = new ItemEvent.UsingItem(handler, player, duration);
|
||||
handler.callScript(EnumScriptType.USING_ITEM, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.USING_ITEM, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onStopUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
|
||||
ItemEvent.StopUsingItem event = new ItemEvent.StopUsingItem(handler, player, duration);
|
||||
handler.callScript(EnumScriptType.STOP_USING_ITEM, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.STOP_USING_ITEM, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onFinishUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
|
||||
ItemEvent.FinishUsingItem event = new ItemEvent.FinishUsingItem(handler, player, duration);
|
||||
handler.callScript(EnumScriptType.FINISH_USING_ITEM, event);
|
||||
((ScriptCustomItem) handler).callScript(EnumScriptType.FINISH_USING_ITEM, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.api.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
|
||||
public class NBTTags {
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.swing.GuiJTextArea;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.api.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import noppes.npcs.controllers.data.NPCDataScript;
|
||||
|
||||
@@ -18,7 +18,7 @@ import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.api.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.api.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.entity.ScriptNpc;
|
||||
|
||||
@@ -19,7 +19,6 @@ import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.api.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
public class ForgeDataScript implements IScriptHandler {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
|
||||
public interface IScriptHandler {
|
||||
void callScript(EnumScriptType var1, Event var2);
|
||||
|
||||
boolean isClient();
|
||||
|
||||
boolean getEnabled();
|
||||
|
||||
void setEnabled(boolean var1);
|
||||
|
||||
String getLanguage();
|
||||
|
||||
void setLanguage(String var1);
|
||||
|
||||
List<ScriptContainer> getScripts();
|
||||
|
||||
String noticeString();
|
||||
|
||||
Map<Long, String> getConsoleText();
|
||||
|
||||
void clearConsole();
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import net.minecraft.util.math.BlockPos;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.api.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
@@ -16,7 +16,6 @@ import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.api.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
|
||||
@@ -49,15 +49,15 @@ public class PlayerItemGiverData implements IPlayerItemGiverData {
|
||||
}
|
||||
|
||||
public long getTime(IJobItemGiver jobItemGiver){
|
||||
return itemgivers.get(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId);
|
||||
return itemgivers.get(((JobItemGiver) jobItemGiver).itemGiverId);
|
||||
}
|
||||
|
||||
public void setTime(IJobItemGiver jobItemGiver, long day) {
|
||||
itemgivers.put(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId, day);
|
||||
itemgivers.put(((JobItemGiver) jobItemGiver).itemGiverId, day);
|
||||
}
|
||||
|
||||
public boolean hasInteractedBefore(IJobItemGiver jobItemGiver) {
|
||||
return itemgivers.containsKey(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId);
|
||||
return itemgivers.containsKey(((JobItemGiver) jobItemGiver).itemGiverId);
|
||||
}
|
||||
|
||||
public IJobItemGiver[] getItemGivers() {
|
||||
|
||||
@@ -3,10 +3,11 @@ package noppes.npcs.scripted;
|
||||
import net.minecraft.entity.passive.EntityTameable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.IPixelmonPlayerData;
|
||||
import noppes.npcs.controllers.PixelmonHelper;
|
||||
import noppes.npcs.scripted.entity.ScriptPixelmon;
|
||||
|
||||
public class ScriptPixelmonPlayerData {
|
||||
public class ScriptPixelmonPlayerData implements IPixelmonPlayerData {
|
||||
private EntityPlayerMP player;
|
||||
public ScriptPixelmonPlayerData(EntityPlayerMP player){
|
||||
this.player = player;
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.scoreboard.IScoreboard;
|
||||
import noppes.npcs.blocks.tiles.TileBigSign;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
@@ -878,7 +879,7 @@ public class ScriptWorld implements IWorld {
|
||||
return this.spawnClone(pos.getX(),pos.getY(),pos.getZ(),tab,name);
|
||||
}
|
||||
|
||||
public ScriptScoreboard getScoreboard(){
|
||||
public IScoreboard getScoreboard(){
|
||||
return new ScriptScoreboard();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EntityDamageSource;
|
||||
import net.minecraft.util.Vec3;
|
||||
import noppes.npcs.api.IDamageSource;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.ScriptDamageSource;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
@@ -49,7 +50,7 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
|
||||
entity.attackEntityFrom(new EntityDamageSource(source.getTypeName(),source.getMCEntity()),damage);
|
||||
}
|
||||
|
||||
public void hurt(float damage, ScriptDamageSource damageSource) {
|
||||
public void hurt(float damage, IDamageSource damageSource) {
|
||||
entity.attackEntityFrom(damageSource.getMCDamageSource(),damage);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.util.UUID;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.jobs.IJob;
|
||||
import noppes.npcs.api.roles.IRole;
|
||||
import noppes.npcs.constants.EnumAnimation;
|
||||
import noppes.npcs.constants.EnumJobType;
|
||||
import noppes.npcs.constants.EnumNavType;
|
||||
@@ -331,7 +333,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
/**
|
||||
* @return Returns the npcs current role
|
||||
*/
|
||||
public ScriptRoleInterface getRole(){
|
||||
public IRole getRole(){
|
||||
if(npc.advanced.role == EnumRoleType.Bank)
|
||||
return new ScriptRoleBank(npc);
|
||||
else if(npc.advanced.role == EnumRoleType.Follower)
|
||||
@@ -357,7 +359,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
/**
|
||||
* @return Returns the npcs current job
|
||||
*/
|
||||
public ScriptJobInterface getJob(){
|
||||
public IJob getJob(){
|
||||
if(npc.advanced.job == EnumJobType.Bard)
|
||||
return new ScriptJobBard(npc);
|
||||
else if(npc.advanced.job == EnumJobType.Conversation)
|
||||
|
||||
@@ -663,7 +663,7 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
* Requires pixelmon to be installed
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
public ScriptPixelmonPlayerData getPixelmonData(){
|
||||
public IPixelmonPlayerData getPixelmonData(){
|
||||
if(!PixelmonHelper.Enabled)
|
||||
return null;
|
||||
return new ScriptPixelmonPlayerData(player);
|
||||
|
||||
@@ -15,6 +15,14 @@ public class CustomGuiEvent extends Event {
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
public IPlayer getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public ICustomGui getGui() {
|
||||
return gui;
|
||||
}
|
||||
|
||||
public static class ButtonEvent extends CustomGuiEvent {
|
||||
public final int buttonId;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import noppes.npcs.api.AbstractNpcAPI;
|
||||
import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.handler.data.INaturalSpawn;
|
||||
|
||||
public class CustomNPCsEvent extends Event{
|
||||
public class CustomNPCsEvent extends Event implements noppes.npcs.api.event.CustomNPCsEvent {
|
||||
public final AbstractNpcAPI API = AbstractNpcAPI.Instance();
|
||||
|
||||
public CustomNPCsEvent() {
|
||||
@@ -24,7 +24,7 @@ public class CustomNPCsEvent extends Event{
|
||||
public boolean isCancelled(){return this.isCanceled();}
|
||||
|
||||
@Cancelable
|
||||
public static class CNPCNaturalSpawnEvent extends CustomNPCsEvent {
|
||||
public static class CNPCNaturalSpawnEvent extends CustomNPCsEvent implements noppes.npcs.api.event.CustomNPCsEvent.CNPCNaturalSpawnEvent {
|
||||
public final INaturalSpawn naturalSpawn;
|
||||
public final IPos attemptPosition;
|
||||
public final boolean animalSpawnPassed;
|
||||
@@ -41,5 +41,29 @@ public class CustomNPCsEvent extends Event{
|
||||
this.liquidSpawnPassed = liquidSpawnPassed;
|
||||
this.airSpawnPassed = airSpawnPassed;
|
||||
}
|
||||
|
||||
public INaturalSpawn getNaturalSpawn() {
|
||||
return this.naturalSpawn;
|
||||
}
|
||||
|
||||
public IPos getAttemptPosition() {
|
||||
return this.attemptPosition;
|
||||
}
|
||||
|
||||
public boolean animalSpawnPassed() {
|
||||
return this.animalSpawnPassed;
|
||||
}
|
||||
|
||||
public boolean monsterSpawnPassed() {
|
||||
return this.monsterSpawnPassed;
|
||||
}
|
||||
|
||||
public boolean liquidSpawnPassed() {
|
||||
return this.liquidSpawnPassed;
|
||||
}
|
||||
|
||||
public boolean airSpawnPassed() {
|
||||
return this.airSpawnPassed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.api.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
|
||||
@@ -9,11 +9,12 @@ import net.minecraft.scoreboard.ScoreObjective;
|
||||
import net.minecraft.scoreboard.ScorePlayerTeam;
|
||||
import net.minecraft.scoreboard.Scoreboard;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.api.scoreboard.IScoreboard;
|
||||
|
||||
/**
|
||||
* @author Karel
|
||||
*/
|
||||
public class ScriptScoreboard {
|
||||
public class ScriptScoreboard implements IScoreboard {
|
||||
private Scoreboard board;
|
||||
|
||||
public ScriptScoreboard(){
|
||||
|
||||
Reference in new issue
Block a user