Skip to content

Commit

Permalink
Update and fix coffee shrub growth
Browse files Browse the repository at this point in the history
  • Loading branch information
Chikorita-Lover committed Jan 12, 2024
1 parent 69836a0 commit 2b3d3d9
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 94 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.23
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.15.3

# Mod Properties
mod_version=1.0.4
mod_version=1.0.5
mod_id="caffeinated"
maven_group=com.chikoritalover
archives_base_name=caffeinated

# Dependencies
fabric_version=0.90.0+1.20.2
fabric_version=0.91.0+1.20.1
farmersdelight_version=4640640
20 changes: 10 additions & 10 deletions src/main/generated/.cache/c189bb4c92920ea572e0709157481155fe15e5dc
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// 1.20.2 2023-10-15T20:29:42.2651439 Caffeinated/Recipes
60edf397c8d26670727ae0676dbce298d423a987 data\caffeinated\advancements\recipes\misc\coffee_beans_from_block.json
f6f83c2813afcd361f26fd2425359f9454b597f0 data\caffeinated\advancements\recipes\misc\java_banner_pattern.json
// 1.20.1 2024-01-06T12:11:53.8042848 Caffeinated/Recipes
e154bc568fca23d856835d0e300a33c5e3c1fcd5 data\caffeinated\advancements\recipes\misc\coffee_beans_from_block.json
2b1061f72b3e9a1295c9aa4334d37c9dcb3dfc53 data\caffeinated\advancements\recipes\misc\java_banner_pattern.json
76a46edddf4e31119b24a67f63988b18a8aee17f data\caffeinated\recipes\ground_coffee_block.json
37f206007eb9d1e0cc82f0ddd2f9867861230dd9 data\caffeinated\advancements\recipes\misc\ground_coffee_from_block.json
268aa1e50835caea02401ad05034a8a1c3ad2caf data\caffeinated\advancements\recipes\food\tiramisu.json
187961e40d0322c1b7b655376bfe28d0b99ec8bd data\caffeinated\advancements\recipes\misc\ground_coffee_from_block.json
06c7edbdec5cf1deb92d8e421279587f14aaab54 data\caffeinated\advancements\recipes\food\tiramisu.json
aff0b344beb7238820d9ef40b8eeae0b6ee96bb9 data\caffeinated\recipes\coffee_beans_from_block.json
4c85433379ef206f984248f2181f8f0d58e04302 data\caffeinated\recipes\coffee_beans_from_coffee_berries.json
bd42cc3cdc3aef8bcd1c23d64644e0aa0f6e5f16 data\caffeinated\advancements\recipes\misc\coffee_beans_from_coffee_berries.json
6b9902befd959eb3bc01bca55faa32da5902eaeb data\caffeinated\recipes\tiramisu.json
195cc52740e219af6b8b65dde7d9ef8d0768d307 data\caffeinated\advancements\recipes\misc\coffee_beans_from_coffee_berries.json
d34b1b5cba65cbe93df946e3a6badee9edc69dc0 data\caffeinated\recipes\coffee_berries.json
7872d0d8329ad57778754a3bb074ae65f2fe2990 data\caffeinated\recipes\coffee_bean_block.json
743816fab7585e00cd7f2678713589c48bdc2aed data\caffeinated\recipes\ground_coffee_from_block.json
4e0afabfb869f92af827bcaf26544ff753642fa6 data\caffeinated\advancements\recipes\building_blocks\ground_coffee_block.json
55a0f263de5782dd9ec9aecd1d1ae815e3760bdb data\caffeinated\advancements\recipes\building_blocks\ground_coffee_block.json
d466ced2e8e679a807bdbcee307e0eb5e6547942 data\caffeinated\recipes\java_banner_pattern.json
56980a68399285002606be4ec589599d4c1f808b data\caffeinated\advancements\recipes\building_blocks\coffee_bean_block.json
bb529f25b75b190a9da8518d7a0931d22cbaf194 data\caffeinated\advancements\recipes\building_blocks\coffee_bean_block.json
9d1c02e4b749346060e0aca83030e22690aed245 data\caffeinated\recipes\ground_coffee_from_coffee_beans.json
bf1133b51ff5c6bf1ab08f8f94bf2304385509d8 data\caffeinated\advancements\recipes\misc\ground_coffee_from_coffee_beans.json
167bcffb66060dd5db590232e162c6f0a0b3b497 data\caffeinated\advancements\recipes\food\coffee_berries.json
c25fb492ba07b4ed02e133e2329fe9f0b00a2b5e data\caffeinated\advancements\recipes\misc\ground_coffee_from_coffee_beans.json
7ac9428c1c4810e6e439997467b8c5afad1711b9 data\caffeinated\advancements\recipes\food\coffee_berries.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.2 2023-10-15T20:29:42.2624264 Caffeinated/Model Definitions
// 1.20.1 2024-01-06T12:11:53.8005201 Caffeinated/Model Definitions
da4528a3cfafc1ab21e5814b64029c10ec357178 assets\caffeinated\blockstates\ground_coffee_block.json
26f35f3a03b0d53578efd2c555721b08353d75f0 assets\caffeinated\blockstates\coffee_cauldron.json
b1a481861132973fe035c9b9ce7613e15938034c assets\caffeinated\models\block\coffee_berry_crate.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_coffee_beans"
"has_coffee_beans",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_ground_coffee"
"has_ground_coffee",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_coffee_berry_crate"
"has_coffee_berry_crate",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_coffee_bottle"
"has_coffee_bottle",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_coffee_bean_block"
"has_coffee_bean_block",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_coffee_berries"
"has_coffee_berries",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_ground_coffee_block"
"has_ground_coffee_block",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_coffee_beans"
"has_coffee_beans",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_coffee_bottle"
"has_coffee_bottle",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.block.Block;
import net.minecraft.block.LeveledCauldronBlock;
import net.minecraft.data.client.*;
import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.RecipeJsonProvider;
import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder;
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.item.ItemConvertible;
Expand All @@ -23,6 +23,8 @@
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.function.Consumer;

