Added a function to create an item stack from a linked item in the LinkedItem class, referenced in the controller and creation packet as well.

This commit is contained in:
Luis C.M. committed 2025-02-17 17:26:40 -06:00
1 parent 5c04b1aae6
commit f62ff8a474
3 files changed
+25 -6

No files matched your search

@@ -64,14 +64,11 @@ public final class LinkedItemBuildPacket extends AbstractPacket {
return;
int id = in.readInt();
LinkedItem original = LinkedItemController.getInstance().get(id);
if(original == null)
LinkedItem linkedItem = LinkedItemController.getInstance().get(id);
if(linkedItem == null)
return;
LinkedItem copy = original.clone();
EntityPlayerMP playerMP = (EntityPlayerMP) player;
ItemStack stack = new ItemStack(CustomItems.linked_item, 1);
ScriptLinkedItem scriptLinkedItem = new ScriptLinkedItem(stack, copy);
playerMP.inventory.addItemStackToInventory(scriptLinkedItem.item);
playerMP.inventory.addItemStackToInventory(linkedItem.createStack().getMCItemStack());
}
}
@@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.handler.data.ILinkedItem;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.data.*;
import noppes.npcs.util.NBTJsonUtil;
@@ -34,6 +35,14 @@ public class LinkedItemController {
return new LinkedItem(name);
}
public IItemStack createItemStack(int id) {
LinkedItem linkedItem = this.get(id);
if (linkedItem != null) {
return linkedItem.createStack();
}
return null;
}
public void add(LinkedItem linkedItem) {
if (linkedItem != null) {
String name = linkedItem.getName();
@@ -1,10 +1,16 @@
package noppes.npcs.controllers.data;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.CustomItems;
import noppes.npcs.api.handler.data.ILinkedItem;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.CustomEffectController;
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";
@@ -35,6 +41,13 @@ 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());
}