mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-22 21:09:51 +00:00
Fix flower registry, remove config for now
This commit is contained in:
1 parent
d4cfbe9f29
commit
55cf7b5c16
7 files changed
+93
-298
No files matched your search
@@ -5,6 +5,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -13,5 +14,5 @@ public interface IFlowerAcceptableRule {
|
||||
* Checks if the flower at this position is accepted by this rule.
|
||||
* flowerType is passed in case this rule is registered for multiple flower types.
|
||||
*/
|
||||
boolean isAcceptableFlower(String flowerType, World world, BlockPos pos);
|
||||
boolean isAcceptableFlower(IBlockState blockState, World world, BlockPos pos, String flowerType);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -29,14 +30,14 @@ public interface IFlowerRegistry {
|
||||
void registerGrowthRule(IFlowerGrowthRule rule, String... flowerTypes);
|
||||
|
||||
/**
|
||||
* Registers an accepted flower with any meta value.
|
||||
* Registers an accepted flower with any state.
|
||||
*/
|
||||
void registerAcceptableFlower(Block flowerBlock, String... flowerTypes);
|
||||
void registerAcceptableFlower(Block block, String... flowerTypes);
|
||||
|
||||
/**
|
||||
* Registers an accepted flower with a specific meta value.
|
||||
* Registers an accepted flower with a particular state.
|
||||
*/
|
||||
void registerAcceptableFlower(Block flowerBlock, int flowerMeta, String... flowerTypes);
|
||||
void registerAcceptableFlower(IBlockState blockState, String... flowerTypes);
|
||||
|
||||
/**
|
||||
* Registers custom logic for accepted flowers.
|
||||
@@ -53,7 +54,7 @@ public interface IFlowerRegistry {
|
||||
* @param weight Weight for the Flower (Vanilla = 1.0, Modded flowers < 1.0)
|
||||
* @param flowerTypes See {@link forestry.api.apiculture.FlowerManager}.FlowerTypeXXX
|
||||
*/
|
||||
void registerPlantableFlower(Block flowerBlock, int flowerMeta, double weight, String... flowerTypes);
|
||||
void registerPlantableFlower(IBlockState blockState, double weight, String... flowerTypes);
|
||||
|
||||
/**
|
||||
* Calls the appropriate IFlowerGrowthRule to grow a flower at a specified position.
|
||||
|
||||
@@ -21,7 +21,9 @@ import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFlower;
|
||||
import net.minecraft.block.BlockRedFlower;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -37,7 +39,6 @@ import net.minecraft.world.storage.loot.LootTableList;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
@@ -47,7 +48,6 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.common.registry.VillagerRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.Forestry;
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
@@ -71,7 +71,6 @@ import forestry.apiculture.commands.CommandBee;
|
||||
import forestry.apiculture.entities.EntityMinecartApiary;
|
||||
import forestry.apiculture.entities.EntityMinecartBeehouse;
|
||||
import forestry.apiculture.entities.ParticleBee;
|
||||
import forestry.apiculture.flowers.Flower;
|
||||
import forestry.apiculture.flowers.FlowerRegistry;
|
||||
import forestry.apiculture.genetics.BeeBranchDefinition;
|
||||
import forestry.apiculture.genetics.BeeDefinition;
|
||||
@@ -114,11 +113,8 @@ import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.EntityUtil;
|
||||
import forestry.core.utils.IMCUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
import forestry.core.utils.Stack;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.core.utils.VillagerTradeLists;
|
||||
import forestry.food.PluginFood;
|
||||
import forestry.food.items.ItemRegistryFood;
|
||||
@@ -208,19 +204,17 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
@Override
|
||||
public void doInit() {
|
||||
File configFile = new File(Forestry.instance.getConfigFolder(), CONFIG_CATEGORY + ".cfg");
|
||||
if (!configFile.exists()) {
|
||||
setDefaultsForConfig();
|
||||
}
|
||||
|
||||
LocalizedConfiguration config = new LocalizedConfiguration(configFile, "2.0.0");
|
||||
LocalizedConfiguration config = new LocalizedConfiguration(configFile, "3.0.0");
|
||||
if (!Objects.equals(config.getLoadedConfigVersion(), config.getDefinedConfigVersion())) {
|
||||
boolean deleted = configFile.delete();
|
||||
if (deleted) {
|
||||
config = new LocalizedConfiguration(configFile, "2.0.0");
|
||||
setDefaultsForConfig();
|
||||
config = new LocalizedConfiguration(configFile, "3.0.0");
|
||||
}
|
||||
}
|
||||
|
||||
initFlowerRegistry();
|
||||
|
||||
List<IBeekeepingMode> beekeepingModes = BeeManager.beeRoot.getBeekeepingModes();
|
||||
String[] validBeekeepingModeNames = new String[beekeepingModes.size()];
|
||||
for (int i = 0; i < beekeepingModes.size(); i++) {
|
||||
@@ -232,34 +226,6 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
|
||||
secondPrincessChance = config.getFloatLocalized("beekeeping", "second.princess", secondPrincessChance, 0.0f, 100.0f);
|
||||
|
||||
String acceptedFlowerMessage = Translator.translateToLocal("for.config.beekeeping.flowers.accepted.comment");
|
||||
String plantableFlowerMessage = Translator.translateToLocal("for.config.beekeeping.flowers.plantable.comment");
|
||||
|
||||
FlowerRegistry flowerRegistry = (FlowerRegistry) FlowerManager.flowerRegistry;
|
||||
|
||||
for (String flowerType : flowerRegistry.getFlowerTypes()) {
|
||||
String[] defaultAccepted = defaultAcceptedFlowers.get(flowerType);
|
||||
if (defaultAccepted == null) {
|
||||
defaultAccepted = Constants.EMPTY_STRINGS;
|
||||
}
|
||||
Property property = config.get("beekeeping.flowers." + flowerType, "accepted", defaultAccepted);
|
||||
property.setComment(acceptedFlowerMessage);
|
||||
parseAcceptedFlowers(property.getStringList(), flowerType);
|
||||
|
||||
String[] defaultPlantable = defaultPlantableFlowers.get(flowerType);
|
||||
if (defaultPlantable == null) {
|
||||
defaultPlantable = Constants.EMPTY_STRINGS;
|
||||
}
|
||||
property = config.get("beekeeping.flowers." + flowerType, "plantable", defaultPlantable);
|
||||
property.setComment(plantableFlowerMessage);
|
||||
parsePlantableFlowers(property, flowerType);
|
||||
|
||||
Set<Flower> acceptableFlowers = flowerRegistry.getAcceptableFlowers(flowerType);
|
||||
if (acceptableFlowers == null || acceptableFlowers.isEmpty()) {
|
||||
Log.error("Flower type '" + flowerType + "' has no valid flowers set in apiculture.cfg. Add valid flowers or delete the config to set it to default.");
|
||||
}
|
||||
}
|
||||
|
||||
String[] blacklist = config.getStringListLocalized("species", "blacklist", Constants.EMPTY_STRINGS);
|
||||
parseBeeBlacklist(blacklist);
|
||||
|
||||
@@ -346,8 +312,7 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
registerDungeonLoot();
|
||||
}
|
||||
|
||||
private void setDefaultsForConfig() {
|
||||
|
||||
private void initFlowerRegistry() {
|
||||
FlowerRegistry flowerRegistry = (FlowerRegistry) FlowerManager.flowerRegistry;
|
||||
|
||||
flowerRegistry.registerAcceptableFlowerRule(new EndFlowerAcceptableRule(), FlowerManager.FlowerTypeEnd);
|
||||
@@ -361,53 +326,19 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
flowerRegistry.registerAcceptableFlower(Blocks.MELON_STEM, FlowerManager.FlowerTypeGourd);
|
||||
flowerRegistry.registerAcceptableFlower(Blocks.NETHER_WART, FlowerManager.FlowerTypeNether);
|
||||
flowerRegistry.registerAcceptableFlower(Blocks.CACTUS, FlowerManager.FlowerTypeCacti);
|
||||
|
||||
flowerRegistry.registerAcceptableFlower(Blocks.DOUBLE_PLANT, 0, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
flowerRegistry.registerAcceptableFlower(Blocks.DOUBLE_PLANT, 1, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
flowerRegistry.registerAcceptableFlower(Blocks.DOUBLE_PLANT, 4, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
flowerRegistry.registerAcceptableFlower(Blocks.DOUBLE_PLANT, 5, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
|
||||
|
||||
// Register plantable plants
|
||||
for (int meta = 0; meta <= 8; meta++) {
|
||||
flowerRegistry.registerPlantableFlower(Blocks.RED_FLOWER, meta, 1.0, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
BlockRedFlower blockRedFlower = (BlockRedFlower) Blocks.RED_FLOWER;
|
||||
IBlockState defaultState = blockRedFlower.getDefaultState();
|
||||
for (BlockFlower.EnumFlowerType flowerType : BlockFlower.EnumFlowerType.getTypes(BlockFlower.EnumFlowerColor.RED)) {
|
||||
IBlockState blockState = defaultState.withProperty(blockRedFlower.getTypeProperty(), flowerType);
|
||||
flowerRegistry.registerPlantableFlower(blockState, 1.0, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
}
|
||||
|
||||
flowerRegistry.registerPlantableFlower(Blocks.YELLOW_FLOWER, 0, 1.0, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
flowerRegistry.registerPlantableFlower(Blocks.BROWN_MUSHROOM, 0, 1.0, FlowerManager.FlowerTypeMushrooms);
|
||||
flowerRegistry.registerPlantableFlower(Blocks.RED_MUSHROOM, 0, 1.0, FlowerManager.FlowerTypeMushrooms);
|
||||
flowerRegistry.registerPlantableFlower(Blocks.CACTUS, 0, 1.0, FlowerManager.FlowerTypeCacti);
|
||||
|
||||
for (String flowerType : flowerRegistry.getFlowerTypes()) {
|
||||
Set<Flower> flowers = flowerRegistry.getAcceptableFlowers(flowerType);
|
||||
List<String> acceptedFlowerNames = new ArrayList<>();
|
||||
List<String> plantableFlowerNames = new ArrayList<>();
|
||||
if (flowers != null) {
|
||||
for (Flower flower : flowers) {
|
||||
String name = ItemStackUtil.getBlockNameFromRegistryAsSting(flower.getBlock());
|
||||
if (name == null) {
|
||||
Log.warning("Could not find name for flower: " + flower + " with type: " + flowerType);
|
||||
continue;
|
||||
}
|
||||
|
||||
int meta = flower.getMeta();
|
||||
if (flower.getMeta() != OreDictionary.WILDCARD_VALUE) {
|
||||
name = name + ':' + meta;
|
||||
}
|
||||
|
||||
if (flower.isPlantable()) {
|
||||
plantableFlowerNames.add(name);
|
||||
} else {
|
||||
acceptedFlowerNames.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String[] acceptedFlowerNamesArray = acceptedFlowerNames.toArray(new String[acceptedFlowerNames.size()]);
|
||||
defaultAcceptedFlowers.put(flowerType, acceptedFlowerNamesArray);
|
||||
|
||||
String[] plantableFlowerNamesArray = plantableFlowerNames.toArray(new String[plantableFlowerNames.size()]);
|
||||
defaultPlantableFlowers.put(flowerType, plantableFlowerNamesArray);
|
||||
}
|
||||
flowerRegistry.registerPlantableFlower(Blocks.YELLOW_FLOWER.getDefaultState(), 1.0, FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
flowerRegistry.registerPlantableFlower(Blocks.BROWN_MUSHROOM.getDefaultState(), 1.0, FlowerManager.FlowerTypeMushrooms);
|
||||
flowerRegistry.registerPlantableFlower(Blocks.RED_MUSHROOM.getDefaultState(), 1.0, FlowerManager.FlowerTypeMushrooms);
|
||||
flowerRegistry.registerPlantableFlower(Blocks.CACTUS.getDefaultState(), 1.0, FlowerManager.FlowerTypeCacti);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -866,36 +797,6 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseAcceptedFlowers(String[] acceptedFlowers, String flowerType) {
|
||||
List<Stack> acceptedFlowerItemStacks = Stack.parseStackStrings(acceptedFlowers, OreDictionary.WILDCARD_VALUE);
|
||||
for (Stack acceptedFlower : acceptedFlowerItemStacks) {
|
||||
Block acceptedFlowerBlock = acceptedFlower.getBlock();
|
||||
int meta = acceptedFlower.getMeta();
|
||||
if (acceptedFlowerBlock != null) {
|
||||
FlowerManager.flowerRegistry.registerAcceptableFlower(acceptedFlowerBlock, meta, flowerType);
|
||||
} else {
|
||||
Log.warning("No block found for '" + acceptedFlower + "' in apiculture config for '" + flowerType + "'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void parsePlantableFlowers(Property property, String flowerType) {
|
||||
for (String string : property.getStringList()) {
|
||||
Stack plantableFlower = Stack.parseStackString(string, OreDictionary.WILDCARD_VALUE);
|
||||
if (plantableFlower == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block plantableFlowerBlock = plantableFlower.getBlock();
|
||||
int meta = plantableFlower.getMeta();
|
||||
if (plantableFlowerBlock != null) {
|
||||
FlowerManager.flowerRegistry.registerPlantableFlower(plantableFlowerBlock, meta, 1.0, flowerType);
|
||||
} else {
|
||||
Log.warning("No block found for '" + string + "' in config '" + property.getName() + "'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISaveEventHandler getSaveEventHandler() {
|
||||
return new SaveEventHandlerApiculture();
|
||||
@@ -946,7 +847,7 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
|
||||
private static class EndFlowerAcceptableRule implements IFlowerAcceptableRule {
|
||||
@Override
|
||||
public boolean isAcceptableFlower(String flowerType, World world, BlockPos pos) {
|
||||
public boolean isAcceptableFlower(IBlockState blockState, World world, BlockPos pos, String flowerType) {
|
||||
Biome biomeGenForCoords = world.getBiome(pos);
|
||||
return BiomeDictionary.isBiomeOfType(biomeGenForCoords, BiomeDictionary.Type.END);
|
||||
}
|
||||
|
||||
@@ -12,19 +12,15 @@ package forestry.apiculture.flowers;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
||||
public final class Flower {
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
private final IBlockState blockState;
|
||||
private Double weight;
|
||||
|
||||
public Flower(Block block, int meta, double weight) {
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
public Flower(IBlockState blockState, double weight) {
|
||||
this.blockState = blockState;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
@@ -40,20 +36,16 @@ public final class Flower {
|
||||
|
||||
Flower flower = (Flower) obj;
|
||||
|
||||
return Block.isEqualTo(this.block, flower.getBlock()) && (this.meta == OreDictionary.WILDCARD_VALUE || flower.getMeta() == OreDictionary.WILDCARD_VALUE || this.meta == flower.getMeta());
|
||||
return this.blockState == flower.getBlockState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(block);
|
||||
return Objects.hashCode(blockState);
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public int getMeta() {
|
||||
return meta;
|
||||
public IBlockState getBlockState() {
|
||||
return blockState;
|
||||
}
|
||||
|
||||
public double getWeight() {
|
||||
@@ -66,7 +58,7 @@ public final class Flower {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).add("block", block).add("meta", meta).add("weight", weight).toString();
|
||||
return Objects.toStringHelper(this).add("blockState", blockState).add("weight", weight).toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,12 +13,9 @@ package forestry.apiculture.flowers;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -27,18 +24,12 @@ import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFlowerPot;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityFlowerPot;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.FlowerManager;
|
||||
import forestry.api.apiculture.IBee;
|
||||
@@ -50,7 +41,7 @@ import forestry.api.genetics.IFlowerGrowthHelper;
|
||||
import forestry.api.genetics.IFlowerGrowthRule;
|
||||
import forestry.api.genetics.IFlowerRegistry;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.VectUtil;
|
||||
|
||||
public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelper {
|
||||
@@ -67,17 +58,19 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
FlowerManager.FlowerTypeGourd
|
||||
);
|
||||
|
||||
private final HashMultimap<String, IFlowerAcceptableRule> registeredRules; // custom check
|
||||
private final HashMultimap<String, Block> registeredBlocks; // quick first check
|
||||
private final HashMultimap<String, Flower> registeredFlowers; // full check
|
||||
private final HashMultimap<String, IFlowerAcceptableRule> registeredRules;
|
||||
private final HashMultimap<String, Block> acceptableBlocks;
|
||||
private final HashMultimap<String, IBlockState> acceptableBlockStates;
|
||||
private final HashMultimap<String, Flower> plantableFlowers;
|
||||
|
||||
private final ArrayListMultimap<String, IFlowerGrowthRule> growthRules;
|
||||
private final Map<String, TreeMap<Double, Flower>> chances;
|
||||
|
||||
public FlowerRegistry() {
|
||||
this.registeredRules = HashMultimap.create();
|
||||
this.registeredBlocks = HashMultimap.create();
|
||||
this.registeredFlowers = HashMultimap.create();
|
||||
this.acceptableBlocks = HashMultimap.create();
|
||||
this.acceptableBlockStates = HashMultimap.create();
|
||||
this.plantableFlowers = HashMultimap.create();
|
||||
this.growthRules = ArrayListMultimap.create();
|
||||
this.chances = new HashMap<>();
|
||||
|
||||
@@ -86,28 +79,40 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
|
||||
@Override
|
||||
public void registerAcceptableFlower(Block block, String... flowerTypes) {
|
||||
registerFlower(block, OreDictionary.WILDCARD_VALUE, 0.0, flowerTypes);
|
||||
for (String flowerType : flowerTypes) {
|
||||
if (flowerType == null) {
|
||||
throw new NullPointerException("Tried to register flower with null type. " + block);
|
||||
}
|
||||
|
||||
this.acceptableBlocks.get(flowerType).add(block);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAcceptableFlower(Block block, int meta, String... flowerTypes) {
|
||||
registerFlower(block, meta, 0.0, flowerTypes);
|
||||
public void registerAcceptableFlower(IBlockState blockState, String... flowerTypes) {
|
||||
for (String flowerType : flowerTypes) {
|
||||
if (flowerType == null) {
|
||||
throw new NullPointerException("Tried to register flower with null type. " + blockState);
|
||||
}
|
||||
|
||||
this.acceptableBlockStates.get(flowerType).add(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAcceptableFlowerRule(IFlowerAcceptableRule acceptableFlower, String... flowerTypes) {
|
||||
for (String flowerType : flowerTypes) {
|
||||
if (flowerType == null) {
|
||||
throw new NullPointerException("Tried to register flower with null type. " + acceptableFlower);
|
||||
}
|
||||
|
||||
registeredRules.put(flowerType, acceptableFlower);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlantableFlower(Block block, int meta, double weight, String... flowerTypes) {
|
||||
registerFlower(block, meta, weight, flowerTypes);
|
||||
}
|
||||
|
||||
private void registerFlower(Block block, int meta, double weight, String... flowerTypes) {
|
||||
if (block == null) {
|
||||
public void registerPlantableFlower(IBlockState blockState, double weight, String... flowerTypes) {
|
||||
if (blockState == null) {
|
||||
return;
|
||||
}
|
||||
if (weight <= 0.0) {
|
||||
@@ -117,18 +122,22 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
weight = 1.0;
|
||||
}
|
||||
|
||||
Flower newFlower = new Flower(block, meta, weight);
|
||||
if (blockState.getBlock() == Blocks.AIR) {
|
||||
Log.error("Tried to register AIR as a flower. Bad idea.");
|
||||
}
|
||||
|
||||
Flower newFlower = new Flower(blockState, weight);
|
||||
|
||||
for (String flowerType : flowerTypes) {
|
||||
if (flowerType == null) {
|
||||
throw new NullPointerException("Tried to register flower with null type. " + block);
|
||||
throw new NullPointerException("Tried to register flower with null type. " + blockState);
|
||||
}
|
||||
|
||||
Set<Flower> flowers = this.registeredFlowers.get(flowerType);
|
||||
Set<Flower> flowers = this.plantableFlowers.get(flowerType);
|
||||
flowers.add(newFlower);
|
||||
|
||||
Set<Block> blocks = this.registeredBlocks.get(flowerType);
|
||||
blocks.add(block);
|
||||
Set<IBlockState> blocks = this.acceptableBlockStates.get(flowerType);
|
||||
blocks.add(blockState);
|
||||
|
||||
if (this.chances.containsKey(flowerType)) {
|
||||
this.chances.remove(flowerType);
|
||||
@@ -145,13 +154,9 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
@Override
|
||||
@Nonnull
|
||||
public List<BlockPos> getAcceptedFlowerCoordinates(IBeeHousing beeHousing, IBee bee, String flowerType, int maxFlowers) {
|
||||
if (!this.registeredFlowers.containsKey(flowerType)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Set<IFlowerAcceptableRule> acceptableRules = this.registeredRules.get(flowerType);
|
||||
Set<Block> acceptedBlocks = this.registeredBlocks.get(flowerType);
|
||||
Set<Flower> acceptedFlowers = this.registeredFlowers.get(flowerType);
|
||||
Set<IBlockState> acceptedBlockStates = this.acceptableBlockStates.get(flowerType);
|
||||
Set<Block> acceptedBlocks = this.acceptableBlocks.get(flowerType);
|
||||
World world = beeHousing.getWorldObj();
|
||||
|
||||
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(beeHousing);
|
||||
@@ -162,8 +167,13 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
|
||||
List<BlockPos> flowerCoords = new ArrayList<>();
|
||||
for (BlockPos.MutableBlockPos posBlock : BlockPos.getAllInBoxMutable(minPos, maxPos)) {
|
||||
IBlockState blockState = world.getBlockState(posBlock);
|
||||
if (blockState.getBlock().isAir(blockState, world, posBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (IFlowerAcceptableRule acceptableRule : acceptableRules) {
|
||||
if (acceptableRule.isAcceptableFlower(flowerType, world, posBlock)) {
|
||||
if (acceptableRule.isAcceptableFlower(blockState, world, posBlock, flowerType)) {
|
||||
flowerCoords.add(posBlock.toImmutable());
|
||||
if (flowerCoords.size() >= maxFlowers) {
|
||||
return flowerCoords;
|
||||
@@ -171,7 +181,7 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
}
|
||||
}
|
||||
|
||||
if (isAcceptedFlower(acceptedBlocks, acceptedFlowers, world, posBlock)) {
|
||||
if (isAcceptedFlower(blockState, acceptedBlocks, acceptedBlockStates)) {
|
||||
flowerCoords.add(posBlock.toImmutable());
|
||||
if (flowerCoords.size() >= maxFlowers) {
|
||||
return flowerCoords;
|
||||
@@ -184,44 +194,23 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedFlower(String flowerType, World world, BlockPos pos) {
|
||||
if (!this.registeredFlowers.containsKey(flowerType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Set<IFlowerAcceptableRule> acceptedCustom = this.registeredRules.get(flowerType);
|
||||
for (IFlowerAcceptableRule acceptableFlower : acceptedCustom) {
|
||||
if (acceptableFlower.isAcceptableFlower(flowerType, world, pos)) {
|
||||
if (acceptableFlower.isAcceptableFlower(blockState, world, pos, flowerType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Set<Block> acceptedBlocks = this.registeredBlocks.get(flowerType);
|
||||
Set<Flower> acceptedFlowers = this.registeredFlowers.get(flowerType);
|
||||
Set<IBlockState> acceptedBlockStates = this.acceptableBlockStates.get(flowerType);
|
||||
Set<Block> acceptedBlocks = this.acceptableBlocks.get(flowerType);
|
||||
|
||||
return isAcceptedFlower(acceptedBlocks, acceptedFlowers, world, pos);
|
||||
return isAcceptedFlower(blockState, acceptedBlocks, acceptedBlockStates);
|
||||
}
|
||||
|
||||
private static boolean isAcceptedFlower(Set<Block> acceptedBlocks, Set<Flower> acceptedFlowers, World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
private static boolean isAcceptedFlower(IBlockState blockState, Set<Block> acceptedBlocks, Set<IBlockState> acceptedBlockStates) {
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
final int meta;
|
||||
|
||||
if (block instanceof BlockFlowerPot) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
TileEntityFlowerPot tileFlowerPot = (TileEntityFlowerPot) tile;
|
||||
Item item = tileFlowerPot.getFlowerPotItem();
|
||||
block = Block.getBlockFromItem(item);
|
||||
meta = tileFlowerPot.getFlowerPotData();
|
||||
} else {
|
||||
if (!acceptedBlocks.contains(block)) {
|
||||
return false;
|
||||
}
|
||||
meta = block.getMetaFromState(blockState);
|
||||
}
|
||||
|
||||
Flower flower = new Flower(block, meta, 0);
|
||||
return acceptedFlowers.contains(flower);
|
||||
return acceptedBlocks.contains(block) || acceptedBlockStates.contains(blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -239,10 +228,6 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<Flower> getAcceptableFlowers(String flowerType) {
|
||||
return ImmutableSet.copyOf(this.registeredFlowers.get(flowerType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGrowthRule(IFlowerGrowthRule rule, String... flowerTypes) {
|
||||
if (rule == null) {
|
||||
@@ -260,15 +245,11 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
return chancesMap.get(chancesMap.lowerKey(rand.nextDouble() * maxKey));
|
||||
}
|
||||
|
||||
public Collection<String> getFlowerTypes() {
|
||||
return new ArrayList<>(Sets.union(defaultFlowerTypes, registeredFlowers.keySet()));
|
||||
}
|
||||
|
||||
private TreeMap<Double, Flower> getChancesMap(String flowerType) {
|
||||
if (!this.chances.containsKey(flowerType)) {
|
||||
TreeMap<Double, Flower> flowerChances = new TreeMap<>();
|
||||
double count = 0.0;
|
||||
for (Flower flower : this.registeredFlowers.get(flowerType)) {
|
||||
for (Flower flower : this.plantableFlowers.get(flowerType)) {
|
||||
if (flower.isPlantable()) {
|
||||
flowerChances.put(count, flower);
|
||||
count += flower.getWeight();
|
||||
@@ -282,8 +263,6 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
private void registerVanillaGrowthRules() {
|
||||
registerGrowthRule(new GrowthRuleDirtGrass(), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow);
|
||||
registerGrowthRule(new GrowthRuleSnow(), FlowerManager.FlowerTypeSnow);
|
||||
registerGrowthRule(new GrowthRuleFlowerPot(), FlowerManager.FlowerTypeVanilla, FlowerManager.FlowerTypeSnow, FlowerManager.FlowerTypeMushrooms, FlowerManager.FlowerTypeCacti,
|
||||
FlowerManager.FlowerTypeJungle);
|
||||
registerGrowthRule(new GrowthRuleMycelium(), FlowerManager.FlowerTypeMushrooms);
|
||||
registerGrowthRule(new GrowthRuleNone(), FlowerManager.FlowerTypeEnd);
|
||||
registerGrowthRule(new GrowthRuleFertilize(Blocks.MELON_STEM, Blocks.PUMPKIN_STEM), FlowerManager.FlowerTypeGourd);
|
||||
@@ -293,6 +272,6 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
@Override
|
||||
public boolean plantRandomFlower(String flowerType, World world, BlockPos pos) {
|
||||
Flower flower = getRandomPlantableFlower(flowerType, world.rand);
|
||||
return world.setBlockState(pos, flower.getBlock().getStateFromMeta(flower.getMeta()), Constants.FLAG_BLOCK_SYNC);
|
||||
return world.setBlockState(pos, flower.getBlockState());
|
||||
}
|
||||
}
|
||||
@@ -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.flowers;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFlowerPot;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityFlowerPot;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.apiculture.FlowerManager;
|
||||
import forestry.api.genetics.IFlowerGrowthHelper;
|
||||
import forestry.api.genetics.IFlowerGrowthRule;
|
||||
|
||||
public class GrowthRuleFlowerPot implements IFlowerGrowthRule {
|
||||
|
||||
@Override
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos) {
|
||||
return growFlower(flowerType, world, pos);
|
||||
}
|
||||
|
||||
private static boolean growFlower(String flowerType, World world, BlockPos pos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof TileEntityFlowerPot)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntityFlowerPot flowerPotTile = (TileEntityFlowerPot) tile;
|
||||
if (flowerPotTile.getFlowerPotItem() != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (!(block instanceof BlockFlowerPot)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockFlowerPot flowerPot = (BlockFlowerPot) block;
|
||||
|
||||
int flower;
|
||||
switch (flowerType) {
|
||||
case FlowerManager.FlowerTypeVanilla:
|
||||
case FlowerManager.FlowerTypeSnow:
|
||||
flower = world.rand.nextInt(2) + 1;
|
||||
break;
|
||||
case FlowerManager.FlowerTypeJungle:
|
||||
flower = 6;
|
||||
break;
|
||||
case FlowerManager.FlowerTypeCacti:
|
||||
flower = world.rand.nextInt(2) + 9;
|
||||
break;
|
||||
case FlowerManager.FlowerTypeMushrooms:
|
||||
flower = world.rand.nextInt(2) + 7;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntityFlowerPot newTile = (TileEntityFlowerPot) flowerPot.createNewTileEntity(world, flower);
|
||||
|
||||
flowerPotTile.setFlowerPotData(newTile.getFlowerPotItem(), newTile.getFlowerPotData());
|
||||
flowerPotTile.markDirty();
|
||||
|
||||
if (!world.setBlockState(pos, world.getBlockState(pos).getBlock().getStateFromMeta(1), 2)) {
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -314,7 +314,7 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 {
|
||||
|
||||
FlowerRegistry flowerRegistry = (FlowerRegistry) FlowerManager.flowerRegistry;
|
||||
Flower flower = flowerRegistry.getRandomPlantableFlower(FlowerManager.FlowerTypeVanilla, world.rand);
|
||||
setBlockState(world, flower.getBlock().getStateFromMeta(flower.getMeta()), j, i, k, box);
|
||||
setBlockState(world, flower.getBlockState(), j, i, k, box);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user