Skip to content

Commit

Permalink
feat: Hopefully functional Wyndsprouts + Crop
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jun 11, 2024
1 parent 4e1b73a commit 3b62f76
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 69 deletions.
22 changes: 10 additions & 12 deletions src/main/java/net/zepalesque/redux/block/ReduxBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import net.minecraft.world.level.block.state.BlockBehaviour.OffsetType;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.MapColor;
import net.neoforged.neoforge.registries.DeferredBlock;
Expand All @@ -22,7 +22,7 @@
import net.zepalesque.redux.block.dungeon.RunelightBlock;
import net.zepalesque.redux.block.dungeon.TrappedPillarBlock;
import net.zepalesque.redux.block.natural.AetherShortGrassBlock;
import net.zepalesque.redux.block.natural.crop.WyndGrassBlock;
import net.zepalesque.redux.block.natural.crop.WyndoatsBlock;
import net.zepalesque.redux.block.natural.leaves.FallingLeavesBlock;
import net.zepalesque.redux.block.state.ReduxBlockBuilders;
import net.zepalesque.redux.client.particle.ReduxParticles;
Expand All @@ -37,16 +37,15 @@ public class ReduxBlocks extends ReduxBlockBuilders {
public static DeferredBlock<AetherShortGrassBlock> SHORT_AETHER_GRASS = register("short_aether_grass",
() -> new AetherShortGrassBlock(
Properties.ofFullCopy(Blocks.SHORT_GRASS)
.offsetType(BlockBehaviour.OffsetType.XZ)
.offsetType(OffsetType.XZ)
.hasPostProcess((state, level, pos) -> true)
));

public static final DeferredBlock<SaplingBlock> CLOUDROOT_SAPLING = register("cloudroot_sapling",
() -> new SaplingBlock(ReduxTreeGrowers.CLOUDROOT, Properties.ofFullCopy(Blocks.OAK_SAPLING)));
() -> new SaplingBlock(ReduxTreeGrowers.CLOUDROOT, Properties.ofFullCopy(Blocks.OAK_SAPLING).mapColor(MapColor.QUARTZ)));

public static DeferredBlock<FallingLeavesBlock> CLOUDROOT_LEAVES = register("cloudroot_leaves",
() -> new FallingLeavesBlock(ReduxParticles.CLOUDROOT_LEAF,
BlockBehaviour.Properties.ofFullCopy(AetherBlocks.SKYROOT_LEAVES.get()).mapColor(MapColor.QUARTZ)));
() -> new FallingLeavesBlock(ReduxParticles.CLOUDROOT_LEAF, Properties.ofFullCopy(AetherBlocks.SKYROOT_LEAVES.get()).mapColor(MapColor.QUARTZ)));

public static final DeferredBlock<Block> CARVED_PILLAR = register("carved_pillar", () -> new RotatedPillarBlock(Properties.of().mapColor(MapColor.STONE).instrument(NoteBlockInstrument.BASEDRUM).strength(0.5F, 6.0F).requiresCorrectToolForDrops()));
public static final DeferredBlock<Block> SENTRY_PILLAR = register("sentry_pillar", () -> new RotatedPillarBlock(Properties.ofFullCopy(CARVED_PILLAR.get()).lightLevel(state -> 11)));
Expand Down Expand Up @@ -100,20 +99,19 @@ public class ReduxBlocks extends ReduxBlockBuilders {
// TODO: Automate pot creation

public static DeferredBlock<Block> WYNDSPROUTS = register("wyndsprouts",
() -> new AetherBushBlock(Properties.ofFullCopy(Blocks.SHORT_GRASS).sound(SoundType.CHERRY_SAPLING).offsetType(BlockBehaviour.OffsetType.XZ)));
() -> new AetherBushBlock(Properties.ofFullCopy(Blocks.SHORT_GRASS).sound(SoundType.CHERRY_SAPLING).offsetType(OffsetType.XZ)));
public static final DeferredBlock<FlowerPotBlock> POTTED_WYNDSPROUTS = BLOCKS.register("potted_wyndsprouts", () -> new FlowerPotBlock(() -> (FlowerPotBlock) Blocks.FLOWER_POT, WYNDSPROUTS, Properties.ofFullCopy(Blocks.FLOWER_POT)));

public static DeferredBlock<Block> WYND_GRASS = BLOCKS.register("wynd_grass",
() -> new WyndGrassBlock(Properties.ofFullCopy(Blocks.WHEAT)));

