mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 05:15:11 +00:00
Implemented version change and build events for linked items
This commit is contained in:
1 parent
f62ff8a474
commit
90bd8aeb02
6 files changed
+83
-13
No files matched your search
@@ -22,6 +22,7 @@ import noppes.npcs.api.gui.IItemSlot;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
import noppes.npcs.api.handler.data.IFrame;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.api.item.IItemLinked;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.CustomGuiController;
|
||||
@@ -146,6 +147,24 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onLinkedItemVersionChange(IItemLinked item, int version, int prevVersion) {
|
||||
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
|
||||
LinkedItemEvent.VersionChangeEvent event = new LinkedItemEvent.VersionChangeEvent(item, version, prevVersion);
|
||||
if (handler != null) {
|
||||
handler.callScript(EnumScriptType.LINKED_ITEM_VERSION, event);
|
||||
}
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onLinkedItemBuild(IItemLinked item) {
|
||||
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
|
||||
LinkedItemEvent.BuildEvent event = new LinkedItemEvent.BuildEvent(item);
|
||||
if (handler != null) {
|
||||
handler.callScript(EnumScriptType.LINKED_ITEM_BUILD, event);
|
||||
}
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onNPCInit(EntityNPCInterface npc) {
|
||||
if(npc == null || npc.wrappedNPC == null)
|
||||
return;
|
||||
|
||||
@@ -104,7 +104,10 @@ public enum EnumScriptType {
|
||||
ANIMATION_START("animationStart"),
|
||||
ANIMATION_END("animationEnd"),
|
||||
ANIMATION_FRAME_ENTER("frameEnter"),
|
||||
ANIMATION_FRAME_EXIT("frameExit");
|
||||
ANIMATION_FRAME_EXIT("frameExit"),
|
||||
|
||||
LINKED_ITEM_VERSION("versionChanged"),
|
||||
LINKED_ITEM_BUILD("buildingItem");
|
||||
|
||||
public String function;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
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.CustomEffectController;
|
||||
@@ -41,13 +42,6 @@ public class LinkedItem implements ILinkedItem {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public IItemStack createStack() {
|
||||
LinkedItem copy = this.clone();
|
||||
ItemStack stack = new ItemStack(CustomItems.linked_item, 1);
|
||||
ScriptLinkedItem scriptLinkedItem = new ScriptLinkedItem(stack, copy);
|
||||
return NpcAPI.Instance().getIItemStack(scriptLinkedItem.item);
|
||||
}
|
||||
|
||||
public LinkedItemScript getScriptHandler() {
|
||||
return (LinkedItemScript) LinkedItemController.getInstance().getScriptHandler(this.getId());
|
||||
}
|
||||
@@ -116,6 +110,14 @@ public class LinkedItem implements ILinkedItem {
|
||||
LinkedItemController.getInstance().linkedItemsScripts.put(this.id, handler);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.*;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
@@ -490,16 +491,15 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
if(scriptStack instanceof ScriptLinkedItem && CustomNpcs.side() == Side.SERVER){
|
||||
ScriptLinkedItem scriptLinkedItem = (ScriptLinkedItem) scriptStack;
|
||||
LinkedItem linkedItem = LinkedItemController.getInstance().get(scriptLinkedItem.linkedItem.getId());
|
||||
|
||||
int prevVersion = scriptLinkedItem.linkedVersion;
|
||||
if(linkedItem != null && scriptLinkedItem.linkedVersion != linkedItem.version){
|
||||
scriptLinkedItem.linkedItem = linkedItem.clone();
|
||||
scriptLinkedItem.linkedVersion = linkedItem.version;
|
||||
scriptLinkedItem.saveItemData();
|
||||
|
||||
// Send Version Change Event
|
||||
// TODO: Version Change Event
|
||||
|
||||
|
||||
|
||||
EventHooks.onLinkedItemVersionChange(scriptLinkedItem, linkedItem.version, prevVersion);
|
||||
} else if (linkedItem == null){
|
||||
// Destroy Linked Item
|
||||
scriptStack.item.stackSize = 0;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package noppes.npcs.scripted.event;
|
||||
|
||||
import noppes.npcs.api.event.ILinkedItemEvent;
|
||||
import noppes.npcs.api.item.IItemLinked;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
|
||||
public class LinkedItemEvent extends ItemEvent implements ILinkedItemEvent {
|
||||
|
||||
public LinkedItemEvent(IItemLinked item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
public static class VersionChangeEvent extends ItemEvent implements ILinkedItemEvent.VersionChangeEvent {
|
||||
public final int version, prevVersion;
|
||||
|
||||
public VersionChangeEvent(IItemLinked item, int version, int prevVersion) {
|
||||
super(item);
|
||||
this.version = version;
|
||||
this.prevVersion = prevVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreviousVersion() {
|
||||
return this.prevVersion;
|
||||
}
|
||||
|
||||
public String getHookName() {
|
||||
return EnumScriptType.LINKED_ITEM_VERSION.function;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BuildEvent extends ItemEvent implements ILinkedItemEvent.BuildEvent {
|
||||
public BuildEvent(IItemLinked item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
public String getHookName() {
|
||||
return EnumScriptType.LINKED_ITEM_BUILD.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user