2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
2020-01-17 14:27:26 +01:00
|
|
|
|
2020-05-19 18:41:01 +02:00
|
|
|
import com.minelittlepony.unicopia.block.StickPlantBlock;
|
2020-04-15 19:06:45 +02:00
|
|
|
import com.minelittlepony.unicopia.block.UBlocks;
|
2020-01-17 14:27:26 +01:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemUsageContext;
|
2020-05-19 18:41:01 +02:00
|
|
|
import net.minecraft.sound.BlockSoundGroup;
|
|
|
|
import net.minecraft.sound.SoundCategory;
|
2020-01-17 14:27:26 +01:00
|
|
|
import net.minecraft.util.ActionResult;
|
2020-05-19 18:41:01 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2020-01-17 14:27:26 +01:00
|
|
|
|
|
|
|
public class TomatoSeedsItem extends Item {
|
|
|
|
|
2020-04-25 18:41:48 +02:00
|
|
|
public TomatoSeedsItem(Item.Settings settings) {
|
|
|
|
super(settings);
|
2020-01-17 14:27:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ActionResult useOnBlock(ItemUsageContext context) {
|
|
|
|
|
2020-05-19 18:41:01 +02:00
|
|
|
World world = context.getWorld();
|
|
|
|
BlockPos pos = context.getBlockPos();
|
|
|
|
BlockState state = world.getBlockState(context.getBlockPos());
|
2020-01-17 14:27:26 +01:00
|
|
|
|
|
|
|
Block block = state.getBlock();
|
|
|
|
|
2020-05-19 18:41:01 +02:00
|
|
|
if (block instanceof StickPlantBlock && (block == UBlocks.TOMATO_PLANT || block == UBlocks.CLOUDSDALE_TOMATO_PLANT)) {
|
|
|
|
StickPlantBlock plant = (StickPlantBlock)block;
|
|
|
|
|
|
|
|
if (plant.getSeedsItem() == this && state.get(plant.getAgeProperty()) == 0 && world.setBlockState(pos, plant.getPlacedState(world, pos, state).with(plant.getAgeProperty(), 1), 11)) {
|
|
|
|
BlockSoundGroup sound = block.getSoundGroup(state);
|
|
|
|
|
|
|
|
context.getWorld().playSound(null, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, sound.getVolume(), sound.getPitch() * 2);
|
|
|
|
|
2020-01-17 14:27:26 +01:00
|
|
|
PlayerEntity player = context.getPlayer();
|
|
|
|
|
|
|
|
if (player == null || !player.isCreative()) {
|
|
|
|
context.getStack().decrement(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ActionResult.PASS;
|
|
|
|
}
|
|
|
|
}
|