Skip to content
Permalink
Browse files

Committing stuff so I can pull in changes.

  • Loading branch information...
Bunsan committed Nov 18, 2018
1 parent 11b619e commit c48871e1f71da1670baa537c1b87caba6a5b61aa
@@ -0,0 +1,120 @@
/*
* * Work under Copyright. Licensed under the EUPL.
* * See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.api.types;

import javax.annotation.Nonnull;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.IForgeRegistryEntry;

public class Crop extends IForgeRegistryEntry.Impl<Crop>
{

private final float minTemp;
private final float maxTemp;
private final float minGrowthTemp;
private final float maxGrowthTemp;
private final float minRain;
private final float maxRain;
private final int growthStages;
private final float minStageGrowthTime;
private final float minDensity;
private final float maxDensity;


/**
* This is a registry object that will create a number of things:
* 1. Crop blocks and seedbags
* 2. A crop object to be used in TFC world gen
*
* Addon mods that want to add crops should subscribe to the registry event for this class
* They also must put (in their mod) the required resources in /assets/tfc/...
*
*
* @param name the ResourceLocation registry name of this tree
* @param minTemp min temperature that crop will stay planted
* @param maxTemp max temperature that crop will stay planted
* @param minGrowthTemp min temperature crop will grow
* @param maxGrowthTemp max temperature crop will grow
* @param minRain min rainfall
* @param maxRain max rainfall
* @param growthStages the number of growth stages for crop
* @param minStageGrowthTime the amount of time (in in-game days) that this crop requires to grow one stage
* @param minDensity min density. Use -1 to get all density values. 0.1 is the default, to create really low density regions of no crops
* @param maxDensity max density. Use 2 to get all density values
*/

public Crop(@Nonnull ResourceLocation name, float minTemp, float maxTemp, float minGrowthTemp, float maxGrowthTemp, float minRain, float maxRain, float minDensity, float maxDensity, int growthStages, float minStageGrowthTime)
{
this.minTemp = minTemp;
this.maxTemp = maxTemp;
this.minGrowthTemp = minGrowthTemp;
this.maxGrowthTemp = maxGrowthTemp;
this.minRain = minRain;
this.maxRain = maxRain;
this.growthStages = growthStages;
this.minStageGrowthTime = minStageGrowthTime;
this.minDensity = minDensity;
this.maxDensity = maxDensity;


setRegistryName(name);
}

public boolean isValidLocation(float temp, float rain, float density)
{
return minGrowthTemp <= temp && maxGrowthTemp >= temp && minRain <= rain && maxRain >= rain && minDensity <= density && maxDensity >= density;
}

@Override
public String toString() { return String.valueOf(getRegistryName()); }

public static class Builder
{
private float minTemp;
private float maxTemp;
private float minGrowthTemp;
private float maxGrowthTemp;
private float minRain;
private float maxRain;
private int growthStages;
private float minStageGrowthTime;
private float minDensity;
private float maxDensity;

private ResourceLocation name;

public Builder(@Nonnull ResourceLocation name, float minTemp, float maxTemp, float minGrowthTemp, float maxGrowthTemp, float minRain, float maxRain, int growthStages, float minStageGrowthTime)
{
this.name = name;
this.minTemp = minTemp; // required values
this.maxTemp = maxTemp;
this.minRain = minRain;
this.minGrowthTemp = minGrowthTemp;
this.maxGrowthTemp = maxGrowthTemp;
this.maxRain = maxRain;
this.growthStages = growthStages;
this.minStageGrowthTime = minStageGrowthTime;
this.minDensity = 0.1f; // default values
this.maxDensity = 2f;

}

public Builder setDensity(float min, float max)
{
this.minDensity = min;
this.maxDensity = max;
return this;
}

public Crop build()
{
return new Crop(name, minTemp, maxTemp, minGrowthTemp, maxGrowthTemp, minRain, maxRain, minDensity, maxDensity, growthStages, minStageGrowthTime);
}

}
}
@@ -1,7 +1,6 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
* * Work under Copyright. Licensed under the EUPL.
* * See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.api.types;
@@ -33,11 +32,13 @@
private static final ResourceLocation ROCK = new ResourceLocation(MOD_ID, "rock");
private static final ResourceLocation ORE = new ResourceLocation(MOD_ID, "ore");
private static final ResourceLocation TREE = new ResourceLocation(MOD_ID, "tree");
private static final ResourceLocation CROP = new ResourceLocation(MOD_ID, "crop");
private static final Map<ResourceLocation, IForgeRegistry<?>> preBlockRegistries = new HashMap<>();
private static IForgeRegistry<RockCategory> rockCategoryRegistry;
private static IForgeRegistry<Rock> rockRegistry;
private static IForgeRegistry<Ore> oreRegistry;
private static IForgeRegistry<Tree> treeRegistry;
private static IForgeRegistry<Crop> cropRegistry;