public class CaffeinatedDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
Expand Down Expand Up @@ -84,13 +86,13 @@ private CaffeinatedRecipeGenerator(FabricDataOutput output) {
super(output);
}

public static void offerReversibleCompactingRecipes(RecipeExporter exporter, ItemConvertible input, ItemConvertible compacted, String compactingRecipeName, @Nullable String compactingRecipeGroup, String reverseRecipeName, @Nullable String reverseRecipeGroup) {
public static void offerReversibleCompactingRecipes(Consumer<RecipeJsonProvider> exporter, ItemConvertible input, ItemConvertible compacted, String compactingRecipeName, @Nullable String compactingRecipeGroup, String reverseRecipeName, @Nullable String reverseRecipeGroup) {
ShapelessRecipeJsonBuilder.create(RecipeCategory.MISC, input, 9).input(compacted).group(reverseRecipeGroup).criterion(hasItem(compacted), conditionsFromItem(compacted)).offerTo(exporter, new Identifier(Caffeinated.MODID, reverseRecipeName));
ShapedRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, compacted).input('#', input).pattern("###").pattern("###").pattern("###").group(compactingRecipeGroup).criterion(hasItem(input), conditionsFromItem(input)).offerTo(exporter, new Identifier(Caffeinated.MODID, compactingRecipeName));
}

