Skip to content

Commit

Permalink
fix #19
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsterner committed Jul 2, 2024
1 parent 6c56611 commit 7cbe16f
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 75 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.20.1+build.9
loader_version=0.15.9

# Mod Properties
mod_version = 1.0.1+1.20.1
mod_version = 1.0.3+1.20.1
maven_group = dev.sterner
archives_base_name = cultural-delights-fabric

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import dev.sterner.culturaldelights.common.registry.CDTags;
import dev.sterner.culturaldelights.common.registry.CDWorldGenerators;
import dev.sterner.culturaldelights.common.utils.Constants;
import dev.sterner.culturaldelights.common.world.AvocadoBundleTreeDecorator;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
Expand All @@ -33,7 +32,6 @@
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import vectorwing.farmersdelight.FarmersDelight;

public class CulturalDelights implements ModInitializer {
public static final String MOD_ID = "culturaldelights";
Expand All @@ -42,8 +40,7 @@ public class CulturalDelights implements ModInitializer {

public static final ResourceKey<CreativeModeTab> ITEM_GROUP = ResourceKey.create(Registries.CREATIVE_MODE_TAB, new ResourceLocation(MOD_ID));

public static final TreeDecoratorType<AvocadoBundleTreeDecorator> AVOCADO_BUNDLE_TREE_DECORATOR_TYPE = register(Constants.id("avocado_bundle"), AvocadoBundleTreeDecorator.CODEC);


private static <P extends TreeDecorator> TreeDecoratorType<P> register(ResourceLocation id, Codec<P> codec) {
return Registry.register(BuiltInRegistries.TREE_DECORATOR_TYPE, id, new TreeDecoratorType<>(codec));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package dev.sterner.culturaldelights.common.block;

import dev.sterner.culturaldelights.common.registry.CDObjects;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
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.level.gameevent.GameEvent;
import net.minecraft.world.phys.BlockHitResult;

public class FruitingLeaves extends LeavesBlock implements BonemealableBlock {
public static final int MAX_AGE = 4;
public static final IntegerProperty AGE = BlockStateProperties.AGE_4;

public FruitingLeaves(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any()
.setValue(AGE, Integer.valueOf(0))
.setValue(DISTANCE, Integer.valueOf(7))
.setValue(PERSISTENT, Boolean.valueOf(false))
.setValue(WATERLOGGED, Boolean.valueOf(false)));

}

//public ItemStack getCloneItemStack(BlockGetter p_57256_, BlockPos p_57257_, BlockState p_57258_) {
// return new ItemStack(ModItems.AVOCADO.get());
//}
@Override
public boolean isRandomlyTicking(BlockState state) {
return state.getValue(AGE) < MAX_AGE || state.getValue(DISTANCE) == 7 && !state.getValue(PERSISTENT);
}
@Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource rand) {
if (this.decaying(state)) {
dropResources(state, world, pos);
world.removeBlock(pos, false);
}
else {
int age = state.getValue(AGE);
if (age < MAX_AGE) {
BlockState blockstate = state.setValue(AGE, Integer.valueOf(age + 1));
world.setBlock(pos, blockstate, 2);
world.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(blockstate));
}
}
}
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult result) {
int i = state.getValue(AGE);
boolean flag = i == MAX_AGE;
if (!flag && player.getItemInHand(hand).is(Items.BONE_MEAL)) {
return InteractionResult.PASS;
} else if (i > 1) {
int j = 1 + world.random.nextInt(2);
popResource(world, pos, new ItemStack(CDObjects.AVOCADO, j + (flag ? 1 : 0)));
world.playSound((Player)null, pos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
BlockState blockstate = state.setValue(AGE, Integer.valueOf(0));
world.setBlock(pos, blockstate, 2);
world.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, blockstate));
return InteractionResult.sidedSuccess(world.isClientSide);
} else {
return super.use(state, world, pos, player, hand, result);
}
}

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

@Override
public boolean isValidBonemealTarget(LevelReader levelReader, BlockPos blockPos, BlockState blockState, boolean bl) {
return blockState.getValue(AGE) < MAX_AGE;
}