@SubscribeEvent
public static void onNewRegistryEvent(RegistryEvent.NewRegistry event)
@@ -46,6 +47,7 @@ public static void onNewRegistryEvent(RegistryEvent.NewRegistry event)
rockRegistry = newRegistry(ROCK, Rock.class, true);
oreRegistry = newRegistry(ORE, Ore.class, true);
treeRegistry = newRegistry(TREE, Tree.class, true);
cropRegistry = newRegistry(CROP, Crop.class, true);
}

/**
@@ -72,6 +74,8 @@ public static void onRegisterBlock(RegistryEvent.Register<Block> event)
return treeRegistry;
}

static IForgeRegistry<Crop> getCrops() {return cropRegistry; }

static IForgeRegistry<RockCategory> getRockCategories()
{
return rockCategoryRegistry;
@@ -0,0 +1,55 @@
/*
* * Work under Copyright. Licensed under the EUPL.
* * See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.types;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import net.dries007.tfc.ConfigTFC;
import net.dries007.tfc.api.types.Crop;
import net.dries007.tfc.api.types.TFCRegistries;
import net.dries007.tfc.api.types.Tree;
import net.dries007.tfc.world.classic.CalenderTFC;

import static net.dries007.tfc.Constants.MOD_ID;

public class DefaultCrops
{
/**
* Default tree ResourceLocations
*/
public static final ResourceLocation BARLEY = new ResourceLocation(MOD_ID, "barley");
public static final ResourceLocation OAT = new ResourceLocation(MOD_ID, "oat");
public static final ResourceLocation RICE = new ResourceLocation(MOD_ID, "rice");
public static final ResourceLocation RYE = new ResourceLocation(MOD_ID, "rye");
public static final ResourceLocation WHEAT = new ResourceLocation(MOD_ID, "wheat");
public static final ResourceLocation BEET = new ResourceLocation(MOD_ID, "beet");

public static final ResourceLocation CABBAGE = new ResourceLocation(MOD_ID, "cabbage");
public static final ResourceLocation CARROT = new ResourceLocation(MOD_ID, "carrot");
public static final ResourceLocation GARLIC = new ResourceLocation(MOD_ID, "garlic");
public static final ResourceLocation GREENBEAN = new ResourceLocation(MOD_ID, "greenbean");
public static final ResourceLocation MAIZE = new ResourceLocation(MOD_ID, "maize");
public static final ResourceLocation ONION = new ResourceLocation(MOD_ID, "onion");
public static final ResourceLocation POTATO = new ResourceLocation(MOD_ID, "onion");
public static final ResourceLocation SOYBEAN = new ResourceLocation(MOD_ID, "soybean");
public static final ResourceLocation SQUASH = new ResourceLocation(MOD_ID, "squash");
public static final ResourceLocation SUGARCANE = new ResourceLocation(MOD_ID, "sugarcane");
public static final ResourceLocation REDBELLPEPPER = new ResourceLocation(MOD_ID, "redbellpepper");
public static final ResourceLocation TOMATO = new ResourceLocation(MOD_ID, "tomato");
public static final ResourceLocation YELLOWBELLPEPPER = new ResourceLocation(MOD_ID, "yellowbellpepper");
public static final ResourceLocation JUTE = new ResourceLocation(MOD_ID, "jute");

@SubscribeEvent
public static void onPreRegisterRockCategory(TFCRegistries.RegisterPreBlock<Crop> event)
{
event.getRegistry().registerAll(
new Crop.Builder(BARLEY, 0f, 40f, 4f, 35f, 20, 210, (ConfigTFC.GENERAL.monthLength / 2), 8).setDensity(0.1f, 0.6f).build(),
new Crop.Builder(BEET, 0f, 40f, 4f, 35f, 20, 210, (ConfigTFC.GENERAL.monthLength / 2), 8).setDensity(0.1f, 0.6f).build(),
);
}
}
@@ -1,6 +1,6 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
* * Work under Copyright. Licensed under the EUPL.
* * See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.world.classic;
@@ -90,8 +90,8 @@ public static Month getMonthOfYear()

public static void reload()
{
daysInYear = ConfigTFC.GENERAL.monthLength;
daysInMonth = daysInYear / 12;
daysInYear = daysInMonth * 12;
daysInMonth = ConfigTFC.GENERAL.monthLength;
ticksInMonth = daysInMonth * TICKS_IN_DAY;
ticksInYear = daysInYear * TICKS_IN_DAY;
startTime = ticksInMonth * 3;

0 comments on commit c48871e

Please sign in to comment.
You can’t perform that action at this time.