The Black Hole Talisman will no longer keep a stack of the specified item in your inventory, block placing is done through right clicking with it exclusively now. Putting the talisman in a crafting table will allow you to extract a stack of the block at once.

This commit is contained in:
Lizbeth Rika committed 2015-04-09 22:26:48 +01:00
1 parent 12d91ce302
commit bf2e2ce70b
2 files changed
+141 -34

No files matched your search

@@ -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 @ [Apr 9, 2015, 7:48:00 PM (GMT)]
*/
package vazkii.botania.common.crafting.recipe;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import vazkii.botania.common.item.ItemBlackHoleTalisman;
import vazkii.botania.common.item.ModItems;
public class BlackHoleTalismanExtractRecipe implements IRecipe {
@Override
public boolean matches(InventoryCrafting var1, World var2) {
boolean foundTalisman = false;
for(int i = 0; i < var1.getSizeInventory(); i++) {
ItemStack stack = var1.getStackInSlot(i);
if(stack != null) {
if(stack.getItem() == ModItems.blackHoleTalisman && !foundTalisman)
foundTalisman = true;
else return false;
}
}
return foundTalisman;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1) {
ItemStack talisman = null;
for(int i = 0; i < var1.getSizeInventory(); i++) {
ItemStack stack = var1.getStackInSlot(i);
if(stack != null)
talisman = stack;
}
int count = ItemBlackHoleTalisman.getBlockCount(talisman);
if(count > 0) {
Block block = ItemBlackHoleTalisman.getBlock(talisman);
int meta = ItemBlackHoleTalisman.getBlockMeta(talisman);
return new ItemStack(block, Math.min(64, count), meta);
}
return null;
}
@Override
public int getRecipeSize() {
return 10;
}
@Override
public ItemStack getRecipeOutput() {
return null;
}
}
@@ -26,10 +26,15 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.oredict.RecipeSorter.Category;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.crafting.recipe.AncientWillRecipe;
import vazkii.botania.common.crafting.recipe.BlackHoleTalismanExtractRecipe;
import vazkii.botania.common.lib.LibItemNames;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -45,36 +50,11 @@ public class ItemBlackHoleTalisman extends ItemMod {
setUnlocalizedName(LibItemNames.BLACK_HOLE_TALISMAN);
setMaxStackSize(1);
setHasSubtypes(true);
GameRegistry.addRecipe(new BlackHoleTalismanExtractRecipe());
RecipeSorter.register("botania:blackHoleTalismanExtract", BlackHoleTalismanExtractRecipe.class, Category.SHAPELESS, "");
}
private static void setCount(ItemStack stack, int count) {
ItemNBTHelper.setInt(stack, TAG_BLOCK_COUNT, count);
}
public static int remove(ItemStack stack, int count) {
int current = getBlockCount(stack);
setCount(stack, Math.max(current - count, 0));
return Math.min(current, count);
}
public static String getBlockName(ItemStack stack) {
return ItemNBTHelper.getString(stack, TAG_BLOCK_NAME, "");
}
public static Block getBlock(ItemStack stack) {
Block block = Block.getBlockFromName(getBlockName(stack));
return block;
}
public static int getBlockMeta(ItemStack stack) {
return ItemNBTHelper.getInt(stack, TAG_BLOCK_META, 0);
}
public static int getBlockCount(ItemStack stack) {
return ItemNBTHelper.getInt(stack, TAG_BLOCK_COUNT, 0);
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
if(getBlock(par1ItemStack) != Blocks.air && par3EntityPlayer.isSneaking()) {
@@ -164,33 +144,63 @@ public class ItemBlackHoleTalisman extends ItemMod {
}
if(highest == -1) {
ItemStack heldItem = player.inventory.getItemStack();
/*ItemStack heldItem = player.inventory.getItemStack();
if(hasFreeSlot && (heldItem == null || Item.getItemFromBlock(block) == heldItem.getItem() || heldItem.getItemDamage() != meta)) {
ItemStack stack = new ItemStack(block, remove(itemstack, 64), meta);
if(stack.stackSize != 0)
player.inventory.addItemStackToInventory(stack);
}
}*/
// Used to keep one stack, disabled for now
} else {
for(int i = 0; i < counts.length; i++) {
int count = counts[i];
if(i == highest || count == 0)
// highest is used to keep one stack, disabled for now
if(/*i == highest || */count == 0)
continue;
add(itemstack, count);
player.inventory.setInventorySlotContents(i, null);
}
int countInHighest = counts[highest];
/*int countInHighest = counts[highest];
int maxSize = new ItemStack(block, 1, meta).getMaxStackSize();
if(countInHighest < maxSize) {
int missing = maxSize - countInHighest;
ItemStack stackInHighest = player.inventory.getStackInSlot(highest);
stackInHighest.stackSize += remove(itemstack, missing);
}
}*/
// Used to keep one stack, disabled for now
}
}
}
@Override
public ItemStack getContainerItem(ItemStack itemStack) {
int count = getBlockCount(itemStack);
if(count == 0)
return null;
int extract = Math.min(64, count);
ItemStack copy = itemStack.copy();
remove(copy, extract);
int dmg = copy.getItemDamage();
if(dmg == 1)
copy.setItemDamage(0);
return copy;
}
@Override
public boolean hasContainerItem(ItemStack stack) {
return getContainerItem(stack) != null;
}
@Override
public boolean doesContainerItemLeaveCraftingGrid(ItemStack p_77630_1_) {
return false;
}
private boolean setBlock(ItemStack stack, Block block, int meta) {
if(getBlock(stack) == Blocks.air || getBlockCount(stack) == 0) {
@@ -237,4 +247,32 @@ public class ItemBlackHoleTalisman extends ItemMod {
tooltip.add(s.replaceAll("&", "\u00a7"));
}
private static void setCount(ItemStack stack, int count) {
ItemNBTHelper.setInt(stack, TAG_BLOCK_COUNT, count);
}
public static int remove(ItemStack stack, int count) {
int current = getBlockCount(stack);
setCount(stack, Math.max(current - count, 0));
return Math.min(current, count);
}
public static String getBlockName(ItemStack stack) {
return ItemNBTHelper.getString(stack, TAG_BLOCK_NAME, "");
}
public static Block getBlock(ItemStack stack) {
Block block = Block.getBlockFromName(getBlockName(stack));
return block;
}
public static int getBlockMeta(ItemStack stack) {
return ItemNBTHelper.getInt(stack, TAG_BLOCK_META, 0);
}
public static int getBlockCount(ItemStack stack) {
return ItemNBTHelper.getInt(stack, TAG_BLOCK_COUNT, 0);
}
}