From 5847495fa522079e99db92265370385ae2b87a9a Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Sun, 2 Feb 2014 19:52:54 +0000 Subject: [PATCH] Getting started with the inventory features of the Runic Altar. --- .../botania/common/block/BlockRuneAltar.java | 57 +++++++++++++++++-- .../common/block/tile/TileRuneAltar.java | 55 +++++++++++++++++- 2 files changed, 105 insertions(+), 7 deletions(-) diff --git a/MODSRC/vazkii/botania/common/block/BlockRuneAltar.java b/MODSRC/vazkii/botania/common/block/BlockRuneAltar.java index 42b74b89a..1ce1f6abc 100644 --- a/MODSRC/vazkii/botania/common/block/BlockRuneAltar.java +++ b/MODSRC/vazkii/botania/common/block/BlockRuneAltar.java @@ -11,20 +11,27 @@ */ package vazkii.botania.common.block; +import java.util.Random; + import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; import vazkii.botania.client.core.helper.IconHelper; import vazkii.botania.common.block.tile.TileRuneAltar; +import vazkii.botania.common.block.tile.TileSimpleInventory; import vazkii.botania.common.lib.LibBlockIDs; import vazkii.botania.common.lib.LibBlockNames; public class BlockRuneAltar extends BlockModContainer { + Random random; Icon[] icons; - + public BlockRuneAltar() { super(LibBlockIDs.idRuneAltar, Material.rock); setBlockBounds(0F, 0F, 0F, 1F, 0.75F, 1F); @@ -32,25 +39,65 @@ public class BlockRuneAltar extends BlockModContainer { setResistance(10.0F); setStepSound(soundStoneFootstep); setUnlocalizedName(LibBlockNames.RUNE_ALTAR); + + random = new Random(); } - + @Override public boolean isOpaqueCube() { return false; } - + @Override public boolean renderAsNormalBlock() { return false; } - + @Override public void registerIcons(IconRegister par1IconRegister) { icons = new Icon[3]; for(int i = 0; i < icons.length; i++) icons[i] = IconHelper.forBlock(par1IconRegister, this, i); } - + + @Override + public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) { + TileSimpleInventory inv = (TileSimpleInventory) par1World.getBlockTileEntity(par2, par3, par4); + + if (inv != null) { + for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) { + ItemStack itemstack = inv.getStackInSlot(j1); + + if (itemstack != null) { + float f = random.nextFloat() * 0.8F + 0.1F; + float f1 = random.nextFloat() * 0.8F + 0.1F; + EntityItem entityitem; + + for (float f2 = random.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; par1World.spawnEntityInWorld(entityitem)) { + int k1 = random.nextInt(21) + 10; + + if (k1 > itemstack.stackSize) + k1 = itemstack.stackSize; + + itemstack.stackSize -= k1; + entityitem = new EntityItem(par1World, par2 + f, par3 + f1, par4 + f2, new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage())); + float f3 = 0.05F; + entityitem.motionX = (float)random.nextGaussian() * f3; + entityitem.motionY = (float)random.nextGaussian() * f3 + 0.2F; + entityitem.motionZ = (float)random.nextGaussian() * f3; + + if (itemstack.hasTagCompound()) + entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); + } + } + } + + par1World.func_96440_m(par2, par3, par4, par5); + } + + super.breakBlock(par1World, par2, par3, par4, par5, par6); + } + @Override public Icon getIcon(int par1, int par2) { return icons[Math.min(2, par1)]; diff --git a/MODSRC/vazkii/botania/common/block/tile/TileRuneAltar.java b/MODSRC/vazkii/botania/common/block/tile/TileRuneAltar.java index 1e67b453a..a5cfc4b87 100644 --- a/MODSRC/vazkii/botania/common/block/tile/TileRuneAltar.java +++ b/MODSRC/vazkii/botania/common/block/tile/TileRuneAltar.java @@ -11,8 +11,59 @@ */ package vazkii.botania.common.block.tile; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import vazkii.botania.common.lib.LibBlockNames; -public class TileRuneAltar extends TileEntity { +public class TileRuneAltar extends TileSimpleInventory implements ISidedInventory { + + public void addItem(EntityPlayer player, ItemStack stack) { + for(int i = 0; i < getSizeInventory(); i++) + if(getStackInSlot(i) == null) { + ItemStack stackToAdd = stack.copy(); + stackToAdd.stackSize = 1; + setInventorySlotContents(i, stackToAdd); + + stack.stackSize--; + if(stack.stackSize == 0) + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + } + } + + @Override + public int getSizeInventory() { + return 16; + } + + @Override + public String getInvName() { + return LibBlockNames.RUNE_ALTAR; + } + + @Override + public int getInventoryStackLimit() { + return 1; + } + + @Override + public int[] getAccessibleSlotsFromSide(int var1) { + int accessibleSlot = -1; + for(int i = 0; i < getSizeInventory(); i++) + if(getStackInSlot(i) != null) + accessibleSlot = i; + + return accessibleSlot == -1 ? new int[0] : new int[] { accessibleSlot }; + } + + @Override + public boolean canInsertItem(int i, ItemStack itemstack, int j) { + return true; + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) { + return false; + } }