generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
188 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/main/java/dev/sterner/culturaldelights/common/block/FruitingLeaves.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
src/main/java/dev/sterner/culturaldelights/common/world/AvocadoBundleTreeDecorator.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/main/resources/assets/culturaldelights/blockstates/fruiting_avocado_leaves.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/culturaldelights/models/block/fruiting_avocado_leaves_0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/culturaldelights/models/block/fruiting_avocado_leaves_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/culturaldelights/models/block/fruiting_avocado_leaves_2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/culturaldelights/models/block/fruiting_avocado_leaves_3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/culturaldelights/models/block/fruiting_avocado_leaves_4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/culturaldelights/models/item/fruiting_avocado_leaves.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"parent": "culturaldelights:block/fruiting_avocado_leaves_0" | ||
} |
Binary file added
BIN
+553 Bytes
.../resources/assets/culturaldelights/textures/block/fruiting_avocado_leaves_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+573 Bytes
.../resources/assets/culturaldelights/textures/block/fruiting_avocado_leaves_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+580 Bytes
.../resources/assets/culturaldelights/textures/block/fruiting_avocado_leaves_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+556 Bytes
.../resources/assets/culturaldelights/textures/block/fruiting_avocado_leaves_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+569 Bytes
.../resources/assets/culturaldelights/textures/block/fruiting_avocado_leaves_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters