mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 01:27:27 +00:00
Brush Editor
This commit is contained in:
1 parent
16f2901fbc
commit
cb2c7910cf
13 files changed
+274
-19
No files matched your search
@@ -37,6 +37,7 @@ import kamkeel.npcs.network.packets.request.effects.EffectSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.effects.EffectsGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.faction.*;
|
||||
import kamkeel.npcs.network.packets.request.feather.DimensionTeleportPacket;
|
||||
import kamkeel.npcs.network.packets.request.item.ColorSetPacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerAddPacket;
|
||||
@@ -307,6 +308,9 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new MovingPathSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MovingPathGetPacket());
|
||||
|
||||
// Tool Packets
|
||||
REQUEST_PACKET.registerPacket(new ColorSetPacket());
|
||||
|
||||
// Custom Effect Packets
|
||||
REQUEST_PACKET.registerPacket(new EffectGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new EffectsGetPacket());
|
||||
|
||||
@@ -87,6 +87,13 @@ public class PacketUtil {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BRUSH:
|
||||
if (item.getItem() != CustomItems.tool || item.getItemDamage() != 1) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Pather, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -141,6 +148,8 @@ public class PacketUtil {
|
||||
return !(item.getItem() == Item.getItemFromBlock(CustomItems.waypoint)
|
||||
|| item.getItem() == Item.getItemFromBlock(CustomItems.border)
|
||||
|| item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock));
|
||||
case BRUSH:
|
||||
return item.getItem() == CustomItems.tool && item.getItemDamage() == 1;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -176,6 +185,8 @@ public class PacketUtil {
|
||||
return "Pather";
|
||||
case BLOCK:
|
||||
return "valid Block";
|
||||
case BRUSH:
|
||||
return "Paintbrush";
|
||||
default:
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
@@ -7,5 +7,6 @@ public enum EnumItemPacketType {
|
||||
TELEPORTER,
|
||||
SCRIPTER,
|
||||
PATHER,
|
||||
BLOCK
|
||||
BLOCK,
|
||||
BRUSH
|
||||
}
|
||||
@@ -177,4 +177,6 @@ public enum EnumRequestPacket {
|
||||
EffectScriptGet,
|
||||
EffectRemove,
|
||||
EffectSave,
|
||||
|
||||
ColorSet,
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package kamkeel.npcs.network.packets.request.item;
|
||||
|
||||
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.CustomNpcsPermissions;
|
||||
import noppes.npcs.controllers.LinkedNpcController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ColorSetPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ColorSet";
|
||||
|
||||
private int color;
|
||||
|
||||
public ColorSetPacket(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public ColorSetPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ColorSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_BUILD;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(this.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.BRUSH, player))
|
||||
return;
|
||||
|
||||
int color = in.readInt();
|
||||
ItemStack stack = player.getHeldItem();
|
||||
setBrushColor(stack, color);
|
||||
}
|
||||
|
||||
public static void setBrushColor(ItemStack brush, int color){
|
||||
NBTTagCompound brushCompound = brush.getTagCompound();
|
||||
if(brushCompound == null)
|
||||
brushCompound = new NBTTagCompound();
|
||||
|
||||
brushCompound.setInteger("Color", color);
|
||||
brush.setTagCompound(brushCompound);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,10 @@ import java.util.List;
|
||||
public class CustomNpcsPermissions{
|
||||
// Open GUI
|
||||
public static final Permission NPC_GUI = new Permission("customnpcs.npc.gui");
|
||||
public static final Permission PAINTBRUSH_GUI = new Permission("customnpcs.npc.paintbrush");
|
||||
|
||||
// Builder
|
||||
public static final Permission NPC_BUILD = new Permission("customnpcs.npc.build");
|
||||
|
||||
// Modify NPC
|
||||
public static final Permission NPC_DELETE = new Permission("customnpcs.npc.delete");
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ReportedException;
|
||||
@@ -43,6 +44,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.GuiNpcPaintbrush;
|
||||
import noppes.npcs.client.gui.mainmenu.*;
|
||||
import noppes.npcs.client.gui.player.*;
|
||||
import noppes.npcs.client.gui.player.companion.GuiNpcCompanionInv;
|
||||
@@ -57,6 +59,7 @@ import noppes.npcs.client.model.*;
|
||||
import noppes.npcs.client.renderer.*;
|
||||
import noppes.npcs.client.renderer.blocks.*;
|
||||
import noppes.npcs.client.renderer.items.CustomItemRenderer;
|
||||
import noppes.npcs.client.renderer.items.NpcItemToolRenderer;
|
||||
import noppes.npcs.client.renderer.items.ScriptedBlockItemRenderer;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
@@ -68,6 +71,7 @@ import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.entity.*;
|
||||
import noppes.npcs.entity.data.ModelData;
|
||||
import noppes.npcs.entity.data.ModelPartData;
|
||||
import noppes.npcs.items.ItemNpcTool;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import tconstruct.client.tabs.InventoryTabCustomNpc;
|
||||
@@ -409,6 +413,9 @@ public class ClientProxy extends CommonProxy {
|
||||
else if (gui == EnumGuiType.ScriptBlock)
|
||||
return new GuiScriptBlock(x,y,z);
|
||||
|
||||
else if (gui == EnumGuiType.Paintbrush)
|
||||
return new GuiNpcPaintbrush();
|
||||
|
||||
else if (gui == EnumGuiType.GlobalRemote)
|
||||
return new GuiNPCGlobalMainMenu(null);
|
||||
|
||||
@@ -523,7 +530,9 @@ public class ClientProxy extends CommonProxy {
|
||||
public void registerItem(Item item) {
|
||||
if (item instanceof ItemScripted) {
|
||||
MinecraftForgeClient.registerItemRenderer(item, new CustomItemRenderer());
|
||||
} else {
|
||||
} else if (item instanceof ItemNpcTool) {
|
||||
MinecraftForgeClient.registerItemRenderer(item, new NpcItemToolRenderer());
|
||||
}else {
|
||||
MinecraftForgeClient.registerItemRenderer(item, new NpcItemRenderer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
package noppes.npcs.client.gui.item;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.item.ColorSetPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class GuiNpcPaintbrush extends GuiNPCInterface {
|
||||
|
||||
private GuiNpcTextField textfield;
|
||||
private int color = 0xffffff; // default color
|
||||
private int colorX, colorY;
|
||||
private static final ResourceLocation resource = new ResourceLocation("customnpcs:textures/gui/color.png");
|
||||
|
||||
public GuiNpcPaintbrush() {
|
||||
super();
|
||||
xSize = 256;
|
||||
setBackground("menubg.png");
|
||||
|
||||
ItemStack brush = this.player.getHeldItem();
|
||||
if(brush == null)
|
||||
return;
|
||||
|
||||
NBTTagCompound compound = brush.getTagCompound();
|
||||
if(compound != null && compound.hasKey("Color"))
|
||||
color = compound.getInteger("Color");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
// Move the color picker slightly more to the left.
|
||||
colorX = guiLeft + 20; // was guiLeft + 30
|
||||
colorY = guiTop + 50;
|
||||
|
||||
// Add the hex color text field, also moved left accordingly.
|
||||
this.addTextField(textfield = new GuiNpcTextField(0, this, guiLeft + 43, guiTop + 20, 70, 20, getColor()));
|
||||
textfield.setTextColor(color);
|
||||
|
||||
// Move the done button to the bottom right.
|
||||
int margin = 10;
|
||||
addButton(new GuiNpcButton(66, guiLeft + xSize - 55 - margin, guiTop + ySize - 20 - margin, 60, 20, "gui.done"));
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
String str = Integer.toHexString(color);
|
||||
while (str.length() < 6)
|
||||
str = "0" + str;
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
String prev = textfield.getText();
|
||||
super.keyTyped(c, i);
|
||||
String newText = textfield.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
try {
|
||||
color = Integer.parseInt(newText, 16);
|
||||
textfield.setTextColor(color);
|
||||
} catch (NumberFormatException e) {
|
||||
textfield.setText(prev);
|
||||
}
|
||||
}
|
||||
if (i == 1) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
if (guibutton.id == 66) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
PacketClient.sendClient(new ColorSetPacket(this.color));
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int i, int j, int k) {
|
||||
super.mouseClicked(i, j, k);
|
||||
if (i < colorX || i > colorX + 117 || j < colorY || j > colorY + 117)
|
||||
return;
|
||||
|
||||
InputStream stream = null;
|
||||
try {
|
||||
IResource iresource = this.mc.getResourceManager().getResource(resource);
|
||||
stream = iresource.getInputStream();
|
||||
BufferedImage bufferedimage = ImageIO.read(stream);
|
||||
|
||||
// Calculate the corresponding pixel on the texture (scaling factor 4)
|
||||
int imgX = (i - guiLeft - 20) * 4;
|
||||
int imgY = (j - guiTop - 50) * 4;
|
||||
color = bufferedimage.getRGB(imgX, imgY) & 0xFFFFFF;
|
||||
textfield.setTextColor(color);
|
||||
textfield.setText(getColor());
|
||||
} catch (IOException e) {
|
||||
// Optionally log the error here
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore quietly
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
super.drawScreen(par1, par2, par3);
|
||||
|
||||
// Draw the color picker on the left side
|
||||
mc.getTextureManager().bindTexture(resource);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
drawTexturedModalRect(colorX, colorY, 0, 0, 120, 120);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Implement save functionality if needed.
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import noppes.npcs.items.ItemNpcTool;
|
||||
import noppes.npcs.items.ItemRenderInterface;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
@@ -16,8 +17,8 @@ import org.lwjgl.opengl.GL12;
|
||||
public class NpcItemToolRenderer implements IItemRenderer {
|
||||
|
||||
// Textures for the assembled paintbrush parts:
|
||||
private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("noppes", "textures/items/paintbrush_handle.png");
|
||||
private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("noppes", "textures/items/paintbrush_brush.png");
|
||||
private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/paintbrush_handle.png");
|
||||
private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/paintbrush_brush.png");
|
||||
private static final ResourceLocation ENCHANT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
|
||||
|
||||
@Override
|
||||
@@ -34,25 +35,17 @@ public class NpcItemToolRenderer implements IItemRenderer {
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
// Ensure the item implements our render interface
|
||||
if (!(item.getItem() instanceof ItemRenderInterface))
|
||||
if (!(item.getItem() instanceof ItemNpcTool))
|
||||
return;
|
||||
|
||||
EntityLivingBase entity = (EntityLivingBase) data[1];
|
||||
|
||||
GL11.glPushMatrix();
|
||||
// Apply base translations/rotations
|
||||
GL11.glTranslatef(0.9375F, 0.0625F, 0.0F);
|
||||
GL11.glRotatef(-315.0F, 0.0F, 0.0F, 1.0F);
|
||||
|
||||
// For meta==1 (paintbrush) we want to assemble the texture from two parts
|
||||
if (item.getItemDamage() == 1) {
|
||||
renderPaintbrush(entity, item);
|
||||
} else {
|
||||
// For other tools, fall back on the normal special render routine.
|
||||
((ItemRenderInterface) item.getItem()).renderSpecial();
|
||||
GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F);
|
||||
GL11.glRotatef(-50.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glTranslatef(-0.09375F, 0.0625F, 0.0F);
|
||||
renderItem3d(entity, item);
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
|
||||
@@ -66,5 +66,6 @@ public enum EnumGuiType {
|
||||
ManageLinked,
|
||||
CustomGui,
|
||||
ScriptItem,
|
||||
ScriptBlock;
|
||||
ScriptBlock,
|
||||
Paintbrush;
|
||||
}
|
||||
@@ -12,6 +12,9 @@ import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,6 +33,7 @@ public class ItemNpcTool extends Item {
|
||||
setHasSubtypes(true);
|
||||
setMaxDamage(0);
|
||||
setCreativeTab(CustomItems.tab);
|
||||
CustomNpcs.proxy.registerItem(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,15 +71,26 @@ public class ItemNpcTool extends Item {
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
if(world.isRemote) {
|
||||
int meta = stack.getItemDamage();
|
||||
if(meta < 0 || meta >= toolTypes.length) meta = 0;
|
||||
// Send a simple chat message indicating which tool was used
|
||||
player.addChatMessage(new ChatComponentTranslation("item.npc_tool." + toolTypes[meta] + ".use"));
|
||||
if(!world.isRemote)
|
||||
return stack;
|
||||
|
||||
if(player.isSneaking() && isPaintbrush(stack)){
|
||||
|
||||
} else if(isPaintbrush(stack)){
|
||||
|
||||
}
|
||||
if(CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.PAINTBRUSH_GUI)){
|
||||
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.Paintbrush, player);
|
||||
}
|
||||
else
|
||||
player.addChatMessage(new ChatComponentTranslation("item.npc_tool." + toolTypes[stack.getItemDamage()] + ".use"));
|
||||
return stack;
|
||||
}
|
||||
|
||||
public boolean isPaintbrush(ItemStack itemStack){
|
||||
return itemStack.getItemDamage() == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item setUnlocalizedName(String name){
|
||||
GameRegistry.registerItem(this, name);
|
||||
|
||||
Reference in new issue
Block a user