Brush Editor

This commit is contained in:
Kam committed 2025-02-13 02:09:50 -05:00
1 parent 16f2901fbc
commit cb2c7910cf
13 files changed
+274 -19

No files matched your search

@@ -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();