Added Composite Lenses.

This commit is contained in:
Vasco Lavos committed 2014-03-17 20:49:40 +00:00
1 parent fd100c330e
commit 994061682f
3 files changed
+106 -4

No files matched your search

@@ -15,6 +15,7 @@ import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
@@ -24,6 +25,7 @@ import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.DamageSource;
@@ -41,12 +43,14 @@ import vazkii.botania.common.Botania;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.core.helper.MathHelper;
import vazkii.botania.common.core.helper.Vector3;
import vazkii.botania.common.item.recipe.CompositeLensRecipe;
import vazkii.botania.common.lib.LibItemIDs;
import vazkii.botania.common.lib.LibItemNames;
public class ItemLens extends ItemMod implements ILens {
private static final String TAG_COLOR = "color";
private static final String TAG_COMPOSITE_LENS = "compositeLens";
public static Icon iconGlass;
@@ -58,6 +62,8 @@ public class ItemLens extends ItemMod implements ILens {
setUnlocalizedName(LibItemNames.LENS);
setMaxStackSize(1);
setHasSubtypes(true);
GameRegistry.addRecipe(new CompositeLensRecipe());
}
@Override
@@ -105,6 +111,10 @@ public class ItemLens extends ItemMod implements ILens {
int storedColor = getStoredColor(par1ItemStack);
if(storedColor != -1)
par3List.add(String.format(StatCollector.translateToLocal("botaniamisc.color"), StatCollector.translateToLocal("botania.color" + storedColor)));
ItemStack compositeLens = getCompositeLens(par1ItemStack);
if(compositeLens != null)
par3List.add(String.format(StatCollector.translateToLocal("botaniamisc.compositeLens"), compositeLens.getDisplayName()));
}
@Override
@@ -325,16 +335,22 @@ public class ItemLens extends ItemMod implements ILens {
// TODO
@Override
public boolean canCombineLenses(ItemStack sourceLens, ItemStack compositeLens) {
return false;
return true;
}
@Override
public ItemStack getCompositeLens(ItemStack stack) {
return null;
NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_COMPOSITE_LENS, false);
ItemStack lens = ItemStack.loadItemStackFromNBT(cmp);
return lens;
}
@Override
public ItemStack setCompositeLens(ItemStack sourceLens, ItemStack compositeLens) {
return null;
NBTTagCompound cmp = new NBTTagCompound();
compositeLens.writeToNBT(cmp);
ItemNBTHelper.setCompound(sourceLens, TAG_COMPOSITE_LENS, cmp);
return sourceLens;
}
}
@@ -0,0 +1,85 @@
/**
* 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 17, 2014, 8:30:41 PM (GMT)]
*/
package vazkii.botania.common.item.recipe;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import vazkii.botania.api.mana.ILens;
import vazkii.botania.common.item.ItemLens;
import vazkii.botania.common.item.ModItems;
public class CompositeLensRecipe implements IRecipe {
@Override
public boolean matches(InventoryCrafting var1, World var2) {
boolean foundLens = false;
boolean foundSecondLens = false;
boolean foundSlimeball = false;
for(int i = 0; i < var1.getSizeInventory(); i++) {
ItemStack stack = var1.getStackInSlot(i);
if(stack != null) {
if(stack.getItem() instanceof ILens && !foundSecondLens) {
if(foundLens)
foundSecondLens = true;
else foundLens = true;
} else if(stack.itemID == Item.slimeBall.itemID)
foundSlimeball = true;
else return false; // Found an invalid item, breaking the recipe
}
}
return foundSecondLens && foundSlimeball;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1) {
ItemStack lens = null;
ItemStack secondLens = null;
for(int i = 0; i < var1.getSizeInventory(); i++) {
ItemStack stack = var1.getStackInSlot(i);
if(stack != null) {
if(stack.getItem() instanceof ILens)
if(lens == null)
lens = stack;
else secondLens = stack;
}
}
if(lens.getItem() instanceof ILens) {
ILens lensItem = (ILens) lens.getItem();
if(secondLens == null || !lensItem.canCombineLenses(lens, secondLens))
return null;
ItemStack lensCopy = lens.copy();
((ItemLens) ModItems.lens).setCompositeLens(lensCopy, secondLens);
return lensCopy;
}
return null;
}
@Override
public int getRecipeSize() {
return 10;
}
@Override
public ItemStack getRecipeOutput() {
return null;
}
}
+1
View File
@@ -17,6 +17,7 @@ botaniamisc.outputtingPower=Sparing Power to Items
botaniamisc.inputtingPower=Accepting Power from Items
botaniamisc.creative=Creative
botaniamisc.invFull=Your inventory is full.
botaniamisc.compositeLens=Composite with %s
# COLORS
botania.color0=White