mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-25 06:24:27 +00:00
Runic Crafting is functional!
This commit is contained in:
1 parent
d14c148c68
commit
0b1aac8708
6 files changed
+197
-26
No files matched your search
@@ -14,16 +14,19 @@ package vazkii.botania.api;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.text.html.HTMLDocument.RunElement;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import vazkii.botania.api.internal.DummyMethodHandler;
|
||||
import vazkii.botania.api.internal.IInternalMethodHandler;
|
||||
import vazkii.botania.api.internal.DummySubTile;
|
||||
import vazkii.botania.api.internal.IInternalMethodHandler;
|
||||
import vazkii.botania.api.lexicon.LexiconCategory;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
@@ -34,6 +37,7 @@ public final class BotaniaAPI {
|
||||
private static List<LexiconEntry> allEntries = new ArrayList<LexiconEntry>();
|
||||
|
||||
public static List<RecipePetals> petalRecipes = new ArrayList<RecipePetals>();
|
||||
public static List<RecipeRuneAltar> runeAltarRecipes = new ArrayList<RecipeRuneAltar>();
|
||||
public static List<RecipeManaInfusion> manaInfusionRecipes = new ArrayList<RecipeManaInfusion>();
|
||||
|
||||
private static BiMap<String, Class<? extends SubTileEntity>> subTiles = HashBiMap.<String, Class<? extends SubTileEntity>> create();
|
||||
@@ -59,6 +63,19 @@ public final class BotaniaAPI {
|
||||
petalRecipes.add(recipe);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Rune Altar
|
||||
* @param output The ItemStack to craft.
|
||||
* @param mana The amount of mana required.
|
||||
* @param inputs The ore dictionary names of the items required for crafting.
|
||||
* @return The recipe created.
|
||||
*/
|
||||
public static RecipeRuneAltar registerRuneAltarRecipe(ItemStack output, int mana, String... inputs) {
|
||||
RecipeRuneAltar recipe = new RecipeRuneAltar(output, mana, inputs);
|
||||
runeAltarRecipes.add(recipe);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Mana Infusion Recipe (throw an item in a mana pool)
|
||||
|
||||
@@ -40,9 +40,10 @@ public class RecipeRuneAltar {
|
||||
break;
|
||||
|
||||
String ore = OreDictionary.getOreName(OreDictionary.getOreID(stack));
|
||||
|
||||
|
||||
if(!inputsMissing.contains(ore))
|
||||
return false;
|
||||
return false;
|
||||
|
||||
inputsMissing.remove(ore);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,14 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.IWandable;
|
||||
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 {
|
||||
public class BlockRuneAltar extends BlockModContainer implements IWandable {
|
||||
|
||||
Random random;
|
||||
Icon[] icons;
|
||||
@@ -64,10 +65,8 @@ public class BlockRuneAltar extends BlockModContainer {
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
|
||||
ItemStack stack = par5EntityPlayer.getCurrentEquippedItem();
|
||||
if(stack != null) {
|
||||
((TileRuneAltar) par1World.getBlockTileEntity(par2, par3, par4)).addItem(par5EntityPlayer, stack);
|
||||
return true;
|
||||
}
|
||||
if(stack != null)
|
||||
return ((TileRuneAltar) par1World.getBlockTileEntity(par2, par3, par4)).addItem(par5EntityPlayer, stack);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -120,4 +119,10 @@ public class BlockRuneAltar extends BlockModContainer {
|
||||
return new TileRuneAltar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int side) {
|
||||
((TileRuneAltar) world.getBlockTileEntity(x, y, z)).onWanded(player, stack);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,28 +11,43 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.mana.IManaReceiver;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
|
||||
public class TileRuneAltar extends TileSimpleInventory implements ISidedInventory {
|
||||
public class TileRuneAltar extends TileSimpleInventory implements ISidedInventory, IManaReceiver {
|
||||
|
||||
public float[] angles = new float[getSizeInventory()];
|
||||
boolean firstTick = true;
|
||||
|
||||
public void addItem(EntityPlayer player, ItemStack stack) {
|
||||
boolean did = false;
|
||||
int manaToGet = 0;
|
||||
int mana = 0;
|
||||
|
||||
public boolean addItem(EntityPlayer player, ItemStack stack) {
|
||||
if(stack.itemID == ModItems.twigWand.itemID)
|
||||
return false;
|
||||
|
||||
boolean did = false;
|
||||
|
||||
for(int i = 0; i < getSizeInventory(); i++)
|
||||
if(getStackInSlot(i) == null) {
|
||||
did = true;
|
||||
ItemStack stackToAdd = stack.copy();
|
||||
stackToAdd.stackSize = 1;
|
||||
setInventorySlotContents(i, stackToAdd);
|
||||
|
||||
|
||||
if(!player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
if(stack.stackSize == 0)
|
||||
@@ -42,45 +57,129 @@ public class TileRuneAltar extends TileSimpleInventory implements ISidedInventor
|
||||
break;
|
||||
}
|
||||
|
||||
if(did) {
|
||||
Vector3 vec = Vector3.fromTileEntityCenter(this);
|
||||
Vector3 endVec = vec.copy().add(0, 2.5, 0);
|
||||
Botania.proxy.lightningFX(worldObj, vec, endVec, 2F, 0x00948B, 0x00E4D7);
|
||||
}
|
||||
if(did)
|
||||
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
|
||||
if(firstTick) {
|
||||
updateRotationAngles();
|
||||
firstTick = false;
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < angles.length; i++)
|
||||
angles[i]++;
|
||||
|
||||
// Update every tick.
|
||||
recieveMana(0);
|
||||
|
||||
if(manaToGet > 0 && mana >= manaToGet) {
|
||||
if(worldObj.rand.nextInt(20) == 0) {
|
||||
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "mob.creeper.live", 1F, 1F);
|
||||
|
||||
Vector3 vec = Vector3.fromTileEntityCenter(this);
|
||||
Vector3 endVec = vec.copy().add(0, 2.5, 0);
|
||||
Botania.proxy.lightningFX(worldObj, vec, endVec, 2F, 0x00948B, 0x00E4D7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
super.setInventorySlotContents(i, itemstack);
|
||||
updateRotationAngles();
|
||||
}
|
||||
|
||||
|
||||
public void updateRecipe() {
|
||||
int manaToGet = this.manaToGet;
|
||||
|
||||
getMana : {
|
||||
for(RecipeRuneAltar recipe : BotaniaAPI.runeAltarRecipes)
|
||||
if(recipe.matches(this)) {
|
||||
this.manaToGet = recipe.getManaUsage();
|
||||
break getMana;
|
||||
}
|
||||
this.manaToGet = 0;
|
||||
}
|
||||
|
||||
if(manaToGet != this.manaToGet) {
|
||||
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "random.orb", 1F, 1F);
|
||||
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRotationAngles() {
|
||||
int items = 0;
|
||||
for(int i = 0; i < getSizeInventory(); i++)
|
||||
if(getStackInSlot(i) == null)
|
||||
break;
|
||||
else items++;
|
||||
|
||||
|
||||
float anglePer = 360F / (float) items;
|
||||
float totalAngle = 0F;
|
||||
for(int i = 0; i < angles.length; i++)
|
||||
angles[i] = (totalAngle += anglePer);
|
||||
}
|
||||
|
||||
|
||||
public void onWanded(EntityPlayer player, ItemStack wand) {
|
||||
updateRecipe();
|
||||
|
||||
if(manaToGet > 0 && mana >= manaToGet) {
|
||||
RecipeRuneAltar recipe = null;
|
||||
|
||||
for(RecipeRuneAltar recipe_ : BotaniaAPI.runeAltarRecipes)
|
||||
if(recipe_.matches(this)) {
|
||||
recipe = recipe_;
|
||||
break;
|
||||
}
|
||||
|
||||
List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1));
|
||||
EntityItem livingrock = null;
|
||||
for(EntityItem item : items)
|
||||
if(item.getEntityItem() != null && item.getEntityItem().itemID == ModBlocks.livingrock.blockID) {
|
||||
livingrock = item;
|
||||
break;
|
||||
}
|
||||
|
||||
if(livingrock != null) {
|
||||
int mana = recipe.getManaUsage();
|
||||
recieveMana(-mana);
|
||||
if(!worldObj.isRemote) {
|
||||
ItemStack output = recipe.getOutput().copy();
|
||||
EntityItem outputItem = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, output);
|
||||
worldObj.spawnEntityInWorld(outputItem);
|
||||
}
|
||||
|
||||
for(int i = 0; i < getSizeInventory(); i++)
|
||||
setInventorySlotContents(i, null);
|
||||
|
||||
ItemStack livingrockItem = livingrock.getEntityItem();
|
||||
livingrockItem.stackSize--;
|
||||
if(livingrockItem.stackSize == 0)
|
||||
livingrock.setDead();
|
||||
|
||||
craftingFanciness();
|
||||
updateRecipe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void craftingFanciness() {
|
||||
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "random.levelup", 1F, 1F);
|
||||
for(int i = 0; i < 25; i++) {
|
||||
float red = (float) Math.random();
|
||||
float green = (float) Math.random();
|
||||
float blue = (float) Math.random();
|
||||
Botania.proxy.sparkleFX(worldObj, xCoord + 0.5 + Math.random() * 0.4 - 0.2, yCoord + 1, zCoord + 0.5 + Math.random() * 0.4 - 0.2, red, green, blue, (float) Math.random(), 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 16;
|
||||
@@ -90,7 +189,7 @@ public class TileRuneAltar extends TileSimpleInventory implements ISidedInventor
|
||||
public String getInvName() {
|
||||
return LibBlockNames.RUNE_ALTAR;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
@@ -116,4 +215,24 @@ public class TileRuneAltar extends TileSimpleInventory implements ISidedInventor
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentMana() {
|
||||
return mana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
return mana >= manaToGet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recieveMana(int mana) {
|
||||
this.mana = Math.min(this.mana + mana, manaToGet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRecieveManaFromBursts() {
|
||||
return !isFull();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import vazkii.botania.common.core.helper.Vector3;
|
||||
import vazkii.botania.common.crafting.ModCrafingRecipes;
|
||||
import vazkii.botania.common.crafting.ModManaInfusionRecipes;
|
||||
import vazkii.botania.common.crafting.ModPetalRecipes;
|
||||
import vazkii.botania.common.crafting.ModRuneRecipes;
|
||||
import vazkii.botania.common.entity.ModEntities;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
@@ -47,6 +48,7 @@ public class CommonProxy {
|
||||
|
||||
ModCrafingRecipes.init();
|
||||
ModPetalRecipes.init();
|
||||
ModRuneRecipes.init();
|
||||
ModManaInfusionRecipes.init();
|
||||
|
||||
LexiconData.init();
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 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 @ [Feb 6, 2014, 5:59:28 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
|
||||
public final class ModRuneRecipes {
|
||||
|
||||
public static RecipeRuneAltar recipeDebug;
|
||||
|
||||
public static void init() {
|
||||
recipeDebug = BotaniaAPI.registerRuneAltarRecipe(new ItemStack(Item.diamond), 1000, "ingotIron", "cobblestone", "plankWood", "ingotGold");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user