LinkedItem Things

This commit is contained in:
Kam committed 2025-02-16 05:50:03 -05:00
1 parent eb8b5387ea
commit f51c636b79
6 files changed
+118 -6

No files matched your search

@@ -153,6 +153,7 @@ public class PacketHandler {
REQUEST_PACKET.registerPacket(new LinkedNPCAddPacket());
REQUEST_PACKET.registerPacket(new LinkedItemSavePacket());
REQUEST_PACKET.registerPacket(new LinkedItemRemovePacket());
REQUEST_PACKET.registerPacket(new LinkedItemBuildPacket());
// Bank Packets
@@ -180,5 +180,5 @@ public enum EnumRequestPacket {
EffectRemove,
EffectSave,
ColorSet, LinkedItemSave, LinkedItemRemove, ColorBrush
ColorSet, LinkedItemSave, LinkedItemRemove, LinkedItemBuild, ColorBrush
}
@@ -0,0 +1,77 @@
package kamkeel.npcs.network.packets.request.linked;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.data.LinkedItem;
import noppes.npcs.scripted.item.ScriptLinkedItem;
import java.io.IOException;
public final class LinkedItemBuildPacket extends AbstractPacket {
public static String packetName = "Request|LinkedItemBuild";
private int id;
public LinkedItemBuildPacket(){}
public LinkedItemBuildPacket(int id){
this.id = id;
}
@Override
public Enum getType() {
return EnumRequestPacket.LinkedItemBuild;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.GLOBAL_LINKED;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.id);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
return;
int id = in.readInt();
LinkedItem linkedItem = LinkedItemController.getInstance().get(id);
if(linkedItem == null)
return;
EntityPlayerMP playerMP = (EntityPlayerMP) player;
ItemStack stack = new ItemStack(CustomItems.linked_item, 1);
ScriptLinkedItem scriptLinkedItem = new ScriptLinkedItem(stack, linkedItem.writeToNBT());
scriptLinkedItem.linkedVersion = linkedItem.version;
scriptLinkedItem.saveItemData();
playerMP.inventory.addItemStackToInventory(stack.copy());
}
}
@@ -77,8 +77,10 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
this.addButton(new GuiNpcButton(3,guiLeft + 368, y += 22, 45, 20, "gui.edit"));
this.addButton(new GuiNpcButton(4,guiLeft + 368, y += 22, 45, 20, "gui.copy"));
this.addButton(new GuiNpcButton(5,guiLeft + 368, y += 22, 45, 20, "gui.build"));
getButton(3).enabled = tab == 1;
getButton(4).enabled = tab == 1;
getButton(5).enabled = tab == 1;
if(scroll == null){
scroll = new GuiCustomScroll(this,0,0);
@@ -234,6 +236,12 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
if(button.id == 3){
setSubGui(new SubGuiLinkedItem(this, this.linkedItem));
}
if(button.id == 5){
// Build Linked Item
if(tab == 1)
PacketClient.sendClient(new LinkedItemBuildPacket(this.linkedItem.getId()));
}
}
@Override
@@ -317,9 +325,6 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
if(!((SubGuiEditText)subgui).cancelled){
PacketClient.sendClient(new LinkedNPCAddPacket(((SubGuiEditText)subgui).text));
}
}
else if (subgui instanceof SubGuiLinkedItem){
}
}
@@ -18,7 +18,7 @@ import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.items.ItemCustomizable;
import noppes.npcs.scripted.NpcAPI;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@@ -142,7 +142,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glTranslatef(0.9375F, 0.0625F, 0.0F);
GL11.glRotatef(-315.0F, 0.0F, 0.0F, 1.0F);
((ItemScripted) itemStack.getItem()).renderOffset(scriptCustomItem);
((ItemCustomizable) itemStack.getItem()).renderOffset(scriptCustomItem);
if(scriptCustomItem.isNormalItem()){
GL11.glTranslatef(-0.05F, 0.3F, 0.3F);
GL11.glRotatef(50, 1, 0, 0);
@@ -16,6 +16,33 @@ public class ScriptLinkedItem extends ScriptCustomizableItem implements IItemLin
loadItemData();
}
// For Building
public ScriptLinkedItem(ItemStack item, NBTTagCompound linkedData) {
super(item);
setDefaults();
this.linkedItem = new LinkedItem();
this.linkedItem.readFromNBT(linkedData, false);
}
public void setDefaults(){
this.itemDisplay.texture = null;
this.itemDisplay.translateX = null;
this.itemDisplay.translateY = null;
this.itemDisplay.translateZ = null;
this.itemDisplay.itemColor = null;
this.itemDisplay.scaleX = null;
this.itemDisplay.scaleY = null;
this.itemDisplay.scaleZ = null;
this.itemDisplay.rotationX = null;
this.itemDisplay.rotationY = null;
this.itemDisplay.rotationZ = null;
this.itemDisplay.rotationXRate = null;
this.itemDisplay.rotationYRate = null;
this.itemDisplay.rotationZRate = null;
this.itemDisplay.durabilityShow = null;
this.itemDisplay.durabilityColor = null;
}
public LinkedItem getLinkedItem() {
return LinkedItemController.getInstance().get(this.linkedItem.getId());
}
@@ -175,6 +202,8 @@ public class ScriptLinkedItem extends ScriptCustomizableItem implements IItemLin
public void setItemNBT(NBTTagCompound compound) {
this.itemDisplay.readFromNBT(compound);
if(linkedItem == null)
this.linkedItem = new LinkedItem();
this.linkedItem.readFromNBT(compound, false);
this.linkedVersion = compound.getInteger(LinkedItem.LINKED_VERSION_VERSION_TAG);
}