public static DeferredBlock<Block> SKYSPROUTS = register("skysprouts",
() -> new AetherBushBlock(Properties.ofFullCopy(Blocks.SHORT_GRASS).sound(SoundType.CHERRY_SAPLING).offsetType(BlockBehaviour.OffsetType.XZ)));
() -> new AetherBushBlock(Properties.ofFullCopy(Blocks.SHORT_GRASS).sound(SoundType.CHERRY_SAPLING).offsetType(OffsetType.XZ)));
public static final DeferredBlock<FlowerPotBlock> POTTED_SKYSPROUTS = BLOCKS.register("potted_skysprouts", () -> new FlowerPotBlock(() -> (FlowerPotBlock) Blocks.FLOWER_POT, SKYSPROUTS, Properties.ofFullCopy(Blocks.FLOWER_POT)));

public static DeferredBlock<Block> WYNDOATS = BLOCKS.register("wyndoats",
() -> new WyndoatsBlock(Properties.ofFullCopy(Blocks.WHEAT)));


public static void registerFlammability() {
FireAccessor accessor = (FireAccessor) Blocks.FIRE;

Redux.WOOD_SETS.forEach(set -> set.flammables(accessor));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.monster.Ravager;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ItemLike;
Expand All @@ -21,6 +22,7 @@
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.common.CommonHooks;
Expand All @@ -29,26 +31,32 @@
import net.neoforged.neoforge.event.EventHooks;
import net.zepalesque.redux.item.ReduxItems;

public class WyndGrassBlock extends BushBlock implements BonemealableBlock {
public static final int MAX_AGE = 4;
public static final IntegerProperty AGE = BlockStateProperties.AGE_4;
public class WyndoatsBlock extends BushBlock implements BonemealableBlock {
public static final int MAX_AGE = 5;
public static final IntegerProperty AGE = BlockStateProperties.AGE_5;

private static final VoxelShape[] SHAPE_BY_AGE = new VoxelShape[]{
Block.box(3.0D, -1.0D, 3.0D, 13.0D, 2.0D, 13.0D),
Block.box(3.0D, -1.0D, 3.0D, 13.0D, 4.0D, 13.0D),
Block.box(3.0D, -1.0D, 3.0D, 13.0D, 6.0D, 13.0D),
Block.box(3.0D, -1.0D, 3.0D, 13.0D, 9.0D, 13.0D),
Block.box(3.0D, -1.0D, 3.0D, 13.0D, 13.0D, 13.0D)};
Block.box(3.0D, -1.0D, 3.0D, 13.0D, 11.0D, 13.0D),
Block.box(3.0D, -1.0D, 3.0D, 13.0D, 13.0D, 13.0D)
};

public WyndGrassBlock(BlockBehaviour.Properties properties) {
public static final MapCodec<WyndoatsBlock> CODEC = simpleCodec(WyndoatsBlock::new);

public WyndoatsBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(this.getAgeProperty(), Integer.valueOf(0)));
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPE_BY_AGE[this.getAge(state)];
}

@Override
protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) {
return state.is(Blocks.FARMLAND);
}
Expand Down Expand Up @@ -76,15 +84,17 @@ public final boolean isMaxAge(BlockState state) {
/**
* @return whether this block needs random ticking.
*/
@Override
public boolean isRandomlyTicking(BlockState state) {
return !this.isMaxAge(state);
}

/**
* Performs a random tick on a block.
*/
@Override
public void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
if (!level.isAreaLoaded(pos, 1)) return; // NeoForge: prevent loading unloaded chunks when checking neighbor's light
if (!level.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light
if (level.getRawBrightness(pos, 0) >= 9) {
int i = this.getAge(state);
if (i < this.getMaxAge()) {
Expand Down Expand Up @@ -153,10 +163,12 @@ protected static float getGrowthSpeed(Block block, BlockGetter level, BlockPos p
return f;
}

@Override
public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
return (level.getRawBrightness(pos, 0) >= 8 || level.canSeeSky(pos)) && super.canSurvive(state, level, pos);
}

@Override
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
if (entity instanceof Ravager && EventHooks.getMobGriefingEvent(level, entity)) {
level.destroyBlock(pos, true, entity);
Expand All @@ -166,24 +178,28 @@ public void entityInside(BlockState state, Level level, BlockPos pos, Entity ent
}

protected ItemLike getBaseSeedId() {
return ReduxItems.WYNDSPROUT_SEEDS.get();
return ReduxItems.WYND_OATS.get();
}

public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState state) {
@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos, Player player) {
return new ItemStack(this.getBaseSeedId());
}

/**
* @return whether bonemeal can be used on this block
*/
@Override
public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) {
return !this.isMaxAge(state);
}

@Override
public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) {
return true;
}

@Override
public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) {
this.growCrops(level, pos, state);
}
Expand All @@ -193,12 +209,11 @@ public PlantType getPlantType(BlockGetter level, BlockPos pos) {
return PlantType.CROP;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(AGE);
}

