New Plant API that allows for custom plants/soils.

This commit is contained in:
LexManos committed 2012-09-20 19:53:43 -07:00
1 parent c3f9fed484
commit 28d2460611
12 files changed
+452 -16

No files matched your search

@@ -1,6 +1,6 @@
--- ../src_base/common/net/minecraft/src/Block.java
+++ ../src_work/common/net/minecraft/src/Block.java
@@ -2,11 +2,23 @@
@@ -2,11 +2,21 @@
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
@@ -9,9 +9,7 @@
import java.util.List;
import java.util.Random;
+import net.minecraftforge.common.ForgeHooks;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.common.ForgeDirection;
+import net.minecraftforge.common.*;
+import static net.minecraftforge.common.ForgeDirection.*;
+
public class Block
@@ -24,7 +22,7 @@
/**
* used as foreach item, if item.tab = current tab, display it on the screen
*/
@@ -279,6 +291,7 @@
@@ -279,6 +289,7 @@
lightOpacity[par1] = this.isOpaqueCube() ? 255 : 0;
canBlockGrass[par1] = !par2Material.getCanBlockGrass();
}
@@ -32,7 +30,7 @@
}
/**
@@ -417,9 +430,10 @@
@@ -417,9 +428,10 @@
return this.needsRandomTick;
}
@@ -44,7 +42,7 @@
}
/**
@@ -442,7 +456,7 @@
@@ -442,7 +454,7 @@
*/
public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
@@ -53,7 +51,7 @@
}
@SideOnly(Side.CLIENT)
@@ -452,7 +466,7 @@
@@ -452,7 +464,7 @@
*/
public int getMixedBrightnessForBlock(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
@@ -62,7 +60,7 @@
}
@SideOnly(Side.CLIENT)
@@ -621,8 +635,7 @@
@@ -621,8 +633,7 @@
*/
public float getPlayerRelativeBlockHardness(EntityPlayer par1EntityPlayer, World par2World, int par3, int par4, int par5)
{
@@ -72,7 +70,7 @@
}
/**
@@ -640,18 +653,13 @@
@@ -640,18 +651,13 @@
{
if (!par1World.isRemote)
{
@@ -95,7 +93,7 @@
}
}
}
@@ -985,7 +993,7 @@
@@ -985,7 +991,7 @@
par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1);
par2EntityPlayer.addExhaustion(0.025F);
@@ -104,7 +102,7 @@
{
ItemStack var8 = this.createStackedBlock(par6);
@@ -1249,4 +1257,717 @@
@@ -1249,4 +1255,797 @@
canBlockGrass[0] = true;
StatList.initBreakableStats();
}
@@ -821,4 +819,84 @@
+ {
+ return false;
+ }
+
+ /**
+ * Determines if this block can support the passed in plant, allowing it to be planted and grow.
+ * Some examples:
+ * Reeds check if its a reed, or if its sand/dirt/grass and adjacent to water
+ * Cacti checks if its a cacti, or if its sand
+ * Nether types check for soul sand
+ * Crops check for tilled soil
+ * Caves check if it's a colid surface
+ * Plains check if its grass or dirt
+ * Water check if its still water
+ *
+ * @param world The current world
+ * @param x X Position
+ * @param y Y Position
+ * @param z Z position
+ * @param direction The direction relative to the given position the plant wants to be, typically its UP
+ * @param plant The plant that wants to check
+ * @return True to allow the plant to be planted/stay.
+ */
+ public boolean canSustainPlant(World world, int x, int y, int z, ForgeDirection direction, IPlantable plant)
+ {
+ int plantID = plant.getPlantID(world, x, y + 1, z);
+ EnumPlantType plantType = plant.getPlantType(world, x, y + 1, z);
+
+ if (plantID == cactus.blockID && blockID == cactus.blockID)
+ {
+ return true;
+ }
+
+ if (plantID == reed.blockID && blockID == reed.blockID)
+ {
+ return true;
+ }
+
+ if (plant instanceof BlockFlower && ((BlockFlower)plant).canThisPlantGrowOnThisBlockID(blockID))
+ {
+ return true;
+ }
+
+ switch (plantType)
+ {
+ case Desert: return blockID == sand.blockID;
+ case Nether: return blockID == slowSand.blockID;
+ case Crop: return blockID == tilledField.blockID;
+ case Cave: return isBlockSolidOnSide(world, x, y, z, UP);
+ case Plains: return blockID == grass.blockID || blockID == dirt.blockID;
+ case Water: return world.getBlockMaterial(x, y, z) == Material.water && world.getBlockMetadata(x, y, z) == 0;
+ case Beach:
+ boolean isBeach = (blockID == Block.grass.blockID || blockID == Block.dirt.blockID || blockID == Block.sand.blockID);
+ boolean hasWater = (world.getBlockMaterial(x - 1, y - 1, z ) == Material.water ||
+ world.getBlockMaterial(x + 1, y - 1, z ) == Material.water ||
+ world.getBlockMaterial(x, y - 1, z - 1) == Material.water ||
+ world.getBlockMaterial(x, y - 1, z + 1) == Material.water);
+ return isBeach && hasWater;
+ }
+
+ return false;
+ }
+
+ /**
+ * Checks if this soil is fertile, typically this means that growth rates
+ * of plants on this soil will be slightly sped up.
+ * Only vanilla case is tilledField when it is within range of water.
+ *
+ * @param world The current world
+ * @param x X Position
+ * @param y Y Position
+ * @param z Z position
+ * @return True if the soil should be considered fertile.
+ */
+ public boolean isFertile(World world, int x, int y, int z)
+ {
+ if (blockID == tilledField.blockID)
+ {
+ return world.getBlockMetadata(x, y, z) > 0;
+ }
+
+ return false;
+ }
}