mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 11:49:37 +00:00
Proper brewery behaviour and rendering, now it needs more fanciness.
This commit is contained in:
1 parent
fb3d99001e
commit
a76d01ecd8
14 files changed
+561
-15
No files matched your search
@@ -36,6 +36,7 @@ import vazkii.botania.api.internal.IInternalMethodHandler;
|
||||
import vazkii.botania.api.lexicon.KnowledgeType;
|
||||
import vazkii.botania.api.lexicon.LexiconCategory;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
@@ -63,6 +64,7 @@ public final class BotaniaAPI {
|
||||
public static List<RecipeRuneAltar> runeAltarRecipes = new ArrayList<RecipeRuneAltar>();
|
||||
public static List<RecipeManaInfusion> manaInfusionRecipes = new ArrayList<RecipeManaInfusion>();
|
||||
public static List<RecipeElvenTrade> elvenTradeRecipes = new ArrayList<RecipeElvenTrade>();
|
||||
public static List<RecipeBrew> brewRecipes = new ArrayList<RecipeBrew>();
|
||||
|
||||
private static BiMap<String, Class<? extends SubTileEntity>> subTiles = HashBiMap.<String, Class<? extends SubTileEntity>> create();
|
||||
private static Map<Class<? extends SubTileEntity>, SubTileSignature> subTileSignatures = new HashMap<Class<? extends SubTileEntity>, SubTileSignature>();
|
||||
@@ -280,6 +282,17 @@ public final class BotaniaAPI {
|
||||
elvenTradeRecipes.add(recipe);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Brew Recipe (for the Botanical Brewery).
|
||||
* @param brew The brew in to be set in this recipe.
|
||||
* @inputs The items used in the recipe, no more than 5.
|
||||
*/
|
||||
public static RecipeBrew registerBrewRecipe(Brew brew, Object... inputs) {
|
||||
RecipeBrew recipe = new RecipeBrew(brew, inputs);
|
||||
brewRecipes.add(recipe);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a SubTileEntity, a new special flower. Look in the subtile package of the API.
|
||||
|
||||
@@ -41,6 +41,7 @@ public class Brew {
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.cost = cost;
|
||||
this.effects = new ArrayList(Arrays.asList(effects));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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 @ [Nov 1, 2014, 9:20:33 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.brew;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* An Item that implements this is a Brew item, by which it contains
|
||||
* a brew. This is only used in vanilla to prevent the brew item
|
||||
* from going back into the brewery but other mods might use it for whatever.
|
||||
*/
|
||||
public interface IBrewItem {
|
||||
|
||||
public Brew getBrew(ItemStack brew);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* 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 @ [Nov 1, 2014, 8:52:00 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import vazkii.botania.api.brew.Brew;
|
||||
import vazkii.botania.api.brew.IBrewContainer;
|
||||
|
||||
public class RecipeBrew {
|
||||
|
||||
Brew brew;
|
||||
List<Object> inputs;
|
||||
|
||||
public RecipeBrew(Brew brew, Object... inputs) {
|
||||
this.brew = brew;
|
||||
|
||||
List<Object> inputsToSet = new ArrayList();
|
||||
for(Object obj : inputs) {
|
||||
if(obj instanceof String || obj instanceof ItemStack)
|
||||
inputsToSet.add(obj);
|
||||
else throw new IllegalArgumentException("Invalid input");
|
||||
}
|
||||
|
||||
this.inputs = inputsToSet;
|
||||
}
|
||||
|
||||
public boolean matches(IInventory inv) {
|
||||
List<Object> inputsMissing = new ArrayList(inputs);
|
||||
|
||||
for(int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if(stack == null)
|
||||
break;
|
||||
|
||||
if(stack.getItem() instanceof IBrewContainer)
|
||||
continue;
|
||||
|
||||
int stackIndex = -1, oredictIndex = -1;
|
||||
|
||||
for(int j = 0; j < inputsMissing.size(); j++) {
|
||||
Object input = inputsMissing.get(j);
|
||||
if(input instanceof String) {
|
||||
List<ItemStack> validStacks = OreDictionary.getOres((String) input);
|
||||
boolean found = false;
|
||||
for(ItemStack ostack : validStacks) {
|
||||
ItemStack cstack = ostack.copy();
|
||||
if(cstack.getItemDamage() == Short.MAX_VALUE)
|
||||
cstack.setItemDamage(stack.getItemDamage());
|
||||
|
||||
if(stack.isItemEqual(cstack)) {
|
||||
oredictIndex = j;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(found)
|
||||
break;
|
||||
} else if(input instanceof ItemStack && simpleAreStacksEqual((ItemStack) input, stack)) {
|
||||
stackIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(stackIndex != -1)
|
||||
inputsMissing.remove(stackIndex);
|
||||
else if(oredictIndex != -1)
|
||||
inputsMissing.remove(oredictIndex);
|
||||
else return false;
|
||||
}
|
||||
|
||||
return inputsMissing.isEmpty();
|
||||
}
|
||||
|
||||
boolean simpleAreStacksEqual(ItemStack stack, ItemStack stack2) {
|
||||
return stack.getItem() == stack2.getItem() && stack.getItemDamage() == stack2.getItemDamage();
|
||||
}
|
||||
|
||||
public List<Object> getInputs() {
|
||||
return new ArrayList(inputs);
|
||||
}
|
||||
|
||||
public int getManaUsage() {
|
||||
return brew.getManaCost();
|
||||
}
|
||||
|
||||
public ItemStack getOutput(ItemStack stack) {
|
||||
if(stack == null || !(stack.getItem() instanceof IBrewContainer))
|
||||
return new ItemStack(Items.glass_bottle); // Fallback...
|
||||
IBrewContainer container = (IBrewContainer) stack.getItem();
|
||||
|
||||
return container.getItemForBrew(brew, stack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,12 +15,10 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public class RecipeRuneAltar extends RecipePetals {
|
||||
|
||||
ItemStack output;
|
||||
int mana;
|
||||
|
||||
public RecipeRuneAltar(ItemStack output, int mana, Object... inputs) {
|
||||
super(output, inputs);
|
||||
this.output = output;
|
||||
this.mana = mana;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
*/
|
||||
package vazkii.botania.client.model;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import vazkii.botania.client.render.tile.RenderTileBrewery;
|
||||
|
||||
public class ModelBrewery extends ModelBase {
|
||||
|
||||
@@ -46,7 +47,7 @@ public class ModelBrewery extends ModelBase {
|
||||
Plate.setTextureSize(64, 32);
|
||||
}
|
||||
|
||||
public void render(double time) {
|
||||
public void render(RenderTileBrewery render, double time) {
|
||||
float f = 1F / 16F;
|
||||
|
||||
float offset = (float) Math.sin(time / 40) * 0.1F + 0.05F;
|
||||
@@ -56,6 +57,14 @@ public class ModelBrewery extends ModelBase {
|
||||
|
||||
GL11.glTranslatef(0F, offset, 0F);
|
||||
GL11.glRotatef(polerot, 0F, 1F, 0F);
|
||||
if(render.brewery.getStackInSlot(0) != null) {
|
||||
GL11.glRotatef(180F, 1F, 0F, 0F);
|
||||
GL11.glTranslatef(-1F / 8F, -0.5F, 1F / 128F);
|
||||
render.renderItemStack(render.brewery.getStackInSlot(0));
|
||||
GL11.glTranslatef(1F / 8F, 0.5F, -1F / 128F);
|
||||
GL11.glRotatef(-180F, 1F, 0F, 0F);
|
||||
}
|
||||
|
||||
Pole.render(f);
|
||||
Top.render(f);
|
||||
Bottom.render(f);
|
||||
@@ -69,6 +78,20 @@ public class ModelBrewery extends ModelBase {
|
||||
offset1 = 0F;
|
||||
|
||||
GL11.glTranslatef(0F, offset1, 0F);
|
||||
if(render.brewery.getStackInSlot(i + 1) != null) {
|
||||
float rot = Plate.rotateAngleY * 180F / (float) Math.PI;
|
||||
float transX = 0.3125F;
|
||||
float transY = 1.06F;
|
||||
float transZ = 0.1245F;
|
||||
GL11.glRotatef(rot, 0F, 1F, 0F);
|
||||
GL11.glTranslatef(transX, transY, transZ);
|
||||
GL11.glRotatef(-90F, 1F, 0F, 0F);
|
||||
render.renderItemStack(render.brewery.getStackInSlot(i + 1));
|
||||
GL11.glRotatef(90F, 1F, 0F, 0F);
|
||||
GL11.glTranslatef(-transX, -transY, -transZ);
|
||||
GL11.glRotatef(-rot, 0F, 1F, 0F);
|
||||
}
|
||||
|
||||
Plate.render(f);
|
||||
GL11.glTranslatef(0F, -offset1, 0F);
|
||||
|
||||
|
||||
@@ -24,22 +24,31 @@ import vazkii.botania.client.model.ModelBrewery;
|
||||
import vazkii.botania.client.render.item.RenderLens;
|
||||
import vazkii.botania.common.block.tile.TileBrewery;
|
||||
import vazkii.botania.common.block.tile.mana.TileSpreader;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
public class RenderTileBrewery extends TileEntitySpecialRenderer {
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation(LibResources.MODEL_BREWERY);
|
||||
ModelBrewery model = new ModelBrewery();
|
||||
public TileBrewery brewery;
|
||||
public static boolean rotate = true;
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f) {
|
||||
TileBrewery brewery = (TileBrewery) tileentity;
|
||||
brewery = (TileBrewery) tileentity;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
@@ -53,9 +62,50 @@ public class RenderTileBrewery extends TileEntitySpecialRenderer {
|
||||
if(!rotate)
|
||||
time = -1;
|
||||
|
||||
model.render(time);
|
||||
model.render(this, time);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public void renderItemStack(ItemStack stack) {
|
||||
if(stack != null) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.renderEngine.bindTexture(stack.getItem() instanceof ItemBlock ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture);
|
||||
|
||||
float s = 0.25F;
|
||||
GL11.glScalef(s, s, s);
|
||||
GL11.glScalef(2F, 2F, 2F);
|
||||
if(!ForgeHooksClient.renderEntityItem(new EntityItem(brewery.getWorldObj(), brewery.xCoord, brewery.yCoord, brewery.zCoord, stack), stack, 0F, 0F, brewery.getWorldObj().rand, mc.renderEngine, RenderBlocks.getInstance(), 1)) {
|
||||
GL11.glScalef(0.5F, 0.5F, 0.5F);
|
||||
if(stack.getItem() instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.getBlockFromItem(stack.getItem()).getRenderType())) {
|
||||
GL11.glScalef(0.5F, 0.5F, 0.5F);
|
||||
GL11.glTranslatef(1F, 1.1F, 0F);
|
||||
RenderBlocks.getInstance().renderBlockAsItem(Block.getBlockFromItem(stack.getItem()), stack.getItemDamage(), 1F);
|
||||
GL11.glTranslatef(-1F, -1.1F, 0F);
|
||||
GL11.glScalef(2F, 2F, 2F);
|
||||
} else {
|
||||
int renderPass = 0;
|
||||
do {
|
||||
IIcon icon = stack.getItem().getIcon(stack, renderPass);
|
||||
if(icon != null) {
|
||||
Color color = new Color(stack.getItem().getColorFromItemStack(stack, renderPass));
|
||||
GL11.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
|
||||
float f = icon.getMinU();
|
||||
float f1 = icon.getMaxU();
|
||||
float f2 = icon.getMinV();
|
||||
float f3 = icon.getMaxV();
|
||||
|
||||
ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F);
|
||||
GL11.glColor3f(1F, 1F, 1F);
|
||||
}
|
||||
renderPass++;
|
||||
} while(renderPass < stack.getItem().getRenderPasses(stack.getItemDamage()));
|
||||
}
|
||||
}
|
||||
GL11.glScalef(1F / s, 1F / s, 1F / s);
|
||||
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,23 +11,110 @@
|
||||
*/
|
||||
package vazkii.botania.common.block;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import vazkii.botania.client.lib.LibRenderIDs;
|
||||
import vazkii.botania.common.block.tile.TileBrewery;
|
||||
import vazkii.botania.common.block.tile.TileRuneAltar;
|
||||
import vazkii.botania.common.block.tile.TileSimpleInventory;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockBrewery extends BlockModContainer {
|
||||
|
||||
Random random;
|
||||
|
||||
protected BlockBrewery() {
|
||||
super(Material.rock);
|
||||
float f = 6F / 16F;
|
||||
setBlockBounds(f, 0F, f, 1F - f, 1F, 1F - f);
|
||||
setBlockName(LibBlockNames.BREWERY);
|
||||
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
|
||||
TileBrewery brew = (TileBrewery) par1World.getTileEntity(par2, par3, par4);
|
||||
|
||||
if(par5EntityPlayer.isSneaking()) {
|
||||
if(brew.recipe == null && par1World.getBlockMetadata(par2, par3, par4) == 0)
|
||||
for(int i = brew.getSizeInventory() - 1; i >= 0; i--) {
|
||||
ItemStack stackAt = brew.getStackInSlot(i);
|
||||
if(stackAt != null) {
|
||||
ItemStack copy = stackAt.copy();
|
||||
if(!par5EntityPlayer.inventory.addItemStackToInventory(copy))
|
||||
par5EntityPlayer.dropPlayerItemWithRandomChoice(copy, false);
|
||||
brew.setInventorySlotContents(i, null);
|
||||
par1World.func_147453_f(par2, par3, par4, this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ItemStack stack = par5EntityPlayer.getCurrentEquippedItem();
|
||||
if(stack != null)
|
||||
return brew.addItem(par5EntityPlayer, stack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, int par2, int par3, int par4, Block par5, int par6) {
|
||||
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(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.getItem(), 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_147453_f(par2, par3, par4, par5);
|
||||
}
|
||||
|
||||
super.breakBlock(par1World, par2, par3, par4, par5, par6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5) {
|
||||
TileRuneAltar altar = (TileRuneAltar) par1World.getTileEntity(par2, par3, par4);
|
||||
return altar.signal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister par1IconRegister) {
|
||||
// NO-OP
|
||||
|
||||
@@ -71,9 +71,10 @@ public class BlockRuneAltar extends BlockModContainer implements IWandable, IWan
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
|
||||
if(par5EntityPlayer.isSneaking()) {
|
||||
TileRuneAltar altar = (TileRuneAltar) par1World.getTileEntity(par2, par3, par4);
|
||||
TileRuneAltar altar = (TileRuneAltar) par1World.getTileEntity(par2, par3, par4);
|
||||
|
||||
|
||||
if(par5EntityPlayer.isSneaking()) {
|
||||
if(altar.manaToGet == 0)
|
||||
for(int i = altar.getSizeInventory() - 1; i >= 0; i--) {
|
||||
ItemStack stackAt = altar.getStackInSlot(i);
|
||||
@@ -89,7 +90,7 @@ public class BlockRuneAltar extends BlockModContainer implements IWandable, IWan
|
||||
} else {
|
||||
ItemStack stack = par5EntityPlayer.getCurrentEquippedItem();
|
||||
if(stack != null)
|
||||
return ((TileRuneAltar) par1World.getTileEntity(par2, par3, par4)).addItem(par5EntityPlayer, stack);
|
||||
return altar.addItem(par5EntityPlayer, stack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,209 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
public class TileBrewery extends TileMod {
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.brew.IBrewContainer;
|
||||
import vazkii.botania.api.brew.IBrewItem;
|
||||
import vazkii.botania.api.mana.IManaReceiver;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
import vazkii.botania.client.core.handler.ClientTickHandler;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
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;
|
||||
|
||||
// This is mostly copypasta from TileRuneAltar
|
||||
public class TileBrewery extends TileSimpleInventory implements ISidedInventory, IManaReceiver {
|
||||
|
||||
private static final String TAG_MANA = "mana";
|
||||
|
||||
public RecipeBrew recipe;
|
||||
int mana = 0;
|
||||
public int signal = 0;
|
||||
|
||||
public boolean addItem(EntityPlayer player, ItemStack stack) {
|
||||
if(recipe != null || stack == null || stack.getItem() instanceof IBrewItem || ((getStackInSlot(0) == null) != stack.getItem() instanceof IBrewContainer))
|
||||
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 == null || !player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
if(stack.stackSize == 0 && player != null)
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(did) {
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
for(RecipeBrew recipe : BotaniaAPI.brewRecipes)
|
||||
if(recipe.matches(this)) {
|
||||
this.recipe = recipe;
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 | 2);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
// Update every tick.
|
||||
recieveMana(0);
|
||||
|
||||
if(!worldObj.isRemote && recipe == null) {
|
||||
List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1));
|
||||
for(EntityItem item : items)
|
||||
if(!item.isDead && item.getEntityItem() != null) {
|
||||
ItemStack stack = item.getEntityItem();
|
||||
if(addItem(null, stack) && stack.stackSize == 0)
|
||||
item.setDead();
|
||||
}
|
||||
}
|
||||
|
||||
if(recipe != null) {
|
||||
if(!recipe.matches(this)) {
|
||||
recipe = null;
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 | 2);
|
||||
}
|
||||
|
||||
if(recipe != null && mana >= recipe.getManaUsage() && !worldObj.isRemote) {
|
||||
int mana = recipe.getManaUsage();
|
||||
recieveMana(-mana);
|
||||
if(!worldObj.isRemote) {
|
||||
ItemStack output = recipe.getOutput(getStackInSlot(0));
|
||||
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);
|
||||
|
||||
craftingFanciness();
|
||||
}
|
||||
}
|
||||
|
||||
int newSignal = 0;
|
||||
if(recipe != null)
|
||||
newSignal++;
|
||||
|
||||
if(newSignal != signal) {
|
||||
signal = newSignal;
|
||||
worldObj.func_147453_f(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
}
|
||||
}
|
||||
|
||||
public void craftingFanciness() {
|
||||
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "botania:runeAltarCraft", 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 void writeCustomNBT(NBTTagCompound par1nbtTagCompound) {
|
||||
super.writeCustomNBT(par1nbtTagCompound);
|
||||
|
||||
par1nbtTagCompound.setInteger(TAG_MANA, mana);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound par1nbtTagCompound) {
|
||||
super.readCustomNBT(par1nbtTagCompound);
|
||||
|
||||
mana = par1nbtTagCompound.getInteger(TAG_MANA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
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 mana == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentMana() {
|
||||
return mana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
return recipe == null ? true : mana >= recipe.getManaUsage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recieveMana(int mana) {
|
||||
this.mana = Math.min(this.mana + mana, recipe == null ? 0 : recipe.getManaUsage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRecieveManaFromBursts() {
|
||||
return !isFull();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class TileRuneAltar extends TileSimpleInventory implements ISidedInventor
|
||||
// Update every tick.
|
||||
recieveMana(0);
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
if(!worldObj.isRemote && manaToGet == 0) {
|
||||
List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1));
|
||||
for(EntityItem item : items)
|
||||
if(!item.isDead && item.getEntityItem() != null && item.getEntityItem().getItem() != Item.getItemFromBlock(ModBlocks.livingrock)) {
|
||||
|
||||
@@ -37,6 +37,7 @@ import vazkii.botania.common.core.handler.PixieHandler;
|
||||
import vazkii.botania.common.core.handler.SheddingHandler;
|
||||
import vazkii.botania.common.core.handler.SpawnerChangingHandler;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
import vazkii.botania.common.crafting.ModBrewRecipes;
|
||||
import vazkii.botania.common.crafting.ModCrafingRecipes;
|
||||
import vazkii.botania.common.crafting.ModElvenTradeRecipes;
|
||||
import vazkii.botania.common.crafting.ModManaAlchemyRecipes;
|
||||
@@ -78,6 +79,8 @@ public class CommonProxy {
|
||||
ModManaConjurationRecipes.init();
|
||||
ModManaInfusionRecipes.init();
|
||||
ModElvenTradeRecipes.init();
|
||||
ModBrewRecipes.init();
|
||||
|
||||
ChestGenHandler.init();
|
||||
|
||||
LexiconData.init();
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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 @ [Nov 1, 2014, 9:15:15 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.common.brew.ModBrews;
|
||||
|
||||
public class ModBrewRecipes {
|
||||
|
||||
public static RecipeBrew speedBrew;
|
||||
public static RecipeBrew strengthBrew;
|
||||
|
||||
public static void init() {
|
||||
speedBrew = BotaniaAPI.registerBrewRecipe(ModBrews.speed, new ItemStack(Items.nether_wart), new ItemStack(Items.sugar), new ItemStack(Items.redstone));
|
||||
strengthBrew = BotaniaAPI.registerBrewRecipe(ModBrews.strength, new ItemStack(Items.nether_wart), new ItemStack(Items.blaze_powder), new ItemStack(Items.glowstone_dust));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,11 +30,12 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.brew.Brew;
|
||||
import vazkii.botania.api.brew.IBrewItem;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.item.ItemMod;
|
||||
|
||||
public abstract class ItemBrewBase extends ItemMod {
|
||||
public abstract class ItemBrewBase extends ItemMod implements IBrewItem {
|
||||
|
||||
private static final String TAG_BREW_KEY = "brewKey";
|
||||
private static final String TAG_SWIGS_LEFT = "swigsLeft";
|
||||
@@ -105,7 +106,7 @@ public abstract class ItemBrewBase extends ItemMod {
|
||||
}
|
||||
}
|
||||
|
||||
public static Brew getBrew(ItemStack stack) {
|
||||
public Brew getBrew(ItemStack stack) {
|
||||
String key = ItemNBTHelper.getString(stack, TAG_BREW_KEY, "");
|
||||
return BotaniaAPI.getBrewFromKey(key);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user