Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
Ritual
Browse files Browse the repository at this point in the history
  • Loading branch information
orange809 committed Jul 28, 2024
1 parent 8bb0bad commit 6d1e7e6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21 2024-07-26T18:40:32.3926357 Registries
20e0d3a34f134cd8aed6f7ccca4cfbb3d26a1fca data/farm_away/farm_away/ritual/potato_ritual.json
// 1.21 2024-07-28T23:06:29.5088446 Registries
8d2d23bbc1d194e9c7b773687b64a27d9c310ea8 data/farm_away/farm_away/ritual/ice_cream.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"base_out": "farm_away:andesite_farmland",
"center": "farm_away:empty_root",
"center_out": "farm_away:soft_potatoes",
"ritual_base": [
"minecraft:air",
"minecraft:farmland",
"farm_away:solid_cloud"
]
}

This file was deleted.

12 changes: 6 additions & 6 deletions src/main/java/ho/artisan/farmaway/common/data/FARituals.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import java.util.List;

public class FARituals {
public static final ResourceKey<Ritual> POTATO_RITUAL = create("potato_ritual");
public static final ResourceKey<Ritual> ICE_CREAM = create("ice_cream");

public static void init(BootstrapContext<Ritual> context) {
context.register(POTATO_RITUAL, new Ritual(
Blocks.POTATOES.builtInRegistryHolder(),
Blocks.STONE.builtInRegistryHolder(),
List.of(Blocks.STONE.builtInRegistryHolder()),
FABlocks.STONE_FARMLAND
context.register(ICE_CREAM, new Ritual(
FABlocks.EMPTY_ROOT,
FABlocks.SOFT_POTATOES,
List.of(Blocks.AIR.builtInRegistryHolder(), Blocks.FARMLAND.builtInRegistryHolder(), FABlocks.SOLID_CLOUD),
FABlocks.ANDESITE_FARMLAND
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ho.artisan.farmaway.common.item;

import ho.artisan.farmaway.common.data.FARituals;
import ho.artisan.farmaway.common.registry.FABlocks;
import ho.artisan.farmaway.common.util.RitualUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.stats.Stats;
Expand All @@ -25,7 +27,7 @@ public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
if (level.getBlockState(context.getClickedPos()).getBlock() instanceof CropBlock crop && context.getPlayer() != null) {
if (crop == FABlocks.EMPTY_ROOT.get()) {

RitualUtil.start(level, context.getClickedPos(), FARituals.ICE_CREAM);
} else if (!crop.isMaxAge(context.getLevel().getBlockState(context.getClickedPos()))) {
crop.growCrops(level, context.getClickedPos(), level.getBlockState(context.getClickedPos()));
context.getPlayer().hurt(level.damageSources().magic(), 2.0f);
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/ho/artisan/farmaway/common/util/RitualUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@

import ho.artisan.farmaway.common.ritual.Ritual;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.references.Blocks;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AirBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.phys.AABB;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class RitualUtil {
public static void start(Level level, BlockPos pos, ResourceKey<Ritual> key) {
var r = Ritual.of(level.registryAccess(), key);
if (r.isPresent()) {
var ritual = r.get();
if (level.getBlockState(pos).getBlock() == ritual.center().value()) {
Set<Block> list = new HashSet<>();
Set<Block> base = new HashSet<>();
list.addAll(level.getBlockStates(AABB.ofSize(pos.below().getCenter(), 2.0, 0.0, 2.0)).map(BlockBehaviour.BlockStateBase::getBlock).toList());
base.addAll(ritual.ritualBase().stream().map(Holder::value).toList());
if (level.getBlockState(pos).getBlock() == ritual.center().value() && list.equals(base)) {
level.setBlock(pos.below(), ritual.baseOut().value().defaultBlockState(), 2);
level.setBlock(pos, ritual.centerOut().value().defaultBlockState(), 2);
}
Expand Down

0 comments on commit 6d1e7e6

Please sign in to comment.