Added the Flower Pouch. You guessed it, it stored flowers. And there was much rejoicing! Closes #538

This commit is contained in:
Lizbeth Rika committed 2015-03-16 22:24:20 +00:00
1 parent fba7495c0b
commit cedd724617
13 files changed
+497 -8

No files matched your search

@@ -0,0 +1,93 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Mar 16, 2015, 6:42:40 PM (GMT)]
*/
package vazkii.botania.client.gui.bag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerFlowerBag extends Container {
InventoryFlowerBag flowerBagInv;
public ContainerFlowerBag(EntityPlayer player) {
int i;
int j;
int slot = player.inventory.currentItem;
IInventory playerInv = player.inventory;
flowerBagInv = new InventoryFlowerBag(player, slot);
for(i = 0; i < 2; ++i)
for(j = 0; j < 8; ++j) {
int k = j + i * 8;
this.addSlotToContainer(new SlotFlower(flowerBagInv, k, 17 + j * 18, 26 + i * 18, k));
}
for(i = 0; i < 3; ++i)
for(j = 0; j < 9; ++j)
this.addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
for(i = 0; i < 9; ++i)
this.addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142));
}
@Override
public boolean canInteractWith(EntityPlayer player) {
boolean can = flowerBagInv.isUseableByPlayer(player);
if(!can)
onContainerClosed(player);
return can;
}
@Override
public void onContainerClosed(EntityPlayer player) {
super.onContainerClosed(player);
flowerBagInv.pushInventory();
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(p_82846_2_);
if(slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if(p_82846_2_ < 16) {
if(!this.mergeItemStack(itemstack1, 16, 52, true))
return null;
} else {
int i = itemstack.getItemDamage();
Slot slot1 = (Slot)this.inventorySlots.get(i);
if(slot1.isItemValid(itemstack) && !this.mergeItemStack(itemstack1, i, i + 1, true))
return null;
}
if(itemstack1.stackSize == 0)
slot.putStack((ItemStack)null);
else slot.onSlotChanged();
if(itemstack1.stackSize == itemstack.stackSize)
return null;
slot.onPickupFromSlot(p_82846_1_, itemstack1);
}
return itemstack;
}
}
@@ -0,0 +1,69 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Mar 16, 2015, 6:42:43 PM (GMT)]
*/
package vazkii.botania.client.gui.bag;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.block.ModBlocks;
public class GuiFlowerBag extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation(LibResources.GUI_FLOWER_BAG);
public GuiFlowerBag(EntityPlayer player) {
super(new ContainerFlowerBag(player));
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
String s = StatCollector.translateToLocal("item.botania:flowerBag.name");
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
List<Slot> slotList = inventorySlots.inventorySlots;
for(Slot slot : slotList)
if(slot instanceof SlotFlower) {
SlotFlower slotf = (SlotFlower) slot;
if(!slotf.getHasStack()) {
ItemStack stack = new ItemStack(ModBlocks.flower, 0, slotf.color);
int x = guiLeft + slotf.xDisplayPosition;
int y = guiTop + slotf.yDisplayPosition;
RenderHelper.enableGUIStandardItemLighting();
RenderItem.getInstance().renderItemIntoGUI(mc.fontRenderer, mc.renderEngine, stack, x, y);
RenderHelper.disableStandardItemLighting();
mc.fontRenderer.drawStringWithShadow("0", x + 11, y + 9, 0xFF6666);
}
}
}
}
@@ -0,0 +1,161 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Mar 16, 2015, 6:42:56 PM (GMT)]
*/
package vazkii.botania.client.gui.bag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.item.ItemFlowerBag;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibItemNames;
public class InventoryFlowerBag implements IInventory {
private static final ItemStack[] FALLBACK_INVENTORY = new ItemStack[16];
EntityPlayer player;
int slot;
ItemStack[] stacks = null;
boolean invPushed = false;
ItemStack storedInv = null;
public InventoryFlowerBag(EntityPlayer player, int slot) {
this.player = player;
this.slot = slot;
}
public static boolean isFlowerBag(ItemStack stack) {
return stack != null && stack.getItem() == ModItems.flowerBag;
}
ItemStack getStack() {
ItemStack stack = player.inventory.getStackInSlot(slot);
if(stack != null)
storedInv = stack;
return stack;
}
ItemStack[] getInventory() {
if(stacks != null)
return stacks;
ItemStack stack = getStack();
if(isFlowerBag(getStack())) {
stacks = ItemFlowerBag.loadStacks(stack);
return stacks;
}
return FALLBACK_INVENTORY;
}
public void pushInventory() {
if(invPushed)
return;
ItemStack stack = getStack();
if(stack == null)
stack = storedInv;
if(stack != null) {
ItemStack[] inv = getInventory();
ItemFlowerBag.setStacks(stack, inv);
}
invPushed = true;
}
@Override
public int getSizeInventory() {
return 16;
}
@Override
public ItemStack getStackInSlot(int i) {
return getInventory()[i];
}
@Override
public ItemStack decrStackSize(int i, int j) {
ItemStack[] inventorySlots = getInventory();
if (inventorySlots[i] != null) {
ItemStack stackAt;
if (inventorySlots[i].stackSize <= j) {
stackAt = inventorySlots[i];
inventorySlots[i] = null;
return stackAt;
} else {
stackAt = inventorySlots[i].splitStack(j);
if (inventorySlots[i].stackSize == 0)
inventorySlots[i] = null;
return stackAt;
}
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
return getStackInSlot(i);
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
ItemStack[] inventorySlots = getInventory();
inventorySlots[i] = itemstack;
}
@Override
public int getInventoryStackLimit() {
return isFlowerBag(getStack()) ? 64 : 0;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return isFlowerBag(getStack());
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return isFlowerBag(getStack());
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public void openInventory() {
// NO-OP
}
@Override
public void closeInventory() {
// NO-OP
}
@Override
public String getInventoryName() {
return LibItemNames.FLOWER_BAG;
}
@Override
public void markDirty() {
// NO-OP
}
}
@@ -0,0 +1,42 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Mar 16, 2015, 7:20:05 PM (GMT)]
*/
package vazkii.botania.client.gui.bag;
import vazkii.botania.common.block.ModBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
public class SlotFlower extends Slot {
InventoryFlowerBag inv;
int color;
public SlotFlower(InventoryFlowerBag p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_, int color) {
super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_);
this.color = color;
inv = p_i1824_1_;
}
@Override
public void onSlotChange(ItemStack oldStack, ItemStack newStack) {
inv.setInventorySlotContents(color, newStack);
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack.getItem() == Item.getItemFromBlock(ModBlocks.flower) && stack.getItemDamage() == color;
}
}
@@ -41,6 +41,7 @@ public final class LibResources {
public static final String GUI_POTIONS = PREFIX_GUI + "potions.png";
public static final String GUI_NEI_BLANK = PREFIX_GUI + "neiBlank.png";
public static final String GUI_NEI_BREWERY = PREFIX_GUI + "neiBrewery.png";
public static final String GUI_FLOWER_BAG = PREFIX_GUI + "flowerBag.png";
public static final String ENTRY_FLOWERS = PREFIX_ENTRIES + "flowers.png";
public static final String ENTRY_APOTHECARY = PREFIX_ENTRIES + "apothecary.png";
@@ -0,0 +1,115 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Mar 16, 2015, 6:43:33 PM (GMT)]
*/
package vazkii.botania.common.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibGuiIDs;
import vazkii.botania.common.lib.LibItemNames;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class ItemFlowerBag extends ItemMod {
private static final String TAG_ITEMS = "InvItems";
private static final String TAG_SLOT = "Slot";
public ItemFlowerBag() {
setUnlocalizedName(LibItemNames.FLOWER_BAG);
setMaxStackSize(1);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event) {
ItemStack stack = event.item.getEntityItem();
if(stack.getItem() == Item.getItemFromBlock(ModBlocks.flower) && stack.stackSize > 0) {
int color = stack.getItemDamage();
if(color > 15)
return;
for(int i = 0; i < event.entityPlayer.inventory.getSizeInventory(); i++) {
if(i == event.entityPlayer.inventory.currentItem)
continue; // prevent item deletion
ItemStack invStack = event.entityPlayer.inventory.getStackInSlot(i);
if(invStack != null && invStack.getItem() == this) {
ItemStack[] bagInv = loadStacks(invStack);
ItemStack stackAt = bagInv[color];
boolean didChange = false;
if(stackAt == null) {
bagInv[color] = stack.copy();
stack.stackSize = 0;
didChange = true;
} else {
int stackAtSize = stackAt.stackSize;
int stackSize = stack.stackSize;
int spare = 64 - stackAtSize;
int pass = Math.min(spare, stackSize);
if(pass > 0) {
stackAt.stackSize += pass;
stack.stackSize -= pass;
didChange = true;
}
}
if(didChange)
setStacks(invStack, bagInv);
}
if(stack.stackSize == 0)
return;
}
}
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
player.openGui(Botania.instance, LibGuiIDs.FLOWER_BAG, world, 0, 0, 0);
return stack;
}
public static ItemStack[] loadStacks(ItemStack stack) {
NBTTagList var2 = ItemNBTHelper.getList(stack, TAG_ITEMS, 10, false);
ItemStack[] inventorySlots = new ItemStack[16];
for(int var3 = 0; var3 < var2.tagCount(); ++var3) {
NBTTagCompound var4 = var2.getCompoundTagAt(var3);
byte var5 = var4.getByte(TAG_SLOT);
if(var5 >= 0 && var5 < inventorySlots.length)
inventorySlots[var5] = ItemStack.loadItemStackFromNBT(var4);
}
return inventorySlots;
}
public static void setStacks(ItemStack stack, ItemStack[] inventorySlots) {
NBTTagList var2 = new NBTTagList();
for(int var3 = 0; var3 < inventorySlots.length; ++var3)
if(inventorySlots[var3] != null) {
NBTTagCompound var4 = new NBTTagCompound();
var4.setByte(TAG_SLOT, (byte)var3);
inventorySlots[var3].writeToNBT(var4);
var2.appendTag(var4);
}
ItemNBTHelper.setList(stack, TAG_ITEMS, var2);
}
}
@@ -210,7 +210,8 @@ public final class ModItems {
public static Item crystalBow;
public static Item cosmetic;
public static Item swapRing;
public static Item flowerBag;
public static void init() {
lexicon = new ItemLexicon();
petal = new ItemPetal();
@@ -324,7 +325,8 @@ public final class ModItems {
crystalBow = new ItemCrystalBow();
cosmetic = new ItemBaubleCosmetic();
swapRing = new ItemSwapRing();
flowerBag = new ItemFlowerBag();
OreDictionary.registerOre(LibOreDict.LEXICON, lexicon);
for(int i = 0; i < 16; i++) {
OreDictionary.registerOre(LibOreDict.PETAL[i], new ItemStack(petal, 1, i));
@@ -14,5 +14,6 @@ public final class LibGuiIDs {
public static final int LEXICON = 0;
public static final int CRAFTING_HALO = 1;
public static final int FLOWER_BAG = 2;
}
@@ -125,6 +125,7 @@ public final class LibItemNames {
public static final String CRYSTAL_BOW = "crystalBow";
public static final String COSMETIC = "cosmetic";
public static final String SWAP_RING = "swapRing";
public static final String FLOWER_BAG = "flowerBag";
public static final String[] LENS_NAMES = new String[] {
"lensNormal",
@@ -12,6 +12,8 @@ package vazkii.botania.common.network;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import vazkii.botania.client.gui.bag.ContainerFlowerBag;
import vazkii.botania.client.gui.bag.GuiFlowerBag;
import vazkii.botania.client.gui.crafting.ContainerCraftingHalo;
import vazkii.botania.client.gui.crafting.GuiCraftingHalo;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
@@ -23,9 +25,10 @@ public class GuiHandler implements IGuiHandler {
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch(ID) {
case LibGuiIDs.CRAFTING_HALO : {
case LibGuiIDs.CRAFTING_HALO :
return new ContainerCraftingHalo(player.inventory, world);
}
case LibGuiIDs.FLOWER_BAG :
return new ContainerFlowerBag(player);
}
return null;
@@ -34,13 +37,13 @@ public class GuiHandler implements IGuiHandler {
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch(ID) {
case LibGuiIDs.LEXICON : {
case LibGuiIDs.LEXICON :
GuiLexicon lex = GuiLexicon.currentOpenLexicon;
return lex;
}
case LibGuiIDs.CRAFTING_HALO : {
case LibGuiIDs.CRAFTING_HALO :
return new GuiCraftingHalo(player.inventory, world);
}
case LibGuiIDs.FLOWER_BAG :
return new GuiFlowerBag(player);
}
return null;