Skip to content

Commit

Permalink
Smooth crop growth: reimplemented sugarcane and cactus seeds
Browse files Browse the repository at this point in the history
It looks really good when sugar cane growed on sugar cane, so now cactus/sugar cane grows into cactus/sugar cane seeds to make the growth smoother. Doubles as a way to bring back the seeds that fits in the mod
Changed cactus seed models to better fit this feature
  • Loading branch information
KnightMiner committed Dec 27, 2019
1 parent 8988d58 commit 2978dd5
Show file tree
Hide file tree
Showing 23 changed files with 406 additions and 357 deletions.
59 changes: 46 additions & 13 deletions src/main/java/knightminer/inspirations/common/Config.java
Expand Up @@ -217,7 +217,14 @@ public static boolean brewHeartbeet() {
public static IntValue heartbeetChance;

// seeds
public static BooleanValue enableMoreSeeds;
public static BooleanValue enableBlockCrops;
private static BooleanValue smoothBlockCropGrowth;
public static BooleanValue bonemealBlockCrop;
public static boolean smoothBlockCropGrowth() {
return enableBlockCrops.get() && smoothBlockCropGrowth.get();
}
public static BooleanValue nerfCactusFarms;
// public static BooleanValue enableMoreSeeds;
// private static BooleanValue addGrassDrops;
// private static BooleanValue nerfCarrotPotatoDrops;
// public static boolean addGrassDrops() {
Expand Down Expand Up @@ -651,18 +658,44 @@ private static void configure(Builder builder, Builder builder_override) {
.define("unstackableRecipeAlts", true);

// seeds
/*
enableMoreSeeds = builder
.comment("Adds seeds for additional vanilla plants, including cactus, sugar cane, carrots, and potatoes.")
.worldRestart()
.define("moreSeeds.enable", true);
addGrassDrops = builder
.comment("Makes carrot and potato seeds drop from grass")
.define("moreSeeds.grassDrops", true);
nerfCarrotPotatoDrops = builder
.comment("Makes carrots and potatoes drop their respective seed if not fully grown")
.define("moreSeeds.nerfCarrotPotatoDrops", true);
*/
builder.push("seeds");
{
builder.push("blockCrops");
{
enableBlockCrops = builder
.comment("If true, adds seeds for cactus and sugar cane, useful for recipes for the crops")
.worldRestart()
.define("enable", true);
smoothBlockCropGrowth = builder
.comment("If true, cactus and sugar cane will grow in 2 pixel increments using the block crops")
.define("smoothGrowth", true);
bonemealBlockCrop = builder
.comment("If true, allows bonemeal to be used to speed block crop growth")
.define("bonemeal", false);
nerfCactusFarms = builder
.comment("If false, cactus seeds planted on cactus have fewer restrictions.",
"Setting to true means cactus seeds are broken by neighboring blocks, meaning classic cactus farms will drop cactus seeds instead of full cactus.")
.define("nerfCactusFarms", false);
}
builder.pop();
/*
builder.push("veggies");
{
enableMoreSeeds = builder
.comment("Adds seeds for carrots and potatoes.")
.worldRestart()
.define("enable", true);
addGrassDrops = builder
.comment("Makes carrot and potato seeds drop from grass")
.define("grassDrops", true);
nerfCarrotPotatoDrops = builder
.comment("Makes carrots and potatoes drop their respective seed if not fully grown")
.define("nerfCarrotPotatoDrops", true);
}
builder.pop();
*/
}
builder.pop();

// milk cooldown
milkCooldown = builder
Expand Down
Expand Up @@ -3,12 +3,16 @@
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.PulseBase;
import knightminer.inspirations.common.item.HidableItem;
import knightminer.inspirations.tweaks.block.BlockCropBlock;
import knightminer.inspirations.tweaks.block.CactusCropBlock;
import knightminer.inspirations.tweaks.block.FittedCarpetBlock;
import knightminer.inspirations.tweaks.block.FlatCarpetBlock;
import knightminer.inspirations.tweaks.block.SugarCaneCropBlock;
import knightminer.inspirations.tweaks.item.SeedItem;
import knightminer.inspirations.tweaks.recipe.NormalBrewingRecipe;
import knightminer.inspirations.tweaks.util.SmoothGrowthListener;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.CropsBlock;
import net.minecraft.block.DispenserBlock;
import net.minecraft.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.dispenser.IDispenseItemBehavior;
Expand Down Expand Up @@ -46,12 +50,12 @@ public class InspirationsTweaks extends PulseBase {
// blocks
public static FittedCarpetBlock[] fitCarpets = new FittedCarpetBlock[16];
public static FlatCarpetBlock[] flatCarpets = new FlatCarpetBlock[16];
public static CropsBlock cactusCrop;
public static CropsBlock sugarCaneCrop;
public static BlockCropBlock cactus;
public static BlockCropBlock sugarCane;

// items
public static Item potatoSeeds;
public static Item carrotSeeds;
//public static Item potatoSeeds;
//public static Item carrotSeeds;
public static Item sugarCaneSeeds;
public static Item cactusSeeds;
//public static Item silverfishPowder;
Expand Down Expand Up @@ -81,8 +85,8 @@ public void registerBlocks(Register<Block> event) {
registerCarpet(r, DyeColor.BLACK, Blocks.BLACK_CARPET);
}

//cactusCrop = register(r, new CactusCropBlock(), "cactus_crop");
//sugarCaneCrop = register(r, new BlockSugarCaneCrop(), "sugar_cane_crop");
cactus = register(r, new CactusCropBlock(), "cactus");
sugarCane = register(r, new SugarCaneCropBlock(), "sugar_cane");
}

private void registerCarpet(IForgeRegistry<Block> r, DyeColor color, Block origCarpet) {
Expand All @@ -107,17 +111,11 @@ public void registerItem(Register<Item> event) {
}
}

/*
cactusSeeds = registerItem(r, new HidableBlockItem(
InspirationsTweaks.cactusCrop,
new Item.Properties().group(ItemGroup.FOOD)
), "cactus_seeds");
sugarCaneSeeds = registerItem(r, new HidableBlockItem(
InspirationsTweaks.sugarCaneCrop,
new Item.Properties().group(ItemGroup.FOOD)
), "sugar_cane_seeds");
Item.Properties props = new Item.Properties().group(ItemGroup.FOOD);
cactusSeeds = registerItem(r, new SeedItem(cactus, props), "cactus_seeds");
sugarCaneSeeds = registerItem(r, new SeedItem(sugarCane, props), "sugar_cane_seeds");

/*
carrotSeeds = registerItem(r, new SeedItem((CropsBlock) Blocks.CARROTS, PlantType.Crop), "carrot_seeds");
potatoSeeds = registerItem(r, new SeedItem((CropsBlock) Blocks.POTATOES, PlantType.Crop), "potato_seeds");
*/
Expand Down Expand Up @@ -154,6 +152,8 @@ public void setup(FMLCommonSetupEvent event) {
registerDispenserBehavior();

MinecraftForge.EVENT_BUS.register(TweaksEvents.class);
MinecraftForge.EVENT_BUS.addListener(new SmoothGrowthListener(Blocks.CACTUS, cactus, false));
MinecraftForge.EVENT_BUS.addListener(new SmoothGrowthListener(Blocks.SUGAR_CANE, sugarCane, true));
}

@SubscribeEvent
Expand Down
Expand Up @@ -93,7 +93,7 @@ public void registerBlockColors(ColorHandlerEvent.Block event) {
return -1;
}
return BiomeColors.getGrassColor(world, pos);
}, InspirationsTweaks.sugarCaneCrop);
}, InspirationsTweaks.sugarCane);