@Override
public void generate(RecipeExporter exporter) {
public void generate(Consumer<RecipeJsonProvider> exporter) {
offerReversibleCompactingRecipes(exporter, CaffeinatedItems.COFFEE_BEANS, CaffeinatedBlocks.COFFEE_BEAN_BLOCK, "coffee_bean_block", null, "coffee_beans_from_block", "coffee_beans");

offerReversibleCompactingRecipes(exporter, CaffeinatedItems.GROUND_COFFEE, CaffeinatedBlocks.GROUND_COFFEE_BLOCK, "ground_coffee_block", null, "ground_coffee_from_block", "ground_coffee");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,63 +28,70 @@ public class CoffeeShrubBlock extends PlantBlock implements Fertilizable {

public CoffeeShrubBlock(AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(AGE, 0));
this.setDefaultState(this.getStateManager().getDefaultState().with(AGE, 0));
}

@Override
public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
return new ItemStack(CaffeinatedItems.COFFEE_BEANS);
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return state.get(AGE) < 2 ? SMALL_SHAPE : LARGE_SHAPE;
}

@Override
public boolean hasRandomTicks(BlockState state) {
return true;
}

@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
int i = state.get(AGE);
BlockState aboveState = world.getBlockState(pos.up());
if ((i < 3 || aboveState.isReplaceable()) && random.nextInt(5) == 0 && world.getBaseLightLevel(pos.up(), 0) >= 9) {
grow(world, random, pos, state);
BlockState state2 = world.getBlockState(pos);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(state2));
if (!this.canGrow(world, random, pos, state)) {
return;
}
if (random.nextInt(5) == 0 && world.getBaseLightLevel(pos.up(), 0) >= 9) {
this.grow(world, random, pos, state);
BlockState blockState = world.getBlockState(pos);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(blockState));
}

}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
int i = state.get(AGE);
BlockState aboveState = world.getBlockState(pos.up());
boolean bl = i == 3 && !aboveState.isReplaceable();
if (!bl && player.getStackInHand(hand).isOf(Items.BONE_MEAL)) {
boolean bl = this.isFertilizable(world, pos, state, world.isClient());
if (bl && player.getStackInHand(hand).isOf(Items.BONE_MEAL)) {
return ActionResult.PASS;
} else {
return super.onUse(state, world, pos, player, hand, hit);
}
}

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

@Override
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
int i = state.get(AGE);
BlockState aboveState = world.getBlockState(pos.up());
return i < 3 || aboveState.isReplaceable();
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) {
return state.get(AGE) < 3 || world.isAir(pos.up());
}

@Override
public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
return true;
return state.get(AGE) < 3 || world.isAir(pos.up());
}

