Merge pull request #31 from c0508383/master

Increased NPC Inventory & Other Additions.
This commit is contained in:
Kamron Vaswani authored and GitHub committed 2022-01-31 16:27:15 -05:00
commit bc54e8cd7b
63 files changed
+2815 -216

No files matched your search

@@ -72,6 +72,9 @@ public class CustomNpcs {
@ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96.")
public static int NpcNavRange = 32;
@ConfigProp(info = "Size limit for NPCs. Default 100, larger sizes may cause lag on clients and servers that can't take it!")
public static int NpcSizeLimit = 100;
@ConfigProp(info = "Set to true if you want the dialog command option to be able to use op commands like tp etc")
public static boolean NpcUseOpCommands = false;
@@ -171,6 +174,9 @@ public class CustomNpcs {
NpcNavRange = 96;
}
if(NpcSizeLimit < 1)
NpcSizeLimit = 1;
EnchantInterface.load();
CustomItems.load();
@@ -133,6 +133,9 @@ public class DataDisplay {
glowTexture = nbttagcompound.getString("GlowTexture");
modelSize = ValueUtil.CorrectInt(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE);
if(modelSize > CustomNpcs.NpcSizeLimit)
modelSize = CustomNpcs.NpcSizeLimit;
modelType = nbttagcompound.getInteger("modelType");
showName = nbttagcompound.getInteger("ShowName");
+15 -5
View File
@@ -18,7 +18,7 @@ import noppes.npcs.entity.EntityNPCInterface;
public class DataInventory implements IInventory{
public HashMap<Integer,ItemStack> items = new HashMap<Integer,ItemStack>();
public HashMap<Integer,Integer> dropchance = new HashMap<Integer,Integer>();
public HashMap<Integer,Double> dropchance = new HashMap<Integer,Double>();
public HashMap<Integer, ItemStack> weapons = new HashMap<Integer, ItemStack>();
public HashMap<Integer, ItemStack> armor = new HashMap<Integer, ItemStack>();
@@ -38,7 +38,7 @@ public class DataInventory implements IInventory{
nbttagcompound.setTag("NpcInv", NBTTags.nbtItemStackList(items));
nbttagcompound.setTag("Armor", NBTTags.nbtItemStackList(getArmor()));
nbttagcompound.setTag("Weapons", NBTTags.nbtItemStackList(getWeapons()));
nbttagcompound.setTag("DropChance", NBTTags.nbtIntegerIntegerMap(dropchance));
nbttagcompound.setTag("DoubleDropChance", NBTTags.nbtIntegerDoubleMap(dropchance));
nbttagcompound.setInteger("LootMode", lootMode);
return nbttagcompound;
@@ -49,7 +49,17 @@ public class DataInventory implements IInventory{
items = NBTTags.getItemStackList(nbttagcompound.getTagList("NpcInv", 10));
setArmor(NBTTags.getItemStackList(nbttagcompound.getTagList("Armor", 10)));
setWeapons(NBTTags.getItemStackList(nbttagcompound.getTagList("Weapons", 10)));
dropchance = NBTTags.getIntegerIntegerMap(nbttagcompound.getTagList("DropChance", 10));
if(!nbttagcompound.hasKey("DoubleDropChance")) {
dropchance.clear();
HashMap<Integer, Integer> oldDropChance = NBTTags.getIntegerIntegerMap(nbttagcompound.getTagList("DropChance", 10));
for(int i = 0; i < oldDropChance.entrySet().size(); i++){
dropchance.put(i, Double.valueOf(oldDropChance.get(i)));
}
} else {
dropchance = NBTTags.getIntegerDoubleMap(nbttagcompound.getTagList("DoubleDropChance", 10));
}
lootMode = nbttagcompound.getInteger("LootMode");
}
public HashMap<Integer, ItemStack> getWeapons() {
@@ -89,10 +99,10 @@ public class DataInventory implements IInventory{
ItemStack item = items.get(i);
if(item == null)
continue;
int dchance = 100;
double dchance = 100;
if(dropchance.containsKey(i))
dchance = dropchance.get(i);
int chance = npc.worldObj.rand.nextInt(100) + dchance;
double chance = Math.random()*100 + dchance;
if(chance >= 100){
EntityItem e = getEntityItem(item.copy());
if(e != null)
+24
View File
@@ -69,6 +69,17 @@ public class NBTTags {
}
return list;
}
public static HashMap<Integer, Double> getIntegerDoubleMap(
NBTTagList tagList) {
HashMap<Integer, Double> list = new HashMap<Integer, Double>();
for(int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i);
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getDouble("Double"));
}
return list;
}
public static HashMap<Integer, Long> getIntegerLongMap(
NBTTagList tagList) {
@@ -239,6 +250,19 @@ public class NBTTags {
return nbttaglist;
}
public static NBTTagList nbtIntegerDoubleMap(HashMap<Integer, Double> lines) {
NBTTagList nbttaglist = new NBTTagList();
if(lines == null)
return nbttaglist;
for (int slot : lines.keySet()) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setInteger("Slot", slot);
nbttagcompound.setDouble("Double", lines.get(slot));
nbttaglist.appendTag(nbttagcompound);
}
return nbttaglist;
}
public static NBTTagList nbtIntegerLongMap(HashMap<Integer, Long> lines) {
NBTTagList nbttaglist = new NBTTagList();
if(lines == null)
@@ -21,7 +21,6 @@ import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
@@ -43,7 +42,6 @@ import noppes.npcs.items.ItemShield;
import noppes.npcs.items.ItemSoulstoneEmpty;
import noppes.npcs.quests.QuestKill;
import noppes.npcs.roles.RoleFollower;
import noppes.npcs.scripted.event.ForgeEvent;
public class ServerEventsHandler {
@@ -309,6 +307,8 @@ public class ServerEventsHandler {
}
String name = entityName;
QuestKill quest = (QuestKill) data.quest.questInterface;
if(quest.targetType == 1 && !(entity instanceof EntityNPCInterface))
continue;
if(quest.targets.containsKey(entity.getCommandSenderName()))
name = entity.getCommandSenderName();
else if(!quest.targets.containsKey(name))
@@ -4,13 +4,16 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.util.HashMap;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.constants.EnumPacketServer;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
public class Client {
public static HashMap<Integer, OverlayCustom> customOverlays = new HashMap<>();
public static void sendData(EnumPacketServer enu, Object... obs) {
ByteBuf buffer = Unpooled.buffer();
@@ -1,5 +1,18 @@
package noppes.npcs.client;
public class ClientEventHandler {
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import org.lwjgl.opengl.GL11;
public class ClientEventHandler {
@SubscribeEvent
public void onOverlayRender(RenderGameOverlayEvent.Post event){
if(event.type == RenderGameOverlayEvent.ElementType.ALL) {
for (OverlayCustom overlayCustom : Client.customOverlays.values()) {
overlayCustom.renderGameOverlay(event.partialTicks);
}
}
}
}
@@ -26,6 +26,7 @@ import noppes.npcs.ServerEventsHandler;
import noppes.npcs.client.ClientProxy.FontContainer;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.gui.GuiNpcMobSpawnerAdd;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.player.GuiBook;
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
import noppes.npcs.client.gui.util.GuiNPCInterface;
@@ -259,5 +260,15 @@ public class PacketHandlerClient extends PacketHandlerServer{
NoppesUtil.isGUIOpen(isGUIOpen);
}
else if(type == EnumPacketClient.OVERLAY_DATA){
OverlayCustom overlayCustom = new OverlayCustom(Minecraft.getMinecraft());
overlayCustom.setOverlayData(Server.readNBT(buffer));
Client.customOverlays.put(overlayCustom.overlay.getID(),overlayCustom);
}
else if(type == EnumPacketClient.OVERLAY_CLOSE){
int id = buffer.readInt();
Client.customOverlays.remove(id);
}
}
}
@@ -130,8 +130,16 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD
Iterator var4 = this.components.values().iterator();
while(var4.hasNext()) {
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GL11.glDisable(GL11.GL_ALPHA_TEST);
IGuiComponent component = (IGuiComponent)var4.next();
component.onRender(this.mc, mouseX, mouseY, Mouse.getDWheel(), partialTicks);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_ALPHA_TEST);
}
if (this.hoverText != null) {
@@ -429,6 +437,11 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD
this.components.put(scroll.getID(), scroll);
this.addDataHolder(scroll);
this.addClickListener(scroll);
break;
case 6:
CustomGuiLine line = CustomGuiLine.fromComponent((ScriptGuiLine) component);
this.components.put(line.getID(),line);
break;
}
}
@@ -6,12 +6,16 @@
package noppes.npcs.client.gui.custom.components;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.custom.interfaces.IClickListener;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import noppes.npcs.scripted.gui.ScriptGuiButton;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import org.lwjgl.opengl.GL11;
@@ -23,17 +27,17 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
public int textureY;
boolean field_146123_n;
String label;
int colour;
String[] hoverText;
int color;
float alpha;
public CustomGuiButton(int id, String buttonText, int x, int y) {
super(id, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, buttonText);
this.colour = 16777215;
}
public CustomGuiButton(int id, String buttonText, int x, int y, int width, int height) {
super(id, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, width, height, buttonText);
this.colour = 16777215;
}
public CustomGuiButton(int buttonId, String buttonText, int x, int y, int width, int height, String texture) {
@@ -46,6 +50,12 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
this.textureY = textureY;
this.label = buttonText;
this.texture = new ResourceLocation(texture);
if(texture.startsWith("https://")){
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false));
texturemanager.loadTexture(this.texture, object);
}
}
public void setParent(GuiCustom parent) {
@@ -66,6 +76,9 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
btn = new CustomGuiButton(component.getID(), component.getLabel(), component.getPosX(), component.getPosY());
}
btn.color = component.getColor();
btn.alpha = component.getAlpha();
if (component.hasHoverText()) {
btn.hoverText = component.getHoverText();
}
@@ -81,59 +94,59 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
//GL11.func_179094_E();
//GL11.func_179109_b(0.0F, 0.0F, (float)this.id);
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, 0.0F, (float)this.id);
FontRenderer fontRenderer = mc.fontRenderer;
int i;
if (this.texture == null) {
mc.getTextureManager().bindTexture(buttonTextures);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
i = this.getHoverState(this.field_146123_n);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO);
//GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + i * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
this.mouseDragged(mc, mouseX, mouseY);
int j = 14737632;
if (this.packedFGColour != 0) {
j = this.packedFGColour;
} else if (!this.enabled) {
j = 10526880;
} else if (this.field_146123_n) {
j = 16777120;
}
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glTranslated(0.0D, 0.0D, 0.1D);
this.drawCenteredString(fontRenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, j);
} else {
mc.getTextureManager().bindTexture(this.texture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
i = this.hoverState(this.field_146123_n);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO);
//GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.xPosition, this.yPosition, this.textureX, this.textureY + i * this.height, this.width, this.height);
this.drawCenteredString(fontRenderer, this.label, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, this.colour);
if (this.field_146123_n && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
}
}
GL11.glTranslatef(0.0F, 0.0F, (float)this.id);
FontRenderer fontRenderer = mc.fontRenderer;
int i;
if (this.texture == null) {
mc.getTextureManager().bindTexture(buttonTextures);
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
i = this.getHoverState(this.field_146123_n);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO);
//GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + i * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
this.mouseDragged(mc, mouseX, mouseY);
int j = 14737632;
if (this.packedFGColour != 0) {
j = this.packedFGColour;
} else if (!this.enabled) {
j = 10526880;
} else if (this.field_146123_n) {
j = 16777120;
}
GL11.glTranslated(0.0D, 0.0D, 0.1D);
this.drawCenteredString(fontRenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, j);
} else {
mc.getTextureManager().bindTexture(this.texture);
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
i = this.hoverState(this.field_146123_n);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO);
//GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.xPosition, this.yPosition, this.textureX, this.textureY + i * this.height, this.width, this.height);
this.drawCenteredString(fontRenderer, this.label, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, this.color);
if (this.field_146123_n && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
}
}
GL11.glPopMatrix();
}
public ICustomGuiComponent toComponent() {
ScriptGuiButton component = new ScriptGuiButton(this.id, this.label, this.xPosition, this.yPosition, this.width, this.height, this.texture.toString(), this.textureX, this.textureY);
component.setHoverText(this.hoverText);
component.setColor(this.color);
component.setAlpha(this.alpha);
return component;
}
public void setColour(int colour) {
this.colour = colour;
}
protected int hoverState(boolean mouseOver) {
int i = 0;
if (mouseOver) {
@@ -5,24 +5,32 @@
package noppes.npcs.client.gui.custom.components;
import com.ibm.icu.text.ArabicShaping;
import com.ibm.icu.text.ArabicShapingException;
import com.ibm.icu.text.Bidi;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.custom.interfaces.IGuiComponent;
import noppes.npcs.scripted.gui.ScriptGuiLabel;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import org.lwjgl.opengl.GL11;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
public class CustomGuiLabel extends Gui implements IGuiComponent {
int x, y, width, height;
GuiCustom parent;
String fullLabel;
int color;
String[] hoverText;
float scale;
int id;
@@ -30,21 +38,35 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
boolean labelBgEnabled = true;
boolean labelShadowEnabled = false;
int color;
float alpha;
protected int field_146167_a;
protected int field_146161_f;
public int field_146162_g;
public int field_146174_h;
private ArrayList field_146173_k;
private boolean field_146170_l;
public boolean field_146172_j;
private boolean field_146171_m;
private int field_146168_n;
private int field_146169_o;
private int field_146166_p;
private int field_146165_q;
private FontRenderer field_146164_r;
private int field_146163_s;
private static final String __OBFID = "CL_00000671";
private boolean randomStyle = false;
private boolean boldStyle = false;
private boolean italicStyle = false;
private boolean underlineStyle = false;
private boolean strikethroughStyle = false;
private boolean bidiFlag = false;
private boolean unicodeFlag = false;
private static final ResourceLocation[] unicodePageLocations = new ResourceLocation[256];
protected final ResourceLocation locationFontTexture;
protected int[] charWidth = new int[256];
protected byte[] glyphWidth = new byte[65536];
private final int[] colorCode = new int[32];
private float red;
private float green;
private float blue;
private float posX;
private float posY;
public CustomGuiLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){
this.id = id;
@@ -54,6 +76,41 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
this.width = width;
this.height = height;
this.labelShadowEnabled = shadow;
locationFontTexture = new ResourceLocation("textures/font/ascii.png");
readFontTexture();
readGlyphSizes();
for (int i = 0; i < 32; ++i)
{
int j = (i >> 3 & 1) * 85;
int k = (i >> 2 & 1) * 170 + j;
int l = (i >> 1 & 1) * 170 + j;
int i1 = (i >> 0 & 1) * 170 + j;
if (i == 6)
{
k += 85;
}
if (Minecraft.getMinecraft().gameSettings.anaglyph)
{
int j1 = (k * 30 + l * 59 + i1 * 11) / 100;
int k1 = (k * 30 + l * 70) / 100;
int l1 = (k * 30 + i1 * 70) / 100;
k = j1;
l = k1;
i1 = l1;
}
if (i >= 16)
{
k /= 4;
l /= 4;
i1 /= 4;
}
this.colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255;
}
}
public void setParent(GuiCustom parent) {
@@ -80,12 +137,13 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
CustomGuiLabel lbl = new CustomGuiLabel(component.getID(), component.getText(), GuiCustom.guiLeft + component.getPosX(), GuiCustom.guiTop + component.getPosY(), component.getWidth(), component.getHeight(), component.hasShadow());
lbl.scale = 1.0F;
lbl.color = component.getColor();
lbl.field_146172_j = true;
lbl.setScale(component.getScale());
if (component.hasHoverText()) {
lbl.hoverText = component.getHoverText();
}
lbl.labelShadowEnabled = component.hasShadow();
lbl.color = component.getColor();
lbl.alpha = component.getAlpha();
return lbl;
}
@@ -94,39 +152,413 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
ScriptGuiLabel component = new ScriptGuiLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color);
component.setHoverText(this.hoverText);
component.enableShadow(this.labelShadowEnabled);
component.setColor(this.color);
component.setAlpha(this.alpha);
return component;
}
public void drawLabel()
{
if (this.field_146172_j)
{
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glPushMatrix();
red = (color >> 16 & 255) / 255f;
green = (color >> 8 & 255) / 255f;
blue = (color & 255) / 255f;
this.drawLabelBackground();
GL11.glPushMatrix();
GL11.glTranslatef(this.x,this.y,0.0F);
GL11.glScalef(this.scale, this.scale, this.scale);
Minecraft.getMinecraft().fontRenderer.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled);
GL11.glPopMatrix();
GL11.glTranslatef(this.x,this.y,0.0F);
GL11.glScalef(this.scale, this.scale, this.scale);
this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled);
GL11.glPopMatrix();
}
public int drawString(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_, boolean p_85187_5_)
{
this.resetStyles();
int l;
if (p_85187_5_)
{
l = this.renderString(p_85187_1_, p_85187_2_ + 1, p_85187_3_ + 1, p_85187_4_, true);
l = Math.max(l, this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false));
}
else
{
l = this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false);
}
return l;
}
private void resetStyles()
{
this.randomStyle = false;
this.boldStyle = false;
this.italicStyle = false;
this.underlineStyle = false;
this.strikethroughStyle = false;
}
private int renderString(String p_78258_1_, int p_78258_2_, int p_78258_3_, int p_78258_4_, boolean p_78258_5_)
{
if (p_78258_1_ == null)
{
return 0;
}
else
{
if (this.bidiFlag)
{
p_78258_1_ = this.bidiReorder(p_78258_1_);
}
setColor(this.red, this.green, this.blue, this.alpha);
this.posX = (float)p_78258_2_;
this.posY = (float)p_78258_3_;
this.renderStringAtPos(p_78258_1_, p_78258_5_);
return (int)this.posX;
}
}
protected void drawLabelBackground()
private void renderStringAtPos(String p_78255_1_, boolean p_78255_2_)
{
if (this.labelBgEnabled)
for (int i = 0; i < p_78255_1_.length(); ++i)
{
int k = (int)(this.width*this.scale) + this.border * 2;
int l = (int)(this.height*this.scale) + this.border * 2;
int i1 = this.x - this.border;
int j1 = this.y - this.border;
drawRect(i1, j1, i1 + k, j1 + l, this.color);//backColor
this.drawHorizontalLine(i1, i1 + k, j1, this.color);//ulColor
this.drawHorizontalLine(i1, i1 + k, j1 + l, this.color);//brColor
this.drawVerticalLine(i1, j1, j1 + l, this.color);//ulColor
this.drawVerticalLine(i1 + k, j1, j1 + l, this.color);//brColor
char c0 = p_78255_1_.charAt(i);
int j;
int k;
if (c0 == 38 && i + 1 < p_78255_1_.length())
{
j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1));
if(j < 16){
this.randomStyle = false;
this.boldStyle = false;
this.strikethroughStyle = false;
this.underlineStyle = false;
this.italicStyle = false;
if (j < 0 || j > 15)
{
j = 15;
}
if (p_78255_2_)
{
j += 16;
}
k = this.colorCode[j];
setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha);
}
else if (j == 16)
{
this.randomStyle = true;
}
else if (j == 17)
{
this.boldStyle = true;
}
else if (j == 18)
{
this.strikethroughStyle = true;
}
else if (j == 19)
{
this.underlineStyle = true;
}
else if (j == 20)
{
this.italicStyle = true;
}
else if (j == 21)
{
this.randomStyle = false;
this.boldStyle = false;
this.strikethroughStyle = false;
this.underlineStyle = false;
this.italicStyle = false;
}
++i;
}
else
{
j = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(c0);
if (this.randomStyle && j != -1)
{
do
{
k = Minecraft.getMinecraft().fontRenderer.fontRandom.nextInt(this.charWidth.length);
}
while (this.charWidth[j] != this.charWidth[k]);
j = k;
}
float f1 = this.unicodeFlag ? 0.5F : 1.0F;
boolean flag1 = (c0 == 0 || j == -1 || this.unicodeFlag) && p_78255_2_;
if (flag1)
{
this.posX -= f1;
this.posY -= f1;
}
float f = this.renderCharAtPos(j, c0, this.italicStyle);
if (flag1)
{
this.posX += f1;
this.posY += f1;
}
if (this.boldStyle)
{
this.posX += f1;
if (flag1)
{
this.posX -= f1;
this.posY -= f1;
}
this.renderCharAtPos(j, c0, this.italicStyle);
this.posX -= f1;
if (flag1)
{
this.posX += f1;
this.posY += f1;
}
++f;
}
doDraw(f);
}
}
}
protected void doDraw(float f)
{
{
{
Tessellator tessellator;
if (this.strikethroughStyle)
{
tessellator = Tessellator.instance;
GL11.glDisable(GL11.GL_TEXTURE_2D);
tessellator.startDrawingQuads();
tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D);
tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D);
tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D);
tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
if (this.underlineStyle)
{
tessellator = Tessellator.instance;
GL11.glDisable(GL11.GL_TEXTURE_2D);
tessellator.startDrawingQuads();
int l = this.underlineStyle ? -1 : 0;
tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D);
tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D);
tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D);
tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
this.posX += (float)((int)f);
}
}
}
private float renderCharAtPos(int p_78278_1_, char p_78278_2_, boolean p_78278_3_)
{
return p_78278_2_ == 32 ? 4.0F : ("\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(p_78278_2_) != -1 && !this.unicodeFlag ? this.renderDefaultChar(p_78278_1_, p_78278_3_) : this.renderUnicodeChar(p_78278_2_, p_78278_3_));
}
protected float renderDefaultChar(int p_78266_1_, boolean p_78266_2_)
{
float f = (float)(p_78266_1_ % 16 * 8);
float f1 = (float)(p_78266_1_ / 16 * 8);
float f2 = p_78266_2_ ? 1.0F : 0.0F;
bindTexture(this.locationFontTexture);
float f3 = (float)this.charWidth[p_78266_1_] - 0.01F;
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
GL11.glTexCoord2f(f / 128.0F, f1 / 128.0F);
GL11.glVertex3f(this.posX + f2, this.posY, 0.0F);
GL11.glTexCoord2f(f / 128.0F, (f1 + 7.99F) / 128.0F);
GL11.glVertex3f(this.posX - f2, this.posY + 7.99F, 0.0F);
GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, f1 / 128.0F);
GL11.glVertex3f(this.posX + f3 - 1.0F + f2, this.posY, 0.0F);
GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, (f1 + 7.99F) / 128.0F);
GL11.glVertex3f(this.posX + f3 - 1.0F - f2, this.posY + 7.99F, 0.0F);
GL11.glEnd();
return (float)this.charWidth[p_78266_1_];
}
private ResourceLocation getUnicodePageLocation(int p_111271_1_)
{
if (unicodePageLocations[p_111271_1_] == null)
{
unicodePageLocations[p_111271_1_] = new ResourceLocation(String.format("textures/font/unicode_page_%02x.png", new Object[] {Integer.valueOf(p_111271_1_)}));
}
return unicodePageLocations[p_111271_1_];
}
private void loadGlyphTexture(int p_78257_1_)
{
bindTexture(this.getUnicodePageLocation(p_78257_1_));
}
/**
* Render a single Unicode character at current (posX,posY) location using one of the /font/glyph_XX.png files...
*/
protected float renderUnicodeChar(char p_78277_1_, boolean p_78277_2_)
{
if (this.glyphWidth[p_78277_1_] == 0)
{
return 0.0F;
}
else
{
int i = p_78277_1_ / 256;
this.loadGlyphTexture(i);
int j = this.glyphWidth[p_78277_1_] >>> 4;
int k = this.glyphWidth[p_78277_1_] & 15;
float f = (float)j;
float f1 = (float)(k + 1);
float f2 = (float)(p_78277_1_ % 16 * 16) + f;
float f3 = (float)((p_78277_1_ & 255) / 16 * 16);
float f4 = f1 - f - 0.02F;
float f5 = p_78277_2_ ? 1.0F : 0.0F;
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
GL11.glTexCoord2f(f2 / 256.0F, f3 / 256.0F);
GL11.glVertex3f(this.posX + f5, this.posY, 0.0F);
GL11.glTexCoord2f(f2 / 256.0F, (f3 + 15.98F) / 256.0F);
GL11.glVertex3f(this.posX - f5, this.posY + 7.99F, 0.0F);
GL11.glTexCoord2f((f2 + f4) / 256.0F, f3 / 256.0F);
GL11.glVertex3f(this.posX + f4 / 2.0F + f5, this.posY, 0.0F);
GL11.glTexCoord2f((f2 + f4) / 256.0F, (f3 + 15.98F) / 256.0F);
GL11.glVertex3f(this.posX + f4 / 2.0F - f5, this.posY + 7.99F, 0.0F);
GL11.glEnd();
return (f1 - f) / 2.0F + 1.0F;
}
}
protected void setColor(float r, float g, float b, float a)
{
GL11.glColor4f(r, g, b, a);
}
protected void bindTexture(ResourceLocation location)
{
Minecraft.getMinecraft().renderEngine.bindTexture(location);
}
private void readFontTexture()
{
BufferedImage bufferedimage;
try
{
bufferedimage = ImageIO.read(getResourceInputStream(this.locationFontTexture));
}
catch (IOException ioexception)
{
throw new RuntimeException(ioexception);
}
int i = bufferedimage.getWidth();
int j = bufferedimage.getHeight();
int[] aint = new int[i * j];
bufferedimage.getRGB(0, 0, i, j, aint, 0, i);
int k = j / 16;
int l = i / 16;
byte b0 = 1;
float f = 8.0F / (float)l;
int i1 = 0;
while (i1 < 256)
{
int j1 = i1 % 16;
int k1 = i1 / 16;
if (i1 == 32)
{
this.charWidth[i1] = 3 + b0;
}
int l1 = l - 1;
while (true)
{
if (l1 >= 0)
{
int i2 = j1 * l + l1;
boolean flag = true;
for (int j2 = 0; j2 < k && flag; ++j2)
{
int k2 = (k1 * l + j2) * i;
if ((aint[i2 + k2] >> 24 & 255) != 0)
{
flag = false;
}
}
if (flag)
{
--l1;
continue;
}
}
++l1;
this.charWidth[i1] = (int)(0.5D + (double)((float)l1 * f)) + b0;
++i1;
break;
}
}
}
private void readGlyphSizes()
{
try
{
InputStream inputstream = getResourceInputStream(new ResourceLocation("font/glyph_sizes.bin"));
inputstream.read(this.glyphWidth);
}
catch (IOException ioexception)
{
throw new RuntimeException(ioexception);
}
}
protected InputStream getResourceInputStream(ResourceLocation location) throws IOException
{
return Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream();
}
private String bidiReorder(String p_147647_1_)
{
try
{
Bidi bidi = new Bidi((new ArabicShaping(8)).shape(p_147647_1_), 127);
bidi.setReorderingMode(0);
return bidi.writeReordered(2);
}
catch (ArabicShapingException arabicshapingexception)
{
return p_147647_1_;
}
}
}
@@ -0,0 +1,75 @@
package noppes.npcs.client.gui.custom.components;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.custom.interfaces.IGuiComponent;
import noppes.npcs.scripted.gui.ScriptGuiLine;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
public class CustomGuiLine extends Gui implements IGuiComponent {
int id;
GuiCustom parent;
int x1;
int y1;
int x2;
int y2;
int color;
float alpha;
int thickness;
public CustomGuiLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){
this.id = id;
this.x1 = GuiCustom.guiLeft + x1;
this.y1 = GuiCustom.guiTop + y1;
this.x2 = GuiCustom.guiLeft + x2;
this.y2 = GuiCustom.guiTop + y2;
this.color = color;
this.thickness = thickness;
}
public void setParent(GuiCustom parent) {
this.parent = parent;
}
@Override
public int getID() {
return this.id;
}
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
double distance = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png"));
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glTranslatef(this.x1,this.y1,0.0F);
GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F);
GL11.glScaled(thickness, distance,0.0D);
this.drawTexturedModalRect(0,0,0,0, 1, 1);
GL11.glPopMatrix();
}
public ICustomGuiComponent toComponent() {
ScriptGuiLine line = new ScriptGuiLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness);
line.setColor(this.color);
line.setAlpha(this.alpha);
return line;
}
public static CustomGuiLine fromComponent(ScriptGuiLine component) {
CustomGuiLine line = new CustomGuiLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness());
line.color = component.getColor();
line.alpha = component.getAlpha();
return line;
}
}
@@ -25,6 +25,9 @@ public class CustomGuiScrollComponent extends GuiCustomScroll implements IDataHo
String[] hoverText;
public boolean multiSelect = false;
int color;
float alpha;
public CustomGuiScrollComponent(Minecraft mc, GuiScreen parent, int id) {
super(parent, id);
this.mc = mc;
@@ -48,13 +51,17 @@ public class CustomGuiScrollComponent extends GuiCustomScroll implements IDataHo
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, 0.0F, (float)this.id);
boolean hovered = mouseX >= this.guiLeft && mouseY >= this.guiTop && mouseX < this.guiLeft + this.xSize && mouseY < this.guiTop + this.ySize;
super.drawScreen(mouseX, mouseY, partialTicks, mouseWheel);
if (hovered && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
}
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glTranslatef(0.0F, 0.0F, (float)this.id);
boolean hovered = mouseX >= this.guiLeft && mouseY >= this.guiTop && mouseX < this.guiLeft + this.xSize && mouseY < this.guiTop + this.ySize;
super.drawScreen(mouseX, mouseY, partialTicks, mouseWheel);
if (hovered && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
}
GL11.glPopMatrix();
}
@@ -79,11 +86,15 @@ public class CustomGuiScrollComponent extends GuiCustomScroll implements IDataHo
this.hoverText = component.getHoverText();
}
this.color = component.getColor();
this.alpha = component.getAlpha();
}
public ICustomGuiComponent toComponent() {
ScriptGuiScroll component = new ScriptGuiScroll(this.id, this.guiLeft - GuiCustom.guiLeft, this.guiTop - GuiCustom.guiTop, this.width, this.height, (String[])this.getList().toArray(new String[0]));
component.setHoverText(this.hoverText);
component.setColor(color);
component.setAlpha(alpha);
return component;
}
@@ -16,12 +16,16 @@ import noppes.npcs.client.gui.custom.interfaces.IKeyListener;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.scripted.gui.ScriptGuiTextField;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import org.lwjgl.opengl.GL11;
public class CustomGuiTextField extends GuiTextField implements IKeyListener, IDataHolder, IClickListener {
GuiCustom parent;
String[] hoverText;
int id;
int color;
float alpha;
public CustomGuiTextField(int id, int x, int y, int width, int height) {
super(Minecraft.getMinecraft().fontRenderer, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, width, height);
this.id = id;
@@ -34,7 +38,12 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
boolean hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
this.drawTextBox();
GL11.glColor4f(1.0F,1.0F,1.0F,1.0F);
if (hovered && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
}
@@ -59,6 +68,8 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID
ScriptGuiTextField component = new ScriptGuiTextField(this.id, this.xPosition - GuiCustom.guiLeft, this.yPosition - GuiCustom.guiTop, this.width, this.height);
component.setText(this.getText());
component.setHoverText(this.hoverText);
component.setColor(color);
component.setAlpha(alpha);
return component;
}
@@ -72,6 +83,9 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID
txt.setText(component.getText());
}
txt.color = component.getColor();
txt.alpha = component.getAlpha();
return txt;
}
@@ -8,13 +8,21 @@ package noppes.npcs.client.gui.custom.components;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.custom.interfaces.IGuiComponent;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import noppes.npcs.scripted.gui.ScriptGuiTexturedRect;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
GuiCustom parent;
ResourceLocation texture;
@@ -28,6 +36,9 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
float scale;
String[] hoverText;
int color;
float alpha;
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
this(id, texture, x, y, width, height, 0, 0);
}
@@ -42,6 +53,12 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
this.height = height;
this.textureX = textureX;
this.textureY = textureY;
if(texture.startsWith("https://")){
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false));
texturemanager.loadTexture(this.texture, object);
}
}
public void setParent(GuiCustom parent) {
@@ -57,7 +74,11 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
mc.getTextureManager().bindTexture(this.texture);
GL11.glPushMatrix();
GL11.glColor4f(1.0F,1.0F,1.0F,1.0F);
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glScalef(this.scale, this.scale, this.scale);
this.drawTexturedModalRect((int) (this.x/this.scale), (int) (this.y/this.scale), this.textureX, this.textureY, (int)(this.width), (int)(this.height));
GL11.glPopMatrix();
@@ -71,6 +92,8 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY);
component.setHoverText(this.hoverText);
component.setScale(this.scale);
component.setColor(color);
component.setAlpha(alpha);
return component;
}
@@ -87,6 +110,9 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
rect.hoverText = component.getHoverText();
}
rect.color = component.getColor();
rect.alpha = component.getAlpha();
return rect;
}
}
@@ -0,0 +1,97 @@
package noppes.npcs.client.gui.customoverlay;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.customoverlay.components.CustomOverlayLabel;
import noppes.npcs.client.gui.customoverlay.components.CustomOverlayLine;
import noppes.npcs.client.gui.customoverlay.components.CustomOverlayTexturedRect;
import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent;
import noppes.npcs.scripted.interfaces.ICustomOverlayComponent;
import noppes.npcs.scripted.overlay.*;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class OverlayCustom extends Gui {
protected final Minecraft mc;
private ScaledResolution res = null;
public static int scaledWidth = 0;
public static int scaledHeight = 0;
public ScriptOverlay overlay;
Map<Integer, IOverlayComponent> components = new HashMap();
public OverlayCustom(Minecraft mc) {
this.mc = mc;
}
public void initOverlay(){
res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
if(this.overlay != null){
scaledWidth = res.getScaledWidth();
scaledHeight = res.getScaledHeight();
this.components.clear();
Iterator var1 = this.overlay.getComponents().iterator();
while(var1.hasNext()) {
ICustomOverlayComponent c = (ICustomOverlayComponent)var1.next();
this.addComponent(c);
}
}
}
private void addComponent(ICustomOverlayComponent component) {
ScriptOverlayComponent c = (ScriptOverlayComponent)component;
switch(c.getType()) {
case 0:
CustomOverlayTexturedRect rect = CustomOverlayTexturedRect.fromComponent((ScriptOverlayTexturedRect) component);
rect.setParent(this);
this.components.put(rect.getID(), rect);
break;
case 1:
CustomOverlayLabel lbl = CustomOverlayLabel.fromComponent((ScriptOverlayLabel)component);
lbl.setParent(this);
this.components.put(lbl.getID(), lbl);
break;
case 2:
CustomOverlayLine line = CustomOverlayLine.fromComponent((ScriptOverlayLine) component);
line.setParent(this);
this.components.put(line.getID(), line);
break;
}
}
public void renderGameOverlay(float partialTicks){
res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
scaledWidth = res.getScaledWidth();
scaledHeight = res.getScaledHeight();
Iterator var4 = this.components.values().iterator();
while(var4.hasNext()) {
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GL11.glDisable(GL11.GL_ALPHA_TEST);
IOverlayComponent component = (IOverlayComponent)var4.next();
component.onRender(this.mc, partialTicks);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_ALPHA_TEST);
}
}
public void setOverlayData(NBTTagCompound compound) {
this.overlay = (ScriptOverlay)(new ScriptOverlay()).fromNBT(compound);
this.initOverlay();
}
}
@@ -0,0 +1,560 @@
package noppes.npcs.client.gui.customoverlay.components;
import com.ibm.icu.text.ArabicShaping;
import com.ibm.icu.text.ArabicShapingException;
import com.ibm.icu.text.Bidi;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent;
import noppes.npcs.scripted.interfaces.ICustomOverlayComponent;
import noppes.npcs.scripted.overlay.ScriptOverlayLabel;
import org.lwjgl.opengl.GL11;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
public class CustomOverlayLabel extends Gui implements IOverlayComponent {
OverlayCustom parent;
int id;
String fullLabel;
int x, y, width, height, alignment;
float scale, rotation;
int color;
float alpha;
int border = 2;
boolean labelBgEnabled = true;
boolean labelShadowEnabled = false;
protected int field_146167_a;
protected int field_146161_f;
public int field_146162_g;
public int field_146174_h;
private boolean randomStyle = false;
private boolean boldStyle = false;
private boolean italicStyle = false;
private boolean underlineStyle = false;
private boolean strikethroughStyle = false;
private boolean bidiFlag = false;
private boolean unicodeFlag = false;
private static final ResourceLocation[] unicodePageLocations = new ResourceLocation[256];
protected final ResourceLocation locationFontTexture;
protected int[] charWidth = new int[256];
protected byte[] glyphWidth = new byte[65536];
private final int[] colorCode = new int[32];
private float red;
private float green;
private float blue;
private float posX;
private float posY;
public CustomOverlayLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){
this.id = id;
this.fullLabel = fullLabel;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.labelShadowEnabled = shadow;
locationFontTexture = new ResourceLocation("textures/font/ascii.png");
readFontTexture();
readGlyphSizes();
for (int i = 0; i < 32; ++i)
{
int j = (i >> 3 & 1) * 85;
int k = (i >> 2 & 1) * 170 + j;
int l = (i >> 1 & 1) * 170 + j;
int i1 = (i >> 0 & 1) * 170 + j;
if (i == 6)
{
k += 85;
}
if (Minecraft.getMinecraft().gameSettings.anaglyph)
{
int j1 = (k * 30 + l * 59 + i1 * 11) / 100;
int k1 = (k * 30 + l * 70) / 100;
int l1 = (k * 30 + i1 * 70) / 100;
k = j1;
l = k1;
i1 = l1;
}
if (i >= 16)
{
k /= 4;
l /= 4;
i1 /= 4;
}
this.colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255;
}
}
public void setParent(OverlayCustom parent) {
this.parent = parent;
}
public void onRender(Minecraft mc, float partialTicks) {
this.drawLabel();
}
public int getID() {
return this.id;
}
public void setScale(float scale) {
this.scale = scale;
}
public static CustomOverlayLabel fromComponent(ScriptOverlayLabel component) {
CustomOverlayLabel lbl = new CustomOverlayLabel(component.getID(), component.getText(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getShadow());
lbl.scale = 1.0F;
lbl.color = component.getColor();
lbl.labelShadowEnabled = component.getShadow();
lbl.alignment = component.getAlignment();
lbl.alpha = component.getAlpha();
lbl.rotation = component.getRotation();
lbl.setScale(component.getScale());
return lbl;
}
public ICustomOverlayComponent toComponent() {
ScriptOverlayLabel component = new ScriptOverlayLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color);
component.setShadow(this.labelShadowEnabled);
component.setAlignment(alignment);
component.setAlpha(alpha);
component.setColor(color);
component.setRotation(rotation);
return component;
}
public void drawLabel()
{
GL11.glPushMatrix();
GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2
red = (color >> 16 & 255) / 255f;
green = (color >> 8 & 255) / 255f;
blue = (color & 255) / 255f;
GL11.glTranslatef(this.x,this.y,0.0F);
GL11.glRotated(rotation,0.0D,0.0D,1.0D);
GL11.glScalef(this.scale, this.scale, this.scale);
this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled);
GL11.glPopMatrix();
}
public int drawString(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_, boolean p_85187_5_)
{
this.resetStyles();
int l;
if (p_85187_5_)
{
l = this.renderString(p_85187_1_, p_85187_2_ + 1, p_85187_3_ + 1, p_85187_4_, true);
l = Math.max(l, this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false));
}
else
{
l = this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false);
}
return l;
}
private void resetStyles()
{
this.randomStyle = false;
this.boldStyle = false;
this.italicStyle = false;
this.underlineStyle = false;
this.strikethroughStyle = false;
}
private int renderString(String p_78258_1_, int p_78258_2_, int p_78258_3_, int p_78258_4_, boolean p_78258_5_)
{
if (p_78258_1_ == null)
{
return 0;
}
else
{
if (this.bidiFlag)
{
p_78258_1_ = this.bidiReorder(p_78258_1_);
}
setColor(this.red, this.green, this.blue, this.alpha);
this.posX = (float)p_78258_2_;
this.posY = (float)p_78258_3_;
this.renderStringAtPos(p_78258_1_, p_78258_5_);
return (int)this.posX;
}
}
private void renderStringAtPos(String p_78255_1_, boolean p_78255_2_)
{
for (int i = 0; i < p_78255_1_.length(); ++i)
{
char c0 = p_78255_1_.charAt(i);
int j;
int k;
if (c0 == 38 && i + 1 < p_78255_1_.length())
{
j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1));
if(j < 16){
this.randomStyle = false;
this.boldStyle = false;
this.strikethroughStyle = false;
this.underlineStyle = false;
this.italicStyle = false;
if (j < 0 || j > 15)
{
j = 15;
}
if (p_78255_2_)
{
j += 16;
}
k = this.colorCode[j];
setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha);
}
else if (j == 16)
{
this.randomStyle = true;
}
else if (j == 17)
{
this.boldStyle = true;
}
else if (j == 18)
{
this.strikethroughStyle = true;
}
else if (j == 19)
{
this.underlineStyle = true;
}
else if (j == 20)
{
this.italicStyle = true;
}
else if (j == 21)
{
this.randomStyle = false;
this.boldStyle = false;
this.strikethroughStyle = false;
this.underlineStyle = false;
this.italicStyle = false;
}
++i;
}
else
{
j = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(c0);
if (this.randomStyle && j != -1)
{
do
{
k = Minecraft.getMinecraft().fontRenderer.fontRandom.nextInt(this.charWidth.length);
}
while (this.charWidth[j] != this.charWidth[k]);
j = k;
}
float f1 = this.unicodeFlag ? 0.5F : 1.0F;
boolean flag1 = (c0 == 0 || j == -1 || this.unicodeFlag) && p_78255_2_;
if (flag1)
{
this.posX -= f1;
this.posY -= f1;
}
float f = this.renderCharAtPos(j, c0, this.italicStyle);
if (flag1)
{
this.posX += f1;
this.posY += f1;
}
if (this.boldStyle)
{
this.posX += f1;
if (flag1)
{
this.posX -= f1;
this.posY -= f1;
}
this.renderCharAtPos(j, c0, this.italicStyle);
this.posX -= f1;
if (flag1)
{
this.posX += f1;
this.posY += f1;
}
++f;
}
doDraw(f);
}
}
}
protected void doDraw(float f)
{
{
{
Tessellator tessellator;
if (this.strikethroughStyle)
{
tessellator = Tessellator.instance;
GL11.glDisable(GL11.GL_TEXTURE_2D);
tessellator.startDrawingQuads();
tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D);
tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D);
tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D);
tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
if (this.underlineStyle)
{
tessellator = Tessellator.instance;
GL11.glDisable(GL11.GL_TEXTURE_2D);
tessellator.startDrawingQuads();
int l = this.underlineStyle ? -1 : 0;
tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D);
tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D);
tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D);
tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
this.posX += (float)((int)f);
}
}
}
private float renderCharAtPos(int p_78278_1_, char p_78278_2_, boolean p_78278_3_)
{
return p_78278_2_ == 32 ? 4.0F : ("\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(p_78278_2_) != -1 && !this.unicodeFlag ? this.renderDefaultChar(p_78278_1_, p_78278_3_) : this.renderUnicodeChar(p_78278_2_, p_78278_3_));
}
protected float renderDefaultChar(int p_78266_1_, boolean p_78266_2_)
{
float f = (float)(p_78266_1_ % 16 * 8);
float f1 = (float)(p_78266_1_ / 16 * 8);
float f2 = p_78266_2_ ? 1.0F : 0.0F;
bindTexture(this.locationFontTexture);
float f3 = (float)this.charWidth[p_78266_1_] - 0.01F;
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
GL11.glTexCoord2f(f / 128.0F, f1 / 128.0F);
GL11.glVertex3f(this.posX + f2, this.posY, 0.0F);
GL11.glTexCoord2f(f / 128.0F, (f1 + 7.99F) / 128.0F);
GL11.glVertex3f(this.posX - f2, this.posY + 7.99F, 0.0F);
GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, f1 / 128.0F);
GL11.glVertex3f(this.posX + f3 - 1.0F + f2, this.posY, 0.0F);
GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, (f1 + 7.99F) / 128.0F);
GL11.glVertex3f(this.posX + f3 - 1.0F - f2, this.posY + 7.99F, 0.0F);
GL11.glEnd();
return (float)this.charWidth[p_78266_1_];
}
private ResourceLocation getUnicodePageLocation(int p_111271_1_)
{
if (unicodePageLocations[p_111271_1_] == null)
{
unicodePageLocations[p_111271_1_] = new ResourceLocation(String.format("textures/font/unicode_page_%02x.png", new Object[] {Integer.valueOf(p_111271_1_)}));
}
return unicodePageLocations[p_111271_1_];
}
private void loadGlyphTexture(int p_78257_1_)
{
bindTexture(this.getUnicodePageLocation(p_78257_1_));
}
/**
* Render a single Unicode character at current (posX,posY) location using one of the /font/glyph_XX.png files...
*/
protected float renderUnicodeChar(char p_78277_1_, boolean p_78277_2_)
{
if (this.glyphWidth[p_78277_1_] == 0)
{
return 0.0F;
}
else
{
int i = p_78277_1_ / 256;
this.loadGlyphTexture(i);
int j = this.glyphWidth[p_78277_1_] >>> 4;
int k = this.glyphWidth[p_78277_1_] & 15;
float f = (float)j;
float f1 = (float)(k + 1);
float f2 = (float)(p_78277_1_ % 16 * 16) + f;
float f3 = (float)((p_78277_1_ & 255) / 16 * 16);
float f4 = f1 - f - 0.02F;
float f5 = p_78277_2_ ? 1.0F : 0.0F;
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
GL11.glTexCoord2f(f2 / 256.0F, f3 / 256.0F);
GL11.glVertex3f(this.posX + f5, this.posY, 0.0F);
GL11.glTexCoord2f(f2 / 256.0F, (f3 + 15.98F) / 256.0F);
GL11.glVertex3f(this.posX - f5, this.posY + 7.99F, 0.0F);
GL11.glTexCoord2f((f2 + f4) / 256.0F, f3 / 256.0F);
GL11.glVertex3f(this.posX + f4 / 2.0F + f5, this.posY, 0.0F);
GL11.glTexCoord2f((f2 + f4) / 256.0F, (f3 + 15.98F) / 256.0F);
GL11.glVertex3f(this.posX + f4 / 2.0F - f5, this.posY + 7.99F, 0.0F);
GL11.glEnd();
return (f1 - f) / 2.0F + 1.0F;
}
}
protected void setColor(float r, float g, float b, float a)
{
GL11.glColor4f(r, g, b, a);
}
protected void bindTexture(ResourceLocation location)
{
Minecraft.getMinecraft().renderEngine.bindTexture(location);
}
private void readFontTexture()
{
BufferedImage bufferedimage;
try
{
bufferedimage = ImageIO.read(getResourceInputStream(this.locationFontTexture));
}
catch (IOException ioexception)
{
throw new RuntimeException(ioexception);
}
int i = bufferedimage.getWidth();
int j = bufferedimage.getHeight();
int[] aint = new int[i * j];
bufferedimage.getRGB(0, 0, i, j, aint, 0, i);
int k = j / 16;
int l = i / 16;
byte b0 = 1;
float f = 8.0F / (float)l;
int i1 = 0;
while (i1 < 256)
{
int j1 = i1 % 16;
int k1 = i1 / 16;
if (i1 == 32)
{
this.charWidth[i1] = 3 + b0;
}
int l1 = l - 1;
while (true)
{
if (l1 >= 0)
{
int i2 = j1 * l + l1;
boolean flag = true;
for (int j2 = 0; j2 < k && flag; ++j2)
{
int k2 = (k1 * l + j2) * i;
if ((aint[i2 + k2] >> 24 & 255) != 0)
{
flag = false;
}
}
if (flag)
{
--l1;
continue;
}
}
++l1;
this.charWidth[i1] = (int)(0.5D + (double)((float)l1 * f)) + b0;
++i1;
break;
}
}
}
private void readGlyphSizes()
{
try
{
InputStream inputstream = getResourceInputStream(new ResourceLocation("font/glyph_sizes.bin"));
inputstream.read(this.glyphWidth);
}
catch (IOException ioexception)
{
throw new RuntimeException(ioexception);
}
}
protected InputStream getResourceInputStream(ResourceLocation location) throws IOException
{
return Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream();
}
private String bidiReorder(String p_147647_1_)
{
try
{
Bidi bidi = new Bidi((new ArabicShaping(8)).shape(p_147647_1_), 127);
bidi.setReorderingMode(0);
return bidi.writeReordered(2);
}
catch (ArabicShapingException arabicshapingexception)
{
return p_147647_1_;
}
}
}
@@ -0,0 +1,104 @@
package noppes.npcs.client.gui.customoverlay.components;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent;
import noppes.npcs.scripted.interfaces.ICustomOverlayComponent;
import noppes.npcs.scripted.overlay.ScriptOverlayLine;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
public class CustomOverlayLine extends Gui implements IOverlayComponent {
OverlayCustom parent;
int alignment;
int id;
int x1;
int y1;
int x2;
int y2;
int color;
int thickness;
float alpha;
float rotation;
public CustomOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){
this.id = id;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.color = color;
this.thickness = thickness;
}
public void setParent(OverlayCustom parent) {
this.parent = parent;
}
public int getID() {
return this.id;
}
public void onRender(Minecraft mc, float partialTicks) {
double distance = Math.hypot(x1-x2, y1-y2);
mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png"));
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2
GL11.glTranslatef(this.x1,this.y1,0.0F);
GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F);
GL11.glRotated(rotation,0.0D,0.0D,1.0D);
GL11.glScaled(thickness, distance,0.0D);
int p_73729_1_ = 0;
int p_73729_2_ = 0;
int p_73729_3_ = 0;
int p_73729_4_ = 0;
int p_73729_5_ = 1;
int p_73729_6_ = 1;
float f = 0.00390625F;
float f1 = 0.00390625F;
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorOpaque_F(1, 1, 1);
tessellator.setColorRGBA_F(red, green, blue, alpha);
tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1));
tessellator.draw();
GL11.glPopMatrix();
}
public ICustomOverlayComponent toComponent() {
ScriptOverlayLine line = new ScriptOverlayLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness);
line.setAlignment(alignment);
line.setAlpha(alpha);
line.setColor(color);
line.setRotation(rotation);
return line;
}
public static CustomOverlayLine fromComponent(ScriptOverlayLine component) {
CustomOverlayLine line = new CustomOverlayLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness());
line.alignment = component.getAlignment();
line.alpha = component.getAlpha();
line.color = component.getColor();
line.rotation = component.getRotation();
return line;
}
}
@@ -0,0 +1,132 @@
package noppes.npcs.client.gui.customoverlay.components;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import noppes.npcs.scripted.interfaces.ICustomOverlayComponent;
import noppes.npcs.scripted.overlay.ScriptOverlayTexturedRect;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL14.glBlendFuncSeparate;
public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent {
OverlayCustom parent;
int alignment;
int id;
ResourceLocation texture;
int x;
int y;
int width;
int height;
int textureX;
int textureY;
float scale;
int color;
float alpha;
float rotation;
public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) {
this(id, texture, x, y, width, height, 0, 0);
}
public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) {
this.scale = 1.0F;
this.alignment = 0;
this.id = id;
this.texture = new ResourceLocation(texture);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.textureX = textureX;
this.textureY = textureY;
if(texture.startsWith("https://")){
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false));
texturemanager.loadTexture(this.texture, object);
}
}
public void setParent(OverlayCustom parent) {
this.parent = parent;
}
public int getID() {
return this.id;
}
public void onRender(Minecraft mc, float partialTicks) {
mc.getTextureManager().bindTexture(this.texture);
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2
GL11.glScalef(this.scale, this.scale, this.scale);
GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F);
int p_73729_1_ = (int) (this.x/this.scale);
int p_73729_2_ = (int) (this.y/this.scale);
int p_73729_3_ = this.textureX;
int p_73729_4_ = this.textureY;
int p_73729_5_ = (int)(this.width);
int p_73729_6_ = (int)(this.height);
float f = 0.00390625F;
float f1 = 0.00390625F;
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorOpaque_F(1, 1, 1);
tessellator.setColorRGBA_F(red, green, blue, alpha);
tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1));
tessellator.draw();
GL11.glPopMatrix();
}
public ICustomOverlayComponent toComponent() {
ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY);
component.setScale(scale);
component.setAlignment(alignment);
component.setAlpha(alpha);
component.setColor(color);
component.setRotation(rotation);
return component;
}
public static CustomOverlayTexturedRect fromComponent(ScriptOverlayTexturedRect component) {
CustomOverlayTexturedRect rect;
if (component.getTextureX() >= 0 && component.getTextureY() >= 0) {
rect = new CustomOverlayTexturedRect(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTextureX(), component.getTextureY());
} else {
rect = new CustomOverlayTexturedRect(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight());
}
rect.scale = component.getScale();
rect.alignment = component.getAlignment();
rect.alpha = component.getAlpha();
rect.color = component.getColor();
rect.rotation = component.getRotation();
return rect;
}
}
@@ -0,0 +1,7 @@
package noppes.npcs.client.gui.customoverlay.interfaces;
import net.minecraft.client.Minecraft;
public interface IOverlayComponent {
void onRender(Minecraft mc, float partialTicks);
}
@@ -6,29 +6,30 @@ import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.util.GuiContainerNPCInterface2;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcSlider;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.IGuiData;
import noppes.npcs.client.gui.util.ISliderListener;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.containers.ContainerNPCInv;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.opengl.GL11;
public class GuiNPCInv extends GuiContainerNPCInterface2 implements ISliderListener, IGuiData
public class GuiNPCInv extends GuiContainerNPCInterface2 implements IGuiData, ITextfieldListener
{
private HashMap<Integer,Integer> chances = new HashMap<Integer, Integer>();
private HashMap<Integer,Double> chances = new HashMap<Integer, Double>();
private ContainerNPCInv container;
private ResourceLocation slot;
private int inventoryTab = 0;
public GuiNPCInv(EntityNPCInterface npc,ContainerNPCInv container)
{
super(npc,container,3);
@@ -56,25 +57,58 @@ public class GuiNPCInv extends GuiContainerNPCInterface2 implements ISliderListe
addLabel(new GuiNpcLabel(2,"inv.npcInventory", guiLeft + 191, guiTop + 5));
addLabel(new GuiNpcLabel(3,"inv.inventory", guiLeft + 8, guiTop + 101));
for(int i = 0; i < 9; i++){
int chance = 100;
if(npc.inventory.dropchance.containsKey(i)){
chance = npc.inventory.dropchance.get(i);
}
if(chance <= 0 || chance > 100)
chance = 100;
chances.put(i, chance);
GuiNpcSlider slider = new GuiNpcSlider(this, i, guiLeft + 211, guiTop + 14 + i * 21, ((float)chance)/100);
addSlider(slider);
addLabel(new GuiNpcLabel(4,"Tab", guiLeft + 381, guiTop + 5));
addButton(new GuiNpcButton(11, guiLeft + 375, guiTop + 13, 30, 20, "1"));
addButton(new GuiNpcButton(12, guiLeft + 375, guiTop + 34, 30, 20, "2"));
for(int c = 0; c < 4; c++) {
for (int r = 0; r < 9; r++) {
double chance = 100;
if (npc.inventory.dropchance.containsKey(r + c*9)) {
chance = npc.inventory.dropchance.get(r + c*9);
}
if (chance <= 0 || chance > 100)
chance = 100;
chances.put(r + c*9, chance);
if(Math.floor((float)c/2) != this.inventoryTab) {
container.getSlot(r + c*9 + 7).xDisplayPosition = 10000;
container.getSlot(r + c*9 + 7).yDisplayPosition = 10000;
continue;
} else {
container.getSlot(r + c*9 + 7).xDisplayPosition = 191 + (c-this.inventoryTab*2) * 90;
container.getSlot(r + c*9 + 7).yDisplayPosition = 16 + r * 21;
}
GuiNpcTextField textField = new GuiNpcTextField(2 + r + c*9, this, fontRendererObj, guiLeft + 210 + (c-this.inventoryTab*2)*90, guiTop + 14 + r * 21, 60, 18, chance + "");
addLabel(new GuiNpcLabel(c*9 + r + 5,"%", guiLeft + 272 + (c-this.inventoryTab*2)*90, guiTop + 16 + r * 21));
textField.doublesOnly = true;
textField.setMinMaxDefaultDouble(0, 100, 100);
addTextField(textField);
}
}
}
private void drawSlot(int x, int y)
{
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND); // Forge: Blending needs to be enabled for this.
this.mc.getTextureManager().bindTexture(slot);
this.drawTexturedModalRect(x, y, 0,0,18, 18);
GL11.glDisable(GL11.GL_BLEND); // Forge: And clean that up
GL11.glEnable(GL11.GL_LIGHTING);
}
@Override
protected void actionPerformed(GuiButton guibutton) {
if(guibutton.id == 10){
npc.inventory.lootMode = ((GuiNpcButton)guibutton).getValue();
}
if(guibutton.id == 11 || guibutton.id == 12){
this.inventoryTab = Integer.parseInt(guibutton.displayString)-1;
initGui();
}
}
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
@@ -82,12 +116,18 @@ public class GuiNPCInv extends GuiContainerNPCInterface2 implements ISliderListe
super.drawGuiContainerBackgroundLayer(f, i, j);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(slot);
for(int id = 4; id <= 6;id++){
Slot slot = container.getSlot(id);
if(slot.getHasStack())
drawTexturedModalRect(guiLeft + slot.xDisplayPosition - 1, guiTop + slot.yDisplayPosition -1, 0, 0, 18, 18);
}
for(int c = 0; c < 2; c++) {
for (int r = 0; r < 9; r++) {
this.drawSlot(guiLeft + 190 + c*90, guiTop + 15 + r * 21);
}
}
}
public void drawScreen(int i, int j, float f)
{
@@ -149,18 +189,12 @@ public class GuiNPCInv extends GuiContainerNPCInterface2 implements ISliderListe
npc.inventory.readEntityFromNBT(compound);
initGui();
}
@Override
public void mouseDragged(GuiNpcSlider guiNpcSlider) {
guiNpcSlider.displayString = StatCollector.translateToLocal("inv.dropChance") + ": " + (int) (guiNpcSlider.sliderValue * 100) + "%";
}
@Override
public void mousePressed(GuiNpcSlider guiNpcSlider) {
}
@Override
public void mouseReleased(GuiNpcSlider guiNpcSlider) {
chances.put(guiNpcSlider.id, (int) (guiNpcSlider.sliderValue * 100));
}
@Override
public void unFocused(GuiNpcTextField textfield) {
if(textfield.id >= 2){
chances.put(textfield.id-2, Double.parseDouble(textfield.getText()));
this.save();
}
}
}
@@ -4,6 +4,7 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcs;
import noppes.npcs.DataDisplay;
import noppes.npcs.client.Client;
import noppes.npcs.client.NoppesUtil;
@@ -56,7 +57,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene
addLabel(new GuiNpcLabel(2,"display.size", guiLeft + 175, y + 5));
addTextField(new GuiNpcTextField(2,this, fontRendererObj, guiLeft + 203, y, 40, 20, display.modelSize + ""));
getTextField(2).integersOnly = true;
getTextField(2).setMinMaxDefault(1, Integer.MAX_VALUE, 5);
getTextField(2).setMinMaxDefault(1, CustomNpcs.NpcSizeLimit, 5);
//addLabel(new GuiNpcLabel(3,"(1-30)", guiLeft + 246 , y + 5));
y+=23;
@@ -37,29 +37,35 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi
quest = (QuestKill) q.questInterface;
setBackground("menubg.png");
xSize = 356;
ySize = 216;
setBackground("largebg.png");
bgScale = 1.7F;
bgScaleX = 1.1F;
xSize = 300;
ySize = 300;
closeOnEsc = true;
}
public void initGui() {
super.initGui();
guiTop -= 20;
int i = 0;
addLabel(new GuiNpcLabel(0, "You can fill in npc or player names too", guiLeft + 4, guiTop + 50));
addLabel(new GuiNpcLabel(0, "You can fill in npc or player names too", guiLeft + 4, guiTop + 20));
for (String name : quest.targets.keySet()) {
this.addTextField(new GuiNpcTextField(i, this, fontRendererObj, guiLeft + 4, guiTop + 70 + i * 22, 180, 20, name));
this.addTextField(new GuiNpcTextField(i + 3, this, fontRendererObj, guiLeft + 186, guiTop + 70 + i * 22, 24, 20, quest.targets.get(name) + ""));
this.getTextField(i+3).integersOnly = true;
this.getTextField(i+3).setMinMaxDefault(1, Integer.MAX_VALUE, 1);
this.addTextField(new GuiNpcTextField(i, this, fontRendererObj, guiLeft + 4, guiTop + 40 + i * 22, 180, 20, name));
this.addTextField(new GuiNpcTextField(i + 12, this, fontRendererObj, guiLeft + 186, guiTop + 40 + i * 22, 24, 20, quest.targets.get(name) + ""));
this.getTextField(i+12).integersOnly = true;
this.getTextField(i+12).setMinMaxDefault(1, Integer.MAX_VALUE, 1);
i++;
}
for(;i < 3; i++){
this.addTextField(new GuiNpcTextField(i, this, fontRendererObj, guiLeft + 4, guiTop + 70 + i * 22, 180, 20, ""));
this.addTextField(new GuiNpcTextField(i + 3, this, fontRendererObj, guiLeft + 186, guiTop + 70 + i * 22, 24, 20, "1"));
this.getTextField(i+3).integersOnly = true;
this.getTextField(i+3).setMinMaxDefault(1, Integer.MAX_VALUE, 1);
for(;i < 12; i++){
this.addTextField(new GuiNpcTextField(i, this, fontRendererObj, guiLeft + 4, guiTop + 40 + i * 22, 180, 20, ""));
this.addTextField(new GuiNpcTextField(i + 12, this, fontRendererObj, guiLeft + 186, guiTop + 40 + i * 22, 24, 20, "1"));
this.getTextField(i+12).integersOnly = true;
this.getTextField(i+12).setMinMaxDefault(1, Integer.MAX_VALUE, 1);
}
Map<?,?> data = EntityList.stringToClassMapping;
ArrayList<String> list = new ArrayList<String>();
@@ -78,9 +84,13 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi
scroll.setList(list);
scroll.setSize(130, 198);
scroll.guiLeft = guiLeft + 220;
scroll.guiTop = guiTop + 14;
scroll.guiTop = guiTop + 40;
addScroll(scroll);
this.addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 140, 98, 20, "gui.back"));
guiTop += 50;
this.addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 300, 98, 20, "gui.back"));
this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + 260, 98, 20, new String[]{"Any", "NPCs"}, quest.targetType));
guiTop -= 50;
scroll.visible = GuiNpcTextField.isFieldActive();
}
@@ -90,6 +100,9 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi
if (guibutton.id == 0) {
close();
}
if (guibutton.id == 1) {
quest.targetType = guibutton.displayString.equals("NPCs") ? 1 : 0;
}
}
public void mouseClicked(int i, int j, int k)
{
@@ -101,18 +114,18 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi
@Override
public void unFocused(GuiNpcTextField guiNpcTextField) {
if(guiNpcTextField.id < 3)
if(guiNpcTextField.id < 12)
lastSelected = guiNpcTextField;
saveTargets();
}
private void saveTargets(){
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(int i = 0; i< 3; i++){
for(int i = 0; i< 12; i++){
String name = getTextField(i).getText();
if(name.isEmpty())
continue;
map.put(name, getTextField(i+3).getInteger());
map.put(name, getTextField(i+12).getInteger());
}
quest.targets = map;
}
@@ -45,7 +45,10 @@ public abstract class GuiNPCInterface extends GuiScreen
public int mouseX, mouseY;
public float bgScale = 1;
public float bgScaleX = 1;
public float bgScaleY = 1;
public float bgScaleZ = 1;
public GuiNPCInterface(EntityNPCInterface npc)
{
this.player = Minecraft.getMinecraft().thePlayer;
@@ -102,7 +105,7 @@ public abstract class GuiNPCInterface extends GuiScreen
gui.setWorldAndResolution(mc, 350, 250);
extra.put(gui.id, gui);
}
public void mouseClicked(int i, int j, int k)
{
if(AWTWindow != null)
@@ -202,11 +205,11 @@ public abstract class GuiNPCInterface extends GuiScreen
scrolls.put(scroll.id, scroll);
}
public GuiCustomScroll getScroll(int id){
return scrolls.get(id);
return scrolls.get(id);
}
public abstract void save();
@Override
public void drawScreen(int i, int j, float f){
if(AWTWindow != null){
@@ -223,12 +226,12 @@ public abstract class GuiNPCInterface extends GuiScreen
mouseY = j;
if(drawDefaultBackground && subgui == null)
drawDefaultBackground();
if(background != null && mc.renderEngine != null){
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPushMatrix();
GL11.glTranslatef(guiLeft, guiTop, 0);
GL11.glScalef(bgScale, bgScale, bgScale);
GL11.glScalef(bgScale*bgScaleX, bgScale*bgScaleY, bgScale*bgScaleZ);
mc.renderEngine.bindTexture(background);
if(xSize > 256){
drawTexturedModalRect(0, 0, 0, 0, 250, ySize);
@@ -112,8 +112,6 @@ public class RenderCustomNpc extends RenderNPCHumanMale{
@Override
public void doRender(EntityLiving entityliving, double d, double d1, double d2, float f, float f1){
EntityNPCInterface npc = (EntityNPCInterface) entityliving;
super.doRender(entityliving, d, d1, d2, f, f1);
}
@@ -1,6 +1,6 @@
package noppes.npcs.constants;
public enum EnumPacketClient {
CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN
CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN, OVERLAY_DATA, OVERLAY_CLOSE
}
@@ -16,15 +16,16 @@ public class ContainerNPCInv extends Container{
addSlotToContainer(new Slot(npc.inventory, 5, 81, 40));
addSlotToContainer(new Slot(npc.inventory, 6, 81, 58));
for(int l = 0; l < 9; l++){
addSlotToContainer(new Slot(npc.inventory, l + 7 , 191 , 16 + l * 21));
for(int c = 0; c < 4; c++) {
for (int r = 0; r < 9; r++) {
addSlotToContainer(new Slot(npc.inventory, c*9 + r + 7, 191 + (c%2)*90, 16 + r * 21));
}
}
for(int i1 = 0; i1 < 3; i1++){
for(int l1 = 0; l1 < 9; l1++){
addSlotToContainer(new Slot(player.inventory, l1 + i1 * 9 + 9, l1 * 18 + 8, 113 + i1 * 18));
}
}
for(int j1 = 0; j1 < 9; j1++){
@@ -3,10 +3,7 @@ package noppes.npcs.controllers;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.constants.EnumGuiType;
@@ -18,6 +15,7 @@ import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.event.CustomGuiEvent;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.overlay.ScriptOverlay;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
import java.io.IOException;
@@ -42,6 +40,15 @@ public class CustomGuiController {
}
}
public static void openOverlay(ScriptPlayer player, ScriptOverlay gui) {
Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.OVERLAY_DATA, new Object[]{gui.toNBT()});
}
public static boolean updateOverlay(ScriptPlayer player, ScriptOverlay gui) {
Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.OVERLAY_DATA, new Object[]{gui.toNBT()});
return true;
}
static boolean checkGui(CustomGuiEvent event) {
EntityPlayer player = (EntityPlayer) event.player.getMCEntity();
if (!(player.openContainer instanceof ContainerCustomGui)) {
@@ -239,4 +239,39 @@ public class Dialog implements ICompatibilty, IDialog {
public void setCommand(String command) {
this.command = command;
}
public void setDarkenScreen(boolean darkenScreen) {
this.darkenScreen = darkenScreen;
}
public boolean getDarkenScreen() {
return this.darkenScreen;
}
public void setDisableEsc(boolean disableEsc) {
this.disableEsc = disableEsc;
}
public boolean getDisableEsc() {
return this.disableEsc;
}
public void setShowWheel(boolean showWheel) {
this.showWheel = showWheel;
}
public boolean getShowWheel() {
return this.showWheel;
}
public void setHideNPC(boolean hideNPC) {
this.hideNPC = hideNPC;
}
public boolean getHideNPC() {
return this.hideNPC;
}
public void setSound(String sound) {
this.sound = sound;
}
public String getSound() {
return this.sound;
}
}
@@ -20,6 +20,7 @@ import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.handler.data.IQuest;
import noppes.npcs.scripted.handler.data.IQuestCategory;
import noppes.npcs.scripted.handler.data.IQuestInterface;
import noppes.npcs.scripted.handler.data.IQuestObjective;
import noppes.npcs.scripted.interfaces.IContainer;
import noppes.npcs.scripted.interfaces.IPlayer;
@@ -242,4 +243,8 @@ public class Quest implements ICompatibilty, IQuest {
public IContainer getRewards() {
return NpcAPI.Instance().getIContainer(this.rewardItems);
}
public IQuestInterface getQuestInterface(){
return this.questInterface;
}
}
@@ -14,9 +14,10 @@ import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.PlayerData;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.handler.data.IQuestDialog;
import noppes.npcs.scripted.handler.data.IQuestObjective;
public class QuestDialog extends QuestInterface{
public class QuestDialog extends QuestInterface implements IQuestDialog {
public HashMap<Integer,Integer> dialogs = new HashMap<Integer,Integer>();
@@ -4,9 +4,10 @@ import java.util.Vector;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.scripted.handler.data.IQuestInterface;
import noppes.npcs.scripted.handler.data.IQuestObjective;
public abstract class QuestInterface {
public abstract class QuestInterface implements IQuestInterface {
public int questId;
public abstract void writeEntityToNBT(NBTTagCompound compound);
public abstract void readEntityFromNBT(NBTTagCompound compound);
@@ -9,10 +9,11 @@ import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.NpcMiscInventory;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.handler.data.IQuestItem;
import noppes.npcs.scripted.handler.data.IQuestObjective;
import noppes.npcs.util.ValueUtil;
public class QuestItem extends QuestInterface{
public class QuestItem extends QuestInterface implements IQuestItem {
public NpcMiscInventory items = new NpcMiscInventory(3);
public boolean leaveItems = false;
public boolean ignoreDamage = false;
@@ -137,6 +138,27 @@ public class QuestItem extends QuestInterface{
return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]);
}
public void setLeaveItems(boolean leaveItems){
this.leaveItems = leaveItems;
}
public boolean getLeaveItems(){
return this.leaveItems;
}
public void setIgnoreDamage(boolean ignoreDamage){
this.ignoreDamage = ignoreDamage;
}
public boolean getIgnoreDamage(){
return this.ignoreDamage;
}
public void setIgnoreNbt(boolean ignoreNbt){
this.ignoreNBT = ignoreNbt;
}
public boolean getIgnoreNbt(){
return this.ignoreNBT;
}
class QuestItemObjective implements IQuestObjective {
private final QuestItem parent;
private final EntityPlayer player;
@@ -14,19 +14,32 @@ import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.PlayerQuestData;
import noppes.npcs.controllers.QuestData;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.handler.data.IQuestKill;
import noppes.npcs.scripted.handler.data.IQuestObjective;
public class QuestKill extends QuestInterface{
public class QuestKill extends QuestInterface implements IQuestKill {
public HashMap<String,Integer> targets = new HashMap<String,Integer>();
@Override
public void readEntityFromNBT(NBTTagCompound compound) {
targets = NBTTags.getStringIntegerMap(compound.getTagList("QuestDialogs", 10));
}
public int targetType = 0;
@Override
public void writeEntityToNBT(NBTTagCompound compound) {
compound.setTag("QuestDialogs", NBTTags.nbtStringIntegerMap(targets));
compound.setTag("QuestKills", NBTTags.nbtStringIntegerMap(targets));
//compound.setTag("QuestDialogs", NBTTags.nbtStringIntegerMap(targets));
compound.setInteger("TargetType",targetType);
}
@Override
public void readEntityFromNBT(NBTTagCompound compound) {
if(!compound.hasKey("QuestKills")) {
targets.clear();
HashMap<String,Integer> oldTargets = NBTTags.getStringIntegerMap(compound.getTagList("QuestDialogs", 10));
targets.putAll(oldTargets);
} else {
targets = NBTTags.getStringIntegerMap(compound.getTagList("QuestKills", 10));
}
//targets = NBTTags.getStringIntegerMap(compound.getTagList("QuestDialogs", 10));
targetType = compound.getInteger("TargetType");
}
@Override
@@ -90,6 +103,18 @@ public class QuestKill extends QuestInterface{
return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]);
}
public void setTargetType(int type) {
if(type < 0)
type = 0;
if(type > 1)
type = 1;
this.targetType = type;
}
public int getTargetType() {
return this.targetType;
}
class QuestKillObjective implements IQuestObjective {
private final QuestKill parent;
private final EntityPlayer player;
@@ -13,9 +13,10 @@ import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.PlayerQuestData;
import noppes.npcs.controllers.QuestData;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.handler.data.IQuestLocation;
import noppes.npcs.scripted.handler.data.IQuestObjective;
public class QuestLocation extends QuestInterface{
public class QuestLocation extends QuestInterface implements IQuestLocation {
public String location = "";
public String location2 = "";
public String location3 = "";
@@ -118,6 +119,27 @@ public class QuestLocation extends QuestInterface{
return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]);
}
public void setLocation1(String loc1){
this.location = loc1;
}
public String getLocation1(){
return location;
}
public void setLocation2(String loc2){
this.location2 = loc2;
}
public String getLocation2(){
return location2;
}
public void setLocation3(String loc3){
this.location3 = loc3;
}
public String getLocation3(){
return location3;
}
class QuestLocationObjective implements IQuestObjective {
private final QuestLocation parent;
private final EntityPlayer player;
@@ -1,6 +1,7 @@
package noppes.npcs.scripted.entity;
import net.minecraft.item.ItemStack;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.constants.*;
import noppes.npcs.controllers.Line;
@@ -53,6 +54,9 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
public void setSize(int size){
if(size < 1)
size = 1;
if(size > CustomNpcs.NpcSizeLimit)
size = CustomNpcs.NpcSizeLimit;
npc.display.modelSize = size;
npc.script.clientNeedsUpdate = true;
}
@@ -528,7 +532,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param slot The slot from the NPC's drop list to return (0-8)
* @return The chance of dropping the item in this slot. Returns 100 if the slot is not found.
*/
public int getLootChance(int slot) {
public double getLootChance(int slot) {
if(!npc.inventory.dropchance.containsKey(slot))
return 100;
@@ -540,8 +544,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param slot The slot from the NPC's drop list to change
* @param chance The new chance of dropping the item in this slot
*/
public void setLootChance(int slot, int chance) {
if(slot < 0 || slot > 8)
public void setLootChance(int slot, double chance) {
if(!npc.inventory.dropchance.containsKey(slot))
return;
if(chance < 0)
@@ -25,10 +25,8 @@ import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.event.FactionEvent;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.handler.data.IQuest;
import noppes.npcs.scripted.interfaces.IContainer;
import noppes.npcs.scripted.interfaces.ICustomGui;
import noppes.npcs.scripted.interfaces.IPlayer;
import noppes.npcs.scripted.interfaces.ITimers;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.overlay.ScriptOverlay;
import noppes.npcs.util.ValueUtil;
import java.util.ArrayList;
@@ -459,7 +457,15 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
public void closeGui() {
((EntityPlayerMP)this.entity).closeContainer();
Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.GUI_CLOSE, new Object[]{-1, new NBTTagCompound()});
Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.GUI_CLOSE, -1, new NBTTagCompound());
}
public void showCustomOverlay(ICustomOverlay overlay) {
CustomGuiController.openOverlay(this, (ScriptOverlay) overlay);
}
public void closeOverlay(int id) {
Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.OVERLAY_CLOSE, id, new NBTTagCompound());
}
public IQuest[] getFinishedQuests() {
@@ -13,17 +13,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.PlayerDataScript;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import noppes.npcs.scripted.interfaces.IPlayer;
import noppes.npcs.scripted.interfaces.IButton;
import noppes.npcs.scripted.interfaces.ICustomGui;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import noppes.npcs.scripted.interfaces.IItemSlot;
import noppes.npcs.scripted.interfaces.ILabel;
import noppes.npcs.scripted.interfaces.IScroll;
import noppes.npcs.scripted.interfaces.ITextField;
import noppes.npcs.scripted.interfaces.ITexturedRect;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.controllers.CustomGuiController;
import noppes.npcs.controllers.ScriptContainer;
@@ -170,6 +161,18 @@ public class ScriptGui implements ICustomGui {
return (IScroll)this.components.get(this.components.size() - 1);
}
public ILine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness) {
ScriptGuiLine line = new ScriptGuiLine(id, x1, y1, x2, y2, color, thickness);
this.components.add(line);
return (ILine) this.components.get(this.components.size() - 1);
}
public ILine addLine(int id, int x1, int y1, int x2, int y2) {
ScriptGuiLine line = new ScriptGuiLine(id, x1, y1, x2, y2);
this.components.add(line);
return (ILine) this.components.get(this.components.size() - 1);
}
public void showPlayerInventory(int x, int y) {
this.showPlayerInv = true;
this.playerInvX = x;
@@ -4,6 +4,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import noppes.npcs.scripted.interfaces.ICustomOverlayComponent;
public abstract class ScriptGuiComponent implements ICustomGuiComponent {
int id;
@@ -11,6 +12,9 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent {
int posY;
String[] hoverText;
int color = 0xFFFFFF;
float alpha = 1.0F;
public ScriptGuiComponent() {
}
@@ -55,11 +59,30 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent {
return this;
}
public int getColor() {
return this.color;
}
public ICustomGuiComponent setColor(int color) {
this.color = color;
return this;
}
public float getAlpha() {
return this.alpha;
}
public void setAlpha(float alpha) {
this.alpha = alpha;
}
public abstract int getType();
public NBTTagCompound toNBT(NBTTagCompound nbt) {
nbt.setInteger("id", this.id);
nbt.setIntArray("pos", new int[]{this.posX, this.posY});
nbt.setInteger("color", this.color);
nbt.setFloat("alpha",this.alpha);
if (this.hoverText != null) {
NBTTagList list = new NBTTagList();
String[] var3 = this.hoverText;
@@ -84,6 +107,8 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent {
public ScriptGuiComponent fromNBT(NBTTagCompound nbt) {
this.setID(nbt.getInteger("id"));
this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]);
this.setColor(nbt.getInteger("color"));
this.setAlpha(nbt.getFloat("alpha"));
if (nbt.hasKey("hover")) {
NBTTagList list = nbt.getTagList("hover", 8);
String[] hoverText = new String[list.tagCount()];
@@ -112,6 +137,8 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent {
return (new ScriptGuiScroll()).fromNBT(nbt);
case 5:
return (new ScriptGuiItemSlot()).fromNBT(nbt);
case 6:
return (new ScriptGuiLine()).fromNBT(nbt);
default:
return null;
}
@@ -7,17 +7,14 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel {
String label;
int width;
int height;
int color;
float scale;
boolean shadow;
public ScriptGuiLabel() {
this.color = 16777215;
this.scale = 1.0F;
}
public ScriptGuiLabel(int id, String label, int x, int y, int width, int height) {
this.color = 16777215;
this.scale = 1.0F;
this.setID(id);
this.setText(label);
@@ -54,15 +51,6 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel {
return this;
}
public int getColor() {
return this.color;
}
public ILabel setColor(int color) {
this.color = color;
return this;
}
public float getScale() {
return this.scale;
}
@@ -88,7 +76,6 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel {
super.toNBT(nbt);
nbt.setString("label", this.label);
nbt.setIntArray("size", new int[]{this.width, this.height});
nbt.setInteger("color", this.color);
nbt.setFloat("scale", this.scale);
nbt.setBoolean("shadow",this.shadow);
return nbt;
@@ -98,9 +85,8 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel {
super.fromNBT(nbt);
this.setText(nbt.getString("label"));
this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]);
this.setColor(nbt.getInteger("color"));
this.setScale(nbt.getFloat("scale"));
this.enableShadow(this.shadow);
this.enableShadow(nbt.getBoolean("shadow"));
return this;
}
}
@@ -0,0 +1,98 @@
package noppes.npcs.scripted.gui;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.scripted.interfaces.ILine;
public class ScriptGuiLine extends ScriptGuiComponent implements ILine {
int x1;
int y1;
int x2;
int y2;
int thickness = 2;
public ScriptGuiLine(){
}
public ScriptGuiLine(int id, int x1, int y1, int x2, int y2){
this.setPos(x1, y1);
this.setID(id);
this.hoverText = new String[]{""};
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public ScriptGuiLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){
this.setPos(x1, y1);
this.setID(id);
this.hoverText = new String[]{""};
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.color = color;
this.thickness = thickness;
}
@Override
public int getType() {
return 6;
}
public NBTTagCompound toNBT(NBTTagCompound nbt) {
super.toNBT(nbt);
nbt.setInteger("X1",x1);
nbt.setInteger("Y1",y1);
nbt.setInteger("X2",x2);
nbt.setInteger("Y2",y2);
nbt.setInteger("Thickness",thickness);
return nbt;
}
public ScriptGuiComponent fromNBT(NBTTagCompound nbt) {
super.fromNBT(nbt);
x1 = nbt.getInteger("X1");
y1 = nbt.getInteger("Y1");
x2 = nbt.getInteger("X2");
y2 = nbt.getInteger("Y2");
thickness = nbt.getInteger("Thickness");
return this;
}
public int getX1(){
return this.x1;
}
public int getY1(){
return this.y1;
}
public int getX2(){
return this.x2;
}
public int getY2(){
return this.y2;
}
public int getThickness(){
return this.thickness;
}
public void setX1(int x1){
this.x1 = x1;
}
public void setY1(int y1){
this.y1 = y1;
}
public void setX2(int x2){
this.x2 = x2;
}
public void setY2(int y2){
this.y2 = y2;
}
public void setThickness(int thickness){
this.thickness = thickness;
}
}
@@ -34,5 +34,20 @@ public interface IDialog {
IDialogCategory getCategory();
void setDarkenScreen(boolean darkenScreen);
boolean getDarkenScreen();
void setDisableEsc(boolean disableEsc);
boolean getDisableEsc();
void setShowWheel(boolean showWheel);
boolean getShowWheel();
void setHideNPC(boolean hideNPC);
boolean getHideNPC();
void setSound(String sound);
String getSound();
void save();
}
@@ -44,4 +44,6 @@ public interface IQuest {
void save();
boolean getIsRepeatable();
IQuestInterface getQuestInterface();
}
@@ -0,0 +1,4 @@
package noppes.npcs.scripted.handler.data;
public interface IQuestDialog extends IQuestInterface {
}
@@ -0,0 +1,4 @@
package noppes.npcs.scripted.handler.data;
public interface IQuestInterface {
}
@@ -0,0 +1,12 @@
package noppes.npcs.scripted.handler.data;
public interface IQuestItem extends IQuestInterface {
void setLeaveItems(boolean leaveItems);
boolean getLeaveItems();
void setIgnoreDamage(boolean ignoreDamage);
boolean getIgnoreDamage();
void setIgnoreNbt(boolean ignoreNbt);
boolean getIgnoreNbt();
}
@@ -0,0 +1,6 @@
package noppes.npcs.scripted.handler.data;
public interface IQuestKill extends IQuestInterface {
void setTargetType(int type);
int getTargetType();
}
@@ -0,0 +1,12 @@
package noppes.npcs.scripted.handler.data;
public interface IQuestLocation extends IQuestInterface {
void setLocation1(String loc1);
String getLocation1();
void setLocation2(String loc2);
String getLocation2();
void setLocation3(String loc3);
String getLocation3();
}
@@ -44,6 +44,10 @@ public interface ICustomGui {
IScroll addScroll(int var1, int var2, int var3, int var4, int var5, String[] var6);
ILine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness);
ILine addLine(int id, int x1, int y1, int x2, int y2);
IItemSlot addItemSlot(int var1, int var2);
IItemSlot addItemSlot(int var1, int var2, IItemStack var3);
@@ -299,14 +299,14 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
* @param slot The slot from the NPC's drop list to return (0-8)
* @return The chance of dropping the item in this slot. Returns 100 if the slot is not found.
*/
public int getLootChance(int slot);
public double getLootChance(int slot);
/**
*
* @param slot The slot from the NPC's drop list to change
* @param chance The new chance of dropping the item in this slot
*/
public void setLootChance(int slot, int chance);
public void setLootChance(int slot, double chance);
/**
*
@@ -0,0 +1,4 @@
package noppes.npcs.scripted.interfaces;
public interface ICustomOverlay {
}
@@ -0,0 +1,29 @@
package noppes.npcs.scripted.interfaces;
public interface ICustomOverlayComponent {
int getID();
ICustomOverlayComponent setID(int id);
int getPosX();
int getPosY();
ICustomOverlayComponent setPos(int x, int y);
int getAlignment();
void setAlignment(int alignment);
int getColor();
ICustomOverlayComponent setColor(int color);
float getAlpha();
void setAlpha(float alpha);
float getRotation();
void setRotation(float rotation);
}
@@ -16,10 +16,6 @@ public interface ILabel extends ICustomGuiComponent {
ILabel setSize(int var1, int var2);
int getColor();
ILabel setColor(int var1);
float getScale();
ILabel setScale(float var1);
@@ -0,0 +1,15 @@
package noppes.npcs.scripted.interfaces;
public interface ILine extends ICustomGuiComponent {
int getX1();
int getY1();
int getX2();
int getY2();
int getThickness();
void setX1(int x1);
void setY1(int y1);
void setX2(int x2);
void setY2(int y2);
void setThickness(int thickness);
}
@@ -0,0 +1,17 @@
package noppes.npcs.scripted.interfaces;
public interface IOverlayLabel extends ICustomOverlayComponent {
String getText();
IOverlayLabel setText(String var1);
int getWidth();
int getHeight();
IOverlayLabel setSize(int var1, int var2);
float getScale();
IOverlayLabel setScale(float var1);
}
@@ -0,0 +1,17 @@
package noppes.npcs.scripted.interfaces;
import noppes.npcs.scripted.overlay.ScriptOverlayLine;
public interface IOverlayLine extends ICustomOverlayComponent {
int getX1();
int getY1();
int getX2();
int getY2();
int getThickness();
void setX1(int x1);
void setY1(int y1);
void setX2(int x2);
void setY2(int y2);
void setThickness(int thickness);
}
@@ -0,0 +1,23 @@
package noppes.npcs.scripted.interfaces;
public interface IOverlayTexturedRect extends ICustomOverlayComponent {
String getTexture();
IOverlayTexturedRect setTexture(String var1);
int getWidth();
int getHeight();
IOverlayTexturedRect setSize(int var1, int var2);
float getScale();
IOverlayTexturedRect setScale(float var1);
int getTextureX();
int getTextureY();
IOverlayTexturedRect setTextureOffset(int var1, int var2);
}
@@ -0,0 +1,161 @@
package noppes.npcs.scripted.overlay;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.controllers.CustomGuiController;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.PlayerDataScript;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.gui.ScriptGuiComponent;
import noppes.npcs.scripted.gui.ScriptGuiItemSlot;
import noppes.npcs.scripted.gui.ScriptGuiLabel;
import noppes.npcs.scripted.gui.ScriptGuiLine;
import noppes.npcs.scripted.interfaces.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ScriptOverlay implements ICustomOverlay {
int id;
int defaultAlignment = 0;
List<ICustomOverlayComponent> components = new ArrayList();
public ScriptOverlay(){
}
public ScriptOverlay(int id){
this.id = id;
}
public int getID() {
return this.id;
}
public List<ICustomOverlayComponent> getComponents() {
return this.components;
}
public PlayerDataScript getScriptHandler() {
return ScriptController.Instance.playerScripts;//this.scriptHandler;
}
public int getDefaultAlignment(){
return this.defaultAlignment;
}
public void setDefaultAlignment(int defaultAlignment) {
this.defaultAlignment = defaultAlignment;
}
public IOverlayTexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height) {
ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(id, texture, x, y, width, height);
this.components.add(component);
return (IOverlayTexturedRect)this.components.get(this.components.size() - 1);
}
public IOverlayTexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) {
ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(id, texture, x, y, width, height, textureX, textureY);
this.components.add(component);
return (IOverlayTexturedRect)this.components.get(this.components.size() - 1);
}
public IOverlayLabel addLabel(int id, String label, int x, int y, int width, int height) {
ScriptOverlayLabel component = new ScriptOverlayLabel(id, label, x, y, width, height);
this.components.add(component);
return (IOverlayLabel)this.components.get(this.components.size() - 1);
}
public IOverlayLabel addLabel(int id, String label, int x, int y, int width, int height, int color) {
ScriptOverlayLabel component = new ScriptOverlayLabel(id, label, x, y, width, height, color);
this.components.add(component);
return (IOverlayLabel)this.components.get(this.components.size() - 1);
}
public IOverlayLine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness) {
ScriptOverlayLine line = new ScriptOverlayLine(id, x1, y1, x2, y2, color, thickness);
this.components.add(line);
return (IOverlayLine) this.components.get(this.components.size() - 1);
}
public IOverlayLine addLine(int id, int x1, int y1, int x2, int y2) {
ScriptOverlayLine line = new ScriptOverlayLine(id, x1, y1, x2, y2);
this.components.add(line);
return (IOverlayLine) this.components.get(this.components.size() - 1);
}
public ICustomOverlayComponent getComponent(int componentID) {
Iterator var2 = this.components.iterator();
ICustomOverlayComponent component;
do {
if (!var2.hasNext()) {
return null;
}
component = (ICustomOverlayComponent)var2.next();
} while(component.getID() != componentID);
return component;
}
public void removeComponent(int componentID) {
for(int i = 0; i < this.components.size(); ++i) {
if (((ICustomOverlayComponent)this.components.get(i)).getID() == componentID) {
this.components.remove(i);
return;
}
}
}
public void updateComponent(ICustomOverlayComponent component) {
for(int i = 0; i < this.components.size(); ++i) {
ICustomOverlayComponent c = (ICustomOverlayComponent)this.components.get(i);
if (c.getID() == component.getID()) {
this.components.set(i, component);
return;
}
}
}
public void update(IPlayer player) {
CustomGuiController.updateOverlay((ScriptPlayer)player, this);
}
public ICustomOverlay fromNBT(NBTTagCompound tag) {
this.id = tag.getInteger("id");
List<ICustomOverlayComponent> components = new ArrayList();
NBTTagList list = tag.getTagList("components", 10);
for(int i = 0; i < list.tagCount(); i++){
NBTBase b = list.getCompoundTagAt(i);
ScriptOverlayComponent component = ScriptOverlayComponent.createFromNBT((NBTTagCompound)b);
components.add(component);
}
this.components = components;
return this;
}
public NBTTagCompound toNBT() {
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("id", this.id);
NBTTagList list = new NBTTagList();
Iterator var3 = this.components.iterator();
ICustomOverlayComponent c;
while(var3.hasNext()) {
c = (ICustomOverlayComponent)var3.next();
list.appendTag(((ScriptOverlayComponent)c).toNBT(new NBTTagCompound()));
}
tag.setTag("components", list);
return tag;
}
}
@@ -0,0 +1,123 @@
package noppes.npcs.scripted.overlay;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.scripted.gui.*;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
import noppes.npcs.scripted.interfaces.ICustomOverlayComponent;
import noppes.npcs.scripted.interfaces.IOverlayTexturedRect;
public abstract class ScriptOverlayComponent implements ICustomOverlayComponent {
int id;
int posX;
int posY;
int alignment = 0;
int color = 0xFFFFFF;
float alpha = 1.0F;
float rotation = 0;
/* ========ALIGNMENTS========
0 1 2
3 4 5
6 7 8
*/
public ScriptOverlayComponent(){
}
public int getID() {
return this.id;
}
public ICustomOverlayComponent setID(int id) {
this.id = id;
return this;
}
public int getPosX() {
return this.posX;
}
public int getPosY() {
return this.posY;
}
public ICustomOverlayComponent setPos(int x, int y) {
this.posX = x;
this.posY = y;
return this;
}
public int getAlignment() {
return this.alignment;
}
public void setAlignment(int alignment) {
this.alignment = alignment;
}
public int getColor() {
return this.color;
}
public ICustomOverlayComponent setColor(int color) {
this.color = color;
return this;
}
public float getAlpha() {
return this.alpha;
}
public void setAlpha(float alpha) {
this.alpha = alpha;
}
public float getRotation() {
return rotation;
}
public void setRotation(float rotation) {
this.rotation = rotation;
}
public abstract int getType();
public NBTTagCompound toNBT(NBTTagCompound nbt) {
nbt.setInteger("id", this.id);
nbt.setIntArray("pos", new int[]{this.posX, this.posY});
nbt.setInteger("alignment",this.alignment);
nbt.setInteger("color", this.color);
nbt.setFloat("alpha",this.alpha);
nbt.setFloat("rotation",this.rotation);
nbt.setInteger("type", this.getType());
return nbt;
}
public ScriptOverlayComponent fromNBT(NBTTagCompound nbt) {
this.setID(nbt.getInteger("id"));
this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]);
this.setAlignment(nbt.getInteger("alignment"));
this.setColor(nbt.getInteger("color"));
this.setAlpha(nbt.getFloat("alpha"));
this.setRotation(nbt.getInteger("rotation"));
return this;
}
public static ScriptOverlayComponent createFromNBT(NBTTagCompound nbt) {
switch(nbt.getInteger("type")) {
case 0:
return (new ScriptOverlayTexturedRect()).fromNBT(nbt);
case 1:
return (new ScriptOverlayLabel()).fromNBT(nbt);
case 2:
return (new ScriptOverlayLine()).fromNBT(nbt);
default:
return null;
}
}
}
@@ -0,0 +1,97 @@
package noppes.npcs.scripted.overlay;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.scripted.gui.ScriptGuiComponent;
import noppes.npcs.scripted.interfaces.ILabel;
import noppes.npcs.scripted.interfaces.IOverlayLabel;
public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverlayLabel {
String label;
int width;
int height;
float scale;
boolean shadow;
public ScriptOverlayLabel() {
this.color = 16777215;
this.scale = 1.0F;
}
public ScriptOverlayLabel(int id, String label, int x, int y, int width, int height) {
this.color = 16777215;
this.scale = 1.0F;
this.setID(id);
this.setText(label);
this.setPos(x, y);
this.setSize(width, height);
this.setShadow(false);
}
public ScriptOverlayLabel(int id, String label, int x, int y, int width, int height, int color) {
this(id, label, x, y, width, height);
this.setColor(color);
}
public String getText() {
return this.label;
}
public IOverlayLabel setText(String label) {
this.label = label;
return this;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public IOverlayLabel setSize(int width, int height) {
this.width = width;
this.height = height;
return this;
}
public float getScale() {
return this.scale;
}
public IOverlayLabel setScale(float scale) {
this.scale = scale;
return this;
}
public boolean getShadow(){
return this.shadow;
}
public void setShadow(boolean shadow){
this.shadow = shadow;
}
@Override
public int getType() {
return 1;
}
public NBTTagCompound toNBT(NBTTagCompound nbt) {
super.toNBT(nbt);
nbt.setString("label", this.label);
nbt.setIntArray("size", new int[]{this.width, this.height});
nbt.setFloat("scale", this.scale);
nbt.setBoolean("shadow",this.shadow);
return nbt;
}
public ScriptOverlayLabel fromNBT(NBTTagCompound nbt) {
super.fromNBT(nbt);
this.setText(nbt.getString("label"));
this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]);
this.setScale(nbt.getFloat("scale"));
this.setShadow(nbt.getBoolean("shadow"));
return this;
}
}
@@ -0,0 +1,97 @@
package noppes.npcs.scripted.overlay;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.scripted.gui.ScriptGuiComponent;
import noppes.npcs.scripted.interfaces.IOverlayLine;
public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverlayLine {
int x1;
int y1;
int x2;
int y2;
int thickness = 2;
public ScriptOverlayLine(){
}
public ScriptOverlayLine(int id, int x1, int y1, int x2, int y2){
this.setPos(x1, y1);
this.setID(id);
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public ScriptOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){
this.setPos(x1, y1);
this.setID(id);
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.color = color;
this.thickness = thickness;
}
@Override
public int getType() {
return 2;
}
public NBTTagCompound toNBT(NBTTagCompound nbt) {
super.toNBT(nbt);
nbt.setInteger("X1",x1);
nbt.setInteger("Y1",y1);
nbt.setInteger("X2",x2);
nbt.setInteger("Y2",y2);
nbt.setInteger("Thickness",thickness);
return nbt;
}
public ScriptOverlayLine fromNBT(NBTTagCompound nbt) {
super.fromNBT(nbt);
x1 = nbt.getInteger("X1");
y1 = nbt.getInteger("Y1");
x2 = nbt.getInteger("X2");
y2 = nbt.getInteger("Y2");
thickness = nbt.getInteger("Thickness");
return this;
}
public int getX1(){
return this.x1;
}
public int getY1(){
return this.y1;
}
public int getX2(){
return this.x2;
}
public int getY2(){
return this.y2;
}
public int getThickness(){
return this.thickness;
}
public void setX1(int x1){
this.x1 = x1;
}
public void setY1(int y1){
this.y1 = y1;
}
public void setX2(int x2){
this.x2 = x2;
}
public void setY2(int y2){
this.y2 = y2;
}
public void setThickness(int thickness){
this.thickness = thickness;
}
}
@@ -0,0 +1,110 @@
package noppes.npcs.scripted.overlay;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.scripted.gui.ScriptGuiComponent;
import noppes.npcs.scripted.interfaces.IOverlayLabel;
import noppes.npcs.scripted.interfaces.IOverlayTexturedRect;
import noppes.npcs.scripted.interfaces.ITexturedRect;
public class ScriptOverlayTexturedRect extends ScriptOverlayComponent implements IOverlayTexturedRect {
int width;
int height;
int textureX;
int textureY;
float scale;
String texture;
public ScriptOverlayTexturedRect() {
this.textureY = -1;
this.scale = 1.0F;
}
public ScriptOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) {
this.textureY = -1;
this.scale = 1.0F;
this.setID(id);
this.setTexture(texture);
this.setPos(x, y);
this.setSize(width, height);
}
public ScriptOverlayTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) {
this(id, texture, x, y, width, height);
this.setTextureOffset(textureX, textureY);
}
public String getTexture() {
return this.texture;
}
public IOverlayTexturedRect setTexture(String texture) {
this.texture = texture;
return this;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public IOverlayTexturedRect setSize(int width, int height) {
this.width = width;
this.height = height;
return this;
}
public float getScale() {
return this.scale;
}
public IOverlayTexturedRect setScale(float scale) {
this.scale = scale;
return this;
}
public int getTextureX() {
return this.textureX;
}
public int getTextureY() {
return this.textureY;
}
public IOverlayTexturedRect setTextureOffset(int offsetX, int offsetY) {
this.textureX = offsetX;
this.textureY = offsetY;
return this;
}
@Override
public int getType() {
return 0;
}
public NBTTagCompound toNBT(NBTTagCompound nbt) {
super.toNBT(nbt);
nbt.setIntArray("size", new int[]{this.width, this.height});
nbt.setFloat("scale", this.scale);
nbt.setString("texture", this.texture);
if (this.textureX >= 0 && this.textureY >= 0) {
nbt.setIntArray("texPos", new int[]{this.textureX, this.textureY});
}
return nbt;
}
public ScriptOverlayComponent fromNBT(NBTTagCompound nbt) {
super.fromNBT(nbt);
this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]);
this.setScale(nbt.getFloat("scale"));
this.setTexture(nbt.getString("texture"));
if (nbt.hasKey("texPos")) {
this.setTextureOffset(nbt.getIntArray("texPos")[0], nbt.getIntArray("texPos")[1]);
}
return this;
}
}
@@ -41,6 +41,7 @@ import noppes.npcs.scripted.entity.*;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.handler.*;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.overlay.ScriptOverlay;
import noppes.npcs.util.JsonException;
import noppes.npcs.util.LRUHashMap;
import noppes.npcs.util.NBTJsonUtil;
@@ -275,4 +276,8 @@ public class WrapperNpcAPI extends NpcAPI {
public ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame) {
return new ScriptGui(id, width, height, pauseGame);
}
public ICustomOverlay createCustomOverlay(int id) {
return new ScriptOverlay(id);
}
}