Added more a full inventory to NPCs, selectable on two tabs and double-point values for NPC droprates.

This commit is contained in:
luisc committed 2022-01-27 03:50:36 -06:00
1 parent f14337f1bb
commit 989effb5c5
6 files changed
+116 -48

No files matched your search

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