Skip to content

Commit

Permalink
Add proper config + reimplement hints
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkcolour committed Aug 11, 2024
1 parent d48168f commit 6e7aa4c
Show file tree
Hide file tree
Showing 55 changed files with 372 additions and 558 deletions.
8 changes: 7 additions & 1 deletion src/main/java/forestry/Forestry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

import net.minecraftforge.common.MinecraftForge;

import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;

import forestry.api.ForestryConstants;
import forestry.api.IForestryApi;
import forestry.apiimpl.plugin.PluginManager;
import forestry.core.EventHandlerCore;
import forestry.core.config.ForestryConfig;
import forestry.core.network.NetworkHandler;
import forestry.modules.ForestryModuleManager;
import forestry.apiimpl.plugin.PluginManager;

/**
* Forestry Minecraft Mod
Expand All @@ -32,6 +35,7 @@
*/
@Mod(ForestryConstants.MOD_ID)
public class Forestry {
public static final boolean DEBUG = ModList.get().isLoaded("modkit");
public static final Logger LOGGER = LogManager.getLogger(ForestryConstants.MOD_ID);

public Forestry() {
Expand All @@ -42,5 +46,7 @@ public Forestry() {

PluginManager.loadPlugins();
PluginManager.registerErrors();

ForestryConfig.register(ModLoadingContext.get());
}
}
28 changes: 0 additions & 28 deletions src/main/java/forestry/api/core/IForestryConstants.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/forestry/apiculture/genetics/Bee.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
import forestry.api.genetics.alleles.AllelePair;
import forestry.api.genetics.alleles.BeeChromosomes;
import forestry.api.genetics.alleles.IIntegerChromosome;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.config.ForestryConfig;
import forestry.core.genetics.IndividualLiving;
import forestry.core.genetics.mutations.Mutation;
import forestry.core.utils.GeneticsUtil;
Expand Down Expand Up @@ -529,7 +529,7 @@ public boolean pollinateRandom(IBeeHousing housing, IIndividual pollen) {
continue;
}

IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwner(), level, posBlock, Config.pollinateVanillaTrees);
IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwner(), level, posBlock, ForestryConfig.SERVER.pollinateVanillaLeaves.get());

