Bauble Case.

This commit is contained in:
Vasco Lavos committed 2015-11-25 20:40:13 +00:00
1 parent d1d5c8d977
commit 6782ef152c
16 files changed
+466 -1

No files matched your search

@@ -8,7 +8,7 @@
*
* File Created @ [Sep 6, 2015, 1:11:25 AM (GMT)]
*/
package vazkii.botania.client.gui.bag;
package vazkii.botania.client.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@@ -10,6 +10,7 @@
*/
package vazkii.botania.client.gui.bag;
import vazkii.botania.client.gui.SlotLocked;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
@@ -0,0 +1,122 @@
/**
* 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 @ [25/11/2015, 19:59:06 (GMT)]
*/
package vazkii.botania.client.gui.box;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.client.gui.SlotLocked;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.common.container.InventoryBaubles;
import baubles.common.container.SlotBauble;
import baubles.common.lib.PlayerHandler;
public class ContainerBaubleBox extends Container {
InventoryBaubleBox baubleBoxInv;
InventoryBaubles baubles;
public ContainerBaubleBox(EntityPlayer player) {
int i;
int j;
int slot = player.inventory.currentItem;
IInventory playerInv = player.inventory;
baubleBoxInv = new InventoryBaubleBox(player, slot);
baubles = new InventoryBaubles(player);
baubles.setEventHandler(this);
if(!player.worldObj.isRemote)
baubles.stackList = PlayerHandler.getPlayerBaubles(player).stackList;
addSlotToContainer(new SlotBauble(baubles, BaubleType.AMULET, 0, 8, 8 + 0 * 18));
addSlotToContainer(new SlotBauble(baubles, BaubleType.RING, 1, 8, 8 + 1 * 18));
addSlotToContainer(new SlotBauble(baubles, BaubleType.RING, 2, 8, 8 + 2 * 18));
addSlotToContainer(new SlotBauble(baubles, BaubleType.BELT, 3, 8, 8 + 3 * 18));
for(i = 0; i < 4; ++i)
for(j = 0; j < 6; ++j) {
int k = j + i * 6;
addSlotToContainer(new SlotAnyBauble(baubleBoxInv, k, 62 + j * 18, 8 + i * 18));
}
for(i = 0; i < 3; ++i)
for(j = 0; j < 9; ++j)
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
for(i = 0; i < 9; ++i) {
if(player.inventory.currentItem == i)
addSlotToContainer(new SlotLocked(playerInv, i, 8 + i * 18, 142));
else addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer player) {
boolean can = baubleBoxInv.isUseableByPlayer(player);
if(!can)
onContainerClosed(player);
return can;
}
@Override
public void onContainerClosed(EntityPlayer player) {
super.onContainerClosed(player);
baubleBoxInv.pushInventory();
if(!player.worldObj.isRemote)
PlayerHandler.setPlayerBaubles(player, baubles);
}
@Override
public void putStacksInSlots(ItemStack[] p_75131_1_) {
baubles.blockEvents = true;
super.putStacksInSlots(p_75131_1_);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {
ItemStack itemstack = null;
Slot slot = (Slot)inventorySlots.get(p_82846_2_);
if(slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
System.out.println(p_82846_2_ + " " + itemstack);
if(p_82846_2_ < 28) {
if(!mergeItemStack(itemstack1, 28, 64, true))
return null;
} else {
if(itemstack1 != null && (itemstack1.getItem() instanceof IBauble || itemstack1.getItem() instanceof IManaItem) && !mergeItemStack(itemstack1, 4, 28, false))
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,53 @@
/**
* 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 @ [25/11/2015, 19:59:11 (GMT)]
*/
package vazkii.botania.client.gui.box;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.lib.LibResources;
public class GuiBaubleBox extends InventoryEffectRenderer {
private static final ResourceLocation texture = new ResourceLocation(LibResources.GUI_BAUBLE_BOX);
public GuiBaubleBox(EntityPlayer player) {
super(new ContainerBaubleBox(player));
}
@Override
protected boolean checkHotbarKeys(int p_146983_1_) {
return false;
}
@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);
mc.getTextureManager().bindTexture(texture);
int k = (width - xSize) / 2;
int l = (height - ySize) / 2;
drawTexturedModalRect(k, l, 0, 0, xSize, ySize);
for(int i1 = 0; i1 < 4; ++i1) {
Slot slot = (Slot) inventorySlots.inventorySlots.get(i1);
if(slot.getHasStack() && slot.getSlotStackLimit() == 1)
drawTexturedModalRect(k+slot.xDisplayPosition, l+slot.yDisplayPosition, 200, 0, 16, 16);
}
GuiInventory.func_147046_a(this.guiLeft + 43, this.guiTop + 61, 20, (float)(this.guiLeft + 43 - p_146976_2_), (float)(this.guiTop + 45 - 30 - p_146976_3_), this.mc.thePlayer);
}
}
@@ -0,0 +1,160 @@
/**
* 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 @ [25/11/2015, 19:59:16 (GMT)]
*/
package vazkii.botania.client.gui.box;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import vazkii.botania.common.item.ItemBaubleBox;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibItemNames;
public class InventoryBaubleBox 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 InventoryBaubleBox(EntityPlayer player, int slot) {
this.player = player;
this.slot = slot;
}
public static boolean isBaubleBox(ItemStack stack) {
return stack != null && stack.getItem() == ModItems.baubleBox;
}
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(isBaubleBox(getStack())) {
stacks = ItemBaubleBox.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();
ItemBaubleBox.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 slot, ItemStack itemstack) {
ItemStack[] inventorySlots = getInventory();
inventorySlots[slot] = itemstack;
}
@Override
public int getInventoryStackLimit() {
return isBaubleBox(getStack()) ? 64 : 0;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return isBaubleBox(getStack());
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return isBaubleBox(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.BAUBLE_BOX;
}
@Override
public void markDirty() {
// NO-OP
}
}
@@ -0,0 +1,40 @@
/**
* 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 @ [25/11/2015, 19:59:22 (GMT)]
*/
package vazkii.botania.client.gui.box;
import baubles.api.IBauble;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.client.gui.bag.InventoryFlowerBag;
import vazkii.botania.common.block.ModBlocks;
public class SlotAnyBauble extends Slot {
InventoryBaubleBox inv;
public SlotAnyBauble(InventoryBaubleBox p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_) {
super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_);
inv = p_i1824_1_;
}
@Override
public void onSlotChange(ItemStack oldStack, ItemStack newStack) {
inv.setInventorySlotContents(slotNumber, newStack);
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack.getItem() instanceof IBauble || stack.getItem() instanceof IManaItem;
}
}
@@ -44,6 +44,7 @@ public final class LibResources {
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 GUI_BAUBLE_BOX = PREFIX_GUI + "baubleBox.png";
public static final String GUI_HUD_ICONS = PREFIX_GUI + "hudIcons.png";
public static final String GUI_STENCIL = PREFIX_GUI + "stencil.png";
@@ -224,6 +224,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
addItem(ModItems.aesirRing);
}
addItem(ModItems.baubleBox);
addItem(ModItems.tinyPlanet);
addBlock(ModBlocks.tinyPlanet);
addItem(ModItems.manaRing);
@@ -0,0 +1,76 @@
/**
* 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 @ [25/11/2015, 19:46:11 (GMT)]
*/
package vazkii.botania.common.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibGuiIDs;
import vazkii.botania.common.lib.LibItemNames;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class ItemBaubleBox extends ItemMod {
private static final String TAG_ITEMS = "InvItems";
private static final String TAG_SLOT = "Slot";
public ItemBaubleBox() {
setUnlocalizedName(LibItemNames.BAUBLE_BOX);
setMaxStackSize(1);
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
player.openGui(Botania.instance, LibGuiIDs.BAUBLE_BOX, 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[36];
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);
}
}
@@ -268,6 +268,7 @@ public final class ModItems {
public static Item gaiaHead;
public static Item sextant;
public static Item speedUpBelt;
public static Item baubleBox;
public static void init() {
lexicon = new ItemLexicon();
@@ -417,6 +418,7 @@ public final class ModItems {
gaiaHead = new ItemGaiaHead();
sextant = new ItemSextant();
speedUpBelt = new ItemSpeedUpBelt();
baubleBox = new ItemBaubleBox();
OreDictionary.registerOre(LibOreDict.LEXICON, lexicon);
for(int i = 0; i < 16; i++) {
@@ -15,5 +15,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;
public static final int BAUBLE_BOX = 3;
}
@@ -160,6 +160,7 @@ public final class LibItemNames {
public static final String GAIA_HEAD = "gaiaHead";
public static final String SEXTANT = "sextant";
public static final String SPEED_UP_BELT = "speedUpBelt";
public static final String BAUBLE_BOX = "baubleBox";
public static final String[] LENS_NAMES = new String[] {
"lensNormal",
@@ -14,6 +14,8 @@ 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.box.ContainerBaubleBox;
import vazkii.botania.client.gui.box.GuiBaubleBox;
import vazkii.botania.client.gui.crafting.ContainerCraftingHalo;
import vazkii.botania.client.gui.crafting.GuiCraftingHalo;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
@@ -29,6 +31,8 @@ public class GuiHandler implements IGuiHandler {
return new ContainerCraftingHalo(player.inventory, world);
case LibGuiIDs.FLOWER_BAG :
return new ContainerFlowerBag(player);
case LibGuiIDs.BAUBLE_BOX :
return new ContainerBaubleBox(player);
}
return null;
@@ -44,6 +48,8 @@ public class GuiHandler implements IGuiHandler {
return new GuiCraftingHalo(player.inventory, world);
case LibGuiIDs.FLOWER_BAG :
return new GuiFlowerBag(player);
case LibGuiIDs.BAUBLE_BOX :
return new GuiBaubleBox(player);
}
return null;