public static final MapCodec<WyndGrassBlock> CODEC = simpleCodec(WyndGrassBlock::new);

@Override
protected MapCodec<? extends BushBlock> codec() {
return CODEC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.zepalesque.redux.Redux;
import net.zepalesque.redux.block.ReduxBlocks;
import net.zepalesque.redux.block.natural.crop.WyndGrassBlock;
import net.zepalesque.redux.block.natural.crop.WyndoatsBlock;
import net.zepalesque.redux.blockset.stone.ReduxStoneSets;
import net.zepalesque.redux.data.prov.ReduxBlockStateProvider;

Expand Down Expand Up @@ -51,7 +51,7 @@ protected void registerStatesAndModels() {

// TODO: Textures and stuff
this.crossTintedOverlay(ReduxBlocks.WYNDSPROUTS.get(), "natural/");
this.cropGrowable(ReduxBlocks.WYND_GRASS.get(), "natural/", WyndGrassBlock.AGE);
this.cropGrowable(ReduxBlocks.WYNDOATS.get(), "natural/", WyndoatsBlock.AGE);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.zepalesque.redux.data.ReduxDataMaps;
import net.zepalesque.redux.data.ReduxTags;
import net.zepalesque.redux.data.prov.ReduxDataMapProvider;
import net.zepalesque.redux.item.ReduxItems;
import net.zepalesque.redux.world.biome.tint.ReduxBiomeTints;

import java.util.concurrent.CompletableFuture;
Expand All @@ -35,5 +36,9 @@ protected void gather() {
var compostables = this.builder(NeoForgeDataMaps.COMPOSTABLES);
this.addCompost(compostables, ReduxBlocks.CLOUDROOT_LEAVES, 0.3F);
this.addCompost(compostables, ReduxBlocks.CLOUDROOT_SAPLING, 0.3F);
this.addCompost(compostables, ReduxBlocks.SHORT_AETHER_GRASS, 0.3F);
this.addCompost(compostables, ReduxItems.WYND_OATS, 0.3F);
this.addCompost(compostables, ReduxBlocks.WYNDSPROUTS, 0.3F);
this.addCompost(compostables, ReduxItems.WYND_OAT_PANICLE, 0.65F);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.zepalesque.redux.block.ReduxBlocks;
import net.zepalesque.redux.blockset.stone.ReduxStoneSets;
import net.zepalesque.redux.data.prov.ReduxItemModelProvider;
import net.zepalesque.redux.item.ReduxItems;

public class ReduxItemModelGen extends ReduxItemModelProvider {

Expand All @@ -18,7 +19,7 @@ protected void registerModels() {
Redux.WOOD_SETS.forEach(set -> set.itemData(this));
Redux.STONE_SETS.forEach(set -> set.itemData(this));

itemBlockFlatCustomTexture(ReduxBlocks.SHORT_AETHER_GRASS, "natural/aether_medium_grass");
itemBlockFlatCustomTexture(ReduxBlocks.SHORT_AETHER_GRASS.get(), "natural/aether_medium_grass");
this.itemBlock(ReduxBlocks.CLOUDROOT_LEAVES.get());
this.itemBlockFlat(ReduxBlocks.CLOUDROOT_SAPLING.get(), "natural/");

Expand All @@ -45,6 +46,10 @@ protected void registerModels() {
this.itemBlock(ReduxBlocks.RUNELIGHT.get(), "_on");
this.itemOverlayDungeonBlock(ReduxBlocks.LOCKED_RUNELIGHT.get(), ReduxBlocks.RUNELIGHT.get(), "lock", "dungeon/", "_on");
this.itemOverlayDungeonBlock(ReduxBlocks.LOCKED_SENTRITE_BRICKS.get(), ReduxStoneSets.SENTRITE_BRICKS.block().get(), "construction/", "lock");

this.item(ReduxItems.WYND_OAT_PANICLE.get(), "materials/");
itemBlockFlatTintOverlay(ReduxBlocks.WYNDSPROUTS.get(), "natural/");
itemBlockFlatTintOverlay(ReduxBlocks.SKYSPROUTS.get(), "natural/");
}

}
Loading

0 comments on commit 3b62f76

Please sign in to comment.