if (realPollinatable != null) {
realPollinatable.mateWith(pollen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import forestry.api.genetics.alleles.BeeChromosomes;
import forestry.api.genetics.alleles.IIntegerAllele;
import forestry.api.genetics.alleles.IValueAllele;
import forestry.core.config.Config;
import forestry.core.gui.GuiAlyzer;
import forestry.core.gui.GuiForestry;
import forestry.core.gui.TextLayoutHelper;
import forestry.core.gui.widgets.ItemStackWidget;
import forestry.core.gui.widgets.WidgetManager;
Expand Down Expand Up @@ -244,7 +244,7 @@ public Map<ISpecies<?>, ItemStack> getIconStacks() {

@Override
public List<String> getHints() {
return Config.hints.get("beealyzer");
return GuiForestry.HINTS.get("beealyzer");
}

}
4 changes: 2 additions & 2 deletions src/main/java/forestry/apiculture/genetics/BeePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import forestry.api.genetics.gatgets.DatabaseMode;
import forestry.apiculture.features.ApicultureItems;
import forestry.apiculture.items.EnumHoneyComb;
import forestry.core.config.Config;
import forestry.core.genetics.analyzer.DatabasePlugin;
import forestry.core.genetics.analyzer.MutationsTab;
import forestry.core.genetics.analyzer.ProductsTab;
import forestry.core.gui.GuiForestry;
import forestry.core.utils.GeneticsUtil;
import forestry.core.utils.SpeciesUtil;

Expand All @@ -39,6 +39,6 @@ public Map<ISpecies<?>, ItemStack> getIndividualStacks() {

@Override
public List<String> getHints() {
return Config.hints.get("beealyzer");
return GuiForestry.HINTS.get("beealyzer");
}
}
16 changes: 5 additions & 11 deletions src/main/java/forestry/apiculture/hives/HiveDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;

import forestry.Forestry;
import forestry.api.IForestryApi;
import forestry.api.apiculture.hives.IHive;
import forestry.api.core.HumidityType;
import forestry.api.core.TemperatureType;
import forestry.core.config.Config;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;

public class HiveDecorator extends Feature<NoneFeatureConfiguration> {
// todo make configurable
public static final float generateBeehivesAmount = 1.0f;

public HiveDecorator() {
super(NoneFeatureConfiguration.CODEC);
}
Expand Down Expand Up @@ -76,14 +77,7 @@ private static boolean setHive(WorldGenLevel world, RandomSource rand, BlockPos

hiveBlock.onPlace(state, world.getLevel(), pos, hiveState, false);

if (!Config.generateBeehivesDebug) {
hive.postGen(world, rand, pos);
}

if (Config.logHivePlacement) {
//getCoordinatesAsString
Forestry.LOGGER.info("Placed {} at {}", hive, pos.toShortString());
}
hive.postGen(world, rand, pos);

return true;
}
Expand All @@ -104,7 +98,7 @@ public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
HumidityType humidity = IForestryApi.INSTANCE.getClimateManager().getHumidity(biome);

for (IHive hive : hives) {
if (hive.genChance() * Config.generateBeehivesAmount * hives.size() / 8 >= rand.nextFloat() * 0.5f) {
if (hive.genChance() * generateBeehivesAmount * hives.size() / 8 >= rand.nextFloat() * 0.5f) {
if (hive.isGoodBiome(biome) && hive.isGoodHumidity(humidity)) {
int x = pos.getX() + rand.nextInt(16);
int z = pos.getZ() + rand.nextInt(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import forestry.core.items.definitions.EnumCraftingMaterial;

public class ItemArmorApiarist extends ArmorItem {
public static final String TEXTURE_APIARIST_ARMOR_PRIMARY = ForestryConstants.MOD_ID + ":" + Constants.TEXTURE_PATH_ITEM + "/apiarist_armor_1.png";
public static final String TEXTURE_APIARIST_ARMOR_SECONDARY = ForestryConstants.MOD_ID + ":" + Constants.TEXTURE_PATH_ITEM + "/apiarist_armor_2.png";

public static final class ApiaristArmorMaterial implements ArmorMaterial {

private static final int[] reductions = new int[]{1, 2, 3, 1};

@Override
Expand All @@ -55,7 +56,7 @@ public SoundEvent getEquipSound() {

@Override
public Ingredient getRepairIngredient() {
return Ingredient.of(CoreItems.CRAFTING_MATERIALS.stack(EnumCraftingMaterial.WOVEN_SILK, 1));
return Ingredient.of(CoreItems.CRAFTING_MATERIALS.get(EnumCraftingMaterial.WOVEN_SILK).get());
}

@Override
Expand All @@ -81,9 +82,9 @@ public ItemArmorApiarist(EquipmentSlot equipmentSlotIn) {
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
if (ApicultureItems.APIARIST_LEGS.itemEqual(stack)) {
return ForestryConstants.MOD_ID + ":" + Constants.TEXTURE_APIARIST_ARMOR_SECONDARY;
return TEXTURE_APIARIST_ARMOR_SECONDARY;
} else {
return ForestryConstants.MOD_ID + ":" + Constants.TEXTURE_APIARIST_ARMOR_PRIMARY;
return TEXTURE_APIARIST_ARMOR_PRIMARY;
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/forestry/apiculture/tiles/TileHive.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import forestry.apiculture.WorldgenBeekeepingLogic;
import forestry.apiculture.blocks.BlockBeeHive;
import forestry.apiculture.features.ApicultureTiles;
import forestry.core.config.Config;
import forestry.core.inventory.InventoryAdapter;
import forestry.core.network.packets.PacketActiveUpdate;
import forestry.core.tiles.IActivatable;
Expand Down Expand Up @@ -96,7 +95,7 @@ public TileHive(BlockPos pos, BlockState state) {
}

public void tick() {
if (Config.generateBeehivesDebug) {
if (false) {
return;
}
tickHelper.onTick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import forestry.api.arboriculture.ICharcoalManager;
import forestry.api.arboriculture.ICharcoalPileWall;
import forestry.api.arboriculture.TreeManager;
import forestry.arboriculture.charcoal.CharcoalManager;
import forestry.arboriculture.features.CharcoalBlocks;
import forestry.core.config.Config;

// TODO: Fix propagation, aging
public class BlockWoodPile extends Block {
Expand Down Expand Up @@ -108,7 +108,7 @@ public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource
if (state.getValue(AGE) < 7) {
world.setBlock(pos, state.setValue(AGE, state.getValue(AGE) + 1), Block.UPDATE_CLIENTS);
} else {
BlockState ashState = CharcoalBlocks.ASH.setValue(BlockAsh.AMOUNT, Math.min(Math.round(Config.charcoalAmountBase + getCharcoalAmount(world, pos)), 63));
BlockState ashState = CharcoalBlocks.ASH.setValue(BlockAsh.AMOUNT, Math.min(Math.round(CharcoalManager.charcoalAmountBase + getCharcoalAmount(world, pos)), 63));
world.setBlock(pos, ashState, Block.UPDATE_CLIENTS);
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ private float getCharcoalAmount(Level world, BlockPos pos) {
for (Direction facing : Direction.VALUES) {
charcoalAmount += getCharcoalFaceAmount(world, pos, facing);
}
return Mth.clamp(charcoalAmount / 6, Config.charcoalAmountBase, 63.0F - Config.charcoalAmountBase);
return Mth.clamp(charcoalAmount / 6, CharcoalManager.charcoalAmountBase, 63.0F - CharcoalManager.charcoalAmountBase);
}

private int getCharcoalFaceAmount(Level world, BlockPos pos, Direction facing) {
Expand All @@ -174,7 +174,7 @@ private int getCharcoalFaceAmount(Level world, BlockPos pos, Direction facing) {
BlockPos.MutableBlockPos testPos = pos.mutable();
testPos.move(facing);
int i = 0;
while (i < Config.charcoalWallCheckRange && world.hasChunkAt(testPos) && !world.isEmptyBlock(testPos)) {
while (i < CharcoalManager.charcoalWallCheckRange && world.hasChunkAt(testPos) && !world.isEmptyBlock(testPos)) {
BlockState state = world.getBlockState(testPos);
ICharcoalPileWall wall = charcoalManager.getWall(state);
if (wall != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;

import forestry.api.arboriculture.ICharcoalManager;
import forestry.api.arboriculture.ICharcoalPileWall;
import forestry.core.config.Config;

public class CharcoalManager implements ICharcoalManager {
// Charcoal
public static final int charcoalAmountBase = 8;
public static final int charcoalWallCheckRange = 16;
private final List<ICharcoalPileWall> walls = new ArrayList<>();

@Override
public void registerWall(Block block, int amount) {
Preconditions.checkNotNull(block, "block must not be null.");
Preconditions.checkArgument(amount > (-Config.charcoalAmountBase) && amount < (63 - Config.charcoalAmountBase), "amount must be bigger than -10 and smaller than 64.");
Preconditions.checkArgument(amount > (-charcoalAmountBase) && amount < (63 - charcoalAmountBase), "amount must be bigger than -10 and smaller than 64.");
walls.add(new CharcoalPileWall(block, amount));
}

@Override
public void registerWall(BlockState blockState, int amount) {
Preconditions.checkNotNull(blockState, "block state must not be null.");
Preconditions.checkArgument(amount > (-Config.charcoalAmountBase) && amount < (63 - Config.charcoalAmountBase), "amount must be bigger than -10 and smaller than 64.");
Preconditions.checkArgument(amount > (-charcoalAmountBase) && amount < (63 - charcoalAmountBase), "amount must be bigger than -10 and smaller than 64.");
walls.add(new CharcoalPileWall(blockState, amount));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import forestry.api.genetics.ISpecies;
import forestry.api.genetics.alleles.TreeChromosomes;
import forestry.api.genetics.capability.IIndividualHandlerItem;
import forestry.core.config.Config;
import forestry.core.gui.GuiAlyzer;
import forestry.core.gui.GuiForestry;
import forestry.core.gui.TextLayoutHelper;
import forestry.core.gui.widgets.ItemStackWidget;
import forestry.core.gui.widgets.WidgetManager;
Expand Down Expand Up @@ -248,7 +248,7 @@ public Map<ISpecies<?>, ItemStack> getIconStacks() {

@Override
public List<String> getHints() {
return Config.hints.get("treealyzer");
return GuiForestry.HINTS.get("treealyzer");
}

}
4 changes: 2 additions & 2 deletions src/main/java/forestry/arboriculture/genetics/TreePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import forestry.api.genetics.ISpecies;
import forestry.api.genetics.gatgets.DatabaseMode;
import forestry.arboriculture.features.ArboricultureItems;
import forestry.core.config.Config;
import forestry.core.features.CoreItems;
import forestry.core.genetics.analyzer.DatabasePlugin;
import forestry.core.genetics.analyzer.MutationsTab;
import forestry.core.genetics.analyzer.ProductsTab;
import forestry.core.gui.GuiForestry;
import forestry.core.items.ItemFruit;
import forestry.core.utils.GeneticsUtil;
import forestry.core.utils.SpeciesUtil;
Expand All @@ -39,6 +39,6 @@ public Map<ISpecies<?>, ItemStack> getIndividualStacks() {

@Override
public List<String> getHints() {
return Config.hints.get("treealyzer");
return GuiForestry.HINTS.get("treealyzer");
}
}
9 changes: 4 additions & 5 deletions src/main/java/forestry/core/blocks/BlockHumus.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.PlantType;

import forestry.core.config.Config;

public class BlockHumus extends Block {
private static final int degradeDelimiter = Config.humusDegradeDelimiter;
public static final IntegerProperty DEGRADE = IntegerProperty.create("degrade", 0, degradeDelimiter); // degradation level of humus
private static final int DEGRADE_STEPS = 3;

public static final IntegerProperty DEGRADE = IntegerProperty.create("degrade", 0, DEGRADE_STEPS);

public BlockHumus() {
super(Block.Properties.of(Material.DIRT)
Expand Down Expand Up @@ -78,7 +77,7 @@ private static void degradeSoil(Level world, final BlockPos pos) {
int degrade = blockState.getValue(DEGRADE);
degrade++;

if (degrade >= degradeDelimiter) {
if (degrade >= DEGRADE_STEPS) {
world.setBlock(pos, Blocks.SAND.defaultBlockState(), UPDATE_CLIENTS);
} else {
world.setBlock(pos, blockState.setValue(DEGRADE, degrade), UPDATE_CLIENTS);
Expand Down
Loading

0 comments on commit 6e7aa4c

Please sign in to comment.