Flower Rewrite Based on a weighted distribution system

Create cla-signatures.txt
Fixed code convention in Flower Class
This commit is contained in:
Martin Stühmer authored and mezz committed 2015-01-19 13:46:38 -08:00
1 parent 8eb366997d
commit 7ace6d7faa
21 files changed
+528 -631

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
Account;Email;Date;
samtrion;samtrion@gmail.com;2015-01-18
@@ -1,79 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class FlowerProviderCacti implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// Specific check for flower pots.
if (block == Blocks.flower_pot)
return checkFlowerPot(world.getBlockMetadata(x, y, z));
return block == Blocks.cactus;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
return pollinatable.getPlantType().contains(EnumPlantType.Desert);
}
private boolean checkFlowerPot(int meta) {
return meta == 9;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (block == Blocks.flower_pot && world.getBlockMetadata(x, y, z) == 0)
return growInPot(world, x, y, z);
return false;
}
private boolean growInPot(World world, int x, int y, int z) {
if (world.rand.nextBoolean())
world.setBlock(x, y, z, Blocks.flower_pot, 9, Defaults.FLAG_BLOCK_SYNCH);
else
world.setBlock(x, y, z, Blocks.flower_pot, 10, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.cacti");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.cactus) };
}
}
@@ -1,58 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.utils.StringUtil;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class FlowerProviderEnd implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == Blocks.dragon_egg;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.end");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.dragon_egg) };
}
}
@@ -1,76 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class FlowerProviderGourd implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == Blocks.pumpkin_stem || block == Blocks.melon_stem;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// We only grow wheat, we don't plant it
if (block != Blocks.pumpkin_stem && block != Blocks.melon_stem)
return false;
int meta = world.getBlockMetadata(x, y, z);
if (meta > 6)
return false;
if (meta < 6)
meta += 2;
else
meta = 7;
world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.gourd");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.wheat, 1, 8) };
}
}
@@ -1,79 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class FlowerProviderJungle implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
// Specific check for flower pots.
if (block == Blocks.flower_pot)
return checkFlowerPot(meta);
return block == Blocks.vine || (block == Blocks.tallgrass && meta == 2);
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
private boolean checkFlowerPot(int meta) {
return meta == 11;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (block == Blocks.flower_pot)
return growInPot(world, x, y, z);
return false;
}
private boolean growInPot(World world, int x, int y, int z) {
world.setBlock(x, y, z, Blocks.flower_pot, 11, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.jungle");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.vine), new ItemStack(Blocks.tallgrass, 1, 2) };
}
}
@@ -1,97 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class FlowerProviderMushroom implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// Specific check for flower pots.
if (block == Blocks.flower_pot)
return checkFlowerPot(world.getBlockMetadata(x, y, z));
return block == Blocks.brown_mushroom || block == Blocks.red_mushroom;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
private boolean checkFlowerPot(int meta) {
return meta == 7 || meta == 8;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (!block.isAir(world, x, y, z))
if (block == Blocks.flower_pot)
return growInPot(world, x, y, z);
else
return false;
// Check ground
Block ground = world.getBlock(x, y - 1, z);
if (ground != Blocks.mycelium)
return false;
Block mushroom;
if (world.rand.nextBoolean())
mushroom = Blocks.brown_mushroom;
else
mushroom = Blocks.red_mushroom;
world.setBlock(x, y, z, mushroom, 0, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
private boolean growInPot(World world, int x, int y, int z) {
if (world.rand.nextBoolean())
world.setBlock(x, y, z, Blocks.flower_pot, 7, Defaults.FLAG_BLOCK_SYNCH);
else
world.setBlock(x, y, z, Blocks.flower_pot, 8, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.mushroom");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.brown_mushroom), new ItemStack(Blocks.red_mushroom) };
}
}
@@ -1,74 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class FlowerProviderNetherwart implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == Blocks.nether_wart;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
return pollinatable.getPlantType().contains(EnumPlantType.Nether);
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// We only grow netherwart, we don't plant it
if (block != Blocks.nether_wart)
return false;
int meta = world.getBlockMetadata(x, y, z);
if (meta >= 3)
return false;
if (meta == 2)
meta = 3;
else
meta = 2;
world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.nether");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.nether_wart) };
}
}
@@ -1,106 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
import forestry.api.apiculture.FlowerManager;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StackUtils;
import forestry.core.utils.StringUtil;
import java.util.Collections;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class FlowerProviderVanilla implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
// Specific check for flower pots.
if (block == Blocks.flower_pot)
return checkFlowerPot(meta);
ItemStack flower = new ItemStack(block, 1, meta);
for (ItemStack stack : FlowerManager.plainFlowers)
if (flower.isItemEqual(stack))
return true;
return false;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
private boolean checkFlowerPot(int meta) {
return meta == 1 || meta == 2;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (!block.isAir(world, x, y, z))
if (block == Blocks.flower_pot && world.getBlockMetadata(x, y, z) == 0)
return growInPot(world, x, y, z);
else
return false;
// Check ground
Block ground = world.getBlock(x, y - 1, z);
if (ground != Blocks.dirt && ground != Blocks.grass)
return false;
// Determine flower to plant
Collections.shuffle(FlowerManager.plainFlowers);
ItemStack flower = FlowerManager.plainFlowers.get(world.rand.nextInt(FlowerManager.plainFlowers.size() - 1));
world.setBlock(x, y, z, StackUtils.getBlock(flower), flower.getItemDamage(), Defaults.FLAG_BLOCK_SYNCH);
return true;
}
private boolean growInPot(World world, int x, int y, int z) {
if (world.rand.nextBoolean())
world.setBlock(x, y, z, Blocks.flower_pot, 1, Defaults.FLAG_BLOCK_SYNCH);
else
world.setBlock(x, y, z, Blocks.flower_pot, 2, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.vanilla");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return FlowerManager.plainFlowers.toArray(new ItemStack[FlowerManager.plainFlowers.size()]);
}
}
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.flowers;
import forestry.core.utils.StackUtils;
import net.minecraft.item.ItemStack;
final class Flower implements Comparable<Flower> {
public final ItemStack item;
public final Double weight;
public final boolean isPlantable;
public Flower(ItemStack item, double weight, boolean isPlantable) {
this.item = item;
this.weight = weight;
this.isPlantable = isPlantable;
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof Flower))
return false;
return StackUtils.isIdenticalItem(this.item, ((Flower) obj).item) && this.isPlantable == ((Flower) obj).isPlantable;
}
@Override
public int compareTo(Flower other) {
return this.weight.compareTo(other.weight);
}
}
@@ -4,63 +4,59 @@
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture;
package forestry.apiculture.flowers;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.apiculture.FlowerManager;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.utils.StringUtil;
public class FlowerProviderWheat implements IFlowerProvider {
public class FlowerProvider implements IFlowerProvider {
private final String flowerType;
private final String description;
public FlowerProvider(String flowerType, String description) {
this.flowerType = flowerType;
this.description = description;
}
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == Blocks.wheat;
return FlowerManager.flowerRegistry.isAcceptedFlower(this.flowerType, world, individual, x, y, z);
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
if (types.size() > 1) {
if (flowerType.equals(FlowerManager.FlowerTypeNether) && types.contains(EnumPlantType.Nether)) {
return true;
} else if (!flowerType.equals(FlowerManager.FlowerTypeNether) && !types.contains(EnumPlantType.Nether)) {
return true;
}
}
return false;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// We only grow wheat, we don't plant it
if (block != Blocks.wheat)
return false;
int meta = world.getBlockMetadata(x, y, z);
if (meta > 6)
return false;
if (meta < 6)
meta += 2;
else
meta = 7;
world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH);
return true;
return FlowerManager.flowerRegistry.growFlower(this.flowerType, world, individual, x, y, z);
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.wheat");
return StringUtil.localize(this.description);
}
@Override
@@ -70,7 +66,7 @@ public class FlowerProviderWheat implements IFlowerProvider {
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.wheat, 1, 8) };
return FlowerManager.flowerRegistry.getAcceptableFlowers(this.flowerType);
}
}
@@ -0,0 +1,206 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.flowers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import forestry.api.apiculture.FlowerManager;
import forestry.api.genetics.IFlowerGrowthRule;
import forestry.api.genetics.IFlowerRegistry;
import forestry.api.genetics.IIndividual;
import forestry.core.utils.StackUtils;
public final class FlowerRegistry implements IFlowerRegistry {
private final Map<String, List<Flower>> registeredFlowers;
private final Map<String, List<IFlowerGrowthRule>> growthRules;
private boolean hasDepricatedFlowersImported;
public FlowerRegistry() {
this.registeredFlowers = new HashMap<String, List<Flower>>();
this.growthRules = new HashMap<String, List<IFlowerGrowthRule>>();
this.hasDepricatedFlowersImported = false;
registerVanillaFlowers();
registerVanillaGrowthRules();
}
@Override
public void registerAcceptableFlower(ItemStack is, String... flowerTypes) {
registerFlower(is, null, false, flowerTypes);
}
@Override
public void registerPlantableFlower(ItemStack is, double weight, String... flowerTypes) {
registerFlower(is, weight, true, flowerTypes);
}
private void registerFlower(ItemStack is, Double weight, boolean isPlantable, String... flowerTypes) {
if (is == null || is.getItem() == null)
return;
if (is.getItemDamage() == Short.MAX_VALUE || is.getItemDamage() == -1)
return;
if (weight == null || weight <= 0.0)
weight = 0.0;
if (weight >= 1.0)
weight = 1.0;
Flower newFlower = new Flower(is, weight, isPlantable);
for (String flowerType : flowerTypes) {
if (!this.registeredFlowers.containsKey(flowerType)) {
this.registeredFlowers.put(flowerType, new ArrayList<Flower>());
}
if (!this.registeredFlowers.get(flowerType).contains(newFlower)) {
this.registeredFlowers.get(flowerType).add(newFlower);
Collections.sort(this.registeredFlowers.get(flowerType));
}
}
}
@Override
public boolean isAcceptedFlower(String flowerType, World world, IIndividual individual, int x, int y, int z) {
internalInitialize();
if (!this.registeredFlowers.containsKey(flowerType))
return false;
Block b = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
ItemStack is = new ItemStack(b, 1, meta);
for (Flower f : this.registeredFlowers.get(flowerType))
if (StackUtils.isIdenticalItem(f.item, is))
return true;
return false;
}
@Override
public boolean growFlower(String flowerType, World world, IIndividual individual, int x, int y, int z) {
internalInitialize();
if (!this.growthRules.containsKey(flowerType))
return false;
for (IFlowerGrowthRule r : this.growthRules.get(flowerType))
if (r.growFlower(this, flowerType, world, individual, x, y, z))
return true;
return false;
}
@Override
public ItemStack[] getAcceptableFlowers(String flowerType) {
internalInitialize();
List<Flower> flowers = this.registeredFlowers.get(flowerType);
ItemStack[] acceptableFlowers = new ItemStack[flowers.size()];
for (int i = 0; i < acceptableFlowers.length; i++)
acceptableFlowers[i] = flowers.get(i).item;
return acceptableFlowers;
}
@Override
public void registerGrowthRule(IFlowerGrowthRule rule, String... flowerTypes) {
if (rule == null)
return;
for (String flowerType : flowerTypes) {
if (!this.growthRules.containsKey(flowerType))
this.growthRules.put(flowerType, new ArrayList<IFlowerGrowthRule>());
this.growthRules.get(flowerType).add(rule);
}
}
@Override
public ItemStack getRandomPlantableFlower(String flowerType, Random rand) {
TreeMap<Double, Flower> tm = new TreeMap<Double, Flower>();
double count = 0.0;
for (Flower f : this.registeredFlowers.get(flowerType)) {
if (f.isPlantable) {
tm.put(count, f);
count += f.weight;
}
}
return tm.get(tm.lowerKey(rand.nextDouble() * count)).item;
}
/*
* Method to support deprecated FlowerManager.plainFlowers
*/
@SuppressWarnings("deprecation")
private void internalInitialize() {
if (!hasDepricatedFlowersImported) {
for (ItemStack f : FlowerManager.plainFlowers)
registerPlantableFlower(f, 1.0, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
hasDepricatedFlowersImported = true;
}
}
private void registerVanillaFlowers() {
// Register plantable plants
for (int sc = 0; sc <= 8; sc++)
registerPlantableFlower(new ItemStack(Blocks.red_flower, 1, sc), 1.0, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
registerPlantableFlower(new ItemStack(Blocks.yellow_flower), 1.0, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
registerPlantableFlower(new ItemStack(Blocks.brown_mushroom), 1.0, FlowerManager.FlowerTypeMushrooms);
registerPlantableFlower(new ItemStack(Blocks.red_mushroom), 1.0, FlowerManager.FlowerTypeMushrooms);
registerPlantableFlower(new ItemStack(Blocks.cactus), 1.0, FlowerManager.FlowerTypeCacti);
// Register acceptable plants
registerAcceptableFlower(new ItemStack(Blocks.flower_pot, 1, 1), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
registerAcceptableFlower(new ItemStack(Blocks.flower_pot, 1, 2), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
registerAcceptableFlower(new ItemStack(Blocks.flower_pot, 1, 7), FlowerManager.FlowerTypeMushrooms);
registerAcceptableFlower(new ItemStack(Blocks.flower_pot, 1, 8), FlowerManager.FlowerTypeMushrooms);
registerAcceptableFlower(new ItemStack(Blocks.flower_pot, 1, 9), FlowerManager.FlowerTypeCacti);
registerAcceptableFlower(new ItemStack(Blocks.flower_pot, 1, 11), FlowerManager.FlowerTypeJungle);
registerAcceptableFlower(new ItemStack(Blocks.dragon_egg), FlowerManager.FlowerTypeEnd);
registerAcceptableFlower(new ItemStack(Blocks.vine), FlowerManager.FlowerTypeJungle);
registerAcceptableFlower(new ItemStack(Blocks.tallgrass, 1, 2), FlowerManager.FlowerTypeJungle);
registerAcceptableFlower(new ItemStack(Blocks.wheat, 1, 8), FlowerManager.FlowerTypeWheat);
registerAcceptableFlower(new ItemStack(Blocks.pumpkin_stem), FlowerManager.FlowerTypeGourd);
registerAcceptableFlower(new ItemStack(Blocks.melon_stem), FlowerManager.FlowerTypeGourd);
registerAcceptableFlower(new ItemStack(Blocks.nether_wart), FlowerManager.FlowerTypeNether);
registerAcceptableFlower(new ItemStack(Blocks.double_plant, 1, 0), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
registerAcceptableFlower(new ItemStack(Blocks.double_plant, 1, 1), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
registerAcceptableFlower(new ItemStack(Blocks.double_plant, 1, 4), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
registerAcceptableFlower(new ItemStack(Blocks.double_plant, 1, 5), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
}
private void registerVanillaGrowthRules() {
registerGrowthRule(new VanillaDirtGrassGrowthRule(), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
registerGrowthRule(new VanillaSnowGrowthRule(), FlowerManager.FlowerTypeSnow);
registerGrowthRule(new VanillaFlowerPotGrowthRule(), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow, FlowerManager.FlowerTypeMushrooms, FlowerManager.FlowerTypeCacti,
FlowerManager.FlowerTypeJungle);
registerGrowthRule(new VanillaMyceliumGrowthRule(), FlowerManager.FlowerTypeMushrooms);
registerGrowthRule(new VanillaDefaultGrowthRule(), FlowerManager.FlowerTypeEnd);
registerGrowthRule(new VanillaFertilizeGrowthRule(Blocks.melon_stem, Blocks.pumpkin_stem), FlowerManager.FlowerTypeGourd);
registerGrowthRule(new VanillaFertilizeGrowthRule(Blocks.wheat), FlowerManager.FlowerTypeWheat);
}
}
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.flowers;
import net.minecraft.world.World;
import forestry.api.genetics.IFlowerGrowthRule;
import forestry.api.genetics.IFlowerRegistry;
import forestry.api.genetics.IIndividual;
public class VanillaDefaultGrowthRule implements IFlowerGrowthRule {
@Override
public boolean growFlower(IFlowerRegistry fr, String flowerType, World world, IIndividual individual, int x, int y, int z) {
return true;
}
}
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.flowers;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import forestry.api.genetics.IFlowerGrowthRule;
import forestry.api.genetics.IFlowerRegistry;
import forestry.api.genetics.IIndividual;
import forestry.core.config.Defaults;
import forestry.core.utils.StackUtils;
public class VanillaDirtGrassGrowthRule implements IFlowerGrowthRule {
@Override
public boolean growFlower(IFlowerRegistry fr, String flowerType, World world, IIndividual individual, int x, int y, int z) {
if (!world.isAirBlock(x, y, z))
return false;
Block ground = world.getBlock(x, y - 1, z);
if (ground != Blocks.dirt && ground != Blocks.grass)
return false;
ItemStack flower = fr.getRandomPlantableFlower(flowerType, world.rand);
return world.setBlock(x, y, z, StackUtils.getBlock(flower), flower.getItemDamage(), Defaults.FLAG_BLOCK_SYNCH);
}
}
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.flowers;
import java.util.Arrays;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import forestry.api.genetics.IFlowerGrowthRule;
import forestry.api.genetics.IFlowerRegistry;
import forestry.api.genetics.IIndividual;
public class VanillaFertilizeGrowthRule implements IFlowerGrowthRule {
private final List<Block> allowedItems;
public VanillaFertilizeGrowthRule(Block... allowedItems) {
this.allowedItems = Arrays.asList(allowedItems);
}
@Override
public boolean growFlower(IFlowerRegistry fr, String flowerType, World world, IIndividual individual, int x, int y, int z) {
Block ground = world.getBlock(x, y, z);
int groundMeta;
for (Block b : this.allowedItems) {
if (b == ground) {
groundMeta = world.getBlockMetadata(x, y, z);
if (groundMeta > 6)
return false;
if (groundMeta < 6)
groundMeta += world.rand.nextInt(1) + 1;
else
groundMeta = 7;
return world.setBlockMetadataWithNotify(x, y, z, groundMeta, 2);
}
}
return false;
}
}
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.flowers;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import forestry.api.apiculture.FlowerManager;
import forestry.api.genetics.IFlowerGrowthRule;
import forestry.api.genetics.IFlowerRegistry;
import forestry.api.genetics.IIndividual;
import forestry.core.config.Defaults;
public class VanillaFlowerPotGrowthRule implements IFlowerGrowthRule {
@Override
public boolean growFlower(IFlowerRegistry fr, String flowerType, World world, IIndividual individual, int x, int y, int z) {
Block ground = world.getBlock(x, y, z);
int groundMeta = world.getBlockMetadata(x, y, z);
if (ground != Blocks.flower_pot && groundMeta != 0)
return false;
if (flowerType.equals(FlowerManager.FlowerTypeVanilla) || flowerType.equals(FlowerManager.FlowerTypeSnow)) {
groundMeta = world.rand.nextInt(1) + 1;
} else if (flowerType.equals(FlowerManager.FlowerTypeJungle)) {
groundMeta = 11;
} else if (flowerType.equals(FlowerManager.FlowerTypeCacti)) {
groundMeta = world.rand.nextInt(1) + 9;
} else if (flowerType.equals(FlowerManager.FlowerTypeMushrooms)) {
groundMeta = world.rand.nextInt(1) + 7;
} else {
return false;
}
return world.setBlock(x, y, z, ground, groundMeta, Defaults.FLAG_BLOCK_SYNCH);
}
}
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.flowers;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import forestry.api.genetics.IFlowerGrowthRule;
import forestry.api.genetics.IFlowerRegistry;
import forestry.api.genetics.IIndividual;
import forestry.core.config.Defaults;
import forestry.core.utils.StackUtils;
public class VanillaMyceliumGrowthRule implements IFlowerGrowthRule {
@Override
public boolean growFlower(IFlowerRegistry fr, String flowerType, World world, IIndividual individual, int x, int y, int z) {
if (!world.isAirBlock(x, y, z))
return false;
Block ground = world.getBlock(x, y - 1, z);
if (ground != Blocks.mycelium)
return false;
ItemStack flower = fr.getRandomPlantableFlower(flowerType, world.rand);
return world.setBlock(x, y, z, StackUtils.getBlock(flower), flower.getItemDamage(), Defaults.FLAG_BLOCK_SYNCH);
}
}
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.flowers;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import forestry.api.genetics.IFlowerGrowthRule;
import forestry.api.genetics.IFlowerRegistry;
import forestry.api.genetics.IIndividual;
import forestry.core.config.Defaults;
import forestry.core.utils.StackUtils;
public class VanillaSnowGrowthRule implements IFlowerGrowthRule {
@Override
public boolean growFlower(IFlowerRegistry fr, String flowerType, World world, IIndividual individual, int x, int y, int z) {
if (world.getBlock(x, y, z) != Blocks.snow)
return false;
Block ground = world.getBlock(x, y - 1, z);
if (ground != Blocks.dirt && ground != Blocks.grass)
return false;
ItemStack flower = fr.getRandomPlantableFlower(flowerType, world.rand);
return world.setBlock(x, y, z, StackUtils.getBlock(flower), flower.getItemDamage(), Defaults.FLAG_BLOCK_SYNCH);
}
}
@@ -270,7 +270,7 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 {
if (!Blocks.red_flower.canBlockStay(world, xCoord, yCoord, zCoord))
continue;
ItemStack flower = FlowerManager.plainFlowers.get(world.rand.nextInt(FlowerManager.plainFlowers.size()));
ItemStack flower = FlowerManager.flowerRegistry.getRandomPlantableFlower(FlowerManager.FlowerTypeVanilla, world.rand);
this.placeBlockAtCurrentPosition(world, flower, j, i, k, box);
}
}
@@ -14,7 +14,6 @@ import com.google.common.collect.ImmutableList;
import java.io.File;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
@@ -26,7 +25,6 @@ import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import forestry.api.apiculture.FlowerManager;
import forestry.api.core.ForestryAPI;
import forestry.api.fuels.EngineBronzeFuel;
import forestry.api.fuels.EngineCopperFuel;
@@ -103,11 +101,6 @@ public class ForestryCore {
Defaults.RAINMAKER_RAIN_DURATION_IODINE, 0.01f));
FuelManager.rainSubstrate.put(ForestryItem.craftingMaterial.getItemStack(1, 4), new RainSubstrate(ForestryItem.craftingMaterial.getItemStack(1, 4), 0.075f));
// Set additional apiary flowers
for (int i = 0; i < 9; i++)
FlowerManager.plainFlowers.add(new ItemStack(Blocks.red_flower, 1, i));
FlowerManager.plainFlowers.add(new ItemStack(Blocks.yellow_flower));
// Register gui handler
NetworkRegistry.INSTANCE.registerGuiHandler(basemod, new GuiHandler());
@@ -28,13 +28,11 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
@@ -45,7 +43,6 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.VillagerRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.FlowerManager;
@@ -64,19 +61,13 @@ import forestry.api.genetics.IClassification.EnumClassLevel;
import forestry.api.recipes.RecipeManagers;
import forestry.api.storage.ICrateRegistry;
import forestry.api.storage.StorageManager;
import forestry.apiculture.FlowerProviderCacti;
import forestry.apiculture.FlowerProviderEnd;
import forestry.apiculture.FlowerProviderGourd;
import forestry.apiculture.FlowerProviderJungle;
import forestry.apiculture.FlowerProviderMushroom;
import forestry.apiculture.FlowerProviderNetherwart;
import forestry.apiculture.FlowerProviderVanilla;
import forestry.apiculture.FlowerProviderWheat;
import forestry.apiculture.flowers.FlowerProvider;
import forestry.apiculture.GuiHandlerApiculture;
import forestry.apiculture.PacketHandlerApiculture;
import forestry.apiculture.SaveEventHandlerApiculture;
import forestry.apiculture.VillageHandlerApiculture;
import forestry.apiculture.commands.CommandBee;
import forestry.apiculture.flowers.FlowerRegistry;
import forestry.apiculture.gadgets.BlockAlveary;
import forestry.apiculture.gadgets.BlockBeehives;
import forestry.apiculture.gadgets.BlockCandle;
@@ -202,6 +193,8 @@ public class PluginApiculture extends ForestryPlugin {
HiveManager.genHelper = new HiveGenHelper();
createHiveDropArrays();
FlowerManager.flowerRegistry = new FlowerRegistry();
ForestryBlock.apiculture.registerBlock(new BlockBase(Material.iron), ItemForestryBlock.class, "apiculture");
ForestryBlock.apiculture.block().setCreativeTab(Tabs.tabApiculture);
@@ -994,16 +987,18 @@ public class PluginApiculture extends ForestryPlugin {
.addSpecialty(ForestryItem.beeComb.getItemStack(1, 16), 20).setJubilanceProvider(new JubilanceProviderHermit()).setHasEffect().setIsSecret();
// / BEES // FLOWER PROVIDERS 1500 - 1599
Allele.flowersVanilla = new AlleleFlowers("flowersVanilla", new FlowerProviderVanilla(), true);
Allele.flowersNether = new AlleleFlowers("flowersNether", new FlowerProviderNetherwart());
Allele.flowersCacti = new AlleleFlowers("flowersCacti", new FlowerProviderCacti());
Allele.flowersMushrooms = new AlleleFlowers("flowersMushrooms", new FlowerProviderMushroom());
Allele.flowersEnd = new AlleleFlowers("flowersEnd", new FlowerProviderEnd());
Allele.flowersJungle = new AlleleFlowers("flowersJungle", new FlowerProviderJungle());
Allele.flowersSnow = new AlleleFlowers("flowersSnow", new FlowerProviderVanilla(), true);
Allele.flowersWheat = new AlleleFlowers("flowersWheat", new FlowerProviderWheat(), true);
Allele.flowersGourd = new AlleleFlowers("flowersGourd", new FlowerProviderGourd(), true);
Allele.flowersVanilla = new AlleleFlowers("flowersVanilla", new FlowerProvider(FlowerManager.FlowerTypeVanilla, "flowers.vanilla"), true);
Allele.flowersNether = new AlleleFlowers("flowersNether", new FlowerProvider(FlowerManager.FlowerTypeNether, "flowers.nether"));
Allele.flowersCacti = new AlleleFlowers("flowersCacti", new FlowerProvider(FlowerManager.FlowerTypeCacti, "flowers.cacti"));
Allele.flowersMushrooms = new AlleleFlowers("flowersMushrooms", new FlowerProvider(FlowerManager.FlowerTypeMushrooms, "flowers.mushroom"));
Allele.flowersEnd = new AlleleFlowers("flowersEnd", new FlowerProvider(FlowerManager.FlowerTypeEnd, "flowers.end"));
Allele.flowersJungle = new AlleleFlowers("flowersJungle", new FlowerProvider(FlowerManager.FlowerTypeJungle, "flowers.jungle"));
Allele.flowersSnow = new AlleleFlowers("flowersSnow", new FlowerProvider(FlowerManager.FlowerTypeSnow, "flowers.vanilla"), true);
Allele.flowersWheat = new AlleleFlowers("flowersWheat", new FlowerProvider(FlowerManager.FlowerTypeWheat, "flowers.wheat"), true);
Allele.flowersGourd = new AlleleFlowers("flowersGourd", new FlowerProvider(FlowerManager.FlowerTypeGourd, "flowers.gourd"), true);
// REgiste
// / BEES // EFFECTS 1800 - 1899
Allele.effectNone = new AlleleEffectNone("effectNone");
Allele.effectAggressive = new AlleleEffectAggressive("effectAggressive");