generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
2946ce9
commit f84ebb9
Showing
4 changed files
with
83 additions
and
8 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
48 changes: 48 additions & 0 deletions
48
src/main/java/com/nateplays/my_neoforge_mod/block/NulberryBushBlock.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,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); | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/nateplays/my_neoforge_mod/item/NulberryItem.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,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); | ||
} | ||
} |