mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 18:05:10 +00:00
Added more a full inventory to NPCs, selectable on two tabs and double-point values for NPC droprates.
This commit is contained in:
1 parent
f14337f1bb
commit
989effb5c5
6 files changed
+116
-48
No files matched your search
@@ -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,16 @@ 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)));
|
||||
}
|
||||
}
|
||||
dropchance = NBTTags.getIntegerDoubleMap(nbttagcompound.getTagList("DoubleDropChance", 10));
|
||||
|
||||
lootMode = nbttagcompound.getInteger("LootMode");
|
||||
}
|
||||
public HashMap<Integer, ItemStack> getWeapons() {
|
||||
@@ -89,10 +98,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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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++){
|
||||
|
||||
@@ -532,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;
|
||||
|
||||
@@ -544,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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user