2020-01-30 16:04:40 +01:00
|
|
|
package de.ellpeck.naturesaura.items;
|
|
|
|
|
2020-02-25 15:14:56 +01:00
|
|
|
import de.ellpeck.naturesaura.gen.ModFeatures;
|
2020-01-30 16:04:40 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.block.Blocks;
|
|
|
|
import net.minecraft.block.NetherWartBlock;
|
|
|
|
import net.minecraft.item.ItemUseContext;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.util.InteractionResult;
|
2020-01-30 16:04:40 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2021-12-04 19:17:21 +01:00
|
|
|
import net.minecraft.util.math.Mth;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.level.Level;
|
|
|
|
import net.minecraft.level.gen.feature.IFeatureConfig;
|
|
|
|
import net.minecraft.level.server.ServerLevel;
|
2020-01-30 16:04:40 +01:00
|
|
|
|
|
|
|
public class ItemCrimsonMeal extends ItemImpl {
|
|
|
|
public ItemCrimsonMeal() {
|
|
|
|
super("crimson_meal");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public InteractionResult onItemUse(ItemUseContext context) {
|
|
|
|
Level level = context.getLevel();
|
2020-01-30 16:04:40 +01:00
|
|
|
BlockPos pos = context.getPos();
|
2021-12-04 15:40:09 +01:00
|
|
|
BlockState state = level.getBlockState(pos);
|
2020-01-30 16:04:40 +01:00
|
|
|
if (state.getBlock() == Blocks.NETHER_WART) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!level.isClientSide) {
|
|
|
|
if (level.rand.nextInt(5) == 0) {
|
2020-01-30 16:04:40 +01:00
|
|
|
int age = state.get(NetherWartBlock.AGE);
|
|
|
|
if (age >= 3) {
|
2021-12-04 15:40:09 +01:00
|
|
|
ModFeatures.NETHER_WART_MUSHROOM.func_241855_a((ServerLevel) level, ((ServerLevel) level).getChunkProvider().getChunkGenerator(), level.rand, pos, IFeatureConfig.NO_FEATURE_CONFIG);
|
2020-01-30 16:04:40 +01:00
|
|
|
} else {
|
2021-12-04 15:40:09 +01:00
|
|
|
level.setBlockState(pos, state.with(NetherWartBlock.AGE, age + 1));
|
2020-01-30 16:04:40 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
level.playEvent(2005, pos, 0);
|
2020-01-30 16:04:40 +01:00
|
|
|
context.getItem().shrink(1);
|
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
return InteractionResult.SUCCESS;
|
|
|
|
} else if (level.getBlockState(pos.up()).isAir(level, pos.up()) && level.getBlockState(pos).getBlock() == Blocks.SOUL_SAND) {
|
|
|
|
if (!level.isClientSide) {
|
|
|
|
for (int i = level.rand.nextInt(5); i >= 0; i--) {
|
2021-12-04 19:17:21 +01:00
|
|
|
BlockPos offset = pos.add(Mth.nextInt(level.rand, -3, 3), 1, Mth.nextInt(level.rand, -3, 3));
|
2021-12-04 15:40:09 +01:00
|
|
|
if (level.getBlockState(offset.down()).getBlock() == Blocks.SOUL_SAND && level.getBlockState(offset).isAir(level, offset)) {
|
|
|
|
level.setBlockState(offset, Blocks.NETHER_WART.getDefaultState());
|
2020-01-30 20:35:25 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
level.playEvent(2005, pos, 0);
|
2020-01-30 20:35:25 +01:00
|
|
|
context.getItem().shrink(1);
|
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
return InteractionResult.SUCCESS;
|
2020-01-30 16:04:40 +01:00
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
return InteractionResult.FAIL;
|
2020-01-30 16:04:40 +01:00
|
|
|
}
|
|
|
|
}
|