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

Commit

Permalink
half-finished ritual
Browse files Browse the repository at this point in the history
  • Loading branch information
orange809 committed Jul 26, 2024
1 parent 5d6fd6a commit 345b963
Show file tree
Hide file tree
Showing 29 changed files with 221 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "farm_away:item/soft_potato"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"farm_away:gerbera_potatoes"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"farm_away:gerbera_potato"
]
}
2 changes: 2 additions & 0 deletions src/main/java/ho/artisan/farmaway/FarmAway.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ho.artisan.farmaway;

import ho.artisan.farmaway.common.data.FARegistries;
import ho.artisan.farmaway.common.registry.*;
import net.minecraft.Util;
import net.minecraft.network.chat.Component;
Expand All @@ -16,6 +17,7 @@ public class FarmAway {
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public FarmAway(IEventBus bus, ModContainer container) {
FARegistries.bring();
FABlocks.register(bus);
FAItems.register(bus);
FATabs.register(bus);
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/ho/artisan/farmaway/common/block/EmptyRootBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ho.artisan.farmaway.common.block;

import com.mojang.serialization.MapCodec;
import ho.artisan.farmaway.common.registry.FAItems;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class EmptyRootBlock extends CropBlock {
public static final MapCodec<EmptyRootBlock> CODEC = simpleCodec(EmptyRootBlock::new);

public MapCodec<EmptyRootBlock> codec() {
return CODEC;
}
public EmptyRootBlock(Properties properties) {
super(properties);
}

@Override
public int getMaxAge() {
return 0;
}

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

protected ItemLike getBaseSeedId() {
return FAItems.EMPTY_ROOT.get();
}

protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return Block.box(0.0, 0.0, 0.0, 16.0, 2.0, 16.0);
}
}
17 changes: 17 additions & 0 deletions src/main/java/ho/artisan/farmaway/common/data/FARegistries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ho.artisan.farmaway.common.data;

import ho.artisan.farmaway.FarmAway;
import ho.artisan.farmaway.common.ritual.Ritual;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModList;
import net.neoforged.neoforge.registries.DataPackRegistryEvent;

public class FARegistries {
public static final ResourceKey<Registry<Ritual>> RITUAL = ResourceKey.createRegistryKey(FarmAway.getResourceLocation("ritual"));
public static void bring() {
IEventBus bus = ModList.get().getModContainerById(RITUAL.location().getNamespace()).get().getEventBus();
bus.addListener(DataPackRegistryEvent.NewRegistry.class, (event) -> event.dataPackRegistry(RITUAL, Ritual.CODEC, Ritual.CODEC));
}
}
30 changes: 30 additions & 0 deletions src/main/java/ho/artisan/farmaway/common/data/FARituals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ho.artisan.farmaway.common.data;

import ho.artisan.farmaway.FarmAway;
import ho.artisan.farmaway.common.registry.FABlocks;
import ho.artisan.farmaway.common.ritual.Ritual;
import net.minecraft.core.Holder;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;

import java.util.ArrayList;
import java.util.List;

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

public static void init(BootstrapContext<Ritual> init) {
init.register(POTATO_RITUAL, new Ritual(
Blocks.POTATOES,
Blocks.STONE,
List.of(Blocks.STONE),
FABlocks.STONE_FARMLAND.get()
));
}

public static ResourceKey<Ritual> create(String name) {
return ResourceKey.create(FARegistries.RITUAL, FarmAway.getResourceLocation(name));
}
}
19 changes: 14 additions & 5 deletions src/main/java/ho/artisan/farmaway/common/event/FAEvents.java
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.effect.MobEffectInstance;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CropBlock;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.living.LivingIncomingDamageEvent;
Expand Down Expand Up @@ -34,14 +35,22 @@ private static void onLivingIncomingDamage(LivingIncomingDamageEvent event) {
@SubscribeEvent
private static void onBlockBreak(BlockEvent.BreakEvent event) {
Optional<Block> block = RandomUtil.randomBlock();
if (event.getPlayer().hasEffect(FAMobEffects.PHANTOM)) {
var block_state = event.getLevel().getBlockState(event.getPos());
if (event.getPlayer().hasEffect(FAMobEffects.VOID)) {
event.setCanceled(true);
} else if (event.getPlayer().hasEffect(FAMobEffects.PHANTOM)) {
if (!event.getLevel().getBlockState(event.getPos()).is(FABlocks.PHANTOM_DIRT)) {
if (RandomSource.create().nextInt(100) > 80) {
if (block_state.getBlock() instanceof CropBlock crop && crop != FABlocks.EMPTY_ROOT.get() && crop.getAge(block_state) == 0) {
event.setCanceled(true);
block.ifPresent(value -> event.getLevel().setBlock(event.getPos(), value.defaultBlockState(), 2));
event.getLevel().setBlock(event.getPos(), FABlocks.EMPTY_ROOT.get().defaultBlockState(), 2);
} else {
event.setCanceled(true);
event.getLevel().setBlock(event.getPos(), FABlocks.PHANTOM_DIRT.get().defaultBlockState(), 2);
if (RandomSource.create().nextInt(100) > 80) {
event.setCanceled(true);
block.ifPresent(value -> event.getLevel().setBlock(event.getPos(), value.defaultBlockState(), 2));
} else {
event.setCanceled(true);
event.getLevel().setBlock(event.getPos(), FABlocks.PHANTOM_DIRT.get().defaultBlockState(), 2);
}
}
} else {
event.setCanceled(true);
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/ho/artisan/farmaway/common/item/RosePotatoItem.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
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.ritual.Ritual;
import ho.artisan.farmaway.common.util.RitualUtil;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemNameBlockItem;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CropBlock;

public class RosePotatoItem extends ItemNameBlockItem {
Expand All @@ -17,11 +22,17 @@ public RosePotatoItem(Block block, Properties properties) {
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
if (level.getBlockState(context.getClickedPos()).getBlock() instanceof CropBlock crop && context.getPlayer() != null) {
crop.growCrops(level, context.getClickedPos(), level.getBlockState(context.getClickedPos()));
context.getPlayer().hurt(level.damageSources().magic(), 2.0f);
context.getPlayer().awardStat(Stats.ITEM_USED.get(this));
this.getDefaultInstance().consume(1, context.getPlayer());
return InteractionResult.sidedSuccess(true);
if (crop == FABlocks.EMPTY_ROOT.get()) {

} else if(crop == Blocks.STONE) {
RitualUtil.start(context.getLevel(), context.getClickedPos(), FARituals.POTATO_RITUAL);
} else {
crop.growCrops(level, context.getClickedPos(), level.getBlockState(context.getClickedPos()));
context.getPlayer().hurt(level.damageSources().magic(), 2.0f);
context.getPlayer().awardStat(Stats.ITEM_USED.get(this));
this.getDefaultInstance().consume(1, context.getPlayer());
return InteractionResult.sidedSuccess(true);
}
}
return super.useOn(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class FABlocks {
public static final DeferredBlock<FarmlandBlock> DIORITE_FARMLAND = registerFarmland("diorite_farmland", BlockBehaviour.Properties.ofFullCopy(Blocks.DIORITE).randomTicks());

// Crops
public static final DeferredBlock<EmptyRootBlock> EMPTY_ROOT = BLOCKS.register("empty_root", () -> new EmptyRootBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.WHEAT).randomTicks()));
public static final DeferredBlock<ExplosionPotatoBlock> EXPLOSION_POTATOES = BLOCKS.register("explosion_potatoes", () -> new ExplosionPotatoBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.POTATOES).randomTicks()));
public static final DeferredBlock<SoftPotatoBlock> SOFT_POTATOES = BLOCKS.register("soft_potatoes", () -> new SoftPotatoBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.POTATOES).randomTicks()));
public static final DeferredBlock<GerberaPotatoBlock> GERBERA_POTATOES = BLOCKS.register("gerbera_potatoes", () -> new GerberaPotatoBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.POTATOES).randomTicks()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class FAItems {
public static final DeferredItem<EnhancedHoeItem> ENHANCED_HOE = ITEMS.register("enhanced_hoe", () -> new EnhancedHoeItem(Tiers.NETHERITE, new Item.Properties().rarity(Rarity.RARE).fireResistant().attributes(HoeItem.createAttributes(Tiers.NETHERITE, -4.0F, 0.0F))));

// Blocks
public static final DeferredItem<BlockItem> EMPTY_ROOT = registerBlock(FABlocks.EMPTY_ROOT);
public static final DeferredItem<BlockItem> STONE_FARMLAND = registerBlock(FABlocks.STONE_FARMLAND);
public static final DeferredItem<BlockItem> NETHERRACK_FARMLAND = registerBlock(FABlocks.NETHERRACK_FARMLAND);
public static final DeferredItem<BlockItem> END_STONE_FARMLAND = registerBlock(FABlocks.END_STONE_FARMLAND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class FAMobEffects {
private static final DeferredRegister<MobEffect> MOB_EFFECTS = DeferredRegister.create(BuiltInRegistries.MOB_EFFECT, FarmAway.MOD_ID);
public static final DeferredHolder<MobEffect, MobEffect> BLUES = MOB_EFFECTS.register("blues", () -> new MobEffect(MobEffectCategory.NEUTRAL, 0x1e197f));
public static final DeferredHolder<MobEffect, MobEffect> PHANTOM = MOB_EFFECTS.register("phantom", () -> new MobEffect(MobEffectCategory.NEUTRAL, 0x1e197f));
public static final DeferredHolder<MobEffect, MobEffect> VOID = MOB_EFFECTS.register("void", () -> new MobEffect(MobEffectCategory.NEUTRAL, 0x1e197f));

public static void register(IEventBus bus) {
MOB_EFFECTS.register(bus);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/ho/artisan/farmaway/common/ritual/Ritual.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ho.artisan.farmaway.common.ritual;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import ho.artisan.farmaway.common.data.FARegistries;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.block.Block;

import java.util.List;
import java.util.Optional;

public record Ritual(Holder<Block> centre, Holder<Block> centreOut, List<Holder<Block>> ritualBase, Holder<Block> baseOut) {
public Ritual(Block centre, Block centreOut, List<Block> base, Block baseOut) {
this(Holder.direct(centre), Holder.direct(centreOut), base.stream().map(Holder::direct).toList(), Holder.direct(baseOut));
}

public static final Codec<Ritual> CODEC = RecordCodecBuilder.create(instance -> instance.group(
BuiltInRegistries.BLOCK.holderByNameCodec().fieldOf("centre").forGetter(Ritual::centre),
BuiltInRegistries.BLOCK.holderByNameCodec().fieldOf("centre_out").forGetter(Ritual::centreOut),
BuiltInRegistries.BLOCK.holderByNameCodec().listOf().fieldOf("ritual_base").forGetter(Ritual::ritualBase),
BuiltInRegistries.BLOCK.holderByNameCodec().fieldOf("base_out").forGetter(Ritual::baseOut)
).apply(instance, Ritual::new));

public static Optional<Ritual> of(RegistryAccess access, ResourceKey<Ritual> key) {
Registry<Ritual> registry = access.registryOrThrow(FARegistries.RITUAL);
var holder = registry.getHolder(key);
return holder.map(Holder::value);
}
}
23 changes: 23 additions & 0 deletions src/main/java/ho/artisan/farmaway/common/util/RitualUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ho.artisan.farmaway.common.util;

import ho.artisan.farmaway.common.ritual.Ritual;
import net.minecraft.core.BlockPos;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
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.state.BlockState;

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.centre()) {
level.setBlock(pos.below(), ritual.baseOut().value().defaultBlockState(), 2);
level.setBlock(pos, ritual.centreOut().value().defaultBlockState(), 2);
}
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/ho/artisan/farmaway/datagen/DataGenerators.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ho.artisan.farmaway.datagen.loot.FALootProvider;
import ho.artisan.farmaway.datagen.model.FABlockStateProvider;
import ho.artisan.farmaway.datagen.model.FAItemModelProvider;
import ho.artisan.farmaway.datagen.rotual.FARitualsProvider;
import ho.artisan.farmaway.datagen.tags.FABlockTagsProvider;
import ho.artisan.farmaway.datagen.tags.FAItemTagsProvider;
import net.minecraft.core.HolderLookup;
Expand Down Expand Up @@ -39,5 +40,7 @@ public static void onGatherData(GatherDataEvent event) {

generator.addProvider(event.includeServer(), new FARecipeProvider(output, lookupProvider));
generator.addProvider(event.includeServer(), new FALootProvider(output, lookupProvider));

generator.addProvider(event.includeServer(), new FARitualsProvider(output, lookupProvider));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected void registerStatesAndModels() {
farmland(FABlocks.DIORITE_FARMLAND.get(), Blocks.DIORITE);
crop(FABlocks.PHANTOM_BEETROOTS.get(), 3, BlockStateProperties.AGE_7);
crop(FABlocks.EXPLOSION_POTATOES.get(), 3, BlockStateProperties.AGE_7);
crop(FABlocks.SOFT_POTATOES.get(), 3, BlockStateProperties.AGE_7);
crop(FABlocks.ROSE_POTATOES.get(), 3, BlockStateProperties.AGE_7);
// crop(FABlocks.SOFT_POTATOES.get(), 3, BlockStateProperties.AGE_7);
// crop(FABlocks.ROSE_POTATOES.get(), 3, BlockStateProperties.AGE_7);
crop(FABlocks.BLUES_CARROTS.get(), 3, BlockStateProperties.AGE_15);
crop(FABlocks.STRONG_CARROTS.get(), 3, BlockStateProperties.AGE_3);
// crop(FABlocks.PHANTOM_POTATOES.get(), 2, BlockStateProperties.AGE_3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ho.artisan.farmaway.datagen.rotual;

import ho.artisan.farmaway.FarmAway;
import ho.artisan.farmaway.common.data.FARegistries;
import ho.artisan.farmaway.common.data.FARituals;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.data.PackOutput;
import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider;

import java.util.Set;
import java.util.concurrent.CompletableFuture;

public class FARitualsProvider extends DatapackBuiltinEntriesProvider {
public static final RegistrySetBuilder BUILDER = new RegistrySetBuilder().add(FARegistries.RITUAL, FARituals::init);
public FARitualsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
super(output, registries, BUILDER, Set.of(FarmAway.MOD_ID));
}
}
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.
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.
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.

0 comments on commit 345b963

Please sign in to comment.