// portal tinting
registerBlockColors(colors, PortalColorHandler.INSTANCE, Blocks.NETHER_PORTAL);
Expand Down
Expand Up @@ -7,42 +7,32 @@
import net.minecraft.block.CropsBlock;
import net.minecraft.state.IntegerProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.Direction;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.PlantType;
import net.minecraftforge.registries.IRegistryDelegate;

import javax.annotation.Nonnull;
import java.util.Random;
import java.util.function.Supplier;

public abstract class BlockCropBlock extends CropsBlock implements IHidable, IPlantable {
protected IRegistryDelegate<Block> block;
protected PlantType type;
protected final VoxelShape[] shape;

public static final IntegerProperty SMALL_AGE = IntegerProperty.create("age", 0, 6);

public BlockCropBlock(Block block, PlantType type, VoxelShape[] shape, Block.Properties props) {
protected Supplier<Block> block;
protected PlantType type;

public BlockCropBlock(Supplier<Block> block, PlantType type, Properties props) {
super(props);
this.block = block.delegate;
this.shape = shape;
this.block = block;
this.type = type;
}

@Override
public boolean isEnabled() {
return Config.enableMoreSeeds.get();
}

@Deprecated
@Override
public boolean isValidPosition(@Nonnull BlockState state, IWorldReader world, BlockPos pos) {
BlockState soil = world.getBlockState(pos.down());
return soil.canSustainPlant(world, pos, Direction.UP, this);
public BlockCropBlock(Block block, PlantType type) {
this(block.delegate, type, Properties.from(block));
}

/* Age logic */
Expand Down Expand Up @@ -74,27 +64,38 @@ public boolean isMaxAge(BlockState state) {
return false;
}

@Nonnull
/* Crop logic */
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return shape[this.getAge(state)];
public PlantType getPlantType(IBlockReader world, BlockPos pos) {
return type;
}

@Deprecated
@Nonnull
@Override
public VoxelShape getRaytraceShape(@Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos) {
return shape[this.getAge(state)];
public boolean isValidPosition(@Nonnull BlockState state, IWorldReader world, @Nonnull BlockPos pos) {
return block.get().isValidPosition(block.get().getDefaultState(), world, pos);
}

/* Crop drops */

@Nonnull
@Override
protected abstract IItemProvider getSeedsItem();
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, BlockState state) {
return Config.bonemealBlockCrop.get();
}

/**
* Gets an IPlantable for this plant
* @return The base block's plantable, or this if the base block is not plantable
*/
protected IPlantable getPlant() {
Block block = this.block.get();
if (block instanceof IPlantable) {
return (IPlantable)block;
}
return this;
}

/* Hidable */
@Override
public PlantType getPlantType(IBlockReader world, BlockPos pos) {
return type;
public boolean isEnabled() {
return Config.enableBlockCrops.get();
}
}

This file was deleted.

0 comments on commit 2978dd5

Please sign in to comment.