mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 06:24:42 +00:00
Magic Book Item + Magic Player Packets
This commit is contained in:
1 parent
62046b10e6
commit
3e10207b41
19 files changed
+466
-18
No files matched your search
@@ -41,7 +41,7 @@ public class CustomNpcsPermissions {
|
||||
|
||||
public static final Permission GLOBAL_REMOTE = new Permission("customnpcs.global.remote");
|
||||
|
||||
// Save Globel Preferences
|
||||
// Save Global Preferences
|
||||
public static final Permission GLOBAL_LINKED = new Permission("customnpcs.global.linked");
|
||||
public static final Permission GLOBAL_PLAYERDATA = new Permission("customnpcs.global.playerdata");
|
||||
public static final Permission GLOBAL_BANK = new Permission("customnpcs.global.bank");
|
||||
|
||||
@@ -706,15 +706,15 @@ public class NoppesUtilServer {
|
||||
public static void sendMagicInfo(EntityPlayerMP player, boolean cycles) {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
if (cycles) {
|
||||
for (Magic magic : MagicController.getInstance().magics.values()) {
|
||||
map.put(magic.name, magic.id);
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.MAGIC);
|
||||
} else {
|
||||
for (MagicCycle magicCycle : MagicController.getInstance().cycles.values()) {
|
||||
map.put(magicCycle.name, magicCycle.id);
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.MAGIC_CYCLES);
|
||||
} else {
|
||||
for (Magic magic : MagicController.getInstance().magics.values()) {
|
||||
map.put(magic.name, magic.id);
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.MAGIC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import noppes.npcs.client.fx.EntityRainbowFX;
|
||||
import noppes.npcs.client.gui.*;
|
||||
import noppes.npcs.client.gui.custom.GuiCustom;
|
||||
import noppes.npcs.client.gui.global.*;
|
||||
import noppes.npcs.client.gui.item.GuiNpcMagicBook;
|
||||
import noppes.npcs.client.gui.item.GuiNpcPaintbrush;
|
||||
import noppes.npcs.client.gui.mainmenu.*;
|
||||
import noppes.npcs.client.gui.player.*;
|
||||
@@ -422,6 +423,9 @@ public class ClientProxy extends CommonProxy {
|
||||
else if (gui == EnumGuiType.Paintbrush)
|
||||
return new GuiNpcPaintbrush();
|
||||
|
||||
else if (gui == EnumGuiType.MagicBook)
|
||||
return new GuiNpcMagicBook();
|
||||
|
||||
else if (gui == EnumGuiType.GlobalRemote)
|
||||
return new GuiNPCGlobalMainMenu(null);
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package noppes.npcs.client.gui.item;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.item.MagicCyclesPacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicGetPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.gui.GuiMagicCycleMap;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumScrollData;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class GuiNpcMagicBook extends GuiNPCInterface implements ICustomScrollListener, IScrollData, IGuiData {
|
||||
|
||||
private MagicCycle magicCycle;
|
||||
private GuiMagicCycleMap magicMap;
|
||||
private GuiCustomScroll leftScroll;
|
||||
public HashMap<String, Integer> cycleData = new HashMap<>();
|
||||
|
||||
public GuiNpcMagicBook() {
|
||||
super();
|
||||
xSize = 350;
|
||||
setBackground("menubg.png");
|
||||
closeOnEsc = true;
|
||||
MagicCyclesPacket.GetAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int spacing = 10;
|
||||
int scrollWidth = 120;
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "menu.cycles", guiLeft + 14, guiTop + 10, 0xFFFFFF));
|
||||
|
||||
// --- Left Scroll List ---
|
||||
leftScroll = new GuiCustomScroll(this, 0, 0);
|
||||
leftScroll.guiLeft = guiLeft + spacing;
|
||||
leftScroll.guiTop = guiTop + 22;
|
||||
leftScroll.setSize(scrollWidth, ySize - 32);
|
||||
leftScroll.setList(new ArrayList<>(cycleData.keySet()));
|
||||
addScroll(leftScroll);
|
||||
|
||||
// --- Magic Map (Diagram) on the Right ---
|
||||
if(magicCycle == null)
|
||||
return;
|
||||
|
||||
String displayName = magicCycle.getDisplayName().replace("&", "\u00A7");
|
||||
leftScroll.setSelected(displayName);
|
||||
|
||||
|
||||
int mapX = guiLeft + scrollWidth + 2 * spacing;
|
||||
int mapY = guiTop + 22;
|
||||
int mapWidth = xSize - (scrollWidth + 3 * spacing);
|
||||
int mapHeight = ySize - 32;
|
||||
magicMap = new GuiMagicCycleMap(this, mapX, mapY, mapWidth, mapHeight, magicCycle);
|
||||
addDiagram(0, magicMap);
|
||||
|
||||
int labelY = guiTop + 10;
|
||||
int textWidth = fontRendererObj.getStringWidth(displayName);
|
||||
int labelX = mapX + (mapWidth / 2) - (textWidth / 2);
|
||||
GuiNpcLabel magicLabel = new GuiNpcLabel(1, displayName, labelX, labelY, CustomNpcResourceListener.DefaultTextColor);
|
||||
addLabel(magicLabel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (i == 1) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton guibutton) {}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int i, int j, float f) {
|
||||
super.drawScreen(i, j, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(){
|
||||
super.drawBackground();
|
||||
|
||||
int spacing = 10;
|
||||
int scrollWidth = 120;
|
||||
int barHeight = 16; // Same height as the magic map bar
|
||||
int barY = guiTop + 22 - barHeight - 1;
|
||||
|
||||
// Draw dark rectangle above the left scroll (same width as left scroll)
|
||||
if (leftScroll != null) {
|
||||
int leftRectX = guiLeft + spacing;
|
||||
drawRect(leftRectX, barY, leftRectX + scrollWidth, barY + barHeight, 0xFF333333);
|
||||
}
|
||||
|
||||
// Draw dark rectangle above the magic map
|
||||
if (magicMap != null) {
|
||||
int mapX = guiLeft + scrollWidth + 2 * spacing;
|
||||
int mapWidth = xSize - (scrollWidth + 3 * spacing);
|
||||
drawRect(mapX, barY, mapX + mapWidth, barY + barHeight, 0xFF333333);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
if (magicMap != null) {
|
||||
magicMap.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
if (magicMap != null) {
|
||||
magicMap.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Implement save logic if needed.
|
||||
}
|
||||
|
||||
// --- ICustomScrollListener Methods ---
|
||||
@Override
|
||||
public void customScrollClicked(int id, int index, int clickType, GuiCustomScroll scroll) {
|
||||
if (scroll == leftScroll) {
|
||||
String selectedName = scroll.getSelected();
|
||||
MagicCyclesPacket.GetCycle(cycleData.get(selectedName));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
// Handle double-click if necessary.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if(type == EnumScrollData.MAGIC_CYCLES){
|
||||
cycleData.clear();
|
||||
cycleData.putAll(data);
|
||||
if (leftScroll != null) {
|
||||
leftScroll.setList(new ArrayList<>(cycleData.keySet()));
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if (compound.hasKey("MagicCycle")) {
|
||||
magicCycle = new MagicCycle();
|
||||
magicCycle.readNBT(compound.getCompoundTag("MagicCycle"));
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public class GuiNpcLabel {
|
||||
public int x, y, color;
|
||||
public boolean enabled = true;
|
||||
public int id;
|
||||
public boolean drawShadow = false;
|
||||
|
||||
public GuiNpcLabel(int id, Object label, int x, int y, int color) {
|
||||
this.id = id;
|
||||
@@ -26,7 +27,7 @@ public class GuiNpcLabel {
|
||||
|
||||
public void drawLabel(GuiScreen gui, FontRenderer fontRenderer) {
|
||||
if (enabled)
|
||||
fontRenderer.drawString(label, x, y, color);
|
||||
fontRenderer.drawString(label, x, y, color, drawShadow);
|
||||
}
|
||||
|
||||
public void center(int width) {
|
||||
|
||||
@@ -27,6 +27,7 @@ public class ItemToolRenderer implements IItemRenderer {
|
||||
private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png");
|
||||
private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png");
|
||||
private static final ResourceLocation HAMMER = new ResourceLocation("customnpcs", "textures/items/npcToolHammer.png");
|
||||
private static final ResourceLocation MAGIC_BOOK = new ResourceLocation("customnpcs", "textures/items/npcToolMagicBook.png");
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@@ -77,8 +78,10 @@ public class ItemToolRenderer implements IItemRenderer {
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
GL11.glColor3f(red, green, blue);
|
||||
renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_BRUSH);
|
||||
} else {
|
||||
} else if (itemStack.getItemDamage() == 0){
|
||||
renderEntityCustomItem(itemStack, entityItem, HAMMER);
|
||||
} else if (itemStack.getItemDamage() == 2){
|
||||
renderEntityCustomItem(itemStack, entityItem, MAGIC_BOOK);
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
return;
|
||||
@@ -111,10 +114,14 @@ public class ItemToolRenderer implements IItemRenderer {
|
||||
GL11.glPushMatrix();
|
||||
renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_BRUSH);
|
||||
GL11.glPopMatrix();
|
||||
} else {
|
||||
} else if (itemStack.getItemDamage() == 0){
|
||||
GL11.glPushMatrix();
|
||||
renderItem3d(entityLivingBase, itemStack, HAMMER);
|
||||
GL11.glPopMatrix();
|
||||
} else if (itemStack.getItemDamage() == 2){
|
||||
GL11.glPushMatrix();
|
||||
renderItem3d(entityLivingBase, itemStack, MAGIC_BOOK);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
@@ -290,9 +297,12 @@ public class ItemToolRenderer implements IItemRenderer {
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
textureManager.bindTexture(PAINTBRUSH_BRUSH);
|
||||
renderCustomItemSlot(0, 0, 16, 16, red, green, blue);
|
||||
} else {
|
||||
} else if (itemStack.getItemDamage() == 0){
|
||||
textureManager.bindTexture(HAMMER);
|
||||
renderCustomItemSlot(0, 0, 16, 16, 1.0f, 1.0f, 1.0f);
|
||||
} else if (itemStack.getItemDamage() == 2){
|
||||
textureManager.bindTexture(MAGIC_BOOK);
|
||||
renderCustomItemSlot(0, 0, 16, 16, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
@@ -62,5 +62,6 @@ public enum EnumGuiType {
|
||||
CustomGui,
|
||||
ScriptItem,
|
||||
ScriptBlock,
|
||||
Paintbrush;
|
||||
Paintbrush,
|
||||
MagicBook;
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package noppes.npcs.items;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.item.GuiMagicBookPacket;
|
||||
import kamkeel.npcs.network.packets.player.item.GuiPaintbrushPacket;
|
||||
import kamkeel.npcs.network.packets.request.item.ColorBrushPacket;
|
||||
import kamkeel.npcs.network.packets.request.item.ColorSetPacket;
|
||||
import kamkeel.npcs.network.packets.request.item.HammerPacket;
|
||||
@@ -32,7 +34,7 @@ public class ItemNpcTool extends Item {
|
||||
|
||||
// Define our tool types based on metadata:
|
||||
// meta 0: Hammer, meta 1: Paintbrush, meta 2: Wrench
|
||||
public static final String[] toolTypes = new String[]{"hammer", "paintbrush"};
|
||||
public static final String[] toolTypes = new String[]{"hammer", "paintbrush", "magic_book"};
|
||||
public static String BRUSH_COLOR_TAG = "BrushColor";
|
||||
|
||||
public ItemNpcTool() {
|
||||
@@ -62,13 +64,18 @@ public class ItemNpcTool extends Item {
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
if (world.isRemote)
|
||||
if (!world.isRemote)
|
||||
return stack;
|
||||
|
||||
if (isPaintbrush(stack) && player.isSneaking()) {
|
||||
if (CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.PAINTBRUSH_GUI)) {
|
||||
NoppesUtil.requestOpenGUI(EnumGuiType.Paintbrush);
|
||||
PacketClient.sendClient(new GuiPaintbrushPacket(EnumGuiType.Paintbrush.ordinal(), 0, 0, 0));
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
if (isMagicBook(stack)) {
|
||||
PacketClient.sendClient(new GuiMagicBookPacket(EnumGuiType.MagicBook.ordinal(), 0, 0, 0));
|
||||
return stack;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
@@ -145,6 +152,10 @@ public class ItemNpcTool extends Item {
|
||||
return itemStack.getItemDamage() == 0;
|
||||
}
|
||||
|
||||
public static boolean isMagicBook(ItemStack itemStack) {
|
||||
return itemStack.getItemDamage() == 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item setUnlocalizedName(String name) {
|
||||
GameRegistry.registerItem(this, name);
|
||||
|
||||
Reference in new issue
Block a user