@Override
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
BlockState state2 = state.get(AGE) < 3 ? state.cycle(AGE) : CaffeinatedBlocks.FLOWERING_COFFEE_SHRUB.getDefaultState();
world.setBlockState(pos, state2, 2);
if (state.get(AGE) == 3) {
world.setBlockState(pos.up(), state2.cycle(Properties.DOUBLE_BLOCK_HALF), 2);
if (state.get(AGE) < 3) {
world.setBlockState(pos, state.with(AGE, state.get(AGE) + 1), Block.NOTIFY_LISTENERS);
return;
}
BlockState blockState = CaffeinatedBlocks.FLOWERING_COFFEE_SHRUB.getDefaultState();
if (blockState.canPlaceAt(world, pos) && world.isAir(pos.up())) {
FloweringCoffeeShrubBlock.placeAt(world, blockState, pos, Block.NOTIFY_LISTENERS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.world.event.GameEvent;

public class FloweringCoffeeShrubBlock extends TallPlantBlock implements Fertilizable {
public static final int MAX_AGE = 3;
public static final IntProperty AGE = Properties.AGE_3;

public FloweringCoffeeShrubBlock(Settings settings) {
Expand All @@ -37,77 +38,70 @@ public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
}

public boolean hasRandomTicks(BlockState state) {
return true;
return state.get(HALF) == DoubleBlockHalf.LOWER && state.get(AGE) < MAX_AGE;
}

public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
int i = state.get(AGE);
if (i < 3 && random.nextInt(11) == 0 && world.getBaseLightLevel(pos.up(), 0) >= 9) {
grow(world, random, pos, state);
BlockState blockState = world.getBlockState(pos);

world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(blockState));
if (blockState.get(HALF) == DoubleBlockHalf.LOWER) {
world.setBlockState(pos.up(), blockState.cycle(HALF), 2);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos.up(), GameEvent.Emitter.of(blockState.cycle(HALF)));
} else {
world.setBlockState(pos.down(), blockState.cycle(HALF), 2);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos.down(), GameEvent.Emitter.of(blockState.cycle(HALF)));
}
if (i < MAX_AGE && random.nextInt(5) == 0 && world.getBaseLightLevel(pos.up(), 0) >= 9) {
this.grow(world, random, pos, state);
}

}

public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
int i = state.get(AGE);
boolean bl = i == 3;
if (!bl && player.getStackInHand(hand).isOf(Items.BONE_MEAL)) {
if (i < MAX_AGE && player.getStackInHand(hand).isOf(Items.BONE_MEAL)) {
return ActionResult.PASS;
} else if (i == 3) {
int j = 1 + world.random.nextInt(2);
dropStack(world, pos, new ItemStack(CaffeinatedItems.COFFEE_BERRIES, j + (bl ? 1 : 0)));
world.playSound(null, pos, CaffeinatedSoundEvents.BLOCK_COFFEE_SHRUB_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
}
if (i == MAX_AGE) {
int j = world.getRandom().nextInt(2) + 2;
dropStack(world, pos, new ItemStack(CaffeinatedItems.COFFEE_BERRIES, j));
world.playSound(null, pos, CaffeinatedSoundEvents.BLOCK_COFFEE_SHRUB_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, 0.8F + world.getRandom().nextFloat() * 0.4F);
BlockState blockState = state.with(AGE, 0);

world.setBlockState(pos, blockState, 2);
world.setBlockState(pos, blockState, Block.NOTIFY_LISTENERS);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState));
if (state.get(HALF) == DoubleBlockHalf.LOWER) {
world.setBlockState(pos.up(), blockState.cycle(HALF), 2);
world.setBlockState(pos.up(), blockState.cycle(HALF), Block.NOTIFY_LISTENERS);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos.up(), GameEvent.Emitter.of(player, blockState.cycle(HALF)));
} else {
world.setBlockState(pos.down(), blockState.cycle(HALF), 2);
world.setBlockState(pos.down(), blockState.cycle(HALF), Block.NOTIFY_LISTENERS);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos.down(), GameEvent.Emitter.of(player, blockState.cycle(HALF)));
}

return ActionResult.success(world.isClient);
} else {
return super.onUse(state, world, pos, player, hand, hit);
}
return super.onUse(state, world, pos, player, hand, hit);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(AGE);
super.appendProperties(builder);
}

@Override
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
return state.get(AGE) < 3;
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) {
return state.get(AGE) < MAX_AGE;
}

@Override
public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
return true;
if (state.get(HALF) == DoubleBlockHalf.UPPER) {
return this.canGrow(world, random, pos.down(), world.getBlockState(pos.down()));
}
return state.get(AGE) < MAX_AGE && this.canPlaceAt(state, world, pos);
}

@Override
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
int i = Math.min(3, state.get(AGE) + 1);
world.setBlockState(pos, state.with(AGE, i), 2);
if (!this.canGrow(world, random, pos, state)) {
return;
}
int i = Math.min(MAX_AGE, state.get(AGE) + 1);
world.setBlockState(pos, state.with(AGE, i), Block.NOTIFY_LISTENERS);
if (state.get(HALF) == DoubleBlockHalf.LOWER) {
world.setBlockState(pos.up(), state.with(AGE, i).cycle(HALF), 2);
world.setBlockState(pos.up(), state.with(AGE, i).cycle(HALF), Block.NOTIFY_ALL);
} else {
world.setBlockState(pos.down(), state.with(AGE, i).cycle(HALF), 2);
world.setBlockState(pos.down(), state.with(AGE, i).cycle(HALF), Block.NOTIFY_ALL);
}
}
}
Loading

0 comments on commit 2b3d3d9

Please sign in to comment.