@Override
public boolean isBonemealSuccess(Level p_222558_, RandomSource p_222559_, BlockPos p_222560_, BlockState p_222561_) {
return true;
}
@Override
public void performBonemeal(ServerLevel p_222553_, RandomSource p_222554_, BlockPos p_222555_, BlockState p_222556_) {
int i = Math.min(MAX_AGE, p_222556_.getValue(AGE) + 1);
p_222553_.setBlock(p_222555_, p_222556_.setValue(AGE, Integer.valueOf(i)), 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemNameBlockItem;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockBehaviour;
import vectorwing.farmersdelight.FarmersDelight;
import vectorwing.farmersdelight.common.block.WildCropBlock;
import vectorwing.farmersdelight.common.registry.ModBlocks;
Expand Down Expand Up @@ -82,16 +83,16 @@ public class CDObjects {
public static final Item CALAMARI_ROLL = register("calamari_roll", new Item(settings().food(CDFoodComponents.CALAMARI_ROLL)));



public static final Block AVOCADO_BUNDLE = register("avocado_bundle", new Block(FabricBlockSettings.copy(Blocks.PUMPKIN)), settings(), true);
public static final Block FRUITING_AVOCADO_LEAVES = register("fruiting_avocado_leaves",
new FruitingLeaves(BlockBehaviour.Properties.copy(Blocks.JUNGLE_LEAVES)), settings(), false);

public static final Block WILD_CUCUMBERS = register("wild_cucumbers", new WildCropBlock(MobEffects.DAMAGE_BOOST, 6, FabricBlockSettings.copyOf(Blocks.TALL_GRASS)), settings(), true);
public static final Block WILD_CORN = register("wild_corn", new WildCropBlock(MobEffects.DAMAGE_BOOST, 6, FabricBlockSettings.copyOf(Blocks.TALL_GRASS)), settings(), true);
public static final Block WILD_EGGPLANTS = register("wild_eggplants", new WildCropBlock(MobEffects.DAMAGE_BOOST, 6, FabricBlockSettings.copyOf(Blocks.TALL_GRASS)), settings(), true);

public static final Block AVOCADO_LOG = register("avocado_log", new RotatedPillarBlock(FabricBlockSettings.copy(Blocks.JUNGLE_LOG)), settings(), true);
public static final Block AVOCADO_WOOD = register("avocado_wood", new RotatedPillarBlock(FabricBlockSettings.copy(Blocks.JUNGLE_WOOD)), settings(), true);
public static final Block AVOCADO_LEAVES = register("avocado_leaves", new RotatedPillarBlock(FabricBlockSettings.copy(Blocks.JUNGLE_LEAVES)), settings(), true);
public static final Block AVOCADO_LEAVES = register("avocado_leaves", new LeavesBlock(FabricBlockSettings.copy(Blocks.JUNGLE_LEAVES)), settings(), true);

public static final Block AVOCADO_SAPLING = register("avocado_sapling", new SaplingBlock(new AvocadoSaplingGenerator(), FabricBlockSettings.copy(Blocks.OAK_SAPLING)), settings(), true);

Expand Down Expand Up @@ -141,6 +142,7 @@ public static void init() {

FlammableBlockRegistry flammableRegistry = FlammableBlockRegistry.getDefaultInstance();
flammableRegistry.add(AVOCADO_LEAVES, 30, 60);
flammableRegistry.add(FRUITING_AVOCADO_LEAVES, 30, 60);
flammableRegistry.add(AVOCADO_LOG, 5, 5);
flammableRegistry.add(AVOCADO_WOOD, 5, 5);

Expand All @@ -166,6 +168,6 @@ public static void init() {

compostRegistry.add(POPCORN, 0.85f);

compostRegistry.add(AVOCADO_BUNDLE, 1f);
compostRegistry.add(FRUITING_AVOCADO_LEAVES, 0.65f);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"variants": {
"age=0": {
"model": "culturaldelights:block/fruiting_avocado_leaves_0"
},
"age=1": {
"model": "culturaldelights:block/fruiting_avocado_leaves_1"
},
"age=2": {
"model": "culturaldelights:block/fruiting_avocado_leaves_2"
},
"age=3": {
"model": "culturaldelights:block/fruiting_avocado_leaves_3"
},
"age=4": {
"model": "culturaldelights:block/fruiting_avocado_leaves_4"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/leaves",
"textures": {
"all": "culturaldelights:block/fruiting_avocado_leaves_0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/leaves",
"textures": {
"all": "culturaldelights:block/fruiting_avocado_leaves_1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/leaves",
"textures": {
"all": "culturaldelights:block/fruiting_avocado_leaves_2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/leaves",
"textures": {
"all": "culturaldelights:block/fruiting_avocado_leaves_3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/leaves",
"textures": {
"all": "culturaldelights:block/fruiting_avocado_leaves_4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "culturaldelights:block/fruiting_avocado_leaves_0"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"type": "minecraft:tree",
"config": {
"decorators": [
{
"type": "culturaldelights:avocado_bundle",
"probability": 1
}
],
"dirt_provider": {
"type": "minecraft:simple_state_provider",
Expand All @@ -19,15 +15,32 @@
"radius": 3
},
"foliage_provider": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "culturaldelights:avocado_leaves",
"Properties": {
"distance": "7",
"persistent": "false",
"waterlogged": "false"
"type": "minecraft:weighted_state_provider",
"entries": [
{
"data": {
"Name": "culturaldelights:avocado_leaves",
"Properties": {
"distance": "7",
"persistent": "false",
"waterlogged": "false"
}
},
"weight": 3
},
{
"data": {
"Name": "culturaldelights:fruiting_avocado_leaves",
"Properties": {
"distance": "7",
"persistent": "false",
"waterlogged": "false",
"age": 4
}
},
"weight": 1
}
}
]
},
"force_dirt": false,
"ignore_vines": true,
Expand Down

0 comments on commit 7cbe16f

Please sign in to comment.