Search in sources :

Example 6 with BeehiveBlock

use of net.minecraft.block.BeehiveBlock in project minecolonies by ldtteam.

the class ItemScepterBeekeeper method useOn.

@Override
public ActionResultType useOn(final ItemUseContext useContext) {
    // if server world, do nothing
    if (useContext.getLevel().isClientSide) {
        return ActionResultType.FAIL;
    }
    final PlayerEntity player = useContext.getPlayer();
    final ItemStack scepter = useContext.getPlayer().getItemInHand(useContext.getHand());
    final CompoundNBT compound = scepter.getOrCreateTag();
    final IColony colony = IColonyManager.getInstance().getColonyByWorld(compound.getInt(TAG_ID), useContext.getLevel());
    final BlockPos hutPos = BlockPosUtil.read(compound, TAG_POS);
    final IBuilding hut = colony.getBuildingManager().getBuilding(hutPos);
    final BuildingBeekeeper building = (BuildingBeekeeper) hut;
    if (useContext.getLevel().getBlockState(useContext.getClickedPos()).getBlock() instanceof BeehiveBlock) {
        final Collection<BlockPos> positions = building.getHives();
        final BlockPos pos = useContext.getClickedPos();
        if (positions.contains(pos)) {
            LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.removehive");
            building.removeHive(pos);
            SoundUtils.playSoundForPlayer((ServerPlayerEntity) player, SoundEvents.NOTE_BLOCK_BELL, (float) SoundUtils.VOLUME * 2, 0.5f);
        } else {
            if (positions.size() < building.getMaximumHives()) {
                LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.addhive");
                building.addHive(pos);
                SoundUtils.playSuccessSound(player, player.blockPosition());
            }
            if (positions.size() >= building.getMaximumHives()) {
                LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.maxhives");
                player.inventory.removeItemNoUpdate(player.inventory.selected);
            }
        }
    } else {
        player.inventory.removeItemNoUpdate(player.inventory.selected);
    }
    return super.useOn(useContext);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BeehiveBlock(net.minecraft.block.BeehiveBlock) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Aggregations

BeehiveBlock (net.minecraft.block.BeehiveBlock)6 ItemStack (net.minecraft.item.ItemStack)5 BlockPos (net.minecraft.util.math.BlockPos)5 BuildingBeekeeper (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 World (net.minecraft.world.World)3 TypeToken (com.google.common.reflect.TypeToken)2 IColony (com.minecolonies.api.colony.IColony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)2 Compatibility (com.minecolonies.api.compatibility.Compatibility)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)2 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)2 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)2 InventoryUtils (com.minecolonies.api.util.InventoryUtils)2 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)2 BUILDING_FLOWER_LIST (com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST)2 TICKS_SECOND (com.minecolonies.api.util.constant.Constants.TICKS_SECOND)2