Skip to content

Commit

Permalink
nulberry with classes and effects
Browse files Browse the repository at this point in the history
  • Loading branch information
natanmaia95 committed Aug 19, 2024
1 parent 2946ce9 commit f84ebb9
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ModBlocks {
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MyNeoForgeMod.MODID);



public static final DeferredBlock<Block> EARTH_CRYSTAL_ORE = registerBlock("earth_crystal_ore",
() -> new DropExperienceBlock(
UniformInt.of(2,4),
Expand All @@ -30,10 +31,7 @@ public class ModBlocks {
BlockBehaviour.Properties.of().strength(4f,2f).requiresCorrectToolForDrops().sound(SoundType.STONE)
));

public static final DeferredBlock<Block> NULBERRY_BUSH = registerBlock("nulberry_bush",
() -> new SweetBerryBushBlock(
BlockBehaviour.Properties.of().randomTicks().noCollission().pushReaction(PushReaction.DESTROY).noOcclusion()
));
public static final DeferredBlock<Block> NULBERRY_BUSH = registerBlock("nulberry_bush", NulberryBushBlock::new);



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.nateplays.my_neoforge_mod.block;

import com.nateplays.my_neoforge_mod.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.SweetBerryBushBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;

public class NulberryBushBlock extends SweetBerryBushBlock {

public NulberryBushBlock() {
super(BlockBehaviour.Properties.of().randomTicks().noCollission().pushReaction(PushReaction.DESTROY).noOcclusion());
}

@Override
public ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState state) {
return new ItemStack(ModItems.NULBERRY.get());
}

@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
int age = state.getValue(AGE);
boolean isFullyGrown = (age == 3);
if (age > 1) {
int roll = 1 + level.random.nextInt(2);
popResource(level, pos, new ItemStack(ModItems.NULBERRY.get(), roll + (isFullyGrown ? 1 : 0)));
level.playSound(
null, pos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + level.random.nextFloat() * 0.4F
);
BlockState blockstate = state.setValue(AGE, Integer.valueOf(1));
level.setBlock(pos, blockstate, 2);
level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, blockstate));
return InteractionResult.sidedSuccess(level.isClientSide);
} else {
return super.useWithoutItem(state, level, pos, player, hitResult);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.nateplays.my_neoforge_mod.item;

import com.nateplays.my_neoforge_mod.MyNeoForgeMod;
import com.nateplays.my_neoforge_mod.block.ModBlocks;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemNameBlockItem;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
Expand All @@ -11,15 +13,14 @@ public class ModItems {

public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MyNeoForgeMod.MODID);



public static final DeferredItem<Item> EARTH_CRYSTAL = ITEMS.register("earth_crystal",
() -> new Item(new Item.Properties()));
public static final DeferredItem<Item> MALACHITE_CHUNK = ITEMS.register("machalite_chunk",
() -> new Item(new Item.Properties()));

public static final DeferredItem<Item> NULBERRY = ITEMS.register("nulberry",
() -> new Item(new Item.Properties().food(
new FoodProperties.Builder().alwaysEdible().fast().nutrition(1).saturationModifier(0.5f).build()
)));
() -> new NulberryItem(new Item.Properties()));



Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/nateplays/my_neoforge_mod/item/NulberryItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.nateplays.my_neoforge_mod.item;

import com.nateplays.my_neoforge_mod.block.ModBlocks;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemNameBlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.EffectCures;

public class NulberryItem extends ItemNameBlockItem {

public NulberryItem(Item.Properties properties) {
super(ModBlocks.NULBERRY_BUSH.get(),
properties.food(new FoodProperties.Builder().alwaysEdible().nutrition(1).saturationModifier(0.1F).build()));
}

/**
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using the Item before the action is complete.
*/
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity entityLiving) {
if (!level.isClientSide()) {
entityLiving.removeEffectsCuredBy(EffectCures.MILK);
}
return super.finishUsingItem(stack, level, entityLiving);
}
}

0 comments on commit f84ebb9

Please sign in to comment.