Skip to content
Browse files

Merge pull request #128 from aPunch/master

More Plant Logic
  • Loading branch information...
2 parents 8972144 + 02222b1 commit 37b0af0667e5633f739480c4c9987df1c8e055d0 Chris Sanders committed Apr 15, 2012
View
3 src/main/java/org/spout/vanilla/material/VanillaMaterials.java
@@ -44,6 +44,7 @@
import org.spout.vanilla.material.block.MinecartTrack;
import org.spout.vanilla.material.block.MinecartTrackDetector;
import org.spout.vanilla.material.block.MinecartTrackPowered;
+import org.spout.vanilla.material.block.NetherWartBlock;
import org.spout.vanilla.material.block.Ore;
import org.spout.vanilla.material.block.Plank;
import org.spout.vanilla.material.block.Sandstone;
@@ -200,7 +201,7 @@
public static final Solid NETHER_BRICK = (Solid) register(new Solid("Nether Brick", 112).setHardness(2.0F).setResistance(10.0F));
public static final Solid NETHER_BRICK_FENCE = (Solid) register(new Solid("Nether Brick Fence", 113).setHardness(2.0F).setResistance(10.0F));
public static final Solid NETHER_BRICK_STAIRS = (Solid) register(new Solid("Nether Brick Stairs", 114).setResistance(10.0F));
- public static final Solid NETHER_WART_BLOCK = (Solid) register(new Solid("Nether Wart", 115).setResistance(0.0F));
+ public static final NetherWartBlock NETHER_WART_BLOCK = (NetherWartBlock) register(new NetherWartBlock("Nether Wart", 115).setResistance(0.0F));
public static final Solid ENCHANTMENT_TABLE = (Solid) register(new Solid("Enchantment Table", 116).setHardness(5.0F).setResistance(2000.0F));
public static final Solid BREWING_STAND_BLOCK = (Solid) register(new Solid("Brewing Stand", 117).setHardness(0.5F).setResistance(0.8F).setLightLevel(1));
public static final Solid CAULDRON_BLOCK = (Solid) register(new Solid("Cauldron", 118).setHardness(2.0F).setResistance(3.3F));
View
3 src/main/java/org/spout/vanilla/material/block/Flower.java
@@ -31,6 +31,7 @@
import org.spout.api.material.Material;
import org.spout.api.material.block.BlockFace;
import org.spout.vanilla.material.Plant;
+import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.material.attachable.GroundAttachable;
public class Flower extends GroundAttachable implements Plant {
@@ -57,7 +58,7 @@ public int getMinimumLightToGrow() {
public boolean canPlace(World world, int x, int y, int z, short data, BlockFace against, Source source) {
if (super.canPlace(world, x, y, z, data, against, source)) {
Block block = world.getBlock(x, y, z).move(against.getOpposite());
- return block.getMaterial() instanceof Grass || block.getMaterial().getId() == 3; // Grass or Dirt
+ return block.getMaterial() instanceof Grass || block.getMaterial() == VanillaMaterials.DIRT;
} else {
return false;
}
View
106 src/main/java/org/spout/vanilla/material/block/NetherWartBlock.java
@@ -0,0 +1,106 @@
+/*
+ * This file is part of Vanilla (http://www.spout.org/).
+ *
+ * Vanilla is licensed under the SpoutDev License Version 1.
+ *
+ * Vanilla is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * In addition, 180 days after any changes are published, you can use the
+ * software, incorporating those changes, under the terms of the MIT license,
+ * as described in the SpoutDev License Version 1.
+ *
+ * Vanilla is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License,
+ * the MIT license and the SpoutDev License Version 1 along with this program.
+ * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
+ * License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
+ * including the MIT license.
+ */
+package org.spout.vanilla.material.block;
+
+import java.util.Random;
+
+import org.spout.api.geo.World;
+import org.spout.api.geo.discrete.Point;
+import org.spout.api.inventory.ItemStack;
+import org.spout.api.material.BlockMaterial;
+import org.spout.api.material.Material;
+import org.spout.api.material.source.DataSource;
+import org.spout.vanilla.controller.object.moving.Item;
+import org.spout.vanilla.material.Plant;
+import org.spout.vanilla.material.VanillaMaterials;
+
+public class NetherWartBlock extends Solid implements Plant {
+ private GrowthStage stage = GrowthStage.SEEDLING;
+
+ public NetherWartBlock(String name, int id) {
+ super(name, id);
+ }
+
+ @Override
+ public boolean hasGrowthStages() {
+ return true;
+ }
+
+ @Override
+ public int getNumGrowthStages() {
+ return 3;
+ }
+
+ @Override
+ public int getMinimumLightToGrow() {
+ return 0;
+ }
+
+ @Override
+ public short getData() {
+ return stage.getData();
+ }
+
+ @Override
+ public Material getDrop() {
+ return VanillaMaterials.NETHER_WART;
+ }
+
+ @Override
+ public int getDropCount() {
+ return stage == GrowthStage.LAST ? new Random().nextInt(4) + 2 : 1;
+ }
+
+ @Override
+ public void onUpdate(World world, int x, int y, int z) {
+ BlockMaterial below = world.getBlockMaterial(x, y - 1, z);
+ if (!below.equals(VanillaMaterials.SOUL_SAND)) {
+ Point point = new Point(world, x, y, z);
+ world.setBlockMaterial(x, y, z, VanillaMaterials.AIR, (short) 0, true, world);
+ world.createAndSpawnEntity(point, new Item(new ItemStack(VanillaMaterials.NETHER_WART, 1), point.normalize()));
+ }
+ }
+
+ public GrowthStage getGrowthStage() {
+ return stage;
+ }
+
+ public enum GrowthStage implements DataSource {
+ SEEDLING(1),
+ MIDDLE(2),
+ LAST(3);
+ private final short data;
+
+ GrowthStage(int data) {
+ this.data = (short) data;
+ }
+
+ @Override
+ public short getData() {
+ return data;
+ }
+ }
+}
View
15 src/main/java/org/spout/vanilla/material/block/Sapling.java
@@ -25,7 +25,12 @@
*/
package org.spout.vanilla.material.block;
+import org.spout.api.Source;
+import org.spout.api.geo.World;
+import org.spout.api.geo.cuboid.Block;
+import org.spout.api.material.block.BlockFace;
import org.spout.vanilla.material.Plant;
+import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.material.attachable.GroundAttachable;
public class Sapling extends GroundAttachable implements Plant {
@@ -62,4 +67,14 @@ public int getNumGrowthStages() {
public int getMinimumLightToGrow() {
return 8;
}
+
+ @Override
+ public boolean canPlace(World world, int x, int y, int z, short data, BlockFace against, Source source) {
+ if (super.canPlace(world, x, y, z, data, against, source)) {
+ Block block = world.getBlock(x, y, z).move(against.getOpposite());
+ return block.getMaterial() instanceof Grass || block.getMaterial() == VanillaMaterials.DIRT;
+ } else {
+ return false;
+ }
+ }
}

0 comments on commit 37b0af0

Please sign in to comment.
Something went wrong with that request. Please try again.